summaryrefslogtreecommitdiff
path: root/kernel/kmalloc.c
diff options
context:
space:
mode:
authorAnton Kling <anton@kling.gg>2023-11-10 15:19:49 +0100
committerAnton Kling <anton@kling.gg>2023-11-10 15:19:49 +0100
commit0cb4afef6da5488a128e5aaece435e9aa5f5797e (patch)
treeb77f05fa03878bad5542c31e42f19f4c99034149 /kernel/kmalloc.c
parent8ffef83741948964171ca111fd7c90534515ae87 (diff)
Kernel/Memory: Fill new allocations with random data.
This should make it easier to spot uninitalized memory being used.
Diffstat (limited to 'kernel/kmalloc.c')
-rw-r--r--kernel/kmalloc.c27
1 files changed, 14 insertions, 13 deletions
diff --git a/kernel/kmalloc.c b/kernel/kmalloc.c
index 34c466d..75bc74b 100644
--- a/kernel/kmalloc.c
+++ b/kernel/kmalloc.c
@@ -2,7 +2,8 @@
#include <kmalloc.h>
#include <ksbrk.h>
#include <math.h>
-#define NEW_ALLOC_SIZE 0x30000
+#include <random.h>
+#define NEW_ALLOC_SIZE 0x20000
#define IS_FREE (1 << 0)
#define IS_FINAL (1 << 1)
@@ -142,6 +143,7 @@ void *kmalloc(size_t s) {
free_entry->flags = 0;
free_entry->n = new_entry;
free_entry->magic = 0xdde51ab9410268b1;
+ get_random((void *)rc, s);
return rc;
}
@@ -215,16 +217,15 @@ void *kcalloc(size_t nelem, size_t elsize) {
}
void kfree(void *p) {
- /*
-if (!p)
-return;
-// FIXME: This assumes that p is at the start of a allocated area.
-// Could this be avoided in a simple way?
-MallocHeader *h = (MallocHeader *)((uintptr_t)p - sizeof(MallocHeader));
-assert(h->magic == 0xdde51ab9410268b1);
-if (h->flags & IS_FREE)
-return;
-
-h->flags |= IS_FREE;
-merge_headers(h);*/
+ if (!p)
+ return;
+ // FIXME: This assumes that p is at the start of a allocated area.
+ // Could this be avoided in a simple way?
+ MallocHeader *h = (MallocHeader *)((uintptr_t)p - sizeof(MallocHeader));
+ assert(h->magic == 0xdde51ab9410268b1);
+ if (h->flags & IS_FREE)
+ return;
+
+ h->flags |= IS_FREE;
+ merge_headers(h);
}