From 47a94d8f1a7443033c7da60644b333a9d122041b Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Mon, 25 Nov 2024 03:57:41 -0500 Subject: [PATCH 1/5] Reorder items to be more similar to `main` --- src/unix/linux_like/linux/mod.rs | 172 +++++++++++++++---------------- 1 file changed, 86 insertions(+), 86 deletions(-) diff --git a/src/unix/linux_like/linux/mod.rs b/src/unix/linux_like/linux/mod.rs index 56475e9970c8..d14d4dd8766f 100644 --- a/src/unix/linux_like/linux/mod.rs +++ b/src/unix/linux_like/linux/mod.rs @@ -922,92 +922,6 @@ s! { pub rec_seq: [::c_uchar; TLS_CIPHER_CHACHA20_POLY1305_REC_SEQ_SIZE], } - // #include - - pub struct epoll_params { - pub busy_poll_usecs: u32, - pub busy_poll_budget: u16, - pub prefer_busy_poll: u8, - pub __pad: u8, // Must be zero - } - - #[cfg_attr( - any( - target_pointer_width = "32", - target_arch = "x86_64", - target_arch = "powerpc64", - target_arch = "mips64", - target_arch = "mips64r6", - target_arch = "s390x", - target_arch = "sparc64", - target_arch = "aarch64", - target_arch = "riscv64", - target_arch = "riscv32", - target_arch = "loongarch64" - ), - repr(align(4)) - )] - #[cfg_attr( - not(any( - target_pointer_width = "32", - target_arch = "x86_64", - target_arch = "powerpc64", - target_arch = "mips64", - target_arch = "mips64r6", - target_arch = "s390x", - target_arch = "sparc64", - target_arch = "aarch64", - target_arch = "riscv64", - target_arch = "riscv32", - target_arch = "loongarch64" - )), - repr(align(8)) - )] - pub struct pthread_mutexattr_t { - #[doc(hidden)] - size: [u8; ::__SIZEOF_PTHREAD_MUTEXATTR_T], - } - - #[cfg_attr( - any(target_env = "musl", target_env = "ohos", target_pointer_width = "32"), - repr(align(4)) - )] - #[cfg_attr( - all( - not(target_env = "musl"), - not(target_env = "ohos"), - target_pointer_width = "64" - ), - repr(align(8)) - )] - pub struct pthread_rwlockattr_t { - #[doc(hidden)] - size: [u8; ::__SIZEOF_PTHREAD_RWLOCKATTR_T], - } - - #[repr(align(4))] - pub struct pthread_condattr_t { - #[doc(hidden)] - size: [u8; ::__SIZEOF_PTHREAD_CONDATTR_T], - } - - #[repr(align(4))] - pub struct pthread_barrierattr_t { - #[doc(hidden)] - size: [u8; ::__SIZEOF_PTHREAD_BARRIERATTR_T], - } - - #[repr(align(8))] - pub struct fanotify_event_metadata { - pub event_len: __u32, - pub vers: __u8, - pub reserved: __u8, - pub metadata_len: __u16, - pub mask: __u64, - pub fd: ::c_int, - pub pid: ::c_int, - } - // linux/wireless.h pub struct iw_param { @@ -1142,6 +1056,92 @@ s! { pub get_args: __u16, pub name: [c_char; ::IFNAMSIZ], } + + // #include + + pub struct epoll_params { + pub busy_poll_usecs: u32, + pub busy_poll_budget: u16, + pub prefer_busy_poll: u8, + pub __pad: u8, // Must be zero + } + + #[cfg_attr( + any( + target_pointer_width = "32", + target_arch = "x86_64", + target_arch = "powerpc64", + target_arch = "mips64", + target_arch = "mips64r6", + target_arch = "s390x", + target_arch = "sparc64", + target_arch = "aarch64", + target_arch = "riscv64", + target_arch = "riscv32", + target_arch = "loongarch64" + ), + repr(align(4)) + )] + #[cfg_attr( + not(any( + target_pointer_width = "32", + target_arch = "x86_64", + target_arch = "powerpc64", + target_arch = "mips64", + target_arch = "mips64r6", + target_arch = "s390x", + target_arch = "sparc64", + target_arch = "aarch64", + target_arch = "riscv64", + target_arch = "riscv32", + target_arch = "loongarch64" + )), + repr(align(8)) + )] + pub struct pthread_mutexattr_t { + #[doc(hidden)] + size: [u8; ::__SIZEOF_PTHREAD_MUTEXATTR_T], + } + + #[cfg_attr( + any(target_env = "musl", target_env = "ohos", target_pointer_width = "32"), + repr(align(4)) + )] + #[cfg_attr( + all( + not(target_env = "musl"), + not(target_env = "ohos"), + target_pointer_width = "64" + ), + repr(align(8)) + )] + pub struct pthread_rwlockattr_t { + #[doc(hidden)] + size: [u8; ::__SIZEOF_PTHREAD_RWLOCKATTR_T], + } + + #[repr(align(4))] + pub struct pthread_condattr_t { + #[doc(hidden)] + size: [u8; ::__SIZEOF_PTHREAD_CONDATTR_T], + } + + #[repr(align(4))] + pub struct pthread_barrierattr_t { + #[doc(hidden)] + size: [u8; ::__SIZEOF_PTHREAD_BARRIERATTR_T], + } + + #[repr(align(8))] + pub struct fanotify_event_metadata { + pub event_len: __u32, + pub vers: __u8, + pub reserved: __u8, + pub metadata_len: __u16, + pub mask: __u64, + pub fd: ::c_int, + pub pid: ::c_int, + } } cfg_if! { From d0ed18d50fe28c7ab94c8a90cd10783f45ccada2 Mon Sep 17 00:00:00 2001 From: Folkert de Vries Date: Tue, 19 Nov 2024 19:43:39 +0100 Subject: [PATCH 2/5] add various `ptp_*` structs code is originally from https://github.com/rust-lang/libc/pull/3865. (backport ) (cherry picked from commit 511a00212d75abfc0f3e6bbd450ba953843c5291) --- libc-test/build.rs | 17 ++++++- libc-test/semver/linux.txt | 13 ++++++ src/unix/linux_like/linux/mod.rs | 77 ++++++++++++++++++++++++++++++++ 3 files changed, 106 insertions(+), 1 deletion(-) diff --git a/libc-test/build.rs b/libc-test/build.rs index c8b1297d691a..87848b1a21ba 100644 --- a/libc-test/build.rs +++ b/libc-test/build.rs @@ -3617,6 +3617,8 @@ fn test_linux(target: &str) { "linux/netlink.h", // FIXME: requires Linux >= 5.6: [!musl]: "linux/openat2.h", + // FIXME: some items require Linux >= 5.6: + "linux/ptp_clock.h", [!musl]: "linux/ptrace.h", "linux/quota.h", "linux/random.h", @@ -3766,6 +3768,11 @@ fn test_linux(target: &str) { return true; } + // FIXME: CI has old headers + if ty == "ptp_sys_offset_extended" { + return true; + } + // LFS64 types have been removed in musl 1.2.4+ if musl && (ty.ends_with("64") || ty.ends_with("64_t")) { return true; @@ -4490,7 +4497,11 @@ fn test_linux(target: &str) { // `__exit_status` type is a patch which is absent in musl (struct_ == "utmpx" && field == "ut_exit" && musl) || // `can_addr` is an anonymous union - (struct_ == "sockaddr_can" && field == "can_addr") + (struct_ == "sockaddr_can" && field == "can_addr") || + // `anonymous_1` is an anonymous union + (struct_ == "ptp_perout_request" && field == "anonymous_1") || + // `anonymous_2` is an anonymous union + (struct_ == "ptp_perout_request" && field == "anonymous_2") }); cfg.volatile_item(|i| { @@ -4561,6 +4572,10 @@ fn test_linux(target: &str) { (struct_ == "fanotify_event_info_fid" && field == "fsid") || // `handle` is a VLA (struct_ == "fanotify_event_info_fid" && field == "handle") || + // `anonymous_1` is an anonymous union + (struct_ == "ptp_perout_request" && field == "anonymous_1") || + // `anonymous_2` is an anonymous union + (struct_ == "ptp_perout_request" && field == "anonymous_2") || // invalid application of 'sizeof' to incomplete type 'long unsigned int[]' (musl && struct_ == "mcontext_t" && field == "__extcontext" && loongarch64) || // FIXME(#4121): a new field was added from `f_spare` diff --git a/libc-test/semver/linux.txt b/libc-test/semver/linux.txt index 5557664a1ab0..50f6537cdf93 100644 --- a/libc-test/semver/linux.txt +++ b/libc-test/semver/linux.txt @@ -2252,6 +2252,7 @@ PTHREAD_PRIO_PROTECT PTHREAD_PROCESS_PRIVATE PTHREAD_PROCESS_SHARED PTHREAD_STACK_MIN +PTP_MAX_SAMPLES PTRACE_ATTACH PTRACE_CONT PTRACE_DETACH @@ -3558,11 +3559,15 @@ __WNOTHREAD __c_anonymous_ifc_ifcu __c_anonymous_ifr_ifru __c_anonymous_ifru_map +__c_anonymous_ptp_perout_request_1 +__c_anonymous_ptp_perout_request_2 __c_anonymous_sockaddr_can_can_addr __c_anonymous_sockaddr_can_j1939 __c_anonymous_sockaddr_can_tp __errno_location __exit_status +__kernel_clockid_t +__kernel_fsid_t __s16 __s32 __u16 @@ -3916,6 +3921,14 @@ pthread_spin_lock pthread_spin_trylock pthread_spin_unlock pthread_spinlock_t +ptp_clock_time +ptp_extts_event +ptp_extts_request +ptp_perout_request +ptp_pin_desc +ptp_sys_offset +ptp_sys_offset_extended +ptp_sys_offset_precise ptrace ptsname_r pwrite64 diff --git a/src/unix/linux_like/linux/mod.rs b/src/unix/linux_like/linux/mod.rs index d14d4dd8766f..46c925b818b5 100644 --- a/src/unix/linux_like/linux/mod.rs +++ b/src/unix/linux_like/linux/mod.rs @@ -19,6 +19,7 @@ pub type pthread_key_t = ::c_uint; pub type pthread_once_t = ::c_int; pub type pthread_spinlock_t = ::c_int; pub type __kernel_fsid_t = __c_anonymous__kernel_fsid_t; +pub type __kernel_clockid_t = ::c_int; pub type __u8 = ::c_uchar; pub type __u16 = ::c_ushort; @@ -829,6 +830,40 @@ s! { pub resolve: ::__u64, } + // linux/ptp_clock.h + pub struct ptp_clock_time { + pub sec: ::__s64, + pub nsec: ::__u32, + pub reserved: ::__u32, + } + + pub struct ptp_extts_request { + pub index: ::c_uint, + pub flags: ::c_uint, + pub rsv: [::c_uint; 2], + } + + pub struct ptp_sys_offset_extended { + pub n_samples: ::c_uint, + pub clockid: __kernel_clockid_t, + pub rsv: [::c_uint; 2], + pub ts: [[ptp_clock_time; 3]; PTP_MAX_SAMPLES as usize], + } + + pub struct ptp_sys_offset_precise { + pub device: ptp_clock_time, + pub sys_realtime: ptp_clock_time, + pub sys_monoraw: ptp_clock_time, + pub rsv: [::c_uint; 4], + } + + pub struct ptp_extts_event { + pub t: ptp_clock_time, + index: ::c_uint, + flags: ::c_uint, + rsv: [::c_uint; 2], + } + // linux/sctp.h pub struct sctp_initmsg { @@ -1142,6 +1177,23 @@ s! { pub fd: ::c_int, pub pid: ::c_int, } + + // linux/ptp_clock.h + + pub struct ptp_sys_offset { + pub n_samples: ::c_uint, + pub rsv: [::c_uint; 3], + // FIXME(garando): replace length with `2 * PTP_MAX_SAMPLES + 1` when supported + pub ts: [ptp_clock_time; 51], + } + + pub struct ptp_pin_desc { + pub name: [::c_char; 64], + pub index: ::c_uint, + pub func: ::c_uint, + pub chan: ::c_uint, + pub rsv: [::c_uint; 5], + } } cfg_if! { @@ -1580,6 +1632,28 @@ s_no_extra_traits! { pub ifr_ifrn: __c_anonymous_iwreq, pub u: iwreq_data, } + + // linux/ptp_clock.h + #[allow(missing_debug_implementations)] + pub union __c_anonymous_ptp_perout_request_1 { + pub start: ptp_clock_time, + pub phase: ptp_clock_time, + } + + #[allow(missing_debug_implementations)] + pub union __c_anonymous_ptp_perout_request_2 { + pub on: ptp_clock_time, + pub rsv: [::c_uint; 4], + } + + #[allow(missing_debug_implementations)] + pub struct ptp_perout_request { + pub anonymous_1: __c_anonymous_ptp_perout_request_1, + pub period: ptp_clock_time, + pub index: ::c_uint, + pub flags: ::c_uint, + pub anonymous_2: __c_anonymous_ptp_perout_request_2, + } } cfg_if! { @@ -4504,6 +4578,9 @@ pub const HWTSTAMP_FILTER_PTP_V2_SYNC: ::c_uint = 13; pub const HWTSTAMP_FILTER_PTP_V2_DELAY_REQ: ::c_uint = 14; pub const HWTSTAMP_FILTER_NTP_ALL: ::c_uint = 15; +// linux/ptp_clock.h +pub const PTP_MAX_SAMPLES: ::c_uint = 25; // Maximum allowed offset measurement samples. + // linux/tls.h pub const TLS_TX: ::c_int = 1; pub const TLS_RX: ::c_int = 2; From 214e43a2b8a126940f69af1f231c50125fdb6a3f Mon Sep 17 00:00:00 2001 From: Folkert de Vries Date: Tue, 19 Nov 2024 21:42:17 +0100 Subject: [PATCH 3/5] add `ptp_pin_function` and most `PTP_` constants We cannot (apparently) use a type alias for `ptp_pin_function` because CI is unhappy with that (e.g. https://github.com/rust-lang/libc/actions/runs/11921706273/job/33226419934?pr=4114) We can always add that type alias later; it's not a breaking change (backport ) (cherry picked from commit a2ec6424d0d6781902b34142e7d89cea8cec202e) --- libc-test/build.rs | 16 +++++ libc-test/semver/linux.txt | 20 ++++++ src/unix/linux_like/linux/mod.rs | 110 +++++++++++++++++++++++++++++++ 3 files changed, 146 insertions(+) diff --git a/libc-test/build.rs b/libc-test/build.rs index 87848b1a21ba..42ccecdda953 100644 --- a/libc-test/build.rs +++ b/libc-test/build.rs @@ -3968,6 +3968,22 @@ fn test_linux(target: &str) { { return true; } + // FIXME: Requires >= 4.20 kernel headers + if name == "PTP_SYS_OFFSET_EXTENDED" { + return true; + } + // FIXME: Requires >= 5.4 kernel headers + if name == "PTP_ENABLE_PPS2" + || name == "PTP_EXTTS_REQUEST2" + || name == "PTP_PEROUT_REQUEST2" + || name == "PTP_PIN_GETFUNC2" + || name == "PTP_PIN_SETFUNC2" + || name == "PTP_SYS_OFFSET2" + || name == "PTP_SYS_OFFSET_PRECISE2" + || name == "PTP_SYS_OFFSET_EXTENDED2" + { + return true; + } // FIXME: Requires >= 5.4.1 kernel headers if name.starts_with("J1939") || name.starts_with("RTEXT_FILTER_") diff --git a/libc-test/semver/linux.txt b/libc-test/semver/linux.txt index 50f6537cdf93..78dccdfb72e7 100644 --- a/libc-test/semver/linux.txt +++ b/libc-test/semver/linux.txt @@ -2252,7 +2252,27 @@ PTHREAD_PRIO_PROTECT PTHREAD_PROCESS_PRIVATE PTHREAD_PROCESS_SHARED PTHREAD_STACK_MIN +PTP_ENABLE_PPS +PTP_ENABLE_PPS2 +PTP_EXTTS_REQUEST +PTP_EXTTS_REQUEST2 PTP_MAX_SAMPLES +PTP_PEROUT_REQUEST +PTP_PEROUT_REQUEST2 +PTP_PF_EXTTS +PTP_PF_NONE +PTP_PF_PEROUT +PTP_PF_PHYSYNC +PTP_PIN_GETFUNC +PTP_PIN_GETFUNC2 +PTP_PIN_SETFUNC +PTP_PIN_SETFUNC2 +PTP_SYS_OFFSET +PTP_SYS_OFFSET2 +PTP_SYS_OFFSET_EXTENDED +PTP_SYS_OFFSET_EXTENDED2 +PTP_SYS_OFFSET_PRECISE +PTP_SYS_OFFSET_PRECISE2 PTRACE_ATTACH PTRACE_CONT PTRACE_DETACH diff --git a/src/unix/linux_like/linux/mod.rs b/src/unix/linux_like/linux/mod.rs index 46c925b818b5..b1df6ebef07c 100644 --- a/src/unix/linux_like/linux/mod.rs +++ b/src/unix/linux_like/linux/mod.rs @@ -4581,6 +4581,36 @@ pub const HWTSTAMP_FILTER_NTP_ALL: ::c_uint = 15; // linux/ptp_clock.h pub const PTP_MAX_SAMPLES: ::c_uint = 25; // Maximum allowed offset measurement samples. +const PTP_CLK_MAGIC: u32 = b'=' as u32; + +// FIXME: needs the ptp_clock_caps struct +// pub const PTP_CLOCK_GETCAPS: ::c_uint = _IOR::(PTP_CLK_MAGIC, 1); +pub const PTP_EXTTS_REQUEST: ::c_uint = _IOW::(PTP_CLK_MAGIC, 2); +pub const PTP_PEROUT_REQUEST: ::c_uint = _IOW::(PTP_CLK_MAGIC, 3); +pub const PTP_ENABLE_PPS: ::c_uint = _IOW::<::c_int>(PTP_CLK_MAGIC, 4); +pub const PTP_SYS_OFFSET: ::c_uint = _IOW::(PTP_CLK_MAGIC, 5); +pub const PTP_PIN_GETFUNC: ::c_uint = _IOWR::(PTP_CLK_MAGIC, 6); +pub const PTP_PIN_SETFUNC: ::c_uint = _IOW::(PTP_CLK_MAGIC, 7); +pub const PTP_SYS_OFFSET_PRECISE: ::c_uint = _IOWR::(PTP_CLK_MAGIC, 8); +pub const PTP_SYS_OFFSET_EXTENDED: ::c_uint = _IOWR::(PTP_CLK_MAGIC, 9); + +// FIXME: needs the ptp_clock_caps struct +// pub const PTP_CLOCK_GETCAPS2: ::c_uint = _IOR::(PTP_CLK_MAGIC, 10); +pub const PTP_EXTTS_REQUEST2: ::c_uint = _IOW::(PTP_CLK_MAGIC, 11); +pub const PTP_PEROUT_REQUEST2: ::c_uint = _IOW::(PTP_CLK_MAGIC, 12); +pub const PTP_ENABLE_PPS2: ::c_uint = _IOW::<::c_int>(PTP_CLK_MAGIC, 13); +pub const PTP_SYS_OFFSET2: ::c_uint = _IOW::(PTP_CLK_MAGIC, 14); +pub const PTP_PIN_GETFUNC2: ::c_uint = _IOWR::(PTP_CLK_MAGIC, 15); +pub const PTP_PIN_SETFUNC2: ::c_uint = _IOW::(PTP_CLK_MAGIC, 16); +pub const PTP_SYS_OFFSET_PRECISE2: ::c_uint = _IOWR::(PTP_CLK_MAGIC, 17); +pub const PTP_SYS_OFFSET_EXTENDED2: ::c_uint = _IOWR::(PTP_CLK_MAGIC, 18); + +// enum ptp_pin_function +pub const PTP_PF_NONE: ::c_uint = 0; +pub const PTP_PF_EXTTS: ::c_uint = 1; +pub const PTP_PF_PEROUT: ::c_uint = 2; +pub const PTP_PF_PHYSYNC: ::c_uint = 3; + // linux/tls.h pub const TLS_TX: ::c_int = 1; pub const TLS_RX: ::c_int = 2; @@ -5635,6 +5665,86 @@ 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; + +// 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 ctest2 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(crate) const fn _IO(ty: u32, nr: u32) -> u32 { + _IOC(_IOC_NONE, ty, nr, 0) +} + +/// Build an ioctl number for an read-only ioctl. +pub(crate) const fn _IOR(ty: u32, nr: u32) -> u32 { + _IOC(_IOC_READ, ty, nr, core::mem::size_of::()) +} + +/// Build an ioctl number for an write-only ioctl. +pub(crate) const fn _IOW(ty: u32, nr: u32) -> u32 { + _IOC(_IOC_WRITE, ty, nr, core::mem::size_of::()) +} + +/// Build an ioctl number for a read-write ioctl. +pub(crate) const fn _IOWR(ty: u32, nr: u32) -> u32 { + _IOC(_IOC_READ | _IOC_WRITE, ty, nr, core::mem::size_of::()) +} + f! { pub fn NLA_ALIGN(len: ::c_int) -> ::c_int { return ((len) + NLA_ALIGNTO - 1) & !(NLA_ALIGNTO - 1); From e28e2ec99897dbed8f149e4b9ee1401f01ca8b98 Mon Sep 17 00:00:00 2001 From: arctic-alpaca <67190338+arctic-alpaca@users.noreply.github.com> Date: Wed, 20 Nov 2024 19:42:50 +0100 Subject: [PATCH 4/5] update/add missing AF_XDP structs & constants (backport ) (cherry picked from commit 6bc41c9ce4cb22672db71a7f54f8f733c717f31b) --- libc-test/build.rs | 36 +++++++++++++++++++++++++-- libc-test/semver/linux-gnu.txt | 5 ++++ libc-test/semver/linux-musl.txt | 5 ++++ src/unix/linux_like/linux/gnu/mod.rs | 28 +++++++++++++++++++++ src/unix/linux_like/linux/musl/mod.rs | 28 +++++++++++++++++++++ 5 files changed, 100 insertions(+), 2 deletions(-) diff --git a/libc-test/build.rs b/libc-test/build.rs index 42ccecdda953..37696ea67030 100644 --- a/libc-test/build.rs +++ b/libc-test/build.rs @@ -3888,12 +3888,25 @@ fn test_linux(target: &str) { // FIXME: Requires >= 5.4 kernel headers. // Everything that uses install-musl.sh has 4.19 kernel headers. - "xdp_umem_reg" | "xdp_ring_offset" | "xdp_mmap_offsets" if musl => true, + "xdp_ring_offset" | "xdp_mmap_offsets" if musl => true, + + // FIXME: Requires >= 6.8 kernel headers. + // A field was added in 6.8. + // https://github.com/torvalds/linux/commit/341ac980eab90ac1f6c22ee9f9da83ed9604d899 + // The previous version of the struct was removed in 6.11 due to a bug. + // https://github.com/torvalds/linux/commit/32654bbd6313b4cfc82297e6634fa9725c3c900f + "xdp_umem_reg" => true, // FIXME: Requires >= 5.9 kernel headers. // Everything that uses install-musl.sh has 4.19 kernel headers. "xdp_statistics" if musl => true, + // FIXME: Requires >= 6.8 kernel headers. + "xsk_tx_metadata" + | "__c_anonymous_xsk_tx_metadata_union" + | "xsk_tx_metadata_request" + | "xsk_tx_metadata_completion" => true, + // A new field was added in kernel 5.4, this is the old version for backwards compatibility. // https://github.com/torvalds/linux/commit/77cd0d7b3f257fd0e3096b4fdcff1a7d38e99e10 "xdp_ring_offset_v1" | "xdp_mmap_offsets_v1" => true, @@ -4338,6 +4351,23 @@ fn test_linux(target: &str) { true } + // FIXME: Requires >= 6.8 kernel headers. + "XDP_UMEM_TX_SW_CSUM" + | "XDP_TXMD_FLAGS_TIMESTAMP" + | "XDP_TXMD_FLAGS_CHECKSUM" + | "XDP_TX_METADATA" + => + { + true + } + + // FIXME: Requires >= 6.11 kernel headers. + "XDP_UMEM_TX_METADATA_LEN" + => + { + true + } + // FIXME: Requires >= 6.6 kernel headers. "SYS_fchmodat2" => true, @@ -4596,7 +4626,9 @@ fn test_linux(target: &str) { (musl && struct_ == "mcontext_t" && field == "__extcontext" && loongarch64) || // FIXME(#4121): a new field was added from `f_spare` (struct_ == "statvfs" && field == "__f_spare") || - (struct_ == "statvfs64" && field == "__f_spare") + (struct_ == "statvfs64" && field == "__f_spare") || + // the `xsk_tx_metadata_union` field is an anonymous union + (struct_ == "xsk_tx_metadata" && field == "xsk_tx_metadata_union") }); cfg.skip_roundtrip(move |s| match s { diff --git a/libc-test/semver/linux-gnu.txt b/libc-test/semver/linux-gnu.txt index 83dd825584cd..87fb4e480f7f 100644 --- a/libc-test/semver/linux-gnu.txt +++ b/libc-test/semver/linux-gnu.txt @@ -489,12 +489,17 @@ XDP_RING_NEED_WAKEUP XDP_RX_RING XDP_SHARED_UMEM XDP_STATISTICS +XDP_TXMD_FLAGS_CHECKSUM +XDP_TXMD_FLAGS_TIMESTAMP +XDP_TX_METADATA XDP_TX_RING XDP_UMEM_COMPLETION_RING XDP_UMEM_FILL_RING XDP_UMEM_PGOFF_COMPLETION_RING XDP_UMEM_PGOFF_FILL_RING XDP_UMEM_REG +XDP_UMEM_TX_METADATA_LEN +XDP_UMEM_TX_SW_CSUM XDP_UMEM_UNALIGNED_CHUNK_FLAG XDP_USE_NEED_WAKEUP XDP_USE_SG diff --git a/libc-test/semver/linux-musl.txt b/libc-test/semver/linux-musl.txt index 62b188dac828..802e1477ca47 100644 --- a/libc-test/semver/linux-musl.txt +++ b/libc-test/semver/linux-musl.txt @@ -48,12 +48,17 @@ XDP_RING_NEED_WAKEUP XDP_RX_RING XDP_SHARED_UMEM XDP_STATISTICS +XDP_TXMD_FLAGS_CHECKSUM +XDP_TXMD_FLAGS_TIMESTAMP +XDP_TX_METADATA XDP_TX_RING XDP_UMEM_COMPLETION_RING XDP_UMEM_FILL_RING XDP_UMEM_PGOFF_COMPLETION_RING XDP_UMEM_PGOFF_FILL_RING XDP_UMEM_REG +XDP_UMEM_TX_METADATA_LEN +XDP_UMEM_TX_SW_CSUM XDP_UMEM_UNALIGNED_CHUNK_FLAG XDP_USE_NEED_WAKEUP XDP_USE_SG diff --git a/src/unix/linux_like/linux/gnu/mod.rs b/src/unix/linux_like/linux/gnu/mod.rs index f35a80794235..0f92ac110fea 100644 --- a/src/unix/linux_like/linux/gnu/mod.rs +++ b/src/unix/linux_like/linux/gnu/mod.rs @@ -401,6 +401,7 @@ s! { pub chunk_size: ::__u32, pub headroom: ::__u32, pub flags: ::__u32, + pub tx_metadata_len: ::__u32, } pub struct xdp_umem_reg_v1 { @@ -435,6 +436,15 @@ s! { pub options: ::__u32, } + pub struct xsk_tx_metadata_completion { + pub tx_timestamp: ::__u64, + } + + pub struct xsk_tx_metadata_request { + pub csum_start: ::__u16, + pub csum_offset: ::__u16, + } + pub struct iocb { pub aio_data: ::__u64, #[cfg(target_endian = "little")] @@ -656,6 +666,18 @@ s_no_extra_traits! { pub ut_addr_v6: [i32; 4], __glibc_reserved: [::c_char; 20], } + + #[allow(missing_debug_implementations)] + pub struct xsk_tx_metadata { + pub flags: ::__u64, + pub xsk_tx_metadata_union: __c_anonymous_xsk_tx_metadata_union, + } + + #[allow(missing_debug_implementations)] + pub union __c_anonymous_xsk_tx_metadata_union { + pub request: xsk_tx_metadata_request, + pub completion: xsk_tx_metadata_completion, + } } cfg_if! { @@ -1087,6 +1109,8 @@ pub const XDP_USE_NEED_WAKEUP: ::__u16 = 1 << 3; pub const XDP_USE_SG: ::__u16 = 1 << 4; pub const XDP_UMEM_UNALIGNED_CHUNK_FLAG: ::__u32 = 1 << 0; +pub const XDP_UMEM_TX_SW_CSUM: ::__u32 = 1 << 1; +pub const XDP_UMEM_TX_METADATA_LEN: ::__u32 = 1 << 2; pub const XDP_RING_NEED_WAKEUP: ::__u32 = 1 << 0; @@ -1109,7 +1133,11 @@ pub const XDP_UMEM_PGOFF_COMPLETION_RING: ::c_ulonglong = 0x180000000; pub const XSK_UNALIGNED_BUF_OFFSET_SHIFT: ::c_int = 48; pub const XSK_UNALIGNED_BUF_ADDR_MASK: ::c_ulonglong = (1 << XSK_UNALIGNED_BUF_OFFSET_SHIFT) - 1; +pub const XDP_TXMD_FLAGS_TIMESTAMP: ::__u32 = 1 << 0; +pub const XDP_TXMD_FLAGS_CHECKSUM: ::__u32 = 1 << 1; + pub const XDP_PKT_CONTD: ::__u32 = 1 << 0; +pub const XDP_TX_METADATA: ::__u32 = 1 << 1; pub const ELFOSABI_ARM_AEABI: u8 = 64; diff --git a/src/unix/linux_like/linux/musl/mod.rs b/src/unix/linux_like/linux/musl/mod.rs index 3c13e3a3d131..82d319ff0864 100644 --- a/src/unix/linux_like/linux/musl/mod.rs +++ b/src/unix/linux_like/linux/musl/mod.rs @@ -311,6 +311,7 @@ s! { pub chunk_size: ::__u32, pub headroom: ::__u32, pub flags: ::__u32, + pub tx_metadata_len: ::__u32, } pub struct xdp_umem_reg_v1 { @@ -345,6 +346,15 @@ s! { pub options: ::__u32, } + pub struct xsk_tx_metadata_completion { + pub tx_timestamp: ::__u64, + } + + pub struct xsk_tx_metadata_request { + pub csum_start: ::__u16, + pub csum_offset: ::__u16, + } + // netinet/tcp.h pub struct tcp_info { @@ -482,6 +492,18 @@ s_no_extra_traits! { pub ut_addr_v6: [::c_uint; 4], __unused: [::c_char; 20], } + + #[allow(missing_debug_implementations)] + pub struct xsk_tx_metadata { + pub flags: ::__u64, + pub xsk_tx_metadata_union: __c_anonymous_xsk_tx_metadata_union, + } + + #[allow(missing_debug_implementations)] + pub union __c_anonymous_xsk_tx_metadata_union { + pub request: xsk_tx_metadata_request, + pub completion: xsk_tx_metadata_completion, + } } cfg_if! { @@ -887,6 +909,8 @@ pub const XDP_USE_NEED_WAKEUP: ::__u16 = 1 << 3; pub const XDP_USE_SG: ::__u16 = 1 << 4; pub const XDP_UMEM_UNALIGNED_CHUNK_FLAG: ::__u32 = 1 << 0; +pub const XDP_UMEM_TX_SW_CSUM: ::__u32 = 1 << 1; +pub const XDP_UMEM_TX_METADATA_LEN: ::__u32 = 1 << 2; pub const XDP_RING_NEED_WAKEUP: ::__u32 = 1 << 0; @@ -909,7 +933,11 @@ pub const XDP_UMEM_PGOFF_COMPLETION_RING: ::c_ulonglong = 0x180000000; pub const XSK_UNALIGNED_BUF_OFFSET_SHIFT: ::c_int = 48; pub const XSK_UNALIGNED_BUF_ADDR_MASK: ::c_ulonglong = (1 << XSK_UNALIGNED_BUF_OFFSET_SHIFT) - 1; +pub const XDP_TXMD_FLAGS_TIMESTAMP: ::__u32 = 1 << 0; +pub const XDP_TXMD_FLAGS_CHECKSUM: ::__u32 = 1 << 1; + pub const XDP_PKT_CONTD: ::__u32 = 1 << 0; +pub const XDP_TX_METADATA: ::__u32 = 1 << 1; pub const _CS_V6_ENV: ::c_int = 1148; pub const _CS_V7_ENV: ::c_int = 1149; From 19464c3aaf354dde7e80458833169cb1a229869e Mon Sep 17 00:00:00 2001 From: arctic-alpaca <67190338+arctic-alpaca@users.noreply.github.com> Date: Wed, 20 Nov 2024 21:10:43 +0100 Subject: [PATCH 5/5] move changes to `src/unix/linux_like/linux/mod.rs` (backport ) (cherry picked from commit 88aa42a2c6a7addf3ab66dd77cbd014e0af6181c) --- libc-test/semver/linux-gnu.txt | 5 ----- libc-test/semver/linux-musl.txt | 5 ----- libc-test/semver/linux.txt | 5 +++++ src/unix/linux_like/linux/gnu/mod.rs | 27 ---------------------- src/unix/linux_like/linux/mod.rs | 32 +++++++++++++++++++++++++++ src/unix/linux_like/linux/musl/mod.rs | 27 ---------------------- 6 files changed, 37 insertions(+), 64 deletions(-) diff --git a/libc-test/semver/linux-gnu.txt b/libc-test/semver/linux-gnu.txt index 87fb4e480f7f..83dd825584cd 100644 --- a/libc-test/semver/linux-gnu.txt +++ b/libc-test/semver/linux-gnu.txt @@ -489,17 +489,12 @@ XDP_RING_NEED_WAKEUP XDP_RX_RING XDP_SHARED_UMEM XDP_STATISTICS -XDP_TXMD_FLAGS_CHECKSUM -XDP_TXMD_FLAGS_TIMESTAMP -XDP_TX_METADATA XDP_TX_RING XDP_UMEM_COMPLETION_RING XDP_UMEM_FILL_RING XDP_UMEM_PGOFF_COMPLETION_RING XDP_UMEM_PGOFF_FILL_RING XDP_UMEM_REG -XDP_UMEM_TX_METADATA_LEN -XDP_UMEM_TX_SW_CSUM XDP_UMEM_UNALIGNED_CHUNK_FLAG XDP_USE_NEED_WAKEUP XDP_USE_SG diff --git a/libc-test/semver/linux-musl.txt b/libc-test/semver/linux-musl.txt index 802e1477ca47..62b188dac828 100644 --- a/libc-test/semver/linux-musl.txt +++ b/libc-test/semver/linux-musl.txt @@ -48,17 +48,12 @@ XDP_RING_NEED_WAKEUP XDP_RX_RING XDP_SHARED_UMEM XDP_STATISTICS -XDP_TXMD_FLAGS_CHECKSUM -XDP_TXMD_FLAGS_TIMESTAMP -XDP_TX_METADATA XDP_TX_RING XDP_UMEM_COMPLETION_RING XDP_UMEM_FILL_RING XDP_UMEM_PGOFF_COMPLETION_RING XDP_UMEM_PGOFF_FILL_RING XDP_UMEM_REG -XDP_UMEM_TX_METADATA_LEN -XDP_UMEM_TX_SW_CSUM XDP_UMEM_UNALIGNED_CHUNK_FLAG XDP_USE_NEED_WAKEUP XDP_USE_SG diff --git a/libc-test/semver/linux.txt b/libc-test/semver/linux.txt index 78dccdfb72e7..b9b20c596280 100644 --- a/libc-test/semver/linux.txt +++ b/libc-test/semver/linux.txt @@ -3388,6 +3388,11 @@ W_EXITCODE W_STOPCODE XATTR_CREATE XATTR_REPLACE +XDP_TXMD_FLAGS_CHECKSUM +XDP_TXMD_FLAGS_TIMESTAMP +XDP_TX_METADATA +XDP_UMEM_TX_METADATA_LEN +XDP_UMEM_TX_SW_CSUM XTABS YESEXPR YESSTR diff --git a/src/unix/linux_like/linux/gnu/mod.rs b/src/unix/linux_like/linux/gnu/mod.rs index 0f92ac110fea..7b9d84f967fd 100644 --- a/src/unix/linux_like/linux/gnu/mod.rs +++ b/src/unix/linux_like/linux/gnu/mod.rs @@ -436,15 +436,6 @@ s! { pub options: ::__u32, } - pub struct xsk_tx_metadata_completion { - pub tx_timestamp: ::__u64, - } - - pub struct xsk_tx_metadata_request { - pub csum_start: ::__u16, - pub csum_offset: ::__u16, - } - pub struct iocb { pub aio_data: ::__u64, #[cfg(target_endian = "little")] @@ -666,18 +657,6 @@ s_no_extra_traits! { pub ut_addr_v6: [i32; 4], __glibc_reserved: [::c_char; 20], } - - #[allow(missing_debug_implementations)] - pub struct xsk_tx_metadata { - pub flags: ::__u64, - pub xsk_tx_metadata_union: __c_anonymous_xsk_tx_metadata_union, - } - - #[allow(missing_debug_implementations)] - pub union __c_anonymous_xsk_tx_metadata_union { - pub request: xsk_tx_metadata_request, - pub completion: xsk_tx_metadata_completion, - } } cfg_if! { @@ -1109,8 +1088,6 @@ pub const XDP_USE_NEED_WAKEUP: ::__u16 = 1 << 3; pub const XDP_USE_SG: ::__u16 = 1 << 4; pub const XDP_UMEM_UNALIGNED_CHUNK_FLAG: ::__u32 = 1 << 0; -pub const XDP_UMEM_TX_SW_CSUM: ::__u32 = 1 << 1; -pub const XDP_UMEM_TX_METADATA_LEN: ::__u32 = 1 << 2; pub const XDP_RING_NEED_WAKEUP: ::__u32 = 1 << 0; @@ -1133,11 +1110,7 @@ pub const XDP_UMEM_PGOFF_COMPLETION_RING: ::c_ulonglong = 0x180000000; pub const XSK_UNALIGNED_BUF_OFFSET_SHIFT: ::c_int = 48; pub const XSK_UNALIGNED_BUF_ADDR_MASK: ::c_ulonglong = (1 << XSK_UNALIGNED_BUF_OFFSET_SHIFT) - 1; -pub const XDP_TXMD_FLAGS_TIMESTAMP: ::__u32 = 1 << 0; -pub const XDP_TXMD_FLAGS_CHECKSUM: ::__u32 = 1 << 1; - pub const XDP_PKT_CONTD: ::__u32 = 1 << 0; -pub const XDP_TX_METADATA: ::__u32 = 1 << 1; pub const ELFOSABI_ARM_AEABI: u8 = 64; diff --git a/src/unix/linux_like/linux/mod.rs b/src/unix/linux_like/linux/mod.rs index b1df6ebef07c..fe1f32a907a1 100644 --- a/src/unix/linux_like/linux/mod.rs +++ b/src/unix/linux_like/linux/mod.rs @@ -1194,6 +1194,16 @@ s! { pub chan: ::c_uint, pub rsv: [::c_uint; 5], } + + // linux/if_xdp.h + pub struct xsk_tx_metadata_completion { + pub tx_timestamp: ::__u64, + } + + pub struct xsk_tx_metadata_request { + pub csum_start: ::__u16, + pub csum_offset: ::__u16, + } } cfg_if! { @@ -1654,6 +1664,19 @@ s_no_extra_traits! { pub flags: ::c_uint, pub anonymous_2: __c_anonymous_ptp_perout_request_2, } + + // linux/if_xdp.h + #[allow(missing_debug_implementations)] + pub struct xsk_tx_metadata { + pub flags: ::__u64, + pub xsk_tx_metadata_union: __c_anonymous_xsk_tx_metadata_union, + } + + #[allow(missing_debug_implementations)] + pub union __c_anonymous_xsk_tx_metadata_union { + pub request: xsk_tx_metadata_request, + pub completion: xsk_tx_metadata_completion, + } } cfg_if! { @@ -5632,6 +5655,15 @@ pub const SCHED_FLAG_KEEP_PARAMS: ::c_int = 0x10; pub const SCHED_FLAG_UTIL_CLAMP_MIN: ::c_int = 0x20; pub const SCHED_FLAG_UTIL_CLAMP_MAX: ::c_int = 0x40; +// linux/if_xdp.h +pub const XDP_UMEM_TX_SW_CSUM: ::__u32 = 1 << 1; +pub const XDP_UMEM_TX_METADATA_LEN: ::__u32 = 1 << 2; + +pub const XDP_TXMD_FLAGS_TIMESTAMP: ::__u32 = 1 << 0; +pub const XDP_TXMD_FLAGS_CHECKSUM: ::__u32 = 1 << 1; + +pub const XDP_TX_METADATA: ::__u32 = 1 << 1; + // elf.h pub const NT_PRSTATUS: ::c_int = 1; pub const NT_PRFPREG: ::c_int = 2; diff --git a/src/unix/linux_like/linux/musl/mod.rs b/src/unix/linux_like/linux/musl/mod.rs index 82d319ff0864..ec295aa57deb 100644 --- a/src/unix/linux_like/linux/musl/mod.rs +++ b/src/unix/linux_like/linux/musl/mod.rs @@ -346,15 +346,6 @@ s! { pub options: ::__u32, } - pub struct xsk_tx_metadata_completion { - pub tx_timestamp: ::__u64, - } - - pub struct xsk_tx_metadata_request { - pub csum_start: ::__u16, - pub csum_offset: ::__u16, - } - // netinet/tcp.h pub struct tcp_info { @@ -492,18 +483,6 @@ s_no_extra_traits! { pub ut_addr_v6: [::c_uint; 4], __unused: [::c_char; 20], } - - #[allow(missing_debug_implementations)] - pub struct xsk_tx_metadata { - pub flags: ::__u64, - pub xsk_tx_metadata_union: __c_anonymous_xsk_tx_metadata_union, - } - - #[allow(missing_debug_implementations)] - pub union __c_anonymous_xsk_tx_metadata_union { - pub request: xsk_tx_metadata_request, - pub completion: xsk_tx_metadata_completion, - } } cfg_if! { @@ -909,8 +888,6 @@ pub const XDP_USE_NEED_WAKEUP: ::__u16 = 1 << 3; pub const XDP_USE_SG: ::__u16 = 1 << 4; pub const XDP_UMEM_UNALIGNED_CHUNK_FLAG: ::__u32 = 1 << 0; -pub const XDP_UMEM_TX_SW_CSUM: ::__u32 = 1 << 1; -pub const XDP_UMEM_TX_METADATA_LEN: ::__u32 = 1 << 2; pub const XDP_RING_NEED_WAKEUP: ::__u32 = 1 << 0; @@ -933,11 +910,7 @@ pub const XDP_UMEM_PGOFF_COMPLETION_RING: ::c_ulonglong = 0x180000000; pub const XSK_UNALIGNED_BUF_OFFSET_SHIFT: ::c_int = 48; pub const XSK_UNALIGNED_BUF_ADDR_MASK: ::c_ulonglong = (1 << XSK_UNALIGNED_BUF_OFFSET_SHIFT) - 1; -pub const XDP_TXMD_FLAGS_TIMESTAMP: ::__u32 = 1 << 0; -pub const XDP_TXMD_FLAGS_CHECKSUM: ::__u32 = 1 << 1; - pub const XDP_PKT_CONTD: ::__u32 = 1 << 0; -pub const XDP_TX_METADATA: ::__u32 = 1 << 1; pub const _CS_V6_ENV: ::c_int = 1148; pub const _CS_V7_ENV: ::c_int = 1149;