From 50e1b103669a334d31bb27d7d858400c7a12e29e Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Fri, 19 Sep 2025 23:29:18 -0400 Subject: kern: proc: Keep track of mapped areas with ranges This commit adds a virtual memory range queue to the process descriptor in order to keep track of mapped pages and free their respective frames upon program exit. Signed-off-by: Ian Moffett --- src/sys/vm/vm_map.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src/sys/vm/vm_map.c') diff --git a/src/sys/vm/vm_map.c b/src/sys/vm/vm_map.c index d8cb4b7..27cdcce 100644 --- a/src/sys/vm/vm_map.c +++ b/src/sys/vm/vm_map.c @@ -103,15 +103,19 @@ __vm_map(struct vm_vas *vas, struct mmu_map *spec, size_t len, int prot) int vm_map(struct vm_vas *vas, struct mmu_map *spec, size_t len, int prot) { + const size_t PSIZE = DEFAULT_PAGESIZE; int retval; size_t unmap_len; struct mmu_map spec_cpy; + struct proc *self = proc_self(); if (spec != NULL) { spec_cpy = *spec; } + /* If this fails, unmap the partial region */ + len = ALIGN_UP(len, PSIZE); retval = __vm_map(vas, spec, len, prot); if (retval != 0) { printf("vm_map: could not map <%p>\n", spec_cpy.va); @@ -121,6 +125,11 @@ vm_map(struct vm_vas *vas, struct mmu_map *spec, size_t len, int prot) return -1; } + /* Add the range if we can */ + if (self != NULL) { + proc_add_range(self, spec->va, spec->pa, len); + } + /* Place a guard page at the end */ spec->va = spec_cpy.va + len; __vm_map(vas, spec, DEFAULT_PAGESIZE, 0); -- cgit v1.2.3