diff options
| author | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2024-07-09 20:51:20 +0200 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2024-07-09 20:52:00 +0200 |
| commit | dfaf137915094e7ba72f7d7f1f57dc5158d1b6ab (patch) | |
| tree | 802a5bf263d606b59bb52d5e7434a04c8644d07e /Kernel/Sources/KernelHeap.cxx | |
| parent | 891245c6c9a78cea6074e336d1b04a2264b2fcce (diff) | |
MHR-36: A set of major fixes for bootloader and kernel alongside new
implementations.
- Implement realloc for kernel scheduler improvements.
- Fixed readAll on bootloader's BFileReader.
- Add resources for zeta installation.
- Add STB header.
- Process Heap which replaced the previous User Heap.
Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'Kernel/Sources/KernelHeap.cxx')
| -rw-r--r-- | Kernel/Sources/KernelHeap.cxx | 36 |
1 files changed, 30 insertions, 6 deletions
diff --git a/Kernel/Sources/KernelHeap.cxx b/Kernel/Sources/KernelHeap.cxx index 295c4e76..2cf89480 100644 --- a/Kernel/Sources/KernelHeap.cxx +++ b/Kernel/Sources/KernelHeap.cxx @@ -11,7 +11,7 @@ #include <NewKit/PageManager.hpp> //! @file KernelHeap.cxx -//! @brief Kernel allocator. +//! @brief Kernel heap allocator. #define kKernelHeapMagic (0xD4D7D5) #define kKernelHeapHeaderPaddingSz (16U) @@ -47,23 +47,47 @@ namespace Kernel typedef HeapInformationBlock* HeapInformationBlockPtr; } // namespace Detail + /// @brief Declare a new size for allocatedPtr. + /// @param allocatedPtr the pointer. + /// @return + voidPtr ke_realloc_ke_heap(voidPtr allocatedPtr, SizeT newSz) + { + if (!allocatedPtr || newSz < 1) + return nullptr; + + Detail::HeapInformationBlockPtr heapInfoBlk = + reinterpret_cast<Detail::HeapInformationBlockPtr>( + (UIntPtr)allocatedPtr - sizeof(Detail::HeapInformationBlock)); + + heapInfoBlk->fTargetPtrSize = newSz; + + if (heapInfoBlk->fCRC32 > 0) + { + MUST_PASS(ke_protect_ke_heap(allocatedPtr)); + } + + return allocatedPtr; + } + /// @brief allocate chunk of memory. /// @param sz size of pointer /// @param rw read write (true to enable it) /// @param user is it accesible by user processes? /// @return the pointer - VoidPtr ke_new_ke_heap(SizeT sz, const bool rw, const bool user) + VoidPtr ke_new_ke_heap(const SizeT sz, const bool rw, const bool user) { - if (sz == 0) - ++sz; + auto szFix = sz; + + if (szFix == 0) + ++szFix; - auto wrapper = kHeapPageManager.Request(rw, user, false, sz); + auto wrapper = kHeapPageManager.Request(rw, user, false, szFix); Detail::HeapInformationBlockPtr heapInfo = reinterpret_cast<Detail::HeapInformationBlockPtr>( wrapper.VirtualAddress()); - heapInfo->fTargetPtrSize = sz; + heapInfo->fTargetPtrSize = szFix; heapInfo->fMagic = kKernelHeapMagic; heapInfo->fCRC32 = 0; // dont fill it for now. heapInfo->fTargetPtr = wrapper.VirtualAddress(); |
