r5sdk/r5dev/public/utility/crashhandler.h
Kawe Mazidjatari d2fc2405c3 Add ability to whitelist return addresses from exception filter
Programmer could add and remove whitelisted addresses. If an exception occurs, the system checks the callstack up to 'MAX_IMI_SEARCH' frames (defined in CCrashHandler), and returns true if found (returning early with 'EXCEPTION_CONTINUE_SEARCH' so we use whatever exception handler is set for this particular case), false otherwise.
2022-12-27 23:08:59 +01:00

86 lines
2.5 KiB
C++

#ifndef CRASHHANDLER_H
#define CRASHHANDLER_H
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
class CCrashHandler
{
public:
CCrashHandler();
~CCrashHandler();
//-------------------------------------------------------------------------
// Inlines:
//-------------------------------------------------------------------------
void Lock() const { m_Mutex.lock(); };
void Unlock() const { m_Mutex.unlock(); };
bool GetState() const { return m_bCallState; };
void SetState(bool bState) { m_bCallState = bState; };
//-------------------------------------------------------------------------
// Formatters:
//-------------------------------------------------------------------------
void FormatCrash();
void FormatCallstack();
void FormatRegisters();
void FormatModules();
void FormatSystemInfo();
void FormatBuildInfo();
//-------------------------------------------------------------------------
// Utility:
//-------------------------------------------------------------------------
const char* ExceptionToString() const;
const char* ExceptionToString(DWORD nExceptionCode) const;
void SetExceptionPointers(EXCEPTION_POINTERS* pExceptionPointers) { m_pExceptionPointers = pExceptionPointers; };
void AddWhitelist(void* pWhiteList);
void RemoveWhitelist(void* pWhiteList);
bool HasWhitelist();
void GetCallStack();
void WriteFile();
void CreateMessageProcess();
private:
//-------------------------------------------------------------------------
// Internals:
//-------------------------------------------------------------------------
void FormatExceptionAddress();
void FormatExceptionAddress(LPCSTR pExceptionAddress);
void FormatExceptionCode();
void FormatAPU(const char* pszRegister, DWORD64 nContent);
void FormatFPU(const char* pszRegister, M128A* pxContent);
bool IsPageAccessible() const;
private:
enum
{
MAX_IMI_SEARCH = 7,
NUM_FRAMES_TO_CAPTURE = 128
};
PVOID m_hExceptionHandler;
PVOID m_ppStackTrace[NUM_FRAMES_TO_CAPTURE];
EXCEPTION_POINTERS* m_pExceptionPointers;
WORD m_nCapturedFrames;
string m_svBuffer; // Buffer containing the entire crash log.
string m_svCrashMsgInfo;
uint8_t m_nCrashMsgFlags;
bool m_bCallState; // Set when called to prevent recursive calls.
bool m_bCrashMsgCreated; // Set when crashmsg.exe is created to prevent recursive messages.
std::set<void*> m_WhiteList;
mutable std::mutex m_Mutex;
};
extern CCrashHandler* g_CrashHandler;
#endif // CRASHHANDLER_H