summaryrefslogtreecommitdiffhomepage
path: root/Kernel/Sources/Heap.cxx
diff options
context:
space:
mode:
authorAmlal EL Mahrouss <amlalelmahrouss@icloud.com>2024-07-31 00:13:51 +0200
committerAmlal EL Mahrouss <amlalelmahrouss@icloud.com>2024-07-31 00:13:51 +0200
commit3bfb95803ba25a04ddb57ebbc0f25e4dec29d7e0 (patch)
tree94fc17899142c1631797b9b6257b04359282741b /Kernel/Sources/Heap.cxx
parent659435af7da4ffb15a309063c892b518707fa9d0 (diff)
[IMP] Can now pass arguments to kernel via handover, new version 0x0113.
[IMP] Timeout functions for heap allocation. [IMP] new mp_ and sched_ category of functions. Signed-off-by: Amlal EL Mahrouss <amlalelmahrouss@icloud.com>
Diffstat (limited to 'Kernel/Sources/Heap.cxx')
-rw-r--r--Kernel/Sources/Heap.cxx36
1 files changed, 36 insertions, 0 deletions
diff --git a/Kernel/Sources/Heap.cxx b/Kernel/Sources/Heap.cxx
index f24eda56..94406d1d 100644
--- a/Kernel/Sources/Heap.cxx
+++ b/Kernel/Sources/Heap.cxx
@@ -21,6 +21,8 @@ namespace Kernel
STATIC SizeT kHeapCount = 0UL;
STATIC PageManager kHeapPageManager;
+ STATIC Bool kOperationInProgress = No;
+
namespace Detail
{
/// @brief Kernel heap information block.
@@ -45,6 +47,26 @@ namespace Kernel
};
typedef HEAP_INFORMATION_BLOCK* HEAP_INFORMATION_BLOCK_PTR;
+
+ Bool mm_alloc_init_timeout(Void) noexcept
+ {
+ SizeT timOut = 0U;
+
+ while (kOperationInProgress)
+ {
+ ++timOut;
+ if (timOut > 10000000)
+ return false;
+ }
+
+ kOperationInProgress = Yes;
+ return true;
+ }
+
+ Void mm_alloc_fini_timeout(Void) noexcept
+ {
+ kOperationInProgress = No;
+ }
} // namespace Detail
/// @brief Declare a new size for allocatedPtr.
@@ -76,6 +98,8 @@ namespace Kernel
/// @return the pointer
VoidPtr mm_new_ke_heap(const SizeT sz, const bool rw, const bool user)
{
+ Detail::mm_alloc_init_timeout();
+
auto szFix = sz;
if (szFix == 0)
@@ -95,6 +119,8 @@ namespace Kernel
++kHeapCount;
+ Detail::mm_alloc_fini_timeout();
+
return reinterpret_cast<VoidPtr>(wrapper.VirtualAddress() +
sizeof(Detail::HEAP_INFORMATION_BLOCK));
}
@@ -111,12 +137,16 @@ namespace Kernel
if (((IntPtr)heapPtr - kBadPtr) < 0)
return -kErrorInternal;
+ Detail::mm_alloc_init_timeout();
+
Detail::HEAP_INFORMATION_BLOCK_PTR heapInfoBlk =
reinterpret_cast<Detail::HEAP_INFORMATION_BLOCK_PTR>(
(UIntPtr)heapPtr - sizeof(Detail::HEAP_INFORMATION_BLOCK));
heapInfoBlk->fPagePtr = 1;
+ Detail::mm_alloc_fini_timeout();
+
return 0;
}
@@ -132,6 +162,8 @@ namespace Kernel
if (((IntPtr)heapPtr - kBadPtr) < 0)
return -kErrorInternal;
+ Detail::mm_alloc_init_timeout();
+
Detail::HEAP_INFORMATION_BLOCK_PTR heapInfoBlk =
reinterpret_cast<Detail::HEAP_INFORMATION_BLOCK_PTR>(
(UIntPtr)heapPtr - sizeof(Detail::HEAP_INFORMATION_BLOCK));
@@ -140,6 +172,7 @@ namespace Kernel
{
if (!heapInfoBlk->fPresent)
{
+ Detail::mm_alloc_fini_timeout();
return -kErrorHeapNotPresent;
}
@@ -165,6 +198,9 @@ namespace Kernel
kHeapPageManager.Free(pteAddress);
--kHeapCount;
+
+ Detail::mm_alloc_fini_timeout();
+
return 0;
}