From 88291c190a8781ed94e58799165df0c54b0004de Mon Sep 17 00:00:00 2001 From: naruse Date: Thu, 24 Mar 2016 16:51:30 +0000 Subject: * thread_pthread.c (reserve_stack): fix reserving position where the stack growing bottom to top. [Bug #12118] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54256 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 5 +++++ thread_pthread.c | 26 ++++++++++++++++++++------ 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index eeffdcfc42..19915e009d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Fri Mar 25 01:50:58 2016 NARUSE, Yui + + * thread_pthread.c (reserve_stack): fix reserving position where + the stack growing bottom to top. [Bug #12118] + Fri Mar 25 01:10:42 2016 Sebastian Schuberth * lib/mkmf.rb (find_executable0): On Windows, it is actually valid diff --git a/thread_pthread.c b/thread_pthread.c index ef43b369e7..1fdf3f5431 100644 --- a/thread_pthread.c +++ b/thread_pthread.c @@ -693,17 +693,31 @@ reserve_stack(volatile char *limit, size_t size) const volatile char *end = buf + sizeof(buf); limit += size; if (limit > end) { - size = limit - end; - limit = alloca(size); - limit[stack_check_margin+size-1] = 0; + /* |<-bottom (=limit(a)) top->| + * | .. |<-buf 256B |<-end | stack check | + * | 256B | =size= | margin (4KB)| + * | =size= limit(b)->| 256B | | + * | | alloca(sz) | | | + * | .. |<-buf |<-limit(c) [sz-1]->0> | | + */ + size_t sz = limit - end; + limit = alloca(sz); + limit[sz-1] = 0; } } else { limit -= size; if (buf > limit) { - limit = alloca(buf - limit); - limit[0] = 0; /* ensure alloca is called */ - limit -= stack_check_margin; + /* |<-top (=limit(a)) bottom->| + * | .. | 256B buf->| | stack check | + * | 256B | =size= | margin (4KB)| + * | =size= limit(b)->| 256B | | + * | | alloca(sz) | | | + * | .. | buf->| limit(c)-><0> | | + */ + size_t sz = buf - limit; + limit = alloca(sz); + limit[0] = 0; } } } -- cgit v1.2.3