Skip to content

Commit

Permalink
Use cfg_if in libpanic_abort.
Browse files Browse the repository at this point in the history
This allows setting a default abort using the core intrinsic.
  • Loading branch information
ehuss committed Jul 15, 2020
1 parent 432b4c1 commit 9e58908
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 16 deletions.
1 change: 1 addition & 0 deletions Cargo.lock
Expand Up @@ -2056,6 +2056,7 @@ dependencies = [
name = "panic_abort"
version = "0.0.0"
dependencies = [
"cfg-if",
"compiler_builtins",
"core",
"libc",
Expand Down
1 change: 1 addition & 0 deletions src/libpanic_abort/Cargo.toml
Expand Up @@ -11,6 +11,7 @@ bench = false
doc = false

[dependencies]
cfg-if = { version = "0.1.8", features = ['rustc-dep-of-std'] }
core = { path = "../libcore" }
libc = { version = "0.2", default-features = false }
compiler_builtins = "0.1.0"
34 changes: 18 additions & 16 deletions src/libpanic_abort/lib.rs
Expand Up @@ -40,23 +40,25 @@ pub unsafe extern "C" fn __rust_panic_cleanup(_: *mut u8) -> *mut (dyn Any + Sen
pub unsafe extern "C" fn __rust_start_panic(_payload: usize) -> u32 {
abort();

#[cfg(any(unix, target_os = "cloudabi"))]
unsafe fn abort() -> ! {
libc::abort();
}

#[cfg(any(windows, all(target_arch = "wasm32", not(target_os = "emscripten"))))]
unsafe fn abort() -> ! {
core::intrinsics::abort();
}

#[cfg(any(target_os = "hermit", all(target_vendor = "fortanix", target_env = "sgx")))]
unsafe fn abort() -> ! {
// call std::sys::abort_internal
extern "C" {
pub fn __rust_abort() -> !;
cfg_if::cfg_if! {
if #[cfg(any(unix, target_os = "cloudabi"))] {
unsafe fn abort() -> ! {
libc::abort();
}
} else if #[cfg(any(target_os = "hermit",
all(target_vendor = "fortanix", target_env = "sgx")))] {
unsafe fn abort() -> ! {
// call std::sys::abort_internal
extern "C" {
pub fn __rust_abort() -> !;
}
__rust_abort();
}
} else {
unsafe fn abort() -> ! {
core::intrinsics::abort();
}
}
__rust_abort();
}
}

Expand Down

0 comments on commit 9e58908

Please sign in to comment.