mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-23 03:53:53 +00:00
3bb3f58c73
Well... unless we fail to get the user profile directory.
Also put freeze dumps in a more appropriately-named file.
Discussed in https://gitlab.com/OpenMW/openmw/-/issues/7455
Manual rewrite of c21695c951
As well as that, I found a bug where the crash dump path was being converted from a std::filesystem::path to a utf8-encoded std::string, then passed to the crash catcher, which converted it to a std::filesystem::path implicitly, but using the system eight-bit code page, which wouldn't usually be UTF-8. That's now fixed by passing the function that expects a path a path instead of a string.
75 lines
2.4 KiB
C++
75 lines
2.4 KiB
C++
#ifndef WINDOWS_CRASHCATCHER_HPP
|
|
#define WINDOWS_CRASHCATCHER_HPP
|
|
|
|
#include <filesystem>
|
|
|
|
#include <components/crashcatcher/crashcatcher.hpp>
|
|
#include <components/windows.hpp>
|
|
|
|
namespace Crash
|
|
{
|
|
|
|
// The implementation spawns the current executable as a monitor process which waits
|
|
// for a global synchronization event which is sent when the parent process crashes.
|
|
// The monitor process then extracts crash information from the parent process while
|
|
// the parent process waits for the monitor process to finish. The crashed process
|
|
// quits and the monitor writes the crash information to a file.
|
|
//
|
|
// To detect unexpected shutdowns of the application which are not handled by the
|
|
// crash handler, the monitor periodically checks the exit code of the parent
|
|
// process and exits if it does not return STILL_ACTIVE. You can test this by closing
|
|
// the main openmw process in task manager.
|
|
|
|
static constexpr const int CrashCatcherTimeout = 2500;
|
|
|
|
struct CrashSHM;
|
|
|
|
class CrashCatcher final
|
|
{
|
|
public:
|
|
CrashCatcher(int argc, char** argv, const std::filesystem::path& crashDumpPath,
|
|
const std::filesystem::path& freezeDumpPath);
|
|
~CrashCatcher();
|
|
|
|
private:
|
|
static CrashCatcher* sInstance;
|
|
|
|
// mapped SHM area
|
|
CrashSHM* mShm = nullptr;
|
|
// the handle is allocated by the catcher and passed to the monitor
|
|
// process via the command line which maps the SHM and sends / receives
|
|
// events through it
|
|
HANDLE mShmHandle = nullptr;
|
|
// mutex which guards SHM area
|
|
HANDLE mShmMutex = nullptr;
|
|
|
|
// triggered when the monitor signals the application
|
|
HANDLE mSignalAppEvent = INVALID_HANDLE_VALUE;
|
|
|
|
// triggered when the application wants to wake the monitor process
|
|
HANDLE mSignalMonitorEvent = INVALID_HANDLE_VALUE;
|
|
|
|
void setupIpc();
|
|
|
|
void shmLock();
|
|
|
|
void shmUnlock();
|
|
|
|
void startMonitorProcess(
|
|
const std::filesystem::path& crashDumpPath, const std::filesystem::path& freezeDumpPath);
|
|
|
|
void waitMonitor();
|
|
|
|
void signalMonitor();
|
|
|
|
void installHandler();
|
|
|
|
void handleVectoredException(PEXCEPTION_POINTERS info);
|
|
|
|
public:
|
|
static LONG WINAPI vectoredExceptionHandler(PEXCEPTION_POINTERS info);
|
|
};
|
|
|
|
} // namespace Crash
|
|
|
|
#endif // WINDOWS_CRASHCATCHER_HPP
|