diff --git a/libraries/libstratosphere/source/hos/hos_version_api.cpp b/libraries/libstratosphere/source/hos/hos_version_api.cpp index 2d31bbbe6..02ec4d6f3 100644 --- a/libraries/libstratosphere/source/hos/hos_version_api.cpp +++ b/libraries/libstratosphere/source/hos/hos_version_api.cpp @@ -22,7 +22,7 @@ namespace ams::hos { hos::Version g_hos_version; bool g_has_cached; - os::Mutex g_mutex(false); + os::SdkMutex g_mutex; void CacheValues() { if (__atomic_load_n(&g_has_cached, __ATOMIC_SEQ_CST)) { @@ -37,7 +37,21 @@ namespace ams::hos { /* Hos version is a direct copy of target firmware, just renamed. */ g_hos_version = static_cast(exosphere::GetApiInfo().GetTargetFirmware()); - AMS_ABORT_UNLESS(g_hos_version <= hos::Version_Max); + + /* Ensure that this is a hos version we can sanely *try* to run. */ + /* To be friendly, we will only require that we recognize the major and minor versions. */ + /* We can consider only recognizing major in the future, but micro seems safe to ignore as + /* there are no breaking IPC changes in minor updates. */ + { + constexpr u32 MaxMajor = (static_cast(g_hos_version) >> 24) & 0xFF; + constexpr u32 MaxMinor = (static_cast(g_hos_version) >> 16) & 0xFF; + + const u32 major = (static_cast(g_hos_version) >> 24) & 0xFF; + const u32 minor = (static_cast(g_hos_version) >> 16) & 0xFF; + + const bool is_safely_tryable_version = (g_hos_version <= hos::Version_Max) || (major == MaxMajor && minor <= MaxMinor); + AMS_ABORT_UNLESS(is_safely_tryable_version); + } __atomic_store_n(&g_has_cached, true, __ATOMIC_SEQ_CST); }