aboutsummaryrefslogtreecommitdiffstats
path: root/thread_pthread.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-04-14 22:34:53 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-04-14 22:34:53 +0000
commit78c75612f07fdf4acfb148a3f0a4e129101eb124 (patch)
tree5a7ac4bd197f290fd2cd9ea9ab02aa0f88dcf667 /thread_pthread.c
parentcdf0a92c75f44b55288fcde8771f413ec6063fb4 (diff)
downloadruby-78c75612f07fdf4acfb148a3f0a4e129101eb124.tar.gz
thread_pthread.c: keep sp safe zone
* 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/trunk@50316 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'thread_pthread.c')
-rw-r--r--thread_pthread.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/thread_pthread.c b/thread_pthread.c
index 624095755a..224da92af4 100644
--- a/thread_pthread.c
+++ b/thread_pthread.c
@@ -662,11 +662,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);
@@ -674,13 +679,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;
}
}