From 1df5ebf450b13427466c4e31fd3970c8430b6ac7 Mon Sep 17 00:00:00 2001 From: usa Date: Thu, 21 Nov 2013 06:33:41 +0000 Subject: * 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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43748 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 17 +++++++++++++++++ eval_intern.h | 19 +++++++++++++++++++ signal.c | 6 +++++- thread_win32.c | 6 ++++++ 4 files changed, 47 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 861d11110c..aca3d94dfc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,20 @@ +Thu Nov 21 14:46:57 2013 NAKAMURA Usaku + + * 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 * object.c: [DOC] Clarify Object#dup vs #clone [Bug #9128] diff --git a/eval_intern.h b/eval_intern.h index 5802e277ee..a0ecb5086b 100644 --- a/eval_intern.h +++ b/eval_intern.h @@ -83,9 +83,28 @@ extern int select_large_fdset(int, fd_set *, fd_set *, fd_set *, struct timeval #include +#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(); \ diff --git a/signal.c b/signal.c index 75b4b9bf09..b07a99db15 100644 --- a/signal.c +++ b/signal.c @@ -627,7 +627,7 @@ rb_get_next_signal(void) } -#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) 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 diff --git a/thread_win32.c b/thread_win32.c index c203b556a3..9f851867c8 100644 --- a/thread_win32.c +++ b/thread_win32.c @@ -748,6 +748,12 @@ native_reset_timer_thread(void) } } +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) -- cgit v1.2.3