diff options
| author | Amanieu d'Antras <amanieu@gmail.com> | 2020-01-10 00:19:40 +0000 |
|---|---|---|
| committer | Amanieu d'Antras <amanieu@gmail.com> | 2020-01-11 10:18:44 +0000 |
| commit | 3a025760be8f4c56f0777fa34ba64a4f7bada8e7 (patch) | |
| tree | e9123f65a83caf1dea1e924a64963f99f9d22f84 /src/libpanic_unwind | |
| parent | 757ed07f374edfe93be5c9084ac5c44ba738e1b2 (diff) | |
Abort if C++ tries to swallow a Rust panic
Diffstat (limited to 'src/libpanic_unwind')
| -rw-r--r-- | src/libpanic_unwind/emcc.rs | 1 | ||||
| -rw-r--r-- | src/libpanic_unwind/gcc.rs | 1 | ||||
| -rw-r--r-- | src/libpanic_unwind/lib.rs | 6 | ||||
| -rw-r--r-- | src/libpanic_unwind/seh.rs | 1 |
4 files changed, 9 insertions, 0 deletions
diff --git a/src/libpanic_unwind/emcc.rs b/src/libpanic_unwind/emcc.rs index fbadf4ac6a0..268bafd2409 100644 --- a/src/libpanic_unwind/emcc.rs +++ b/src/libpanic_unwind/emcc.rs @@ -80,6 +80,7 @@ pub unsafe fn panic(data: Box<dyn Any + Send>) -> u32 { extern "C" fn exception_cleanup(ptr: *mut libc::c_void) { unsafe { ptr::drop_in_place(ptr as *mut Exception); + super::__rust_drop_panic(); } } } diff --git a/src/libpanic_unwind/gcc.rs b/src/libpanic_unwind/gcc.rs index 6bec2686533..6e04317d491 100644 --- a/src/libpanic_unwind/gcc.rs +++ b/src/libpanic_unwind/gcc.rs @@ -78,6 +78,7 @@ pub unsafe fn panic(data: Box<dyn Any + Send>) -> u32 { ) { unsafe { let _: Box<Exception> = Box::from_raw(exception as *mut Exception); + super::__rust_drop_panic(); } } } diff --git a/src/libpanic_unwind/lib.rs b/src/libpanic_unwind/lib.rs index 9451eefb9a5..6383ae39fb6 100644 --- a/src/libpanic_unwind/lib.rs +++ b/src/libpanic_unwind/lib.rs @@ -61,6 +61,12 @@ cfg_if::cfg_if! { } } +extern "C" { + /// Handler in libstd called when a panic object is dropped outside of + /// `catch_unwind`. + fn __rust_drop_panic() -> !; +} + mod dwarf; // Entry point for catching an exception, implemented using the `try` intrinsic diff --git a/src/libpanic_unwind/seh.rs b/src/libpanic_unwind/seh.rs index f1d0080472a..d9dca2c0f4f 100644 --- a/src/libpanic_unwind/seh.rs +++ b/src/libpanic_unwind/seh.rs @@ -229,6 +229,7 @@ macro_rules! define_cleanup { unsafe extern $abi fn exception_cleanup(e: *mut [u64; 2]) { if (*e)[0] != 0 { cleanup(*e); + super::__rust_drop_panic(); } } #[unwind(allowed)] |
