Repository navigation
fix(libkernel): set the open file limit at load on macOS - #6836
Conversation
|
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.
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.
|
|
Rebase handoff — rebased onto current Verified on Linux (CachyOS, kernel 7.2.9, GCC 16.2.1, Ninja, Release,
To pick it up: Head is |
|
Thanks, @blawesom. I checked your AI-assisted: yes |
…DavidSamir) Replaces this branch's equivalent fix. Both raise RLIMIT_NOFILE at load to kern.maxfilesperproc, the real ceiling on macOS; the PR's version also records the macOS behaviour in the getrlimit debt entry and extends guest_getrlimit, and is the one going upstream. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…DavidSamir) Replaces this branch's equivalent fix. Both raise RLIMIT_NOFILE at load to kern.maxfilesperproc, the real ceiling on macOS; the PR's version also records the macOS behaviour in the getrlimit debt entry and extends guest_getrlimit, and is the one going upstream. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
getrlimit(RLIMIT_NOFILE) reports the host's limits, and libkernel raised the soft limit to the hard one at load only on Linux. On macOS the soft limit stayed below an unlimited hard limit (1048576 and infinity in a shell here, 256 and infinity by default), so the two differed. XPSemu (PPSA97358) then raises the soft limit to the hard one in QEMU's os_setup_limits, and setrlimit refuses the change. macOS fails with EMFILE at kern.maxfilesperproc (10240 here) whatever the soft limit, even an unlimited one. At load, libkernel now sets both limits to the smaller of the hard limit and kern.maxfilesperproc, so getrlimit reports the descriptor count after which opening fails. The Linux path still raises the soft limit to the hard one.
guest_getrlimit failed on macOS because the host's soft and hard RLIMIT_NOFILE differed. On macOS it now also checks that the limit does not exceed kern.maxfilesperproc, and, as on Windows, that guest pipes fail with EMFILE within 64 descriptors of the reported limit. The pipe loop moves into a helper that both use.
d9149b8 to
f673abe
Compare
…load on macOS (@DavidSamir) This branch already carried an earlier head of this PR; DavidSamir has pushed newer commits since, and this merge brings the branch up to them. The only conflict is the getrlimit and setrlimit debt entries, which this branch keeps further down with main's text and its own short macOS line; the PR's copies would have duplicated them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Rebased onto current |
…DavidSamir) Replaces this branch's equivalent fix. Both raise RLIMIT_NOFILE at load to kern.maxfilesperproc, the real ceiling on macOS; the PR's version also records the macOS behaviour in the getrlimit debt entry and extends guest_getrlimit, and is the one going upstream. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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:maince991f1 with 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(feat(relinker): place macOS executables at a fixed base with --macos-fixed-base #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 feat(libkernel): allow lowering rlim_cur for RLIMIT_NOFILE in setrlimit #5902'sProcess.cpp. With this branch the hard limit is 10240, andguest_setrlimitandguest_getrlimitboth pass with feat(libkernel): allow lowering rlim_cur for RLIMIT_NOFILE in setrlimit #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)