Kernel: Add kmalloc_eternal back

This commit is contained in:
Bananymous 2023-01-22 03:10:48 +02:00
parent cdd27ae3db
commit 026fdc251c
1 changed files with 11 additions and 0 deletions

View File

@ -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);