[前][次][番号順一覧][スレッド一覧]

ruby-changes:26358

From: kosaki <ko1@a...>
Date: Sat, 15 Dec 2012 23:20:23 +0900 (JST)
Subject: [ruby-changes:26358] kosaki:r38409 (trunk): * signal.c (rb_sigaltstack_size): new. calculate stack size for

kosaki	2012-12-15 23:20:12 +0900 (Sat, 15 Dec 2012)

  New Revision: 38409

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=38409

  Log:
    * 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.

  Modified files:
    trunk/ChangeLog
    trunk/gc.c
    trunk/internal.h
    trunk/signal.c
    trunk/vm.c
    trunk/vm_core.h

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 38408)
+++ ChangeLog	(revision 38409)
@@ -1,3 +1,17 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sat Dec 15 23:08:56 2012  KOSAKI Motohiro  <kosaki.motohiro@g...>
+
+	* 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@d...>
 
 	* rational.c (f_round_common): should check overflow.
Index: vm_core.h
===================================================================
--- vm_core.h	(revision 38408)
+++ vm_core.h	(revision 38409)
@@ -456,12 +456,6 @@ struct rb_unblock_callback { https://github.com/ruby/ruby/blob/trunk/vm_core.h#L456
 
 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;
Index: gc.c
===================================================================
--- gc.c	(revision 38408)
+++ gc.c	(revision 38409)
@@ -574,7 +574,7 @@ init_heap(rb_objspace_t *objspace) https://github.com/ruby/ruby/blob/trunk/gc.c#L574
 	/* 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
Index: internal.h
===================================================================
--- internal.h	(revision 38408)
+++ internal.h	(revision 38409)
@@ -252,6 +252,7 @@ VALUE rb_reg_check_preprocess(VALUE); https://github.com/ruby/ruby/blob/trunk/internal.h#L252
 
 /* signal.c */
 int rb_get_next_signal(void);
+int rb_sigaltstack_size(void);
 
 /* strftime.c */
 #ifdef RUBY_ENCODING_H
Index: vm.c
===================================================================
--- vm.c	(revision 38408)
+++ vm.c	(revision 38409)
@@ -1834,7 +1834,7 @@ th_init(rb_thread_t *th, VALUE self) https://github.com/ruby/ruby/blob/trunk/vm.c#L1834
     /* 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);
Index: signal.c
===================================================================
--- signal.c	(revision 38408)
+++ signal.c	(revision 38409)
@@ -447,6 +447,27 @@ typedef RETSIGTYPE ruby_sigaction_t(int) https://github.com/ruby/ruby/blob/trunk/signal.c#L447
 #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) https://github.com/ruby/ruby/blob/trunk/signal.c#L478
 	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. */

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]