From 310648fb88cdbe8d8bfc34801d0ba1d60df310f2 Mon Sep 17 00:00:00 2001 From: tellowkrinkle Date: Wed, 1 Jul 2020 21:14:37 -0500 Subject: [PATCH] recompiler: Fix exception handling on WIN64 Use VEH instead of SEH on WIN64, as SEH needs us to register all our JIT functions for it --- common/include/Utilities/PageFaultSource.h | 2 +- common/src/Utilities/Windows/WinHostSys.cpp | 8 +++++--- pcsx2/System.h | 3 ++- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/common/include/Utilities/PageFaultSource.h b/common/include/Utilities/PageFaultSource.h index 459fc2be67..62009bd4c5 100644 --- a/common/include/Utilities/PageFaultSource.h +++ b/common/include/Utilities/PageFaultSource.h @@ -298,7 +298,7 @@ protected: #elif defined(_WIN32) struct _EXCEPTION_POINTERS; -extern int SysPageFaultExceptionFilter(struct _EXCEPTION_POINTERS *eps); +extern long __stdcall SysPageFaultExceptionFilter(struct _EXCEPTION_POINTERS *eps); #define PCSX2_PAGEFAULT_PROTECT __try #define PCSX2_PAGEFAULT_EXCEPT \ diff --git a/common/src/Utilities/Windows/WinHostSys.cpp b/common/src/Utilities/Windows/WinHostSys.cpp index 6b6059e90b..3121f24a23 100644 --- a/common/src/Utilities/Windows/WinHostSys.cpp +++ b/common/src/Utilities/Windows/WinHostSys.cpp @@ -19,7 +19,7 @@ #include -static int DoSysPageFaultExceptionFilter(EXCEPTION_POINTERS *eps) +static long DoSysPageFaultExceptionFilter(EXCEPTION_POINTERS *eps) { if (eps->ExceptionRecord->ExceptionCode != EXCEPTION_ACCESS_VIOLATION) return EXCEPTION_CONTINUE_SEARCH; @@ -32,7 +32,7 @@ static int DoSysPageFaultExceptionFilter(EXCEPTION_POINTERS *eps) return Source_PageFault->WasHandled() ? EXCEPTION_CONTINUE_EXECUTION : EXCEPTION_CONTINUE_SEARCH; } -int SysPageFaultExceptionFilter(EXCEPTION_POINTERS *eps) +long __stdcall SysPageFaultExceptionFilter(EXCEPTION_POINTERS *eps) { // Prevent recursive exception filtering by catching the exception from the filter here. // In the event that the filter causes an access violation (happened during shutdown @@ -49,7 +49,9 @@ int SysPageFaultExceptionFilter(EXCEPTION_POINTERS *eps) void _platform_InstallSignalHandler() { - // NOP on Win32 systems -- we use __try{} __except{} instead. +#ifdef _WIN64 // We don't handle SEH properly on Win64 so use a vectored exception handler instead + AddVectoredExceptionHandler(true, SysPageFaultExceptionFilter); +#endif } diff --git a/pcsx2/System.h b/pcsx2/System.h index e1f94c7cfc..eed80618a1 100644 --- a/pcsx2/System.h +++ b/pcsx2/System.h @@ -175,12 +175,13 @@ extern SysMainMemory& GetVmMemory(); // This should be available on Windows, via Microsoft or Intel compilers (I'm pretty sure Intel // supports native SEH model). GNUC in Windows, or any compiler in a non-windows platform, will // need to use setjmp/longjmp instead to exit recompiled code. +// In addition, we don't currently set up SEH properly on Windows x64 so disable it there too // //#define PCSX2_SEH 0 // use this to force disable SEH on win32, to test setjmp functionality. #ifndef PCSX2_SEH -# if defined(_WIN32) && !defined(__GNUC__) +# if defined(_WIN32) && !defined(__GNUC__) && !defined(_WIN64) # define PCSX2_SEH 1 # else # define PCSX2_SEH 0