@@ -94,6 +94,9 @@ impl Frame {
94
94
#[ repr( C , align( 16 ) ) ] // required by `CONTEXT`, is a FIXME in windows metadata right now
95
95
struct MyContext ( CONTEXT ) ;
96
96
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.
97
100
#[ inline( always) ]
98
101
pub unsafe fn trace ( cb : & mut dyn FnMut ( & super :: Frame ) -> bool ) {
99
102
// Allocate necessary structures for doing the stack walk
@@ -112,8 +115,6 @@ pub unsafe fn trace(cb: &mut dyn FnMut(&super::Frame) -> bool) {
112
115
let function_table_access = dbghelp. SymFunctionTableAccess64 ( ) ;
113
116
let get_module_base = dbghelp. SymGetModuleBase64 ( ) ;
114
117
115
- let process_handle = unsafe { GetCurrentProcess ( ) } ;
116
-
117
118
// Attempt to use `StackWalkEx` if we can, but fall back to `StackWalk64`
118
119
// since it's in theory supported on more systems.
119
120
match unsafe { ( * dbghelp. dbghelp ( ) ) . StackWalkEx ( ) } {
@@ -147,7 +148,7 @@ pub unsafe fn trace(cb: &mut dyn FnMut(&super::Frame) -> bool) {
147
148
0 ,
148
149
) == TRUE }
149
150
{
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 _ } ;
151
152
152
153
if !cb ( & frame) {
153
154
break ;
@@ -180,7 +181,7 @@ pub unsafe fn trace(cb: &mut dyn FnMut(&super::Frame) -> bool) {
180
181
None ,
181
182
) == TRUE }
182
183
{
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 _ } ;
184
185
185
186
if !cb ( & frame) {
186
187
break ;
0 commit comments