SEH handler for C signal processing is already registered for non-i386 builds via .seh_handler asm directive. GNU asm for i386 does not provide this support and SEH handler has to be registered and unregistered dynamically at runtime. --- mingw-w64-crt/crt/crtexe.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+)
diff --git a/mingw-w64-crt/crt/crtexe.c b/mingw-w64-crt/crt/crtexe.c index f23c5f0edc95..dc6e656cb6fa 100644 --- a/mingw-w64-crt/crt/crtexe.c +++ b/mingw-w64-crt/crt/crtexe.c @@ -55,6 +55,7 @@ extern LPTOP_LEVEL_EXCEPTION_FILTER __mingw_oldexcpt_handler; extern void _pei386_runtime_relocator (void); long CALLBACK _gnu_exception_handler (EXCEPTION_POINTERS * exception_data); +EXCEPTION_DISPOSITION __cdecl __mingw_SEH_error_handler (struct _EXCEPTION_RECORD *, void *, struct _CONTEXT *, void *); static int duplicate_ppstrings (int ac, _TCHAR ***av); extern int _MINGW_INSTALL_DEBUG_MATHERR; @@ -84,6 +85,13 @@ int WinMainCRTStartup (void); __attribute__((used)) /* required due to GNU LD bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30300 */ int WinMainCRTStartup (void) { +#if defined(__i386__) + EXCEPTION_REGISTRATION_RECORD exception_record = { + .Next = (EXCEPTION_REGISTRATION_RECORD *)__readfsdword (0), + .Handler = __mingw_SEH_error_handler, + }; + __writefsdword (0, (DWORD)&exception_record); /* register SEH handler */ +#endif int ret = 255; #ifdef SEH_INLINE_ASM asm ("\t.l_startw:\n"); @@ -102,6 +110,9 @@ int WinMainCRTStartup (void) "\t.long 1\n" "\t.rva .l_startw, .l_endw, _gnu_exception_handler ,.l_endw\n" "\t.text"); +#endif +#if defined(__i386__) + __writefsdword (0, (DWORD)exception_record.Next); /* unregister SEH handler */ #endif return ret; } @@ -115,6 +126,13 @@ int __mingw_init_ehandler (void); __attribute__((used)) /* required due to GNU LD bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30300 */ int mainCRTStartup (void) { +#if defined(__i386__) + EXCEPTION_REGISTRATION_RECORD exception_record = { + .Next = (EXCEPTION_REGISTRATION_RECORD *)__readfsdword (0), + .Handler = __mingw_SEH_error_handler, + }; + __writefsdword (0, (DWORD)&exception_record); /* register SEH handler */ +#endif int ret = 255; #ifdef SEH_INLINE_ASM asm ("\t.l_start:\n"); @@ -133,6 +151,9 @@ int mainCRTStartup (void) "\t.long 1\n" "\t.rva .l_start, .l_end, _gnu_exception_handler ,.l_end\n" "\t.text"); +#endif +#if defined(__i386__) + __writefsdword (0, (DWORD)exception_record.Next); /* unregister SEH handler */ #endif return ret; } -- 2.20.1 _______________________________________________ Mingw-w64-public mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/mingw-w64-public
