Skip to content

Commit 704991c

Browse files
authored
Rollup merge of #102742 - bjorn3:cleanup_rust_start_panic, r=ChrisDenton
Remove unnecessary raw pointer in __rust_start_panic arg It is no longer necessary as __rust_start_panic switched to the Rust abi.
2 parents fe0b042 + b874502 commit 704991c

File tree

4 files changed

+10
-15
lines changed

4 files changed

+10
-15
lines changed

library/panic_abort/src/android.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ type SetAbortMessageType = unsafe extern "C" fn(*const libc::c_char) -> ();
1515
//
1616
// Weakly resolve the symbol for android_set_abort_message. This function is only available
1717
// for API >= 21.
18-
pub(crate) unsafe fn android_set_abort_message(payload: *mut &mut dyn BoxMeUp) {
18+
pub(crate) unsafe fn android_set_abort_message(payload: &mut dyn BoxMeUp) {
1919
let func_addr =
2020
libc::dlsym(libc::RTLD_DEFAULT, ANDROID_SET_ABORT_MESSAGE.as_ptr() as *const libc::c_char)
2121
as usize;
2222
if func_addr == 0 {
2323
return;
2424
}
2525

26-
let payload = (*payload).get();
26+
let payload = payload.get();
2727
let msg = match payload.downcast_ref::<&'static str>() {
2828
Some(msg) => msg.as_bytes(),
2929
None => match payload.downcast_ref::<String>() {

library/panic_abort/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub unsafe extern "C" fn __rust_panic_cleanup(_: *mut u8) -> *mut (dyn Any + Sen
2929

3030
// "Leak" the payload and shim to the relevant abort on the platform in question.
3131
#[rustc_std_internal_symbol]
32-
pub unsafe fn __rust_start_panic(_payload: *mut &mut dyn BoxMeUp) -> u32 {
32+
pub unsafe fn __rust_start_panic(_payload: &mut dyn BoxMeUp) -> u32 {
3333
// Android has the ability to attach a message as part of the abort.
3434
#[cfg(target_os = "android")]
3535
android::android_set_abort_message(_payload);

library/panic_unwind/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ pub unsafe extern "C" fn __rust_panic_cleanup(payload: *mut u8) -> *mut (dyn Any
9999
// Entry point for raising an exception, just delegates to the platform-specific
100100
// implementation.
101101
#[rustc_std_internal_symbol]
102-
pub unsafe fn __rust_start_panic(payload: *mut &mut dyn BoxMeUp) -> u32 {
103-
let payload = Box::from_raw((*payload).take_box());
102+
pub unsafe fn __rust_start_panic(payload: &mut dyn BoxMeUp) -> u32 {
103+
let payload = Box::from_raw(payload.take_box());
104104

105105
imp::panic(payload)
106106
}

library/std/src/panicking.rs

+5-10
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,10 @@ extern "C" {
4646
fn __rust_panic_cleanup(payload: *mut u8) -> *mut (dyn Any + Send + 'static);
4747
}
4848

49-
#[allow(improper_ctypes)]
5049
extern "Rust" {
51-
/// `payload` is passed through another layer of raw pointers as `&mut dyn Trait` is not
52-
/// FFI-safe. `BoxMeUp` lazily performs allocation only when needed (this avoids allocations
53-
/// when using the "abort" panic runtime).
54-
fn __rust_start_panic(payload: *mut &mut dyn BoxMeUp) -> u32;
50+
/// `BoxMeUp` lazily performs allocation only when needed (this avoids
51+
/// allocations when using the "abort" panic runtime).
52+
fn __rust_start_panic(payload: &mut dyn BoxMeUp) -> u32;
5553
}
5654

5755
/// This function is called by the panic runtime if FFI code catches a Rust
@@ -738,10 +736,7 @@ pub fn rust_panic_without_hook(payload: Box<dyn Any + Send>) -> ! {
738736
/// yer breakpoints.
739737
#[inline(never)]
740738
#[cfg_attr(not(test), rustc_std_internal_symbol)]
741-
fn rust_panic(mut msg: &mut dyn BoxMeUp) -> ! {
742-
let code = unsafe {
743-
let obj = &mut msg as *mut &mut dyn BoxMeUp;
744-
__rust_start_panic(obj)
745-
};
739+
fn rust_panic(msg: &mut dyn BoxMeUp) -> ! {
740+
let code = unsafe { __rust_start_panic(msg) };
746741
rtabort!("failed to initiate panic, error {code}")
747742
}

0 commit comments

Comments
 (0)