aboutsummaryrefslogtreecommitdiff
path: root/sys/vm
diff options
context:
space:
mode:
authorIan Moffett <ian@osmora.org>2024-04-22 13:43:54 -0400
committerIan Moffett <ian@osmora.org>2024-04-22 13:43:54 -0400
commitb90f77b95cd1509754b8038db10dde36c679c052 (patch)
tree531706f3336d2e2de98c15fa7930ae396929d648 /sys/vm
parentdd375201a9fd44d1a58f5946dc83018afa240dec (diff)
kernel: vm_map: Fix anon map bug
We should allocate physical memory before we map so the address returned isn't 0. We should also set the virtual memory object for the mapping. Signed-off-by: Ian Moffett <ian@osmora.org>
Diffstat (limited to 'sys/vm')
-rw-r--r--sys/vm/vm_map.c27
1 files changed, 15 insertions, 12 deletions
diff --git a/sys/vm/vm_map.c b/sys/vm/vm_map.c
index 7e67ebd..2d7638e 100644
--- a/sys/vm/vm_map.c
+++ b/sys/vm/vm_map.c
@@ -328,16 +328,6 @@ mmap(void *addr, size_t len, int prot, int flags, int fildes, off_t off)
return MAP_FAILED;
/*
- * Handle address being NULL.
- *
- * FIXME: XXX: We currently identity map physmem which
- * is probably not ideal.
- */
- if (addr == NULL) {
- addr = (void *)physmem;
- }
-
- /*
* Now we check what type of map request
* this is.
*/
@@ -347,6 +337,13 @@ mmap(void *addr, size_t len, int prot, int flags, int fildes, off_t off)
return 0;
/*
+ * If 'addr' is NULL, we'll just allocate physical
+ * memory right away.
+ */
+ if (addr == NULL)
+ physmem = vm_alloc_pageframe(len / GRANULE);
+
+ /*
* Enable demand paging for this object if
* `addr` is not NULL.
*/
@@ -356,8 +353,14 @@ mmap(void *addr, size_t len, int prot, int flags, int fildes, off_t off)
mapping->vmobj = vmobj;
mapping->physmem_base = 0;
- } else {
- physmem = vm_map(addr, 0, prot, len);
+ } else if (physmem != 0) {
+ vm_map((void *)physmem, physmem, prot, len);
+ addr = (void *)physmem;
+
+ vmobj->is_anon = 1;
+ vmobj->demand = 0;
+ mapping->vmobj = vmobj;
+ mapping->physmem_base = physmem;
}
/* Did this work? */