diff options
Diffstat (limited to 'Kernel/Sources/Heap.cxx')
| -rw-r--r-- | Kernel/Sources/Heap.cxx | 36 |
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; } |
