summaryrefslogtreecommitdiff
path: root/thread_pthread.c
diff options
context:
space:
mode:
authornagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-04-19 17:03:11 +0000
committernagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-04-19 17:03:11 +0000
commit6ba7e6cc60842d6aff6229c117c2aa6b0fe2cb9f (patch)
tree9ac93740279636b4187dabac933b4f4f2123f689 /thread_pthread.c
parent7e970d34ed2c34c67b3fd29ea19d745bda730a4d (diff)
merge revision(s) 40102: [Backport #8234]
* thread_pthread.c (ruby_init_stack): Avoid using uninitialized value. stackaddr and size are not set if get_stack() fails. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_0_0@40386 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'thread_pthread.c')
-rw-r--r--thread_pthread.c50
1 files changed, 29 insertions, 21 deletions
diff --git a/thread_pthread.c b/thread_pthread.c
index 0004c6791e..6c22870c1e 100644
--- a/thread_pthread.c
+++ b/thread_pthread.c
@@ -603,6 +603,23 @@ static struct {
extern void *STACK_END_ADDRESS;
#endif
+enum {
+ RUBY_STACK_SPACE_LIMIT = 1024 * 1024, /* 1024KB */
+ RUBY_STACK_SPACE_RATIO = 5
+};
+
+static size_t
+space_size(size_t stack_size)
+{
+ size_t space_size = stack_size / RUBY_STACK_SPACE_RATIO;
+ if (space_size > RUBY_STACK_SPACE_LIMIT) {
+ return RUBY_STACK_SPACE_LIMIT;
+ }
+ else {
+ return space_size;
+ }
+}
+
#undef ruby_init_stack
/* Set stack bottom of Ruby implementation.
*
@@ -633,13 +650,21 @@ ruby_init_stack(volatile VALUE *addr
}
#endif
{
- size_t size = 0;
- size_t space = 0;
+#if defined(PTHREAD_STACK_DEFAULT)
+# if PTHREAD_STACK_DEFAULT < RUBY_STACK_SPACE*5
+# error "PTHREAD_STACK_DEFAULT is too small"
+# endif
+ size_t size = PTHREAD_STACK_DEFAULT;
+#else
+ size_t size = RUBY_VM_THREAD_VM_STACK_SIZE;
+#endif
+ size_t space = space_size(size);
#if MAINSTACKADDR_AVAILABLE
void* stackaddr;
STACK_GROW_DIR_DETECTION;
- get_stack(&stackaddr, &size);
- space = STACK_DIR_UPPER((char *)addr - (char *)stackaddr, (char *)stackaddr - (char *)addr);
+ if (get_stack(&stackaddr, &size) == 0) {
+ space = STACK_DIR_UPPER((char *)addr - (char *)stackaddr, (char *)stackaddr - (char *)addr);
+ }
native_main_thread.stack_maxsize = size - space;
#elif defined(HAVE_GETRLIMIT)
int pagesize = getpagesize();
@@ -846,23 +871,6 @@ use_cached_thread(rb_thread_t *th)
return result;
}
-enum {
- RUBY_STACK_SPACE_LIMIT = 1024 * 1024, /* 1024KB */
- RUBY_STACK_SPACE_RATIO = 5
-};
-
-static size_t
-space_size(size_t stack_size)
-{
- size_t space_size = stack_size / RUBY_STACK_SPACE_RATIO;
- if (space_size > RUBY_STACK_SPACE_LIMIT) {
- return RUBY_STACK_SPACE_LIMIT;
- }
- else {
- return space_size;
- }
-}
-
static int
native_thread_create(rb_thread_t *th)
{