8
8
//!
9
9
//! Note that all dbghelp support is loaded dynamically, see `src/dbghelp.rs`
10
10
//! for more information about that.
11
+ #![ deny( unsafe_op_in_unsafe_fn) ]
11
12
12
13
use super :: super :: { dbghelp, windows_sys:: * } ;
13
14
use core:: ffi:: c_void;
@@ -97,11 +98,12 @@ struct MyContext(CONTEXT);
97
98
#[ inline( always) ]
98
99
pub unsafe fn trace ( cb : & mut dyn FnMut ( & super :: Frame ) -> bool ) {
99
100
// Allocate necessary structures for doing the stack walk
100
- let process = GetCurrentProcess ( ) ;
101
- let thread = GetCurrentThread ( ) ;
101
+ let process = unsafe { GetCurrentProcess ( ) } ;
102
+ let thread = unsafe { GetCurrentThread ( ) } ;
102
103
103
- let mut context = mem:: zeroed :: < MyContext > ( ) ;
104
- RtlCaptureContext ( & mut context. 0 ) ;
104
+ // This is a classic C-style out-ptr struct. Zero it to start.
105
+ let mut context = unsafe { mem:: zeroed :: < MyContext > ( ) } ;
106
+ unsafe { RtlCaptureContext ( & mut context. 0 ) } ;
105
107
106
108
// Ensure this process's symbols are initialized
107
109
let dbghelp = match dbghelp:: init ( ) {
@@ -114,10 +116,11 @@ pub unsafe fn trace(cb: &mut dyn FnMut(&super::Frame) -> bool) {
114
116
115
117
// Attempt to use `StackWalkEx` if we can, but fall back to `StackWalk64`
116
118
// since it's in theory supported on more systems.
117
- match ( * dbghelp. dbghelp ( ) ) . StackWalkEx ( ) {
119
+ match unsafe { ( * dbghelp. dbghelp ( ) ) . StackWalkEx ( ) } {
118
120
#[ allow( non_snake_case) ]
119
121
Some ( StackWalkEx ) => {
120
- let mut inner: STACKFRAME_EX = mem:: zeroed ( ) ;
122
+ // This is a classic C-style out-ptr struct. Zero it to start.
123
+ let mut inner: STACKFRAME_EX = unsafe { mem:: zeroed ( ) } ;
121
124
inner. StackFrameSize = mem:: size_of :: < STACKFRAME_EX > ( ) as u32 ;
122
125
let mut frame = super :: Frame {
123
126
inner : Frame {
@@ -131,19 +134,20 @@ pub unsafe fn trace(cb: &mut dyn FnMut(&super::Frame) -> bool) {
131
134
_ => unreachable ! ( ) ,
132
135
} ;
133
136
134
- while StackWalkEx (
135
- image as u32 ,
136
- process,
137
- thread,
138
- frame_ptr,
139
- & mut context. 0 as * mut CONTEXT as * mut _ ,
140
- None ,
141
- Some ( function_table_access) ,
142
- Some ( get_module_base) ,
143
- None ,
144
- 0 ,
145
- ) == TRUE
146
- {
137
+ while unsafe {
138
+ StackWalkEx (
139
+ image as u32 ,
140
+ process,
141
+ thread,
142
+ frame_ptr,
143
+ & mut context. 0 as * mut CONTEXT as * mut _ ,
144
+ None ,
145
+ Some ( function_table_access) ,
146
+ Some ( get_module_base) ,
147
+ None ,
148
+ 0 ,
149
+ ) == TRUE
150
+ } {
147
151
frame. inner . base_address =
148
152
unsafe { get_module_base ( process, frame. ip ( ) as _ ) as _ } ;
149
153
@@ -155,7 +159,8 @@ pub unsafe fn trace(cb: &mut dyn FnMut(&super::Frame) -> bool) {
155
159
None => {
156
160
let mut frame = super :: Frame {
157
161
inner : Frame {
158
- stack_frame : StackFrame :: Old ( mem:: zeroed ( ) ) ,
162
+ // This is a classic C-style out-ptr struct. Zero it to start.
163
+ stack_frame : StackFrame :: Old ( unsafe { mem:: zeroed ( ) } ) ,
159
164
base_address : 0 as _ ,
160
165
} ,
161
166
} ;
@@ -165,18 +170,19 @@ pub unsafe fn trace(cb: &mut dyn FnMut(&super::Frame) -> bool) {
165
170
_ => unreachable ! ( ) ,
166
171
} ;
167
172
168
- while dbghelp. StackWalk64 ( ) (
169
- image as u32 ,
170
- process,
171
- thread,
172
- frame_ptr,
173
- & mut context. 0 as * mut CONTEXT as * mut _ ,
174
- None ,
175
- Some ( function_table_access) ,
176
- Some ( get_module_base) ,
177
- None ,
178
- ) == TRUE
179
- {
173
+ while unsafe {
174
+ dbghelp. StackWalk64 ( ) (
175
+ image as u32 ,
176
+ process,
177
+ thread,
178
+ frame_ptr,
179
+ & mut context. 0 as * mut CONTEXT as * mut _ ,
180
+ None ,
181
+ Some ( function_table_access) ,
182
+ Some ( get_module_base) ,
183
+ None ,
184
+ ) == TRUE
185
+ } {
180
186
frame. inner . base_address =
181
187
unsafe { get_module_base ( process, frame. ip ( ) as _ ) as _ } ;
182
188
0 commit comments