Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ untrusted = { version = "0.7.0" }
spin = { version = "0.5.2", default-features = false }


[target.'cfg(any(target_os = "android", target_os = "linux"))'.dependencies]
[target.'cfg(any(target_os = "android", target_os = "linux", target_os = "vxworks"))'.dependencies]
libc = { version = "0.2.48", default-features = false }

[target.'cfg(any(target_os = "android", target_os = "freebsd", target_os = "linux", target_os = "netbsd", target_os = "openbsd", target_os = "solaris"))'.dependencies]
Expand Down
2 changes: 1 addition & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ fn cc(
for f in cpp_flags(target) {
let _ = c.flag(&f);
}
if &target.os != "none" && &target.os != "redox" && &target.os != "windows" {
if &target.os != "none" && &target.os != "redox" && &target.os != "windows" && &target.os != "vxworks" {
let _ = c.flag("-fstack-protector");
}

Expand Down
32 changes: 32 additions & 0 deletions src/rand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,9 @@ use self::darwin::fill as fill_impl;
#[cfg(any(target_os = "fuchsia"))]
use self::fuchsia::fill as fill_impl;

#[cfg(target_os = "vxworks")]
use self::vxworks::fill as fill_impl;

#[cfg(any(target_os = "android", target_os = "linux"))]
mod sysrand_chunk {
use crate::{c, error};
Expand Down Expand Up @@ -432,3 +435,32 @@ mod fuchsia {
fn zx_cprng_draw(buffer: *mut u8, length: usize);
}
}

#[cfg(target_os = "vxworks")]
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The supporting for VxWorks have been added in crate getrandom. The code here is copied from https://github.com/rust-random/getrandom/blob/master/src/vxworks.rs.

mod vxworks {
use crate::error;
use core::sync::atomic::{AtomicBool, Ordering::Relaxed};

pub fn fill(dest: &mut [u8]) -> Result<(), error::Unspecified> {
static RNG_INIT: AtomicBool = AtomicBool::new(false);
while !RNG_INIT.load(Relaxed) {
let ret = unsafe { libc::randSecure() };
if ret < 0 {
return Err(error::Unspecified);
} else if ret > 0 {
RNG_INIT.store(true, Relaxed);
break;
}
let _ = unsafe { libc::usleep(10) };
}

// Prevent overflow of i32
for chunk in dest.chunks_mut(i32::max_value() as usize) {
let ret = unsafe { libc::randABytes(chunk.as_mut_ptr(), chunk.len() as i32) };
if ret != 0 {
return Err(error::Unspecified);
}
}
Ok(())
}
}