@@ -51,7 +51,7 @@ pub enum EHAction {
5151
5252pub const USING_SJLJ_EXCEPTIONS : bool = cfg ! ( all( target_os = "ios" , target_arch = "arm" ) ) ;
5353
54- pub unsafe fn find_eh_action ( lsda : * const u8 , context : & EHContext < ' _ > )
54+ pub unsafe fn find_eh_action ( lsda : * const u8 , context : & EHContext < ' _ > , foreign_exception : bool )
5555 -> Result < EHAction , ( ) >
5656{
5757 if lsda. is_null ( ) {
@@ -96,7 +96,7 @@ pub unsafe fn find_eh_action(lsda: *const u8, context: &EHContext<'_>)
9696 return Ok ( EHAction :: None )
9797 } else {
9898 let lpad = lpad_base + cs_lpad;
99- return Ok ( interpret_cs_action ( cs_action, lpad) )
99+ return Ok ( interpret_cs_action ( cs_action, lpad, foreign_exception ) )
100100 }
101101 }
102102 }
@@ -121,16 +121,23 @@ pub unsafe fn find_eh_action(lsda: *const u8, context: &EHContext<'_>)
121121 // Can never have null landing pad for sjlj -- that would have
122122 // been indicated by a -1 call site index.
123123 let lpad = ( cs_lpad + 1 ) as usize ;
124- return Ok ( interpret_cs_action ( cs_action, lpad) )
124+ return Ok ( interpret_cs_action ( cs_action, lpad, foreign_exception ) )
125125 }
126126 }
127127 }
128128}
129129
130- fn interpret_cs_action ( cs_action : u64 , lpad : usize ) -> EHAction {
130+ fn interpret_cs_action ( cs_action : u64 , lpad : usize , foreign_exception : bool ) -> EHAction {
131131 if cs_action == 0 {
132+ // If cs_action is 0 then this is a cleanup (Drop::drop). We run these
133+ // for both Rust panics and foriegn exceptions.
132134 EHAction :: Cleanup ( lpad)
135+ } else if foreign_exception {
136+ // catch_unwind should not catch foreign exceptions, only Rust panics.
137+ // Instead just continue unwinding.
138+ EHAction :: None
133139 } else {
140+ // Stop unwinding Rust panics at catch_unwind.
134141 EHAction :: Catch ( lpad)
135142 }
136143}
0 commit comments