ruby-changes:34495
From: usa <ko1@a...>
Date: Fri, 27 Jun 2014 17:03:21 +0900 (JST)
Subject: [ruby-changes:34495] usa:r46576 (ruby_2_0_0): merge revision(s) 43748, 45947, 45951: [Backport #9739]
usa 2014-06-27 17:03:11 +0900 (Fri, 27 Jun 2014) New Revision: 46576 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=46576 Log: merge revision(s) 43748,45947,45951: [Backport #9739] * 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. * thread_win32.c (rb_w32_stack_overflow_handler): use Structured Exception Handling by Addvectoredexceptionhandler() for machine stack overflow on mingw. This would be equivalent to the handling using __try and __exept on mswin introduced by r43748. Exception Handling by AddVectoredExceptionHandler() for machine This would be equivalent to the handling using __try and __except Modified directories: branches/ruby_2_0_0/ Modified files: branches/ruby_2_0_0/ChangeLog branches/ruby_2_0_0/eval_intern.h branches/ruby_2_0_0/signal.c branches/ruby_2_0_0/thread_win32.c branches/ruby_2_0_0/version.h Index: ruby_2_0_0/eval_intern.h =================================================================== --- ruby_2_0_0/eval_intern.h (revision 46575) +++ ruby_2_0_0/eval_intern.h (revision 46576) @@ -83,9 +83,37 @@ extern int select_large_fdset(int, fd_se https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/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 */ \ + } +#elif defined(__MINGW32__) +LONG WINAPI rb_w32_stack_overflow_handler(struct _EXCEPTION_POINTERS *); +#define SAVE_ROOT_JMPBUF_BEFORE_STMT \ + do { \ + PVOID _handler = AddVectoredExceptionHandler(1, rb_w32_stack_overflow_handler); + +#define SAVE_ROOT_JMPBUF_AFTER_STMT \ + RemoveVectoredExceptionHandler(_handler); \ + } while (0); +#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: ruby_2_0_0/thread_win32.c =================================================================== --- ruby_2_0_0/thread_win32.c (revision 46575) +++ ruby_2_0_0/thread_win32.c (revision 46576) @@ -766,6 +766,24 @@ native_reset_timer_thread(void) https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/thread_win32.c#L766 } } +int +ruby_stack_overflowed_p(const rb_thread_t *th, const void *addr) +{ + return rb_thread_raised_p(th, RAISED_STACKOVERFLOW); +} + +#if defined(__MINGW32__) +LONG WINAPI +rb_w32_stack_overflow_handler(struct _EXCEPTION_POINTERS *exception) +{ + if (exception->ExceptionRecord->ExceptionCode == EXCEPTION_STACK_OVERFLOW) { + rb_thread_raised_set(GET_THREAD(), RAISED_STACKOVERFLOW); + raise(SIGSEGV); + } + return EXCEPTION_CONTINUE_SEARCH; +} +#endif + #ifdef RUBY_ALLOCA_CHKSTK void ruby_alloca_chkstk(size_t len, void *sp) Index: ruby_2_0_0/ChangeLog =================================================================== --- ruby_2_0_0/ChangeLog (revision 46575) +++ ruby_2_0_0/ChangeLog (revision 46576) @@ -1,3 +1,28 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/ChangeLog#L1 +Fri Jun 27 17:02:36 2014 Hiroshi Shirosaki <h.shirosaki@g...> + + * thread_win32.c (rb_w32_stack_overflow_handler): use Structured + Exception Handling by AddVectoredExceptionHandler() for machine + stack overflow on mingw. + This would be equivalent to the handling using __try and __except + on mswin introduced by r43748. + +Fri Jun 27 17:02:36 2014 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. + Fri Jun 27 16:56:38 2014 Eric Wong <e@8...> * signal.c (signal_exec): ignore immediate cmd for SIG_IGN Index: ruby_2_0_0/version.h =================================================================== --- ruby_2_0_0/version.h (revision 46575) +++ ruby_2_0_0/version.h (revision 46576) @@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/version.h#L1 #define RUBY_VERSION "2.0.0" #define RUBY_RELEASE_DATE "2014-06-27" -#define RUBY_PATCHLEVEL 500 +#define RUBY_PATCHLEVEL 501 #define RUBY_RELEASE_YEAR 2014 #define RUBY_RELEASE_MONTH 6 Index: ruby_2_0_0/signal.c =================================================================== --- ruby_2_0_0/signal.c (revision 46575) +++ ruby_2_0_0/signal.c (revision 46576) @@ -605,7 +605,7 @@ rb_get_next_signal(void) https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/signal.c#L605 } -#ifdef USE_SIGALTSTACK +#if defined(USE_SIGALTSTACK) || defined(_WIN32) static void check_stack_overflow(const void *addr) { @@ -616,7 +616,11 @@ check_stack_overflow(const void *addr) https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/signal.c#L616 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 Property changes on: ruby_2_0_0 ___________________________________________________________________ Modified: svn:mergeinfo Merged /trunk:r43748,45947,45951 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/