aboutsummaryrefslogtreecommitdiffstats
path: root/thread_pthread.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-01-28 07:33:20 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-01-28 07:33:20 +0000
commitf423a63cfa55aca46c75c164a94947fc36e18ad3 (patch)
tree4e316ddc3b5b32f81b5d0b9198d4d2784fb66849 /thread_pthread.c
parent239c9942439817e3075b57612b028ada546aea0d (diff)
downloadruby-f423a63cfa55aca46c75c164a94947fc36e18ad3.tar.gz
thread_pthread.c: use get_stack
* 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/trunk@44726 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'thread_pthread.c')
-rw-r--r--thread_pthread.c41
1 files changed, 21 insertions, 20 deletions
diff --git a/thread_pthread.c b/thread_pthread.c
index 63da3c9799..a4a351076e 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)
@@ -1560,23 +1560,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;
-#if defined(HAVE_GETRLIMIT) && defined(__linux__) && MAINSTACKADDR_AVAILABLE
+#ifdef STACKADDR_AVAILABLE
+ 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);
}
-#ifdef STACKADDR_AVAILABLE
- else if (get_stack(&base, &size) == 0) {
- STACK_DIR_UPPER((void)(base = (char *)base + size), (void)0);
- }
-#endif
else {
return 0;
}