summaryrefslogtreecommitdiffhomepage
path: root/src/kernel
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal@nekernel.org>2026-03-06 06:36:01 +0100
committerAmlal El Mahrouss <amlal@nekernel.org>2026-03-06 06:37:15 +0100
commitac993e1cf8ec4c55cbd1e80c7b94ac492d6dc4e8 (patch)
tree7993e57bdab4fa9b6400d81ae477c736193de352 /src/kernel
parenta5f3fdf32ba6aa34a5dd05eeb807446a9f046393 (diff)
[FEAT] HeapMgr: Add LockDelegate to allocation calls, and re-introduce double-free prevention.
[CHORE] FileMgr: Cleanup and tweaks. [CHORE] ABI: Update copyright year. Signed-off-by: Amlal El Mahrouss <amlal@nekernel.org>
Diffstat (limited to 'src/kernel')
-rw-r--r--src/kernel/HALKit/ARM64/CxxAbi.cpp2
-rw-r--r--src/kernel/src/FileMgr.cpp1
-rw-r--r--src/kernel/src/GUIDWizard.cpp4
-rw-r--r--src/kernel/src/HeapMgr.cpp18
4 files changed, 19 insertions, 6 deletions
diff --git a/src/kernel/HALKit/ARM64/CxxAbi.cpp b/src/kernel/HALKit/ARM64/CxxAbi.cpp
index e68d8b14..45c59e9b 100644
--- a/src/kernel/HALKit/ARM64/CxxAbi.cpp
+++ b/src/kernel/HALKit/ARM64/CxxAbi.cpp
@@ -1,4 +1,4 @@
-// Copyright 2024-2025, Amlal El Mahrouss (amlal@nekernel.org)
+// Copyright 2024-2026, Amlal El Mahrouss (amlal@nekernel.org)
// Licensed under the Apache License, Version 2.0 (see LICENSE file)
// Official repository: https://github.com/ne-foss-org/nekernel
diff --git a/src/kernel/src/FileMgr.cpp b/src/kernel/src/FileMgr.cpp
index 5781760c..91114d8b 100644
--- a/src/kernel/src/FileMgr.cpp
+++ b/src/kernel/src/FileMgr.cpp
@@ -17,6 +17,7 @@ STATIC IFilesystemMgr* kMountedFilesystem = nullptr;
/// @brief FilesystemMgr getter.
/// @return The mounted filesystem.
_Output IFilesystemMgr* IFilesystemMgr::GetMounted() {
+ MUST_PASS(kMountedFilesystem);
return kMountedFilesystem;
}
diff --git a/src/kernel/src/GUIDWizard.cpp b/src/kernel/src/GUIDWizard.cpp
index d739e6f0..ac3c2f4a 100644
--- a/src/kernel/src/GUIDWizard.cpp
+++ b/src/kernel/src/GUIDWizard.cpp
@@ -1,4 +1,4 @@
-// Copyright 2024-2025, Amlal El Mahrouss (amlal@nekernel.org)
+// Copyright 2024-2026, Amlal El Mahrouss (amlal@nekernel.org)
// Licensed under the Apache License, Version 2.0 (see LICENSE file)
// Official repository: https://github.com/ne-foss-org/nekernel
@@ -37,7 +37,7 @@ auto cf_make_sequence(const Array<UInt32, 10>& uuidSeq) -> Ref<GUIDSequence*> {
// @brief Tries to make a guid out of a string.
// This function is not complete for now
auto cf_try_guid_to_string(Ref<GUIDSequence*>& seq) -> ErrorOr<Ref<KString>> {
- Char buf[kGUIDSize];
+ Char buf[kGUIDSize] = {0};
for (SizeT index = 0; index < 16; ++index) {
buf[index] = seq.Leak()->fU8[index] + kGUIDAsciiBegin;
diff --git a/src/kernel/src/HeapMgr.cpp b/src/kernel/src/HeapMgr.cpp
index 9ebf8e3c..a13bd9c2 100644
--- a/src/kernel/src/HeapMgr.cpp
+++ b/src/kernel/src/HeapMgr.cpp
@@ -9,6 +9,7 @@
#include <NeKit/Crc32.h>
#include <NeKit/PageMgr.h>
#include <NeKit/Utils.h>
+#include <KernelKit/LockDelegate.h>
/* ========================================
@@ -82,9 +83,15 @@ STATIC PageMgr kPageMgr;
/// @param user User enable bit.
/// @return The newly allocated pointer.
_Output VoidPtr mm_alloc_ptr(SizeT sz, Bool wr, Bool user, SizeT pad_amount) {
+ static Bool locked = false;
+ LockDelegate<255> lock{&locked};
+
auto sz_fix = sz;
if (sz_fix == 0) return nullptr;
+
+ locked = true;
+
sz_fix += sizeof(Detail::MM_INFORMATION_BLOCK);
auto wrapper = kPageMgr.Request(wr, user, No, sz_fix, pad_amount);
@@ -93,7 +100,10 @@ _Output VoidPtr mm_alloc_ptr(SizeT sz, Bool wr, Bool user, SizeT pad_amount) {
reinterpret_cast<Detail::MM_INFORMATION_BLOCK_PTR>(wrapper.VirtualAddress() +
sizeof(Detail::MM_INFORMATION_BLOCK));
- if (!heap_info_ptr) return nullptr;
+ if (!heap_info_ptr) {
+ locked = false;
+ return nullptr;
+ }
heap_info_ptr->fSize = sz_fix;
heap_info_ptr->fMagic = kHeapMgrMagic;
@@ -114,6 +124,8 @@ _Output VoidPtr mm_alloc_ptr(SizeT sz, Bool wr, Bool user, SizeT pad_amount) {
(Void)(kout << "HeapMgr: Registered heap address: "
<< hex_number(reinterpret_cast<UIntPtr>(heap_info_ptr)) << kendl);
+ locked = false;
+
return result;
}
@@ -198,6 +210,8 @@ _Output Int32 mm_free_ptr(VoidPtr heap_ptr) {
kPageMgr.Free(pte_address);
return kErrorSuccess;
+ } else {
+ ke_panic(RUNTIME_CHECK_TLS, "Double-Free Detected on HeapMgr, aborting.");
}
return kErrorInternal;
@@ -227,9 +241,7 @@ _Output Boolean mm_protect_ptr(VoidPtr heap_ptr) {
reinterpret_cast<Detail::MM_INFORMATION_BLOCK_PTR>((UIntPtr) heap_ptr -
sizeof(Detail::MM_INFORMATION_BLOCK));
- /// TODO: if valid, present and is heap header, then compute crc32
if (heap_info_ptr && heap_info_ptr->fPresent && kHeapMgrMagic == heap_info_ptr->fMagic) {
- /// TODO: Protect only the header, information in it may change.
heap_info_ptr->fCRC32 =
ke_calculate_crc32((Char*) heap_info_ptr, sizeof(Detail::MM_INFORMATION_BLOCK));