diff options
author | Anton Kling <anton@kling.gg> | 2024-04-12 14:03:29 +0200 |
---|---|---|
committer | Anton Kling <anton@kling.gg> | 2024-04-12 14:13:08 +0200 |
commit | b450065984b1588966694579230dc40c802212e7 (patch) | |
tree | e67a056b1f3d0d2fa9a8f07fd76f925080dfbf44 /kernel/kmalloc.c | |
parent | ca082f686fd2dc7ee6f0284421f6212d6d4acee8 (diff) |
Kernel/MMU: Dellocate pagedirectory when process exits.
Diffstat (limited to 'kernel/kmalloc.c')
-rw-r--r-- | kernel/kmalloc.c | 24 |
1 files changed, 24 insertions, 0 deletions
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 <kmalloc.h> #include <ksbrk.h> #include <math.h> +#include <mmu.h> #include <random.h> #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; |