std: use random HashMap keys on Hermit

This commit is contained in:
joboet 2023-02-26 11:33:28 +01:00
parent 70fd012439
commit fdbf109b63
No known key found for this signature in database
GPG Key ID: 704E0149B0194B3C

View File

@ -76,9 +76,24 @@ pub fn abort_internal() -> ! {
}
}
// FIXME: just a workaround to test the system
pub fn hashmap_random_keys() -> (u64, u64) {
(1, 2)
let mut buf = [0; 16];
let mut slice = &mut buf[..];
while !slice.is_empty() {
let res = unsafe { abi::read_entropy(slice.as_mut_ptr(), slice.len(), 0) };
if res < 0 {
panic!(
"random key generation failed: {}",
crate::io::Error::from_raw_os_error(-res as i32)
);
} else {
slice = &mut slice[res as usize..];
}
}
let key1 = buf[..8].try_into().unwrap();
let key2 = buf[8..].try_into().unwrap();
(u64::from_ne_bytes(key1), u64::from_ne_bytes(key2))
}
// This function is needed by the panic runtime. The symbol is named in