1 // Copyright 2018 Developers of the Rand project.
3 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
4 // https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
5 // <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
6 // option. This file may not be copied, modified, or distributed
7 // except according to those terms.
9 //! Implementation for VxWorks
10 use crate::error
::{Error, RAND_SECURE_FATAL}
;
11 use crate::util_libc
::last_os_error
;
12 use core
::sync
::atomic
::{AtomicBool, Ordering::Relaxed}
;
14 pub fn getrandom_inner(dest
: &mut [u8]) -> Result
<(), Error
> {
15 static RNG_INIT
: AtomicBool
= AtomicBool
::new(false);
16 while !RNG_INIT
.load(Relaxed
) {
17 let ret
= unsafe { libc::randSecure() }
;
19 return Err(RAND_SECURE_FATAL
);
21 RNG_INIT
.store(true, Relaxed
);
24 unsafe { libc::usleep(10) }
;
27 // Prevent overflow of i32
28 for chunk
in dest
.chunks_mut(i32::max_value() as usize) {
29 let ret
= unsafe { libc::randABytes(chunk.as_mut_ptr(), chunk.len() as i32) }
;
31 return Err(last_os_error());