From be29b406526c931a606d4d4de545f71e62bc893a Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Mon, 25 Mar 2024 16:43:00 +0100 Subject: Kernel: A lot of preliminary changes before AHCI and SMP support. --- Private/Source/KernelHeap.cxx | 2 ++ Private/Source/UserHeap.cxx | 16 +++++++++------- 2 files changed, 11 insertions(+), 7 deletions(-) (limited to 'Private/Source') diff --git a/Private/Source/KernelHeap.cxx b/Private/Source/KernelHeap.cxx index 09f62004..a38156f4 100644 --- a/Private/Source/KernelHeap.cxx +++ b/Private/Source/KernelHeap.cxx @@ -70,6 +70,8 @@ Int32 ke_delete_ke_heap(VoidPtr heapPtr) { (UIntPtr)heapPtr - sizeof(Detail::HeapInformationBlock)); if (virtualAddress && virtualAddress->hMagic == kHeapMagic) { + MUST_PASS(virtualAddress->hPresent); + if (virtualAddress->hCRC32 != 0) { if (virtualAddress->hCRC32 != ke_calculate_crc32((Char *)virtualAddress->hAddress, diff --git a/Private/Source/UserHeap.cxx b/Private/Source/UserHeap.cxx index 83d40845..45b29d51 100644 --- a/Private/Source/UserHeap.cxx +++ b/Private/Source/UserHeap.cxx @@ -18,9 +18,9 @@ namespace HCore { /** * @brief Process Heap Header - * @note Allocated per process, do not allocate twice! + * @note Allocated per process, it denotes the user's heap. */ -struct HeapHeader final { +struct UserHeapHeader final { UInt32 fMagic; Int32 fFlags; Boolean fFree; @@ -66,7 +66,7 @@ STATIC VoidPtr ke_find_unused_heap(Int flags) { !HeapManager::The()[index].Leak().Leak().Leak().Present()) { HeapManager::Leak().Leak().TogglePresent( HeapManager::The()[index].Leak().Leak(), true); - kcout << "[ke_find_unused_heap] Done, trying now to make a pool\r\n"; + kcout << "[ke_find_unused_heap] Done, trying to make a pool now...\r\n"; return ke_make_heap((VoidPtr)HeapManager::The()[index] .Leak() @@ -82,7 +82,7 @@ STATIC VoidPtr ke_find_unused_heap(Int flags) { STATIC VoidPtr ke_make_heap(VoidPtr virtualAddress, Int flags) { if (virtualAddress) { - HeapHeader* poolHdr = reinterpret_cast(virtualAddress); + UserHeapHeader* poolHdr = reinterpret_cast(virtualAddress); if (!poolHdr->fFree) { kcout << "[ke_make_heap] poolHdr->fFree, HeapPtr already exists\n"; @@ -95,7 +95,7 @@ STATIC VoidPtr ke_make_heap(VoidPtr virtualAddress, Int flags) { kcout << "[ke_make_heap] New allocation has been done.\n"; return reinterpret_cast( - (reinterpret_cast(virtualAddress) + sizeof(HeapHeader))); + (reinterpret_cast(virtualAddress) + sizeof(UserHeapHeader))); } kcout << "[ke_make_heap] Address is invalid"; @@ -103,10 +103,12 @@ STATIC VoidPtr ke_make_heap(VoidPtr virtualAddress, Int flags) { } STATIC Void ke_free_heap_internal(VoidPtr virtualAddress) { - HeapHeader* poolHdr = reinterpret_cast( - reinterpret_cast(virtualAddress) - sizeof(HeapHeader)); + UserHeapHeader* poolHdr = reinterpret_cast( + reinterpret_cast(virtualAddress) - sizeof(UserHeapHeader)); if (poolHdr->fMagic == kUserHeapMag) { + MUST_PASS(poolHdr->fFree); + poolHdr->fFree = false; poolHdr->fFlags = 0; -- cgit v1.2.3