Веб-сайт самохостера Lotigara

summaryrefslogtreecommitdiff
path: root/source/core/StarMiniDump_windows.cpp
blob: 368d67d7f98778e29e0e257548f2477e12a54a25 (plain)
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
#include "StarMiniDump.hpp"
#include <windows.h>
#include "minidumpapiset.h"

namespace Star {
  DWORD WINAPI writeMiniDump(void* ExceptionInfo) {
    auto hFile = CreateFileA("starbound.dmp", GENERIC_WRITE, FILE_SHARE_READ, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
    if (hFile == INVALID_HANDLE_VALUE)
      return 0;
    MINIDUMP_EXCEPTION_INFORMATION dumpExceptionInfo{};
    dumpExceptionInfo.ThreadId = GetCurrentThreadId();
    dumpExceptionInfo.ExceptionPointers = (PEXCEPTION_POINTERS)ExceptionInfo;
    dumpExceptionInfo.ClientPointers = FALSE;
    MiniDumpWriteDump(
      GetCurrentProcess(),
      GetCurrentProcessId(),
      hFile,
      MiniDumpNormal,
      &dumpExceptionInfo,
      NULL,
      NULL);
    CloseHandle(hFile);
    if (dumpExceptionInfo.ExceptionPointers->ExceptionRecord->ExceptionCode == EXCEPTION_STACK_OVERFLOW) {
      MessageBoxA(NULL, "Stack overflow encountered\nA minidump has been generated", NULL, MB_OK | MB_ICONERROR | MB_SETFOREGROUND);
    }
    return 0;
  };
}