]> git.proxmox.com Git - rustc.git/blame - src/libstd/sys/common/libunwind.rs
Imported Upstream version 1.9.0+dfsg1
[rustc.git] / src / libstd / sys / common / libunwind.rs
CommitLineData
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"))]
19pub use self::_Unwind_Action::*;
20#[cfg(target_arch = "arm")]
21pub use self::_Unwind_State::*;
22pub use self::_Unwind_Reason_Code::*;
23
24use libc;
25
26#[cfg(any(not(target_arch = "arm"), target_os = "ios"))]
27#[repr(C)]
c34b1796 28#[derive(Copy, Clone)]
1a4d82fc
JJ
29pub 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)]
c1a9b12d 39#[derive(Copy, Clone)]
1a4d82fc
JJ
40pub 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)]
c1a9b12d 50#[derive(Copy, Clone)]
1a4d82fc
JJ
51pub 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
64pub type _Unwind_Exception_Class = u64;
65
66pub type _Unwind_Word = libc::uintptr_t;
67
68#[cfg(target_arch = "x86")]
c34b1796 69pub const unwinder_private_data_size: usize = 5;
1a4d82fc
JJ
70
71#[cfg(target_arch = "x86_64")]
c34b1796 72pub const unwinder_private_data_size: usize = 6;
1a4d82fc
JJ
73
74#[cfg(all(target_arch = "arm", not(target_os = "ios")))]
c34b1796 75pub const unwinder_private_data_size: usize = 20;
1a4d82fc
JJ
76
77#[cfg(all(target_arch = "arm", target_os = "ios"))]
c34b1796 78pub const unwinder_private_data_size: usize = 5;
1a4d82fc
JJ
79
80#[cfg(target_arch = "aarch64")]
c34b1796 81pub const unwinder_private_data_size: usize = 2;
1a4d82fc 82
7453a54e 83#[cfg(target_arch = "mips")]
c34b1796 84pub const unwinder_private_data_size: usize = 2;
1a4d82fc 85
7453a54e 86#[cfg(any(target_arch = "powerpc", target_arch = "powerpc64"))]
c34b1796 87pub const unwinder_private_data_size: usize = 2;
85aaf69f 88
7453a54e
SL
89#[cfg(target_arch = "asmjs")]
90// FIXME: Copied from arm. Need to confirm.
91pub const unwinder_private_data_size: usize = 20;
92
1a4d82fc
JJ
93#[repr(C)]
94pub struct _Unwind_Exception {
95 pub exception_class: _Unwind_Exception_Class,
96 pub exception_cleanup: _Unwind_Exception_Cleanup_Fn,
97 pub private: [_Unwind_Word; unwinder_private_data_size],
98}
99
100pub enum _Unwind_Context {}
101
102pub type _Unwind_Exception_Cleanup_Fn =
103 extern "C" fn(unwind_code: _Unwind_Reason_Code,
104 exception: *mut _Unwind_Exception);
105
92a42be0 106#[cfg_attr(any(all(target_os = "linux", not(target_env = "musl")),
7453a54e
SL
107 target_os = "freebsd",
108 target_os = "solaris",
54a0048b
SL
109 all(target_os = "linux",
110 target_env = "musl",
111 not(target_arch = "x86"),
112 not(target_arch = "x86_64"))),
92a42be0 113 link(name = "gcc_s"))]
54a0048b
SL
114#[cfg_attr(all(target_os = "linux",
115 target_env = "musl",
116 any(target_arch = "x86", target_arch = "x86_64"),
117 not(test)),
92a42be0
SL
118 link(name = "unwind", kind = "static"))]
119#[cfg_attr(any(target_os = "android", target_os = "openbsd"),
120 link(name = "gcc"))]
121#[cfg_attr(all(target_os = "netbsd", not(target_vendor = "rumprun")),
122 link(name = "gcc"))]
123#[cfg_attr(all(target_os = "netbsd", target_vendor = "rumprun"),
124 link(name = "unwind"))]
125#[cfg_attr(target_os = "dragonfly",
126 link(name = "gcc_pic"))]
127#[cfg_attr(target_os = "bitrig",
128 link(name = "c++abi"))]
129#[cfg_attr(all(target_os = "windows", target_env="gnu"),
130 link(name = "gcc_eh"))]
1a4d82fc
JJ
131extern "C" {
132 // iOS on armv7 uses SjLj exceptions and requires to link
133 // against corresponding routine (..._SjLj_...)
134 #[cfg(not(all(target_os = "ios", target_arch = "arm")))]
e9174d1e 135 #[unwind]
1a4d82fc
JJ
136 pub fn _Unwind_RaiseException(exception: *mut _Unwind_Exception)
137 -> _Unwind_Reason_Code;
138
139 #[cfg(all(target_os = "ios", target_arch = "arm"))]
e9174d1e 140 #[unwind]
1a4d82fc
JJ
141 fn _Unwind_SjLj_RaiseException(e: *mut _Unwind_Exception)
142 -> _Unwind_Reason_Code;
143
144 pub fn _Unwind_DeleteException(exception: *mut _Unwind_Exception);
92a42be0 145
92a42be0
SL
146 #[unwind]
147 pub fn _Unwind_Resume(exception: *mut _Unwind_Exception) -> !;
1a4d82fc
JJ
148}
149
150// ... and now we just providing access to SjLj counterspart
151// through a standard name to hide those details from others
152// (see also comment above regarding _Unwind_RaiseException)
153#[cfg(all(target_os = "ios", target_arch = "arm"))]
154#[inline(always)]
155pub unsafe fn _Unwind_RaiseException(exc: *mut _Unwind_Exception)
156 -> _Unwind_Reason_Code {
157 _Unwind_SjLj_RaiseException(exc)
158}