Files
osc2025/lib/kmalloc.c

40 lines
667 B
C

#include <uart.h>
#include <errcode.h>
#include <utils.h>
#include <kmalloc.h>
#include <stddef.h>
extern uint64_t __heap_start;
extern uint64_t __heap_end;
void *_heap_top = (void *)0;
// simple 8-byte aligned linear allocation
void *simple_alloc(size_t size)
{
if (!_heap_top) {
_heap_top = (void *)&__heap_start;
}
size = (size_t)ALIGN8(size);
if ((uint64_t)_heap_top + size >= (uint64_t)&__heap_end)
exit(ERR_NO_MEM);
void *ret = _heap_top;
_heap_top = (void *)((uint64_t)_heap_top + size);
return ret;
}
void *kmalloc(size_t size)
{
return simple_alloc(size);
}
void kfree(void *ptr)
{
// not implemented for now
return;
}