@@ -13,7 +13,6 @@ use crate::fmt::{self, Debug};
1313use crate :: hash:: { BuildHasher , Hash , Hasher , SipHasher13 } ;
1414use crate :: iter:: { FromIterator , FusedIterator } ;
1515use crate :: ops:: Index ;
16- use crate :: sys;
1716
1817/// A hash map implemented with quadratic probing and SIMD lookup.
1918///
@@ -2783,13 +2782,24 @@ impl RandomState {
27832782 // iteration order allows a form of DOS attack. To counter that we
27842783 // increment one of the seeds on every RandomState creation, giving
27852784 // every corresponding HashMap a different iteration order.
2786- thread_local ! ( static KEYS : Cell <( u64 , u64 ) > = {
2787- Cell :: new( sys:: hashmap_random_keys( ) )
2785+ thread_local ! ( static KEYS : Cell <[ u64 ; 2 ] > = {
2786+ let mut buf = [ 0u8 ; 16 ] ;
2787+ // Use a constant seed on `wasm32-unknown-unknown` and Hermit targets.
2788+ // FIXME: remove the Hermit part after its support will be added to `getrandom`
2789+ // TODO: replace the WASM part with `cfg(target = "..")`:
2790+ // https://github.com/rust-lang/rust/issues/63217
2791+ #[ cfg( not( any(
2792+ all( target_arch = "wasm32" , target_vendor = "unknown" , target_os = "unknown" ) ,
2793+ all( target_arch = "aarch64" , target_os = "hermit" ) ,
2794+ ) ) ) ]
2795+ getrandom:: getrandom( & mut buf) . expect( "failed to get system entropy" ) ;
2796+ let n = u128 :: from_ne_bytes( buf) ;
2797+ Cell :: new( [ n as u64 , ( n >> 64 ) as u64 ] )
27882798 } ) ;
27892799
27902800 KEYS . with ( |keys| {
2791- let ( k0, k1) = keys. get ( ) ;
2792- keys. set ( ( k0. wrapping_add ( 1 ) , k1) ) ;
2801+ let [ k0, k1] = keys. get ( ) ;
2802+ keys. set ( [ k0. wrapping_add ( 1 ) , k1] ) ;
27932803 RandomState { k0, k1 }
27942804 } )
27952805 }
0 commit comments