From e48f1c339ff22b3b1951f3dfd05b54b4ba5b075a Mon Sep 17 00:00:00 2001 From: SciresM Date: Wed, 27 Jan 2021 14:20:41 -0800 Subject: [PATCH] add hosversionIsAtmosphere (#525) --- nx/include/switch/runtime/hosversion.h | 3 +++ nx/source/runtime/hosversion.c | 7 ++++++- nx/source/services/ro.c | 2 +- nx/source/services/sm.c | 2 +- 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/nx/include/switch/runtime/hosversion.h b/nx/include/switch/runtime/hosversion.h index d03c642e..3e794309 100644 --- a/nx/include/switch/runtime/hosversion.h +++ b/nx/include/switch/runtime/hosversion.h @@ -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. 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. static inline bool hosversionAtLeast(u8 major, u8 minor, u8 micro) { return hosversionGet() >= MAKEHOSVERSION(major,minor,micro); diff --git a/nx/source/runtime/hosversion.c b/nx/source/runtime/hosversion.c index 5bffb725..f6b5915c 100644 --- a/nx/source/runtime/hosversion.c +++ b/nx/source/runtime/hosversion.c @@ -4,10 +4,15 @@ static u32 g_hosVersion; 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) { __atomic_store_n(&g_hosVersion, version, __ATOMIC_SEQ_CST); } + +bool hosversionIsAtmosphere(void) +{ + return __atomic_load_n(&g_hosVersion, __ATOMIC_SEQ_CST) & (BIT(31)); +} diff --git a/nx/source/services/ro.c b/nx/source/services/ro.c index cfa815e9..d8de3e52 100644 --- a/nx/source/services/ro.c +++ b/nx/source/services/ro.c @@ -49,7 +49,7 @@ Service* ro1GetServiceSession(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"); } diff --git a/nx/source/services/sm.c b/nx/source/services/sm.c index b0ca8788..aba4fa6c 100644 --- a/nx/source/services/sm.c +++ b/nx/source/services/sm.c @@ -112,6 +112,6 @@ Result smUnregisterService(SmServiceName name) { } 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); }