28
28
extern crate cfg_if;
29
29
extern crate libc;
30
30
#[ cfg( windows) ]
31
- extern crate winapi ;
31
+ extern crate windows_sys ;
32
32
#[ macro_use]
33
33
extern crate psm;
34
34
@@ -92,7 +92,7 @@ pub fn remaining_stack() -> Option<usize> {
92
92
get_stack_limit ( ) . map ( |limit| current_ptr - limit)
93
93
}
94
94
95
- psm_stack_information ! (
95
+ psm_stack_information ! (
96
96
yes {
97
97
fn current_stack_ptr( ) -> usize {
98
98
psm:: stack_pointer( ) as usize
@@ -278,29 +278,27 @@ cfg_if! {
278
278
if #[ cfg( windows) ] {
279
279
use std:: ptr;
280
280
use std:: io;
281
-
282
- use winapi:: shared:: basetsd:: * ;
283
- use winapi:: shared:: minwindef:: { LPVOID , BOOL } ;
284
- use winapi:: shared:: ntdef:: * ;
285
- use winapi:: um:: fibersapi:: * ;
286
- use winapi:: um:: memoryapi:: * ;
287
- use winapi:: um:: processthreadsapi:: * ;
288
- use winapi:: um:: winbase:: * ;
281
+ use libc:: c_void;
282
+ use windows_sys:: Win32 :: System :: Threading :: { SwitchToFiber , IsThreadAFiber , ConvertThreadToFiber ,
283
+ CreateFiber , DeleteFiber , ConvertFiberToThread , SetThreadStackGuarantee
284
+ } ;
285
+ use windows_sys:: Win32 :: Foundation :: BOOL ;
286
+ use windows_sys:: Win32 :: System :: Memory :: VirtualQuery ;
289
287
290
288
// Make sure the libstacker.a (implemented in C) is linked.
291
289
// See https://github.com/rust-lang/rust/issues/65610
292
290
#[ link( name="stacker" ) ]
293
291
extern {
294
- fn __stacker_get_current_fiber( ) -> PVOID ;
292
+ fn __stacker_get_current_fiber( ) -> * mut c_void ;
295
293
}
296
294
297
295
struct FiberInfo <F > {
298
296
callback: std:: mem:: MaybeUninit <F >,
299
297
panic: Option <Box <dyn std:: any:: Any + Send + ' static >>,
300
- parent_fiber: LPVOID ,
298
+ parent_fiber: * mut c_void ,
301
299
}
302
300
303
- unsafe extern "system" fn fiber_proc<F : FnOnce ( ) >( data: LPVOID ) {
301
+ unsafe extern "system" fn fiber_proc<F : FnOnce ( ) >( data: * mut c_void ) {
304
302
// This function is the entry point to our inner fiber, and as argument we get an
305
303
// instance of `FiberInfo`. We will set-up the "runtime" for the callback and execute
306
304
// it.
@@ -313,7 +311,6 @@ cfg_if! {
313
311
// Restore to the previous Fiber
314
312
set_stack_limit( old_stack_limit) ;
315
313
SwitchToFiber ( data. parent_fiber) ;
316
- return ;
317
314
}
318
315
319
316
fn _grow( stack_size: usize , callback: & mut dyn FnMut ( ) ) {
@@ -322,7 +319,7 @@ cfg_if! {
322
319
// to it so we can use it's stack. After running `callback` within our fiber, we switch
323
320
// back to the current stack and destroy the fiber and its associated stack.
324
321
unsafe {
325
- let was_fiber = IsThreadAFiber ( ) == TRUE as BOOL ;
322
+ let was_fiber = IsThreadAFiber ( ) == 1 as BOOL ;
326
323
let mut data = FiberInfo {
327
324
callback: std:: mem:: MaybeUninit :: new( callback) ,
328
325
panic: None ,
@@ -346,7 +343,7 @@ cfg_if! {
346
343
}
347
344
348
345
let fiber = CreateFiber (
349
- stack_size as SIZE_T ,
346
+ stack_size as usize ,
350
347
Some ( fiber_proc:: <& mut dyn FnMut ( ) >) ,
351
348
& mut data as * mut FiberInfo <& mut dyn FnMut ( ) > as * mut _,
352
349
) ;
@@ -361,12 +358,11 @@ cfg_if! {
361
358
DeleteFiber ( fiber) ;
362
359
363
360
// Clean-up.
364
- if !was_fiber {
365
- if ConvertFiberToThread ( ) == 0 {
361
+ if !was_fiber && ConvertFiberToThread ( ) == 0 {
366
362
// FIXME: Perhaps should not panic here?
367
363
panic!( "unable to convert back to thread: {}" , io:: Error :: last_os_error( ) ) ;
368
- }
369
364
}
365
+
370
366
if let Some ( p) = data. panic {
371
367
std:: panic:: resume_unwind( p) ;
372
368
}
@@ -400,12 +396,12 @@ cfg_if! {
400
396
// to discover the size of the stack
401
397
//
402
398
// FIXME: we could read stack base from the TIB, specifically the 3rd element of it.
403
- type QueryT = winapi :: um :: winnt :: MEMORY_BASIC_INFORMATION ;
399
+ type QueryT = windows_sys :: Win32 :: System :: Memory :: MEMORY_BASIC_INFORMATION ;
404
400
let mut mi = std:: mem:: MaybeUninit :: <QueryT >:: uninit( ) ;
405
401
VirtualQuery (
406
402
psm:: stack_pointer( ) as * const _,
407
403
mi. as_mut_ptr( ) ,
408
- std:: mem:: size_of:: <QueryT >( ) as SIZE_T ,
404
+ std:: mem:: size_of:: <QueryT >( ) as usize ,
409
405
) ;
410
406
Some ( mi. assume_init( ) . AllocationBase as usize + get_thread_stack_guarantee( ) + 0x1000 )
411
407
}
0 commit comments