@@ -199,23 +199,28 @@ impl Monitor {
199199 fn preempt_thread ( thread_id : u32 ) -> bool {
200200 use windows_sys:: Win32 :: Foundation :: CloseHandle ;
201201 use windows_sys:: Win32 :: System :: Diagnostics :: Debug :: CONTEXT ;
202+ use windows_sys:: Win32 :: System :: Diagnostics :: Debug :: { GetThreadContext , SetThreadContext } ;
202203 use windows_sys:: Win32 :: System :: Threading :: {
203- GetThreadContext , OpenThread , ResumeThread , SetThreadContext , SuspendThread ,
204- THREAD_GET_CONTEXT , THREAD_SET_CONTEXT , THREAD_SUSPEND_RESUME ,
204+ OpenThread , ResumeThread , SuspendThread , THREAD_GET_CONTEXT , THREAD_SET_CONTEXT ,
205+ THREAD_SUSPEND_RESUME ,
205206 } ;
206207
208+ extern "C" {
209+ fn preempt_asm ( ) ;
210+ }
211+
207212 unsafe {
208213 let handle = OpenThread (
209214 THREAD_SUSPEND_RESUME | THREAD_GET_CONTEXT | THREAD_SET_CONTEXT ,
210215 0 ,
211216 thread_id,
212217 ) ;
213- if handle == 0 {
218+ if handle. is_null ( ) {
214219 return false ;
215220 }
216221
217222 if SuspendThread ( handle) == u32:: MAX {
218- CloseHandle ( handle) ;
223+ _ = CloseHandle ( handle) ;
219224 return false ;
220225 }
221226
@@ -230,44 +235,40 @@ impl Monitor {
230235 }
231236 }
232237
233- if GetThreadContext ( handle, & mut context) == 0 {
234- ResumeThread ( handle) ;
235- CloseHandle ( handle) ;
238+ if GetThreadContext ( handle, & raw mut context) == 0 {
239+ _ = ResumeThread ( handle) ;
240+ _ = CloseHandle ( handle) ;
236241 return false ;
237242 }
238243
239- extern "C" {
240- fn preempt_asm ( ) ;
241- }
242-
243244 cfg_if:: cfg_if! {
244245 if #[ cfg( target_arch = "x86_64" ) ] {
245246 // Push original instruction pointer onto the thread's stack
246247 // so preempt_asm can RET to it after preemption.
247248 // Safety: the target thread runs on a coroutine stack allocated
248249 // by corosensei, which has ample space below the current RSP.
249250 context. Rsp -= 8 ;
250- * ( context. Rsp as usize as * mut u64 ) = context. Rip ;
251- context. Rip = preempt_asm as usize as u64 ;
251+ * ( context. Rsp as * mut u64 ) = context. Rip ;
252+ context. Rip = preempt_asm as * const ( ) as u64 ;
252253 } else if #[ cfg( target_arch = "x86" ) ] {
253254 // Push original instruction pointer onto the thread's stack
254255 // so preempt_asm can RET to it after preemption.
255256 // Safety: the target thread runs on a coroutine stack allocated
256257 // by corosensei, which has ample space below the current ESP.
257258 context. Esp -= 4 ;
258259 * ( context. Esp as usize as * mut u32 ) = context. Eip ;
259- context. Eip = preempt_asm as usize as u32 ;
260+ context. Eip = preempt_asm as * const ( ) as u32 ;
260261 }
261262 }
262263
263- if SetThreadContext ( handle, & context) == 0 {
264- ResumeThread ( handle) ;
265- CloseHandle ( handle) ;
264+ if SetThreadContext ( handle, & raw const context) == 0 {
265+ _ = ResumeThread ( handle) ;
266+ _ = CloseHandle ( handle) ;
266267 return false ;
267268 }
268269
269- ResumeThread ( handle) ;
270- CloseHandle ( handle) ;
270+ _ = ResumeThread ( handle) ;
271+ _ = CloseHandle ( handle) ;
271272 true
272273 }
273274 }
0 commit comments