feat: process exit codes, posix_spawn, 4 KiB command lines
Groundwork for the GCC driver: a compiler driver must spawn cc1/as/ld and know whether each stage succeeded. Kernel: the scheduler keeps an exit-code ledger (pid -> code; pids are monotonic so entries never alias), published during teardown right before waiters wake. SYS_EXIT records main()'s return value, SYS_KILL records 256+SIGKILL, and the exception handler records 256+signal mapped from the fault vector (#PF/#GP -> SIGSEGV, #DE/FP -> SIGFPE, #UD -> SIGILL). SYS_WAITPID now returns the code: 0..255 for a normal exit, 256+signal for a violent death. Process args grow from 256 bytes to 4 KiB (cc1 invocations do not fit in 256), with crt1 now parsing up to 255 argv entries from a static buffer. libc: new spawn.h with posix_spawn/posix_spawnp over SYS_SPAWN - libiberty's pex layer has a posix_spawn backend, so GCC's driver works without fork. argv is joined into the kernel args string (spaces in arguments rejected; no kernel quoting), envp is not transferred, and non-empty file actions fail loudly with ENOTSUP until the kernel can redirect stdio on spawn. waitpid() now decodes real POSIX status and the sys/wait.h macros distinguish exited from signaled children. Shell: prints [exit code N] after nonzero exits and [terminated by signal N] for killed or crashed children. Verified on the OS: cat on a missing file reports exit code 1; a window-close (clean exit 0) stays silent as it should. Co-Authored-By: Claude Fable 5 <[email protected]>
This commit is contained in:
@@ -17,11 +17,33 @@ static bool file_exists(const char* path) {
|
||||
|
||||
// ---- Try to spawn an ELF at the given path ----
|
||||
|
||||
static void print_exit_code(int code) {
|
||||
if (code == 0) return;
|
||||
char buf[16];
|
||||
int n = 0;
|
||||
if (code >= 256) {
|
||||
montauk::print("[terminated by signal ");
|
||||
code -= 256;
|
||||
} else {
|
||||
montauk::print("[exit code ");
|
||||
}
|
||||
if (code == 0) buf[n++] = '0';
|
||||
while (code > 0 && n < 15) {
|
||||
buf[n++] = (char)('0' + code % 10);
|
||||
code /= 10;
|
||||
}
|
||||
while (n > 0) {
|
||||
char c[2] = { buf[--n], 0 };
|
||||
montauk::print(c);
|
||||
}
|
||||
montauk::print("]\n");
|
||||
}
|
||||
|
||||
static bool try_exec(const char* path, const char* args) {
|
||||
if (!file_exists(path)) return false;
|
||||
int pid = montauk::spawn(path, args);
|
||||
if (pid < 0) return false;
|
||||
montauk::waitpid(pid);
|
||||
print_exit_code(montauk::waitpid(pid));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user