]> git.lizzy.rs Git - rust.git/blob - library/std/src/sys/windows/rand.rs
Merge commit '05677b6bd6c938ed760835d9b1f6514992654ae3' into sync_cg_clif-2021-08-06
[rust.git] / library / std / src / sys / windows / rand.rs
1 use crate::io;
2 use crate::mem;
3 use crate::sys::c;
4
5 #[cfg(not(target_vendor = "uwp"))]
6 pub fn hashmap_random_keys() -> (u64, u64) {
7     let mut v = (0, 0);
8     let ret =
9         unsafe { c::RtlGenRandom(&mut v as *mut _ as *mut u8, mem::size_of_val(&v) as c::ULONG) };
10     if ret == 0 {
11         panic!("couldn't generate random bytes: {}", io::Error::last_os_error());
12     }
13     v
14 }
15
16 #[cfg(target_vendor = "uwp")]
17 pub fn hashmap_random_keys() -> (u64, u64) {
18     use crate::ptr;
19
20     let mut v = (0, 0);
21     let ret = unsafe {
22         c::BCryptGenRandom(
23             ptr::null_mut(),
24             &mut v as *mut _ as *mut u8,
25             mem::size_of_val(&v) as c::ULONG,
26             c::BCRYPT_USE_SYSTEM_PREFERRED_RNG,
27         )
28     };
29     if ret != 0 {
30         panic!("couldn't generate random bytes: {}", io::Error::last_os_error());
31     }
32     return v;
33 }