-
Notifications
You must be signed in to change notification settings - Fork 211
Add VxWorks support #86
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
bdf7c94
a2a7b11
fd002ec
38a0254
625d97d
d34f279
234cf6c
b0b4ad4
7113c54
78a9054
ce5c773
168806b
2f13c46
eb79bb7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Copyright 2018 Developers of the Rand project. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// https://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
//! Implementation for VxWorks | ||
use crate::error::{Error, RAND_SECURE_FATAL}; | ||
use crate::util_libc::last_os_error; | ||
use core::sync::atomic::{AtomicBool, Ordering::Relaxed}; | ||
|
||
pub fn getrandom_inner(dest: &mut [u8]) -> Result<(), Error> { | ||
static RNG_INIT: AtomicBool = AtomicBool::new(false); | ||
while !RNG_INIT.load(Relaxed) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should use fn rng_init() -> bool {
loop {
let ret = unsafe { libc::randSecure() }
if ret != 0 {
return ret > 0;
}
unsafe { libc::usleep(10) };
}
} pub fn getrandom_inner(dest: &mut [u8]) -> Result<(), Error> {
static RNG_INIT: LazyBool = LazyBool::new();
if !RNG_INIT.unsync_init(rng_init) {
return Err(RAND_SECURE_FATAL);
}
// Prevent overflow of i32
... You could also use a lambda, if you think it would look better. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @BaoshanPang @n-salim There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, the system can recover after randSecure failure. This is the randSecure's function desciption:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
If I'm understanding this right, the RNG module might not be initialized, but it could become initialized later? If that's the case, the current code looks good to me. |
||
let ret = unsafe { libc::randSecure() }; | ||
if ret < 0 { | ||
return Err(RAND_SECURE_FATAL); | ||
} else if ret > 0 { | ||
RNG_INIT.store(true, Relaxed); | ||
break; | ||
} | ||
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(last_os_error()); | ||
} | ||
} | ||
Ok(()) | ||
} |
Uh oh!
There was an error while loading. Please reload this page.