diff options
| author | Amlal El Mahrouss <amlalelmahrouss@icloud.com> | 2024-02-14 11:52:34 +0100 |
|---|---|---|
| committer | Amlal El Mahrouss <amlalelmahrouss@icloud.com> | 2024-02-14 11:52:34 +0100 |
| commit | c49a4199373d546703ea2016f188131648a39a68 (patch) | |
| tree | b7fb7ccd026b24f89a1bc0edc15ae5253d229455 /Private/Source/ProcessManager.cxx | |
| parent | f57ffb30b78efffde3b16572798d2b2dcffd04eb (diff) | |
HCR-18: Heap and scheduler improvements.
Signed-off-by: Amlal El Mahrouss <amlalelmahrouss@icloud.com>
Diffstat (limited to 'Private/Source/ProcessManager.cxx')
| -rw-r--r-- | Private/Source/ProcessManager.cxx | 41 |
1 files changed, 27 insertions, 14 deletions
diff --git a/Private/Source/ProcessManager.cxx b/Private/Source/ProcessManager.cxx index 07f73ef3..ccf037ae 100644 --- a/Private/Source/ProcessManager.cxx +++ b/Private/Source/ProcessManager.cxx @@ -18,6 +18,8 @@ #include <NewKit/KernelHeap.hpp> #include <NewKit/String.hpp> +#include "NewKit/RuntimeCheck.hpp" + ///! bugs = 0 /***********************************************************************************/ @@ -54,10 +56,9 @@ void Process::Wake(const bool should_wakeup) { VoidPtr Process::New(const SizeT &sz) { if (this->FreeMemory < 1) return nullptr; - // RAM allocation - if (this->PoolCursor) { - VoidPtr ptr = this->PoolCursor; - this->PoolCursor = (VoidPtr)((UIntPtr)this->PoolCursor + (sizeof(sz))); + if (this->HeapCursor) { + VoidPtr ptr = this->HeapCursor; + this->HeapCursor = (VoidPtr)((UIntPtr)this->HeapCursor + (sizeof(sz))); ++this->UsedMemory; --this->FreeMemory; @@ -86,13 +87,13 @@ bool rt_in_pool_region(VoidPtr pool_ptr, VoidPtr pool, const SizeT &sz) { /* @brief free pointer from usage. */ Boolean Process::Delete(VoidPtr ptr, const SizeT &sz) { - if (sz < 1 || this->PoolCursor == this->Pool) return false; + if (sz < 1 || this->HeapCursor == this->HeapPtr) 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))); + if (rt_in_pool_region(ptr, this->HeapCursor, this->UsedMemory)) { + this->HeapCursor = (VoidPtr)((UIntPtr)this->HeapCursor - (sizeof(sz))); rt_zero_memory(ptr, sz); ++this->FreeMemory; @@ -131,12 +132,11 @@ void Process::Exit(Int32 exit_code) { kExitCode = exit_code; - if (this->Ring != (Int32)ProcessSelector::kRingDriver && - this->Ring != (Int32)ProcessSelector::kRingKernel) { - if (this->Pool) ke_free_heap(this->Pool); + if (this->Ring != (Int32)ProcessSelector::kRingDriver) { + if (this->HeapPtr) ke_free_heap(this->HeapPtr); - this->Pool = nullptr; - this->PoolCursor = nullptr; + this->HeapPtr = nullptr; + this->HeapCursor = nullptr; this->FreeMemory = 0UL; // TODO: fill available heap. this->UsedMemory = 0UL; @@ -155,11 +155,13 @@ void Process::Exit(Int32 exit_code) { bool ProcessManager::Add(Ref<Process> &process) { if (!process) return false; + if (process.Leak().Ring != (Int32)ProcessSelector::kRingKernel) return false; + kcout << "ProcessManager::Add(Ref<Process>& process)\r\n"; - process.Leak().Pool = ke_new_heap(kPoolUser | kPoolRw); + process.Leak().HeapPtr = ke_new_heap(kPoolUser | kPoolRw); process.Leak().ProcessId = this->m_Headers.Count(); - process.Leak().PoolCursor = process.Leak().Pool; + process.Leak().HeapCursor = process.Leak().HeapPtr; process.Leak().StackFrame = reinterpret_cast<HAL::StackFrame *>( ke_new_ke_heap(sizeof(HAL::StackFrame), true, false)); @@ -172,6 +174,17 @@ bool ProcessManager::Add(Ref<Process> &process) { this->m_Headers.Add(process); + if (!imageStart && process.Leak().Kind == Process::ExecutableType) { + process.Leak().Crash(); + } + + if (!imageStart && process.Leak().Kind == Process::DriverType) { + if (process.Leak().Ring == 3) + process.Leak().Crash(); + else + ke_stop(RUNTIME_CHECK_PROCESS); + } + return true; } |
