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 = extern "C" fn(ctx: *mut _Unwind_Context, arg: *mut c_void)
25 -> _Unwind_Reason_Code;
26 #[cfg(target_arch = "x86")]
27 pub const unwinder_private_data_size: usize = 5;
29 #[cfg(target_arch = "x86_64")]
30 pub const unwinder_private_data_size: usize = 6;
32 #[cfg(all(target_arch = "arm", not(target_os = "ios")))]
33 pub const unwinder_private_data_size: usize = 20;
35 #[cfg(all(target_arch = "arm", target_os = "ios"))]
36 pub const unwinder_private_data_size: usize = 5;
38 #[cfg(target_arch = "aarch64")]
39 pub const unwinder_private_data_size: usize = 2;
41 #[cfg(target_arch = "mips")]
42 pub const unwinder_private_data_size: usize = 2;
44 #[cfg(target_arch = "mips64")]
45 pub const unwinder_private_data_size: usize = 2;
47 #[cfg(any(target_arch = "powerpc", target_arch = "powerpc64"))]
48 pub const unwinder_private_data_size: usize = 2;
50 #[cfg(target_arch = "s390x")]
51 pub const unwinder_private_data_size: usize = 2;
53 #[cfg(target_arch = "sparc64")]
54 pub const unwinder_private_data_size: usize = 2;
56 #[cfg(target_os = "emscripten")]
57 pub const unwinder_private_data_size: usize = 20;
60 pub struct _Unwind_Exception {
61 pub exception_class: _Unwind_Exception_Class,
62 pub exception_cleanup: _Unwind_Exception_Cleanup_Fn,
63 pub private: [_Unwind_Word; unwinder_private_data_size],
66 pub enum _Unwind_Context {}
68 pub type _Unwind_Exception_Cleanup_Fn = extern "C" fn(unwind_code: _Unwind_Reason_Code,
69 exception: *mut _Unwind_Exception);
72 pub fn _Unwind_Resume(exception: *mut _Unwind_Exception) -> !;
73 pub fn _Unwind_DeleteException(exception: *mut _Unwind_Exception);
74 pub fn _Unwind_GetLanguageSpecificData(ctx: *mut _Unwind_Context) -> *mut c_void;
75 pub fn _Unwind_GetRegionStart(ctx: *mut _Unwind_Context) -> _Unwind_Ptr;
76 pub fn _Unwind_GetTextRelBase(ctx: *mut _Unwind_Context) -> _Unwind_Ptr;
77 pub fn _Unwind_GetDataRelBase(ctx: *mut _Unwind_Context) -> _Unwind_Ptr;
81 if #[cfg(all(any(target_os = "ios", target_os = "netbsd", not(target_arch = "arm"))))] {
84 #[derive(Copy, Clone, PartialEq)]
85 pub enum _Unwind_Action {
87 _UA_CLEANUP_PHASE = 2,
88 _UA_HANDLER_FRAME = 4,
90 _UA_END_OF_STACK = 16,
92 pub use _Unwind_Action::*;
95 pub fn _Unwind_GetGR(ctx: *mut _Unwind_Context, reg_index: c_int) -> _Unwind_Word;
96 pub fn _Unwind_SetGR(ctx: *mut _Unwind_Context, reg_index: c_int, value: _Unwind_Word);
97 pub fn _Unwind_GetIP(ctx: *mut _Unwind_Context) -> _Unwind_Word;
98 pub fn _Unwind_SetIP(ctx: *mut _Unwind_Context, value: _Unwind_Word);
99 pub fn _Unwind_GetIPInfo(ctx: *mut _Unwind_Context, ip_before_insn: *mut c_int)
101 pub fn _Unwind_FindEnclosingFunction(pc: *mut c_void) -> *mut c_void;
107 #[derive(Copy, Clone, PartialEq)]
108 pub enum _Unwind_State {
109 _US_VIRTUAL_UNWIND_FRAME = 0,
110 _US_UNWIND_FRAME_STARTING = 1,
111 _US_UNWIND_FRAME_RESUME = 2,
113 _US_FORCE_UNWIND = 8,
114 _US_END_OF_STACK = 16,
116 pub use _Unwind_State::*;
119 enum _Unwind_VRS_Result {
121 _UVRSR_NOT_IMPLEMENTED = 1,
125 enum _Unwind_VRS_RegClass {
132 use _Unwind_VRS_RegClass::*;
134 enum _Unwind_VRS_DataRepresentation {
142 use _Unwind_VRS_DataRepresentation::*;
144 pub const UNWIND_POINTER_REG: c_int = 12;
145 pub const UNWIND_IP_REG: c_int = 15;
148 fn _Unwind_VRS_Get(ctx: *mut _Unwind_Context,
149 regclass: _Unwind_VRS_RegClass,
151 repr: _Unwind_VRS_DataRepresentation,
153 -> _Unwind_VRS_Result;
155 fn _Unwind_VRS_Set(ctx: *mut _Unwind_Context,
156 regclass: _Unwind_VRS_RegClass,
158 repr: _Unwind_VRS_DataRepresentation,
160 -> _Unwind_VRS_Result;
163 // On Android or ARM/Linux, these are implemented as macros:
165 pub unsafe fn _Unwind_GetGR(ctx: *mut _Unwind_Context, reg_index: c_int) -> _Unwind_Word {
166 let mut val: _Unwind_Word = 0;
167 _Unwind_VRS_Get(ctx, _UVRSC_CORE, reg_index as _Unwind_Word, _UVRSD_UINT32,
168 &mut val as *mut _ as *mut c_void);
172 pub unsafe fn _Unwind_SetGR(ctx: *mut _Unwind_Context, reg_index: c_int, value: _Unwind_Word) {
173 let mut value = value;
174 _Unwind_VRS_Set(ctx, _UVRSC_CORE, reg_index as _Unwind_Word, _UVRSD_UINT32,
175 &mut value as *mut _ as *mut c_void);
178 pub unsafe fn _Unwind_GetIP(ctx: *mut _Unwind_Context)
180 let val = _Unwind_GetGR(ctx, UNWIND_IP_REG);
181 (val & !1) as _Unwind_Word
184 pub unsafe fn _Unwind_SetIP(ctx: *mut _Unwind_Context,
185 value: _Unwind_Word) {
186 // Propagate thumb bit to instruction pointer
187 let thumb_state = _Unwind_GetGR(ctx, UNWIND_IP_REG) & 1;
188 let value = value | thumb_state;
189 _Unwind_SetGR(ctx, UNWIND_IP_REG, value);
192 pub unsafe fn _Unwind_GetIPInfo(ctx: *mut _Unwind_Context,
193 ip_before_insn: *mut c_int)
199 // This function also doesn't exist on Android or ARM/Linux, so make it a no-op
200 pub unsafe fn _Unwind_FindEnclosingFunction(pc: *mut c_void) -> *mut c_void {
207 if #[cfg(not(all(target_os = "ios", target_arch = "arm")))] {
211 pub fn _Unwind_RaiseException(exception: *mut _Unwind_Exception) -> _Unwind_Reason_Code;
212 pub fn _Unwind_Backtrace(trace: _Unwind_Trace_Fn,
213 trace_argument: *mut c_void)
214 -> _Unwind_Reason_Code;
217 // 32-bit iOS uses SjLj and does not provide _Unwind_Backtrace()
220 pub fn _Unwind_SjLj_RaiseException(e: *mut _Unwind_Exception) -> _Unwind_Reason_Code;
224 pub unsafe fn _Unwind_RaiseException(exc: *mut _Unwind_Exception) -> _Unwind_Reason_Code {
225 _Unwind_SjLj_RaiseException(exc)