diff options
| author | Mazdak Farrokhzad <twingoow@gmail.com> | 2019-09-14 16:42:25 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-09-14 16:42:25 +0200 |
| commit | 1e2a97018f822edb310742838245d6457370c089 (patch) | |
| tree | f3867b8f0fb0ee8d3695fed3ea3db4521b0416e9 /src/libstd/sys | |
| parent | 10541584d134089e914dd0ee6eadc384b86c94b7 (diff) | |
| parent | 83e7976c842a8ad73aa176b8439e1a2480596134 (diff) | |
| download | rust-1e2a97018f822edb310742838245d6457370c089.tar.gz rust-1e2a97018f822edb310742838245d6457370c089.zip | |
Rollup merge of #64372 - Wind-River:master, r=alexcrichton
use randSecure and randABytes r? @alexcrichton cc @n-salim
Diffstat (limited to 'src/libstd/sys')
| -rw-r--r-- | src/libstd/sys/vxworks/rand.rs | 21 |
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()); } } |
