2014-12-12 17:39:27 -06:00
|
|
|
// Copyright 2014-2015 The Rust Project Developers. See the COPYRIGHT
|
2014-02-05 17:19:40 -06:00
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
|
|
|
//! Unwind library interface
|
|
|
|
|
2014-10-27 17:37:07 -05:00
|
|
|
#![allow(non_upper_case_globals)]
|
2014-03-21 20:05:05 -05:00
|
|
|
#![allow(non_camel_case_types)]
|
2014-07-18 07:45:17 -05:00
|
|
|
#![allow(non_snake_case)]
|
2014-03-21 20:05:05 -05:00
|
|
|
#![allow(dead_code)] // these are just bindings
|
2014-02-05 17:19:40 -06:00
|
|
|
|
2014-11-06 02:05:53 -06:00
|
|
|
#[cfg(any(not(target_arch = "arm"), target_os = "ios"))]
|
|
|
|
pub use self::_Unwind_Action::*;
|
|
|
|
#[cfg(target_arch = "arm")]
|
|
|
|
pub use self::_Unwind_State::*;
|
|
|
|
pub use self::_Unwind_Reason_Code::*;
|
|
|
|
|
2014-02-05 17:19:40 -06:00
|
|
|
use libc;
|
|
|
|
|
2014-09-29 01:38:24 -05:00
|
|
|
#[cfg(any(not(target_arch = "arm"), target_os = "ios"))]
|
2014-02-05 17:19:40 -06:00
|
|
|
#[repr(C)]
|
2015-03-30 08:40:52 -05:00
|
|
|
#[derive(Copy, Clone)]
|
2014-03-27 17:09:47 -05:00
|
|
|
pub enum _Unwind_Action {
|
2014-02-05 17:19:40 -06:00
|
|
|
_UA_SEARCH_PHASE = 1,
|
|
|
|
_UA_CLEANUP_PHASE = 2,
|
|
|
|
_UA_HANDLER_FRAME = 4,
|
|
|
|
_UA_FORCE_UNWIND = 8,
|
|
|
|
_UA_END_OF_STACK = 16,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(target_arch = "arm")]
|
|
|
|
#[repr(C)]
|
2014-03-27 17:09:47 -05:00
|
|
|
pub enum _Unwind_State {
|
|
|
|
_US_VIRTUAL_UNWIND_FRAME = 0,
|
|
|
|
_US_UNWIND_FRAME_STARTING = 1,
|
|
|
|
_US_UNWIND_FRAME_RESUME = 2,
|
|
|
|
_US_ACTION_MASK = 3,
|
|
|
|
_US_FORCE_UNWIND = 8,
|
|
|
|
_US_END_OF_STACK = 16
|
2014-02-05 17:19:40 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
#[repr(C)]
|
|
|
|
pub enum _Unwind_Reason_Code {
|
|
|
|
_URC_NO_REASON = 0,
|
|
|
|
_URC_FOREIGN_EXCEPTION_CAUGHT = 1,
|
|
|
|
_URC_FATAL_PHASE2_ERROR = 2,
|
|
|
|
_URC_FATAL_PHASE1_ERROR = 3,
|
|
|
|
_URC_NORMAL_STOP = 4,
|
|
|
|
_URC_END_OF_STACK = 5,
|
|
|
|
_URC_HANDLER_FOUND = 6,
|
|
|
|
_URC_INSTALL_CONTEXT = 7,
|
|
|
|
_URC_CONTINUE_UNWIND = 8,
|
|
|
|
_URC_FAILURE = 9, // used only by ARM EABI
|
|
|
|
}
|
|
|
|
|
|
|
|
pub type _Unwind_Exception_Class = u64;
|
|
|
|
|
|
|
|
pub type _Unwind_Word = libc::uintptr_t;
|
|
|
|
|
|
|
|
#[cfg(target_arch = "x86")]
|
2015-03-25 19:06:52 -05:00
|
|
|
pub const unwinder_private_data_size: usize = 5;
|
2014-02-05 17:19:40 -06:00
|
|
|
|
|
|
|
#[cfg(target_arch = "x86_64")]
|
2015-03-25 19:06:52 -05:00
|
|
|
pub const unwinder_private_data_size: usize = 6;
|
2014-02-05 17:19:40 -06:00
|
|
|
|
2014-09-29 01:38:24 -05:00
|
|
|
#[cfg(all(target_arch = "arm", not(target_os = "ios")))]
|
2015-03-25 19:06:52 -05:00
|
|
|
pub const unwinder_private_data_size: usize = 20;
|
2014-02-05 17:19:40 -06:00
|
|
|
|
2014-09-29 01:38:24 -05:00
|
|
|
#[cfg(all(target_arch = "arm", target_os = "ios"))]
|
2015-03-25 19:06:52 -05:00
|
|
|
pub const unwinder_private_data_size: usize = 5;
|
2014-05-05 02:07:49 -05:00
|
|
|
|
2014-12-12 17:39:27 -06:00
|
|
|
#[cfg(target_arch = "aarch64")]
|
2015-03-25 19:06:52 -05:00
|
|
|
pub const unwinder_private_data_size: usize = 2;
|
2014-12-12 17:39:27 -06:00
|
|
|
|
2014-09-29 01:38:24 -05:00
|
|
|
#[cfg(any(target_arch = "mips", target_arch = "mipsel"))]
|
2015-03-25 19:06:52 -05:00
|
|
|
pub const unwinder_private_data_size: usize = 2;
|
2014-03-13 01:35:24 -05:00
|
|
|
|
2015-01-09 22:20:57 -06:00
|
|
|
#[cfg(target_arch = "powerpc")]
|
2015-03-25 19:06:52 -05:00
|
|
|
pub const unwinder_private_data_size: usize = 2;
|
2015-01-09 22:20:57 -06:00
|
|
|
|
2014-05-27 01:56:52 -05:00
|
|
|
#[repr(C)]
|
2014-02-05 17:19:40 -06:00
|
|
|
pub struct _Unwind_Exception {
|
2014-03-27 17:09:47 -05:00
|
|
|
pub exception_class: _Unwind_Exception_Class,
|
|
|
|
pub exception_cleanup: _Unwind_Exception_Cleanup_Fn,
|
2014-12-31 22:40:24 -06:00
|
|
|
pub private: [_Unwind_Word; unwinder_private_data_size],
|
2014-02-05 17:19:40 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
pub enum _Unwind_Context {}
|
|
|
|
|
|
|
|
pub type _Unwind_Exception_Cleanup_Fn =
|
|
|
|
extern "C" fn(unwind_code: _Unwind_Reason_Code,
|
2014-06-25 14:47:34 -05:00
|
|
|
exception: *mut _Unwind_Exception);
|
2014-02-05 17:19:40 -06:00
|
|
|
|
2014-09-29 01:38:24 -05:00
|
|
|
#[cfg(any(target_os = "linux", target_os = "freebsd"))]
|
2014-02-05 17:19:40 -06:00
|
|
|
#[link(name = "gcc_s")]
|
|
|
|
extern {}
|
|
|
|
|
2015-01-29 01:19:28 -06:00
|
|
|
#[cfg(any(target_os = "android", target_os = "openbsd"))]
|
2014-02-05 17:19:40 -06:00
|
|
|
#[link(name = "gcc")]
|
|
|
|
extern {}
|
|
|
|
|
2014-07-29 09:44:39 -05:00
|
|
|
#[cfg(target_os = "dragonfly")]
|
|
|
|
#[link(name = "gcc_pic")]
|
|
|
|
extern {}
|
2014-05-05 02:07:49 -05:00
|
|
|
|
2015-01-17 01:51:04 -06:00
|
|
|
#[cfg(target_os = "bitrig")]
|
|
|
|
#[link(name = "c++abi")]
|
|
|
|
extern {}
|
|
|
|
|
2014-02-05 17:19:40 -06:00
|
|
|
extern "C" {
|
2014-05-05 02:07:49 -05:00
|
|
|
// iOS on armv7 uses SjLj exceptions and requires to link
|
2014-07-02 20:27:07 -05:00
|
|
|
// against corresponding routine (..._SjLj_...)
|
2014-09-29 01:38:24 -05:00
|
|
|
#[cfg(not(all(target_os = "ios", target_arch = "arm")))]
|
2014-06-25 14:47:34 -05:00
|
|
|
pub fn _Unwind_RaiseException(exception: *mut _Unwind_Exception)
|
2014-06-13 02:18:12 -05:00
|
|
|
-> _Unwind_Reason_Code;
|
|
|
|
|
2014-09-29 01:38:24 -05:00
|
|
|
#[cfg(all(target_os = "ios", target_arch = "arm"))]
|
2014-06-25 14:47:34 -05:00
|
|
|
fn _Unwind_SjLj_RaiseException(e: *mut _Unwind_Exception)
|
2014-06-13 02:18:12 -05:00
|
|
|
-> _Unwind_Reason_Code;
|
|
|
|
|
2014-06-25 14:47:34 -05:00
|
|
|
pub fn _Unwind_DeleteException(exception: *mut _Unwind_Exception);
|
2014-02-05 17:19:40 -06:00
|
|
|
}
|
2014-05-05 02:07:49 -05:00
|
|
|
|
|
|
|
// ... and now we just providing access to SjLj counterspart
|
|
|
|
// through a standard name to hide those details from others
|
|
|
|
// (see also comment above regarding _Unwind_RaiseException)
|
2014-09-29 01:38:24 -05:00
|
|
|
#[cfg(all(target_os = "ios", target_arch = "arm"))]
|
2014-05-05 02:07:49 -05:00
|
|
|
#[inline(always)]
|
2014-06-25 14:47:34 -05:00
|
|
|
pub unsafe fn _Unwind_RaiseException(exc: *mut _Unwind_Exception)
|
2014-05-05 02:07:49 -05:00
|
|
|
-> _Unwind_Reason_Code {
|
|
|
|
_Unwind_SjLj_RaiseException(exc)
|
|
|
|
}
|