-
Notifications
You must be signed in to change notification settings - Fork 1.1k
if_tun.h ioctls for android #4379
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5940,88 +5940,28 @@ pub const SCHED_FLAG_ALL: c_int = SCHED_FLAG_RESET_ON_FORK | |
pub const EPIOCSPARAMS: Ioctl = 0x40088a01; | ||
pub const EPIOCGPARAMS: Ioctl = 0x80088a02; | ||
|
||
const _IOC_NRBITS: u32 = 8; | ||
const _IOC_TYPEBITS: u32 = 8; | ||
|
||
// siginfo.h | ||
pub const SI_DETHREAD: c_int = -7; | ||
pub const TRAP_PERF: c_int = 6; | ||
|
||
// https://github.com/search?q=repo%3Atorvalds%2Flinux+%22%23define+_IOC_NONE%22&type=code | ||
cfg_if! { | ||
if #[cfg(any( | ||
any(target_arch = "powerpc", target_arch = "powerpc64"), | ||
any(target_arch = "sparc", target_arch = "sparc64"), | ||
any(target_arch = "mips", target_arch = "mips64"), | ||
))] { | ||
// https://github.com/torvalds/linux/blob/b311c1b497e51a628aa89e7cb954481e5f9dced2/arch/powerpc/include/uapi/asm/ioctl.h | ||
// https://github.com/torvalds/linux/blob/b311c1b497e51a628aa89e7cb954481e5f9dced2/arch/sparc/include/uapi/asm/ioctl.h | ||
// https://github.com/torvalds/linux/blob/b311c1b497e51a628aa89e7cb954481e5f9dced2/arch/mips/include/uapi/asm/ioctl.h | ||
|
||
const _IOC_SIZEBITS: u32 = 13; | ||
const _IOC_DIRBITS: u32 = 3; | ||
|
||
const _IOC_NONE: u32 = 1; | ||
const _IOC_READ: u32 = 2; | ||
const _IOC_WRITE: u32 = 4; | ||
} else { | ||
// https://github.com/torvalds/linux/blob/b311c1b497e51a628aa89e7cb954481e5f9dced2/include/uapi/asm-generic/ioctl.h | ||
|
||
const _IOC_SIZEBITS: u32 = 14; | ||
const _IOC_DIRBITS: u32 = 2; | ||
|
||
const _IOC_NONE: u32 = 0; | ||
const _IOC_WRITE: u32 = 1; | ||
const _IOC_READ: u32 = 2; | ||
} | ||
} | ||
|
||
const _IOC_NRMASK: u32 = (1 << _IOC_NRBITS) - 1; | ||
const _IOC_TYPEMASK: u32 = (1 << _IOC_TYPEBITS) - 1; | ||
const _IOC_SIZEMASK: u32 = (1 << _IOC_SIZEBITS) - 1; | ||
const _IOC_DIRMASK: u32 = (1 << _IOC_DIRBITS) - 1; | ||
|
||
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; | ||
|
||
// adapted from https://github.com/torvalds/linux/blob/8a696a29c6905594e4abf78eaafcb62165ac61f1/rust/kernel/ioctl.rs | ||
|
||
/// Build an ioctl number, analogous to the C macro of the same name. | ||
const fn _IOC(dir: u32, ty: u32, nr: u32, size: usize) -> u32 { | ||
// FIXME(ctest) the `garando_syntax` crate (used by ctest in the CI test suite) | ||
// cannot currently parse these `debug_assert!`s | ||
// | ||
// debug_assert!(dir <= _IOC_DIRMASK); | ||
// debug_assert!(ty <= _IOC_TYPEMASK); | ||
// debug_assert!(nr <= _IOC_NRMASK); | ||
// debug_assert!(size <= (_IOC_SIZEMASK as usize)); | ||
|
||
(dir << _IOC_DIRSHIFT) | ||
| (ty << _IOC_TYPESHIFT) | ||
| (nr << _IOC_NRSHIFT) | ||
| ((size as u32) << _IOC_SIZESHIFT) | ||
} | ||
|
||
/// Build an ioctl number for an argumentless ioctl. | ||
pub const fn _IO(ty: u32, nr: u32) -> u32 { | ||
_IOC(_IOC_NONE, ty, nr, 0) | ||
/// Build an ioctl number for an argumentless ioctl. | ||
pub const fn _IO(ty: u32, nr: u32) -> u32 { | ||
super::_IOC(super::_IOC_NONE, ty, nr, 0) | ||
} | ||
Comment on lines
+5948
to
5950
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could these just move to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. They are not strictly duplicates. They differ when it comes to the return type. Of course I could put them in some non public module (e.g. BTW using those There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I missed the return type difference, as-is is fine then 👍 Updating any hardcoded ioctl values would be appreciated if you are interested in doing that. A lot of these definitions come from before we had |
||
|
||
/// Build an ioctl number for an read-only ioctl. | ||
pub const fn _IOR<T>(ty: u32, nr: u32) -> u32 { | ||
_IOC(_IOC_READ, ty, nr, size_of::<T>()) | ||
super::_IOC(super::_IOC_READ, ty, nr, size_of::<T>()) | ||
} | ||
|
||
/// Build an ioctl number for an write-only ioctl. | ||
pub const fn _IOW<T>(ty: u32, nr: u32) -> u32 { | ||
_IOC(_IOC_WRITE, ty, nr, size_of::<T>()) | ||
super::_IOC(super::_IOC_WRITE, ty, nr, size_of::<T>()) | ||
} | ||
|
||
/// Build an ioctl number for a read-write ioctl. | ||
pub const fn _IOWR<T>(ty: u32, nr: u32) -> u32 { | ||
_IOC(_IOC_READ | _IOC_WRITE, ty, nr, size_of::<T>()) | ||
super::_IOC(super::_IOC_READ | super::_IOC_WRITE, ty, nr, size_of::<T>()) | ||
} | ||
|
||
f! { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IOW/R