88//!
99//! Note that all dbghelp support is loaded dynamically, see `src/dbghelp.rs`
1010//! for more information about that.
11+ #![ deny( unsafe_op_in_unsafe_fn) ]
1112
1213use super :: super :: { dbghelp, windows_sys:: * } ;
1314use core:: ffi:: c_void;
@@ -97,11 +98,12 @@ struct MyContext(CONTEXT);
9798#[ inline( always) ]
9899pub unsafe fn trace ( cb : & mut dyn FnMut ( & super :: Frame ) -> bool ) {
99100 // 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 ( ) } ;
102103
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 ) } ;
105107
106108 // Ensure this process's symbols are initialized
107109 let dbghelp = match dbghelp:: init ( ) {
@@ -114,10 +116,11 @@ pub unsafe fn trace(cb: &mut dyn FnMut(&super::Frame) -> bool) {
114116
115117 // Attempt to use `StackWalkEx` if we can, but fall back to `StackWalk64`
116118 // since it's in theory supported on more systems.
117- match ( * dbghelp. dbghelp ( ) ) . StackWalkEx ( ) {
119+ match unsafe { ( * dbghelp. dbghelp ( ) ) . StackWalkEx ( ) } {
118120 #[ allow( non_snake_case) ]
119121 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 ( ) } ;
121124 inner. StackFrameSize = mem:: size_of :: < STACKFRAME_EX > ( ) as u32 ;
122125 let mut frame = super :: Frame {
123126 inner : Frame {
@@ -131,19 +134,20 @@ pub unsafe fn trace(cb: &mut dyn FnMut(&super::Frame) -> bool) {
131134 _ => unreachable ! ( ) ,
132135 } ;
133136
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+ } {
147151 frame. inner . base_address =
148152 unsafe { get_module_base ( process, frame. ip ( ) as _ ) as _ } ;
149153
@@ -155,7 +159,8 @@ pub unsafe fn trace(cb: &mut dyn FnMut(&super::Frame) -> bool) {
155159 None => {
156160 let mut frame = super :: Frame {
157161 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 ( ) } ) ,
159164 base_address : 0 as _ ,
160165 } ,
161166 } ;
@@ -165,18 +170,19 @@ pub unsafe fn trace(cb: &mut dyn FnMut(&super::Frame) -> bool) {
165170 _ => unreachable ! ( ) ,
166171 } ;
167172
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+ } {
180186 frame. inner . base_address =
181187 unsafe { get_module_base ( process, frame. ip ( ) as _ ) as _ } ;
182188
0 commit comments