mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-12 10:17:22 +01:00
feat: add minidump writer
This commit is contained in:
parent
a585c3f1af
commit
805a887f2e
14 changed files with 477 additions and 12 deletions
|
|
@ -162,6 +162,7 @@
|
|||
<ClInclude Include="..\lib\TsudaKageyu-minhook\src\HDE\table32.h" />
|
||||
<ClInclude Include="..\lib\TsudaKageyu-minhook\src\HDE\table64.h" />
|
||||
<ClInclude Include="..\lib\TsudaKageyu-minhook\src\trampoline.h" />
|
||||
<ClInclude Include="crashhandler_shared.h" />
|
||||
<ClInclude Include="DalamudStartInfo.h" />
|
||||
<ClInclude Include="hooks.h" />
|
||||
<ClInclude Include="logging.h" />
|
||||
|
|
@ -182,4 +183,4 @@
|
|||
<Delete Files="$(OutDir)$(TargetName).lib" />
|
||||
<Delete Files="$(OutDir)$(TargetName).exp" />
|
||||
</Target>
|
||||
</Project>
|
||||
</Project>
|
||||
|
|
@ -139,6 +139,7 @@
|
|||
<Filter>MinHook</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="resource.h" />
|
||||
<ClInclude Include="crashhandler_shared.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ResourceCompile Include="Dalamud.Boot.rc" />
|
||||
|
|
@ -146,4 +147,4 @@
|
|||
<ItemGroup>
|
||||
<Image Include="dalamud.ico" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
</Project>
|
||||
15
Dalamud.Boot/crashhandler_shared.h
Normal file
15
Dalamud.Boot/crashhandler_shared.h
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
#pragma once
|
||||
|
||||
#include "windows.h"
|
||||
|
||||
struct exception_info
|
||||
{
|
||||
void* ExceptionPointers; // Cannot dereference!
|
||||
DWORD ThreadId;
|
||||
DWORD ProcessId;
|
||||
BOOL DoFullDump;
|
||||
wchar_t DumpPath[1000];
|
||||
};
|
||||
|
||||
constexpr wchar_t SHARED_INFO_FILE_NAME[] = L"DalamudCrashInfoShare";
|
||||
constexpr wchar_t CRASHDUMP_EVENT_NAME[] = L"Global\\DalamudRequestWriteDump";
|
||||
|
|
@ -136,7 +136,7 @@ DWORD WINAPI InitializeImpl(LPVOID lpParam, HANDLE hMainThreadContinue) {
|
|||
if (utils::is_running_on_linux()) {
|
||||
logging::I("=> VEH was disabled, running on linux");
|
||||
} else if (g_startInfo.BootVehEnabled) {
|
||||
if (veh::add_handler(g_startInfo.BootVehFull))
|
||||
if (veh::add_handler(g_startInfo.BootVehFull, g_startInfo.WorkingDirectory))
|
||||
logging::I("=> Done!");
|
||||
else
|
||||
logging::I("=> Failed!");
|
||||
|
|
|
|||
|
|
@ -9,6 +9,8 @@
|
|||
#include "logging.h"
|
||||
#include "utils.h"
|
||||
|
||||
#include "crashhandler_shared.h"
|
||||
|
||||
#pragma comment(lib, "comctl32.lib")
|
||||
|
||||
#if defined _M_IX86
|
||||
|
|
@ -24,6 +26,9 @@
|
|||
PVOID g_veh_handle = nullptr;
|
||||
bool g_veh_do_full_dump = false;
|
||||
|
||||
exception_info* g_crashhandler_shared_info;
|
||||
HANDLE g_crashhandler_event;
|
||||
|
||||
bool is_whitelist_exception(const DWORD code)
|
||||
{
|
||||
switch (code)
|
||||
|
|
@ -292,14 +297,19 @@ LONG exception_handler(EXCEPTION_POINTERS* ex)
|
|||
ex_info.ClientPointers = false;
|
||||
ex_info.ExceptionPointers = ex;
|
||||
ex_info.ThreadId = GetCurrentThreadId();
|
||||
|
||||
auto miniDumpType = MiniDumpWithDataSegs;
|
||||
if (g_veh_do_full_dump)
|
||||
miniDumpType = MiniDumpWithFullMemory;
|
||||
|
||||
HANDLE file = CreateFileW(dmp_path.c_str(), GENERIC_WRITE, FILE_SHARE_WRITE, nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr);
|
||||
//MiniDumpWriteDump(GetCurrentProcess(), GetCurrentProcessId(), file, miniDumpType, &ex_info, nullptr, nullptr);
|
||||
CloseHandle(file);
|
||||
if (g_crashhandler_shared_info && g_crashhandler_event)
|
||||
{
|
||||
memset(g_crashhandler_shared_info, 0, sizeof(exception_info));
|
||||
|
||||
wcsncpy_s(g_crashhandler_shared_info->DumpPath, dmp_path.c_str(), 1000);
|
||||
g_crashhandler_shared_info->ThreadId = GetThreadId(GetCurrentThread());
|
||||
g_crashhandler_shared_info->ProcessId = GetCurrentProcessId();
|
||||
g_crashhandler_shared_info->ExceptionPointers = ex;
|
||||
g_crashhandler_shared_info->DoFullDump = g_veh_do_full_dump;
|
||||
|
||||
SetEvent(g_crashhandler_event);
|
||||
}
|
||||
|
||||
std::wstring message;
|
||||
void* fn;
|
||||
|
|
@ -384,7 +394,7 @@ LONG exception_handler(EXCEPTION_POINTERS* ex)
|
|||
return EXCEPTION_CONTINUE_SEARCH;
|
||||
}
|
||||
|
||||
bool veh::add_handler(bool doFullDump)
|
||||
bool veh::add_handler(bool doFullDump, std::string workingDirectory)
|
||||
{
|
||||
if (g_veh_handle)
|
||||
return false;
|
||||
|
|
@ -393,6 +403,58 @@ bool veh::add_handler(bool doFullDump)
|
|||
|
||||
g_veh_do_full_dump = doFullDump;
|
||||
|
||||
auto file_mapping = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, sizeof(exception_info), SHARED_INFO_FILE_NAME);
|
||||
if (!file_mapping) {
|
||||
std::cout << "Could not map info share file.\n";
|
||||
g_crashhandler_shared_info = nullptr;
|
||||
}
|
||||
else
|
||||
{
|
||||
g_crashhandler_shared_info = (exception_info*)MapViewOfFile(file_mapping, FILE_MAP_ALL_ACCESS, 0, 0, sizeof(exception_info));
|
||||
if (!g_crashhandler_shared_info) {
|
||||
std::cout << "Could not map view of info share file.\n";
|
||||
}
|
||||
}
|
||||
|
||||
g_crashhandler_event = CreateEvent(
|
||||
NULL, // default security attributes
|
||||
TRUE, // manual-reset event
|
||||
FALSE, // initial state is nonsignaled
|
||||
CRASHDUMP_EVENT_NAME // object name
|
||||
);
|
||||
|
||||
if (!g_crashhandler_event)
|
||||
{
|
||||
std::cout << "Couldn't acquire event handle\n";
|
||||
}
|
||||
|
||||
auto handler_path = std::filesystem::path(workingDirectory) / "DalamudCrashHandler.exe";
|
||||
|
||||
// additional information
|
||||
STARTUPINFO si;
|
||||
PROCESS_INFORMATION pi;
|
||||
|
||||
// set the size of the structures
|
||||
ZeroMemory( &si, sizeof(si) );
|
||||
si.cb = sizeof(si);
|
||||
ZeroMemory( &pi, sizeof(pi) );
|
||||
|
||||
CreateProcess( handler_path.c_str(), // the path
|
||||
NULL, // Command line
|
||||
NULL, // Process handle not inheritable
|
||||
NULL, // Thread handle not inheritable
|
||||
FALSE, // Set handle inheritance to FALSE
|
||||
0, // No creation flags
|
||||
NULL, // Use parent's environment block
|
||||
NULL, // Use parent's starting directory
|
||||
&si, // Pointer to STARTUPINFO structure
|
||||
&pi // Pointer to PROCESS_INFORMATION structure (removed extra parentheses)
|
||||
);
|
||||
|
||||
// Close process and thread handles.
|
||||
CloseHandle( pi.hProcess );
|
||||
CloseHandle( pi.hThread );
|
||||
|
||||
return g_veh_handle != nullptr;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,6 @@
|
|||
|
||||
namespace veh
|
||||
{
|
||||
bool add_handler(bool doFullDump);
|
||||
bool add_handler(bool doFullDump, std::string workingDirectory);
|
||||
bool remove_handler();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue