Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 255
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
bdf7c94a2a7b11fd002ec38a0254625d97dd34f279234cf6cb0b4ad47113c5478a9054ce5c773168806b2f13c46eb79bb7File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
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) { | ||
Member 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 fnrng_init() -> bool{loop{let ret = unsafe{ libc::randSecure()}if ret != 0{return ret > 0;}unsafe{ libc::usleep(10)};}}pubfn getrandom_inner(dest:&mut[u8]) -> Result<(),Error>{staticRNG_INIT:LazyBool = LazyBool::new();if !RNG_INIT.unsync_init(rng_init){returnErr(RAND_SECURE_FATAL);}// Prevent overflow of i32
...You could also use a lambda, if you think it would look better. MemberAuthor 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:
Member 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.