diff options
| -rw-r--r-- | Private/HALKit/AMD64/ProcessPrimitives.cxx | 26 | ||||
| -rw-r--r-- | Private/KernelKit/ProcessManager.hpp | 352 | ||||
| -rw-r--r-- | Private/Source/ProcessManager.cxx | 410 |
3 files changed, 421 insertions, 367 deletions
diff --git a/Private/HALKit/AMD64/ProcessPrimitives.cxx b/Private/HALKit/AMD64/ProcessPrimitives.cxx new file mode 100644 index 00000000..f5b19861 --- /dev/null +++ b/Private/HALKit/AMD64/ProcessPrimitives.cxx @@ -0,0 +1,26 @@ +/* + * ======================================================== + * + * hCore + * Copyright 2024 Mahrouss Logic, all rights reserved. + * + * ======================================================== + */ + +#include "NewKit/Defines.hpp" +#include <KernelKit/ProcessManager.hpp> + +using namespace hCore; + +Void Process::AssignStart(UIntPtr &imageStart) noexcept +{ + if (imageStart == 0) + this->Crash(); + +#ifdef __x86_64__ + this->StackFrame->Rbp = imageStart; +#elif defined(__powerpc) + // link return register towards the __start symbol. + this->StackFrame->R3 = imageStart; +#endif +} diff --git a/Private/KernelKit/ProcessManager.hpp b/Private/KernelKit/ProcessManager.hpp index 6474ec04..cc96a18c 100644 --- a/Private/KernelKit/ProcessManager.hpp +++ b/Private/KernelKit/ProcessManager.hpp @@ -9,12 +9,13 @@ #pragma once -#include <KernelKit/PermissionSelector.hxx> -#include <KernelKit/FileManager.hpp> -#include <NewKit/MutableArray.hpp> -#include <NewKit/LockDelegate.hpp> +#include "NewKit/Defines.hpp" #include <ArchKit/Arch.hpp> +#include <KernelKit/FileManager.hpp> +#include <KernelKit/PermissionSelector.hxx> #include <NewKit/Heap.hpp> +#include <NewKit/LockDelegate.hpp> +#include <NewKit/MutableArray.hpp> #define kMinMicroTime AffinityKind::kStandard @@ -22,202 +23,213 @@ namespace hCore { - //! @brief Process identifier. - typedef Int64 ProcessID; +//! @brief Process identifier. +typedef Int64 ProcessID; - //! @brief Process name length. - inline constexpr SizeT kProcessLen = 256U; +//! @brief Process name length. +inline constexpr SizeT kProcessLen = 256U; - //! @brief Forward declaration. - class Process; - class ProcessManager; - class ProcessHelper; +//! @brief Forward declaration. +class Process; +class ProcessManager; +class ProcessHelper; - //! @brief Process status enum. - enum class ProcessStatus : Int32 - { - kStarting, - kRunning, - kKilled, - kFrozen, - kDead - }; - - //! @brief Affinity is the amount of nano-seconds this process is going - //! to run. - enum class AffinityKind : Int32 - { - kInvalid = 300, - kVeryHigh = 250, - kHigh = 200, - kStandard = 150, - kLowUsage = 100, - kVeryLowUsage = 50, - }; - - // operator overloading. - - inline bool operator<(AffinityKind lhs, AffinityKind rhs) - { - Int32 lhs_int = static_cast<Int>(lhs); - Int32 rhs_int = static_cast<Int>(rhs); +//! @brief Process status enum. +enum class ProcessStatus : Int32 +{ + kStarting, + kRunning, + kKilled, + kFrozen, + kDead +}; + +//! @brief Affinity is the amount of nano-seconds this process is going +//! to run. +enum class AffinityKind : Int32 +{ + kInvalid = 300, + kVeryHigh = 250, + kHigh = 200, + kStandard = 150, + kLowUsage = 100, + kVeryLowUsage = 50, +}; - return lhs_int < rhs_int; - } +// operator overloading. - inline bool operator>(AffinityKind lhs, AffinityKind rhs) - { - Int32 lhs_int = static_cast<Int>(lhs); - Int32 rhs_int = static_cast<Int>(rhs); +inline bool operator<(AffinityKind lhs, AffinityKind rhs) +{ + Int32 lhs_int = static_cast<Int>(lhs); + Int32 rhs_int = static_cast<Int>(rhs); - return lhs_int > rhs_int; - } + return lhs_int < rhs_int; +} - inline bool operator<=(AffinityKind lhs, AffinityKind rhs) - { - Int32 lhs_int = static_cast<Int>(lhs); - Int32 rhs_int = static_cast<Int>(rhs); +inline bool operator>(AffinityKind lhs, AffinityKind rhs) +{ + Int32 lhs_int = static_cast<Int>(lhs); + Int32 rhs_int = static_cast<Int>(rhs); - return lhs_int <= rhs_int; - } + return lhs_int > rhs_int; +} - inline bool operator>=(AffinityKind lhs, AffinityKind rhs) - { - Int32 lhs_int = static_cast<Int>(lhs); - Int32 rhs_int = static_cast<Int>(rhs); +inline bool operator<=(AffinityKind lhs, AffinityKind rhs) +{ + Int32 lhs_int = static_cast<Int>(lhs); + Int32 rhs_int = static_cast<Int>(rhs); - return lhs_int >= rhs_int; - } + return lhs_int <= rhs_int; +} - // end of operator overloading. +inline bool operator>=(AffinityKind lhs, AffinityKind rhs) +{ + Int32 lhs_int = static_cast<Int>(lhs); + Int32 rhs_int = static_cast<Int>(rhs); - using ProcessSubsystem = UInt32; - using ProcessTime = UInt64; - using PID = Int64; - - // for permission manager, tells where we run the code. - enum class ProcessSelector : Int - { - kRingUser, /* user ring (or ring 3 in x86) */ - kRingDriver, /* ring 2 in x86, hypervisor privileges in other archs */ - kRingKernel, /* machine privileges */ - }; + return lhs_int >= rhs_int; +} - // Helper types. - using ImagePtr = VoidPtr; - using HeapPtr = VoidPtr; +// end of operator overloading. + +using ProcessSubsystem = UInt32; +using ProcessTime = UInt64; +using PID = Int64; + +// for permission manager, tells where we run the code. +enum class ProcessSelector : Int +{ + kRingUser, /* user ring (or ring 3 in x86) */ + kRingDriver, /* ring 2 in x86, hypervisor privileges in other archs */ + kRingKernel, /* machine privileges */ +}; - // @brief Process header structure. - class Process final +// Helper types. +using ImagePtr = VoidPtr; +using HeapPtr = VoidPtr; + +// @brief Process header structure. +class Process final +{ + public: + explicit Process(VoidPtr startImage = nullptr) : Image(startImage) { - public: - explicit Process(VoidPtr startImage = nullptr) : Image(startImage) { MUST_PASS(startImage); } - ~Process() = default; - - HCORE_COPY_DEFAULT(Process) - - private: - Char Name[kProcessLen] = { "hCore Process" }; - ProcessSubsystem SubSystem; - ProcessSelector Selector; - HAL::StackFrame* StackFrame{ nullptr }; - AffinityKind Affinity; - ProcessStatus Status; - - // Memory, images. - HeapPtr PoolCursor{ nullptr }; - ImagePtr Image{ nullptr }; - HeapPtr Pool{ nullptr }; - - // memory usage - SizeT UsedMemory{ 0 }; - SizeT FreeMemory{ 0 }; - - ProcessTime PTime; - PID ProcessId{ -1 }; - Int32 Ring{ 3 }; - - public: - //! @brief boolean operator, check status. - operator bool() { return Status != ProcessStatus::kDead; } - - //! @brief Crash program, exits with code ~0. - void Crash(); - - //! @brief Exits program. - void Exit(Int32 exit_code = 0); - - //! @brief TLS new - VoidPtr New(const SizeT& sz); - - //! @brief TLS delete. - Boolean Delete(VoidPtr ptr, const SizeT& sz); - - //! @brief Process name getter, example: "C RunTime" - const Char* GetName(); - - //! @brief Wakes up threads. - void Wake(const bool wakeup = false); - - public: - const ProcessSelector& GetSelector(); - const ProcessStatus& GetStatus(); - const AffinityKind& GetAffinity(); - - private: - friend ProcessManager; - friend ProcessHelper; - - }; - - using ProcessPtr = Process*; - - //! @brief Kernel scheduler.. - class ProcessManager final + MUST_PASS(startImage); + } + ~Process() = default; + + HCORE_COPY_DEFAULT(Process) + + public: + void AssignStart(UIntPtr &imageStart) noexcept; + + private: + Char Name[kProcessLen] = {"hCore Process"}; + ProcessSubsystem SubSystem; + ProcessSelector Selector; + HAL::StackFrame *StackFrame{nullptr}; + AffinityKind Affinity; + ProcessStatus Status; + + // Memory, images. + HeapPtr PoolCursor{nullptr}; + ImagePtr Image{nullptr}; + HeapPtr Pool{nullptr}; + + // memory usage + SizeT UsedMemory{0}; + SizeT FreeMemory{0}; + + ProcessTime PTime; + PID ProcessId{-1}; + Int32 Ring{3}; + + public: + //! @brief boolean operator, check status. + operator bool() { - private: - explicit ProcessManager() = default; + return Status != ProcessStatus::kDead; + } - public: - ~ProcessManager() = default; + //! @brief Crash program, exits with code ~0. + void Crash(); - HCORE_COPY_DEFAULT(ProcessManager) + //! @brief Exits program. + void Exit(Int32 exit_code = 0); - operator bool() { return m_Headers.Count() > 0; } - bool operator!() { return m_Headers.Count() == 0; } + //! @brief TLS new + VoidPtr New(const SizeT &sz); - bool Add(Ref<Process> &Header); - bool Remove(SizeT Header); + //! @brief TLS delete. + Boolean Delete(VoidPtr ptr, const SizeT &sz); - Ref<Process>& GetCurrent(); - SizeT Run() noexcept; + //! @brief Process name getter, example: "C RunTime" + const Char *GetName(); - static Ref<ProcessManager> Shared(); + //! @brief Wakes up threads. + void Wake(const bool wakeup = false); - private: - MutableArray<Ref<Process>> m_Headers; - Ref<Process> m_CurrentProcess; + public: + const ProcessSelector &GetSelector(); + const ProcessStatus &GetStatus(); + const AffinityKind &GetAffinity(); - }; + private: + friend ProcessManager; + friend ProcessHelper; +}; + +using ProcessPtr = Process *; + +//! @brief Kernel scheduler.. +class ProcessManager final +{ + private: + explicit ProcessManager() = default; - /* - * Just a helper class, which contains some utilities for the scheduler. - */ + public: + ~ProcessManager() = default; - class ProcessHelper final + HCORE_COPY_DEFAULT(ProcessManager) + + operator bool() + { + return m_Headers.Count() > 0; + } + bool operator!() { - public: - static bool Switch(HAL::StackFrame* newStack, const PID& newPid); - static bool CanBeScheduled(Ref<Process>& process); - static PID& GetCurrentPID(); - static bool StartScheduling(); + return m_Headers.Count() == 0; + } + + bool Add(Ref<Process> &Header); + bool Remove(SizeT Header); + + Ref<Process> &GetCurrent(); + SizeT Run() noexcept; + + static Ref<ProcessManager> Shared(); - }; + private: + MutableArray<Ref<Process>> m_Headers; + Ref<Process> m_CurrentProcess; +}; - const Int32 &rt_get_exit_code() noexcept; +/* + * Just a helper class, which contains some utilities for the scheduler. + */ + +class ProcessHelper final +{ + public: + static bool Switch(HAL::StackFrame *newStack, const PID &newPid); + static bool CanBeScheduled(Ref<Process> &process); + static PID &GetCurrentPID(); + static bool StartScheduling(); +}; + +const Int32 &rt_get_exit_code() noexcept; } // namespace hCore #include <KernelKit/ThreadLocalStorage.hxx> - -////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
\ No newline at end of file +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/Private/Source/ProcessManager.cxx b/Private/Source/ProcessManager.cxx index f37badee..5dcc98f2 100644 --- a/Private/Source/ProcessManager.cxx +++ b/Private/Source/ProcessManager.cxx @@ -24,275 +24,291 @@ namespace hCore { - static Int32 kExitCode = 0; +static Int32 kExitCode = 0; - const Int32& rt_get_exit_code() noexcept { return kExitCode; } +const Int32 &rt_get_exit_code() noexcept +{ + return kExitCode; +} - void Process::Crash() - { - kcout << this->Name << ": Crashed."; - this->Exit(-1); - } +void Process::Crash() +{ + kcout << this->Name << ": Crashed."; + this->Exit(-1); +} - void Process::Wake(const bool should_wakeup) - { - this->Status = should_wakeup ? ProcessStatus::kRunning : ProcessStatus::kFrozen; - } +void Process::Wake(const bool should_wakeup) +{ + this->Status = should_wakeup ? ProcessStatus::kRunning : ProcessStatus::kFrozen; +} - VoidPtr Process::New(const SizeT& sz) - { - // RAM allocation - if (this->PoolCursor) - { - VoidPtr ptr = this->PoolCursor; - this->PoolCursor = (VoidPtr)((UIntPtr)this->PoolCursor + (sizeof(sz) + kPoolAlign)); +VoidPtr Process::New(const SizeT &sz) +{ + if (this->FreeMemory < 1) + return nullptr; - return ptr; - } + // RAM allocation + if (this->PoolCursor) + { + VoidPtr ptr = this->PoolCursor; + this->PoolCursor = (VoidPtr)((UIntPtr)this->PoolCursor + (sizeof(sz) + kPoolAlign)); - //! TODO: Disk allocation + ++this->UsedMemory; + --this->FreeMemory; - return nullptr; + return ptr; } - /* @brief checks if runtime pointer is in region. */ - bool rt_in_pool_region(VoidPtr pool_ptr, VoidPtr pool, const SizeT& sz) + //! TODO: Disk allocation + + return nullptr; +} + +/* @brief checks if runtime pointer is in region. */ +bool rt_in_pool_region(VoidPtr pool_ptr, VoidPtr pool, const SizeT &sz) +{ + Char *_pool_ptr = (Char *)pool_ptr; + Char *_pool = (Char *)pool; + + for (SizeT index = sz; _pool[sz] != 0x55; --index) { - Char* _pool_ptr = (Char*)pool_ptr; - Char* _pool = (Char*)pool; + if (&_pool[index] > &_pool_ptr[sz]) + continue; - for (SizeT index = sz; _pool[sz] != 0x55; --index) - { - if (&_pool[index] > &_pool_ptr[sz]) - continue; + if (_pool[index] == _pool_ptr[index]) + return true; + } - if (_pool[index] == _pool_ptr[index]) - return true; - } + return false; +} +/* @brief free pointer from usage. */ +Boolean Process::Delete(VoidPtr ptr, const SizeT &sz) +{ + if (sz < 1 || this->PoolCursor == this->Pool) return false; - } - /* @brief free pointer from usage. */ - Boolean Process::Delete(VoidPtr ptr, const SizeT& sz) - { - if (sz < 1 || - this->PoolCursor == this->Pool) - return false; + // also check for the amount of allocations we've done so far. + if (this->UsedMemory < 1) + return false; - if (rt_in_pool_region(ptr, this->PoolCursor, this->UsedMemory)) - { - this->PoolCursor = (VoidPtr)((UIntPtr)this->PoolCursor - (sizeof(sz) - kPoolAlign)); - rt_zero_memory(ptr, sz); + if (rt_in_pool_region(ptr, this->PoolCursor, this->UsedMemory)) + { + this->PoolCursor = (VoidPtr)((UIntPtr)this->PoolCursor - (sizeof(sz) - kPoolAlign)); + rt_zero_memory(ptr, sz); - return true; - } + ++this->FreeMemory; + --this->UsedMemory; - return false; + return true; } - const Char* Process::GetName() { return this->Name; } + return false; +} - const ProcessSelector& Process::GetSelector() { return this->Selector; } +const Char *Process::GetName() +{ + return this->Name; +} - const ProcessStatus& Process::GetStatus() { return this->Status; } +const ProcessSelector &Process::GetSelector() +{ + return this->Selector; +} - const AffinityKind& Process::GetAffinity() { return this->Affinity; } +const ProcessStatus &Process::GetStatus() +{ + return this->Status; +} - void Process::Exit(Int32 exit_code) +const AffinityKind &Process::GetAffinity() +{ + return this->Affinity; +} + +void Process::Exit(Int32 exit_code) +{ + if (this->ProcessId != ProcessManager::Shared().Leak().GetCurrent().Leak().ProcessId) + return; + + if (this->Ring == (Int32)ProcessSelector::kRingKernel && + ProcessManager::Shared().Leak().GetCurrent().Leak().Ring > 0) + return; + + kExitCode = exit_code; + + if (this->Ring != (Int32)ProcessSelector::kRingDriver && this->Ring != (Int32)ProcessSelector::kRingKernel) { - if (this->ProcessId != ProcessManager::Shared().Leak().GetCurrent().Leak().ProcessId) - return; + pool_free_ptr(this->Pool); - if (this->Ring == (Int32)ProcessSelector::kRingKernel && - ProcessManager::Shared().Leak().GetCurrent().Leak().Ring > 0) - return; + this->PoolCursor = nullptr; - kExitCode = exit_code; + this->FreeMemory = kPoolMaxSz; + this->UsedMemory = 0UL; + } - if (this->Ring != (Int32)ProcessSelector::kRingDriver && - this->Ring != (Int32)ProcessSelector::kRingKernel) - { - pool_free_ptr(this->Pool); + //! Delete image if not done already. + if (this->Image) + kernel_delete_ptr(this->Image); - this->PoolCursor = nullptr; + if (this->StackFrame) + kernel_delete_ptr((VoidPtr)this->StackFrame); - this->FreeMemory = kPoolMaxSz; - this->UsedMemory = 0UL; - } + ProcessManager::Shared().Leak().Remove(this->ProcessId); +} - //! Delete image if not done already. - if (this->Image) - kernel_delete_ptr(this->Image); +bool ProcessManager::Add(Ref<Process> &process) +{ + if (!process) + return false; - if (this->StackFrame) - kernel_delete_ptr((VoidPtr)this->StackFrame); + kcout << "ProcessManager::Add(Ref<Process>& process)\r\n"; - ProcessManager::Shared().Leak().Remove(this->ProcessId); - } + process.Leak().Pool = pool_new_ptr(kPoolUser | kPoolRw); + process.Leak().ProcessId = this->m_Headers.Count(); + process.Leak().PoolCursor = process.Leak().Pool; - bool ProcessManager::Add(Ref<Process>& process) - { - if (!process) - return false; + process.Leak().StackFrame = + reinterpret_cast<HAL::StackFrame *>(kernel_new_ptr(sizeof(HAL::StackFrame), true, false)); + + MUST_PASS(process.Leak().StackFrame); - kcout << "ProcessManager::Add(Ref<Process>& process)\r\n"; + UIntPtr imageStart = reinterpret_cast<UIntPtr>(process.Leak().Image); - process.Leak().Pool = pool_new_ptr(kPoolUser | kPoolRw); - process.Leak().ProcessId = this->m_Headers.Count(); - process.Leak().PoolCursor = process.Leak().Pool; + process.Leak().AssignStart(imageStart); - process.Leak().StackFrame = reinterpret_cast<HAL::StackFrame*>( - kernel_new_ptr(sizeof(HAL::StackFrame), true, false) - ); + this->m_Headers.Add(process); - MUST_PASS(process.Leak().StackFrame); + return true; +} - UIntPtr imageStart = reinterpret_cast<UIntPtr>( - process.Leak().Image - ); +bool ProcessManager::Remove(SizeT process) +{ + if (process > this->m_Headers.Count()) + return false; -#ifdef __x86_64__ - process.Leak().StackFrame->Rbp = imageStart; -#elif defined(__powerpc) - // link return register towards the __start symbol. - process.Leak().StackFrame->R3 = imageStart; -#endif + kcout << "ProcessManager::Remove(SizeT process)\r\n"; - this->m_Headers.Add(process); + return this->m_Headers.Remove(process); +} - return true; - } +SizeT ProcessManager::Run() noexcept +{ + SizeT processIndex = 0; //! we store this guy to tell the scheduler how many things we + //! have scheduled. - bool ProcessManager::Remove(SizeT process) + for (; processIndex < this->m_Headers.Count(); ++processIndex) { - if (process > this->m_Headers.Count()) - return false; + auto process = this->m_Headers[processIndex]; + MUST_PASS( + process); //! no need for a MUST_PASS(process.Leak());, it is recursive because of the nature of the class; - kcout << "ProcessManager::Remove(SizeT process)\r\n"; + //! run any process needed to be scheduled. + if (ProcessHelper::CanBeScheduled(process.Leak())) + { + auto unwrapped_process = *process.Leak(); - return this->m_Headers.Remove(process); - } + unwrapped_process.PTime = 0; - SizeT ProcessManager::Run() noexcept - { - SizeT processIndex = 0; //! we store this guy to tell the scheduler how many things we - //! have scheduled. + // set the current process. + m_CurrentProcess = unwrapped_process; - for (; processIndex < this->m_Headers.Count(); ++processIndex) + ProcessHelper::Switch(m_CurrentProcess.Leak().StackFrame, m_CurrentProcess.Leak().ProcessId); + } + else { - auto process = this->m_Headers[processIndex]; - MUST_PASS(process); //! no need for a MUST_PASS(process.Leak());, it is recursive because of the nature of the class; - - //! run any process needed to be scheduled. - if (ProcessHelper::CanBeScheduled(process.Leak())) - { - auto unwrapped_process = *process.Leak(); - - unwrapped_process.PTime = 0; - - // set the current process. - m_CurrentProcess = unwrapped_process; - - ProcessHelper::Switch(m_CurrentProcess.Leak().StackFrame, - m_CurrentProcess.Leak().ProcessId); - } - else - { - // otherwise increment the micro-time. - ++m_CurrentProcess.Leak().PTime; - } + // otherwise increment the micro-time. + ++m_CurrentProcess.Leak().PTime; } - - return processIndex; } - Ref<ProcessManager> ProcessManager::Shared() - { - static ProcessManager ref; - return { ref }; - } + return processIndex; +} - Ref<Process>& ProcessManager::GetCurrent() - { - return m_CurrentProcess; - } +Ref<ProcessManager> ProcessManager::Shared() +{ + static ProcessManager ref; + return {ref}; +} - PID& ProcessHelper::GetCurrentPID() - { - kcout << "ProcessHelper::GetCurrentPID\r\n"; - return ProcessManager::Shared().Leak().GetCurrent().Leak().ProcessId; - } +Ref<Process> &ProcessManager::GetCurrent() +{ + return m_CurrentProcess; +} - bool ProcessHelper::CanBeScheduled(Ref<Process>& process) - { - if (process.Leak().Status == ProcessStatus::kFrozen || - process.Leak().Status == ProcessStatus::kDead) - return false; +PID &ProcessHelper::GetCurrentPID() +{ + kcout << "ProcessHelper::GetCurrentPID\r\n"; + return ProcessManager::Shared().Leak().GetCurrent().Leak().ProcessId; +} - if (process.Leak().GetStatus() == ProcessStatus::kStarting) - { - if (process.Leak().PTime < static_cast<Int>(kMinMicroTime)) - { - process.Leak().Status = ProcessStatus::kRunning; - process.Leak().Affinity = AffinityKind::kStandard; +bool ProcessHelper::CanBeScheduled(Ref<Process> &process) +{ + if (process.Leak().Status == ProcessStatus::kFrozen || process.Leak().Status == ProcessStatus::kDead) + return false; - return true; - } + if (process.Leak().GetStatus() == ProcessStatus::kStarting) + { + if (process.Leak().PTime < static_cast<Int>(kMinMicroTime)) + { + process.Leak().Status = ProcessStatus::kRunning; + process.Leak().Affinity = AffinityKind::kStandard; - ++process.Leak().PTime; + return true; } - return process.Leak().PTime > static_cast<Int>(kMinMicroTime); + ++process.Leak().PTime; } - bool ProcessHelper::StartScheduling() + return process.Leak().PTime > static_cast<Int>(kMinMicroTime); +} + +bool ProcessHelper::StartScheduling() +{ + if (ProcessHelper::CanBeScheduled(ProcessManager::Shared().Leak().GetCurrent())) { - if (ProcessHelper::CanBeScheduled(ProcessManager::Shared().Leak().GetCurrent())) - { - --ProcessManager::Shared().Leak().GetCurrent().Leak().PTime; - return false; - } + --ProcessManager::Shared().Leak().GetCurrent().Leak().PTime; + return false; + } - auto process_ref = ProcessManager::Shared().Leak(); + auto process_ref = ProcessManager::Shared().Leak(); - if (!process_ref) - return false; // we have nothing to schedule. simply return. + if (!process_ref) + return false; // we have nothing to schedule. simply return. - SizeT ret = process_ref.Run(); + SizeT ret = process_ref.Run(); - kcout << StringBuilder::FromInt("ProcessHelper::StartScheduling() iterated over: % processes\r\n", ret); + kcout << StringBuilder::FromInt("ProcessHelper::StartScheduling() iterated over: % processes\r\n", ret); - return true; - } + return true; +} - bool ProcessHelper::Switch(HAL::StackFrame* the_stack, const PID& new_pid) - { - if (!the_stack || - new_pid < 0) - return false; +bool ProcessHelper::Switch(HAL::StackFrame *the_stack, const PID &new_pid) +{ + if (!the_stack || new_pid < 0) + return false; - for (SizeT index = 0UL; index < kMaxHarts; ++index) + for (SizeT index = 0UL; index < kMaxHarts; ++index) + { + if (SMPManager::Shared().Leak()[index].Leak().StackFrame() == the_stack) { - if (SMPManager::Shared().Leak()[index].Leak().StackFrame() == the_stack) - { - SMPManager::Shared().Leak()[index].Leak().Busy(false); - continue; - } - - if (SMPManager::Shared().Leak()[index].Leak().IsBusy()) - continue; - - if (SMPManager::Shared().Leak()[index].Leak().Kind() != ThreadKind::kBoot || - SMPManager::Shared().Leak()[index].Leak().Kind() != ThreadKind::kSystemReserved) - { - SMPManager::Shared().Leak()[index].Leak().Busy(true); - ProcessHelper::GetCurrentPID() = new_pid; - - return SMPManager::Shared().Leak()[index].Leak().Switch(the_stack); - } + SMPManager::Shared().Leak()[index].Leak().Busy(false); + continue; } - return false; + if (SMPManager::Shared().Leak()[index].Leak().IsBusy()) + continue; + + if (SMPManager::Shared().Leak()[index].Leak().Kind() != ThreadKind::kBoot || + SMPManager::Shared().Leak()[index].Leak().Kind() != ThreadKind::kSystemReserved) + { + SMPManager::Shared().Leak()[index].Leak().Busy(true); + ProcessHelper::GetCurrentPID() = new_pid; + + return SMPManager::Shared().Leak()[index].Leak().Switch(the_stack); + } } + + return false; +} } // namespace hCore |
