-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
kmc-solid: I/O safety #115159
kmc-solid: I/O safety #115159
Conversation
(rustbot has picked a reviewer for you, use r? to override) |
r? libs-api -- not sure if we ask for ACPs for extending Tier-3 target APIs. |
It would be unprecedented to ask for such when it is merely extending a target-neutral std API for a tier 3 target. |
#[derive(Copy, Clone)] | ||
#[repr(transparent)] | ||
#[rustc_layout_scalar_valid_range_start(0)] | ||
// This is -2, in two's complement. -1 is `SOLID_NET_INVALID_FD`. | ||
#[rustc_layout_scalar_valid_range_end(0xFF_FF_FF_FE)] | ||
#[rustc_nonnull_optimization_guaranteed] | ||
pub struct BorrowedFd<'socket> { | ||
fd: RawFd, | ||
_phantom: PhantomData<&'socket OwnedFd>, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This layout optimization has come into question on Haiku:
I would appreciate it if you weighed in with your thoughts, either here or in that PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This BorrowedFd
is specific to the SOLID socket subsystem, so technically it's closer to std::os::windows::io::BorrowedSocket
than std::os::fd::BorrowedFd
, the POSIX file descriptor that is in question in the referred issue.
Personally, AT_FDCWD
feels like a special value that can only be handled by a few supported functions. It's also unusual in that it doesn't point to one static entity over its lifetime, which I suspect may break assumption of some code. I'd be fine with fd::BorrowedFd
only being able to hold a "valid" value and leaving the ability to hold such special values unspecified.
Even the POSIX specification's wordings suggest that it's not a file descriptor:
The <fcntl.h> header shall define the following symbolic constant [
AT_FDCWD
] as a special value used in place of a file descriptor [...]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh, interesting! I hadn't realized that SOLID was that divergent!
☔ The latest upstream changes (presumably #116132) made this pull request unmergeable. Please resolve the merge conflicts. |
It's mostly based on `std::os::fd::owned`.
Mostly copied from `std::os::unix::io`, except quantifying file descriptors with SOLID Sockets and removing the paragraph mentioning `mmap`.
…pStream,TcpListener,UdpSocket}`
…`Socket` Follows how other targets are implemented.
Removes the private type `std::sys::solid::net::FileDesc`, replacing its only usage in `std::sys::solid::net::Socket` with `std::os::solid::io:: OwnedFd`.
…et}` by delegating to inner `Socket` Removes some `unsafe` blocks.
3d66f9b
to
52eb92d
Compare
Rebased on top of |
As it would be unprecedented to make std-approved API expansion for a tier 3 platform dependent on explicit T-libs-api approval, I am shipping this. |
…r=workingjubilee kmc-solid: I/O safety Adds the I/O safety API (rust-lang#87329) for socket file descriptors in [`*-kmc-solid_*`](https://doc.rust-lang.org/nightly/rustc/platform-support/kmc-solid.html) Tier 3 targets. All new public items are gated by the `solid_ext` library feature. This PR adds the following public types and traits: std::os::solid::io::AsFd std::os::solid::io::BorrowedFd std::os::solid::io::OwnedFd std::os::solid::prelude::AsFd (re-export) std::os::solid::prelude::BorrowedFd (re-export) std::os::solid::prelude::OwnedFd (re-export) And trait implementations: From<std::net::TcpListener> for std::os::solid::io::OwnedFd From<std::net::TcpStream> for std::os::solid::io::OwnedFd From<std::net::UdpSocket> for std::os::solid::io::OwnedFd From<std::os::solid::io::OwnedFd> for std::net::TcpListener From<std::os::solid::io::OwnedFd> for std::net::TcpStream From<std::os::solid::io::OwnedFd> for std::net::UdpSocket std::fmt::Debug for std::os::solid::io::BorrowedFd<'_> std::fmt::Debug for std::os::solid::io::OwnedFd std::io::IsTerminal for std::os::solid::io::BorrowedFd<'_> std::io::IsTerminal for std::os::solid::io::OwnedFd std::os::fd::AsRawFd for std::os::solid::io::BorrowedFd<'_> std::os::fd::AsRawFd for std::os::solid::io::OwnedFd std::os::fd::FromRawFd for std::os::solid::io::OwnedFd std::os::fd::IntoRawFd for std::os::solid::io::OwnedFd std::os::solid::io::AsFd for &impl std::os::solid::io::AsFd std::os::solid::io::AsFd for &mut impl std::os::solid::io::AsFd std::os::solid::io::AsFd for Arc<impl std::os::solid::io::AsFd> std::os::solid::io::AsFd for Box<impl std::os::solid::io::AsFd> std::os::solid::io::AsFd for Rc<impl std::os::solid::io::AsFd> std::os::solid::io::AsFd for std::net::TcpListener std::os::solid::io::AsFd for std::net::TcpStream std::os::solid::io::AsFd for std::net::UdpSocket std::os::solid::io::AsFd for std::os::solid::io::BorrowedFd<'_> std::os::solid::io::AsFd for std::os::solid::io::OwnedFd Taking advantage of the above change, this PR also refactors the internal details of `std::sys::solid::net` to match the design of other targets, e.g., by redefining `Socket` as a newtype of `OwnedFd`.
💔 Test failed - checks-actions |
@bors retry |
☀️ Test successful - checks-actions |
Finished benchmarking commit (1934665): comparison URL. Overall result: no relevant changes - no action needed@rustbot label: -perf-regression Instruction countThis benchmark run did not return any relevant results for this metric. Max RSS (memory usage)ResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesThis benchmark run did not return any relevant results for this metric. Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 677.231s -> 675.802s (-0.21%) |
Adds the I/O safety API (#87329) for socket file descriptors in
*-kmc-solid_*
Tier 3 targets. All new public items are gated by thesolid_ext
library feature.This PR adds the following public types and traits:
And trait implementations:
Taking advantage of the above change, this PR also refactors the internal details of
std::sys::solid::net
to match the design of other targets, e.g., by redefiningSocket
as a newtype ofOwnedFd
.