Skip to content

Commit ea35453

Browse files
authored
Rollup merge of rust-lang#64372 - Wind-River:master, r=alexcrichton
use randSecure and randABytes r? @alexcrichton cc @n-salim
2 parents 234436b + 83e7976 commit ea35453

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

src/libstd/sys/vxworks/rand.rs

+14-7
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,24 @@ pub fn hashmap_random_keys() -> (u64, u64) {
1414
mod imp {
1515
use libc;
1616
use crate::io;
17-
18-
extern "C" {
19-
fn randBytes (randBuf: *mut libc::c_uchar,
20-
numOfBytes: libc::c_int) -> libc::c_int;
21-
}
17+
use core::sync::atomic::{AtomicBool, Ordering::Relaxed};
2218

2319
pub fn fill_bytes(v: &mut [u8]) {
20+
static RNG_INIT: AtomicBool = AtomicBool::new(false);
21+
while !RNG_INIT.load(Relaxed) {
22+
let ret = unsafe { libc::randSecure() };
23+
if ret < 0 {
24+
panic!("couldn't generate random bytes: {}", io::Error::last_os_error());
25+
} else if ret > 0 {
26+
RNG_INIT.store(true, Relaxed);
27+
break;
28+
}
29+
unsafe { libc::usleep(10) };
30+
}
2431
let ret = unsafe {
25-
randBytes(v.as_mut_ptr() as *mut libc::c_uchar, v.len() as libc::c_int)
32+
libc::randABytes(v.as_mut_ptr() as *mut libc::c_uchar, v.len() as libc::c_int)
2633
};
27-
if ret == -1 {
34+
if ret < 0 {
2835
panic!("couldn't generate random bytes: {}", io::Error::last_os_error());
2936
}
3037
}

0 commit comments

Comments
 (0)