17 Commits
Author SHA1 Message Date
Zulux91 c2b5f0c400 Add missing ARM64 instruction-cache maintenance to the JIT
While chasing an unrelated SPURS hang I noticed the JIT publishes
freshly written code on ARM64 with no instruction-cache maintenance at
all. A grep for clear_cache or flushInstructionCache over the JIT layer
comes back empty. The branch-rewrite sites only issue ISB; DSB ISH,
which performs no D-cache clean or I-cache invalidation and is ordered
backwards for self-modifying code besides. On ARMv8 a correct
publication needs the DC CVAU / IC IVAU broadcast sequence; x86 has a
coherent instruction cache, so none of this was ever visible there.
All sites use the bundled asmjit::VirtMem::flushInstructionCache(),
which emits that sequence portably across toolchains.

This covers every publication path I could find:

- MemoryManager1::finalizeMemory() and MemoryManager2::finalizeMemory()
  were both no-ops. RuntimeDyld calls finalizeMemory() after writing
  code and relies on it for cache maintenance, so LLVM emitted PPU and
  SPU code was never flushed. MemoryManager1 serves the primary PPU
  JIT, MemoryManager2 the SPU JIT and auxiliary engines. Both managers
  now record code section allocations and flush them on finalize. I
  confirmed at runtime that the MemoryManager2 path executes (about
  12800 calls per cold boot).
- jit_runtime_base::_add() copies asmjit output into executable memory
  with no flush.
- jit_runtime::finalize() restores an executable code snapshot in place
  during emulator restart with only the ISB/DSB pair.
- spu_runtime::rebuild_ubertrampoline() publishes a hand-written
  trampoline via CAS with no flush; the flush now happens before the
  publication.
- spu_runtime::make_branch_patchpoint() writes a patchpoint byte by
  byte and returns it with only the ISB/DSB pair.
- Both 16-byte branch-site rewrites (dispatch and branch) atomically
  overwrite live code and only issued the ISB/DSB pair.

The ISB/DSB pairs adjacent to the new flushes are removed along with
their misleading "flush all cache lines" comments: the flush helper
already issues the trailing barriers, and the pairs never performed
any cache maintenance in the first place.

I want to be upfront that this was not the cause of the hang I was
debugging (a same-item compilation race, fixed separately), and I have
not observed a failure that this change alone fixes. It is a latent
correctness issue on any ARM64 host: nothing prevents another core
from fetching stale instruction bytes for freshly published code.
2026-08-09 22:19:32 -04:00
Elad 5bbce42adc MacOS: Do not leak MAP_JIT on utils::memory_decommit 2026-07-01 19:31:41 +03:00
Elad 9dc9730898 vm: Make vm::g_exec_addr not use MAP_JIT 2026-07-01 19:31:41 +03:00
AniandRipleyTom e075170cc4 JITASM: include <mutex> on APPLE
Co-Authored-By: RipleyTom <RipleyTom@users.noreply.github.com>
2026-02-20 19:46:39 +02:00
Vestral e2df71d87c Enable ASLR 2025-04-30 02:56:23 +02:00
Elad 4c0832e6e6 PPU LLVM: Reduce size of JIT-transition treampolines to 16 2025-01-25 12:47:44 +02:00
Elad 6fc643f483 JITASM.cpp: add assert for code building 2025-01-25 12:47:44 +02:00
Elad 3f4210437d JIT.h: Add option for lowered function size 2025-01-25 12:47:44 +02:00
kd-11 4d193ecb6a Block parallel JIT allocation on macos 2024-08-29 13:08:23 +03:00
kd-11 ce9024efc5 Fix overlapping addresses returned by mmap 2024-08-29 13:08:23 +03:00
kd-11 23788b04c6 Restore comment 2024-08-29 13:08:23 +03:00
kd-11 c0e577c4dc Allow overcommit on macos 2024-08-29 13:08:23 +03:00
kd-11 56d35bf409 Fix crash in JIT when compiling LLVM blocks 2024-08-25 22:04:45 +03:00
Megamouse b4d5b44e00 Don't create perf map files in linux unless enabled 2024-04-20 19:46:05 +02:00
pastalian e8ad6ec673 Add missing headers (#15075)
Some systems must explicitly include these headers.
2024-01-24 17:22:37 +01:00
oltolm 0ae1578dce split JIT.cpp and SPURecompiler.cpp 2024-01-14 17:21:39 +01:00
oltolm 2039b85be3 prepare split 2024-01-14 17:21:39 +01:00