From 25383db5245e548b7dfdfa32f98f59aa047368e6 Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Tue, 21 Feb 2023 13:28:14 -0700 Subject: [PATCH] kern: add InfoType_IoRegionHint --- .../include/mesosphere/kern_k_io_region.hpp | 13 +++++++++++++ .../libmesosphere/source/svc/kern_svc_info.cpp | 13 +++++++++++++ .../include/vapours/svc/svc_types_common.hpp | 1 + 3 files changed, 27 insertions(+) diff --git a/libraries/libmesosphere/include/mesosphere/kern_k_io_region.hpp b/libraries/libmesosphere/include/mesosphere/kern_k_io_region.hpp index 7edb02c97..5402bd708 100644 --- a/libraries/libmesosphere/include/mesosphere/kern_k_io_region.hpp +++ b/libraries/libmesosphere/include/mesosphere/kern_k_io_region.hpp @@ -75,6 +75,19 @@ namespace ams::kern { constexpr ALWAYS_INLINE KPhysicalAddress GetAddress() const { return m_physical_address; } constexpr ALWAYS_INLINE size_t GetSize() const { return m_size; } + + constexpr uintptr_t GetHint() const { + /* TODO: Is this architecture specific? */ + if (m_size >= 2_MB) { + return GetInteger(m_physical_address) & (2_MB - 1); + } else if (m_size >= 64_KB) { + return GetInteger(m_physical_address) & (64_KB - 1); + } else if (m_size >= 4_KB) { + return GetInteger(m_physical_address) & (4_KB - 1); + } else { + return 0; + } + } }; } diff --git a/libraries/libmesosphere/source/svc/kern_svc_info.cpp b/libraries/libmesosphere/source/svc/kern_svc_info.cpp index e6e0c97ae..3c107b590 100644 --- a/libraries/libmesosphere/source/svc/kern_svc_info.cpp +++ b/libraries/libmesosphere/source/svc/kern_svc_info.cpp @@ -297,6 +297,19 @@ namespace ams::kern::svc { *out = GetCurrentProcess().IsPermittedSvc(static_cast(info_subtype)); } break; + case ams::svc::InfoType_IoRegionHint: + { + /* Verify the sub-type is valid. */ + R_UNLESS(info_subtype == 0, svc::ResultInvalidCombination()); + + /* Get the io region from its handle. */ + KScopedAutoObject io_region = GetCurrentProcess().GetHandleTable().GetObject(handle); + R_UNLESS(io_region.IsNotNull(), svc::ResultInvalidHandle()); + + /* Get the io region's address hint. */ + *out = io_region->GetHint(); + } + break; case ams::svc::InfoType_MesosphereMeta: { /* Verify the handle is invalid. */ diff --git a/libraries/libvapours/include/vapours/svc/svc_types_common.hpp b/libraries/libvapours/include/vapours/svc/svc_types_common.hpp index 3359ff2d4..c600519df 100644 --- a/libraries/libvapours/include/vapours/svc/svc_types_common.hpp +++ b/libraries/libvapours/include/vapours/svc/svc_types_common.hpp @@ -188,6 +188,7 @@ namespace ams::svc { InfoType_FreeThreadCount = 24, InfoType_ThreadTickCount = 25, InfoType_IsSvcPermitted = 26, + InfoType_IoRegionHint = 27, InfoType_MesosphereMeta = 65000, InfoType_MesosphereCurrentProcess = 65001,