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:
@@ -51,6 +51,7 @@ extern int errno;
|
||||
#define EWOULDBLOCK EAGAIN
|
||||
#define EOVERFLOW 75
|
||||
#define ETIMEDOUT 110
|
||||
#define ENOTSUP 95
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
#ifndef _LIBC_SPAWN_H
|
||||
#define _LIBC_SPAWN_H
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*
|
||||
* posix_spawn for MontaukOS, layered on SYS_SPAWN.
|
||||
*
|
||||
* Limitations (kernel spawn model):
|
||||
* - argv is joined into a single args string; arguments containing
|
||||
* spaces are rejected with EINVAL (no quoting in the kernel).
|
||||
* - envp is ignored (no environment transfer on spawn).
|
||||
* - file actions must be empty: stdio redirection needs kernel
|
||||
* support that does not exist yet, so any recorded action makes
|
||||
* posix_spawn fail with ENOTSUP rather than misbehave silently.
|
||||
*/
|
||||
|
||||
typedef struct {
|
||||
short flags;
|
||||
} posix_spawnattr_t;
|
||||
|
||||
typedef struct {
|
||||
int action_count;
|
||||
} posix_spawn_file_actions_t;
|
||||
|
||||
int posix_spawnattr_init(posix_spawnattr_t *attr);
|
||||
int posix_spawnattr_destroy(posix_spawnattr_t *attr);
|
||||
int posix_spawnattr_setflags(posix_spawnattr_t *attr, short flags);
|
||||
int posix_spawnattr_getflags(const posix_spawnattr_t *attr, short *flags);
|
||||
|
||||
int posix_spawn_file_actions_init(posix_spawn_file_actions_t *actions);
|
||||
int posix_spawn_file_actions_destroy(posix_spawn_file_actions_t *actions);
|
||||
int posix_spawn_file_actions_adddup2(posix_spawn_file_actions_t *actions,
|
||||
int fd, int newfd);
|
||||
int posix_spawn_file_actions_addclose(posix_spawn_file_actions_t *actions,
|
||||
int fd);
|
||||
int posix_spawn_file_actions_addopen(posix_spawn_file_actions_t *actions,
|
||||
int fd, const char *path, int oflag,
|
||||
mode_t mode);
|
||||
|
||||
int posix_spawn(pid_t *pid, const char *path,
|
||||
const posix_spawn_file_actions_t *actions,
|
||||
const posix_spawnattr_t *attr,
|
||||
char *const argv[], char *const envp[]);
|
||||
int posix_spawnp(pid_t *pid, const char *file,
|
||||
const posix_spawn_file_actions_t *actions,
|
||||
const posix_spawnattr_t *attr,
|
||||
char *const argv[], char *const envp[]);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _LIBC_SPAWN_H */
|
||||
@@ -9,12 +9,12 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Status decoding. The Montauk kernel does not yet report exit codes
|
||||
through SYS_WAITPID, so waited children always decode as exit 0. */
|
||||
/* POSIX status decoding. waitpid() encodes a normal exit as code<<8
|
||||
and a killed/crashed child as the signal number in the low bits. */
|
||||
#define WIFEXITED(s) (((s) & 0x7F) == 0)
|
||||
#define WEXITSTATUS(s) (((s) >> 8) & 0xFF)
|
||||
#define WIFSIGNALED(s) (0)
|
||||
#define WTERMSIG(s) (0)
|
||||
#define WIFSIGNALED(s) (((s) & 0x7F) != 0)
|
||||
#define WTERMSIG(s) ((s) & 0x7F)
|
||||
#define WIFSTOPPED(s) (0)
|
||||
#define WSTOPSIG(s) (0)
|
||||
|
||||
|
||||
@@ -321,7 +321,9 @@ namespace montauk {
|
||||
}
|
||||
|
||||
// Process management
|
||||
inline void waitpid(int pid) { syscall1(montauk::abi::SYS_WAITPID, (uint64_t)pid); }
|
||||
// Blocks until pid exits. Returns 0..255 for a normal exit,
|
||||
// 256+signal when the process was killed or crashed.
|
||||
inline int waitpid(int pid) { return (int)syscall1(montauk::abi::SYS_WAITPID, (uint64_t)pid); }
|
||||
|
||||
// Framebuffer
|
||||
inline void fb_info(montauk::abi::FbInfo* info) { syscall1(montauk::abi::SYS_FBINFO, (uint64_t)info); }
|
||||
|
||||
Reference in New Issue
Block a user