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 or the next, on x86 Mac OS X. [EXPERIMENTAL] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45995 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
3622efd2bd
commit
f4f71d6e6b
22
signal.c
22
signal.c
@ -700,17 +700,29 @@ 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 __i386__ || defined __x86_64__))
|
||||||
|
#elif defined __linux__
|
||||||
|
# define USE_UCONTEXT_REG 1
|
||||||
|
#elif defined __APPLE__
|
||||||
# define USE_UCONTEXT_REG 1
|
# define USE_UCONTEXT_REG 1
|
||||||
#endif
|
#endif
|
||||||
#ifdef USE_UCONTEXT_REG
|
#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)
|
||||||
{
|
{
|
||||||
# if defined REG_RSP
|
const struct mcontext *mctx = ctx->uc_mcontext;
|
||||||
const greg_t sp = ctx->uc_mcontext.gregs[REG_RSP];
|
# if defined __linux__
|
||||||
# else
|
# if defined REG_RSP
|
||||||
const greg_t sp = ctx->uc_mcontext.gregs[REG_ESP];
|
const greg_t sp = mctx->gregs[REG_RSP];
|
||||||
|
# else
|
||||||
|
const greg_t sp = mctx->gregs[REG_ESP];
|
||||||
|
# endif
|
||||||
|
# elif defined __APPLE__
|
||||||
|
# if defined(__LP64__)
|
||||||
|
const uintptr_t sp = mctx->ss.rsp;
|
||||||
|
# else
|
||||||
|
const uintptr_t sp = mctx->ss.esp;
|
||||||
|
# endif
|
||||||
# endif
|
# endif
|
||||||
enum {pagesize = 4096};
|
enum {pagesize = 4096};
|
||||||
const uintptr_t sp_page = (uintptr_t)sp / pagesize;
|
const uintptr_t sp_page = (uintptr_t)sp / pagesize;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user