diff options
author | kosaki <kosaki@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-12-15 14:20:12 +0000 |
---|---|---|
committer | kosaki <kosaki@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-12-15 14:20:12 +0000 |
commit | aff9dff46d79181d143697d7b9e76735788e45cc (patch) | |
tree | 004b41af951802cd8638800184cd4633cee21590 | |
parent | cbe5f8820b71e0e9a214ae86e9264712e5580413 (diff) |
* 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
-rw-r--r-- | ChangeLog | 14 | ||||
-rw-r--r-- | gc.c | 2 | ||||
-rw-r--r-- | internal.h | 1 | ||||
-rw-r--r-- | signal.c | 23 | ||||
-rw-r--r-- | vm.c | 2 | ||||
-rw-r--r-- | vm_core.h | 6 |
6 files changed, 39 insertions, 9 deletions
@@ -1,3 +1,17 @@ +Sat Dec 15 23:08:56 2012 KOSAKI Motohiro <kosaki.motohiro@gmail.com> + + * 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 <tadf@dotrb.org> * rational.c (f_round_common): should check overflow. @@ -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 @@ -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. */ @@ -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); @@ -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; |