summaryrefslogtreecommitdiff
path: root/thread_pthread.c
diff options
context:
space:
mode:
authornagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-06-19 15:56:56 +0000
committernagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-06-19 15:56:56 +0000
commitced638cc0f8f8067592b808455e5d17f1dc5d066 (patch)
treed1fbbdd602ebb031e8aa4c4f7a5f8a9981f76ca6 /thread_pthread.c
parent0c5503923bf9a1120d7074281d88249eca372d57 (diff)
merge revision(s) r44712,r44715,r44716,r44722,r44725,r44726,r44753: [Backport #9454] [Backport #9828]
* thread_pthread.c: get current main thread stack size, which may be expanded than allocated size at initialization, by rlimit(). [ruby-core:60113] [Bug #9454] * thread_pthread.c: rlimit is only available on Linux. At least r44712 breaks FreeBSD. [ruby-core:60113] [Bug #9454] * thread_pthread.c (ruby_init_stack, ruby_stack_overflowed_p): place get_stack above others to get stack boundary information. [ruby-core:60113] [Bug #9454] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_1@46468 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'thread_pthread.c')
-rw-r--r--thread_pthread.c73
1 files changed, 41 insertions, 32 deletions
diff --git a/thread_pthread.c b/thread_pthread.c
index aa2c49e949..581dfecaaa 100644
--- a/thread_pthread.c
+++ b/thread_pthread.c
@@ -661,6 +661,18 @@ ruby_init_stack(volatile VALUE *addr
)
{
native_main_thread.id = pthread_self();
+#if MAINSTACKADDR_AVAILABLE
+ if (native_main_thread.stack_maxsize) return;
+ {
+ void* stackaddr;
+ size_t size;
+ if (get_main_stack(&stackaddr, &size) == 0) {
+ native_main_thread.stack_maxsize = size;
+ native_main_thread.stack_start = stackaddr;
+ return;
+ }
+ }
+#endif
#ifdef STACK_END_ADDRESS
native_main_thread.stack_start = STACK_END_ADDRESS;
#else
@@ -677,18 +689,6 @@ ruby_init_stack(volatile VALUE *addr
native_main_thread.register_stack_start = (VALUE*)bsp;
}
#endif
-#if MAINSTACKADDR_AVAILABLE
- if (native_main_thread.stack_maxsize) return;
- {
- void* stackaddr;
- size_t size;
- if (get_main_stack(&stackaddr, &size) == 0) {
- native_main_thread.stack_maxsize = size;
- native_main_thread.stack_start = stackaddr;
- return;
- }
- }
-#endif
{
#if defined(HAVE_GETRLIMIT)
#if defined(PTHREAD_STACK_DEFAULT)
@@ -749,8 +749,8 @@ native_thread_init_stack(rb_thread_t *th)
rb_nativethread_id_t curr = pthread_self();
if (pthread_equal(curr, native_main_thread.id)) {
- th->machine_stack_start = native_main_thread.stack_start;
- th->machine_stack_maxsize = native_main_thread.stack_maxsize;
+ th->machine.stack_start = native_main_thread.stack_start;
+ th->machine.stack_maxsize = native_main_thread.stack_maxsize;
}
else {
#ifdef STACKADDR_AVAILABLE
@@ -758,11 +758,11 @@ native_thread_init_stack(rb_thread_t *th)
size_t size;
if (get_stack(&start, &size) == 0) {
- th->machine_stack_start = start;
- th->machine_stack_maxsize = size;
+ th->machine.stack_start = start;
+ th->machine.stack_maxsize = size;
}
#elif defined get_stack_of
- if (!th->machine_stack_maxsize) {
+ if (!th->machine.stack_maxsize) {
native_mutex_lock(&th->interrupt_lock);
native_mutex_unlock(&th->interrupt_lock);
}
@@ -771,9 +771,9 @@ native_thread_init_stack(rb_thread_t *th)
#endif
}
#ifdef __ia64
- th->machine_register_stack_start = native_main_thread.register_stack_start;
- th->machine_stack_maxsize /= 2;
- th->machine_register_stack_maxsize = th->machine_stack_maxsize;
+ th->machine.register_stack_start = native_main_thread.register_stack_start;
+ th->machine.stack_maxsize /= 2;
+ th->machine.register_stack_maxsize = th->machine.stack_maxsize;
#endif
return 0;
}
@@ -800,7 +800,7 @@ thread_start_func_1(void *th_ptr)
native_thread_init(th);
/* run */
#if defined USE_NATIVE_THREAD_INIT
- thread_start_func_2(th, th->machine_stack_start, rb_ia64_bsp());
+ thread_start_func_2(th, th->machine.stack_start, rb_ia64_bsp());
#else
thread_start_func_2(th, &stack_start, rb_ia64_bsp());
#endif
@@ -922,10 +922,10 @@ native_thread_create(rb_thread_t *th)
const size_t stack_size = th->vm->default_params.thread_machine_stack_size;
const size_t space = space_size(stack_size);
- th->machine_stack_maxsize = stack_size - space;
+ th->machine.stack_maxsize = stack_size - space;
#ifdef __ia64
- th->machine_stack_maxsize /= 2;
- th->machine_register_stack_maxsize = th->machine_stack_maxsize;
+ th->machine.stack_maxsize /= 2;
+ th->machine.register_stack_maxsize = th->machine.stack_maxsize;
#endif
#ifdef HAVE_PTHREAD_ATTR_INIT
@@ -948,8 +948,8 @@ native_thread_create(rb_thread_t *th)
#ifdef get_stack_of
if (!err) {
get_stack_of(th->thread_id,
- &th->machine_stack_start,
- &th->machine_stack_maxsize);
+ &th->machine.stack_start,
+ &th->machine.stack_maxsize);
}
native_mutex_unlock(&th->interrupt_lock);
#endif
@@ -1558,15 +1558,24 @@ ruby_stack_overflowed_p(const rb_thread_t *th, const void *addr)
const size_t water_mark = 1024 * 1024;
STACK_GROW_DIR_DETECTION;
- if (th) {
- size = th->machine_stack_maxsize;
- base = (char *)th->machine_stack_start - STACK_DIR_UPPER(0, size);
- }
#ifdef STACKADDR_AVAILABLE
- else if (get_stack(&base, &size) == 0) {
- STACK_DIR_UPPER((void)(base = (char *)base + size), (void)0);
+ if (get_stack(&base, &size) == 0) {
+# ifdef __APPLE__
+ if (pthread_equal(th->thread_id, native_main_thread.id)) {
+ struct rlimit rlim;
+ if (getrlimit(RLIMIT_STACK, &rlim) == 0 && rlim.rlim_cur > size) {
+ size = (size_t)rlim.rlim_cur;
+ }
+ }
+# endif
+ base = (char *)base + STACK_DIR_UPPER(+size, -size);
}
+ else
#endif
+ if (th) {
+ size = th->machine.stack_maxsize;
+ base = (char *)th->machine.stack_start - STACK_DIR_UPPER(0, size);
+ }
else {
return 0;
}