Skip to content

Commit da5b1a4

Browse files
committed
Apply review feedback
1 parent 5be658a commit da5b1a4

File tree

12 files changed

+40
-68
lines changed

12 files changed

+40
-68
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2301,6 +2301,7 @@ dependencies = [
23012301
name = "panic_abort"
23022302
version = "0.0.0"
23032303
dependencies = [
2304+
"cfg-if",
23042305
"compiler_builtins",
23052306
"core",
23062307
"libc",

src/libpanic_abort/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ doc = false
1414
core = { path = "../libcore" }
1515
libc = { version = "0.2", default-features = false }
1616
compiler_builtins = "0.1.0"
17+
cfg-if = "0.1.8"

src/libpanic_abort/lib.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,11 @@
2020

2121
use core::any::Any;
2222

23+
// We need the definition of TryPayload for __rust_panic_cleanup.
24+
include!("../libpanic_unwind/payload.rs");
25+
2326
#[rustc_std_internal_symbol]
24-
pub unsafe extern "C" fn __rust_panic_cleanup(_: *mut u8) -> *mut (dyn Any + Send + 'static) {
27+
pub unsafe extern "C" fn __rust_panic_cleanup(_: TryPayload) -> *mut (dyn Any + Send + 'static) {
2528
unreachable!()
2629
}
2730

src/libpanic_unwind/dummy.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ use alloc::boxed::Box;
66
use core::any::Any;
77
use core::intrinsics;
88

9-
pub type Payload = *mut u8;
10-
119
pub unsafe fn cleanup(_ptr: *mut u8) -> Box<dyn Any + Send> {
1210
intrinsics::abort()
1311
}

src/libpanic_unwind/emcc.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,6 @@ static EXCEPTION_TYPE_INFO: TypeInfo = TypeInfo {
4848
name: b"rust_panic\0".as_ptr(),
4949
};
5050

51-
pub type Payload = *mut u8;
52-
5351
pub unsafe fn cleanup(ptr: *mut u8) -> Box<dyn Any + Send> {
5452
assert!(!ptr.is_null());
5553
let adjusted_ptr = __cxa_begin_catch(ptr as *mut libc::c_void);

src/libpanic_unwind/gcc.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,6 @@ pub unsafe fn panic(data: Box<dyn Any + Send>) -> u32 {
8181
}
8282
}
8383

84-
pub type Payload = *mut u8;
85-
8684
pub unsafe fn cleanup(ptr: *mut u8) -> Box<dyn Any + Send> {
8785
let my_ep = ptr as *mut Exception;
8886
let cause = (*my_ep).cause.take();

src/libpanic_unwind/hermit.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ use alloc::boxed::Box;
66
use core::any::Any;
77
use core::ptr;
88

9-
pub type Payload = *mut u8;
10-
119
pub unsafe fn cleanup(_ptr: *mut u8) -> Box<dyn Any + Send> {
1210
extern "C" {
1311
pub fn __rust_abort() -> !;

src/libpanic_unwind/lib.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ use alloc::boxed::Box;
3434
use core::any::Any;
3535
use core::panic::BoxMeUp;
3636

37-
// If adding to this list, you should also look at libstd::panicking's identical
38-
// list of Payload types and likely add to there as well.
37+
// If adding to this list, you should also look at the list of TryPayload types
38+
// defined in payload.rs and likely add to there as well.
3939
cfg_if::cfg_if! {
4040
if #[cfg(target_os = "emscripten")] {
4141
#[path = "emcc.rs"]
@@ -61,12 +61,14 @@ cfg_if::cfg_if! {
6161
}
6262
}
6363

64+
include!("payload.rs");
65+
6466
mod dwarf;
6567

6668
#[no_mangle]
67-
pub unsafe extern "C" fn __rust_panic_cleanup(payload: *mut u8) -> *mut (dyn Any + Send + 'static) {
68-
let payload = payload as *mut imp::Payload;
69-
let payload = *(payload);
69+
pub unsafe extern "C" fn __rust_panic_cleanup(
70+
payload: TryPayload,
71+
) -> *mut (dyn Any + Send + 'static) {
7072
Box::into_raw(imp::cleanup(payload))
7173
}
7274

src/libpanic_unwind/payload.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Type definition for the payload argument of the try intrinsic.
2+
//
3+
// This must be kept in sync with the implementations of the try intrinsic.
4+
//
5+
// This file is included by both panic runtimes and libstd. It is part of the
6+
// panic runtime ABI.
7+
cfg_if::cfg_if! {
8+
if #[cfg(target_os = "emscripten")] {
9+
type TryPayload = *mut u8;
10+
} else if #[cfg(target_arch = "wasm32")] {
11+
type TryPayload = *mut u8;
12+
} else if #[cfg(target_os = "hermit")] {
13+
type TryPayload = *mut u8;
14+
} else if #[cfg(all(target_env = "msvc", target_arch = "aarch64"))] {
15+
type TryPayload = *mut u8;
16+
} else if #[cfg(target_env = "msvc")] {
17+
type TryPayload = [u64; 2];
18+
} else {
19+
type TryPayload = *mut u8;
20+
}
21+
}

src/libpanic_unwind/seh.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,8 +264,6 @@ pub unsafe fn panic(data: Box<dyn Any + Send>) -> u32 {
264264
_CxxThrowException(throw_ptr, &mut THROW_INFO as *mut _ as *mut _);
265265
}
266266

267-
pub type Payload = [u64; 2];
268-
269267
pub unsafe fn cleanup(payload: [u64; 2]) -> Box<dyn Any + Send> {
270268
mem::transmute(raw::TraitObject { data: payload[0] as *mut _, vtable: payload[1] as *mut _ })
271269
}

src/libstd/panicking.rs

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -28,30 +28,8 @@ use crate::io::set_panic;
2828
#[cfg(test)]
2929
use realstd::io::set_panic;
3030

31-
// This must be kept in sync with the implementations in libpanic_unwind.
32-
//
33-
// This is *not* checked in anyway; the compiler does not allow us to use a
34-
// type/macro/anything from panic_unwind, since we're then linking in the
35-
// panic_unwind runtime even during -Cpanic=abort.
36-
//
37-
// Essentially this must be the type of `imp::Payload` in libpanic_unwind.
38-
cfg_if::cfg_if! {
39-
if #[cfg(not(feature = "panic_unwind"))] {
40-
type Payload = ();
41-
} else if #[cfg(target_os = "emscripten")] {
42-
type Payload = *mut u8;
43-
} else if #[cfg(target_arch = "wasm32")] {
44-
type Payload = *mut u8;
45-
} else if #[cfg(target_os = "hermit")] {
46-
type Payload = *mut u8;
47-
} else if #[cfg(all(target_env = "msvc", target_arch = "aarch64"))] {
48-
type Payload = *mut u8;
49-
} else if #[cfg(target_env = "msvc")] {
50-
type Payload = [u64; 2];
51-
} else {
52-
type Payload = *mut u8;
53-
}
54-
}
31+
// Include the definition of UnwindPayload from libpanic_unwind.
32+
include!("../libpanic_unwind/payload.rs");
5533

