summaryrefslogtreecommitdiff
path: root/src/sys/ioctl/platform
diff options
context:
space:
mode:
authorBryant Mairs <bryant@mai.rs>2017-07-11 16:46:17 -0700
committerMarcin Mielniczuk <marmistrz.dev@zoho.eu>2017-07-25 09:09:52 +0200
commit82e0139bedfd6f13dd8cd501148ea09619b1d91b (patch)
tree0f27287eb18145ae4910a30a938df628232fa1f1 /src/sys/ioctl/platform
parentcaaffb883d78e09140b6a2fa77cc9fdb74d411fb (diff)
downloadnix-82e0139bedfd6f13dd8cd501148ea09619b1d91b.zip
Use the proper ioctl number type depending on target
This also means that we need to properly mask off bits to the valid range of ioctl numbers.
Diffstat (limited to 'src/sys/ioctl/platform')
-rw-r--r--src/sys/ioctl/platform/bsd.rs17
-rw-r--r--src/sys/ioctl/platform/linux.rs36
2 files changed, 33 insertions, 20 deletions
diff --git a/src/sys/ioctl/platform/bsd.rs b/src/sys/ioctl/platform/bsd.rs
index df3716b9..ea39da3d 100644
--- a/src/sys/ioctl/platform/bsd.rs
+++ b/src/sys/ioctl/platform/bsd.rs
@@ -1,14 +1,19 @@
+/// The datatype used for the ioctl number
+#[doc(hidden)]
+pub type ioctl_num_type = ::libc::c_ulong;
+
mod consts {
+ use ::sys::ioctl::platform::ioctl_num_type;
#[doc(hidden)]
- pub const VOID: u32 = 0x20000000;
+ pub const VOID: ioctl_num_type = 0x20000000;
#[doc(hidden)]
- pub const OUT: u32 = 0x40000000;
+ pub const OUT: ioctl_num_type = 0x40000000;
#[doc(hidden)]
- pub const IN: u32 = 0x80000000;
+ pub const IN: ioctl_num_type = 0x80000000;
#[doc(hidden)]
- pub const INOUT: u32 = (IN|OUT);
+ pub const INOUT: ioctl_num_type = (IN|OUT);
#[doc(hidden)]
- pub const IOCPARM_MASK: u32 = 0x1fff;
+ pub const IOCPARM_MASK: ioctl_num_type = 0x1fff;
}
pub use self::consts::*;
@@ -17,7 +22,7 @@ pub use self::consts::*;
#[doc(hidden)]
macro_rules! ioc {
($inout:expr, $group:expr, $num:expr, $len:expr) => (
- $inout | (($len as u32 & $crate::sys::ioctl::IOCPARM_MASK) << 16) | (($group as u32) << 8) | ($num as u32)
+ $inout | (($len as $crate::sys::ioctl::ioctl_num_type & $crate::sys::ioctl::IOCPARM_MASK) << 16) | (($group as $crate::sys::ioctl::ioctl_num_type) << 8) | ($num as $crate::sys::ioctl::ioctl_num_type)
)
}
diff --git a/src/sys/ioctl/platform/linux.rs b/src/sys/ioctl/platform/linux.rs
index e3a130a9..6daa9257 100644
--- a/src/sys/ioctl/platform/linux.rs
+++ b/src/sys/ioctl/platform/linux.rs
@@ -1,7 +1,15 @@
+/// The datatype used for the ioctl number
+#[cfg(any(target_os = "android", target_env = "musl"))]
#[doc(hidden)]
-pub const NRBITS: u32 = 8;
+pub type ioctl_num_type = ::libc::c_int;
+#[cfg(not(any(target_os = "android", target_env = "musl")))]
#[doc(hidden)]
-pub const TYPEBITS: u32 = 8;
+pub type ioctl_num_type = ::libc::c_ulong;
+
+#[doc(hidden)]
+pub const NRBITS: ioctl_num_type = 8;
+#[doc(hidden)]
+pub const TYPEBITS: ioctl_num_type = 8;
#[cfg(any(target_arch = "mips", target_arch = "mips64", target_arch = "powerpc", target_arch = "powerpc64"))]
mod consts {
@@ -50,32 +58,32 @@ mod consts {
pub use self::consts::*;
#[doc(hidden)]
-pub const NRSHIFT: u32 = 0;
+pub const NRSHIFT: ioctl_num_type = 0;
#[doc(hidden)]
-pub const TYPESHIFT: u32 = NRSHIFT + NRBITS as u32;
+pub const TYPESHIFT: ioctl_num_type = NRSHIFT + NRBITS as ioctl_num_type;
#[doc(hidden)]
-pub const SIZESHIFT: u32 = TYPESHIFT + TYPEBITS as u32;
+pub const SIZESHIFT: ioctl_num_type = TYPESHIFT + TYPEBITS as ioctl_num_type;
#[doc(hidden)]
-pub const DIRSHIFT: u32 = SIZESHIFT + SIZEBITS as u32;
+pub const DIRSHIFT: ioctl_num_type = SIZESHIFT + SIZEBITS as ioctl_num_type;
#[doc(hidden)]
-pub const NRMASK: u32 = (1 << NRBITS) - 1;
+pub const NRMASK: ioctl_num_type = (1 << NRBITS) - 1;
#[doc(hidden)]
-pub const TYPEMASK: u32 = (1 << TYPEBITS) - 1;
+pub const TYPEMASK: ioctl_num_type = (1 << TYPEBITS) - 1;
#[doc(hidden)]
-pub const SIZEMASK: u32 = (1 << SIZEBITS) - 1;
+pub const SIZEMASK: ioctl_num_type = (1 << SIZEBITS) - 1;
#[doc(hidden)]
-pub const DIRMASK: u32 = (1 << DIRBITS) - 1;
+pub const DIRMASK: ioctl_num_type = (1 << DIRBITS) - 1;
/// Encode an ioctl command.
#[macro_export]
#[doc(hidden)]
macro_rules! ioc {
($dir:expr, $ty:expr, $nr:expr, $sz:expr) => (
- (($dir as u32) << $crate::sys::ioctl::DIRSHIFT) |
- (($ty as u32) << $crate::sys::ioctl::TYPESHIFT) |
- (($nr as u32) << $crate::sys::ioctl::NRSHIFT) |
- (($sz as u32) << $crate::sys::ioctl::SIZESHIFT))
+ (($dir as $crate::sys::ioctl::ioctl_num_type & $crate::sys::ioctl::DIRMASK) << $crate::sys::ioctl::DIRSHIFT) |
+ (($ty as $crate::sys::ioctl::ioctl_num_type & $crate::sys::ioctl::TYPEMASK) << $crate::sys::ioctl::TYPESHIFT) |
+ (($nr as $crate::sys::ioctl::ioctl_num_type & $crate::sys::ioctl::NRMASK) << $crate::sys::ioctl::NRSHIFT) |
+ (($sz as $crate::sys::ioctl::ioctl_num_type & $crate::sys::ioctl::SIZEMASK) << $crate::sys::ioctl::SIZESHIFT))
}
/// Encode an ioctl command that has no associated data.