From dbab06dd85c915fe403e7f86b231b9d61b24336a Mon Sep 17 00:00:00 2001 From: ljedrz Date: Wed, 11 Jul 2018 17:11:08 +0200 Subject: [PATCH] Deny bare trait objects in in src/libpanic_unwind --- src/libpanic_unwind/dwarf/eh.rs | 4 ++-- src/libpanic_unwind/emcc.rs | 6 +++--- src/libpanic_unwind/gcc.rs | 6 +++--- src/libpanic_unwind/lib.rs | 3 ++- src/libpanic_unwind/seh.rs | 6 +++--- src/libpanic_unwind/seh64_gnu.rs | 6 +++--- src/libpanic_unwind/wasm32.rs | 4 ++-- 7 files changed, 18 insertions(+), 17 deletions(-) diff --git a/src/libpanic_unwind/dwarf/eh.rs b/src/libpanic_unwind/dwarf/eh.rs index 0c326ce3718..a24c6596891 100644 --- a/src/libpanic_unwind/dwarf/eh.rs +++ b/src/libpanic_unwind/dwarf/eh.rs @@ -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 { diff --git a/src/libpanic_unwind/emcc.rs b/src/libpanic_unwind/emcc.rs index 0e48e37c923..87efc23abc8 100644 --- a/src/libpanic_unwind/emcc.rs +++ b/src/libpanic_unwind/emcc.rs @@ -29,20 +29,20 @@ pub fn payload() -> *mut u8 { ptr::null_mut() } -pub unsafe fn cleanup(ptr: *mut u8) -> Box { +pub unsafe fn cleanup(ptr: *mut u8) -> Box { assert!(!ptr.is_null()); let ex = ptr::read(ptr as *mut _); __cxa_free_exception(ptr as *mut _); ex } -pub unsafe fn panic(data: Box) -> u32 { +pub unsafe fn panic(data: Box) -> 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; + let exception = exception as *mut Box; ptr::write(exception, data); __cxa_throw(exception as *mut _, ptr::null_mut(), ptr::null_mut()); diff --git a/src/libpanic_unwind/gcc.rs b/src/libpanic_unwind/gcc.rs index 06c264725a9..11ebcf5c01e 100644 --- a/src/libpanic_unwind/gcc.rs +++ b/src/libpanic_unwind/gcc.rs @@ -67,10 +67,10 @@ use dwarf::eh::{self, EHContext, EHAction}; #[repr(C)] struct Exception { _uwe: uw::_Unwind_Exception, - cause: Option>, + cause: Option>, } -pub unsafe fn panic(data: Box) -> u32 { +pub unsafe fn panic(data: Box) -> u32 { let exception = Box::new(Exception { _uwe: uw::_Unwind_Exception { exception_class: rust_exception_class(), @@ -94,7 +94,7 @@ pub fn payload() -> *mut u8 { ptr::null_mut() } -pub unsafe fn cleanup(ptr: *mut u8) -> Box { +pub unsafe fn cleanup(ptr: *mut u8) -> Box { let my_ep = ptr as *mut Exception; let cause = (*my_ep).cause.take(); uw::_Unwind_DeleteException(ptr as *mut _); diff --git a/src/libpanic_unwind/lib.rs b/src/libpanic_unwind/lib.rs index 6c52c0fa10c..f8cd29fc086 100644 --- a/src/libpanic_unwind/lib.rs +++ b/src/libpanic_unwind/lib.rs @@ -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", @@ -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())) } diff --git a/src/libpanic_unwind/seh.rs b/src/libpanic_unwind/seh.rs index 58964214930..8cbc4a623fa 100644 --- a/src/libpanic_unwind/seh.rs +++ b/src/libpanic_unwind/seh.rs @@ -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`. Like with Dwarf exceptions +//! specifically a `Box`. 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 @@ -243,7 +243,7 @@ static mut TYPE_DESCRIPTOR2: _TypeDescriptor = _TypeDescriptor { name: imp::NAME2, }; -pub unsafe fn panic(data: Box) -> u32 { +pub unsafe fn panic(data: Box) -> u32 { use core::intrinsics::atomic_store; // _CxxThrowException executes entirely on this stack frame, so there's no @@ -297,7 +297,7 @@ pub fn payload() -> [u64; 2] { [0; 2] } -pub unsafe fn cleanup(payload: [u64; 2]) -> Box { +pub unsafe fn cleanup(payload: [u64; 2]) -> Box { mem::transmute(raw::TraitObject { data: payload[0] as *mut _, vtable: payload[1] as *mut _, diff --git a/src/libpanic_unwind/seh64_gnu.rs b/src/libpanic_unwind/seh64_gnu.rs index c3715f96c64..0b08e54c673 100644 --- a/src/libpanic_unwind/seh64_gnu.rs +++ b/src/libpanic_unwind/seh64_gnu.rs @@ -37,10 +37,10 @@ const RUST_PANIC: c::DWORD = ETYPE | (1 << 24) | MAGIC; #[repr(C)] struct PanicData { - data: Box, + data: Box, } -pub unsafe fn panic(data: Box) -> u32 { +pub unsafe fn panic(data: Box) -> u32 { let panic_ctx = Box::new(PanicData { data: data }); let params = [Box::into_raw(panic_ctx) as c::ULONG_PTR]; c::RaiseException(RUST_PANIC, @@ -54,7 +54,7 @@ pub fn payload() -> *mut u8 { ptr::null_mut() } -pub unsafe fn cleanup(ptr: *mut u8) -> Box { +pub unsafe fn cleanup(ptr: *mut u8) -> Box { let panic_ctx = Box::from_raw(ptr as *mut PanicData); return panic_ctx.data; } diff --git a/src/libpanic_unwind/wasm32.rs b/src/libpanic_unwind/wasm32.rs index 8aed61b3c38..7150560b4a1 100644 --- a/src/libpanic_unwind/wasm32.rs +++ b/src/libpanic_unwind/wasm32.rs @@ -20,10 +20,10 @@ pub fn payload() -> *mut u8 { 0 as *mut u8 } -pub unsafe fn cleanup(_ptr: *mut u8) -> Box { +pub unsafe fn cleanup(_ptr: *mut u8) -> Box { intrinsics::abort() } -pub unsafe fn panic(_data: Box) -> u32 { +pub unsafe fn panic(_data: Box) -> u32 { intrinsics::abort() }