diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-30 18:31:44 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-30 18:31:44 +0000 |
commit | c23a457e72abe608715ac76f076f47dc42af07a5 (patch) | |
tree | 2772049aaf84b5c9d0ed12ec8d86812f7a7904b6 /vendor/rustix/src/backend/libc/io | |
parent | Releasing progress-linux version 1.73.0+dfsg1-1~progress7.99u1. (diff) | |
download | rustc-c23a457e72abe608715ac76f076f47dc42af07a5.tar.xz rustc-c23a457e72abe608715ac76f076f47dc42af07a5.zip |
Merging upstream version 1.74.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/rustix/src/backend/libc/io')
-rw-r--r-- | vendor/rustix/src/backend/libc/io/errno.rs | 28 | ||||
-rw-r--r-- | vendor/rustix/src/backend/libc/io/syscalls.rs | 57 | ||||
-rw-r--r-- | vendor/rustix/src/backend/libc/io/types.rs | 9 | ||||
-rw-r--r-- | vendor/rustix/src/backend/libc/io/windows_syscalls.rs | 29 |
4 files changed, 73 insertions, 50 deletions
diff --git a/vendor/rustix/src/backend/libc/io/errno.rs b/vendor/rustix/src/backend/libc/io/errno.rs index aabd45f8c..1448fe7bd 100644 --- a/vendor/rustix/src/backend/libc/io/errno.rs +++ b/vendor/rustix/src/backend/libc/io/errno.rs @@ -6,10 +6,32 @@ use crate::backend::c; use libc_errno::errno; -/// The error type for `rustix` APIs. +/// `errno`—An error code. /// -/// This is similar to `std::io::Error`, but only holds an OS error code, -/// and no extra error value. +/// The error type for `rustix` APIs. This is similar to [`std::io::Error`], +/// but only holds an OS error code, and no extra error value. +/// +/// # References +/// - [POSIX] +/// - [Linux] +/// - [Winsock2] +/// - [FreeBSD] +/// - [NetBSD] +/// - [OpenBSD] +/// - [DragonFly BSD] +/// - [illumos] +/// - [glibc] +/// +/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/errno.html +/// [Linux]: https://man7.org/linux/man-pages/man3/errno.3.html +/// [Winsock2]: https://learn.microsoft.com/en-us/windows/win32/winsock/windows-sockets-error-codes-2 +/// [FreeBSD]: https://man.freebsd.org/cgi/man.cgi?errno +/// [NetBSD]: https://man.netbsd.org/errno.2 +/// [OpenBSD]: https://man.openbsd.org/errno.2 +/// [DragonFly BSD]: https://man.dragonflybsd.org/?command=errno§ion=2 +/// [illumos]: https://illumos.org/man/3C/errno +/// [glibc]: https://www.gnu.org/software/libc/manual/html_node/Error-Codes.html +/// [`std::io::Error`]: Result #[repr(transparent)] #[doc(alias = "errno")] #[derive(Eq, PartialEq, Hash, Copy, Clone)] diff --git a/vendor/rustix/src/backend/libc/io/syscalls.rs b/vendor/rustix/src/backend/libc/io/syscalls.rs index 362af11ee..19ecfa9b6 100644 --- a/vendor/rustix/src/backend/libc/io/syscalls.rs +++ b/vendor/rustix/src/backend/libc/io/syscalls.rs @@ -15,6 +15,7 @@ use crate::io::DupFlags; #[cfg(linux_kernel)] use crate::io::ReadWriteFlags; use crate::io::{self, FdFlags}; +use crate::ioctl::{IoctlOutput, RawOpcode}; use core::cmp::min; #[cfg(all(feature = "fs", feature = "net"))] use libc_errno::errno; @@ -78,7 +79,7 @@ pub(crate) fn pwrite(fd: BorrowedFd<'_>, buf: &[u8], offset: u64) -> io::Result< } #[cfg(not(target_os = "espidf"))] -pub(crate) fn readv(fd: BorrowedFd<'_>, bufs: &mut [IoSliceMut]) -> io::Result<usize> { +pub(crate) fn readv(fd: BorrowedFd<'_>, bufs: &mut [IoSliceMut<'_>]) -> io::Result<usize> { unsafe { ret_usize(c::readv( borrowed_fd(fd), @@ -89,7 +90,7 @@ pub(crate) fn readv(fd: BorrowedFd<'_>, bufs: &mut [IoSliceMut]) -> io::Result<u } #[cfg(not(target_os = "espidf"))] -pub(crate) fn writev(fd: BorrowedFd<'_>, bufs: &[IoSlice]) -> io::Result<usize> { +pub(crate) fn writev(fd: BorrowedFd<'_>, bufs: &[IoSlice<'_>]) -> io::Result<usize> { unsafe { ret_usize(c::writev( borrowed_fd(fd), @@ -108,7 +109,7 @@ pub(crate) fn writev(fd: BorrowedFd<'_>, bufs: &[IoSlice]) -> io::Result<usize> )))] pub(crate) fn preadv( fd: BorrowedFd<'_>, - bufs: &mut [IoSliceMut], + bufs: &mut [IoSliceMut<'_>], offset: u64, ) -> io::Result<usize> { // Silently cast; we'll get `EINVAL` if the value is negative. @@ -130,7 +131,7 @@ pub(crate) fn preadv( target_os = "redox", target_os = "solaris" )))] -pub(crate) fn pwritev(fd: BorrowedFd<'_>, bufs: &[IoSlice], offset: u64) -> io::Result<usize> { +pub(crate) fn pwritev(fd: BorrowedFd<'_>, bufs: &[IoSlice<'_>], offset: u64) -> io::Result<usize> { // Silently cast; we'll get `EINVAL` if the value is negative. let offset = offset as i64; unsafe { @@ -146,7 +147,7 @@ pub(crate) fn pwritev(fd: BorrowedFd<'_>, bufs: &[IoSlice], offset: u64) -> io:: #[cfg(linux_kernel)] pub(crate) fn preadv2( fd: BorrowedFd<'_>, - bufs: &mut [IoSliceMut], + bufs: &mut [IoSliceMut<'_>], offset: u64, flags: ReadWriteFlags, ) -> io::Result<usize> { @@ -166,7 +167,7 @@ pub(crate) fn preadv2( #[cfg(linux_kernel)] pub(crate) fn pwritev2( fd: BorrowedFd<'_>, - bufs: &[IoSlice], + bufs: &[IoSlice<'_>], offset: u64, flags: ReadWriteFlags, ) -> io::Result<usize> { @@ -203,25 +204,22 @@ pub(crate) unsafe fn close(raw_fd: RawFd) { let _ = c::close(raw_fd as c::c_int); } -#[cfg(not(target_os = "espidf"))] -pub(crate) fn ioctl_fionread(fd: BorrowedFd<'_>) -> io::Result<u64> { - use core::mem::MaybeUninit; - - let mut nread = MaybeUninit::<c::c_int>::uninit(); - unsafe { - ret(c::ioctl(borrowed_fd(fd), c::FIONREAD, nread.as_mut_ptr()))?; - // `FIONREAD` returns the number of bytes silently casted to a `c_int`, - // even when this is lossy. The best we can do is convert it back to a - // `u64` without sign-extending it back first. - Ok(u64::from(nread.assume_init() as c::c_uint)) - } +#[inline] +pub(crate) unsafe fn ioctl( + fd: BorrowedFd<'_>, + request: RawOpcode, + arg: *mut c::c_void, +) -> io::Result<IoctlOutput> { + ret_c_int(c::ioctl(borrowed_fd(fd), request, arg)) } -pub(crate) fn ioctl_fionbio(fd: BorrowedFd<'_>, value: bool) -> io::Result<()> { - unsafe { - let data = value as c::c_int; - ret(c::ioctl(borrowed_fd(fd), c::FIONBIO, &data)) - } +#[inline] +pub(crate) unsafe fn ioctl_readonly( + fd: BorrowedFd<'_>, + request: RawOpcode, + arg: *mut c::c_void, +) -> io::Result<IoctlOutput> { + ioctl(fd, request, arg) } #[cfg(not(any(target_os = "redox", target_os = "wasi")))] @@ -302,11 +300,13 @@ pub(crate) fn dup(fd: BorrowedFd<'_>) -> io::Result<OwnedFd> { unsafe { ret_owned_fd(c::dup(borrowed_fd(fd))) } } +#[allow(clippy::needless_pass_by_ref_mut)] #[cfg(not(target_os = "wasi"))] pub(crate) fn dup2(fd: BorrowedFd<'_>, new: &mut OwnedFd) -> io::Result<()> { unsafe { ret_discarded_fd(c::dup2(borrowed_fd(fd), borrowed_fd(new.as_fd()))) } } +#[allow(clippy::needless_pass_by_ref_mut)] #[cfg(not(any( apple, target_os = "aix", @@ -342,14 +342,3 @@ pub(crate) fn dup3(fd: BorrowedFd<'_>, new: &mut OwnedFd, _flags: DupFlags) -> i // have an `&mut OwnedFd` which means `fd` doesn't alias it. dup2(fd, new) } - -#[cfg(apple)] -pub(crate) fn ioctl_fioclex(fd: BorrowedFd<'_>) -> io::Result<()> { - unsafe { - ret(c::ioctl( - borrowed_fd(fd), - c::FIOCLEX, - core::ptr::null_mut::<u8>(), - )) - } -} diff --git a/vendor/rustix/src/backend/libc/io/types.rs b/vendor/rustix/src/backend/libc/io/types.rs index 8743336f2..eaf3eae71 100644 --- a/vendor/rustix/src/backend/libc/io/types.rs +++ b/vendor/rustix/src/backend/libc/io/types.rs @@ -11,6 +11,9 @@ bitflags! { pub struct FdFlags: u32 { /// `FD_CLOEXEC` const CLOEXEC = bitcast!(c::FD_CLOEXEC); + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } @@ -33,6 +36,9 @@ bitflags! { const NOWAIT = linux_raw_sys::general::RWF_NOWAIT; /// `RWF_APPEND` (since Linux 4.16) const APPEND = linux_raw_sys::general::RWF_APPEND; + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } @@ -52,5 +58,8 @@ bitflags! { target_os = "redox", )))] // Android 5.0 has dup3, but libc doesn't have bindings const CLOEXEC = bitcast!(c::O_CLOEXEC); + + /// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags> + const _ = !0; } } diff --git a/vendor/rustix/src/backend/libc/io/windows_syscalls.rs b/vendor/rustix/src/backend/libc/io/windows_syscalls.rs index c87a2a247..049221d2f 100644 --- a/vendor/rustix/src/backend/libc/io/windows_syscalls.rs +++ b/vendor/rustix/src/backend/libc/io/windows_syscalls.rs @@ -1,27 +1,30 @@ //! Windows system calls in the `io` module. use crate::backend::c; -use crate::backend::conv::{borrowed_fd, ret}; +use crate::backend::conv::{borrowed_fd, ret_c_int}; use crate::backend::fd::LibcFd; use crate::fd::{BorrowedFd, RawFd}; use crate::io; -use core::mem::MaybeUninit; +use crate::ioctl::{IoctlOutput, RawOpcode}; pub(crate) unsafe fn close(raw_fd: RawFd) { let _ = c::close(raw_fd as LibcFd); } -pub(crate) fn ioctl_fionread(fd: BorrowedFd<'_>) -> io::Result<u64> { - let mut nread = MaybeUninit::<c::c_ulong>::uninit(); - unsafe { - ret(c::ioctl(borrowed_fd(fd), c::FIONREAD, nread.as_mut_ptr()))?; - Ok(u64::from(nread.assume_init())) - } +#[inline] +pub(crate) unsafe fn ioctl( + fd: BorrowedFd<'_>, + request: RawOpcode, + arg: *mut c::c_void, +) -> io::Result<IoctlOutput> { + ret_c_int(c::ioctl(borrowed_fd(fd), request, arg.cast())) } -pub(crate) fn ioctl_fionbio(fd: BorrowedFd<'_>, value: bool) -> io::Result<()> { - unsafe { - let mut data = value as c::c_uint; - ret(c::ioctl(borrowed_fd(fd), c::FIONBIO, &mut data)) - } +#[inline] +pub(crate) unsafe fn ioctl_readonly( + fd: BorrowedFd<'_>, + request: RawOpcode, + arg: *mut c::c_void, +) -> io::Result<IoctlOutput> { + ioctl(fd, request, arg) } |