signal.c: check stack overflow by SP
* signal.c (check_stack_overflow): raise SystemStackError if SP register and fault address is in the same page, on x86 linux. [EXPERIMENTAL] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45517 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
e18259424e
commit
c3699626da
24
signal.c
24
signal.c
@ -635,21 +635,41 @@ 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));
|
||||||
|
#if defined __linux__ && (defined __i386__ || defined __x86_64__)
|
||||||
|
static void
|
||||||
|
check_stack_overflow(const uintptr_t addr, const ucontext_t *ctx)
|
||||||
|
{
|
||||||
|
# if defined REG_RSP
|
||||||
|
const greg_t sp = ctx->uc_mcontext.gregs[REG_RSP];
|
||||||
|
# else
|
||||||
|
const greg_t sp = ctx->uc_mcontext.gregs[REG_ESP];
|
||||||
|
# endif
|
||||||
|
enum {pagesize = 4096};
|
||||||
|
if ((uintptr_t)sp / pagesize == addr / pagesize) {
|
||||||
|
ruby_thread_stack_overflow(GET_THREAD());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#else
|
||||||
static void
|
static void
|
||||||
check_stack_overflow(const void *addr)
|
check_stack_overflow(const void *addr)
|
||||||
{
|
{
|
||||||
int ruby_stack_overflowed_p(const rb_thread_t *, const void *);
|
int ruby_stack_overflowed_p(const rb_thread_t *, const void *);
|
||||||
NORETURN(void ruby_thread_stack_overflow(rb_thread_t *th));
|
|
||||||
rb_thread_t *th = GET_THREAD();
|
rb_thread_t *th = GET_THREAD();
|
||||||
if (ruby_stack_overflowed_p(th, addr)) {
|
if (ruby_stack_overflowed_p(th, addr)) {
|
||||||
ruby_thread_stack_overflow(th);
|
ruby_thread_stack_overflow(th);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#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
|
||||||
#define CHECK_STACK_OVERFLOW() check_stack_overflow(FAULT_ADDRESS)
|
#if defined __linux__ && (defined __i386__ || defined __x86_64__)
|
||||||
|
# define CHECK_STACK_OVERFLOW() check_stack_overflow((uintptr_t)FAULT_ADDRESS, ctx)
|
||||||
|
#else
|
||||||
|
# define CHECK_STACK_OVERFLOW() check_stack_overflow(FAULT_ADDRESS)
|
||||||
|
#endif
|
||||||
#define MESSAGE_FAULT_ADDRESS " at %p", FAULT_ADDRESS
|
#define MESSAGE_FAULT_ADDRESS " at %p", FAULT_ADDRESS
|
||||||
#endif
|
#endif
|
||||||
#else
|
#else
|
||||||
|
Loading…
x
Reference in New Issue
Block a user