From dfac99781c5e975cb62d0791142bfd3d5f9832d9 Mon Sep 17 00:00:00 2001 From: Vladimir Serbinenko Date: Wed, 16 Aug 2023 02:47:15 +0200 Subject: [PATCH] memory: Don't map extra page unnecessarily When offset2 != 0 it doesn't necessarily mean that we need an extra page. Fix calculation to map extra page only when necesarry. This is needed as next page may be unavailable like when available RAM follows XSDT and hence not available for mapping. --- kernel/memory.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/kernel/memory.cpp b/kernel/memory.cpp index 9f842b2..0473650 100644 --- a/kernel/memory.cpp +++ b/kernel/memory.cpp @@ -1325,7 +1325,8 @@ void *MMMapPhysical(MMSpace *space, uintptr_t offset, size_t bytes, uint64_t cac uintptr_t offset2 = offset & (K_PAGE_SIZE - 1); offset -= offset2; - if (offset2) bytes += K_PAGE_SIZE; + bytes += offset2; + bytes = (bytes + K_PAGE_SIZE - 1) & ~(K_PAGE_SIZE - 1); MMRegion *region;