diff options
| author | Michael Sullivan <sully@msully.net> | 2012-06-13 17:59:21 -0700 |
|---|---|---|
| committer | Michael Sullivan <sully@msully.net> | 2012-06-13 17:59:21 -0700 |
| commit | 4c0d41cffae78725c20a40302e81ef1246c3e4c7 (patch) | |
| tree | 22bc0c98ad81612eff343237e5cc8d529e552f49 /src/rt/rust_upcall.cpp | |
| parent | 31f4b63dffb49e65d3de4ecbef573e15b0f44e36 (diff) | |
| download | rust-4c0d41cffae78725c20a40302e81ef1246c3e4c7.tar.gz rust-4c0d41cffae78725c20a40302e81ef1246c3e4c7.zip | |
Add a malloc_dyn upcall for dynamically sized allocations on the shared heap.
Diffstat (limited to 'src/rt/rust_upcall.cpp')
| -rw-r--r-- | src/rt/rust_upcall.cpp | 74 |
1 files changed, 46 insertions, 28 deletions
diff --git a/src/rt/rust_upcall.cpp b/src/rt/rust_upcall.cpp index f523f82a4f5..f5745fe4b86 100644 --- a/src/rt/rust_upcall.cpp +++ b/src/rt/rust_upcall.cpp @@ -144,14 +144,8 @@ exchange_malloc(rust_task *task, type_desc *td, uintptr_t size) { 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 = size; - size_t body_align = td->align; - // FIXME: This alignment calculation is suspicious. Is it right? - size_t total_size = align_to(header_size, body_align) + body_size; - - void *p = task->kernel->malloc(total_size, "exchange malloc"); + size_t total_size = get_box_size(size, td->align); + void *p = task->kernel->calloc(total_size, "exchange malloc"); rust_opaque_box *header = static_cast<rust_opaque_box*>(p); header->ref_count = -1; // This is not ref counted @@ -159,8 +153,6 @@ exchange_malloc(rust_task *task, type_desc *td, uintptr_t size) { header->prev = 0; header->next = 0; - memset(&header[1], '\0', body_size); - return (uintptr_t)header; } @@ -174,8 +166,7 @@ upcall_s_exchange_malloc(s_exchange_malloc_args *args) { rust_task *task = rust_get_current_task(); LOG_UPCALL_ENTRY(task); - uintptr_t retval = exchange_malloc(task, args->td, args->td->size); - args->retval = retval; + args->retval = exchange_malloc(task, args->td, args->td->size); } extern "C" CDECL uintptr_t @@ -196,8 +187,7 @@ 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; + args->retval = exchange_malloc(task, args->td, args->size); } extern "C" CDECL uintptr_t @@ -228,22 +218,14 @@ upcall_exchange_free(void *ptr) { * Allocate an object in the task-local heap. */ -struct s_malloc_args { - uintptr_t retval; - type_desc *td; -}; - -extern "C" CDECL void -upcall_s_malloc(s_malloc_args *args) { - rust_task *task = rust_get_current_task(); - LOG_UPCALL_ENTRY(task); - - LOG(task, mem, "upcall malloc(0x%" PRIxPTR ")", args->td); +extern "C" CDECL uintptr_t +shared_malloc(rust_task *task, type_desc *td, uintptr_t size) { + LOG(task, mem, "upcall malloc(0x%" PRIxPTR ")", td); cc::maybe_cc(task); // FIXME--does this have to be calloc? - rust_opaque_box *box = task->boxed.calloc(args->td); + rust_opaque_box *box = task->boxed.calloc(td, size); void *body = box_body(box); debug::maybe_track_origin(task, box); @@ -251,8 +233,22 @@ upcall_s_malloc(s_malloc_args *args) { LOG(task, mem, "upcall malloc(0x%" PRIxPTR ") = box 0x%" PRIxPTR " with body 0x%" PRIxPTR, - args->td, (uintptr_t)box, (uintptr_t)body); - args->retval = (uintptr_t) box; + td, (uintptr_t)box, (uintptr_t)body); + + return (uintptr_t)box; +} + +struct s_malloc_args { + uintptr_t retval; + type_desc *td; +}; + +extern "C" CDECL void +upcall_s_malloc(s_malloc_args *args) { + rust_task *task = rust_get_current_task(); + LOG_UPCALL_ENTRY(task); + + args->retval = shared_malloc(task, args->td, args->td->size); } extern "C" CDECL uintptr_t @@ -262,6 +258,28 @@ upcall_malloc(type_desc *td) { return args.retval; } +struct s_malloc_dyn_args { + uintptr_t retval; + type_desc *td; + uintptr_t size; +}; + +extern "C" CDECL void +upcall_s_malloc_dyn(s_malloc_dyn_args *args) { + rust_task *task = rust_get_current_task(); + LOG_UPCALL_ENTRY(task); + + args->retval = shared_malloc(task, args->td, args->size); +} + +extern "C" CDECL uintptr_t +upcall_malloc_dyn(type_desc *td, uintptr_t size) { + s_malloc_dyn_args args = {0, td, size}; + UPCALL_SWITCH_STACK(&args, upcall_s_malloc_dyn); + return args.retval; +} + + /********************************************************************** * Called whenever an object in the task-local heap is freed. */ |
