fs: implement close_range(2) - #1436
Open
gburd wants to merge 1 commit into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
Adds Linux-compatible close_range(2) support to OSv so software that relies on the syscall (common in runtimes and fd-sanitization paths) no longer fails, including libc exposure and a regression test.
Changes:
- Implement
close_range()over OSv’s fd table (close fds in range, or set CLOEXEC). - Wire up syscall metadata (syscall list, tracepoint, arch syscall numbers) and export the symbol in libc/loader symbol lists.
- Add
tst-close-rangeto the test suite and build.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/tst-close-range.cc | New test covering close-range behavior, CLOEXEC variant, and EINVAL paths. |
| syscalls/syscalls.cc.in | Adds close_range to the syscall wrapper list. |
| syscalls/syscall_tracepoints.cc.in | Adds a syscall tracepoint for close_range. |
| modules/tests/Makefile | Includes the new tst-close-range.so in the test image build. |
| linux.cc | Adds an extern "C" declaration for close_range. |
| include/api/x64/bits/syscall.h | Defines SYS_close_range / __NR_close_range for x86-64. |
| include/api/aarch64/bits/syscall.h | Defines SYS_close_range / __NR_close_range for aarch64. |
| include/api/unistd.h | Declares close_range() under _GNU_SOURCE. |
| fs/vfs/main.cc | Implements close_range() using fdclose() / fget() and O_CLOEXEC. |
| exported_symbols/osv_libc.so.6.symbols | Exports close_range from libc.so.6. |
| exported_symbols/osv_ld-musl.so.1.symbols | Exports close_range from ld-musl.so.1. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Add Linux close_range(2) over OSv's fd table: close (or, with CLOSE_RANGE_CLOEXEC, set close-on-exec on) every open fd in the inclusive range [first, last]. CLOSE_RANGE_UNSHARE is a no-op in a single-process unikernel (there is nothing to unshare). Reject first > last and unknown flags with EINVAL. Wired through libc/syscall dispatch/tracepoints with a regression test. Signed-off-by: Greg Burd <greg@burd.me>
Contributor
Author
|
Thanks Copilot. Addressed / responded in the current tip (7c95715, rebased onto master):
Needs a build to confirm the test passes; queued. |
Contributor
Author
|
Build-validated on x86_64: |
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.
What
close_range(2)was missing entirely. It is the standard way to close a rangeof file descriptors in one call (commonly used to clean up inherited fds and by
some language runtimes), so programs that call it failed.
How
Implemented over the existing fd table: close (or, with
CLOSE_RANGE_CLOEXEC,set
O_CLOEXECon) every open fd in the inclusive range[first, last],clamping
lastto the fd-table size and ignoring fds that are not open, as Linuxdoes.
CLOSE_RANGE_UNSHAREis a no-op in a single-process unikernel (there isnothing to unshare).
first > lastand unknown flags returnEINVAL.Wired as syscall
SYS_close_range(adding__NR_close_range/SYS_close_rangefor x86-64 and aarch64) with a tracepoint, declared inunistd.hunder_GNU_SOURCE, and the symbol exported fromlibc.so.6andld-musl.so.1.Testing
tests/tst-close-range.cccovers closing a contiguous run, a range that spansnot-open fds, the
CLOSE_RANGE_CLOEXECvariant, and theEINVALpaths. Passeson OSv under KVM.
(Recreated from #1417, which GitHub auto-closed when its branch was rebased onto current master. Same change, rebased and verified on master 3aba46c.)