[前][次][番号順一覧][スレッド一覧]

ruby-changes:33843

From: nobu <ko1@a...>
Date: Mon, 12 May 2014 10:35:18 +0900 (JST)
Subject: [ruby-changes:33843] nobu:r45924 (trunk): signal.c: check the next page too

nobu	2014-05-12 10:35:09 +0900 (Mon, 12 May 2014)

  New Revision: 45924

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=45924

  Log:
    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.

  Modified files:
    trunk/signal.c
Index: signal.c
===================================================================
--- signal.c	(revision 45923)
+++ signal.c	(revision 45924)
@@ -701,6 +701,9 @@ rb_get_next_signal(void) https://github.com/ruby/ruby/blob/trunk/signal.c#L701
 #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__)
+# define USE_UCONTEXT_REG 1
+#endif
+#ifdef USE_UCONTEXT_REG
 static void
 check_stack_overflow(const uintptr_t addr, const ucontext_t *ctx)
 {
@@ -710,7 +713,12 @@ check_stack_overflow(const uintptr_t add https://github.com/ruby/ruby/blob/trunk/signal.c#L713
     const greg_t sp = ctx->uc_mcontext.gregs[REG_ESP];
 # endif
     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());
     }
 }
@@ -729,7 +737,7 @@ check_stack_overflow(const void *addr) https://github.com/ruby/ruby/blob/trunk/signal.c#L737
 #define CHECK_STACK_OVERFLOW() check_stack_overflow(0)
 #else
 #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)
 #else
 # define CHECK_STACK_OVERFLOW() check_stack_overflow(FAULT_ADDRESS)

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]