about summary refs log tree commit diff
path: root/src/libpanic_unwind
diff options
context:
space:
mode:
authorAmanieu d'Antras <amanieu@gmail.com>2020-01-07 16:41:59 +0100
committerAmanieu d'Antras <amanieu@gmail.com>2020-03-02 11:43:07 +0000
commit01d04944cefc61cd684e3554e48068926a5f30ab (patch)
tree46acb587cf4decf0b11de1999de8a59e892a94ee /src/libpanic_unwind
parent35349abeb33893e9d683e507f819c16063e4797e (diff)
Apply review feedback
Diffstat (limited to 'src/libpanic_unwind')
-rw-r--r--src/libpanic_unwind/dummy.rs2
-rw-r--r--src/libpanic_unwind/emcc.rs2
-rw-r--r--src/libpanic_unwind/gcc.rs2
-rw-r--r--src/libpanic_unwind/hermit.rs2
-rw-r--r--src/libpanic_unwind/lib.rs12
-rw-r--r--src/libpanic_unwind/payload.rs21
-rw-r--r--src/libpanic_unwind/seh.rs2
7 files changed, 28 insertions, 15 deletions
diff --git a/src/libpanic_unwind/dummy.rs b/src/libpanic_unwind/dummy.rs
index 30593d3b88a..4667ede2baa 100644
--- a/src/libpanic_unwind/dummy.rs
+++ b/src/libpanic_unwind/dummy.rs
@@ -6,8 +6,6 @@ use alloc::boxed::Box;
 use core::any::Any;
 use core::intrinsics;
 
-pub type Payload = *mut u8;
-
 pub unsafe fn cleanup(_ptr: *mut u8) -> Box<dyn Any + Send> {
     intrinsics::abort()
 }
diff --git a/src/libpanic_unwind/emcc.rs b/src/libpanic_unwind/emcc.rs
index 873135414bd..e541ec30025 100644
--- a/src/libpanic_unwind/emcc.rs
+++ b/src/libpanic_unwind/emcc.rs
@@ -48,8 +48,6 @@ static EXCEPTION_TYPE_INFO: TypeInfo = TypeInfo {
     name: b"rust_panic\0".as_ptr(),
 };
 
-pub type Payload = *mut u8;
-
 struct Exception {
     // This needs to be an Option because the object's lifetime follows C++
     // semantics: when catch_unwind moves the Box out of the exception it must
diff --git a/src/libpanic_unwind/gcc.rs b/src/libpanic_unwind/gcc.rs
index dd84a814f48..20ae5edaa2a 100644
--- a/src/libpanic_unwind/gcc.rs
+++ b/src/libpanic_unwind/gcc.rs
@@ -82,8 +82,6 @@ pub unsafe fn panic(data: Box<dyn Any + Send>) -> u32 {
     }
 }
 
-pub type Payload = *mut u8;
-
 pub unsafe fn cleanup(ptr: *mut u8) -> Box<dyn Any + Send> {
     let exception = Box::from_raw(ptr as *mut Exception);
     exception.cause
diff --git a/src/libpanic_unwind/hermit.rs b/src/libpanic_unwind/hermit.rs
index 8ffb4bcd3df..6bded4dd499 100644
--- a/src/libpanic_unwind/hermit.rs
+++ b/src/libpanic_unwind/hermit.rs
@@ -6,8 +6,6 @@ use alloc::boxed::Box;
 use core::any::Any;
 use core::ptr;
 
-pub type Payload = *mut u8;
-
 pub unsafe fn cleanup(_ptr: *mut u8) -> Box<dyn Any + Send> {
     extern "C" {
         pub fn __rust_abort() -> !;
diff --git a/src/libpanic_unwind/lib.rs b/src/libpanic_unwind/lib.rs
index ad82f22510c..87d24841d04 100644
--- a/src/libpanic_unwind/lib.rs
+++ b/src/libpanic_unwind/lib.rs
@@ -35,8 +35,8 @@ use alloc::boxed::Box;
 use core::any::Any;
 use core::panic::BoxMeUp;
 
-// If adding to this list, you should also look at libstd::panicking's identical
-// list of Payload types and likely add to there as well.
+// If adding to this list, you should also look at the list of TryPayload types
+// defined in payload.rs and likely add to there as well.
 cfg_if::cfg_if! {
     if #[cfg(target_os = "emscripten")] {
         #[path = "emcc.rs"]
@@ -62,6 +62,8 @@ cfg_if::cfg_if! {
     }
 }
 
+include!("payload.rs");
+
 extern "C" {
     /// Handler in libstd called when a panic object is dropped outside of
     /// `catch_unwind`.
@@ -71,9 +73,9 @@ extern "C" {
 mod dwarf;
 
 #[no_mangle]
-pub unsafe extern "C" fn __rust_panic_cleanup(payload: *mut u8) -> *mut (dyn Any + Send + 'static) {
-    let payload = payload as *mut imp::Payload;
-    let payload = *(payload);
+pub unsafe extern "C" fn __rust_panic_cleanup(
+    payload: TryPayload,
+) -> *mut (dyn Any + Send + 'static) {
     Box::into_raw(imp::cleanup(payload))
 }
 
diff --git a/src/libpanic_unwind/payload.rs b/src/libpanic_unwind/payload.rs
new file mode 100644
index 00000000000..1234db7da0f
--- /dev/null
+++ b/src/libpanic_unwind/payload.rs
@@ -0,0 +1,21 @@
+// Type definition for the payload argument of the try intrinsic.
+//
+// This must be kept in sync with the implementations of the try intrinsic.
+//
+// This file is included by both panic runtimes and libstd. It is part of the
+// panic runtime ABI.
+cfg_if::cfg_if! {
+    if #[cfg(target_os = "emscripten")] {
+        type TryPayload = *mut u8;
+    } else if #[cfg(target_arch = "wasm32")] {
+        type TryPayload = *mut u8;
+    } else if #[cfg(target_os = "hermit")] {
+        type TryPayload = *mut u8;
+    } else if #[cfg(all(target_env = "msvc", target_arch = "aarch64"))] {
+        type TryPayload = *mut u8;
+    } else if #[cfg(target_env = "msvc")] {
+        type TryPayload = [u64; 2];
+    } else {
+        type TryPayload = *mut u8;
+    }
+}
diff --git a/src/libpanic_unwind/seh.rs b/src/libpanic_unwind/seh.rs
index 6f464c1ab68..da5ee5369e0 100644
--- a/src/libpanic_unwind/seh.rs
+++ b/src/libpanic_unwind/seh.rs
@@ -308,8 +308,6 @@ pub unsafe fn panic(data: Box<dyn Any + Send>) -> u32 {
     _CxxThrowException(throw_ptr, &mut THROW_INFO as *mut _ as *mut _);
 }
 
-pub type Payload = [u64; 2];
-
 pub unsafe fn cleanup(payload: [u64; 2]) -> Box<dyn Any + Send> {
     mem::transmute(raw::TraitObject { data: payload[0] as *mut _, vtable: payload[1] as *mut _ })
 }