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-15 15:04:29 -0700
committerBrian Anderson <banderson@mozilla.com>2012-05-30 21:23:34 -0700
commit178c5cc4a394c7991321dfd349662051d2344cb6 (patch)
treeb45064f9e980c54fcf8d409b0d8e0450605846f4 /src/rt/rust_upcall.cpp
parentc6a23cddfb66c97c5c5a5836a08c602ba2bb4f02 (diff)
downloadrust-178c5cc4a394c7991321dfd349662051d2344cb6.tar.gz
rust-178c5cc4a394c7991321dfd349662051d2344cb6.zip
rt: Add yet another allocating upcall
upcall_exchange_malloc_dyn, for allocating unique boxes for types that don't
have a fixed size.
Diffstat (limited to 'src/rt/rust_upcall.cpp')
-rw-r--r--src/rt/rust_upcall.cpp57
1 files changed, 43 insertions, 14 deletions
diff --git a/src/rt/rust_upcall.cpp b/src/rt/rust_upcall.cpp
index 55d7fc489ad..6a9d663f8fd 100644
--- a/src/rt/rust_upcall.cpp
+++ b/src/rt/rust_upcall.cpp
@@ -155,31 +155,38 @@ 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);
+extern "C" CDECL uintptr_t
+exchange_malloc(rust_task *task, type_desc *td, uintptr_t size) {
 
-    LOG(task, mem, "upcall exchange malloc(0x%" PRIxPTR ")", args->td);
+    LOG(task, mem, "upcall exchange malloc(0x%" PRIxPTR ")", 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 body_size = size;
+    size_t body_align = 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;
+    header->td = td;
+
+    return (uintptr_t)header;
+}
+
+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);
 
-    args->retval = (uintptr_t)header;
+    uintptr_t retval = exchange_malloc(task, args->td, args->td->size);
+    args->retval = retval;
 }
 
 extern "C" CDECL uintptr_t
@@ -189,6 +196,28 @@ upcall_exchange_malloc(type_desc *td) {
     return args.retval;
 }
 
+struct s_exchange_malloc_dyn_args {
+    uintptr_t retval;
+    type_desc *td;
+    uintptr_t size;
+};
+
+extern "C" CDECL void
+upcall_s_exchange_malloc_dyn(s_exchange_malloc_dyn_args *args) {
+    rust_task *task = rust_get_current_task();
+    LOG_UPCALL_ENTRY(task);
+
+    uintptr_t retval = exchange_malloc(task, args->td, args->size);
+    args->retval = retval;
+}
+
+extern "C" CDECL uintptr_t
+upcall_exchange_malloc_dyn(type_desc *td, uintptr_t size) {
+    s_exchange_malloc_dyn_args args = {0, td, size};
+    UPCALL_SWITCH_STACK(&args, upcall_s_exchange_malloc_dyn);
+    return args.retval;
+}
+
 struct s_exchange_free_args {
     void *ptr;
 };