ThrowException(exceptionCode, ap, msg);
}
-SpmiException::SpmiException(PEXCEPTION_POINTERS exp) : exCode(exp->ExceptionRecord->ExceptionCode)
-{
- exMessage =
- (exp->ExceptionRecord->NumberParameters != 1) ? nullptr : (char*)exp->ExceptionRecord->ExceptionInformation[0];
-}
-
-SpmiException::SpmiException(DWORD exceptionCode, char* exceptionMessage)
- : exCode(exceptionCode), exMessage(exceptionMessage)
+SpmiException::SpmiException(FilterSuperPMIExceptionsParam_CaptureException* e)
+ : exCode(e->exceptionCode), exMessage(e->exceptionMessage)
{
}
if (exMessage != nullptr)
{
LogError("Exception thrown: %s", exMessage);
- delete[] exMessage;
- exMessage = nullptr;
}
else
{
LogError("Unexpected exception was thrown.");
}
+
+ DeleteMessage();
}
void SpmiException::DeleteMessage()
// This filter function captures the exception pointers and continues searching.
LONG FilterSuperPMIExceptions_CaptureExceptionAndContinue(PEXCEPTION_POINTERS pExceptionPointers, LPVOID lpvParam)
{
- FilterSuperPMIExceptionsParam_CaptureException* pSPMIEParam =
- (FilterSuperPMIExceptionsParam_CaptureException*)lpvParam;
- pSPMIEParam->exceptionPointers = *pExceptionPointers; // Capture the exception pointers for use later
- pSPMIEParam->exceptionCode = pSPMIEParam->exceptionPointers.ExceptionRecord->ExceptionCode;
+ FilterSuperPMIExceptionsParam_CaptureException* pSPMIEParam = (FilterSuperPMIExceptionsParam_CaptureException*)lpvParam;
+ pSPMIEParam->Initialize(pExceptionPointers);
return EXCEPTION_CONTINUE_SEARCH;
}
LONG FilterSuperPMIExceptions_CaptureExceptionAndStop(PEXCEPTION_POINTERS pExceptionPointers, LPVOID lpvParam)
{
- FilterSuperPMIExceptionsParam_CaptureException* pSPMIEParam =
- (FilterSuperPMIExceptionsParam_CaptureException*)lpvParam;
- pSPMIEParam->exceptionPointers = *pExceptionPointers; // Capture the exception pointers for use later
- pSPMIEParam->exceptionCode = pSPMIEParam->exceptionPointers.ExceptionRecord->ExceptionCode;
+ FilterSuperPMIExceptionsParam_CaptureException* pSPMIEParam = (FilterSuperPMIExceptionsParam_CaptureException*)lpvParam;
+ pSPMIEParam->Initialize(pExceptionPointers);
return EXCEPTION_EXECUTE_HANDLER;
}
#define AssertMsg(expr, msg, ...) AssertCodeMsg(expr, EXCEPTIONCODE_ASSERT, msg, ##__VA_ARGS__)
#define Assert(expr) AssertCode(expr, EXCEPTIONCODE_ASSERT)
-class SpmiException
-{
-private:
- DWORD exCode;
- char* exMessage;
-
-public:
- SpmiException(PEXCEPTION_POINTERS exp);
- SpmiException(DWORD exceptionCode, char* exceptionMessage);
-#if 0
- ~SpmiException();
-#endif
-
- char* GetExceptionMessage();
- DWORD GetCode();
-
- void ShowAndDeleteMessage();
- void DeleteMessage();
-};
-
//
// Functions and types used by PAL_TRY-related macros.
//
struct FilterSuperPMIExceptionsParam_CaptureException
{
- EXCEPTION_POINTERS exceptionPointers;
- DWORD exceptionCode;
+ DWORD exceptionCode;
+ char* exceptionMessage; // 'new' memory passed from ThrowException()
- FilterSuperPMIExceptionsParam_CaptureException() : exceptionCode(0)
+ FilterSuperPMIExceptionsParam_CaptureException()
+ : exceptionCode(0)
+ , exceptionMessage(nullptr)
{
- exceptionPointers.ExceptionRecord = nullptr;
- exceptionPointers.ContextRecord = nullptr;
+ }
+
+ // Note: this is called during an SEH filter; the data pointed to by PEXCEPTION_POINTERS is not valid after
+ // calling this function, so anything we want to safe must be copied.
+ // The exception message string is 'new' memory, allocated in the ThrowException() function.
+ void Initialize(PEXCEPTION_POINTERS pExceptionPointers)
+ {
+ exceptionCode = pExceptionPointers->ExceptionRecord->ExceptionCode;
+ exceptionMessage = (pExceptionPointers->ExceptionRecord->NumberParameters != 1) ? nullptr : (char*)pExceptionPointers->ExceptionRecord->ExceptionInformation[0];
}
};
extern bool RunWithErrorTrap(void (*function)(void*), void* param);
+class SpmiException
+{
+private:
+ DWORD exCode;
+ char* exMessage;
+
+public:
+ SpmiException(FilterSuperPMIExceptionsParam_CaptureException* e);
+#if 0
+ ~SpmiException();
+#endif
+
+ char* GetExceptionMessage();
+ DWORD GetCode();
+
+ void ShowAndDeleteMessage();
+ void DeleteMessage();
+};
+
#endif
}
PAL_EXCEPT_FILTER(FilterSuperPMIExceptions_CaptureExceptionAndStop)
{
- SpmiException e(¶m.exceptionPointers);
+ SpmiException e(¶m);
- if (param.exceptionCode == EXCEPTIONCODE_MC) // Can't check e.GetCode() because of https://github.com/dotnet/runtime/issues/48356
+ if (e.GetCode() == EXCEPTIONCODE_MC)
{
char* message = e.GetExceptionMessage();
LogMissing("Method context %d failed to replay: %s", mcIndex, message);
}
PAL_EXCEPT_FILTER(FilterSuperPMIExceptions_CaptureExceptionAndStop)
{
- SpmiException e(¶m.exceptionPointers);
+ SpmiException e(¶m);
LogError("failed to call jitStartup.");
e.ShowAndDeleteMessage();
}
PAL_EXCEPT_FILTER(FilterSuperPMIExceptions_CaptureExceptionAndStop)
{
- SpmiException e(¶m.exceptionPointers);
+ SpmiException e(¶m);
LogError("main method %d of size %d failed to load and compile correctly.", (*reader)->GetMethodContextIndex(),
(*mc)->methodSize);