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