Commit Graph
30 Commits
Author SHA1 Message Date
Henrik RydgårdandClaude Opus 5.5 6d122f416e 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>
2026-10-11 10:33:30 +02:00
Henrik Rydgård 569f6effa8 at3_standalone: Make all allocations aligned.
Replace av_realloc with regular realloc, as there's no aligned_realloc
and pointers are not compatible with regular free.
2025-03-26 18:03:13 +01:00
Henrik Rydgård f54d701a2e Decentralize the assert for AllocateAlignedMemory failures 2024-10-22 21:49:50 +02:00
M4xw 0cf6f46330 [MemoryUtil] Platform changes for Nintendo Switch 2023-06-26 16:17:45 +02:00
Henrik Rydgård 321a112eff Rename SimpleBuf -> AlignedVector, use regular aligned memory instead of pages. 2023-04-24 12:04:34 +02:00
Henrik Rydgård f45a7cf06b Some semantic cleanup 2023-04-24 12:04:34 +02:00
Henrik Rydgård b1af940d8e Save textures on background tasks when texture dumping is enabled.
Should help #15478, at least a bit.
2022-04-18 00:26:35 +02:00
Henrik Rydgård 4a0437d0ed Remove a useless wrapper function 2017-01-26 10:01:14 +01:00
Henrik Rydgård 193b5f3094 By skipping kernel mappings, I got things to fit in the iOS 64-bit address space. However, something is still a bit broken with JIT... 2017-01-25 18:35:09 +01:00
Florent Castelli 4145b60a0e symbian: Remove! 2016-10-11 18:49:08 +02:00
Florent Castelli 373db56a16 blackberry: Remove! 2016-10-11 17:40:32 +02:00
Henrik Rydgard 1e4b77fb49 Use PAGE_SIZE, fix a comment, fix some indentation. 2016-08-28 18:07:54 +02:00
Henrik Rydgard b264657d56 Implement W^X-compatible path. Works on Windows and Android, hopefully iOS (untested).
Disabled block linking in this mode, can re-enable with some more work later.

To enable W^X on other platforms than iOS, simply change PlatformIsWXExclusive.
2016-08-28 14:52:08 +02:00
Henrik Rydgard 323eb72b7c Write-protect the dispatcher on all platforms. 2016-08-28 13:35:27 +02:00
Henrik Rydgard 5005e83254 Consistency improvements to the memory protect/alloc APIs 2016-08-28 12:28:17 +02:00
Henrik Rydgard adbac55b1d Replace Write/UnWriteProtectMemory with ProtectMemory that takes flags 2016-08-28 12:09:01 +02:00
Lioncash f0f7e48ef4 Common: Move headers over to using pragma once
Just makes the headers more consistent.
2014-12-15 17:09:40 -05:00
Lioncash a962bc5a6c Mark some functions as const 2014-12-07 17:08:13 -05:00
Toad King aa0b4964ed Try to allocate executable memory close to PPSSPP memory if not below 4GB 2014-08-05 18:45:19 -04:00
Unknown W. Brackets e569bb6862 Missed one, try to fix Blackberry too. 2013-12-30 21:52:09 -08:00
Unknown W. Brackets f14361c3b8 Add a bunch more missing cstring includes. 2013-12-30 21:37:19 -08:00
Henrik Rydgård e5e17fbc6e More include cleanup. Hoping for very slightly faster compile times.. 2013-12-30 10:49:05 +01:00
Sacha d50b01a778 Doesn't really 'free', so called 'reset' instead. 2013-11-12 02:13:34 +10:00
Sacha 3bc8adf426 Fix crashes on Symbian related to memory allocation. 2013-11-12 02:06:12 +10:00
Sacha 2c795907b2 Symbian: Handle multiple executable memory allocations.
Windows: Remove MemUsage (from Dolphin) as it was unused.
Fix some tabbing.
2013-11-11 02:55:45 +10:00
Peter Thoman af68180319 Parallelized texture scaling 2013-05-01 14:12:09 +02:00
Sacha d99c9fb2ff Fix Symbian JIT + FastMem by using a mapped virtual address RChunk. 2013-02-17 15:23:56 +10:00
Sacha 7bba8c68c4 Fix JIT on Symbian (HACK). 2013-02-01 09:01:00 +10:00
Henrik Rydgard 64cc573703 Switch to "GPL 2.0 or later" for various reasons. I wrote most of the code I imported from Dolphin (which is GPL2-but-not-later), so it should be OK. 2012-11-04 23:24:00 +01:00
Henrik Rydgard 4f7ad15758 Add snapshot of the whole source code. 2012-11-01 16:19:01 +01:00