Skip to content

Commit 9e58908

Browse files
committed
Use cfg_if in libpanic_abort.
This allows setting a default abort using the core intrinsic.
1 parent 432b4c1 commit 9e58908

File tree

3 files changed

+20
-16
lines changed

3 files changed

+20
-16
lines changed

Cargo.lock

+1
Original file line numberDiff line numberDiff line change
@@ -2056,6 +2056,7 @@ dependencies = [
20562056
name = "panic_abort"
20572057
version = "0.0.0"
20582058
dependencies = [
2059+
"cfg-if",
20592060
"compiler_builtins",
20602061
"core",
20612062
"libc",

src/libpanic_abort/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ bench = false
1111
doc = false
1212

1313
[dependencies]
14+
cfg-if = { version = "0.1.8", features = ['rustc-dep-of-std'] }
1415
core = { path = "../libcore" }
1516
libc = { version = "0.2", default-features = false }
1617
compiler_builtins = "0.1.0"

src/libpanic_abort/lib.rs

+18-16
Original file line numberDiff line numberDiff line change
@@ -40,23 +40,25 @@ pub unsafe extern "C" fn __rust_panic_cleanup(_: *mut u8) -> *mut (dyn Any + Sen
4040
pub unsafe extern "C" fn __rust_start_panic(_payload: usize) -> u32 {
4141
abort();
4242

43-
#[cfg(any(unix, target_os = "cloudabi"))]
44-
unsafe fn abort() -> ! {
45-
libc::abort();
46-
}
47-
48-
#[cfg(any(windows, all(target_arch = "wasm32", not(target_os = "emscripten"))))]
49-
unsafe fn abort() -> ! {
50-
core::intrinsics::abort();
51-
}
52-
53-
#[cfg(any(target_os = "hermit", all(target_vendor = "fortanix", target_env = "sgx")))]
54-
unsafe fn abort() -> ! {
55-
// call std::sys::abort_internal
56-
extern "C" {
57-
pub fn __rust_abort() -> !;
43+
cfg_if::cfg_if! {
44+
if #[cfg(any(unix, target_os = "cloudabi"))] {
45+
unsafe fn abort() -> ! {
46+
libc::abort();
47+
}
48+
} else if #[cfg(any(target_os = "hermit",
49+
all(target_vendor = "fortanix", target_env = "sgx")))] {
50+
unsafe fn abort() -> ! {
51+
// call std::sys::abort_internal
52+
extern "C" {
53+
pub fn __rust_abort() -> !;
54+
}
55+
__rust_abort();
56+
}
57+
} else {
58+
unsafe fn abort() -> ! {
59+
core::intrinsics::abort();
60+
}
5861
}
59-
__rust_abort();
6062
}
6163
}
6264

0 commit comments

Comments
 (0)