diff --git a/nx/include/switch/kernel/detect.h b/nx/include/switch/kernel/detect.h index 09fa3534..edf4efc8 100644 --- a/nx/include/switch/kernel/detect.h +++ b/nx/include/switch/kernel/detect.h @@ -22,3 +22,5 @@ bool detectDebugger(void); /// Returns true if the kernel is patched to allow self-process-jit. bool detectCfwJitPatch(void); +/// After this has been called, libnx will pretend that CFW is not present. For testing purposes only. +void detectPretendNotCfwForTesting(void); diff --git a/nx/source/kernel/detect.c b/nx/source/kernel/detect.c index acabefcb..403d1177 100644 --- a/nx/source/kernel/detect.c +++ b/nx/source/kernel/detect.c @@ -71,6 +71,7 @@ static void _CacheCfwJit(void) { // On an unpatched kernel on 5.0.0 and above, this would return 0xD401. // It is not allowed for the creator-process of a CodeMemory object to use svcControlCodeMemory on it. + // If the patch is present, the function should return 0xF001, because -1 is not a valid enum CodeOperation. rc = svcControlCodeMemory(code, -1, 0, 0x1000, 0); g_CfwJitPatchDetected = (rc == 0xF001); @@ -120,3 +121,10 @@ bool detectCfwJitPatch(void) { _CacheCfwJit(); return g_CfwJitPatchDetected; } + +void detectPretendNotCfwForTesting(void) { + mutexLock(&g_CfwJitMutex); + g_CfwJitPatchDetected = false; + __atomic_store_n(&g_CfwJitCached, true, __ATOMIC_SEQ_CST); + mutexUnlock(&g_CfwJitMutex); +}