add hosversionIsAtmosphere (#525)

This commit is contained in:
SciresM 2021-01-27 14:20:41 -08:00 committed by GitHub
parent 076657fd31
commit e48f1c339f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 11 additions and 3 deletions

View File

@ -25,6 +25,9 @@ u32 hosversionGet(void);
/// Sets or overrides the current HOS version. This function is normally called automatically by libnx on startup with the version info obtained with \ref setsysGetFirmwareVersion. /// Sets or overrides the current HOS version. This function is normally called automatically by libnx on startup with the version info obtained with \ref setsysGetFirmwareVersion.
void hosversionSet(u32 version); void hosversionSet(u32 version);
/// Returns whether the current HOS version is augmented by running the Atmosphère custom firmware.
bool hosversionIsAtmosphere(void);
/// Returns true if the current HOS version is equal to or above the specified major/minor/micro version. /// Returns true if the current HOS version is equal to or above the specified major/minor/micro version.
static inline bool hosversionAtLeast(u8 major, u8 minor, u8 micro) { static inline bool hosversionAtLeast(u8 major, u8 minor, u8 micro) {
return hosversionGet() >= MAKEHOSVERSION(major,minor,micro); return hosversionGet() >= MAKEHOSVERSION(major,minor,micro);

View File

@ -4,10 +4,15 @@ static u32 g_hosVersion;
u32 hosversionGet(void) u32 hosversionGet(void)
{ {
return __atomic_load_n(&g_hosVersion, __ATOMIC_SEQ_CST); return __atomic_load_n(&g_hosVersion, __ATOMIC_SEQ_CST) & ~(BIT(31));
} }
void hosversionSet(u32 version) void hosversionSet(u32 version)
{ {
__atomic_store_n(&g_hosVersion, version, __ATOMIC_SEQ_CST); __atomic_store_n(&g_hosVersion, version, __ATOMIC_SEQ_CST);
} }
bool hosversionIsAtmosphere(void)
{
return __atomic_load_n(&g_hosVersion, __ATOMIC_SEQ_CST) & (BIT(31));
}

View File

@ -49,7 +49,7 @@ Service* ro1GetServiceSession(void) {
} }
Result _roDmntInitialize(void) { Result _roDmntInitialize(void) {
if (hosversionBefore(3,0,0)) return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); if (!hosversionIsAtmosphere() && hosversionBefore(3,0,0)) return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer);
return smGetService(&g_dmntSrv, "ro:dmnt"); return smGetService(&g_dmntSrv, "ro:dmnt");
} }

View File

@ -112,6 +112,6 @@ Result smUnregisterService(SmServiceName name) {
} }
Result smDetachClient(void) { Result smDetachClient(void) {
if (hosversionBefore(11,0,0)) return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); if (!hosversionIsAtmosphere() && hosversionBefore(11,0,0)) return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer);
return _smCmdInPid(4); return _smCmdInPid(4);
} }