From fdc8aaab2ad3c2f2f3f4bb4ffb71bc2d797366aa Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Sat, 24 Aug 2024 17:30:52 +0200 Subject: [IMP] Better kernel design. + If the process has a parent, and it's exited, that means that the thread must go down as well. Signed-off-by: Amlal El Mahrouss --- dev/ZKA/Sources/ProcessScheduler.cxx | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) (limited to 'dev/ZKA/Sources/ProcessScheduler.cxx') diff --git a/dev/ZKA/Sources/ProcessScheduler.cxx b/dev/ZKA/Sources/ProcessScheduler.cxx index 9e0708e7..1d83e519 100644 --- a/dev/ZKA/Sources/ProcessScheduler.cxx +++ b/dev/ZKA/Sources/ProcessScheduler.cxx @@ -25,7 +25,7 @@ namespace Kernel { /***********************************************************************************/ - /// @brief Exit Code global + /// @brief Exit Code global variable. /***********************************************************************************/ STATIC Int32 cLastExitCode = 0U; @@ -44,11 +44,13 @@ namespace Kernel void PROCESS_HEADER_BLOCK::Crash() { - constexpr auto cUnknownProcess = "?"; + constexpr auto cUnknownProcess = "?"; kcout << (*this->Name == 0 ? cUnknownProcess : this->Name) << ": crashed. (id = " << number(kErrorProcessFault); kcout << ")\r"; + this->Status = ProcessStatus::kDead; + this->Exit(kErrorProcessFault); } @@ -60,6 +62,10 @@ namespace Kernel return this->fLastExitCode; } + /***********************************************************************************/ + /// @brief Error code variable getter. + /***********************************************************************************/ + Int32& PROCESS_HEADER_BLOCK::GetLocalCode() noexcept { return fLocalCode; @@ -146,9 +152,9 @@ namespace Kernel } /// @brief process selector getter. - const ProcessLevelRing& PROCESS_HEADER_BLOCK::GetLevelRing() noexcept + const User* PROCESS_HEADER_BLOCK::GetOwner() noexcept { - return this->Selector; + return this->AssignedOwner; } /// @brief process status getter. @@ -172,10 +178,6 @@ namespace Kernel */ void PROCESS_HEADER_BLOCK::Exit(const Int32& exit_code) { - if (this->ProcessId != - ProcessScheduler::The().Leak().TheCurrent().Leak().ProcessId) - ke_stop(RUNTIME_CHECK_PROCESS); - fLastExitCode = exit_code; cLastExitCode = exit_code; @@ -221,6 +223,13 @@ namespace Kernel kcout << "ProcessScheduler:: adding process to team...\r"; + if (process.Leak().GetOwner() == nullptr) + { + // Something went wrong, do not continue, process may be incorrect. + process.Leak().Crash(); + return -kErrorProcessFault; + } + // Create heap according to type of process. if (process.Leak().Kind == PROCESS_HEADER_BLOCK::kAppKind) { @@ -304,6 +313,12 @@ namespace Kernel { auto unwrapped_process = *process.Leak(); + if (unwrapped_process.Parent->Status == ProcessStatus::kKilled) + { + unwrapped_process.Exit(); + continue; + } + // set the current process. mTeam.AsRef() = unwrapped_process; @@ -313,7 +328,7 @@ namespace Kernel unwrapped_process.PTime = static_cast(unwrapped_process.Affinity); - kcout << unwrapped_process.Name << ": has been switched to process core.\r"; + kcout << unwrapped_process.Name << ": has been switched to a CPU core.\r"; } else { -- cgit v1.2.3