aboutsummaryrefslogtreecommitdiff
path: root/sys/vm/vm_map.c
diff options
context:
space:
mode:
authorIan Moffett <ian@osmora.org>2024-03-01 20:46:14 -0500
committerIan Moffett <ian@osmora.org>2024-03-01 20:47:34 -0500
commit078f945812435967b0eb19408856ca9caf2b1246 (patch)
treeb63383db31f13d4c8c7226a43a1a55553a400548 /sys/vm/vm_map.c
parent7984f48b97c8371b17cefcbfdcb14f5fd8560711 (diff)
kernel: vm_map: Add vm_map_destroy()
Signed-off-by: Ian Moffett <ian@osmora.org>
Diffstat (limited to 'sys/vm/vm_map.c')
-rw-r--r--sys/vm/vm_map.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/sys/vm/vm_map.c b/sys/vm/vm_map.c
index aec4c39..ae93c38 100644
--- a/sys/vm/vm_map.c
+++ b/sys/vm/vm_map.c
@@ -105,3 +105,34 @@ vm_map_create(vaddr_t va, paddr_t pa, vm_prot_t prot, size_t bytes)
return 0;
}
+
+/*
+ * Destroy a virtual memory mapping in the current
+ * address space.
+ */
+int
+vm_map_destroy(vaddr_t va, size_t bytes)
+{
+ struct vm_ctx *ctx = vm_get_ctx();
+ size_t granule = vm_get_page_size();
+ int s;
+
+ /* We want bytes to be aligned by the granule */
+ bytes = __ALIGN_UP(bytes, granule);
+
+ /* Align VA by granule */
+ va = __ALIGN_DOWN(va, granule);
+
+ if (bytes == 0) {
+ return -1;
+ }
+
+ for (uintptr_t i = 0; i < bytes; i += granule) {
+ s = pmap_unmap(ctx, va + i);
+ if (s != 0) {
+ return -1;
+ }
+ }
+
+ return 0;
+}