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).
mob
Michael Matz 2019-04-15 20:02:45 +02:00
parent 105107124d
commit c16dadbb97
2 changed files with 21 additions and 0 deletions

View File

@ -4,6 +4,7 @@
// _UNICODE for tchar.h, UNICODE for API
#include <tchar.h>
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
@ -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

View File

@ -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);