From c0608f199fc711aa82867f80059dfeebf38b4a25 Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Sun, 6 Sep 2020 00:02:41 +0200 Subject: Fixed GPF on non-existent exec --- kernel/features/proc.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'kernel') diff --git a/kernel/features/proc.c b/kernel/features/proc.c index 438ded7..a5df875 100644 --- a/kernel/features/proc.c +++ b/kernel/features/proc.c @@ -70,7 +70,7 @@ void proc_print() struct proc *proc_current() { - return current ? current->data : NULL; + return current && current->data ? current->data : NULL; } void proc_send(struct proc *src, struct proc *dest, enum message_type type, void *data) @@ -111,19 +111,24 @@ struct proc *proc_from_pid(u32 pid) void proc_exit(struct proc *proc, int status) { assert(proc); - printf("Process %s exited with status %d\n", proc->name, status); + int res = 0; struct node *iterator = proc_list->head; do { if (iterator->data == proc) { + res = 1; list_remove(proc_list, iterator); break; } } while ((iterator = iterator->next) != NULL); + if (memcmp(proc, current->data, sizeof(*proc)) == 0) + current = NULL; + + if (res) + printf("Process %s exited with status %d\n", proc->name, status); + quantum = 0; // TODO: Add quantum to each process struct? - sti(); - hlt(); } void proc_yield(struct regs *r) -- cgit v1.2.3