Skip to content

Commit 0a96edd

Browse files
committed
add the other constants
1 parent e5f2a2a commit 0a96edd

File tree

2 files changed

+120
-0
lines changed

2 files changed

+120
-0
lines changed

libc-test/semver/linux.txt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2252,11 +2252,29 @@ PTHREAD_PRIO_PROTECT
22522252
PTHREAD_PROCESS_PRIVATE
22532253
PTHREAD_PROCESS_SHARED
22542254
PTHREAD_STACK_MIN
2255+
PTP_CLOCK_GETCAPS
2256+
PTP_CLOCK_GETCAPS2
2257+
PTP_ENABLE_PPS
2258+
PTP_ENABLE_PPS2
2259+
PTP_EXTTS_REQUEST
2260+
PTP_EXTTS_REQUEST2
22552261
PTP_MAX_SAMPLES
2262+
PTP_PEROUT_REQUEST
2263+
PTP_PEROUT_REQUEST2
22562264
PTP_PF_EXTTS
22572265
PTP_PF_NONE
22582266
PTP_PF_PEROUT
22592267
PTP_PF_PHYSYNC
2268+
PTP_PIN_GETFUNC
2269+
PTP_PIN_GETFUNC2
2270+
PTP_PIN_SETFUNC
2271+
PTP_PIN_SETFUNC2
2272+
PTP_SYS_OFFSET
2273+
PTP_SYS_OFFSET2
2274+
PTP_SYS_OFFSET_EXTENDED
2275+
PTP_SYS_OFFSET_EXTENDED2
2276+
PTP_SYS_OFFSET_PRECISE
2277+
PTP_SYS_OFFSET_PRECISE2
22602278
PTRACE_ATTACH
22612279
PTRACE_CONT
22622280
PTRACE_DETACH

src/unix/linux_like/linux/mod.rs

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4541,6 +4541,28 @@ pub const HWTSTAMP_FILTER_NTP_ALL: ::c_uint = 15;
45414541
// linux/ptp_clock.h
45424542
pub const PTP_MAX_SAMPLES: ::c_uint = 25; // Maximum allowed offset measurement samples.
45434543

4544+
const PTP_CLK_MAGIC: u32 = b'=' as u32;
4545+
4546+
pub const PTP_CLOCK_GETCAPS: ::c_uint = _IOR::<ptp_clock_caps>(PTP_CLK_MAGIC, 1);
4547+
pub const PTP_EXTTS_REQUEST: ::c_uint = _IOW::<ptp_extts_request>(PTP_CLK_MAGIC, 2);
4548+
pub const PTP_PEROUT_REQUEST: ::c_uint = _IOW::<ptp_perout_request>(PTP_CLK_MAGIC, 3);
4549+
pub const PTP_ENABLE_PPS: ::c_uint = _IOW::<::c_int>(PTP_CLK_MAGIC, 4);
4550+
pub const PTP_SYS_OFFSET: ::c_uint = _IOW::<ptp_sys_offset>(PTP_CLK_MAGIC, 5);
4551+
pub const PTP_PIN_GETFUNC: ::c_uint = _IOWR::<ptp_pin_desc>(PTP_CLK_MAGIC, 6);
4552+
pub const PTP_PIN_SETFUNC: ::c_uint = _IOW::<ptp_pin_desc>(PTP_CLK_MAGIC, 7);
4553+
pub const PTP_SYS_OFFSET_PRECISE: ::c_uint = _IOWR::<ptp_sys_offset_precise>(PTP_CLK_MAGIC, 8);
4554+
pub const PTP_SYS_OFFSET_EXTENDED: ::c_uint = _IOWR::<ptp_sys_offset_extended>(PTP_CLK_MAGIC, 9);
4555+
4556+
pub const PTP_CLOCK_GETCAPS2: ::c_uint = _IOR::<ptp_clock_caps>(PTP_CLK_MAGIC, 10);
4557+
pub const PTP_EXTTS_REQUEST2: ::c_uint = _IOW::<ptp_extts_request>(PTP_CLK_MAGIC, 11);
4558+
pub const PTP_PEROUT_REQUEST2: ::c_uint = _IOW::<ptp_perout_request>(PTP_CLK_MAGIC, 12);
4559+
pub const PTP_ENABLE_PPS2: ::c_uint = _IOW::<::c_int>(PTP_CLK_MAGIC, 13);
4560+
pub const PTP_SYS_OFFSET2: ::c_uint = _IOW::<ptp_sys_offset>(PTP_CLK_MAGIC, 14);
4561+
pub const PTP_PIN_GETFUNC2: ::c_uint = _IOWR::<ptp_pin_desc>(PTP_CLK_MAGIC, 15);
4562+
pub const PTP_PIN_SETFUNC2: ::c_uint = _IOW::<ptp_pin_desc>(PTP_CLK_MAGIC, 16);
4563+
pub const PTP_SYS_OFFSET_PRECISE2: ::c_uint = _IOWR::<ptp_sys_offset_precise>(PTP_CLK_MAGIC, 17);
4564+
pub const PTP_SYS_OFFSET_EXTENDED2: ::c_uint = _IOWR::<ptp_sys_offset_extended>(PTP_CLK_MAGIC, 18);
4565+
45444566
// enum ptp_pin_function
45454567
pub const PTP_PF_NONE: ::c_uint = 0;
45464568
pub const PTP_PF_EXTTS: ::c_uint = 1;
@@ -5601,6 +5623,86 @@ pub const SCHED_FLAG_ALL: ::c_int = SCHED_FLAG_RESET_ON_FORK
56015623
pub const EPIOCSPARAMS: ::Ioctl = 0x40088a01;
56025624
pub const EPIOCGPARAMS: ::Ioctl = 0x80088a02;
56035625

