diff options
author | Ian Moffett <ian@osmora.org> | 2024-03-01 20:46:14 -0500 |
---|---|---|
committer | Ian Moffett <ian@osmora.org> | 2024-03-01 20:47:34 -0500 |
commit | 078f945812435967b0eb19408856ca9caf2b1246 (patch) | |
tree | b63383db31f13d4c8c7226a43a1a55553a400548 | |
parent | 7984f48b97c8371b17cefcbfdcb14f5fd8560711 (diff) |
kernel: vm_map: Add vm_map_destroy()
Signed-off-by: Ian Moffett <ian@osmora.org>
-rw-r--r-- | sys/include/vm/map.h | 1 | ||||
-rw-r--r-- | sys/vm/vm_map.c | 31 |
2 files changed, 32 insertions, 0 deletions
diff --git a/sys/include/vm/map.h b/sys/include/vm/map.h index 603da92..1cce8b8 100644 --- a/sys/include/vm/map.h +++ b/sys/include/vm/map.h @@ -35,5 +35,6 @@ #include <vm/pmap.h> int vm_map_create(vaddr_t va, paddr_t pa, vm_prot_t prot, size_t bytes); +int vm_map_destroy(vaddr_t va, size_t bytes); #endif /* !_VM_MMAP_H_ */ 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; +} |