feat(libkernel): implement the JIT shared memory calls #3787

Merged
YossiYad merged 3 commits from upstream-pr/3787 into main 2026-10-12 20:17:55 +00:00
YossiYad commented 2026-10-11 16:42:35 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by YossiYad on 2026-10-11T16:42:35Z.


What

Carries screamm's screamm/AnyPS5:feat/libkernel-jit-shared-memory commit from #3736 unchanged onto current main, preserving its author, and adds one follow-up test commit:

  • Implement sceKernelJitCreateSharedMemory, sceKernelJitCreateAliasOfSharedMemory and sceKernelJitMapSharedMemory. Create backs the object with a host anonymous file (memfd on Linux, a delete-on-close temporary file section on Windows) and returns a descriptor; Alias duplicates it with its own maximum protection; Map maps the whole object through the direct-memory placement path, so a write through one view is visible through every other. close, sceKernelClose, dup and dup2 keep the JIT descriptor table in step. VLC (PPSA85300), XPSemu (PPSA97358) and RetroArch import these calls, as reported in #3736; their sources fall back on a non-zero return, so the errors are returned rather than thrown.
  • Extend guest_jit_shared_memory with dup2: a JIT descriptor moved onto another descriptor maps the same object with the source's maximum protection, dup2 onto itself keeps it, and an ordinary descriptor moved onto a JIT one is no longer treated as JIT. The original test does not call dup2: with the Linux dup2 no longer copying the entry, or DuplicateJitSharedMemory no longer forgetting the target, the original test still passes and the extended one fails.

The library progress moves from 2903/3383 (85.81%) to 2906/3386 (85.82%). The total rises by three because none of the calls was exported before. Choices no source settles are recorded in TechnicalDebt.

Closes #3736.

Tested

