Skip to content

Commit ea1e561

Browse files
committed
Auto merge of #3273 - flba-eb:add_qnx_extra_traits, r=JohnTitor
Add trait implementations for QNX Neutrino This change: - adds some missing trait implementations (some structs have been moved to the correct macro) - fixes signal handling `@gh-tr` I would appreciate a new libc release with this change very much, as enhancements for other crates (nix, rustix) depend on it. ❤️
2 parents c16d97c + 0c7a69c commit ea1e561

File tree

4 files changed

+268
-41
lines changed

4 files changed

+268
-41
lines changed

libc-test/build.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2980,7 +2980,8 @@ fn test_neutrino(target: &str) {
29802980
cfg.skip_field(move |struct_, field| {
29812981
(struct_ == "__sched_param" && field == "reserved") ||
29822982
(struct_ == "sched_param" && field == "reserved") ||
2983-
(struct_ == "sigevent" && field == "__sigev_un1") || // union
2983+
(struct_ == "sigevent" && field == "__padding1") || // ensure alignment
2984+
(struct_ == "sigevent" && field == "__padding2") || // union
29842985
(struct_ == "sigevent" && field == "__sigev_un2") || // union
29852986
// sighandler_t type is super weird
29862987
(struct_ == "sigaction" && field == "sa_sigaction") ||

src/unix/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1499,6 +1499,11 @@ cfg_if! {
14991499
timeout: *mut timespec,
15001500
sigmask: *const sigset_t,
15011501
) -> ::c_int;
1502+
pub fn sigaction(
1503+
signum: ::c_int,
1504+
act: *const sigaction,
1505+
oldact: *mut sigaction
1506+
) -> ::c_int;
15021507
}
15031508
} else {
15041509
extern {

src/unix/nto/mod.rs

Lines changed: 251 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,33 @@ impl ::Clone for timezone {
8080
}
8181

8282
s! {
83+
pub struct dirent_extra {
84+
pub d_datalen: u16,
85+
pub d_type: u16,
86+
pub d_reserved: u32,
87+
}
88+
89+
pub struct stat {
90+
pub st_ino: ::ino_t,
91+
pub st_size: ::off_t,
92+
pub st_dev: ::dev_t,
93+
pub st_rdev: ::dev_t,
94+
pub st_uid: ::uid_t,
95+
pub st_gid: ::gid_t,
96+
pub __old_st_mtime: ::_Time32t,
97+
pub __old_st_atime: ::_Time32t,
98+
pub __old_st_ctime: ::_Time32t,
99+
pub st_mode: ::mode_t,
100+
pub st_nlink: ::nlink_t,
101+
pub st_blocksize: ::blksize_t,
102+
pub st_nblocks: i32,
103+
pub st_blksize: ::blksize_t,
104+
pub st_blocks: ::blkcnt_t,
105+
pub st_mtim: ::timespec,
106+
pub st_atim: ::timespec,
107+
pub st_ctim: ::timespec,
108+
}
109+
83110
pub struct ip_mreq {
84111
pub imr_multiaddr: in_addr,
85112
pub imr_interface: in_addr,
@@ -641,7 +668,9 @@ s_no_extra_traits! {
641668

642669
pub struct sigevent {
643670
pub sigev_notify: ::c_int,
644-
__sigev_un1: usize, // union
671+
pub __padding1: ::c_int,
672+
pub sigev_signo: ::c_int, // union
673+
pub __padding2: ::c_int,
645674
pub sigev_value: ::sigval,
646675
__sigev_un2: usize, // union
647676

@@ -654,33 +683,6 @@ s_no_extra_traits! {
654683
pub d_name: [::c_char; 1], // flex array
655684
}
656685

657-
pub struct dirent_extra {
658-
pub d_datalen: u16,
659-
pub d_type: u16,
660-
pub d_reserved: u32,
661-
}
662-
663-
pub struct stat {
664-
pub st_ino: ::ino_t,
665-
pub st_size: ::off_t,
666-
pub st_dev: ::dev_t,
667-
pub st_rdev: ::dev_t,
668-
pub st_uid: ::uid_t,
669-
pub st_gid: ::gid_t,
670-
pub __old_st_mtime: ::_Time32t,
671-
pub __old_st_atime: ::_Time32t,
672-
pub __old_st_ctime: ::_Time32t,
673-
pub st_mode: ::mode_t,
674-
pub st_nlink: ::nlink_t,
675-
pub st_blocksize: ::blksize_t,
676-
pub st_nblocks: i32,
677-
pub st_blksize: ::blksize_t,
678-
pub st_blocks: ::blkcnt_t,
679-
pub st_mtim: ::timespec,
680-
pub st_atim: ::timespec,
681-
pub st_ctim: ::timespec,
682-
}
683-
684686
pub struct sigset_t {
685687
__val: [u32; 2],
686688
}
@@ -756,6 +758,37 @@ s_no_extra_traits! {
756758

757759
cfg_if! {
758760
if #[cfg(feature = "extra_traits")] {
761+
// sigevent
762+
impl PartialEq for sigevent {
763+
fn eq(&self, other: &sigevent) -> bool {
764+
self.sigev_notify == other.sigev_notify
765+
&& self.sigev_signo == other.sigev_signo
766+
&& self.sigev_value == other.sigev_value
767+
&& self.__sigev_un2
768+
== other.__sigev_un2
769+
}
770+
}
771+
impl Eq for sigevent {}
772+
impl ::fmt::Debug for sigevent {
773+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
774+
f.debug_struct("sigevent")
775+
.field("sigev_notify", &self.sigev_notify)
776+
.field("sigev_signo", &self.sigev_signo)
777+
.field("sigev_value", &self.sigev_value)
778+
.field("__sigev_un2",
779+
&self.__sigev_un2)
780+
.finish()
781+
}
782+
}
783+
impl ::hash::Hash for sigevent {
784+
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
785+
self.sigev_notify.hash(state);
786+
self.sigev_signo.hash(state);
787+
self.sigev_value.hash(state);
788+
self.__sigev_un2.hash(state);
789+
}
790+
}
791+
759792
impl PartialEq for sockaddr_un {
760793
fn eq(&self, other: &sockaddr_un) -> bool {
761794
self.sun_len == other.sun_len
@@ -767,9 +800,7 @@ cfg_if! {
767800
.all(|(a,b)| a == b)
768801
}
769802
}
770-
771803
impl Eq for sockaddr_un {}
772-
773804
impl ::fmt::Debug for sockaddr_un {
774805
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
775806
f.debug_struct("sockaddr_un")
@@ -788,6 +819,168 @@ cfg_if! {
788819
}
789820
}
790821

822+
// sigset_t
823+
impl PartialEq for sigset_t {
824+
fn eq(&self, other: &sigset_t) -> bool {
825+
self.__val == other.__val
826+
}
827+
}
828+
impl Eq for sigset_t {}
829+
impl ::fmt::Debug for sigset_t {
830+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
831+
f.debug_struct("sigset_t")
832+
.field("__val", &self.__val)
833+
.finish()
834+
}
835+
}
836+
impl ::hash::Hash for sigset_t {
837+
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
838+
self.__val.hash(state);
839+
}
840+
}
841+
842+
// msg
843+
impl ::fmt::Debug for msg {
844+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
845+
f.debug_struct("msg")
846+
.field("msg_next", &self.msg_next)
847+
.field("msg_type", &self.msg_type)
848+
.field("msg_ts", &self.msg_ts)
849+
.field("msg_spot", &self.msg_spot)
850+
.finish()
851+
}
852+
}
853+
854+
// msqid_ds
855+
impl ::fmt::Debug for msqid_ds {
856+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
857+
f.debug_struct("msqid_ds")
858+
.field("msg_perm", &self.msg_perm)
859+
.field("msg_first", &self.msg_first)
860+
.field("msg_cbytes", &self.msg_cbytes)
861+
.field("msg_qnum", &self.msg_qnum)
862+
.field("msg_qbytes", &self.msg_qbytes)
863+
.field("msg_lspid", &self.msg_lspid)
864+
.field("msg_lrpid", &self.msg_lrpid)
865+
.field("msg_stime", &self.msg_stime)
866+
.field("msg_rtime", &self.msg_rtime)
867+
.field("msg_ctime", &self.msg_ctime)
868+
.finish()
869+
}
870+
}
871+
872+
// sockaddr_dl
873+
impl ::fmt::Debug for sockaddr_dl {
874+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
875+
f.debug_struct("sockaddr_dl")
876+
.field("sdl_len", &self.sdl_len)
877+
.field("sdl_family", &self.sdl_family)
878+
.field("sdl_index", &self.sdl_index)
879+
.field("sdl_type", &self.sdl_type)
880+
.field("sdl_nlen", &self.sdl_nlen)
881+
.field("sdl_alen", &self.sdl_alen)
882+
.field("sdl_slen", &self.sdl_slen)
883+
.field("sdl_data", &self.sdl_data)
884+
.finish()
885+
}
886+
}
887+
impl PartialEq for sockaddr_dl {
888+
fn eq(&self, other: &sockaddr_dl) -> bool {
889+
self.sdl_len == other.sdl_len
890+
&& self.sdl_family == other.sdl_family
891+
&& self.sdl_index == other.sdl_index
892+
&& self.sdl_type == other.sdl_type
893+
&& self.sdl_nlen == other.sdl_nlen
894+
&& self.sdl_alen == other.sdl_alen
895+
&& self.sdl_slen == other.sdl_slen
896+
&& self
897+
.sdl_data
898+
.iter()
899+
.zip(other.sdl_data.iter())
900+
.all(|(a,b)| a == b)
901+
}
902+
}
903+
impl Eq for sockaddr_dl {}
904+
impl ::hash::Hash for sockaddr_dl {
905+
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
906+
self.sdl_len.hash(state);
907+
self.sdl_family.hash(state);
908+
self.sdl_index.hash(state);
909+
self.sdl_type.hash(state);
910+
self.sdl_nlen.hash(state);
911+
self.sdl_alen.hash(state);
912+
self.sdl_slen.hash(state);
913+
self.sdl_data.hash(state);
914+
}
915+
}
916+
917+
// sync_t
918+
impl ::fmt::Debug for sync_t {
919+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
920+
f.debug_struct("sync_t")
921+
.field("__owner", &self.__owner)
922+
.field("__u", &self.__u)
923+
.finish()
924+
}
925+
}
926+
927+
// pthread_barrier_t
928+
impl ::fmt::Debug for pthread_barrier_t {
929+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
930+
f.debug_struct("pthread_barrier_t")
931+
.field("__pad", &self.__pad)
932+
.finish()
933+
}
934+
}
935+
936+
// pthread_rwlock_t
937+
impl ::fmt::Debug for pthread_rwlock_t {
938+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
939+
f.debug_struct("pthread_rwlock_t")
940+
.field("__active", &self.__active)
941+
.field("__blockedwriters", &self.__blockedwriters)
942+
.field("__blockedreaders", &self.__blockedreaders)
943+
.field("__heavy", &self.__heavy)
944+
.field("__lock", &self.__lock)
945+
.field("__rcond", &self.__rcond)
946+
.field("__wcond", &self.__wcond)
947+
.field("__owner", &self.__owner)
948+
.field("__spare", &self.__spare)
949+
.finish()
950+
}
951+
}
952+
953+
// syspage_entry
954+
impl ::fmt::Debug for syspage_entry {
955+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
956+
f.debug_struct("syspage_entry")
957+
.field("size", &self.size)
958+
.field("total_size", &self.total_size)
959+
.field("type_", &self.type_)
960+
.field("num_cpu", &self.num_cpu)
961+
.field("system_private", &self.system_private)
962+
.field("old_asinfo", &self.old_asinfo)
963+
.field("hwinfo", &self.hwinfo)
964+
.field("old_cpuinfo", &self.old_cpuinfo)
965+
.field("old_cacheattr", &self.old_cacheattr)
966+
.field("qtime", &self.qtime)
967+
.field("callout", &self.callout)
968+
.field("callin", &self.callin)
969+
.field("typed_strings", &self.typed_strings)
970+
.field("strings", &self.strings)
971+
.field("old_intrinfo", &self.old_intrinfo)
972+
.field("smp", &self.smp)
973+
.field("pminfo", &self.pminfo)
974+
.field("old_mdriver", &self.old_mdriver)
975+
.field("new_asinfo", &self.new_asinfo)
976+
.field("new_cpuinfo", &self.new_cpuinfo)
977+
.field("new_cacheattr", &self.new_cacheattr)
978+
.field("new_intrinfo", &self.new_intrinfo)
979+
.field("new_mdriver", &self.new_mdriver)
980+
.finish()
981+
}
982+
}
983+
791984
impl PartialEq for utsname {
792985
fn eq(&self, other: &utsname) -> bool {
793986
self.sysname
@@ -868,6 +1061,16 @@ cfg_if! {
8681061
.finish()
8691062
}
8701063
}
1064+
impl ::hash::Hash for mq_attr {
1065+
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
1066+
self.mq_maxmsg.hash(state);
1067+
self.mq_msgsize.hash(state);
1068+
self.mq_flags.hash(state);
1069+
self.mq_curmsgs.hash(state);
1070+
self.mq_sendwait.hash(state);
1071+
self.mq_recvwait.hash(state);
1072+
}
1073+
}
8711074

