summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-04-13 08:02:39 +0000
committerusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-04-13 08:02:39 +0000
commit99fdb0a71b54fbea4ded06b99cb8c003c1d9552e (patch)
tree8e08866a5551b9f80372b3ca888f9b259494af45
parent4f0e238f2854a9f3e5a1f3cbb0c8d32e66dc15d8 (diff)
merge revision(s) 49452: [Backport #10813]
* 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] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_1@50289 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog7
-rw-r--r--thread_pthread.c37
-rw-r--r--version.h2
3 files changed, 45 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 99ed7617a5..883e725bf4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+Mon Apr 13 17:02:25 2015 Scott Francis <scott.francis@shopify.com>
+
+ * 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]
+
Mon Apr 13 16:52:14 2015 Koichi Sasada <ko1@atdot.net>
* class.c (rb_prepend_module): need a WB for klass -> origin.
diff --git a/thread_pthread.c b/thread_pthread.c
index 581dfecaaa..f3cd8702f8 100644
--- a/thread_pthread.c
+++ b/thread_pthread.c
@@ -648,6 +648,42 @@ space_size(size_t stack_size)
}
}
+#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.
*
@@ -669,6 +705,7 @@ ruby_init_stack(volatile VALUE *addr
if (get_main_stack(&stackaddr, &size) == 0) {
native_main_thread.stack_maxsize = size;
native_main_thread.stack_start = stackaddr;
+ reserve_stack(stackaddr, size);
return;
}
}
diff --git a/version.h b/version.h
index 8092f0d733..dbf58ed46d 100644
--- a/version.h
+++ b/version.h
@@ -1,6 +1,6 @@
#define RUBY_VERSION "2.1.5"
#define RUBY_RELEASE_DATE "2015-04-13"
-#define RUBY_PATCHLEVEL 332
+#define RUBY_PATCHLEVEL 333
#define RUBY_RELEASE_YEAR 2015
#define RUBY_RELEASE_MONTH 4