about summary refs log tree commit diff
path: root/src/libstd/sys
diff options
context:
space:
mode:
authorBaoshan Pang <baoshan.pang@windriver.com>2019-09-10 14:58:31 -0700
committerBaoshan Pang <baoshan.pang@windriver.com>2019-09-10 15:11:34 -0700
commit5287885481c018eeef3ee815f9ceab4b4106d5a2 (patch)
treee43bff810f818bc89e8e0b6326107690efacaf3b /src/libstd/sys
parent414d1047291348b5b8bf49e1d76fec978238d89f (diff)
downloadrust-5287885481c018eeef3ee815f9ceab4b4106d5a2.tar.gz
rust-5287885481c018eeef3ee815f9ceab4b4106d5a2.zip
use randSecure and randABytes
Diffstat (limited to 'src/libstd/sys')
-rw-r--r--src/libstd/sys/vxworks/rand.rs21
1 files changed, 14 insertions, 7 deletions
diff --git a/src/libstd/sys/vxworks/rand.rs b/src/libstd/sys/vxworks/rand.rs
index 1ec0cbe4dcf..c22880db2bf 100644
--- a/src/libstd/sys/vxworks/rand.rs
+++ b/src/libstd/sys/vxworks/rand.rs
@@ -14,17 +14,24 @@ pub fn hashmap_random_keys() -> (u64, u64) {
 mod imp {
     use libc;
     use crate::io;
-
-    extern "C" {
-        fn randBytes (randBuf: *mut libc::c_uchar,
-                      numOfBytes: libc::c_int) -> libc::c_int;
-    }
+    use core::sync::atomic::{AtomicBool, Ordering::Relaxed};
 
     pub fn fill_bytes(v: &mut [u8]) {
+        static RNG_INIT: AtomicBool = AtomicBool::new(false);
+        while !RNG_INIT.load(Relaxed) {
+            let ret = unsafe { libc::randSecure() };
+            if ret < 0 {
+                panic!("couldn't generate random bytes: {}", io::Error::last_os_error());
+            } else if ret > 0 {
+                RNG_INIT.store(true, Relaxed);
+                break;
+            }
+            unsafe { libc::usleep(10) };
+        }
         let ret = unsafe {
-            randBytes(v.as_mut_ptr() as *mut libc::c_uchar, v.len() as libc::c_int)
+            libc::randABytes(v.as_mut_ptr() as *mut libc::c_uchar, v.len() as libc::c_int)
         };
-        if ret == -1 {
+        if ret < 0 {
             panic!("couldn't generate random bytes: {}", io::Error::last_os_error());
         }
     }