@@ -86,42 +86,6 @@ impl MyContext {
8686 }
8787}
8888
89- #[ cfg( target_arch = "x86" ) ]
90- impl MyContext {
91- #[ inline( always) ]
92- fn ip ( & self ) -> DWORD {
93- self . 0 . Eip
94- }
95-
96- #[ inline( always) ]
97- fn sp ( & self ) -> DWORD {
98- self . 0 . Esp
99- }
100-
101- #[ inline( always) ]
102- fn fp ( & self ) -> DWORD {
103- self . 0 . Ebp
104- }
105- }
106-
107- #[ cfg( target_arch = "arm" ) ]
108- impl MyContext {
109- #[ inline( always) ]
110- fn ip ( & self ) -> DWORD {
111- self . 0 . Pc
112- }
113-
114- #[ inline( always) ]
115- fn sp ( & self ) -> DWORD {
116- self . 0 . Sp
117- }
118-
119- #[ inline( always) ]
120- fn fp ( & self ) -> DWORD {
121- self . 0 . R11
122- }
123- }
124-
12589#[ cfg( any(
12690 target_arch = "x86_64" ,
12791 target_arch = "aarch64" ,
@@ -172,113 +136,3 @@ pub unsafe fn trace(cb: &mut dyn FnMut(&super::Frame) -> bool) {
172136 ) ;
173137 }
174138}
175-
176- #[ cfg( any( target_arch = "x86" , target_arch = "arm" ) ) ]
177- #[ inline( always) ]
178- pub unsafe fn trace ( cb : & mut dyn FnMut ( & super :: Frame ) -> bool ) {
179- use core:: { mem, ptr} ;
180-
181- // Allocate necessary structures for doing the stack walk
182- let process = GetCurrentProcess ( ) ;
183- let thread = GetCurrentThread ( ) ;
184-
185- let mut context = mem:: zeroed :: < MyContext > ( ) ;
186- RtlCaptureContext ( & mut context. 0 ) ;
187-
188- // Ensure this process's symbols are initialized
189- let dbghelp = match super :: super :: dbghelp:: init ( ) {
190- Ok ( dbghelp) => dbghelp,
191- Err ( ( ) ) => return , // oh well...
192- } ;
193-
194- let function_table_access = dbghelp. SymFunctionTableAccess64 ( ) ;
195- let get_module_base = dbghelp. SymGetModuleBase64 ( ) ;
196-
197- let process_handle = GetCurrentProcess ( ) ;
198-
199- #[ cfg( target_arch = "x86" ) ]
200- let image = IMAGE_FILE_MACHINE_I386 ;
201- #[ cfg( target_arch = "arm" ) ]
202- let image = IMAGE_FILE_MACHINE_ARMNT ;
203-
204- // Attempt to use `StackWalkEx` if we can, but fall back to `StackWalk64`
205- // since it's in theory supported on more systems.
206- match ( * dbghelp. dbghelp ( ) ) . StackWalkEx ( ) {
207- Some ( StackWalkEx ) => {
208- let mut stack_frame_ex: STACKFRAME_EX = mem:: zeroed ( ) ;
209- stack_frame_ex. StackFrameSize = mem:: size_of :: < STACKFRAME_EX > ( ) as DWORD ;
210- stack_frame_ex. AddrPC . Offset = context. ip ( ) as u64 ;
211- stack_frame_ex. AddrPC . Mode = AddrModeFlat ;
212- stack_frame_ex. AddrStack . Offset = context. sp ( ) as u64 ;
213- stack_frame_ex. AddrStack . Mode = AddrModeFlat ;
214- stack_frame_ex. AddrFrame . Offset = context. fp ( ) as u64 ;
215- stack_frame_ex. AddrFrame . Mode = AddrModeFlat ;
216-
217- while StackWalkEx (
218- image as DWORD ,
219- process,
220- thread,
221- & mut stack_frame_ex,
222- ptr:: addr_of_mut!( context. 0 ) as PVOID ,
223- None ,
224- Some ( function_table_access) ,
225- Some ( get_module_base) ,
226- None ,
227- 0 ,
228- ) == TRUE
229- {
230- let frame = super :: Frame {
231- inner : Frame {
232- base_address : get_module_base ( process_handle, stack_frame_ex. AddrPC . Offset )
233- as * mut c_void ,
234- ip : stack_frame_ex. AddrPC . Offset as * mut c_void ,
235- sp : stack_frame_ex. AddrStack . Offset as * mut c_void ,
236- #[ cfg( not( target_env = "gnu" ) ) ]
237- inline_context : Some ( stack_frame_ex. InlineFrameContext ) ,
238- } ,
239- } ;
240-
241- if !cb ( & frame) {
242- break ;
243- }
244- }
245- }
246- None => {
247- let mut stack_frame64: STACKFRAME64 = mem:: zeroed ( ) ;
248- stack_frame64. AddrPC . Offset = context. ip ( ) as u64 ;
249- stack_frame64. AddrPC . Mode = AddrModeFlat ;
250- stack_frame64. AddrStack . Offset = context. sp ( ) as u64 ;
251- stack_frame64. AddrStack . Mode = AddrModeFlat ;
252- stack_frame64. AddrFrame . Offset = context. fp ( ) as u64 ;
253- stack_frame64. AddrFrame . Mode = AddrModeFlat ;
254-
255- while dbghelp. StackWalk64 ( ) (
256- image as DWORD ,
257- process,
258- thread,
259- & mut stack_frame64,
260- ptr:: addr_of_mut!( context. 0 ) as PVOID ,
261- None ,
262- Some ( function_table_access) ,
263- Some ( get_module_base) ,
264- None ,
265- ) == TRUE
266- {
267- let frame = super :: Frame {
268- inner : Frame {
269- base_address : get_module_base ( process_handle, stack_frame64. AddrPC . Offset )
270- as * mut c_void ,
271- ip : stack_frame64. AddrPC . Offset as * mut c_void ,
272- sp : stack_frame64. AddrStack . Offset as * mut c_void ,
273- #[ cfg( not( target_env = "gnu" ) ) ]
274- inline_context : None ,
275- } ,
276- } ;
277-
278- if !cb ( & frame) {
279- break ;
280- }
281- }
282- }
283- }
284- }
0 commit comments