diff options
author | stefan <stefan@s00.xyz> | 2023-04-07 19:02:18 -0400 |
---|---|---|
committer | stefan <stefan@s00.xyz> | 2023-04-07 19:02:18 -0400 |
commit | a1a97aa7b2b0c3d1f3b6766446d605f83de1c561 (patch) | |
tree | 445f9419aee4e0ffdb7271d84474452c7e69d225 /sys/kern/mm | |
parent | cd653dcee96a2673bf4ab5aadba0ecfaf5fe7a0f (diff) | |
download | sv-a1a97aa7b2b0c3d1f3b6766446d605f83de1c561.tar.gz |
stuff and things
Diffstat (limited to 'sys/kern/mm')
-rw-r--r-- | sys/kern/mm/kalloc.c | 30 |
1 files changed, 29 insertions, 1 deletions
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 <stddef.h> +#include <stdint.h> #include <string.h> +#include <printf.h> #include <mm/kalloc.h> +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); +} |