diff options
author | usa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-04-28 05:14:29 +0000 |
---|---|---|
committer | usa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-04-28 05:14:29 +0000 |
commit | 513b313db1b102f330b994b8fd908a2c10553d7b (patch) | |
tree | a44ab43b75e81f1a22c272b316fd0b7cdc05f8be /thread_pthread.c | |
parent | 976bf35c12581658f817541450cac253df3bc2d2 (diff) |
merge revision(s) 50316: [Backport #11030]
* thread_pthread.c (reserve_stack): keep sp safe zone to get rid
of crash by -fstack-check. [ruby-core:68740] [Bug #11030]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_1@50396 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'thread_pthread.c')
-rw-r--r-- | thread_pthread.c | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/thread_pthread.c b/thread_pthread.c index f3cd8702f8..ed4880c40c 100644 --- a/thread_pthread.c +++ b/thread_pthread.c @@ -657,11 +657,16 @@ reserve_stack(volatile char *limit, size_t size) # endif struct rlimit rl; volatile char buf[0x100]; + enum {stack_check_margin = 0x1000}; /* for -fstack-check */ + STACK_GROW_DIR_DETECTION; if (!getrlimit(RLIMIT_STACK, &rl) && rl.rlim_cur == RLIM_INFINITY) return; + if (size < stack_check_margin) return; + size -= stack_check_margin; + size -= sizeof(buf); /* margin */ if (IS_STACK_DIR_UPPER()) { const volatile char *end = buf + sizeof(buf); @@ -669,13 +674,14 @@ reserve_stack(volatile char *limit, size_t size) if (limit > end) { size = limit - end; limit = alloca(size); - limit[size-1] = 0; + limit[stack_check_margin+size-1] = 0; } } else { limit -= size; if (buf > limit) { limit = alloca(buf - limit); + limit -= stack_check_margin; limit[0] = 0; } } |