Skip to content

Commit

Permalink
add various ptp_* structs
Browse files Browse the repository at this point in the history
code is originally from rust-lang#3865.
  • Loading branch information
folkertdev committed Nov 19, 2024
1 parent 2f931d9 commit 166b3eb
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 1 deletion.
17 changes: 16 additions & 1 deletion libc-test/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3552,6 +3552,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",
Expand Down Expand Up @@ -3701,6 +3703,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;
Expand Down Expand Up @@ -4422,7 +4429,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| {
Expand Down Expand Up @@ -4495,6 +4506,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)
});
Expand Down
13 changes: 13 additions & 0 deletions libc-test/semver/linux.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -3557,11 +3558,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
Expand Down Expand Up @@ -3915,6 +3920,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
Expand Down
77 changes: 77 additions & 0 deletions src/unix/linux_like/linux/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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! {
Expand Down Expand Up @@ -1574,6 +1626,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! {
Expand Down Expand Up @@ -4464,6 +4538,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;
Expand Down

0 comments on commit 166b3eb

Please sign in to comment.