Merge branch 'master' into redox
This commit is contained in:
commit
0bb9a95907
896 changed files with 53004 additions and 8585 deletions
|
|
@ -23,7 +23,7 @@
|
|||
//! integration code in `std::sys_common`. See that module's
|
||||
//! documentation for details.
|
||||
//!
|
||||
//! In the future it would be desirable for the indepedent
|
||||
//! In the future it would be desirable for the independent
|
||||
//! implementations of this module to be extracted to their own crates
|
||||
//! that `std` can link to, thus enabling their implementation
|
||||
//! out-of-tree via crate replacement. Though due to the complex
|
||||
|
|
|
|||
|
|
@ -350,11 +350,19 @@ mod imp {
|
|||
|
||||
#[link(name = "magenta")]
|
||||
extern {
|
||||
fn mx_cprng_draw(buffer: *mut u8, len: usize) -> isize;
|
||||
fn mx_cprng_draw(buffer: *mut u8, len: usize, actual: *mut usize) -> i32;
|
||||
}
|
||||
|
||||
fn getrandom(buf: &mut [u8]) -> isize {
|
||||
unsafe { mx_cprng_draw(buf.as_mut_ptr(), buf.len()) }
|
||||
fn getrandom(buf: &mut [u8]) -> Result<usize, i32> {
|
||||
unsafe {
|
||||
let mut actual = 0;
|
||||
let status = mx_cprng_draw(buf.as_mut_ptr(), buf.len(), &mut actual);
|
||||
if status == 0 {
|
||||
Ok(actual)
|
||||
} else {
|
||||
Err(status)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct OsRng {
|
||||
|
|
@ -381,12 +389,16 @@ mod imp {
|
|||
let mut buf = v;
|
||||
while !buf.is_empty() {
|
||||
let ret = getrandom(buf);
|
||||
if ret < 0 {
|
||||
panic!("kernel mx_cprng_draw call failed! (returned {}, buf.len() {})",
|
||||
ret, buf.len());
|
||||
match ret {
|
||||
Err(err) => {
|
||||
panic!("kernel mx_cprng_draw call failed! (returned {}, buf.len() {})",
|
||||
err, buf.len())
|
||||
}
|
||||
Ok(actual) => {
|
||||
let move_buf = buf;
|
||||
buf = &mut move_buf[(actual as usize)..];
|
||||
}
|
||||
}
|
||||
let move_buf = buf;
|
||||
buf = &mut move_buf[(ret as usize)..];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue