Skip to content

Commit

Permalink
Apply review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
Amanieu committed Mar 2, 2020
1 parent 35349ab commit 01d0494
Show file tree
Hide file tree
Showing 12 changed files with 40 additions and 68 deletions.
1 change: 1 addition & 0 deletions Cargo.lock
Expand Up @@ -2308,6 +2308,7 @@ dependencies = [
name = "panic_abort"
version = "0.0.0"
dependencies = [
"cfg-if",
"compiler_builtins",
"core",
"libc",
Expand Down
1 change: 1 addition & 0 deletions src/libpanic_abort/Cargo.toml
Expand Up @@ -14,3 +14,4 @@ doc = false
core = { path = "../libcore" }
libc = { version = "0.2", default-features = false }
compiler_builtins = "0.1.0"
cfg-if = "0.1.8"
5 changes: 4 additions & 1 deletion src/libpanic_abort/lib.rs
Expand Up @@ -20,8 +20,11 @@

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!()
}

Expand Down
2 changes: 0 additions & 2 deletions src/libpanic_unwind/dummy.rs
Expand Up @@ -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()
}
Expand Down
2 changes: 0 additions & 2 deletions src/libpanic_unwind/emcc.rs
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions src/libpanic_unwind/gcc.rs
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions src/libpanic_unwind/hermit.rs
Expand Up @@ -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() -> !;
Expand Down
12 changes: 7 additions & 5 deletions src/libpanic_unwind/lib.rs
Expand Up @@ -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"]
Expand All @@ -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`.
Expand All @@ -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))
}

Expand Down
21 changes: 21 additions & 0 deletions 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;
}
}
2 changes: 0 additions & 2 deletions src/libpanic_unwind/seh.rs
Expand Up @@ -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 _ })
}
Expand Down
34 changes: 6 additions & 28 deletions src/libstd/panicking.rs
Expand Up @@ -28,30 +28,8 @@ use crate::io::set_panic;
#[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.
//
Expand All @@ -67,7 +45,7 @@ cfg_if::cfg_if! {
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
Expand Down Expand Up @@ -297,7 +275,7 @@ pub unsafe fn r#try<R, F: FnOnce() -> R>(f: F) -> Result<R, Box<dyn Any + Send>>
// 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 _;
Expand All @@ -312,8 +290,8 @@ pub unsafe fn r#try<R, F: FnOnce() -> R>(f: F) -> Result<R, Box<dyn Any + Send>>
// 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
}
Expand Down
24 changes: 0 additions & 24 deletions src/test/ui/no-landing-pads.rs

This file was deleted.

0 comments on commit 01d0494

Please sign in to comment.