feat(libkernel): add mlockall export #4386

Merged
MarcZX10 merged 1 commit from upstream-pr/4386 into main 2026-10-13 11:37:29 +00:00
MarcZX10 commented 2026-10-12 08:33:45 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-12T08:33:45Z.


What

Adds the mlockall export as a single focused change. Zero and unknown flags return EINVAL; valid MCL_CURRENT and MCL_FUTURE requests throw because safely locking guest memory would require excluding host stacks, heaps, modules and driver mappings, and tracking later mappings.

On main 7e181fcc, XPSemu (PPSA97358, catalog release) stops loading at unresolved import x7g7Ebeo8-U (mlockall). The reported call sites request MCL_CURRENT | MCL_FUTURE, and run only with -overcommit mem-lock=on; the title's default is off. This supplies the missing export. It does not claim a successful title run with mem-lock enabled, where valid calls remain unsupported.

Tested

  • Before the current rebase, a Windows 10 MinGW-w64 run reported a full build and guest_getrlimit / guest_mlock passing 2/2 on earlier head 61b12b9e1.
  • A Linux rebase handoff reported a full suite passing 954/954 on its earlier two-export branch. Those results are not from this single-export head.
  • Current head: git diff --check upstream/main...HEAD passed. No build or runtime tests were run after the latest rebase onto main fc1f063f5.

Checklist

  • Based on current main; no other open PR implements the same function
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Unblocks: none
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4826897575 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4386). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-12T08:33:45Z. --- ### What Adds the `mlockall` export as a single focused change. Zero and unknown flags return `EINVAL`; valid `MCL_CURRENT` and `MCL_FUTURE` requests throw because safely locking guest memory would require excluding host stacks, heaps, modules and driver mappings, and tracking later mappings. On main `7e181fcc`, XPSemu (PPSA97358, catalog release) stops loading at unresolved import `x7g7Ebeo8-U` (`mlockall`). The reported call sites request `MCL_CURRENT | MCL_FUTURE`, and run only with `-overcommit mem-lock=on`; the title's default is off. This supplies the missing export. It does not claim a successful title run with mem-lock enabled, where valid calls remain unsupported. ### Tested - Before the current rebase, a Windows 10 MinGW-w64 run reported a full build and `guest_getrlimit` / `guest_mlock` passing 2/2 on earlier head `61b12b9e1`. - A Linux rebase handoff reported a full suite passing 954/954 on its earlier two-export branch. Those results are not from this single-export head. - Current head: `git diff --check upstream/main...HEAD` passed. No build or runtime tests were run after the latest rebase onto `main` `fc1f063f5`. ### Checklist - [x] Based on current `main`; no other open PR implements the same function - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except technical debt - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's technical debt file - [x] No notes, investigation `.md` files or images added to the repository - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Unblocks: none - [x] AI-assisted: yes
reyani-dev commented 2026-10-12 08:43:37 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by reyani-dev on 2026-10-12T08:43:37Z.


