diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-01-31 03:06:26 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-01-31 03:06:26 +0000 |
commit | 8fe95fea9d238a6deb70c8953ceb3a28a67f4636 (patch) | |
tree | 88ec6caabd28e337b85c14b8cf47a922d2f0f347 /thread_pthread.c | |
parent | 1b11ba706d62b8ffbd6be61e434e5c48f2097f67 (diff) | |
download | ruby-8fe95fea9d238a6deb70c8953ceb3a28a67f4636.tar.gz |
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]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49452 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'thread_pthread.c')
-rw-r--r-- | thread_pthread.c | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/thread_pthread.c b/thread_pthread.c index 3ef316c639..20dc03cc14 100644 --- a/thread_pthread.c +++ b/thread_pthread.c @@ -653,6 +653,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. * @@ -674,6 +710,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; } } |