diff --git a/kernel/src/memory/Heap.cpp b/kernel/src/memory/Heap.cpp index d0f65e5d..703b7922 100644 --- a/kernel/src/memory/Heap.cpp +++ b/kernel/src/memory/Heap.cpp @@ -29,6 +29,8 @@ struct HeapBlock : DoublyLinkedListNode static_assert(sizeof(HeapBlock) == 48UL); +static const isize HEAP_BLOCK_SIZE = 48; + static DoublyLinkedList heap; static Result allocate_pages(usize count) @@ -64,14 +66,15 @@ static usize space_available(HeapBlock* block) return block->full_size - block->req_size; } +// The heap block is stored right behind a memory block. static HeapBlock* get_heap_block_for_pointer(void* ptr) { - return (HeapBlock*)offset_ptr(ptr, -48); + return (HeapBlock*)offset_ptr(ptr, -HEAP_BLOCK_SIZE); } static void* get_pointer_from_heap_block(HeapBlock* block) { - return (void*)offset_ptr(block, 48); + return (void*)offset_ptr(block, HEAP_BLOCK_SIZE); } static usize get_fair_offset_to_split_at(HeapBlock* block, usize min)