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

ruby-changes:31669

From: usa <ko1@a...>
Date: Thu, 21 Nov 2013 15:33:54 +0900 (JST)
Subject: [ruby-changes:31669] usa:r43748 (trunk): * eval_intern.h (SAVE_ROOT_JMPBUF): workaround for the failure of

usa	2013-11-21 15:33:41 +0900 (Thu, 21 Nov 2013)

  New Revision: 43748

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

  Log:
    * eval_intern.h (SAVE_ROOT_JMPBUF): workaround for the failure of
      test/ruby/test_exception.rb on Windows.
      wrap by __try and __exception statements on mswin to raise SIGSEGV
      when EXCEPTION_STACK_OVERFLOW is occurred, because MSVCRT doesn't
      handle the exception.
      however, (1) mingw-gcc doesn't support __try and __exception
      statements, and (2) we cannot retry SystemStackError after this
      change yet (maybe crashed) because SEH and longjmp() are too
      uncongenial.
    
    * signal.c (check_stack_overflow, CHECK_STACK_OVERFLOW): now defined on
      Windows, too.
    
    * thread_win32.c (ruby_stack_overflowed_p): ditto.

  Modified files:
    trunk/ChangeLog
    trunk/eval_intern.h
    trunk/signal.c
    trunk/thread_win32.c
Index: eval_intern.h
===================================================================
--- eval_intern.h	(revision 43747)
+++ eval_intern.h	(revision 43748)
@@ -83,9 +83,28 @@ extern int select_large_fdset(int, fd_se https://github.com/ruby/ruby/blob/trunk/eval_intern.h#L83
 
 #include <sys/stat.h>
 
+#ifdef _MSC_VER
+#define SAVE_ROOT_JMPBUF_BEFORE_STMT \
+    __try {
+#define SAVE_ROOT_JMPBUF_AFTER_STMT \
+    } \
+    __except (GetExceptionCode() == EXCEPTION_STACK_OVERFLOW ? \
+	      (rb_thread_raised_set(GET_THREAD(), RAISED_STACKOVERFLOW), \
+	       raise(SIGSEGV), \
+	       EXCEPTION_EXECUTE_HANDLER) : \
+	      EXCEPTION_CONTINUE_SEARCH) { \
+	/* never reaches here */ \
+    }
+#else
+#define SAVE_ROOT_JMPBUF_BEFORE_STMT
+#define SAVE_ROOT_JMPBUF_AFTER_STMT
+#endif
+
 #define SAVE_ROOT_JMPBUF(th, stmt) do \
   if (ruby_setjmp((th)->root_jmpbuf) == 0) { \
+      SAVE_ROOT_JMPBUF_BEFORE_STMT \
       stmt; \
+      SAVE_ROOT_JMPBUF_AFTER_STMT \
   } \
   else { \
       rb_fiber_start(); \
Index: thread_win32.c
===================================================================
--- thread_win32.c	(revision 43747)
+++ thread_win32.c	(revision 43748)
@@ -748,6 +748,12 @@ native_reset_timer_thread(void) https://github.com/ruby/ruby/blob/trunk/thread_win32.c#L748
     }
 }
 
+int
+ruby_stack_overflowed_p(const rb_thread_t *th, const void *addr)
+{
+    return rb_thread_raised_p(th, RAISED_STACKOVERFLOW);
+}
+
 #ifdef RUBY_ALLOCA_CHKSTK
 void
 ruby_alloca_chkstk(size_t len, void *sp)
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 43747)
+++ ChangeLog	(revision 43748)
@@ -1,3 +1,20 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Thu Nov 21 14:46:57 2013  NAKAMURA Usaku  <usa@r...>
+
+	* eval_intern.h (SAVE_ROOT_JMPBUF): workaround for the failure of
+	  test/ruby/test_exception.rb on Windows.
+	  wrap by __try and __exception statements on mswin to raise SIGSEGV
+	  when EXCEPTION_STACK_OVERFLOW is occurred, because MSVCRT doesn't
+	  handle the exception.
+	  however, (1) mingw-gcc doesn't support __try and __exception
+	  statements, and (2) we cannot retry SystemStackError after this
+	  change yet (maybe crashed) because SEH and longjmp() are too
+	  uncongenial.
+
+	* signal.c (check_stack_overflow, CHECK_STACK_OVERFLOW): now defined on
+	  Windows, too.
+
+	* thread_win32.c (ruby_stack_overflowed_p): ditto.
+
 Thu Nov 21 14:18:24 2013  Zachary Scott  <e@z...>
 
 	* object.c: [DOC] Clarify Object#dup vs #clone [Bug #9128]
Index: signal.c
===================================================================
--- signal.c	(revision 43747)
+++ signal.c	(revision 43748)
@@ -627,7 +627,7 @@ rb_get_next_signal(void) https://github.com/ruby/ruby/blob/trunk/signal.c#L627
 }
 
 
-#ifdef USE_SIGALTSTACK
+#if defined(USE_SIGALTSTACK) || defined(_WIN32)
 static void
 check_stack_overflow(const void *addr)
 {
@@ -638,7 +638,11 @@ check_stack_overflow(const void *addr) https://github.com/ruby/ruby/blob/trunk/signal.c#L638
 	ruby_thread_stack_overflow(th);
     }
 }
+#ifdef _WIN32
+#define CHECK_STACK_OVERFLOW() check_stack_overflow(0)
+#else
 #define CHECK_STACK_OVERFLOW() check_stack_overflow(info->si_addr)
+#endif
 #else
 #define CHECK_STACK_OVERFLOW() (void)0
 #endif

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

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