5626+
const _IOC_NRBITS: u32 = 8;
5627+
const _IOC_TYPEBITS: u32 = 8;
5628+
5629+
// https://github.com/search?q=repo%3Atorvalds%2Flinux+%22%23define+_IOC_NONE%22&type=code
5630+
cfg_if! {
5631+
if #[cfg(any(
5632+
any(target_arch = "powerpc", target_arch = "powerpc64"),
5633+
any(target_arch = "sparc", target_arch = "sparc64"),
5634+
any(target_arch = "mips", target_arch = "mips64"),
5635+
))] {
5636+
// https://github.com/torvalds/linux/blob/b311c1b497e51a628aa89e7cb954481e5f9dced2/arch/powerpc/include/uapi/asm/ioctl.h
5637+
// https://github.com/torvalds/linux/blob/b311c1b497e51a628aa89e7cb954481e5f9dced2/arch/sparc/include/uapi/asm/ioctl.h
5638+
// https://github.com/torvalds/linux/blob/b311c1b497e51a628aa89e7cb954481e5f9dced2/arch/mips/include/uapi/asm/ioctl.h
5639+
5640+
const _IOC_SIZEBITS: u32 = 13;
5641+
const _IOC_DIRBITS: u32 = 3;
5642+
5643+
const _IOC_NONE: u32 = 1;
5644+
const _IOC_READ: u32 = 2;
5645+
const _IOC_WRITE: u32 = 4;
5646+
} else {
5647+
// https://github.com/torvalds/linux/blob/b311c1b497e51a628aa89e7cb954481e5f9dced2/include/uapi/asm-generic/ioctl.h
5648+
5649+
const _IOC_SIZEBITS: u32 = 14;
5650+
const _IOC_DIRBITS: u32 = 2;
5651+
5652+
const _IOC_NONE: u32 = 0;
5653+
const _IOC_WRITE: u32 = 1;
5654+
const _IOC_READ: u32 = 2;
5655+
}
5656+
}
5657+
5658+
const _IOC_NRMASK: u32 = (1 << _IOC_NRBITS) - 1;
5659+
const _IOC_TYPEMASK: u32 = (1 << _IOC_TYPEBITS) - 1;
5660+
const _IOC_SIZEMASK: u32 = (1 << _IOC_SIZEBITS) - 1;
5661+
const _IOC_DIRMASK: u32 = (1 << _IOC_DIRBITS) - 1;
5662+
5663+
const _IOC_NRSHIFT: u32 = 0;
5664+
const _IOC_TYPESHIFT: u32 = _IOC_NRSHIFT + _IOC_NRBITS;
5665+
const _IOC_SIZESHIFT: u32 = _IOC_TYPESHIFT + _IOC_TYPEBITS;
5666+
const _IOC_DIRSHIFT: u32 = _IOC_SIZESHIFT + _IOC_SIZEBITS;
5667+
5668+
// adapted from https://github.com/torvalds/linux/blob/8a696a29c6905594e4abf78eaafcb62165ac61f1/rust/kernel/ioctl.rs
5669+
5670+
/// Build an ioctl number, analogous to the C macro of the same name.
5671+
const fn _IOC(dir: u32, ty: u32, nr: u32, size: usize) -> u32 {
5672+
// FIXME(ctest) the `garando_syntax` crate (used by ctest2 in the CI test suite)
5673+
// cannot currently parse these `debug_assert!`s
5674+
//
5675+
// debug_assert!(dir <= _IOC_DIRMASK);
5676+
// debug_assert!(ty <= _IOC_TYPEMASK);
5677+
// debug_assert!(nr <= _IOC_NRMASK);
5678+
// debug_assert!(size <= (_IOC_SIZEMASK as usize));
5679+
5680+
(dir << _IOC_DIRSHIFT)
5681+
| (ty << _IOC_TYPESHIFT)
5682+
| (nr << _IOC_NRSHIFT)
5683+
| ((size as u32) << _IOC_SIZESHIFT)
5684+
}
5685+
5686+
/// Build an ioctl number for an argumentless ioctl.
5687+
pub(crate) const fn _IO(ty: u32, nr: u32) -> u32 {
5688+
_IOC(_IOC_NONE, ty, nr, 0)
5689+
}
5690+
5691+
/// Build an ioctl number for an read-only ioctl.
5692+
pub(crate) const fn _IOR<T>(ty: u32, nr: u32) -> u32 {
5693+
_IOC(_IOC_READ, ty, nr, core::mem::size_of::<T>())
5694+
}
5695+
5696+
/// Build an ioctl number for an write-only ioctl.
5697+
pub(crate) const fn _IOW<T>(ty: u32, nr: u32) -> u32 {
5698+
_IOC(_IOC_WRITE, ty, nr, core::mem::size_of::<T>())
5699+
}
5700+
5701+
/// Build an ioctl number for a read-write ioctl.
5702+
pub(crate) const fn _IOWR<T>(ty: u32, nr: u32) -> u32 {
5703+
_IOC(_IOC_READ | _IOC_WRITE, ty, nr, core::mem::size_of::<T>())
5704+
}
5705+
56045706
f! {
56055707
pub fn NLA_ALIGN(len: ::c_int) -> ::c_int {
56065708
return ((len) + NLA_ALIGNTO - 1) & !(NLA_ALIGNTO - 1);

0 commit comments

Comments
 (0)