(index<- ) ./libstd/rt/libunwind.rs
git branch: * master 5200215 auto merge of #14035 : alexcrichton/rust/experimental, r=huonw
modified: Wed Apr 9 17:27:02 2014
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.
4 //
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.
10
11 //! Unwind library interface
12
13 #![allow(non_camel_case_types)]
14 #![allow(dead_code)] // these are just bindings
15
16 use libc;
17
18 #[cfg(not(target_arch = "arm"))]
19 #[repr(C)]
20 pub enum _Unwind_Action {
21 _UA_SEARCH_PHASE = 1,
22 _UA_CLEANUP_PHASE = 2,
23 _UA_HANDLER_FRAME = 4,
24 _UA_FORCE_UNWIND = 8,
25 _UA_END_OF_STACK = 16,
26 }
27
28 #[cfg(target_arch = "arm")]
29 #[repr(C)]
30 pub enum _Unwind_State {
31 _US_VIRTUAL_UNWIND_FRAME = 0,
32 _US_UNWIND_FRAME_STARTING = 1,
33 _US_UNWIND_FRAME_RESUME = 2,
34 _US_ACTION_MASK = 3,
35 _US_FORCE_UNWIND = 8,
36 _US_END_OF_STACK = 16
37 }
38
39 #[repr(C)]
40 pub enum _Unwind_Reason_Code {
41 _URC_NO_REASON = 0,
42 _URC_FOREIGN_EXCEPTION_CAUGHT = 1,
43 _URC_FATAL_PHASE2_ERROR = 2,
44 _URC_FATAL_PHASE1_ERROR = 3,
45 _URC_NORMAL_STOP = 4,
46 _URC_END_OF_STACK = 5,
47 _URC_HANDLER_FOUND = 6,
48 _URC_INSTALL_CONTEXT = 7,
49 _URC_CONTINUE_UNWIND = 8,
50 _URC_FAILURE = 9, // used only by ARM EABI
51 }
52
53 pub type _Unwind_Exception_Class = u64;
54
55 pub type _Unwind_Word = libc::uintptr_t;
56
57 #[cfg(target_arch = "x86")]
58 pub static unwinder_private_data_size: int = 5;
59
60 #[cfg(target_arch = "x86_64")]
61 pub static unwinder_private_data_size: int = 2;
62
63 #[cfg(target_arch = "arm")]
64 pub static unwinder_private_data_size: int = 20;
65
66 #[cfg(target_arch = "mips")]
67 pub static unwinder_private_data_size: int = 2;
68
69 pub struct _Unwind_Exception {
70 pub exception_class: _Unwind_Exception_Class,
71 pub exception_cleanup: _Unwind_Exception_Cleanup_Fn,
72 pub private: [_Unwind_Word, ..unwinder_private_data_size],
73 }
74
75 pub enum _Unwind_Context {}
76
77 pub type _Unwind_Exception_Cleanup_Fn =
78 extern "C" fn(unwind_code: _Unwind_Reason_Code,
79 exception: *_Unwind_Exception);
80
81 pub type _Unwind_Trace_Fn =
82 extern "C" fn(ctx: *_Unwind_Context,
83 arg: *libc::c_void) -> _Unwind_Reason_Code;
84
85 #[cfg(target_os = "linux")]
86 #[cfg(target_os = "freebsd")]
87 #[cfg(target_os = "win32")]
88 #[link(name = "gcc_s")]
89 extern {}
90
91 #[cfg(target_os = "android")]
92 #[link(name = "gcc")]
93 extern {}
94
95 extern "C" {
96 pub fn _Unwind_RaiseException(exception: *_Unwind_Exception)
97 -> _Unwind_Reason_Code;
98 pub fn _Unwind_DeleteException(exception: *_Unwind_Exception);
99 pub fn _Unwind_Backtrace(trace: _Unwind_Trace_Fn,
100 trace_argument: *libc::c_void)
101 -> _Unwind_Reason_Code;
102
103 #[cfg(not(target_os = "android"),
104 not(target_os = "linux", target_arch = "arm"))]
105 pub fn _Unwind_GetIP(ctx: *_Unwind_Context) -> libc::uintptr_t;
106 #[cfg(not(target_os = "android"),
107 not(target_os = "linux", target_arch = "arm"))]
108 pub fn _Unwind_FindEnclosingFunction(pc: *libc::c_void) -> *libc::c_void;
109 }
110
111 // On android, the function _Unwind_GetIP is a macro, and this is the expansion
112 // of the macro. This is all copy/pasted directly from the header file with the
113 // definition of _Unwind_GetIP.
114 #[cfg(target_os = "android")]
115 #[cfg(target_os = "linux", target_arch = "arm")]
116 pub unsafe fn _Unwind_GetIP(ctx: *_Unwind_Context) -> libc::uintptr_t {
117 #[repr(C)]
118 enum _Unwind_VRS_Result {
119 _UVRSR_OK = 0,
120 _UVRSR_NOT_IMPLEMENTED = 1,
121 _UVRSR_FAILED = 2,
122 }
123 #[repr(C)]
124 enum _Unwind_VRS_RegClass {
125 _UVRSC_CORE = 0,
126 _UVRSC_VFP = 1,
127 _UVRSC_FPA = 2,
128 _UVRSC_WMMXD = 3,
129 _UVRSC_WMMXC = 4,
130 }
131 #[repr(C)]
132 enum _Unwind_VRS_DataRepresentation {
133 _UVRSD_UINT32 = 0,
134 _UVRSD_VFPX = 1,
135 _UVRSD_FPAX = 2,
136 _UVRSD_UINT64 = 3,
137 _UVRSD_FLOAT = 4,
138 _UVRSD_DOUBLE = 5,
139 }
140
141 type _Unwind_Word = libc::c_uint;
142 extern {
143 fn _Unwind_VRS_Get(ctx: *_Unwind_Context,
144 klass: _Unwind_VRS_RegClass,
145 word: _Unwind_Word,
146 repr: _Unwind_VRS_DataRepresentation,
147 data: *mut libc::c_void) -> _Unwind_VRS_Result;
148 }
149
150 let mut val: _Unwind_Word = 0;
151 let ptr = &mut val as *mut _Unwind_Word;
152 let _ = _Unwind_VRS_Get(ctx, _UVRSC_CORE, 15, _UVRSD_UINT32,
153 ptr as *mut libc::c_void);
154 (val & !1) as libc::uintptr_t
155 }
156
157 // This function also doesn't exist on android or arm/linux, so make it a no-op
158 #[cfg(target_os = "android")]
159 #[cfg(target_os = "linux", target_arch = "arm")]
160 pub unsafe fn _Unwind_FindEnclosingFunction(pc: *libc::c_void) -> *libc::c_void {
161 pc
162 }
libstd/rt/libunwind.rs:39:11-39:11 -enum- definition:
pub enum _Unwind_Reason_Code {
_URC_NO_REASON = 0,
_URC_FOREIGN_EXCEPTION_CAUGHT = 1,
references:- 996: pub fn _Unwind_RaiseException(exception: *_Unwind_Exception)
97: -> _Unwind_Reason_Code;
98: pub fn _Unwind_DeleteException(exception: *_Unwind_Exception);
libstd/rt/backtrace.rs:
281: extern fn trace_fn(ctx: *uw::_Unwind_Context,
282: arg: *libc::c_void) -> uw::_Unwind_Reason_Code {
283: let cx: &mut Context = unsafe { cast::transmute(arg) };
libstd/rt/unwind.rs:
222: context: *uw::_Unwind_Context
223: ) -> uw::_Unwind_Reason_Code
224: {
--
237: context: *uw::_Unwind_Context
238: ) -> uw::_Unwind_Reason_Code
239: {
libstd/rt/libunwind.rs:
100: trace_argument: *libc::c_void)
101: -> _Unwind_Reason_Code;
libstd/rt/libunwind.rs:68:1-68:1 -struct- definition:
pub struct _Unwind_Exception {
pub exception_class: _Unwind_Exception_Class,
pub exception_cleanup: _Unwind_Exception_Cleanup_Fn,
references:- 1097: -> _Unwind_Reason_Code;
98: pub fn _Unwind_DeleteException(exception: *_Unwind_Exception);
99: pub fn _Unwind_Backtrace(trace: _Unwind_Trace_Fn,
libstd/rt/unwind.rs:
143: unsafe {
144: let exception = box uw::_Unwind_Exception {
145: exception_class: rust_exception_class(),
--
156: unsafe {
157: let _: Box<uw::_Unwind_Exception> =
158: cast::transmute(exception);
--
235: exception_class: uw::_Unwind_Exception_Class,
236: ue_header: *uw::_Unwind_Exception,
237: context: *uw::_Unwind_Context
libstd/rt/libunwind.rs:
78: extern "C" fn(unwind_code: _Unwind_Reason_Code,
79: exception: *_Unwind_Exception);
libstd/rt/libunwind.rs:52:1-52:1 -NK_AS_STR_TODO- definition:
pub type _Unwind_Exception_Class = u64;
pub type _Unwind_Word = libc::uintptr_t;
pub static unwinder_private_data_size: int = 5;
references:- 5libstd/rt/unwind.rs:
174: // determine whether the exception was thrown by their own runtime.
175: fn rust_exception_class() -> uw::_Unwind_Exception_Class {
176: // M O Z \0 R U S T -- vendor, language
--
219: actions: uw::_Unwind_Action,
220: exception_class: uw::_Unwind_Exception_Class,
221: ue_header: *uw::_Unwind_Exception,
--
234: actions: uw::_Unwind_Action,
235: exception_class: uw::_Unwind_Exception_Class,
236: ue_header: *uw::_Unwind_Exception,
libstd/rt/libunwind.rs:
69: pub struct _Unwind_Exception {
70: pub exception_class: _Unwind_Exception_Class,
71: pub exception_cleanup: _Unwind_Exception_Cleanup_Fn,
libstd/rt/libunwind.rs:19:11-19:11 -enum- definition:
pub enum _Unwind_Action {
_UA_SEARCH_PHASE = 1,
_UA_CLEANUP_PHASE = 2,
references:- 3libstd/rt/unwind.rs:
233: version: c_int,
234: actions: uw::_Unwind_Action,
235: exception_class: uw::_Unwind_Exception_Class,
libstd/rt/libunwind.rs:74:1-74:1 -enum- definition:
pub enum _Unwind_Context {}
pub type _Unwind_Exception_Cleanup_Fn =
extern "C" fn(unwind_code: _Unwind_Reason_Code,
references:- 6104: not(target_os = "linux", target_arch = "arm"))]
105: pub fn _Unwind_GetIP(ctx: *_Unwind_Context) -> libc::uintptr_t;
106: #[cfg(not(target_os = "android"),
libstd/rt/backtrace.rs:
281: extern fn trace_fn(ctx: *uw::_Unwind_Context,
282: arg: *libc::c_void) -> uw::_Unwind_Reason_Code {
libstd/rt/unwind.rs:
221: ue_header: *uw::_Unwind_Exception,
222: context: *uw::_Unwind_Context
223: ) -> uw::_Unwind_Reason_Code
--
236: ue_header: *uw::_Unwind_Exception,
237: context: *uw::_Unwind_Context
238: ) -> uw::_Unwind_Reason_Code