summaryrefslogtreecommitdiff
path: root/src/sys/vm
diff options
context:
space:
mode:
authorIan Moffett <ian@osmora.org>2025-09-19 23:29:18 -0400
committerIan Moffett <ian@osmora.org>2025-09-19 23:29:18 -0400
commit50e1b103669a334d31bb27d7d858400c7a12e29e (patch)
tree6459d4bbfd32157be8b62ad64bd01a2a2916c395 /src/sys/vm
parent69933fc75a701502f06fc30680fa6fa1f13b5ebb (diff)
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 <ian@osmora.org>
Diffstat (limited to 'src/sys/vm')
-rw-r--r--src/sys/vm/vm_map.c9
1 files changed, 9 insertions, 0 deletions
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);