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;
59 #[cfg(all(target_arch = "hexagon", target_os = "linux"))]
60 pub const unwinder_private_data_size
: usize = 35;
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
],
69 pub enum _Unwind_Context {}
71 pub type _Unwind_Exception_Cleanup_Fn
= extern "C" fn(unwind_code
: _Unwind_Reason_Code
,
72 exception
: *mut _Unwind_Exception
);
73 #[cfg_attr(all(feature = "llvm-libunwind",
74 any(target_os
= "fuchsia", target_os
= "linux")),
75 link(name
= "unwind", kind
= "static"))]
78 pub fn _Unwind_Resume(exception
: *mut _Unwind_Exception
) -> !;
79 pub fn _Unwind_DeleteException(exception
: *mut _Unwind_Exception
);
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
;
87 if #[cfg(all(any(target_os = "ios", target_os = "netbsd", not(target_arch = "arm"))))] {
90 #[derive(Copy, Clone, PartialEq)]
91 pub enum _Unwind_Action
{
93 _UA_CLEANUP_PHASE
= 2,
94 _UA_HANDLER_FRAME
= 4,
96 _UA_END_OF_STACK
= 16,
98 pub use _Unwind_Action
::*;
100 #[cfg_attr(all(feature = "llvm-libunwind",
101 any(target_os
= "fuchsia", target_os
= "linux")),
102 link(name
= "unwind", kind
= "static"))]
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
)
110 pub fn _Unwind_FindEnclosingFunction(pc
: *mut c_void
) -> *mut c_void
;
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,
122 _US_FORCE_UNWIND
= 8,
123 _US_END_OF_STACK
= 16,
125 pub use _Unwind_State
::*;
128 enum _Unwind_VRS_Result
{
130 _UVRSR_NOT_IMPLEMENTED
= 1,
134 enum _Unwind_VRS_RegClass
{
141 use _Unwind_VRS_RegClass
::*;
143 enum _Unwind_VRS_DataRepresentation
{
151 use _Unwind_VRS_DataRepresentation
::*;
153 pub const UNWIND_POINTER_REG
: c_int
= 12;
154 pub const UNWIND_IP_REG
: c_int
= 15;
156 #[cfg_attr(all(feature = "llvm-libunwind",
157 any(target_os
= "fuchsia", target_os
= "linux")),
158 link(name
= "unwind", kind
= "static"))]
160 fn _Unwind_VRS_Get(ctx
: *mut _Unwind_Context
,
161 regclass
: _Unwind_VRS_RegClass
,
163 repr
: _Unwind_VRS_DataRepresentation
,
165 -> _Unwind_VRS_Result
;
167 fn _Unwind_VRS_Set(ctx
: *mut _Unwind_Context
,
168 regclass
: _Unwind_VRS_RegClass
,
170 repr
: _Unwind_VRS_DataRepresentation
,
172 -> _Unwind_VRS_Result
;
175 // On Android or ARM/Linux, these are implemented as macros:
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
);
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
);
190 pub unsafe fn _Unwind_GetIP(ctx
: *mut _Unwind_Context
)
192 let val
= _Unwind_GetGR(ctx
, UNWIND_IP_REG
);
193 (val
& !1) as _Unwind_Word
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
);
204 pub unsafe fn _Unwind_GetIPInfo(ctx
: *mut _Unwind_Context
,
205 ip_before_insn
: *mut c_int
)
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
{
219 if #[cfg(not(all(target_os = "ios", target_arch = "arm")))] {
221 #[cfg_attr(all(feature = "llvm-libunwind",
222 any(target_os
= "fuchsia", target_os
= "linux")),
223 link(name
= "unwind", kind
= "static"))]
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
;
232 // 32-bit iOS uses SjLj and does not provide _Unwind_Backtrace()
233 #[cfg_attr(all(feature = "llvm-libunwind",
234 any(target_os
= "fuchsia", target_os
= "linux")),
235 link(name
= "unwind", kind
= "static"))]
238 pub fn _Unwind_SjLj_RaiseException(e
: *mut _Unwind_Exception
) -> _Unwind_Reason_Code
;
242 pub unsafe fn _Unwind_RaiseException(exc
: *mut _Unwind_Exception
) -> _Unwind_Reason_Code
{
243 _Unwind_SjLj_RaiseException(exc
)
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
;
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
;
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
;