From b450065984b1588966694579230dc40c802212e7 Mon Sep 17 00:00:00 2001 From: Anton Kling Date: Fri, 12 Apr 2024 14:03:29 +0200 Subject: Kernel/MMU: Dellocate pagedirectory when process exits. --- kernel/kmalloc.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'kernel/kmalloc.c') diff --git a/kernel/kmalloc.c b/kernel/kmalloc.c index 7138d61..59cc93d 100644 --- a/kernel/kmalloc.c +++ b/kernel/kmalloc.c @@ -2,12 +2,36 @@ #include #include #include +#include #include #define NEW_ALLOC_SIZE 0x5000 #define IS_FREE (1 << 0) #define IS_FINAL (1 << 1) +void *kmalloc_align(size_t s, void **physical) { + // TODO: It should reuse virtual regions so that it does not run out + // of address space. + return ksbrk_physical(s, physical); +} + +void kmalloc_align_free(void *p, size_t s) { + for (int i = 0; i < s; i += 0x1000) { + Page *page = get_page((char *)p + i, NULL, PAGE_NO_ALLOCATE, 0); + if (!page) { + continue; + } + if (!page->present) { + continue; + } + if (!page->frame) { + continue; + } + write_to_frame(((u32)page->frame) * 0x1000, 0); + page->present = 0; + } +} + typedef struct MallocHeader { u64 magic; u32 size; -- cgit v1.2.3