From 37ef021e0333cc24d8474fb5accf858d45f6667a Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Wed, 20 Sep 2023 09:27:50 -0700 Subject: [PATCH] Miscellaneous cleanups (#842) - Update to libc 0.2.148, which has `SO_DOMAIN` for OpenBSD and Solarish. - Enable `Mode` constants on WASI, which now defines them. - Simplify some `cfg`s and `allow`s. --- Cargo.toml | 6 +-- benches/mod.rs | 2 +- src/backend/libc/fs/types.rs | 30 ++++++------ src/backend/libc/net/syscalls.rs | 4 -- src/backend/linux_raw/arch/x86.rs | 1 - src/backend/linux_raw/c.rs | 1 - src/backend/linux_raw/event/syscalls.rs | 3 +- src/backend/linux_raw/io_uring/syscalls.rs | 3 +- src/backend/linux_raw/net/syscalls.rs | 3 +- src/backend/linux_raw/pid/syscalls.rs | 3 +- src/backend/linux_raw/pipe/syscalls.rs | 3 +- src/backend/linux_raw/prctl/syscalls.rs | 3 +- src/backend/linux_raw/process/syscalls.rs | 3 +- src/backend/linux_raw/pty/syscalls.rs | 3 +- src/backend/linux_raw/rand/syscalls.rs | 3 +- src/backend/linux_raw/runtime/syscalls.rs | 3 +- src/backend/linux_raw/system/syscalls.rs | 3 +- src/backend/linux_raw/termios/syscalls.rs | 4 +- src/backend/linux_raw/thread/syscalls.rs | 3 +- src/backend/linux_raw/time/syscalls.rs | 3 +- src/backend/linux_raw/ugid/syscalls.rs | 3 +- src/bitcast.rs | 4 +- src/fs/fd.rs | 2 +- src/ioctl/mod.rs | 53 +++++++++++----------- src/ioctl/patterns.rs | 16 +++---- src/net/sockopt.rs | 5 -- src/process/wait.rs | 10 ++-- tests/io/main.rs | 1 - tests/net/sockopt.rs | 2 - tests/process/wait.rs | 6 +-- 30 files changed, 79 insertions(+), 110 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 9ca0cf7f8..eeab646cf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -38,7 +38,7 @@ once_cell = { version = "1.5.2", optional = true } [target.'cfg(all(not(rustix_use_libc), not(miri), target_os = "linux", target_endian = "little", any(target_arch = "arm", all(target_arch = "aarch64", target_pointer_width = "64"), target_arch = "riscv64", all(rustix_use_experimental_asm, target_arch = "powerpc64"), all(rustix_use_experimental_asm, target_arch = "mips"), all(rustix_use_experimental_asm, target_arch = "mips32r6"), all(rustix_use_experimental_asm, target_arch = "mips64"), all(rustix_use_experimental_asm, target_arch = "mips64r6"), target_arch = "x86", all(target_arch = "x86_64", target_pointer_width = "64"))))'.dependencies] linux-raw-sys = { version = "0.4.7", default-features = false, features = ["general", "errno", "ioctl", "no_std", "elf"] } libc_errno = { package = "errno", version = "0.3.1", default-features = false, optional = true } -libc = { version = "0.2.147", default-features = false, features = ["extra_traits"], optional = true } +libc = { version = "0.2.148", default-features = false, features = ["extra_traits"], optional = true } # Dependencies for platforms where only libc is supported: # @@ -46,7 +46,7 @@ libc = { version = "0.2.147", default-features = false, features = ["extra_trait # backend, so enable its dependencies unconditionally. [target.'cfg(all(not(windows), any(rustix_use_libc, miri, not(all(target_os = "linux", target_endian = "little", any(target_arch = "arm", all(target_arch = "aarch64", target_pointer_width = "64"), target_arch = "riscv64", all(rustix_use_experimental_asm, target_arch = "powerpc64"), all(rustix_use_experimental_asm, target_arch = "mips"), all(rustix_use_experimental_asm, target_arch = "mips32r6"), all(rustix_use_experimental_asm, target_arch = "mips64"), all(rustix_use_experimental_asm, target_arch = "mips64r6"), target_arch = "x86", all(target_arch = "x86_64", target_pointer_width = "64")))))))'.dependencies] libc_errno = { package = "errno", version = "0.3.1", default-features = false } -libc = { version = "0.2.147", default-features = false, features = ["extra_traits"] } +libc = { version = "0.2.148", default-features = false, features = ["extra_traits"] } # Additional dependencies for Linux with the libc backend: # @@ -74,7 +74,7 @@ default-features = false [dev-dependencies] tempfile = "3.5.0" -libc = "0.2.147" +libc = "0.2.148" libc_errno = { package = "errno", version = "0.3.1", default-features = false } serial_test = "2.0.0" memoffset = "0.9.0" diff --git a/benches/mod.rs b/benches/mod.rs index 7818779b0..cd3cb323b 100644 --- a/benches/mod.rs +++ b/benches/mod.rs @@ -125,7 +125,7 @@ mod suite { b.iter(|| { let mut s = std::mem::MaybeUninit::::uninit(); unsafe { - assert_eq!(libc::fstat(libc::STDIN_FILENO, s.as_mut_ptr(),), 0); + assert_eq!(libc::fstat(libc::STDIN_FILENO, s.as_mut_ptr()), 0); } }) }); diff --git a/src/backend/libc/fs/types.rs b/src/backend/libc/fs/types.rs index 034f2bbb9..cf86861dc 100644 --- a/src/backend/libc/fs/types.rs +++ b/src/backend/libc/fs/types.rs @@ -92,63 +92,63 @@ bitflags! { #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] pub struct Mode: RawMode { /// `S_IRWXU` - #[cfg(not(any(target_os = "espidf", target_os = "wasi")))] // WASI doesn't have Unix-style mode flags. + #[cfg(not(target_os = "espidf"))] const RWXU = c::S_IRWXU as RawMode; /// `S_IRUSR` - #[cfg(not(any(target_os = "espidf", target_os = "wasi")))] // WASI doesn't have Unix-style mode flags. + #[cfg(not(target_os = "espidf"))] const RUSR = c::S_IRUSR as RawMode; /// `S_IWUSR` - #[cfg(not(any(target_os = "espidf", target_os = "wasi")))] // WASI doesn't have Unix-style mode flags. + #[cfg(not(target_os = "espidf"))] const WUSR = c::S_IWUSR as RawMode; /// `S_IXUSR` - #[cfg(not(any(target_os = "espidf", target_os = "wasi")))] // WASI doesn't have Unix-style mode flags. + #[cfg(not(target_os = "espidf"))] const XUSR = c::S_IXUSR as RawMode; /// `S_IRWXG` - #[cfg(not(any(target_os = "espidf", target_os = "wasi")))] // WASI doesn't have Unix-style mode flags. + #[cfg(not(target_os = "espidf"))] const RWXG = c::S_IRWXG as RawMode; /// `S_IRGRP` - #[cfg(not(any(target_os = "espidf", target_os = "wasi")))] // WASI doesn't have Unix-style mode flags. + #[cfg(not(target_os = "espidf"))] const RGRP = c::S_IRGRP as RawMode; /// `S_IWGRP` - #[cfg(not(any(target_os = "espidf", target_os = "wasi")))] // WASI doesn't have Unix-style mode flags. + #[cfg(not(target_os = "espidf"))] const WGRP = c::S_IWGRP as RawMode; /// `S_IXGRP` - #[cfg(not(any(target_os = "espidf", target_os = "wasi")))] // WASI doesn't have Unix-style mode flags. + #[cfg(not(target_os = "espidf"))] const XGRP = c::S_IXGRP as RawMode; /// `S_IRWXO` - #[cfg(not(any(target_os = "espidf", target_os = "wasi")))] // WASI doesn't have Unix-style mode flags. + #[cfg(not(target_os = "espidf"))] const RWXO = c::S_IRWXO as RawMode; /// `S_IROTH` - #[cfg(not(any(target_os = "espidf", target_os = "wasi")))] // WASI doesn't have Unix-style mode flags. + #[cfg(not(target_os = "espidf"))] const ROTH = c::S_IROTH as RawMode; /// `S_IWOTH` - #[cfg(not(any(target_os = "espidf", target_os = "wasi")))] // WASI doesn't have Unix-style mode flags. + #[cfg(not(target_os = "espidf"))] const WOTH = c::S_IWOTH as RawMode; /// `S_IXOTH` - #[cfg(not(any(target_os = "espidf", target_os = "wasi")))] // WASI doesn't have Unix-style mode flags. + #[cfg(not(target_os = "espidf"))] const XOTH = c::S_IXOTH as RawMode; /// `S_ISUID` - #[cfg(not(any(target_os = "espidf", target_os = "wasi")))] // WASI doesn't have Unix-style mode flags. + #[cfg(not(target_os = "espidf"))] const SUID = c::S_ISUID as RawMode; /// `S_ISGID` - #[cfg(not(any(target_os = "espidf", target_os = "wasi")))] // WASI doesn't have Unix-style mode flags. + #[cfg(not(target_os = "espidf"))] const SGID = c::S_ISGID as RawMode; /// `S_ISVTX` - #[cfg(not(any(target_os = "espidf", target_os = "wasi")))] // WASI doesn't have Unix-style mode flags. + #[cfg(not(target_os = "espidf"))] const SVTX = c::S_ISVTX as RawMode; /// diff --git a/src/backend/libc/net/syscalls.rs b/src/backend/libc/net/syscalls.rs index 20a3bb16e..2e968ba3e 100644 --- a/src/backend/libc/net/syscalls.rs +++ b/src/backend/libc/net/syscalls.rs @@ -523,7 +523,6 @@ pub(crate) mod sockopt { use crate::net::sockopt::Timeout; #[cfg(not(any( apple, - solarish, windows, target_os = "aix", target_os = "dragonfly", @@ -532,7 +531,6 @@ pub(crate) mod sockopt { target_os = "haiku", target_os = "netbsd", target_os = "nto", - target_os = "openbsd" )))] use crate::net::AddressFamily; use crate::net::{Ipv4Addr, Ipv6Addr, SocketType}; @@ -835,7 +833,6 @@ pub(crate) mod sockopt { #[inline] #[cfg(not(any( apple, - solarish, windows, target_os = "aix", target_os = "dragonfly", @@ -844,7 +841,6 @@ pub(crate) mod sockopt { target_os = "haiku", target_os = "netbsd", target_os = "nto", - target_os = "openbsd" )))] pub(crate) fn get_socket_domain(fd: BorrowedFd<'_>) -> io::Result { let domain: c::c_int = getsockopt(fd, c::SOL_SOCKET as _, c::SO_DOMAIN)?; diff --git a/src/backend/linux_raw/arch/x86.rs b/src/backend/linux_raw/arch/x86.rs index 043a54997..581cde278 100644 --- a/src/backend/linux_raw/arch/x86.rs +++ b/src/backend/linux_raw/arch/x86.rs @@ -163,7 +163,6 @@ pub(in crate::backend) unsafe fn indirect_syscall5( FromAsm::from_asm(r0) } -#[allow(clippy::too_many_arguments)] #[inline] pub(in crate::backend) unsafe fn indirect_syscall6( callee: SyscallType, diff --git a/src/backend/linux_raw/c.rs b/src/backend/linux_raw/c.rs index 1219a757a..65ddb1466 100644 --- a/src/backend/linux_raw/c.rs +++ b/src/backend/linux_raw/c.rs @@ -40,7 +40,6 @@ pub(crate) use linux_raw_sys::general::{ XATTR_REPLACE, }; -#[allow(unused)] pub(crate) use linux_raw_sys::ioctl::{BLKPBSZGET, BLKSSZGET, FICLONE}; #[cfg(feature = "io_uring")] diff --git a/src/backend/linux_raw/event/syscalls.rs b/src/backend/linux_raw/event/syscalls.rs index f25ca1132..a8003b004 100644 --- a/src/backend/linux_raw/event/syscalls.rs +++ b/src/backend/linux_raw/event/syscalls.rs @@ -3,8 +3,7 @@ //! # Safety //! //! See the `rustix::backend` module documentation for details. -#![allow(unsafe_code)] -#![allow(clippy::undocumented_unsafe_blocks)] +#![allow(unsafe_code, clippy::undocumented_unsafe_blocks)] use crate::backend::c; use crate::backend::conv::{c_int, c_uint, ret_owned_fd, ret_usize, slice_mut}; diff --git a/src/backend/linux_raw/io_uring/syscalls.rs b/src/backend/linux_raw/io_uring/syscalls.rs index 90c82c129..d10cd1395 100644 --- a/src/backend/linux_raw/io_uring/syscalls.rs +++ b/src/backend/linux_raw/io_uring/syscalls.rs @@ -3,8 +3,7 @@ //! # Safety //! //! See the `rustix::backend::syscalls` module documentation for details. -#![allow(unsafe_code)] -#![allow(clippy::undocumented_unsafe_blocks)] +#![allow(unsafe_code, clippy::undocumented_unsafe_blocks)] use crate::backend::conv::{by_mut, c_uint, pass_usize, ret_c_uint, ret_owned_fd}; use crate::fd::{BorrowedFd, OwnedFd}; diff --git a/src/backend/linux_raw/net/syscalls.rs b/src/backend/linux_raw/net/syscalls.rs index b0e155205..e5ebcc1dd 100644 --- a/src/backend/linux_raw/net/syscalls.rs +++ b/src/backend/linux_raw/net/syscalls.rs @@ -3,8 +3,7 @@ //! # Safety //! //! See the `rustix::backend` module documentation for details. -#![allow(unsafe_code)] -#![allow(clippy::undocumented_unsafe_blocks)] +#![allow(unsafe_code, clippy::undocumented_unsafe_blocks)] use super::msghdr::{ with_noaddr_msghdr, with_recv_msghdr, with_unix_msghdr, with_v4_msghdr, with_v6_msghdr, diff --git a/src/backend/linux_raw/pid/syscalls.rs b/src/backend/linux_raw/pid/syscalls.rs index f36bac048..9665ab3e9 100644 --- a/src/backend/linux_raw/pid/syscalls.rs +++ b/src/backend/linux_raw/pid/syscalls.rs @@ -3,8 +3,7 @@ //! # Safety //! //! See the `rustix::backend` module documentation for details. -#![allow(unsafe_code)] -#![allow(clippy::undocumented_unsafe_blocks)] +#![allow(unsafe_code, clippy::undocumented_unsafe_blocks)] use crate::backend::conv::ret_usize_infallible; use crate::pid::{Pid, RawPid}; diff --git a/src/backend/linux_raw/pipe/syscalls.rs b/src/backend/linux_raw/pipe/syscalls.rs index f0dc65233..ec3e459be 100644 --- a/src/backend/linux_raw/pipe/syscalls.rs +++ b/src/backend/linux_raw/pipe/syscalls.rs @@ -3,8 +3,7 @@ //! # Safety //! //! See the `rustix::backend` module documentation for details. -#![allow(unsafe_code)] -#![allow(clippy::undocumented_unsafe_blocks)] +#![allow(unsafe_code, clippy::undocumented_unsafe_blocks)] use crate::backend::conv::{c_int, c_uint, opt_mut, pass_usize, ret, ret_usize, slice}; use crate::backend::{c, MAX_IOV}; diff --git a/src/backend/linux_raw/prctl/syscalls.rs b/src/backend/linux_raw/prctl/syscalls.rs index 193f4b7b4..1410d5128 100644 --- a/src/backend/linux_raw/prctl/syscalls.rs +++ b/src/backend/linux_raw/prctl/syscalls.rs @@ -3,8 +3,7 @@ //! # Safety //! //! See the `rustix::backend` module documentation for details. -#![allow(unsafe_code)] -#![allow(clippy::undocumented_unsafe_blocks)] +#![allow(unsafe_code, clippy::undocumented_unsafe_blocks)] use crate::backend::c; use crate::backend::conv::{c_int, ret_c_int}; diff --git a/src/backend/linux_raw/process/syscalls.rs b/src/backend/linux_raw/process/syscalls.rs index d08c6b15d..c0416bf5a 100644 --- a/src/backend/linux_raw/process/syscalls.rs +++ b/src/backend/linux_raw/process/syscalls.rs @@ -3,8 +3,7 @@ //! # Safety //! //! See the `rustix::backend` module documentation for details. -#![allow(unsafe_code)] -#![allow(clippy::undocumented_unsafe_blocks)] +#![allow(unsafe_code, clippy::undocumented_unsafe_blocks)] use super::types::RawCpuSet; use crate::backend::c; diff --git a/src/backend/linux_raw/pty/syscalls.rs b/src/backend/linux_raw/pty/syscalls.rs index 7fd24b068..b64344fb9 100644 --- a/src/backend/linux_raw/pty/syscalls.rs +++ b/src/backend/linux_raw/pty/syscalls.rs @@ -3,8 +3,7 @@ //! # Safety //! //! See the `rustix::backend` module documentation for details. -#![allow(unsafe_code)] -#![allow(clippy::undocumented_unsafe_blocks)] +#![allow(unsafe_code, clippy::undocumented_unsafe_blocks)] use crate::backend::conv::{by_ref, c_uint, ret}; use crate::fd::BorrowedFd; diff --git a/src/backend/linux_raw/rand/syscalls.rs b/src/backend/linux_raw/rand/syscalls.rs index 95a6efcff..e744f3193 100644 --- a/src/backend/linux_raw/rand/syscalls.rs +++ b/src/backend/linux_raw/rand/syscalls.rs @@ -3,8 +3,7 @@ //! # Safety //! //! See the `rustix::backend` module documentation for details. -#![allow(unsafe_code)] -#![allow(clippy::undocumented_unsafe_blocks)] +#![allow(unsafe_code, clippy::undocumented_unsafe_blocks)] use crate::backend::conv::{ret_usize, slice_mut}; use crate::io; diff --git a/src/backend/linux_raw/runtime/syscalls.rs b/src/backend/linux_raw/runtime/syscalls.rs index 06cdb1ad2..c1ff3d239 100644 --- a/src/backend/linux_raw/runtime/syscalls.rs +++ b/src/backend/linux_raw/runtime/syscalls.rs @@ -3,8 +3,7 @@ //! # Safety //! //! See the `rustix::backend` module documentation for details. -#![allow(unsafe_code)] -#![allow(clippy::undocumented_unsafe_blocks)] +#![allow(unsafe_code, clippy::undocumented_unsafe_blocks)] use crate::backend::c; #[cfg(target_arch = "x86")] diff --git a/src/backend/linux_raw/system/syscalls.rs b/src/backend/linux_raw/system/syscalls.rs index 514751d6f..947d5168e 100644 --- a/src/backend/linux_raw/system/syscalls.rs +++ b/src/backend/linux_raw/system/syscalls.rs @@ -3,8 +3,7 @@ //! # Safety //! //! See the `rustix::backend` module documentation for details. -#![allow(unsafe_code)] -#![allow(clippy::undocumented_unsafe_blocks)] +#![allow(unsafe_code, clippy::undocumented_unsafe_blocks)] use super::types::RawUname; use crate::backend::conv::{ret, ret_infallible, slice}; diff --git a/src/backend/linux_raw/termios/syscalls.rs b/src/backend/linux_raw/termios/syscalls.rs index 0bd77db3d..09100441f 100644 --- a/src/backend/linux_raw/termios/syscalls.rs +++ b/src/backend/linux_raw/termios/syscalls.rs @@ -3,8 +3,7 @@ //! # Safety //! //! See the `rustix::backend` module documentation for details. -#![allow(unsafe_code)] -#![allow(clippy::undocumented_unsafe_blocks)] +#![allow(unsafe_code, clippy::undocumented_unsafe_blocks)] use crate::backend::c; use crate::backend::conv::{by_ref, c_uint, ret}; @@ -230,7 +229,6 @@ pub(crate) fn isatty(fd: BorrowedFd<'_>) -> bool { } #[cfg(all(feature = "alloc", feature = "procfs"))] -#[allow(unsafe_code)] pub(crate) fn ttyname(fd: BorrowedFd<'_>, buf: &mut [MaybeUninit]) -> io::Result { let fd_stat = crate::backend::fs::syscalls::fstat(fd)?; diff --git a/src/backend/linux_raw/thread/syscalls.rs b/src/backend/linux_raw/thread/syscalls.rs index e3f24fabf..0095eed79 100644 --- a/src/backend/linux_raw/thread/syscalls.rs +++ b/src/backend/linux_raw/thread/syscalls.rs @@ -3,8 +3,7 @@ //! # Safety //! //! See the `rustix::backend` module documentation for details. -#![allow(unsafe_code)] -#![allow(clippy::undocumented_unsafe_blocks)] +#![allow(unsafe_code, clippy::undocumented_unsafe_blocks)] use crate::backend::c; use crate::backend::conv::{ diff --git a/src/backend/linux_raw/time/syscalls.rs b/src/backend/linux_raw/time/syscalls.rs index 634ce2674..27c3652a4 100644 --- a/src/backend/linux_raw/time/syscalls.rs +++ b/src/backend/linux_raw/time/syscalls.rs @@ -3,8 +3,7 @@ //! # Safety //! //! See the `rustix::backend` module documentation for details. -#![allow(unsafe_code)] -#![allow(clippy::undocumented_unsafe_blocks)] +#![allow(unsafe_code, clippy::undocumented_unsafe_blocks)] use crate::backend::conv::{ret, ret_infallible}; use crate::clockid::ClockId; diff --git a/src/backend/linux_raw/ugid/syscalls.rs b/src/backend/linux_raw/ugid/syscalls.rs index 12ff6dce1..5f1551e7c 100644 --- a/src/backend/linux_raw/ugid/syscalls.rs +++ b/src/backend/linux_raw/ugid/syscalls.rs @@ -3,8 +3,7 @@ //! # Safety //! //! See the `rustix::backend` module documentation for details. -#![allow(unsafe_code)] -#![allow(clippy::undocumented_unsafe_blocks)] +#![allow(unsafe_code, clippy::undocumented_unsafe_blocks)] use crate::backend::c; use crate::backend::conv::ret_usize_infallible; diff --git a/src/bitcast.rs b/src/bitcast.rs index 3924c29d5..735101766 100644 --- a/src/bitcast.rs +++ b/src/bitcast.rs @@ -1,6 +1,7 @@ +#![allow(unused_macros)] + // Ensure that the source and destination types are both primitive integer // types and the same size, and then bitcast. -#[allow(unused_macros)] macro_rules! bitcast { ($x:expr) => {{ if false { @@ -24,7 +25,6 @@ macro_rules! bitcast { /// Return a [`bitcast`] of the value of `$x.bits()`, where `$x` is a /// `bitflags` type. -#[allow(unused_macros)] macro_rules! bitflags_bits { ($x:expr) => {{ bitcast!($x.bits()) diff --git a/src/fs/fd.rs b/src/fs/fd.rs index de49c97f8..94de43daa 100644 --- a/src/fs/fd.rs +++ b/src/fs/fd.rs @@ -256,7 +256,7 @@ pub(crate) fn _is_file_read_write(fd: BorrowedFd<'_>) -> io::Result<(bool, bool) let mode = backend::fs::syscalls::fcntl_getfl(fd)?; // Check for `O_PATH`. - #[cfg(any(linux_kernel, target_os = "fuchsia", target_os = "emscripten"))] + #[cfg(any(linux_kernel, target_os = "emscripten", target_os = "fuchsia"))] if mode.contains(OFlags::PATH) { return Ok((false, false)); } diff --git a/src/ioctl/mod.rs b/src/ioctl/mod.rs index e5a3b6337..bf2215ab6 100644 --- a/src/ioctl/mod.rs +++ b/src/ioctl/mod.rs @@ -18,7 +18,7 @@ use crate::backend::c; use crate::fd::{AsFd, BorrowedFd}; use crate::io::Result; -#[cfg(any(linux_kernel, apple, bsd))] +#[cfg(any(linux_kernel, bsd))] use core::mem; pub use patterns::*; @@ -28,13 +28,13 @@ mod patterns; #[cfg(linux_kernel)] mod linux; -#[cfg(any(apple, bsd))] +#[cfg(bsd)] mod bsd; #[cfg(linux_kernel)] use linux as platform; -#[cfg(any(apple, bsd))] +#[cfg(bsd)] use bsd as platform; /// Perform an `ioctl` call. @@ -120,8 +120,8 @@ unsafe fn _ioctl_readonly( /// Objects implementing this trait can be passed to [`ioctl`] to make an /// `ioctl` call. The contents of the object represent the inputs to the /// `ioctl` call. The inputs must be convertible to a pointer through the -/// `as_ptr` method. In most cases, this involves either casting a number to -/// a pointer, or creating a pointer to the actual data. The latter case is +/// `as_ptr` method. In most cases, this involves either casting a number to a +/// pointer, or creating a pointer to the actual data. The latter case is /// necessary for `ioctl` calls that modify userspace data. /// /// # Safety @@ -163,8 +163,8 @@ pub unsafe trait Ioctl { /// # Safety /// /// This should only be set to `false` if the `ioctl` call does not mutate - /// any data in the userspace. Undefined behavior may occur if this is - /// set to `false` when it should be `true`. + /// any data in the userspace. Undefined behavior may occur if this is set + /// to `false` when it should be `true`. const IS_MUTATING: bool; /// Get a pointer to the data to be passed to the `ioctl` command. @@ -178,8 +178,8 @@ pub unsafe trait Ioctl { /// /// The `extract_output` value must be the resulting value after a /// successful `ioctl` call, and `out` is the direct return value of an - /// `ioctl` call that did not fail. In this case `extract_output` is - /// the pointer that was passed to the `ioctl` call. + /// `ioctl` call that did not fail. In this case `extract_output` is the + /// pointer that was passed to the `ioctl` call. unsafe fn output_from_ptr( out: IoctlOutput, extract_output: *mut c::c_void, @@ -197,15 +197,15 @@ impl Opcode { /// Create a new old `Opcode` from a raw opcode. /// /// Rather than being a composition of several attributes, old opcodes are - /// just numbers. In general most drivers follow stricter conventions, - /// but older drivers may still use this strategy. + /// just numbers. In general most drivers follow stricter conventions, but + /// older drivers may still use this strategy. #[inline] pub const fn old(raw: RawOpcode) -> Self { Self { raw } } /// Create a new opcode from a direction, group, number and size. - #[cfg(any(linux_kernel, apple, bsd))] + #[cfg(any(linux_kernel, bsd))] #[inline] pub const fn from_components( direction: Direction, @@ -227,7 +227,7 @@ impl Opcode { /// Create a new non-mutating opcode from a group, a number and the type of /// data. - #[cfg(any(linux_kernel, apple, bsd))] + #[cfg(any(linux_kernel, bsd))] #[inline] pub const fn none(group: u8, number: u8) -> Self { Self::from_components(Direction::None, group, number, mem::size_of::()) @@ -235,7 +235,7 @@ impl Opcode { /// Create a new reading opcode from a group, a number and the type of /// data. - #[cfg(any(linux_kernel, apple, bsd))] + #[cfg(any(linux_kernel, bsd))] #[inline] pub const fn read(group: u8, number: u8) -> Self { Self::from_components(Direction::Read, group, number, mem::size_of::()) @@ -243,7 +243,7 @@ impl Opcode { /// Create a new writing opcode from a group, a number and the type of /// data. - #[cfg(any(linux_kernel, apple, bsd))] + #[cfg(any(linux_kernel, bsd))] #[inline] pub const fn write(group: u8, number: u8) -> Self { Self::from_components(Direction::Write, group, number, mem::size_of::()) @@ -251,7 +251,7 @@ impl Opcode { /// Create a new reading and writing opcode from a group, a number and the /// type of data. - #[cfg(any(linux_kernel, apple, bsd))] + #[cfg(any(linux_kernel, bsd))] #[inline] pub const fn read_write(group: u8, number: u8) -> Self { Self::from_components(Direction::ReadWrite, group, number, mem::size_of::()) @@ -289,11 +289,11 @@ pub type IoctlOutput = c::c_int; /// The type used by the `ioctl` to signify the command. pub type RawOpcode = _RawOpcode; -// Under raw Linux, this is an unsigned int. +// Under raw Linux, this is an `unsigned int`. #[cfg(linux_raw)] type _RawOpcode = c::c_uint; -// On libc Linux with GNU libc or uclibc, this is an unsigned long. +// On libc Linux with GNU libc or uclibc, this is an `unsigned long`. #[cfg(all( not(linux_raw), target_os = "linux", @@ -301,7 +301,7 @@ type _RawOpcode = c::c_uint; ))] type _RawOpcode = c::c_ulong; -// Musl uses a c_int +// Musl uses `c_int`. #[cfg(all( not(linux_raw), target_os = "linux", @@ -310,19 +310,18 @@ type _RawOpcode = c::c_ulong; ))] type _RawOpcode = c::c_int; -// Android uses c_int +// Android uses `c_int`. #[cfg(all(not(linux_raw), target_os = "android"))] type _RawOpcode = c::c_int; -// Every BSD I looked at, Haiku and Redox uses an unsigned long. -#[cfg(any(apple, bsd, target_os = "redox", target_os = "haiku"))] +// BSD, Haiku, and Redox use `unsigned long`. +#[cfg(any(bsd, target_os = "redox", target_os = "haiku"))] type _RawOpcode = c::c_ulong; -// AIX, Solaris, Fuchsia, Emscripten and WASI use an int +// AIX, Emscripten, Fuchsia, Solaris, and WASI use a `int`. #[cfg(any( + solarish, target_os = "aix", - target_os = "solaris", - target_os = "illumos", target_os = "fuchsia", target_os = "emscripten", target_os = "wasi", @@ -330,10 +329,10 @@ type _RawOpcode = c::c_ulong; ))] type _RawOpcode = c::c_int; -// ESP-IDF uses a c_uint +// ESP-IDF uses a `c_uint`. #[cfg(target_os = "espidf")] type _RawOpcode = c::c_uint; -// Windows has ioctlsocket, which uses i32 +// Windows has `ioctlsocket`, which uses `i32`. #[cfg(windows)] type _RawOpcode = i32; diff --git a/src/ioctl/patterns.rs b/src/ioctl/patterns.rs index 39eb51706..4b33d7d80 100644 --- a/src/ioctl/patterns.rs +++ b/src/ioctl/patterns.rs @@ -166,37 +166,37 @@ impl CompileTimeOpcode for BadOpcode { } /// Provides a read code at compile time. -#[cfg(any(linux_kernel, apple, bsd))] +#[cfg(any(linux_kernel, bsd))] pub struct ReadOpcode(Data); -#[cfg(any(linux_kernel, apple, bsd))] +#[cfg(any(linux_kernel, bsd))] impl CompileTimeOpcode for ReadOpcode { const OPCODE: Opcode = Opcode::read::(GROUP, NUM); } /// Provides a write code at compile time. -#[cfg(any(linux_kernel, apple, bsd))] +#[cfg(any(linux_kernel, bsd))] pub struct WriteOpcode(Data); -#[cfg(any(linux_kernel, apple, bsd))] +#[cfg(any(linux_kernel, bsd))] impl CompileTimeOpcode for WriteOpcode { const OPCODE: Opcode = Opcode::write::(GROUP, NUM); } /// Provides a read/write code at compile time. -#[cfg(any(linux_kernel, apple, bsd))] +#[cfg(any(linux_kernel, bsd))] pub struct ReadWriteOpcode(Data); -#[cfg(any(linux_kernel, apple, bsd))] +#[cfg(any(linux_kernel, bsd))] impl CompileTimeOpcode for ReadWriteOpcode { const OPCODE: Opcode = Opcode::read_write::(GROUP, NUM); } /// Provides a `None` code at compile time. -#[cfg(any(linux_kernel, apple, bsd))] +#[cfg(any(linux_kernel, bsd))] pub struct NoneOpcode(Data); -#[cfg(any(linux_kernel, apple, bsd))] +#[cfg(any(linux_kernel, bsd))] impl CompileTimeOpcode for NoneOpcode { const OPCODE: Opcode = Opcode::none::(GROUP, NUM); } diff --git a/src/net/sockopt.rs b/src/net/sockopt.rs index 650e2d475..1939155d9 100644 --- a/src/net/sockopt.rs +++ b/src/net/sockopt.rs @@ -8,7 +8,6 @@ #[cfg(not(any( apple, - solarish, windows, target_os = "aix", target_os = "dragonfly", @@ -17,7 +16,6 @@ target_os = "haiku", target_os = "netbsd", target_os = "nto", - target_os = "openbsd" )))] use crate::net::AddressFamily; use crate::net::{Ipv4Addr, Ipv6Addr, SocketType}; @@ -796,10 +794,8 @@ pub fn get_socket_send_buffer_size(fd: Fd) -> io::Result { /// [illumos]: https://illumos.org/man/3SOCKET/getsockopt /// [glibc `getsockopt`]: https://www.gnu.org/software/libc/manual/html_node/Socket-Option-Functions.html /// [glibc `SOL_SOCKET` options]: https://www.gnu.org/software/libc/manual/html_node/Socket_002dLevel-Options.html -// TODO: OpenBSD and Solarish support submitted upstream: https://github.com/rust-lang/libc/pull/3316 #[cfg(not(any( apple, - solarish, windows, target_os = "aix", target_os = "dragonfly", @@ -808,7 +804,6 @@ pub fn get_socket_send_buffer_size(fd: Fd) -> io::Result { target_os = "haiku", target_os = "netbsd", target_os = "nto", - target_os = "openbsd" )))] #[inline] #[doc(alias = "SO_DOMAIN")] diff --git a/src/process/wait.rs b/src/process/wait.rs index c4bacd7dd..b43bd03d6 100644 --- a/src/process/wait.rs +++ b/src/process/wait.rs @@ -176,7 +176,7 @@ impl WaitidStatus { /// Returns the number of the signal that stopped the process, /// if the process was stopped by a signal. #[inline] - #[cfg(not(any(target_os = "netbsd", target_os = "fuchsia", target_os = "emscripten")))] + #[cfg(not(any(target_os = "emscripten", target_os = "fuchsia", target_os = "netbsd")))] pub fn stopping_signal(&self) -> Option { if self.stopped() { Some(self.si_status() as _) @@ -188,7 +188,7 @@ impl WaitidStatus { /// Returns the number of the signal that trapped the process, /// if the process was trapped by a signal. #[inline] - #[cfg(not(any(target_os = "netbsd", target_os = "fuchsia", target_os = "emscripten")))] + #[cfg(not(any(target_os = "emscripten", target_os = "fuchsia", target_os = "netbsd")))] pub fn trapping_signal(&self) -> Option { if self.trapped() { Some(self.si_status() as _) @@ -200,7 +200,7 @@ impl WaitidStatus { /// Returns the exit status number returned by the process, /// if it exited normally. #[inline] - #[cfg(not(any(target_os = "netbsd", target_os = "fuchsia", target_os = "emscripten")))] + #[cfg(not(any(target_os = "emscripten", target_os = "fuchsia", target_os = "netbsd")))] pub fn exit_status(&self) -> Option { if self.exited() { Some(self.si_status() as _) @@ -212,7 +212,7 @@ impl WaitidStatus { /// Returns the number of the signal that terminated the process, /// if the process was terminated by a signal. #[inline] - #[cfg(not(any(target_os = "netbsd", target_os = "fuchsia", target_os = "emscripten")))] + #[cfg(not(any(target_os = "emscripten", target_os = "fuchsia", target_os = "netbsd")))] pub fn terminating_signal(&self) -> Option { if self.killed() || self.dumped() { Some(self.si_status() as _) @@ -237,7 +237,7 @@ impl WaitidStatus { self.0.si_code } - #[cfg(not(any(target_os = "netbsd", target_os = "fuchsia", target_os = "emscripten")))] + #[cfg(not(any(target_os = "emscripten", target_os = "fuchsia", target_os = "netbsd")))] #[allow(unsafe_code)] fn si_status(&self) -> backend::c::c_int { // SAFETY: POSIX [specifies] that the `siginfo_t` returned by a diff --git a/tests/io/main.rs b/tests/io/main.rs index a654bbb4e..3fbb55e88 100644 --- a/tests/io/main.rs +++ b/tests/io/main.rs @@ -10,5 +10,4 @@ mod from_into; mod ioctl; #[cfg(not(windows))] #[cfg(not(target_os = "redox"))] // redox doesn't have cwd/openat -#[cfg(not(target_os = "wasi"))] // wasi support for `S_IRUSR` etc. submitted to libc in #2264 mod read_write; diff --git a/tests/net/sockopt.rs b/tests/net/sockopt.rs index cf58af301..996e667c0 100644 --- a/tests/net/sockopt.rs +++ b/tests/net/sockopt.rs @@ -51,7 +51,6 @@ fn test_sockopts_ipv4() { ); #[cfg(not(any( apple, - solarish, windows, target_os = "dragonfly", target_os = "emscripten", @@ -59,7 +58,6 @@ fn test_sockopts_ipv4() { target_os = "haiku", target_os = "netbsd", target_os = "nto", - target_os = "openbsd" )))] assert_eq!( rustix::net::sockopt::get_socket_domain(&s).unwrap(), diff --git a/tests/process/wait.rs b/tests/process/wait.rs index 3846d56ce..1cd2a62f1 100644 --- a/tests/process/wait.rs +++ b/tests/process/wait.rs @@ -47,7 +47,7 @@ fn test_waitid() { .unwrap(); assert!(status.stopped()); - #[cfg(not(any(target_os = "netbsd", target_os = "fuchsia")))] + #[cfg(not(any(target_os = "fuchsia", target_os = "netbsd")))] assert_eq!(status.stopping_signal(), Some(SIGSTOP as _)); unsafe { kill(child.id() as _, SIGCONT) }; @@ -76,7 +76,7 @@ fn test_waitid() { .unwrap(); assert!(status.killed()); - #[cfg(not(any(target_os = "netbsd", target_os = "fuchsia")))] + #[cfg(not(any(target_os = "fuchsia", target_os = "netbsd")))] assert_eq!(status.terminating_signal(), Some(SIGKILL as _)); let status = process::waitid(process::WaitId::Pid(pid), process::WaitidOptions::EXITED) @@ -84,6 +84,6 @@ fn test_waitid() { .unwrap(); assert!(status.killed()); - #[cfg(not(any(target_os = "netbsd", target_os = "fuchsia")))] + #[cfg(not(any(target_os = "fuchsia", target_os = "netbsd")))] assert_eq!(status.terminating_signal(), Some(SIGKILL as _)); }