From 3217df147ed6489a53015fc6813964e5fd346554 Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Wed, 27 Dec 2023 23:17:52 -0700 Subject: [PATCH] kern: allow ktrace map capability when ktrace is disabled --- libraries/libmesosphere/source/kern_k_capabilities.cpp | 5 +++++ stratosphere/loader/source/ldr_capabilities.cpp | 10 +--------- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/libraries/libmesosphere/source/kern_k_capabilities.cpp b/libraries/libmesosphere/source/kern_k_capabilities.cpp index 6b2c6f4b4..feb245eda 100644 --- a/libraries/libmesosphere/source/kern_k_capabilities.cpp +++ b/libraries/libmesosphere/source/kern_k_capabilities.cpp @@ -184,6 +184,11 @@ namespace ams::kern { case RegionType::NoMapping: break; case RegionType::KernelTraceBuffer: + /* NOTE: This does not match official, but is used to make pre-processing hbl capabilities in userland unnecessary. */ + /* If ktrace isn't enabled, allow ktrace to succeed without mapping anything. */ + if constexpr (!ams::kern::IsKTraceEnabled) { + break; + } case RegionType::OnMemoryBootImage: case RegionType::DTB: R_TRY(f(MemoryRegions[static_cast(type)], perm)); diff --git a/stratosphere/loader/source/ldr_capabilities.cpp b/stratosphere/loader/source/ldr_capabilities.cpp index c1693c7b4..6835267b3 100644 --- a/stratosphere/loader/source/ldr_capabilities.cpp +++ b/stratosphere/loader/source/ldr_capabilities.cpp @@ -418,15 +418,7 @@ namespace ams::ldr { for (size_t i = 0; i < count; ++i) { const auto cap = kac[i]; switch (GetCapabilityId(cap)) { - case CapabilityId::MapRegion: - { - /* MapRegion was added in 8.0.0+, and is only allowed under kernels which have the relevant mappings. */ - /* However, we allow it under all firmwares on mesosphere, to facilitate KTrace usage by hbl. */ - if (!svc::IsKTraceEnabled()) { - kac[i] = EmptyCapability; - } - } - break; + /* NOTE: Currently, there is no pre-processing necessary. */ default: break; }