summaryrefslogtreecommitdiff
path: root/kernel/memory/virtalloc.c
diff options
context:
space:
mode:
authorFreya Murphy <freya@freyacat.org>2025-04-22 13:18:29 -0400
committerFreya Murphy <freya@freyacat.org>2025-04-22 13:18:29 -0400
commit7e10614afe11f2f5381f7ee66d80590104f2c735 (patch)
tree707dbb57dc79258f85c549247a9fe9eccc97f9c1 /kernel/memory/virtalloc.c
parentbuild user code in main make (diff)
downloadcomus-7e10614afe11f2f5381f7ee66d80590104f2c735.tar.gz
comus-7e10614afe11f2f5381f7ee66d80590104f2c735.tar.bz2
comus-7e10614afe11f2f5381f7ee66d80590104f2c735.zip
add pml4 allocation/mem ctx alloation
Diffstat (limited to 'kernel/memory/virtalloc.c')
-rw-r--r--kernel/memory/virtalloc.c12
1 files changed, 9 insertions, 3 deletions
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);
+}