@@ -97,11 +97,11 @@ struct MyContext(CONTEXT);
97
97
#[ inline( always) ]
98
98
pub unsafe fn trace ( cb : & mut dyn FnMut ( & super :: Frame ) -> bool ) {
99
99
// Allocate necessary structures for doing the stack walk
100
- let process = GetCurrentProcess ( ) ;
101
- let thread = GetCurrentThread ( ) ;
100
+ let process = unsafe { GetCurrentProcess ( ) } ;
101
+ let thread = unsafe { GetCurrentThread ( ) } ;
102
102
103
- let mut context = mem:: zeroed :: < MyContext > ( ) ;
104
- RtlCaptureContext ( & mut context. 0 ) ;
103
+ let mut context = unsafe { mem:: zeroed :: < MyContext > ( ) } ;
104
+ unsafe { RtlCaptureContext ( & mut context. 0 ) } ;
105
105
106
106
// Ensure this process's symbols are initialized
107
107
let dbghelp = match dbghelp:: init ( ) {
@@ -112,14 +112,15 @@ pub unsafe fn trace(cb: &mut dyn FnMut(&super::Frame) -> bool) {
112
112
let function_table_access = dbghelp. SymFunctionTableAccess64 ( ) ;
113
113
let get_module_base = dbghelp. SymGetModuleBase64 ( ) ;
114
114
115
- let process_handle = GetCurrentProcess ( ) ;
115
+ let process_handle = unsafe { GetCurrentProcess ( ) } ;
116
116
117
117
// Attempt to use `StackWalkEx` if we can, but fall back to `StackWalk64`
118
118
// since it's in theory supported on more systems.
119
- match ( * dbghelp. dbghelp ( ) ) . StackWalkEx ( ) {
119
+ match unsafe { ( * dbghelp. dbghelp ( ) ) . StackWalkEx ( ) } {
120
120
#[ allow( non_snake_case) ]
121
121
Some ( StackWalkEx ) => {
122
- let mut inner: STACKFRAME_EX = mem:: zeroed ( ) ;
122
+ // It is a C struct meant to be used in classic "out-pointer" fashion, so we zero it
123
+ let mut inner: STACKFRAME_EX = unsafe { mem:: zeroed ( ) } ;
123
124
inner. StackFrameSize = mem:: size_of :: < STACKFRAME_EX > ( ) as u32 ;
124
125
let mut frame = super :: Frame {
125
126
inner : Frame {
@@ -133,7 +134,7 @@ pub unsafe fn trace(cb: &mut dyn FnMut(&super::Frame) -> bool) {
133
134
_ => unreachable ! ( ) ,
134
135
} ;
135
136
136
- while StackWalkEx (
137
+ while unsafe { StackWalkEx (
137
138
image as u32 ,
138
139
process,
139
140
thread,
@@ -144,9 +145,9 @@ pub unsafe fn trace(cb: &mut dyn FnMut(&super::Frame) -> bool) {
144
145
Some ( get_module_base) ,
145
146
None ,
146
147
0 ,
147
- ) == TRUE
148
+ ) == TRUE }
148
149
{
149
- frame. inner . base_address = get_module_base ( process_handle, frame. ip ( ) as _ ) as _ ;
150
+ frame. inner . base_address = unsafe { get_module_base ( process_handle, frame. ip ( ) as _ ) as _ } ;
150
151
151
152
if !cb ( & frame) {
152
153
break ;
@@ -156,7 +157,8 @@ pub unsafe fn trace(cb: &mut dyn FnMut(&super::Frame) -> bool) {
156
157
None => {
157
158
let mut frame = super :: Frame {
158
159
inner : Frame {
159
- stack_frame : StackFrame :: Old ( mem:: zeroed ( ) ) ,
160
+ // It is a C struct meant to be used in classic "out-pointer" fashion, so we zero it
161
+ stack_frame : StackFrame :: Old ( unsafe { mem:: zeroed ( ) } ) ,
160
162
base_address : 0 as _ ,
161
163
} ,
162
164
} ;
@@ -166,7 +168,7 @@ pub unsafe fn trace(cb: &mut dyn FnMut(&super::Frame) -> bool) {
166
168
_ => unreachable ! ( ) ,
167
169
} ;
168
170
169
- while dbghelp. StackWalk64 ( ) (
171
+ while unsafe { dbghelp. StackWalk64 ( ) (
170
172
image as u32 ,
171
173
process,
172
174
thread,
@@ -176,9 +178,9 @@ pub unsafe fn trace(cb: &mut dyn FnMut(&super::Frame) -> bool) {
176
178
Some ( function_table_access) ,
177
179
Some ( get_module_base) ,
178
180
None ,
179
- ) == TRUE
181
+ ) == TRUE }
180
182
{
181
- frame. inner . base_address = get_module_base ( process_handle, frame. ip ( ) as _ ) as _ ;
183
+ frame. inner . base_address = unsafe { get_module_base ( process_handle, frame. ip ( ) as _ ) as _ } ;
182
184
183
185
if !cb ( & frame) {
184
186
break ;
0 commit comments