aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Moffett <ian@osmora.org>2024-05-01 21:53:49 -0400
committerIan Moffett <ian@osmora.org>2024-05-01 21:57:47 -0400
commitc282dc146525a911044fea6cd5d851a742e9b342 (patch)
treef6c77748f42e739d10bfe9c54751cbad9bed14a5
parent3baafe30aa682b40a49c38b6b97fc077dd0033a3 (diff)
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 <ian@osmora.org>
-rw-r--r--sys/vm/vm_map.c5
1 files changed, 4 insertions, 1 deletions
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;