From af45cc8701deb2e03b200f1129032466430c6253 Mon Sep 17 00:00:00 2001 From: Gary Guo Date: Thu, 26 Aug 2021 10:58:26 +0100 Subject: [PATCH] Move dummy panic handler to lib as well --- Cargo.toml | 1 + cdylib/Cargo.toml | 2 +- cdylib/src/lib.rs | 9 --------- src/lib.rs | 7 ++++++- src/panic_handler_dummy.rs | 6 ++++++ 5 files changed, 14 insertions(+), 11 deletions(-) create mode 100644 src/panic_handler_dummy.rs diff --git a/Cargo.toml b/Cargo.toml index d1e873e..6ad469f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,6 +23,7 @@ personality-dummy = [] print = ["libc"] panic = ["alloc"] panic-handler = ["print", "panic"] +panic-handler-dummy = [] system-alloc = [] default = ["dwarf-expr", "hide-trace", "fde-phdr", "fde-registry"] diff --git a/cdylib/Cargo.toml b/cdylib/Cargo.toml index ae0e0a0..c8fd029 100644 --- a/cdylib/Cargo.toml +++ b/cdylib/Cargo.toml @@ -8,5 +8,5 @@ edition = "2018" crate-type = ["cdylib"] [dependencies] -unwind = { path = "../", features = ["system-alloc", "personality-dummy"] } +unwind = { path = "../", features = ["system-alloc", "personality-dummy", "panic-handler-dummy"] } libc = "0.2" diff --git a/cdylib/src/lib.rs b/cdylib/src/lib.rs index df6c43b..91679f8 100644 --- a/cdylib/src/lib.rs +++ b/cdylib/src/lib.rs @@ -1,17 +1,8 @@ #![no_std] #![feature(default_alloc_error_handler)] -#![feature(lang_items)] #![warn(rust_2018_idioms)] #![warn(unsafe_op_in_unsafe_fn)] // Keep this explicit #[allow(unused_extern_crates)] extern crate unwind; - -use core::panic::PanicInfo; - -#[panic_handler] -fn panic(_info: &PanicInfo<'_>) -> ! { - // `unwind` crate should never panic. - unsafe { core::hint::unreachable_unchecked() } -} diff --git a/src/lib.rs b/src/lib.rs index 1e2e323..00ba6b0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -5,7 +5,10 @@ any(feature = "personality", feature = "personality-dummy"), feature(lang_items) )] -#![cfg_attr(feature = "panic", feature(core_intrinsics))] +#![cfg_attr( + any(feature = "panic", feature = "panic-handler-dummy"), + feature(core_intrinsics) +)] #![cfg_attr(feature = "panic-handler", feature(thread_local))] #![warn(rust_2018_idioms)] #![warn(unsafe_op_in_unsafe_fn)] @@ -34,6 +37,8 @@ pub mod panic; #[cfg(feature = "panic-handler")] pub mod panic_handler; +#[cfg(feature = "panic-handler-dummy")] +pub mod panic_handler_dummy; #[cfg(feature = "system-alloc")] mod system_alloc; diff --git a/src/panic_handler_dummy.rs b/src/panic_handler_dummy.rs new file mode 100644 index 0000000..74c8a5d --- /dev/null +++ b/src/panic_handler_dummy.rs @@ -0,0 +1,6 @@ +use core::panic::PanicInfo; + +#[panic_handler] +fn panic(_info: &PanicInfo<'_>) -> ! { + core::intrinsics::abort(); +}