about summary refs log tree commit diff
path: root/src/rt
diff options
context:
space:
mode:
authorBrian Anderson <banderson@mozilla.com>2013-05-02 20:51:56 -0700
committerBrian Anderson <banderson@mozilla.com>2013-05-02 20:51:56 -0700
commit6c478c7de889ec4943b9dcdcbfbb8a8244f479cc (patch)
tree7f9fd01150a7611007255cbb2e45cf41e0cd4989 /src/rt
parentbaa1c1834f608c8c789db6d2495626ff9d28dd96 (diff)
parentf8dffc6789113a10c9dbf1d815c3569b19b53e96 (diff)
downloadrust-6c478c7de889ec4943b9dcdcbfbb8a8244f479cc.tar.gz
rust-6c478c7de889ec4943b9dcdcbfbb8a8244f479cc.zip
Merge remote-tracking branch 'brson/io' into incoming
Conflicts:
	mk/rt.mk
	src/libcore/run.rs
Diffstat (limited to 'src/rt')
-rw-r--r--src/rt/boxed_region.cpp14
-rw-r--r--src/rt/boxed_region.h6
-rw-r--r--src/rt/memory_region.cpp15
-rw-r--r--src/rt/memory_region.h5
-rw-r--r--src/rt/rust_builtin.cpp57
-rw-r--r--src/rt/rust_sched_loop.cpp2
-rw-r--r--src/rt/rust_task.cpp2
-rw-r--r--src/rt/rust_test_helpers.cpp11
-rw-r--r--src/rt/rust_upcall.cpp16
-rw-r--r--src/rt/rustrt.def.in10
10 files changed, 114 insertions, 24 deletions
diff --git a/src/rt/boxed_region.cpp b/src/rt/boxed_region.cpp
index d159df03dc3..a49b52bffe1 100644
--- a/src/rt/boxed_region.cpp
+++ b/src/rt/boxed_region.cpp
@@ -27,11 +27,11 @@ rust_opaque_box *boxed_region::malloc(type_desc *td, size_t body_size) {
     if (live_allocs) live_allocs->prev = box;
     live_allocs = box;
 
-    LOG(rust_get_current_task(), box,
+    /*LOG(rust_get_current_task(), box,
         "@malloc()=%p with td %p, size %lu==%lu+%lu, "
         "align %lu, prev %p, next %p\n",
         box, td, total_size, sizeof(rust_opaque_box), body_size,
-        td->align, box->prev, box->next);
+        td->align, box->prev, box->next);*/
 
     return box;
 }
@@ -50,9 +50,9 @@ rust_opaque_box *boxed_region::realloc(rust_opaque_box *box,
     if (new_box->next) new_box->next->prev = new_box;
     if (live_allocs == box) live_allocs = new_box;
 
-    LOG(rust_get_current_task(), box,
+    /*LOG(rust_get_current_task(), box,
         "@realloc()=%p with orig=%p, size %lu==%lu+%lu",
-        new_box, box, total_size, sizeof(rust_opaque_box), new_size);
+        new_box, box, total_size, sizeof(rust_opaque_box), new_size);*/
 
     return new_box;
 }
@@ -74,15 +74,15 @@ void boxed_region::free(rust_opaque_box *box) {
     // double frees (kind of).
     assert(box->td != NULL);
 
-    LOG(rust_get_current_task(), box,
+    /*LOG(rust_get_current_task(), box,
         "@free(%p) with td %p, prev %p, next %p\n",
-        box, box->td, box->prev, box->next);
+        box, box->td, box->prev, box->next);*/
 
     if (box->prev) box->prev->next = box->next;
     if (box->next) box->next->prev = box->prev;
     if (live_allocs == box) live_allocs = box->next;
 
-    if (env->poison_on_free) {
+    if (poison_on_free) {
         memset(box_body(box), 0xab, box->td->size);
     }
 
diff --git a/src/rt/boxed_region.h b/src/rt/boxed_region.h
index 4097b6d41b7..178772007e5 100644
--- a/src/rt/boxed_region.h
+++ b/src/rt/boxed_region.h
@@ -24,7 +24,7 @@ struct rust_env;
  * a type descr which describes the payload (what follows the header). */
 class boxed_region {
 private:
-    rust_env *env;
+    bool poison_on_free;
     memory_region *backing_region;
     rust_opaque_box *live_allocs;
 
@@ -41,8 +41,8 @@ private:
     boxed_region& operator=(const boxed_region& rhs);
 
 public:
-    boxed_region(rust_env *e, memory_region *br)
-        : env(e)
+    boxed_region(memory_region *br, bool poison_on_free)
+        : poison_on_free(poison_on_free)
         , backing_region(br)
         , live_allocs(NULL)
     {}
diff --git a/src/rt/memory_region.cpp b/src/rt/memory_region.cpp
index 6de9d5a1df4..f3406712cb0 100644
--- a/src/rt/memory_region.cpp
+++ b/src/rt/memory_region.cpp
@@ -11,7 +11,6 @@
 
 #include "sync/sync.h"
 #include "memory_region.h"
-#include "rust_env.h"
 
 #if RUSTRT_TRACK_ALLOCATIONS >= 3
 #include <execinfo.h>
@@ -35,15 +34,19 @@ void *memory_region::get_data(alloc_header *ptr) {
     return (void*)((char *)ptr + HEADER_SIZE);
 }
 
-memory_region::memory_region(rust_env *env, bool synchronized) :
-    _env(env), _parent(NULL), _live_allocations(0),
-    _detailed_leaks(env->detailed_leaks),
+memory_region::memory_region(bool synchronized,
+                             bool detailed_leaks,
+                             bool poison_on_free) :
+    _parent(NULL), _live_allocations(0),
+    _detailed_leaks(detailed_leaks),
+    _poison_on_free(poison_on_free),
     _synchronized(synchronized) {
 }
 
 memory_region::memory_region(memory_region *parent) :
-    _env(parent->_env), _parent(parent), _live_allocations(0),
+    _parent(parent), _live_allocations(0),
     _detailed_leaks(parent->_detailed_leaks),
+    _poison_on_free(parent->_poison_on_free),
     _synchronized(parent->_synchronized) {
 }
 
@@ -241,7 +244,7 @@ memory_region::claim_alloc(void *mem) {
 void
 memory_region::maybe_poison(void *mem) {
 
-    if (!_env->poison_on_free)
+    if (!_poison_on_free)
         return;
 
 #   if RUSTRT_TRACK_ALLOCATIONS >= 1
diff --git a/src/rt/memory_region.h b/src/rt/memory_region.h
index 999a992eefa..4ad57c11809 100644
--- a/src/rt/memory_region.h
+++ b/src/rt/memory_region.h
@@ -54,11 +54,11 @@ private:
     inline alloc_header *get_header(void *mem);
     inline void *get_data(alloc_header *);
 
-    rust_env *_env;
     memory_region *_parent;
     int _live_allocations;
     array_list<alloc_header *> _allocation_list;
     const bool _detailed_leaks;
+    const bool _poison_on_free;
     const bool _synchronized;
     lock_and_signal _lock;
 
@@ -75,7 +75,8 @@ private:
     memory_region& operator=(const memory_region& rhs);
 
 public:
-    memory_region(rust_env *env, bool synchronized);
+    memory_region(bool synchronized,
+                  bool detailed_leaks, bool poison_on_free);
     memory_region(memory_region *parent);
     void *malloc(size_t size, const char *tag);
     void *realloc(void *mem, size_t size);
diff --git a/src/rt/rust_builtin.cpp b/src/rt/rust_builtin.cpp
index ee025a39ff4..8b7b89680fc 100644
--- a/src/rt/rust_builtin.cpp
+++ b/src/rt/rust_builtin.cpp
@@ -856,6 +856,63 @@ rust_initialize_global_state() {
     }
 }
 
+extern "C" CDECL memory_region*
+rust_new_memory_region(uintptr_t synchronized,
+                       uintptr_t detailed_leaks,
+                       uintptr_t poison_on_free) {
+    return new memory_region((bool)synchronized,
+                             (bool)detailed_leaks,
+                             (bool)poison_on_free);
+}
+
+extern "C" CDECL void
+rust_delete_memory_region(memory_region *region) {
+    delete region;
+}
+
+extern "C" CDECL boxed_region*
+rust_new_boxed_region(memory_region *region,
+                      uintptr_t poison_on_free) {
+    return new boxed_region(region, poison_on_free);
+}
+
+extern "C" CDECL void
+rust_delete_boxed_region(boxed_region *region) {
+    delete region;
+}
+
+extern "C" CDECL rust_opaque_box*
+rust_boxed_region_malloc(boxed_region *region, type_desc *td, size_t size) {
+    return region->malloc(td, size);
+}
+
+extern "C" CDECL void
+rust_boxed_region_free(boxed_region *region, rust_opaque_box *box) {
+    region->free(box);
+}
+
+typedef void *(rust_try_fn)(void*, void*);
+
+extern "C" CDECL uintptr_t
+rust_try(rust_try_fn f, void *fptr, void *env) {
+    try {
+        f(fptr, env);
+    } catch (uintptr_t token) {
+        assert(token != 0);
+        return token;
+    }
+    return 0;
+}
+
+extern "C" CDECL void
+rust_begin_unwind(uintptr_t token) {
+#ifndef __WIN32__
+    throw token;
+#else
+    abort();
+#endif
+}
+
 //
 // Local Variables:
 // mode: C++
diff --git a/src/rt/rust_sched_loop.cpp b/src/rt/rust_sched_loop.cpp
index dbcbd7b83cf..2911b970b13 100644
--- a/src/rt/rust_sched_loop.cpp
+++ b/src/rt/rust_sched_loop.cpp
@@ -38,7 +38,7 @@ rust_sched_loop::rust_sched_loop(rust_scheduler *sched, int id, bool killed) :
     sched(sched),
     log_lvl(log_debug),
     min_stack_size(kernel->env->min_stack_size),
-    local_region(kernel->env, false),
+    local_region(false, kernel->env->detailed_leaks, kernel->env->poison_on_free),
     // FIXME #2891: calculate a per-scheduler name.
     name("main")
 {
diff --git a/src/rt/rust_task.cpp b/src/rt/rust_task.cpp
index e6293aa5c1d..7e3c91f6211 100644
--- a/src/rt/rust_task.cpp
+++ b/src/rt/rust_task.cpp
@@ -36,7 +36,7 @@ rust_task::rust_task(rust_sched_loop *sched_loop, rust_task_state state,
     kernel(sched_loop->kernel),
     name(name),
     list_index(-1),
-    boxed(sched_loop->kernel->env, &local_region),
+    boxed(&local_region, sched_loop->kernel->env->poison_on_free),
     local_region(&sched_loop->local_region),
     unwinding(false),
     total_stack_sz(0),
diff --git a/src/rt/rust_test_helpers.cpp b/src/rt/rust_test_helpers.cpp
index 64966bd3454..d82c39d6838 100644
--- a/src/rt/rust_test_helpers.cpp
+++ b/src/rt/rust_test_helpers.cpp
@@ -165,3 +165,14 @@ extern "C" CDECL TwoDoubles
 rust_dbg_extern_identity_TwoDoubles(TwoDoubles u) {
     return u;
 }
+
+// Generates increasing port numbers for network testing
+extern "C" CDECL uintptr_t
+rust_dbg_next_port() {
+  static lock_and_signal dbg_port_lock;
+  static uintptr_t next_port = 9600;
+  scoped_lock with(dbg_port_lock);
+  uintptr_t this_port = next_port;
+  next_port += 1;
+  return this_port;
+}
diff --git a/src/rt/rust_upcall.cpp b/src/rt/rust_upcall.cpp
index 59f06feee4b..658fdec6df2 100644
--- a/src/rt/rust_upcall.cpp
+++ b/src/rt/rust_upcall.cpp
@@ -293,7 +293,13 @@ upcall_rust_personality(int version,
     s_rust_personality_args args = {(_Unwind_Reason_Code)0,
                                     version, actions, exception_class,
                                     ue_header, context};
-    rust_task *task = rust_get_current_task();
+    rust_task *task = rust_try_get_current_task();
+
+    if (task == NULL) {
+        // Assuming we're running with the new scheduler
+        upcall_s_rust_personality(&args);
+        return args.retval;
+    }
 
     // The personality function is run on the stack of the
     // last function that threw or landed, which is going
@@ -330,8 +336,12 @@ upcall_del_stack() {
 // needs to acquire the value of the stack pointer
 extern "C" CDECL void
 upcall_reset_stack_limit() {
-    rust_task *task = rust_get_current_task();
-    task->reset_stack_limit();
+    rust_task *task = rust_try_get_current_task();
+    if (task != NULL) {
+        task->reset_stack_limit();
+    } else {
+        // We must be in a newsched task
+    }
 }
 
 //
diff --git a/src/rt/rustrt.def.in b/src/rt/rustrt.def.in
index 408e2e9a816..3ca05b94711 100644
--- a/src/rt/rustrt.def.in
+++ b/src/rt/rustrt.def.in
@@ -224,4 +224,12 @@ rust_uv_free_ip4_addr
 rust_uv_free_ip6_addr
 rust_call_nullary_fn
 rust_initialize_global_state
-
+rust_dbg_next_port
+rust_new_memory_region
+rust_delete_memory_region
+rust_new_boxed_region
+rust_delete_boxed_region
+rust_boxed_region_malloc
+rust_boxed_region_free
+rust_try
+rust_begin_unwind