From 6d8330afb6c925d1092f27919f61d4ce6a3fb1d4 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Thu, 17 Oct 2013 01:40:33 -0700 Subject: Use __morestack to detect stack overflow This commit resumes management of the stack boundaries and limits when switching between tasks. This additionally leverages the __morestack function to run code on "stack overflow". The current behavior is to abort the process, but this is probably not the best behavior in the long term (for deails, see the comment I wrote up in the stack exhaustion routine). --- src/rt/rust_builtin.cpp | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) (limited to 'src/rt/rust_builtin.cpp') diff --git a/src/rt/rust_builtin.cpp b/src/rt/rust_builtin.cpp index 9750e22e945..755235a9138 100644 --- a/src/rt/rust_builtin.cpp +++ b/src/rt/rust_builtin.cpp @@ -16,7 +16,6 @@ #include "memory_region.h" #include "boxed_region.h" #include "vg/valgrind.h" -#include "sp.h" #include @@ -340,22 +339,26 @@ rust_unlock_little_lock(lock_and_signal *lock) { lock->unlock(); } +typedef void(startfn)(void*, void*); + class raw_thread: public rust_thread { public: - fn_env_pair fn; + startfn *raw_start; + void *rust_fn; + void *rust_env; - raw_thread(fn_env_pair fn) : fn(fn) { } + raw_thread(startfn *raw_start, void *rust_fn, void *rust_env) + : raw_start(raw_start), rust_fn(rust_fn), rust_env(rust_env) { } virtual void run() { - record_sp_limit(0); - fn.f(fn.env, NULL); + raw_start(rust_fn, rust_env); } }; extern "C" raw_thread* -rust_raw_thread_start(fn_env_pair *fn) { - assert(fn); - raw_thread *thread = new raw_thread(*fn); +rust_raw_thread_start(startfn *raw_start, void *rust_start, void *rust_env) { + assert(raw_start && rust_start); + raw_thread *thread = new raw_thread(raw_start, rust_start, rust_env); thread->start(); return thread; } @@ -552,12 +555,6 @@ rust_get_global_args_ptr() { return &global_args_ptr; } -// Used by i386 __morestack -extern "C" CDECL uintptr_t -rust_get_task() { - return 0; -} - static lock_and_signal env_lock; extern "C" CDECL void -- cgit 1.4.1-3-g733a5