Skip to content

Commit fdbf109

Browse files
committed
std: use random HashMap keys on Hermit
1 parent 70fd012 commit fdbf109

File tree

1 file changed

+17
-2
lines changed
  • library/std/src/sys/hermit

1 file changed

+17
-2
lines changed

library/std/src/sys/hermit/mod.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,24 @@ pub fn abort_internal() -> ! {
7676
}
7777
}
7878

79-
// FIXME: just a workaround to test the system
8079
pub fn hashmap_random_keys() -> (u64, u64) {
81-
(1, 2)
80+
let mut buf = [0; 16];
81+
let mut slice = &mut buf[..];
82+
while !slice.is_empty() {
83+
let res = unsafe { abi::read_entropy(slice.as_mut_ptr(), slice.len(), 0) };
84+
if res < 0 {
85+
panic!(
86+
"random key generation failed: {}",
87+
crate::io::Error::from_raw_os_error(-res as i32)
88+
);
89+
} else {
90+
slice = &mut slice[res as usize..];
91+
}
92+
}
93+
94+
let key1 = buf[..8].try_into().unwrap();
95+
let key2 = buf[8..].try_into().unwrap();
96+
(u64::from_ne_bytes(key1), u64::from_ne_bytes(key2))
8297
}
8398

8499
// This function is needed by the panic runtime. The symbol is named in

0 commit comments

Comments
 (0)