From 641748bd4256754be33c94fb6ec41f499754a61c Mon Sep 17 00:00:00 2001 From: Jameson Nash Date: Tue, 3 Sep 2024 12:24:01 -0400 Subject: [PATCH] win: move stack_overflow_warning to the backtrace fiber (#55640) There is not enough stack space remaining after a stack overflow on Windows to allocate the 4k page used by `write` to call the WriteFile syscall. This causes it to hard-crash. But we can simply run this on the altstack implementation, where there is plenty of space. --- src/signals-win.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/signals-win.c b/src/signals-win.c index d7288b5d365d8a..dbc3f8dad09688 100644 --- a/src/signals-win.c +++ b/src/signals-win.c @@ -109,6 +109,8 @@ static jl_ptls_t stkerror_ptls; static int have_backtrace_fiber; static void JL_NORETURN start_backtrace_fiber(void) { + // print the warning (this mysteriously needs a lot of stack for the WriteFile syscall) + stack_overflow_warning(); // collect the backtrace stkerror_ptls->bt_size = rec_backtrace_ctx(stkerror_ptls->bt_data, JL_MAX_BT_SIZE, stkerror_ctx, @@ -244,7 +246,6 @@ LONG WINAPI jl_exception_handler(struct _EXCEPTION_POINTERS *ExceptionInfo) case EXCEPTION_STACK_OVERFLOW: if (ct->eh != NULL) { ptls->needs_resetstkoflw = 1; - stack_overflow_warning(); jl_throw_in_ctx(ct, jl_stackovf_exception, ExceptionInfo->ContextRecord); return EXCEPTION_CONTINUE_EXECUTION; }