@@ -94,6 +94,9 @@ impl Frame {
9494#[ repr( C , align( 16 ) ) ] // required by `CONTEXT`, is a FIXME in windows metadata right now
9595struct MyContext ( CONTEXT ) ;
9696
97+ /// # Safety
98+ /// This function makes many calls to dbghelp, which must be called in a single-threaded fashion.
99+ /// Therefore, it is unsound to call this function concurrently without synchronization.
97100#[ inline( always) ]
98101pub unsafe fn trace ( cb : & mut dyn FnMut ( & super :: Frame ) -> bool ) {
99102 // Allocate necessary structures for doing the stack walk
@@ -112,8 +115,6 @@ pub unsafe fn trace(cb: &mut dyn FnMut(&super::Frame) -> bool) {
112115 let function_table_access = dbghelp. SymFunctionTableAccess64 ( ) ;
113116 let get_module_base = dbghelp. SymGetModuleBase64 ( ) ;
114117
115- let process_handle = unsafe { GetCurrentProcess ( ) } ;
116-
117118 // Attempt to use `StackWalkEx` if we can, but fall back to `StackWalk64`
118119 // since it's in theory supported on more systems.
119120 match unsafe { ( * dbghelp. dbghelp ( ) ) . StackWalkEx ( ) } {
@@ -147,7 +148,7 @@ pub unsafe fn trace(cb: &mut dyn FnMut(&super::Frame) -> bool) {
147148 0 ,
148149 ) == TRUE }
149150 {
150- frame. inner . base_address = unsafe { get_module_base ( process_handle , frame. ip ( ) as _ ) as _ } ;
151+ frame. inner . base_address = unsafe { get_module_base ( process , frame. ip ( ) as _ ) as _ } ;
151152
152153 if !cb ( & frame) {
153154 break ;
@@ -180,7 +181,7 @@ pub unsafe fn trace(cb: &mut dyn FnMut(&super::Frame) -> bool) {
180181 None ,
181182 ) == TRUE }
182183 {
183- frame. inner . base_address = unsafe { get_module_base ( process_handle , frame. ip ( ) as _ ) as _ } ;
184+ frame. inner . base_address = unsafe { get_module_base ( process , frame. ip ( ) as _ ) as _ } ;
184185
185186 if !cb ( & frame) {
186187 break ;
0 commit comments