]>
Commit | Line | Data |
---|---|---|
1a4d82fc JJ |
1 | // Copyright 2014-2015 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_upper_case_globals)] | |
14 | #![allow(non_camel_case_types)] | |
15 | #![allow(non_snake_case)] | |
16 | #![allow(dead_code)] // these are just bindings | |
17 | ||
18 | #[cfg(any(not(target_arch = "arm"), target_os = "ios"))] | |
19 | pub use self::_Unwind_Action::*; | |
20 | #[cfg(target_arch = "arm")] | |
21 | pub use self::_Unwind_State::*; | |
22 | pub use self::_Unwind_Reason_Code::*; | |
23 | ||
24 | use libc; | |
25 | ||
26 | #[cfg(any(not(target_arch = "arm"), target_os = "ios"))] | |
27 | #[repr(C)] | |
28 | #[derive(Copy)] | |
29 | pub enum _Unwind_Action { | |
30 | _UA_SEARCH_PHASE = 1, | |
31 | _UA_CLEANUP_PHASE = 2, | |
32 | _UA_HANDLER_FRAME = 4, | |
33 | _UA_FORCE_UNWIND = 8, | |
34 | _UA_END_OF_STACK = 16, | |
35 | } | |
36 | ||
37 | #[cfg(target_arch = "arm")] | |
38 | #[repr(C)] | |
39 | pub enum _Unwind_State { | |
40 | _US_VIRTUAL_UNWIND_FRAME = 0, | |
41 | _US_UNWIND_FRAME_STARTING = 1, | |
42 | _US_UNWIND_FRAME_RESUME = 2, | |
43 | _US_ACTION_MASK = 3, | |
44 | _US_FORCE_UNWIND = 8, | |
45 | _US_END_OF_STACK = 16 | |
46 | } | |
47 | ||
48 | #[repr(C)] | |
49 | pub enum _Unwind_Reason_Code { | |
50 | _URC_NO_REASON = 0, | |
51 | _URC_FOREIGN_EXCEPTION_CAUGHT = 1, | |
52 | _URC_FATAL_PHASE2_ERROR = 2, | |
53 | _URC_FATAL_PHASE1_ERROR = 3, | |
54 | _URC_NORMAL_STOP = 4, | |
55 | _URC_END_OF_STACK = 5, | |
56 | _URC_HANDLER_FOUND = 6, | |
57 | _URC_INSTALL_CONTEXT = 7, | |
58 | _URC_CONTINUE_UNWIND = 8, | |
59 | _URC_FAILURE = 9, // used only by ARM EABI | |
60 | } | |
61 | ||
62 | pub type _Unwind_Exception_Class = u64; | |
63 | ||
64 | pub type _Unwind_Word = libc::uintptr_t; | |
65 | ||
66 | #[cfg(target_arch = "x86")] | |
67 | pub const unwinder_private_data_size: uint = 5; | |
68 | ||
69 | #[cfg(target_arch = "x86_64")] | |
70 | pub const unwinder_private_data_size: uint = 6; | |
71 | ||
72 | #[cfg(all(target_arch = "arm", not(target_os = "ios")))] | |
73 | pub const unwinder_private_data_size: uint = 20; | |
74 | ||
75 | #[cfg(all(target_arch = "arm", target_os = "ios"))] | |
76 | pub const unwinder_private_data_size: uint = 5; | |
77 | ||
78 | #[cfg(target_arch = "aarch64")] | |
79 | pub const unwinder_private_data_size: uint = 2; | |
80 | ||
81 | #[cfg(any(target_arch = "mips", target_arch = "mipsel"))] | |
82 | pub const unwinder_private_data_size: uint = 2; | |
83 | ||
84 | #[repr(C)] | |
85 | pub struct _Unwind_Exception { | |
86 | pub exception_class: _Unwind_Exception_Class, | |
87 | pub exception_cleanup: _Unwind_Exception_Cleanup_Fn, | |
88 | pub private: [_Unwind_Word; unwinder_private_data_size], | |
89 | } | |
90 | ||
91 | pub enum _Unwind_Context {} | |
92 | ||
93 | pub type _Unwind_Exception_Cleanup_Fn = | |
94 | extern "C" fn(unwind_code: _Unwind_Reason_Code, | |
95 | exception: *mut _Unwind_Exception); | |
96 | ||
97 | #[cfg(any(target_os = "linux", target_os = "freebsd"))] | |
98 | #[link(name = "gcc_s")] | |
99 | extern {} | |
100 | ||
101 | #[cfg(target_os = "android")] | |
102 | #[link(name = "gcc")] | |
103 | extern {} | |
104 | ||
105 | #[cfg(target_os = "dragonfly")] | |
106 | #[link(name = "gcc_pic")] | |
107 | extern {} | |
108 | ||
109 | extern "C" { | |
110 | // iOS on armv7 uses SjLj exceptions and requires to link | |
111 | // against corresponding routine (..._SjLj_...) | |
112 | #[cfg(not(all(target_os = "ios", target_arch = "arm")))] | |
113 | pub fn _Unwind_RaiseException(exception: *mut _Unwind_Exception) | |
114 | -> _Unwind_Reason_Code; | |
115 | ||
116 | #[cfg(all(target_os = "ios", target_arch = "arm"))] | |
117 | fn _Unwind_SjLj_RaiseException(e: *mut _Unwind_Exception) | |
118 | -> _Unwind_Reason_Code; | |
119 | ||
120 | pub fn _Unwind_DeleteException(exception: *mut _Unwind_Exception); | |
121 | } | |
122 | ||
123 | // ... and now we just providing access to SjLj counterspart | |
124 | // through a standard name to hide those details from others | |
125 | // (see also comment above regarding _Unwind_RaiseException) | |
126 | #[cfg(all(target_os = "ios", target_arch = "arm"))] | |
127 | #[inline(always)] | |
128 | pub unsafe fn _Unwind_RaiseException(exc: *mut _Unwind_Exception) | |
129 | -> _Unwind_Reason_Code { | |
130 | _Unwind_SjLj_RaiseException(exc) | |
131 | } |