From 56535ffd16b848aef0f67c515baad85f9b23117a Mon Sep 17 00:00:00 2001 From: PavelBARABANOV Date: Thu, 22 Oct 2026 04:29:47 +0300 Subject: [PATCH] John patch --- src/core/hle/service/service.cpp | 7 ++++--- src/frontend_common/firmware_manager.h | 21 +++++++++++++++++++-- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/core/hle/service/service.cpp b/src/core/hle/service/service.cpp index 2c6e8d1c07..e8f3b5a4e0 100644 --- a/src/core/hle/service/service.cpp +++ b/src/core/hle/service/service.cpp @@ -72,9 +72,10 @@ void ServiceFrameworkBase::ReportUnimplementedFunction(HLERequestContext& ctx, c } [[nodiscard]] static bool VersionGateCheck(Core::System& system, u32 vg) { - u32 const c_maj = FirmwareManager::GetFirmwareVersion(system).first.major; - u32 const c_min = FirmwareManager::GetFirmwareVersion(system).first.minor; - u32 const c_pat = FirmwareManager::GetFirmwareVersion(system).first.micro; + const auto fw = FirmwareManager::GetFirmwareVersion(system).first; + u32 const c_maj = fw.major; + u32 const c_min = fw.minor; + u32 const c_pat = fw.micro; u32 const cg = (c_pat << 0) | (c_min << 4) | (c_maj << 8); u32 const sg = (vg >> 16) & 0xffff; u32 const ug = vg & 0xffff; diff --git a/src/frontend_common/firmware_manager.h b/src/frontend_common/firmware_manager.h index 4c1297431d..c421b8eb5a 100644 --- a/src/frontend_common/firmware_manager.h +++ b/src/frontend_common/firmware_manager.h @@ -4,6 +4,8 @@ #pragma once #include "common/common_types.h" +#include + #include "core/core.h" #include "core/file_sys/nca_metadata.h" #include "core/file_sys/content_archive.h" @@ -95,13 +97,28 @@ FirmwareCheckResult VerifyFirmware(Core::System &system); */ inline std::pair GetFirmwareVersion(Core::System &system) { + // The version cannot change while a session runs, and this is on the IPC dispatch path: + // looking it up per call costs a firmware data read with firmware installed, and a + // synthesized SystemVersion archive without one. Remember it. + static std::mutex cache_mutex; + static std::pair> cache{}; + { + std::scoped_lock lock{cache_mutex}; + if (cache.first == &system) { + return cache.second; + } + } + Service::Set::FirmwareVersionFormat firmware_data{}; const auto result = Service::Set::GetFirmwareVersionImpl(firmware_data, system, Service::Set::GetFirmwareVersionType::Version2); - - return {firmware_data, result}; + { + std::scoped_lock lock{cache_mutex}; + cache = {&system, {firmware_data, result}}; + return cache.second; + } } // TODO(crueter): GET AS STRING