mirror of
https://github.com/gbowne1/ClassicOS.git
synced 2025-10-13 21:25:07 -07:00
mostly improvements to malloc
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user