8721075
impl PartialEq for sockaddr_storage {
8731076
fn eq(&self, other: &sockaddr_storage) -> bool {
@@ -2606,6 +2809,14 @@ f! {
26062809
};
26072810
::mem::size_of::<sockcred>() + ::mem::size_of::<::gid_t>() * ngrps
26082811
}
2812+
2813+
pub fn major(dev: ::dev_t) -> ::c_uint {
2814+
((dev as ::c_uint) >> 10) & 0x3f
2815+
}
2816+
2817+
pub fn minor(dev: ::dev_t) -> ::c_uint {
2818+
(dev as ::c_uint) & 0x3ff
2819+
}
26092820
}
26102821

26112822
safe_f! {
@@ -2644,6 +2855,10 @@ safe_f! {
26442855
pub {const} fn IPTOS_ECN(x: u8) -> u8 {
26452856
x & ::IPTOS_ECN_MASK
26462857
}
2858+
2859+
pub {const} fn makedev(major: ::c_uint, minor: ::c_uint) -> ::dev_t {
2860+
((major << 10) | (minor)) as ::dev_t
2861+
}
26472862
}
26482863

26492864
// Network related functions are provided by libsocket and regex
@@ -2658,6 +2873,12 @@ extern "C" {
26582873
pub fn getpriority(which: ::c_int, who: ::id_t) -> ::c_int;
26592874
pub fn setpriority(which: ::c_int, who: ::id_t, prio: ::c_int) -> ::c_int;
26602875
pub fn mkfifoat(dirfd: ::c_int, pathname: *const ::c_char, mode: ::mode_t) -> ::c_int;
2876+
pub fn mknodat(
2877+
__fd: ::c_int,
2878+
pathname: *const ::c_char,
2879+
mode: ::mode_t,
2880+
dev: ::dev_t,
2881+
) -> ::c_int;
26612882

26622883
pub fn clock_getres(clk_id: ::clockid_t, tp: *mut ::timespec) -> ::c_int;
26632884
pub fn clock_gettime(clk_id: ::clockid_t, tp: *mut ::timespec) -> ::c_int;

0 commit comments

Comments
 (0)