From 4021cb3ac0d41044c8e22b13c1c743f1dcaed4bc Mon Sep 17 00:00:00 2001 From: apio Date: Wed, 12 Oct 2022 14:28:48 +0200 Subject: [PATCH] KernelHeap: do not crash the entire system Previously, calling free_virtual_page(s) would cause an assertion fail if the address was not in the kernel heap range. Now, we just return. --- kernel/src/memory/KernelHeap.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kernel/src/memory/KernelHeap.cpp b/kernel/src/memory/KernelHeap.cpp index 538bb772..2b4b35b4 100644 --- a/kernel/src/memory/KernelHeap.cpp +++ b/kernel/src/memory/KernelHeap.cpp @@ -70,7 +70,7 @@ uint64_t KernelHeap::request_virtual_pages(uint64_t count) void KernelHeap::free_virtual_page(uint64_t address) { - ASSERT(address >= ALLOC_BASE && address < ALLOC_END); + if (address < ALLOC_BASE || address >= ALLOC_END) return; uint64_t index = (address - ALLOC_BASE) / PAGE_SIZE; bitmap_set(index, false); if (start_index > index) start_index = index; @@ -78,7 +78,7 @@ void KernelHeap::free_virtual_page(uint64_t address) void KernelHeap::free_virtual_pages(uint64_t address, uint64_t count) { - ASSERT(address >= ALLOC_BASE && address < ALLOC_END); + if (address < ALLOC_BASE || address >= ALLOC_END) return; uint64_t index = (address - ALLOC_BASE) / PAGE_SIZE; for (uint64_t i = 0; i < count; i++) { bitmap_set(index + i, false); } if (start_index > index) start_index = index;