summary refs log tree commit diff
path: root/src/rt/rust_builtin.cpp
diff options
context:
space:
mode:
authorGraydon Hoare <graydon@mozilla.com>2013-02-19 07:06:20 -0800
committerGraydon Hoare <graydon@mozilla.com>2013-02-19 07:06:36 -0800
commit968ab03026d716f1e648aadebe8f199bdacbe4ad (patch)
tree4a27364dcfcab05c01198462ab343e0a968ce5da /src/rt/rust_builtin.cpp
parenta8efa2133392cc846d4ea3cae14f0eb4eccb5f1e (diff)
downloadrust-968ab03026d716f1e648aadebe8f199bdacbe4ad.tar.gz
rust-968ab03026d716f1e648aadebe8f199bdacbe4ad.zip
rt: fix memory-unsafe random seed logic, r=valgrindclean
Diffstat (limited to 'src/rt/rust_builtin.cpp')
-rw-r--r--src/rt/rust_builtin.cpp35
1 files changed, 8 insertions, 27 deletions
diff --git a/src/rt/rust_builtin.cpp b/src/rt/rust_builtin.cpp
index 85caf7b2e53..2c5b56f3fa4 100644
--- a/src/rt/rust_builtin.cpp
+++ b/src/rt/rust_builtin.cpp
@@ -128,49 +128,30 @@ vec_reserve_shared(type_desc* ty, rust_vec_box** vp,
     reserve_vec_exact(task, vp, n_elts * ty->size);
 }
 
-extern "C" CDECL rust_vec*
-rand_seed() {
-    size_t size = sizeof(ub4) * RANDSIZ;
-    rust_task *task = rust_get_current_task();
-    rust_vec *v = (rust_vec *) task->kernel->malloc(vec_size<uint8_t>(size),
-                                            "rand_seed");
-    v->fill = v->alloc = size;
-    rng_gen_seed(task->kernel, (uint8_t*) &v->data, size);
-    return v;
+extern "C" CDECL size_t
+rand_seed_size() {
+    return rng_seed_size();
 }
 
-extern "C" CDECL void *
-rand_new() {
+extern "C" CDECL void
+rand_gen_seed(uint8_t* dest, size_t size) {
     rust_task *task = rust_get_current_task();
-    rust_sched_loop *thread = task->sched_loop;
-    rust_rng *rng = (rust_rng *) task->malloc(sizeof(rust_rng), "rand_new");
-    if (!rng) {
-        task->fail();
-        return NULL;
-    }
-    rng_init(thread->kernel, rng, NULL);
-    return rng;
+    rng_gen_seed(task->kernel, dest, size);
 }
 
 extern "C" CDECL void *
-rand_new_seeded(rust_vec_box* seed) {
+rand_new_seeded(uint8_t* seed, size_t seed_size) {
     rust_task *task = rust_get_current_task();
-    rust_sched_loop *thread = task->sched_loop;
     rust_rng *rng = (rust_rng *) task->malloc(sizeof(rust_rng),
                                               "rand_new_seeded");
     if (!rng) {
         task->fail();
         return NULL;
     }
-    rng_init(thread->kernel, rng, seed);
+    rng_init(task->kernel, rng, seed, seed_size);
     return rng;
 }
 
-extern "C" CDECL void *
-rand_new_seeded2(rust_vec_box** seed) {
-    return rand_new_seeded(*seed);
-}
-
 extern "C" CDECL uint32_t
 rand_next(rust_rng *rng) {
     rust_task *task = rust_get_current_task();