diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/kernel/mem/alloc.c | 11 | ||||
-rw-r--r-- | src/kernel/mem/alloc.h | 1 | ||||
-rw-r--r-- | src/kernel/proc.c | 2 | ||||
-rw-r--r-- | src/kernel/vfs/request.c | 1 |
4 files changed, 12 insertions, 3 deletions
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 <stdint.h> 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 <stddef.h> void mem_init(struct kmain_info *); +void mem_debugprint(void); // allocates `pages` consecutive pages void *page_alloc(size_t pages); diff --git a/src/kernel/proc.c b/src/kernel/proc.c index 9a38881..39b4fb0 100644 --- a/src/kernel/proc.c +++ b/src/kernel/proc.c @@ -66,7 +66,7 @@ _Noreturn void process_switch_any(void) { if (found) process_switch(found); - tty_const(" no running processes left..."); + mem_debugprint(); panic(); } diff --git a/src/kernel/vfs/request.c b/src/kernel/vfs/request.c index 46c52b8..2fd4689 100644 --- a/src/kernel/vfs/request.c +++ b/src/kernel/vfs/request.c @@ -102,6 +102,5 @@ int vfs_request_finish(struct vfs_request *req, int ret) { req->caller->state = PS_RUNNING; regs_savereturn(&req->caller->regs, ret); - kfree(req); return ret; } |