mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-10-14 23:10:33 +02:00
Keep JIT block entries and replacement hooks out of PSP memory
The JITs used to find a block by overwriting its first instruction with an "emuhack" holding the offset into the code space, and replacement functions installed their own emuhack the same way. Anything that read code (savestates, the debugger, memory dumps, cheats, the function hasher, games reading their own code) had to translate them back. Blocks now live in a block shadow: one u32 per guest instruction, indexed by the PC masked with BLOCK_SHADOW_MASK (1GB on 64-bit, folding the kernel and uncached mirrors; 256MB on 32-bit, iOS and Switch, where address space is short), with the low bits cleared so a misaligned PC can't read across two entries. Only the ranges under memory views are committed, so a bad PC still faults in the dispatcher, and the shadow is reserved before the memory map so it can't land in a gap of the 4GB window. Entries hold full 32-bit offsets, lifting the 16MB limit. The dispatchers on every backend, and the IR interpreter's loop, look blocks up there. A hooked instruction without a compiled block gets the JIT's hook value in its entry: the offset of the dispatcher's compile path (1 for the interpreters, the IR arena keeping that offset empty), so dispatching there compiles a block, and the frontends substitute the hook. Compiling replaces the entry with the block's, and destroying the block puts the hook value back. The hook value is rewritten when the JIT changes or regenerates its dispatcher. Hooks live in a map keyed by the masked address, and are dropped when the game overwrites the hooked instruction, or when an icache invalidation finds the function's hash (immediates masked, as when matching it) changed. Those checks run when queued invalidations are processed, since cheats and the debugger queue them before writing. Installing and removing hooks invalidates deferred, as it happens in HLE calls that can run inside a block. The cache instruction goes through MIPSState, so it drops changed hooks too. With clean memory, the save/clear/restore around savestates, memory reads and dumps goes away, as do the source-range invalidations in the memcpy replacements, sceDmac and the cheats. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
0a8ec4d8f1
commit
6d122f416e
57 files changed
+876
-759
No files matched your search
@@ -80,7 +80,6 @@ INT_PTR CALLBACK DumpMemoryWindow::dlgFunc(HWND hwnd, UINT iMsg, WPARAM wParam,
|
||||
break;
|
||||
case IDOK:
|
||||
if (bp->fetchDialogData(hwnd)) {
|
||||
bool includeReplacements = SendMessage(GetDlgItem(hwnd, IDC_DUMP_INCLUDEHACKS), BM_GETCHECK, 0, 0) != 0;
|
||||
|
||||
// Route the actual memory dump to the CPU thread instead of forcing the emulator
|
||||
// to pause and poking at it directly from this GUI thread - see
|
||||
@@ -98,19 +97,7 @@ INT_PTR CALLBACK DumpMemoryWindow::dlgFunc(HWND hwnd, UINT iMsg, WPARAM wParam,
|
||||
return;
|
||||
}
|
||||
|
||||
if (includeReplacements) {
|
||||
fwrite(Memory::GetPointerOrException(bp->start), 1, bp->size, output);
|
||||
} else {
|
||||
auto savedReplacements = SaveAndClearReplacements();
|
||||
if (MIPSComp::jit) {
|
||||
auto savedBlocks = MIPSComp::jit->SaveAndClearEmuHackOps();
|
||||
fwrite(Memory::GetPointerOrException(bp->start), 1, bp->size, output);
|
||||
MIPSComp::jit->RestoreSavedEmuHackOps(savedBlocks);
|
||||
} else {
|
||||
fwrite(Memory::GetPointerOrException(bp->start), 1, bp->size, output);
|
||||
}
|
||||
RestoreSavedReplacements(savedReplacements);
|
||||
}
|
||||
fwrite(Memory::GetPointerOrException(bp->start), 1, bp->size, output);
|
||||
|
||||
fclose(output);
|
||||
outcome = Outcome::Success;
|
||||
|
||||
Reference in new issue
Block a user