signal.c: fatal stack
* signal.c (check_stack_overflow): raise fatal when the last tag is in danger zone. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59634 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
2f3eef8ee0
commit
066e9a8b4a
8
signal.c
8
signal.c
@ -763,7 +763,7 @@ static const char *received_signal;
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(USE_SIGALTSTACK) || defined(_WIN32)
|
#if defined(USE_SIGALTSTACK) || defined(_WIN32)
|
||||||
NORETURN(void rb_threadptr_stack_overflow(rb_thread_t *th));
|
NORETURN(void rb_threadptr_stack_overflow(rb_thread_t *th, int crit));
|
||||||
# if defined __HAIKU__
|
# if defined __HAIKU__
|
||||||
# define USE_UCONTEXT_REG 1
|
# define USE_UCONTEXT_REG 1
|
||||||
# elif !(defined(HAVE_UCONTEXT_H) && (defined __i386__ || defined __x86_64__ || defined __amd64__))
|
# elif !(defined(HAVE_UCONTEXT_H) && (defined __i386__ || defined __x86_64__ || defined __amd64__))
|
||||||
@ -843,14 +843,16 @@ check_stack_overflow(int sig, const uintptr_t addr, const ucontext_t *ctx)
|
|||||||
if (sp_page == fault_page || sp_page == fault_page + 1 ||
|
if (sp_page == fault_page || sp_page == fault_page + 1 ||
|
||||||
sp_page <= fault_page && fault_page <= bp_page) {
|
sp_page <= fault_page && fault_page <= bp_page) {
|
||||||
rb_thread_t *th = ruby_current_thread;
|
rb_thread_t *th = ruby_current_thread;
|
||||||
|
int crit = FALSE;
|
||||||
if ((uintptr_t)th->ec.tag->buf / pagesize <= fault_page + 1) {
|
if ((uintptr_t)th->ec.tag->buf / pagesize <= fault_page + 1) {
|
||||||
/* drop the last tag if it is close to the fault,
|
/* drop the last tag if it is close to the fault,
|
||||||
* otherwise it can cause stack overflow again at the same
|
* otherwise it can cause stack overflow again at the same
|
||||||
* place. */
|
* place. */
|
||||||
th->ec.tag = th->ec.tag->prev;
|
th->ec.tag = th->ec.tag->prev;
|
||||||
|
crit = TRUE;
|
||||||
}
|
}
|
||||||
reset_sigmask(sig);
|
reset_sigmask(sig);
|
||||||
rb_threadptr_stack_overflow(th);
|
rb_threadptr_stack_overflow(th, crit);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
# else
|
# else
|
||||||
@ -861,7 +863,7 @@ check_stack_overflow(int sig, const void *addr)
|
|||||||
rb_thread_t *th = ruby_current_thread;
|
rb_thread_t *th = ruby_current_thread;
|
||||||
if (ruby_stack_overflowed_p(th, addr)) {
|
if (ruby_stack_overflowed_p(th, addr)) {
|
||||||
reset_sigmask(sig);
|
reset_sigmask(sig);
|
||||||
rb_threadptr_stack_overflow(th);
|
rb_threadptr_stack_overflow(th, FALSE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
# endif
|
# endif
|
||||||
|
@ -258,7 +258,7 @@ stack_check(rb_thread_t *th)
|
|||||||
if (!rb_thread_raised_p(th, RAISED_STACKOVERFLOW) &&
|
if (!rb_thread_raised_p(th, RAISED_STACKOVERFLOW) &&
|
||||||
rb_threadptr_stack_check(th)) {
|
rb_threadptr_stack_check(th)) {
|
||||||
rb_thread_raised_set(th, RAISED_STACKOVERFLOW);
|
rb_thread_raised_set(th, RAISED_STACKOVERFLOW);
|
||||||
rb_threadptr_stack_overflow(th);
|
rb_threadptr_stack_overflow(th, FALSE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,11 +52,11 @@ vm_stackoverflow(void)
|
|||||||
threadptr_stack_overflow(GET_THREAD(), TRUE);
|
threadptr_stack_overflow(GET_THREAD(), TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
NORETURN(void rb_threadptr_stack_overflow(rb_thread_t *th));
|
NORETURN(void rb_threadptr_stack_overflow(rb_thread_t *th, int crit));
|
||||||
void
|
void
|
||||||
rb_threadptr_stack_overflow(rb_thread_t *th)
|
rb_threadptr_stack_overflow(rb_thread_t *th, int crit)
|
||||||
{
|
{
|
||||||
if (rb_during_gc()) {
|
if (crit || rb_during_gc()) {
|
||||||
th->ec.raised_flag = RAISED_STACKOVERFLOW;
|
th->ec.raised_flag = RAISED_STACKOVERFLOW;
|
||||||
th->ec.errinfo = th->vm->special_exceptions[ruby_error_stackfatal];
|
th->ec.errinfo = th->vm->special_exceptions[ruby_error_stackfatal];
|
||||||
TH_JUMP_TAG(th, TAG_RAISE);
|
TH_JUMP_TAG(th, TAG_RAISE);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user