feat(libkernel): report RLIMIT_NOFILE through getrlimit #5187
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/5187"
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 p3n1cillin on 2026-10-13T14:10:03Z.
What
XPSemu (PPSA97358, catalog release) loads on current
mainonce #4377 (pthread_atfork), #4105 (execve) and #5061 (getdtablesize) are in (mlockalland theposix_spawnfamily are merged). It then stops at once:Resource 8 is
RLIMIT_NOFILE. The two call sites (guest 0xF5011B and 0xD21A78) are QEMU'sos_setup_limits:getrlimit(RLIMIT_NOFILE)warns "unable to query NOFILE limit" on failure, returns if the soft limit equals the hard limit, and otherwise raises the soft limit withsetrlimitand warns "unable to set NOFILE limit" on failure.getrlimit(RLIMIT_NOFILE)now reports, as both limits, the descriptor count after which AnyPS5 itself fails withEMFILE:_setmaxstdio). Guest files and pipes are C runtime descriptors, and guest socket numbers take one too (_open_osfhandleof aNULplaceholder inUdp.cpp), so they all share that table.RLIMIT_NOFILE, whose soft limit libkernel already raises to the hard limit at load (OpenFileLimit.cpp).Since both limits are equal,
setrlimitwith the same values succeeds as before and QEMU never needs to raise them. This mirrors the existingRLIMIT_DATA, which reports the host's limit. The console's own limit is unknown; thegetrlimitdebt entry is updated. Once this is in, #5061'sgetdtablesizecould report the same value (FreeBSD returns the smaller of the soft limit andmaxfilesperproc); I have kept that separate.Tested
main3faa9cb40with #4377, #4105 and #5061. Before, it stops as above within 1 s. After, it gets pastos_setup_limitsand faults reading its GOT at the fixed console base 0x400000 (read of 0x339c6e0=rax + 0x400000). That is the load-address assumption #4013 tracks (#4140).guest_getrlimit:setrlimitwith them returns 0;pipeuntil it fails givesEMFILE, with every descriptor below the limit and fewer than 64 lost to the test process;python tools/check_conventions.py --base origin/mainpasses.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)os_setup_limits🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by p3n1cillin on 2026-10-13T14:34:51Z.
Linux run: Ubuntu in WSL2, GCC 15.2.0, Ninja Release,
BUILD_TESTING=ON, full build of a local test head838d4fd85. That head ismain3faa9cb40with this PR, my other open libkernel PRs (#5013, #5061, #5078, #5098, #5183–#5187, #5191) and the open PRs the catalog titles need (#4377, #4379, #4374, #4383, #3798, #4467, #4863, #4105). All 123 libkernel and 69 libc tests pass, includingguest_system_configuration,guest_getrlimit,guest_kernel_fcntl,guest_freebsd_clocks,guest_kernel_sysandguest_filesystem. Not built alone on Linux; no title run on Linux.Imported from boykopovar/AnyPS5. Originally posted by babyhuey on 2026-10-13T18:37:36Z.
A title that stops here: XPSemu (PPSA97358). On
main18c438b1with #5061 merged and relinked with #4593's--linux-fixed-base 0x400000(Linux, headless), it throwsgetrlimit: unsupported resource 8. With this PR stacked as well, it gets past that and xemu starts: it loads its BIOS files and builds shaders, then stops at a GPU check in its own probe (details in #5061). The stack conflicts only inGuestGetrlimit.cpp, which #5061 also edits.Imported from boykopovar/AnyPS5. Originally posted by pipe1os on 2026-10-14T06:44:31Z.
Built and ran this on Windows: head
a915c0723merged ontomain107190d11, Windows 11, WinLibs GCC 15.2.0, Ninja Release. The merge conflicts only indocs/dev/debt/libkernel.md:mainadded themachdep.tsc_freqentry right above thegetrlimitone, so it needs a rebase.guest_getrlimitpasses 5/5. WithProcess.cppput back tomainand the test kept, it aborts withgetrlimit: unsupported resource 8.getrlimit: unsupported resource 8right afterSTAGE: Calling real JNI_CreateJavaVM. The caller is HotSpot'sos::init_2(os_bsd.cpp L2113-L2143). With this PR added,JNI_CreateJavaVM returned 0and the title's DNS row finishes (LAN/DNS fixture returned normally); its LAN row needs the author's Mac helper, so it times out here.CheckOpenFileLimit, the guest gets 8188 descriptors frompipebeforeEMFILE, the highest being 8190. That matches FreeBSD, wherefdallocfails withEMFILEonce the first free number reacheslim_cur(RLIMIT_NOFILE)(kern_descrip.c L799-L803, L1648-L1650).One thing for Linux, which I can't run here: right after
getrlimit, HotSpot callssetrlimit(RLIMIT_NOFILE)withrlim_cur = MIN(0x100000, rlim_max)(os_bsd.cpp L2130-L2132), and the Java 25 eboot does the same:getrlimit(8)at 0x9EE0FE, thencmp rax, 0x100000/cmovlonrlim_maxbeforesetrlimitat 0x9EE163. On Windows that asks for 8192/8192 andsetrlimitaccepts it. On a Linux host whose hard limit is above 0x100000 or unlimited, it asks for a soft limit below the hard one, andsetrlimitthrows, since it only accepts the valuesgetrlimitreturns (Process.cpp L333-L334), so HotSpot's retry withMAX(OPEN_MAX, original)at 0x9EE187 never runs. XPSemu's path, QEMU'sos_setup_limits, never gets there because it returns when both limits are equal, and hosts with the usual 1048576 or 524288 hard limit are fine. Probably a follow-up rather than something for this PR.Imported from boykopovar/AnyPS5. Originally posted by p3n1cillin on 2026-10-14T07:27:32Z.
Rebased onto
main78f1aea70(head1aaec9728), thanks @pipe1os. The conflicts were only adjacent additions:machdep.tsc_freqindocs/dev/debt/libkernel.md, andgetdtablesizeinGuestGetrlimit.cpp. I kept both sides. On Windows (MinGW GCC 15, Release) all 129 libkernel tests pass, includingguest_getrlimitwith both checks, and the conventions check passes.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-14T11:30:34Z.
Checked on the PR merged onto main: build + ctest green (166/166,
guest_getrlimitpasses), and the new test fails with theProcess.cppchange reverted. The Windows branch (8192 descriptors,EMFILEtest) is confirmed by @pipe1os and the author on Windows; the full Build's Windows job covers it before merge. Merging.