From c282dc146525a911044fea6cd5d851a742e9b342 Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Wed, 1 May 2024 21:53:49 -0400 Subject: kernel: vm_map: Ensure mmap len is always aligned Physical memory pages to be allocated is 'len / GRANULE'. Previously, if 'len' was less than the machine page-size, the amount of pages to allocate would be 0 causing the map to fail. Signed-off-by: Ian Moffett --- sys/vm/vm_map.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'sys/vm') diff --git a/sys/vm/vm_map.c b/sys/vm/vm_map.c index 4f7aadc..9e40e95 100644 --- a/sys/vm/vm_map.c +++ b/sys/vm/vm_map.c @@ -358,6 +358,9 @@ mmap(void *addr, size_t len, int prot, int flags, int fildes, off_t off) mapping->prot = prot | PROT_USER; map_start = __ALIGN_DOWN(va, GRANULE); + /* Ensure the length is aligned */ + len = __ALIGN_UP(len + misalign, GRANULE); + /* * Now we check what type of map request * this is. @@ -409,7 +412,7 @@ mmap(void *addr, size_t len, int prot, int flags, int fildes, off_t off) } /* Setup map_end and map ranges */ - map_end = map_start + __ALIGN_UP(len + misalign, GRANULE); + map_end = map_start + len; mapping->range.start = map_start; mapping->range.end = map_end; mapping->physmem_base = physmem; -- cgit v1.2.3