* thread_pthread.c (get_stack): the return address of get_stack

must be the highest address of the current thread's stack.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32395 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
naruse 2011-07-03 22:16:02 +00:00
Родитель eb35bb0b35
Коммит 948f01a865
2 изменённых файлов: 14 добавлений и 3 удалений

Просмотреть файл

@ -1,3 +1,8 @@
Mon Jul 4 07:14:12 2011 NARUSE, Yui <naruse@ruby-lang.org>
* thread_pthread.c (get_stack): the return address of get_stack
must be the highest address of the current thread's stack.
Mon Jul 4 06:37:22 2011 Koichi Sasada <ko1@atdot.net> Mon Jul 4 06:37:22 2011 Koichi Sasada <ko1@atdot.net>
* include/ruby/intern.h, thread_pthread.c (rb_reserved_fd_p, * include/ruby/intern.h, thread_pthread.c (rb_reserved_fd_p,

Просмотреть файл

@ -453,6 +453,9 @@ static rb_thread_t *register_cached_thread_and_wait(void);
#endif #endif
#ifdef STACKADDR_AVAILABLE #ifdef STACKADDR_AVAILABLE
/*
* Get the highest address and size of current thread's stack
*/
static int static int
get_stack(void **addr, size_t *size) get_stack(void **addr, size_t *size)
{ {
@ -478,6 +481,7 @@ get_stack(void **addr, size_t *size)
CHECK_ERR(pthread_attr_get_np(pthread_self(), &attr)); CHECK_ERR(pthread_attr_get_np(pthread_self(), &attr));
CHECK_ERR(pthread_attr_getstackaddr(&attr, addr)); CHECK_ERR(pthread_attr_getstackaddr(&attr, addr));
CHECK_ERR(pthread_attr_getstacksize(&attr, size)); CHECK_ERR(pthread_attr_getstacksize(&attr, size));
*addr = (char *)*addr + *size;
# else /* MacOS X */ # else /* MacOS X */
pthread_t th = pthread_self(); pthread_t th = pthread_self();
*addr = pthread_get_stackaddr_np(th); *addr = pthread_get_stackaddr_np(th);
@ -489,14 +493,14 @@ get_stack(void **addr, size_t *size)
pthread_attr_destroy(&attr); pthread_attr_destroy(&attr);
#elif defined HAVE_THR_STKSEGMENT || defined HAVE_PTHREAD_STACKSEG_NP #elif defined HAVE_THR_STKSEGMENT || defined HAVE_PTHREAD_STACKSEG_NP
stack_t stk; stack_t stk;
# if defined HAVE_THR_STKSEGMENT # if defined HAVE_THR_STKSEGMENT /* Solaris */
CHECK_ERR(thr_stksegment(&stk)); CHECK_ERR(thr_stksegment(&stk));
# else # else /* OpenBSD */
CHECK_ERR(pthread_stackseg_np(pthread_self(), &stk)); CHECK_ERR(pthread_stackseg_np(pthread_self(), &stk));
# endif # endif
*addr = stk.ss_sp; *addr = stk.ss_sp;
*size = stk.ss_size; *size = stk.ss_size;
#elif defined HAVE_PTHREAD_GETTHRDS_NP #elif defined HAVE_PTHREAD_GETTHRDS_NP /* AIX */
pthread_t th = pthread_self(); pthread_t th = pthread_self();
struct __pthrdsinfo thinfo; struct __pthrdsinfo thinfo;
char reg[256]; char reg[256];
@ -506,6 +510,8 @@ get_stack(void **addr, size_t *size)
&reg, &regsiz)); &reg, &regsiz));
*addr = thinfo.__pi_stackaddr; *addr = thinfo.__pi_stackaddr;
*size = thinfo.__pi_stacksize; *size = thinfo.__pi_stacksize;
#else
#error STACKADDR_AVAILABLE is defined but not implemented.
#endif #endif
return 0; return 0;
#undef CHECK_ERR #undef CHECK_ERR