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

ruby-changes:37371

From: nobu <ko1@a...>
Date: Sat, 31 Jan 2015 12:06:38 +0900 (JST)
Subject: [ruby-changes:37371] nobu:r49452 (trunk): thread_pthread.c: Fix intermittent SIGBUS on Linux

nobu	2015-01-31 12:06:26 +0900 (Sat, 31 Jan 2015)

  New Revision: 49452

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

  Log:
    thread_pthread.c: Fix intermittent SIGBUS on Linux
    
    * thread_pthread.c (reserve_stack): fix intermittent SIGBUS on
      Linux, by reserving the stack virtual address space at process
      start up so that it will not clash with the heap space.
      [Fix GH-822]

  Modified files:
    trunk/ChangeLog
    trunk/thread_pthread.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 49451)
+++ ChangeLog	(revision 49452)
@@ -1,3 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sat Jan 31 12:06:23 2015  Scott Francis  <scott.francis@s...>
+
+	* thread_pthread.c (reserve_stack): fix intermittent SIGBUS on
+	  Linux, by reserving the stack virtual address space at process
+	  start up so that it will not clash with the heap space.
+	  [Fix GH-822]
+
 Fri Jan 30 17:28:29 2015  gogotanaka  <mail@t...>
 
 	* math.c (num2dbl_with_to_f): make faster when Bignum passed by
Index: thread_pthread.c
===================================================================
--- thread_pthread.c	(revision 49451)
+++ thread_pthread.c	(revision 49452)
@@ -653,6 +653,42 @@ space_size(size_t stack_size) https://github.com/ruby/ruby/blob/trunk/thread_pthread.c#L653
     }
 }
 
+#ifdef __linux__
+static __attribute__((noinline)) void
+reserve_stack(volatile char *limit, size_t size)
+{
+# ifdef C_ALLOCA
+#   error needs alloca()
+# endif
+    struct rlimit rl;
+    volatile char buf[0x100];
+    STACK_GROW_DIR_DETECTION;
+
+    if (!getrlimit(RLIMIT_STACK, &rl) && rl.rlim_cur == RLIM_INFINITY)
+	return;
+
+    size -= sizeof(buf); /* margin */
+    if (IS_STACK_DIR_UPPER()) {
+	const volatile char *end = buf + sizeof(buf);
+	limit += size;
+	if (limit > end) {
+	    size = limit - end;
+	    limit = alloca(size);
+	    limit[size-1] = 0;
+	}
+    }
+    else {
+	limit -= size;
+	if (buf > limit) {
+	    limit = alloca(buf - limit);
+	    limit[0] = 0;
+	}
+    }
+}
+#else
+# define reserve_stack(limit, size) ((void)(limit), (void)(size))
+#endif
+
 #undef ruby_init_stack
 /* Set stack bottom of Ruby implementation.
  *
@@ -674,6 +710,7 @@ ruby_init_stack(volatile VALUE *addr https://github.com/ruby/ruby/blob/trunk/thread_pthread.c#L710
 	if (get_main_stack(&stackaddr, &size) == 0) {
 	    native_main_thread.stack_maxsize = size;
 	    native_main_thread.stack_start = stackaddr;
+	    reserve_stack(stackaddr, size);
 	    return;
 	}
     }

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

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