diff --git a/kernel/inc/mm/heap.h b/kernel/inc/mm/heap.h index 2483be5..9a084b5 100644 --- a/kernel/inc/mm/heap.h +++ b/kernel/inc/mm/heap.h @@ -35,7 +35,7 @@ typedef struct { heap_segment_T* last_segment; } heap_T; -heap_T heap_create (void* base); +void heap_init (heap_T* heap, void* base); void* heap_memory_allocate (heap_T* heap, uint64_t size); void heap_memory_free (heap_T* heap, void* address); void heap_dump_segments (heap_T* heap); diff --git a/kernel/src/mm/heap.c b/kernel/src/mm/heap.c index 45440bb..331cef1 100644 --- a/kernel/src/mm/heap.c +++ b/kernel/src/mm/heap.c @@ -81,9 +81,7 @@ bool heap_segment_shrink(heap_T* heap, heap_segment_T* segment, uint64_t size) { return true; } -heap_T heap_create(void* base) { - heap_T heap; - +void heap_init(heap_T* heap, void* base) { uint64_t num_pages = 2; uint64_t size = num_pages * PFRAME_SIZE; @@ -95,11 +93,9 @@ heap_T heap_create(void* base) { heap_segment_init(base_segment, NULL, NULL, size - sizeof(heap_segment_T)); - heap.start = base; - heap.end = base + size; - heap.last_segment = base_segment; - - return heap; + heap->start = base; + heap->end = base + size; + heap->last_segment = base_segment; } heap_segment_T* heap_append_segment(heap_T* heap, uint64_t minimum_size) { @@ -190,6 +186,8 @@ void heap_dump_segments(heap_T* heap) { } void heap_memory_free(heap_T* heap, void* address) { + if (heap->start == NULL) { return; } + heap_segment_T* segment = (heap_segment_T*)(address - sizeof(heap_segment_T)); if (!heap_segment_validate(segment)) { log(LOG_ERROR, "Heap Segment Invalid! while trying to free 0x%x", address);