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.
14 ( $( if #[cfg( $meta:meta )] { $($it1:item)* } else { $($it2:item)* } )* ) =>
15 ( $( $( #[cfg($meta)] $it1)* $( #[cfg(not($meta))] $it2)* )* )
18 use libc::{c_int, c_void, uintptr_t};
21 #[derive(Copy, Clone, PartialEq)]
22 pub enum _Unwind_Reason_Code {
24 _URC_FOREIGN_EXCEPTION_CAUGHT = 1,
25 _URC_FATAL_PHASE2_ERROR = 2,
26 _URC_FATAL_PHASE1_ERROR = 3,
28 _URC_END_OF_STACK = 5,
29 _URC_HANDLER_FOUND = 6,
30 _URC_INSTALL_CONTEXT = 7,
31 _URC_CONTINUE_UNWIND = 8,
32 _URC_FAILURE = 9, // used only by ARM EHABI
34 pub use self::_Unwind_Reason_Code::*;
36 pub type _Unwind_Exception_Class = u64;
37 pub type _Unwind_Word = uintptr_t;
38 pub type _Unwind_Ptr = uintptr_t;
39 pub type _Unwind_Trace_Fn = extern "C" fn(ctx: *mut _Unwind_Context, arg: *mut c_void)
40 -> _Unwind_Reason_Code;
41 #[cfg(target_arch = "x86")]
42 pub const unwinder_private_data_size: usize = 5;
44 #[cfg(target_arch = "x86_64")]
45 pub const unwinder_private_data_size: usize = 6;
47 #[cfg(all(target_arch = "arm", not(target_os = "ios")))]
48 pub const unwinder_private_data_size: usize = 20;
50 #[cfg(all(target_arch = "arm", target_os = "ios"))]
51 pub const unwinder_private_data_size: usize = 5;
53 #[cfg(target_arch = "aarch64")]
54 pub const unwinder_private_data_size: usize = 2;
56 #[cfg(target_arch = "mips")]
57 pub const unwinder_private_data_size: usize = 2;
59 #[cfg(target_arch = "mips64")]
60 pub const unwinder_private_data_size: usize = 2;
62 #[cfg(any(target_arch = "powerpc", target_arch = "powerpc64"))]
63 pub const unwinder_private_data_size: usize = 2;
65 #[cfg(target_arch = "s390x")]
66 pub const unwinder_private_data_size: usize = 2;
68 #[cfg(target_os = "emscripten")]
69 pub const unwinder_private_data_size: usize = 20;
72 pub struct _Unwind_Exception {
73 pub exception_class: _Unwind_Exception_Class,
74 pub exception_cleanup: _Unwind_Exception_Cleanup_Fn,
75 pub private: [_Unwind_Word; unwinder_private_data_size],
78 pub enum _Unwind_Context {}
80 pub type _Unwind_Exception_Cleanup_Fn = extern "C" fn(unwind_code: _Unwind_Reason_Code,
81 exception: *mut _Unwind_Exception);
84 pub fn _Unwind_Resume(exception: *mut _Unwind_Exception) -> !;
85 pub fn _Unwind_DeleteException(exception: *mut _Unwind_Exception);
86 pub fn _Unwind_GetLanguageSpecificData(ctx: *mut _Unwind_Context) -> *mut c_void;
87 pub fn _Unwind_GetRegionStart(ctx: *mut _Unwind_Context) -> _Unwind_Ptr;
88 pub fn _Unwind_GetTextRelBase(ctx: *mut _Unwind_Context) -> _Unwind_Ptr;
89 pub fn _Unwind_GetDataRelBase(ctx: *mut _Unwind_Context) -> _Unwind_Ptr;
93 if #[cfg(not(any(all(target_os = "android", target_arch = "arm"),
94 all(target_os = "linux", target_arch = "arm"))))] {
97 #[derive(Copy, Clone, PartialEq)]
98 pub enum _Unwind_Action {
100 _UA_CLEANUP_PHASE = 2,
101 _UA_HANDLER_FRAME = 4,
102 _UA_FORCE_UNWIND = 8,
103 _UA_END_OF_STACK = 16,
105 pub use self::_Unwind_Action::*;
108 pub fn _Unwind_GetGR(ctx: *mut _Unwind_Context, reg_index: c_int) -> _Unwind_Word;
109 pub fn _Unwind_SetGR(ctx: *mut _Unwind_Context, reg_index: c_int, value: _Unwind_Word);
110 pub fn _Unwind_GetIP(ctx: *mut _Unwind_Context) -> _Unwind_Word;
111 pub fn _Unwind_SetIP(ctx: *mut _Unwind_Context, value: _Unwind_Word);
112 pub fn _Unwind_GetIPInfo(ctx: *mut _Unwind_Context, ip_before_insn: *mut c_int)
114 pub fn _Unwind_FindEnclosingFunction(pc: *mut c_void) -> *mut c_void;
120 #[derive(Copy, Clone, PartialEq)]
121 pub enum _Unwind_State {
122 _US_VIRTUAL_UNWIND_FRAME = 0,
123 _US_UNWIND_FRAME_STARTING = 1,
124 _US_UNWIND_FRAME_RESUME = 2,
126 _US_FORCE_UNWIND = 8,
127 _US_END_OF_STACK = 16,
129 pub use self::_Unwind_State::*;
132 enum _Unwind_VRS_Result {
134 _UVRSR_NOT_IMPLEMENTED = 1,
138 enum _Unwind_VRS_RegClass {
145 use self::_Unwind_VRS_RegClass::*;
147 enum _Unwind_VRS_DataRepresentation {
155 use self::_Unwind_VRS_DataRepresentation::*;
157 pub const UNWIND_POINTER_REG: c_int = 12;
158 pub const UNWIND_IP_REG: c_int = 15;
161 fn _Unwind_VRS_Get(ctx: *mut _Unwind_Context,
162 regclass: _Unwind_VRS_RegClass,
164 repr: _Unwind_VRS_DataRepresentation,
166 -> _Unwind_VRS_Result;
168 fn _Unwind_VRS_Set(ctx: *mut _Unwind_Context,
169 regclass: _Unwind_VRS_RegClass,
171 repr: _Unwind_VRS_DataRepresentation,
173 -> _Unwind_VRS_Result;
176 // On Android or ARM/Linux, these are implemented as macros:
178 pub unsafe fn _Unwind_GetGR(ctx: *mut _Unwind_Context, reg_index: c_int) -> _Unwind_Word {
179 let mut val: _Unwind_Word = 0;
180 _Unwind_VRS_Get(ctx, _UVRSC_CORE, reg_index as _Unwind_Word, _UVRSD_UINT32,
181 &mut val as *mut _ as *mut c_void);
185 pub unsafe fn _Unwind_SetGR(ctx: *mut _Unwind_Context, reg_index: c_int, value: _Unwind_Word) {
186 let mut value = value;
187 _Unwind_VRS_Set(ctx, _UVRSC_CORE, reg_index as _Unwind_Word, _UVRSD_UINT32,
188 &mut value as *mut _ as *mut c_void);
191 pub unsafe fn _Unwind_GetIP(ctx: *mut _Unwind_Context)
193 let val = _Unwind_GetGR(ctx, UNWIND_IP_REG);
194 (val & !1) as _Unwind_Word
197 pub unsafe fn _Unwind_SetIP(ctx: *mut _Unwind_Context,
198 value: _Unwind_Word) {
199 // Propagate thumb bit to instruction pointer
200 let thumb_state = _Unwind_GetGR(ctx, UNWIND_IP_REG) & 1;
201 let value = value | thumb_state;
202 _Unwind_SetGR(ctx, UNWIND_IP_REG, value);
205 pub unsafe fn _Unwind_GetIPInfo(ctx: *mut _Unwind_Context,
206 ip_before_insn: *mut c_int)
212 // This function also doesn't exist on Android or ARM/Linux, so make it a no-op
213 pub unsafe fn _Unwind_FindEnclosingFunction(pc: *mut c_void) -> *mut c_void {
218 if #[cfg(not(all(target_os = "ios", target_arch = "arm")))] {
222 pub fn _Unwind_RaiseException(exception: *mut _Unwind_Exception) -> _Unwind_Reason_Code;
223 pub fn _Unwind_Backtrace(trace: _Unwind_Trace_Fn,
224 trace_argument: *mut c_void)
225 -> _Unwind_Reason_Code;
228 // 32-bit iOS uses SjLj and does not provide _Unwind_Backtrace()
231 pub fn _Unwind_SjLj_RaiseException(e: *mut _Unwind_Exception) -> _Unwind_Reason_Code;
235 pub unsafe fn _Unwind_RaiseException(exc: *mut _Unwind_Exception) -> _Unwind_Reason_Code {
236 _Unwind_SjLj_RaiseException(exc)
241 #[cfg_attr(any(all(target_os = "linux", not(target_env = "musl")),
242 target_os = "freebsd",
243 target_os = "solaris",
245 all(target_os = "linux",
247 not(target_arch = "x86"),
248 not(target_arch = "x86_64"))),
249 link(name = "gcc_s"))]
250 #[cfg_attr(all(target_os = "linux",
252 any(target_arch = "x86", target_arch = "x86_64"),
254 link(name = "unwind", kind = "static"))]
255 #[cfg_attr(any(target_os = "android", target_os = "openbsd"),
257 #[cfg_attr(all(target_os = "netbsd", not(target_vendor = "rumprun")),
259 #[cfg_attr(all(target_os = "netbsd", target_vendor = "rumprun"),
260 link(name = "unwind"))]
261 #[cfg_attr(target_os = "dragonfly",
262 link(name = "gcc_pic"))]
263 #[cfg_attr(target_os = "bitrig",
264 link(name = "c++abi"))]
265 #[cfg_attr(all(target_os = "windows", target_env = "gnu"),
266 link(name = "gcc_eh"))]
267 #[cfg(not(cargobuild))]