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

ruby-changes:44834

From: nobu <ko1@a...>
Date: Sun, 27 Nov 2016 20:22:47 +0900 (JST)
Subject: [ruby-changes:44834] nobu:r56907 (trunk): signal.c: improve stack overflow check

nobu	2016-11-27 20:22:42 +0900 (Sun, 27 Nov 2016)

  New Revision: 56907

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=56907

  Log:
    signal.c: improve stack overflow check
    
    * signal.c (check_stack_overflow): [EXPERIMENTAL] consider the
      segfault a stack overflow when the fault address is between SP
      and BP.

  Modified files:
    trunk/signal.c
Index: signal.c
===================================================================
--- signal.c	(revision 56906)
+++ signal.c	(revision 56907)
@@ -780,35 +780,45 @@ check_stack_overflow(const uintptr_t add https://github.com/ruby/ruby/blob/trunk/signal.c#L780
 # if defined __linux__
 #   if defined REG_RSP
     const greg_t sp = mctx->gregs[REG_RSP];
+    const greg_t bp = mctx->gregs[REG_RBP];
 #   else
     const greg_t sp = mctx->gregs[REG_ESP];
+    const greg_t bp = mctx->gregs[REG_EBP];
 #   endif
 # elif defined __APPLE__
 #   if defined(__LP64__)
     const uintptr_t sp = mctx->__ss.__rsp;
+    const uintptr_t bp = mctx->__ss.__rbp;
 #   else
     const uintptr_t sp = mctx->__ss.__esp;
+    const uintptr_t bp = mctx->__ss.__ebp;
 #   endif
 # elif defined __FreeBSD__
 #   if defined(__amd64__)
     const __register_t sp = mctx->mc_rsp;
+    const __register_t bp = mctx->mc_rbp;
 #   else
     const __register_t sp = mctx->mc_esp;
+    const __register_t bp = mctx->mc_ebp;
 #   endif
 # elif defined __HAIKU__
 #   if defined(__amd64__)
     const unsigned long sp = mctx->rsp;
+    const unsigned long bp = mctx->rbp;
 #   else
     const unsigned long sp = mctx->esp;
+    const unsigned long bp = mctx->ebp;
 #   endif
 # endif
     enum {pagesize = 4096};
     const uintptr_t sp_page = (uintptr_t)sp / pagesize;
+    const uintptr_t bp_page = (uintptr_t)bp / 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) {
+    if (sp_page == fault_page || sp_page == fault_page + 1 ||
+	sp_page <= fault_page && fault_page <= bp_page) {
 	rb_thread_t *th = ruby_current_thread;
 	if ((uintptr_t)th->tag->buf / pagesize == sp_page) {
 	    /* drop the last tag if it is close to the fault,

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

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