summaryrefslogtreecommitdiff
path: root/thread_pthread.c
diff options
context:
space:
mode:
authornaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-08-23 02:21:38 +0000
committernaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-08-23 02:21:38 +0000
commitcc8354ba83e311056b2ccf69de0d67aa547afe27 (patch)
treea9a0db909a944316df22dbaf7d897d19dcd141cf /thread_pthread.c
parentf869ed2ff334c78d21aaebf7c359df80593e358c (diff)
merge revision(s) 35978,36013,36014,36015,36052,36076,36487: [Backport #6898]
* thread_pthread.c (ruby_init_stack): use stack info if possible. * thread_pthread.c (ruby_init_stack): adjust stack size for offset of addr from the bottom. * thread_pthread.c (get_stack): seems stack size does not include guard size on Mac OS X. * gc.h (IS_STACK_DIR_UPPER): utility macro. * thread_pthread.c (get_stack): Linux is the only OS which includes the size of guard page into the stack size. * thread_pthread.c (ruby_init_stack): STACK_GROW_DIR_DETECTION is necessary on platforms with unknown stack direction. [Bug #6761] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_3@36789 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'thread_pthread.c')
-rw-r--r--thread_pthread.c43
1 files changed, 21 insertions, 22 deletions
diff --git a/thread_pthread.c b/thread_pthread.c
index eff3d81368..6659972d97 100644
--- a/thread_pthread.c
+++ b/thread_pthread.c
@@ -477,41 +477,38 @@ get_stack(void **addr, size_t *size)
{
#define CHECK_ERR(expr) \
{int err = (expr); if (err) return err;}
-#if defined HAVE_PTHREAD_GETATTR_NP || defined HAVE_PTHREAD_ATTR_GET_NP || \
- (defined HAVE_PTHREAD_GET_STACKADDR_NP && defined HAVE_PTHREAD_GET_STACKSIZE_NP)
+#ifdef HAVE_PTHREAD_GETATTR_NP /* Linux */
pthread_attr_t attr;
size_t guard = 0;
-
-# ifdef HAVE_PTHREAD_GETATTR_NP /* Linux */
STACK_GROW_DIR_DETECTION;
CHECK_ERR(pthread_getattr_np(pthread_self(), &attr));
-# ifdef HAVE_PTHREAD_ATTR_GETSTACK
+# ifdef HAVE_PTHREAD_ATTR_GETSTACK
CHECK_ERR(pthread_attr_getstack(&attr, addr, size));
STACK_DIR_UPPER((void)0, (void)(*addr = (char *)*addr + *size));
-# else
+# else
CHECK_ERR(pthread_attr_getstackaddr(&attr, addr));
CHECK_ERR(pthread_attr_getstacksize(&attr, size));
-# endif
-# elif defined HAVE_PTHREAD_ATTR_GET_NP /* FreeBSD, DragonFly BSD, NetBSD */
+# endif
+ CHECK_ERR(pthread_attr_getguardsize(&attr, &guard));
+ *size -= guard;
+ pthread_attr_destroy(&attr);
+#elif defined HAVE_PTHREAD_ATTR_GET_NP /* FreeBSD, DragonFly BSD, NetBSD */
+ pthread_attr_t attr;
CHECK_ERR(pthread_attr_init(&attr));
CHECK_ERR(pthread_attr_get_np(pthread_self(), &attr));
-# ifdef HAVE_PTHREAD_ATTR_GETSTACK
+# ifdef HAVE_PTHREAD_ATTR_GETSTACK
CHECK_ERR(pthread_attr_getstack(&attr, addr, size));
STACK_DIR_UPPER((void)0, (void)(*addr = (char *)*addr + *size));
-# else
+# else
CHECK_ERR(pthread_attr_getstackaddr(&attr, addr));
CHECK_ERR(pthread_attr_getstacksize(&attr, size));
STACK_DIR_UPPER((void)0, (void)(*addr = (char *)*addr + *size));
-# endif
-# else /* MacOS X */
+# endif
+ pthread_attr_destroy(&attr);
+#elif (defined HAVE_PTHREAD_GET_STACKADDR_NP && defined HAVE_PTHREAD_GET_STACKSIZE_NP) /* MacOS X */
pthread_t th = pthread_self();
*addr = pthread_get_stackaddr_np(th);
*size = pthread_get_stacksize_np(th);
- CHECK_ERR(pthread_attr_init(&attr));
-# endif
- CHECK_ERR(pthread_attr_getguardsize(&attr, &guard));
- *size -= guard;
- pthread_attr_destroy(&attr);
#elif defined HAVE_THR_STKSEGMENT || defined HAVE_PTHREAD_STACKSEG_NP
stack_t stk;
# if defined HAVE_THR_STKSEGMENT /* Solaris */
@@ -581,16 +578,18 @@ ruby_init_stack(volatile VALUE *addr
{
size_t size = 0;
size_t space = 0;
-#if defined(HAVE_PTHREAD_ATTR_GET_NP)
- void* addr;
- get_stack(&addr, &size);
+#if defined(STACKADDR_AVAILABLE)
+ void* stackaddr;
+ STACK_GROW_DIR_DETECTION;
+ get_stack(&stackaddr, &size);
+ space = STACK_DIR_UPPER((char *)addr - (char *)stackaddr, (char *)stackaddr - (char *)addr);
#elif defined(HAVE_GETRLIMIT)
struct rlimit rlim;
if (getrlimit(RLIMIT_STACK, &rlim) == 0) {
size = (size_t)rlim.rlim_cur;
}
-#endif
space = size > 5 * 1024 * 1024 ? 1024 * 1024 : size / 5;
+#endif
native_main_thread.stack_maxsize = size - space;
}
}
@@ -1310,7 +1309,7 @@ ruby_stack_overflowed_p(const rb_thread_t *th, const void *addr)
}
size /= 5;
if (size > water_mark) size = water_mark;
- if (STACK_DIR_UPPER(1, 0)) {
+ if (IS_STACK_DIR_UPPER()) {
if (size > ~(size_t)base+1) size = ~(size_t)base+1;
if (addr > base && addr <= (void *)((char *)base + size)) return 1;
}