diff --git a/nx/include/switch/kernel/detect.h b/nx/include/switch/kernel/detect.h index 2c5ee370..6d86a09e 100644 --- a/nx/include/switch/kernel/detect.h +++ b/nx/include/switch/kernel/detect.h @@ -13,5 +13,7 @@ bool kernelAbove200(void); bool kernelAbove300(void); /// Returns true if the kernel version is equal to or above 4.0.0. bool kernelAbove400(void); +/// Returns true if the kernel version is equal to or above 5.0.0. +bool kernelAbove500(void); /// Returns true if the process has a debugger attached. bool detectDebugger(void); diff --git a/nx/source/kernel/detect.c b/nx/source/kernel/detect.c index d0ff6074..eace0bf4 100644 --- a/nx/source/kernel/detect.c +++ b/nx/source/kernel/detect.c @@ -1,24 +1,39 @@ // Copyright 2017 plutoo #include "types.h" #include "kernel/detect.h" +#include "kernel/mutex.h" #include "kernel/svc.h" static bool g_IsAbove200; static bool g_IsAbove300; static bool g_IsAbove400; +static bool g_IsAbove500; static bool g_HasCached = 0; +static Mutex g_Mutex; static void _CacheValues(void) { - // This is actually thread safe, might cache twice but that's fine. - if (!g_HasCached) - { - u64 tmp; - g_IsAbove200 = (svcGetInfo(&tmp, 12, INVALID_HANDLE, 0) != 0xF001); - g_IsAbove300 = (svcGetInfo(&tmp, 18, INVALID_HANDLE, 0) != 0xF001); - g_IsAbove400 = (svcGetInfo(&tmp, 19, INVALID_HANDLE, 0) != 0xF001); - g_HasCached = true; - } + if (g_HasCached) + return; + + mutexLock(&g_Mutex); + + if (g_HasCached) + return; + + u64 tmp; + g_IsAbove200 = (svcGetInfo(&tmp, 12, INVALID_HANDLE, 0) != 0xF001); + g_IsAbove300 = (svcGetInfo(&tmp, 18, INVALID_HANDLE, 0) != 0xF001); + g_IsAbove400 = (svcGetInfo(&tmp, 19, INVALID_HANDLE, 0) != 0xF001); + g_IsAbove500 = (svcGetInfo(&tmp, 20, INVALID_HANDLE, 0) != 0xF001); + + g_IsAbove400 |= g_IsAbove500; + g_IsAbove300 |= g_IsAbove400; + g_IsAbove200 |= g_IsAbove300; + + g_HasCached = true; + + mutexUnlock(&g_Mutex); } bool kernelAbove200(void) { @@ -36,6 +51,11 @@ bool kernelAbove400(void) { return g_IsAbove400; } +bool kernelAbove500(void) { + _CacheValues(); + return g_IsAbove500; +} + bool detectDebugger(void) { u64 tmp; svcGetInfo(&tmp, 8, 0, 0);