5634
// Binary interface to the panic runtime that the standard library depends on.
5735
//
@@ -67,7 +45,7 @@ cfg_if::cfg_if! {
6745
extern "C" {
6846
/// The payload ptr here is actually the same as the payload ptr for the try
6947
/// intrinsic (i.e., is really `*mut [u64; 2]` or `*mut *mut u8`).
70-
fn __rust_panic_cleanup(payload: *mut u8) -> *mut (dyn Any + Send + 'static);
48+
fn __rust_panic_cleanup(payload: TryPayload) -> *mut (dyn Any + Send + 'static);
7149

7250
/// `payload` is actually a `*mut &mut dyn BoxMeUp` but that would cause FFI warnings.
7351
/// It cannot be `Box<dyn BoxMeUp>` because the other end of this call does not depend
@@ -288,7 +266,7 @@ pub unsafe fn r#try<R, F: FnOnce() -> R>(f: F) -> Result<R, Box<dyn Any + Send>>
288266
// method of calling a catch panic whilst juggling ownership.
289267
let mut data = Data { f: ManuallyDrop::new(f) };
290268

291-
let mut payload: MaybeUninit<Payload> = MaybeUninit::uninit();
269+
let mut payload: MaybeUninit<TryPayload> = MaybeUninit::uninit();
292270

293271
let data_ptr = &mut data as *mut _ as *mut u8;
294272
let payload_ptr = payload.as_mut_ptr() as *mut _;
@@ -304,8 +282,8 @@ pub unsafe fn r#try<R, F: FnOnce() -> R>(f: F) -> Result<R, Box<dyn Any + Send>>
304282
// optimizer (in most cases this function is not inlined even as a normal,
305283
// non-cold function, though, as of the writing of this comment).
306284
#[cold]
307-
unsafe fn cleanup(mut payload: Payload) -> Box<dyn Any + Send + 'static> {
308-
let obj = Box::from_raw(__rust_panic_cleanup(&mut payload as *mut _ as *mut u8));
285+
unsafe fn cleanup(payload: TryPayload) -> Box<dyn Any + Send + 'static> {
286+
let obj = Box::from_raw(__rust_panic_cleanup(payload));
309287
update_panic_count(-1);
310288
debug_assert!(update_panic_count(0) == 0);
311289
obj

src/test/ui/no-landing-pads.rs

Lines changed: 0 additions & 24 deletions
This file was deleted.

0 commit comments

Comments
 (0)