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).
Unified · Split
| @@ -4,6 +4,7 @@ · 3 unmodified lines | ||
| 4 | 4 | // _UNICODE for tchar.h, UNICODE for API |
| 5 | 5 | #include <tchar.h> |
| 6 | 6 | |
| 7 | +#include <windows.h> | |
| 7 | 8 | #include <stdio.h> |
| 8 | 9 | #include <stdlib.h> |
| 9 | 10 | |
| @@ -37,9 +38,19 @@ extern int _tmain(int argc, _TCHAR * argv[], _TCHAR * env[]); · 27 unmodified lines | ||
| 37 | 38 | /* Allow command-line globbing with "int _dowildcard = 1;" in the user source */ |
| 38 | 39 | int _dowildcard; |
| 39 | 40 | |
| 41 | +#ifdef __x86_64__ | |
| 42 | +static LONG WINAPI catch_sig(EXCEPTION_POINTERS *ex) | |
| 43 | +{ | |
| 44 | + return _XcptFilter(ex->ExceptionRecord->ExceptionCode, ex); | |
| 45 | +} | |
| 46 | +#endif | |
| 47 | + | |
| 40 | 48 | void _tstart(void) |
| 41 | 49 | { |
| 42 | 50 | __TRY__ |
| 51 | +#ifdef __x86_64__ | |
| 52 | + SetUnhandledExceptionFilter(catch_sig); | |
| 53 | +#endif | |
| 43 | 54 | _startupinfo start_info = {0}; |
| 44 | 55 | |
| 45 | 56 | // Sets the current application type |
| @@ -26,6 +26,13 @@ int APIENTRY wWinMain(HINSTANCE, HINSTANCE, LPWSTR, int); · 25 unmodified lines | ||
| 26 | 26 | typedef struct { int newmode; } _startupinfo; |
| 27 | 27 | int __cdecl __tgetmainargs(int *pargc, _TCHAR ***pargv, _TCHAR ***penv, int globb, _startupinfo*); |
| 28 | 28 | |
| 29 | +#ifdef __x86_64__ | |
| 30 | +static LONG WINAPI catch_sig(EXCEPTION_POINTERS *ex) | |
| 31 | +{ | |
| 32 | + return _XcptFilter(ex->ExceptionRecord->ExceptionCode, ex); | |
| 33 | +} | |
| 34 | +#endif | |
| 35 | + | |
| 29 | 36 | static int go_winmain(TCHAR *arg1) |
| 30 | 37 | { |
| 31 | 38 | STARTUPINFO si; |
| @@ -54,6 +61,9 @@ static int go_winmain(TCHAR *arg1) · 22 unmodified lines | ||
| 54 | 61 | int _twinstart(void) |
| 55 | 62 | { |
| 56 | 63 | __TRY__ |
| 64 | +#ifdef __x86_64__ | |
| 65 | + SetUnhandledExceptionFilter(catch_sig); | |
| 66 | +#endif | |
| 57 | 67 | _startupinfo start_info_con = {0}; |
| 58 | 68 | __set_app_type(__GUI_APP); |
| 59 | 69 | __tgetmainargs(&__argc, &__targv, &_tenviron, 0, &start_info_con); |