From 7e10614afe11f2f5381f7ee66d80590104f2c735 Mon Sep 17 00:00:00 2001 From: Freya Murphy Date: Tue, 22 Apr 2025 13:18:29 -0400 Subject: add pml4 allocation/mem ctx alloation --- kernel/memory/virtalloc.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'kernel/memory/virtalloc.c') diff --git a/kernel/memory/virtalloc.c b/kernel/memory/virtalloc.c index 8a0d1ed..0f4de93 100644 --- a/kernel/memory/virtalloc.c +++ b/kernel/memory/virtalloc.c @@ -3,8 +3,6 @@ #include "virtalloc.h" -struct virt_ctx kernel_virt_ctx; - static struct virt_addr_node *get_node_idx(struct virt_ctx *ctx, int idx) { if (idx < BOOTSTRAP_VIRT_ALLOC_NODES) { @@ -88,7 +86,7 @@ void virtaddr_init(struct virt_ctx *ctx) .is_alloc = false, .is_used = true, }; - memsetv(ctx->bootstrap_nodes, 0, sizeof(ctx->bootstrap_nodes)); + memset(ctx, 0, sizeof(struct virt_ctx)); ctx->bootstrap_nodes[0] = init; ctx->alloc_nodes = NULL; ctx->start_node = &ctx->bootstrap_nodes[0]; @@ -169,6 +167,9 @@ void *virtaddr_alloc(struct virt_ctx *ctx, int n_pages) long virtaddr_free(struct virt_ctx *ctx, void *virtaddr) { + if (virtaddr == NULL) + return -1; + uintptr_t virt = (uintptr_t)virtaddr; if (virt % PAGE_SIZE) @@ -188,3 +189,8 @@ long virtaddr_free(struct virt_ctx *ctx, void *virtaddr) return -1; } + +void virtaddr_cleanup(struct virt_ctx *ctx) +{ + kfree(ctx->alloc_nodes); +} -- cgit v1.2.3-freya