rustc: Implement custom panic runtimes
This commit is an implementation of [RFC 1513] which allows applications to
alter the behavior of panics at compile time. A new compiler flag, `-C panic`,
is added and accepts the values `unwind` or `panic`, with the default being
`unwind`. This model affects how code is generated for the local crate, skipping
generation of landing pads with `-C panic=abort`.
[RFC 1513]: https://github.com/rust-lang/rfcs/blob/master/text/1513-less-unwinding.md
Panic implementations are then provided by crates tagged with
`#![panic_runtime]` and lazily required by crates with
`#![needs_panic_runtime]`. The panic strategy (`-C panic` value) of the panic
runtime must match the final product, and if the panic strategy is not `abort`
then the entire DAG must have the same panic strategy.
With the `-C panic=abort` strategy, users can expect a stable method to disable
generation of landing pads, improving optimization in niche scenarios,
decreasing compile time, and decreasing output binary size. With the `-C
panic=unwind` strategy users can expect the existing ability to isolate failure
in Rust code from the outside world.
Organizationally, this commit dismantles the `sys_common::unwind` module in
favor of some bits moving part of it to `libpanic_unwind` and the rest into the
`panicking` module in libstd. The custom panic runtime support is pretty similar
to the custom allocator support with the only major difference being how the
panic runtime is injected (takes the `-C panic` flag into account).
2016-04-08 18:18:40 -05:00
|
|
|
// Copyright 2016 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.
|
|
|
|
|
rustc: Implement custom panic runtimes
This commit is an implementation of [RFC 1513] which allows applications to
alter the behavior of panics at compile time. A new compiler flag, `-C panic`,
is added and accepts the values `unwind` or `panic`, with the default being
`unwind`. This model affects how code is generated for the local crate, skipping
generation of landing pads with `-C panic=abort`.
[RFC 1513]: https://github.com/rust-lang/rfcs/blob/master/text/1513-less-unwinding.md
Panic implementations are then provided by crates tagged with
`#![panic_runtime]` and lazily required by crates with
`#![needs_panic_runtime]`. The panic strategy (`-C panic` value) of the panic
runtime must match the final product, and if the panic strategy is not `abort`
then the entire DAG must have the same panic strategy.
With the `-C panic=abort` strategy, users can expect a stable method to disable
generation of landing pads, improving optimization in niche scenarios,
decreasing compile time, and decreasing output binary size. With the `-C
panic=unwind` strategy users can expect the existing ability to isolate failure
in Rust code from the outside world.
Organizationally, this commit dismantles the `sys_common::unwind` module in
favor of some bits moving part of it to `libpanic_unwind` and the rest into the
`panicking` module in libstd. The custom panic runtime support is pretty similar
to the custom allocator support with the only major difference being how the
panic runtime is injected (takes the `-C panic` flag into account).
2016-04-08 18:18:40 -05:00
|
|
|
#![allow(bad_style)]
|
2014-02-05 17:19:40 -06:00
|
|
|
|
2016-07-23 19:25:25 -05:00
|
|
|
macro_rules! cfg_if {
|
|
|
|
( $( if #[cfg( $meta:meta )] { $($it1:item)* } else { $($it2:item)* } )* ) =>
|
|
|
|
( $( $( #[cfg($meta)] $it1)* $( #[cfg(not($meta))] $it2)* )* )
|
2014-02-05 17:19:40 -06:00
|
|
|
}
|
|
|
|
|
2016-07-23 19:25:25 -05:00
|
|
|
use libc::{c_int, c_void, uintptr_t};
|
2014-02-05 17:19:40 -06:00
|
|
|
|
|
|
|
#[repr(C)]
|
2016-12-04 15:38:27 -06:00
|
|
|
#[derive(Debug, Copy, Clone, PartialEq)]
|
2014-02-05 17:19:40 -06:00
|
|
|
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,
|
2016-07-23 19:25:25 -05:00
|
|
|
_URC_FAILURE = 9, // used only by ARM EHABI
|
2014-02-05 17:19:40 -06:00
|
|
|
}
|
2016-07-23 19:25:25 -05:00
|
|
|
pub use self::_Unwind_Reason_Code::*;
|
2014-02-05 17:19:40 -06:00
|
|
|
|
|
|
|
pub type _Unwind_Exception_Class = u64;
|
2016-07-23 19:25:25 -05:00
|
|
|
pub type _Unwind_Word = uintptr_t;
|
|
|
|
pub type _Unwind_Ptr = uintptr_t;
|
|
|
|
pub type _Unwind_Trace_Fn = extern "C" fn(ctx: *mut _Unwind_Context, arg: *mut c_void)
|
2016-05-28 22:17:51 -05:00
|
|
|
-> _Unwind_Reason_Code;
|
2014-02-05 17:19:40 -06:00
|
|
|
#[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
|
|
|
|
2016-01-30 15:27:00 -06:00
|
|
|
#[cfg(target_arch = "mips")]
|
2015-03-25 19:06:52 -05:00
|
|
|
pub const unwinder_private_data_size: usize = 2;
|
2014-03-13 01:35:24 -05:00
|
|
|
|
2016-08-27 01:39:29 -05:00
|
|
|
#[cfg(target_arch = "mips64")]
|
|
|
|
pub const unwinder_private_data_size: usize = 2;
|
|
|
|
|
2016-01-30 15:27:00 -06:00
|
|
|
#[cfg(any(target_arch = "powerpc", target_arch = "powerpc64"))]
|
2015-03-25 19:06:52 -05:00
|
|
|
pub const unwinder_private_data_size: usize = 2;
|
2015-01-09 22:20:57 -06:00
|
|
|
|
2016-09-09 16:00:23 -05:00
|
|
|
#[cfg(target_arch = "s390x")]
|
|
|
|
pub const unwinder_private_data_size: usize = 2;
|
|
|
|
|
2016-12-06 15:59:15 -06:00
|
|
|
#[cfg(target_arch = "sparc64")]
|
|
|
|
pub const unwinder_private_data_size: usize = 2;
|
|
|
|
|
2016-09-22 14:55:42 -05:00
|
|
|
#[cfg(target_os = "emscripten")]
|
2015-11-26 13:05:10 -06:00
|
|
|
pub const unwinder_private_data_size: usize = 20;
|
|
|
|
|
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 {}
|
|
|
|
|
2016-05-28 22:17:51 -05:00
|
|
|
pub type _Unwind_Exception_Cleanup_Fn = extern "C" fn(unwind_code: _Unwind_Reason_Code,
|
|
|
|
exception: *mut _Unwind_Exception);
|
|
|
|
extern "C" {
|
2018-04-04 09:16:25 -05:00
|
|
|
#[unwind(allowed)]
|
2015-10-18 16:28:47 -05:00
|
|
|
pub fn _Unwind_Resume(exception: *mut _Unwind_Exception) -> !;
|
2016-07-23 19:25:25 -05:00
|
|
|
pub fn _Unwind_DeleteException(exception: *mut _Unwind_Exception);
|
|
|
|
pub fn _Unwind_GetLanguageSpecificData(ctx: *mut _Unwind_Context) -> *mut c_void;
|
2016-07-22 16:57:54 -05:00
|
|
|
pub fn _Unwind_GetRegionStart(ctx: *mut _Unwind_Context) -> _Unwind_Ptr;
|
|
|
|
pub fn _Unwind_GetTextRelBase(ctx: *mut _Unwind_Context) -> _Unwind_Ptr;
|
|
|
|
pub fn _Unwind_GetDataRelBase(ctx: *mut _Unwind_Context) -> _Unwind_Ptr;
|
2014-02-05 17:19:40 -06:00
|
|
|
}
|
2014-05-05 02:07:49 -05:00
|
|
|
|
2016-07-23 19:25:25 -05:00
|
|
|
cfg_if! {
|
2018-01-19 02:20:34 -06:00
|
|
|
if #[cfg(all(any(target_os = "ios", not(target_arch = "arm"))))] {
|
2016-07-23 19:25:25 -05:00
|
|
|
// Not ARM EHABI
|
|
|
|
#[repr(C)]
|
|
|
|
#[derive(Copy, Clone, PartialEq)]
|
|
|
|
pub enum _Unwind_Action {
|
|
|
|
_UA_SEARCH_PHASE = 1,
|
|
|
|
_UA_CLEANUP_PHASE = 2,
|
|
|
|
_UA_HANDLER_FRAME = 4,
|
|
|
|
_UA_FORCE_UNWIND = 8,
|
|
|
|
_UA_END_OF_STACK = 16,
|
|
|
|
}
|
|
|
|
pub use self::_Unwind_Action::*;
|
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
pub fn _Unwind_GetGR(ctx: *mut _Unwind_Context, reg_index: c_int) -> _Unwind_Word;
|
|
|
|
pub fn _Unwind_SetGR(ctx: *mut _Unwind_Context, reg_index: c_int, value: _Unwind_Word);
|
|
|
|
pub fn _Unwind_GetIP(ctx: *mut _Unwind_Context) -> _Unwind_Word;
|
|
|
|
pub fn _Unwind_SetIP(ctx: *mut _Unwind_Context, value: _Unwind_Word);
|
|
|
|
pub fn _Unwind_GetIPInfo(ctx: *mut _Unwind_Context, ip_before_insn: *mut c_int)
|
|
|
|
-> _Unwind_Word;
|
|
|
|
pub fn _Unwind_FindEnclosingFunction(pc: *mut c_void) -> *mut c_void;
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
// ARM EHABI
|
|
|
|
#[repr(C)]
|
|
|
|
#[derive(Copy, Clone, PartialEq)]
|
|
|
|
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,
|
|
|
|
}
|
|
|
|
pub use self::_Unwind_State::*;
|
rustc: Implement custom panic runtimes
This commit is an implementation of [RFC 1513] which allows applications to
alter the behavior of panics at compile time. A new compiler flag, `-C panic`,
is added and accepts the values `unwind` or `panic`, with the default being
`unwind`. This model affects how code is generated for the local crate, skipping
generation of landing pads with `-C panic=abort`.
[RFC 1513]: https://github.com/rust-lang/rfcs/blob/master/text/1513-less-unwinding.md
Panic implementations are then provided by crates tagged with
`#![panic_runtime]` and lazily required by crates with
`#![needs_panic_runtime]`. The panic strategy (`-C panic` value) of the panic
runtime must match the final product, and if the panic strategy is not `abort`
then the entire DAG must have the same panic strategy.
With the `-C panic=abort` strategy, users can expect a stable method to disable
generation of landing pads, improving optimization in niche scenarios,
decreasing compile time, and decreasing output binary size. With the `-C
panic=unwind` strategy users can expect the existing ability to isolate failure
in Rust code from the outside world.
Organizationally, this commit dismantles the `sys_common::unwind` module in
favor of some bits moving part of it to `libpanic_unwind` and the rest into the
`panicking` module in libstd. The custom panic runtime support is pretty similar
to the custom allocator support with the only major difference being how the
panic runtime is injected (takes the `-C panic` flag into account).
2016-04-08 18:18:40 -05:00
|
|
|
|
|
|
|
#[repr(C)]
|
|
|
|
enum _Unwind_VRS_Result {
|
|
|
|
_UVRSR_OK = 0,
|
|
|
|
_UVRSR_NOT_IMPLEMENTED = 1,
|
|
|
|
_UVRSR_FAILED = 2,
|
|
|
|
}
|
|
|
|
#[repr(C)]
|
|
|
|
enum _Unwind_VRS_RegClass {
|
|
|
|
_UVRSC_CORE = 0,
|
|
|
|
_UVRSC_VFP = 1,
|
|
|
|
_UVRSC_FPA = 2,
|
|
|
|
_UVRSC_WMMXD = 3,
|
|
|
|
_UVRSC_WMMXC = 4,
|
|
|
|
}
|
2016-07-23 19:25:25 -05:00
|
|
|
use self::_Unwind_VRS_RegClass::*;
|
rustc: Implement custom panic runtimes
This commit is an implementation of [RFC 1513] which allows applications to
alter the behavior of panics at compile time. A new compiler flag, `-C panic`,
is added and accepts the values `unwind` or `panic`, with the default being
`unwind`. This model affects how code is generated for the local crate, skipping
generation of landing pads with `-C panic=abort`.
[RFC 1513]: https://github.com/rust-lang/rfcs/blob/master/text/1513-less-unwinding.md
Panic implementations are then provided by crates tagged with
`#![panic_runtime]` and lazily required by crates with
`#![needs_panic_runtime]`. The panic strategy (`-C panic` value) of the panic
runtime must match the final product, and if the panic strategy is not `abort`
then the entire DAG must have the same panic strategy.
With the `-C panic=abort` strategy, users can expect a stable method to disable
generation of landing pads, improving optimization in niche scenarios,
decreasing compile time, and decreasing output binary size. With the `-C
panic=unwind` strategy users can expect the existing ability to isolate failure
in Rust code from the outside world.
Organizationally, this commit dismantles the `sys_common::unwind` module in
favor of some bits moving part of it to `libpanic_unwind` and the rest into the
`panicking` module in libstd. The custom panic runtime support is pretty similar
to the custom allocator support with the only major difference being how the
panic runtime is injected (takes the `-C panic` flag into account).
2016-04-08 18:18:40 -05:00
|
|
|
#[repr(C)]
|
|
|
|
enum _Unwind_VRS_DataRepresentation {
|
|
|
|
_UVRSD_UINT32 = 0,
|
|
|
|
_UVRSD_VFPX = 1,
|
|
|
|
_UVRSD_FPAX = 2,
|
|
|
|
_UVRSD_UINT64 = 3,
|
|
|
|
_UVRSD_FLOAT = 4,
|
|
|
|
_UVRSD_DOUBLE = 5,
|
|
|
|
}
|
2016-07-23 19:25:25 -05:00
|
|
|
use self::_Unwind_VRS_DataRepresentation::*;
|
|
|
|
|
|
|
|
pub const UNWIND_POINTER_REG: c_int = 12;
|
|
|
|
pub const UNWIND_IP_REG: c_int = 15;
|
rustc: Implement custom panic runtimes
This commit is an implementation of [RFC 1513] which allows applications to
alter the behavior of panics at compile time. A new compiler flag, `-C panic`,
is added and accepts the values `unwind` or `panic`, with the default being
`unwind`. This model affects how code is generated for the local crate, skipping
generation of landing pads with `-C panic=abort`.
[RFC 1513]: https://github.com/rust-lang/rfcs/blob/master/text/1513-less-unwinding.md
Panic implementations are then provided by crates tagged with
`#![panic_runtime]` and lazily required by crates with
`#![needs_panic_runtime]`. The panic strategy (`-C panic` value) of the panic
runtime must match the final product, and if the panic strategy is not `abort`
then the entire DAG must have the same panic strategy.
With the `-C panic=abort` strategy, users can expect a stable method to disable
generation of landing pads, improving optimization in niche scenarios,
decreasing compile time, and decreasing output binary size. With the `-C
panic=unwind` strategy users can expect the existing ability to isolate failure
in Rust code from the outside world.
Organizationally, this commit dismantles the `sys_common::unwind` module in
favor of some bits moving part of it to `libpanic_unwind` and the rest into the
`panicking` module in libstd. The custom panic runtime support is pretty similar
to the custom allocator support with the only major difference being how the
panic runtime is injected (takes the `-C panic` flag into account).
2016-04-08 18:18:40 -05:00
|
|
|
|
2016-05-28 22:17:51 -05:00
|
|
|
extern "C" {
|
rustc: Implement custom panic runtimes
This commit is an implementation of [RFC 1513] which allows applications to
alter the behavior of panics at compile time. A new compiler flag, `-C panic`,
is added and accepts the values `unwind` or `panic`, with the default being
`unwind`. This model affects how code is generated for the local crate, skipping
generation of landing pads with `-C panic=abort`.
[RFC 1513]: https://github.com/rust-lang/rfcs/blob/master/text/1513-less-unwinding.md
Panic implementations are then provided by crates tagged with
`#![panic_runtime]` and lazily required by crates with
`#![needs_panic_runtime]`. The panic strategy (`-C panic` value) of the panic
runtime must match the final product, and if the panic strategy is not `abort`
then the entire DAG must have the same panic strategy.
With the `-C panic=abort` strategy, users can expect a stable method to disable
generation of landing pads, improving optimization in niche scenarios,
decreasing compile time, and decreasing output binary size. With the `-C
panic=unwind` strategy users can expect the existing ability to isolate failure
in Rust code from the outside world.
Organizationally, this commit dismantles the `sys_common::unwind` module in
favor of some bits moving part of it to `libpanic_unwind` and the rest into the
`panicking` module in libstd. The custom panic runtime support is pretty similar
to the custom allocator support with the only major difference being how the
panic runtime is injected (takes the `-C panic` flag into account).
2016-04-08 18:18:40 -05:00
|
|
|
fn _Unwind_VRS_Get(ctx: *mut _Unwind_Context,
|
2016-07-23 19:25:25 -05:00
|
|
|
regclass: _Unwind_VRS_RegClass,
|
|
|
|
regno: _Unwind_Word,
|
|
|
|
repr: _Unwind_VRS_DataRepresentation,
|
|
|
|
data: *mut c_void)
|
|
|
|
-> _Unwind_VRS_Result;
|
|
|
|
|
|
|
|
fn _Unwind_VRS_Set(ctx: *mut _Unwind_Context,
|
|
|
|
regclass: _Unwind_VRS_RegClass,
|
|
|
|
regno: _Unwind_Word,
|
rustc: Implement custom panic runtimes
This commit is an implementation of [RFC 1513] which allows applications to
alter the behavior of panics at compile time. A new compiler flag, `-C panic`,
is added and accepts the values `unwind` or `panic`, with the default being
`unwind`. This model affects how code is generated for the local crate, skipping
generation of landing pads with `-C panic=abort`.
[RFC 1513]: https://github.com/rust-lang/rfcs/blob/master/text/1513-less-unwinding.md
Panic implementations are then provided by crates tagged with
`#![panic_runtime]` and lazily required by crates with
`#![needs_panic_runtime]`. The panic strategy (`-C panic` value) of the panic
runtime must match the final product, and if the panic strategy is not `abort`
then the entire DAG must have the same panic strategy.
With the `-C panic=abort` strategy, users can expect a stable method to disable
generation of landing pads, improving optimization in niche scenarios,
decreasing compile time, and decreasing output binary size. With the `-C
panic=unwind` strategy users can expect the existing ability to isolate failure
in Rust code from the outside world.
Organizationally, this commit dismantles the `sys_common::unwind` module in
favor of some bits moving part of it to `libpanic_unwind` and the rest into the
`panicking` module in libstd. The custom panic runtime support is pretty similar
to the custom allocator support with the only major difference being how the
panic runtime is injected (takes the `-C panic` flag into account).
2016-04-08 18:18:40 -05:00
|
|
|
repr: _Unwind_VRS_DataRepresentation,
|
2016-07-23 19:25:25 -05:00
|
|
|
data: *mut c_void)
|
2016-05-28 22:17:51 -05:00
|
|
|
-> _Unwind_VRS_Result;
|
rustc: Implement custom panic runtimes
This commit is an implementation of [RFC 1513] which allows applications to
alter the behavior of panics at compile time. A new compiler flag, `-C panic`,
is added and accepts the values `unwind` or `panic`, with the default being
`unwind`. This model affects how code is generated for the local crate, skipping
generation of landing pads with `-C panic=abort`.
[RFC 1513]: https://github.com/rust-lang/rfcs/blob/master/text/1513-less-unwinding.md
Panic implementations are then provided by crates tagged with
`#![panic_runtime]` and lazily required by crates with
`#![needs_panic_runtime]`. The panic strategy (`-C panic` value) of the panic
runtime must match the final product, and if the panic strategy is not `abort`
then the entire DAG must have the same panic strategy.
With the `-C panic=abort` strategy, users can expect a stable method to disable
generation of landing pads, improving optimization in niche scenarios,
decreasing compile time, and decreasing output binary size. With the `-C
panic=unwind` strategy users can expect the existing ability to isolate failure
in Rust code from the outside world.
Organizationally, this commit dismantles the `sys_common::unwind` module in
favor of some bits moving part of it to `libpanic_unwind` and the rest into the
`panicking` module in libstd. The custom panic runtime support is pretty similar
to the custom allocator support with the only major difference being how the
panic runtime is injected (takes the `-C panic` flag into account).
2016-04-08 18:18:40 -05:00
|
|
|
}
|
|
|
|
|
2016-07-23 19:25:25 -05:00
|
|
|
// On Android or ARM/Linux, these are implemented as macros:
|
|
|
|
|
|
|
|
pub unsafe fn _Unwind_GetGR(ctx: *mut _Unwind_Context, reg_index: c_int) -> _Unwind_Word {
|
|
|
|
let mut val: _Unwind_Word = 0;
|
|
|
|
_Unwind_VRS_Get(ctx, _UVRSC_CORE, reg_index as _Unwind_Word, _UVRSD_UINT32,
|
|
|
|
&mut val as *mut _ as *mut c_void);
|
|
|
|
val
|
|
|
|
}
|
rustc: Implement custom panic runtimes
This commit is an implementation of [RFC 1513] which allows applications to
alter the behavior of panics at compile time. A new compiler flag, `-C panic`,
is added and accepts the values `unwind` or `panic`, with the default being
`unwind`. This model affects how code is generated for the local crate, skipping
generation of landing pads with `-C panic=abort`.
[RFC 1513]: https://github.com/rust-lang/rfcs/blob/master/text/1513-less-unwinding.md
Panic implementations are then provided by crates tagged with
`#![panic_runtime]` and lazily required by crates with
`#![needs_panic_runtime]`. The panic strategy (`-C panic` value) of the panic
runtime must match the final product, and if the panic strategy is not `abort`
then the entire DAG must have the same panic strategy.
With the `-C panic=abort` strategy, users can expect a stable method to disable
generation of landing pads, improving optimization in niche scenarios,
decreasing compile time, and decreasing output binary size. With the `-C
panic=unwind` strategy users can expect the existing ability to isolate failure
in Rust code from the outside world.
Organizationally, this commit dismantles the `sys_common::unwind` module in
favor of some bits moving part of it to `libpanic_unwind` and the rest into the
`panicking` module in libstd. The custom panic runtime support is pretty similar
to the custom allocator support with the only major difference being how the
panic runtime is injected (takes the `-C panic` flag into account).
2016-04-08 18:18:40 -05:00
|
|
|
|
2016-07-23 19:25:25 -05:00
|
|
|
pub unsafe fn _Unwind_SetGR(ctx: *mut _Unwind_Context, reg_index: c_int, value: _Unwind_Word) {
|
|
|
|
let mut value = value;
|
|
|
|
_Unwind_VRS_Set(ctx, _UVRSC_CORE, reg_index as _Unwind_Word, _UVRSD_UINT32,
|
|
|
|
&mut value as *mut _ as *mut c_void);
|
|
|
|
}
|
|
|
|
|
|
|
|
pub unsafe fn _Unwind_GetIP(ctx: *mut _Unwind_Context)
|
|
|
|
-> _Unwind_Word {
|
|
|
|
let val = _Unwind_GetGR(ctx, UNWIND_IP_REG);
|
|
|
|
(val & !1) as _Unwind_Word
|
|
|
|
}
|
|
|
|
|
|
|
|
pub unsafe fn _Unwind_SetIP(ctx: *mut _Unwind_Context,
|
|
|
|
value: _Unwind_Word) {
|
|
|
|
// Propagate thumb bit to instruction pointer
|
|
|
|
let thumb_state = _Unwind_GetGR(ctx, UNWIND_IP_REG) & 1;
|
|
|
|
let value = value | thumb_state;
|
|
|
|
_Unwind_SetGR(ctx, UNWIND_IP_REG, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
pub unsafe fn _Unwind_GetIPInfo(ctx: *mut _Unwind_Context,
|
|
|
|
ip_before_insn: *mut c_int)
|
|
|
|
-> _Unwind_Word {
|
|
|
|
*ip_before_insn = 0;
|
|
|
|
_Unwind_GetIP(ctx)
|
|
|
|
}
|
|
|
|
|
|
|
|
// This function also doesn't exist on Android or ARM/Linux, so make it a no-op
|
|
|
|
pub unsafe fn _Unwind_FindEnclosingFunction(pc: *mut c_void) -> *mut c_void {
|
|
|
|
pc
|
|
|
|
}
|
rustc: Implement custom panic runtimes
This commit is an implementation of [RFC 1513] which allows applications to
alter the behavior of panics at compile time. A new compiler flag, `-C panic`,
is added and accepts the values `unwind` or `panic`, with the default being
`unwind`. This model affects how code is generated for the local crate, skipping
generation of landing pads with `-C panic=abort`.
[RFC 1513]: https://github.com/rust-lang/rfcs/blob/master/text/1513-less-unwinding.md
Panic implementations are then provided by crates tagged with
`#![panic_runtime]` and lazily required by crates with
`#![needs_panic_runtime]`. The panic strategy (`-C panic` value) of the panic
runtime must match the final product, and if the panic strategy is not `abort`
then the entire DAG must have the same panic strategy.
With the `-C panic=abort` strategy, users can expect a stable method to disable
generation of landing pads, improving optimization in niche scenarios,
decreasing compile time, and decreasing output binary size. With the `-C
panic=unwind` strategy users can expect the existing ability to isolate failure
in Rust code from the outside world.
Organizationally, this commit dismantles the `sys_common::unwind` module in
favor of some bits moving part of it to `libpanic_unwind` and the rest into the
`panicking` module in libstd. The custom panic runtime support is pretty similar
to the custom allocator support with the only major difference being how the
panic runtime is injected (takes the `-C panic` flag into account).
2016-04-08 18:18:40 -05:00
|
|
|
}
|
|
|
|
|
2016-07-23 19:25:25 -05:00
|
|
|
if #[cfg(not(all(target_os = "ios", target_arch = "arm")))] {
|
|
|
|
// Not 32-bit iOS
|
|
|
|
extern "C" {
|
2018-04-04 09:16:25 -05:00
|
|
|
#[unwind(allowed)]
|
2016-07-23 19:25:25 -05:00
|
|
|
pub fn _Unwind_RaiseException(exception: *mut _Unwind_Exception) -> _Unwind_Reason_Code;
|
|
|
|
pub fn _Unwind_Backtrace(trace: _Unwind_Trace_Fn,
|
|
|
|
trace_argument: *mut c_void)
|
|
|
|
-> _Unwind_Reason_Code;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// 32-bit iOS uses SjLj and does not provide _Unwind_Backtrace()
|
|
|
|
extern "C" {
|
2018-04-04 09:16:25 -05:00
|
|
|
#[unwind(allowed)]
|
2016-07-23 19:25:25 -05:00
|
|
|
pub fn _Unwind_SjLj_RaiseException(e: *mut _Unwind_Exception) -> _Unwind_Reason_Code;
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
pub unsafe fn _Unwind_RaiseException(exc: *mut _Unwind_Exception) -> _Unwind_Reason_Code {
|
|
|
|
_Unwind_SjLj_RaiseException(exc)
|
|
|
|
}
|
rustc: Implement custom panic runtimes
This commit is an implementation of [RFC 1513] which allows applications to
alter the behavior of panics at compile time. A new compiler flag, `-C panic`,
is added and accepts the values `unwind` or `panic`, with the default being
`unwind`. This model affects how code is generated for the local crate, skipping
generation of landing pads with `-C panic=abort`.
[RFC 1513]: https://github.com/rust-lang/rfcs/blob/master/text/1513-less-unwinding.md
Panic implementations are then provided by crates tagged with
`#![panic_runtime]` and lazily required by crates with
`#![needs_panic_runtime]`. The panic strategy (`-C panic` value) of the panic
runtime must match the final product, and if the panic strategy is not `abort`
then the entire DAG must have the same panic strategy.
With the `-C panic=abort` strategy, users can expect a stable method to disable
generation of landing pads, improving optimization in niche scenarios,
decreasing compile time, and decreasing output binary size. With the `-C
panic=unwind` strategy users can expect the existing ability to isolate failure
in Rust code from the outside world.
Organizationally, this commit dismantles the `sys_common::unwind` module in
favor of some bits moving part of it to `libpanic_unwind` and the rest into the
`panicking` module in libstd. The custom panic runtime support is pretty similar
to the custom allocator support with the only major difference being how the
panic runtime is injected (takes the `-C panic` flag into account).
2016-04-08 18:18:40 -05:00
|
|
|
}
|
2016-07-23 19:25:25 -05:00
|
|
|
} // cfg_if!
|