diff options
| author | Amlal <amlal@el-mahrouss-logic.com> | 2024-09-08 08:18:37 +0200 |
|---|---|---|
| committer | Amlal <amlal@el-mahrouss-logic.com> | 2024-09-08 08:18:37 +0200 |
| commit | df8a42aa1266d953a9ee473afe9f6349bd1837c7 (patch) | |
| tree | cad53c222ca90ee98ac82ee2d630a4ff0b0c3ee3 /dev/ZKA/Sources/UserProcessScheduler.cxx | |
| parent | 884ea5c2d43b6c8d4c2bb4fc33c11dc2313eeca2 (diff) | |
[dev/FeatureAdd] Add mm_new_class, as C++ new doesn't initialize class directly.
[dev/FeatureFix] CR2 set to invalid address due to stack corruption, fixing that.
Signed-off-by: Amlal <amlal@el-mahrouss-logic.com>
Diffstat (limited to 'dev/ZKA/Sources/UserProcessScheduler.cxx')
| -rw-r--r-- | dev/ZKA/Sources/UserProcessScheduler.cxx | 60 |
1 files changed, 37 insertions, 23 deletions
diff --git a/dev/ZKA/Sources/UserProcessScheduler.cxx b/dev/ZKA/Sources/UserProcessScheduler.cxx index eba81677..721bd02f 100644 --- a/dev/ZKA/Sources/UserProcessScheduler.cxx +++ b/dev/ZKA/Sources/UserProcessScheduler.cxx @@ -91,11 +91,11 @@ namespace Kernel { #ifdef __ZKA_AMD64__ auto pd = hal_read_cr3(); - hal_write_cr3(this->MemoryPD); + hal_write_cr3(reinterpret_cast<VoidPtr>(this->MemoryPD)); auto ptr = mm_new_ke_heap(sz, Yes, Yes); - hal_write_cr3(reinterpret_cast<UIntPtr>(pd)); + hal_write_cr3(reinterpret_cast<VoidPtr>(pd)); #else auto ptr = mm_new_ke_heap(sz, Yes, Yes); #endif @@ -143,10 +143,10 @@ namespace Kernel { #ifdef __ZKA_AMD64__ auto pd = hal_read_cr3(); - hal_write_cr3(this->MemoryPD); + hal_write_cr3(reinterpret_cast<VoidPtr>(this->MemoryPD)); bool ret = mm_delete_ke_heap(ptr); - hal_write_cr3(reinterpret_cast<UIntPtr>(pd)); + hal_write_cr3(reinterpret_cast<VoidPtr>(pd)); return ret; #else @@ -233,12 +233,17 @@ namespace Kernel /// @brief Add process to list. /// @param process the process *Ref* class. /// @return the process index inside the team. - SizeT UserProcessScheduler::Add(UserProcess& process) + SizeT UserProcessScheduler::Add(UserProcess process) { + if (mTeam.mProcessAmount > kSchedProcessLimitPerTeam) + return 0; + #ifdef __ZKA_AMD64__ process.MemoryPD = reinterpret_cast<UIntPtr>(hal_read_cr3()); #endif // __ZKA_AMD64__ + process.Status = ProcessStatusKind::kStarting; + process.StackFrame = (HAL::StackFramePtr)mm_new_ke_heap(sizeof(HAL::StackFrame), Yes, Yes); if (!process.StackFrame) @@ -268,21 +273,22 @@ namespace Kernel if (!process.StackReserve) { - process.Crash(); + mm_delete_ke_heap(process.StackFrame); + process.StackFrame = nullptr; return -kErrorProcessFault; } - if (mTeam.mProcessAmount > kSchedProcessLimitPerTeam) - mTeam.mProcessAmount = 0UL; - ++mTeam.mProcessAmount; process.ProcessId = mTeam.mProcessAmount; - process.Status = ProcessStatusKind::kStarting; + process.Status = ProcessStatusKind::kRunning; + + // avoid the pitfalls of moving process. + auto ret_pid = process.ProcessId; - mTeam.AsArray()[process.ProcessId] = process; + mTeam.AsArray()[process.ProcessId] = move(process); - return process.ProcessId; + return ret_pid; } /***********************************************************************************/ @@ -318,21 +324,21 @@ namespace Kernel SizeT process_index = 0; //! we store this guy to tell the scheduler how many //! things we have scheduled. - kcout << "Finding available process...\r"; - for (; process_index < mTeam.AsArray().Capacity(); ++process_index) { + kcout << "Grabbing available process...\r"; + auto& process = mTeam.AsArray()[process_index]; //! check if process needs to be scheduled. if (UserProcessHelper::CanBeScheduled(process)) { - // set the current process. - mTeam.AsRef() = process; + kcout << process.Name << ": will be runned.\r"; - process.PTime = static_cast<Int32>(process.Affinity); + // Set current process header. + this->CurrentProcess() = process; - kcout << process.Name << ": will be runned.\r"; + process.PTime = static_cast<Int32>(process.Affinity); // tell helper to find a core to schedule on. if (!UserProcessHelper::Switch(process.Image, &process.StackReserve[process.StackSize - 1], process.StackFrame, @@ -349,6 +355,8 @@ namespace Kernel } } + kcout << "Scheduled Process Count: " << number(process_index) << endl; + return process_index; } @@ -380,13 +388,17 @@ namespace Kernel /// @param process the process reference. /// @retval true can be schedulded. /// @retval false cannot be schedulded. - bool UserProcessHelper::CanBeScheduled(const UserProcess process) + bool UserProcessHelper::CanBeScheduled(const UserProcess& process) { + kcout << "Checking Status...\r"; + if (process.Status == ProcessStatusKind::kFrozen || process.Status == ProcessStatusKind::kDead) - return false; + return No; + + kcout << "Checking PTime...\r"; - return process.PTime < 1; + return process.PTime <= 0; } /** @@ -400,12 +412,14 @@ namespace Kernel { if (!cHardwareThreadScheduler) { - cHardwareThreadScheduler = new HardwareThreadScheduler(); + cHardwareThreadScheduler = mm_new_class<HardwareThreadScheduler>(); + MUST_PASS(cHardwareThreadScheduler); } if (!cProcessScheduler) { - cProcessScheduler = new UserProcessScheduler(); + cProcessScheduler = mm_new_class<UserProcessScheduler>(); + MUST_PASS(cProcessScheduler); } SizeT ret = cProcessScheduler->Run(); |
