diff options
author | Ian Moffett <ian@osmora.org> | 2024-03-09 22:55:58 -0500 |
---|---|---|
committer | Ian Moffett <ian@osmora.org> | 2024-03-09 22:55:58 -0500 |
commit | 2d0d7a6f61899fa7263edf63c019e53a0278928a (patch) | |
tree | f4a7e4653bf5a449fca48e7337957861a31ba96f | |
parent | 02b190f4c97758f7871d1301a68eb6a0bff2f365 (diff) |
kernel: vm_map: Account for address misalignment
Signed-off-by: Ian Moffett <ian@osmora.org>
-rw-r--r-- | sys/vm/vm_map.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/sys/vm/vm_map.c b/sys/vm/vm_map.c index 0d27738..f65bad2 100644 --- a/sys/vm/vm_map.c +++ b/sys/vm/vm_map.c @@ -78,12 +78,13 @@ int vm_map_create(struct vas vas, vaddr_t va, paddr_t pa, vm_prot_t prot, size_t bytes) { size_t granule = vm_get_page_size(); + size_t misalign = va & (granule - 1); int s; struct vm_ctx *ctx = vm_get_ctx(); /* We want bytes to be aligned by the granule */ - bytes = __ALIGN_UP(bytes, granule); + bytes = __ALIGN_UP(bytes + misalign, granule); /* Align VA/PA by granule */ va = __ALIGN_DOWN(va, granule); @@ -115,10 +116,11 @@ vm_map_destroy(struct vas vas, vaddr_t va, size_t bytes) { struct vm_ctx *ctx = vm_get_ctx(); size_t granule = vm_get_page_size(); + size_t misalign = va & (granule - 1); int s; /* We want bytes to be aligned by the granule */ - bytes = __ALIGN_UP(bytes, granule); + bytes = __ALIGN_UP(bytes + misalign, granule); /* Align VA by granule */ va = __ALIGN_DOWN(va, granule); |