From ed22f802ee2b8bbf34dcf8f7900e6fa525128bfd Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Tue, 21 Feb 2023 08:06:12 -0700 Subject: [PATCH] kern: allow QueryIoMapping to find Static mappings --- .../source/svc/kern_svc_address_translation.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/libraries/libmesosphere/source/svc/kern_svc_address_translation.cpp b/libraries/libmesosphere/source/svc/kern_svc_address_translation.cpp index a3bdc2d4d..746eed6bb 100644 --- a/libraries/libmesosphere/source/svc/kern_svc_address_translation.cpp +++ b/libraries/libmesosphere/source/svc/kern_svc_address_translation.cpp @@ -48,7 +48,7 @@ namespace ams::kern::svc { /* Check whether the address is aligned. */ const bool aligned = util::IsAligned(phys_addr, PageSize); - auto QueryIoMappingFromPageTable = [&](uint64_t phys_addr, size_t size) ALWAYS_INLINE_LAMBDA -> Result { + auto QueryMappingFromPageTable = [&](uint64_t phys_addr, size_t size) ALWAYS_INLINE_LAMBDA -> Result { /* The size must be non-zero. */ R_UNLESS(size > 0, svc::ResultInvalidSize()); @@ -56,7 +56,12 @@ namespace ams::kern::svc { R_UNLESS((phys_addr < phys_addr + size), svc::ResultNotFound()); /* Query the mapping. */ - R_TRY(pt.QueryIoMapping(std::addressof(found_address), phys_addr, size)); + R_TRY_CATCH(pt.QueryIoMapping(std::addressof(found_address), phys_addr, size)) { + R_CATCH(svc::ResultNotFound) { + /* If we failed to find an io mapping, check if the address is a static mapping. */ + R_TRY(pt.QueryStaticMapping(std::addressof(found_address), phys_addr, size)); + } + } R_END_TRY_CATCH; /* Use the size as the found size. */ found_size = size; @@ -66,12 +71,12 @@ namespace ams::kern::svc { if (aligned) { /* Query the input. */ - R_TRY(QueryIoMappingFromPageTable(phys_addr, size)); + R_TRY(QueryMappingFromPageTable(phys_addr, size)); } else { if (kern::GetTargetFirmware() < TargetFirmware_8_0_0 && phys_addr >= PageSize) { /* Query the aligned-down page. */ const size_t offset = phys_addr & (PageSize - 1); - R_TRY(QueryIoMappingFromPageTable(phys_addr - offset, size + offset)); + R_TRY(QueryMappingFromPageTable(phys_addr - offset, size + offset)); /* Adjust the output address. */ found_address += offset;