Refactor LoadMeta to handle npdm flags globally

This commit modifies the handling of npdm debug capabilities across all applications to comply with new HOS restrictions. Instead of applying a specific fix for HBL, the `PreProcessCapability` function has been updated to ensure only one debug flag is set globally for all applications. The `FixDebugCapabilityForHbl` function has been removed as it is no longer necessary.

Key changes:
- Removed HBL-specific debug flag handling from `LoadMeta`.
- Centralized debug flag adjustment within `PreProcessCapability`.
- Ensured compatibility with the new HOS npdm flag restrictions.
This commit is contained in:
rashevskyv 2024-10-17 14:57:09 +03:00 committed by CostelaCNX
parent 321e15a45d
commit 1b9d102d45
3 changed files with 21 additions and 20 deletions

View File

@ -425,29 +425,35 @@ 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];
switch (GetCapabilityId(cap)) {
/* NOTE: Currently, there is no pre-processing necessary. */
case CapabilityId::DebugFlags:
{
// Ensure that only one debug flag is set
auto debug_cap = CapabilityDebugFlags::Decode(cap);
u32 total_flags = 0;
if (debug_cap.GetAllowDebug()) { ++total_flags; }
if (debug_cap.GetForceDebugProd()) { ++total_flags; }
if (debug_cap.GetForceDebug()) { ++total_flags; }
// If more than one flag is set, adjust the capability
if (total_flags > 1) {
// Set the most appropriate flag (e.g., ForceDebug)
kac[i] = CapabilityDebugFlags::Encode(
false, // AllowDebug
false, // ForceDebugProd
true // ForceDebug
);
}
}
break;
default:
break;
}
}
}
}

View File

@ -23,8 +23,6 @@ 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);
}

View File

@ -253,9 +253,6 @@ namespace ams::ldr {
}
}
/* Fix the debug capabilities, to prevent needing a hbl recompilation. */
FixDebugCapabilityForHbl(static_cast<util::BitPack32 *>(meta->acid_kac), meta->acid->kac_size / sizeof(util::BitPack32));
FixDebugCapabilityForHbl(static_cast<util::BitPack32 *>(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. */