diff --git a/src/rt/rust_builtin.cpp b/src/rt/rust_builtin.cpp index f9d1f71f0ac94..f9c95db1d04b2 100644 --- a/src/rt/rust_builtin.cpp +++ b/src/rt/rust_builtin.cpp @@ -182,7 +182,7 @@ rand_seed() { rust_vec *v = (rust_vec *) task->kernel->malloc(vec_size(size), "rand_seed"); v->fill = v->alloc = size; - isaac_seed(task->kernel, (uint8_t*) &v->data); + isaac_seed(task->kernel, (uint8_t*) &v->data, size); return v; } diff --git a/src/rt/rust_util.h b/src/rt/rust_util.h index e2c75d0cae4c1..018be4248eb98 100644 --- a/src/rt/rust_util.h +++ b/src/rt/rust_util.h @@ -128,9 +128,8 @@ inline size_t get_box_size(size_t body_size, size_t body_align) { // Initialization helpers for ISAAC RNG -inline void isaac_seed(rust_kernel* kernel, uint8_t* dest) +inline void isaac_seed(rust_kernel* kernel, uint8_t* dest, size_t size) { - size_t size = sizeof(ub4) * RANDSIZ; #ifdef __WIN32__ HCRYPTPROV hProv; kernel->win32_require @@ -144,8 +143,14 @@ inline void isaac_seed(rust_kernel* kernel, uint8_t* dest) #else int fd = open("/dev/urandom", O_RDONLY); assert(fd > 0); - assert(read(fd, dest, size) == (int) size); - assert(close(fd) == 0); + size_t amount = 0; + do { + ssize_t ret = read(fd, dest+amount, size-amount); + assert(ret >= 0); + amount += (size_t)ret; + } while (amount < size); + int ret = close(fd); + assert(ret == 0); #endif } @@ -167,7 +172,7 @@ isaac_init(rust_kernel *kernel, randctx *rctx, rust_vec_box* user_seed) seed = (seed + 0x7ed55d16) + (seed << 12); } } else { - isaac_seed(kernel, (uint8_t*) &rctx->randrsl); + isaac_seed(kernel, (uint8_t*) &rctx->randrsl, sizeof(rctx->randrsl)); } randinit(rctx, 1);