[common/client] platform: abstract runtime services

This commit is contained in:
Geoffrey McRae
2026-09-12 12:51:17 +10:00
parent a7d2e4592f
commit eabc56a6de
49 changed files with 4064 additions and 940 deletions

View File

@@ -57,3 +57,13 @@ void platform_debugInit(void)
debug_lookup = (isatty(STDERR_FILENO) == 1) ? colorLookup : plainLookup;
}
void debug_lock(void)
{
flockfile(stderr);
}
void debug_unlock(void)
{
funlockfile(stderr);
}

View File

@@ -30,6 +30,14 @@
#include <windows.h>
#include <dbghelp.h>
struct CrashHandlerState
{
LPTOP_LEVEL_EXCEPTION_FILTER previous;
bool installed;
};
static struct CrashHandlerState crashHandler;
static const char * exception_name(DWORD code)
{
switch (code)
@@ -124,8 +132,8 @@ static LONG CALLBACK exception_filter(EXCEPTION_POINTERS * exc)
if (SymFromAddr(hProcess, frame.AddrPC.Offset, &disp, symbol))
{
IMAGEHLP_LINE line = { sizeof(IMAGEHLP_LINE), 0 };
DWORD lineDisp;
IMAGEHLP_LINE line = { .SizeOfStruct = sizeof(line) };
DWORD lineDisp;
if (SymGetLineFromAddr64(hProcess, frame.AddrPC.Offset, &lineDisp, &line))
DEBUG_ERROR("[trace]: %2d: %s:%s+0x%" PRIx64 " (%s:%" PRIx64 "+0x%" PRIx64 ")",
@@ -152,10 +160,25 @@ bool installCrashHandler(const char * exe, char * argv0)
{
(void)exe;
(void)argv0;
SetUnhandledExceptionFilter(exception_filter);
if (!crashHandler.installed)
{
crashHandler.previous = SetUnhandledExceptionFilter(exception_filter);
crashHandler.installed = true;
}
return true;
}
void cleanupCrashHandler(void)
{
if (!crashHandler.installed)
return;
SetUnhandledExceptionFilter(crashHandler.previous);
crashHandler.previous = NULL;
crashHandler.installed = false;
}
void printBacktrace(void)
{
}
@@ -172,6 +195,10 @@ bool installCrashHandler(const char * exe, char * argv0)
return true;
}
void cleanupCrashHandler(void)
{
}
void printBacktrace(void)
{
}

View File

@@ -37,3 +37,13 @@ void platform_debugInit(void)
debug_lookup = plainLookup;
}
void debug_lock(void)
{
_lock_file(stderr);
}
void debug_unlock(void)
{
_unlock_file(stderr);
}