From 7757d874adc269dce5b6ee44792b6c5a3841ff58 Mon Sep 17 00:00:00 2001 From: Idan Horowitz Date: Sun, 26 Dec 2021 00:52:33 +0200 Subject: [PATCH] Kernel: Assert that a KmallocSubheap fits inside a page Since we allocate the subheap in the first page of the given storage let's assert that the subheap can actually fit in a single page, to prevent the possible future headache of trying to debug the cause of random kernel memory corruption :^) --- Kernel/Heap/kmalloc.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/Kernel/Heap/kmalloc.cpp b/Kernel/Heap/kmalloc.cpp index 7eb3bf0ddbd..613669d5b45 100644 --- a/Kernel/Heap/kmalloc.cpp +++ b/Kernel/Heap/kmalloc.cpp @@ -58,6 +58,7 @@ struct KmallocGlobalData { void add_subheap(u8* storage, size_t storage_size) { dbgln("Adding kmalloc subheap @ {} with size {}", storage, storage_size); + static_assert(sizeof(KmallocSubheap) <= PAGE_SIZE); auto* subheap = new (storage) KmallocSubheap(storage + PAGE_SIZE, storage_size - PAGE_SIZE); subheaps.append(*subheap); }