diff options
author | Anton Kling <anton@kling.gg> | 2024-02-14 17:40:06 +0100 |
---|---|---|
committer | Anton Kling <anton@kling.gg> | 2024-02-14 17:40:06 +0100 |
commit | 3922adcdec5bd003b4106ffce79c28553bc40c15 (patch) | |
tree | f1af360cd7ad75d4b5f19bf066bf7e29ce8e3e53 /kernel/sched | |
parent | a8ffc46136eb16adc87fb520c724467d1295a854 (diff) |
Kernel: Update signal handling and IPC
Diffstat (limited to 'kernel/sched')
-rw-r--r-- | kernel/sched/scheduler.c | 60 | ||||
-rw-r--r-- | kernel/sched/scheduler.h | 17 |
2 files changed, 77 insertions, 0 deletions
diff --git a/kernel/sched/scheduler.c b/kernel/sched/scheduler.c index 8019e5a..505dbd8 100644 --- a/kernel/sched/scheduler.c +++ b/kernel/sched/scheduler.c @@ -26,6 +26,66 @@ process_t *get_current_task(void) { return current_task; } +void process_push_restore_context(process_t *p, reg_t r) { + if (!p) { + p = current_task; + } + reg_t *new_r = kmalloc(sizeof(reg_t)); + memcpy(new_r, &r, sizeof(reg_t)); + stack_push(&p->restore_context_stack, new_r); + return; +} + +void process_pop_restore_context(process_t *p, reg_t *out_r) { + if (!p) { + p = current_task; + } + reg_t *r = stack_pop(&p->restore_context_stack); + if (NULL == r) { + assert(NULL); + } + memcpy(out_r, r, sizeof(reg_t)); + kfree(r); +} + +void process_push_signal(process_t *p, signal_t s) { + if (!p) { + p = current_task; + } + + int index = -1; + for (int i = 0; i < 100; i++) { + const signal_t *s = p->active_signals[i]; + if (!s) { + index = i; + break; + } + } + if (-1 == index) { + assert(0); + return; + } + signal_t *new_signal_entry = kmalloc(sizeof(signal_t)); + memcpy(new_signal_entry, &s, sizeof(signal_t)); + p->active_signals[index] = new_signal_entry; +} + +const signal_t *process_pop_signal(process_t *p) { + if (!p) { + p = current_task; + } + + for (int i = 0; i < 100; i++) { + const signal_t *s = p->active_signals[i]; + if (!s) { + continue; + } + p->active_signals[i] = NULL; + return s; + } + return NULL; +} + bool get_task_from_pid(u32 pid, process_t **out) { for (process_t *tmp = ready_queue; tmp; tmp = tmp->next) { if (tmp->pid == pid) { diff --git a/kernel/sched/scheduler.h b/kernel/sched/scheduler.h index 01276dc..f73d8ef 100644 --- a/kernel/sched/scheduler.h +++ b/kernel/sched/scheduler.h @@ -4,6 +4,7 @@ #include <fs/vfs.h> #include <halts.h> #include <ipc.h> +#include <lib/stack.h> #include <mmu.h> #include <signal.h> #include <stdbool.h> @@ -32,6 +33,10 @@ typedef struct { int fd; } MemoryMap; +typedef struct { + uintptr_t handler_ip; +} signal_t; + typedef struct Process process_t; typedef struct TCB { @@ -40,6 +45,11 @@ typedef struct TCB { uint32_t ESP0; } __attribute__((packed)) TCB; +void process_push_restore_context(process_t *p, reg_t r); +void process_pop_restore_context(process_t *p, reg_t *out_r); +void process_push_signal(process_t *p, signal_t s); +const signal_t *process_pop_signal(process_t *p); + struct Process { u32 pid; char program_name[100]; @@ -57,6 +67,13 @@ struct Process { vfs_inode_t *read_halt_inode[100]; vfs_inode_t *write_halt_inode[100]; vfs_inode_t *disconnect_halt_inode[100]; + + // // FIXME: Make this a array or circular buffer + // reg_t restore_context; + struct stack restore_context_stack; + + signal_t *active_signals[100]; + u32 halts[2]; struct Halt *halt_list; void *data_segment_end; |