From 6a98f5ffd8b8f32c7d0d7e03064c4d4b07deef1a Mon Sep 17 00:00:00 2001 From: David Venhoek Date: Thu, 14 Sep 2023 16:59:55 +0200 Subject: [PATCH 01/25] Added all definitions from linux/ptp-clock.h --- libc-test/build.rs | 25 +++- libc-test/semver/linux.txt | 23 ++++ src/fuchsia/mod.rs | 65 ++++++---- src/unix/linux_like/linux/mod.rs | 202 +++++++++++++++++++++++++++++++ 4 files changed, 288 insertions(+), 27 deletions(-) diff --git a/libc-test/build.rs b/libc-test/build.rs index 9d97705a1444a..aa07b2682ba52 100644 --- a/libc-test/build.rs +++ b/libc-test/build.rs @@ -3552,6 +3552,8 @@ fn test_linux(target: &str) { "linux/netlink.h", // FIXME: requires Linux >= 5.6: [!musl]: "linux/openat2.h", + "linux/ptp_clock.h", + // FIXME: requires Linux >= 5.6: [!musl]: "linux/ptrace.h", "linux/quota.h", "linux/random.h", @@ -3700,6 +3702,9 @@ fn test_linux(target: &str) { if musl && ty == "seccomp_notif_sizes" { return true; } + if musl && 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")) { @@ -3889,6 +3894,7 @@ fn test_linux(target: &str) { if name == "SECCOMP_GET_NOTIF_SIZES" || name == "SECCOMP_FILTER_FLAG_NEW_LISTENER" || name == "SECCOMP_FILTER_FLAG_TSYNC_ESRCH" + || name == "PTP_SYS_OFFSET_EXTENDED" || name == "SECCOMP_USER_NOTIF_FLAG_CONTINUE" // requires >= 5.5 || name == "SECCOMP_ADDFD_FLAG_SETFD" // requires >= 5.9 || name == "SECCOMP_ADDFD_FLAG_SEND" // requires >= 5.9 @@ -3901,6 +3907,15 @@ fn test_linux(target: &str) { || name.starts_with("RTEXT_FILTER_") || name.starts_with("SO_J1939") || name.starts_with("SCM_J1939") + || name == "PTP_CLOCK_GETCAPS2" + || name == "PTP_EXTTS_REQUEST2" + || name == "PTP_PEROUT_REQUEST2" + || name == "PTP_ENABLE_PPS2" + || name == "PTP_SYS_OFFSET2" + || name == "PTP_PIN_GETFUNC2" + || name == "PTP_PIN_SETFUNC2" + || name == "PTP_SYS_OFFSET_PRECISE2" + || name == "PTP_SYS_OFFSET_EXTENDED2" { return true; } @@ -4422,7 +4437,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| { @@ -4495,6 +4514,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) }); diff --git a/libc-test/semver/linux.txt b/libc-test/semver/linux.txt index ced3f2b751508..6286abd032fbc 100644 --- a/libc-test/semver/linux.txt +++ b/libc-test/semver/linux.txt @@ -2252,6 +2252,29 @@ PTHREAD_PRIO_PROTECT PTHREAD_PROCESS_PRIVATE PTHREAD_PROCESS_SHARED PTHREAD_STACK_MIN +PTP_CLOCK_GETCAPS +PTP_CLOCK_GETCAPS2 +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/fuchsia/mod.rs b/src/fuchsia/mod.rs index 8d0010bbc12b6..df75b1eb05e21 100644 --- a/src/fuchsia/mod.rs +++ b/src/fuchsia/mod.rs @@ -121,7 +121,7 @@ impl ::Clone for fpos64_t { // PUB_STRUCT -s! { +fn s_fmt_tmp() { pub struct group { pub gr_name: *mut ::c_char, pub gr_passwd: *mut ::c_char, @@ -907,7 +907,7 @@ s! { } } -s_no_extra_traits! { +fn s_no_extra_traits_fmt_tmp() { pub struct sysinfo { pub uptime: ::c_ulong, pub loads: [::c_ulong; 3], @@ -1048,8 +1048,8 @@ s_no_extra_traits! { } } -cfg_if! { - if #[cfg(feature = "extra_traits")] { +fn cfg_if_fmt_tmp() { + if cfg_tmp!([feature = "extra_traits"]) { impl PartialEq for sysinfo { fn eq(&self, other: &sysinfo) -> bool { self.uptime == other.uptime @@ -3357,10 +3357,10 @@ pub const HUGETLB_FLAG_ENCODE_SHIFT: u32 = 26; pub const MAP_HUGE_SHIFT: u32 = 26; // intentionally not public, only used for fd_set -cfg_if! { - if #[cfg(target_pointer_width = "32")] { +fn cfg_if_fmt_tmp() { + if cfg_tmp!([target_pointer_width = "32"]) { const ULONG_SIZE: usize = 32; - } else if #[cfg(target_pointer_width = "64")] { + } else if cfg_tmp!([target_pointer_width = "64"]) { const ULONG_SIZE: usize = 64; } else { // Unknown target_pointer_width @@ -3369,7 +3369,7 @@ cfg_if! { // END_PUB_CONST -f! { +fn f_fmt_tmp() { pub fn FD_CLR(fd: ::c_int, set: *mut fd_set) -> () { let fd = fd as usize; let size = ::mem::size_of_val(&(*set).fds_bits[0]) * 8; @@ -3462,57 +3462,70 @@ f! { } } - pub {const} fn CMSG_ALIGN(len: ::size_t) -> ::size_t { + /* FMT-CONST */ + pub const fn CMSG_ALIGN(len: ::size_t) -> ::size_t { (len + ::mem::size_of::<::size_t>() - 1) & !(::mem::size_of::<::size_t>() - 1) } - pub {const} fn CMSG_SPACE(len: ::c_uint) -> ::c_uint { + /* FMT-CONST */ + pub const fn CMSG_SPACE(len: ::c_uint) -> ::c_uint { (CMSG_ALIGN(len as ::size_t) + CMSG_ALIGN(::mem::size_of::())) as ::c_uint } - pub {const} fn CMSG_LEN(len: ::c_uint) -> ::c_uint { + /* FMT-CONST */ + pub const fn CMSG_LEN(len: ::c_uint) -> ::c_uint { (CMSG_ALIGN(::mem::size_of::()) + len as ::size_t) as ::c_uint } } -safe_f! { - pub {const} fn WIFSTOPPED(status: ::c_int) -> bool { +fn safe_f_fmt_tmp() { + /* FMT-CONST */ + pub const fn WIFSTOPPED(status: ::c_int) -> bool { (status & 0xff) == 0x7f } - pub {const} fn WSTOPSIG(status: ::c_int) -> ::c_int { + /* FMT-CONST */ + pub const fn WSTOPSIG(status: ::c_int) -> ::c_int { (status >> 8) & 0xff } - pub {const} fn WIFCONTINUED(status: ::c_int) -> bool { + /* FMT-CONST */ + pub const fn WIFCONTINUED(status: ::c_int) -> bool { status == 0xffff } - pub {const} fn WIFSIGNALED(status: ::c_int) -> bool { + /* FMT-CONST */ + pub const fn WIFSIGNALED(status: ::c_int) -> bool { ((status & 0x7f) + 1) as i8 >= 2 } - pub {const} fn WTERMSIG(status: ::c_int) -> ::c_int { + /* FMT-CONST */ + pub const fn WTERMSIG(status: ::c_int) -> ::c_int { status & 0x7f } - pub {const} fn WIFEXITED(status: ::c_int) -> bool { + /* FMT-CONST */ + pub const fn WIFEXITED(status: ::c_int) -> bool { (status & 0x7f) == 0 } - pub {const} fn WEXITSTATUS(status: ::c_int) -> ::c_int { + /* FMT-CONST */ + pub const fn WEXITSTATUS(status: ::c_int) -> ::c_int { (status >> 8) & 0xff } - pub {const} fn WCOREDUMP(status: ::c_int) -> bool { + /* FMT-CONST */ + pub const fn WCOREDUMP(status: ::c_int) -> bool { (status & 0x80) != 0 } - pub {const} fn QCMD(cmd: ::c_int, type_: ::c_int) -> ::c_int { + /* FMT-CONST */ + pub const fn QCMD(cmd: ::c_int, type_: ::c_int) -> ::c_int { (cmd << 8) | (type_ & 0x00ff) } - pub {const} fn makedev(major: ::c_uint, minor: ::c_uint) -> ::dev_t { + /* FMT-CONST */ + pub const fn makedev(major: ::c_uint, minor: ::c_uint) -> ::dev_t { let major = major as ::dev_t; let minor = minor as ::dev_t; let mut dev = 0; @@ -4455,14 +4468,14 @@ extern "C" { ) -> ::c_int; } -cfg_if! { - if #[cfg(target_arch = "aarch64")] { +fn cfg_if_fmt_tmp() { + if cfg_tmp!([target_arch = "aarch64"]) { mod aarch64; pub use self::aarch64::*; - } else if #[cfg(any(target_arch = "x86_64"))] { + } else if cfg_tmp!([any(target_arch = "x86_64")]) { mod x86_64; pub use self::x86_64::*; - } else if #[cfg(any(target_arch = "riscv64"))] { + } else if cfg_tmp!([any(target_arch = "riscv64")]) { mod riscv64; pub use self::riscv64::*; } else { diff --git a/src/unix/linux_like/linux/mod.rs b/src/unix/linux_like/linux/mod.rs index 8e9f80a5d48d1..f829c7b6faa20 100644 --- a/src/unix/linux_like/linux/mod.rs +++ b/src/unix/linux_like/linux/mod.rs @@ -829,6 +829,57 @@ 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_clock_caps { + pub max_adj: ::c_int, + pub n_alarm: ::c_int, + pub n_ext_ts: ::c_int, + pub n_per_out: ::c_int, + pub pps: ::c_int, + pub n_pins: ::c_int, + pub cross_timestamping: ::c_int, + #[cfg(target_env = "gnu")] + pub adjust_phase: ::c_int, + #[cfg(target_env = "gnu")] + pub max_phase_adj: ::c_int, + #[cfg(target_env = "gnu")] + pub rsv: [::c_int; 11], + #[cfg(any(target_env = "musl", target_env = "ohos"))] + pub rsv: [::c_int; 13], + } + + 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 rsv: [::c_uint; 3], + pub ts: [[ptp_clock_time; 3]; 25], + } + + 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 { @@ -1331,6 +1382,21 @@ s_no_extra_traits! { pub hdr: ::tpacket_bd_header_u, } + // linux/ptp_clock.h + pub struct ptp_sys_offset { + pub n_samples: ::c_uint, + pub rsv: [::c_uint; 3], + 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_attr( all( any(target_env = "musl", target_env = "ohos"), @@ -1576,6 +1642,34 @@ s_no_extra_traits! { } } +cfg_if! { + if #[cfg(libc_union)] { + s_no_extra_traits! { + // 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! { if #[cfg(feature = "extra_traits")] { impl PartialEq for sockaddr_nl { @@ -2062,6 +2156,62 @@ cfg_if! { .finish() } } + + impl PartialEq for ptp_sys_offset { + fn eq(&self, other: &ptp_sys_offset) -> bool { + self.n_samples == other.n_samples && + self.rsv == other.rsv && + self.ts[..] == other.ts[..] + } + } + impl Eq for ptp_sys_offset {} + impl ::fmt::Debug for ptp_sys_offset { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("ptp_sys_offset") + .field("n_samples", &self.n_samples) + .field("rsv", &self.rsv) + .field("ts", &&self.ts[..]) + .finish() + } + } + impl ::hash::Hash for ptp_sys_offset { + fn hash(&self, state: &mut H) { + self.n_samples.hash(state); + self.rsv.hash(state); + self.ts[..].hash(state); + } + } + + impl PartialEq for ptp_pin_desc { + fn eq(&self, other: &ptp_pin_desc) -> bool { + self.name[..] == other.name[..] && + self.index == other.index && + self.func == other.func && + self.chan == other.chan && + self.rsv == other.rsv + } + } + impl Eq for ptp_pin_desc {} + impl ::fmt::Debug for ptp_pin_desc { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("ptp_pin_desc") + .field("name", &&self.name[..]) + .field("index", &self.index) + .field("func", &self.func) + .field("chan", &self.chan) + .field("rsv", &self.rsv) + .finish() + } + } + impl ::hash::Hash for ptp_pin_desc { + fn hash(&self, state: &mut H) { + self.name[..].hash(state); + self.index.hash(state); + self.func.hash(state); + self.chan.hash(state); + self.rsv.hash(state); + } + } } } @@ -4464,6 +4614,58 @@ 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; + +cfg_if! { + if #[cfg(any(target_arch = "powerpc", target_arch = "powerpc64", target_arch = "sparc64"))] { + pub const PTP_CLOCK_GETCAPS: ::c_uint = 0x40503d01; + pub const PTP_EXTTS_REQUEST: ::c_uint = 0x80103d02; + pub const PTP_PEROUT_REQUEST: ::c_uint = 0x80383d03; + pub const PTP_ENABLE_PPS: ::c_uint = 0x80043d04; + pub const PTP_SYS_OFFSET: ::c_uint = 0x83403d05; + pub const PTP_PIN_GETFUNC: ::c_uint = 0xc0603d06; + pub const PTP_PIN_SETFUNC: ::c_uint = 0x80603d07; + pub const PTP_SYS_OFFSET_PRECISE: ::c_uint = 0xc0403d08; + pub const PTP_SYS_OFFSET_EXTENDED: ::c_uint = 0xc4c03d09; + + pub const PTP_CLOCK_GETCAPS2: ::c_uint = 0x40503d0a; + pub const PTP_EXTTS_REQUEST2: ::c_uint = 0x80103d0b; + pub const PTP_PEROUT_REQUEST2: ::c_uint = 0x80383d0c; + pub const PTP_ENABLE_PPS2: ::c_uint = 0x80043d0d; + pub const PTP_SYS_OFFSET2: ::c_uint = 0x83403d0e; + pub const PTP_PIN_GETFUNC2: ::c_uint = 0xc0603d0f; + pub const PTP_PIN_SETFUNC2: ::c_uint = 0x80603d10; + pub const PTP_SYS_OFFSET_PRECISE2: ::c_uint = 0xc0403d11; + pub const PTP_SYS_OFFSET_EXTENDED2: ::c_uint = 0xc4c03d12; + } else { + pub const PTP_CLOCK_GETCAPS: ::c_uint = 0x80503d01; + pub const PTP_EXTTS_REQUEST: ::c_uint = 0x40103d02; + pub const PTP_PEROUT_REQUEST: ::c_uint = 0x40383d03; + pub const PTP_ENABLE_PPS: ::c_uint = 0x40043d04; + pub const PTP_SYS_OFFSET: ::c_uint = 0x43403d05; + pub const PTP_PIN_GETFUNC: ::c_uint = 0xc0603d06; + pub const PTP_PIN_SETFUNC: ::c_uint = 0x40603d07; + pub const PTP_SYS_OFFSET_PRECISE: ::c_uint = 0xc0403d08; + pub const PTP_SYS_OFFSET_EXTENDED: ::c_uint = 0xc4c03d09; + + pub const PTP_CLOCK_GETCAPS2: ::c_uint = 0x80503d0a; + pub const PTP_EXTTS_REQUEST2: ::c_uint = 0x40103d0b; + pub const PTP_PEROUT_REQUEST2: ::c_uint = 0x40383d0c; + pub const PTP_ENABLE_PPS2: ::c_uint = 0x40043d0d; + pub const PTP_SYS_OFFSET2: ::c_uint = 0x43403d0e; + pub const PTP_PIN_GETFUNC2: ::c_uint = 0xc0603d0f; + pub const PTP_PIN_SETFUNC2: ::c_uint = 0x40603d10; + pub const PTP_SYS_OFFSET_PRECISE2: ::c_uint = 0xc0403d11; + pub const PTP_SYS_OFFSET_EXTENDED2: ::c_uint = 0xc4c03d12; + } +} + +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; From 1ac55343615e1e7faf8c64ac07e734283bc8aa93 Mon Sep 17 00:00:00 2001 From: Folkert de Vries Date: Wed, 21 Aug 2024 22:55:23 +0200 Subject: [PATCH 02/25] Apply suggestions from code review Co-authored-by: Trevor Gross --- libc-test/build.rs | 8 ++++---- src/unix/linux_like/linux/mod.rs | 1 + 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/libc-test/build.rs b/libc-test/build.rs index aa07b2682ba52..56ef0f3f75e06 100644 --- a/libc-test/build.rs +++ b/libc-test/build.rs @@ -3891,10 +3891,10 @@ fn test_linux(target: &str) { } if musl { // FIXME: Requires >= 5.0 kernel headers - if name == "SECCOMP_GET_NOTIF_SIZES" + if name == "PTP_SYS_OFFSET_EXTENDED" + || name == "SECCOMP_GET_NOTIF_SIZES" || name == "SECCOMP_FILTER_FLAG_NEW_LISTENER" || name == "SECCOMP_FILTER_FLAG_TSYNC_ESRCH" - || name == "PTP_SYS_OFFSET_EXTENDED" || name == "SECCOMP_USER_NOTIF_FLAG_CONTINUE" // requires >= 5.5 || name == "SECCOMP_ADDFD_FLAG_SETFD" // requires >= 5.9 || name == "SECCOMP_ADDFD_FLAG_SEND" // requires >= 5.9 @@ -3908,12 +3908,12 @@ fn test_linux(target: &str) { || name.starts_with("SO_J1939") || name.starts_with("SCM_J1939") || name == "PTP_CLOCK_GETCAPS2" + || name == "PTP_ENABLE_PPS2" || name == "PTP_EXTTS_REQUEST2" || name == "PTP_PEROUT_REQUEST2" - || name == "PTP_ENABLE_PPS2" - || name == "PTP_SYS_OFFSET2" || name == "PTP_PIN_GETFUNC2" || name == "PTP_PIN_SETFUNC2" + || name == "PTP_SYS_OFFSET2" || name == "PTP_SYS_OFFSET_PRECISE2" || name == "PTP_SYS_OFFSET_EXTENDED2" { diff --git a/src/unix/linux_like/linux/mod.rs b/src/unix/linux_like/linux/mod.rs index f829c7b6faa20..9933861709249 100644 --- a/src/unix/linux_like/linux/mod.rs +++ b/src/unix/linux_like/linux/mod.rs @@ -4661,6 +4661,7 @@ cfg_if! { } } +// 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; From 67d86fa9ac21a5c8e928c2404a827daa09f4638b Mon Sep 17 00:00:00 2001 From: Folkert de Vries Date: Wed, 21 Aug 2024 22:59:55 +0200 Subject: [PATCH 03/25] use `PTP_MAX_SAMPLES` in struct definitions --- src/unix/linux_like/linux/mod.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/unix/linux_like/linux/mod.rs b/src/unix/linux_like/linux/mod.rs index 9933861709249..5bccc5fd81d48 100644 --- a/src/unix/linux_like/linux/mod.rs +++ b/src/unix/linux_like/linux/mod.rs @@ -863,7 +863,7 @@ s! { pub struct ptp_sys_offset_extended { pub n_samples: ::c_uint, pub rsv: [::c_uint; 3], - pub ts: [[ptp_clock_time; 3]; 25], + pub ts: [[ptp_clock_time; 3]; PTP_MAX_SAMPLES as usize], } pub struct ptp_sys_offset_precise { @@ -1386,7 +1386,7 @@ s_no_extra_traits! { pub struct ptp_sys_offset { pub n_samples: ::c_uint, pub rsv: [::c_uint; 3], - pub ts: [ptp_clock_time; 51], + pub ts: [ptp_clock_time; 2 * PTP_MAX_SAMPLES as usize + 1], } pub struct ptp_pin_desc { @@ -4615,7 +4615,7 @@ 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; +pub const PTP_MAX_SAMPLES: ::c_uint = 25; // Maximum allowed offset measurement samples. cfg_if! { if #[cfg(any(target_arch = "powerpc", target_arch = "powerpc64", target_arch = "sparc64"))] { From 20faa52d2a91f0eccebe5973df1d058384b1fa09 Mon Sep 17 00:00:00 2001 From: Folkert de Vries Date: Wed, 21 Aug 2024 23:45:19 +0200 Subject: [PATCH 04/25] derive traits where possible --- src/unix/linux_like/linux/mod.rs | 58 ++------------------------------ 1 file changed, 2 insertions(+), 56 deletions(-) diff --git a/src/unix/linux_like/linux/mod.rs b/src/unix/linux_like/linux/mod.rs index 5bccc5fd81d48..3a3f3c302fea9 100644 --- a/src/unix/linux_like/linux/mod.rs +++ b/src/unix/linux_like/linux/mod.rs @@ -1381,7 +1381,9 @@ s_no_extra_traits! { pub offset_to_priv: ::__u32, pub hdr: ::tpacket_bd_header_u, } +} +s! { // linux/ptp_clock.h pub struct ptp_sys_offset { pub n_samples: ::c_uint, @@ -2156,62 +2158,6 @@ cfg_if! { .finish() } } - - impl PartialEq for ptp_sys_offset { - fn eq(&self, other: &ptp_sys_offset) -> bool { - self.n_samples == other.n_samples && - self.rsv == other.rsv && - self.ts[..] == other.ts[..] - } - } - impl Eq for ptp_sys_offset {} - impl ::fmt::Debug for ptp_sys_offset { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("ptp_sys_offset") - .field("n_samples", &self.n_samples) - .field("rsv", &self.rsv) - .field("ts", &&self.ts[..]) - .finish() - } - } - impl ::hash::Hash for ptp_sys_offset { - fn hash(&self, state: &mut H) { - self.n_samples.hash(state); - self.rsv.hash(state); - self.ts[..].hash(state); - } - } - - impl PartialEq for ptp_pin_desc { - fn eq(&self, other: &ptp_pin_desc) -> bool { - self.name[..] == other.name[..] && - self.index == other.index && - self.func == other.func && - self.chan == other.chan && - self.rsv == other.rsv - } - } - impl Eq for ptp_pin_desc {} - impl ::fmt::Debug for ptp_pin_desc { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("ptp_pin_desc") - .field("name", &&self.name[..]) - .field("index", &self.index) - .field("func", &self.func) - .field("chan", &self.chan) - .field("rsv", &self.rsv) - .finish() - } - } - impl ::hash::Hash for ptp_pin_desc { - fn hash(&self, state: &mut H) { - self.name[..].hash(state); - self.index.hash(state); - self.func.hash(state); - self.chan.hash(state); - self.rsv.hash(state); - } - } } } From 5a1f2dc737a8393d1eebe715248841f5a3d55540 Mon Sep 17 00:00:00 2001 From: Folkert de Vries Date: Wed, 21 Aug 2024 23:57:12 +0200 Subject: [PATCH 05/25] adjust `ptp_clock_caps` to older version --- src/unix/linux_like/linux/mod.rs | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/unix/linux_like/linux/mod.rs b/src/unix/linux_like/linux/mod.rs index 3a3f3c302fea9..0b8872b518a6c 100644 --- a/src/unix/linux_like/linux/mod.rs +++ b/src/unix/linux_like/linux/mod.rs @@ -844,14 +844,8 @@ s! { pub pps: ::c_int, pub n_pins: ::c_int, pub cross_timestamping: ::c_int, - #[cfg(target_env = "gnu")] pub adjust_phase: ::c_int, - #[cfg(target_env = "gnu")] - pub max_phase_adj: ::c_int, - #[cfg(target_env = "gnu")] - pub rsv: [::c_int; 11], - #[cfg(any(target_env = "musl", target_env = "ohos"))] - pub rsv: [::c_int; 13], + pub rsv: [::c_int; 12], } pub struct ptp_extts_request { From eabe270e0ec3ccb4ddf81dfa9ff044886fe9156c Mon Sep 17 00:00:00 2001 From: Folkert de Vries Date: Thu, 22 Aug 2024 00:17:38 +0200 Subject: [PATCH 06/25] clarify comment --- libc-test/build.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libc-test/build.rs b/libc-test/build.rs index 56ef0f3f75e06..297029045a7c8 100644 --- a/libc-test/build.rs +++ b/libc-test/build.rs @@ -3553,7 +3553,7 @@ fn test_linux(target: &str) { // FIXME: requires Linux >= 5.6: [!musl]: "linux/openat2.h", "linux/ptp_clock.h", - // FIXME: requires Linux >= 5.6: + // FIXME: some items require Linux >= 5.6: [!musl]: "linux/ptrace.h", "linux/quota.h", "linux/random.h", From 70d6a2be66dd139f404f77809dba5a6f603e0fc8 Mon Sep 17 00:00:00 2001 From: Folkert de Vries Date: Wed, 21 Aug 2024 23:40:02 +0200 Subject: [PATCH 07/25] use a `_IOC` const fn to generate constants adopted from RFL --- src/unix/linux_like/linux/mod.rs | 155 ++++++++++++++++++++++--------- 1 file changed, 112 insertions(+), 43 deletions(-) diff --git a/src/unix/linux_like/linux/mod.rs b/src/unix/linux_like/linux/mod.rs index 0b8872b518a6c..8f01cea416086 100644 --- a/src/unix/linux_like/linux/mod.rs +++ b/src/unix/linux_like/linux/mod.rs @@ -4557,49 +4557,33 @@ 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. -cfg_if! { - if #[cfg(any(target_arch = "powerpc", target_arch = "powerpc64", target_arch = "sparc64"))] { - pub const PTP_CLOCK_GETCAPS: ::c_uint = 0x40503d01; - pub const PTP_EXTTS_REQUEST: ::c_uint = 0x80103d02; - pub const PTP_PEROUT_REQUEST: ::c_uint = 0x80383d03; - pub const PTP_ENABLE_PPS: ::c_uint = 0x80043d04; - pub const PTP_SYS_OFFSET: ::c_uint = 0x83403d05; - pub const PTP_PIN_GETFUNC: ::c_uint = 0xc0603d06; - pub const PTP_PIN_SETFUNC: ::c_uint = 0x80603d07; - pub const PTP_SYS_OFFSET_PRECISE: ::c_uint = 0xc0403d08; - pub const PTP_SYS_OFFSET_EXTENDED: ::c_uint = 0xc4c03d09; - - pub const PTP_CLOCK_GETCAPS2: ::c_uint = 0x40503d0a; - pub const PTP_EXTTS_REQUEST2: ::c_uint = 0x80103d0b; - pub const PTP_PEROUT_REQUEST2: ::c_uint = 0x80383d0c; - pub const PTP_ENABLE_PPS2: ::c_uint = 0x80043d0d; - pub const PTP_SYS_OFFSET2: ::c_uint = 0x83403d0e; - pub const PTP_PIN_GETFUNC2: ::c_uint = 0xc0603d0f; - pub const PTP_PIN_SETFUNC2: ::c_uint = 0x80603d10; - pub const PTP_SYS_OFFSET_PRECISE2: ::c_uint = 0xc0403d11; - pub const PTP_SYS_OFFSET_EXTENDED2: ::c_uint = 0xc4c03d12; - } else { - pub const PTP_CLOCK_GETCAPS: ::c_uint = 0x80503d01; - pub const PTP_EXTTS_REQUEST: ::c_uint = 0x40103d02; - pub const PTP_PEROUT_REQUEST: ::c_uint = 0x40383d03; - pub const PTP_ENABLE_PPS: ::c_uint = 0x40043d04; - pub const PTP_SYS_OFFSET: ::c_uint = 0x43403d05; - pub const PTP_PIN_GETFUNC: ::c_uint = 0xc0603d06; - pub const PTP_PIN_SETFUNC: ::c_uint = 0x40603d07; - pub const PTP_SYS_OFFSET_PRECISE: ::c_uint = 0xc0403d08; - pub const PTP_SYS_OFFSET_EXTENDED: ::c_uint = 0xc4c03d09; - - pub const PTP_CLOCK_GETCAPS2: ::c_uint = 0x80503d0a; - pub const PTP_EXTTS_REQUEST2: ::c_uint = 0x40103d0b; - pub const PTP_PEROUT_REQUEST2: ::c_uint = 0x40383d0c; - pub const PTP_ENABLE_PPS2: ::c_uint = 0x40043d0d; - pub const PTP_SYS_OFFSET2: ::c_uint = 0x43403d0e; - pub const PTP_PIN_GETFUNC2: ::c_uint = 0xc0603d0f; - pub const PTP_PIN_SETFUNC2: ::c_uint = 0x40603d10; - pub const PTP_SYS_OFFSET_PRECISE2: ::c_uint = 0xc0403d11; - pub const PTP_SYS_OFFSET_EXTENDED2: ::c_uint = 0xc4c03d12; - } -} +const PTP_CLK_MAGIC: u32 = b'=' as u32; + +pub const PTP_CLOCK_GETCAPS: ::c_uint = ioctl::_IOR::(PTP_CLK_MAGIC, 1); +pub const PTP_EXTTS_REQUEST: ::c_uint = ioctl::_IOW::(PTP_CLK_MAGIC, 2); +pub const PTP_PEROUT_REQUEST: ::c_uint = ioctl::_IOW::(PTP_CLK_MAGIC, 3); +pub const PTP_ENABLE_PPS: ::c_uint = ioctl::_IOW::<::c_int>(PTP_CLK_MAGIC, 4); +pub const PTP_SYS_OFFSET: ::c_uint = ioctl::_IOW::(PTP_CLK_MAGIC, 5); +pub const PTP_PIN_GETFUNC: ::c_uint = ioctl::_IOWR::(PTP_CLK_MAGIC, 6); +pub const PTP_PIN_SETFUNC: ::c_uint = ioctl::_IOW::(PTP_CLK_MAGIC, 7); +pub const PTP_SYS_OFFSET_PRECISE: ::c_uint = + ioctl::_IOWR::(PTP_CLK_MAGIC, 8); +pub const PTP_SYS_OFFSET_EXTENDED: ::c_uint = + ioctl::_IOWR::(PTP_CLK_MAGIC, 9); + +pub const PTP_CLOCK_GETCAPS2: ::c_uint = ioctl::_IOR::(PTP_CLK_MAGIC, 10); +pub const PTP_EXTTS_REQUEST2: ::c_uint = ioctl::_IOW::(PTP_CLK_MAGIC, 11); +pub const PTP_PEROUT_REQUEST2: ::c_uint = ioctl::_IOW::(PTP_CLK_MAGIC, 12); +pub const PTP_ENABLE_PPS2: ::c_uint = ioctl::_IOW::<::c_int>(PTP_CLK_MAGIC, 13); +pub const PTP_SYS_OFFSET2: ::c_uint = ioctl::_IOW::(PTP_CLK_MAGIC, 14); +pub const PTP_PIN_GETFUNC2: ::c_uint = ioctl::_IOWR::(PTP_CLK_MAGIC, 15); +pub const PTP_PIN_SETFUNC2: ::c_uint = ioctl::_IOW::(PTP_CLK_MAGIC, 16); +pub const PTP_SYS_OFFSET_PRECISE2: ::c_uint = + ioctl::_IOWR::(PTP_CLK_MAGIC, 17); +pub const PTP_SYS_OFFSET_EXTENDED2: ::c_uint = + ioctl::_IOWR::(PTP_CLK_MAGIC, 18); +pub const PTP_MASK_CLEAR_ALL: ::c_uint = ioctl::_IO(PTP_CLK_MAGIC, 19); +pub const PTP_MASK_EN_SINGLE: ::c_uint = ioctl::_IOW::<::c_uint>(PTP_CLK_MAGIC, 20); // enum ptp_pin_function pub const PTP_PF_NONE: ::c_uint = 0; @@ -6682,6 +6666,91 @@ cfg_if! { } } +mod ioctl { + 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; + + // adopted 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. + #[inline(always)] + const fn _IOC(dir: u32, ty: u32, nr: u32, size: usize) -> u32 { + 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. + #[inline(always)] + pub const fn _IO(ty: u32, nr: u32) -> u32 { + _IOC(_IOC_NONE, ty, nr, 0) + } + + /// Build an ioctl number for an read-only ioctl. + #[inline(always)] + pub 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. + #[inline(always)] + pub 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. + #[inline(always)] + pub const fn _IOWR(ty: u32, nr: u32) -> u32 { + _IOC(_IOC_READ | _IOC_WRITE, ty, nr, core::mem::size_of::()) + } +} + cfg_if! { if #[cfg(target_env = "uclibc")] { mod uclibc; From cc9356724ee34b49f27799c3cfeac54ba68e138b Mon Sep 17 00:00:00 2001 From: Folkert de Vries Date: Thu, 22 Aug 2024 11:48:11 +0200 Subject: [PATCH 08/25] add `ptp_perout_request` --- src/unix/linux_like/linux/mod.rs | 42 +++++++++++++++----------------- 1 file changed, 19 insertions(+), 23 deletions(-) diff --git a/src/unix/linux_like/linux/mod.rs b/src/unix/linux_like/linux/mod.rs index 8f01cea416086..2ef8f6d7d2166 100644 --- a/src/unix/linux_like/linux/mod.rs +++ b/src/unix/linux_like/linux/mod.rs @@ -1638,31 +1638,27 @@ s! { } } -cfg_if! { - if #[cfg(libc_union)] { - s_no_extra_traits! { - // 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, - } +s_no_extra_traits! { + // 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 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, - } - } + #[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, } } From f72d11a40cc8c79e97b493dd92a0c99d6b29cd21 Mon Sep 17 00:00:00 2001 From: Folkert de Vries Date: Thu, 22 Aug 2024 12:00:29 +0200 Subject: [PATCH 09/25] deduplicate `s!` macro calls --- src/unix/linux_like/linux/mod.rs | 171 ++++--------------------------- 1 file changed, 18 insertions(+), 153 deletions(-) diff --git a/src/unix/linux_like/linux/mod.rs b/src/unix/linux_like/linux/mod.rs index 2ef8f6d7d2166..f3804d17a26c7 100644 --- a/src/unix/linux_like/linux/mod.rs +++ b/src/unix/linux_like/linux/mod.rs @@ -1187,6 +1187,22 @@ 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], + pub ts: [ptp_clock_time; 2 * PTP_MAX_SAMPLES as usize + 1], + } + + 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! { @@ -1392,160 +1408,9 @@ s! { pub chan: ::c_uint, pub rsv: [::c_uint; 5], } +} - #[cfg_attr( - all( - any(target_env = "musl", target_env = "ohos"), - target_pointer_width = "32" - ), - repr(align(4)) - )] - #[cfg_attr( - all( - any(target_env = "musl", target_env = "ohos"), - target_pointer_width = "64" - ), - repr(align(8)) - )] - #[cfg_attr( - all( - not(any(target_env = "musl", target_env = "ohos")), - target_arch = "x86" - ), - repr(align(4)) - )] - #[cfg_attr( - all( - not(any(target_env = "musl", target_env = "ohos")), - not(target_arch = "x86") - ), - repr(align(8)) - )] - pub struct pthread_cond_t { - #[doc(hidden)] - size: [u8; ::__SIZEOF_PTHREAD_COND_T], - } - - #[cfg_attr( - all( - target_pointer_width = "32", - any( - target_arch = "mips", - target_arch = "mips32r6", - target_arch = "arm", - target_arch = "hexagon", - target_arch = "m68k", - target_arch = "csky", - target_arch = "powerpc", - target_arch = "sparc", - target_arch = "x86_64", - target_arch = "x86" - ) - ), - repr(align(4)) - )] - #[cfg_attr( - any( - target_pointer_width = "64", - not(any( - target_arch = "mips", - target_arch = "mips32r6", - target_arch = "arm", - target_arch = "hexagon", - target_arch = "m68k", - target_arch = "csky", - target_arch = "powerpc", - target_arch = "sparc", - target_arch = "x86_64", - target_arch = "x86" - )) - ), - repr(align(8)) - )] - pub struct pthread_mutex_t { - #[doc(hidden)] - size: [u8; ::__SIZEOF_PTHREAD_MUTEX_T], - } - - #[cfg_attr( - all( - target_pointer_width = "32", - any( - target_arch = "mips", - target_arch = "mips32r6", - target_arch = "arm", - target_arch = "hexagon", - target_arch = "m68k", - target_arch = "csky", - target_arch = "powerpc", - target_arch = "sparc", - target_arch = "x86_64", - target_arch = "x86" - ) - ), - repr(align(4)) - )] - #[cfg_attr( - any( - target_pointer_width = "64", - not(any( - target_arch = "mips", - target_arch = "mips32r6", - target_arch = "arm", - target_arch = "hexagon", - target_arch = "m68k", - target_arch = "powerpc", - target_arch = "sparc", - target_arch = "x86_64", - target_arch = "x86" - )) - ), - repr(align(8)) - )] - pub struct pthread_rwlock_t { - size: [u8; ::__SIZEOF_PTHREAD_RWLOCK_T], - } - - #[cfg_attr( - all( - target_pointer_width = "32", - any( - target_arch = "mips", - target_arch = "mips32r6", - target_arch = "arm", - target_arch = "hexagon", - target_arch = "m68k", - target_arch = "csky", - target_arch = "powerpc", - target_arch = "sparc", - target_arch = "x86_64", - target_arch = "x86" - ) - ), - repr(align(4)) - )] - #[cfg_attr( - any( - target_pointer_width = "64", - not(any( - target_arch = "mips", - target_arch = "mips32r6", - target_arch = "arm", - target_arch = "hexagon", - target_arch = "m68k", - target_arch = "csky", - target_arch = "powerpc", - target_arch = "sparc", - target_arch = "x86_64", - target_arch = "x86" - )) - ), - repr(align(8)) - )] - pub struct pthread_barrier_t { - size: [u8; ::__SIZEOF_PTHREAD_BARRIER_T], - } - +s_no_extra_traits! { // linux/net_tstamp.h #[allow(missing_debug_implementations)] pub struct sock_txtime { From dc33d9c789e6b17abf1cb4b803124b5ff0643f29 Mon Sep 17 00:00:00 2001 From: Folkert de Vries Date: Wed, 28 Aug 2024 22:45:56 +0200 Subject: [PATCH 10/25] fix style issue --- src/unix/linux_like/linux/ioctl.rs | 82 ++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 src/unix/linux_like/linux/ioctl.rs diff --git a/src/unix/linux_like/linux/ioctl.rs b/src/unix/linux_like/linux/ioctl.rs new file mode 100644 index 0000000000000..5836a885251d4 --- /dev/null +++ b/src/unix/linux_like/linux/ioctl.rs @@ -0,0 +1,82 @@ +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; + +// adopted 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. +#[inline(always)] +const fn _IOC(dir: u32, ty: u32, nr: u32, size: usize) -> u32 { + 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. +#[inline(always)] +pub const fn _IO(ty: u32, nr: u32) -> u32 { + _IOC(_IOC_NONE, ty, nr, 0) +} + +/// Build an ioctl number for an read-only ioctl. +#[inline(always)] +pub 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. +#[inline(always)] +pub 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. +#[inline(always)] +pub const fn _IOWR(ty: u32, nr: u32) -> u32 { + _IOC(_IOC_READ | _IOC_WRITE, ty, nr, core::mem::size_of::()) +} From 064e6e814399f16ac0c9e277e007781261112810 Mon Sep 17 00:00:00 2001 From: Folkert de Vries Date: Wed, 28 Aug 2024 23:28:01 +0200 Subject: [PATCH 11/25] fix parsing problems --- src/unix/linux_like/linux/ioctl.rs | 11 +++++++---- src/unix/linux_like/linux/mod.rs | 5 +++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/unix/linux_like/linux/ioctl.rs b/src/unix/linux_like/linux/ioctl.rs index 5836a885251d4..4dd0c095c9ea2 100644 --- a/src/unix/linux_like/linux/ioctl.rs +++ b/src/unix/linux_like/linux/ioctl.rs @@ -46,10 +46,13 @@ const _IOC_DIRSHIFT: u32 = _IOC_SIZESHIFT + _IOC_SIZEBITS; /// Build an ioctl number, analogous to the C macro of the same name. #[inline(always)] const fn _IOC(dir: u32, ty: u32, nr: u32, size: usize) -> u32 { - debug_assert!(dir <= _IOC_DIRMASK); - debug_assert!(ty <= _IOC_TYPEMASK); - debug_assert!(nr <= _IOC_NRMASK); - debug_assert!(size <= (_IOC_SIZEMASK as usize)); + // TODO 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) diff --git a/src/unix/linux_like/linux/mod.rs b/src/unix/linux_like/linux/mod.rs index f3804d17a26c7..9273e4264b74f 100644 --- a/src/unix/linux_like/linux/mod.rs +++ b/src/unix/linux_like/linux/mod.rs @@ -845,7 +845,8 @@ s! { pub n_pins: ::c_int, pub cross_timestamping: ::c_int, pub adjust_phase: ::c_int, - pub rsv: [::c_int; 12], + pub max_phase_adj: ::c_int, + pub rsv: [::c_int; 11], } pub struct ptp_extts_request { @@ -1193,7 +1194,7 @@ s! { pub struct ptp_sys_offset { pub n_samples: ::c_uint, pub rsv: [::c_uint; 3], - pub ts: [ptp_clock_time; 2 * PTP_MAX_SAMPLES as usize + 1], + pub ts: [ptp_clock_time; 51], } pub struct ptp_pin_desc { From 4abfd63b6affded37bf09eead30896a1ad9fbd11 Mon Sep 17 00:00:00 2001 From: Folkert de Vries Date: Thu, 29 Aug 2024 00:18:20 +0200 Subject: [PATCH 12/25] add missed constants --- libc-test/build.rs | 2 ++ libc-test/semver/linux.txt | 2 ++ 2 files changed, 4 insertions(+) diff --git a/libc-test/build.rs b/libc-test/build.rs index 297029045a7c8..bc120c9e014da 100644 --- a/libc-test/build.rs +++ b/libc-test/build.rs @@ -3910,6 +3910,8 @@ fn test_linux(target: &str) { || name == "PTP_CLOCK_GETCAPS2" || name == "PTP_ENABLE_PPS2" || name == "PTP_EXTTS_REQUEST2" + || name == "PTP_MASK_CLEAR_ALL" + || name == "PTP_MASK_EN_SINGLE" || name == "PTP_PEROUT_REQUEST2" || name == "PTP_PIN_GETFUNC2" || name == "PTP_PIN_SETFUNC2" diff --git a/libc-test/semver/linux.txt b/libc-test/semver/linux.txt index 6286abd032fbc..a1813b259012d 100644 --- a/libc-test/semver/linux.txt +++ b/libc-test/semver/linux.txt @@ -2275,6 +2275,8 @@ PTP_SYS_OFFSET_EXTENDED PTP_SYS_OFFSET_EXTENDED2 PTP_SYS_OFFSET_PRECISE PTP_SYS_OFFSET_PRECISE2 +PTP_MASK_CLEAR_ALL +PTP_MASK_EN_SINGLE PTRACE_ATTACH PTRACE_CONT PTRACE_DETACH From 0fa92515c05eee83cc21feebbd46ed347c390ac3 Mon Sep 17 00:00:00 2001 From: Folkert de Vries Date: Thu, 29 Aug 2024 14:54:45 +0200 Subject: [PATCH 13/25] remove `PTP_MASK_CLEAR_ALL` and `PTP_MASK_EN_SINGLE` for now --- libc-test/build.rs | 2 -- libc-test/semver/linux.txt | 2 -- src/unix/linux_like/linux/mod.rs | 2 -- 3 files changed, 6 deletions(-) diff --git a/libc-test/build.rs b/libc-test/build.rs index bc120c9e014da..297029045a7c8 100644 --- a/libc-test/build.rs +++ b/libc-test/build.rs @@ -3910,8 +3910,6 @@ fn test_linux(target: &str) { || name == "PTP_CLOCK_GETCAPS2" || name == "PTP_ENABLE_PPS2" || name == "PTP_EXTTS_REQUEST2" - || name == "PTP_MASK_CLEAR_ALL" - || name == "PTP_MASK_EN_SINGLE" || name == "PTP_PEROUT_REQUEST2" || name == "PTP_PIN_GETFUNC2" || name == "PTP_PIN_SETFUNC2" diff --git a/libc-test/semver/linux.txt b/libc-test/semver/linux.txt index a1813b259012d..6286abd032fbc 100644 --- a/libc-test/semver/linux.txt +++ b/libc-test/semver/linux.txt @@ -2275,8 +2275,6 @@ PTP_SYS_OFFSET_EXTENDED PTP_SYS_OFFSET_EXTENDED2 PTP_SYS_OFFSET_PRECISE PTP_SYS_OFFSET_PRECISE2 -PTP_MASK_CLEAR_ALL -PTP_MASK_EN_SINGLE 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 9273e4264b74f..53b64443253ad 100644 --- a/src/unix/linux_like/linux/mod.rs +++ b/src/unix/linux_like/linux/mod.rs @@ -4444,8 +4444,6 @@ pub const PTP_SYS_OFFSET_PRECISE2: ::c_uint = ioctl::_IOWR::(PTP_CLK_MAGIC, 17); pub const PTP_SYS_OFFSET_EXTENDED2: ::c_uint = ioctl::_IOWR::(PTP_CLK_MAGIC, 18); -pub const PTP_MASK_CLEAR_ALL: ::c_uint = ioctl::_IO(PTP_CLK_MAGIC, 19); -pub const PTP_MASK_EN_SINGLE: ::c_uint = ioctl::_IOW::<::c_uint>(PTP_CLK_MAGIC, 20); // enum ptp_pin_function pub const PTP_PF_NONE: ::c_uint = 0; From 66c59b891562b4e717d1a255545f25fefabddeaa Mon Sep 17 00:00:00 2001 From: Folkert de Vries Date: Thu, 29 Aug 2024 14:57:24 +0200 Subject: [PATCH 14/25] please musl --- src/unix/linux_like/linux/mod.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/unix/linux_like/linux/mod.rs b/src/unix/linux_like/linux/mod.rs index 53b64443253ad..04c9b0473de5f 100644 --- a/src/unix/linux_like/linux/mod.rs +++ b/src/unix/linux_like/linux/mod.rs @@ -844,9 +844,14 @@ s! { pub pps: ::c_int, pub n_pins: ::c_int, pub cross_timestamping: ::c_int, + #[cfg(not(any(target_env = "musl", target_env = "ohos")))] pub adjust_phase: ::c_int, + #[cfg(not(any(target_env = "musl", target_env = "ohos")))] pub max_phase_adj: ::c_int, + #[cfg(not(any(target_env = "musl", target_env = "ohos")))] pub rsv: [::c_int; 11], + #[cfg(any(target_env = "musl", target_env = "ohos"))] + pub rsv: [::c_int; 13], } pub struct ptp_extts_request { From f36c3deb6af435787e9093cdf77f4362405e327d Mon Sep 17 00:00:00 2001 From: Folkert de Vries Date: Thu, 29 Aug 2024 15:29:03 +0200 Subject: [PATCH 15/25] another attempt at `ptp_clock_caps` --- src/unix/linux_like/linux/mod.rs | 64 +++++++++++++++++++++++--------- 1 file changed, 47 insertions(+), 17 deletions(-) diff --git a/src/unix/linux_like/linux/mod.rs b/src/unix/linux_like/linux/mod.rs index 04c9b0473de5f..40eab34d9b21c 100644 --- a/src/unix/linux_like/linux/mod.rs +++ b/src/unix/linux_like/linux/mod.rs @@ -836,23 +836,7 @@ s! { pub reserved: ::__u32, } - pub struct ptp_clock_caps { - pub max_adj: ::c_int, - pub n_alarm: ::c_int, - pub n_ext_ts: ::c_int, - pub n_per_out: ::c_int, - pub pps: ::c_int, - pub n_pins: ::c_int, - pub cross_timestamping: ::c_int, - #[cfg(not(any(target_env = "musl", target_env = "ohos")))] - pub adjust_phase: ::c_int, - #[cfg(not(any(target_env = "musl", target_env = "ohos")))] - pub max_phase_adj: ::c_int, - #[cfg(not(any(target_env = "musl", target_env = "ohos")))] - pub rsv: [::c_int; 11], - #[cfg(any(target_env = "musl", target_env = "ohos"))] - pub rsv: [::c_int; 13], - } + pub struct ptp_extts_request { pub index: ::c_uint, @@ -1211,6 +1195,52 @@ s! { } } +cfg_if! { + if #[cfg(any(target_arch = "sparc", target_arch = "sparc64"))] { + s!{ + pub struct ptp_clock_caps { + pub max_adj: ::c_int, + pub n_alarm: ::c_int, + pub n_ext_ts: ::c_int, + pub n_per_out: ::c_int, + pub pps: ::c_int, + pub n_pins: ::c_int, + pub cross_timestamping: ::c_int, + pub adjust_phase: ::c_int, + pub rsv: [::c_int; 12], + } + } + } else if #[cfg(any(target_env = "musl", target_env = "ohos"))] { + s!{ + pub struct ptp_clock_caps { + pub max_adj: ::c_int, + pub n_alarm: ::c_int, + pub n_ext_ts: ::c_int, + pub n_per_out: ::c_int, + pub pps: ::c_int, + pub n_pins: ::c_int, + pub cross_timestamping: ::c_int, + pub rsv: [::c_int; 13], + } + } + } else { + s! { + pub struct ptp_clock_caps { + pub max_adj: ::c_int, + pub n_alarm: ::c_int, + pub n_ext_ts: ::c_int, + pub n_per_out: ::c_int, + pub pps: ::c_int, + pub n_pins: ::c_int, + pub cross_timestamping: ::c_int, + pub adjust_phase: ::c_int, + pub max_phase_adj: ::c_int, + pub rsv: [::c_int; 11], + } + } + } +} + cfg_if! { if #[cfg(not(target_arch = "sparc64"))] { s! { From be73cc73df6112cce50a8eff78f3a6c4961c77a6 Mon Sep 17 00:00:00 2001 From: Folkert de Vries Date: Sat, 31 Aug 2024 12:58:51 +0200 Subject: [PATCH 16/25] uglier version of `ptp_clock_caps` --- src/unix/linux_like/linux/mod.rs | 73 +++++++++++++------------------- 1 file changed, 29 insertions(+), 44 deletions(-) diff --git a/src/unix/linux_like/linux/mod.rs b/src/unix/linux_like/linux/mod.rs index 40eab34d9b21c..56b664ca3ab02 100644 --- a/src/unix/linux_like/linux/mod.rs +++ b/src/unix/linux_like/linux/mod.rs @@ -1193,51 +1193,36 @@ s! { pub chan: ::c_uint, pub rsv: [::c_uint; 5], } -} -cfg_if! { - if #[cfg(any(target_arch = "sparc", target_arch = "sparc64"))] { - s!{ - pub struct ptp_clock_caps { - pub max_adj: ::c_int, - pub n_alarm: ::c_int, - pub n_ext_ts: ::c_int, - pub n_per_out: ::c_int, - pub pps: ::c_int, - pub n_pins: ::c_int, - pub cross_timestamping: ::c_int, - pub adjust_phase: ::c_int, - pub rsv: [::c_int; 12], - } - } - } else if #[cfg(any(target_env = "musl", target_env = "ohos"))] { - s!{ - pub struct ptp_clock_caps { - pub max_adj: ::c_int, - pub n_alarm: ::c_int, - pub n_ext_ts: ::c_int, - pub n_per_out: ::c_int, - pub pps: ::c_int, - pub n_pins: ::c_int, - pub cross_timestamping: ::c_int, - pub rsv: [::c_int; 13], - } - } - } else { - s! { - pub struct ptp_clock_caps { - pub max_adj: ::c_int, - pub n_alarm: ::c_int, - pub n_ext_ts: ::c_int, - pub n_per_out: ::c_int, - pub pps: ::c_int, - pub n_pins: ::c_int, - pub cross_timestamping: ::c_int, - pub adjust_phase: ::c_int, - pub max_phase_adj: ::c_int, - pub rsv: [::c_int; 11], - } - } + pub struct ptp_clock_caps { + pub max_adj: ::c_int, + pub n_alarm: ::c_int, + pub n_ext_ts: ::c_int, + pub n_per_out: ::c_int, + pub pps: ::c_int, + pub n_pins: ::c_int, + pub cross_timestamping: ::c_int, + #[cfg(any(target_arch = "sparc", target_arch = "sparc64"))] + pub adjust_phase: ::c_int, + #[cfg(any(target_arch = "sparc", target_arch = "sparc64"))] + pub rsv: [::c_int; 12], + #[cfg(any(target_env = "musl", target_env = "ohos"))] + pub rsv: [::c_int; 13], + #[cfg(not(any( + any(target_arch = "sparc", target_arch = "sparc64"), + any(target_env = "musl", target_env = "ohos"), + )))] + pub adjust_phase: ::c_int, + #[cfg(not(any( + any(target_arch = "sparc", target_arch = "sparc64"), + any(target_env = "musl", target_env = "ohos"), + )))] + pub max_phase_adj: ::c_int, + #[cfg(not(any( + any(target_arch = "sparc", target_arch = "sparc64"), + any(target_env = "musl", target_env = "ohos"), + )))] + pub rsv: [::c_int; 11], } } From d857c024385db63fb4d8efc05319f1c97583b939 Mon Sep 17 00:00:00 2001 From: Folkert de Vries Date: Wed, 13 Nov 2024 18:56:28 +0100 Subject: [PATCH 17/25] fixes after code review --- libc-test/build.rs | 2 +- src/unix/linux_like/linux/ioctl.rs | 5 ----- src/unix/linux_like/linux/mod.rs | 2 -- 3 files changed, 1 insertion(+), 8 deletions(-) diff --git a/libc-test/build.rs b/libc-test/build.rs index 297029045a7c8..664db51e3a3d3 100644 --- a/libc-test/build.rs +++ b/libc-test/build.rs @@ -3552,8 +3552,8 @@ fn test_linux(target: &str) { "linux/netlink.h", // FIXME: requires Linux >= 5.6: [!musl]: "linux/openat2.h", - "linux/ptp_clock.h", // FIXME: some items require Linux >= 5.6: + "linux/ptp_clock.h", [!musl]: "linux/ptrace.h", "linux/quota.h", "linux/random.h", diff --git a/src/unix/linux_like/linux/ioctl.rs b/src/unix/linux_like/linux/ioctl.rs index 4dd0c095c9ea2..fa512a89a5526 100644 --- a/src/unix/linux_like/linux/ioctl.rs +++ b/src/unix/linux_like/linux/ioctl.rs @@ -44,7 +44,6 @@ const _IOC_DIRSHIFT: u32 = _IOC_SIZESHIFT + _IOC_SIZEBITS; // adopted 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. -#[inline(always)] const fn _IOC(dir: u32, ty: u32, nr: u32, size: usize) -> u32 { // TODO the `garando_syntax` crate (used by ctest2 in the CI test suite) // cannot currently parse these `debug_assert!`s @@ -61,25 +60,21 @@ const fn _IOC(dir: u32, ty: u32, nr: u32, size: usize) -> u32 { } /// Build an ioctl number for an argumentless ioctl. -#[inline(always)] pub const fn _IO(ty: u32, nr: u32) -> u32 { _IOC(_IOC_NONE, ty, nr, 0) } /// Build an ioctl number for an read-only ioctl. -#[inline(always)] pub 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. -#[inline(always)] pub 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. -#[inline(always)] pub const fn _IOWR(ty: u32, nr: u32) -> u32 { _IOC(_IOC_READ | _IOC_WRITE, ty, nr, core::mem::size_of::()) } diff --git a/src/unix/linux_like/linux/mod.rs b/src/unix/linux_like/linux/mod.rs index 56b664ca3ab02..4f0fb9e5ab964 100644 --- a/src/unix/linux_like/linux/mod.rs +++ b/src/unix/linux_like/linux/mod.rs @@ -836,8 +836,6 @@ s! { pub reserved: ::__u32, } - - pub struct ptp_extts_request { pub index: ::c_uint, pub flags: ::c_uint, From c0dea2a5ea5ed512d8a7fa0dfb8302e423c2b424 Mon Sep 17 00:00:00 2001 From: Folkert de Vries Date: Wed, 13 Nov 2024 18:57:11 +0100 Subject: [PATCH 18/25] add `ptp_pin_function` --- src/unix/linux_like/linux/mod.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/unix/linux_like/linux/mod.rs b/src/unix/linux_like/linux/mod.rs index 4f0fb9e5ab964..a62db465e34a0 100644 --- a/src/unix/linux_like/linux/mod.rs +++ b/src/unix/linux_like/linux/mod.rs @@ -56,6 +56,9 @@ cfg_if! { } } +// linux/ptp_clock.h +pub type ptp_pin_function = ::c_uint; + // linux/can.h pub type canid_t = u32; @@ -4464,10 +4467,10 @@ pub const PTP_SYS_OFFSET_EXTENDED2: ::c_uint = ioctl::_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; +pub const PTP_PF_NONE: ptp_pin_function = 0; +pub const PTP_PF_EXTTS: ptp_pin_function = 1; +pub const PTP_PF_PEROUT: ptp_pin_function = 2; +pub const PTP_PF_PHYSYNC: ptp_pin_function = 3; // linux/tls.h pub const TLS_TX: ::c_int = 1; From 810e82d53611898b0f2aaf2d640661dd19585cbe Mon Sep 17 00:00:00 2001 From: Folkert de Vries Date: Wed, 13 Nov 2024 19:05:03 +0100 Subject: [PATCH 19/25] define `PTP_CLOCK_CAPS_RSV_LEN` --- src/unix/linux_like/linux/mod.rs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/unix/linux_like/linux/mod.rs b/src/unix/linux_like/linux/mod.rs index a62db465e34a0..faf0773e290fe 100644 --- a/src/unix/linux_like/linux/mod.rs +++ b/src/unix/linux_like/linux/mod.rs @@ -1205,10 +1205,6 @@ s! { pub cross_timestamping: ::c_int, #[cfg(any(target_arch = "sparc", target_arch = "sparc64"))] pub adjust_phase: ::c_int, - #[cfg(any(target_arch = "sparc", target_arch = "sparc64"))] - pub rsv: [::c_int; 12], - #[cfg(any(target_env = "musl", target_env = "ohos"))] - pub rsv: [::c_int; 13], #[cfg(not(any( any(target_arch = "sparc", target_arch = "sparc64"), any(target_env = "musl", target_env = "ohos"), @@ -1223,7 +1219,7 @@ s! { any(target_arch = "sparc", target_arch = "sparc64"), any(target_env = "musl", target_env = "ohos"), )))] - pub rsv: [::c_int; 11], + pub rsv: [::c_int; PTP_CLOCK_CAPS_RSV_LEN], } } @@ -5526,6 +5522,17 @@ pub const SCHED_FLAG_ALL: ::c_int = SCHED_FLAG_RESET_ON_FORK pub const EPIOCSPARAMS: ::Ioctl = 0x40088a01; pub const EPIOCGPARAMS: ::Ioctl = 0x80088a02; +// ptp_clock.h +cfg_if! { + if #[cfg(any(target_arch = "sparc", target_arch = "sparc64"))] { + pub const PTP_CLOCK_CAPS_RSV_LEN: usize = 12; + } else if #[cfg(any(target_env = "musl", target_env = "ohos"))] { + pub const PTP_CLOCK_CAPS_RSV_LEN: usize = 13; + } else { + pub const PTP_CLOCK_CAPS_RSV_LEN: usize = 11; + } +} + f! { pub fn NLA_ALIGN(len: ::c_int) -> ::c_int { return ((len) + NLA_ALIGNTO - 1) & !(NLA_ALIGNTO - 1); From 49cd9aa1a33ed1e131b12fd360356fe829335b9f Mon Sep 17 00:00:00 2001 From: Folkert de Vries Date: Wed, 13 Nov 2024 20:11:58 +0100 Subject: [PATCH 20/25] move ioctl functions to `linux/mod.rs` --- src/unix/linux_like/linux/ioctl.rs | 80 ------------------- src/unix/linux_like/linux/mod.rs | 123 +++++++++++++++++++++++------ 2 files changed, 100 insertions(+), 103 deletions(-) delete mode 100644 src/unix/linux_like/linux/ioctl.rs diff --git a/src/unix/linux_like/linux/ioctl.rs b/src/unix/linux_like/linux/ioctl.rs deleted file mode 100644 index fa512a89a5526..0000000000000 --- a/src/unix/linux_like/linux/ioctl.rs +++ /dev/null @@ -1,80 +0,0 @@ -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; - -// adopted 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 { - // TODO 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 const fn _IO(ty: u32, nr: u32) -> u32 { - _IOC(_IOC_NONE, ty, nr, 0) -} - -/// Build an ioctl number for an read-only ioctl. -pub 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 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 const fn _IOWR(ty: u32, nr: u32) -> u32 { - _IOC(_IOC_READ | _IOC_WRITE, ty, nr, core::mem::size_of::()) -} diff --git a/src/unix/linux_like/linux/mod.rs b/src/unix/linux_like/linux/mod.rs index faf0773e290fe..6716ef2612a90 100644 --- a/src/unix/linux_like/linux/mod.rs +++ b/src/unix/linux_like/linux/mod.rs @@ -4438,29 +4438,25 @@ pub const PTP_MAX_SAMPLES: ::c_uint = 25; // Maximum allowed offset measurement const PTP_CLK_MAGIC: u32 = b'=' as u32; -pub const PTP_CLOCK_GETCAPS: ::c_uint = ioctl::_IOR::(PTP_CLK_MAGIC, 1); -pub const PTP_EXTTS_REQUEST: ::c_uint = ioctl::_IOW::(PTP_CLK_MAGIC, 2); -pub const PTP_PEROUT_REQUEST: ::c_uint = ioctl::_IOW::(PTP_CLK_MAGIC, 3); -pub const PTP_ENABLE_PPS: ::c_uint = ioctl::_IOW::<::c_int>(PTP_CLK_MAGIC, 4); -pub const PTP_SYS_OFFSET: ::c_uint = ioctl::_IOW::(PTP_CLK_MAGIC, 5); -pub const PTP_PIN_GETFUNC: ::c_uint = ioctl::_IOWR::(PTP_CLK_MAGIC, 6); -pub const PTP_PIN_SETFUNC: ::c_uint = ioctl::_IOW::(PTP_CLK_MAGIC, 7); -pub const PTP_SYS_OFFSET_PRECISE: ::c_uint = - ioctl::_IOWR::(PTP_CLK_MAGIC, 8); -pub const PTP_SYS_OFFSET_EXTENDED: ::c_uint = - ioctl::_IOWR::(PTP_CLK_MAGIC, 9); - -pub const PTP_CLOCK_GETCAPS2: ::c_uint = ioctl::_IOR::(PTP_CLK_MAGIC, 10); -pub const PTP_EXTTS_REQUEST2: ::c_uint = ioctl::_IOW::(PTP_CLK_MAGIC, 11); -pub const PTP_PEROUT_REQUEST2: ::c_uint = ioctl::_IOW::(PTP_CLK_MAGIC, 12); -pub const PTP_ENABLE_PPS2: ::c_uint = ioctl::_IOW::<::c_int>(PTP_CLK_MAGIC, 13); -pub const PTP_SYS_OFFSET2: ::c_uint = ioctl::_IOW::(PTP_CLK_MAGIC, 14); -pub const PTP_PIN_GETFUNC2: ::c_uint = ioctl::_IOWR::(PTP_CLK_MAGIC, 15); -pub const PTP_PIN_SETFUNC2: ::c_uint = ioctl::_IOW::(PTP_CLK_MAGIC, 16); -pub const PTP_SYS_OFFSET_PRECISE2: ::c_uint = - ioctl::_IOWR::(PTP_CLK_MAGIC, 17); -pub const PTP_SYS_OFFSET_EXTENDED2: ::c_uint = - ioctl::_IOWR::(PTP_CLK_MAGIC, 18); +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); + +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: ptp_pin_function = 0; @@ -5533,6 +5529,87 @@ cfg_if! { } } +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 { + // TODO 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 97b426932622f7710a33ce23ab5713305ba4c319 Mon Sep 17 00:00:00 2001 From: Folkert de Vries Date: Thu, 14 Nov 2024 12:55:59 +0100 Subject: [PATCH 21/25] document that constant should be computed (when garando supports it) --- src/unix/linux_like/linux/mod.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/unix/linux_like/linux/mod.rs b/src/unix/linux_like/linux/mod.rs index 6716ef2612a90..bcfbf530872ed 100644 --- a/src/unix/linux_like/linux/mod.rs +++ b/src/unix/linux_like/linux/mod.rs @@ -1184,6 +1184,7 @@ s! { 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], } From dbbf82cab217d47adefe46b1f46b469943ad1506 Mon Sep 17 00:00:00 2001 From: Folkert de Vries Date: Thu, 14 Nov 2024 13:16:45 +0100 Subject: [PATCH 22/25] update `ptp_sys_offset_extended` to latest version it changed recently https://github.com/torvalds/linux/commit/c259acab839e57eab0318f32da4ae803a8d59397#diff-721f436093b6e07475c0784886e2092c2d0bc269397e0efd279fdf943ea55f27R175 --- libc-test/build.rs | 4 +++- src/unix/linux_like/linux/mod.rs | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/libc-test/build.rs b/libc-test/build.rs index 664db51e3a3d3..ca22d74cab8d4 100644 --- a/libc-test/build.rs +++ b/libc-test/build.rs @@ -3702,7 +3702,9 @@ fn test_linux(target: &str) { if musl && ty == "seccomp_notif_sizes" { return true; } - if musl && ty == "ptp_sys_offset_extended" { + + // FIXME: CI has old headers + if ty == "ptp_sys_offset_extended" { return true; } diff --git a/src/unix/linux_like/linux/mod.rs b/src/unix/linux_like/linux/mod.rs index bcfbf530872ed..6ee2eec53fe4b 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; @@ -847,7 +848,8 @@ s! { pub struct ptp_sys_offset_extended { pub n_samples: ::c_uint, - pub rsv: [::c_uint; 3], + pub clockid: __kernel_clockid_t, + pub rsv: [::c_uint; 2], pub ts: [[ptp_clock_time; 3]; PTP_MAX_SAMPLES as usize], } From c9d29cc2fe1795c27f7f3ef9175c2ee216ae1b8f Mon Sep 17 00:00:00 2001 From: Folkert de Vries Date: Tue, 19 Nov 2024 11:48:00 +0100 Subject: [PATCH 23/25] todo -> fixme --- src/unix/linux_like/linux/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/unix/linux_like/linux/mod.rs b/src/unix/linux_like/linux/mod.rs index 6ee2eec53fe4b..d9ce59465f2c0 100644 --- a/src/unix/linux_like/linux/mod.rs +++ b/src/unix/linux_like/linux/mod.rs @@ -5579,7 +5579,7 @@ const _IOC_DIRSHIFT: u32 = _IOC_SIZESHIFT + _IOC_SIZEBITS; /// 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 { - // TODO the `garando_syntax` crate (used by ctest2 in the CI test suite) + // 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); From f550a24fe339fed01ea979ea9cd791e57faf167a Mon Sep 17 00:00:00 2001 From: Folkert de Vries Date: Tue, 19 Nov 2024 11:55:39 +0100 Subject: [PATCH 24/25] add symbols to semver/linux.txt --- libc-test/semver/linux.txt | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/libc-test/semver/linux.txt b/libc-test/semver/linux.txt index 6286abd032fbc..1873aa38ac577 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_CLOCK_CAPS_RSV_LEN PTP_CLOCK_GETCAPS PTP_CLOCK_GETCAPS2 PTP_ENABLE_PPS @@ -3580,6 +3581,8 @@ __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 @@ -3938,6 +3941,16 @@ pthread_spin_lock pthread_spin_trylock pthread_spin_unlock pthread_spinlock_t +ptp_clock_caps +ptp_clock_time +ptp_extts_event +ptp_extts_request +ptp_perout_request +ptp_pin_desc +ptp_pin_function +ptp_sys_offset +ptp_sys_offset_extended +ptp_sys_offset_precise ptrace ptsname_r pwrite64 From b3d238985123b4a63e213741e6b661d53e876a6e Mon Sep 17 00:00:00 2001 From: Folkert de Vries Date: Tue, 19 Nov 2024 12:14:43 +0100 Subject: [PATCH 25/25] fix rebase problem --- src/fuchsia/mod.rs | 65 +++++------- src/unix/linux_like/linux/mod.rs | 164 ++++++++++++++++++++++++++++--- 2 files changed, 175 insertions(+), 54 deletions(-) diff --git a/src/fuchsia/mod.rs b/src/fuchsia/mod.rs index df75b1eb05e21..8d0010bbc12b6 100644 --- a/src/fuchsia/mod.rs +++ b/src/fuchsia/mod.rs @@ -121,7 +121,7 @@ impl ::Clone for fpos64_t { // PUB_STRUCT -fn s_fmt_tmp() { +s! { pub struct group { pub gr_name: *mut ::c_char, pub gr_passwd: *mut ::c_char, @@ -907,7 +907,7 @@ fn s_fmt_tmp() { } } -fn s_no_extra_traits_fmt_tmp() { +s_no_extra_traits! { pub struct sysinfo { pub uptime: ::c_ulong, pub loads: [::c_ulong; 3], @@ -1048,8 +1048,8 @@ fn s_no_extra_traits_fmt_tmp() { } } -fn cfg_if_fmt_tmp() { - if cfg_tmp!([feature = "extra_traits"]) { +cfg_if! { + if #[cfg(feature = "extra_traits")] { impl PartialEq for sysinfo { fn eq(&self, other: &sysinfo) -> bool { self.uptime == other.uptime @@ -3357,10 +3357,10 @@ pub const HUGETLB_FLAG_ENCODE_SHIFT: u32 = 26; pub const MAP_HUGE_SHIFT: u32 = 26; // intentionally not public, only used for fd_set -fn cfg_if_fmt_tmp() { - if cfg_tmp!([target_pointer_width = "32"]) { +cfg_if! { + if #[cfg(target_pointer_width = "32")] { const ULONG_SIZE: usize = 32; - } else if cfg_tmp!([target_pointer_width = "64"]) { + } else if #[cfg(target_pointer_width = "64")] { const ULONG_SIZE: usize = 64; } else { // Unknown target_pointer_width @@ -3369,7 +3369,7 @@ fn cfg_if_fmt_tmp() { // END_PUB_CONST -fn f_fmt_tmp() { +f! { pub fn FD_CLR(fd: ::c_int, set: *mut fd_set) -> () { let fd = fd as usize; let size = ::mem::size_of_val(&(*set).fds_bits[0]) * 8; @@ -3462,70 +3462,57 @@ fn f_fmt_tmp() { } } - /* FMT-CONST */ - pub const fn CMSG_ALIGN(len: ::size_t) -> ::size_t { + pub {const} fn CMSG_ALIGN(len: ::size_t) -> ::size_t { (len + ::mem::size_of::<::size_t>() - 1) & !(::mem::size_of::<::size_t>() - 1) } - /* FMT-CONST */ - pub const fn CMSG_SPACE(len: ::c_uint) -> ::c_uint { + pub {const} fn CMSG_SPACE(len: ::c_uint) -> ::c_uint { (CMSG_ALIGN(len as ::size_t) + CMSG_ALIGN(::mem::size_of::())) as ::c_uint } - /* FMT-CONST */ - pub const fn CMSG_LEN(len: ::c_uint) -> ::c_uint { + pub {const} fn CMSG_LEN(len: ::c_uint) -> ::c_uint { (CMSG_ALIGN(::mem::size_of::()) + len as ::size_t) as ::c_uint } } -fn safe_f_fmt_tmp() { - /* FMT-CONST */ - pub const fn WIFSTOPPED(status: ::c_int) -> bool { +safe_f! { + pub {const} fn WIFSTOPPED(status: ::c_int) -> bool { (status & 0xff) == 0x7f } - /* FMT-CONST */ - pub const fn WSTOPSIG(status: ::c_int) -> ::c_int { + pub {const} fn WSTOPSIG(status: ::c_int) -> ::c_int { (status >> 8) & 0xff } - /* FMT-CONST */ - pub const fn WIFCONTINUED(status: ::c_int) -> bool { + pub {const} fn WIFCONTINUED(status: ::c_int) -> bool { status == 0xffff } - /* FMT-CONST */ - pub const fn WIFSIGNALED(status: ::c_int) -> bool { + pub {const} fn WIFSIGNALED(status: ::c_int) -> bool { ((status & 0x7f) + 1) as i8 >= 2 } - /* FMT-CONST */ - pub const fn WTERMSIG(status: ::c_int) -> ::c_int { + pub {const} fn WTERMSIG(status: ::c_int) -> ::c_int { status & 0x7f } - /* FMT-CONST */ - pub const fn WIFEXITED(status: ::c_int) -> bool { + pub {const} fn WIFEXITED(status: ::c_int) -> bool { (status & 0x7f) == 0 } - /* FMT-CONST */ - pub const fn WEXITSTATUS(status: ::c_int) -> ::c_int { + pub {const} fn WEXITSTATUS(status: ::c_int) -> ::c_int { (status >> 8) & 0xff } - /* FMT-CONST */ - pub const fn WCOREDUMP(status: ::c_int) -> bool { + pub {const} fn WCOREDUMP(status: ::c_int) -> bool { (status & 0x80) != 0 } - /* FMT-CONST */ - pub const fn QCMD(cmd: ::c_int, type_: ::c_int) -> ::c_int { + pub {const} fn QCMD(cmd: ::c_int, type_: ::c_int) -> ::c_int { (cmd << 8) | (type_ & 0x00ff) } - /* FMT-CONST */ - pub const fn makedev(major: ::c_uint, minor: ::c_uint) -> ::dev_t { + pub {const} fn makedev(major: ::c_uint, minor: ::c_uint) -> ::dev_t { let major = major as ::dev_t; let minor = minor as ::dev_t; let mut dev = 0; @@ -4468,14 +4455,14 @@ extern "C" { ) -> ::c_int; } -fn cfg_if_fmt_tmp() { - if cfg_tmp!([target_arch = "aarch64"]) { +cfg_if! { + if #[cfg(target_arch = "aarch64")] { mod aarch64; pub use self::aarch64::*; - } else if cfg_tmp!([any(target_arch = "x86_64")]) { + } else if #[cfg(any(target_arch = "x86_64"))] { mod x86_64; pub use self::x86_64::*; - } else if cfg_tmp!([any(target_arch = "riscv64")]) { + } else if #[cfg(any(target_arch = "riscv64"))] { mod riscv64; pub use self::riscv64::*; } else { diff --git a/src/unix/linux_like/linux/mod.rs b/src/unix/linux_like/linux/mod.rs index d9ce59465f2c0..9daf3d0cb328a 100644 --- a/src/unix/linux_like/linux/mod.rs +++ b/src/unix/linux_like/linux/mod.rs @@ -1412,26 +1412,160 @@ s_no_extra_traits! { pub offset_to_priv: ::__u32, pub hdr: ::tpacket_bd_header_u, } -} -s! { - // linux/ptp_clock.h - pub struct ptp_sys_offset { - pub n_samples: ::c_uint, - pub rsv: [::c_uint; 3], - pub ts: [ptp_clock_time; 2 * PTP_MAX_SAMPLES as usize + 1], + #[cfg_attr( + all( + any(target_env = "musl", target_env = "ohos"), + target_pointer_width = "32" + ), + repr(align(4)) + )] + #[cfg_attr( + all( + any(target_env = "musl", target_env = "ohos"), + target_pointer_width = "64" + ), + repr(align(8)) + )] + #[cfg_attr( + all( + not(any(target_env = "musl", target_env = "ohos")), + target_arch = "x86" + ), + repr(align(4)) + )] + #[cfg_attr( + all( + not(any(target_env = "musl", target_env = "ohos")), + not(target_arch = "x86") + ), + repr(align(8)) + )] + pub struct pthread_cond_t { + #[doc(hidden)] + size: [u8; ::__SIZEOF_PTHREAD_COND_T], } - 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_attr( + all( + target_pointer_width = "32", + any( + target_arch = "mips", + target_arch = "mips32r6", + target_arch = "arm", + target_arch = "hexagon", + target_arch = "m68k", + target_arch = "csky", + target_arch = "powerpc", + target_arch = "sparc", + target_arch = "x86_64", + target_arch = "x86" + ) + ), + repr(align(4)) + )] + #[cfg_attr( + any( + target_pointer_width = "64", + not(any( + target_arch = "mips", + target_arch = "mips32r6", + target_arch = "arm", + target_arch = "hexagon", + target_arch = "m68k", + target_arch = "csky", + target_arch = "powerpc", + target_arch = "sparc", + target_arch = "x86_64", + target_arch = "x86" + )) + ), + repr(align(8)) + )] + pub struct pthread_mutex_t { + #[doc(hidden)] + size: [u8; ::__SIZEOF_PTHREAD_MUTEX_T], + } + + #[cfg_attr( + all( + target_pointer_width = "32", + any( + target_arch = "mips", + target_arch = "mips32r6", + target_arch = "arm", + target_arch = "hexagon", + target_arch = "m68k", + target_arch = "csky", + target_arch = "powerpc", + target_arch = "sparc", + target_arch = "x86_64", + target_arch = "x86" + ) + ), + repr(align(4)) + )] + #[cfg_attr( + any( + target_pointer_width = "64", + not(any( + target_arch = "mips", + target_arch = "mips32r6", + target_arch = "arm", + target_arch = "hexagon", + target_arch = "m68k", + target_arch = "powerpc", + target_arch = "sparc", + target_arch = "x86_64", + target_arch = "x86" + )) + ), + repr(align(8)) + )] + pub struct pthread_rwlock_t { + size: [u8; ::__SIZEOF_PTHREAD_RWLOCK_T], + } + + #[cfg_attr( + all( + target_pointer_width = "32", + any( + target_arch = "mips", + target_arch = "mips32r6", + target_arch = "arm", + target_arch = "hexagon", + target_arch = "m68k", + target_arch = "csky", + target_arch = "powerpc", + target_arch = "sparc", + target_arch = "x86_64", + target_arch = "x86" + ) + ), + repr(align(4)) + )] + #[cfg_attr( + any( + target_pointer_width = "64", + not(any( + target_arch = "mips", + target_arch = "mips32r6", + target_arch = "arm", + target_arch = "hexagon", + target_arch = "m68k", + target_arch = "csky", + target_arch = "powerpc", + target_arch = "sparc", + target_arch = "x86_64", + target_arch = "x86" + )) + ), + repr(align(8)) + )] + pub struct pthread_barrier_t { + size: [u8; ::__SIZEOF_PTHREAD_BARRIER_T], } -} -s_no_extra_traits! { // linux/net_tstamp.h #[allow(missing_debug_implementations)] pub struct sock_txtime {