]> git.lizzy.rs Git - rust.git/blob - src/libpanic_unwind/windows.rs
Auto merge of #53815 - F001:if-let-guard, r=petrochenkov
[rust.git] / src / libpanic_unwind / windows.rs
1 // Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 #![allow(nonstandard_style)]
12 #![allow(dead_code)]
13 #![cfg(windows)]
14
15 use libc::{c_long, c_ulong, c_void};
16
17 pub type DWORD = c_ulong;
18 pub type LONG = c_long;
19 pub type ULONG_PTR = usize;
20 pub type LPVOID = *mut c_void;
21
22 pub const EXCEPTION_MAXIMUM_PARAMETERS: usize = 15;
23 pub const EXCEPTION_NONCONTINUABLE: DWORD = 0x1;   // Noncontinuable exception
24 pub const EXCEPTION_UNWINDING: DWORD = 0x2;        // Unwind is in progress
25 pub const EXCEPTION_EXIT_UNWIND: DWORD = 0x4;      // Exit unwind is in progress
26 pub const EXCEPTION_TARGET_UNWIND: DWORD = 0x20;   // Target unwind in progress
27 pub const EXCEPTION_COLLIDED_UNWIND: DWORD = 0x40; // Collided exception handler call
28 pub const EXCEPTION_UNWIND: DWORD = EXCEPTION_UNWINDING | EXCEPTION_EXIT_UNWIND |
29                                     EXCEPTION_TARGET_UNWIND |
30                                     EXCEPTION_COLLIDED_UNWIND;
31
32 #[repr(C)]
33 pub struct EXCEPTION_RECORD {
34     pub ExceptionCode: DWORD,
35     pub ExceptionFlags: DWORD,
36     pub ExceptionRecord: *mut EXCEPTION_RECORD,
37     pub ExceptionAddress: LPVOID,
38     pub NumberParameters: DWORD,
39     pub ExceptionInformation: [LPVOID; EXCEPTION_MAXIMUM_PARAMETERS],
40 }
41
42 #[repr(C)]
43 pub struct EXCEPTION_POINTERS {
44     pub ExceptionRecord: *mut EXCEPTION_RECORD,
45     pub ContextRecord: *mut CONTEXT,
46 }
47
48 pub enum UNWIND_HISTORY_TABLE {}
49
50 #[repr(C)]
51 pub struct RUNTIME_FUNCTION {
52     pub BeginAddress: DWORD,
53     pub EndAddress: DWORD,
54     pub UnwindData: DWORD,
55 }
56
57 pub enum CONTEXT {}
58
59 #[repr(C)]
60 pub struct DISPATCHER_CONTEXT {
61     pub ControlPc: LPVOID,
62     pub ImageBase: LPVOID,
63     pub FunctionEntry: *const RUNTIME_FUNCTION,
64     pub EstablisherFrame: LPVOID,
65     pub TargetIp: LPVOID,
66     pub ContextRecord: *const CONTEXT,
67     pub LanguageHandler: LPVOID,
68     pub HandlerData: *const u8,
69     pub HistoryTable: *const UNWIND_HISTORY_TABLE,
70 }
71
72 #[repr(C)]
73 pub enum EXCEPTION_DISPOSITION {
74     ExceptionContinueExecution,
75     ExceptionContinueSearch,
76     ExceptionNestedException,
77     ExceptionCollidedUnwind,
78 }
79 pub use self::EXCEPTION_DISPOSITION::*;
80
81 extern "system" {
82     #[unwind(allowed)]
83     pub fn RaiseException(dwExceptionCode: DWORD,
84                           dwExceptionFlags: DWORD,
85                           nNumberOfArguments: DWORD,
86                           lpArguments: *const ULONG_PTR);
87     #[unwind(allowed)]
88     pub fn RtlUnwindEx(TargetFrame: LPVOID,
89                        TargetIp: LPVOID,
90                        ExceptionRecord: *const EXCEPTION_RECORD,
91                        ReturnValue: LPVOID,
92                        OriginalContext: *const CONTEXT,
93                        HistoryTable: *const UNWIND_HISTORY_TABLE);
94     #[unwind(allowed)]
95     pub fn _CxxThrowException(pExceptionObject: *mut c_void, pThrowInfo: *mut u8);
96 }