Skip to content

[fuchsia] Update zx_cprng_draw to target semantics #51850

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

Merged
merged 1 commit into from
Jun 27, 2018
Merged
Changes from all commits
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
28 changes: 2 additions & 26 deletions src/libstd/sys/unix/rand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,34 +183,10 @@ mod imp {
mod imp {
#[link(name = "zircon")]
extern {
fn zx_cprng_draw_new(buffer: *mut u8, len: usize) -> i32;
}

fn getrandom(buf: &mut [u8]) -> Result<usize, i32> {
unsafe {
let status = zx_cprng_draw_new(buf.as_mut_ptr(), buf.len());
if status == 0 {
Ok(buf.len())
} else {
Err(status)
}
}
fn zx_cprng_draw(buffer: *mut u8, len: usize);
}

pub fn fill_bytes(v: &mut [u8]) {
let mut buf = v;
while !buf.is_empty() {
let ret = getrandom(buf);
match ret {
Err(err) => {
panic!("kernel zx_cprng_draw call failed! (returned {}, buf.len() {})",
err, buf.len())
}
Ok(actual) => {
let move_buf = buf;
buf = &mut move_buf[(actual as usize)..];
}
}
}
unsafe { zx_cprng_draw(v.as_mut_ptr(), v.len()) }
}
}