File: windows_crashcatcher.hpp

package info (click to toggle)
openmw 0.49.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 33,992 kB
  • sloc: cpp: 372,479; xml: 2,149; sh: 1,403; python: 797; makefile: 26
file content (83 lines) | stat: -rw-r--r-- 2,861 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#ifndef WINDOWS_CRASHCATCHER_HPP
#define WINDOWS_CRASHCATCHER_HPP

#include <filesystem>

#include <components/crashcatcher/crashcatcher.hpp>
#include <components/misc/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;
    static constexpr const int CrashCatcherThawTimeout = 250;

    struct CrashSHM;

    class CrashCatcher final
    {
    public:
        static CrashCatcher* instance() { return sInstance; }

        CrashCatcher(int argc, char** argv, const std::filesystem::path& dumpPath,
            const std::filesystem::path& crashDumpName, const std::filesystem::path& freezeDumpName);
        ~CrashCatcher();

        void updateDumpPath(const std::filesystem::path& dumpPath);

        void updateDumpNames(const std::filesystem::path& crashDumpName, const std::filesystem::path& freezeDumpName);

    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& dumpPath, const std::filesystem::path& crashDumpName,
            const std::filesystem::path& freezeDumpName);

        void waitMonitor();
        bool waitMonitorNoThrow();

        void signalMonitor();

        void installHandler();

        void handleVectoredException(PEXCEPTION_POINTERS info);

    public:
        static LONG WINAPI vectoredExceptionHandler(PEXCEPTION_POINTERS info);
    };

} // namespace Crash

#endif // WINDOWS_CRASHCATCHER_HPP