Skip to content

Commit

Permalink
Remove unnecessary raw pointer in __rust_start_panic arg
Browse files Browse the repository at this point in the history
It is no longer necessary as __rust_start_panic switched to the Rust abi.
  • Loading branch information
bjorn3 committed Mar 26, 2023
1 parent 89c2e3d commit b874502
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 15 deletions.
4 changes: 2 additions & 2 deletions library/panic_abort/src/android.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ type SetAbortMessageType = unsafe extern "C" fn(*const libc::c_char) -> ();
//
// Weakly resolve the symbol for android_set_abort_message. This function is only available
// for API >= 21.
pub(crate) unsafe fn android_set_abort_message(payload: *mut &mut dyn BoxMeUp) {
pub(crate) unsafe fn android_set_abort_message(payload: &mut dyn BoxMeUp) {
let func_addr =
libc::dlsym(libc::RTLD_DEFAULT, ANDROID_SET_ABORT_MESSAGE.as_ptr() as *const libc::c_char)
as usize;
if func_addr == 0 {
return;
}

let payload = (*payload).get();
let payload = payload.get();
let msg = match payload.downcast_ref::<&'static str>() {
Some(msg) => msg.as_bytes(),
None => match payload.downcast_ref::<String>() {
Expand Down
2 changes: 1 addition & 1 deletion library/panic_abort/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub unsafe extern "C" fn __rust_panic_cleanup(_: *mut u8) -> *mut (dyn Any + Sen

// "Leak" the payload and shim to the relevant abort on the platform in question.
#[rustc_std_internal_symbol]
pub unsafe fn __rust_start_panic(_payload: *mut &mut dyn BoxMeUp) -> u32 {
pub unsafe fn __rust_start_panic(_payload: &mut dyn BoxMeUp) -> u32 {
// Android has the ability to attach a message as part of the abort.
#[cfg(target_os = "android")]
android::android_set_abort_message(_payload);
Expand Down
4 changes: 2 additions & 2 deletions library/panic_unwind/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ pub unsafe extern "C" fn __rust_panic_cleanup(payload: *mut u8) -> *mut (dyn Any
// Entry point for raising an exception, just delegates to the platform-specific
// implementation.
#[rustc_std_internal_symbol]
pub unsafe fn __rust_start_panic(payload: *mut &mut dyn BoxMeUp) -> u32 {
let payload = Box::from_raw((*payload).take_box());
pub unsafe fn __rust_start_panic(payload: &mut dyn BoxMeUp) -> u32 {
let payload = Box::from_raw(payload.take_box());

imp::panic(payload)
}
15 changes: 5 additions & 10 deletions library/std/src/panicking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,10 @@ extern "C" {
fn __rust_panic_cleanup(payload: *mut u8) -> *mut (dyn Any + Send + 'static);
}

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

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

0 comments on commit b874502

Please sign in to comment.