mirror of
https://github.com/JannisHeydemann/BoredOS.git
synced 2026-05-30 02:16:58 +00:00
feat: Add signals, exec/wait, and FD/pipe support
Introduce process lifecycle and POSIX-like features: add parent_pid, pgid, exited/exit_status, signal state and handlers, waitpid/reap, and an exec-replace function. Refactor file descriptor handling to use fd_kind/fd_flags with reference-counted file refs and in-process pipes; implement open/read/write/close/seek/tell/size/dup/dup2/pipe/fcntl semantics and O_* flags. Add syscall handlers for exec, waitpid, kill/signal, sigaction, sigprocmask, sigpending, meminfo/ticks and map many SYSTEM_CMD_* constants; deliver signals from the syscall path. Cleanup/terminate logic updated to free resources correctly and initialize kernel/user processes with new state. Misc: minor syscall/table renames (wallpaper), helper utilities (process_close_fd_inner, process_init_signal_state) and paging/stack handling for exec.
This commit is contained in:
@@ -11,6 +11,26 @@
|
||||
|
||||
#define MAX_GUI_EVENTS 32
|
||||
#define MAX_PROCESS_FDS 16
|
||||
#define MAX_SIGNALS 32
|
||||
|
||||
#define PROC_FD_KIND_NONE 0
|
||||
#define PROC_FD_KIND_FILE 1
|
||||
#define PROC_FD_KIND_PIPE_READ 2
|
||||
#define PROC_FD_KIND_PIPE_WRITE 3
|
||||
|
||||
typedef struct {
|
||||
void *file;
|
||||
int refs;
|
||||
} process_fd_file_ref_t;
|
||||
|
||||
typedef struct {
|
||||
uint8_t data[4096];
|
||||
uint32_t read_pos;
|
||||
uint32_t write_pos;
|
||||
uint32_t count;
|
||||
int readers;
|
||||
int writers;
|
||||
} process_fd_pipe_t;
|
||||
|
||||
struct FAT32_FileHandle;
|
||||
|
||||
@@ -38,6 +58,8 @@ typedef struct process {
|
||||
uint64_t heap_end;
|
||||
|
||||
void *fds[MAX_PROCESS_FDS];
|
||||
uint8_t fd_kind[MAX_PROCESS_FDS];
|
||||
int fd_flags[MAX_PROCESS_FDS];
|
||||
|
||||
void *kernel_stack_alloc;
|
||||
void *user_stack_alloc;
|
||||
@@ -57,6 +79,17 @@ typedef struct process {
|
||||
uint32_t cpu_affinity;
|
||||
bool is_idle;
|
||||
char cwd[1024];
|
||||
|
||||
uint32_t parent_pid;
|
||||
uint32_t pgid;
|
||||
bool exited;
|
||||
int exit_status;
|
||||
|
||||
uint64_t signal_mask;
|
||||
uint64_t signal_pending;
|
||||
uint64_t signal_handlers[MAX_SIGNALS];
|
||||
uint64_t signal_action_mask[MAX_SIGNALS];
|
||||
int signal_action_flags[MAX_SIGNALS];
|
||||
} __attribute__((aligned(16))) process_t;
|
||||
|
||||
typedef struct {
|
||||
@@ -70,13 +103,17 @@ typedef struct {
|
||||
void process_init(void);
|
||||
process_t* process_create(void (*entry_point)(void), bool is_user);
|
||||
process_t* process_create_elf(const char* filepath, const char* args_str, bool terminal_proc, int tty_id);
|
||||
int process_exec_replace_current(registers_t *regs, const char* filepath, const char* args_str);
|
||||
process_t* process_get_current(void);
|
||||
void process_set_current_for_cpu(uint32_t cpu_id, process_t* p);
|
||||
process_t* process_get_current_for_cpu(uint32_t cpu_id);
|
||||
uint64_t process_schedule(uint64_t current_rsp);
|
||||
uint64_t process_terminate_current(void);
|
||||
void process_terminate(process_t *proc);
|
||||
void process_terminate_with_status(process_t *proc, int status);
|
||||
process_t* process_get_by_pid(uint32_t pid);
|
||||
int process_waitpid(uint32_t caller_pid, int target_pid, int options, int *status_out);
|
||||
int process_reap(uint32_t caller_pid, uint32_t pid, int *status_out);
|
||||
void process_kill_by_tty(int tty_id);
|
||||
|
||||
// SMP: IPI handler for AP scheduling
|
||||
|
||||
Reference in New Issue
Block a user