diff options
Diffstat (limited to 'sys')
-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; +} |