From 4f0954dd447ca604832688f6eb9798e8245ca334 Mon Sep 17 00:00:00 2001 From: mitaclaw <140017135+mitaclaw@users.noreply.github.com> Date: Sun, 28 Jul 2024 15:45:52 -0700 Subject: [PATCH] MainAndroid: Thread Correctness In WriteJitBlockLogDump MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In a race condition, the core could shut down between the `JitInterface::GetCore` nullptr check and the `JitInterface::JitBlockLogDump` call which constructs a `CPUThreadGuard`. In this scenario, nothing horrible happens—`JitBlockLogDump` also checks for a nullptr—but it would be a failure to display the correct feedback to the user. --- Source/Android/jni/MainAndroid.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Source/Android/jni/MainAndroid.cpp b/Source/Android/jni/MainAndroid.cpp index 2ca05572a8..811b28c32b 100644 --- a/Source/Android/jni/MainAndroid.cpp +++ b/Source/Android/jni/MainAndroid.cpp @@ -417,6 +417,7 @@ JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_WriteJitBloc HostThreadLock guard; auto& system = Core::System::GetInstance(); auto& jit_interface = system.GetJitInterface(); + const Core::CPUThreadGuard cpu_guard(system); if (jit_interface.GetCore() == nullptr) { env->CallStaticVoidMethod(native_library_class, IDCache::GetDisplayToastMsg(), @@ -434,7 +435,7 @@ JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_WriteJitBloc JNI_FALSE); return; } - jit_interface.JitBlockLogDump(Core::CPUThreadGuard{system}, f.GetHandle()); + jit_interface.JitBlockLogDump(cpu_guard, f.GetHandle()); env->CallStaticVoidMethod(native_library_class, IDCache::GetDisplayToastMsg(), ToJString(env, Common::FmtFormatT("Wrote to \"{0}\".", filename)), JNI_FALSE);