mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2024-11-22 20:06:40 +00:00
hos: better safe than sorry
This commit is contained in:
parent
018ae08409
commit
d63be0737b
1 changed files with 36 additions and 37 deletions
|
@ -68,53 +68,52 @@ namespace ams::hos {
|
||||||
if (IsUnitTestProgramForSetVersion()) {
|
if (IsUnitTestProgramForSetVersion()) {
|
||||||
g_hos_version = hos::Version_Current;
|
g_hos_version = hos::Version_Current;
|
||||||
g_set_hos_version = true;
|
g_set_hos_version = true;
|
||||||
return;
|
} else {
|
||||||
}
|
/* Get the current (and previous approximation of) target firmware. */
|
||||||
|
hos::Version prev, current;
|
||||||
|
bool has_prev = false;
|
||||||
|
{
|
||||||
|
/* Acquire exclusive access to set hos version. */
|
||||||
|
std::scoped_lock lk(g_hos_init_lock);
|
||||||
|
|
||||||
/* Get the current (and previous approximation of) target firmware. */
|
/* Save the previous value of g_hos_version. */
|
||||||
hos::Version prev, current;
|
prev = g_hos_version;
|
||||||
bool has_prev = false;
|
has_prev = g_set_hos_version;
|
||||||
{
|
|
||||||
/* Acquire exclusive access to set hos version. */
|
|
||||||
std::scoped_lock lk(g_hos_init_lock);
|
|
||||||
|
|
||||||
/* Save the previous value of g_hos_version. */
|
/* Set hos version = exosphere api version target firmware. */
|
||||||
prev = g_hos_version;
|
g_hos_version = static_cast<hos::Version>(GetExosphereApiInfo(allow_approximate).GetTargetFirmware());
|
||||||
has_prev = g_set_hos_version;
|
|
||||||
|
|
||||||
/* Set hos version = exosphere api version target firmware. */
|
/* Save the current value of g_hos_version. */
|
||||||
g_hos_version = static_cast<hos::Version>(GetExosphereApiInfo(allow_approximate).GetTargetFirmware());
|
current = g_hos_version;
|
||||||
|
|
||||||
/* Save the current value of g_hos_version. */
|
/* Note that we've set a previous hos version. */
|
||||||
current = g_hos_version;
|
g_set_hos_version = true;
|
||||||
|
}
|
||||||
|
|
||||||
/* Note that we've set a previous hos version. */
|
/* Ensure that this is a hos version we can sanely *try* to run. */
|
||||||
g_set_hos_version = true;
|
/* 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>(hos::Version_Max) >> 24) & 0xFF;
|
||||||
|
constexpr u32 MaxMinor = (static_cast<u32>(hos::Version_Max) >> 16) & 0xFF;
|
||||||
|
|
||||||
/* Ensure that this is a hos version we can sanely *try* to run. */
|
const u32 major = (static_cast<u32>(current) >> 24) & 0xFF;
|
||||||
/* To be friendly, we will only require that we recognize the major and minor versions. */
|
const u32 minor = (static_cast<u32>(current) >> 16) & 0xFF;
|
||||||
/* 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>(hos::Version_Max) >> 24) & 0xFF;
|
|
||||||
constexpr u32 MaxMinor = (static_cast<u32>(hos::Version_Max) >> 16) & 0xFF;
|
|
||||||
|
|
||||||
const u32 major = (static_cast<u32>(current) >> 24) & 0xFF;
|
const bool is_safely_tryable_version = (current <= hos::Version_Max) || (major == MaxMajor && minor <= MaxMinor);
|
||||||
const u32 minor = (static_cast<u32>(current) >> 16) & 0xFF;
|
AMS_ABORT_UNLESS(is_safely_tryable_version);
|
||||||
|
}
|
||||||
|
|
||||||
const bool is_safely_tryable_version = (current <= hos::Version_Max) || (major == MaxMajor && minor <= MaxMinor);
|
/* Ensure that this is a hos version compatible with previous approximations. */
|
||||||
AMS_ABORT_UNLESS(is_safely_tryable_version);
|
if (has_prev) {
|
||||||
}
|
AMS_ABORT_UNLESS(current >= prev);
|
||||||
|
|
||||||
/* Ensure that this is a hos version compatible with previous approximations. */
|
const u32 current_major = (static_cast<u32>(current) >> 24) & 0xFF;
|
||||||
if (has_prev) {
|
const u32 prev_major = (static_cast<u32>(prev) >> 24) & 0xFF;
|
||||||
AMS_ABORT_UNLESS(current >= prev);
|
|
||||||
|
|
||||||
const u32 current_major = (static_cast<u32>(current) >> 24) & 0xFF;
|
AMS_ABORT_UNLESS(current_major == prev_major);
|
||||||
const u32 prev_major = (static_cast<u32>(prev) >> 24) & 0xFF;
|
}
|
||||||
|
|
||||||
AMS_ABORT_UNLESS(current_major == prev_major);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set the version for libnx. */
|
/* Set the version for libnx. */
|
||||||
|
|
Loading…
Reference in a new issue