]> git.lizzy.rs Git - rust.git/blobdiff - src/libstd/sys/windows/rand.rs
Rollup merge of #65144 - clarfon:moo, r=sfackler
[rust.git] / src / libstd / sys / windows / rand.rs
index 0193f4defa1fff6f8d52968ed3e95748d1b33a39..993831bec188698d85939205e5aa74a208323c62 100644 (file)
@@ -2,6 +2,7 @@
 use crate::mem;
 use crate::sys::c;
 
+#[cfg(not(target_vendor = "uwp"))]
 pub fn hashmap_random_keys() -> (u64, u64) {
     let mut v = (0, 0);
     let ret = unsafe {
@@ -12,5 +13,22 @@ pub fn hashmap_random_keys() -> (u64, u64) {
         panic!("couldn't generate random bytes: {}",
                io::Error::last_os_error());
     }
+    v
+}
+
+#[cfg(target_vendor = "uwp")]
+pub fn hashmap_random_keys() -> (u64, u64) {
+    use crate::ptr;
+
+    let mut v = (0, 0);
+    let ret = unsafe {
+        c::BCryptGenRandom(ptr::null_mut(), &mut v as *mut _ as *mut u8,
+                           mem::size_of_val(&v) as c::ULONG,
+                           c::BCRYPT_USE_SYSTEM_PREFERRED_RNG)
+    };
+    if ret != 0 {
+        panic!("couldn't generate random bytes: {}",
+               io::Error::last_os_error());
+    }
     return v
 }