name = "panic_abort"
version = "0.0.0"
dependencies = [
+ "cfg-if",
"compiler_builtins",
"core",
"libc",
core = { path = "../libcore" }
libc = { version = "0.2", default-features = false }
compiler_builtins = "0.1.0"
+cfg-if = "0.1.8"
use core::any::Any;
+// We need the definition of TryPayload for __rust_panic_cleanup.
+include!("../libpanic_unwind/payload.rs");
+
#[rustc_std_internal_symbol]
-pub unsafe extern "C" fn __rust_panic_cleanup(_: *mut u8) -> *mut (dyn Any + Send + 'static) {
+pub unsafe extern "C" fn __rust_panic_cleanup(_: TryPayload) -> *mut (dyn Any + Send + 'static) {
unreachable!()
}
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()
}
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
}
}
-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
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() -> !;
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"]
}
}
+include!("payload.rs");
+
extern "C" {
/// Handler in libstd called when a panic object is dropped outside of
/// `catch_unwind`.
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))
}
--- /dev/null
+// 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;
+ }
+}
_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 _ })
}
#[cfg(test)]
use realstd::io::set_panic;
-// This must be kept in sync with the implementations in libpanic_unwind.
-//
-// This is *not* checked in anyway; the compiler does not allow us to use a
-// type/macro/anything from panic_unwind, since we're then linking in the
-// panic_unwind runtime even during -Cpanic=abort.
-//
-// Essentially this must be the type of `imp::Payload` in libpanic_unwind.
-cfg_if::cfg_if! {
- if #[cfg(not(feature = "panic_unwind"))] {
- type Payload = ();
- } else if #[cfg(target_os = "emscripten")] {
- type Payload = *mut u8;
- } else if #[cfg(target_arch = "wasm32")] {
- type Payload = *mut u8;
- } else if #[cfg(target_os = "hermit")] {
- type Payload = *mut u8;
- } else if #[cfg(all(target_env = "msvc", target_arch = "aarch64"))] {
- type Payload = *mut u8;
- } else if #[cfg(target_env = "msvc")] {
- type Payload = [u64; 2];
- } else {
- type Payload = *mut u8;
- }
-}
+// Include the definition of UnwindPayload from libpanic_unwind.
+include!("../libpanic_unwind/payload.rs");
// Binary interface to the panic runtime that the standard library depends on.
//
extern "C" {
/// The payload ptr here is actually the same as the payload ptr for the try
/// intrinsic (i.e., is really `*mut [u64; 2]` or `*mut *mut u8`).
- fn __rust_panic_cleanup(payload: *mut u8) -> *mut (dyn Any + Send + 'static);
+ fn __rust_panic_cleanup(payload: TryPayload) -> *mut (dyn Any + Send + 'static);
/// `payload` is actually a `*mut &mut dyn BoxMeUp` but that would cause FFI warnings.
/// It cannot be `Box<dyn BoxMeUp>` because the other end of this call does not depend
// method of calling a catch panic whilst juggling ownership.
let mut data = Data { f: ManuallyDrop::new(f) };
- let mut payload: MaybeUninit<Payload> = MaybeUninit::uninit();
+ let mut payload: MaybeUninit<TryPayload> = MaybeUninit::uninit();
let data_ptr = &mut data as *mut _ as *mut u8;
let payload_ptr = payload.as_mut_ptr() as *mut _;
// optimizer (in most cases this function is not inlined even as a normal,
// non-cold function, though, as of the writing of this comment).
#[cold]
- unsafe fn cleanup(mut payload: Payload) -> Box<dyn Any + Send + 'static> {
- let obj = Box::from_raw(__rust_panic_cleanup(&mut payload as *mut _ as *mut u8));
+ unsafe fn cleanup(payload: TryPayload) -> Box<dyn Any + Send + 'static> {
+ let obj = Box::from_raw(__rust_panic_cleanup(payload));
update_panic_count(-1);
obj
}
+++ /dev/null
-// run-pass
-// compile-flags: -Z no-landing-pads -C codegen-units=1
-// ignore-emscripten no threads support
-// ignore-test fails because catch_unwind doesn't work with no-landing-pads
-
-use std::thread;
-
-static mut HIT: bool = false;
-
-struct A;
-
-impl Drop for A {
- fn drop(&mut self) {
- unsafe { HIT = true; }
- }
-}
-
-fn main() {
- thread::spawn(move|| -> () {
- let _a = A;
- panic!();
- }).join().unwrap_err();
- assert!(unsafe { !HIT });
-}