feat: add process termination codes and SYS_ABORT; whole-process abort() from any thread in libc and montauk-rt
This commit is contained in:
1 parent
f8b8f9610f
commit
278b208258
15 files changed
+126
-37
No files matched your search
@@ -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
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user