This commit is contained in:
2025-03-16 05:52:09 +08:00
parent 41d4a30610
commit be5045fde1
28 changed files with 738 additions and 76 deletions

View File

@@ -1,8 +1,11 @@
#include <uart.h>
#include <errcode.h>
#include <utils.h>
#include <kmalloc.h>
#include <stddef.h>
extern void *__heap_start;
extern void *__heap_end;
extern uint64_t __heap_start;
extern uint64_t __heap_end;
void *_heap_top = (void *)0;
@@ -10,14 +13,14 @@ void *_heap_top = (void *)0;
void *simple_alloc(size_t size)
{
if (!_heap_top) {
_heap_top = __heap_start;
_heap_top = (void *)&__heap_start;
}
if (size & 0xff)
size = (size & ~0xff) + 0x100;
if ((uint64_t)_heap_top + size >= (uint64_t)__heap_end)
return (void *)0;
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);