mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-23 06:09:50 -06:00
DolphinQt: Properly lock CPU before accessing emulated memory
This fixes a problem I was having where using frame advance with the debugger open would frequently cause panic alerts about invalid addresses due to the CPU thread changing MSR.DR while the host thread was trying to access memory. To aid in tracking down all the places where we weren't properly locking the CPU, I've created a new type (in Core.h) that you have to pass as a reference or pointer to functions that require running as the CPU thread.
This commit is contained in:
@ -166,7 +166,12 @@ void OnFrameEnd()
|
||||
{
|
||||
#ifdef USE_MEMORYWATCHER
|
||||
if (s_memory_watcher)
|
||||
s_memory_watcher->Step();
|
||||
{
|
||||
ASSERT(IsCPUThread());
|
||||
CPUThreadGuard guard;
|
||||
|
||||
s_memory_watcher->Step(guard);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -537,7 +542,9 @@ static void EmuThread(std::unique_ptr<BootParameters> boot, WindowSystemInfo wsi
|
||||
|
||||
PatchEngine::Shutdown();
|
||||
HLE::Clear();
|
||||
PowerPC::debug_interface.Clear();
|
||||
|
||||
CPUThreadGuard guard;
|
||||
PowerPC::debug_interface.Clear(guard);
|
||||
}};
|
||||
|
||||
VideoBackendBase::PopulateBackendInfo();
|
||||
@ -587,8 +594,12 @@ static void EmuThread(std::unique_ptr<BootParameters> boot, WindowSystemInfo wsi
|
||||
if (SConfig::GetInstance().bWii)
|
||||
savegame_redirect = DiscIO::Riivolution::ExtractSavegameRedirect(boot->riivolution_patches);
|
||||
|
||||
if (!CBoot::BootUp(system, std::move(boot)))
|
||||
return;
|
||||
{
|
||||
ASSERT(IsCPUThread());
|
||||
CPUThreadGuard guard;
|
||||
if (!CBoot::BootUp(system, guard, std::move(boot)))
|
||||
return;
|
||||
}
|
||||
|
||||
// Initialise Wii filesystem contents.
|
||||
// This is done here after Boot and not in BootManager to ensure that we operate
|
||||
@ -1036,4 +1047,16 @@ void UpdateInputGate(bool require_focus, bool require_full_focus)
|
||||
ControlReference::SetInputGate(focus_passes && full_focus_passes);
|
||||
}
|
||||
|
||||
CPUThreadGuard::CPUThreadGuard() : m_was_cpu_thread(IsCPUThread())
|
||||
{
|
||||
if (!m_was_cpu_thread)
|
||||
m_was_unpaused = PauseAndLock(true, true);
|
||||
}
|
||||
|
||||
CPUThreadGuard::~CPUThreadGuard()
|
||||
{
|
||||
if (!m_was_cpu_thread)
|
||||
PauseAndLock(false, m_was_unpaused);
|
||||
}
|
||||
|
||||
} // namespace Core
|
||||
|
Reference in New Issue
Block a user