From 25108684fe235d4296c3cbc480298df209682586 Mon Sep 17 00:00:00 2001 From: stefan Date: Tue, 4 Apr 2023 06:01:50 +0000 Subject: build system and some other stuff --- sys/kern/mm/kalloc.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 sys/kern/mm/kalloc.c (limited to 'sys/kern/mm/kalloc.c') diff --git a/sys/kern/mm/kalloc.c b/sys/kern/mm/kalloc.c new file mode 100644 index 0000000..b17d432 --- /dev/null +++ b/sys/kern/mm/kalloc.c @@ -0,0 +1,40 @@ +#include +#include +#include + +typedef struct freenode { + struct freenode *next; +} freenode_t; + +freenode_t *head = NULL; + +void * +kalloc(void) +{ + freenode_t *p = head; + + if (p == NULL) + return NULL; + + head = p->next; + return p; +} + +void * +kzalloc(void) +{ + freenode_t *p = kalloc(); + memset(p, 0, PAGE_SIZE); + return p; +} + +void +kfree(void *p) +{ + if (p == NULL || (unsigned long)p % PAGE_SIZE) + return; + + freenode_t *tmp = head; + head = p; + head->next = tmp; +} -- cgit v1.2.3