summaryrefslogtreecommitdiffhomepage
path: root/dev
diff options
context:
space:
mode:
authorAmlal <amlal@el-mahrouss-logic.com>2024-09-19 15:43:25 +0200
committerAmlal <amlal@el-mahrouss-logic.com>2024-09-19 15:43:25 +0200
commit5f4a9440e97d6602222c93e8dcab8c483800a462 (patch)
treedd0ce2e4e27174a8ccc28d63ff3f79cb4df6f374 /dev
parent6417aa8e514b55e3c13b0dc7ed5035bc0b5e2a5a (diff)
IMP: Heap.hxx, Add mm_delete_class, which calls C++ destructor and then frees it.
FIX: BMPMgr.cxx, fix cast issue. RM: Remove filesystem initialization code for now, need to have a clear structure depending on product. Signed-off-by: Amlal <amlal@el-mahrouss-logic.com>
Diffstat (limited to 'dev')
-rw-r--r--dev/ZKA/HALKit/AMD64/HalBMPMgr.cxx2
-rw-r--r--dev/ZKA/HALKit/AMD64/HalKernelMain.cxx5
-rw-r--r--dev/ZKA/KernelKit/Heap.hxx9
-rw-r--r--dev/ZKA/Sources/Heap.cxx47
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();