@@ -5,7 +5,7 @@ use fallible_iterator::FallibleIterator;
55use gimli:: X86_64 ;
66
77use registers:: Registers ;
8- use super :: { DwarfUnwinder , Unwinder } ;
8+ use super :: { DwarfUnwinder , Unwinder , StackFrames } ;
99
1010#[ repr( C ) ]
1111#[ derive( Copy , Clone , PartialEq ) ]
@@ -58,7 +58,11 @@ type PersonalityRoutine = extern "C" fn(version: c_int, actions: c_int, class: u
5858// it never needs any cleanup. Currently this is not true.
5959#[ no_mangle]
6060pub unsafe extern "C" fn _Unwind_Resume ( exception : * mut _Unwind_Exception ) -> ! {
61- DwarfUnwinder :: default ( ) . trace ( |frames| unwind_tracer ( frames, exception) ) ;
61+ :: glue:: registers ( |registers| {
62+ if let Some ( registers) = unwind_tracer ( registers, exception) {
63+ :: glue:: land ( & registers) ;
64+ }
65+ } ) ;
6266 unreachable ! ( ) ;
6367}
6468
@@ -120,19 +124,26 @@ pub unsafe extern "C" fn _Unwind_FindEnclosingFunction(pc: *mut c_void) -> *mut
120124#[ no_mangle]
121125pub unsafe extern "C" fn _Unwind_RaiseException ( exception : * mut _Unwind_Exception ) -> _Unwind_Reason_Code {
122126 ( * exception) . private_contptr = None ;
123- DwarfUnwinder :: default ( ) . trace ( |frames| unwind_tracer ( frames, exception) ) ;
127+ :: glue:: registers ( |registers| {
128+ if let Some ( registers) = unwind_tracer ( registers, exception) {
129+ :: glue:: land ( & registers) ;
130+ }
131+ } ) ;
124132 unreachable ! ( ) ;
125133}
126134
127- unsafe fn unwind_tracer ( frames : & mut :: StackFrames , exception : * mut _Unwind_Exception ) {
135+ unsafe fn unwind_tracer ( registers : Registers , exception : * mut _Unwind_Exception ) -> Option < Registers > {
136+ let mut unwinder = DwarfUnwinder :: default ( ) ;
137+ let mut frames = StackFrames :: new ( & mut unwinder, registers) ;
138+
128139 if let Some ( contptr) = ( * exception) . private_contptr {
129140 loop {
130141 if let Some ( frame) = frames. next ( ) . unwrap ( ) {
131142 if frames. registers ( ) [ X86_64 :: RSP ] . unwrap ( ) == contptr {
132143 break ;
133144 }
134145 } else {
135- return ;
146+ return None ;
136147 }
137148 }
138149 }
@@ -155,11 +166,12 @@ unsafe fn unwind_tracer(frames: &mut ::StackFrames, exception: *mut _Unwind_Exce
155166 match personality ( 1 , _Unwind_Action:: _UA_CLEANUP_PHASE as c_int , ( * exception) . exception_class ,
156167 exception, & mut ctx) {
157168 _Unwind_Reason_Code:: _URC_CONTINUE_UNWIND => ( ) ,
158- _Unwind_Reason_Code:: _URC_INSTALL_CONTEXT => :: glue :: land ( frames. registers ( ) ) ,
169+ _Unwind_Reason_Code:: _URC_INSTALL_CONTEXT => return Some ( frames. registers ) ,
159170 x => panic ! ( "wtf reason code {:?}" , x) ,
160171 }
161172 }
162173 }
174+ None
163175}
164176
165177#[ no_mangle]
0 commit comments