Linux (Bazzite 44, GCC 16.2.1, Ninja, Release, -DBUILD_TESTING=ON), based on main a11c8f7f:

  • Full build, libs, and full ctest: 825 pass, 8 skip, no failures (833 registered tests). The GPU agc_driver_pixel_interlock test failed on an earlier run and passed on the final full run; the changed library does not participate in that test.
  • guest_jit_shared_memory, guest_shm_open, guest_memory, guest_dup and guest_kernel_fcntl pass 10 consecutive runs; guest_jit_shared_memory runs every case here, including executing code through the RX and RWX views.
  • The two mutations above were applied one at a time and checked against both the original and the extended test.
  • tools/check_conventions.py --base upstream/main and git diff --check pass.
  • The original author reported Windows testing in #3736, and babyhuey reported a Linux run of the carried commit there. The new test case was not run on Windows, and no title was run on this machine.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw; no silent stubs added
  • No notes, investigation .md files or images added to the repository
  • No new third-party code
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4820643916 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3787). Originally posted by [YossiYad](https://github.com/YossiYad) on 2026-10-11T16:42:35Z. --- ### What Carries screamm's `screamm/AnyPS5:feat/libkernel-jit-shared-memory` commit from #3736 unchanged onto current `main`, preserving its author, and adds one follow-up test commit: - Implement `sceKernelJitCreateSharedMemory`, `sceKernelJitCreateAliasOfSharedMemory` and `sceKernelJitMapSharedMemory`. Create backs the object with a host anonymous file (`memfd` on Linux, a delete-on-close temporary file section on Windows) and returns a descriptor; Alias duplicates it with its own maximum protection; Map maps the whole object through the direct-memory placement path, so a write through one view is visible through every other. `close`, `sceKernelClose`, `dup` and `dup2` keep the JIT descriptor table in step. VLC (PPSA85300), XPSemu (PPSA97358) and RetroArch import these calls, as reported in #3736; their sources fall back on a non-zero return, so the errors are returned rather than thrown. - Extend `guest_jit_shared_memory` with `dup2`: a JIT descriptor moved onto another descriptor maps the same object with the source's maximum protection, `dup2` onto itself keeps it, and an ordinary descriptor moved onto a JIT one is no longer treated as JIT. The original test does not call `dup2`: with the Linux `dup2` no longer copying the entry, or `DuplicateJitSharedMemory` no longer forgetting the target, the original test still passes and the extended one fails. The library progress moves from 2903/3383 (85.81%) to 2906/3386 (85.82%). The total rises by three because none of the calls was exported before. Choices no source settles are recorded in TechnicalDebt. Closes #3736. ### Tested Linux (Bazzite 44, GCC 16.2.1, Ninja, Release, `-DBUILD_TESTING=ON`), based on `main` `a11c8f7f`: - Full build, `libs`, and full `ctest`: 825 pass, 8 skip, no failures (833 registered tests). The GPU `agc_driver_pixel_interlock` test failed on an earlier run and passed on the final full run; the changed library does not participate in that test. - `guest_jit_shared_memory`, `guest_shm_open`, `guest_memory`, `guest_dup` and `guest_kernel_fcntl` pass 10 consecutive runs; `guest_jit_shared_memory` runs every case here, including executing code through the RX and RWX views. - The two mutations above were applied one at a time and checked against both the original and the extended test. - `tools/check_conventions.py --base upstream/main` and `git diff --check` pass. - The original author reported Windows testing in #3736, and babyhuey reported a Linux run of the carried commit there. The new test case was not run on Windows, and no title was run on this machine. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except technical debt - [x] Unimplemented paths throw; no silent stubs added - [x] No notes, investigation `.md` files or images added to the repository - [x] No new third-party code - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes
github-actions[bot] commented 2026-10-11 16:44:25 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-11T16:44:25Z.


Progress report (3e0e01f → 3b7ac15)

📈 System libraries: 86.38% (+0.02%, +3 implemented functions)

✅ 3 implemented
Library Name
libkernel sceKernelJitCreateAliasOfSharedMemory
libkernel sceKernelJitCreateSharedMemory
libkernel sceKernelJitMapSharedMemory
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6111303478 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3787#issuecomment-6111303478). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-11T16:44:25Z. --- <!-- progress-report --> ### Progress report (3e0e01f → 3b7ac15) 📈 **System libraries**: 86.38% (+0.02%, +3 implemented functions) <details> <summary>✅ 3 implemented</summary> | Library | Name | | - | - | | libkernel | `sceKernelJitCreateAliasOfSharedMemory` | | libkernel | `sceKernelJitCreateSharedMemory` | | libkernel | `sceKernelJitMapSharedMemory` | </details>
oneandonlydean commented 2026-10-11 23:16:59 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-11T23:16:59Z.


Two retries after an error in core/libs/prx/libkernel/DirectMemory/Jit.cpp, which aren't allowed here:

  • CreateExecutableFile calls memfd_create with MFD_EXEC and calls it again without the flag on EINVAL. Pick one call up front.
  • The Windows CreateBacking loops up to 64 times on ERROR_FILE_EXISTS. Use a name that can't collide and throw if CreateFileW fails.
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6115005312 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3787#issuecomment-6115005312). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-11T23:16:59Z. --- Two retries after an error in `core/libs/prx/libkernel/DirectMemory/Jit.cpp`, which aren't allowed here: - `CreateExecutableFile` calls `memfd_create` with `MFD_EXEC` and calls it again without the flag on `EINVAL`. Pick one call up front. - The Windows `CreateBacking` loops up to 64 times on `ERROR_FILE_EXISTS`. Use a name that can't collide and throw if `CreateFileW` fails.
screamm commented 2026-10-12 06:56:44 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by screamm on 2026-10-12T06:56:44Z.


Thanks for the review. The two retries are removed in a fix-up commit on top of this PR's carried commit: screamm:feat/libkernel-jit-shared-memory-v2, commit eb91497b7 (fix(libkernel): create the JIT shared memory backing in one call, based on current main 2ccbd376); @YossiYad, cherry-picking that one commit onto this branch should be enough (your dup2 test commit is untouched).

  • Linux: memfd_create is called once with MFD_CLOEXEC only. MFD_EXEC is dropped rather than retried: it only sets the file's execute permission bits (6.3+, EINVAL on older kernels), while mapping the object executable depends on the mapping protection alone, the same as the direct memory memfd in DirectMemory.cpp; a compile-time #ifdef MFD_EXEC would reflect the headers, not the running kernel. Recorded in TechnicalDebt, including that vm.memfd_noexec=2 makes the call throw.
  • Windows: CreateBacking no longer loops on ERROR_FILE_EXISTS; the delete-on-close backing file is named anyps5-jit-<pid>-<atomic counter>-<QueryPerformanceCounter>, so CREATE_NEW cannot meet an existing name, and any CreateFileW failure throws std::system_error with the Win32 error. The descriptor stays a CRT descriptor, so close/dup/dup2 behave as before.

Tested on Windows 11 Pro 26220, WinLibs MinGW-w64 GCC 15.2.0 r7, Release, 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" 594/594; conventions and git diff --check pass. The Linux side is not compiled here.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6119324417 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3787#issuecomment-6119324417). Originally posted by [screamm](https://github.com/screamm) on 2026-10-12T06:56:44Z. --- Thanks for the review. The two retries are removed in a fix-up commit on top of this PR's carried commit: [`screamm:feat/libkernel-jit-shared-memory-v2`](https://github.com/screamm/AnyPS5/tree/feat/libkernel-jit-shared-memory-v2), commit `eb91497b7` (`fix(libkernel): create the JIT shared memory backing in one call`, based on current `main` `2ccbd376`); @YossiYad, cherry-picking that one commit onto this branch should be enough (your `dup2` test commit is untouched). - Linux: `memfd_create` is called once with `MFD_CLOEXEC` only. `MFD_EXEC` is dropped rather than retried: it only sets the file's execute permission bits (6.3+, `EINVAL` on older kernels), while mapping the object executable depends on the mapping protection alone, the same as the direct memory memfd in `DirectMemory.cpp`; a compile-time `#ifdef MFD_EXEC` would reflect the headers, not the running kernel. Recorded in TechnicalDebt, including that `vm.memfd_noexec=2` makes the call throw. - Windows: `CreateBacking` no longer loops on `ERROR_FILE_EXISTS`; the delete-on-close backing file is named `anyps5-jit-<pid>-<atomic counter>-<QueryPerformanceCounter>`, so `CREATE_NEW` cannot meet an existing name, and any `CreateFileW` failure throws `std::system_error` with the Win32 error. The descriptor stays a CRT descriptor, so close/dup/dup2 behave as before. Tested on Windows 11 Pro 26220, WinLibs MinGW-w64 GCC 15.2.0 r7, Release, 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"` 594/594; conventions and `git diff --check` pass. The Linux side is not compiled here.
babyhuey commented 2026-10-12 10:54:44 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by babyhuey on 2026-10-12T10:54:44Z.


A catalog title reaches these calls: PS5CEMU-HAR (PPSA99360). It is built with the ps5-payload-dev SDK, so it relinks only with --trap-sdk-syscall-stubs (#3804, see #2136).

  • On main it stops at avvJ3J0H0EY (sceKernelJitCreateSharedMemory). It also imports YKT49TOLQWs (sceKernelJitMapSharedMemory).
  • With this PR merged onto main e7c70a2d (ea27cc46, clean), both resolve, and the next stop is pthread_setaffinity_np on Linux and Windows 11 (MinGW GCC 15.2):
    • Linux: undefined symbol: 5KWrg7-ZqvE (pthread_setaffinity_np)
    • Windows: FAIL: unresolved ELF import 5KWrg7-ZqvE (pthread_setaffinity_np) from libkernel.prx
  • guest_jit_shared_memory passes 5/5 (--repeat until-fail:5) on both, with no warnings in the PR's files.
  • No anyps5-jit-* temporary files remain in %TEMP% on Windows after the tests and the title run.
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6122846457 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3787#issuecomment-6122846457). Originally posted by [babyhuey](https://github.com/babyhuey) on 2026-10-12T10:54:44Z. --- A catalog title reaches these calls: PS5CEMU-HAR (PPSA99360). It is built with the ps5-payload-dev SDK, so it relinks only with `--trap-sdk-syscall-stubs` (#3804, see #2136). - On `main` it stops at `avvJ3J0H0EY` (`sceKernelJitCreateSharedMemory`). It also imports `YKT49TOLQWs` (`sceKernelJitMapSharedMemory`). - With this PR merged onto `main` e7c70a2d (ea27cc46, clean), both resolve, and the next stop is `pthread_setaffinity_np` on Linux and Windows 11 (MinGW GCC 15.2): - Linux: `undefined symbol: 5KWrg7-ZqvE (pthread_setaffinity_np)` - Windows: `FAIL: unresolved ELF import 5KWrg7-ZqvE (pthread_setaffinity_np) from libkernel.prx` - `guest_jit_shared_memory` passes 5/5 (`--repeat until-fail:5`) on both, with no warnings in the PR's files. - No `anyps5-jit-*` temporary files remain in `%TEMP%` on Windows after the tests and the title run.
Dextroid17 commented 2026-10-12 18:30:10 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-12T18:30:10Z.

Review: COMMENTED


The two review points, and the Linux half of the fix-up commit

No PR of mine touches this path — this is a measurement, and nothing is requested.

Both of @oneandonlydean's points are addressed by @screamm's fix-up commit eb91497b7 (screamm:feat/libkernel-jit-shared-memory-v2). His comment on this PR says that commit's Linux side was not compiled there ("The Linux side is not compiled here"), and that is the half I built and ran below.

The two asks, still open at the head 151626cc7

core/libs/prx/libkernel/DirectMemory/Jit.cpp:111  for (int attempt = 0; attempt < 64 && file == INVALID_HANDLE_VALUE; ++attempt)
core/libs/prx/libkernel/DirectMemory/Jit.cpp:143  const int file = memfd_create("anyps5 jit shared memory", MFD_CLOEXEC | MFD_EXEC);
core/libs/prx/libkernel/DirectMemory/Jit.cpp:146  return memfd_create("anyps5 jit shared memory", MFD_CLOEXEC);

The fix applies to this head unchanged

git cherry-pick -x eb91497b7 on 151626cc7 gives 81a9cae57 with no conflicts (the only merge message is Auto-merging docs/dev/TechnicalDebt.md; its tree is c9eb40b9). Afterwards — a source reading, since Windows is not built on this box:

Jit.cpp:104  std::filesystem::path BackingPath()   pid + process-wide atomic counter + QueryPerformanceCounter
Jit.cpp:113  CreateFileW(BackingPath().c_str(), ..., CREATE_NEW, FILE_FLAG_DELETE_ON_CLOSE)
Jit.cpp:115  a failure throws std::system_error(GetLastError(), ...)      (the 64-attempt loop is gone)
Jit.cpp:140  memfd_create("anyps5 jit shared memory", MFD_CLOEXEC)        (one call site, no #ifdef)

MFD_EXEC occurs nowhere in that file afterwards (twice at the head), and the name cannot repeat within a process (pid plus a process-wide counter; the performance counter covers the cross-process case). <random> and <stdexcept> are dropped from the includes with no random_device and no runtime_error left, so the Windows branch still has everything it uses (<system_error>, <atomic>, <filesystem>, <windows.h>).

One inconsistency worth a look while this is open: :115 throws for any CreateFileW failure, while the section failure two lines below still routes the memory errors through WindowsFailure to SCE_KERNEL_ERROR_ENOMEM (:99-101, called at :121). That follows the review as written ("throw if CreateFileW fails"), so it is an observation, not a request.

Linux, both arms

CachyOS, GCC 16.2.1, CMake 4.4.3, Ninja, Release, -DBUILD_TESTING=ON, kernel 7.2.9-2-cachyos. Arm A is the head 151626cc7, arm B is 81a9cae57; Jit.cpp is the only compiled difference (the fix also edits one TechnicalDebt sentence).

                       guest_jit_shared_memory   ctest          direct, 3 consecutive runs
arm A  151626cc7       pass                      1/1  0.00 s    exit 0, 0, 0
arm B  81a9cae57       pass                      1/1  0.00 s    exit 0, 0, 0
arm B  neighbours      guest_shm_open, guest_dup, guest_memory, guest_kernel_fcntl -> 5/5, 0.12 s

The test maps an RX view (core/libs/tests/GuestJitSharedMemory.cpp:67) and calls through it (:72), maps an RWX view (:90) and calls through it (:93), and repeats that through a dup descriptor (:97, called at :98) — so the Linux path the fix touches really ran code here. Both arms pass, so the test does not by itself separate the fix; the counts below do.

The call counts, measured

An LD_PRELOAD interposer on memfd_create (logging the name and the flags), with the test binary rebuilt from each arm:

arm A  151626cc7   4x memfd_create("anyps5 jit shared memory", flags=0x0011)   MFD_CLOEXEC|MFD_EXEC
                   3x memfd_create("anyps5 shm_open",          flags=0x0001)
arm B  81a9cae57   4x memfd_create("anyps5 jit shared memory", flags=0x0001)
                   3x memfd_create("anyps5 shm_open",          flags=0x0001)

Seven calls and four JIT objects in both arms. The object file says the same without running anything: Jit.cpp.o carries two memfd_create relocations at arm A (0x208c, 0x20e1) and one at arm B (0x208c). So on Linux the fix removes a call site rather than a call — on this host there is no first error to retry, because vm.memfd_noexec is 0 and the kernel accepts MFD_EXEC, and the review point is about the retry the shape allows. On Windows the change is behavioural, as noted above; these counts say nothing about that platform.

Is dropping MFD_EXEC safe here? An independent probe, not the PR's code

memfd_create + ftruncate(4096) + mmap(PROT_READ|PROT_WRITE|PROT_EXEC, MAP_SHARED, fd, 0), then executing mov $42,%eax; ret out of that mapping, on this kernel — the execute-through-mapping rows, verbatim:

MFD_CLOEXEC|MFD_EXEC         memfd ok, mode 0777, mmap RWX ok, executed 42
MFD_CLOEXEC (no MFD_EXEC)    memfd ok, mode 0777, mmap RWX ok, executed 42
MFD_CLOEXEC|MFD_NOEXEC_SEAL  memfd ok, mode 0666, mmap RWX ok, executed 42

So on this kernel the flag is not what makes the object executable — the mapping protection is, which is what the commit message says — and it is not a new pattern either: the direct memory memfd beside it is created without MFD_EXEC (DirectMemory.cpp:232, MFD_CLOEXEC | MFD_ALLOW_SEALING). What I could not check: there is no root here, so vm.memfd_noexec cannot be moved off 0, and the policy-2 refusal in the new debt sentence is screamm's statement rather than something I ran; and a pre-6.3 kernel, where MFD_EXEC is an unknown flag returning EINVAL — the case the removed retry existed for.

Three smaller things

  • This test cannot run in CI for this PR. The linux and windows jobs are gated on github.event_name == 'push' || 'workflow_dispatch' with full == 'true' (build.yml:193, :240), and the job a pull request does get configures -DANYPS5_RELINKER_ONLY=ON (build.yml:160), after which CMakeLists.txt:90-93 returns before add_subdirectory(core/libs) at :153 — guest_jit_shared_memory is not even registered in that build. Every execution of it is a local one.
  • The head does not merge into current main cleanly: git merge-tree --write-tree pr-3787 upstream/main reports conflicts in core/libs/prx/libkernel/File/src/Open.cpp and File/src/Stdio.cpp (main was 4a49cda98 when I ran it, having moved twice earlier today), so a rebase is due — and the fix applies to this head with no conflicts.
  • The PR body says sceKernelClose keeps the descriptor table in step, and Open.cpp:227-229 does hook it, but the test closes only through close_nid_postfix, so that path has no case.

Not checked here: Windows compile and behaviour (screamm's and @babyhuey's Windows runs on the thread stand), and the full suite — I built the JIT target and the four neighbours, not all of the registered tests. The title half of the bar is already on the thread (@babyhuey's PS5CEMU-HAR run above).

AI-assisted: yes.

Hermes Agent 🤖 at your service

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5494618109 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3787#pullrequestreview-5494618109). Originally posted by [Dextroid17](https://github.com/Dextroid17) on 2026-10-12T18:30:10Z. **Review:** COMMENTED --- **The two review points, and the Linux half of the fix-up commit** No PR of mine touches this path — this is a measurement, and nothing is requested. Both of @oneandonlydean's points are addressed by @screamm's fix-up commit `eb91497b7` (`screamm:feat/libkernel-jit-shared-memory-v2`). His comment on this PR says that commit's Linux side was not compiled there ("The Linux side is not compiled here"), and that is the half I built and ran below. ### The two asks, still open at the head `151626cc7` ``` core/libs/prx/libkernel/DirectMemory/Jit.cpp:111 for (int attempt = 0; attempt < 64 && file == INVALID_HANDLE_VALUE; ++attempt) core/libs/prx/libkernel/DirectMemory/Jit.cpp:143 const int file = memfd_create("anyps5 jit shared memory", MFD_CLOEXEC | MFD_EXEC); core/libs/prx/libkernel/DirectMemory/Jit.cpp:146 return memfd_create("anyps5 jit shared memory", MFD_CLOEXEC); ``` ### The fix applies to this head unchanged `git cherry-pick -x eb91497b7` on `151626cc7` gives `81a9cae57` with no conflicts (the only merge message is `Auto-merging docs/dev/TechnicalDebt.md`; its tree is `c9eb40b9`). Afterwards — a source reading, since Windows is not built on this box: ``` Jit.cpp:104 std::filesystem::path BackingPath() pid + process-wide atomic counter + QueryPerformanceCounter Jit.cpp:113 CreateFileW(BackingPath().c_str(), ..., CREATE_NEW, FILE_FLAG_DELETE_ON_CLOSE) Jit.cpp:115 a failure throws std::system_error(GetLastError(), ...) (the 64-attempt loop is gone) Jit.cpp:140 memfd_create("anyps5 jit shared memory", MFD_CLOEXEC) (one call site, no #ifdef) ``` `MFD_EXEC` occurs nowhere in that file afterwards (twice at the head), and the name cannot repeat within a process (pid plus a process-wide counter; the performance counter covers the cross-process case). `<random>` and `<stdexcept>` are dropped from the includes with no `random_device` and no `runtime_error` left, so the Windows branch still has everything it uses (`<system_error>`, `<atomic>`, `<filesystem>`, `<windows.h>`). One inconsistency worth a look while this is open: `:115` throws for any `CreateFileW` failure, while the section failure two lines below still routes the memory errors through `WindowsFailure` to `SCE_KERNEL_ERROR_ENOMEM` (`:99-101`, called at `:121`). That follows the review as written ("throw if `CreateFileW` fails"), so it is an observation, not a request. ### Linux, both arms CachyOS, GCC 16.2.1, CMake 4.4.3, Ninja, Release, `-DBUILD_TESTING=ON`, kernel `7.2.9-2-cachyos`. Arm A is the head `151626cc7`, arm B is `81a9cae57`; `Jit.cpp` is the only compiled difference (the fix also edits one TechnicalDebt sentence). ``` guest_jit_shared_memory ctest direct, 3 consecutive runs arm A 151626cc7 pass 1/1 0.00 s exit 0, 0, 0 arm B 81a9cae57 pass 1/1 0.00 s exit 0, 0, 0 arm B neighbours guest_shm_open, guest_dup, guest_memory, guest_kernel_fcntl -> 5/5, 0.12 s ``` The test maps an RX view (`core/libs/tests/GuestJitSharedMemory.cpp:67`) and calls through it (`:72`), maps an RWX view (`:90`) and calls through it (`:93`), and repeats that through a `dup` descriptor (`:97`, called at `:98`) — so the Linux path the fix touches really ran code here. Both arms pass, so the test does not by itself separate the fix; the counts below do. ### The call counts, measured An `LD_PRELOAD` interposer on `memfd_create` (logging the name and the flags), with the test binary rebuilt from each arm: ``` arm A 151626cc7 4x memfd_create("anyps5 jit shared memory", flags=0x0011) MFD_CLOEXEC|MFD_EXEC 3x memfd_create("anyps5 shm_open", flags=0x0001) arm B 81a9cae57 4x memfd_create("anyps5 jit shared memory", flags=0x0001) 3x memfd_create("anyps5 shm_open", flags=0x0001) ``` Seven calls and four JIT objects in both arms. The object file says the same without running anything: `Jit.cpp.o` carries two `memfd_create` relocations at arm A (`0x208c`, `0x20e1`) and one at arm B (`0x208c`). So on Linux the fix removes a call site rather than a call — on this host there is no first error to retry, because `vm.memfd_noexec` is 0 and the kernel accepts `MFD_EXEC`, and the review point is about the retry the shape allows. On Windows the change is behavioural, as noted above; these counts say nothing about that platform. ### Is dropping `MFD_EXEC` safe here? An independent probe, not the PR's code `memfd_create` + `ftruncate(4096)` + `mmap(PROT_READ|PROT_WRITE|PROT_EXEC, MAP_SHARED, fd, 0)`, then executing `mov $42,%eax; ret` out of that mapping, on this kernel — the execute-through-mapping rows, verbatim: ``` MFD_CLOEXEC|MFD_EXEC memfd ok, mode 0777, mmap RWX ok, executed 42 MFD_CLOEXEC (no MFD_EXEC) memfd ok, mode 0777, mmap RWX ok, executed 42 MFD_CLOEXEC|MFD_NOEXEC_SEAL memfd ok, mode 0666, mmap RWX ok, executed 42 ``` So on this kernel the flag is not what makes the object executable — the mapping protection is, which is what the commit message says — and it is not a new pattern either: the direct memory memfd beside it is created without `MFD_EXEC` (`DirectMemory.cpp:232`, `MFD_CLOEXEC | MFD_ALLOW_SEALING`). What I could not check: there is no root here, so `vm.memfd_noexec` cannot be moved off 0, and the policy-2 refusal in the new debt sentence is screamm's statement rather than something I ran; and a pre-6.3 kernel, where `MFD_EXEC` is an unknown flag returning `EINVAL` — the case the removed retry existed for. ### Three smaller things - **This test cannot run in CI for this PR.** The `linux` and `windows` jobs are gated on `github.event_name == 'push' || 'workflow_dispatch'` with `full == 'true'` (`build.yml:193`, `:240`), and the job a pull request does get configures `-DANYPS5_RELINKER_ONLY=ON` (`build.yml:160`), after which `CMakeLists.txt:90-93` returns before `add_subdirectory(core/libs)` at `:153` — `guest_jit_shared_memory` is not even registered in that build. Every execution of it is a local one. - The head does not merge into current `main` cleanly: `git merge-tree --write-tree pr-3787 upstream/main` reports conflicts in `core/libs/prx/libkernel/File/src/Open.cpp` and `File/src/Stdio.cpp` (main was `4a49cda98` when I ran it, having moved twice earlier today), so a rebase is due — and the fix applies to this head with no conflicts. - The PR body says `sceKernelClose` keeps the descriptor table in step, and `Open.cpp:227-229` does hook it, but the test closes only through `close_nid_postfix`, so that path has no case. Not checked here: Windows compile and behaviour (screamm's and @babyhuey's Windows runs on the thread stand), and the full suite — I built the JIT target and the four neighbours, not all of the registered tests. The title half of the bar is already on the thread (@babyhuey's PS5CEMU-HAR run above). AI-assisted: yes. Hermes Agent 🤖 at your service
adriadam10 commented 2026-10-12 20:02:08 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-12T20:02:08Z.


Rebased onto current main (the TechnicalDebt entry now lives in docs/dev/debt/libkernel.md) and added @screamm's fix-up for @oneandonlydean's two review points, cherry-picked with its authorship: memfd_create is called once with MFD_CLOEXEC (no MFD_EXEC retry), and the Windows backing name is unique per process/counter/performance counter with CreateFileW failure thrown instead of looping on ERROR_FILE_EXISTS. TechnicalDebt records the dropped MFD_EXEC.

Checked on Linux (GCC, Release): guest_jit_shared_memory, guest_shm_open, guest_dup and guest_kernel_fcntl pass 5 consecutive runs, including the RX/RWX execution cases. The Windows part of the fix-up was reviewed but not compiled here. Merging once CI is green.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6131675051 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3787#issuecomment-6131675051). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-12T20:02:08Z. --- Rebased onto current `main` (the TechnicalDebt entry now lives in `docs/dev/debt/libkernel.md`) and added @screamm's fix-up for @oneandonlydean's two review points, cherry-picked with its authorship: `memfd_create` is called once with `MFD_CLOEXEC` (no `MFD_EXEC` retry), and the Windows backing name is unique per process/counter/performance counter with `CreateFileW` failure thrown instead of looping on `ERROR_FILE_EXISTS`. TechnicalDebt records the dropped `MFD_EXEC`. Checked on Linux (GCC, Release): `guest_jit_shared_memory`, `guest_shm_open`, `guest_dup` and `guest_kernel_fcntl` pass 5 consecutive runs, including the RX/RWX execution cases. The Windows part of the fix-up was reviewed but not compiled here. Merging once CI is green.
github-actions[bot] commented 2026-10-12 20:06:46 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-12T20:06:46Z.


Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
#3649 core/libs/prx/libkernel/File/src/Stdio.cpp L586
#4101 docs/dev/debt/libkernel.md L93
#4725 core/libs/prx/libkernel/DirectMemory/DirectMemory.hpp L40
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6131743602 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3787#issuecomment-6131743602). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-12T20:06:46Z. --- <!-- pr-overlap --> Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in **Depends on**. | Pull request | Conflicting files (lines on `main`) | Same exports | Same new files | |---|---|---|---| | #3649 | `core/libs/prx/libkernel/File/src/Stdio.cpp` [L586](https://github.com/boykopovar/AnyPS5/blob/0428328b79af7820990ffc6964fb9009041bcdcf/core/libs/prx/libkernel/File/src/Stdio.cpp#L586) | | | | #4101 | `docs/dev/debt/libkernel.md` [L93](https://github.com/boykopovar/AnyPS5/blob/0428328b79af7820990ffc6964fb9009041bcdcf/docs/dev/debt/libkernel.md#L93) | | | | #4725 | `core/libs/prx/libkernel/DirectMemory/DirectMemory.hpp` [L40](https://github.com/boykopovar/AnyPS5/blob/0428328b79af7820990ffc6964fb9009041bcdcf/core/libs/prx/libkernel/DirectMemory/DirectMemory.hpp#L40) | | |
Sign in to join this conversation.
No reviewers
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!3787
No description provided.