diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-19 09:26:03 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-19 09:26:03 +0000 |
commit | 9918693037dce8aa4bb6f08741b6812923486c18 (patch) | |
tree | 21d2b40bec7e6a7ea664acee056eb3d08e15a1cf /vendor/rustix/src/ioctl | |
parent | Releasing progress-linux version 1.75.0+dfsg1-5~progress7.99u1. (diff) | |
download | rustc-9918693037dce8aa4bb6f08741b6812923486c18.tar.xz rustc-9918693037dce8aa4bb6f08741b6812923486c18.zip |
Merging upstream version 1.76.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/rustix/src/ioctl')
-rw-r--r-- | vendor/rustix/src/ioctl/bsd.rs | 9 | ||||
-rw-r--r-- | vendor/rustix/src/ioctl/mod.rs | 17 | ||||
-rw-r--r-- | vendor/rustix/src/ioctl/patterns.rs | 44 |
3 files changed, 58 insertions, 12 deletions
diff --git a/vendor/rustix/src/ioctl/bsd.rs b/vendor/rustix/src/ioctl/bsd.rs index 66b75b54b..2639d81fc 100644 --- a/vendor/rustix/src/ioctl/bsd.rs +++ b/vendor/rustix/src/ioctl/bsd.rs @@ -1,4 +1,4 @@ -//! `ioctl` opcode behavior for Linux platforms. +//! `ioctl` opcode behavior for BSD platforms. use super::{Direction, RawOpcode}; @@ -18,7 +18,10 @@ pub(super) const fn compose_opcode( dir | num | (group << 8) | ((size & IOCPARAM_MASK) << 16) } +// `IOC_VOID` pub const NONE: RawOpcode = 0x2000_0000; -pub const WRITE: RawOpcode = 0x4000_0000; -pub const READ: RawOpcode = 0x8000_0000; +// `IOC_OUT` ("out" is from the perspective of the kernel) +pub const READ: RawOpcode = 0x4000_0000; +// `IOC_IN` +pub const WRITE: RawOpcode = 0x8000_0000; pub const IOCPARAM_MASK: RawOpcode = 0x1FFF; diff --git a/vendor/rustix/src/ioctl/mod.rs b/vendor/rustix/src/ioctl/mod.rs index ce62d75c4..b56b82b41 100644 --- a/vendor/rustix/src/ioctl/mod.rs +++ b/vendor/rustix/src/ioctl/mod.rs @@ -65,15 +65,14 @@ use bsd as platform; /// `ioctl` call is safe to make. /// /// # References -/// -/// - [Linux] -/// - [WinSock2] -/// - [FreeBSD] -/// - [NetBSD] -/// - [OpenBSD] -/// - [Apple] -/// - [Solaris] -/// - [illumos] +/// - [Linux] +/// - [WinSock2] +/// - [FreeBSD] +/// - [NetBSD] +/// - [OpenBSD] +/// - [Apple] +/// - [Solaris] +/// - [illumos] /// /// [Linux]: https://man7.org/linux/man-pages/man2/ioctl.2.html /// [Winsock2]: https://learn.microsoft.com/en-us/windows/win32/api/winsock/nf-winsock-ioctlsocket diff --git a/vendor/rustix/src/ioctl/patterns.rs b/vendor/rustix/src/ioctl/patterns.rs index 7bc5c4e86..6cf7ebd61 100644 --- a/vendor/rustix/src/ioctl/patterns.rs +++ b/vendor/rustix/src/ioctl/patterns.rs @@ -153,6 +153,50 @@ unsafe impl<Opcode: CompileTimeOpcode, Input> Ioctl for Setter<Opcode, Input> { } } +/// Implements an “updater” pattern for `ioctl`s. +/// +/// The ioctl takes a reference to a struct that it reads its input from, +/// then writes output to the same struct. +pub struct Updater<'a, Opcode, Value> { + /// Reference to input/output data. + value: &'a mut Value, + + /// The opcode. + _opcode: PhantomData<Opcode>, +} + +impl<'a, Opcode: CompileTimeOpcode, Value> Updater<'a, Opcode, Value> { + /// Create a new pointer updater-style `ioctl` object. + /// + /// # Safety + /// + /// - `Opcode` must provide a valid opcode. + /// - For this opcode, `Value` must be the type that the kernel expects to + /// get. + #[inline] + pub unsafe fn new(value: &'a mut Value) -> Self { + Self { + value, + _opcode: PhantomData, + } + } +} + +unsafe impl<'a, Opcode: CompileTimeOpcode, T> Ioctl for Updater<'a, Opcode, T> { + type Output = (); + + const IS_MUTATING: bool = true; + const OPCODE: self::Opcode = Opcode::OPCODE; + + fn as_ptr(&mut self) -> *mut c::c_void { + (self.value as *mut T).cast() + } + + unsafe fn output_from_ptr(_output: IoctlOutput, _ptr: *mut c::c_void) -> Result<()> { + Ok(()) + } +} + /// Trait for something that provides an `ioctl` opcode at compile time. pub trait CompileTimeOpcode { /// The opcode. |