From 026fdc251c95f7a04ff5638e32e756c684230d7e Mon Sep 17 00:00:00 2001 From: Bananymous Date: Sun, 22 Jan 2023 03:10:48 +0200 Subject: [PATCH] Kernel: Add kmalloc_eternal back --- kernel/kernel/kmalloc.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/kernel/kernel/kmalloc.cpp b/kernel/kernel/kmalloc.cpp index 560e4bf767..2cfee304ca 100644 --- a/kernel/kernel/kmalloc.cpp +++ b/kernel/kernel/kmalloc.cpp @@ -23,6 +23,7 @@ static constexpr uintptr_t s_kmalloc_end = s_kmalloc_base + s_kmalloc_size; static constexpr uintptr_t s_kmalloc_eternal_base = s_kmalloc_end; static constexpr size_t s_kmalloc_eternal_size = 1 * MB; static constexpr uintptr_t s_kmalloc_eternal_end = s_kmalloc_eternal_base + s_kmalloc_eternal_size; +static uintptr_t s_kmalloc_eternal_ptr = s_kmalloc_eternal_base; static constexpr size_t s_kmalloc_default_align = alignof(max_align_t); static constexpr size_t s_kmalloc_chunk_size = s_kmalloc_default_align; @@ -97,6 +98,16 @@ void kmalloc_dump_info() kprintln(" free: {}", s_kmalloc_eternal_free); } +void* kmalloc_eternal(size_t size) +{ + if (size_t rem = size % alignof(max_align_t)) + size += alignof(max_align_t) - rem; + ASSERT(s_kmalloc_eternal_ptr + size < s_kmalloc_eternal_end); + void* result = (void*)s_kmalloc_eternal_ptr; + s_kmalloc_eternal_ptr += size; + return result; +} + void* kmalloc(size_t size) { return kmalloc(size, s_kmalloc_default_align);