fix (kernel): heap init takes now a heap pointer instead of creating a heap struct

This commit is contained in:
antifallobst 2023-02-12 17:44:44 +01:00
parent cd8704eabc
commit 52d400d0c6
2 changed files with 7 additions and 9 deletions

View File

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

View File

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