[前][次][番号順一覧][スレッド一覧]

ruby-changes:42182

From: naruse <ko1@a...>
Date: Fri, 25 Mar 2016 01:51:34 +0900 (JST)
Subject: [ruby-changes:42182] naruse:r54256 (trunk): * thread_pthread.c (reserve_stack): fix reserving position where

naruse	2016-03-25 01:51:30 +0900 (Fri, 25 Mar 2016)

  New Revision: 54256

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=54256

  Log:
    * thread_pthread.c (reserve_stack): fix reserving position where
      the stack growing bottom to top. [Bug #12118]

  Modified files:
    trunk/ChangeLog
    trunk/thread_pthread.c
Index: thread_pthread.c
===================================================================
--- thread_pthread.c	(revision 54255)
+++ thread_pthread.c	(revision 54256)
@@ -693,17 +693,31 @@ reserve_stack(volatile char *limit, size https://github.com/ruby/ruby/blob/trunk/thread_pthread.c#L693
 	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;
 	}
     }
 }
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 54255)
+++ ChangeLog	(revision 54256)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Fri Mar 25 01:50:58 2016  NARUSE, Yui  <naruse@r...>
+
+	* 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  <sschuberth@g...>
 
 	* lib/mkmf.rb (find_executable0): On Windows, it is actually valid

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]