signal.c: check the next page too
* signal.c (check_stack_overflow): check the next page too. SP in ucontext is not decremented yet when `push` failed, so the fault page can be the next. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45924 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
642e3ae935
commit
4f8c0b90bb
12
signal.c
12
signal.c
@ -701,6 +701,9 @@ rb_get_next_signal(void)
|
|||||||
#if defined(USE_SIGALTSTACK) || defined(_WIN32)
|
#if defined(USE_SIGALTSTACK) || defined(_WIN32)
|
||||||
NORETURN(void ruby_thread_stack_overflow(rb_thread_t *th));
|
NORETURN(void ruby_thread_stack_overflow(rb_thread_t *th));
|
||||||
#if defined(HAVE_UCONTEXT_H) && defined __linux__ && (defined __i386__ || defined __x86_64__)
|
#if defined(HAVE_UCONTEXT_H) && defined __linux__ && (defined __i386__ || defined __x86_64__)
|
||||||
|
# define USE_UCONTEXT_REG 1
|
||||||
|
#endif
|
||||||
|
#ifdef USE_UCONTEXT_REG
|
||||||
static void
|
static void
|
||||||
check_stack_overflow(const uintptr_t addr, const ucontext_t *ctx)
|
check_stack_overflow(const uintptr_t addr, const ucontext_t *ctx)
|
||||||
{
|
{
|
||||||
@ -710,7 +713,12 @@ check_stack_overflow(const uintptr_t addr, const ucontext_t *ctx)
|
|||||||
const greg_t sp = ctx->uc_mcontext.gregs[REG_ESP];
|
const greg_t sp = ctx->uc_mcontext.gregs[REG_ESP];
|
||||||
# endif
|
# endif
|
||||||
enum {pagesize = 4096};
|
enum {pagesize = 4096};
|
||||||
if ((uintptr_t)sp / pagesize == addr / pagesize) {
|
const uintptr_t sp_page = (uintptr_t)sp / pagesize;
|
||||||
|
const uintptr_t fault_page = addr / pagesize;
|
||||||
|
|
||||||
|
/* SP in ucontext is not decremented yet when `push` failed, so
|
||||||
|
* the fault page can be the next. */
|
||||||
|
if (sp_page == fault_page || sp_page == fault_page + 1) {
|
||||||
ruby_thread_stack_overflow(GET_THREAD());
|
ruby_thread_stack_overflow(GET_THREAD());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -729,7 +737,7 @@ check_stack_overflow(const void *addr)
|
|||||||
#define CHECK_STACK_OVERFLOW() check_stack_overflow(0)
|
#define CHECK_STACK_OVERFLOW() check_stack_overflow(0)
|
||||||
#else
|
#else
|
||||||
#define FAULT_ADDRESS info->si_addr
|
#define FAULT_ADDRESS info->si_addr
|
||||||
#if defined(HAVE_UCONTEXT_H) && defined __linux__ && (defined __i386__ || defined __x86_64__)
|
# ifdef USE_UCONTEXT_REG
|
||||||
# define CHECK_STACK_OVERFLOW() check_stack_overflow((uintptr_t)FAULT_ADDRESS, ctx)
|
# define CHECK_STACK_OVERFLOW() check_stack_overflow((uintptr_t)FAULT_ADDRESS, ctx)
|
||||||
#else
|
#else
|
||||||
# define CHECK_STACK_OVERFLOW() check_stack_overflow(FAULT_ADDRESS)
|
# define CHECK_STACK_OVERFLOW() check_stack_overflow(FAULT_ADDRESS)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user