Skip to content

Commit d0ed18d

Browse files
folkertdevtgross35
authored andcommitted
add various ptp_* structs
code is originally from rust-lang#3865. (backport <rust-lang#4113>) (cherry picked from commit 511a002)
1 parent 47a94d8 commit d0ed18d

File tree

3 files changed

+106
-1
lines changed

3 files changed

+106
-1
lines changed

libc-test/build.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3617,6 +3617,8 @@ fn test_linux(target: &str) {
36173617
"linux/netlink.h",
36183618
// FIXME: requires Linux >= 5.6:
36193619
[!musl]: "linux/openat2.h",
3620+
// FIXME: some items require Linux >= 5.6:
3621+
"linux/ptp_clock.h",
36203622
[!musl]: "linux/ptrace.h",
36213623
"linux/quota.h",
36223624
"linux/random.h",
@@ -3766,6 +3768,11 @@ fn test_linux(target: &str) {
37663768
return true;
37673769
}
37683770

3771+
// FIXME: CI has old headers
3772+
if ty == "ptp_sys_offset_extended" {
3773+
return true;
3774+
}
3775+
37693776
// LFS64 types have been removed in musl 1.2.4+
37703777
if musl && (ty.ends_with("64") || ty.ends_with("64_t")) {
37713778
return true;
@@ -4490,7 +4497,11 @@ fn test_linux(target: &str) {
44904497
// `__exit_status` type is a patch which is absent in musl
44914498
(struct_ == "utmpx" && field == "ut_exit" && musl) ||
44924499
// `can_addr` is an anonymous union
4493-
(struct_ == "sockaddr_can" && field == "can_addr")
4500+
(struct_ == "sockaddr_can" && field == "can_addr") ||
4501+
// `anonymous_1` is an anonymous union
4502+
(struct_ == "ptp_perout_request" && field == "anonymous_1") ||
4503+
// `anonymous_2` is an anonymous union
4504+
(struct_ == "ptp_perout_request" && field == "anonymous_2")
44944505
});
44954506

44964507
cfg.volatile_item(|i| {
@@ -4561,6 +4572,10 @@ fn test_linux(target: &str) {
45614572
(struct_ == "fanotify_event_info_fid" && field == "fsid") ||
45624573
// `handle` is a VLA
45634574
(struct_ == "fanotify_event_info_fid" && field == "handle") ||
4575+
// `anonymous_1` is an anonymous union
4576+
(struct_ == "ptp_perout_request" && field == "anonymous_1") ||
4577+
// `anonymous_2` is an anonymous union
4578+
(struct_ == "ptp_perout_request" && field == "anonymous_2") ||
45644579
// invalid application of 'sizeof' to incomplete type 'long unsigned int[]'
45654580
(musl && struct_ == "mcontext_t" && field == "__extcontext" && loongarch64) ||
45664581
// FIXME(#4121): a new field was added from `f_spare`

libc-test/semver/linux.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2252,6 +2252,7 @@ PTHREAD_PRIO_PROTECT
22522252
PTHREAD_PROCESS_PRIVATE
22532253
PTHREAD_PROCESS_SHARED
22542254
PTHREAD_STACK_MIN
2255+
PTP_MAX_SAMPLES
22552256
PTRACE_ATTACH
22562257
PTRACE_CONT
22572258
PTRACE_DETACH
@@ -3558,11 +3559,15 @@ __WNOTHREAD
35583559
__c_anonymous_ifc_ifcu
35593560
__c_anonymous_ifr_ifru
35603561
__c_anonymous_ifru_map
3562+
__c_anonymous_ptp_perout_request_1
3563+
__c_anonymous_ptp_perout_request_2
35613564
__c_anonymous_sockaddr_can_can_addr
35623565
__c_anonymous_sockaddr_can_j1939
35633566
__c_anonymous_sockaddr_can_tp
35643567
__errno_location
35653568
__exit_status
3569+
__kernel_clockid_t
3570+
__kernel_fsid_t
35663571
__s16
35673572
__s32
35683573
__u16
@@ -3916,6 +3921,14 @@ pthread_spin_lock
39163921
pthread_spin_trylock
39173922
pthread_spin_unlock
39183923
pthread_spinlock_t
3924+
ptp_clock_time
3925+
ptp_extts_event
3926+
ptp_extts_request
3927+
ptp_perout_request
3928+
ptp_pin_desc
3929+
ptp_sys_offset
3930+
ptp_sys_offset_extended
3931+
ptp_sys_offset_precise
39193932
ptrace
39203933
ptsname_r
39213934
pwrite64

src/unix/linux_like/linux/mod.rs

Lines changed: 77 additions & 0 deletions
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,23 @@ 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+
}
11451197
}
11461198

11471199
cfg_if! {
@@ -1580,6 +1632,28 @@ s_no_extra_traits! {
15801632
pub ifr_ifrn: __c_anonymous_iwreq,
15811633
pub u: iwreq_data,
15821634
}
1635+
1636+
// linux/ptp_clock.h
1637+
#[allow(missing_debug_implementations)]
1638+
pub union __c_anonymous_ptp_perout_request_1 {
1639+
pub start: ptp_clock_time,
1640+
pub phase: ptp_clock_time,
1641+
}
1642+
1643+
#[allow(missing_debug_implementations)]
1644+
pub union __c_anonymous_ptp_perout_request_2 {
1645+
pub on: ptp_clock_time,
1646+
pub rsv: [::c_uint; 4],
1647+
}
1648+
1649+
#[allow(missing_debug_implementations)]
1650+
pub struct ptp_perout_request {
1651+
pub anonymous_1: __c_anonymous_ptp_perout_request_1,
1652+
pub period: ptp_clock_time,
1653+
pub index: ::c_uint,
1654+
pub flags: ::c_uint,
1655+
pub anonymous_2: __c_anonymous_ptp_perout_request_2,
1656+
}
15831657
}
15841658

15851659
cfg_if! {
@@ -4504,6 +4578,9 @@ pub const HWTSTAMP_FILTER_PTP_V2_SYNC: ::c_uint = 13;
45044578
pub const HWTSTAMP_FILTER_PTP_V2_DELAY_REQ: ::c_uint = 14;
45054579
pub const HWTSTAMP_FILTER_NTP_ALL: ::c_uint = 15;
45064580

4581+
// linux/ptp_clock.h
4582+
pub const PTP_MAX_SAMPLES: ::c_uint = 25; // Maximum allowed offset measurement samples.
4583+
45074584
// linux/tls.h
45084585
pub const TLS_TX: ::c_int = 1;
45094586
pub const TLS_RX: ::c_int = 2;

0 commit comments

Comments
 (0)