From c16dadbb975d10e8c530b2c7cfe476d50ae12bac Mon Sep 17 00:00:00 2001 From: Michael Matz Date: Mon, 15 Apr 2019 20:02:45 +0200 Subject: [PATCH] win64: make signal handlers work somewhat we can register a top-level exception filter which does nothing else than call into _XcptFilter (provided by the default C runtime environment) and signal handlers for the few POSIX signals that Windows can handle start working (that includes e.g. SEGV). --- win32/lib/crt1.c | 11 +++++++++++ win32/lib/wincrt1.c | 10 ++++++++++ 2 files changed, 21 insertions(+) diff --git a/win32/lib/crt1.c b/win32/lib/crt1.c index 0e04fc01..e0ec5d59 100644 --- a/win32/lib/crt1.c +++ b/win32/lib/crt1.c @@ -4,6 +4,7 @@ // _UNICODE for tchar.h, UNICODE for API #include +#include #include #include @@ -37,9 +38,19 @@ extern int _tmain(int argc, _TCHAR * argv[], _TCHAR * env[]); /* Allow command-line globbing with "int _dowildcard = 1;" in the user source */ int _dowildcard; +#ifdef __x86_64__ +static LONG WINAPI catch_sig(EXCEPTION_POINTERS *ex) +{ + return _XcptFilter(ex->ExceptionRecord->ExceptionCode, ex); +} +#endif + void _tstart(void) { __TRY__ +#ifdef __x86_64__ + SetUnhandledExceptionFilter(catch_sig); +#endif _startupinfo start_info = {0}; // Sets the current application type diff --git a/win32/lib/wincrt1.c b/win32/lib/wincrt1.c index ce3a63f1..bad3d957 100644 --- a/win32/lib/wincrt1.c +++ b/win32/lib/wincrt1.c @@ -26,6 +26,13 @@ int APIENTRY wWinMain(HINSTANCE, HINSTANCE, LPWSTR, int); typedef struct { int newmode; } _startupinfo; int __cdecl __tgetmainargs(int *pargc, _TCHAR ***pargv, _TCHAR ***penv, int globb, _startupinfo*); +#ifdef __x86_64__ +static LONG WINAPI catch_sig(EXCEPTION_POINTERS *ex) +{ + return _XcptFilter(ex->ExceptionRecord->ExceptionCode, ex); +} +#endif + static int go_winmain(TCHAR *arg1) { STARTUPINFO si; @@ -54,6 +61,9 @@ static int go_winmain(TCHAR *arg1) int _twinstart(void) { __TRY__ +#ifdef __x86_64__ + SetUnhandledExceptionFilter(catch_sig); +#endif _startupinfo start_info_con = {0}; __set_app_type(__GUI_APP); __tgetmainargs(&__argc, &__targv, &_tenviron, 0, &start_info_con);