summaryrefslogtreecommitdiffstats
path: root/third_party/rust/ioctl-sys
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
commit43a97878ce14b72f0981164f87f2e35e14151312 (patch)
tree620249daf56c0258faa40cbdcf9cfba06de2a846 /third_party/rust/ioctl-sys
parentInitial commit. (diff)
downloadfirefox-43a97878ce14b72f0981164f87f2e35e14151312.tar.xz
firefox-43a97878ce14b72f0981164f87f2e35e14151312.zip
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/rust/ioctl-sys')
-rw-r--r--third_party/rust/ioctl-sys/.cargo-checksum.json1
-rw-r--r--third_party/rust/ioctl-sys/Cargo.lock5
-rw-r--r--third_party/rust/ioctl-sys/Cargo.toml23
-rw-r--r--third_party/rust/ioctl-sys/examples/smoke.rs23
-rw-r--r--third_party/rust/ioctl-sys/src/lib.rs37
-rw-r--r--third_party/rust/ioctl-sys/src/platform/linux.rs59
-rw-r--r--third_party/rust/ioctl-sys/src/platform/macos.rs19
-rw-r--r--third_party/rust/ioctl-sys/src/platform/mod.rs263
8 files changed, 430 insertions, 0 deletions
diff --git a/third_party/rust/ioctl-sys/.cargo-checksum.json b/third_party/rust/ioctl-sys/.cargo-checksum.json
new file mode 100644
index 0000000000..dcb61238ab
--- /dev/null
+++ b/third_party/rust/ioctl-sys/.cargo-checksum.json
@@ -0,0 +1 @@
+{"files":{"Cargo.lock":"d6cc4881890b2366d449578cb0261a4ce398d97447865470e0566113fbc02070","Cargo.toml":"445dd422b0dee7675bf54bc7e7451530f4ebc888ddfaf1486ddee37f1defd9b1","examples/smoke.rs":"cca98c8eebc1f0f265e13d9966c936f0c51b99f4eb4b0e54c1303a6a853bcc76","src/lib.rs":"d19dac0fd5d49dfd4a17edf66114173479384f694c9f054692b18b5e8f86b40e","src/platform/linux.rs":"fcd4a2fc527b00846f9e806f834903ffadabb0ee63b64bd2f3df74767585986d","src/platform/macos.rs":"7650309cfb2a362f5fbb9b6593c65465d5feddfe3922ddaabd51a099989589c0","src/platform/mod.rs":"2de33a652d079c43193f441126a8a7a69be0f98da1c10a8dc889e84d6b3dd6fa"},"package":"7f9d0b6b23885487578d10590edc36fd95426257c7017973b20633e34df23b08"} \ No newline at end of file
diff --git a/third_party/rust/ioctl-sys/Cargo.lock b/third_party/rust/ioctl-sys/Cargo.lock
new file mode 100644
index 0000000000..c739ff781e
--- /dev/null
+++ b/third_party/rust/ioctl-sys/Cargo.lock
@@ -0,0 +1,5 @@
+# This file is automatically @generated by Cargo.
+# It is not intended for manual editing.
+[[package]]
+name = "ioctl-sys"
+version = "0.7.1"
diff --git a/third_party/rust/ioctl-sys/Cargo.toml b/third_party/rust/ioctl-sys/Cargo.toml
new file mode 100644
index 0000000000..3c62d31bdb
--- /dev/null
+++ b/third_party/rust/ioctl-sys/Cargo.toml
@@ -0,0 +1,23 @@
+# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO
+#
+# When uploading crates to the registry Cargo will automatically
+# "normalize" Cargo.toml files for maximal compatibility
+# with all versions of Cargo and also rewrite `path` dependencies
+# to registry (e.g., crates.io) dependencies
+#
+# If you believe there's an error in this file please file an
+# issue against the rust-lang/cargo repository. If you're
+# editing this file be aware that the upstream Cargo.toml
+# will likely look very different (and much more reasonable)
+
+[package]
+name = "ioctl-sys"
+version = "0.7.1"
+authors = ["Cody P Schafer <dev@codyps.com>", "Corey Richardson <corey@octayn.net>"]
+include = ["Cargo.toml", "**/*.rs"]
+description = "IO Control for POSIX-and-beyond systems (core fn & macros, see `ioctls` for many ioctl definitions)"
+documentation = "https://docs.rs/ioctl-sys"
+license = "MIT OR Apache-2.0"
+repository = "https://github.com/jmesmon/ioctl"
+
+[dependencies]
diff --git a/third_party/rust/ioctl-sys/examples/smoke.rs b/third_party/rust/ioctl-sys/examples/smoke.rs
new file mode 100644
index 0000000000..1508123491
--- /dev/null
+++ b/third_party/rust/ioctl-sys/examples/smoke.rs
@@ -0,0 +1,23 @@
+#[macro_use]
+extern crate ioctl_sys;
+
+ioctl!(bad kiocsound with 0x4B2F);
+ioctl!(none drm_ioctl_set_master with b'd', 0x1e);
+ioctl!(read ev_get_version with b'E', 0x01; u32);
+ioctl!(write ev_set_repeat with b'E', 0x03; [u32; 2]);
+
+ioctl!(try none drm_ioctl_set_master2 with b'd', 0x1e);
+ioctl!(try read ev_get_version2 with b'E', 0x01; u32);
+ioctl!(try read0 ev_get_version3 with b'E', 0x01; u32);
+ioctl!(try write ev_set_repeat2 with b'E', 0x03; [u32; 2]);
+
+fn main() {
+ let mut x = 0;
+ let ret = unsafe { ev_get_version(0, &mut x) };
+ println!("returned {}, x = {}", ret, x);
+ let mut x2 = 0;
+ let ret2 = unsafe { ev_get_version2(0, &mut x2) };
+ println!("returned {:?}, x = {}", ret2, x2);
+ let ret3 = unsafe { ev_get_version3(0) };
+ println!("returned {:?}", ret3);
+}
diff --git a/third_party/rust/ioctl-sys/src/lib.rs b/third_party/rust/ioctl-sys/src/lib.rs
new file mode 100644
index 0000000000..508c4cd248
--- /dev/null
+++ b/third_party/rust/ioctl-sys/src/lib.rs
@@ -0,0 +1,37 @@
+use std::os::raw::{c_int, c_ulong};
+
+#[cfg(any(target_os = "linux", target_os = "macos", target_os = "android"))]
+#[macro_use]
+mod platform;
+
+#[cfg(any(target_os = "linux", target_os = "macos", target_os = "android"))]
+pub use platform::*;
+
+extern "C" {
+ #[doc(hidden)]
+ pub fn ioctl(fd: c_int, req: c_ulong, ...) -> c_int;
+}
+
+#[doc(hidden)]
+pub fn check_res(res: c_int) -> std::io::Result<()> {
+ if res < 0 {
+ Err(std::io::Error::last_os_error())
+ } else {
+ Ok(())
+ }
+}
+
+#[cfg(not(any(target_os = "linux", target_os = "macos", target_os = "android")))]
+use platform_not_supported;
+
+#[cfg(doctest)]
+mod test_readme {
+ macro_rules! external_doc_test {
+ ($x:expr) => {
+ #[doc = $x]
+ extern "C" {}
+ };
+ }
+
+ external_doc_test!(include_str!("../../README.md"));
+}
diff --git a/third_party/rust/ioctl-sys/src/platform/linux.rs b/third_party/rust/ioctl-sys/src/platform/linux.rs
new file mode 100644
index 0000000000..300718f996
--- /dev/null
+++ b/third_party/rust/ioctl-sys/src/platform/linux.rs
@@ -0,0 +1,59 @@
+#[cfg(target_arch = "mips")]
+mod consts {
+ #[doc(hidden)]
+ pub const NONE: u8 = 1;
+ #[doc(hidden)]
+ pub const READ: u8 = 2;
+ #[doc(hidden)]
+ pub const WRITE: u8 = 4;
+ #[doc(hidden)]
+ pub const SIZEBITS: u8 = 13;
+ #[doc(hidden)]
+ pub const DIRBITS: u8 = 3;
+}
+#[cfg(target_arch = "powerpc")]
+mod consts {
+ #[doc(hidden)]
+ pub const NONE: u8 = 1;
+ #[doc(hidden)]
+ pub const READ: u8 = 2;
+ #[doc(hidden)]
+ pub const WRITE: u8 = 4;
+ #[doc(hidden)]
+ pub const SIZEBITS: u8 = 13;
+ #[doc(hidden)]
+ pub const DIRBITS: u8 = 3;
+}
+
+#[cfg(not(any(
+ target_arch = "powerpc",
+ target_arch = "mips",
+ target_arch = "x86",
+ target_arch = "arm",
+ target_arch = "x86_64",
+ target_arch = "aarch64"
+)))]
+use this_arch_not_supported;
+
+// "Generic" ioctl protocol
+#[cfg(any(
+ target_arch = "x86",
+ target_arch = "arm",
+ target_arch = "x86_64",
+ target_arch = "aarch64"
+))]
+mod consts {
+ #[doc(hidden)]
+ pub const NONE: u8 = 0;
+ #[doc(hidden)]
+ pub const READ: u8 = 2;
+ #[doc(hidden)]
+ pub const WRITE: u8 = 1;
+ #[doc(hidden)]
+ pub const SIZEBITS: u8 = 14;
+ #[doc(hidden)]
+ pub const DIRBITS: u8 = 2;
+}
+
+#[doc(hidden)]
+pub use self::consts::*;
diff --git a/third_party/rust/ioctl-sys/src/platform/macos.rs b/third_party/rust/ioctl-sys/src/platform/macos.rs
new file mode 100644
index 0000000000..63314409cf
--- /dev/null
+++ b/third_party/rust/ioctl-sys/src/platform/macos.rs
@@ -0,0 +1,19 @@
+#[cfg(any(target_arch = "aarch64", target_arch = "x86_64"))]
+mod consts {
+ #[doc(hidden)]
+ pub const NONE: u8 = 1;
+ #[doc(hidden)]
+ pub const READ: u8 = 2;
+ #[doc(hidden)]
+ pub const WRITE: u8 = 4;
+ #[doc(hidden)]
+ pub const SIZEBITS: u8 = 13;
+ #[doc(hidden)]
+ pub const DIRBITS: u8 = 3;
+}
+
+#[cfg(not(any(target_arch = "aarch64", target_arch = "x86_64")))]
+use this_arch_not_supported;
+
+#[doc(hidden)]
+pub use self::consts::*;
diff --git a/third_party/rust/ioctl-sys/src/platform/mod.rs b/third_party/rust/ioctl-sys/src/platform/mod.rs
new file mode 100644
index 0000000000..d795b4f3c5
--- /dev/null
+++ b/third_party/rust/ioctl-sys/src/platform/mod.rs
@@ -0,0 +1,263 @@
+#[doc(hidden)]
+pub const NRBITS: u32 = 8;
+#[doc(hidden)]
+pub const TYPEBITS: u32 = 8;
+
+#[cfg(any(target_os = "linux", target_os = "android"))]
+#[path = "linux.rs"]
+mod consts;
+
+#[cfg(target_os = "macos")]
+#[path = "macos.rs"]
+mod consts;
+
+#[doc(hidden)]
+pub use self::consts::*;
+
+#[doc(hidden)]
+pub const NRSHIFT: u32 = 0;
+#[doc(hidden)]
+pub const TYPESHIFT: u32 = NRSHIFT + NRBITS as u32;
+#[doc(hidden)]
+pub const SIZESHIFT: u32 = TYPESHIFT + TYPEBITS as u32;
+#[doc(hidden)]
+pub const DIRSHIFT: u32 = SIZESHIFT + SIZEBITS as u32;
+
+#[doc(hidden)]
+pub const NRMASK: u32 = (1 << NRBITS) - 1;
+#[doc(hidden)]
+pub const TYPEMASK: u32 = (1 << TYPEBITS) - 1;
+#[doc(hidden)]
+pub const SIZEMASK: u32 = (1 << SIZEBITS) - 1;
+#[doc(hidden)]
+pub const DIRMASK: u32 = (1 << DIRBITS) - 1;
+
+/// Encode an ioctl command.
+#[macro_export]
+macro_rules! ioc {
+ ($dir:expr, $ty:expr, $nr:expr, $sz:expr) => {
+ (($dir as u32) << $crate::DIRSHIFT)
+ | (($ty as u32) << $crate::TYPESHIFT)
+ | (($nr as u32) << $crate::NRSHIFT)
+ | (($sz as u32) << $crate::SIZESHIFT)
+ };
+}
+
+/// Encode an ioctl command that has no associated data.
+#[macro_export]
+macro_rules! io {
+ ($ty:expr, $nr:expr) => {
+ $crate::ioc!($crate::NONE, $ty, $nr, 0)
+ };
+}
+
+/// Encode an ioctl command that reads.
+#[macro_export]
+macro_rules! ior {
+ ($ty:expr, $nr:expr, $sz:expr) => {
+ $crate::ioc!($crate::READ, $ty, $nr, $sz)
+ };
+}
+
+/// Encode an ioctl command that writes.
+#[macro_export]
+macro_rules! iow {
+ ($ty:expr, $nr:expr, $sz:expr) => {
+ $crate::ioc!($crate::WRITE, $ty, $nr, $sz)
+ };
+}
+
+/// Encode an ioctl command that both reads and writes.
+#[macro_export]
+macro_rules! iorw {
+ ($ty:expr, $nr:expr, $sz:expr) => {
+ $crate::ioc!($crate::READ | $crate::WRITE, $ty, $nr, $sz)
+ };
+}
+
+/// Declare a wrapper function around an ioctl.
+#[macro_export]
+macro_rules! ioctl {
+ (bad $name:ident with $nr:expr) => {
+ pub unsafe fn $name(fd: ::std::os::raw::c_int, data: *mut u8) -> ::std::os::raw::c_int {
+ $crate::ioctl(fd, $nr as ::std::os::raw::c_ulong, data)
+ }
+ };
+ (bad read $name:ident with $nr:expr; $ty:ty) => {
+ pub unsafe fn $name(fd: ::std::os::raw::c_int, data: *mut $ty) -> ::std::os::raw::c_int {
+ $crate::ioctl(fd, $nr as ::std::os::raw::c_ulong, data)
+ }
+ };
+ (bad write $name:ident with $nr:expr; $ty:ty) => {
+ pub unsafe fn $name(fd: ::std::os::raw::c_int, data: *const $ty) -> ::std::os::raw::c_int {
+ $crate::ioctl(fd, $nr as ::std::os::raw::c_ulong, data)
+ }
+ };
+ (none $name:ident with $ioty:expr, $nr:expr) => {
+ pub unsafe fn $name(fd: ::std::os::raw::c_int) -> ::std::os::raw::c_int {
+ $crate::ioctl(fd, $crate::io!($ioty, $nr) as ::std::os::raw::c_ulong)
+ }
+ };
+ (try none $name:ident with $ioty:expr, $nr:expr) => {
+ pub unsafe fn $name(fd: ::std::os::raw::c_int) -> std::result::Result<(), std::io::Error> {
+ $crate::check_res($crate::ioctl(
+ fd,
+ $crate::io!($ioty, $nr) as ::std::os::raw::c_ulong,
+ ))
+ }
+ };
+ (arg $name:ident with $ioty:expr, $nr:expr) => {
+ pub unsafe fn $name(
+ fd: ::std::os::raw::c_int,
+ arg: ::std::os::raw::c_ulong,
+ ) -> ::std::os::raw::c_int {
+ $crate::ioctl(fd, $crate::io!($ioty, $nr) as ::std::os::raw::c_ulong, arg)
+ }
+ };
+ (read $name:ident with $ioty:expr, $nr:expr; $ty:ty) => {
+ pub unsafe fn $name(fd: ::std::os::raw::c_int, val: *mut $ty) -> ::std::os::raw::c_int {
+ $crate::ioctl(
+ fd,
+ $crate::ior!($ioty, $nr, ::std::mem::size_of::<$ty>()) as ::std::os::raw::c_ulong,
+ val,
+ )
+ }
+ };
+ (try read $name:ident with $ioty:expr, $nr:expr; $ty:ty) => {
+ pub unsafe fn $name(
+ fd: ::std::os::raw::c_int,
+ val: *mut $ty,
+ ) -> std::result::Result<(), std::io::Error> {
+ $crate::check_res($crate::ioctl(
+ fd,
+ $crate::ior!($ioty, $nr, ::std::mem::size_of::<$ty>()) as ::std::os::raw::c_ulong,
+ val,
+ ))
+ }
+ };
+ (try read0 $name:ident with $ioty:expr, $nr:expr; $ty:ty) => {
+ pub unsafe fn $name(fd: ::std::os::raw::c_int) -> std::result::Result<$ty, std::io::Error> {
+ let mut val: $ty = std::mem::zeroed();
+ $crate::check_res($crate::ioctl(
+ fd,
+ $crate::ior!($ioty, $nr, ::std::mem::size_of::<$ty>()) as ::std::os::raw::c_ulong,
+ &mut val as *mut $ty,
+ ))
+ .map(|_| val)
+ }
+ };
+ (write $name:ident with $ioty:expr, $nr:expr; $ty:ty) => {
+ pub unsafe fn $name(fd: ::std::os::raw::c_int, val: *const $ty) -> ::std::os::raw::c_int {
+ $crate::ioctl(
+ fd,
+ $crate::iow!($ioty, $nr, ::std::mem::size_of::<$ty>()) as ::std::os::raw::c_ulong,
+ val,
+ )
+ }
+ };
+ (try write $name:ident with $ioty:expr, $nr:expr; $ty:ty) => {
+ pub unsafe fn $name(
+ fd: ::std::os::raw::c_int,
+ val: *const $ty,
+ ) -> std::result::Result<(), std::io::Error> {
+ $crate::check_res($crate::ioctl(
+ fd,
+ $crate::iow!($ioty, $nr, ::std::mem::size_of::<$ty>()) as ::std::os::raw::c_ulong,
+ val,
+ ))
+ }
+ };
+ (readwrite $name:ident with $ioty:expr, $nr:expr; $ty:ty) => {
+ pub unsafe fn $name(fd: ::std::os::raw::c_int, val: *mut $ty) -> ::std::os::raw::c_int {
+ $crate::ioctl(
+ fd,
+ $crate::iorw!($ioty, $nr, ::std::mem::size_of::<$ty>()) as ::std::os::raw::c_ulong,
+ val,
+ )
+ }
+ };
+ (try readwrite $name:ident with $ioty:expr, $nr:expr; $ty:ty) => {
+ pub unsafe fn $name(
+ fd: ::std::os::raw::c_int,
+ val: *mut $ty,
+ ) -> std::result::Result<(), std::io::Error> {
+ $crate::check_res($crate::ioctl(
+ fd,
+ $crate::iorw!($ioty, $nr, ::std::mem::size_of::<$ty>()) as ::std::os::raw::c_ulong,
+ val,
+ ))
+ }
+ };
+ (read buf $name:ident with $ioty:expr, $nr:expr; $ty:ty) => {
+ pub unsafe fn $name(
+ fd: ::std::os::raw::c_int,
+ val: *mut $ty,
+ len: usize,
+ ) -> ::std::os::raw::c_int {
+ $crate::ioctl(
+ fd,
+ $crate::ior!($ioty, $nr, len) as ::std::os::raw::c_ulong,
+ val,
+ )
+ }
+ };
+ (write buf $name:ident with $ioty:expr, $nr:expr; $ty:ty) => {
+ pub unsafe fn $name(
+ fd: ::std::os::raw::c_int,
+ val: *const $ty,
+ len: usize,
+ ) -> ::std::os::raw::c_int {
+ $crate::ioctl(
+ fd,
+ $crate::iow!($ioty, $nr, len) as ::std::os::raw::c_ulong,
+ val,
+ )
+ }
+ };
+ (readwrite buf $name:ident with $ioty:expr, $nr:expr; $ty:ty) => {
+ pub unsafe fn $name(
+ fd: ::std::os::raw::c_int,
+ val: *const $ty,
+ len: usize,
+ ) -> ::std::os::raw::c_int {
+ $crate::ioctl(
+ fd,
+ $crate::iorw!($ioty, $nr, len) as ::std::os::raw::c_ulong,
+ val,
+ )
+ }
+ };
+}
+
+/// Extracts the "direction" (read/write/none) from an encoded ioctl command.
+#[inline(always)]
+pub fn ioc_dir(nr: u32) -> u8 {
+ ((nr >> DIRSHIFT) & DIRMASK) as u8
+}
+
+/// Extracts the type from an encoded ioctl command.
+#[inline(always)]
+pub fn ioc_type(nr: u32) -> u32 {
+ (nr >> TYPESHIFT) & TYPEMASK
+}
+
+/// Extracts the ioctl number from an encoded ioctl command.
+#[inline(always)]
+pub fn ioc_nr(nr: u32) -> u32 {
+ (nr >> NRSHIFT) & NRMASK
+}
+
+/// Extracts the size from an encoded ioctl command.
+#[inline(always)]
+pub fn ioc_size(nr: u32) -> u32 {
+ ((nr >> SIZESHIFT) as u32) & SIZEMASK
+}
+
+#[doc(hidden)]
+pub const IN: u32 = (WRITE as u32) << DIRSHIFT;
+#[doc(hidden)]
+pub const OUT: u32 = (READ as u32) << DIRSHIFT;
+#[doc(hidden)]
+pub const INOUT: u32 = ((READ | WRITE) as u32) << DIRSHIFT;
+#[doc(hidden)]
+pub const SIZE_MASK: u32 = SIZEMASK << SIZESHIFT;