Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Simplify exception cleanup for libunwind-style unwinding
  • Loading branch information
Amanieu committed Jan 11, 2020
1 parent 10720b4 commit 46f5226
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/libpanic_unwind/gcc.rs
Expand Up @@ -57,7 +57,7 @@ use unwind as uw;
#[repr(C)]
struct Exception {
_uwe: uw::_Unwind_Exception,
cause: Option<Box<dyn Any + Send>>,
cause: Box<dyn Any + Send>,
}

pub unsafe fn panic(data: Box<dyn Any + Send>) -> u32 {
Expand All @@ -67,7 +67,7 @@ pub unsafe fn panic(data: Box<dyn Any + Send>) -> u32 {
exception_cleanup,
private: [0; uw::unwinder_private_data_size],
},
cause: Some(data),
cause: data,
});
let exception_param = Box::into_raw(exception) as *mut uw::_Unwind_Exception;
return uw::_Unwind_RaiseException(exception_param) as u32;
Expand All @@ -87,10 +87,8 @@ pub fn payload() -> *mut u8 {
}

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 _);
cause.unwrap()
let exception = Box::from_raw(ptr as *mut Exception);
exception.cause
}

// Rust's exception class identifier. This is used by personality routines to
Expand Down

0 comments on commit 46f5226

Please sign in to comment.