fix(libkernel): set the open file limit at load on macOS #6836
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/6836"
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 DavidSamir on 2026-10-16T13:48:30Z.
What
getrlimit(RLIMIT_NOFILE)reports the host's limits, and thelibkernel.mdentry says that on Linux libkernel raises the soft limit to the hard one at load. That happens inOpenFileLimit.cpp, which is built only for Linux. On macOS the two limits stay different: 1048576 and unlimited in a shell here, 256 and unlimited by default.XPSemu (PPSA97358) raises the soft limit to the hard one in QEMU's
os_setup_limitswhen they differ. On macOSsetrlimitrefuses that, and the title stops:The soft limit can't simply be raised to the hard one on macOS. macOS fails with
EMFILEatkern.maxfilesperproc, 10240 here, whatever the soft limit. A standalone program opened/dev/nullup to fd 10239 both with the soft limit unlimited and with both limits at 10240. At load, libkernel now sets both limits to the smaller of the hard limit andkern.maxfilesperproc. Sogetrlimitreports, as the debt entry describes, the descriptor count after which opening fails. The Linux path still raises the soft limit to the hard one, and Windows is unchanged.Commits:
guest_getrlimiton macOS: the limit againstkern.maxfilesperproc, and guest pipes failing withEMFILEat the reported limit (the check Windows already runs, moved into a helper).getrlimitdebt entry.Tested
macOS 26.7.1, Apple M2, AppleClang 21.0.0, x86-64 under Rosetta, Release.
maindoesn't build the system libraries on macOS by itself, so the tests and the title ran in a local tree:maince991f1ecwith the macOS runtime work merged (#4627, #4630, #6124, the macOS relinker PRs, mugurc's port branches). The branch'sOpenFileLimit.cppandGuestGetrlimit.cppare identical to the ones tested.guest_getrlimitaborts withmain'sOpenFileLimit.cpp, because soft and hard differ. With this branch it passes 5 runs of 5, and also with the shell limits set to 256/unlimited, 256/4096 and 4096/4096.kern.maxfilesperprocclamp fails the extended test.guest_tests here, withmain's file and with this branch:guest_getrlimitis the only difference. The other 22 failures are the same with both.--macos --to-rosetta --macos-fixed-base 0x400000(#6802), 2 runs of 2:main's file it stops on thesetrlimitrefusal above.sceKernelJitCreateSharedMemory, which this local tree doesn't build on macOS.main's POSIX backing usesmemfd_create, which macOS doesn't have. In standalone probes under Rosetta, code in a shared memory mapping didn't run. Anshm_openobject mapped twice (one view RW, one RX) raised SIGBUS, and so did one mapped once RWX. A temporary file couldn't be mapped executable (EPERM). Only anonymous private memory ran written code.tools/check_conventions.py --base origin/mainandgit diff --checkpass.Not tested: Linux and Windows. Linux takes the same branch as before: it returns when soft equals hard, and otherwise raises soft to hard. Windows compiles none of the changed lines, apart from the pipe loop moving into a helper.
Overlap:
setrlimit(RLIMIT_NOFILE)accept a request whose hard limit doesn't exceed the current one. On macOS here the hard limit is unlimited, soguest_setrlimit'sThrows(GUEST_RLIMIT_NOFILE, infinity)aborts with #5902'sProcess.cpp. With this branch the hard limit is 10240, andguest_setrlimitandguest_getrlimitboth pass with #5902'sProcess.cpp.GuestGetrlimit.cppand thegetrlimit/setrlimitdebt entries next to the lines changed here.Whichever lands second rebases.
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 github-actions[bot] on 2026-10-16T14:39:45Z.
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.mdL169-170Some 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.
docs/dev/debt/libkernel.mdcore/libs/tests/GuestGetrlimit.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.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/File/src/OpenFileLimit.cppdocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mdImported from boykopovar/AnyPS5. Originally posted by blawesom on 2026-10-17T09:46:20Z.
Rebase handoff — rebased onto current
main(authorship unchanged). One conflict indocs/dev/debt/libkernel.md: your macOSRLIMIT_NOFILEentry is unioned withmain's newer entries.Verified on Linux (CachyOS, kernel 7.2.9, GCC 16.2.1, Ninja, Release,
BUILD_TESTING=ON, AMD RX 9070 XT / RADV):tools/check_conventions.py --base origin/mainpassesmainregression (agc_driver_tessellationsegfault, #4727), not this PRTo pick it up:
Head is
375614b61.Imported from boykopovar/AnyPS5. Originally posted by DavidSamir on 2026-10-17T15:34:31Z.
Thanks, @blawesom. I checked your
rebase/6836against this branch: the code commits are identical, and the debt-file commit differs only by the conflict resolution. Rather than force-pushing, I merged currentmaininto the branch with the same resolution, so the history stays as reviewed. The PR's diff againstmainnow matches your rebase. Head isa3fb02df9, and it merges cleanly withmain.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-19T14:39:30Z.
Rebased onto current
main(conflicts inGuestGetrlimit.cppand thegetrlimitdebt entry after the Windows stdio-limit change): the Windows stream check is now a_WIN32-only helper called after the shared descriptor check, and the debt entry lists Windows, Linux and macOS. Re-checked the macOS clamp, the unchanged Linux path and the extended test; libkernel tests pass; merged.