mostly improvements to malloc

This commit is contained in:
2025-07-01 11:20:04 -07:00
parent 109e554524
commit e1e30b511a
15 changed files with 276 additions and 30 deletions

View File

@@ -1,6 +1,8 @@
#include "kmalloc.h"
#include "terminal.h" // Optional: for debug output
#define HEAP_END 0xC0100000
static uint32_t current_heap = 0;
// Initialize the allocator with a starting heap address
@@ -32,7 +34,18 @@ void* kmalloc_aligned(size_t size, uint32_t alignment) {
current_heap = (current_heap + alignment) & ~(alignment - 1);
}
if (current_heap + size > HEAP_END) {
terminal_write("kmalloc_aligned: Out of memory!\n");
return 0;
}
void* addr = (void*)current_heap;
current_heap += size;
return addr;
}
void kfree(void* ptr) {
// In a bump allocator, we cannot free individual blocks.
// We can reset the allocator to the initial state.
current_heap = 0; // Reset the heap pointer
}