ruby-changes:6703
From: nobu <ko1@a...>
Date: Fri, 25 Jul 2008 23:24:34 +0900 (JST)
Subject: [ruby-changes:6703] Ruby:r18219 (mvm): * thread_pthread.c (get_stack): subtract guard size.
nobu 2008-07-25 23:24:10 +0900 (Fri, 25 Jul 2008) New Revision: 18219 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=18219 Log: * thread_pthread.c (get_stack): subtract guard size. * thread_pthread.c (thread_start_func_1): fix for stack size adjustment. * thread_pthread.c (ruby_stack_overflowed_p): take thread and the address. * gc.c (ruby_stack_check): check overflow. * signal.c (sigsegv): use ruby_stack_overflowed_p. Modified files: branches/mvm/ChangeLog branches/mvm/gc.c branches/mvm/signal.c branches/mvm/thread_pthread.c Index: mvm/ChangeLog =================================================================== --- mvm/ChangeLog (revision 18218) +++ mvm/ChangeLog (revision 18219) @@ -1,3 +1,17 @@ +Fri Jul 25 23:24:07 2008 Nobuyoshi Nakada <nobu@r...> + + * thread_pthread.c (get_stack): subtract guard size. + + * thread_pthread.c (thread_start_func_1): fix for stack size + adjustment. + + * thread_pthread.c (ruby_stack_overflowed_p): take thread and the + address. + + * gc.c (ruby_stack_check): check overflow. + + * signal.c (sigsegv): use ruby_stack_overflowed_p. + Fri Jul 25 16:21:14 2008 Nobuyoshi Nakada <nobu@r...> * include/ruby/io.h (ruby_absolute_path_p): published. Index: mvm/thread_pthread.c =================================================================== --- mvm/thread_pthread.c (revision 18218) +++ mvm/thread_pthread.c (revision 18219) @@ -194,6 +194,14 @@ #define USE_THREAD_CACHE 0 +#if STACK_GROW_DIRECTION +#define STACK_GROW_DIR_DETECTION +#define STACK_DIR_UPPER(a,b) STACK_UPPER(0, a, b) +#else +#define STACK_GROW_DIR_DETECTION VALUE stack_grow_dir_detection +#define STACK_DIR_UPPER(a,b) STACK_UPPER(&stack_grow_dir_detection, a, b) +#endif + static int get_stack(void **addr, size_t *size) { @@ -212,6 +220,11 @@ CHECK_ERR(pthread_attr_getstackaddr(&attr, addr)); CHECK_ERR(pthread_attr_getstacksize(&attr, size)); # endif + if (pthread_attr_getguardsize(&attr, &guard) == 0) { + STACK_GROW_DIR_DETECTION; + STACK_DIR_UPPER((void)0, *addr = (char *)*addr + guard); + *size -= guard; + } # else CHECK_ERR(pthread_attr_init(&attr)); CHECK_ERR(pthread_attr_get_np(pthread_self(), &attr)); @@ -302,14 +315,6 @@ #endif } -#if STACK_GROW_DIRECTION -#define STACK_GROW_DIR_DETECTION -#define STACK_DIR_UPPER(a,b) STACK_UPPER(0, a, b) -#else -#define STACK_GROW_DIR_DETECTION VALUE stack_grow_dir_detection -#define STACK_DIR_UPPER(a,b) STACK_UPPER(&stack_grow_dir_detection, a, b) -#endif - static int native_thread_init_stack(rb_thread_t *th) { @@ -357,9 +362,9 @@ void *addr; size_t size; if (get_stack(&addr, &size)) return 0; - size -= STACK_UPPER(&stack_start, - (char *)&stack_start - (char *)addr, - (char *)addr - (char *)&stack_start); + STACK_UPPER(&stack_start, + size -= (char *)&stack_start - (char *)addr, + size = (char *)&stack_start - (char *)addr); th->machine_stack_start = &stack_start; th->machine_stack_maxsize = size; #endif @@ -801,12 +806,11 @@ #ifdef HAVE_SIGALTSTACK int -ruby_stack_overflow_p(siginfo_t *info, ucontext_t *ctx) +ruby_stack_overflowed_p(const rb_thread_t *th, const void *addr) { - void *base, *addr = info->si_addr; + void *base; size_t size; const size_t water_mark = 64 * 1024; - rb_thread_t *th = ruby_thread_from_native(); STACK_GROW_DIR_DETECTION; if (th) { Index: mvm/gc.c =================================================================== --- mvm/gc.c (revision 18218) +++ mvm/gc.c (revision 18219) @@ -819,13 +819,10 @@ ruby_stack_check(void) { int ret = 0; -#if !defined HAVE_SIGALTSTACK || defined __ia64 rb_thread_t *th = GET_THREAD(); -#endif -#ifndef HAVE_SIGALTSTACK + SET_STACK_END; ret = STACK_LENGTH > STACK_LEVEL_MAX - GC_WATER_MARK; -#endif #ifdef __ia64 if (!ret) { ret = (VALUE*)rb_ia64_bsp() - th->machine_register_stack_start > Index: mvm/signal.c =================================================================== --- mvm/signal.c (revision 18218) +++ mvm/signal.c (revision 18219) @@ -583,17 +583,14 @@ #endif #ifdef SIGSEGV -# ifdef HAVE_SIGALTSTACK -int ruby_stack_overflow_p(siginfo_t*, ucontext_t*); -# endif - static int segv_received = 0; static RETSIGTYPE sigsegv(int sig SIGINFO_ARG) { #ifdef HAVE_SIGALTSTACK - if (ruby_stack_overflow_p(info, ctx)) { - rb_thread_t *th = GET_THREAD(); + int ruby_stack_overflowed_p(const rb_thread_t *, const void *); + rb_thread_t *th = GET_THREAD(); + if (ruby_stack_overflowed_p(th, info->si_addr)) { th->errinfo = sysstack_error; rb_thread_raised_clear(th); TH_JUMP_TAG(th, TAG_RAISE); -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/