summaryrefslogtreecommitdiff
path: root/Source/Core/Common/Debug/MemoryPatches.cpp
diff options
context:
space:
mode:
authorJosJuice <josjuice@gmail.com>2023-02-12 11:07:11 +0100
committerJosJuice <josjuice@gmail.com>2023-02-12 11:27:50 +0100
commit7cecb28bdf6443362a6ab20e0042ddb3b407ebec (patch)
tree710c9afcd7296dbc9591ac42ec6da81ba2daa2b6 /Source/Core/Common/Debug/MemoryPatches.cpp
parentefed037c4af882171237b70f47e50359bc5260da (diff)
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.
Diffstat (limited to 'Source/Core/Common/Debug/MemoryPatches.cpp')
-rw-r--r--Source/Core/Common/Debug/MemoryPatches.cpp41
1 files changed, 21 insertions, 20 deletions
diff --git a/Source/Core/Common/Debug/MemoryPatches.cpp b/Source/Core/Common/Debug/MemoryPatches.cpp
index f48e6e5bb5..d4f7e92379 100644
--- a/Source/Core/Common/Debug/MemoryPatches.cpp
+++ b/Source/Core/Common/Debug/MemoryPatches.cpp
@@ -23,36 +23,37 @@ MemoryPatch::MemoryPatch(u32 address_, u32 value_)
MemoryPatches::MemoryPatches() = default;
MemoryPatches::~MemoryPatches() = default;
-void MemoryPatches::SetPatch(u32 address, u32 value)
+void MemoryPatches::SetPatch(const Core::CPUThreadGuard& guard, u32 address, u32 value)
{
const std::size_t index = m_patches.size();
m_patches.emplace_back(address, value);
- Patch(index);
+ Patch(guard, index);
}
-void MemoryPatches::SetPatch(u32 address, std::vector<u8> value)
+void MemoryPatches::SetPatch(const Core::CPUThreadGuard& guard, u32 address, std::vector<u8> value)
{
- UnsetPatch(address);
+ UnsetPatch(guard, address);
const std::size_t index = m_patches.size();
m_patches.emplace_back(address, std::move(value));
- Patch(index);
+ Patch(guard, index);
}
-void MemoryPatches::SetFramePatch(u32 address, u32 value)
+void MemoryPatches::SetFramePatch(const Core::CPUThreadGuard& guard, u32 address, u32 value)
{
const std::size_t index = m_patches.size();
m_patches.emplace_back(address, value);
m_patches.back().type = MemoryPatch::ApplyType::EachFrame;
- Patch(index);
+ Patch(guard, index);
}
-void MemoryPatches::SetFramePatch(u32 address, std::vector<u8> value)
+void MemoryPatches::SetFramePatch(const Core::CPUThreadGuard& guard, u32 address,
+ std::vector<u8> value)
{
- UnsetPatch(address);
+ UnsetPatch(guard, address);
const std::size_t index = m_patches.size();
m_patches.emplace_back(address, std::move(value));
m_patches.back().type = MemoryPatch::ApplyType::EachFrame;
- Patch(index);
+ Patch(guard, index);
}
const std::vector<MemoryPatch>& MemoryPatches::GetPatches() const
@@ -60,7 +61,7 @@ const std::vector<MemoryPatch>& MemoryPatches::GetPatches() const
return m_patches;
}
-void MemoryPatches::UnsetPatch(u32 address)
+void MemoryPatches::UnsetPatch(const Core::CPUThreadGuard& guard, u32 address)
{
const auto it = std::find_if(m_patches.begin(), m_patches.end(),
[address](const auto& patch) { return patch.address == address; });
@@ -69,23 +70,23 @@ void MemoryPatches::UnsetPatch(u32 address)
return;
const std::size_t index = std::distance(m_patches.begin(), it);
- RemovePatch(index);
+ RemovePatch(guard, index);
}
-void MemoryPatches::EnablePatch(std::size_t index)
+void MemoryPatches::EnablePatch(const Core::CPUThreadGuard& guard, std::size_t index)
{
if (m_patches[index].is_enabled == MemoryPatch::State::Enabled)
return;
m_patches[index].is_enabled = MemoryPatch::State::Enabled;
- Patch(index);
+ Patch(guard, index);
}
-void MemoryPatches::DisablePatch(std::size_t index)
+void MemoryPatches::DisablePatch(const Core::CPUThreadGuard& guard, std::size_t index)
{
if (m_patches[index].is_enabled == MemoryPatch::State::Disabled)
return;
m_patches[index].is_enabled = MemoryPatch::State::Disabled;
- Patch(index);
+ Patch(guard, index);
}
bool MemoryPatches::HasEnabledPatch(u32 address) const
@@ -95,19 +96,19 @@ bool MemoryPatches::HasEnabledPatch(u32 address) const
});
}
-void MemoryPatches::RemovePatch(std::size_t index)
+void MemoryPatches::RemovePatch(const Core::CPUThreadGuard& guard, std::size_t index)
{
- DisablePatch(index);
+ DisablePatch(guard, index);
UnPatch(index);
m_patches.erase(m_patches.begin() + index);
}
-void MemoryPatches::ClearPatches()
+void MemoryPatches::ClearPatches(const Core::CPUThreadGuard& guard)
{
const std::size_t size = m_patches.size();
for (std::size_t index = 0; index < size; ++index)
{
- DisablePatch(index);
+ DisablePatch(guard, index);
UnPatch(index);
}
m_patches.clear();