Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ioctl generation macros for linux #1662

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/unix/linux_like/linux/gnu/b32/arm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -868,6 +868,16 @@ pub const SYS_pkey_alloc: ::c_long = 395;
pub const SYS_pkey_free: ::c_long = 396;
pub const SYS_statx: ::c_long = 397;

// from uapi/asm-generic
pub const _IOC_NRBITS: u32 = 8;
pub const _IOC_TYPEBITS: u32 = 8;
pub const _IOC_SIZEBITS: u32 = 14;
pub const _IOC_DIRBITS: u32 = 2;

pub const _IOC_NONE: ::c_ulong = 0;
pub const _IOC_READ: ::c_ulong = 1;
pub const _IOC_WRITE: ::c_ulong = 2;

cfg_if! {
if #[cfg(libc_align)] {
mod align;
Expand Down
11 changes: 11 additions & 0 deletions src/unix/linux_like/linux/gnu/b32/mips/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -893,6 +893,17 @@ pub const TIOCM_DSR: ::c_int = 0x400;

pub const EHWPOISON: ::c_int = 168;

// from uapi/asm-generic
pub const _IOC_NRBITS: u32 = 8;
pub const _IOC_TYPEBITS: u32 = 8;
// from arch/mips/include/uapi/asm
pub const _IOC_SIZEBITS: u32 = 13;
pub const _IOC_DIRBITS: u32 = 3;

pub const _IOC_NONE: ::c_ulong = 1;
pub const _IOC_READ: ::c_ulong = 2;
pub const _IOC_WRITE: ::c_ulong = 4;

cfg_if! {
if #[cfg(libc_align)] {
mod align;
Expand Down
11 changes: 11 additions & 0 deletions src/unix/linux_like/linux/gnu/b32/powerpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -871,3 +871,14 @@ pub const SYS_preadv2: ::c_long = 380;
pub const SYS_pwritev2: ::c_long = 381;
pub const SYS_kexec_file_load: ::c_long = 382;
pub const SYS_statx: ::c_long = 383;

// from uapi/asm-generic
pub const _IOC_NRBITS: u32 = 8;
pub const _IOC_TYPEBITS: u32 = 8;
// from arch/powerpc/include/uapi/asm
pub const _IOC_SIZEBITS: u32 = 13;
pub const _IOC_DIRBITS: u32 = 3;

pub const _IOC_NONE: ::c_ulong = 1;
pub const _IOC_READ: ::c_ulong = 2;
pub const _IOC_WRITE: ::c_ulong = 4;
11 changes: 11 additions & 0 deletions src/unix/linux_like/linux/gnu/b32/sparc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -958,6 +958,17 @@ pub const SYS_preadv2: ::c_long = 358;
pub const SYS_pwritev2: ::c_long = 359;
pub const SYS_statx: ::c_long = 360;

// from uapi/asm-generic
pub const _IOC_NRBITS: u32 = 8;
pub const _IOC_TYPEBITS: u32 = 8;
// from arch/sparc/include/uapi/asm
pub const _IOC_SIZEBITS: u32 = 13;
pub const _IOC_DIRBITS: u32 = 3;

pub const _IOC_NONE: ::c_ulong = 1;
pub const _IOC_READ: ::c_ulong = 2;
pub const _IOC_WRITE: ::c_ulong = 4;

#[link(name = "util")]
extern "C" {
pub fn sysctl(
Expand Down
10 changes: 10 additions & 0 deletions src/unix/linux_like/linux/gnu/b32/x86/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1101,6 +1101,16 @@ pub const SYS_pkey_alloc: ::c_long = 381;
pub const SYS_pkey_free: ::c_long = 382;
pub const SYS_statx: ::c_long = 383;

// from uapi/asm-generic
pub const _IOC_NRBITS: u32 = 8;
pub const _IOC_TYPEBITS: u32 = 8;
pub const _IOC_SIZEBITS: u32 = 14;
pub const _IOC_DIRBITS: u32 = 2;

pub const _IOC_NONE: ::c_ulong = 0;
pub const _IOC_READ: ::c_ulong = 1;
pub const _IOC_WRITE: ::c_ulong = 2;

// offsets in user_regs_structs, from sys/reg.h
pub const EBX: ::c_int = 0;
pub const ECX: ::c_int = 1;
Expand Down
10 changes: 10 additions & 0 deletions src/unix/linux_like/linux/gnu/b64/aarch64/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -946,6 +946,16 @@ extern "C" {
) -> ::c_int;
}

// from uapi/asm-generic
pub const _IOC_NRBITS: u32 = 8;
pub const _IOC_TYPEBITS: u32 = 8;
pub const _IOC_SIZEBITS: u32 = 14;
pub const _IOC_DIRBITS: u32 = 2;

pub const _IOC_NONE: ::c_ulong = 0;
pub const _IOC_READ: ::c_ulong = 1;
pub const _IOC_WRITE: ::c_ulong = 2;

cfg_if! {
if #[cfg(libc_align)] {
mod align;
Expand Down
11 changes: 11 additions & 0 deletions src/unix/linux_like/linux/gnu/b64/mips64/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -997,6 +997,17 @@ pub const TIOCM_DSR: ::c_int = 0x400;

pub const EHWPOISON: ::c_int = 168;

// from uapi/asm-generic
pub const _IOC_NRBITS: u32 = 8;
pub const _IOC_TYPEBITS: u32 = 8;
// from arch/mips/include/uapi/asm
pub const _IOC_SIZEBITS: u32 = 13;
pub const _IOC_DIRBITS: u32 = 3;

pub const _IOC_NONE: ::c_ulong = 1;
pub const _IOC_READ: ::c_ulong = 2;
pub const _IOC_WRITE: ::c_ulong = 4;

#[link(name = "util")]
extern "C" {
pub fn sysctl(
Expand Down
11 changes: 11 additions & 0 deletions src/unix/linux_like/linux/gnu/b64/powerpc64/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1032,6 +1032,17 @@ pub const SYS_pwritev2: ::c_long = 381;
pub const SYS_kexec_file_load: ::c_long = 382;
pub const SYS_statx: ::c_long = 383;

// from uapi/asm-generic
pub const _IOC_NRBITS: u32 = 8;
pub const _IOC_TYPEBITS: u32 = 8;
// from arch/powerpc/include/uapi/asm
pub const _IOC_SIZEBITS: u32 = 13;
pub const _IOC_DIRBITS: u32 = 3;

pub const _IOC_NONE: ::c_ulong = 1;
pub const _IOC_READ: ::c_ulong = 2;
pub const _IOC_WRITE: ::c_ulong = 4;

#[link(name = "util")]
extern "C" {
pub fn sysctl(
Expand Down
10 changes: 10 additions & 0 deletions src/unix/linux_like/linux/gnu/b64/riscv64/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -859,3 +859,13 @@ pub const SYS_pkey_mprotect: ::c_long = 288;
pub const SYS_pkey_alloc: ::c_long = 289;
pub const SYS_pkey_free: ::c_long = 290;
pub const SYS_statx: ::c_long = 291;

// from uapi/asm-generic
pub const _IOC_NRBITS: u32 = 8;
pub const _IOC_TYPEBITS: u32 = 8;
pub const _IOC_SIZEBITS: u32 = 14;
pub const _IOC_DIRBITS: u32 = 2;

pub const _IOC_NONE: ::c_ulong = 0;
pub const _IOC_READ: ::c_ulong = 1;
pub const _IOC_WRITE: ::c_ulong = 2;
10 changes: 10 additions & 0 deletions src/unix/linux_like/linux/gnu/b64/s390x.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1003,6 +1003,16 @@ pub const SYS_setfsgid: ::c_long = 216;
pub const SYS_newfstatat: ::c_long = 293;
pub const SYS_statx: ::c_long = 379;

// from uapi/asm-generic
pub const _IOC_NRBITS: u32 = 8;
pub const _IOC_TYPEBITS: u32 = 8;
pub const _IOC_SIZEBITS: u32 = 14;
pub const _IOC_DIRBITS: u32 = 2;

pub const _IOC_NONE: ::c_ulong = 0;
pub const _IOC_READ: ::c_ulong = 1;
pub const _IOC_WRITE: ::c_ulong = 2;

#[link(name = "util")]
extern "C" {

Expand Down
11 changes: 11 additions & 0 deletions src/unix/linux_like/linux/gnu/b64/sparc64/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -968,6 +968,17 @@ pub const SYS_preadv2: ::c_long = 358;
pub const SYS_pwritev2: ::c_long = 359;
pub const SYS_statx: ::c_long = 360;

// from uapi/asm-generic
pub const _IOC_NRBITS: u32 = 8;
pub const _IOC_TYPEBITS: u32 = 8;
// from arch/sparc/include/uapi/asm
pub const _IOC_SIZEBITS: u32 = 13;
pub const _IOC_DIRBITS: u32 = 3;

pub const _IOC_NONE: ::c_ulong = 1;
pub const _IOC_READ: ::c_ulong = 2;
pub const _IOC_WRITE: ::c_ulong = 4;

#[link(name = "util")]
extern "C" {
pub fn sysctl(
Expand Down
10 changes: 10 additions & 0 deletions src/unix/linux_like/linux/gnu/b64/x86_64/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -890,6 +890,16 @@ pub const REG_TRAPNO: ::c_int = 20;
pub const REG_OLDMASK: ::c_int = 21;
pub const REG_CR2: ::c_int = 22;

// from uapi/asm-generic
pub const _IOC_NRBITS: u32 = 8;
pub const _IOC_TYPEBITS: u32 = 8;
pub const _IOC_SIZEBITS: u32 = 14;
pub const _IOC_DIRBITS: u32 = 2;

pub const _IOC_NONE: ::c_ulong = 0;
pub const _IOC_READ: ::c_ulong = 1;
pub const _IOC_WRITE: ::c_ulong = 2;

extern "C" {
pub fn getcontext(ucp: *mut ucontext_t) -> ::c_int;
pub fn setcontext(ucp: *const ucontext_t) -> ::c_int;
Expand Down
32 changes: 32 additions & 0 deletions src/unix/linux_like/linux/gnu/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -961,6 +961,38 @@ extern "C" {
) -> ::ssize_t;
}

// glibc uses the definitions from the kernel header files.
pub fn _IOC(dir: ::c_ulong, typ: u8, nr: u8, size: ::c_ulong) -> ::c_ulong {
const _IOC_NRSHIFT: u32 = 0;
const _IOC_TYPESHIFT: u32 = _IOC_NRSHIFT+_IOC_NRBITS;
const _IOC_SIZESHIFT: u32 = _IOC_TYPESHIFT+_IOC_TYPEBITS;
const _IOC_DIRSHIFT: u32 = _IOC_SIZESHIFT+_IOC_SIZEBITS;

((dir) << _IOC_DIRSHIFT) |
((typ as ::c_ulong) << _IOC_TYPESHIFT) |
((nr as ::c_ulong) << _IOC_NRSHIFT) |
((size) << _IOC_SIZESHIFT)
}

pub fn _IO(a:u8,b:u8) -> ::c_ulong {
_IOC(_IOC_NONE,a,b,0)
}

pub fn _IOW<T: Sized> (a:u8,b:u8) -> ::c_ulong {
let size = ::core::mem::size_of::<T>() as ::c_ulong;
_IOC(_IOC_WRITE,a,b,size)
}

pub fn _IOR<T: Sized> (a:u8,b:u8) -> ::c_ulong {
let size = ::core::mem::size_of::<T>() as ::c_ulong;
_IOC(_IOC_READ,a,b,size)
}

pub fn _IOWR<T: Sized> (a:u8,b:u8) -> ::c_ulong {
let size = ::core::mem::size_of::<T>() as ::c_ulong;
_IOC(_IOC_READ|_IOC_WRITE,a,b,size)
}

#[link(name = "util")]
extern "C" {
pub fn ioctl(fd: ::c_int, request: ::c_ulong, ...) -> ::c_int;
Expand Down
27 changes: 27 additions & 0 deletions src/unix/linux_like/linux/musl/b32/arm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,33 @@ s! {
}
}

pub fn _IOC(a: ::c_uint, b: u8, c: u8, d: ::c_int) -> ::c_int {
(a<<30) as ::c_int | (b as ::c_int)<<8 | c as ::c_int | d<<16
}

pub const _IOC_NONE: ::c_uint = 0;
pub const _IOC_WRITE: ::c_uint = 1;
pub const _IOC_READ: ::c_uint = 2;

pub fn _IO(a:u8,b:u8) -> ::c_int {
_IOC(_IOC_NONE,a,b,0)
}

pub fn _IOW<T: Sized> (a:u8,b:u8) -> ::c_int {
let size = ::core::mem::size_of::<T>() as ::c_int;
_IOC(_IOC_WRITE,a,b,size)
}

pub fn _IOR<T: Sized> (a:u8,b:u8) -> ::c_int {
let size = ::core::mem::size_of::<T>() as ::c_int;
_IOC(_IOC_READ,a,b,size)
}

pub fn _IOWR<T: Sized> (a:u8,b:u8) -> ::c_int {
let size = ::core::mem::size_of::<T>() as ::c_int;
_IOC(_IOC_READ|_IOC_WRITE,a,b,size)
}

pub const SIGSTKSZ: ::size_t = 8192;
pub const MINSIGSTKSZ: ::size_t = 2048;

Expand Down
27 changes: 27 additions & 0 deletions src/unix/linux_like/linux/musl/b32/mips/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,33 @@ s! {
}
}

pub fn _IOC(a: ::c_uint, b: u8, c: u8, d: ::c_int) -> ::c_int {
(a<<29) as ::c_int | (b as ::c_int)<<8 | c as ::c_int | d<<16
}

pub const _IOC_NONE: ::c_uint = 1;
pub const _IOC_READ: ::c_uint = 2;
pub const _IOC_WRITE: ::c_uint = 4;

pub fn _IO(a:u8,b:u8) -> ::c_int {
_IOC(_IOC_NONE,a,b,0)
}

pub fn _IOW<T: Sized> (a:u8,b:u8) -> ::c_int {
let size = ::core::mem::size_of::<T>() as ::c_int;
_IOC(_IOC_WRITE,a,b,size)
}

pub fn _IOR<T: Sized> (a:u8,b:u8) -> ::c_int {
let size = ::core::mem::size_of::<T>() as ::c_int;
_IOC(_IOC_READ,a,b,size)
}

pub fn _IOWR<T: Sized> (a:u8,b:u8) -> ::c_int {
let size = ::core::mem::size_of::<T>() as ::c_int;
_IOC(_IOC_READ|_IOC_WRITE,a,b,size)
}

pub const SIGSTKSZ: ::size_t = 8192;
pub const MINSIGSTKSZ: ::size_t = 2048;

Expand Down
27 changes: 27 additions & 0 deletions src/unix/linux_like/linux/musl/b32/powerpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,33 @@ s! {
}
}

pub fn _IOC(a: ::c_uint, b: u8, c: u8, d: ::c_int) -> ::c_int {
(a<<29) as ::c_int | (b as ::c_int)<<8 | c as ::c_int | d<<16
}

pub const _IOC_NONE: ::c_uint = 1;
pub const _IOC_WRITE: ::c_uint = 4;
pub const _IOC_READ: ::c_uint = 2;

pub fn _IO(a:u8,b:u8) -> ::c_int {
_IOC(_IOC_NONE,a,b,0)
}

pub fn _IOW<T: Sized> (a:u8,b:u8) -> ::c_int {
let size = ::core::mem::size_of::<T>() as ::c_int;
_IOC(_IOC_WRITE,a,b,size)
}

pub fn _IOR<T: Sized> (a:u8,b:u8) -> ::c_int {
let size = ::core::mem::size_of::<T>() as ::c_int;
_IOC(_IOC_READ,a,b,size)
}

pub fn _IOWR<T: Sized> (a:u8,b:u8) -> ::c_int {
let size = ::core::mem::size_of::<T>() as ::c_int;
_IOC(_IOC_READ|_IOC_WRITE,a,b,size)
}

pub const MADV_SOFT_OFFLINE: ::c_int = 101;
pub const SIGSTKSZ: ::size_t = 10240;
pub const MINSIGSTKSZ: ::size_t = 4096;
Expand Down
27 changes: 27 additions & 0 deletions src/unix/linux_like/linux/musl/b32/x86/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,33 @@ cfg_if! {
}
}

pub fn _IOC(a: ::c_uint, b: u8, c: u8, d: ::c_int) -> ::c_int {
(a<<30) as ::c_int | (b as ::c_int)<<8 | c as ::c_int | (d<<16)
}

pub const _IOC_NONE: ::c_uint = 0;
pub const _IOC_WRITE: ::c_uint = 1;
pub const _IOC_READ: ::c_uint = 2;

pub fn _IO(a:u8,b:u8) -> ::c_int {
_IOC(_IOC_NONE,a,b,0)
}

pub fn _IOW<T: Sized> (a:u8,b:u8) -> ::c_int {
let size = ::core::mem::size_of::<T>() as ::c_int;
_IOC(_IOC_WRITE,a,b,size)
}

pub fn _IOR<T: Sized> (a:u8,b:u8) -> ::c_int {
let size = ::core::mem::size_of::<T>() as ::c_int;
_IOC(_IOC_READ,a,b,size)
}

pub fn _IOWR<T: Sized> (a:u8,b:u8) -> ::c_int {
let size = ::core::mem::size_of::<T>() as ::c_int;
_IOC(_IOC_READ|_IOC_WRITE,a,b,size)
}

pub const SIGSTKSZ: ::size_t = 8192;
pub const MINSIGSTKSZ: ::size_t = 2048;

Expand Down
Loading