rt: Add rust_task::call_on_c_stack

This commit is contained in:
Brian Anderson
2012-02-08 21:42:04 -08:00
parent 1e2fe4ab8f
commit ea76d3f454
3 changed files with 24 additions and 7 deletions

View File

@@ -194,7 +194,7 @@ void task_start_wrapper(spawn_args *a)
// The cleanup work needs lots of stack // The cleanup work needs lots of stack
cleanup_args ca = {a, threw_exception}; cleanup_args ca = {a, threw_exception};
task->thread->c_context.call_and_change_stacks(&ca, (void*)cleanup_task); task->call_on_c_stack(&ca, (void*)cleanup_task);
task->ctx.next->swap(task->ctx); task->ctx.next->swap(task->ctx);
} }
@@ -699,7 +699,18 @@ Returns true if we're currently running on the Rust stack
*/ */
bool bool
rust_task::on_rust_stack() { rust_task::on_rust_stack() {
return sp_in_stk_seg(get_sp(), stk); uintptr_t sp = get_sp();
bool in_first_segment = sp_in_stk_seg(sp, stk);
if (in_first_segment) {
return true;
} else if (stk->next != NULL) {
// This happens only when calling the upcall to delete
// a stack segment
bool in_second_segment = sp_in_stk_seg(sp, stk->next);
return in_second_segment;
} else {
return false;
}
} }
void void
@@ -713,6 +724,12 @@ rust_task::config_notify(chan_handle chan) {
notify_chan = chan; notify_chan = chan;
} }
void
rust_task::call_on_c_stack(void *args, void *fn_ptr) {
I(thread, on_rust_stack());
thread->c_context.call_and_change_stacks(args, fn_ptr);
}
// //
// Local Variables: // Local Variables:
// mode: C++ // mode: C++

View File

@@ -181,6 +181,8 @@ public:
void check_stack_canary(); void check_stack_canary();
void config_notify(chan_handle chan); void config_notify(chan_handle chan);
void call_on_c_stack(void *args, void *fn_ptr);
}; };
// //

View File

@@ -47,8 +47,7 @@ inline void
call_upcall_on_c_stack(void *args, void *fn_ptr) { call_upcall_on_c_stack(void *args, void *fn_ptr) {
check_stack_alignment(); check_stack_alignment();
rust_task *task = rust_task_thread::get_task(); rust_task *task = rust_task_thread::get_task();
rust_task_thread *thread = task->thread; task->call_on_c_stack(args, fn_ptr);
thread->c_context.call_and_change_stacks(args, fn_ptr);
} }
extern "C" void record_sp(void *limit); extern "C" void record_sp(void *limit);
@@ -69,11 +68,10 @@ upcall_call_shim_on_c_stack(void *args, void *fn_ptr) {
// stack. // stack.
record_sp(0); record_sp(0);
rust_task_thread *thread = task->thread;
try { try {
thread->c_context.call_and_change_stacks(args, fn_ptr); task->call_on_c_stack(args, fn_ptr);
} catch (...) { } catch (...) {
A(thread, false, "Native code threw an exception"); A(task->thread, false, "Native code threw an exception");
} }
task = rust_task_thread::get_task(); task = rust_task_thread::get_task();