summaryrefslogtreecommitdiffstats
path: root/vendor/rustix/src/ioctl/linux.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-07 05:48:48 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-07 05:48:48 +0000
commitef24de24a82fe681581cc130f342363c47c0969a (patch)
tree0d494f7e1a38b95c92426f58fe6eaa877303a86c /vendor/rustix/src/ioctl/linux.rs
parentReleasing progress-linux version 1.74.1+dfsg1-1~progress7.99u1. (diff)
downloadrustc-ef24de24a82fe681581cc130f342363c47c0969a.tar.xz
rustc-ef24de24a82fe681581cc130f342363c47c0969a.zip
Merging upstream version 1.75.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/rustix/src/ioctl/linux.rs')
-rw-r--r--vendor/rustix/src/ioctl/linux.rs49
1 files changed, 42 insertions, 7 deletions
diff --git a/vendor/rustix/src/ioctl/linux.rs b/vendor/rustix/src/ioctl/linux.rs
index 9dc278656..2f3599fc2 100644
--- a/vendor/rustix/src/ioctl/linux.rs
+++ b/vendor/rustix/src/ioctl/linux.rs
@@ -10,9 +10,9 @@ pub(super) const fn compose_opcode(
num: RawOpcode,
size: RawOpcode,
) -> RawOpcode {
- macro_rules! shift_and_mask {
+ macro_rules! mask_and_shift {
($val:expr, $shift:expr, $mask:expr) => {{
- ($val << $shift) & $mask
+ ($val & $mask) << $shift
}};
}
@@ -23,10 +23,10 @@ pub(super) const fn compose_opcode(
Direction::ReadWrite => READ | WRITE,
};
- shift_and_mask!(group, GROUP_SHIFT, GROUP_MASK)
- | shift_and_mask!(num, NUM_SHIFT, NUM_MASK)
- | shift_and_mask!(size, SIZE_SHIFT, SIZE_MASK)
- | shift_and_mask!(dir, DIR_SHIFT, DIR_MASK)
+ mask_and_shift!(group, GROUP_SHIFT, GROUP_MASK)
+ | mask_and_shift!(num, NUM_SHIFT, NUM_MASK)
+ | mask_and_shift!(size, SIZE_SHIFT, SIZE_MASK)
+ | mask_and_shift!(dir, DIR_SHIFT, DIR_MASK)
}
const NUM_BITS: RawOpcode = 8;
@@ -50,7 +50,8 @@ const DIR_MASK: RawOpcode = (1 << DIR_BITS) - 1;
target_arch = "aarch64",
target_arch = "riscv32",
target_arch = "riscv64",
- target_arch = "loongarch64"
+ target_arch = "loongarch64",
+ target_arch = "csky"
))]
mod consts {
use super::RawOpcode;
@@ -81,3 +82,37 @@ mod consts {
pub(super) const SIZE_BITS: RawOpcode = 13;
pub(super) const DIR_BITS: RawOpcode = 3;
}
+
+#[cfg(not(any(
+ // These have no ioctl opcodes defined in linux_raw_sys
+ // so can't use that as a known-good value for this test.
+ target_arch = "sparc",
+ target_arch = "sparc64"
+)))]
+#[test]
+fn check_known_opcodes() {
+ use crate::backend::c::{c_long, c_uint};
+ use core::mem::size_of;
+
+ // _IOR('U', 15, unsigned int)
+ assert_eq!(
+ compose_opcode(
+ Direction::Read,
+ b'U' as RawOpcode,
+ 15,
+ size_of::<c_uint>() as RawOpcode
+ ),
+ linux_raw_sys::ioctl::USBDEVFS_CLAIMINTERFACE as RawOpcode
+ );
+
+ // _IOW('v', 2, long)
+ assert_eq!(
+ compose_opcode(
+ Direction::Write,
+ b'v' as RawOpcode,
+ 2,
+ size_of::<c_long>() as RawOpcode
+ ),
+ linux_raw_sys::ioctl::FS_IOC_SETVERSION as RawOpcode
+ );
+}