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

ruby-changes:33438

From: nobu <ko1@a...>
Date: Fri, 4 Apr 2014 17:37:29 +0900 (JST)
Subject: [ruby-changes:33438] nobu:r45517 (trunk): signal.c: check stack overflow by SP

nobu	2014-04-04 17:37:25 +0900 (Fri, 04 Apr 2014)

  New Revision: 45517

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

  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, on x86 linux.
      [EXPERIMENTAL]

  Modified files:
    trunk/signal.c
Index: signal.c
===================================================================
--- signal.c	(revision 45516)
+++ signal.c	(revision 45517)
@@ -635,21 +635,41 @@ rb_get_next_signal(void) https://github.com/ruby/ruby/blob/trunk/signal.c#L635
 
 
 #if defined(USE_SIGALTSTACK) || defined(_WIN32)
+NORETURN(void ruby_thread_stack_overflow(rb_thread_t *th));
+#if defined __linux__ && (defined __i386__ || defined __x86_64__)
+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];
+# endif
+    enum {pagesize = 4096};
+    if ((uintptr_t)sp / pagesize == addr / pagesize) {
+	ruby_thread_stack_overflow(GET_THREAD());
+    }
+}
+#else
 static void
 check_stack_overflow(const void *addr)
 {
     int ruby_stack_overflowed_p(const rb_thread_t *, const void *);
-    NORETURN(void ruby_thread_stack_overflow(rb_thread_t *th));
     rb_thread_t *th = GET_THREAD();
     if (ruby_stack_overflowed_p(th, addr)) {
 	ruby_thread_stack_overflow(th);
     }
 }
+#endif
 #ifdef _WIN32
 #define CHECK_STACK_OVERFLOW() check_stack_overflow(0)
 #else
 #define FAULT_ADDRESS info->si_addr
-#define CHECK_STACK_OVERFLOW() check_stack_overflow(FAULT_ADDRESS)
+#if defined __linux__ && (defined __i386__ || defined __x86_64__)
+# define CHECK_STACK_OVERFLOW() check_stack_overflow((uintptr_t)FAULT_ADDRESS, ctx)
+#else
+# define CHECK_STACK_OVERFLOW() check_stack_overflow(FAULT_ADDRESS)
+#endif
 #define MESSAGE_FAULT_ADDRESS " at %p", FAULT_ADDRESS
 #endif
 #else

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

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