about summary refs log tree commit diff
path: root/src/libpanic_unwind
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2019-11-12 21:27:04 +0000
committerbors <bors@rust-lang.org>2019-11-12 21:27:04 +0000
commita333eed7fc0c903df9d6befcfb40af02148bf255 (patch)
treef58c8bd9ef3b92b31916f3a4eda588a00e41fb75 /src/libpanic_unwind
parent4f03f4a989d1c8346c19dfb417a77c09b34408b8 (diff)
parentb4545a4ad625c68479120db845280f4c61b39640 (diff)
Auto merge of #60026 - Aaron1011:feature/miri-unwind, r=RalfJung,oli-obk
Add hooks for Miri panic unwinding

This commits adds in some additional hooks to allow Miri to properly
handle panic unwinding. None of this should have any impact on CTFE mode

This supports https://github.com/rust-lang/miri/pull/693
Diffstat (limited to 'src/libpanic_unwind')
-rw-r--r--src/libpanic_unwind/lib.rs5
-rw-r--r--src/libpanic_unwind/miri.rs23
2 files changed, 27 insertions, 1 deletions
diff --git a/src/libpanic_unwind/lib.rs b/src/libpanic_unwind/lib.rs
index 7de347446ad..4c6c728f6f7 100644
--- a/src/libpanic_unwind/lib.rs
+++ b/src/libpanic_unwind/lib.rs
@@ -36,7 +36,10 @@ use core::raw;
 use core::panic::BoxMeUp;
 
 cfg_if::cfg_if! {
-    if #[cfg(target_os = "emscripten")] {
+    if #[cfg(miri)] {
+        #[path = "miri.rs"]
+        mod imp;
+    } else if #[cfg(target_os = "emscripten")] {
         #[path = "emcc.rs"]
         mod imp;
     } else if #[cfg(target_arch = "wasm32")] {
diff --git a/src/libpanic_unwind/miri.rs b/src/libpanic_unwind/miri.rs
new file mode 100644
index 00000000000..254a9383b42
--- /dev/null
+++ b/src/libpanic_unwind/miri.rs
@@ -0,0 +1,23 @@
+use core::any::Any;
+use alloc::boxed::Box;
+
+pub fn payload() -> *mut u8 {
+    core::ptr::null_mut()
+}
+
+pub unsafe fn panic(data: Box<dyn Any + Send>) -> ! {
+    core::intrinsics::miri_start_panic(Box::into_raw(data))
+}
+
+pub unsafe fn cleanup(ptr: *mut u8) -> Box<dyn Any + Send> {
+    Box::from_raw(ptr)
+}
+
+
+// This is required by the compiler to exist (e.g., it's a lang item),
+// but is never used by Miri. Therefore, we just use a stub here
+#[lang = "eh_personality"]
+#[cfg(not(test))]
+fn rust_eh_personality() {
+    unsafe { core::intrinsics::abort() }
+}