Detect 5.0.0 properly

This commit is contained in:
plutoo 2018-03-23 19:01:09 +01:00
parent bf216aa667
commit 6c72bf8273
2 changed files with 31 additions and 9 deletions

View File

@ -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);

View File

@ -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);