Repository navigation
fix: enable close_range on older Linux sysroots and fix fd fallback - #1024
Merged
Merged
Conversation
Use __NR_close_range and linux/close_range.h with ABI fallbacks so glibc 2.28 sysroots (including older 4.19 kernel headers) compile in close_range() without requiring newer glibc symbols. Fall back to close_range(..., 0) on EINVAL for Linux 5.9-5.10, and replace the fd loop with a bounded RLIMIT_NOFILE scan when /proc/self/fd is unavailable.
Dmitriy Vasyura (dmitrivMS)
approved these changes
Dec 2, 2026
Anthony Kim (anthonykim1)
approved these changes
Dec 2, 2026
Contributor
There was a problem hiding this comment.
Copilot verified on Linux arm64 (kernel 7.0.12) with main and this PR built like CI (glibc 2.28 sysroot).
The sysroot build now calls close_range(3, ~0U, CLOSE_RANGE_CLOEXEC) once in the child instead of walking /proc/self/fd. Spawn to exit for sh -c :, median of 30 spawns:
| Extra fds | main | this PR |
|---|---|---|
| 0 | 0.41 ms | 0.41 ms |
| 1,000 | 1.71 ms | 0.50 ms |
| 10,000 | 10.95 ms | 0.76 ms |
| 100,000 | 101.81 ms | 2.83 ms |
To cover the fallbacks, I forced them with seccomp: EINVAL for CLOSE_RANGE_CLOEXEC (Linux 5.9/5.10) and ENOSYS (before 5.9). Neither leaks a pty master into a new shell, and the 20 tests pass. The x64 and arm64 sysroot builds still pass verify-glibc-requirements.sh.
Authored with Copilot on behalf of anthonykim1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1023
Use
__NR_close_rangewith ABI fallbacks so glibc 2.28 sysroots (including older 4.19 kernel headers) compile inclose_range. Fall back toclose_range(..., 0)on EINVAL for Linux 5.9-5.10, and replace the fd loop with a bounded RLIMIT_NOFILE scan when /proc/self/fd is unavailable.