Title evidence for the getdtablesize half (#3650 was closed because "no title gets further with this"). VLC (PPSA85300) does get further with a throwing getdtablesize, because it never calls it:

  • Stop: on main e013f8c9 plus a readdir_r (#3635 doesn't merge onto main right now, so I used screamm's branch from #3556), VLC stops at FAIL: unresolved ELF import sZuwaDPATKs from libkernel.prx (getdtablesize). Windows 11, catalog build.
  • The only call site (guest 0x16FA11D) is a closefrom-style loop: n = getdtablesize(); for (fd = max(low, 0); fd < n; ++fd) close(fd);. It is called once, with low = 3, from a spawn helper's child path (0x16f6380..0x16f6520): pipe/dup, then dup2(in, 0), dup2(out, 1), closefrom(3), execvp, _exit.
  • That child never exists: the helper forks through 0x141ee3ca0, which sets errno 78 (ENOSYS) and returns -1. That's xemu_ps5_fork in libc_missing.c, the same reason the merged execvp TechnicalDebt entry gives.
  • With a throwing getdtablesize added, VLC's next stop is YKT49TOLQWs (sceKernelJitMapSharedMemory, #3787).

XPSemu (PPSA97358) also imports it, from a different call site (0x3603DD, after pipe and four fcntl calls). I haven't traced whether that one is reachable.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6120805606 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4386#issuecomment-6120805606). Originally posted by [reyani-dev](https://github.com/reyani-dev) on 2026-10-12T08:43:37Z. --- Title evidence for the `getdtablesize` half (#3650 was closed because "no title gets further with this"). VLC (PPSA85300) does get further with a throwing `getdtablesize`, because it never calls it: - **Stop:** on `main` e013f8c9 plus a `readdir_r` (#3635 doesn't merge onto `main` right now, so I used screamm's branch from #3556), VLC stops at `FAIL: unresolved ELF import sZuwaDPATKs from libkernel.prx` (`getdtablesize`). Windows 11, catalog build. - **The only call site** (guest `0x16FA11D`) is a `closefrom`-style loop: `n = getdtablesize(); for (fd = max(low, 0); fd < n; ++fd) close(fd);`. It is called once, with `low = 3`, from a spawn helper's child path (`0x16f6380`..`0x16f6520`): `pipe`/`dup`, then `dup2(in, 0)`, `dup2(out, 1)`, `closefrom(3)`, `execvp`, `_exit`. - **That child never exists:** the helper forks through `0x141ee3ca0`, which sets errno 78 (`ENOSYS`) and returns -1. That's `xemu_ps5_fork` in [libc_missing.c](https://github.com/ZiZc3/VLC/blob/f3253020a64368153233ede29183014c0b6c8979/ps5/compat/libc_missing.c#L290-L292), the same reason the merged `execvp` TechnicalDebt entry gives. - **With a throwing `getdtablesize` added**, VLC's next stop is `YKT49TOLQWs` (`sceKernelJitMapSharedMemory`, #3787). XPSemu (PPSA97358) also imports it, from a different call site (`0x3603DD`, after `pipe` and four `fcntl` calls). I haven't traced whether that one is reachable.
github-actions[bot] commented 2026-10-12 09:02:50 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-12T09:02:50Z.


Progress report (fc1f063 → a7ea2bd)

➖ System libraries: 87.83% (+0.0%, +1 implemented functions)

✅ 1 implemented
Library Name
libkernel mlockall_nid_postfix
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6121091140 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4386#issuecomment-6121091140). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-12T09:02:50Z. --- <!-- progress-report --> ### Progress report (fc1f063 → a7ea2bd) ➖ **System libraries**: 87.83% (+0.0%, +1 implemented functions) <details> <summary>✅ 1 implemented</summary> | Library | Name | | - | - | | libkernel | `mlockall_nid_postfix` | </details>
xXPBSXx commented 2026-10-12 11:22:25 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-12T11:22:25Z.


Windows test: head 61b12b9e1 merged onto current main 5a031d49e (clean merge, no conflicts). Windows 10, MinGW GCC (WinLibs), Ninja Release, -j4: full build 0 errors; ctest (guest_getrlimit, guest_mlock): 2/2 passed; python tools/check_conventions.py --base upstream/main passed. I did not run the new tests against main without the change.

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6123260525 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4386#issuecomment-6123260525). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-12T11:22:25Z. --- Windows test: head `61b12b9e1` merged onto current `main` `5a031d49e` (clean merge, no conflicts). Windows 10, MinGW GCC (WinLibs), Ninja Release, `-j4`: full build 0 errors; ctest (guest_getrlimit, guest_mlock): 2/2 passed; `python tools/check_conventions.py --base upstream/main` passed. I did not run the new tests against `main` without the change. AI-assisted (Claude Code).
blawesom commented 2026-10-12 14:02:08 +00:00 (Migrated from github.com)

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


Rebase handoff — rebased onto current main, authorship unchanged (both commits).

Conflicts resolved:

  • TechnicalDebt.md: union, both entries kept (both commits).
  • GuestGetrlimit.cpp: main had expanded the unsupported-resources loop while this PR added its checks. The merge keeps main's loop plus this PR's RequireTableSizeUnsupported(); the PR's RequireUnsupported(GUEST_RLIMIT_AS) was dropped because main has since made RLIMIT_AS a supported resource (it is now in the supported loop), so that expectation no longer holds against current main.

Verified on Linux (CachyOS, kernel 7.2.9, GCC 16.2.1, Ninja, Release, BUILD_TESTING=ON, AMD RX 9070 XT / RADV):

  • builds; tools/check_conventions.py --base origin/main passes
  • full suite: 954/954 passed

To pick it up:

git fetch https://github.com/blawesom/AnyPS5 rebase/4386
git checkout <your branch>
git merge --ff-only FETCH_HEAD
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6125843860 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4386#issuecomment-6125843860). Originally posted by [blawesom](https://github.com/blawesom) on 2026-10-12T14:02:08Z. --- **Rebase handoff** — rebased onto current `main`, authorship unchanged (both commits). Conflicts resolved: - `TechnicalDebt.md`: union, both entries kept (both commits). - `GuestGetrlimit.cpp`: main had expanded the unsupported-resources loop while this PR added its checks. The merge keeps main's loop plus this PR's `RequireTableSizeUnsupported()`; the PR's `RequireUnsupported(GUEST_RLIMIT_AS)` was **dropped** because main has since made `RLIMIT_AS` a supported resource (it is now in the supported loop), so that expectation no longer holds against current `main`. Verified on Linux (CachyOS, kernel 7.2.9, GCC 16.2.1, Ninja, Release, `BUILD_TESTING=ON`, AMD RX 9070 XT / RADV): - builds; `tools/check_conventions.py --base origin/main` passes - **full suite: 954/954 passed** **To pick it up:** ``` git fetch https://github.com/blawesom/AnyPS5 rebase/4386 git checkout <your branch> git merge --ff-only FETCH_HEAD ```
oneandonlydean commented 2026-10-13 00:58:03 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-13T00:58:03Z.


Please drop the mlockall commit and rebase (docs/dev/debt/libkernel.md conflicts): no title stops at mlockall. getdtablesize can go in after #3635, since PPSA85300 stops at sZuwaDPATKs once readdir_r is in.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6135723608 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4386#issuecomment-6135723608). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-13T00:58:03Z. --- Please drop the `mlockall` commit and rebase (`docs/dev/debt/libkernel.md` conflicts): no title stops at `mlockall`. `getdtablesize` can go in after #3635, since PPSA85300 stops at `sZuwaDPATKs` once `readdir_r` is in.
babyhuey commented 2026-10-13 06:28:04 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by babyhuey on 2026-10-13T06:28:04Z.


A title that stops at mlockall on main: XPSemu (PPSA97358, catalog release). On main 7e181fcc, both Linux and Windows 11 stop it at the unresolved import x7g7Ebeo8-U (mlockall) from libkernel.prx. This PR's throwing behaviour for valid flags would be enough for it. XPSemu is QEMU, and its two calls are QEMU's mem-lock path: mlockall(MCL_CURRENT | MCL_FUTURE) at guest 0xD2033B and in os_mlock at 0xF504B4. Both run only with -overcommit mem-lock=on, and its help text says the default is off.

It isn't the last import it needs. import_audit.py on main ea2bbefb also lists getdtablesize (this PR), pthread_atfork (#4377), execve and the posix_spawn family (#3651), all absent.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6139678200 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4386#issuecomment-6139678200). Originally posted by [babyhuey](https://github.com/babyhuey) on 2026-10-13T06:28:04Z. --- A title that stops at `mlockall` on `main`: XPSemu (PPSA97358, catalog release). On `main` 7e181fcc, both Linux and Windows 11 stop it at the unresolved import `x7g7Ebeo8-U` (`mlockall`) from `libkernel.prx`. This PR's throwing behaviour for valid flags would be enough for it. XPSemu is QEMU, and its two calls are QEMU's mem-lock path: `mlockall(MCL_CURRENT | MCL_FUTURE)` at guest 0xD2033B and in `os_mlock` at 0xF504B4. Both run only with `-overcommit mem-lock=on`, and its help text says the default is off. It isn't the last import it needs. `import_audit.py` on `main` ea2bbefb also lists `getdtablesize` (this PR), `pthread_atfork` (#4377), `execve` and the `posix_spawn` family (#3651), all absent.
MarcZX10 commented 2026-10-13 07:12:00 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-13T07:12:00Z.


Thanks for raising the scope and rebase issues. The new XPSemu report in this thread changes the mlockall part: on main, XPSemu fails to load at the unresolved mlockall import, and the reported call sites use valid MCL_CURRENT | MCL_FUTURE flags. That makes the throwing implementation relevant to a real import stop, although the call is exercised only with -overcommit mem-lock=on. getdtablesize still has no demonstrated runtime call, so I agree it should not be bundled without title evidence. The PR head remains conflicted; I have not yet updated it.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6140317611 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4386#issuecomment-6140317611). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-13T07:12:00Z. --- Thanks for raising the scope and rebase issues. The new XPSemu report in this thread changes the mlockall part: on main, XPSemu fails to load at the unresolved mlockall import, and the reported call sites use valid MCL_CURRENT | MCL_FUTURE flags. That makes the throwing implementation relevant to a real import stop, although the call is exercised only with -overcommit mem-lock=on. getdtablesize still has no demonstrated runtime call, so I agree it should not be bundled without title evidence. The PR head remains conflicted; I have not yet updated it.
MarcZX10 commented 2026-10-13 07:47:43 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-13T07:47:43Z.


The new XPSemu evidence resolves the earlier “no title stops at mlockall” concern: PPSA97358 on main 7e181fcc stops at unresolved import x7g7Ebeo8-U, with its valid MCL_CURRENT | MCL_FUTURE calls gated behind -overcommit mem-lock=on.

I narrowed this PR to mlockall only, dropped getdtablesize, rebased onto current main a24da902, retained the current debt entries, and updated the title and description. The evidence shows an import stop, not a successful patched title run; with mem-lock enabled, valid calls still throw because full locking is unsupported. Prior build results are labeled as pre-rebase, and no tests were run on the new head. The rebased diff passes git diff --check.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6140864334 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4386#issuecomment-6140864334). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-13T07:47:43Z. --- The new XPSemu evidence resolves the earlier “no title stops at mlockall” concern: PPSA97358 on main `7e181fcc` stops at unresolved import `x7g7Ebeo8-U`, with its valid `MCL_CURRENT | MCL_FUTURE` calls gated behind `-overcommit mem-lock=on`. I narrowed this PR to `mlockall` only, dropped `getdtablesize`, rebased onto current main `a24da902`, retained the current debt entries, and updated the title and description. The evidence shows an import stop, not a successful patched title run; with mem-lock enabled, valid calls still throw because full locking is unsupported. Prior build results are labeled as pre-rebase, and no tests were run on the new head. The rebased diff passes `git diff --check`.
MarcZX10 commented 2026-10-13 07:51:50 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-13T07:51:50Z.


Follow-up: main advanced again while I was resolving this thread. The single-mlockall branch is now rebased on fc1f063f5; the debt entry and scope are unchanged. The description identifies all runtime results as pre-rebase.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6140931499 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4386#issuecomment-6140931499). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-13T07:51:50Z. --- Follow-up: main advanced again while I was resolving this thread. The single-`mlockall` branch is now rebased on `fc1f063f5`; the debt entry and scope are unchanged. The description identifies all runtime results as pre-rebase.
screamm commented 2026-10-13 09:20:14 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by screamm on 2026-10-13T09:20:14Z.


Windows validation with title evidence (Windows 11 Pro 26220, WinLibs MinGW-w64 GCC 15.2.0 r7, Ninja, Release, BUILD_TESTING=ON, full build including libs): head 80b04706 merged onto main 5f426f94 (one textual conflict in docs/dev/debt/libkernel.md with the new sceKernelGetPageTableStats bullet, both kept). Code and tests are identical to my feat/libkernel-xpsemu-process commits; only the debt bullets moved. guest_mlock and guest_getrlimit 3/3; ctest -j8 -E "^agc_driver_|^video_out_flip" 684/686 plus one skip, the only failure being patched_libraries, which fails on main itself since #4877 (libkernel_sys.prx imports rename_nid_postfix that the patched libkernel does not export; fix in #5025); conventions and git diff --check pass.

XPSemu (PPSA97358) relinked against this build: on main it stops at FAIL: unresolved ELF import x7g7Ebeo8-U from libkernel.prx (mlockall); with this PR it moves on to FAIL: unresolved ELF import U9t5kJAWPnA from libkernel.prx (pthread_atfork, #4377). So mlockall is the title's current stop on main, which supports keeping it in this PR as babyhuey reported; the valid-flag throw is not reached because XPSemu only calls mlockall with -overcommit mem-lock=on.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6142388233 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4386#issuecomment-6142388233). Originally posted by [screamm](https://github.com/screamm) on 2026-10-13T09:20:14Z. --- Windows validation with title evidence (Windows 11 Pro 26220, WinLibs MinGW-w64 GCC 15.2.0 r7, Ninja, Release, `BUILD_TESTING=ON`, full build including `libs`): head `80b04706` merged onto `main` `5f426f94` (one textual conflict in `docs/dev/debt/libkernel.md` with the new `sceKernelGetPageTableStats` bullet, both kept). Code and tests are identical to my `feat/libkernel-xpsemu-process` commits; only the debt bullets moved. `guest_mlock` and `guest_getrlimit` 3/3; `ctest -j8 -E "^agc_driver_|^video_out_flip"` 684/686 plus one skip, the only failure being `patched_libraries`, which fails on `main` itself since #4877 (`libkernel_sys.prx` imports `rename_nid_postfix` that the patched libkernel does not export; fix in #5025); conventions and `git diff --check` pass. XPSemu (PPSA97358) relinked against this build: on `main` it stops at `FAIL: unresolved ELF import x7g7Ebeo8-U from libkernel.prx` (`mlockall`); with this PR it moves on to `FAIL: unresolved ELF import U9t5kJAWPnA from libkernel.prx` (`pthread_atfork`, #4377). So `mlockall` is the title's current stop on `main`, which supports keeping it in this PR as babyhuey reported; the valid-flag throw is not reached because XPSemu only calls `mlockall` with `-overcommit mem-lock=on`.
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!4386
No description provided.