libkernel: the JIT shared memory calls are absent (VLC, XPSemu, RetroArch); fix branch ready #3736

Closed
opened 2026-10-11 16:12:16 +00:00 by screamm · 1 comment
screamm commented 2026-10-11 16:12:16 +00:00 (Migrated from github.com)
Contributor

Imported from boykopovar/AnyPS5. Originally posted by screamm on 2026-10-11T16:12:16Z.


libkernel lacks sceKernelJitCreateSharedMemory (avvJ3J0H0EY), sceKernelJitCreateAliasOfSharedMemory (MR221Mwo0Pc) and sceKernelJitMapSharedMemory (YKT49TOLQWs). From the relink registry order they are the next predicted stops of VLC (PPSA85300, 452/462, after getdtablesize), XPSemu (PPSA97358, 398/399) and RetroArch (476 to 478); not yet observed in a run. The titles' own sources (VLC and XPSemu ps5/compat/mmap.c, RetroArch's platform probe Create("ps5-platform-probe", 0x10000, 7, &fd), Alias(fd, 3, &out), Map(fd, 5, &addr)) fall back on any non-zero return, so a throw would be worse than a documented error.

Branch ready: screamm:feat/libkernel-jit-shared-memory (one commit on main a11c8f7f). I cannot open it as a PR because of the intake check; anyone eligible is welcome to carry it, keeping the commit as is.

  • Signatures from Orbital tools/ida/db_types.json, ps4sdk include/sce/kernel.h and ps5-jar-loader LibKernel.java (all agree on the out-pointer form of Alias; SharpProspero's by-value Alias was not followed). New DirectMemory/Jit.cpp: Create makes a host anonymous file (memfd on Linux, a delete-on-close temporary file with a PAGE_EXECUTE_READWRITE section on Windows) and returns a descriptor; Alias duplicates the descriptor with its own maximum protection; Map maps the whole object through the direct-memory placement path (*startOut as a hint like mmap without MAP_FIXED), so a write through one view is visible through every other. close, sceKernelClose, dup and dup2 keep the JIT descriptor table in step.
  • Errors: EINVAL for a zero or non-16 KiB-multiple length, protection bits outside 0x7 or a null output pointer; EACCES for an alias or map asking more than the descriptor's maximum (FreeBSD vm_map_protect); EBADF for a non-JIT descriptor (including shm_open ones); host exhaustion as ENOMEM/EMFILE/ENFILE. Choices no source settles (the 16 KiB rule, EACCES, the ignored name, no flexible-memory accounting, mprotect not capped, no mmap of these descriptors) are recorded in TechnicalDebt.
  • New guest_jit_shared_memory maps an RW alias and an RX view, writes mov eax, imm; ret through one and executes it through the other at two offsets, maps a single RWX view at a hint and runs code there, checks the object survives closing the creating descriptor and dup, and covers every error case.

Tested on Windows 11 Pro 26220, WinLibs MinGW-w64 GCC 15.2.0 r7, Ninja, Release, BUILD_TESTING=ON, full build including libs: guest_jit_shared_memory, guest_shm_open, guest_memory, guest_dup, guest_kernel_fcntl 3/3; ctest -j8 -E "^agc_driver_|^video_out_flip" 534/537, the failures being the known windows_exceptions (#3411, fixed by #3415), guest_kernel_sys (#3510) and guest_filesystem (#3518); the negative check is inconclusive because the implementation file is new (the test is compiled into its own executable and cannot run against main); tools/check_conventions.py --base main and git diff --check pass. The Linux path (memfd, MFD_EXEC with an EINVAL fallback) is not built or run.

Written with Claude Code assistance (implementation by a subagent, reviewed and validated in this session).

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5802808203 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/3736). Originally posted by [screamm](https://github.com/screamm) on 2026-10-11T16:12:16Z. --- libkernel lacks `sceKernelJitCreateSharedMemory` (`avvJ3J0H0EY`), `sceKernelJitCreateAliasOfSharedMemory` (`MR221Mwo0Pc`) and `sceKernelJitMapSharedMemory` (`YKT49TOLQWs`). From the relink registry order they are the next predicted stops of VLC (PPSA85300, 452/462, after `getdtablesize`), XPSemu (PPSA97358, 398/399) and RetroArch (476 to 478); not yet observed in a run. The titles' own sources (VLC and XPSemu `ps5/compat/mmap.c`, RetroArch's platform probe `Create("ps5-platform-probe", 0x10000, 7, &fd)`, `Alias(fd, 3, &out)`, `Map(fd, 5, &addr)`) fall back on any non-zero return, so a throw would be worse than a documented error. **Branch ready:** [`screamm:feat/libkernel-jit-shared-memory`](https://github.com/screamm/AnyPS5/tree/feat/libkernel-jit-shared-memory) (one commit on `main` `a11c8f7f`). I cannot open it as a PR because of the intake check; anyone eligible is welcome to carry it, keeping the commit as is. - Signatures from Orbital `tools/ida/db_types.json`, ps4sdk `include/sce/kernel.h` and ps5-jar-loader `LibKernel.java` (all agree on the out-pointer form of Alias; SharpProspero's by-value Alias was not followed). New `DirectMemory/Jit.cpp`: Create makes a host anonymous file (`memfd` on Linux, a delete-on-close temporary file with a `PAGE_EXECUTE_READWRITE` section on Windows) and returns a descriptor; Alias duplicates the descriptor with its own maximum protection; Map maps the whole object through the direct-memory placement path (`*startOut` as a hint like `mmap` without `MAP_FIXED`), so a write through one view is visible through every other. `close`, `sceKernelClose`, `dup` and `dup2` keep the JIT descriptor table in step. - Errors: `EINVAL` for a zero or non-16 KiB-multiple length, protection bits outside 0x7 or a null output pointer; `EACCES` for an alias or map asking more than the descriptor's maximum (FreeBSD `vm_map_protect`); `EBADF` for a non-JIT descriptor (including `shm_open` ones); host exhaustion as `ENOMEM`/`EMFILE`/`ENFILE`. Choices no source settles (the 16 KiB rule, `EACCES`, the ignored name, no flexible-memory accounting, `mprotect` not capped, no `mmap` of these descriptors) are recorded in TechnicalDebt. - New `guest_jit_shared_memory` maps an RW alias and an RX view, writes `mov eax, imm; ret` through one and executes it through the other at two offsets, maps a single RWX view at a hint and runs code there, checks the object survives closing the creating descriptor and `dup`, and covers every error case. **Tested** on Windows 11 Pro 26220, WinLibs MinGW-w64 GCC 15.2.0 r7, Ninja, Release, `BUILD_TESTING=ON`, full build including `libs`: `guest_jit_shared_memory`, `guest_shm_open`, `guest_memory`, `guest_dup`, `guest_kernel_fcntl` 3/3; `ctest -j8 -E "^agc_driver_|^video_out_flip"` 534/537, the failures being the known `windows_exceptions` (#3411, fixed by #3415), `guest_kernel_sys` (#3510) and `guest_filesystem` (#3518); the negative check is inconclusive because the implementation file is new (the test is compiled into its own executable and cannot run against `main`); `tools/check_conventions.py --base main` and `git diff --check` pass. The Linux path (`memfd`, `MFD_EXEC` with an `EINVAL` fallback) is not built or run. Written with Claude Code assistance (implementation by a subagent, reviewed and validated in this session).
babyhuey commented 2026-10-11 16:37:54 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by babyhuey on 2026-10-11T16:37:54Z.


Linux run of the branch (799e048b, on main a11c8f7f), Ubuntu 24.04, GCC 13, Release, in the repo's build container:

  • guest_jit_shared_memory, guest_shm_open, guest_memory, guest_dup and guest_kernel_fcntl pass 5/5 (--repeat until-fail:5). The JIT test runs all its cases here, including executing the code through the RX and RWX views, so the memfd path works.
  • No new warnings. The one -Wformat-overflow in sceKernelOpen (Open.cpp) shows up on main as well.
  • check_conventions.py --base main passes.

The static import audit on main agrees: sceKernelJitCreateSharedMemory and sceKernelJitMapSharedMemory are absent imports of VLC, XPSemu and RetroArch, and sceKernelJitCreateAliasOfSharedMemory of RetroArch only. None of them is a first stop on main yet. Once one of these titles reaches them I'm happy to carry the branch with your commit as is, unless someone else gets there first.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6111242993 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/3736#issuecomment-6111242993). Originally posted by [babyhuey](https://github.com/babyhuey) on 2026-10-11T16:37:54Z. --- Linux run of the branch (799e048b, on `main` a11c8f7f), Ubuntu 24.04, GCC 13, Release, in the repo's build container: - `guest_jit_shared_memory`, `guest_shm_open`, `guest_memory`, `guest_dup` and `guest_kernel_fcntl` pass 5/5 (`--repeat until-fail:5`). The JIT test runs all its cases here, including executing the code through the RX and RWX views, so the `memfd` path works. - No new warnings. The one `-Wformat-overflow` in `sceKernelOpen` (`Open.cpp`) shows up on `main` as well. - `check_conventions.py --base main` passes. The static import audit on `main` agrees: `sceKernelJitCreateSharedMemory` and `sceKernelJitMapSharedMemory` are absent imports of VLC, XPSemu and RetroArch, and `sceKernelJitCreateAliasOfSharedMemory` of RetroArch only. None of them is a first stop on `main` yet. Once one of these titles reaches them I'm happy to carry the branch with your commit as is, unless someone else gets there first.
Sign in to join this conversation.
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5#3736
No description provided.