diff options
| author | Amlal El Mahrouss <amlal@el-mahrouss-logic.com> | 2024-03-20 18:24:58 +0100 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal@el-mahrouss-logic.com> | 2024-03-20 18:25:02 +0100 |
| commit | f48c5b2cda43241919d3ea1b263bef01e014c537 (patch) | |
| tree | 5bf74621fcff0a98163b3908d35cef2a6339bfb7 /Private/Source/KernelHeap.cxx | |
| parent | 4ba02280f19b8a2beb1ad8445be7df6b7f9e1805 (diff) | |
Kernel: See below.
- Fix: Kernel page alloc. Inside HalPageAlloc.cpp.
- Made NewFSJournalRunner fields private.
- Rework StorageKit for current ticket 14.
- :boom: Breaking changes to virtual memory api.
Signed-off-by: Amlal El Mahrouss <amlal@el-mahrouss-logic.com>
Diffstat (limited to 'Private/Source/KernelHeap.cxx')
| -rw-r--r-- | Private/Source/KernelHeap.cxx | 32 |
1 files changed, 20 insertions, 12 deletions
diff --git a/Private/Source/KernelHeap.cxx b/Private/Source/KernelHeap.cxx index 359e3cbd..438df005 100644 --- a/Private/Source/KernelHeap.cxx +++ b/Private/Source/KernelHeap.cxx @@ -4,8 +4,9 @@ ------------------------------------------- */ -#include <NewKit/Crc32.hpp> +#include <KernelKit/DebugOutput.hpp> #include <KernelKit/KernelHeap.hpp> +#include <NewKit/Crc32.hpp> #include <NewKit/PageManager.hpp> //! @file KernelHeap.cxx @@ -14,19 +15,19 @@ #define kHeapMagic 0xD4D7 namespace HCore { -STATIC SizeT kHeapCount = 0UL; -STATIC Ref<PTEWrapper> kHeapLastWrapper; -STATIC PageManager kHeapPageManager; +STATIC SizeT kHeapCount = 0UL; +STATIC Ref<PTEWrapper> kHeapLastWrapper; +STATIC PageManager kHeapPageManager; namespace Detail { /// @brief Kernel heap information block. /// Located before the address bytes. /// | HIB | ADDRESS | struct HeapInformationBlock final { - UInt16 hMagic; + UInt16 hMagic; Boolean hPresent; - Int32 hCRC32; - Int64 hSizeAddress; + Int32 hCRC32; + Int64 hSizeAddress; UIntPtr hAddress; }; @@ -44,17 +45,21 @@ VoidPtr ke_new_ke_heap(SizeT sz, const bool rw, const bool user) { auto wrapper = kHeapPageManager.Request(rw, user, false); kHeapLastWrapper = wrapper; + kcout << "HCoreKrnl.exe: Populating HIB...\r\n"; + Detail::HeapInformationBlockPtr heapInfo = reinterpret_cast<Detail::HeapInformationBlockPtr>( wrapper.VirtualAddress()); heapInfo->hSizeAddress = sz; heapInfo->hMagic = kHeapMagic; - heapInfo->hCRC32 = 0; // dont fill it for now. + heapInfo->hCRC32 = 0; // dont fill it for now. heapInfo->hAddress = wrapper.VirtualAddress(); ++kHeapCount; + kcout << "HCoreKrnl.exe: Return address...\r\n"; + return reinterpret_cast<VoidPtr>(wrapper.VirtualAddress() + sizeof(Detail::HeapInformationBlock)); } @@ -70,8 +75,10 @@ Int32 ke_delete_ke_heap(VoidPtr ptr) { if (kHeapLastWrapper && virtualAddress->hMagic == kHeapMagic && virtualAddress->hAddress == kHeapLastWrapper.Leak().VirtualAddress()) { - virtualAddress->hSizeAddress = 0UL; - virtualAddress->hPresent = false; + virtualAddress->hSizeAddress = 0UL; + virtualAddress->hPresent = false; + + --kHeapCount; return true; } @@ -84,13 +91,14 @@ Int32 ke_delete_ke_heap(VoidPtr ptr) { /// @param ptr the pointer /// @return if it exists. Boolean ke_is_valid_ptr(VoidPtr ptr) { + if (kHeapCount < 1) return false; + if (ptr) { Detail::HeapInformationBlockPtr virtualAddress = reinterpret_cast<Detail::HeapInformationBlockPtr>(ptr) - sizeof(Detail::HeapInformationBlock); - if (virtualAddress->hPresent && - virtualAddress->hMagic == kHeapMagic) { + if (virtualAddress->hPresent && virtualAddress->hMagic == kHeapMagic) { return true; } } |
