]>
Commit | Line | Data |
---|---|---|
b7449926 | 1 | #![allow(nonstandard_style)] |
1a4d82fc | 2 | |
5bcae85e | 3 | use libc::{c_int, c_void, uintptr_t}; |
1a4d82fc JJ |
4 | |
5 | #[repr(C)] | |
8bb4bdeb | 6 | #[derive(Debug, Copy, Clone, PartialEq)] |
1a4d82fc JJ |
7 | pub enum _Unwind_Reason_Code { |
8 | _URC_NO_REASON = 0, | |
9 | _URC_FOREIGN_EXCEPTION_CAUGHT = 1, | |
10 | _URC_FATAL_PHASE2_ERROR = 2, | |
11 | _URC_FATAL_PHASE1_ERROR = 3, | |
12 | _URC_NORMAL_STOP = 4, | |
13 | _URC_END_OF_STACK = 5, | |
14 | _URC_HANDLER_FOUND = 6, | |
15 | _URC_INSTALL_CONTEXT = 7, | |
16 | _URC_CONTINUE_UNWIND = 8, | |
5bcae85e | 17 | _URC_FAILURE = 9, // used only by ARM EHABI |
1a4d82fc | 18 | } |
9fa01778 | 19 | pub use _Unwind_Reason_Code::*; |
1a4d82fc JJ |
20 | |
21 | pub type _Unwind_Exception_Class = u64; | |
5bcae85e SL |
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) | |
3157f602 | 25 | -> _Unwind_Reason_Code; |
1a4d82fc | 26 | #[cfg(target_arch = "x86")] |
c34b1796 | 27 | pub const unwinder_private_data_size: usize = 5; |
1a4d82fc JJ |
28 | |
29 | #[cfg(target_arch = "x86_64")] | |
c34b1796 | 30 | pub const unwinder_private_data_size: usize = 6; |
1a4d82fc JJ |
31 | |
32 | #[cfg(all(target_arch = "arm", not(target_os = "ios")))] | |
c34b1796 | 33 | pub const unwinder_private_data_size: usize = 20; |
1a4d82fc JJ |
34 | |
35 | #[cfg(all(target_arch = "arm", target_os = "ios"))] | |
c34b1796 | 36 | pub const unwinder_private_data_size: usize = 5; |
1a4d82fc JJ |
37 | |
38 | #[cfg(target_arch = "aarch64")] | |
c34b1796 | 39 | pub const unwinder_private_data_size: usize = 2; |
1a4d82fc | 40 | |
7453a54e | 41 | #[cfg(target_arch = "mips")] |
c34b1796 | 42 | pub const unwinder_private_data_size: usize = 2; |
1a4d82fc | 43 | |
9e0c209e SL |
44 | #[cfg(target_arch = "mips64")] |
45 | pub const unwinder_private_data_size: usize = 2; | |
46 | ||
7453a54e | 47 | #[cfg(any(target_arch = "powerpc", target_arch = "powerpc64"))] |
c34b1796 | 48 | pub const unwinder_private_data_size: usize = 2; |
85aaf69f | 49 | |
9e0c209e SL |
50 | #[cfg(target_arch = "s390x")] |
51 | pub const unwinder_private_data_size: usize = 2; | |
52 | ||
32a655c1 SL |
53 | #[cfg(target_arch = "sparc64")] |
54 | pub const unwinder_private_data_size: usize = 2; | |
55 | ||
c30ab7b3 | 56 | #[cfg(target_os = "emscripten")] |
7453a54e SL |
57 | pub const unwinder_private_data_size: usize = 20; |
58 | ||
416331ca XL |
59 | #[cfg(all(target_arch = "hexagon", target_os = "linux"))] |
60 | pub const unwinder_private_data_size: usize = 35; | |
61 | ||
1a4d82fc JJ |
62 | #[repr(C)] |
63 | pub struct _Unwind_Exception { | |
64 | pub exception_class: _Unwind_Exception_Class, | |
65 | pub exception_cleanup: _Unwind_Exception_Cleanup_Fn, | |
66 | pub private: [_Unwind_Word; unwinder_private_data_size], | |
67 | } | |
68 | ||
69 | pub enum _Unwind_Context {} | |
70 | ||
3157f602 XL |
71 | pub type _Unwind_Exception_Cleanup_Fn = extern "C" fn(unwind_code: _Unwind_Reason_Code, |
72 | exception: *mut _Unwind_Exception); | |
e1599b0c | 73 | #[cfg_attr(all(feature = "llvm-libunwind", |
416331ca XL |
74 | any(target_os = "fuchsia", target_os = "linux")), |
75 | link(name = "unwind", kind = "static"))] | |
3157f602 | 76 | extern "C" { |
83c7162d | 77 | #[unwind(allowed)] |
5bcae85e | 78 | pub fn _Unwind_Resume(exception: *mut _Unwind_Exception) -> !; |
1a4d82fc | 79 | pub fn _Unwind_DeleteException(exception: *mut _Unwind_Exception); |
5bcae85e SL |
80 | pub fn _Unwind_GetLanguageSpecificData(ctx: *mut _Unwind_Context) -> *mut c_void; |
81 | pub fn _Unwind_GetRegionStart(ctx: *mut _Unwind_Context) -> _Unwind_Ptr; | |
82 | pub fn _Unwind_GetTextRelBase(ctx: *mut _Unwind_Context) -> _Unwind_Ptr; | |
83 | pub fn _Unwind_GetDataRelBase(ctx: *mut _Unwind_Context) -> _Unwind_Ptr; | |
84 | } | |
92a42be0 | 85 | |
dc9dc135 | 86 | cfg_if::cfg_if! { |
94b46f34 | 87 | if #[cfg(all(any(target_os = "ios", target_os = "netbsd", not(target_arch = "arm"))))] { |
5bcae85e SL |
88 | // Not ARM EHABI |
89 | #[repr(C)] | |
90 | #[derive(Copy, Clone, PartialEq)] | |
91 | pub enum _Unwind_Action { | |
92 | _UA_SEARCH_PHASE = 1, | |
93 | _UA_CLEANUP_PHASE = 2, | |
94 | _UA_HANDLER_FRAME = 4, | |
95 | _UA_FORCE_UNWIND = 8, | |
96 | _UA_END_OF_STACK = 16, | |
97 | } | |
9fa01778 | 98 | pub use _Unwind_Action::*; |
a7813a04 | 99 | |
e1599b0c | 100 | #[cfg_attr(all(feature = "llvm-libunwind", |
416331ca XL |
101 | any(target_os = "fuchsia", target_os = "linux")), |
102 | link(name = "unwind", kind = "static"))] | |
5bcae85e SL |
103 | extern "C" { |
104 | pub fn _Unwind_GetGR(ctx: *mut _Unwind_Context, reg_index: c_int) -> _Unwind_Word; | |
105 | pub fn _Unwind_SetGR(ctx: *mut _Unwind_Context, reg_index: c_int, value: _Unwind_Word); | |
106 | pub fn _Unwind_GetIP(ctx: *mut _Unwind_Context) -> _Unwind_Word; | |
107 | pub fn _Unwind_SetIP(ctx: *mut _Unwind_Context, value: _Unwind_Word); | |
108 | pub fn _Unwind_GetIPInfo(ctx: *mut _Unwind_Context, ip_before_insn: *mut c_int) | |
109 | -> _Unwind_Word; | |
110 | pub fn _Unwind_FindEnclosingFunction(pc: *mut c_void) -> *mut c_void; | |
111 | } | |
1a4d82fc | 112 | |
5bcae85e SL |
113 | } else { |
114 | // ARM EHABI | |
115 | #[repr(C)] | |
116 | #[derive(Copy, Clone, PartialEq)] | |
117 | pub enum _Unwind_State { | |
118 | _US_VIRTUAL_UNWIND_FRAME = 0, | |
119 | _US_UNWIND_FRAME_STARTING = 1, | |
120 | _US_UNWIND_FRAME_RESUME = 2, | |
121 | _US_ACTION_MASK = 3, | |
122 | _US_FORCE_UNWIND = 8, | |
123 | _US_END_OF_STACK = 16, | |
124 | } | |
9fa01778 | 125 | pub use _Unwind_State::*; |
a7813a04 | 126 | |
a7813a04 XL |
127 | #[repr(C)] |
128 | enum _Unwind_VRS_Result { | |
129 | _UVRSR_OK = 0, | |
130 | _UVRSR_NOT_IMPLEMENTED = 1, | |
131 | _UVRSR_FAILED = 2, | |
132 | } | |
133 | #[repr(C)] | |
134 | enum _Unwind_VRS_RegClass { | |
135 | _UVRSC_CORE = 0, | |
136 | _UVRSC_VFP = 1, | |
137 | _UVRSC_FPA = 2, | |
138 | _UVRSC_WMMXD = 3, | |
139 | _UVRSC_WMMXC = 4, | |
140 | } | |
9fa01778 | 141 | use _Unwind_VRS_RegClass::*; |
a7813a04 XL |
142 | #[repr(C)] |
143 | enum _Unwind_VRS_DataRepresentation { | |
144 | _UVRSD_UINT32 = 0, | |
145 | _UVRSD_VFPX = 1, | |
146 | _UVRSD_FPAX = 2, | |
147 | _UVRSD_UINT64 = 3, | |
148 | _UVRSD_FLOAT = 4, | |
149 | _UVRSD_DOUBLE = 5, | |
150 | } | |
9fa01778 | 151 | use _Unwind_VRS_DataRepresentation::*; |
5bcae85e SL |
152 | |
153 | pub const UNWIND_POINTER_REG: c_int = 12; | |
154 | pub const UNWIND_IP_REG: c_int = 15; | |
a7813a04 | 155 | |
e1599b0c | 156 | #[cfg_attr(all(feature = "llvm-libunwind", |
416331ca XL |
157 | any(target_os = "fuchsia", target_os = "linux")), |
158 | link(name = "unwind", kind = "static"))] | |
3157f602 | 159 | extern "C" { |
a7813a04 | 160 | fn _Unwind_VRS_Get(ctx: *mut _Unwind_Context, |
5bcae85e SL |
161 | regclass: _Unwind_VRS_RegClass, |
162 | regno: _Unwind_Word, | |
a7813a04 | 163 | repr: _Unwind_VRS_DataRepresentation, |
5bcae85e SL |
164 | data: *mut c_void) |
165 | -> _Unwind_VRS_Result; | |
166 | ||
167 | fn _Unwind_VRS_Set(ctx: *mut _Unwind_Context, | |
168 | regclass: _Unwind_VRS_RegClass, | |
169 | regno: _Unwind_Word, | |
170 | repr: _Unwind_VRS_DataRepresentation, | |
171 | data: *mut c_void) | |
3157f602 | 172 | -> _Unwind_VRS_Result; |
a7813a04 XL |
173 | } |
174 | ||
5bcae85e SL |
175 | // On Android or ARM/Linux, these are implemented as macros: |
176 | ||
177 | pub unsafe fn _Unwind_GetGR(ctx: *mut _Unwind_Context, reg_index: c_int) -> _Unwind_Word { | |
178 | let mut val: _Unwind_Word = 0; | |
179 | _Unwind_VRS_Get(ctx, _UVRSC_CORE, reg_index as _Unwind_Word, _UVRSD_UINT32, | |
180 | &mut val as *mut _ as *mut c_void); | |
181 | val | |
182 | } | |
183 | ||
184 | pub unsafe fn _Unwind_SetGR(ctx: *mut _Unwind_Context, reg_index: c_int, value: _Unwind_Word) { | |
185 | let mut value = value; | |
186 | _Unwind_VRS_Set(ctx, _UVRSC_CORE, reg_index as _Unwind_Word, _UVRSD_UINT32, | |
187 | &mut value as *mut _ as *mut c_void); | |
188 | } | |
189 | ||
190 | pub unsafe fn _Unwind_GetIP(ctx: *mut _Unwind_Context) | |
191 | -> _Unwind_Word { | |
192 | let val = _Unwind_GetGR(ctx, UNWIND_IP_REG); | |
193 | (val & !1) as _Unwind_Word | |
194 | } | |
a7813a04 | 195 | |
5bcae85e SL |
196 | pub unsafe fn _Unwind_SetIP(ctx: *mut _Unwind_Context, |
197 | value: _Unwind_Word) { | |
198 | // Propagate thumb bit to instruction pointer | |
199 | let thumb_state = _Unwind_GetGR(ctx, UNWIND_IP_REG) & 1; | |
200 | let value = value | thumb_state; | |
201 | _Unwind_SetGR(ctx, UNWIND_IP_REG, value); | |
202 | } | |
203 | ||
204 | pub unsafe fn _Unwind_GetIPInfo(ctx: *mut _Unwind_Context, | |
205 | ip_before_insn: *mut c_int) | |
206 | -> _Unwind_Word { | |
207 | *ip_before_insn = 0; | |
208 | _Unwind_GetIP(ctx) | |
209 | } | |
210 | ||
211 | // This function also doesn't exist on Android or ARM/Linux, so make it a no-op | |
212 | pub unsafe fn _Unwind_FindEnclosingFunction(pc: *mut c_void) -> *mut c_void { | |
213 | pc | |
214 | } | |
a7813a04 | 215 | } |
dc9dc135 | 216 | } // cfg_if! |
a7813a04 | 217 | |
dc9dc135 | 218 | cfg_if::cfg_if! { |
5bcae85e SL |
219 | if #[cfg(not(all(target_os = "ios", target_arch = "arm")))] { |
220 | // Not 32-bit iOS | |
e1599b0c | 221 | #[cfg_attr(all(feature = "llvm-libunwind", |
416331ca XL |
222 | any(target_os = "fuchsia", target_os = "linux")), |
223 | link(name = "unwind", kind = "static"))] | |
5bcae85e | 224 | extern "C" { |
83c7162d | 225 | #[unwind(allowed)] |
5bcae85e SL |
226 | pub fn _Unwind_RaiseException(exception: *mut _Unwind_Exception) -> _Unwind_Reason_Code; |
227 | pub fn _Unwind_Backtrace(trace: _Unwind_Trace_Fn, | |
228 | trace_argument: *mut c_void) | |
229 | -> _Unwind_Reason_Code; | |
230 | } | |
231 | } else { | |
232 | // 32-bit iOS uses SjLj and does not provide _Unwind_Backtrace() | |
e1599b0c | 233 | #[cfg_attr(all(feature = "llvm-libunwind", |
416331ca XL |
234 | any(target_os = "fuchsia", target_os = "linux")), |
235 | link(name = "unwind", kind = "static"))] | |
5bcae85e | 236 | extern "C" { |
83c7162d | 237 | #[unwind(allowed)] |
5bcae85e SL |
238 | pub fn _Unwind_SjLj_RaiseException(e: *mut _Unwind_Exception) -> _Unwind_Reason_Code; |
239 | } | |
240 | ||
241 | #[inline] | |
242 | pub unsafe fn _Unwind_RaiseException(exc: *mut _Unwind_Exception) -> _Unwind_Reason_Code { | |
243 | _Unwind_SjLj_RaiseException(exc) | |
244 | } | |
a7813a04 | 245 | } |
5bcae85e | 246 | } // cfg_if! |
e74abb32 XL |
247 | |
248 | cfg_if::cfg_if! { | |
249 | if #[cfg(all(windows, target_arch = "x86_64", target_env = "gnu"))] { | |
250 | // We declare these as opaque types. This is fine since you just need to | |
251 | // pass them to _GCC_specific_handler and forget about them. | |
252 | pub enum EXCEPTION_RECORD {} | |
253 | pub type LPVOID = *mut c_void; | |
254 | pub enum CONTEXT {} | |
255 | pub enum DISPATCHER_CONTEXT {} | |
256 | pub type EXCEPTION_DISPOSITION = c_int; | |
257 | type PersonalityFn = unsafe extern "C" fn(version: c_int, | |
258 | actions: _Unwind_Action, | |
259 | exception_class: _Unwind_Exception_Class, | |
260 | exception_object: *mut _Unwind_Exception, | |
261 | context: *mut _Unwind_Context) | |
262 | -> _Unwind_Reason_Code; | |
263 | ||
264 | extern "C" { | |
265 | pub fn _GCC_specific_handler(exceptionRecord: *mut EXCEPTION_RECORD, | |
266 | establisherFrame: LPVOID, | |
267 | contextRecord: *mut CONTEXT, | |
268 | dispatcherContext: *mut DISPATCHER_CONTEXT, | |
269 | personality: PersonalityFn) | |
270 | -> EXCEPTION_DISPOSITION; | |
271 | } | |
272 | } | |
273 | } // cfg_if! |