@@ -67,31 +67,6 @@ extern "system" {
6767 fn WaitForSingleObject ( hHandle : HANDLE , dwMilliseconds : DWORD ) -> DWORD ;
6868}
6969
70- #[ link( name = "advapi32" ) ]
71- extern "system" {
72- #[ link_name = "SystemFunction036" ]
73- fn RtlGenRandom ( RandomBuffer : * mut u8 , RandomBufferLength : u32 ) -> u8 ;
74- }
75-
76- // Note that we ideally would use the `getrandom` crate, but unfortunately
77- // that causes build issues when this crate is used in rust-lang/rust (see
78- // rust-lang/rust#65014 for more information). As a result we just inline
79- // the pretty simple Windows-specific implementation of generating
80- // randomness.
81- fn getrandom ( dest : & mut [ u8 ] ) -> io:: Result < ( ) > {
82- // Prevent overflow of u32
83- for chunk in dest. chunks_mut ( u32:: MAX as usize ) {
84- let ret = unsafe { RtlGenRandom ( chunk. as_mut_ptr ( ) , chunk. len ( ) as u32 ) } ;
85- if ret == 0 {
86- return Err ( io:: Error :: new (
87- io:: ErrorKind :: Other ,
88- "failed to generate random bytes" ,
89- ) ) ;
90- }
91- }
92- Ok ( ( ) )
93- }
94-
9570impl Client {
9671 pub fn new ( limit : usize ) -> io:: Result < Client > {
9772 // Try a bunch of random semaphore names until we get a unique one,
@@ -103,9 +78,8 @@ impl Client {
10378 // slot and then immediately acquire it (without ever releaseing it
10479 // back).
10580 for _ in 0 ..100 {
106- let mut bytes = [ 0 ; 4 ] ;
107- getrandom ( & mut bytes) ?;
108- let mut name = format ! ( "__rust_jobserver_semaphore_{}\0 " , u32 :: from_ne_bytes( bytes) ) ;
81+ let bytes = getrandom:: u32 ( ) ?;
82+ let mut name = format ! ( "__rust_jobserver_semaphore_{}\0 " , bytes) ;
10983 unsafe {
11084 let create_limit = if limit == 0 { 1 } else { limit } ;
11185 let r = CreateSemaphoreA (
0 commit comments