Commit Graph
85 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 f094752f21 MemoryUtil: fall back to far memory when the near reservation fails
The x86-64 path searched for free memory near the code, and if it found some,
committed to it - if that VirtualAlloc failed, ptr was left null and we returned
null, never reaching the else branch that exists precisely to say "can still run,
thanks to RipAccessible".

Finding a free region isn't the same as being able to reserve it. VirtualAlloc
rounds a non-null lpAddress down to the 64K allocation granularity while
SearchForFreeMem only guarantees page alignment, so the rounded-down base can land
back inside a committed region; a concurrent allocation between the VirtualQuery and
the VirtualAlloc does it too. Callers don't check the result - AllocCodeSpace stores
it unchecked and the emitters write from there - so this turned into a wild write
rather than a clean JIT-unavailable fallback.
2026-08-31 12:52:35 +02:00
Henrik Rydgård 2feaeef837 Add support for 16kb page size on Android 2025-06-10 16:16:13 +02:00
Henrik Rydgård f54d701a2e Decentralize the assert for AllocateAlignedMemory failures 2024-10-22 21:49:50 +02:00
Henrik Rydgård 4d6905672e Bunch more linting 2024-10-10 11:57:10 +02:00
Henrik Rydgård e01ca5b057 Logging API change (refactor) (#19324)
* Rename LogType to Log

* Explicitly use the Log:: enum when logging. Allows for autocomplete when editing.

* Mac/ARM64 buildfix

* Do the same with the hle result log macros

* Rename the log names to mixed case while at it.

* iOS buildfix

* Qt buildfix attempt, ARM32 buildfix
2024-07-14 14:42:59 +02:00
Henrik Rydgård be65cf0fc2 Assert improvements 2023-09-12 17:15:26 +02:00
fp64 f133739cd0 Replace some signed divison in SoftGPU
This also adds a few bitwise operations to Vec4<int> and further
SIMDifies it.
Also, fixes unrelated warning.
2023-06-29 16:43:21 -04:00
M4xw 0cf6f46330 [MemoryUtil] Platform changes for Nintendo Switch 2023-06-26 16:17:45 +02:00
Henrik Rydgård f45a7cf06b Some semantic cleanup 2023-04-24 12:04:34 +02:00
Henrik Rydgård 7a75119ed0 Split out the Windows version of AllocateExecutableMemory 2023-04-24 12:04:27 +02:00
Henrik Rydgård 79f4e73110 Replacer: Perform the padding to pow2 size during CopyLevelTo, not during load. Saves memory. 2023-03-17 14:00:14 +01:00
Unknown W. Brackets fa1a4d26dc Windows: Fix crash dependent on alloc order.
Without IR, we don't allocate executable memory, so the first allocation
always fails.
2023-03-15 21:30:21 -07:00
Henrik Rydgård 73452b4743 Minor cleanups 2022-04-23 22:52:28 +02:00
Unknown W. Brackets 2479d52202 Global: Reduce includes of common headers.
In many places, string, map, or Common.h were included but not needed.
2022-01-30 16:35:33 -08:00
Unknown W. Brackets 4178f09e57 Build: More consistently avoid _M_ defines.
We use PPSSPP_ARCH in several places already, this makes it more complete.
2021-03-02 21:49:21 -08:00
Unknown W. Brackets 5119d79082 Build: Remove IOS define. 2021-03-02 21:04:03 -08:00
Henrik Rydgård 5077a004ff Mark ARM64 Macs as needing WX-exclusive memory protection 2020-12-02 19:13:52 +01:00
Henrik Rydgård f46759be5a Another missing header buildfix
thanks autechre
2020-10-14 23:49:59 +02:00
Henrik Rydgård 11ab77b995 Remove some TLS. 2020-09-29 15:51:51 +02:00
Henrik Rydgård b43698a13d Remove most instances of base/logging.h from Common, Core, GPU, more 2020-08-15 19:08:44 +02:00
Henrik Rydgård 0829543987 Third part of getting rid of PanicAlert 2020-07-19 20:34:02 +02:00
Henrik Rydgård 617bbcfb87 Step 1 of removing PanicAlert 2020-07-19 20:33:25 +02:00
Unknown W. Brackets a0f846d966 Core: Avoid shadowing a define. 2020-03-08 21:27:45 -07:00
Henrik Rydgård a04720e37e Don't use the MAP_32BIT flag on any platform. 2020-01-04 21:54:25 +01:00
Henrik Rydgård d9b6ab83cf Mac: MAP_32BIT is no longer supported in Catalina and breaks. We don't need it anymore anyway. Fixes #12495. 2020-01-04 21:00:15 +01:00
Anthony J. Bentley 9fc355eee4 Use W^X on OpenBSD. 2017-11-05 17:06:09 -07:00
Jan Beich e33acdc5e9 Common: fix MAP_32BIT after 9f24203ef8
9f24203ef8 added 0x20000000 as a default fallback address hint which
unconditionally disabled MAP_32BIT. FreeBSD cannot use the hints
because without adjusting RLIMIT_DATA lower addresses are reserved for
brk(2) style heap. So, don't try to use hints with MAP_32BIT.
2017-07-26 15:25:54 +00:00
Henrik Rydgård f7fea57bb6 More RIP addressing in software skinning.. 2017-07-07 15:12:57 +02:00
Henrik Rydgård 837118d230 More RIP elimination 2017-07-07 15:07:56 +02:00
Henrik Rydgård 0ec1e5e3b2 Don't erase and rewrite the dispatcher when the cache is cleared. Fixes #9708 2017-05-26 15:48:03 +02:00
Henrik Rydgard ff2b6b3fca Assorted cleanup, UWP memory map fixes. PSPFlower runs in both 32-bit and 64-bit. 2017-03-23 10:02:28 +01:00
Henrik Rydgard 4ced81b1df UWP: Hook up basic touch/mouse input. Start work on loading from a StorageFile. Getting closer to starting to boot a game 2017-03-23 10:02:28 +01:00
Henrik Rydgard de3e906795 Linux buildfix 2017-03-05 11:25:07 +01:00
Henrik Rydgard 7b3f84aae8 More buildfixes for Windows on ARM 2017-03-05 10:52:08 +01:00
Henrik Rydgard f2ccd1d648 Assorted Windows-on-ARM fixes 2017-03-05 10:47:41 +01:00
Henrik Rydgård 1503f00885 Memory function cleanups. Better simulation of RW exclusive mode on Windows (if desired) 2017-01-26 09:49:26 +01:00
Henrik Rydgard b10e0a9a57 Windows buildfix 2017-01-25 20:10:17 +01:00
Henrik Rydgård ff9e1517c7 More bugfixes 2017-01-25 19:11:33 +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 70593d1004 android: Change preprocessor define to standard __ANDROID__
ANDROID is only standard to the old Makefile buildsystem, not the platform.
2016-10-12 11:14:09 +02:00
Florent Castelli 4145b60a0e symbian: Remove! 2016-10-11 18:49:08 +02:00
Henrik Rydgard f39c603acb Move memory protect logging to VERBOSE level. See #8941 (probably something else going on though) 2016-09-04 16:35:23 +02:00
Henrik Rydgard dde50cbdf5 Remove checks for various iOS non-jit situations in settings 2016-08-28 19:01:00 +02:00
Unknown W. Brackets 2fd81a4b29 Fix typo. 2016-08-28 09:44:52 -07:00
Henrik Rydgard 740ef4e0eb Apple buildfix 2016-08-28 18:41:24 +02:00
Henrik Rydgard 3ab2094b76 Buildfix attempt 2016-08-28 18:35:57 +02:00
Henrik Rydgard 2a4f4ed41d iOS buildfix, fix another comment 2016-08-28 18:10:26 +02:00
Henrik Rydgard 1e4b77fb49 Use PAGE_SIZE, fix a comment, fix some indentation. 2016-08-28 18:07:54 +02:00
Henrik Rydgard d82ba24485 Symbian buildfix 2016-08-28 15:07:33 +02:00