1 // Copyright 2014 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.
11 //! Unwind library interface
13 #[allow(non_camel_case_types)];
14 #[allow(dead_code)]; // these are just bindings
18 #[cfg(not(target_arch = "arm"))]
20 pub enum _Unwind_Action
23 _UA_CLEANUP_PHASE = 2,
24 _UA_HANDLER_FRAME = 4,
26 _UA_END_OF_STACK = 16,
29 #[cfg(target_arch = "arm")]
31 pub enum _Unwind_State
33 _US_VIRTUAL_UNWIND_FRAME = 0,
34 _US_UNWIND_FRAME_STARTING = 1,
35 _US_UNWIND_FRAME_RESUME = 2,
42 pub enum _Unwind_Reason_Code {
44 _URC_FOREIGN_EXCEPTION_CAUGHT = 1,
45 _URC_FATAL_PHASE2_ERROR = 2,
46 _URC_FATAL_PHASE1_ERROR = 3,
48 _URC_END_OF_STACK = 5,
49 _URC_HANDLER_FOUND = 6,
50 _URC_INSTALL_CONTEXT = 7,
51 _URC_CONTINUE_UNWIND = 8,
52 _URC_FAILURE = 9, // used only by ARM EABI
55 pub type _Unwind_Exception_Class = u64;
57 pub type _Unwind_Word = libc::uintptr_t;
59 #[cfg(target_arch = "x86")]
60 pub static unwinder_private_data_size: int = 5;
62 #[cfg(target_arch = "x86_64")]
63 pub static unwinder_private_data_size: int = 2;
65 #[cfg(target_arch = "arm")]
66 pub static unwinder_private_data_size: int = 20;
68 #[cfg(target_arch = "mips")]
69 pub static unwinder_private_data_size: int = 2;
71 pub struct _Unwind_Exception {
72 exception_class: _Unwind_Exception_Class,
73 exception_cleanup: _Unwind_Exception_Cleanup_Fn,
74 private: [_Unwind_Word, ..unwinder_private_data_size],
77 pub enum _Unwind_Context {}
79 pub type _Unwind_Exception_Cleanup_Fn =
80 extern "C" fn(unwind_code: _Unwind_Reason_Code,
81 exception: *_Unwind_Exception);
83 pub type _Unwind_Trace_Fn =
84 extern "C" fn(ctx: *_Unwind_Context,
85 arg: *libc::c_void) -> _Unwind_Reason_Code;
87 #[cfg(target_os = "linux")]
88 #[cfg(target_os = "freebsd")]
89 #[cfg(target_os = "win32")]
90 #[link(name = "gcc_s")]
93 #[cfg(target_os = "android")]
98 pub fn _Unwind_RaiseException(exception: *_Unwind_Exception)
99 -> _Unwind_Reason_Code;
100 pub fn _Unwind_DeleteException(exception: *_Unwind_Exception);
101 pub fn _Unwind_Backtrace(trace: _Unwind_Trace_Fn,
102 trace_argument: *libc::c_void)
103 -> _Unwind_Reason_Code;
105 #[cfg(not(target_os = "android"),
106 not(target_os = "linux", target_arch = "arm"))]
107 pub fn _Unwind_GetIP(ctx: *_Unwind_Context) -> libc::uintptr_t;
108 #[cfg(not(target_os = "android"),
109 not(target_os = "linux", target_arch = "arm"))]
110 pub fn _Unwind_FindEnclosingFunction(pc: *libc::c_void) -> *libc::c_void;
113 // On android, the function _Unwind_GetIP is a macro, and this is the expansion
114 // of the macro. This is all copy/pasted directly from the header file with the
115 // definition of _Unwind_GetIP.
116 #[cfg(target_os = "android")]
117 #[cfg(target_os = "linux", target_arch = "arm")]
118 pub unsafe fn _Unwind_GetIP(ctx: *_Unwind_Context) -> libc::uintptr_t {
120 enum _Unwind_VRS_Result {
122 _UVRSR_NOT_IMPLEMENTED = 1,
126 enum _Unwind_VRS_RegClass {
134 enum _Unwind_VRS_DataRepresentation {
143 type _Unwind_Word = libc::c_uint;
145 fn _Unwind_VRS_Get(ctx: *_Unwind_Context,
146 klass: _Unwind_VRS_RegClass,
148 repr: _Unwind_VRS_DataRepresentation,
149 data: *mut libc::c_void) -> _Unwind_VRS_Result;
152 let mut val: _Unwind_Word = 0;
153 let ptr = &mut val as *mut _Unwind_Word;
154 let _ = _Unwind_VRS_Get(ctx, _UVRSC_CORE, 15, _UVRSD_UINT32,
155 ptr as *mut libc::c_void);
156 (val & !1) as libc::uintptr_t
159 // This function also doesn't exist on android or arm/linux, so make it a no-op
160 #[cfg(target_os = "android")]
161 #[cfg(target_os = "linux", target_arch = "arm")]
162 pub unsafe fn _Unwind_FindEnclosingFunction(pc: *libc::c_void) -> *libc::c_void {