hw2 done
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user