1 // Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
15 #[cfg(any(not(target_arch = "arm"), target_os = "ios"))]
16 pub use self::_Unwind_Action
::*;
17 #[cfg(target_arch = "arm")]
18 pub use self::_Unwind_State
::*;
19 pub use self::_Unwind_Reason_Code
::*;
21 #[cfg(any(not(target_arch = "arm"), target_os = "ios"))]
23 #[derive(Clone, Copy)]
24 pub enum _Unwind_Action
{
26 _UA_CLEANUP_PHASE
= 2,
27 _UA_HANDLER_FRAME
= 4,
29 _UA_END_OF_STACK
= 16,
32 #[cfg(target_arch = "arm")]
34 #[derive(Clone, Copy)]
35 pub enum _Unwind_State
{
36 _US_VIRTUAL_UNWIND_FRAME
= 0,
37 _US_UNWIND_FRAME_STARTING
= 1,
38 _US_UNWIND_FRAME_RESUME
= 2,
41 _US_END_OF_STACK
= 16,
45 pub enum _Unwind_Reason_Code
{
47 _URC_FOREIGN_EXCEPTION_CAUGHT
= 1,
48 _URC_FATAL_PHASE2_ERROR
= 2,
49 _URC_FATAL_PHASE1_ERROR
= 3,
51 _URC_END_OF_STACK
= 5,
52 _URC_HANDLER_FOUND
= 6,
53 _URC_INSTALL_CONTEXT
= 7,
54 _URC_CONTINUE_UNWIND
= 8,
55 _URC_FAILURE
= 9, // used only by ARM EABI
58 pub type _Unwind_Exception_Class
= u64;
60 pub type _Unwind_Word
= libc
::uintptr_t
;
62 pub type _Unwind_Trace_Fn
= extern "C" fn(ctx
: *mut _Unwind_Context
, arg
: *mut libc
::c_void
)
63 -> _Unwind_Reason_Code
;
65 #[cfg(target_arch = "x86")]
66 pub const unwinder_private_data_size
: usize = 5;
68 #[cfg(target_arch = "x86_64")]
69 pub const unwinder_private_data_size
: usize = 6;
71 #[cfg(all(target_arch = "arm", not(target_os = "ios")))]
72 pub const unwinder_private_data_size
: usize = 20;
74 #[cfg(all(target_arch = "arm", target_os = "ios"))]
75 pub const unwinder_private_data_size
: usize = 5;
77 #[cfg(target_arch = "aarch64")]
78 pub const unwinder_private_data_size
: usize = 2;
80 #[cfg(target_arch = "mips")]
81 pub const unwinder_private_data_size
: usize = 2;
83 #[cfg(any(target_arch = "powerpc", target_arch = "powerpc64"))]
84 pub const unwinder_private_data_size
: usize = 2;
86 #[cfg(target_arch = "asmjs")]
87 // FIXME: Copied from arm. Need to confirm.
88 pub const unwinder_private_data_size
: usize = 20;
91 pub struct _Unwind_Exception
{
92 pub exception_class
: _Unwind_Exception_Class
,
93 pub exception_cleanup
: _Unwind_Exception_Cleanup_Fn
,
94 pub private
: [_Unwind_Word
; unwinder_private_data_size
],
97 pub enum _Unwind_Context {}
99 pub type _Unwind_Exception_Cleanup_Fn
= extern "C" fn(unwind_code
: _Unwind_Reason_Code
,
100 exception
: *mut _Unwind_Exception
);
102 #[cfg_attr(any(all(target_os = "linux", not(target_env = "musl")),
103 target_os
= "freebsd",
104 target_os
= "solaris",
105 all(target_os
= "linux",
107 not(target_arch
= "x86"),
108 not(target_arch
= "x86_64"))),
109 link(name
= "gcc_s"))]
110 #[cfg_attr(all(target_os = "linux",
112 any(target_arch
= "x86", target_arch
= "x86_64"),
114 link(name
= "unwind", kind
= "static"))]
115 #[cfg_attr(any(target_os = "android", target_os = "openbsd"),
117 #[cfg_attr(all(target_os = "netbsd", not(target_vendor = "rumprun")),
119 #[cfg_attr(all(target_os = "netbsd", target_vendor = "rumprun"),
120 link(name
= "unwind"))]
121 #[cfg_attr(target_os = "dragonfly",
122 link(name
= "gcc_pic"))]
123 #[cfg_attr(target_os = "bitrig",
124 link(name
= "c++abi"))]
125 #[cfg_attr(all(target_os = "windows", target_env = "gnu"),
126 link(name
= "gcc_eh"))]
127 #[cfg(not(cargobuild))]
131 // iOS on armv7 uses SjLj exceptions and requires to link
132 // against corresponding routine (..._SjLj_...)
133 #[cfg(not(all(target_os = "ios", target_arch = "arm")))]
135 pub fn _Unwind_RaiseException(exception
: *mut _Unwind_Exception
) -> _Unwind_Reason_Code
;
137 #[cfg(all(target_os = "ios", target_arch = "arm"))]
139 fn _Unwind_SjLj_RaiseException(e
: *mut _Unwind_Exception
) -> _Unwind_Reason_Code
;
141 pub fn _Unwind_DeleteException(exception
: *mut _Unwind_Exception
);
144 pub fn _Unwind_Resume(exception
: *mut _Unwind_Exception
) -> !;
146 // No native _Unwind_Backtrace on iOS
147 #[cfg(not(all(target_os = "ios", target_arch = "arm")))]
148 pub fn _Unwind_Backtrace(trace
: _Unwind_Trace_Fn
,
149 trace_argument
: *mut libc
::c_void
)
150 -> _Unwind_Reason_Code
;
152 // available since GCC 4.2.0, should be fine for our purpose
153 #[cfg(all(not(all(target_os = "android", target_arch = "arm")),
154 not(all(target_os
= "linux", target_arch
= "arm"))))]
155 pub fn _Unwind_GetIPInfo(ctx
: *mut _Unwind_Context
,
156 ip_before_insn
: *mut libc
::c_int
)
159 #[cfg(all(not(target_os = "android"),
160 not(all(target_os
= "linux", target_arch
= "arm"))))]
161 pub fn _Unwind_FindEnclosingFunction(pc
: *mut libc
::c_void
) -> *mut libc
::c_void
;
164 // ... and now we just providing access to SjLj counterspart
165 // through a standard name to hide those details from others
166 // (see also comment above regarding _Unwind_RaiseException)
167 #[cfg(all(target_os = "ios", target_arch = "arm"))]
169 pub unsafe fn _Unwind_RaiseException(exc
: *mut _Unwind_Exception
) -> _Unwind_Reason_Code
{
170 _Unwind_SjLj_RaiseException(exc
)
173 // On android, the function _Unwind_GetIP is a macro, and this is the
174 // expansion of the macro. This is all copy/pasted directly from the
175 // header file with the definition of _Unwind_GetIP.
176 #[cfg(any(all(target_os = "android", target_arch = "arm"),
177 all(target_os
= "linux", target_arch
= "arm")))]
178 pub unsafe fn _Unwind_GetIP(ctx
: *mut _Unwind_Context
) -> libc
::uintptr_t
{
180 enum _Unwind_VRS_Result
{
182 _UVRSR_NOT_IMPLEMENTED
= 1,
186 enum _Unwind_VRS_RegClass
{
194 enum _Unwind_VRS_DataRepresentation
{
203 type _Unwind_Word
= libc
::c_uint
;
205 fn _Unwind_VRS_Get(ctx
: *mut _Unwind_Context
,
206 klass
: _Unwind_VRS_RegClass
,
208 repr
: _Unwind_VRS_DataRepresentation
,
209 data
: *mut libc
::c_void
)
210 -> _Unwind_VRS_Result
;
213 let mut val
: _Unwind_Word
= 0;
214 let ptr
= &mut val
as *mut _Unwind_Word
;
215 let _
= _Unwind_VRS_Get(ctx
,
216 _Unwind_VRS_RegClass
::_UVRSC_CORE
,
218 _Unwind_VRS_DataRepresentation
::_UVRSD_UINT32
,
219 ptr
as *mut libc
::c_void
);
220 (val
& !1) as libc
::uintptr_t
223 // This function doesn't exist on Android or ARM/Linux, so make it same
225 #[cfg(any(all(target_os = "android", target_arch = "arm"),
226 all(target_os
= "linux", target_arch
= "arm")))]
227 pub unsafe fn _Unwind_GetIPInfo(ctx
: *mut _Unwind_Context
,
228 ip_before_insn
: *mut libc
::c_int
)
234 // This function also doesn't exist on Android or ARM/Linux, so make it
236 #[cfg(any(target_os = "android",
237 all(target_os
= "linux", target_arch
= "arm")))]
238 pub unsafe fn _Unwind_FindEnclosingFunction(pc
: *mut libc
::c_void
) -> *mut libc
::c_void
{