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:
JosJuice
2023-02-12 11:07:11 +01:00
parent efed037c4a
commit 7cecb28bdf
79 changed files with 1796 additions and 1184 deletions

View File

@ -25,6 +25,7 @@ typedef SSIZE_T ssize_t;
#include <unistd.h>
#endif
#include "Common/Assert.h"
#include "Common/Event.h"
#include "Common/Logging/Log.h"
#include "Common/SocketContext.h"
@ -799,7 +800,7 @@ static void WriteRegister()
SendReply("OK");
}
static void ReadMemory()
static void ReadMemory(const Core::CPUThreadGuard& guard)
{
static u8 reply[GDB_BFR_MAX - 4];
u32 addr, len;
@ -819,7 +820,7 @@ static void ReadMemory()
if (len * 2 > sizeof reply)
SendReply("E01");
if (!PowerPC::HostIsRAMAddress(addr))
if (!PowerPC::HostIsRAMAddress(guard, addr))
return SendReply("E00");
auto& system = Core::System::GetInstance();
@ -830,7 +831,7 @@ static void ReadMemory()
SendReply((char*)reply);
}
static void WriteMemory()
static void WriteMemory(const Core::CPUThreadGuard& guard)
{
u32 addr, len;
u32 i;
@ -846,7 +847,7 @@ static void WriteMemory()
len = (len << 4) | Hex2char(s_cmd_bfr[i++]);
INFO_LOG_FMT(GDB_STUB, "gdb: write memory: {:08x} bytes to {:08x}", len, addr);
if (!PowerPC::HostIsRAMAddress(addr))
if (!PowerPC::HostIsRAMAddress(guard, addr))
return SendReply("E00");
auto& system = Core::System::GetInstance();
@ -990,11 +991,19 @@ void ProcessCommands(bool loop_until_continue)
WriteRegister();
break;
case 'm':
ReadMemory();
{
ASSERT(Core::IsCPUThread());
Core::CPUThreadGuard guard;
ReadMemory(guard);
break;
}
case 'M':
{
WriteMemory();
ASSERT(Core::IsCPUThread());
Core::CPUThreadGuard guard;
WriteMemory(guard);
auto& system = Core::System::GetInstance();
auto& ppc_state = system.GetPPCState();
ppc_state.iCache.Reset();