ruby-changes:33914
From: nobu <ko1@a...>
Date: Sun, 18 May 2014 16:39:02 +0900 (JST)
Subject: [ruby-changes:33914] nobu:r45995 (trunk): signal.c: check stack overflow by SP
nobu 2014-05-18 16:38:54 +0900 (Sun, 18 May 2014) New Revision: 45995 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=45995 Log: 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] Modified files: trunk/signal.c Index: signal.c =================================================================== --- signal.c (revision 45994) +++ signal.c (revision 45995) @@ -700,17 +700,29 @@ rb_get_next_signal(void) https://github.com/ruby/ruby/blob/trunk/signal.c#L700 #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; -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/