From 11a4f8cc90fa5d6aea4016a769892d98b56fbad8 Mon Sep 17 00:00:00 2001 From: apio Date: Sun, 28 May 2023 21:50:13 +0200 Subject: [PATCH] kernel: Wake the parent process when a child exits because of a page fault --- kernel/src/arch/x86_64/CPU.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/kernel/src/arch/x86_64/CPU.cpp b/kernel/src/arch/x86_64/CPU.cpp index c1e503b0..5b8e957d 100644 --- a/kernel/src/arch/x86_64/CPU.cpp +++ b/kernel/src/arch/x86_64/CPU.cpp @@ -73,7 +73,22 @@ void decode_page_fault_error_code(u64 code) { // FIXME: Kill this process with SIGSEGV once we have signals and all that. kerrorln("Current task %zu was terminated because of a page fault", Scheduler::current()->id); - Scheduler::current()->state = ThreadState::Exited; + if (Scheduler::current()->is_kernel) Scheduler::current()->state = ThreadState::Dying; + else + { + auto* current = Scheduler::current(); + auto* parent = current->parent; + if (parent && parent->state == ThreadState::Waiting) + { + auto child = *parent->child_being_waited_for; + if (child == -1 || child == (pid_t)current->id) + { + parent->child_being_waited_for = (pid_t)current->id; + parent->wake_up(); + } + } + current->state = ThreadState::Exited; + } Scheduler::current()->status = 127; kernel_yield(); unreachable();