Deny bare trait objects in in src/libpanic_unwind
This commit is contained in:
parent
11432ba980
commit
dbab06dd85
@ -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 {
|
||||
|
@ -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());
|
||||
|
||||
|
@ -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(),
|
||||
@ -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 _);
|
||||
|
@ -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()))
|
||||
}
|
||||
|
@ -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
|
||||
@ -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
|
||||
@ -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 _,
|
||||
|
@ -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,
|
||||
@ -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;
|
||||
}
|
||||
|
@ -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()
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user