From abcba25c5f5579e50ab205d8fc01ca9dbaa0f5e8 Mon Sep 17 00:00:00 2001 From: Anton Kling Date: Sat, 6 Jul 2024 20:47:14 +0200 Subject: Kernel: Add kmalloc scan This will scan for possible overflows in the program. It is a somewhat expensive operation but really useful for debugging. --- kernel/kmalloc.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'kernel/kmalloc.c') diff --git a/kernel/kmalloc.c b/kernel/kmalloc.c index 939589d..86c4eda 100644 --- a/kernel/kmalloc.c +++ b/kernel/kmalloc.c @@ -100,7 +100,7 @@ int add_heap_memory(size_t min_desired) { return 1; } -MallocHeader *next_header(MallocHeader *a) { +static MallocHeader *next_header(MallocHeader *a) { assert(a->magic == 0xdde51ab9410268b1); if (a->n) { if (a->n->magic != 0xdde51ab9410268b1) { @@ -113,7 +113,16 @@ MallocHeader *next_header(MallocHeader *a) { return NULL; } -MallocHeader *next_close_header(MallocHeader *a) { +void kmalloc_scan(void) { + if (!head) { + return; + } + MallocHeader *p = head; + for (; (p = next_header(p));) + ; +} + +static MallocHeader *next_close_header(MallocHeader *a) { if (!a) { kprintf("next close header fail\n"); for (;;) -- cgit v1.2.3