From 508ccca014fcc3a8ef241868ea05e36058b3e61c Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Tue, 8 May 2012 16:47:18 -0700 Subject: rt: Add upcall_exchange_malloc/free --- src/rt/rust_upcall.cpp | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) (limited to 'src/rt/rust_upcall.cpp') 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 @@ -151,6 +151,61 @@ upcall_trace(char const *msg, UPCALL_SWITCH_STACK(&args, upcall_s_trace); } +/********************************************************************** + * 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(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. */ -- cgit 1.4.1-3-g733a5