aienux
Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.
Brought by drakestapleton
aienux / vendor / libc / src / new / apple / xnu / sys / ioccom.rs
| 1 | //! Header: `sys/ioccom.h` |
| 2 | //! |
| 3 | //! <https://github.com/apple-oss-distributions/xnu/blob/main/bsd/sys/ioccom.h> |
| 4 | |
| 5 | use crate::prelude::*; |
| 6 | |
| 7 | const IOCPARM_MASK: c_ulong = 0x1fff; |
| 8 | |
| 9 | const IOCPARM_MAX: c_ulong = IOCPARM_MASK + 1; |
| 10 | |
| 11 | // These are u32 in source but would probably be more practical as c_ulong if we ever need |
| 12 | // to make them public. |
| 13 | pub(crate) const IOC_VOID: u32 = 0x20000000; |
| 14 | pub(crate) const IOC_OUT: u32 = 0x40000000; |
| 15 | pub(crate) const IOC_IN: u32 = 0x80000000; |
| 16 | pub(crate) const IOC_INOUT: u32 = IOC_IN | IOC_OUT; |
| 17 | pub(crate) const IOC_DIRMASK: u32 = 0xe0000000; |
| 18 | |
| 19 | // Only pub(crate) for the above reason. |
| 20 | pub(crate) const fn _IOC(inout: u32, group: c_ulong, num: c_ulong, len: c_ulong) -> c_ulong { |
| 21 | debug_assert!(inout <= IOC_DIRMASK); |
| 22 | debug_assert!(group <= 0xff); |
| 23 | debug_assert!(num <= 0xff); |
| 24 | debug_assert!(len <= IOCPARM_MAX); |
| 25 | |
| 26 | // Sanity check the cast |
| 27 | assert!(size_of::<u32>() <= size_of::<c_ulong>()); |
| 28 | |
| 29 | (inout as c_ulong) | ((len & IOCPARM_MASK) << 16) | (group << 8) | num |
| 30 | } |
| 31 | |
| 32 | pub const fn _IO(g: c_ulong, n: c_ulong) -> c_ulong { |
| 33 | _IOC(IOC_VOID, g, n, 0) |
| 34 | } |
| 35 | |
| 36 | /// Build an ioctl number for an read-only ioctl. |
| 37 | pub const fn _IOR<T>(g: c_ulong, n: c_ulong) -> c_ulong { |
| 38 | _IOC(IOC_OUT, g, n, mem::size_of::<T>() as c_ulong) |
| 39 | } |
| 40 | |
| 41 | /// Build an ioctl number for an write-only ioctl. |
| 42 | pub const fn _IOW<T>(g: c_ulong, n: c_ulong) -> c_ulong { |
| 43 | _IOC(IOC_IN, g, n, mem::size_of::<T>() as c_ulong) |
| 44 | } |
| 45 | |
| 46 | /// Build an ioctl number for a read-write ioctl. |
| 47 | pub const fn _IOWR<T>(g: c_ulong, n: c_ulong) -> c_ulong { |
| 48 | _IOC(IOC_INOUT, g, n, mem::size_of::<T>() as c_ulong) |
| 49 | } |