feat(libkernel): implement getdtablesize #6201
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/6201"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by bruceblake on 2026-10-15T02:38:17Z.
What
Implement
getdtablesizein libkernel. It previously threwNotImplemented_nid_no_patch. It now returns theRLIMIT_NOFILEsoft limit thatgetrlimitreports, capped atINT_MAX: FreeBSD'ssys_getdtablesizereturns the smaller of that limit andmaxfilesperproc, and the guest limit never exceeds the hard limit that bounds it here (guest limits cannot be changed;setrlimitrejects changes). The guest test asserts the returned value instead of the throw, and the libkernel debt entry records the semantics and that the console'smaxfilesperprocis not measured.Tested
Linux x86-64 (Arch, WSL2), GCC 16. Configured with
-DBUILD_TESTING=ON; built thelibstarget andguest_getrlimit_tests. ctest:guest_getrlimit,guest_setrlimitandpatched_librariesall pass.tools/check_conventions.py --base origin/mainpasses. No title or homebrew run: the function is covered by the guest test; VLC (PPSA85300) imports it only on a path that never runs (itsforkfails withENOSYS).Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-15T03:28:47Z.
Review: COMMENTED
On macOS the
RLIMIT_NOFILEsoft limit is not a bound on the descriptor table, so this returns more than the process can open. Checked againstb6c9bd7f3on an Apple M2 Max, macOS 27.2, Apple clang 21, standalone snippets built for arm64 and x86_64 (same results on both):kern.maxfilesperprocis 122880.setrlimit(RLIMIT_NOFILE)accepts a soft limit above it,RLIM_INFINITYincluded, andgetrlimitreports what was set.getdtablesize()already returns the smaller of the two, as FreeBSD'ssys_getdtablesizedoes.dupfails withEMFILEat fd 122879 whatever the soft limit says.getdtablesize()RLIM_INFINITYThe formula is the PR's:
toGuestLimit(rlim_cur)capped atINT_MAX. Guest descriptors are host descriptors here (pipe_nid_postfixcalls::pipe). With an unlimited soft limit, aclosefrom-style loop up togetdtablesize()(the VLC case in the debt entry) would run 2^31 iterations instead of about 122k. On macOS, taking the smaller of the guest soft limit and the host's::getdtablesize()would give the FreeBSD result.The new assertion in
GuestGetrlimit.cppuses the same formula as the implementation, so it can't catch this. The debt entry says the limit is "raised to the hard limit when libkernel loads", butFile/src/OpenFileLimit.cpponly does that under__linux__. On macOS the guest gets whatever soft limit the host process inherited.Not a full build:
maindoesn't linklibc.dylibon macOS yet.Written with AI assistance (Claude Code). I ran the checks above on my machine.
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-15T12:16:34Z.
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.
main)docs/dev/debt/libkernel.mdL102-103core/libs/prx/libkernel/System/src/Process.cppL667-668core/libs/prx/libkernel/System/src/Process.cppL667-668core/libs/tests/GuestGetrlimit.cppL177-183docs/dev/debt/libkernel.mdL103core/libs/tests/GuestGetrlimit.cppL169-183Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
core/libs/prx/libkernel/System/src/Process.cppdocs/dev/debt/libkernel.mdcore/libs/tests/GuestGetrlimit.cppdocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/System/src/Process.cppdocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/System/src/Process.cppdocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mdImported from boykopovar/AnyPS5. Originally posted by bruceblake on 2026-10-15T14:44:25Z.
Thanks for checking this against real macOS behavior — the measurements make the problem clear, and you're right on all three points.
What changed in the new commit on this branch:
getdtablesizenow returns the smaller of the guestRLIMIT_NOFILEsoft limit and the host's::getdtablesize()(still capped atINT_MAX), which is the FreeBSDsys_getdtablesizeresult — on macOS the value now tracksmaxfilesperprocinstead of the raw soft limit, so an unlimited soft limit no longer produces a ~2^31-iteration bound for aclosefrom-style loop. The host call is compiled only on non-Windows hosts; on Windows the guest limit stays the constant CRT value.GuestGetrlimitassertion no longer reuses the implementation's formula: the test derives its expectation itself from the guest soft limit and its own host::getdtablesize()call, so an implementation that ignored the host bound would fail it.OpenFileLimit.cppis__linux__-only), and on macOS the guest gets whatever soft limit the host process inherited.Verified on Linux (WSL): full
libsbuild passes,guest_getrlimitandguest_setrlimittests pass, and the conventions check passes. I can't run the macOS case here — this machine is Linux, where the hostgetdtablesize()already tracks the soft limit — so the macOS behavior rests on your measurements; happy to adjust if you spot anything off in the new commit.Written with AI assistance (Claude). I ran the checks above on my machine.
Imported from boykopovar/AnyPS5. Originally posted by screamm on 2026-10-15T22:27:28Z.
Windows 11 Pro 26220, RTX 4070 (596.21), MinGW GCC 15.2: head
873fbe99amerged on main44df21632.guest_getrlimit,--repeat until-fail:3: 3 of 3 pass. On Windows the host call is compiled out, so the test covers the guest-limit branch only; the macOS bound from the review is not checked here.getdtablesizeis NIDsZuwaDPATKsin aerolib. Of the relinked registries I have, PPSA85300 (VLC 0.3.1) and PPSA97358 import it fromlibkernel.prx; no other local title does.libkernel.prxalready exported the NID onmain(the export count is 1646 before and after), so the PR changes what the call does, not whether the import resolves.--windows-fixed-base 0x400000, 120 s with the display):mainand the PR both run to the limit with no stop line, 9541 and 9601 frames, and the same log. As the description says, the call is on a path VLC never runs, so this run is a no-regression check, not a demonstration of the function.tools/check_conventions.py --base origin/mainandgit diff --checkpass.Not checked: macOS and the full suite on this head.
Written with Claude Code assistance (validation by a subagent, reviewed in this session).
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-18T17:15:23Z.
Progress report (
ff23657→873fbe9)📈 System libraries: 88.77% (+0.03%, +1 implemented functions)
✅ 1 implemented
getdtablesize_nid_postfix