summaryrefslogtreecommitdiffstats
path: root/vendor/rustix/src/backend/libc/io
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/rustix/src/backend/libc/io')
-rw-r--r--vendor/rustix/src/backend/libc/io/epoll.rs366
-rw-r--r--vendor/rustix/src/backend/libc/io/errno.rs2
-rw-r--r--vendor/rustix/src/backend/libc/io/io_slice.rs87
-rw-r--r--vendor/rustix/src/backend/libc/io/mod.rs7
-rw-r--r--vendor/rustix/src/backend/libc/io/poll_fd.rs136
-rw-r--r--vendor/rustix/src/backend/libc/io/syscalls.rs433
-rw-r--r--vendor/rustix/src/backend/libc/io/types.rs138
-rw-r--r--vendor/rustix/src/backend/libc/io/windows_syscalls.rs18
8 files changed, 49 insertions, 1138 deletions
diff --git a/vendor/rustix/src/backend/libc/io/epoll.rs b/vendor/rustix/src/backend/libc/io/epoll.rs
deleted file mode 100644
index 62a3c742b..000000000
--- a/vendor/rustix/src/backend/libc/io/epoll.rs
+++ /dev/null
@@ -1,366 +0,0 @@
-//! epoll support.
-//!
-//! This is an experiment, and it isn't yet clear whether epoll is the right
-//! level of abstraction at which to introduce safety. But it works fairly well
-//! in simple examples 🙂.
-//!
-//! # Examples
-//!
-//! ```no_run
-//! # #![cfg_attr(io_lifetimes_use_std, feature(io_safety))]
-//! # #[cfg(feature = "net")]
-//! # fn main() -> std::io::Result<()> {
-//! use io_lifetimes::AsFd;
-//! use rustix::io::{epoll, ioctl_fionbio, read, write};
-//! use rustix::net::{
-//! accept, bind_v4, listen, socket, AddressFamily, Ipv4Addr, Protocol, SocketAddrV4,
-//! SocketType,
-//! };
-//! use std::collections::HashMap;
-//! use std::os::unix::io::AsRawFd;
-//!
-//! // Create a socket and listen on it.
-//! let listen_sock = socket(AddressFamily::INET, SocketType::STREAM, Protocol::default())?;
-//! bind_v4(&listen_sock, &SocketAddrV4::new(Ipv4Addr::LOCALHOST, 0))?;
-//! listen(&listen_sock, 1)?;
-//!
-//! // Create an epoll object. Using `Owning` here means the epoll object will
-//! // take ownership of the file descriptors registered with it.
-//! let epoll = epoll::epoll_create(epoll::CreateFlags::CLOEXEC)?;
-//!
-//! // Register the socket with the epoll object.
-//! epoll::epoll_add(&epoll, &listen_sock, 1, epoll::EventFlags::IN)?;
-//!
-//! // Keep track of the sockets we've opened.
-//! let mut next_id = 2;
-//! let mut sockets = HashMap::new();
-//!
-//! // Process events.
-//! let mut event_list = epoll::EventVec::with_capacity(4);
-//! loop {
-//! epoll::epoll_wait(&epoll, &mut event_list, -1)?;
-//! for (_event_flags, target) in &event_list {
-//! if target == 1 {
-//! // Accept a new connection, set it to non-blocking, and
-//! // register to be notified when it's ready to write to.
-//! let conn_sock = accept(&listen_sock)?;
-//! ioctl_fionbio(&conn_sock, true)?;
-//! epoll::epoll_add(
-//! &epoll,
-//! &conn_sock,
-//! next_id,
-//! epoll::EventFlags::OUT | epoll::EventFlags::ET,
-//! )?;
-//!
-//! // Keep track of the socket.
-//! sockets.insert(next_id, conn_sock);
-//! next_id += 1;
-//! } else {
-//! // Write a message to the stream and then unregister it.
-//! let target = sockets.remove(&target).unwrap();
-//! write(&target, b"hello\n")?;
-//! let _ = epoll::epoll_del(&epoll, &target)?;
-//! }
-//! }
-//! }
-//! # }
-//! # #[cfg(not(feature = "net"))]
-//! # fn main() {}
-//! ```
-
-use super::super::c;
-use super::super::conv::{ret, ret_owned_fd, ret_u32};
-use crate::fd::{AsFd, AsRawFd, OwnedFd};
-use crate::io;
-use alloc::vec::Vec;
-use bitflags::bitflags;
-use core::convert::TryInto;
-use core::ptr::null_mut;
-
-bitflags! {
- /// `EPOLL_*` for use with [`Epoll::new`].
- pub struct CreateFlags: c::c_int {
- /// `EPOLL_CLOEXEC`
- const CLOEXEC = c::EPOLL_CLOEXEC;
- }
-}
-
-bitflags! {
- /// `EPOLL*` for use with [`Epoll::add`].
- #[derive(Default)]
- pub struct EventFlags: u32 {
- /// `EPOLLIN`
- const IN = c::EPOLLIN as u32;
-
- /// `EPOLLOUT`
- const OUT = c::EPOLLOUT as u32;
-
- /// `EPOLLPRI`
- const PRI = c::EPOLLPRI as u32;
-
- /// `EPOLLERR`
- const ERR = c::EPOLLERR as u32;
-
- /// `EPOLLHUP`
- const HUP = c::EPOLLHUP as u32;
-
- /// `EPOLLRDNORM`
- const RDNORM = c::EPOLLRDNORM as u32;
-
- /// `EPOLLRDBAND`
- const RDBAND = c::EPOLLRDBAND as u32;
-
- /// `EPOLLWRNORM`
- const WRNORM = c::EPOLLWRNORM as u32;
-
- /// `EPOLLWRBAND`
- const WRBAND = c::EPOLLWRBAND as u32;
-
- /// `EPOLLMSG`
- const MSG = c::EPOLLMSG as u32;
-
- /// `EPOLLRDHUP`
- const RDHUP = c::EPOLLRDHUP as u32;
-
- /// `EPOLLET`
- const ET = c::EPOLLET as u32;
-
- /// `EPOLLONESHOT`
- const ONESHOT = c::EPOLLONESHOT as u32;
-
- /// `EPOLLWAKEUP`
- const WAKEUP = c::EPOLLWAKEUP as u32;
-
- /// `EPOLLEXCLUSIVE`
- #[cfg(not(target_os = "android"))]
- const EXCLUSIVE = c::EPOLLEXCLUSIVE as u32;
- }
-}
-
-/// `epoll_create1(flags)`—Creates a new `Epoll`.
-///
-/// Use the [`CreateFlags::CLOEXEC`] flag to prevent the resulting file
-/// descriptor from being implicitly passed across `exec` boundaries.
-#[inline]
-#[doc(alias = "epoll_create1")]
-pub fn epoll_create(flags: CreateFlags) -> io::Result<OwnedFd> {
- // SAFETY: We're calling `epoll_create1` via FFI and we know how it
- // behaves.
- unsafe { ret_owned_fd(c::epoll_create1(flags.bits())) }
-}
-
-/// `epoll_ctl(self, EPOLL_CTL_ADD, data, event)`—Adds an element to an
-/// `Epoll`.
-///
-/// Note that if `epoll_del` is not called on the I/O source passed into
-/// this function before the I/O source is `close`d, then the `epoll` will
-/// act as if the I/O source is still registered with it. This can lead to
-/// spurious events being returned from `epoll_wait`. If a file descriptor
-/// is an `Arc<dyn SystemResource>`, then `epoll` can be thought to maintain
-/// a `Weak<dyn SystemResource>` to the file descriptor.
-#[doc(alias = "epoll_ctl")]
-pub fn epoll_add(
- epoll: impl AsFd,
- source: impl AsFd,
- data: u64,
- event_flags: EventFlags,
-) -> io::Result<()> {
- // SAFETY: We're calling `epoll_ctl` via FFI and we know how it
- // behaves.
- unsafe {
- let raw_fd = source.as_fd().as_raw_fd();
- ret(c::epoll_ctl(
- epoll.as_fd().as_raw_fd(),
- c::EPOLL_CTL_ADD,
- raw_fd,
- &mut c::epoll_event {
- events: event_flags.bits(),
- r#u64: data,
- },
- ))
- }
-}
-
-/// `epoll_ctl(self, EPOLL_CTL_MOD, target, event)`—Modifies an element in
-/// this `Epoll`.
-///
-/// This sets the events of interest with `target` to `events`.
-#[doc(alias = "epoll_ctl")]
-pub fn epoll_mod(
- epoll: impl AsFd,
- source: impl AsFd,
- data: u64,
- event_flags: EventFlags,
-) -> io::Result<()> {
- let raw_fd = source.as_fd().as_raw_fd();
-
- // SAFETY: We're calling `epoll_ctl` via FFI and we know how it
- // behaves.
- unsafe {
- ret(c::epoll_ctl(
- epoll.as_fd().as_raw_fd(),
- c::EPOLL_CTL_MOD,
- raw_fd,
- &mut c::epoll_event {
- events: event_flags.bits(),
- r#u64: data,
- },
- ))
- }
-}
-
-/// `epoll_ctl(self, EPOLL_CTL_DEL, target, NULL)`—Removes an element in
-/// this `Epoll`.
-#[doc(alias = "epoll_ctl")]
-pub fn epoll_del(epoll: impl AsFd, source: impl AsFd) -> io::Result<()> {
- // SAFETY: We're calling `epoll_ctl` via FFI and we know how it
- // behaves.
- unsafe {
- let raw_fd = source.as_fd().as_raw_fd();
- ret(c::epoll_ctl(
- epoll.as_fd().as_raw_fd(),
- c::EPOLL_CTL_DEL,
- raw_fd,
- null_mut(),
- ))
- }
-}
-
-/// `epoll_wait(self, events, timeout)`—Waits for registered events of
-/// interest.
-///
-/// For each event of interest, an element is written to `events`. On
-/// success, this returns the number of written elements.
-pub fn epoll_wait(
- epoll: impl AsFd,
- event_list: &mut EventVec,
- timeout: c::c_int,
-) -> io::Result<()> {
- // SAFETY: We're calling `epoll_wait` via FFI and we know how it
- // behaves.
- unsafe {
- event_list.events.set_len(0);
- let nfds = ret_u32(c::epoll_wait(
- epoll.as_fd().as_raw_fd(),
- event_list.events.as_mut_ptr().cast::<c::epoll_event>(),
- event_list.events.capacity().try_into().unwrap_or(i32::MAX),
- timeout,
- ))?;
- event_list.events.set_len(nfds as usize);
- }
-
- Ok(())
-}
-
-/// An iterator over the `Event`s in an `EventVec`.
-pub struct Iter<'a> {
- iter: core::slice::Iter<'a, Event>,
-}
-
-impl<'a> Iterator for Iter<'a> {
- type Item = (EventFlags, u64);
-
- fn next(&mut self) -> Option<Self::Item> {
- // SAFETY: `self.context` is guaranteed to be valid because we hold
- // `'context` for it. And we know this event is associated with this
- // context because `wait` sets both.
- self.iter
- .next()
- .map(|event| (event.event_flags, event.data))
- }
-}
-
-/// A record of an event that occurred.
-#[repr(C)]
-#[cfg_attr(
- any(
- all(
- target_arch = "x86",
- not(target_env = "musl"),
- not(target_os = "android"),
- ),
- target_arch = "x86_64",
- ),
- repr(packed)
-)]
-struct Event {
- // Match the layout of `c::epoll_event`. We just use a `u64` instead of
- // the full union.
- event_flags: EventFlags,
- data: u64,
-}
-
-/// A vector of `Event`s, plus context for interpreting them.
-pub struct EventVec {
- events: Vec<Event>,
-}
-
-impl EventVec {
- /// Constructs an `EventVec` with memory for `capacity` `Event`s.
- #[inline]
- pub fn with_capacity(capacity: usize) -> Self {
- Self {
- events: Vec::with_capacity(capacity),
- }
- }
-
- /// Returns the current `Event` capacity of this `EventVec`.
- #[inline]
- pub fn capacity(&self) -> usize {
- self.events.capacity()
- }
-
- /// Reserves enough memory for at least `additional` more `Event`s.
- #[inline]
- pub fn reserve(&mut self, additional: usize) {
- self.events.reserve(additional);
- }
-
- /// Reserves enough memory for exactly `additional` more `Event`s.
- #[inline]
- pub fn reserve_exact(&mut self, additional: usize) {
- self.events.reserve_exact(additional);
- }
-
- /// Clears all the `Events` out of this `EventVec`.
- #[inline]
- pub fn clear(&mut self) {
- self.events.clear();
- }
-
- /// Shrinks the capacity of this `EventVec` as much as possible.
- #[inline]
- pub fn shrink_to_fit(&mut self) {
- self.events.shrink_to_fit();
- }
-
- /// Returns an iterator over the `Event`s in this `EventVec`.
- #[inline]
- pub fn iter(&self) -> Iter<'_> {
- Iter {
- iter: self.events.iter(),
- }
- }
-
- /// Returns the number of `Event`s logically contained in this `EventVec`.
- #[inline]
- pub fn len(&mut self) -> usize {
- self.events.len()
- }
-
- /// Tests whether this `EventVec` is logically empty.
- #[inline]
- pub fn is_empty(&mut self) -> bool {
- self.events.is_empty()
- }
-}
-
-impl<'a> IntoIterator for &'a EventVec {
- type IntoIter = Iter<'a>;
- type Item = (EventFlags, u64);
-
- #[inline]
- fn into_iter(self) -> Self::IntoIter {
- self.iter()
- }
-}
diff --git a/vendor/rustix/src/backend/libc/io/errno.rs b/vendor/rustix/src/backend/libc/io/errno.rs
index 9e808c0b4..71fba49e9 100644
--- a/vendor/rustix/src/backend/libc/io/errno.rs
+++ b/vendor/rustix/src/backend/libc/io/errno.rs
@@ -3,7 +3,7 @@
//! This type holds an OS error code, which conceptually corresponds to an
//! `errno` value.
-use super::super::c;
+use crate::backend::c;
use libc_errno::errno;
/// The error type for `rustix` APIs.
diff --git a/vendor/rustix/src/backend/libc/io/io_slice.rs b/vendor/rustix/src/backend/libc/io/io_slice.rs
deleted file mode 100644
index de1ef434c..000000000
--- a/vendor/rustix/src/backend/libc/io/io_slice.rs
+++ /dev/null
@@ -1,87 +0,0 @@
-//! The following is derived from Rust's
-//! library/std/src/sys/unix/io.rs
-//! dca3f1b786efd27be3b325ed1e01e247aa589c3b.
-
-#![allow(missing_docs)]
-
-use super::super::c;
-use core::marker::PhantomData;
-use core::slice;
-
-#[derive(Copy, Clone)]
-#[repr(transparent)]
-pub struct IoSlice<'a> {
- vec: c::iovec,
- _p: PhantomData<&'a [u8]>,
-}
-
-impl<'a> IoSlice<'a> {
- #[inline]
- pub fn new(buf: &'a [u8]) -> IoSlice<'a> {
- IoSlice {
- vec: c::iovec {
- iov_base: buf.as_ptr() as *mut u8 as *mut c::c_void,
- iov_len: buf.len(),
- },
- _p: PhantomData,
- }
- }
-
- #[inline]
- pub fn advance(&mut self, n: usize) {
- if self.vec.iov_len < n {
- panic!("advancing IoSlice beyond its length");
- }
-
- unsafe {
- self.vec.iov_len -= n;
- self.vec.iov_base = self.vec.iov_base.add(n);
- }
- }
-
- #[inline]
- pub fn as_slice(&self) -> &[u8] {
- unsafe { slice::from_raw_parts(self.vec.iov_base as *mut u8, self.vec.iov_len) }
- }
-}
-
-#[repr(transparent)]
-pub struct IoSliceMut<'a> {
- vec: c::iovec,
- _p: PhantomData<&'a mut [u8]>,
-}
-
-impl<'a> IoSliceMut<'a> {
- #[inline]
- pub fn new(buf: &'a mut [u8]) -> IoSliceMut<'a> {
- IoSliceMut {
- vec: c::iovec {
- iov_base: buf.as_mut_ptr() as *mut c::c_void,
- iov_len: buf.len(),
- },
- _p: PhantomData,
- }
- }
-
- #[inline]
- pub fn advance(&mut self, n: usize) {
- if self.vec.iov_len < n {
- panic!("advancing IoSliceMut beyond its length");
- }
-
- unsafe {
- self.vec.iov_len -= n;
- self.vec.iov_base = self.vec.iov_base.add(n);
- }
- }
-
- #[inline]
- pub fn as_slice(&self) -> &[u8] {
- unsafe { slice::from_raw_parts(self.vec.iov_base as *mut u8, self.vec.iov_len) }
- }
-
- #[inline]
- pub fn as_mut_slice(&mut self) -> &mut [u8] {
- unsafe { slice::from_raw_parts_mut(self.vec.iov_base as *mut u8, self.vec.iov_len) }
- }
-}
diff --git a/vendor/rustix/src/backend/libc/io/mod.rs b/vendor/rustix/src/backend/libc/io/mod.rs
index 1378adf3d..487388576 100644
--- a/vendor/rustix/src/backend/libc/io/mod.rs
+++ b/vendor/rustix/src/backend/libc/io/mod.rs
@@ -1,13 +1,6 @@
pub(crate) mod errno;
#[cfg(not(windows))]
-#[cfg(not(feature = "std"))]
-pub(crate) mod io_slice;
-pub(crate) mod poll_fd;
-#[cfg(not(windows))]
pub(crate) mod types;
#[cfg_attr(windows, path = "windows_syscalls.rs")]
pub(crate) mod syscalls;
-
-#[cfg(any(target_os = "android", target_os = "linux"))]
-pub mod epoll;
diff --git a/vendor/rustix/src/backend/libc/io/poll_fd.rs b/vendor/rustix/src/backend/libc/io/poll_fd.rs
deleted file mode 100644
index a0568c60a..000000000
--- a/vendor/rustix/src/backend/libc/io/poll_fd.rs
+++ /dev/null
@@ -1,136 +0,0 @@
-use super::super::c;
-use super::super::conv::borrowed_fd;
-#[cfg(windows)]
-use super::super::fd::RawFd;
-use super::super::fd::{AsFd, AsRawFd, BorrowedFd, LibcFd};
-use bitflags::bitflags;
-use core::marker::PhantomData;
-#[cfg(windows)]
-use std::fmt;
-
-bitflags! {
- /// `POLL*` flags for use with [`poll`].
- ///
- /// [`poll`]: crate::io::poll
- pub struct PollFlags: c::c_short {
- /// `POLLIN`
- const IN = c::POLLIN;
- /// `POLLPRI`
- #[cfg(not(target_os = "wasi"))]
- const PRI = c::POLLPRI;
- /// `POLLOUT`
- const OUT = c::POLLOUT;
- /// `POLLRDNORM`
- #[cfg(not(target_os = "redox"))]
- const RDNORM = c::POLLRDNORM;
- /// `POLLWRNORM`
- #[cfg(not(target_os = "redox"))]
- const WRNORM = c::POLLWRNORM;
- /// `POLLRDBAND`
- #[cfg(not(any(target_os = "redox", target_os = "wasi")))]
- const RDBAND = c::POLLRDBAND;
- /// `POLLWRBAND`
- #[cfg(not(any(target_os = "redox", target_os = "wasi")))]
- const WRBAND = c::POLLWRBAND;
- /// `POLLERR`
- const ERR = c::POLLERR;
- /// `POLLHUP`
- const HUP = c::POLLHUP;
- /// `POLLNVAL`
- const NVAL = c::POLLNVAL;
- /// `POLLRDHUP`
- #[cfg(all(
- any(target_os = "android", target_os = "linux"),
- not(any(target_arch = "sparc", target_arch = "sparc64"))),
- )]
- const RDHUP = c::POLLRDHUP;
- }
-}
-
-/// `struct pollfd`—File descriptor and flags for use with [`poll`].
-///
-/// [`poll`]: crate::io::poll
-#[doc(alias = "pollfd")]
-#[derive(Clone)]
-#[cfg_attr(not(windows), derive(Debug))]
-#[repr(transparent)]
-pub struct PollFd<'fd> {
- pollfd: c::pollfd,
- _phantom: PhantomData<BorrowedFd<'fd>>,
-}
-
-#[cfg(windows)]
-impl<'fd> fmt::Debug for PollFd<'fd> {
- fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
- fmt.debug_struct("pollfd")
- .field("fd", &self.pollfd.fd)
- .field("events", &self.pollfd.events)
- .field("revents", &self.pollfd.revents)
- .finish()
- }
-}
-
-impl<'fd> PollFd<'fd> {
- /// Constructs a new `PollFd` holding `fd` and `events`.
- #[inline]
- pub fn new<Fd: AsFd>(fd: &'fd Fd, events: PollFlags) -> Self {
- Self::from_borrowed_fd(fd.as_fd(), events)
- }
-
- /// Sets the contained file descriptor to `fd`.
- #[inline]
- pub fn set_fd<Fd: AsFd>(&mut self, fd: &'fd Fd) {
- self.pollfd.fd = fd.as_fd().as_raw_fd() as LibcFd;
- }
-
- /// Clears the ready events.
- #[inline]
- pub fn clear_revents(&mut self) {
- self.pollfd.revents = 0;
- }
-
- /// Constructs a new `PollFd` holding `fd` and `events`.
- ///
- /// This is the same as `new`, but can be used to avoid borrowing the
- /// `BorrowedFd`, which can be tricky in situations where the `BorrowedFd`
- /// is a temporary.
- #[inline]
- pub fn from_borrowed_fd(fd: BorrowedFd<'fd>, events: PollFlags) -> Self {
- Self {
- pollfd: c::pollfd {
- fd: borrowed_fd(fd),
- events: events.bits(),
- revents: 0,
- },
- _phantom: PhantomData,
- }
- }
-
- /// Returns the ready events.
- #[inline]
- pub fn revents(&self) -> PollFlags {
- // Use `unwrap()` here because in theory we know we know all the bits
- // the OS might set here, but OS's have added extensions in the past.
- PollFlags::from_bits(self.pollfd.revents).unwrap()
- }
-}
-
-#[cfg(not(windows))]
-impl<'fd> AsFd for PollFd<'fd> {
- #[inline]
- fn as_fd(&self) -> BorrowedFd<'_> {
- // SAFETY: Our constructors and `set_fd` require `pollfd.fd` to be
- // valid for the `fd lifetime.
- unsafe { BorrowedFd::borrow_raw(self.pollfd.fd) }
- }
-}
-
-#[cfg(windows)]
-impl<'fd> io_lifetimes::AsSocket for PollFd<'fd> {
- #[inline]
- fn as_socket(&self) -> BorrowedFd<'_> {
- // SAFETY: Our constructors and `set_fd` require `pollfd.fd` to be
- // valid for the `fd lifetime.
- unsafe { BorrowedFd::borrow_raw(self.pollfd.fd as RawFd) }
- }
-}
diff --git a/vendor/rustix/src/backend/libc/io/syscalls.rs b/vendor/rustix/src/backend/libc/io/syscalls.rs
index b74a63fa3..6ac1fa593 100644
--- a/vendor/rustix/src/backend/libc/io/syscalls.rs
+++ b/vendor/rustix/src/backend/libc/io/syscalls.rs
@@ -1,43 +1,17 @@
//! libc syscalls supporting `rustix::io`.
-use super::super::c;
-#[cfg(any(target_os = "android", target_os = "linux"))]
-use super::super::conv::syscall_ret_owned_fd;
-#[cfg(any(
- target_os = "android",
- all(target_os = "linux", not(target_env = "gnu")),
-))]
-use super::super::conv::syscall_ret_usize;
-use super::super::conv::{borrowed_fd, ret, ret_c_int, ret_discarded_fd, ret_owned_fd, ret_usize};
-use super::super::offset::{libc_pread, libc_pwrite};
-#[cfg(not(any(target_os = "haiku", target_os = "redox", target_os = "solaris")))]
-use super::super::offset::{libc_preadv, libc_pwritev};
-#[cfg(all(target_os = "linux", target_env = "gnu"))]
-use super::super::offset::{libc_preadv2, libc_pwritev2};
+use crate::backend::conv::{
+ borrowed_fd, ret, ret_c_int, ret_discarded_fd, ret_owned_fd, ret_usize,
+};
+use crate::backend::{c, MAX_IOV};
use crate::fd::{AsFd, BorrowedFd, OwnedFd, RawFd};
-#[cfg(bsd)]
-use crate::io::kqueue::Event;
-#[cfg(solarish)]
-use crate::io::port::Event;
#[cfg(not(any(target_os = "aix", target_os = "wasi")))]
use crate::io::DupFlags;
-#[cfg(any(
- target_os = "android",
- target_os = "freebsd",
- target_os = "illumos",
- target_os = "linux"
-))]
-use crate::io::EventfdFlags;
-#[cfg(not(any(apple, target_os = "aix", target_os = "haiku", target_os = "wasi")))]
-use crate::io::PipeFlags;
-use crate::io::{self, FdFlags, IoSlice, IoSliceMut, PollFd};
-#[cfg(any(target_os = "android", target_os = "linux"))]
-use crate::io::{IoSliceRaw, ReadWriteFlags, SpliceFlags};
+#[cfg(linux_kernel)]
+use crate::io::ReadWriteFlags;
+use crate::io::{self, FdFlags, IoSlice, IoSliceMut};
use core::cmp::min;
-use core::convert::TryInto;
use core::mem::MaybeUninit;
-#[cfg(any(target_os = "android", target_os = "linux"))]
-use core::ptr;
#[cfg(all(feature = "fs", feature = "net"))]
use libc_errno::errno;
@@ -68,7 +42,7 @@ pub(crate) fn pread(fd: BorrowedFd<'_>, buf: &mut [u8], offset: u64) -> io::Resu
let offset = offset as i64;
unsafe {
- ret_usize(libc_pread(
+ ret_usize(c::pread(
borrowed_fd(fd),
buf.as_mut_ptr().cast(),
len,
@@ -83,14 +57,7 @@ pub(crate) fn pwrite(fd: BorrowedFd<'_>, buf: &[u8], offset: u64) -> io::Result<
// Silently cast; we'll get `EINVAL` if the value is negative.
let offset = offset as i64;
- unsafe {
- ret_usize(libc_pwrite(
- borrowed_fd(fd),
- buf.as_ptr().cast(),
- len,
- offset,
- ))
- }
+ unsafe { ret_usize(c::pwrite(borrowed_fd(fd), buf.as_ptr().cast(), len, offset)) }
}
pub(crate) fn readv(fd: BorrowedFd<'_>, bufs: &mut [IoSliceMut]) -> io::Result<usize> {
@@ -98,7 +65,7 @@ pub(crate) fn readv(fd: BorrowedFd<'_>, bufs: &mut [IoSliceMut]) -> io::Result<u
ret_usize(c::readv(
borrowed_fd(fd),
bufs.as_ptr().cast::<c::iovec>(),
- min(bufs.len(), max_iov()) as c::c_int,
+ min(bufs.len(), MAX_IOV) as c::c_int,
))
}
}
@@ -108,7 +75,7 @@ pub(crate) fn writev(fd: BorrowedFd<'_>, bufs: &[IoSlice]) -> io::Result<usize>
ret_usize(c::writev(
borrowed_fd(fd),
bufs.as_ptr().cast::<c::iovec>(),
- min(bufs.len(), max_iov()) as c::c_int,
+ min(bufs.len(), MAX_IOV) as c::c_int,
))
}
}
@@ -122,10 +89,10 @@ pub(crate) fn preadv(
// Silently cast; we'll get `EINVAL` if the value is negative.
let offset = offset as i64;
unsafe {
- ret_usize(libc_preadv(
+ ret_usize(c::preadv(
borrowed_fd(fd),
bufs.as_ptr().cast::<c::iovec>(),
- min(bufs.len(), max_iov()) as c::c_int,
+ min(bufs.len(), MAX_IOV) as c::c_int,
offset,
))
}
@@ -136,42 +103,16 @@ pub(crate) fn pwritev(fd: BorrowedFd<'_>, bufs: &[IoSlice], offset: u64) -> io::
// Silently cast; we'll get `EINVAL` if the value is negative.
let offset = offset as i64;
unsafe {
- ret_usize(libc_pwritev(
- borrowed_fd(fd),
- bufs.as_ptr().cast::<c::iovec>(),
- min(bufs.len(), max_iov()) as c::c_int,
- offset,
- ))
- }
-}
-
-#[cfg(all(target_os = "linux", target_env = "gnu"))]
-pub(crate) fn preadv2(
- fd: BorrowedFd<'_>,
- bufs: &mut [IoSliceMut],
- offset: u64,
- flags: ReadWriteFlags,
-) -> io::Result<usize> {
- // Silently cast; we'll get `EINVAL` if the value is negative.
- let offset = offset as i64;
- unsafe {
- ret_usize(libc_preadv2(
+ ret_usize(c::pwritev(
borrowed_fd(fd),
bufs.as_ptr().cast::<c::iovec>(),
- min(bufs.len(), max_iov()) as c::c_int,
+ min(bufs.len(), MAX_IOV) as c::c_int,
offset,
- flags.bits(),
))
}
}
-/// At present, `libc` only has `preadv2` defined for glibc. On other
-/// ABIs, use `c::syscall`.
-#[cfg(any(
- target_os = "android",
- all(target_os = "linux", not(target_env = "gnu")),
-))]
-#[inline]
+#[cfg(linux_kernel)]
pub(crate) fn preadv2(
fd: BorrowedFd<'_>,
bufs: &mut [IoSliceMut],
@@ -181,18 +122,17 @@ pub(crate) fn preadv2(
// Silently cast; we'll get `EINVAL` if the value is negative.
let offset = offset as i64;
unsafe {
- syscall_ret_usize(c::syscall(
- c::SYS_preadv2,
+ ret_usize(c::preadv2(
borrowed_fd(fd),
bufs.as_ptr().cast::<c::iovec>(),
- min(bufs.len(), max_iov()) as c::c_int,
+ min(bufs.len(), MAX_IOV) as c::c_int,
offset,
- flags.bits(),
+ bitflags_bits!(flags),
))
}
}
-#[cfg(all(target_os = "linux", target_env = "gnu"))]
+#[cfg(linux_kernel)]
pub(crate) fn pwritev2(
fd: BorrowedFd<'_>,
bufs: &[IoSlice],
@@ -202,39 +142,12 @@ pub(crate) fn pwritev2(
// Silently cast; we'll get `EINVAL` if the value is negative.
let offset = offset as i64;
unsafe {
- ret_usize(libc_pwritev2(
+ ret_usize(c::pwritev2(
borrowed_fd(fd),
bufs.as_ptr().cast::<c::iovec>(),
- min(bufs.len(), max_iov()) as c::c_int,
+ min(bufs.len(), MAX_IOV) as c::c_int,
offset,
- flags.bits(),
- ))
- }
-}
-
-/// At present, `libc` only has `pwritev2` defined for glibc. On other
-/// ABIs, use `c::syscall`.
-#[cfg(any(
- target_os = "android",
- all(target_os = "linux", not(target_env = "gnu")),
-))]
-#[inline]
-pub(crate) fn pwritev2(
- fd: BorrowedFd<'_>,
- bufs: &[IoSlice],
- offset: u64,
- flags: ReadWriteFlags,
-) -> io::Result<usize> {
- // Silently cast; we'll get `EINVAL` if the value is negative.
- let offset = offset as i64;
- unsafe {
- syscall_ret_usize(c::syscall(
- c::SYS_pwritev2,
- borrowed_fd(fd),
- bufs.as_ptr().cast::<c::iovec>(),
- min(bufs.len(), max_iov()) as c::c_int,
- offset,
- flags.bits(),
+ bitflags_bits!(flags),
))
}
}
@@ -255,72 +168,10 @@ const READ_LIMIT: usize = c::c_int::MAX as usize - 1;
#[cfg(not(target_os = "macos"))]
const READ_LIMIT: usize = c::ssize_t::MAX as usize;
-#[cfg(bsd)]
-const fn max_iov() -> usize {
- c::IOV_MAX as usize
-}
-
-#[cfg(any(
- target_os = "android",
- target_os = "emscripten",
- target_os = "linux",
- target_os = "nto"
-))]
-const fn max_iov() -> usize {
- c::UIO_MAXIOV as usize
-}
-
-#[cfg(not(any(
- bsd,
- target_os = "android",
- target_os = "emscripten",
- target_os = "linux",
- target_os = "nto",
- target_os = "horizon",
-)))]
-const fn max_iov() -> usize {
- 16 // The minimum value required by POSIX.
-}
-
pub(crate) unsafe fn close(raw_fd: RawFd) {
let _ = c::close(raw_fd as c::c_int);
}
-#[cfg(any(target_os = "android", target_os = "linux"))]
-pub(crate) fn eventfd(initval: u32, flags: EventfdFlags) -> io::Result<OwnedFd> {
- unsafe { syscall_ret_owned_fd(c::syscall(c::SYS_eventfd2, initval, flags.bits())) }
-}
-
-#[cfg(any(target_os = "freebsd", target_os = "illumos"))]
-pub(crate) fn eventfd(initval: u32, flags: EventfdFlags) -> io::Result<OwnedFd> {
- unsafe { ret_owned_fd(c::eventfd(initval, flags.bits())) }
-}
-
-#[cfg(any(target_os = "android", target_os = "linux"))]
-#[inline]
-pub(crate) fn ioctl_blksszget(fd: BorrowedFd) -> io::Result<u32> {
- let mut result = MaybeUninit::<c::c_uint>::uninit();
- unsafe {
- ret(c::ioctl(borrowed_fd(fd), c::BLKSSZGET, result.as_mut_ptr()))?;
- Ok(result.assume_init() as u32)
- }
-}
-
-#[cfg(any(target_os = "android", target_os = "linux"))]
-#[inline]
-pub(crate) fn ioctl_blkpbszget(fd: BorrowedFd) -> io::Result<u32> {
- let mut result = MaybeUninit::<c::c_uint>::uninit();
- unsafe {
- ret(c::ioctl(
- borrowed_fd(fd),
- c::BLKPBSZGET,
- result.as_mut_ptr(),
- ))?;
- Ok(result.assume_init() as u32)
- }
-}
-
-#[cfg(not(target_os = "redox"))]
pub(crate) fn ioctl_fionread(fd: BorrowedFd<'_>) -> io::Result<u64> {
let mut nread = MaybeUninit::<c::c_int>::uninit();
unsafe {
@@ -339,40 +190,6 @@ pub(crate) fn ioctl_fionbio(fd: BorrowedFd<'_>, value: bool) -> io::Result<()> {
}
}
-#[cfg(any(target_os = "android", target_os = "linux"))]
-pub(crate) fn ioctl_ficlone(fd: BorrowedFd<'_>, src_fd: BorrowedFd<'_>) -> io::Result<()> {
- // TODO: Enable this on mips and power once libc is updated.
- #[cfg(not(any(
- target_arch = "mips",
- target_arch = "mips64",
- target_arch = "powerpc",
- target_arch = "powerpc64",
- target_arch = "sparc",
- target_arch = "sparc64"
- )))]
- unsafe {
- ret(c::ioctl(
- borrowed_fd(fd),
- c::FICLONE as _,
- borrowed_fd(src_fd),
- ))
- }
-
- #[cfg(any(
- target_arch = "mips",
- target_arch = "mips64",
- target_arch = "powerpc",
- target_arch = "powerpc64",
- target_arch = "sparc",
- target_arch = "sparc64"
- ))]
- {
- let _ = fd;
- let _ = src_fd;
- Err(io::Errno::NOSYS)
- }
-}
-
#[cfg(not(any(target_os = "redox", target_os = "wasi")))]
#[cfg(all(feature = "fs", feature = "net"))]
pub(crate) fn is_read_write(fd: BorrowedFd<'_>) -> io::Result<(bool, bool)> {
@@ -410,8 +227,7 @@ pub(crate) fn is_read_write(fd: BorrowedFd<'_>) -> io::Result<(bool, bool)> {
if unsafe { c::send(borrowed_fd(fd), [].as_ptr(), 0, c::MSG_DONTWAIT) } == -1 {
#[allow(unreachable_patterns)] // `EAGAIN` may equal `EWOULDBLOCK`
match errno().0 {
- c::EAGAIN | c::EWOULDBLOCK => (),
- c::ENOTSOCK => (),
+ c::EAGAIN | c::EWOULDBLOCK | c::ENOTSOCK => (),
c::EPIPE => write = false,
err => return Err(io::Errno(err)),
}
@@ -427,7 +243,8 @@ pub(crate) fn is_read_write(_fd: BorrowedFd<'_>) -> io::Result<(bool, bool)> {
}
pub(crate) fn fcntl_getfd(fd: BorrowedFd<'_>) -> io::Result<FdFlags> {
- unsafe { ret_c_int(c::fcntl(borrowed_fd(fd), c::F_GETFD)).map(FdFlags::from_bits_truncate) }
+ let flags = unsafe { ret_c_int(c::fcntl(borrowed_fd(fd), c::F_GETFD))? };
+ Ok(FdFlags::from_bits_retain(bitcast!(flags)))
}
pub(crate) fn fcntl_setfd(fd: BorrowedFd<'_>, flags: FdFlags) -> io::Result<()> {
@@ -463,7 +280,7 @@ pub(crate) fn dup3(fd: BorrowedFd<'_>, new: &mut OwnedFd, flags: DupFlags) -> io
ret_discarded_fd(c::dup3(
borrowed_fd(fd),
borrowed_fd(new.as_fd()),
- flags.bits(),
+ bitflags_bits!(flags),
))
}
}
@@ -493,199 +310,3 @@ pub(crate) fn ioctl_fioclex(fd: BorrowedFd<'_>) -> io::Result<()> {
))
}
}
-
-#[cfg(not(any(target_os = "haiku", target_os = "redox", target_os = "wasi")))]
-pub(crate) fn ioctl_tiocexcl(fd: BorrowedFd) -> io::Result<()> {
- unsafe { ret(c::ioctl(borrowed_fd(fd), c::TIOCEXCL as _)) }
-}
-
-#[cfg(not(any(target_os = "haiku", target_os = "redox", target_os = "wasi")))]
-pub(crate) fn ioctl_tiocnxcl(fd: BorrowedFd) -> io::Result<()> {
- unsafe { ret(c::ioctl(borrowed_fd(fd), c::TIOCNXCL as _)) }
-}
-
-#[cfg(bsd)]
-pub(crate) fn kqueue() -> io::Result<OwnedFd> {
- unsafe { ret_owned_fd(c::kqueue()) }
-}
-
-#[cfg(bsd)]
-pub(crate) unsafe fn kevent(
- kq: BorrowedFd<'_>,
- changelist: &[Event],
- eventlist: &mut [MaybeUninit<Event>],
- timeout: Option<&c::timespec>,
-) -> io::Result<c::c_int> {
- ret_c_int(c::kevent(
- borrowed_fd(kq),
- changelist.as_ptr() as *const _,
- changelist
- .len()
- .try_into()
- .map_err(|_| io::Errno::OVERFLOW)?,
- eventlist.as_mut_ptr() as *mut _,
- eventlist
- .len()
- .try_into()
- .map_err(|_| io::Errno::OVERFLOW)?,
- timeout.map_or(core::ptr::null(), |t| t as *const _),
- ))
-}
-
-#[cfg(not(target_os = "wasi"))]
-pub(crate) fn pipe() -> io::Result<(OwnedFd, OwnedFd)> {
- unsafe {
- let mut result = MaybeUninit::<[OwnedFd; 2]>::uninit();
- ret(c::pipe(result.as_mut_ptr().cast::<i32>()))?;
- let [p0, p1] = result.assume_init();
- Ok((p0, p1))
- }
-}
-
-#[cfg(not(any(apple, target_os = "aix", target_os = "haiku", target_os = "wasi")))]
-pub(crate) fn pipe_with(flags: PipeFlags) -> io::Result<(OwnedFd, OwnedFd)> {
- unsafe {
- let mut result = MaybeUninit::<[OwnedFd; 2]>::uninit();
- ret(c::pipe2(result.as_mut_ptr().cast::<i32>(), flags.bits()))?;
- let [p0, p1] = result.assume_init();
- Ok((p0, p1))
- }
-}
-
-#[inline]
-pub(crate) fn poll(fds: &mut [PollFd<'_>], timeout: c::c_int) -> io::Result<usize> {
- let nfds = fds
- .len()
- .try_into()
- .map_err(|_convert_err| io::Errno::INVAL)?;
-
- ret_c_int(unsafe { c::poll(fds.as_mut_ptr().cast(), nfds, timeout) })
- .map(|nready| nready as usize)
-}
-
-#[cfg(any(target_os = "android", target_os = "linux"))]
-#[inline]
-pub fn splice(
- fd_in: BorrowedFd,
- off_in: Option<&mut u64>,
- fd_out: BorrowedFd,
- off_out: Option<&mut u64>,
- len: usize,
- flags: SpliceFlags,
-) -> io::Result<usize> {
- let off_in = off_in
- .map(|off| (off as *mut u64).cast())
- .unwrap_or(ptr::null_mut());
-
- let off_out = off_out
- .map(|off| (off as *mut u64).cast())
- .unwrap_or(ptr::null_mut());
-
- unsafe {
- ret_usize(c::splice(
- borrowed_fd(fd_in),
- off_in,
- borrowed_fd(fd_out),
- off_out,
- len,
- flags.bits(),
- ))
- }
-}
-
-#[cfg(any(target_os = "android", target_os = "linux"))]
-#[inline]
-pub unsafe fn vmsplice(
- fd: BorrowedFd,
- bufs: &[IoSliceRaw],
- flags: SpliceFlags,
-) -> io::Result<usize> {
- ret_usize(c::vmsplice(
- borrowed_fd(fd),
- bufs.as_ptr().cast::<c::iovec>(),
- min(bufs.len(), max_iov()),
- flags.bits(),
- ))
-}
-
-#[cfg(solarish)]
-pub(crate) fn port_create() -> io::Result<OwnedFd> {
- unsafe { ret_owned_fd(c::port_create()) }
-}
-
-#[cfg(solarish)]
-pub(crate) unsafe fn port_associate(
- port: BorrowedFd<'_>,
- source: c::c_int,
- object: c::uintptr_t,
- events: c::c_int,
- user: *mut c::c_void,
-) -> io::Result<()> {
- ret(c::port_associate(
- borrowed_fd(port),
- source,
- object,
- events,
- user,
- ))
-}
-
-#[cfg(solarish)]
-pub(crate) unsafe fn port_dissociate(
- port: BorrowedFd<'_>,
- source: c::c_int,
- object: c::uintptr_t,
-) -> io::Result<()> {
- ret(c::port_dissociate(borrowed_fd(port), source, object))
-}
-
-#[cfg(solarish)]
-pub(crate) fn port_get(
- port: BorrowedFd<'_>,
- timeout: Option<&mut c::timespec>,
-) -> io::Result<Event> {
- let mut event = MaybeUninit::<c::port_event>::uninit();
- let timeout = timeout.map_or(core::ptr::null_mut(), |t| t as *mut _);
-
- unsafe {
- ret(c::port_get(borrowed_fd(port), event.as_mut_ptr(), timeout))?;
- }
-
- // If we're done, initialize the event and return it.
- Ok(Event(unsafe { event.assume_init() }))
-}
-
-#[cfg(solarish)]
-pub(crate) fn port_getn(
- port: BorrowedFd<'_>,
- timeout: Option<&mut c::timespec>,
- events: &mut Vec<Event>,
- mut nget: u32,
-) -> io::Result<()> {
- let timeout = timeout.map_or(core::ptr::null_mut(), |t| t as *mut _);
- unsafe {
- ret(c::port_getn(
- borrowed_fd(port),
- events.as_mut_ptr().cast(),
- events.len().try_into().unwrap(),
- &mut nget,
- timeout,
- ))?;
- }
-
- // Update the vector length.
- unsafe {
- events.set_len(nget.try_into().unwrap());
- }
-
- Ok(())
-}
-
-#[cfg(solarish)]
-pub(crate) fn port_send(
- port: BorrowedFd<'_>,
- events: c::c_int,
- userdata: *mut c::c_void,
-) -> io::Result<()> {
- unsafe { ret(c::port_send(borrowed_fd(port), events, userdata)) }
-}
diff --git a/vendor/rustix/src/backend/libc/io/types.rs b/vendor/rustix/src/backend/libc/io/types.rs
index 90a5e15b5..8743336f2 100644
--- a/vendor/rustix/src/backend/libc/io/types.rs
+++ b/vendor/rustix/src/backend/libc/io/types.rs
@@ -1,51 +1,38 @@
-use super::super::c;
+use crate::backend::c;
use bitflags::bitflags;
-#[cfg(any(target_os = "android", target_os = "linux"))]
-use core::marker::PhantomData;
bitflags! {
/// `FD_*` constants for use with [`fcntl_getfd`] and [`fcntl_setfd`].
///
/// [`fcntl_getfd`]: crate::io::fcntl_getfd
/// [`fcntl_setfd`]: crate::io::fcntl_setfd
- pub struct FdFlags: c::c_int {
+ #[repr(transparent)]
+ #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
+ pub struct FdFlags: u32 {
/// `FD_CLOEXEC`
- const CLOEXEC = c::FD_CLOEXEC;
+ const CLOEXEC = bitcast!(c::FD_CLOEXEC);
}
}
-#[cfg(any(target_os = "android", target_os = "linux"))]
+#[cfg(linux_kernel)]
bitflags! {
/// `RWF_*` constants for use with [`preadv2`] and [`pwritev2`].
///
/// [`preadv2`]: crate::io::preadv2
/// [`pwritev2`]: crate::io::pwritev
- pub struct ReadWriteFlags: c::c_int {
+ #[repr(transparent)]
+ #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
+ pub struct ReadWriteFlags: u32 {
/// `RWF_DSYNC` (since Linux 4.7)
- const DSYNC = linux_raw_sys::general::RWF_DSYNC as c::c_int;
+ const DSYNC = linux_raw_sys::general::RWF_DSYNC;
/// `RWF_HIPRI` (since Linux 4.6)
- const HIPRI = linux_raw_sys::general::RWF_HIPRI as c::c_int;
+ const HIPRI = linux_raw_sys::general::RWF_HIPRI;
/// `RWF_SYNC` (since Linux 4.7)
- const SYNC = linux_raw_sys::general::RWF_SYNC as c::c_int;
+ const SYNC = linux_raw_sys::general::RWF_SYNC;
/// `RWF_NOWAIT` (since Linux 4.14)
- const NOWAIT = linux_raw_sys::general::RWF_NOWAIT as c::c_int;
+ const NOWAIT = linux_raw_sys::general::RWF_NOWAIT;
/// `RWF_APPEND` (since Linux 4.16)
- const APPEND = linux_raw_sys::general::RWF_APPEND as c::c_int;
- }
-}
-
-#[cfg(any(target_os = "android", target_os = "linux"))]
-bitflags! {
- /// `SPLICE_F_*` constants for use with [`splice`] and [`vmsplice`].
- pub struct SpliceFlags: c::c_uint {
- /// `SPLICE_F_MOVE`
- const MOVE = c::SPLICE_F_MOVE;
- /// `SPLICE_F_NONBLOCK`
- const NONBLOCK = c::SPLICE_F_NONBLOCK;
- /// `SPLICE_F_MORE`
- const MORE = c::SPLICE_F_MORE;
- /// `SPLICE_F_GIFT`
- const GIFT = c::SPLICE_F_GIFT;
+ const APPEND = linux_raw_sys::general::RWF_APPEND;
}
}
@@ -54,7 +41,9 @@ bitflags! {
/// `O_*` constants for use with [`dup2`].
///
/// [`dup2`]: crate::io::dup2
- pub struct DupFlags: c::c_int {
+ #[repr(transparent)]
+ #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
+ pub struct DupFlags: u32 {
/// `O_CLOEXEC`
#[cfg(not(any(
apple,
@@ -62,97 +51,6 @@ bitflags! {
target_os = "android",
target_os = "redox",
)))] // Android 5.0 has dup3, but libc doesn't have bindings
- const CLOEXEC = c::O_CLOEXEC;
- }
-}
-
-#[cfg(not(any(apple, target_os = "wasi")))]
-bitflags! {
- /// `O_*` constants for use with [`pipe_with`].
- ///
- /// [`pipe_with`]: crate::io::pipe_with
- pub struct PipeFlags: c::c_int {
- /// `O_CLOEXEC`
- const CLOEXEC = c::O_CLOEXEC;
- /// `O_DIRECT`
- #[cfg(not(any(
- solarish,
- target_os = "haiku",
- target_os = "openbsd",
- target_os = "redox",
- )))]
- const DIRECT = c::O_DIRECT;
- /// `O_NONBLOCK`
- const NONBLOCK = c::O_NONBLOCK;
- }
-}
-
-#[cfg(any(
- target_os = "android",
- target_os = "freebsd",
- target_os = "illumos",
- target_os = "linux"
-))]
-bitflags! {
- /// `EFD_*` flags for use with [`eventfd`].
- ///
- /// [`eventfd`]: crate::io::eventfd
- pub struct EventfdFlags: c::c_int {
- /// `EFD_CLOEXEC`
- const CLOEXEC = c::EFD_CLOEXEC;
- /// `EFD_NONBLOCK`
- const NONBLOCK = c::EFD_NONBLOCK;
- /// `EFD_SEMAPHORE`
- const SEMAPHORE = c::EFD_SEMAPHORE;
- }
-}
-
-/// `PIPE_BUF`—The maximum size of a write to a pipe guaranteed to be atomic.
-#[cfg(not(any(solarish, target_os = "haiku", target_os = "redox", target_os = "wasi")))]
-pub const PIPE_BUF: usize = c::PIPE_BUF;
-
-#[cfg(not(any(windows, target_os = "redox")))]
-pub(crate) const AT_FDCWD: c::c_int = c::AT_FDCWD;
-#[cfg(not(windows))]
-pub(crate) const STDIN_FILENO: c::c_int = c::STDIN_FILENO;
-#[cfg(not(windows))]
-pub(crate) const STDOUT_FILENO: c::c_int = c::STDOUT_FILENO;
-#[cfg(not(windows))]
-pub(crate) const STDERR_FILENO: c::c_int = c::STDERR_FILENO;
-
-/// A buffer type used with `vmsplice`.
-/// It is guaranteed to be ABI compatible with the iovec type on Unix platforms
-/// and `WSABUF` on Windows. Unlike `IoSlice` and `IoSliceMut` it is
-/// semantically like a raw pointer, and therefore can be shared or mutated as
-/// needed.
-#[cfg(any(target_os = "android", target_os = "linux"))]
-#[repr(transparent)]
-pub struct IoSliceRaw<'a> {
- _buf: c::iovec,
- _lifetime: PhantomData<&'a ()>,
-}
-
-#[cfg(any(target_os = "android", target_os = "linux"))]
-impl<'a> IoSliceRaw<'a> {
- /// Creates a new `IoSlice` wrapping a byte slice.
- pub fn from_slice(buf: &'a [u8]) -> Self {
- IoSliceRaw {
- _buf: c::iovec {
- iov_base: buf.as_ptr() as *mut u8 as *mut c::c_void,
- iov_len: buf.len() as _,
- },
- _lifetime: PhantomData,
- }
- }
-
- /// Creates a new `IoSlice` wrapping a mutable byte slice.
- pub fn from_slice_mut(buf: &'a mut [u8]) -> Self {
- IoSliceRaw {
- _buf: c::iovec {
- iov_base: buf.as_mut_ptr() as *mut c::c_void,
- iov_len: buf.len() as _,
- },
- _lifetime: PhantomData,
- }
+ const CLOEXEC = bitcast!(c::O_CLOEXEC);
}
}
diff --git a/vendor/rustix/src/backend/libc/io/windows_syscalls.rs b/vendor/rustix/src/backend/libc/io/windows_syscalls.rs
index 4c6e86f94..c87a2a247 100644
--- a/vendor/rustix/src/backend/libc/io/windows_syscalls.rs
+++ b/vendor/rustix/src/backend/libc/io/windows_syscalls.rs
@@ -1,12 +1,10 @@
//! Windows system calls in the `io` module.
-use super::super::c;
-use super::super::conv::{borrowed_fd, ret, ret_c_int};
-use super::super::fd::LibcFd;
+use crate::backend::c;
+use crate::backend::conv::{borrowed_fd, ret};
+use crate::backend::fd::LibcFd;
use crate::fd::{BorrowedFd, RawFd};
use crate::io;
-use crate::io::PollFd;
-use core::convert::TryInto;
use core::mem::MaybeUninit;
pub(crate) unsafe fn close(raw_fd: RawFd) {
@@ -27,13 +25,3 @@ pub(crate) fn ioctl_fionbio(fd: BorrowedFd<'_>, value: bool) -> io::Result<()> {
ret(c::ioctl(borrowed_fd(fd), c::FIONBIO, &mut data))
}
}
-
-pub(crate) fn poll(fds: &mut [PollFd<'_>], timeout: c::c_int) -> io::Result<usize> {
- let nfds = fds
- .len()
- .try_into()
- .map_err(|_convert_err| io::Errno::INVAL)?;
-
- ret_c_int(unsafe { c::poll(fds.as_mut_ptr().cast(), nfds, timeout) })
- .map(|nready| nready as usize)
-}