diff options
| -rw-r--r-- | dev/ZKA/HALKit/AMD64/HalBMPMgr.cxx | 2 | ||||
| -rw-r--r-- | dev/ZKA/HALKit/AMD64/HalKernelMain.cxx | 5 | ||||
| -rw-r--r-- | dev/ZKA/KernelKit/Heap.hxx | 9 | ||||
| -rw-r--r-- | dev/ZKA/Sources/Heap.cxx | 47 |
4 files changed, 44 insertions, 19 deletions
diff --git a/dev/ZKA/HALKit/AMD64/HalBMPMgr.cxx b/dev/ZKA/HALKit/AMD64/HalBMPMgr.cxx index 83fa2af3..b788902a 100644 --- a/dev/ZKA/HALKit/AMD64/HalBMPMgr.cxx +++ b/dev/ZKA/HALKit/AMD64/HalBMPMgr.cxx @@ -73,7 +73,7 @@ namespace Kernel /// @return The new address which was found. auto FindBitMap(VoidPtr base_ptr, SizeT size, Bool rw, Bool user) -> VoidPtr { - VoidPtr base = base_ptr + kPageSize; + VoidPtr base = reinterpret_cast<VoidPtr>(((UIntPtr)base_ptr) + kPageSize); while (base && size) { diff --git a/dev/ZKA/HALKit/AMD64/HalKernelMain.cxx b/dev/ZKA/HALKit/AMD64/HalKernelMain.cxx index ef743c20..b11d0701 100644 --- a/dev/ZKA/HALKit/AMD64/HalKernelMain.cxx +++ b/dev/ZKA/HALKit/AMD64/HalKernelMain.cxx @@ -89,8 +89,9 @@ EXTERN_C Kernel::Void hal_real_init(Kernel::Void) noexcept Kernel::NeFileSystemMgr* mgr = (Kernel::mm_new_class<Kernel::NeFileSystemMgr>()); Kernel::NeFileSystemMgr::Mount(mgr); - delete (NFS_CATALOG_STRUCT*)mgr->CreateDirectory("\\Boot\\"); - delete (NFS_CATALOG_STRUCT*)mgr->CreateDirectory("\\Support\\"); + /// Do filesystem stuff here... (TODO) + + Kernel::mm_delete_class(mgr); mp_do_user_switch(); diff --git a/dev/ZKA/KernelKit/Heap.hxx b/dev/ZKA/KernelKit/Heap.hxx index 044004dc..41779146 100644 --- a/dev/ZKA/KernelKit/Heap.hxx +++ b/dev/ZKA/KernelKit/Heap.hxx @@ -23,7 +23,7 @@ namespace Kernel /// @brief Declare a new size for heap_ptr. /// @param heap_ptr the pointer. /// @return - voidPtr mm_realloc_ke_heap(voidPtr heap_ptr, SizeT new_sz); + VoidPtr mm_realloc_ke_heap(voidPtr heap_ptr, SizeT new_sz); /// @brief Check if pointer is a valid Kernel pointer. /// @param heap_ptr the pointer @@ -53,6 +53,13 @@ namespace Kernel T* ptr = new T(move(args)...); return ptr; } + + template <typename T> + inline Void mm_delete_class(T* cls) + { + cls->~T(); + delete cls; + } } // namespace Kernel #endif // !_INC_KERNEL_HEAP_HXX_ diff --git a/dev/ZKA/Sources/Heap.cxx b/dev/ZKA/Sources/Heap.cxx index 21ee6d67..c2894f61 100644 --- a/dev/ZKA/Sources/Heap.cxx +++ b/dev/ZKA/Sources/Heap.cxx @@ -23,6 +23,8 @@ namespace Kernel /// @brief Contains data structures and algorithms for the heap. namespace Detail { + struct PACKED HEAP_INFORMATION_BLOCK; + /// @brief Kernel heap information block. /// Located before the address bytes. /// | HIB | ADDRESS | @@ -46,6 +48,26 @@ namespace Kernel UInt8 fPadding[kKernelHeapHeaderPaddingSz]; }; + /// @brief Check for heap address validity. + /// @param heap_ptr The address_ptr + /// @return Bool if the pointer is valid or not. + auto mm_check_heap_address(VoidPtr heap_ptr) -> Bool + { + if (!heap_ptr) + return false; + + /// Add that check in case we're having an integer underflow. /// + + auto base_heap = (IntPtr)(heap_ptr) - sizeof(Detail::HEAP_INFORMATION_BLOCK); + + if (base_heap < 0) + { + return false; + } + + return true; + } + typedef HEAP_INFORMATION_BLOCK* HEAP_INFORMATION_BLOCK_PTR; Void mm_alloc_init_timeout(Void) noexcept @@ -63,24 +85,19 @@ namespace Kernel /// @brief Declare a new size for ptr_heap. /// @param ptr_heap the pointer. - /// @return + /// @return Newly allocated heap header. voidPtr mm_realloc_ke_heap(voidPtr ptr_heap, SizeT new_sz) { - if (!ptr_heap || new_sz < 1) + if (Detail::mm_check_heap_address(ptr_heap) == No) return nullptr; - Detail::HEAP_INFORMATION_BLOCK_PTR heap_blk = - reinterpret_cast<Detail::HEAP_INFORMATION_BLOCK_PTR>( - (UIntPtr)ptr_heap - sizeof(Detail::HEAP_INFORMATION_BLOCK)); + if (!ptr_heap || new_sz < 1) + return nullptr; - heap_blk->fHeapSize = new_sz; + kcout << "This function is not implemented in the kernel, please refrain from using that.\r"; + ke_stop(RUNTIME_CHECK_PROCESS); - if (heap_blk->fCRC32 > 0) - { - MUST_PASS(mm_protect_ke_heap(ptr_heap)); - } - - return ptr_heap; + return nullptr; } /// @brief Allocate chunk of memory. @@ -130,7 +147,7 @@ namespace Kernel /// @return Int32 mm_make_ke_page(VoidPtr heap_ptr) { - if (!heap_ptr) + if (Detail::mm_check_heap_address(heap_ptr) == No) return -kErrorHeapNotPresent; Detail::mm_alloc_init_timeout(); @@ -154,8 +171,8 @@ namespace Kernel /// @return Int32 mm_delete_ke_heap(VoidPtr heap_ptr) { - if (!heap_ptr) - return -kErrorInvalidData; + if (Detail::mm_check_heap_address(heap_ptr) == No) + return -kErrorHeapNotPresent; Detail::mm_alloc_init_timeout(); |
