From a1a97aa7b2b0c3d1f3b6766446d605f83de1c561 Mon Sep 17 00:00:00 2001 From: stefan Date: Fri, 7 Apr 2023 19:02:18 -0400 Subject: stuff and things --- sys/kern/mm/kalloc.c | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) (limited to 'sys/kern/mm/kalloc.c') diff --git a/sys/kern/mm/kalloc.c b/sys/kern/mm/kalloc.c index b17d432..f354648 100644 --- a/sys/kern/mm/kalloc.c +++ b/sys/kern/mm/kalloc.c @@ -1,7 +1,11 @@ #include +#include #include +#include #include +extern uint64_t HEAP_START; + typedef struct freenode { struct freenode *next; } freenode_t; @@ -31,10 +35,34 @@ kzalloc(void) void kfree(void *p) { - if (p == NULL || (unsigned long)p % PAGE_SIZE) + if (p == NULL) return; freenode_t *tmp = head; head = p; head->next = tmp; } + +void +kalloc_init(void) +{ + printf("1\n"); + freenode_t *p = (freenode_t*)HEAP_START; + for (;(unsigned long)p + PAGE_SIZE <= (HEAP_START + 0x100000); p += PAGE_SIZE) { + printf("freeing page at %p", p); + kfree(p); + } +} + +void +walkfree(void) +{ + freenode_t *node = head; + int nfree = 0; + while (node) { + printf("freenode at %p\n", node); + node = node->next; + nfree++; + } + printf("found and printed %d free pages!\n", nfree); +} -- cgit v1.2.3