fix(libkernel): report the getrlimit values measured on a PS5 for RLIMIT_STACK, RSS, MEMLOCK and NPROC #7543
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/7543"
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 ionut27001 on 2026-10-18T13:00:34Z.
What
getrlimitnow answersRLIMIT_STACK,RLIMIT_RSS,RLIMIT_MEMLOCKandRLIMIT_NPROCwith the limits a payload process reads on a PS5 (firmware 12.70). Before this PR, all four threwunsupported resource.mainbefore this PRRLIMIT_STACK(3)RLIMIT_RSS(5)RLIMIT_MEMLOCK(6)RLIMIT_NPROC(7)EFAULTsetrlimitside effect:setrlimitreadsgetrlimitfirst, so it now acceptsRLIMIT_STACK,RLIMIT_RSSandRLIMIT_MEMLOCKwhen the values do not change, as the payload process does.RLIMIT_NPROCthrows even for its current value, because the limit is not stored here: in the payload process that call succeeds, butgetrlimitthen reads 1443. That fits FreeBSD 11'ssetrlimitclamp tomaxprocperuid, nine tenths ofmaxproc(cited in the debt entry), if the console'smaxprocis 1604;kern.maxprocfails withENOENTin the payload process (p10), somaxprocis not measured. Any other change still throws, as for the other resources whose limit is not stored.Main thread stack: in the payload process the main thread's stack is 0x200000 as well (p17,
pthread_attr_get_np), the same asRLIMIT_STACK. Here the main thread runs on the host thread's stack. The debt entry says so; this PR does not change it.Not established: these values come from a payload process started through a payload manager. Whether a title process reads the same limits is not measured, and the debt entry says so.
docs/dev/debt/libkernel.md:RLIMIT_DATA(0x800000000) andRLIMIT_NOFILE(13952) readings, and the 12555 descriptor ceiling, measured with the soft limit untouched. This PR does not adopt them, because those two limits follow the host here. It also says that guest locking still follows the host:mlockandsceKernelMlockfail at the host's hardRLIMIT_MEMLOCKon Linux, and on Windows when the working set cannot grow, althoughRLIMIT_MEMLOCKnow reports infinity.RLIMIT_NOFILElimit of 13952 to 12555, for the hard limit and for the soft limit;RLIMIT_NPROCto its current 1604 succeeds, butgetrlimitthen reads 1443.How the console was measured
resolvelines of p10 and p13 show that theirgetrlimitandsetrlimitare the oneslibkernel_sys.sprxexports; p24 prints no resolve lines and links them the same way.0xAAand logged eachgetrlimitreturn value. p24's same-value and descriptor cases did neither, so the 1443 thatRLIMIT_NPROCread after the same-value set comes from agetrlimitcall whose return value was not logged.RLIMIT_NOFILEsoft limit to 1000; setting the original {13952, 13952} back then read 12555 for both. p24 set STACK, RSS, MEMLOCK and NPROC to their current values; NPROC then read 1443.Console output (excerpt, lines copied unchanged)
The
pNN:prefix names the probe; the rest of each line is copied unchanged.nofile_loweredissetrlimit(RLIMIT_NOFILE, {1000, 13952}), andnofile_restoredissetrlimit(RLIMIT_NOFILE, {13952, 13952}).Overlaps:
getrlimitdebt line to add the macOS open file limit, and that line still says that the four resources throw. #7332 also moves thegetrlimitandsetrlimitlines belowexecvp. Whichever lands second keeps the measured values.CheckOpenFileLimitinGuestGetrlimit.cpp. Those hunks are apart from this PR's, and git merges them without a conflict; only the debt line conflicts.main6e27fc8f0conflicted with it inGuestGetrlimit.cpp, where #6201 replaced the test's check thatgetdtablesizethrows with a check of its value; the resolution keeps that check next to this PR'sRLIMIT_STACKandRLIMIT_NPROCchecks. #7039, which also implementsgetdtablesize, now conflicts withmaininProcess.cpp,GuestGetrlimit.cppand the debt file, and this branch adds no other file to that.getdtablesizeis not measured, and thefcntlentry calls the console'sRLIMIT_NOFILEunknown. This PR leaves them alone to stay on its topic and to avoid conflicts with #7403 and #7437, which rewrite thefcntlline. Until they are updated, the file contradicts itself there. Thegetdtablesizeentry, which #6201 rewrote and #7039 rewrites, says only thatmaxfilesperprocis not measured on the console; this PR records nomaxfilesperprocreading, so that line does not contradict it.getrlimitentry's "whose size can differ" still holds. #3965 (Windows) and #7532 (Linux) run the guest main thread on a stack in the guest arena; if either lands first, the main-thread sentence in thegetrlimitentry needs updating.Tested
Build: Windows 11 x86-64, full build with WinLibs MinGW-w64 GCC 15.2.0 (posix-seh, ucrt, r7) and
-DBUILD_TESTING=ON.Rebase (not re-tested): after #7813 landed, this branch was rebased onto
mainbbb45463c. The only conflict was indocs/dev/debt/libkernel.md: #7813 added the Windowsstdiostream limit to thegetrlimitline this PR rewrites, and the resolution keeps that clause inside this PR's rewritten line. The code and test changes are the same as before the rebase, and the tests above were not run again on the new base.Tests: with this branch on top of
main9f25d0bf5b,guest_getrlimit,guest_setrlimitand the otherguest_*tests pass: 464 of 465 pass andguest_video_out_wqhd_detection_no_vulkanis skipped on this machine. The branch was then rebased ontomain5bf2e139efwithout conflicts, since upstream changed none of its code or test files, andguest_getrlimitandguest_setrlimitpass there too.Old code, new test: with
Process.cppreverted tomainand the new tests kept,guest_getrlimitandguest_setrlimitabort.Rebase onto
main6e27fc8f0: after #6201 landed, the branch was rebased ontomain6e27fc8f0, resolving theGuestGetrlimit.cppconflict with #6201 described under Overlaps; the other files merged without conflicts. With this branch and #7541's branch built in one tree on thatmain, theguest_*tests pass: 473 of 474, andguest_video_out_wqhd_detection_no_vulkanis skipped on this machine. That is the second of two full runs; the first, right after the build, timed out in four tests this PR does not touch (guest_message_destructor_unshared-decoy,guest_video_out_cursor,guest_app_info,guest_pthread_rwlock).guest_getrlimitandguest_setrlimitalso passed 3 runs in a row. WithProcess.cppreverted to thatmainand the new tests kept,guest_getrlimitaborts withgetrlimit: unsupported resource 5andguest_setrlimitwithgetrlimit: unsupported resource 3. The branch merges cleanly withmain3259e4c3e.Console: behaviour measured on a PS5 (firmware 12.70), as described above.
Not tested here: Linux (a reviewer reported a Linux run in the comments), and no title.
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)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-18T13:36:51Z.
Some 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.cppcore/libs/tests/GuestSetrlimit.cppdocs/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.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/System/src/Process.cppcore/libs/prx/libkernel/System/src/Process.cppcore/libs/tests/GuestGetrlimit.cppdocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mdImported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-19T00:01:11Z.
Review: COMMENTED
Linux run, since the description lists only Windows.
Machine: Linux x86_64, i7-8700, Ubuntu 26.04, GCC 15.2, Release,
BUILD_TESTING=ON, full build.Head
85226f402merged ontomain84c1a4d9a(clean merge).guest_getrlimitandguest_setrlimitpass.main:guest_getrlimitaborts withgetrlimit: unsupported resource 5andguest_setrlimitwithgetrlimit: unsupported resource 3, so both tests cover the new cases.ctest -E "^agc|gpu|vulkan|video_out"): 739/739, same asmain.Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
Imported from boykopovar/AnyPS5. Originally posted by wachi35676 on 2026-10-19T01:09:52Z.
The 1443 that
RLIMIT_NPROCreads after setting it to its current 1604 is FreeBSD 11.4's clamp:init_main.c#L566-L567starts the limit atmaxproc;subr_param.c#L266setsmaxprocperuid = (maxproc * 9) / 10;kern_resource.c#L714-L718lowers both limits tomaxprocperuidinsetrlimit.1604 × 9 / 10 = 1443.6, which truncates to 1443. So
setrlimit(RLIMIT_NPROC)could be modelled exactly, by clamping to 1443 and storing it, instead of throwing. At the least, the debt line can cite this rather than describe 1443 as unexplained.Windows 11 with GCC 15.2.0, base
a373e85e5:guest_getrlimitandguest_setrlimitpass, and abort withProcess.cppreverted.AI-assisted: yes (Claude Code); results above were run on this machine.
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-20T00:09:31Z.
Checked the diff, the new
guest_getrlimit/guest_setrlimitcases (they fail onmainwithunsupported resource, as @jotitadev's Linux run also shows) and the FreeBSD clamp behind the 1443 reading. The only conflict was thegetrlimitdebt line that #6836 rewrote for macOS; rebased it ontomain, keeping the macOS clause inside your rewritten line. Merged.