crt: crt_handler: Enable __mingw_SEH_error_handler code for all builds Improve __mingw_SEH_error_handler() to include also handling of __SEH__ and non-_WIN64 code from _gnu_exception_handler() function. With this change __mingw_SEH_error_handler() and _gnu_exception_handler() would provide same functionality. Signed-off-by: LIU Hao <lh_mouse@126.com>
diff --git a/mingw-w64-crt/crt/crt_handler.c b/mingw-w64-crt/crt/crt_handler.c index 190b900..e0e7764 100644 --- a/mingw-w64-crt/crt/crt_handler.c +++ b/mingw-w64-crt/crt/crt_handler.c
@@ -13,6 +13,10 @@ #include <signal.h> #include <stdio.h> +#define GCC_MAGIC (('G' << 16) | ('C' << 8) | 'C' | (1U << 29)) + +EXCEPTION_DISPOSITION __cdecl __mingw_SEH_error_handler(struct _EXCEPTION_RECORD *, void *, struct _CONTEXT *, void *); + #if defined(__x86_64__) && !defined(_MSC_VER) && !defined(__SEH__) #pragma pack(push,1) @@ -29,8 +33,6 @@ PIMAGE_SECTION_HEADER _FindPESectionExec (size_t); PBYTE _GetPEImageBase (void); -EXCEPTION_DISPOSITION __cdecl __mingw_SEH_error_handler(struct _EXCEPTION_RECORD *, void *, struct _CONTEXT *, void *); - #define MAX_PDATA_ENTRIES 32 static RUNTIME_FUNCTION emu_pdata[MAX_PDATA_ENTRIES]; static UNWIND_INFO emu_xdata[MAX_PDATA_ENTRIES]; @@ -73,6 +75,8 @@ return 1; } +#endif + extern void _fpreset (void); EXCEPTION_DISPOSITION __cdecl @@ -88,6 +92,14 @@ if (ExceptionRecord->ExceptionFlags & EXCEPTION_UNWINDING) return ExceptionContinueSearch; +#ifdef __SEH__ + if ((ExceptionRecord->ExceptionCode & 0x20ffffff) == GCC_MAGIC) + { + if ((ExceptionRecord->ExceptionFlags & EXCEPTION_NONCONTINUABLE) == 0) + return ExceptionContinueExecution; + } +#endif + switch (ExceptionRecord->ExceptionCode) { case EXCEPTION_ACCESS_VIOLATION: @@ -151,6 +163,7 @@ action = ExceptionContinueExecution; } break; +#ifdef _WIN64 case EXCEPTION_DATATYPE_MISALIGNMENT: case EXCEPTION_ARRAY_BOUNDS_EXCEEDED: case EXCEPTION_FLT_STACK_CHECK: @@ -159,21 +172,18 @@ /*case EXCEPTION_POSSIBLE_DEADLOCK: */ action = ExceptionContinueExecution; break; +#endif default: break; } return action; } -#endif - LPTOP_LEVEL_EXCEPTION_FILTER __mingw_oldexcpt_handler = NULL; long CALLBACK _gnu_exception_handler (EXCEPTION_POINTERS *exception_data); -#define GCC_MAGIC (('G' << 16) | ('C' << 8) | 'C' | (1U << 29)) - long CALLBACK _gnu_exception_handler (EXCEPTION_POINTERS *exception_data) {