From b90f77b95cd1509754b8038db10dde36c679c052 Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Mon, 22 Apr 2024 13:43:54 -0400 Subject: 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 --- sys/vm/vm_map.c | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) (limited to 'sys') 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 @@ -327,16 +327,6 @@ mmap(void *addr, size_t len, int prot, int flags, int fildes, off_t off) if ((prot & ~PROT_MASK) != 0) 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. @@ -346,6 +336,13 @@ mmap(void *addr, size_t len, int prot, int flags, int fildes, off_t off) if (vm_obj_init(&vmobj, NULL) != 0) 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? */ -- cgit v1.2.3