History

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).

Michael Matz committed 7 years ago

Commit c16dadb1 parent 10510712 files · +21 −0Browse files

Unified · Split

2 files
  1. win32/lib/crt1.c +11 −0
  2. win32/lib/wincrt1.c +10 −0
win32/lib/crt1.c+11−0
@@ -4,6 +4,7 @@ · 3 unmodified lines
44 // _UNICODE for tchar.h, UNICODE for API
55 #include <tchar.h>
66
7+#include <windows.h>
78 #include <stdio.h>
89 #include <stdlib.h>
910
@@ -37,9 +38,19 @@ extern int _tmain(int argc, _TCHAR * argv[], _TCHAR * env[]); · 27 unmodified lines
3738 /* Allow command-line globbing with "int _dowildcard = 1;" in the user source */
3839 int _dowildcard;
3940
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+
4048 void _tstart(void)
4149 {
4250 __TRY__
51+#ifdef __x86_64__
52+ SetUnhandledExceptionFilter(catch_sig);
53+#endif
4354 _startupinfo start_info = {0};
4455
4556 // Sets the current application type
win32/lib/wincrt1.c+10−0
@@ -26,6 +26,13 @@ int APIENTRY wWinMain(HINSTANCE, HINSTANCE, LPWSTR, int); · 25 unmodified lines
2626 typedef struct { int newmode; } _startupinfo;
2727 int __cdecl __tgetmainargs(int *pargc, _TCHAR ***pargv, _TCHAR ***penv, int globb, _startupinfo*);
2828
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+
2936 static int go_winmain(TCHAR *arg1)
3037 {
3138 STARTUPINFO si;
@@ -54,6 +61,9 @@ static int go_winmain(TCHAR *arg1) · 22 unmodified lines
5461 int _twinstart(void)
5562 {
5663 __TRY__
64+#ifdef __x86_64__
65+ SetUnhandledExceptionFilter(catch_sig);
66+#endif
5767 _startupinfo start_info_con = {0};
5868 __set_app_type(__GUI_APP);
5969 __tgetmainargs(&__argc, &__targv, &_tenviron, 0, &start_info_con);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t