about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2018-06-27 17:20:27 +0000
committerbors <bors@rust-lang.org>2018-06-27 17:20:27 +0000
commit4aff10bb1b9b202bb6464f99d198d3e6f49e6991 (patch)
tree6655864497bc1e8907c5a65e4efd5e5dc0be5661 /src/libstd
parented0350e94569d74bdfe0e612fedfd5ab173f5242 (diff)
parenta9f7cc3b4968d1ec5a8bc857a83ea7ade33fffa8 (diff)
downloadrust-4aff10bb1b9b202bb6464f99d198d3e6f49e6991.tar.gz
rust-4aff10bb1b9b202bb6464f99d198d3e6f49e6991.zip
Auto merge of #51850 - abarth:draw_again, r=cramertj
[fuchsia] Update zx_cprng_draw to target semantics

This change is the final step in improving the semantics of
zx_cprng_draw. Now the syscall always generates the requested number of
bytes. If the syscall would have failed to generate the requested number
of bytes, the syscall either terminates the entire operating system or
terminates the calling process, depending on whether the error is a
result of the kernel misbehaving or the userspace program misbehaving.
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/sys/unix/rand.rs28
1 files changed, 2 insertions, 26 deletions
diff --git a/src/libstd/sys/unix/rand.rs b/src/libstd/sys/unix/rand.rs
index 3f7f0671490..01c0ada4ffb 100644
--- a/src/libstd/sys/unix/rand.rs
+++ b/src/libstd/sys/unix/rand.rs
@@ -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()) }
     }
 }