Skip to content

Commit 95f4217

Browse files
committed
add various ptp_* structs
1 parent 2f931d9 commit 95f4217

File tree

3 files changed

+143
-1
lines changed

3 files changed

+143
-1
lines changed

libc-test/build.rs

+16-1
Original file line numberDiff line numberDiff line change
@@ -3552,6 +3552,8 @@ fn test_linux(target: &str) {
35523552
"linux/netlink.h",
35533553
// FIXME: requires Linux >= 5.6:
35543554
[!musl]: "linux/openat2.h",
3555+
// FIXME: some items require Linux >= 5.6:
3556+
"linux/ptp_clock.h",
35553557
[!musl]: "linux/ptrace.h",
35563558
"linux/quota.h",
35573559
"linux/random.h",
@@ -3701,6 +3703,11 @@ fn test_linux(target: &str) {
37013703
return true;
37023704
}
37033705

3706+
// FIXME: CI has old headers
3707+
if ty == "ptp_sys_offset_extended" {
3708+
return true;
3709+
}
3710+
37043711
// LFS64 types have been removed in musl 1.2.4+
37053712
if musl && (ty.ends_with("64") || ty.ends_with("64_t")) {
37063713
return true;
@@ -4422,7 +4429,11 @@ fn test_linux(target: &str) {
44224429
// `__exit_status` type is a patch which is absent in musl
44234430
(struct_ == "utmpx" && field == "ut_exit" && musl) ||
44244431
// `can_addr` is an anonymous union
4425-
(struct_ == "sockaddr_can" && field == "can_addr")
4432+
(struct_ == "sockaddr_can" && field == "can_addr") ||
4433+
// `anonymous_1` is an anonymous union
4434+
(struct_ == "ptp_perout_request" && field == "anonymous_1") ||
4435+
// `anonymous_2` is an anonymous union
4436+
(struct_ == "ptp_perout_request" && field == "anonymous_2")
44264437
});
44274438

44284439
cfg.volatile_item(|i| {
@@ -4495,6 +4506,10 @@ fn test_linux(target: &str) {
44954506
(struct_ == "fanotify_event_info_fid" && field == "fsid") ||
44964507
// `handle` is a VLA
44974508
(struct_ == "fanotify_event_info_fid" && field == "handle") ||
4509+
// `anonymous_1` is an anonymous union
4510+
(struct_ == "ptp_perout_request" && field == "anonymous_1") ||
4511+
// `anonymous_2` is an anonymous union
4512+
(struct_ == "ptp_perout_request" && field == "anonymous_2") ||
44984513
// invalid application of 'sizeof' to incomplete type 'long unsigned int[]'
44994514
(musl && struct_ == "mcontext_t" && field == "__extcontext" && loongarch64)
45004515
});

libc-test/semver/linux.txt

+13
Original file line numberDiff line numberDiff line change
@@ -2252,6 +2252,8 @@ PTHREAD_PRIO_PROTECT
22522252
PTHREAD_PROCESS_PRIVATE
22532253
PTHREAD_PROCESS_SHARED
22542254
PTHREAD_STACK_MIN
2255+
PTP_CLOCK_CAPS_RSV_LEN
2256+
PTP_MAX_SAMPLES
22552257
PTRACE_ATTACH
22562258
PTRACE_CONT
22572259
PTRACE_DETACH
@@ -3557,6 +3559,8 @@ __WNOTHREAD
35573559
__c_anonymous_ifc_ifcu
35583560
__c_anonymous_ifr_ifru
35593561
__c_anonymous_ifru_map
3562+
__c_anonymous_ptp_perout_request_1
3563+
__c_anonymous_ptp_perout_request_2
35603564
__c_anonymous_sockaddr_can_can_addr
35613565
__c_anonymous_sockaddr_can_j1939
35623566
__c_anonymous_sockaddr_can_tp
@@ -3915,6 +3919,15 @@ pthread_spin_lock
39153919
pthread_spin_trylock
39163920
pthread_spin_unlock
39173921
pthread_spinlock_t
3922+
ptp_clock_caps
3923+
ptp_clock_time
3924+
ptp_extts_event
3925+
ptp_extts_request
3926+
ptp_perout_request
3927+
ptp_pin_desc
3928+
ptp_sys_offset
3929+
ptp_sys_offset_extended
3930+
ptp_sys_offset_precise
39183931
ptrace
39193932
ptsname_r
39203933
pwrite64

src/unix/linux_like/linux/mod.rs

+114
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ pub type pthread_key_t = ::c_uint;
1919
pub type pthread_once_t = ::c_int;
2020
pub type pthread_spinlock_t = ::c_int;
2121
pub type __kernel_fsid_t = __c_anonymous__kernel_fsid_t;
22+
pub type __kernel_clockid_t = ::c_int;
2223

2324
pub type __u8 = ::c_uchar;
2425
pub type __u16 = ::c_ushort;
@@ -829,6 +830,40 @@ s! {
829830
pub resolve: ::__u64,
830831
}
831832

833+
// linux/ptp_clock.h
834+
pub struct ptp_clock_time {
835+
pub sec: ::__s64,
836+
pub nsec: ::__u32,
837+
pub reserved: ::__u32,
838+
}
839+
840+
pub struct ptp_extts_request {
841+
pub index: ::c_uint,
842+
pub flags: ::c_uint,
843+
pub rsv: [::c_uint; 2],
844+
}
845+
846+
pub struct ptp_sys_offset_extended {
847+
pub n_samples: ::c_uint,
848+
pub clockid: __kernel_clockid_t,
849+
pub rsv: [::c_uint; 2],
850+
pub ts: [[ptp_clock_time; 3]; PTP_MAX_SAMPLES as usize],
851+
}
852+
853+
pub struct ptp_sys_offset_precise {
854+
pub device: ptp_clock_time,
855+
pub sys_realtime: ptp_clock_time,
856+
pub sys_monoraw: ptp_clock_time,
857+
pub rsv: [::c_uint; 4],
858+
}
859+
860+
pub struct ptp_extts_event {
861+
pub t: ptp_clock_time,
862+
index: ::c_uint,
863+
flags: ::c_uint,
864+
rsv: [::c_uint; 2],
865+
}
866+
832867
// linux/sctp.h
833868

834869
pub struct sctp_initmsg {
@@ -1142,6 +1177,50 @@ s! {
11421177
pub fd: ::c_int,
11431178
pub pid: ::c_int,
11441179
}
1180+
1181+
// linux/ptp_clock.h
1182+
1183+
pub struct ptp_sys_offset {
1184+
pub n_samples: ::c_uint,
1185+
pub rsv: [::c_uint; 3],
1186+
// FIXME(garando): replace length with `2 * PTP_MAX_SAMPLES + 1` when supported
1187+
pub ts: [ptp_clock_time; 51],
1188+
}
1189+
1190+
pub struct ptp_pin_desc {
1191+
pub name: [::c_char; 64],
1192+
pub index: ::c_uint,
1193+
pub func: ::c_uint,
1194+
pub chan: ::c_uint,
1195+
pub rsv: [::c_uint; 5],
1196+
}
1197+
1198+
pub struct ptp_clock_caps {
1199+
pub max_adj: ::c_int,
1200+
pub n_alarm: ::c_int,
1201+
pub n_ext_ts: ::c_int,
1202+
pub n_per_out: ::c_int,
1203+
pub pps: ::c_int,
1204+
pub n_pins: ::c_int,
1205+
pub cross_timestamping: ::c_int,
1206+
#[cfg(any(target_arch = "sparc", target_arch = "sparc64"))]
1207+
pub adjust_phase: ::c_int,
1208+
#[cfg(not(any(
1209+
any(target_arch = "sparc", target_arch = "sparc64"),
1210+
any(target_env = "musl", target_env = "ohos"),
1211+
)))]
1212+
pub adjust_phase: ::c_int,
1213+
#[cfg(not(any(
1214+
any(target_arch = "sparc", target_arch = "sparc64"),
1215+
any(target_env = "musl", target_env = "ohos"),
1216+
)))]
1217+
pub max_phase_adj: ::c_int,
1218+
#[cfg(not(any(
1219+
any(target_arch = "sparc", target_arch = "sparc64"),
1220+
any(target_env = "musl", target_env = "ohos"),
1221+
)))]
1222+
pub rsv: [::c_int; PTP_CLOCK_CAPS_RSV_LEN],
1223+
}
11451224
}
11461225

