Skip to content

Commit

Permalink
panic_unwind: add #![warn(unreachable_pub)]
Browse files Browse the repository at this point in the history
  • Loading branch information
Urgau authored and gitbot committed Feb 22, 2025
1 parent b6e2d54 commit 174446a
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 26 deletions.
4 changes: 2 additions & 2 deletions panic_unwind/src/dummy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ use alloc::boxed::Box;
use core::any::Any;
use core::intrinsics;

pub unsafe fn cleanup(_ptr: *mut u8) -> Box<dyn Any + Send> {
pub(crate) unsafe fn cleanup(_ptr: *mut u8) -> Box<dyn Any + Send> {
intrinsics::abort()
}

pub unsafe fn panic(_data: Box<dyn Any + Send>) -> u32 {
pub(crate) unsafe fn panic(_data: Box<dyn Any + Send>) -> u32 {
intrinsics::abort()
}
4 changes: 2 additions & 2 deletions panic_unwind/src/emcc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ struct Exception {
data: Option<Box<dyn Any + Send>>,
}

pub unsafe fn cleanup(ptr: *mut u8) -> Box<dyn Any + Send> {
pub(crate) unsafe fn cleanup(ptr: *mut u8) -> Box<dyn Any + Send> {
// intrinsics::try actually gives us a pointer to this structure.
#[repr(C)]
struct CatchData {
Expand Down Expand Up @@ -93,7 +93,7 @@ pub unsafe fn cleanup(ptr: *mut u8) -> Box<dyn Any + Send> {
out
}

pub unsafe fn panic(data: Box<dyn Any + Send>) -> u32 {
pub(crate) unsafe fn panic(data: Box<dyn Any + Send>) -> u32 {
let exception = __cxa_allocate_exception(mem::size_of::<Exception>()) as *mut Exception;
if exception.is_null() {
return uw::_URC_FATAL_PHASE1_ERROR as u32;
Expand Down
4 changes: 2 additions & 2 deletions panic_unwind/src/gcc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ struct Exception {
cause: Box<dyn Any + Send>,
}

pub unsafe fn panic(data: Box<dyn Any + Send>) -> u32 {
pub(crate) unsafe fn panic(data: Box<dyn Any + Send>) -> u32 {
let exception = Box::new(Exception {
_uwe: uw::_Unwind_Exception {
exception_class: RUST_EXCEPTION_CLASS,
Expand All @@ -82,7 +82,7 @@ pub unsafe fn panic(data: Box<dyn Any + Send>) -> u32 {
}
}

pub unsafe fn cleanup(ptr: *mut u8) -> Box<dyn Any + Send> {
pub(crate) unsafe fn cleanup(ptr: *mut u8) -> Box<dyn Any + Send> {
let exception = ptr as *mut uw::_Unwind_Exception;
if (*exception).exception_class != RUST_EXCEPTION_CLASS {
uw::_Unwind_DeleteException(exception);
Expand Down
4 changes: 2 additions & 2 deletions panic_unwind/src/hermit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
use alloc::boxed::Box;
use core::any::Any;

pub unsafe fn cleanup(_ptr: *mut u8) -> Box<dyn Any + Send> {
pub(crate) unsafe fn cleanup(_ptr: *mut u8) -> Box<dyn Any + Send> {
extern "C" {
pub fn __rust_abort() -> !;
}
__rust_abort();
}

pub unsafe fn panic(_data: Box<dyn Any + Send>) -> u32 {
pub(crate) unsafe fn panic(_data: Box<dyn Any + Send>) -> u32 {
extern "C" {
pub fn __rust_abort() -> !;
}
Expand Down
1 change: 1 addition & 0 deletions panic_unwind/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#![cfg_attr(miri, allow(dead_code))]
#![allow(internal_features)]
#![cfg_attr(not(bootstrap), feature(cfg_emscripten_wasm_eh))]
#![warn(unreachable_pub)]

use alloc::boxed::Box;
use core::any::Any;
Expand Down
4 changes: 2 additions & 2 deletions panic_unwind/src/miri.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ extern "Rust" {
fn miri_start_unwind(payload: *mut u8) -> !;
}

pub unsafe fn panic(payload: Box<dyn Any + Send>) -> u32 {
pub(crate) unsafe fn panic(payload: Box<dyn Any + Send>) -> u32 {
// The payload we pass to `miri_start_unwind` will be exactly the argument we get
// in `cleanup` below. So we just box it up once, to get something pointer-sized.
let payload_box: Payload = Box::new(payload);
miri_start_unwind(Box::into_raw(payload_box) as *mut u8)
}

pub unsafe fn cleanup(payload_box: *mut u8) -> Box<dyn Any + Send> {
pub(crate) unsafe fn cleanup(payload_box: *mut u8) -> Box<dyn Any + Send> {
// Recover the underlying `Box`.
let payload_box: Payload = Box::from_raw(payload_box as *mut _);
*payload_box
Expand Down
32 changes: 16 additions & 16 deletions panic_unwind/src/seh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,18 +111,18 @@ struct Exception {
mod imp {
#[repr(transparent)]
#[derive(Copy, Clone)]
pub struct ptr_t(*mut u8);
pub(super) struct ptr_t(*mut u8);

impl ptr_t {
pub const fn null() -> Self {
pub(super) const fn null() -> Self {
Self(core::ptr::null_mut())
}

pub const fn new(ptr: *mut u8) -> Self {
pub(super) const fn new(ptr: *mut u8) -> Self {
Self(ptr)
}

pub const fn raw(self) -> *mut u8 {
pub(super) const fn raw(self) -> *mut u8 {
self.0
}
}
Expand All @@ -133,18 +133,18 @@ mod imp {
// On 64-bit systems, SEH represents pointers as 32-bit offsets from `__ImageBase`.
#[repr(transparent)]
#[derive(Copy, Clone)]
pub struct ptr_t(u32);
pub(super) struct ptr_t(u32);

extern "C" {
pub static __ImageBase: u8;
static __ImageBase: u8;
}

impl ptr_t {
pub const fn null() -> Self {
pub(super) const fn null() -> Self {
Self(0)
}

pub fn new(ptr: *mut u8) -> Self {
pub(super) fn new(ptr: *mut u8) -> Self {
// We need to expose the provenance of the pointer because it is not carried by
// the `u32`, while the FFI needs to have this provenance to excess our statics.
//
Expand All @@ -159,7 +159,7 @@ mod imp {
Self(offset as u32)
}

pub const fn raw(self) -> u32 {
pub(super) const fn raw(self) -> u32 {
self.0
}
}
Expand All @@ -168,21 +168,21 @@ mod imp {
use imp::ptr_t;

#[repr(C)]
pub struct _ThrowInfo {
struct _ThrowInfo {
pub attributes: c_uint,
pub pmfnUnwind: ptr_t,
pub pForwardCompat: ptr_t,
pub pCatchableTypeArray: ptr_t,
}

#[repr(C)]
pub struct _CatchableTypeArray {
struct _CatchableTypeArray {
pub nCatchableTypes: c_int,
pub arrayOfCatchableTypes: [ptr_t; 1],
}

#[repr(C)]
pub struct _CatchableType {
struct _CatchableType {
pub properties: c_uint,
pub pType: ptr_t,
pub thisDisplacement: _PMD,
Expand All @@ -191,14 +191,14 @@ pub struct _CatchableType {
}

#[repr(C)]
pub struct _PMD {
struct _PMD {
pub mdisp: c_int,
pub pdisp: c_int,
pub vdisp: c_int,
}

#[repr(C)]
pub struct _TypeDescriptor {
struct _TypeDescriptor {
pub pVFTable: *const u8,
pub spare: *mut u8,
pub name: [u8; 11],
Expand Down Expand Up @@ -288,7 +288,7 @@ cfg_if::cfg_if! {
}
}

pub unsafe fn panic(data: Box<dyn Any + Send>) -> u32 {
pub(crate) unsafe fn panic(data: Box<dyn Any + Send>) -> u32 {
use core::intrinsics::atomic_store_seqcst;

// _CxxThrowException executes entirely on this stack frame, so there's no
Expand Down Expand Up @@ -350,7 +350,7 @@ pub unsafe fn panic(data: Box<dyn Any + Send>) -> u32 {
_CxxThrowException(throw_ptr, (&raw mut THROW_INFO) as *mut _);
}

pub unsafe fn cleanup(payload: *mut u8) -> Box<dyn Any + Send> {
pub(crate) unsafe fn cleanup(payload: *mut u8) -> Box<dyn Any + Send> {
// A null payload here means that we got here from the catch (...) of
// __rust_try. This happens when a non-Rust foreign exception is caught.
if payload.is_null() {
Expand Down

0 comments on commit 174446a

Please sign in to comment.