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