Skip to content

Commit ed712e0

Browse files
committed
Apply review feedback
1 parent eb04e37 commit ed712e0

File tree

12 files changed

+40
-68
lines changed

12 files changed

+40
-68
lines changed

Cargo.lock

+1
Original file line numberDiff line numberDiff line change
@@ -2308,6 +2308,7 @@ dependencies = [
23082308
name = "panic_abort"
23092309
version = "0.0.0"
23102310
dependencies = [
2311+
"cfg-if",
23112312
"compiler_builtins",
23122313
"core",
23132314
"libc",

src/libpanic_abort/Cargo.toml

+1
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

+4-1
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

-2
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

-2
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
struct Exception {
5452
// This needs to be an Option because the object's lifetime follows C++
5553
// semantics: when catch_unwind moves the Box out of the exception it must

src/libpanic_unwind/gcc.rs

-2
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,6 @@ pub unsafe fn panic(data: Box<dyn Any + Send>) -> u32 {
8282
}
8383
}
8484

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

src/libpanic_unwind/hermit.rs

-2
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

+7-5
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ use alloc::boxed::Box;
3535
use core::any::Any;
3636
use core::panic::BoxMeUp;
3737

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

65+
include!("payload.rs");
66+
6567
extern "C" {
6668
/// Handler in libstd called when a panic object is dropped outside of
6769
/// `catch_unwind`.
@@ -71,9 +73,9 @@ extern "C" {
7173
mod dwarf;
7274

7375
#[no_mangle]
74-
pub unsafe extern "C" fn __rust_panic_cleanup(payload: *mut u8) -> *mut (dyn Any + Send + 'static) {
75-
let payload = payload as *mut imp::Payload;
76-
let payload = *(payload);
76+
pub unsafe extern "C" fn __rust_panic_cleanup(
77+
payload: TryPayload,
78+
) -> *mut (dyn Any + Send + 'static) {
7779
Box::into_raw(imp::cleanup(payload))
7880
}
7981

src/libpanic_unwind/payload.rs

+21
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

-2
Original file line numberDiff line numberDiff line change
@@ -308,8 +308,6 @@ pub unsafe fn panic(data: Box<dyn Any + Send>) -> u32 {
308308
_CxxThrowException(throw_ptr, &mut THROW_INFO as *mut _ as *mut _);
309309
}
310310

311-
pub type Payload = [u64; 2];
312-
313311
pub unsafe fn cleanup(payload: [u64; 2]) -> Box<dyn Any + Send> {
314312
mem::transmute(raw::TraitObject { data: payload[0] as *mut _, vtable: payload[1] as *mut _ })
315313
}

src/libstd/panicking.rs

+6-28
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
@@ -297,7 +275,7 @@ pub unsafe fn r#try<R, F: FnOnce() -> R>(f: F) -> Result<R, Box<dyn Any + Send>>
297275
// method of calling a catch panic whilst juggling ownership.
298276
let mut data = Data { f: ManuallyDrop::new(f) };
299277

300-
let mut payload: MaybeUninit<Payload> = MaybeUninit::uninit();
278+
let mut payload: MaybeUninit<TryPayload> = MaybeUninit::uninit();
301279

302280
let data_ptr = &mut data as *mut _ as *mut u8;
303281
let payload_ptr = payload.as_mut_ptr() as *mut _;
@@ -312,8 +290,8 @@ pub unsafe fn r#try<R, F: FnOnce() -> R>(f: F) -> Result<R, Box<dyn Any + Send>>
312290
// optimizer (in most cases this function is not inlined even as a normal,
313291
// non-cold function, though, as of the writing of this comment).
314292
#[cold]
315-
unsafe fn cleanup(mut payload: Payload) -> Box<dyn Any + Send + 'static> {
316-
let obj = Box::from_raw(__rust_panic_cleanup(&mut payload as *mut _ as *mut u8));
293+
unsafe fn cleanup(payload: TryPayload) -> Box<dyn Any + Send + 'static> {
294+
let obj = Box::from_raw(__rust_panic_cleanup(payload));
317295
update_panic_count(-1);
318296
obj
319297
}

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

-24
This file was deleted.

0 commit comments

Comments
 (0)