summaryrefslogtreecommitdiff
path: root/stage3/heap.c
diff options
context:
space:
mode:
Diffstat (limited to 'stage3/heap.c')
-rw-r--r--stage3/heap.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/stage3/heap.c b/stage3/heap.c
index dd1b23a..0a82213 100644
--- a/stage3/heap.c
+++ b/stage3/heap.c
@@ -1,5 +1,6 @@
#include "halt.h"
#include "heap.h"
+#include "memory.h"
#define PAGESIZE 0x1000
#define MAGIC ((void *) 0x69)
@@ -74,6 +75,24 @@ void *malloc(usize size)
return nil;
}
+void *realloc(void *ptr, usize size)
+{
+ if (ptr == nil)
+ return malloc(size);
+
+ Header *h = ((Header *) ptr) - 1;
+
+ if (h->next != MAGIC)
+ panic("realloc: invalid pointer");
+
+ void *new = malloc(size);
+
+ memcpy(new, ptr, h->size);
+ free(ptr);
+
+ return new;
+}
+
void heap_init()
{
free_ptr = &init_free_ptr;