Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add all definitions from linux/ptp-clock.h #3559

Open
wants to merge 1 commit into
base: libc-0.2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 25 additions & 2 deletions libc-test/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3457,6 +3457,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",
Expand Down Expand Up @@ -3594,6 +3596,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")) {
Expand Down Expand Up @@ -3757,6 +3762,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
Expand All @@ -3769,6 +3775,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;
}
Expand Down Expand Up @@ -4264,7 +4279,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 @@ -4322,7 +4341,11 @@ fn test_linux(target: &str) {
// the `ifc_ifcu` field is an anonymous union
(struct_ == "ifconf" && field == "ifc_ifcu") ||
// glibc uses a single array `uregs` instead of individual fields.
(struct_ == "user_regs" && arm)
(struct_ == "user_regs" && arm) ||
// `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")
Comment on lines +4344 to +4348
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure why but both this and block and the block above excluding these fields seem required for CI to be satisfied?!

});

cfg.skip_roundtrip(move |s| match s {
Expand Down
23 changes: 23 additions & 0 deletions libc-test/semver/linux.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1990,6 +1990,29 @@ PTHREAD_INHERIT_SCHED
PTHREAD_EXPLICIT_SCHED
PTHREAD_STACK_MIN
PTHREAD_ONCE_INIT
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
Expand Down
202 changes: 202 additions & 0 deletions src/unix/linux_like/linux/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,57 @@ s! {
pub val: ::c_int,
}

// 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 {
Expand Down Expand Up @@ -889,6 +940,21 @@ s_no_extra_traits! {
pub sched_deadline: ::__u64,
pub sched_period: ::__u64,
}

// 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],
}
}

s_no_extra_traits! {
Expand Down Expand Up @@ -920,6 +986,34 @@ cfg_if! {
}
}

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 {
Expand Down Expand Up @@ -1394,6 +1488,62 @@ cfg_if! {
self.sched_period.hash(state);
}
}

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<H: ::hash::Hasher>(&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<H: ::hash::Hasher>(&self, state: &mut H) {
self.name[..].hash(state);
self.index.hash(state);
self.func.hash(state);
self.chan.hash(state);
self.rsv.hash(state);
}
}
}
}

Expand Down Expand Up @@ -3638,6 +3788,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;
Comment on lines +3796 to +3803
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these are defined with some macros. There are rust versions here https://github.com/torvalds/linux/blob/8a696a29c6905594e4abf78eaafcb62165ac61f1/rust/kernel/ioctl.rs#L13

should those be used instead?

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;
Expand Down