11471226
cfg_if! {
@@ -1574,6 +1653,28 @@ s_no_extra_traits! {
15741653
pub ifr_ifrn: __c_anonymous_iwreq,
15751654
pub u: iwreq_data,
15761655
}
1656+
1657+
// linux/ptp_clock.h
1658+
#[allow(missing_debug_implementations)]
1659+
pub union __c_anonymous_ptp_perout_request_1 {
1660+
pub start: ptp_clock_time,
1661+
pub phase: ptp_clock_time,
1662+
}
1663+
1664+
#[allow(missing_debug_implementations)]
1665+
pub union __c_anonymous_ptp_perout_request_2 {
1666+
pub on: ptp_clock_time,
1667+
pub rsv: [::c_uint; 4],
1668+
}
1669+
1670+
#[allow(missing_debug_implementations)]
1671+
pub struct ptp_perout_request {
1672+
pub anonymous_1: __c_anonymous_ptp_perout_request_1,
1673+
pub period: ptp_clock_time,
1674+
pub index: ::c_uint,
1675+
pub flags: ::c_uint,
1676+
pub anonymous_2: __c_anonymous_ptp_perout_request_2,
1677+
}
15771678
}
15781679

15791680
cfg_if! {
@@ -4464,6 +4565,19 @@ pub const HWTSTAMP_FILTER_PTP_V2_SYNC: ::c_uint = 13;
44644565
pub const HWTSTAMP_FILTER_PTP_V2_DELAY_REQ: ::c_uint = 14;
44654566
pub const HWTSTAMP_FILTER_NTP_ALL: ::c_uint = 15;
44664567

4568+
// linux/ptp_clock.h
4569+
pub const PTP_MAX_SAMPLES: ::c_uint = 25; // Maximum allowed offset measurement samples.
4570+
4571+
pub const PTP_CLOCK_CAPS_RSV_LEN: usize = {
4572+
if cfg!(any(target_arch = "sparc", target_arch = "sparc64")) {
4573+
12
4574+
} else if cfg!(any(target_env = "musl", target_env = "ohos")) {
4575+
13
4576+
} else {
4577+
11
4578+
}
4579+
}
4580+
44674581
// linux/tls.h
44684582
pub const TLS_TX: ::c_int = 1;
44694583
pub const TLS_RX: ::c_int = 2;

0 commit comments

Comments
 (0)