hos: be a little friendlier about versioning

This commit is contained in:
Michael Scire 2020-06-14 22:50:08 -07:00
parent 9b8ffdf093
commit d236b88571

View file

@ -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<hos::Version>(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<u32>(g_hos_version) >> 24) & 0xFF;
constexpr u32 MaxMinor = (static_cast<u32>(g_hos_version) >> 16) & 0xFF;
const u32 major = (static_cast<u32>(g_hos_version) >> 24) & 0xFF;
const u32 minor = (static_cast<u32>(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);
}