From 8d84ffd84fd152eb0969eb10681c27443b9e5ac5 Mon Sep 17 00:00:00 2001 From: Elliot Saba Date: Thu, 17 Nov 2022 08:21:07 -0800 Subject: [PATCH 1/2] Enable coredumps on Windows This commit provides two pieces; first, it enables building libuv with `SIGQUIT` support on Windows (useful for [0]), and second it enables coredumping when exceptions are hit, after our exception handler has finished printing out a backtrace. This is useful for using WER to create dump files when we segfault, etc... This commit requires libuv PRs [1] and [2] to properly function. [0] https://github.com/JuliaLang/julia/pull/45864 [1] https://github.com/JuliaLang/libuv/pull/30 [2] https://github.com/JuliaLang/libuv/pull/31 --- Make.inc | 2 +- src/signals-win.c | 22 +++++++++++++++++----- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/Make.inc b/Make.inc index 5676f8c0a2878..c2943eb708397 100644 --- a/Make.inc +++ b/Make.inc @@ -1300,7 +1300,7 @@ endif ifeq ($(OS), WINNT) HAVE_SSP := 1 OSLIBS += -Wl,--export-all-symbols -Wl,--version-script=$(JULIAHOME)/src/julia.expmap \ - $(NO_WHOLE_ARCHIVE) -lpsapi -lkernel32 -lws2_32 -liphlpapi -lwinmm -ldbghelp -luserenv -lsecur32 -latomic + $(NO_WHOLE_ARCHIVE) -lpsapi -lkernel32 -lws2_32 -liphlpapi -lwinmm -ldbghelp -luserenv -lsecur32 -latomic -ldbghelp -lshell32 -lole32 -luuid JLDFLAGS += -Wl,--stack,8388608 ifeq ($(ARCH),i686) JLDFLAGS += -Wl,--large-address-aware diff --git a/src/signals-win.c b/src/signals-win.c index f20a4d5287669..ab460e18a808b 100644 --- a/src/signals-win.c +++ b/src/signals-win.c @@ -277,6 +277,19 @@ LONG WINAPI jl_exception_handler(struct _EXCEPTION_POINTERS *ExceptionInfo) break; } } + static int thread0_exit_count = 0; + SetUnhandledExceptionFilter(NULL); + thread0_exit_count++; + uv_tty_reset_mode(); + fflush(NULL); + + if (thread0_exit_count > 1) { + // This should not return + RaiseFailFastException(ExceptionInfo->ExceptionRecord, ExceptionInfo->ContextRecord, 0); + jl_safe_printf("Unexpected return from RaiseFailFastException()!\n"); + return EXCEPTION_CONTINUE_SEARCH; + } + if (ExceptionInfo->ExceptionRecord->ExceptionCode == EXCEPTION_ILLEGAL_INSTRUCTION) { jl_safe_printf("\n"); jl_show_sigill(ExceptionInfo->ContextRecord); @@ -330,11 +343,10 @@ LONG WINAPI jl_exception_handler(struct _EXCEPTION_POINTERS *ExceptionInfo) jl_print_native_codeloc((uintptr_t)ExceptionInfo->ExceptionRecord->ExceptionAddress); jl_critical_error(0, 0, ExceptionInfo->ContextRecord, ct); - static int recursion = 0; - if (recursion++) - exit(1); - else - jl_exit(1); + jl_atexit_hook(128); + RaiseFailFastException(ExceptionInfo->ExceptionRecord, ExceptionInfo->ContextRecord, 0); + jl_safe_printf("Unexpected return from RaiseFailFastException()!\n"); + return EXCEPTION_CONTINUE_SEARCH; } JL_DLLEXPORT void jl_install_sigint_handler(void) From 6441d99741485821dad7c9a51059e82b9eebb798 Mon Sep 17 00:00:00 2001 From: Elliot Saba Date: Thu, 17 Nov 2022 15:09:32 -0800 Subject: [PATCH 2/2] Update Make.inc --- Make.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Make.inc b/Make.inc index c2943eb708397..f87277ac69aab 100644 --- a/Make.inc +++ b/Make.inc @@ -1300,7 +1300,7 @@ endif ifeq ($(OS), WINNT) HAVE_SSP := 1 OSLIBS += -Wl,--export-all-symbols -Wl,--version-script=$(JULIAHOME)/src/julia.expmap \ - $(NO_WHOLE_ARCHIVE) -lpsapi -lkernel32 -lws2_32 -liphlpapi -lwinmm -ldbghelp -luserenv -lsecur32 -latomic -ldbghelp -lshell32 -lole32 -luuid + $(NO_WHOLE_ARCHIVE) -lpsapi -lkernel32 -lws2_32 -liphlpapi -lwinmm -ldbghelp -luserenv -lsecur32 -latomic -lshell32 -lole32 -luuid JLDFLAGS += -Wl,--stack,8388608 ifeq ($(ARCH),i686) JLDFLAGS += -Wl,--large-address-aware