From aff9dff46d79181d143697d7b9e76735788e45cc Mon Sep 17 00:00:00 2001 From: kosaki Date: Sat, 15 Dec 2012 14:20:12 +0000 Subject: * signal.c (rb_sigaltstack_size): new. calculate stack size for sigsegv handler. enlarge value when x86 or x86_64 on Linux. Linux has very small MINSIGSTKSZ size (2048 bytes) and our sigsegv routine need 5KiB at least. [Bug #7141] * internal.h: add declaration of rb_sigaltstack_size(). * vm_core.h: remove ALT_STACK_SIZE definition. * signal.c (rb_register_sigaltstack): replace ALT_STACK_SIZE with rb_sigaltstack_size(); * gc.c (Init_heap): ditto. * vm.c (th_init): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38409 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 14 ++++++++++++++ gc.c | 2 +- internal.h | 1 + signal.c | 23 ++++++++++++++++++++++- vm.c | 2 +- vm_core.h | 6 ------ 6 files changed, 39 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index 27c746c766..2dd72299a3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +Sat Dec 15 23:08:56 2012 KOSAKI Motohiro + + * signal.c (rb_sigaltstack_size): new. calculate stack size for + sigsegv handler. enlarge value when x86 or x86_64 on Linux. + Linux has very small MINSIGSTKSZ size (2048 bytes) and + our sigsegv routine need 5KiB at least. [Bug #7141] + * internal.h: add declaration of rb_sigaltstack_size(). + * vm_core.h: remove ALT_STACK_SIZE definition. + + * signal.c (rb_register_sigaltstack): replace ALT_STACK_SIZE with + rb_sigaltstack_size(); + * gc.c (Init_heap): ditto. + * vm.c (th_init): ditto. + Sat Dec 15 18:24:21 2012 Tadayoshi Funaba * rational.c (f_round_common): should check overflow. diff --git a/gc.c b/gc.c index 4c5e2b48a8..c87526d016 100644 --- a/gc.c +++ b/gc.c @@ -574,7 +574,7 @@ init_heap(rb_objspace_t *objspace) /* altstack of another threads are allocated in another place */ rb_thread_t *th = GET_THREAD(); void *tmp = th->altstack; - th->altstack = malloc(ALT_STACK_SIZE); + th->altstack = malloc(rb_sigaltstack_size()); free(tmp); /* free previously allocated area */ } #endif diff --git a/internal.h b/internal.h index b069f67bb1..4ae0edf4b6 100644 --- a/internal.h +++ b/internal.h @@ -252,6 +252,7 @@ VALUE rb_reg_check_preprocess(VALUE); /* signal.c */ int rb_get_next_signal(void); +int rb_sigaltstack_size(void); /* strftime.c */ #ifdef RUBY_ENCODING_H diff --git a/signal.c b/signal.c index 59ffde93db..44cb8e713e 100644 --- a/signal.c +++ b/signal.c @@ -447,6 +447,27 @@ typedef RETSIGTYPE ruby_sigaction_t(int); #endif #ifdef USE_SIGALTSTACK +int rb_sigaltstack_size(void) +{ + /* XXX: BSD_vfprintf() uses >1500KiB stack and x86-64 need >5KiB stack. */ + int size = 8192; + +#ifdef MINSIGSTKSZ + if (size < MINSIGSTKSZ) + size = MINSIGSTKSZ; +#endif +#if defined(HAVE_SYSCONF) && defined(_SC_PAGE_SIZE) + { + int pagesize; + pagesize = sysconf(_SC_PAGE_SIZE); + if (size < pagesize) + size = pagesize; + } +#endif + + return size; +} + /* alternate stack for SIGSEGV */ void rb_register_sigaltstack(rb_thread_t *th) @@ -457,7 +478,7 @@ rb_register_sigaltstack(rb_thread_t *th) rb_bug("rb_register_sigaltstack: th->altstack not initialized\n"); newSS.ss_sp = th->altstack; - newSS.ss_size = ALT_STACK_SIZE; + newSS.ss_size = rb_sigaltstack_size(); newSS.ss_flags = 0; sigaltstack(&newSS, &oldSS); /* ignore error. */ diff --git a/vm.c b/vm.c index da15fd2675..2266754fc7 100644 --- a/vm.c +++ b/vm.c @@ -1834,7 +1834,7 @@ th_init(rb_thread_t *th, VALUE self) /* allocate thread stack */ #ifdef USE_SIGALTSTACK /* altstack of main thread is reallocated in another place */ - th->altstack = malloc(ALT_STACK_SIZE); + th->altstack = malloc(rb_sigaltstack_size()); #endif th->stack_size = RUBY_VM_THREAD_STACK_SIZE; th->stack = thread_recycle_stack(th->stack_size); diff --git a/vm_core.h b/vm_core.h index 73b24a1e0e..8cc48bc00d 100644 --- a/vm_core.h +++ b/vm_core.h @@ -456,12 +456,6 @@ struct rb_unblock_callback { struct rb_mutex_struct; -#ifdef MINSIGSTKSZ -#define ALT_STACK_SIZE (MINSIGSTKSZ*2) -#else -#define ALT_STACK_SIZE (4*1024) -#endif - struct rb_thread_struct; typedef struct rb_thread_list_struct{ struct rb_thread_list_struct *next; -- cgit v1.2.3