Core/PatchEngine: Get rid of global system accessors

We can pass the system instance into ApplyFramePatches() instead,
especially considering the patch engine callback already has it
available.
This commit is contained in:
Lioncache 2023-12-18 16:44:39 -05:00
parent 0cab6583a9
commit 3802c7bf11
3 changed files with 13 additions and 9 deletions

View File

@ -170,7 +170,7 @@ void PatchEngineCallback(Core::System& system, u64 userdata, s64 cycles_late)
s64 next_schedule = 0;
// Try to patch mem and run the Action Replay
if (PatchEngine::ApplyFramePatches())
if (PatchEngine::ApplyFramePatches(system))
{
next_schedule = vi_interval - cycles_pruned;
cycles_pruned = 0;

View File

@ -294,21 +294,22 @@ static void ApplyMemoryPatches(const Core::CPUThreadGuard& guard,
// We require at least 2 stack frames, if the stack is shallower than that then it won't work.
static bool IsStackValid(const Core::CPUThreadGuard& guard)
{
auto& system = Core::System::GetInstance();
auto& ppc_state = system.GetPPCState();
const auto& ppc_state = guard.GetSystem().GetPPCState();
DEBUG_ASSERT(ppc_state.msr.DR && ppc_state.msr.IR);
// Check the stack pointer
u32 SP = ppc_state.gpr[1];
const u32 SP = ppc_state.gpr[1];
if (!PowerPC::MMU::HostIsRAMAddress(guard, SP))
return false;
// Read the frame pointer from the stack (find 2nd frame from top), assert that it makes sense
u32 next_SP = PowerPC::MMU::HostRead_U32(guard, SP);
const u32 next_SP = PowerPC::MMU::HostRead_U32(guard, SP);
if (next_SP <= SP || !PowerPC::MMU::HostIsRAMAddress(guard, next_SP) ||
!PowerPC::MMU::HostIsRAMAddress(guard, next_SP + 4))
{
return false;
}
// Check the link register makes sense (that it points to a valid IBAT address)
const u32 address = PowerPC::MMU::HostRead_U32(guard, next_SP + 4);
@ -328,10 +329,9 @@ void RemoveMemoryPatch(std::size_t index)
std::erase(s_on_frame_memory, index);
}
bool ApplyFramePatches()
bool ApplyFramePatches(Core::System& system)
{
auto& system = Core::System::GetInstance();
auto& ppc_state = system.GetPPCState();
const auto& ppc_state = system.GetPPCState();
ASSERT(Core::IsCPUThread());
Core::CPUThreadGuard guard(system);

View File

@ -13,6 +13,10 @@ namespace Common
{
class IniFile;
}
namespace Core
{
class System;
}
namespace PatchEngine
{
@ -57,7 +61,7 @@ void LoadPatches();
void AddMemoryPatch(std::size_t index);
void RemoveMemoryPatch(std::size_t index);
bool ApplyFramePatches();
bool ApplyFramePatches(Core::System& system);
void Shutdown();
void Reload();