From 9a93ed59ce8e9311dd29e148048c6c20ba54388c Mon Sep 17 00:00:00 2001 From: dzwdz Date: Sun, 19 Sep 2021 21:39:06 +0200 Subject: show the malloc balance on halt; remove a bad kfree() call the kfree() call was freeing a buffer which was inside a process struct --- src/kernel/mem/alloc.c | 11 ++++++++++- src/kernel/mem/alloc.h | 1 + 2 files changed, 11 insertions(+), 1 deletion(-) (limited to 'src/kernel/mem') diff --git a/src/kernel/mem/alloc.c b/src/kernel/mem/alloc.c index 42a2f3b..51576bb 100644 --- a/src/kernel/mem/alloc.c +++ b/src/kernel/mem/alloc.c @@ -4,6 +4,7 @@ #include static void *highest_page; +static int malloc_balance = 0; void mem_init(struct kmain_info *info) { // finds the highest used page, and starts allocating pages above it @@ -16,6 +17,12 @@ void mem_init(struct kmain_info *info) { highest_page = (void*)(((uintptr_t)highest + PAGE_MASK) & ~PAGE_MASK); } +void mem_debugprint(void) { + tty_const("malloc balance: "); + _tty_var(malloc_balance); + tty_const(" "); +} + void *page_alloc(size_t pages) { void *bottom = highest_page; highest_page += pages * PAGE_SIZE; @@ -29,10 +36,12 @@ void page_free(void *first, size_t pages) { void *kmalloc(size_t len) { + malloc_balance++; // extremely inefficient, but this is only temporary anyways return page_alloc(len / PAGE_SIZE + 1); } void kfree(void *ptr) { - // unimplemented + if (ptr == NULL) return; + malloc_balance--; } diff --git a/src/kernel/mem/alloc.h b/src/kernel/mem/alloc.h index 571b289..4f45520 100644 --- a/src/kernel/mem/alloc.h +++ b/src/kernel/mem/alloc.h @@ -4,6 +4,7 @@ #include void mem_init(struct kmain_info *); +void mem_debugprint(void); // allocates `pages` consecutive pages void *page_alloc(size_t pages); -- cgit v1.2.3