@@ -13,7 +13,6 @@ use crate::fmt::{self, Debug};
13
13
use crate :: hash:: { BuildHasher , Hash , Hasher , SipHasher13 } ;
14
14
use crate :: iter:: { FromIterator , FusedIterator } ;
15
15
use crate :: ops:: Index ;
16
- use crate :: sys;
17
16
18
17
/// A hash map implemented with quadratic probing and SIMD lookup.
19
18
///
@@ -2783,13 +2782,24 @@ impl RandomState {
2783
2782
// iteration order allows a form of DOS attack. To counter that we
2784
2783
// increment one of the seeds on every RandomState creation, giving
2785
2784
// 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 ] )
2788
2798
} ) ;
2789
2799
2790
2800
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] ) ;
2793
2803
RandomState { k0, k1 }
2794
2804
} )
2795
2805
}
0 commit comments