Skip to content

Commit

Permalink
Deny bare trait objects in in src/libpanic_unwind
Browse files Browse the repository at this point in the history
  • Loading branch information
ljedrz committed Jul 11, 2018
1 parent 11432ba commit dbab06d
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 17 deletions.
4 changes: 2 additions & 2 deletions src/libpanic_unwind/dwarf/eh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ pub const DW_EH_PE_indirect: u8 = 0x80;
pub struct EHContext<'a> {
pub ip: usize, // Current instruction pointer
pub func_start: usize, // Address of the current function
pub get_text_start: &'a Fn() -> usize, // Get address of the code section
pub get_data_start: &'a Fn() -> usize, // Get address of the data section
pub get_text_start: &'a dyn Fn() -> usize, // Get address of the code section
pub get_data_start: &'a dyn Fn() -> usize, // Get address of the data section
}

pub enum EHAction {
Expand Down
6 changes: 3 additions & 3 deletions src/libpanic_unwind/emcc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,20 @@ pub fn payload() -> *mut u8 {
ptr::null_mut()
}

pub unsafe fn cleanup(ptr: *mut u8) -> Box<Any + Send> {
pub unsafe fn cleanup(ptr: *mut u8) -> Box<dyn Any + Send> {
assert!(!ptr.is_null());
let ex = ptr::read(ptr as *mut _);
__cxa_free_exception(ptr as *mut _);
ex
}

pub unsafe fn panic(data: Box<Any + Send>) -> u32 {
pub unsafe fn panic(data: Box<dyn Any + Send>) -> u32 {
let sz = mem::size_of_val(&data);
let exception = __cxa_allocate_exception(sz);
if exception == ptr::null_mut() {
return uw::_URC_FATAL_PHASE1_ERROR as u32;
}
let exception = exception as *mut Box<Any + Send>;
let exception = exception as *mut Box<dyn Any + Send>;
ptr::write(exception, data);
__cxa_throw(exception as *mut _, ptr::null_mut(), ptr::null_mut());

Expand Down
6 changes: 3 additions & 3 deletions src/libpanic_unwind/gcc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ use dwarf::eh::{self, EHContext, EHAction};
#[repr(C)]
struct Exception {
_uwe: uw::_Unwind_Exception,
cause: Option<Box<Any + Send>>,
cause: Option<Box<dyn Any + Send>>,
}

pub unsafe fn panic(data: Box<Any + Send>) -> u32 {
pub 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 @@ -94,7 +94,7 @@ pub fn payload() -> *mut u8 {
ptr::null_mut()
}

pub unsafe fn cleanup(ptr: *mut u8) -> Box<Any + Send> {
pub unsafe fn cleanup(ptr: *mut u8) -> Box<dyn Any + Send> {
let my_ep = ptr as *mut Exception;
let cause = (*my_ep).cause.take();
uw::_Unwind_DeleteException(ptr as *mut _);
Expand Down
3 changes: 2 additions & 1 deletion src/libpanic_unwind/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
//! More documentation about each implementation can be found in the respective
//! module.
#![deny(bare_trait_objects)]
#![no_std]
#![unstable(feature = "panic_unwind", issue = "32837")]
#![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
Expand Down Expand Up @@ -117,6 +118,6 @@ pub unsafe extern "C" fn __rust_maybe_catch_panic(f: fn(*mut u8),
#[no_mangle]
#[unwind(allowed)]
pub unsafe extern "C" fn __rust_start_panic(payload: usize) -> u32 {
let payload = payload as *mut &mut BoxMeUp;
let payload = payload as *mut &mut dyn BoxMeUp;
imp::panic(Box::from_raw((*payload).box_me_up()))
}
6 changes: 3 additions & 3 deletions src/libpanic_unwind/seh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
//! throwing. Note that throwing an exception into Rust is undefined behavior
//! anyway, so this should be fine.
//! * We've got some data to transmit across the unwinding boundary,
//! specifically a `Box<Any + Send>`. Like with Dwarf exceptions
//! specifically a `Box<dyn Any + Send>`. Like with Dwarf exceptions
//! these two pointers are stored as a payload in the exception itself. On
//! MSVC, however, there's no need for an extra heap allocation because the
//! call stack is preserved while filter functions are being executed. This
Expand Down Expand Up @@ -243,7 +243,7 @@ static mut TYPE_DESCRIPTOR2: _TypeDescriptor = _TypeDescriptor {
name: imp::NAME2,
};

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

// _CxxThrowException executes entirely on this stack frame, so there's no
Expand Down Expand Up @@ -297,7 +297,7 @@ pub fn payload() -> [u64; 2] {
[0; 2]
}

pub unsafe fn cleanup(payload: [u64; 2]) -> Box<Any + Send> {
pub unsafe fn cleanup(payload: [u64; 2]) -> Box<dyn Any + Send> {
mem::transmute(raw::TraitObject {
data: payload[0] as *mut _,
vtable: payload[1] as *mut _,
Expand Down
6 changes: 3 additions & 3 deletions src/libpanic_unwind/seh64_gnu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ const RUST_PANIC: c::DWORD = ETYPE | (1 << 24) | MAGIC;

#[repr(C)]
struct PanicData {
data: Box<Any + Send>,
data: Box<dyn Any + Send>,
}

pub unsafe fn panic(data: Box<Any + Send>) -> u32 {
pub unsafe fn panic(data: Box<dyn Any + Send>) -> u32 {
let panic_ctx = Box::new(PanicData { data: data });
let params = [Box::into_raw(panic_ctx) as c::ULONG_PTR];
c::RaiseException(RUST_PANIC,
Expand All @@ -54,7 +54,7 @@ pub fn payload() -> *mut u8 {
ptr::null_mut()
}

pub unsafe fn cleanup(ptr: *mut u8) -> Box<Any + Send> {
pub unsafe fn cleanup(ptr: *mut u8) -> Box<dyn Any + Send> {
let panic_ctx = Box::from_raw(ptr as *mut PanicData);
return panic_ctx.data;
}
Expand Down
4 changes: 2 additions & 2 deletions src/libpanic_unwind/wasm32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ pub fn payload() -> *mut u8 {
0 as *mut u8
}

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

pub unsafe fn panic(_data: Box<Any + Send>) -> u32 {
pub unsafe fn panic(_data: Box<dyn Any + Send>) -> u32 {
intrinsics::abort()
}

0 comments on commit dbab06d

Please sign in to comment.