From cfb12deb516fe8b824916c447494ca6210b0dcb4 Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Thu, 28 Mar 2024 02:22:19 -0700 Subject: [PATCH] kern: simplify size calculations in KPageTableBase::Read/WriteDebugIoMemory --- libraries/libmesosphere/source/kern_k_page_table_base.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/libmesosphere/source/kern_k_page_table_base.cpp b/libraries/libmesosphere/source/kern_k_page_table_base.cpp index 5ad8b274b..b96a6da3a 100644 --- a/libraries/libmesosphere/source/kern_k_page_table_base.cpp +++ b/libraries/libmesosphere/source/kern_k_page_table_base.cpp @@ -2994,7 +2994,7 @@ namespace ams::kern { MESOSPHERE_ABORT_UNLESS(src_page_table.GetPhysicalAddressLocked(std::addressof(phys_addr), address)); /* Determine the current read size. */ - const size_t cur_size = std::min(last_address - address + 1, util::AlignDown(GetInteger(address) + PageSize, PageSize) - GetInteger(address)); + const size_t cur_size = std::min(last_address - address + 1, PageSize - (GetInteger(address) & (PageSize - 1))); /* Read. */ R_TRY(dst_page_table.ReadIoMemoryImpl(dst, phys_addr, cur_size, state)); @@ -3030,7 +3030,7 @@ namespace ams::kern { MESOSPHERE_ABORT_UNLESS(src_page_table.GetPhysicalAddressLocked(std::addressof(phys_addr), address)); /* Determine the current read size. */ - const size_t cur_size = std::min(last_address - address + 1, util::AlignDown(GetInteger(address) + PageSize, PageSize) - GetInteger(address)); + const size_t cur_size = std::min(last_address - address + 1, PageSize - (GetInteger(address) & (PageSize - 1))); /* Read. */ R_TRY(dst_page_table.WriteIoMemoryImpl(phys_addr, src, cur_size, state));