Heap: Count the heap blocks' size in the size required for an allocation

This commit is contained in:
apio 2022-12-05 21:01:06 +01:00
parent 0edabd6d87
commit 6c3024d4ee
Signed by: apio
GPG Key ID: B8A7D06E42258954

View File

@ -176,7 +176,7 @@ Result<void*> kmalloc(usize size)
if (!heap_start)
{
const usize pages = get_pages_for_allocation(size);
const usize pages = get_pages_for_allocation(size + sizeof(HeapBlock));
HeapBlock* const block = TRY(allocate_pages(pages));
block->full_size = (pages * ARCH_PAGE_SIZE) - sizeof(HeapBlock);
@ -214,7 +214,7 @@ Result<void*> kmalloc(usize size)
if (!block) // No free blocks, let's allocate a new one
{
usize pages = get_pages_for_allocation(size);
usize pages = get_pages_for_allocation(size + sizeof(HeapBlock));
block = TRY(allocate_pages(pages));
block->full_size = (pages * ARCH_PAGE_SIZE) - sizeof(HeapBlock);