From 6d15ab07d39ab71ea358e08f5a4a783f5bb19d48 Mon Sep 17 00:00:00 2001 From: Luke Usher Date: Thu, 16 Aug 2018 22:05:11 +0100 Subject: [PATCH] Revert "Remove __try/__catch blocks: Vectored Exceptions made this unnecessary" This reverts commit 1ff481ac0a0a772d0ad9c68259df0211515eacc4. --- src/CxbxKrnl/CxbxKrnl.cpp | 13 ++++++++--- src/CxbxKrnl/EmuKrnlKe.cpp | 33 ++++++++++++++++++--------- src/CxbxKrnl/EmuKrnlPs.cpp | 46 +++++++++++++++++++++++++------------- src/CxbxKrnl/EmuXapi.cpp | 11 +++++++-- 4 files changed, 72 insertions(+), 31 deletions(-) diff --git a/src/CxbxKrnl/CxbxKrnl.cpp b/src/CxbxKrnl/CxbxKrnl.cpp index a00eb3590..fadce290f 100644 --- a/src/CxbxKrnl/CxbxKrnl.cpp +++ b/src/CxbxKrnl/CxbxKrnl.cpp @@ -195,7 +195,14 @@ void SetupPerTitleKeys() void CxbxLaunchXbe(void(*Entry)()) { - Entry(); + __try + { + Entry(); + } + __except (EmuException(GetExceptionInformation())) + { + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Problem with ExceptionFilter"); + } } // Entry point address XOR keys per Xbe type (Retail, Debug or Chihiro) : @@ -686,8 +693,8 @@ bool IsRdtscInstruction(xbaddr addr) // Note : Check second opcode first, as that's most likely to fail fast return (opAddr[1] == 0x90) // NOP && (opAddr[0] == 0xEF) // OUT DX, EAX - // Note : It's not needed to check for g_SkipRdtscPatching, - // as when that's set, the g_RdtscPatches vector will be empty + // Note : It's not needed to check for g_SkipRdtscPatching, + // as when that's set, the g_RdtscPatches vector will be empty // anyway, failing this lookup : && (std::find(g_RdtscPatches.begin(), g_RdtscPatches.end(), addr) != g_RdtscPatches.end()); } diff --git a/src/CxbxKrnl/EmuKrnlKe.cpp b/src/CxbxKrnl/EmuKrnlKe.cpp index 1c6d38528..c4769aa52 100644 --- a/src/CxbxKrnl/EmuKrnlKe.cpp +++ b/src/CxbxKrnl/EmuKrnlKe.cpp @@ -161,12 +161,18 @@ DWORD ExecuteDpcQueue() // Set DpcRoutineActive to support KeIsExecutingDpc: KeGetCurrentPrcb()->DpcRoutineActive = TRUE; // Experimental DbgPrintf(LOG_PREFIX, "Global DpcQueue, calling DPC at 0x%.8X\n", pkdpc->DeferredRoutine); - // Call the Deferred Procedure : - pkdpc->DeferredRoutine( - pkdpc, - pkdpc->DeferredContext, - pkdpc->SystemArgument1, - pkdpc->SystemArgument2); + __try { + // Call the Deferred Procedure : + pkdpc->DeferredRoutine( + pkdpc, + pkdpc->DeferredContext, + pkdpc->SystemArgument1, + pkdpc->SystemArgument2); + } __except (EmuException(GetExceptionInformation())) + { + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Problem with ExceptionFilter!"); + } + KeGetCurrentPrcb()->DpcRoutineActive = FALSE; // Experimental } @@ -200,11 +206,16 @@ DWORD ExecuteDpcQueue() DbgPrintf(LOG_PREFIX, "Global TimerQueue, calling DPC at 0x%.8X\n", pkdpc->DeferredRoutine); - pkdpc->DeferredRoutine( - pkdpc, - pkdpc->DeferredContext, - pkdpc->SystemArgument1, - pkdpc->SystemArgument2); + __try { + pkdpc->DeferredRoutine( + pkdpc, + pkdpc->DeferredContext, + pkdpc->SystemArgument1, + pkdpc->SystemArgument2); + } __except (EmuException(GetExceptionInformation())) + { + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Problem with ExceptionFilter!"); + } } } diff --git a/src/CxbxKrnl/EmuKrnlPs.cpp b/src/CxbxKrnl/EmuKrnlPs.cpp index b210091a9..77d616d9b 100644 --- a/src/CxbxKrnl/EmuKrnlPs.cpp +++ b/src/CxbxKrnl/EmuKrnlPs.cpp @@ -167,21 +167,28 @@ static unsigned int WINAPI PCSTProxy } // use the special calling convention - // Given the non-standard calling convention (requiring - // the first argument in ebp+4) we need the below __asm. - // - // Otherwise, this call would have looked something like this : - // ((xboxkrnl::PKSYSTEM_ROUTINE)SystemRoutine)( - // (xboxkrnl::PKSTART_ROUTINE)StartRoutine, - // StartContext); - __asm + __try { - mov esi, SystemRoutine - push StartContext - push StartRoutine - push offset callComplete - lea ebp, [esp - 4] - jmp near esi + // Given the non-standard calling convention (requiring + // the first argument in ebp+4) we need the below __asm. + // + // Otherwise, this call would have looked something like this : + // ((xboxkrnl::PKSYSTEM_ROUTINE)SystemRoutine)( + // (xboxkrnl::PKSTART_ROUTINE)StartRoutine, + // StartContext); + __asm + { + mov esi, SystemRoutine + push StartContext + push StartRoutine + push offset callComplete + lea ebp, [esp - 4] + jmp near esi + } + } + __except (EmuException(GetExceptionInformation())) + { + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Problem with ExceptionFilter!"); } callComplete: @@ -200,7 +207,16 @@ void PspSystemThreadStartup IN PVOID StartContext ) { - (StartRoutine)(StartContext); + __try + { + (StartRoutine)(StartContext); + } + __except (EmuException(GetExceptionInformation())) + // TODO : Call PspUnhandledExceptionInSystemThread(GetExceptionInformation()) + { + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Problem with ExceptionFilter!"); // TODO : Disable? + } + xboxkrnl::PsTerminateSystemThread(STATUS_SUCCESS); } diff --git a/src/CxbxKrnl/EmuXapi.cpp b/src/CxbxKrnl/EmuXapi.cpp index 0b3705019..0e8a1c40b 100644 --- a/src/CxbxKrnl/EmuXapi.cpp +++ b/src/CxbxKrnl/EmuXapi.cpp @@ -1424,8 +1424,15 @@ typedef struct { void WINAPI EmuFiberStartup(fiber_context_t* context) { - LPFIBER_START_ROUTINE pfStartRoutine = (LPFIBER_START_ROUTINE)context->lpStartRoutine; - pfStartRoutine(context->lpParameter); + __try + { + LPFIBER_START_ROUTINE pfStartRoutine = (LPFIBER_START_ROUTINE)context->lpStartRoutine; + pfStartRoutine(context->lpParameter); + } + __except (EmuException(GetExceptionInformation())) + { + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Problem with ExceptionFilter"); + } } // ******************************************************************