feat: add process termination codes and SYS_ABORT; whole-process abort() from any thread in libc and montauk-rt

This commit is contained in:
daniel committed 2026-10-14 07:32:15 +02:00
1 parent f8b8f9610f
commit 278b208258
15 files changed
+126 -37

No files matched your search

+5
View File
@@ -288,6 +288,11 @@ namespace montauk::abi {
static constexpr uint64_t FUTEX_WAIT_FOREVER = ~0ULL;
static constexpr uint32_t FUTEX_WAKE_ALL = 0xFFFFFFFFu;
/* Abnormal termination from any thread: ends the whole process (every
thread) with exit code TerminatedAborted (256+SIGABRT). SYS_EXIT from a
sibling thread ends only that thread, so abort() needs its own call. */
static constexpr uint64_t SYS_ABORT = 198; // () -> does not return
/* Kernel-owned process capabilities. User identities may namespace
per-user resources, but never participate in authorization decisions. */
static constexpr uint64_t CAP_PROCESS_ADMIN = 1ULL << 0;
+1
View File
@@ -221,6 +221,7 @@ extern "C" {
#define MTK_SYS_CHILDIO_WRITEKEY_EX 195
#define MTK_SYS_FUTEX_WAIT 196
#define MTK_SYS_FUTEX_WAKE 197
#define MTK_SYS_ABORT 198
/* @SYSCALLS-END */
/* Syscall status codes (montauk/statuscodes.h for C++). */
+27
View File
@@ -101,6 +101,33 @@ inline const char* GetStatusExplanationText(StatusCode statusCode) {
return GetStatusText(statusCode);
}
// Process termination codes: what waitpid returns when the kernel ended the
// process (crash, kill, abort) instead of it calling exit. 256 + POSIX
// signal number, so normal exit codes (0..255) can never collide.
// Analogous to kernel/src/Common/TerminationCodes.hpp; same values.
typedef enum {
TerminationBase = 256,
TerminatedIllegalInstruction = TerminationBase + 4, // SIGILL
TerminatedBreakpoint = TerminationBase + 5, // SIGTRAP
TerminatedAborted = TerminationBase + 6, // SIGABRT
TerminatedArithmeticError = TerminationBase + 8, // SIGFPE
TerminatedKilled = TerminationBase + 9, // SIGKILL
TerminatedAccessViolation = TerminationBase + 11 // SIGSEGV
} TerminationCode;
// Shared with C (libc.c), so no nullptr. Returns 0 for an unknown code.
inline const char* GetTerminationText(int exitCode) {
switch (exitCode) {
case TerminatedIllegalInstruction: return "Illegal instruction";
case TerminatedBreakpoint: return "Breakpoint";
case TerminatedAborted: return "Aborted";
case TerminatedArithmeticError: return "Arithmetic error";
case TerminatedKilled: return "Killed";
case TerminatedAccessViolation: return "Access violation";
default: return 0;
}
}
#ifdef __cplusplus
}
#endif
+5
View File
@@ -527,6 +527,11 @@ namespace montauk {
inline int kill(int pid) {
return (int)syscall1(montauk::abi::SYS_KILL, (uint64_t)pid);
}
// End the whole process from any thread (exit code TerminatedAborted).
[[noreturn]] inline void abort() {
syscall0(montauk::abi::SYS_ABORT);
__builtin_unreachable();
}
inline int setsession() {
return (int)syscall0(montauk::abi::SYS_SETSESSION);
}