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 16:18:40 -07:00
|
|
|
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
|
2014-02-05 15:19:40 -08: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 16:18:40 -07:00
|
|
|
#![allow(bad_style)]
|
2014-02-05 15:19:40 -08:00
|
|
|
|
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 16:18:40 -07:00
|
|
|
use libc;
|
2014-02-05 15:19:40 -08:00
|
|
|
|
2014-11-06 00:05:53 -08: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-09-28 23:38:24 -07:00
|
|
|
#[cfg(any(not(target_arch = "arm"), target_os = "ios"))]
|
2014-02-05 15:19:40 -08:00
|
|
|
#[repr(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 16:18:40 -07:00
|
|
|
#[derive(Clone, Copy)]
|
2014-03-27 15:09:47 -07:00
|
|
|
pub enum _Unwind_Action {
|
2014-02-05 15:19:40 -08: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)]
|
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 16:18:40 -07:00
|
|
|
#[derive(Clone, Copy)]
|
2014-03-27 15:09:47 -07: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,
|
2016-05-29 08:47:51 +05:30
|
|
|
_US_END_OF_STACK = 16,
|
2014-02-05 15:19:40 -08: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;
|
|
|
|
|
|
2016-05-29 08:47:51 +05:30
|
|
|
pub type _Unwind_Trace_Fn = extern "C" fn(ctx: *mut _Unwind_Context, arg: *mut libc::c_void)
|
|
|
|
|
-> _Unwind_Reason_Code;
|
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 16:18:40 -07:00
|
|
|
|
2014-02-05 15:19:40 -08:00
|
|
|
#[cfg(target_arch = "x86")]
|
2015-03-25 17:06:52 -07:00
|
|
|
pub const unwinder_private_data_size: usize = 5;
|
2014-02-05 15:19:40 -08:00
|
|
|
|
|
|
|
|
#[cfg(target_arch = "x86_64")]
|
2015-03-25 17:06:52 -07:00
|
|
|
pub const unwinder_private_data_size: usize = 6;
|
2014-02-05 15:19:40 -08:00
|
|
|
|
2014-09-28 23:38:24 -07:00
|
|
|
#[cfg(all(target_arch = "arm", not(target_os = "ios")))]
|
2015-03-25 17:06:52 -07:00
|
|
|
pub const unwinder_private_data_size: usize = 20;
|
2014-02-05 15:19:40 -08:00
|
|
|
|
2014-09-28 23:38:24 -07:00
|
|
|
#[cfg(all(target_arch = "arm", target_os = "ios"))]
|
2015-03-25 17:06:52 -07:00
|
|
|
pub const unwinder_private_data_size: usize = 5;
|
2014-05-05 10:07:49 +03:00
|
|
|
|
2014-12-12 23:39:27 +00:00
|
|
|
#[cfg(target_arch = "aarch64")]
|
2015-03-25 17:06:52 -07:00
|
|
|
pub const unwinder_private_data_size: usize = 2;
|
2014-12-12 23:39:27 +00:00
|
|
|
|
2016-01-30 13:27:00 -08:00
|
|
|
#[cfg(target_arch = "mips")]
|
2015-03-25 17:06:52 -07:00
|
|
|
pub const unwinder_private_data_size: usize = 2;
|
2014-03-13 14:35:24 +08:00
|
|
|
|
2016-01-30 13:27:00 -08:00
|
|
|
#[cfg(any(target_arch = "powerpc", target_arch = "powerpc64"))]
|
2015-03-25 17:06:52 -07:00
|
|
|
pub const unwinder_private_data_size: usize = 2;
|
2015-01-09 20:20:57 -08:00
|
|
|
|
2015-11-26 19:05:10 +00:00
|
|
|
#[cfg(target_arch = "asmjs")]
|
|
|
|
|
// FIXME: Copied from arm. Need to confirm.
|
|
|
|
|
pub const unwinder_private_data_size: usize = 20;
|
|
|
|
|
|
2014-05-26 23:56:52 -07:00
|
|
|
#[repr(C)]
|
2014-02-05 15:19:40 -08:00
|
|
|
pub struct _Unwind_Exception {
|
2014-03-27 15:09:47 -07:00
|
|
|
pub exception_class: _Unwind_Exception_Class,
|
|
|
|
|
pub exception_cleanup: _Unwind_Exception_Cleanup_Fn,
|
2015-01-01 17:40:24 +13:00
|
|
|
pub private: [_Unwind_Word; unwinder_private_data_size],
|
2014-02-05 15:19:40 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub enum _Unwind_Context {}
|
|
|
|
|
|
2016-05-29 08:47:51 +05:30
|
|
|
pub type _Unwind_Exception_Cleanup_Fn = extern "C" fn(unwind_code: _Unwind_Reason_Code,
|
|
|
|
|
exception: *mut _Unwind_Exception);
|
2014-02-05 15:19:40 -08:00
|
|
|
|
2015-10-18 16:13:48 -07:00
|
|
|
#[cfg_attr(any(all(target_os = "linux", not(target_env = "musl")),
|
2016-01-25 16:23:31 -05:00
|
|
|
target_os = "freebsd",
|
2016-01-28 14:02:31 +03:00
|
|
|
target_os = "solaris",
|
2016-03-06 08:19:51 -05:00
|
|
|
all(target_os = "linux",
|
|
|
|
|
target_env = "musl",
|
|
|
|
|
not(target_arch = "x86"),
|
|
|
|
|
not(target_arch = "x86_64"))),
|
2015-10-18 16:13:48 -07:00
|
|
|
link(name = "gcc_s"))]
|
2016-03-06 08:19:51 -05:00
|
|
|
#[cfg_attr(all(target_os = "linux",
|
|
|
|
|
target_env = "musl",
|
|
|
|
|
any(target_arch = "x86", target_arch = "x86_64"),
|
|
|
|
|
not(test)),
|
2015-10-18 16:13:48 -07:00
|
|
|
link(name = "unwind", kind = "static"))]
|
|
|
|
|
#[cfg_attr(any(target_os = "android", target_os = "openbsd"),
|
|
|
|
|
link(name = "gcc"))]
|
|
|
|
|
#[cfg_attr(all(target_os = "netbsd", not(target_vendor = "rumprun")),
|
|
|
|
|
link(name = "gcc"))]
|
|
|
|
|
#[cfg_attr(all(target_os = "netbsd", target_vendor = "rumprun"),
|
|
|
|
|
link(name = "unwind"))]
|
|
|
|
|
#[cfg_attr(target_os = "dragonfly",
|
|
|
|
|
link(name = "gcc_pic"))]
|
|
|
|
|
#[cfg_attr(target_os = "bitrig",
|
|
|
|
|
link(name = "c++abi"))]
|
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 16:18:40 -07:00
|
|
|
#[cfg_attr(all(target_os = "windows", target_env = "gnu"),
|
2015-10-18 16:13:48 -07:00
|
|
|
link(name = "gcc_eh"))]
|
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 16:18:40 -07:00
|
|
|
#[cfg(not(cargobuild))]
|
2016-05-29 08:47:51 +05:30
|
|
|
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 16:18:40 -07:00
|
|
|
|
2016-05-29 08:47:51 +05:30
|
|
|
extern "C" {
|
2014-05-05 10:07:49 +03:00
|
|
|
// iOS on armv7 uses SjLj exceptions and requires to link
|
2014-07-02 21:27:07 -04:00
|
|
|
// against corresponding routine (..._SjLj_...)
|
2014-09-28 23:38:24 -07:00
|
|
|
#[cfg(not(all(target_os = "ios", target_arch = "arm")))]
|
2015-09-11 20:10:43 +02:00
|
|
|
#[unwind]
|
2016-05-29 08:47:51 +05:30
|
|
|
pub fn _Unwind_RaiseException(exception: *mut _Unwind_Exception) -> _Unwind_Reason_Code;
|
2014-06-13 10:18:12 +03:00
|
|
|
|
2014-09-28 23:38:24 -07:00
|
|
|
#[cfg(all(target_os = "ios", target_arch = "arm"))]
|
2015-09-11 20:10:43 +02:00
|
|
|
#[unwind]
|
2016-05-29 08:47:51 +05:30
|
|
|
fn _Unwind_SjLj_RaiseException(e: *mut _Unwind_Exception) -> _Unwind_Reason_Code;
|
2014-06-13 10:18:12 +03:00
|
|
|
|
2014-06-25 12:47:34 -07:00
|
|
|
pub fn _Unwind_DeleteException(exception: *mut _Unwind_Exception);
|
2015-10-18 14:28:47 -07:00
|
|
|
|
|
|
|
|
#[unwind]
|
|
|
|
|
pub fn _Unwind_Resume(exception: *mut _Unwind_Exception) -> !;
|
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 16:18:40 -07:00
|
|
|
|
|
|
|
|
// No native _Unwind_Backtrace on iOS
|
|
|
|
|
#[cfg(not(all(target_os = "ios", target_arch = "arm")))]
|
|
|
|
|
pub fn _Unwind_Backtrace(trace: _Unwind_Trace_Fn,
|
|
|
|
|
trace_argument: *mut libc::c_void)
|
2016-05-29 08:47:51 +05:30
|
|
|
-> _Unwind_Reason_Code;
|
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 16:18:40 -07:00
|
|
|
|
|
|
|
|
// available since GCC 4.2.0, should be fine for our purpose
|
|
|
|
|
#[cfg(all(not(all(target_os = "android", target_arch = "arm")),
|
|
|
|
|
not(all(target_os = "linux", target_arch = "arm"))))]
|
|
|
|
|
pub fn _Unwind_GetIPInfo(ctx: *mut _Unwind_Context,
|
|
|
|
|
ip_before_insn: *mut libc::c_int)
|
2016-05-29 08:47:51 +05:30
|
|
|
-> libc::uintptr_t;
|
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 16:18:40 -07:00
|
|
|
|
|
|
|
|
#[cfg(all(not(target_os = "android"),
|
|
|
|
|
not(all(target_os = "linux", target_arch = "arm"))))]
|
2016-05-29 08:47:51 +05:30
|
|
|
pub fn _Unwind_FindEnclosingFunction(pc: *mut libc::c_void) -> *mut libc::c_void;
|
2014-02-05 15:19:40 -08:00
|
|
|
}
|
2014-05-05 10:07:49 +03: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-28 23:38:24 -07:00
|
|
|
#[cfg(all(target_os = "ios", target_arch = "arm"))]
|
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 16:18:40 -07:00
|
|
|
#[inline]
|
2016-05-29 08:47:51 +05:30
|
|
|
pub unsafe fn _Unwind_RaiseException(exc: *mut _Unwind_Exception) -> _Unwind_Reason_Code {
|
2014-05-05 10:07:49 +03:00
|
|
|
_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 16:18:40 -07:00
|
|
|
|
|
|
|
|
// On android, the function _Unwind_GetIP is a macro, and this is the
|
|
|
|
|
// expansion of the macro. This is all copy/pasted directly from the
|
|
|
|
|
// header file with the definition of _Unwind_GetIP.
|
|
|
|
|
#[cfg(any(all(target_os = "android", target_arch = "arm"),
|
|
|
|
|
all(target_os = "linux", target_arch = "arm")))]
|
|
|
|
|
pub unsafe fn _Unwind_GetIP(ctx: *mut _Unwind_Context) -> libc::uintptr_t {
|
|
|
|
|
#[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,
|
|
|
|
|
}
|
|
|
|
|
#[repr(C)]
|
|
|
|
|
enum _Unwind_VRS_DataRepresentation {
|
|
|
|
|
_UVRSD_UINT32 = 0,
|
|
|
|
|
_UVRSD_VFPX = 1,
|
|
|
|
|
_UVRSD_FPAX = 2,
|
|
|
|
|
_UVRSD_UINT64 = 3,
|
|
|
|
|
_UVRSD_FLOAT = 4,
|
|
|
|
|
_UVRSD_DOUBLE = 5,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type _Unwind_Word = libc::c_uint;
|
2016-05-29 08:47:51 +05:30
|
|
|
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 16:18:40 -07:00
|
|
|
fn _Unwind_VRS_Get(ctx: *mut _Unwind_Context,
|
|
|
|
|
klass: _Unwind_VRS_RegClass,
|
|
|
|
|
word: _Unwind_Word,
|
|
|
|
|
repr: _Unwind_VRS_DataRepresentation,
|
|
|
|
|
data: *mut libc::c_void)
|
2016-05-29 08:47:51 +05:30
|
|
|
-> _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 16:18:40 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let mut val: _Unwind_Word = 0;
|
|
|
|
|
let ptr = &mut val as *mut _Unwind_Word;
|
2016-05-29 08:47:51 +05:30
|
|
|
let _ = _Unwind_VRS_Get(ctx,
|
|
|
|
|
_Unwind_VRS_RegClass::_UVRSC_CORE,
|
|
|
|
|
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 16:18:40 -07:00
|
|
|
_Unwind_VRS_DataRepresentation::_UVRSD_UINT32,
|
|
|
|
|
ptr as *mut libc::c_void);
|
|
|
|
|
(val & !1) as libc::uintptr_t
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// This function doesn't exist on Android or ARM/Linux, so make it same
|
|
|
|
|
// to _Unwind_GetIP
|
|
|
|
|
#[cfg(any(all(target_os = "android", target_arch = "arm"),
|
|
|
|
|
all(target_os = "linux", target_arch = "arm")))]
|
|
|
|
|
pub unsafe fn _Unwind_GetIPInfo(ctx: *mut _Unwind_Context,
|
|
|
|
|
ip_before_insn: *mut libc::c_int)
|
2016-05-29 08:47:51 +05:30
|
|
|
-> libc::uintptr_t {
|
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 16:18:40 -07:00
|
|
|
*ip_before_insn = 0;
|
|
|
|
|
_Unwind_GetIP(ctx)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// This function also doesn't exist on Android or ARM/Linux, so make it
|
|
|
|
|
// a no-op
|
|
|
|
|
#[cfg(any(target_os = "android",
|
|
|
|
|
all(target_os = "linux", target_arch = "arm")))]
|
2016-05-29 08:47:51 +05:30
|
|
|
pub unsafe fn _Unwind_FindEnclosingFunction(pc: *mut libc::c_void) -> *mut libc::c_void {
|
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 16:18:40 -07:00
|
|
|
pc
|
|
|
|
|
}
|