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:
nobu 2014-05-18 07:38:54 +00:00
Родитель 3622efd2bd
Коммит f4f71d6e6b
1 изменённых файлов: 17 добавлений и 5 удалений

Просмотреть файл

@ -700,17 +700,29 @@ rb_get_next_signal(void)
#if defined(USE_SIGALTSTACK) || defined(_WIN32)
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
#endif
#ifdef USE_UCONTEXT_REG
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];
const struct mcontext *mctx = ctx->uc_mcontext;
# if defined __linux__
# if defined REG_RSP
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
enum {pagesize = 4096};
const uintptr_t sp_page = (uintptr_t)sp / pagesize;