1 #![allow(nonstandard_style)]
3 use libc::{c_int, c_void, uintptr_t};
6 #[derive(Debug, Copy, Clone, PartialEq)]
7 pub enum _Unwind_Reason_Code {
9 _URC_FOREIGN_EXCEPTION_CAUGHT = 1,
10 _URC_FATAL_PHASE2_ERROR = 2,
11 _URC_FATAL_PHASE1_ERROR = 3,
13 _URC_END_OF_STACK = 5,
14 _URC_HANDLER_FOUND = 6,
15 _URC_INSTALL_CONTEXT = 7,
16 _URC_CONTINUE_UNWIND = 8,
17 _URC_FAILURE = 9, // used only by ARM EHABI
19 pub use _Unwind_Reason_Code::*;
21 pub type _Unwind_Exception_Class = u64;
22 pub type _Unwind_Word = uintptr_t;
23 pub type _Unwind_Ptr = uintptr_t;
24 pub type _Unwind_Trace_Fn =
25 extern "C" fn(ctx: *mut _Unwind_Context, arg: *mut c_void) -> _Unwind_Reason_Code;
27 #[cfg(target_arch = "x86")]
28 pub const unwinder_private_data_size: usize = 5;
30 #[cfg(target_arch = "x86_64")]
31 pub const unwinder_private_data_size: usize = 6;
33 #[cfg(all(target_arch = "arm", not(target_os = "ios")))]
34 pub const unwinder_private_data_size: usize = 20;
36 #[cfg(all(target_arch = "arm", target_os = "ios"))]
37 pub const unwinder_private_data_size: usize = 5;
39 #[cfg(all(target_arch = "aarch64", target_pointer_width = "64"))]
40 pub const unwinder_private_data_size: usize = 2;
42 #[cfg(all(target_arch = "aarch64", target_pointer_width = "32"))]
43 pub const unwinder_private_data_size: usize = 5;
45 #[cfg(target_arch = "mips")]
46 pub const unwinder_private_data_size: usize = 2;
48 #[cfg(target_arch = "mips64")]
49 pub const unwinder_private_data_size: usize = 2;
51 #[cfg(any(target_arch = "powerpc", target_arch = "powerpc64"))]
52 pub const unwinder_private_data_size: usize = 2;
54 #[cfg(target_arch = "s390x")]
55 pub const unwinder_private_data_size: usize = 2;
57 #[cfg(any(target_arch = "sparc", target_arch = "sparc64"))]
58 pub const unwinder_private_data_size: usize = 2;
60 #[cfg(any(target_arch = "riscv64", target_arch = "riscv32"))]
61 pub const unwinder_private_data_size: usize = 2;
63 #[cfg(target_os = "emscripten")]
64 pub const unwinder_private_data_size: usize = 20;
66 #[cfg(all(target_arch = "hexagon", target_os = "linux"))]
67 pub const unwinder_private_data_size: usize = 35;
70 pub struct _Unwind_Exception {
71 pub exception_class: _Unwind_Exception_Class,
72 pub exception_cleanup: _Unwind_Exception_Cleanup_Fn,
73 pub private: [_Unwind_Word; unwinder_private_data_size],
76 pub enum _Unwind_Context {}
78 pub type _Unwind_Exception_Cleanup_Fn =
79 extern "C" fn(unwind_code: _Unwind_Reason_Code, exception: *mut _Unwind_Exception);
81 all(feature = "llvm-libunwind", any(target_os = "fuchsia", target_os = "linux")),
82 link(name = "unwind", kind = "static")
86 pub fn _Unwind_Resume(exception: *mut _Unwind_Exception) -> !;
87 pub fn _Unwind_DeleteException(exception: *mut _Unwind_Exception);
88 pub fn _Unwind_GetLanguageSpecificData(ctx: *mut _Unwind_Context) -> *mut c_void;
89 pub fn _Unwind_GetRegionStart(ctx: *mut _Unwind_Context) -> _Unwind_Ptr;
90 pub fn _Unwind_GetTextRelBase(ctx: *mut _Unwind_Context) -> _Unwind_Ptr;
91 pub fn _Unwind_GetDataRelBase(ctx: *mut _Unwind_Context) -> _Unwind_Ptr;
95 if #[cfg(any(target_os = "ios", target_os = "netbsd", not(target_arch = "arm")))] {
98 #[derive(Copy, Clone, PartialEq)]
99 pub enum _Unwind_Action {
100 _UA_SEARCH_PHASE = 1,
101 _UA_CLEANUP_PHASE = 2,
102 _UA_HANDLER_FRAME = 4,
103 _UA_FORCE_UNWIND = 8,
104 _UA_END_OF_STACK = 16,
106 pub use _Unwind_Action::*;
108 #[cfg_attr(all(feature = "llvm-libunwind",
109 any(target_os = "fuchsia", target_os = "linux")),
110 link(name = "unwind", kind = "static"))]
112 pub fn _Unwind_GetGR(ctx: *mut _Unwind_Context, reg_index: c_int) -> _Unwind_Word;
113 pub fn _Unwind_SetGR(ctx: *mut _Unwind_Context, reg_index: c_int, value: _Unwind_Word);
114 pub fn _Unwind_GetIP(ctx: *mut _Unwind_Context) -> _Unwind_Word;
115 pub fn _Unwind_SetIP(ctx: *mut _Unwind_Context, value: _Unwind_Word);
116 pub fn _Unwind_GetIPInfo(ctx: *mut _Unwind_Context, ip_before_insn: *mut c_int)
118 pub fn _Unwind_FindEnclosingFunction(pc: *mut c_void) -> *mut c_void;
124 #[derive(Copy, Clone, PartialEq)]
125 pub enum _Unwind_State {
126 _US_VIRTUAL_UNWIND_FRAME = 0,
127 _US_UNWIND_FRAME_STARTING = 1,
128 _US_UNWIND_FRAME_RESUME = 2,
130 _US_FORCE_UNWIND = 8,
131 _US_END_OF_STACK = 16,
133 pub use _Unwind_State::*;
136 enum _Unwind_VRS_Result {
138 _UVRSR_NOT_IMPLEMENTED = 1,
142 enum _Unwind_VRS_RegClass {
149 use _Unwind_VRS_RegClass::*;
151 enum _Unwind_VRS_DataRepresentation {
159 use _Unwind_VRS_DataRepresentation::*;
161 pub const UNWIND_POINTER_REG: c_int = 12;
162 pub const UNWIND_SP_REG: c_int = 13;
163 pub const UNWIND_IP_REG: c_int = 15;
165 #[cfg_attr(all(feature = "llvm-libunwind",
166 any(target_os = "fuchsia", target_os = "linux")),
167 link(name = "unwind", kind = "static"))]
169 fn _Unwind_VRS_Get(ctx: *mut _Unwind_Context,
170 regclass: _Unwind_VRS_RegClass,
172 repr: _Unwind_VRS_DataRepresentation,
174 -> _Unwind_VRS_Result;
176 fn _Unwind_VRS_Set(ctx: *mut _Unwind_Context,
177 regclass: _Unwind_VRS_RegClass,
179 repr: _Unwind_VRS_DataRepresentation,
181 -> _Unwind_VRS_Result;
184 // On Android or ARM/Linux, these are implemented as macros:
186 pub unsafe fn _Unwind_GetGR(ctx: *mut _Unwind_Context, reg_index: c_int) -> _Unwind_Word {
187 let mut val: _Unwind_Word = 0;
188 _Unwind_VRS_Get(ctx, _UVRSC_CORE, reg_index as _Unwind_Word, _UVRSD_UINT32,
189 &mut val as *mut _ as *mut c_void);
193 pub unsafe fn _Unwind_SetGR(ctx: *mut _Unwind_Context, reg_index: c_int, value: _Unwind_Word) {
194 let mut value = value;
195 _Unwind_VRS_Set(ctx, _UVRSC_CORE, reg_index as _Unwind_Word, _UVRSD_UINT32,
196 &mut value as *mut _ as *mut c_void);
199 pub unsafe fn _Unwind_GetIP(ctx: *mut _Unwind_Context)
201 let val = _Unwind_GetGR(ctx, UNWIND_IP_REG);
202 (val & !1) as _Unwind_Word
205 pub unsafe fn _Unwind_SetIP(ctx: *mut _Unwind_Context,
206 value: _Unwind_Word) {
207 // Propagate thumb bit to instruction pointer
208 let thumb_state = _Unwind_GetGR(ctx, UNWIND_IP_REG) & 1;
209 let value = value | thumb_state;
210 _Unwind_SetGR(ctx, UNWIND_IP_REG, value);
213 pub unsafe fn _Unwind_GetIPInfo(ctx: *mut _Unwind_Context,
214 ip_before_insn: *mut c_int)
220 // This function also doesn't exist on Android or ARM/Linux, so make it a no-op
221 pub unsafe fn _Unwind_FindEnclosingFunction(pc: *mut c_void) -> *mut c_void {
228 if #[cfg(not(all(target_os = "ios", target_arch = "arm")))] {
230 #[cfg_attr(all(feature = "llvm-libunwind",
231 any(target_os = "fuchsia", target_os = "linux")),
232 link(name = "unwind", kind = "static"))]
235 pub fn _Unwind_RaiseException(exception: *mut _Unwind_Exception) -> _Unwind_Reason_Code;
236 pub fn _Unwind_Backtrace(trace: _Unwind_Trace_Fn,
237 trace_argument: *mut c_void)
238 -> _Unwind_Reason_Code;
241 // 32-bit iOS uses SjLj and does not provide _Unwind_Backtrace()
242 #[cfg_attr(all(feature = "llvm-libunwind",
243 any(target_os = "fuchsia", target_os = "linux")),
244 link(name = "unwind", kind = "static"))]
247 pub fn _Unwind_SjLj_RaiseException(e: *mut _Unwind_Exception) -> _Unwind_Reason_Code;
251 pub unsafe fn _Unwind_RaiseException(exc: *mut _Unwind_Exception) -> _Unwind_Reason_Code {
252 _Unwind_SjLj_RaiseException(exc)
258 if #[cfg(all(windows, target_arch = "x86_64", target_env = "gnu"))] {
259 // We declare these as opaque types. This is fine since you just need to
260 // pass them to _GCC_specific_handler and forget about them.
261 pub enum EXCEPTION_RECORD {}
262 pub type LPVOID = *mut c_void;
264 pub enum DISPATCHER_CONTEXT {}
265 pub type EXCEPTION_DISPOSITION = c_int;
266 type PersonalityFn = unsafe extern "C" fn(version: c_int,
267 actions: _Unwind_Action,
268 exception_class: _Unwind_Exception_Class,
269 exception_object: *mut _Unwind_Exception,
270 context: *mut _Unwind_Context)
271 -> _Unwind_Reason_Code;
274 pub fn _GCC_specific_handler(exceptionRecord: *mut EXCEPTION_RECORD,
275 establisherFrame: LPVOID,
276 contextRecord: *mut CONTEXT,
277 dispatcherContext: *mut DISPATCHER_CONTEXT,
278 personality: PersonalityFn)
279 -> EXCEPTION_DISPOSITION;