diff options
author | Anton Kling <anton@kling.gg> | 2024-07-06 20:47:14 +0200 |
---|---|---|
committer | Anton Kling <anton@kling.gg> | 2024-07-06 20:47:14 +0200 |
commit | abcba25c5f5579e50ab205d8fc01ca9dbaa0f5e8 (patch) | |
tree | 02187d5cd1e3a14002ef3d350039ec3995310dd8 /kernel/kmalloc.c | |
parent | 6d6289f0fb3b07b0d1a02f671df6b096318d4a4c (diff) |
Kernel: Add kmalloc scan
This will scan for possible overflows in the program. It is a somewhat
expensive operation but really useful for debugging.
Diffstat (limited to 'kernel/kmalloc.c')
-rw-r--r-- | kernel/kmalloc.c | 13 |
1 files changed, 11 insertions, 2 deletions
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 (;;) |