From b75915d0ca20c6d066a7368ad53491a55a5a57d2 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Wed, 31 Jul 2013 23:12:20 -0700 Subject: Remove the C++ runtime. Sayonara --- src/rt/rust_upcall.cpp | 243 ++----------------------------------------------- 1 file changed, 9 insertions(+), 234 deletions(-) (limited to 'src/rt/rust_upcall.cpp') diff --git a/src/rt/rust_upcall.cpp b/src/rt/rust_upcall.cpp index c011219ade8..f1b31e89df8 100644 --- a/src/rt/rust_upcall.cpp +++ b/src/rt/rust_upcall.cpp @@ -17,8 +17,6 @@ */ #include "rust_globals.h" -#include "rust_task.h" -#include "rust_sched_loop.h" #include "rust_upcall.h" #include "rust_util.h" @@ -29,28 +27,6 @@ typedef int _Unwind_Action; struct _Unwind_Context; struct _Unwind_Exception; -#ifdef __GNUC__ -#define LOG_UPCALL_ENTRY(task) \ - LOG(task, upcall, \ - "> UPCALL %s - task: %s 0x%" PRIxPTR \ - " retpc: x%" PRIxPTR, \ - __FUNCTION__, \ - (task)->name, (task), \ - __builtin_return_address(0)); -#else -#define LOG_UPCALL_ENTRY(task) \ - LOG(task, upcall, "> UPCALL task: %s @x%" PRIxPTR, \ - (task)->name, (task)); -#endif - -#define UPCALL_SWITCH_STACK(T, A, F) \ - call_upcall_on_c_stack(T, (void*)A, (void*)F) - -inline void -call_upcall_on_c_stack(rust_task *task, void *args, void *fn_ptr) { - task->call_on_c_stack(args, fn_ptr); -} - typedef void (*CDECL stack_switch_shim)(void*); /********************************************************************** @@ -62,21 +38,8 @@ typedef void (*CDECL stack_switch_shim)(void*); */ extern "C" CDECL void upcall_call_shim_on_c_stack(void *args, void *fn_ptr) { - rust_task *task = rust_try_get_current_task(); - - if (task) { - // We're running in task context, do a stack switch - try { - task->call_on_c_stack(args, fn_ptr); - } catch (...) { - // Logging here is not reliable - assert(false && "Foreign code threw an exception"); - } - } else { - // There's no task. Call the function and hope for the best - stack_switch_shim f = (stack_switch_shim)fn_ptr; - f(args); - } + stack_switch_shim f = (stack_switch_shim)fn_ptr; + f(args); } /* @@ -85,171 +48,9 @@ upcall_call_shim_on_c_stack(void *args, void *fn_ptr) { */ extern "C" CDECL void upcall_call_shim_on_rust_stack(void *args, void *fn_ptr) { - rust_task *task = rust_try_get_current_task(); - - if (task) { - try { - task->call_on_rust_stack(args, fn_ptr); - } catch (...) { - // We can't count on being able to unwind through arbitrary - // code. Our best option is to just fail hard. - // Logging here is not reliable - assert(false - && "Rust task failed after reentering the Rust stack"); - } - } else { - // There's no task. Call the function and hope for the best - stack_switch_shim f = (stack_switch_shim)fn_ptr; - f(args); - } -} - -/**********************************************************************/ - -struct s_fail_args { - rust_task *task; - char const *expr; - char const *file; - size_t line; -}; - -extern "C" CDECL void -upcall_s_fail(s_fail_args *args) { - rust_task *task = args->task; - LOG_UPCALL_ENTRY(task); - task->fail(args->expr, args->file, args->line); -} - -extern "C" CDECL void -upcall_fail(char const *expr, - char const *file, - size_t line) { - rust_task *task = rust_try_get_current_task(); - if (task == NULL) { - // FIXME #5161: Need to think about what to do here - printf("failure outside of a task"); - abort(); - } - s_fail_args args = {task,expr,file,line}; - UPCALL_SWITCH_STACK(task, &args, upcall_s_fail); -} - -// FIXME (#2861): Alias used by libcore/rt.rs to avoid naming conflicts with -// autogenerated wrappers for upcall_fail. Remove this when we fully move away -// away from the C upcall path. -extern "C" CDECL void -rust_upcall_fail(char const *expr, - char const *file, - size_t line) { - upcall_fail(expr, file, line); -} - -struct s_trace_args { - rust_task *task; - char const *msg; - char const *file; - size_t line; -}; - -/********************************************************************** - * Allocate an object in the task-local heap. - */ - -struct s_malloc_args { - rust_task *task; - uintptr_t retval; - type_desc *td; - uintptr_t size; -}; - -extern "C" CDECL void -upcall_s_malloc(s_malloc_args *args) { - rust_task *task = args->task; - LOG_UPCALL_ENTRY(task); - LOG(task, mem, "upcall malloc(0x%" PRIxPTR ")", args->td); - - rust_opaque_box *box = task->boxed.malloc(args->td, args->size); - void *body = box_body(box); - - debug::maybe_track_origin(task, box); - - 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; -} - -extern "C" CDECL uintptr_t -upcall_malloc(type_desc *td, uintptr_t size) { - rust_task *task = rust_get_current_task(); - s_malloc_args args = {task, 0, td, size}; - UPCALL_SWITCH_STACK(task, &args, upcall_s_malloc); - return args.retval; -} - -// FIXME (#2861): Alias used by libcore/rt.rs to avoid naming conflicts with -// autogenerated wrappers for upcall_malloc. Remove this when we fully move -// away from the C upcall path. -extern "C" CDECL uintptr_t -rust_upcall_malloc(type_desc *td, uintptr_t size) { - return upcall_malloc(td, size); -} - -extern "C" CDECL uintptr_t -rust_upcall_malloc_noswitch(type_desc *td, uintptr_t size) { - rust_task *task = rust_get_current_task(); - s_malloc_args args = {task, 0, td, size}; - upcall_s_malloc(&args); - return args.retval; -} - -/********************************************************************** - * Called whenever an object in the task-local heap is freed. - */ - -struct s_free_args { - rust_task *task; - void *ptr; -}; - -extern "C" CDECL void -upcall_s_free(s_free_args *args) { - rust_task *task = args->task; - LOG_UPCALL_ENTRY(task); - - rust_sched_loop *sched_loop = task->sched_loop; - DLOG(sched_loop, mem, - "upcall free(0x%" PRIxPTR ", is_gc=%" PRIdPTR ")", - (uintptr_t)args->ptr); - - debug::maybe_untrack_origin(task, args->ptr); - - rust_opaque_box *box = (rust_opaque_box*) args->ptr; - task->boxed.free(box); -} - -extern "C" CDECL void -upcall_free(void* ptr) { - rust_task *task = rust_get_current_task(); - s_free_args args = {task,ptr}; - UPCALL_SWITCH_STACK(task, &args, upcall_s_free); -} - -// FIXME (#2861): Alias used by libcore/rt.rs to avoid naming conflicts with -// autogenerated wrappers for upcall_free. Remove this when we fully move away -// away from the C upcall path. -extern "C" CDECL void -rust_upcall_free(void* ptr) { - upcall_free(ptr); -} - -extern "C" CDECL void -rust_upcall_free_noswitch(void* ptr) { - rust_task *task = rust_get_current_task(); - s_free_args args = {task,ptr}; - upcall_s_free(&args); + // There's no task. Call the function and hope for the best + stack_switch_shim f = (stack_switch_shim)fn_ptr; + f(args); } /**********************************************************************/ @@ -293,41 +94,21 @@ 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_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 - // to sometimes be the C stack. If we're on the Rust stack - // then switch to the C stack. - - if (task->on_rust_stack()) { - UPCALL_SWITCH_STACK(task, &args, upcall_s_rust_personality); - } else { - upcall_s_rust_personality(&args); - } + upcall_s_rust_personality(&args); return args.retval; } // NB: This needs to be blazing fast. Don't switch stacks extern "C" CDECL void * upcall_new_stack(size_t stk_sz, void *args_addr, size_t args_sz) { - rust_task *task = rust_get_current_task(); - return task->next_stack(stk_sz, - args_addr, - args_sz); + assert(false && "newsched shouldn't be growing the stack"); + return NULL; } // NB: This needs to be blazing fast. Don't switch stacks extern "C" CDECL void upcall_del_stack() { - rust_task *task = rust_get_current_task(); - task->prev_stack(); + assert(false && "newsched shouldn't be growing the stack"); } // Landing pads need to call this to insert the @@ -336,12 +117,6 @@ upcall_del_stack() { // needs to acquire the value of the stack pointer extern "C" CDECL void upcall_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 - } } // -- cgit 1.4.1-3-g733a5