|
HydraHook
Direct3D and Core Audio hooking library for Windows
|
Crash handler implementation – SEH, minidump, CRT handlers. More...
#include <Windows.h>#include <DbgHelp.h>#include <eh.h>#include <signal.h>#include <cstdio>#include <ctime>#include <mutex>#include <atomic>#include <vector>#include "HydraHook/Engine/HydraHookCore.h"#include "HydraHook/Engine/HydraHookDirect3D9.h"#include "HydraHook/Engine/HydraHookDirect3D10.h"#include "HydraHook/Engine/HydraHookDirect3D11.h"#include "HydraHook/Engine/HydraHookDirect3D12.h"#include "HydraHook/Engine/HydraHookCoreAudio.h"#include "Engine.h"#include "CrashHandler.h"#include "Exceptions.hpp"#include "Utils/Global.h"#include <spdlog/spdlog.h>Go to the source code of this file.
Classes | |
| struct | CrashConfigSnapshot |
| struct | CrashRegistration |
Macros | |
| #define | WIN32_LEAN_AND_MEAN |
Functions | |
| static void | ReapDeferredSnapshots () |
| static void | RetireSnapshot (CrashConfigSnapshot *retired) |
| static const char * | ExceptionCodeToString (DWORD code) |
| static void | GetModuleFromAddress (PVOID address, char *moduleName, size_t nameLen, DWORD_PTR *offset) |
| static MINIDUMP_TYPE | GetMiniDumpTypeFlags (HYDRAHOOK_DUMP_TYPE type) |
| static void | AppendDumpDirectory (std::vector< std::string > &dirs, std::string path) |
| static std::vector< std::string > | DumpDirectoryCandidates (const CrashConfigSnapshot *snap) |
| static std::string | GetProcessBaseName () |
| static void | WriteCrashDump (EXCEPTION_POINTERS *exInfo, const char *trigger) |
| static LONG | HydraHookUnhandledExceptionFilter (EXCEPTION_POINTERS *exInfo) |
| static void | HydraHookTerminateHandler () |
| static void | HydraHookInvalidParameterHandler (const wchar_t *expression, const wchar_t *function, const wchar_t *file, unsigned int line, uintptr_t pReserved) |
| static void | HydraHookPurecallHandler () |
| static void | HydraHookSehTranslator (unsigned int code, EXCEPTION_POINTERS *info) |
| static CrashConfigSnapshot * | MakeSnapshot (PHYDRAHOOK_ENGINE engine) |
| bool | HydraHookCrashHandlerInstall (PHYDRAHOOK_ENGINE engine) |
| Installs global crash handlers (ref-counted) for the given engine. | |
| void | HydraHookCrashHandlerUninstall (PHYDRAHOOK_ENGINE engine) |
| Decrements the crash handler reference count. | |
| void | HydraHookCrashHandlerInstallThreadSEH () |
| Installs the per-thread SEH-to-C++ translator on the calling thread. | |
| PHYDRAHOOK_ENGINE | HydraHookCrashHandlerActiveOwnerForTest () |
| Test accessor. Returns the engine that owns the published crash snapshot. | |
| bool | HydraHookCrashHandlerReferencesEngine (PHYDRAHOOK_ENGINE engine) |
| True when a published or deferred snapshot still names this engine. Destroy must not free the engine while this is true. | |
Variables | |
| static LPTOP_LEVEL_EXCEPTION_FILTER | s_prevUnhandledFilter = nullptr |
| static std::terminate_handler | s_prevTerminateHandler = nullptr |
| static _invalid_parameter_handler | s_prevInvalidParamHandler = nullptr |
| static _purecall_handler | s_prevPurecallHandler = nullptr |
| static std::atomic< int > | s_refCount { 0 } |
| static std::mutex | s_installMutex |
| static std::atomic< CrashConfigSnapshot * > | s_snapshot { nullptr } |
| static std::atomic< int > | s_dumpInFlight { 0 } |
| static std::vector< CrashRegistration > | s_registrations |
| static std::vector< CrashConfigSnapshot * > | s_deferredSnapshots |
Crash handler implementation – SEH, minidump, CRT handlers.
Definition in file CrashHandler.cpp.
| #define WIN32_LEAN_AND_MEAN |
Definition at line 9 of file CrashHandler.cpp.
|
static |
Definition at line 180 of file CrashHandler.cpp.
References AppendDumpDirectory().
Referenced by AppendDumpDirectory(), and DumpDirectoryCandidates().
|
static |
Definition at line 194 of file CrashHandler.cpp.
References AppendDumpDirectory(), DumpDirectoryCandidates(), CrashConfigSnapshot::DumpDirectoryPath, HydraHook::Core::Util::expand_environment_variables(), HydraHook::Core::Util::get_module_directory(), HydraHook::Core::Util::get_process_directory(), and CrashConfigSnapshot::HostInstance.
Referenced by DumpDirectoryCandidates(), and WriteCrashDump().
|
static |
Definition at line 96 of file CrashHandler.cpp.
References ExceptionCodeToString().
Referenced by ExceptionCodeToString(), and WriteCrashDump().
|
static |
Definition at line 154 of file CrashHandler.cpp.
References GetMiniDumpTypeFlags(), HydraHookDumpTypeFull, HydraHookDumpTypeMinimal, and HydraHookDumpTypeNormal.
Referenced by GetMiniDumpTypeFlags(), and WriteCrashDump().
|
static |
Definition at line 133 of file CrashHandler.cpp.
References GetModuleFromAddress().
Referenced by GetModuleFromAddress(), and WriteCrashDump().
|
static |
Definition at line 217 of file CrashHandler.cpp.
References GetProcessBaseName().
Referenced by GetProcessBaseName(), and WriteCrashDump().
| PHYDRAHOOK_ENGINE HydraHookCrashHandlerActiveOwnerForTest | ( | ) |
Test accessor. Returns the engine that owns the published crash snapshot.
Definition at line 600 of file CrashHandler.cpp.
References HydraHookCrashHandlerActiveOwnerForTest(), CrashConfigSnapshot::OwnerEngine, s_installMutex, and s_snapshot.
Referenced by HydraHookCrashHandlerActiveOwnerForTest().
| bool HydraHookCrashHandlerInstall | ( | PHYDRAHOOK_ENGINE | engine | ) |
Installs global crash handlers (ref-counted) for the given engine.
On first call: registers SetUnhandledExceptionFilter, set_terminate, _set_invalid_parameter_handler, and _set_purecall_handler. Subsequent calls increment the reference count without re-installing.
| engine | Engine whose CrashHandler config controls dump output. |
engine is null or the snapshot could not be registered. Definition at line 490 of file CrashHandler.cpp.
References HydraHookCrashHandlerInstall(), HydraHookInvalidParameterHandler(), HydraHookPurecallHandler(), HydraHookTerminateHandler(), HydraHookUnhandledExceptionFilter(), MakeSnapshot(), ReapDeferredSnapshots(), RetireSnapshot(), s_installMutex, s_prevInvalidParamHandler, s_prevPurecallHandler, s_prevTerminateHandler, s_prevUnhandledFilter, s_refCount, s_registrations, and s_snapshot.
Referenced by HydraHookCrashHandlerInstall(), and HydraHookEngineCreate().
| void HydraHookCrashHandlerInstallThreadSEH | ( | ) |
Installs the per-thread SEH-to-C++ translator on the calling thread.
Must be called from the engine worker thread. Bridges Win32 structured exceptions into HydraHook::Core::Exceptions::SehException so that existing try/catch blocks can catch hardware faults.
Definition at line 595 of file CrashHandler.cpp.
References HydraHookCrashHandlerInstallThreadSEH(), and HydraHookSehTranslator().
Referenced by HydraHookCrashHandlerInstallThreadSEH(), and HydraHookMainThread().
| bool HydraHookCrashHandlerReferencesEngine | ( | PHYDRAHOOK_ENGINE | engine | ) |
True when a published or deferred snapshot still names this engine. Destroy must not free the engine while this is true.
Definition at line 607 of file CrashHandler.cpp.
References HydraHookCrashHandlerReferencesEngine(), CrashConfigSnapshot::OwnerEngine, ReapDeferredSnapshots(), s_deferredSnapshots, s_installMutex, and s_snapshot.
Referenced by DestroyEngine(), HydraHookCrashHandlerReferencesEngine(), and HydraHookEngineCreate().
| void HydraHookCrashHandlerUninstall | ( | PHYDRAHOOK_ENGINE | engine | ) |
Decrements the crash handler reference count.
If the uninstalling engine owns the active crash config snapshot, the next surviving registration is published. The previous snapshot is deleted only after in-flight dump writers have finished. When the last engine uninstalls, restores all previous handlers.
| engine | The engine that is being destroyed. |
Definition at line 530 of file CrashHandler.cpp.
References HydraHookCrashHandlerUninstall(), ReapDeferredSnapshots(), RetireSnapshot(), s_installMutex, s_prevInvalidParamHandler, s_prevPurecallHandler, s_prevTerminateHandler, s_prevUnhandledFilter, s_refCount, s_registrations, and s_snapshot.
Referenced by DestroyEngine(), HydraHookCrashHandlerUninstall(), and HydraHookEngineCreate().
|
static |
Definition at line 427 of file CrashHandler.cpp.
References HydraHookInvalidParameterHandler(), s_prevInvalidParamHandler, and WriteCrashDump().
Referenced by HydraHookCrashHandlerInstall(), and HydraHookInvalidParameterHandler().
|
static |
Definition at line 449 of file CrashHandler.cpp.
References HydraHookPurecallHandler(), s_prevPurecallHandler, and WriteCrashDump().
Referenced by HydraHookCrashHandlerInstall(), and HydraHookPurecallHandler().
|
static |
Definition at line 466 of file CrashHandler.cpp.
References HydraHookSehTranslator().
Referenced by HydraHookCrashHandlerInstallThreadSEH(), and HydraHookSehTranslator().
|
static |
Definition at line 408 of file CrashHandler.cpp.
References HydraHookTerminateHandler(), s_prevTerminateHandler, and WriteCrashDump().
Referenced by HydraHookCrashHandlerInstall(), and HydraHookTerminateHandler().
|
static |
Definition at line 395 of file CrashHandler.cpp.
References HydraHookUnhandledExceptionFilter(), s_prevUnhandledFilter, and WriteCrashDump().
Referenced by HydraHookCrashHandlerInstall(), and HydraHookUnhandledExceptionFilter().
|
static |
Definition at line 475 of file CrashHandler.cpp.
References CrashConfigSnapshot::DumpDirectoryPath, and MakeSnapshot().
Referenced by HydraHookCrashHandlerInstall(), and MakeSnapshot().
|
static |
Definition at line 70 of file CrashHandler.cpp.
References ReapDeferredSnapshots(), s_deferredSnapshots, and s_dumpInFlight.
Referenced by HydraHookCrashHandlerInstall(), HydraHookCrashHandlerReferencesEngine(), HydraHookCrashHandlerUninstall(), and ReapDeferredSnapshots().
|
static |
Definition at line 80 of file CrashHandler.cpp.
References RetireSnapshot(), s_deferredSnapshots, and s_dumpInFlight.
Referenced by HydraHookCrashHandlerInstall(), HydraHookCrashHandlerUninstall(), and RetireSnapshot().
|
static |
Definition at line 234 of file CrashHandler.cpp.
References DumpDirectoryCandidates(), CrashConfigSnapshot::DumpType, CrashConfigSnapshot::EvtCrashHandler, ExceptionCodeToString(), GetMiniDumpTypeFlags(), GetModuleFromAddress(), GetProcessBaseName(), HydraHookDumpTypeNormal, CrashConfigSnapshot::OwnerEngine, s_dumpInFlight, s_snapshot, and WriteCrashDump().
Referenced by HydraHookInvalidParameterHandler(), HydraHookPurecallHandler(), HydraHookTerminateHandler(), HydraHookUnhandledExceptionFilter(), and WriteCrashDump().
|
static |
Definition at line 68 of file CrashHandler.cpp.
Referenced by HydraHookCrashHandlerReferencesEngine(), ReapDeferredSnapshots(), and RetireSnapshot().
|
static |
Definition at line 59 of file CrashHandler.cpp.
Referenced by ReapDeferredSnapshots(), RetireSnapshot(), and WriteCrashDump().
|
static |
Definition at line 45 of file CrashHandler.cpp.
Referenced by HydraHookCrashHandlerActiveOwnerForTest(), HydraHookCrashHandlerInstall(), HydraHookCrashHandlerReferencesEngine(), and HydraHookCrashHandlerUninstall().
|
static |
Definition at line 40 of file CrashHandler.cpp.
Referenced by HydraHookCrashHandlerInstall(), HydraHookCrashHandlerUninstall(), and HydraHookInvalidParameterHandler().
|
static |
Definition at line 41 of file CrashHandler.cpp.
Referenced by HydraHookCrashHandlerInstall(), HydraHookCrashHandlerUninstall(), and HydraHookPurecallHandler().
|
static |
Definition at line 39 of file CrashHandler.cpp.
Referenced by HydraHookCrashHandlerInstall(), HydraHookCrashHandlerUninstall(), and HydraHookTerminateHandler().
|
static |
Definition at line 38 of file CrashHandler.cpp.
Referenced by HydraHookCrashHandlerInstall(), HydraHookCrashHandlerUninstall(), and HydraHookUnhandledExceptionFilter().
|
static |
Definition at line 44 of file CrashHandler.cpp.
Referenced by HydraHookCrashHandlerInstall(), and HydraHookCrashHandlerUninstall().
|
static |
Definition at line 67 of file CrashHandler.cpp.
Referenced by HydraHookCrashHandlerInstall(), and HydraHookCrashHandlerUninstall().
|
static |
Definition at line 58 of file CrashHandler.cpp.
Referenced by HydraHookCrashHandlerActiveOwnerForTest(), HydraHookCrashHandlerInstall(), HydraHookCrashHandlerReferencesEngine(), HydraHookCrashHandlerUninstall(), and WriteCrashDump().