@@ -73,8 +73,14 @@ pub unsafe fn panic(data: Box<dyn Any + Send>) -> u32 {
7373}
7474
7575pub unsafe fn cleanup ( ptr : * mut u8 ) -> Box < dyn Any + Send > {
76- let exception = Box :: from_raw ( ptr as * mut Exception ) ;
77- exception. cause
76+ let exception = ptr as * mut uw:: _Unwind_Exception ;
77+ if ( * exception) . exception_class != rust_exception_class ( ) {
78+ uw:: _Unwind_DeleteException ( exception) ;
79+ super :: __rust_foreign_exception ( ) ;
80+ } else {
81+ let exception = Box :: from_raw ( exception as * mut Exception ) ;
82+ exception. cause
83+ }
7884}
7985
8086// Rust's exception class identifier. This is used by personality routines to
@@ -164,9 +170,7 @@ cfg_if::cfg_if! {
164170 // _Unwind_Context in our libunwind bindings and fetch the required data from there
165171 // directly, bypassing DWARF compatibility functions.
166172
167- let exception_class = ( * exception_object) . exception_class;
168- let foreign_exception = exception_class != rust_exception_class( ) ;
169- let eh_action = match find_eh_action( context, foreign_exception) {
173+ let eh_action = match find_eh_action( context) {
170174 Ok ( action) => action,
171175 Err ( _) => return uw:: _URC_FAILURE,
172176 } ;
@@ -221,15 +225,14 @@ cfg_if::cfg_if! {
221225 // and indirectly on Windows x86_64 via SEH.
222226 unsafe extern "C" fn rust_eh_personality_impl( version: c_int,
223227 actions: uw:: _Unwind_Action,
224- exception_class : uw:: _Unwind_Exception_Class,
228+ _exception_class : uw:: _Unwind_Exception_Class,
225229 exception_object: * mut uw:: _Unwind_Exception,
226230 context: * mut uw:: _Unwind_Context)
227231 -> uw:: _Unwind_Reason_Code {
228232 if version != 1 {
229233 return uw:: _URC_FATAL_PHASE1_ERROR;
230234 }
231- let foreign_exception = exception_class != rust_exception_class( ) ;
232- let eh_action = match find_eh_action( context, foreign_exception) {
235+ let eh_action = match find_eh_action( context) {
233236 Ok ( action) => action,
234237 Err ( _) => return uw:: _URC_FATAL_PHASE1_ERROR,
235238 } ;
@@ -293,10 +296,7 @@ cfg_if::cfg_if! {
293296 }
294297}
295298
296- unsafe fn find_eh_action (
297- context : * mut uw:: _Unwind_Context ,
298- foreign_exception : bool ,
299- ) -> Result < EHAction , ( ) > {
299+ unsafe fn find_eh_action ( context : * mut uw:: _Unwind_Context ) -> Result < EHAction , ( ) > {
300300 let lsda = uw:: _Unwind_GetLanguageSpecificData ( context) as * const u8 ;
301301 let mut ip_before_instr: c_int = 0 ;
302302 let ip = uw:: _Unwind_GetIPInfo ( context, & mut ip_before_instr) ;
@@ -308,7 +308,7 @@ unsafe fn find_eh_action(
308308 get_text_start : & || uw:: _Unwind_GetTextRelBase ( context) ,
309309 get_data_start : & || uw:: _Unwind_GetDataRelBase ( context) ,
310310 } ;
311- eh:: find_eh_action ( lsda, & eh_context, foreign_exception )
311+ eh:: find_eh_action ( lsda, & eh_context)
312312}
313313
314314// Frame unwind info registration
0 commit comments