]> git.lizzy.rs Git - rust.git/blob - src/libstd/sys/common/libunwind.rs
feb05c7b56008e7881947f4fc0889607bd3d0fe2
[rust.git] / src / libstd / sys / common / libunwind.rs
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, Clone)]
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 #[derive(Copy, Clone)]
40 pub enum _Unwind_State {
41     _US_VIRTUAL_UNWIND_FRAME = 0,
42     _US_UNWIND_FRAME_STARTING = 1,
43     _US_UNWIND_FRAME_RESUME = 2,
44     _US_ACTION_MASK = 3,
45     _US_FORCE_UNWIND = 8,
46     _US_END_OF_STACK = 16
47 }
48
49 #[repr(C)]
50 #[derive(Copy, Clone)]
51 pub enum _Unwind_Reason_Code {
52     _URC_NO_REASON = 0,
53     _URC_FOREIGN_EXCEPTION_CAUGHT = 1,
54     _URC_FATAL_PHASE2_ERROR = 2,
55     _URC_FATAL_PHASE1_ERROR = 3,
56     _URC_NORMAL_STOP = 4,
57     _URC_END_OF_STACK = 5,
58     _URC_HANDLER_FOUND = 6,
59     _URC_INSTALL_CONTEXT = 7,
60     _URC_CONTINUE_UNWIND = 8,
61     _URC_FAILURE = 9, // used only by ARM EABI
62 }
63
64 pub type _Unwind_Exception_Class = u64;
65
66 pub type _Unwind_Word = libc::uintptr_t;
67
68 #[cfg(target_arch = "x86")]
69 pub const unwinder_private_data_size: usize = 5;
70
71 #[cfg(target_arch = "x86_64")]
72 pub const unwinder_private_data_size: usize = 6;
73
74 #[cfg(all(target_arch = "arm", not(target_os = "ios")))]
75 pub const unwinder_private_data_size: usize = 20;
76
77 #[cfg(all(target_arch = "arm", target_os = "ios"))]
78 pub const unwinder_private_data_size: usize = 5;
79
80 #[cfg(target_arch = "aarch64")]
81 pub const unwinder_private_data_size: usize = 2;
82
83 #[cfg(any(target_arch = "mips", target_arch = "mipsel"))]
84 pub const unwinder_private_data_size: usize = 2;
85
86 #[cfg(target_arch = "powerpc")]
87 pub const unwinder_private_data_size: usize = 2;
88
89 #[repr(C)]
90 pub struct _Unwind_Exception {
91     pub exception_class: _Unwind_Exception_Class,
92     pub exception_cleanup: _Unwind_Exception_Cleanup_Fn,
93     pub private: [_Unwind_Word; unwinder_private_data_size],
94 }
95
96 pub enum _Unwind_Context {}
97
98 pub type _Unwind_Exception_Cleanup_Fn =
99         extern "C" fn(unwind_code: _Unwind_Reason_Code,
100                       exception: *mut _Unwind_Exception);
101
102 #[cfg_attr(any(all(target_os = "linux", not(target_env = "musl")),
103                target_os = "freebsd"),
104            link(name = "gcc_s"))]
105 #[cfg_attr(all(target_os = "linux", target_env = "musl", not(test)),
106            link(name = "unwind", kind = "static"))]
107 #[cfg_attr(any(target_os = "android", target_os = "openbsd"),
108            link(name = "gcc"))]
109 #[cfg_attr(all(target_os = "netbsd", not(target_vendor = "rumprun")),
110            link(name = "gcc"))]
111 #[cfg_attr(all(target_os = "netbsd", target_vendor = "rumprun"),
112            link(name = "unwind"))]
113 #[cfg_attr(target_os = "dragonfly",
114            link(name = "gcc_pic"))]
115 #[cfg_attr(target_os = "bitrig",
116            link(name = "c++abi"))]
117 #[cfg_attr(all(target_os = "windows", target_env="gnu"),
118            link(name = "gcc_eh"))]
119 extern "C" {
120     // iOS on armv7 uses SjLj exceptions and requires to link
121     // against corresponding routine (..._SjLj_...)
122     #[cfg(not(all(target_os = "ios", target_arch = "arm")))]
123     #[unwind]
124     pub fn _Unwind_RaiseException(exception: *mut _Unwind_Exception)
125                                   -> _Unwind_Reason_Code;
126
127     #[cfg(all(target_os = "ios", target_arch = "arm"))]
128     #[unwind]
129     fn _Unwind_SjLj_RaiseException(e: *mut _Unwind_Exception)
130                                    -> _Unwind_Reason_Code;
131
132     pub fn _Unwind_DeleteException(exception: *mut _Unwind_Exception);
133
134     #[unwind]
135     pub fn _Unwind_Resume(exception: *mut _Unwind_Exception) -> !;
136 }
137
138 // ... and now we just providing access to SjLj counterspart
139 // through a standard name to hide those details from others
140 // (see also comment above regarding _Unwind_RaiseException)
141 #[cfg(all(target_os = "ios", target_arch = "arm"))]
142 #[inline(always)]
143 pub unsafe fn _Unwind_RaiseException(exc: *mut _Unwind_Exception)
144                                      -> _Unwind_Reason_Code {
145     _Unwind_SjLj_RaiseException(exc)
146 }