From 0c4ae5573153166e6eb026cc0da1bb41d77e194b Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Thu, 10 Oct 2024 03:45:09 -0700 Subject: [PATCH] ldr: ProgramInfo is 0x410 now, and fix debug flags for hbl --- .../include/stratosphere/ldr/ldr_types.hpp | 3 ++- .../source/ldr/ldr_pm_api.os.horizon.cpp | 2 ++ stratosphere/loader/source/ldr_capabilities.cpp | 14 ++++++++++++++ stratosphere/loader/source/ldr_capabilities.hpp | 2 ++ stratosphere/loader/source/ldr_main.cpp | 2 +- stratosphere/loader/source/ldr_meta.cpp | 4 ++++ 6 files changed, 25 insertions(+), 2 deletions(-) diff --git a/libraries/libstratosphere/include/stratosphere/ldr/ldr_types.hpp b/libraries/libstratosphere/include/stratosphere/ldr/ldr_types.hpp index e81be6b7d..7d1a94aa1 100644 --- a/libraries/libstratosphere/include/stratosphere/ldr/ldr_types.hpp +++ b/libraries/libstratosphere/include/stratosphere/ldr/ldr_types.hpp @@ -34,9 +34,10 @@ namespace ams::ldr { u32 aci_sac_size; u32 acid_fac_size; u32 aci_fah_size; + u8 unused_20[0x10]; u8 ac_buffer[0x3E0]; }; - static_assert(util::is_pod::value && sizeof(ProgramInfo) == 0x400, "ProgramInfo definition!"); + static_assert(util::is_pod::value && sizeof(ProgramInfo) == 0x410, "ProgramInfo definition!"); enum ProgramInfoFlag { ProgramInfoFlag_SystemModule = (0 << 0), diff --git a/libraries/libstratosphere/source/ldr/ldr_pm_api.os.horizon.cpp b/libraries/libstratosphere/source/ldr/ldr_pm_api.os.horizon.cpp index 8441977f5..2e00417de 100644 --- a/libraries/libstratosphere/source/ldr/ldr_pm_api.os.horizon.cpp +++ b/libraries/libstratosphere/source/ldr/ldr_pm_api.os.horizon.cpp @@ -24,6 +24,7 @@ namespace ams::ldr::pm { } Result GetProgramInfo(ProgramInfo *out, const ncm::ProgramLocation &loc) { + static_assert(sizeof(*out) == sizeof(LoaderProgramInfo)); R_RETURN(ldrPmGetProgramInfo(reinterpret_cast(std::addressof(loc)), reinterpret_cast(out))); } @@ -42,6 +43,7 @@ namespace ams::ldr::pm { Result AtmosphereGetProgramInfo(ProgramInfo *out, cfg::OverrideStatus *out_status, const ncm::ProgramLocation &loc) { static_assert(sizeof(*out_status) == sizeof(CfgOverrideStatus), "CfgOverrideStatus definition!"); + static_assert(sizeof(*out) == sizeof(LoaderProgramInfo)); R_RETURN(ldrPmAtmosphereGetProgramInfo(reinterpret_cast(out), reinterpret_cast(out_status), reinterpret_cast(std::addressof(loc)))); } diff --git a/stratosphere/loader/source/ldr_capabilities.cpp b/stratosphere/loader/source/ldr_capabilities.cpp index cd93d855f..b3bc25e65 100644 --- a/stratosphere/loader/source/ldr_capabilities.cpp +++ b/stratosphere/loader/source/ldr_capabilities.cpp @@ -425,6 +425,20 @@ namespace ams::ldr { } } + void FixDebugCapabilityForHbl(util::BitPack32 *kac, size_t count) { + for (size_t i = 0; i < count; ++i) { + const auto cap = kac[i]; + switch (GetCapabilityId(cap)) { + case CapabilityId::DebugFlags: + /* 19.0.0+ disallows more than one flag set; we are always DebugMode for kernel, so ForceDebug is the most powerful/flexible flag to set. */ + kac[i] = CapabilityDebugFlags::Encode(false, false, true); + break; + default: + break; + } + } + } + void PreProcessCapability(util::BitPack32 *kac, size_t count) { for (size_t i = 0; i < count; ++i) { const auto cap = kac[i]; diff --git a/stratosphere/loader/source/ldr_capabilities.hpp b/stratosphere/loader/source/ldr_capabilities.hpp index 0a91b23cc..21748a7fb 100644 --- a/stratosphere/loader/source/ldr_capabilities.hpp +++ b/stratosphere/loader/source/ldr_capabilities.hpp @@ -23,6 +23,8 @@ namespace ams::ldr { u16 MakeProgramInfoFlag(const util::BitPack32 *kac, size_t count); void UpdateProgramInfoFlag(u16 flags, util::BitPack32 *kac, size_t count); + void FixDebugCapabilityForHbl(util::BitPack32 *kac, size_t count); + void PreProcessCapability(util::BitPack32 *kac, size_t count); } diff --git a/stratosphere/loader/source/ldr_main.cpp b/stratosphere/loader/source/ldr_main.cpp index 5b6001f93..5e4d8ca06 100644 --- a/stratosphere/loader/source/ldr_main.cpp +++ b/stratosphere/loader/source/ldr_main.cpp @@ -46,7 +46,7 @@ namespace ams { namespace { struct ServerOptions { - static constexpr size_t PointerBufferSize = 0x400; + static constexpr size_t PointerBufferSize = 0x420; static constexpr size_t MaxDomains = 0; static constexpr size_t MaxDomainObjects = 0; static constexpr bool CanDeferInvokeRequest = false; diff --git a/stratosphere/loader/source/ldr_meta.cpp b/stratosphere/loader/source/ldr_meta.cpp index ee43aeedc..b1d1a85ad 100644 --- a/stratosphere/loader/source/ldr_meta.cpp +++ b/stratosphere/loader/source/ldr_meta.cpp @@ -252,6 +252,10 @@ namespace ams::ldr { meta->npdm->main_thread_priority = HblMainThreadPriorityApplet; } } + + /* Fix the debug capabilities, to prevent needing a hbl recompilation. */ + FixDebugCapabilityForHbl(static_cast(meta->acid_kac), meta->acid->kac_size / sizeof(util::BitPack32)); + FixDebugCapabilityForHbl(static_cast(meta->aci_kac), meta->aci->kac_size / sizeof(util::BitPack32)); } else if (hos::GetVersion() >= hos::Version_10_0_0) { /* If storage id is none, there is no base code filesystem, and thus it is impossible for us to validate. */ /* However, if we're an application, we are guaranteed a base code filesystem. */