Skip to content

Commit

Permalink
sigint handler; dotnet exception code in crash handler
Browse files Browse the repository at this point in the history
  • Loading branch information
malytomas committed Jul 13, 2024
1 parent 5576b27 commit fed7be0
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
1 change: 1 addition & 0 deletions sources/include/cage-core/process.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ namespace cage
CAGE_CORE_API Holder<Process> newProcess(const ProcessCreateConfig &config);

CAGE_CORE_API void installSigTermHandler(Delegate<void()> handler);
CAGE_CORE_API void installSigIntHandler(Delegate<void()> handler);
}

#endif // guard_program_h_f16ac3b2_6520_4503_a6ad_f4a582216f67_
14 changes: 13 additions & 1 deletion sources/libcore/concurrent/process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -512,17 +512,29 @@ namespace cage
namespace
{
Delegate<void()> sigTermHandler;

void sigTermHandlerEntry(int)
{
if (sigTermHandler)
sigTermHandler();
}

Delegate<void()> sigIntHandler;
void sigIntHandlerEntry(int)
{
if (sigIntHandler)
sigIntHandler();
}
}

void installSigTermHandler(Delegate<void()> handler)
{
sigTermHandler = handler;
signal(SIGTERM, &sigTermHandlerEntry);
}

void installSigIntHandler(Delegate<void()> handler)
{
sigIntHandler = handler;
signal(SIGINT, &sigIntHandlerEntry);
}
}
11 changes: 10 additions & 1 deletion sources/libcore/crashHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <DbgHelp.h>
#pragma comment(lib, "DbgHelp.lib")
#define EXCEPTION_CPP 0xE06D7363
#define EXCEPTION_DOTNET 0xE0434352
#define EXCEPTION_RENAME_THREAD 0x406D1388

#include <cage-core/core.h>
Expand Down Expand Up @@ -100,10 +101,12 @@ namespace cage
return "DBG_EXCEPTION_NOT_HANDLED";
case EXCEPTION_CPP:
return "EXCEPTION_CPP";
case EXCEPTION_DOTNET:
return "EXCEPTION_DOTNET";
case EXCEPTION_RENAME_THREAD:
return "EXCEPTION_RENAME_THREAD";
default:
return Stringizer() + "unknown code: " + code;
return Stringizer() + "unknown exception code: " + code;
}
}

Expand Down Expand Up @@ -202,12 +205,18 @@ namespace cage
static std::mutex mutex;
std::scoped_lock lock(mutex);
CAGE_LOG(SeverityEnum::Error, "crash-handler", Stringizer() + "crash handler: " + exceptionCodeToString(ex->ExceptionRecord->ExceptionCode));
CAGE_LOG(SeverityEnum::Info, "crash-handler", Stringizer() + "address: " + ex->ExceptionRecord->ExceptionAddress);
if (ex->ExceptionRecord->ExceptionCode == EXCEPTION_ACCESS_VIOLATION || ex->ExceptionRecord->ExceptionCode == EXCEPTION_IN_PAGE_ERROR)
{
const uint64 mode = ex->ExceptionRecord->ExceptionInformation[0];
const uint64 addr = ex->ExceptionRecord->ExceptionInformation[1];
CAGE_LOG(SeverityEnum::Info, "crash-handler", Stringizer() + "violation: " + exceptionAccessModeToString(mode) + ", at address: " + addr);
}
else
{
for (uint32 i = 0; i < ex->ExceptionRecord->NumberParameters; i++)
CAGE_LOG(SeverityEnum::Info, "crash-handler", Stringizer() + "parameter[" + i + "]: " + ex->ExceptionRecord->ExceptionInformation);
}
printStackTrace(ex);
}

Expand Down

0 comments on commit fed7be0

Please sign in to comment.