about summary refs log tree commit diff
path: root/src/rt/rust_upcall.cpp
diff options
context:
space:
mode:
authorBrian Anderson <banderson@mozilla.com>2012-05-08 16:47:18 -0700
committerBrian Anderson <banderson@mozilla.com>2012-05-30 21:23:33 -0700
commit508ccca014fcc3a8ef241868ea05e36058b3e61c (patch)
tree7c6d2e53921eff3bf172bf16d6de8f3e76e2033c /src/rt/rust_upcall.cpp
parent6d37c90ce638f6bbf2b9abdc6625fcb1d8887bfe (diff)
downloadrust-508ccca014fcc3a8ef241868ea05e36058b3e61c.tar.gz
rust-508ccca014fcc3a8ef241868ea05e36058b3e61c.zip
rt: Add upcall_exchange_malloc/free
Diffstat (limited to 'src/rt/rust_upcall.cpp')
-rw-r--r--src/rt/rust_upcall.cpp55
1 files changed, 55 insertions, 0 deletions
diff --git a/src/rt/rust_upcall.cpp b/src/rt/rust_upcall.cpp
index 9ad1f3a5e4d..55d7fc489ad 100644
--- a/src/rt/rust_upcall.cpp
+++ b/src/rt/rust_upcall.cpp
@@ -152,6 +152,61 @@ upcall_trace(char const *msg,
 }
 
 /**********************************************************************
+ * Allocate an object in the exchange heap
+ */
+
+struct s_exchange_malloc_args {
+    uintptr_t retval;
+    type_desc *td;
+};
+
+extern "C" CDECL void
+upcall_s_exchange_malloc(s_exchange_malloc_args *args) {
+    rust_task *task = rust_get_current_task();
+    LOG_UPCALL_ENTRY(task);
+
+    LOG(task, mem, "upcall exchange malloc(0x%" PRIxPTR ")", args->td);
+
+    // Copied from boxed_region
+    size_t header_size = sizeof(rust_opaque_box);
+    size_t body_size = args->td->size;
+    size_t body_align = args->td->align;
+    size_t total_size = align_to(header_size, body_align) + body_size;
+
+    void *p = task->kernel->malloc(total_size, "exchange malloc");
+    memset(p, '\0', total_size);
+
+    rust_opaque_box *header = static_cast<rust_opaque_box*>(p);
+    header->td = args->td;
+
+    args->retval = (uintptr_t)header;
+}
+
+extern "C" CDECL uintptr_t
+upcall_exchange_malloc(type_desc *td) {
+    s_exchange_malloc_args args = {0, td};
+    UPCALL_SWITCH_STACK(&args, upcall_s_exchange_malloc);
+    return args.retval;
+}
+
+struct s_exchange_free_args {
+    void *ptr;
+};
+
+extern "C" CDECL void
+upcall_s_exchange_free(s_exchange_free_args *args) {
+    rust_task *task = rust_get_current_task();
+    LOG_UPCALL_ENTRY(task);
+    task->kernel->free(args->ptr);
+}
+
+extern "C" CDECL void
+upcall_exchange_free(void *ptr) {
+    s_exchange_free_args args = {ptr};
+    UPCALL_SWITCH_STACK(&args, upcall_s_exchange_free);
+}
+
+/**********************************************************************
  * Allocate an object in the task-local heap.
  */