From adb2c2ab41c0f23fb1c794335ff5ef23ffa92cf9 Mon Sep 17 00:00:00 2001 From: apio Date: Sun, 4 Dec 2022 12:52:49 +0100 Subject: [PATCH] Add kernel-side new and delete --- kernel/src/memory/Heap.cpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/kernel/src/memory/Heap.cpp b/kernel/src/memory/Heap.cpp index 6c7a4bad..1189b8dc 100644 --- a/kernel/src/memory/Heap.cpp +++ b/kernel/src/memory/Heap.cpp @@ -364,4 +364,34 @@ void dump_heap_usage() kdbgln("-- Total memory allocated for heap: %zu bytes", alloc_total); kdbgln("-- Heap memory in use by the kernel: %zu bytes", alloc_used); +} + +void* operator new(usize size) +{ + return kmalloc(size).expect_release_value("FIXME: Kernel new panics on OOM, since there are no exceptions"); +} + +void* operator new[](usize size) +{ + return kmalloc(size).expect_release_value("FIXME: Kernel new[] panics on OOM, since there are no exceptions"); +} + +void operator delete(void* p) +{ + kfree(p); +} + +void operator delete[](void* p) +{ + kfree(p); +} + +void operator delete(void* p, usize) +{ + kfree(p); +} + +void operator delete[](void* p, usize) +{ + kfree(p); } \ No newline at end of file