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
This commit is contained in:
nobu 2014-01-28 07:33:20 +00:00
Родитель 239c994243
Коммит f423a63cfa
2 изменённых файлов: 33 добавлений и 20 удалений

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

@ -1,3 +1,15 @@
Tue Jan 28 16:33:18 2014 Nobuyoshi Nakada <nobu@ruby-lang.org>
* 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]
Tue Jan 28 16:31:13 2014 Nobuyoshi Nakada <nobu@ruby-lang.org>
* 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]
Tue Jan 28 15:27:36 2014 NARUSE, Yui <naruse@ruby-lang.org>
* thread_pthread.c: rlimit is only available on Linux.

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

@ -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
@ -676,18 +688,6 @@ ruby_init_stack(volatile VALUE *addr
(VALUE*)bsp < native_main_thread.register_stack_start) {
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)
@ -1560,9 +1560,9 @@ 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) {
@ -1570,13 +1570,14 @@ ruby_stack_overflowed_p(const rb_thread_t *th, const void *addr)
}
}
# 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;
}