libkernel: pthread_atfork, mlockall and getdtablesize are absent (XPSemu, VLC); branch ready #3628

Closed
opened 2026-10-11 14:26:26 +00:00 by screamm · 3 comments
screamm commented 2026-10-11 14:26:26 +00:00 (Migrated from github.com)
Contributor

Imported from boykopovar/AnyPS5. Originally posted by screamm on 2026-10-11T14:26:26Z.


libkernel lacks pthread_atfork (U9t5kJAWPnA), mlockall (x7g7Ebeo8-U) and getdtablesize (sZuwaDPATKs). From the relink registry order they are predicted stops of XPSemu (PPSA97358, indices 255, 201, 395) and VLC (PPSA85300, getdtablesize at 354 after #3556); not yet observed in a run. XPSemu calls pthread_atfork from a constructor (util/rcu.c:488-495), so that one must return.

Branch ready: screamm:feat/libkernel-xpsemu-process (three commits on main a11c8f7f: f37bccf6 feat(libkernel): implement pthread_atfork, 87f4aa33 feat(libkernel): add mlockall, 774670de feat(libkernel): add getdtablesize). I cannot open it as a PR because of the intake check; anyone eligible is welcome to carry it, keeping the commits as they are.

  • pthread_atfork (new Pthread/Posix/Atfork.cpp): appends the three handlers to a locked list and returns 0 (ENOMEM on allocation failure), as FreeBSD 11.4 libthr thr_fork.c (8c639945); null handlers accepted; the handlers never run because fork throws here, which is recorded, and the list is exposed through PthreadAtforkHandlers_nid_no_patch() for a future fork. New guest_pthread_atfork checks order, null handlers, concurrent registration from four threads, and that nothing runs.
  • mlockall(flags): EINVAL for 0 or bits outside MCL_CURRENT|MCL_FUTURE (FreeBSD vm_mmap.c); valid flags throw naming the flag, because no mapping path can lock future mappings and mlock pins host pages range by range without a record to build on; XPSemu only calls it with -overcommit mem-lock=on. guest_mlock gains the cases.
  • getdtablesize: FreeBSD's syscall returns min(RLIMIT_NOFILE, kern.maxfilesperproc) (kern_descrip.c), and no public source (shadPS4, KytyPS5, OpenOrbis, fpPS4 placeholder, SharpProspero) gives the console's descriptor limit, so it throws like getrlimit(RLIMIT_NOFILE) still does; the export alone lets VLC and XPSemu load, and both call it only from their own closefrom, which XPSemu does not use. guest_getrlimit checks the throw.

Tested on Windows 11 Pro 26220, WinLibs MinGW-w64 GCC 15.2.0 r7, Ninja, Release, BUILD_TESTING=ON, full build including libs: the three tests 3/3; ctest -j8 -E "^agc_driver_|^video_out_flip" 534/537, the failures being the known windows_exceptions (#3411), guest_kernel_sys (#3510) and guest_filesystem (#3518); with main's Process.cpp the extended getrlimit test fails; tools/check_conventions.py --base main and git diff --check pass. Not run on Linux.

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

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5801946180 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/3628). Originally posted by [screamm](https://github.com/screamm) on 2026-10-11T14:26:26Z. --- libkernel lacks `pthread_atfork` (`U9t5kJAWPnA`), `mlockall` (`x7g7Ebeo8-U`) and `getdtablesize` (`sZuwaDPATKs`). From the relink registry order they are predicted stops of XPSemu (PPSA97358, indices 255, 201, 395) and VLC (PPSA85300, `getdtablesize` at 354 after #3556); not yet observed in a run. XPSemu calls `pthread_atfork` from a constructor (`util/rcu.c:488-495`), so that one must return. **Branch ready:** [`screamm:feat/libkernel-xpsemu-process`](https://github.com/screamm/AnyPS5/tree/feat/libkernel-xpsemu-process) (three commits on `main` `a11c8f7f`: `f37bccf6` `feat(libkernel): implement pthread_atfork`, `87f4aa33` `feat(libkernel): add mlockall`, `774670de` `feat(libkernel): add getdtablesize`). I cannot open it as a PR because of the intake check; anyone eligible is welcome to carry it, keeping the commits as they are. - `pthread_atfork` (new `Pthread/Posix/Atfork.cpp`): appends the three handlers to a locked list and returns 0 (`ENOMEM` on allocation failure), as FreeBSD 11.4 libthr `thr_fork.c` (`8c639945`); null handlers accepted; the handlers never run because `fork` throws here, which is recorded, and the list is exposed through `PthreadAtforkHandlers_nid_no_patch()` for a future `fork`. New `guest_pthread_atfork` checks order, null handlers, concurrent registration from four threads, and that nothing runs. - `mlockall(flags)`: `EINVAL` for 0 or bits outside `MCL_CURRENT|MCL_FUTURE` (FreeBSD `vm_mmap.c`); valid flags throw naming the flag, because no mapping path can lock future mappings and `mlock` pins host pages range by range without a record to build on; XPSemu only calls it with `-overcommit mem-lock=on`. `guest_mlock` gains the cases. - `getdtablesize`: FreeBSD's syscall returns `min(RLIMIT_NOFILE, kern.maxfilesperproc)` (`kern_descrip.c`), and no public source (shadPS4, KytyPS5, OpenOrbis, fpPS4 placeholder, SharpProspero) gives the console's descriptor limit, so it throws like `getrlimit(RLIMIT_NOFILE)` still does; the export alone lets VLC and XPSemu load, and both call it only from their own `closefrom`, which XPSemu does not use. `guest_getrlimit` checks the throw. **Tested** on Windows 11 Pro 26220, WinLibs MinGW-w64 GCC 15.2.0 r7, Ninja, Release, `BUILD_TESTING=ON`, full build including `libs`: the three tests 3/3; `ctest -j8 -E "^agc_driver_|^video_out_flip"` 534/537, the failures being the known `windows_exceptions` (#3411), `guest_kernel_sys` (#3510) and `guest_filesystem` (#3518); with `main`'s `Process.cpp` the extended getrlimit test fails; `tools/check_conventions.py --base main` and `git diff --check` pass. Not run on Linux. Written with Claude Code assistance (implementation by a subagent, reviewed and validated in this session).
MarcZX10 commented 2026-10-11 14:44:58 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-11T14:44:58Z.


I carried the three commits from David’s ready branch into PR #3650, preserving his authorship. The PR adds pthread_atfork, mlockall, and getdtablesize as separate commits, with their known limits recorded in TechnicalDebt. On Linux/GCC 12.2 Release, all three targeted tests passed; conventions and git diff --check pass on current main. The PR text distinguishes the issue author’s Windows test report from my local run. The predicted title stops remain unobserved in a title run.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6110201964 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/3628#issuecomment-6110201964). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-11T14:44:58Z. --- I carried the three commits from David’s ready branch into [PR #3650](https://github.com/boykopovar/AnyPS5/pull/3650), preserving his authorship. The PR adds `pthread_atfork`, `mlockall`, and `getdtablesize` as separate commits, with their known limits recorded in TechnicalDebt. On Linux/GCC 12.2 Release, all three targeted tests passed; conventions and `git diff --check` pass on current `main`. The PR text distinguishes the issue author’s Windows test report from my local run. The predicted title stops remain unobserved in a title run.
MarcZX10 commented 2026-10-12 08:33:52 +00:00 (Migrated from github.com)
Author
Contributor

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


I carried the mlockall and getdtablesize parts of the offered branch into PR #4386, preserving David’s authorship. Linux Release GCC 12.2 built guest_mlock_tests and guest_getrlimit_tests; both focused tests passed, along with conventions/diff checks. The PR documents that valid mlock operations and the console descriptor limit remain unsupported.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6120659877 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/3628#issuecomment-6120659877). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-12T08:33:52Z. --- I carried the `mlockall` and `getdtablesize` parts of the offered branch into [PR #4386](https://github.com/boykopovar/AnyPS5/pull/4386), preserving David’s authorship. Linux Release GCC 12.2 built `guest_mlock_tests` and `guest_getrlimit_tests`; both focused tests passed, along with conventions/diff checks. The PR documents that valid mlock operations and the console descriptor limit remain unsupported.
oneandonlydean commented 2026-10-14 00:09:20 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-14T00:09:20Z.


Closing: pthread_atfork (#4377) and mlockall (#4386) are on main. getdtablesize isn't; it can go in when a title stops on it, so comment here with the title ID and the log line if VLC or XPSemu does.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6157877943 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/3628#issuecomment-6157877943). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-14T00:09:20Z. --- Closing: `pthread_atfork` (#4377) and `mlockall` (#4386) are on main. `getdtablesize` isn't; it can go in when a title stops on it, so comment here with the title ID and the log line if VLC or XPSemu does.
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#3628
No description provided.