Skip to content

Commit 99fdb0a

Browse files
committed
merge revision(s) 49452: [Backport ruby#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 rubyGH-822] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_1@50289 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
1 parent 4f0e238 commit 99fdb0a

File tree

3 files changed

+45
-1
lines changed

3 files changed

+45
-1
lines changed

ChangeLog

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
Mon Apr 13 17:02:25 2015 Scott Francis <[email protected]>
2+
3+
* thread_pthread.c (reserve_stack): fix intermittent SIGBUS on
4+
Linux, by reserving the stack virtual address space at process
5+
start up so that it will not clash with the heap space.
6+
[Fix GH-822]
7+
18
Mon Apr 13 16:52:14 2015 Koichi Sasada <[email protected]>
29

310
* class.c (rb_prepend_module): need a WB for klass -> origin.

thread_pthread.c

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,42 @@ space_size(size_t stack_size)
648648
}
649649
}
650650

651+
#ifdef __linux__
652+
static __attribute__((noinline)) void
653+
reserve_stack(volatile char *limit, size_t size)
654+
{
655+
# ifdef C_ALLOCA
656+
# error needs alloca()
657+
# endif
658+
struct rlimit rl;
659+
volatile char buf[0x100];
660+
STACK_GROW_DIR_DETECTION;
661+
662+
if (!getrlimit(RLIMIT_STACK, &rl) && rl.rlim_cur == RLIM_INFINITY)
663+
return;
664+
665+
size -= sizeof(buf); /* margin */
666+
if (IS_STACK_DIR_UPPER()) {
667+
const volatile char *end = buf + sizeof(buf);
668+
limit += size;
669+
if (limit > end) {
670+
size = limit - end;
671+
limit = alloca(size);
672+
limit[size-1] = 0;
673+
}
674+
}
675+
else {
676+
limit -= size;
677+
if (buf > limit) {
678+
limit = alloca(buf - limit);
679+
limit[0] = 0;
680+
}
681+
}
682+
}
683+
#else
684+
# define reserve_stack(limit, size) ((void)(limit), (void)(size))
685+
#endif
686+
651687
#undef ruby_init_stack
652688
/* Set stack bottom of Ruby implementation.
653689
*
@@ -669,6 +705,7 @@ ruby_init_stack(volatile VALUE *addr
669705
if (get_main_stack(&stackaddr, &size) == 0) {
670706
native_main_thread.stack_maxsize = size;
671707
native_main_thread.stack_start = stackaddr;
708+
reserve_stack(stackaddr, size);
672709
return;
673710
}
674711
}

version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#define RUBY_VERSION "2.1.5"
22
#define RUBY_RELEASE_DATE "2015-04-13"
3-
#define RUBY_PATCHLEVEL 332
3+
#define RUBY_PATCHLEVEL 333
44

55
#define RUBY_RELEASE_YEAR 2015
66
#define RUBY_RELEASE_MONTH 4

0 commit comments

Comments
 (0)