diff --git a/signal.c b/signal.c index 412782e44f..e4f04d101a 100644 --- a/signal.c +++ b/signal.c @@ -761,7 +761,7 @@ static const char *received_signal; #endif #if defined(USE_SIGALTSTACK) || defined(_WIN32) -NORETURN(void ruby_thread_stack_overflow(rb_thread_t *th)); +NORETURN(void rb_threadptr_stack_overflow(rb_thread_t *th)); # if defined __HAIKU__ # define USE_UCONTEXT_REG 1 # elif !(defined(HAVE_UCONTEXT_H) && (defined __i386__ || defined __x86_64__ || defined __amd64__)) @@ -792,7 +792,7 @@ raise_stack_overflow(int sig, rb_thread_t *th) rb_bug_errno(STRINGIZE(ruby_sigunmask)":unblock", errno); } #endif - ruby_thread_stack_overflow(th); + rb_threadptr_stack_overflow(th); } # ifdef USE_UCONTEXT_REG diff --git a/thread.c b/thread.c index 6c7bb6d1bd..a21ef7ba78 100644 --- a/thread.c +++ b/thread.c @@ -2165,20 +2165,6 @@ rb_threadptr_signal_exit(rb_thread_t *th) #define USE_SIGALTSTACK #endif -NORETURN(void ruby_thread_stack_overflow(rb_thread_t *th)); -void -ruby_thread_stack_overflow(rb_thread_t *th) -{ - th->raised_flag = 0; -#ifdef USE_SIGALTSTACK - if (!rb_threadptr_during_gc(th)) { - rb_exc_raise(sysstack_error); - } -#endif - th->errinfo = sysstack_error; - TH_JUMP_TAG(th, TAG_RAISE); -} - int rb_threadptr_set_raised(rb_thread_t *th) { diff --git a/vm_insnhelper.c b/vm_insnhelper.c index 6006b5d579..fd259fd428 100644 --- a/vm_insnhelper.c +++ b/vm_insnhelper.c @@ -30,12 +30,40 @@ ruby_vm_special_exception_copy(VALUE exc) return e; } +NORETURN(static void threadptr_stack_overflow(rb_thread_t *, int)); +static void +threadptr_stack_overflow(rb_thread_t *th, int setup) +{ + VALUE mesg = th->vm->special_exceptions[ruby_error_sysstack]; + th->raised_flag = 0; + if (setup) { + VALUE at = rb_threadptr_backtrace_object(th); + mesg = ruby_vm_special_exception_copy(mesg); + rb_ivar_set(mesg, idBt, at); + rb_ivar_set(mesg, idBt_locations, at); + } + th->errinfo = mesg; + TH_JUMP_TAG(th, TAG_RAISE); +} + static void vm_stackoverflow(void) { - rb_exc_raise(ruby_vm_special_exception_copy(sysstack_error)); + threadptr_stack_overflow(GET_THREAD(), TRUE); } +NORETURN(void rb_threadptr_stack_overflow(rb_thread_t *th)); +void +rb_threadptr_stack_overflow(rb_thread_t *th) +{ +#ifdef USE_SIGALTSTACK + threadptr_stack_overflow(th, !rb_threadptr_during_gc(th)); +#else + threadptr_stack_overflow(th, FALSE); +#endif +} + + #if VM_CHECK_MODE > 0 static int callable_class_p(VALUE klass)