1 #![allow(nonstandard_style)]
4 ( $( if #[cfg( $meta:meta )] { $($it1:item)* } else { $($it2:item)* } )* ) =>
5 ( $( $( #[cfg($meta)] $it1)* $( #[cfg(not($meta))] $it2)* )* )
8 use libc::{c_int, c_void, uintptr_t};
11 #[derive(Debug, Copy, Clone, PartialEq)]
12 pub enum _Unwind_Reason_Code {
14 _URC_FOREIGN_EXCEPTION_CAUGHT = 1,
15 _URC_FATAL_PHASE2_ERROR = 2,
16 _URC_FATAL_PHASE1_ERROR = 3,
18 _URC_END_OF_STACK = 5,
19 _URC_HANDLER_FOUND = 6,
20 _URC_INSTALL_CONTEXT = 7,
21 _URC_CONTINUE_UNWIND = 8,
22 _URC_FAILURE = 9, // used only by ARM EHABI
24 pub use _Unwind_Reason_Code::*;
26 pub type _Unwind_Exception_Class = u64;
27 pub type _Unwind_Word = uintptr_t;
28 pub type _Unwind_Ptr = uintptr_t;
29 pub type _Unwind_Trace_Fn = extern "C" fn(ctx: *mut _Unwind_Context, arg: *mut c_void)
30 -> _Unwind_Reason_Code;
31 #[cfg(target_arch = "x86")]
32 pub const unwinder_private_data_size: usize = 5;
34 #[cfg(target_arch = "x86_64")]
35 pub const unwinder_private_data_size: usize = 6;
37 #[cfg(all(target_arch = "arm", not(target_os = "ios")))]
38 pub const unwinder_private_data_size: usize = 20;
40 #[cfg(all(target_arch = "arm", target_os = "ios"))]
41 pub const unwinder_private_data_size: usize = 5;
43 #[cfg(target_arch = "aarch64")]
44 pub const unwinder_private_data_size: usize = 2;
46 #[cfg(target_arch = "mips")]
47 pub const unwinder_private_data_size: usize = 2;
49 #[cfg(target_arch = "mips64")]
50 pub const unwinder_private_data_size: usize = 2;
52 #[cfg(any(target_arch = "powerpc", target_arch = "powerpc64"))]
53 pub const unwinder_private_data_size: usize = 2;
55 #[cfg(target_arch = "s390x")]
56 pub const unwinder_private_data_size: usize = 2;
58 #[cfg(target_arch = "sparc64")]
59 pub const unwinder_private_data_size: usize = 2;
61 #[cfg(target_os = "emscripten")]
62 pub const unwinder_private_data_size: usize = 20;
65 pub struct _Unwind_Exception {
66 pub exception_class: _Unwind_Exception_Class,
67 pub exception_cleanup: _Unwind_Exception_Cleanup_Fn,
68 pub private: [_Unwind_Word; unwinder_private_data_size],
71 pub enum _Unwind_Context {}
73 pub type _Unwind_Exception_Cleanup_Fn = extern "C" fn(unwind_code: _Unwind_Reason_Code,
74 exception: *mut _Unwind_Exception);
77 pub fn _Unwind_Resume(exception: *mut _Unwind_Exception) -> !;
78 pub fn _Unwind_DeleteException(exception: *mut _Unwind_Exception);
79 pub fn _Unwind_GetLanguageSpecificData(ctx: *mut _Unwind_Context) -> *mut c_void;
80 pub fn _Unwind_GetRegionStart(ctx: *mut _Unwind_Context) -> _Unwind_Ptr;
81 pub fn _Unwind_GetTextRelBase(ctx: *mut _Unwind_Context) -> _Unwind_Ptr;
82 pub fn _Unwind_GetDataRelBase(ctx: *mut _Unwind_Context) -> _Unwind_Ptr;
86 if #[cfg(all(any(target_os = "ios", target_os = "netbsd", not(target_arch = "arm"))))] {
89 #[derive(Copy, Clone, PartialEq)]
90 pub enum _Unwind_Action {
92 _UA_CLEANUP_PHASE = 2,
93 _UA_HANDLER_FRAME = 4,
95 _UA_END_OF_STACK = 16,
97 pub use _Unwind_Action::*;
100 pub fn _Unwind_GetGR(ctx: *mut _Unwind_Context, reg_index: c_int) -> _Unwind_Word;
101 pub fn _Unwind_SetGR(ctx: *mut _Unwind_Context, reg_index: c_int, value: _Unwind_Word);
102 pub fn _Unwind_GetIP(ctx: *mut _Unwind_Context) -> _Unwind_Word;
103 pub fn _Unwind_SetIP(ctx: *mut _Unwind_Context, value: _Unwind_Word);
104 pub fn _Unwind_GetIPInfo(ctx: *mut _Unwind_Context, ip_before_insn: *mut c_int)
106 pub fn _Unwind_FindEnclosingFunction(pc: *mut c_void) -> *mut c_void;
112 #[derive(Copy, Clone, PartialEq)]
113 pub enum _Unwind_State {
114 _US_VIRTUAL_UNWIND_FRAME = 0,
115 _US_UNWIND_FRAME_STARTING = 1,
116 _US_UNWIND_FRAME_RESUME = 2,
118 _US_FORCE_UNWIND = 8,
119 _US_END_OF_STACK = 16,
121 pub use _Unwind_State::*;
124 enum _Unwind_VRS_Result {
126 _UVRSR_NOT_IMPLEMENTED = 1,
130 enum _Unwind_VRS_RegClass {
137 use _Unwind_VRS_RegClass::*;
139 enum _Unwind_VRS_DataRepresentation {
147 use _Unwind_VRS_DataRepresentation::*;
149 pub const UNWIND_POINTER_REG: c_int = 12;
150 pub const UNWIND_IP_REG: c_int = 15;
153 fn _Unwind_VRS_Get(ctx: *mut _Unwind_Context,
154 regclass: _Unwind_VRS_RegClass,
156 repr: _Unwind_VRS_DataRepresentation,
158 -> _Unwind_VRS_Result;
160 fn _Unwind_VRS_Set(ctx: *mut _Unwind_Context,
161 regclass: _Unwind_VRS_RegClass,
163 repr: _Unwind_VRS_DataRepresentation,
165 -> _Unwind_VRS_Result;
168 // On Android or ARM/Linux, these are implemented as macros:
170 pub unsafe fn _Unwind_GetGR(ctx: *mut _Unwind_Context, reg_index: c_int) -> _Unwind_Word {
171 let mut val: _Unwind_Word = 0;
172 _Unwind_VRS_Get(ctx, _UVRSC_CORE, reg_index as _Unwind_Word, _UVRSD_UINT32,
173 &mut val as *mut _ as *mut c_void);
177 pub unsafe fn _Unwind_SetGR(ctx: *mut _Unwind_Context, reg_index: c_int, value: _Unwind_Word) {
178 let mut value = value;
179 _Unwind_VRS_Set(ctx, _UVRSC_CORE, reg_index as _Unwind_Word, _UVRSD_UINT32,
180 &mut value as *mut _ as *mut c_void);
183 pub unsafe fn _Unwind_GetIP(ctx: *mut _Unwind_Context)
185 let val = _Unwind_GetGR(ctx, UNWIND_IP_REG);
186 (val & !1) as _Unwind_Word
189 pub unsafe fn _Unwind_SetIP(ctx: *mut _Unwind_Context,
190 value: _Unwind_Word) {
191 // Propagate thumb bit to instruction pointer
192 let thumb_state = _Unwind_GetGR(ctx, UNWIND_IP_REG) & 1;
193 let value = value | thumb_state;
194 _Unwind_SetGR(ctx, UNWIND_IP_REG, value);
197 pub unsafe fn _Unwind_GetIPInfo(ctx: *mut _Unwind_Context,
198 ip_before_insn: *mut c_int)
204 // This function also doesn't exist on Android or ARM/Linux, so make it a no-op
205 pub unsafe fn _Unwind_FindEnclosingFunction(pc: *mut c_void) -> *mut c_void {
210 if #[cfg(not(all(target_os = "ios", target_arch = "arm")))] {
214 pub fn _Unwind_RaiseException(exception: *mut _Unwind_Exception) -> _Unwind_Reason_Code;
215 pub fn _Unwind_Backtrace(trace: _Unwind_Trace_Fn,
216 trace_argument: *mut c_void)
217 -> _Unwind_Reason_Code;
220 // 32-bit iOS uses SjLj and does not provide _Unwind_Backtrace()
223 pub fn _Unwind_SjLj_RaiseException(e: *mut _Unwind_Exception) -> _Unwind_Reason_Code;
227 pub unsafe fn _Unwind_RaiseException(exc: *mut _Unwind_Exception) -> _Unwind_Reason_Code {
228 _Unwind_SjLj_RaiseException(exc)