diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2016-11-04 16:49:33 -0700 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2016-11-05 10:50:25 -0700 |
| commit | 8e5c91a6fb842257b7ae38967da7073ff9a2f528 (patch) | |
| tree | d5b02183e911fea34c247ae34b5533750f013e71 /src/libstd/sys | |
| parent | 5bce6ad16ad39468fdc4da91103f4fbe2d3233d7 (diff) | |
| parent | fe953dc16ee205ec27a946398f2d3350666962e3 (diff) | |
| download | rust-8e5c91a6fb842257b7ae38967da7073ff9a2f528.tar.gz rust-8e5c91a6fb842257b7ae38967da7073ff9a2f528.zip | |
Rollup merge of #37589 - raphlinus:fuchsia_random, r=alexcrichton
std: Track change to cprng syscall signature (Fuchsia) The mx_cprng_draw syscall has changed signature to separate the status and size return values, rather than multiplexing them into a single value with errors interpreted as a negative value. This patch tracks that change.
Diffstat (limited to 'src/libstd/sys')
| -rw-r--r-- | src/libstd/sys/unix/rand.rs | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/src/libstd/sys/unix/rand.rs b/src/libstd/sys/unix/rand.rs index 3aebb8c18ec..9b1cf6ffd0e 100644 --- a/src/libstd/sys/unix/rand.rs +++ b/src/libstd/sys/unix/rand.rs @@ -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)..]; } } } |
