فهرست منبع

Move dummy panic handler to lib as well

Gary Guo 3 سال پیش
والد
کامیت
af45cc8701
5فایلهای تغییر یافته به همراه14 افزوده شده و 11 حذف شده
  1. 1 0
      Cargo.toml
  2. 1 1
      cdylib/Cargo.toml
  3. 0 9
      cdylib/src/lib.rs
  4. 6 1
      src/lib.rs
  5. 6 0
      src/panic_handler_dummy.rs

+ 1 - 0
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"]
 

+ 1 - 1
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"

+ 0 - 9
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() }
-}

+ 6 - 1
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;

+ 6 - 0
src/panic_handler_dummy.rs

@@ -0,0 +1,6 @@
+use core::panic::PanicInfo;
+
+#[panic_handler]
+fn panic(_info: &PanicInfo<'_>) -> ! {
+    core::intrinsics::abort();
+}