]> git.lizzy.rs Git - rust.git/blob - src/librustrt/libunwind.rs
Add a few more derivings to AST types
[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_functions)]
15 #![allow(dead_code)] // these are just bindings
16
17 use libc;
18
19 #[cfg(not(target_arch = "arm"))]
20 #[cfg(target_os = "ios")]
21 #[repr(C)]
22 pub enum _Unwind_Action {
23     _UA_SEARCH_PHASE = 1,
24     _UA_CLEANUP_PHASE = 2,
25     _UA_HANDLER_FRAME = 4,
26     _UA_FORCE_UNWIND = 8,
27     _UA_END_OF_STACK = 16,
28 }
29
30 #[cfg(target_arch = "arm")]
31 #[repr(C)]
32 pub enum _Unwind_State {
33     _US_VIRTUAL_UNWIND_FRAME = 0,
34     _US_UNWIND_FRAME_STARTING = 1,
35     _US_UNWIND_FRAME_RESUME = 2,
36     _US_ACTION_MASK = 3,
37     _US_FORCE_UNWIND = 8,
38     _US_END_OF_STACK = 16
39 }
40
41 #[repr(C)]
42 pub enum _Unwind_Reason_Code {
43     _URC_NO_REASON = 0,
44     _URC_FOREIGN_EXCEPTION_CAUGHT = 1,
45     _URC_FATAL_PHASE2_ERROR = 2,
46     _URC_FATAL_PHASE1_ERROR = 3,
47     _URC_NORMAL_STOP = 4,
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
53 }
54
55 pub type _Unwind_Exception_Class = u64;
56
57 pub type _Unwind_Word = libc::uintptr_t;
58
59 #[cfg(target_arch = "x86")]
60 pub static unwinder_private_data_size: uint = 5;
61
62 #[cfg(target_arch = "x86_64")]
63 pub static unwinder_private_data_size: uint = 2;
64
65 #[cfg(target_arch = "arm", not(target_os = "ios"))]
66 pub static unwinder_private_data_size: uint = 20;
67
68 #[cfg(target_arch = "arm", target_os = "ios")]
69 pub static unwinder_private_data_size: uint = 5;
70
71 #[cfg(target_arch = "mips")]
72 #[cfg(target_arch = "mipsel")]
73 pub static unwinder_private_data_size: uint = 2;
74
75 pub struct _Unwind_Exception {
76     pub exception_class: _Unwind_Exception_Class,
77     pub exception_cleanup: _Unwind_Exception_Cleanup_Fn,
78     pub private: [_Unwind_Word, ..unwinder_private_data_size],
79 }
80
81 pub enum _Unwind_Context {}
82
83 pub type _Unwind_Exception_Cleanup_Fn =
84         extern "C" fn(unwind_code: _Unwind_Reason_Code,
85                       exception: *mut _Unwind_Exception);
86
87 #[cfg(target_os = "linux")]
88 #[cfg(target_os = "freebsd")]
89 #[cfg(target_os = "win32")]
90 #[link(name = "gcc_s")]
91 extern {}
92
93 #[cfg(target_os = "android")]
94 #[link(name = "gcc")]
95 extern {}
96
97
98 extern "C" {
99     // iOS on armv7 uses SjLj exceptions and requires to link
100     // against corresponding routine (..._SjLj_...)
101     #[cfg(not(target_os = "ios", target_arch = "arm"))]
102     pub fn _Unwind_RaiseException(exception: *mut _Unwind_Exception)
103                                   -> _Unwind_Reason_Code;
104
105     #[cfg(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(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 }