D006 - Dynamic code generation and JIT memory interface
Status: decided Date: 2026-09-14
Context
Recompilers, dynamic translators, and runtime compiler engines (such as shader compilers, Java VMs, and emulator translation layers) require the ability to emit machine instructions into memory and subsequently execute them. Under PlayStation OS (Prospero / Orbis), the kernel enforces strict W^X (Write XOR Execute) memory policies by default.
Architectural Solution: Dual Strategy
oops-sdk provides an explicit, clean-room JIT subsystem
(oops/jit.h and src/system/jit.c) supporting a
progressive fallback strategy:
Sony Shared Memory Dual-Mapping (
OOPS_JIT_METHOD_SHARED_MEM):- The platform-native mechanism exposes
sceKernelJitCreateSharedMemory,sceKernelJitMapSharedMemory, andsceKernelJitCreateAliasOfSharedMemory. - The underlying physical memory is mapped to two distinct virtual
addresses:
rw_addr: Writable view (mappedSCE_PROT_READ | SCE_PROT_WRITE) used by the recompiler to emit code.rx_addr: Executable view (mappedSCE_PROT_READ | SCE_PROT_EXEC) used by the CPU to execute code.
- This satisfies hardware W^X invariants without flipping page permissions.
- This path is unlocked when the calling process carries JIT authority
(e.g. WebKit Auth ID or
authinfostamped into the fSELF signature area).
- The platform-native mechanism exposes
Relaxed W^X / Direct mprotect (
OOPS_JIT_METHOD_MPROTECT):- On jailbroken systems running
kstuff-lite, the kernel'ssys_mprotectpermission checks are bypassed via hardware debug-register traps (mprotect_fix_start->mprotect_fix_end). - If
sceKernelJitCreateSharedMemoryreturns0x80020001(EPERM) due to default game credentials,oops_jit_alloctransparently falls back tommap+mprotect(PROT_READ | PROT_WRITE | PROT_EXEC). - In this mode,
rw_addrandrx_addrpoint to the same virtual address, permitting immediate execution without requiring custom container authority blocks.
- On jailbroken systems running
Host Emulation (
OOPS_JIT_METHOD_HOST):- On host test runners and CI environments, standard POSIX
mmap/mprotectis utilized, ensuring full testability of dynamic code execution pipelines without hardware dependency.
- On host test runners and CI environments, standard POSIX
Cache Synchronization
Instruction caches must be synchronized and memory writes fenced
before jumping to dynamically generated code.
oops_jit_flush_icache() provides:
- Compiler cache clearing via
__builtin___clear_cache(). - Pipeline serialization and memory fencing via x86
mfence.
Provenance and Safety
- All symbols (
sceKernelJitCreateSharedMemory,sceKernelJitMapSharedMemory,sceKernelJitCreateAliasOfSharedMemory,mmap,mprotect,munmap) are declared as weak symbols or resolved dynamically. oops_jit_alloc()andoops_jit_is_available()fail safely and return-1or0on unpatched or unsupported platforms, adhering strictly to CONVENTIONS ยง3.