diff --git a/ci/verify-build.py b/ci/verify-build.py index 0e0ea0c25b2ca..b3b35f1c6e0bc 100755 --- a/ci/verify-build.py +++ b/ci/verify-build.py @@ -155,6 +155,7 @@ class TargetResult: Target("aarch64-unknown-openbsd", dist=False), Target("aarch64-wrs-vxworks", dist=False), Target("armebv7r-none-eabihf", dist=False), + Target("armv7-rtems-eabihf", dist=False), Target("armv7-wrs-vxworks-eabihf", dist=False), Target("armv7r-none-eabihf", dist=False), Target("armv7s-apple-ios", dist=False), diff --git a/libc-test/build.rs b/libc-test/build.rs index 330388f874553..66cced85f5a6c 100644 --- a/libc-test/build.rs +++ b/libc-test/build.rs @@ -1737,7 +1737,6 @@ fn test_dragonflybsd(target: &str) { "sem_t" => true, // mqd_t is a pointer on DragonFly "mqd_t" => true, - _ => false, } }); @@ -4653,16 +4652,23 @@ fn test_linux(target: &str) { }); let c_enums = [ - "tpacket_versions", - "proc_cn_mcast_op", - "proc_cn_event", + "membarrier_cmd", "pid_type", + "proc_cn_event", + "proc_cn_mcast_op", + "tpacket_versions", ]; cfg.alias_is_c_enum(move |e| c_enums.contains(&e)); // FIXME(libc): `pid_type` and `proc_cn_event` is hidden. cfg.skip_c_enum(|e| e == "pid_type" || e == "proc_cn_event"); + cfg.skip_signededness(move |c| match c { + // FIXME(1.0): uses the enum default signedness + "membarrier_cmd" => true, + _ => false, + }); + cfg.skip_fn(move |function| { let name = function.ident(); // skip those that are manually verified diff --git a/libc-test/semver/linux-gnu.txt b/libc-test/semver/linux-gnu.txt index 0db7c9688797e..a28ac82250fb6 100644 --- a/libc-test/semver/linux-gnu.txt +++ b/libc-test/semver/linux-gnu.txt @@ -117,7 +117,6 @@ LOGIN_PROCESS Lmid_t MADV_COLLAPSE MAXTC -MAX_LINKS MINIX2_SUPER_MAGIC MINIX2_SUPER_MAGIC2 MINIX3_SUPER_MAGIC @@ -637,9 +636,6 @@ malloc_usable_size mallopt mempcpy mq_notify -nl_mmap_hdr -nl_mmap_req -nl_pktinfo ntp_adjtime ntp_gettime ntptimeval diff --git a/libc-test/semver/linux.txt b/libc-test/semver/linux.txt index f3cca5611ee4d..25a3a593f44e8 100644 --- a/libc-test/semver/linux.txt +++ b/libc-test/semver/linux.txt @@ -1641,6 +1641,7 @@ MAP_TYPE MAXTTL MAX_ADDR_LEN MAX_IPOPTLEN +MAX_LINKS MCAST_BLOCK_SOURCE MCAST_EXCLUDE MCAST_INCLUDE @@ -4085,6 +4086,7 @@ madvise major makedev memalign +membarrier_cmd memmem memrchr mincore @@ -4128,6 +4130,9 @@ nice nl_item nl_langinfo nl_langinfo_l +nl_mmap_hdr +nl_mmap_req +nl_pktinfo nlattr nlmsgerr nlmsghdr diff --git a/libc-test/tests/cmsg.rs b/libc-test/tests/cmsg.rs index 80d4af53938e8..c358081698afc 100644 --- a/libc-test/tests/cmsg.rs +++ b/libc-test/tests/cmsg.rs @@ -17,8 +17,6 @@ mod t { extern "C" { pub fn cmsg_firsthdr(msgh: *const msghdr) -> *mut cmsghdr; - // see below - #[cfg(not(target_arch = "sparc64"))] pub fn cmsg_nxthdr(mhdr: *const msghdr, cmsg: *const cmsghdr) -> *mut cmsghdr; pub fn cmsg_space(length: c_uint) -> usize; pub fn cmsg_len(length: c_uint) -> usize; @@ -59,9 +57,6 @@ mod t { } } - // Skip on sparc64 - // https://github.com/rust-lang/libc/issues/1239 - #[cfg(not(target_arch = "sparc64"))] #[test] fn test_cmsg_nxthdr() { // Helps to align the buffer on the stack. @@ -70,32 +65,52 @@ mod t { const CAPACITY: usize = 512; let mut buffer = Align8([0_u8; CAPACITY]); + let pcmsghdr = buffer.0.as_mut_ptr().cast::(); + let mut mhdr: msghdr = unsafe { mem::zeroed() }; - for start_ofs in 0..64 { - let pcmsghdr = buffer.0.as_mut_ptr().cast::(); - mhdr.msg_control = pcmsghdr.cast::(); - mhdr.msg_controllen = (160 - start_ofs) as _; - for cmsg_len in 0..64 { - // Address must be a multiple of 0x4 for testing on AIX. - if cfg!(target_os = "aix") && cmsg_len % std::mem::size_of::() != 0 { + mhdr.msg_control = pcmsghdr.cast::(); + + for trunc in 0..64 { + mhdr.msg_controllen = (160 - trunc) as _; + + for cmsg_payload_len in 0..64 { + // AIX does not apply any alignment or padding to ancillary + // data and CMSG_ALIGN() is a noop. So only test addresses + // that are multiples of the size of cmsghdr here. + if cfg!(target_os = "aix") && cmsg_payload_len % std::mem::size_of::() != 0 + { continue; } - for next_cmsg_len in 0..32 { + + let mut current_cmsghdr_ptr = pcmsghdr; + assert!(!current_cmsghdr_ptr.is_null()); + let mut count = 0; + + // Go from first cmsghdr to the last (until null) using various + // cmsg_len increments. `cmsg_len` is set by us to check that + // the jump to the next cmsghdr is correct with respect to + // alignment and payload padding. + while !current_cmsghdr_ptr.is_null() { unsafe { - pcmsghdr.cast::().write_bytes(0, CAPACITY); - (*pcmsghdr).cmsg_len = cmsg_len as _; - let libc_next = libc::CMSG_NXTHDR(&mhdr, pcmsghdr); - let next = cmsg_nxthdr(&mhdr, pcmsghdr); - assert_eq!(libc_next, next); - - if !libc_next.is_null() { - (*libc_next).cmsg_len = next_cmsg_len; - let libc_next = libc::CMSG_NXTHDR(&mhdr, pcmsghdr); - let next = cmsg_nxthdr(&mhdr, pcmsghdr); - assert_eq!(libc_next, next); - } + (*current_cmsghdr_ptr).cmsg_len = + libc::CMSG_LEN(cmsg_payload_len as _) as _; + + let libc_next = libc::CMSG_NXTHDR(&mhdr, current_cmsghdr_ptr); + let system_next = cmsg_nxthdr(&mhdr, current_cmsghdr_ptr); + assert_eq!( + system_next, libc_next, + "msg_crontrollen: {}, payload_len: {}, count: {}", + mhdr.msg_controllen, cmsg_payload_len, count + ); + + current_cmsghdr_ptr = libc_next; + count += 1; } } + + unsafe { + pcmsghdr.cast::().write_bytes(0, CAPACITY); + } } } } diff --git a/src/new/linux_uapi/linux/membarrier.rs b/src/new/linux_uapi/linux/membarrier.rs new file mode 100644 index 0000000000000..4446202cb3bfb --- /dev/null +++ b/src/new/linux_uapi/linux/membarrier.rs @@ -0,0 +1,20 @@ +//! Header: `uapi/linux/membarrier.h` + +use crate::prelude::*; + +c_enum! { + // FIXME(1.0): incorrect repr signedness, this should be removed in a breaking change. + #[repr(c_int)] + pub enum membarrier_cmd { + pub MEMBARRIER_CMD_QUERY = 0, + pub MEMBARRIER_CMD_GLOBAL = 1 << 0, + pub MEMBARRIER_CMD_GLOBAL_EXPEDITED = 1 << 1, + pub MEMBARRIER_CMD_REGISTER_GLOBAL_EXPEDITED = 1 << 2, + pub MEMBARRIER_CMD_PRIVATE_EXPEDITED = 1 << 3, + pub MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED = 1 << 4, + pub MEMBARRIER_CMD_PRIVATE_EXPEDITED_SYNC_CORE = 1 << 5, + pub MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED_SYNC_CORE = 1 << 6, + pub MEMBARRIER_CMD_PRIVATE_EXPEDITED_RSEQ = 1 << 7, + pub MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED_RSEQ = 1 << 8, + } +} diff --git a/src/new/linux_uapi/linux/mod.rs b/src/new/linux_uapi/linux/mod.rs index 993394e4370ca..994a59c0c3864 100644 --- a/src/new/linux_uapi/linux/mod.rs +++ b/src/new/linux_uapi/linux/mod.rs @@ -4,3 +4,5 @@ pub(crate) mod can; pub(crate) mod keyctl; +pub(crate) mod membarrier; +pub(crate) mod netlink; diff --git a/src/new/linux_uapi/linux/netlink.rs b/src/new/linux_uapi/linux/netlink.rs new file mode 100644 index 0000000000000..03e18d739300a --- /dev/null +++ b/src/new/linux_uapi/linux/netlink.rs @@ -0,0 +1,136 @@ +//! Header: `uapi/linux/netlink.h` + +use crate::prelude::*; + +pub const NETLINK_ROUTE: c_int = 0; +pub const NETLINK_UNUSED: c_int = 1; +pub const NETLINK_USERSOCK: c_int = 2; +pub const NETLINK_FIREWALL: c_int = 3; +pub const NETLINK_SOCK_DIAG: c_int = 4; +pub const NETLINK_NFLOG: c_int = 5; +pub const NETLINK_XFRM: c_int = 6; +pub const NETLINK_SELINUX: c_int = 7; +pub const NETLINK_ISCSI: c_int = 8; +pub const NETLINK_AUDIT: c_int = 9; +pub const NETLINK_FIB_LOOKUP: c_int = 10; +pub const NETLINK_CONNECTOR: c_int = 11; +pub const NETLINK_NETFILTER: c_int = 12; +pub const NETLINK_IP6_FW: c_int = 13; +pub const NETLINK_DNRTMSG: c_int = 14; +pub const NETLINK_KOBJECT_UEVENT: c_int = 15; +pub const NETLINK_GENERIC: c_int = 16; +pub const NETLINK_SCSITRANSPORT: c_int = 18; +pub const NETLINK_ECRYPTFS: c_int = 19; +pub const NETLINK_RDMA: c_int = 20; +pub const NETLINK_CRYPTO: c_int = 21; + +pub const NETLINK_INET_DIAG: c_int = NETLINK_SOCK_DIAG; + +pub const MAX_LINKS: c_int = 32; + +s! { + pub struct sockaddr_nl { + pub nl_family: crate::sa_family_t, + nl_pad: Padding, + pub nl_pid: u32, + pub nl_groups: u32, + } + + pub struct nlmsghdr { + pub nlmsg_len: u32, + pub nlmsg_type: u16, + pub nlmsg_flags: u16, + pub nlmsg_seq: u32, + pub nlmsg_pid: u32, + } +} + +pub const NLM_F_REQUEST: c_int = 1; +pub const NLM_F_MULTI: c_int = 2; +pub const NLM_F_ACK: c_int = 4; +pub const NLM_F_ECHO: c_int = 8; +pub const NLM_F_DUMP_INTR: c_int = 16; +pub const NLM_F_DUMP_FILTERED: c_int = 32; + +pub const NLM_F_ROOT: c_int = 0x100; +pub const NLM_F_MATCH: c_int = 0x200; +pub const NLM_F_ATOMIC: c_int = 0x400; +pub const NLM_F_DUMP: c_int = NLM_F_ROOT | NLM_F_MATCH; + +pub const NLM_F_REPLACE: c_int = 0x100; +pub const NLM_F_EXCL: c_int = 0x200; +pub const NLM_F_CREATE: c_int = 0x400; +pub const NLM_F_APPEND: c_int = 0x800; + +pub const NLM_F_NONREC: c_int = 0x100; + +pub const NLM_F_CAPPED: c_int = 0x100; +pub const NLM_F_ACK_TLVS: c_int = 0x200; + +pub const NLMSG_NOOP: c_int = 0x1; +pub const NLMSG_ERROR: c_int = 0x2; +pub const NLMSG_DONE: c_int = 0x3; +pub const NLMSG_OVERRUN: c_int = 0x4; + +pub const NLMSG_MIN_TYPE: c_int = 0x10; + +s! { + pub struct nlmsgerr { + pub error: c_int, + pub msg: nlmsghdr, + } +} + +pub const NETLINK_ADD_MEMBERSHIP: c_int = 1; +pub const NETLINK_DROP_MEMBERSHIP: c_int = 2; +pub const NETLINK_PKTINFO: c_int = 3; +pub const NETLINK_BROADCAST_ERROR: c_int = 4; +pub const NETLINK_NO_ENOBUFS: c_int = 5; +pub const NETLINK_RX_RING: c_int = 6; +pub const NETLINK_TX_RING: c_int = 7; +pub const NETLINK_LISTEN_ALL_NSID: c_int = 8; +pub const NETLINK_LIST_MEMBERSHIPS: c_int = 9; +pub const NETLINK_CAP_ACK: c_int = 10; +pub const NETLINK_EXT_ACK: c_int = 11; +pub const NETLINK_GET_STRICT_CHK: c_int = 12; + +s! { + pub struct nl_pktinfo { + pub group: u32, + } + + pub struct nl_mmap_req { + pub nm_block_size: c_uint, + pub nm_block_nr: c_uint, + pub nm_frame_size: c_uint, + pub nm_frame_nr: c_uint, + } + + pub struct nl_mmap_hdr { + pub nm_status: c_uint, + pub nm_len: c_uint, + pub nm_group: u32, + pub nm_pid: u32, + pub nm_uid: u32, + pub nm_gid: u32, + } +} + +s! { + pub struct nlattr { + pub nla_len: u16, + pub nla_type: u16, + } +} + +pub const NLA_F_NESTED: c_int = 1 << 15; +pub const NLA_F_NET_BYTEORDER: c_int = 1 << 14; +pub const NLA_TYPE_MASK: c_int = !(NLA_F_NESTED | NLA_F_NET_BYTEORDER); + +pub const NLA_ALIGNTO: c_int = 4; + +f! { + pub fn NLA_ALIGN(len: c_int) -> c_int { + return ((len) + NLA_ALIGNTO - 1) & !(NLA_ALIGNTO - 1); + } +} diff --git a/src/new/mod.rs b/src/new/mod.rs index d4d2636601e18..9a1e56df20053 100644 --- a/src/new/mod.rs +++ b/src/new/mod.rs @@ -110,7 +110,7 @@ cfg_if! { // pub(crate) use redox::*; } else if #[cfg(target_os = "rtems")] { mod rtems; - pub(crate) use rtems::*; + // pub(crate) use rtems::*; } else if #[cfg(target_os = "solaris")] { mod solaris; pub(crate) use solaris::*; @@ -181,6 +181,8 @@ cfg_if! { pub use linux::can::raw::*; pub use linux::can::*; pub use linux::keyctl::*; + pub use linux::membarrier::*; + pub use linux::netlink::*; #[cfg(target_env = "gnu")] pub use net::route::*; } else if #[cfg(target_vendor = "apple")] { diff --git a/src/unix/bsd/netbsdlike/netbsd/riscv64.rs b/src/unix/bsd/netbsdlike/netbsd/riscv64.rs index 8cacb7250eddc..05c0cd55cb80d 100644 --- a/src/unix/bsd/netbsdlike/netbsd/riscv64.rs +++ b/src/unix/bsd/netbsdlike/netbsd/riscv64.rs @@ -2,17 +2,9 @@ use crate::prelude::*; use crate::PT_FIRSTMACH; pub type __greg_t = u64; -pub type __cpu_simple_lock_nv_t = c_int; -pub type __gregset = [__greg_t; _NGREG]; -pub type __fregset = [__fpreg; _NFREG]; - -s! { - pub struct mcontext_t { - pub __gregs: __gregset, - pub __fregs: __fregset, - __spare: [crate::__greg_t; 7], - } -} +pub type __cpu_simple_lock_nv_t = c_uint; +pub type __gregset_t = [__greg_t; _NGREG]; +pub type __fregset_t = [__fpreg; _NFREG]; s_no_extra_traits! { pub union __fpreg { @@ -21,23 +13,36 @@ s_no_extra_traits! { } } +s! { + pub struct mcontext_t { + pub __gregs: __gregset_t, + pub __fregs: __fregset_t, + __spare: [crate::__greg_t; 7], + } +} + cfg_if! { if #[cfg(feature = "extra_traits")] { impl PartialEq for __fpreg { - fn eq(&self, other: &Self) -> bool { - unsafe { self.u_u64 == other.u_u64 } + fn eq(&self, other: &__fpreg) -> bool { + unsafe { self.u_u64 == other.u_u64 || self.u_d == other.u_d } } } impl Eq for __fpreg {} impl hash::Hash for __fpreg { fn hash(&self, state: &mut H) { - unsafe { self.u_u64.hash(state) }; + unsafe { + self.u_u64.hash(state); + } } } } } -pub(crate) const _ALIGNBYTES: usize = size_of::() - 1; +// gcc for riscv64 defines `BIGGEST_ALIGNMENT`, but it's mesured in bits. +pub(crate) const __BIGGEST_ALIGNMENT_IN_BITS__: usize = 128; +// `_ALIGNBYTES` is measured in, well, bytes. +pub(crate) const _ALIGNBYTES: usize = (__BIGGEST_ALIGNMENT_IN_BITS__ / 8) - 1; pub const PT_GETREGS: c_int = PT_FIRSTMACH + 0; pub const PT_SETREGS: c_int = PT_FIRSTMACH + 1; diff --git a/src/unix/linux_like/emscripten/mod.rs b/src/unix/linux_like/emscripten/mod.rs index 35d7001ff5f59..711ed8f8b4c37 100644 --- a/src/unix/linux_like/emscripten/mod.rs +++ b/src/unix/linux_like/emscripten/mod.rs @@ -1257,7 +1257,7 @@ f! { } let next = (cmsg as usize + super::CMSG_ALIGN((*cmsg).cmsg_len as usize)) as *mut cmsghdr; let max = (*mhdr).msg_control as usize + (*mhdr).msg_controllen as usize; - if (next.offset(1)) as usize > max { + if (next.offset(1)) as usize >= max { core::ptr::null_mut::() } else { next as *mut cmsghdr diff --git a/src/unix/linux_like/l4re/mod.rs b/src/unix/linux_like/l4re/mod.rs index eb7cde2e3cde6..5ac4868f7d1c2 100644 --- a/src/unix/linux_like/l4re/mod.rs +++ b/src/unix/linux_like/l4re/mod.rs @@ -186,6 +186,16 @@ pub const TIOCGICOUNT: Ioctl = 0x545D; pub const BLKSSZGET: Ioctl = 0x1268; +cfg_if! { + if #[cfg(not(target_env = "uclibc"))] { + pub const NLMSG_NOOP: c_int = 0x1; + pub const NLMSG_ERROR: c_int = 0x2; + pub const NLMSG_DONE: c_int = 0x3; + pub const NLMSG_OVERRUN: c_int = 0x4; + pub const NLMSG_MIN_TYPE: c_int = 0x10; + } +} + cfg_if! { if #[cfg(target_env = "uclibc")] { mod uclibc; diff --git a/src/unix/linux_like/linux/gnu/mod.rs b/src/unix/linux_like/linux/gnu/mod.rs index 6e424b8b1d362..5fa2fdf591dda 100644 --- a/src/unix/linux_like/linux/gnu/mod.rs +++ b/src/unix/linux_like/linux/gnu/mod.rs @@ -133,26 +133,6 @@ s! { pub keepcost: size_t, } - pub struct nl_pktinfo { - pub group: u32, - } - - pub struct nl_mmap_req { - pub nm_block_size: c_uint, - pub nm_block_nr: c_uint, - pub nm_frame_size: c_uint, - pub nm_frame_nr: c_uint, - } - - pub struct nl_mmap_hdr { - pub nm_status: c_uint, - pub nm_len: c_uint, - pub nm_group: u32, - pub nm_pid: u32, - pub nm_uid: u32, - pub nm_gid: u32, - } - pub struct ntptimeval { pub time: crate::timeval, pub maxerror: c_long, @@ -810,8 +790,6 @@ pub const NDA_SRC_VNI: c_ushort = 11; pub const UNAME26: c_int = 0x0020000; pub const FDPIC_FUNCPTRS: c_int = 0x0080000; -pub const MAX_LINKS: c_int = 32; - pub const GENL_UNS_ADMIN_PERM: c_int = 0x10; pub const GENL_ID_VFS_DQUOT: c_int = crate::NLMSG_MIN_TYPE + 1; diff --git a/src/unix/linux_like/linux/mod.rs b/src/unix/linux_like/linux/mod.rs index 7b2c21df5516c..13d25bd9722d9 100644 --- a/src/unix/linux_like/linux/mod.rs +++ b/src/unix/linux_like/linux/mod.rs @@ -473,24 +473,6 @@ s! { pub newfd_flags: __u32, } - pub struct nlmsghdr { - pub nlmsg_len: u32, - pub nlmsg_type: u16, - pub nlmsg_flags: u16, - pub nlmsg_seq: u32, - pub nlmsg_pid: u32, - } - - pub struct nlmsgerr { - pub error: c_int, - pub msg: nlmsghdr, - } - - pub struct nlattr { - pub nla_len: u16, - pub nla_type: u16, - } - pub struct in6_ifreq { pub ifr6_addr: crate::in6_addr, pub ifr6_prefixlen: u32, @@ -1063,13 +1045,6 @@ s! { pub token_count: crate::__u32, } - pub struct sockaddr_nl { - pub nl_family: crate::sa_family_t, - nl_pad: Padding, - pub nl_pid: u32, - pub nl_groups: u32, - } - pub struct sockaddr_alg { pub salg_family: crate::sa_family_t, pub salg_type: [c_uchar; 14], @@ -1582,18 +1557,6 @@ pub const MPOL_F_NUMA_BALANCING: c_int = 1 << 13; pub const MPOL_F_RELATIVE_NODES: c_int = 1 << 14; pub const MPOL_F_STATIC_NODES: c_int = 1 << 15; -// linux/membarrier.h -pub const MEMBARRIER_CMD_QUERY: c_int = 0; -pub const MEMBARRIER_CMD_GLOBAL: c_int = 1 << 0; -pub const MEMBARRIER_CMD_GLOBAL_EXPEDITED: c_int = 1 << 1; -pub const MEMBARRIER_CMD_REGISTER_GLOBAL_EXPEDITED: c_int = 1 << 2; -pub const MEMBARRIER_CMD_PRIVATE_EXPEDITED: c_int = 1 << 3; -pub const MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED: c_int = 1 << 4; -pub const MEMBARRIER_CMD_PRIVATE_EXPEDITED_SYNC_CORE: c_int = 1 << 5; -pub const MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED_SYNC_CORE: c_int = 1 << 6; -pub const MEMBARRIER_CMD_PRIVATE_EXPEDITED_RSEQ: c_int = 1 << 7; -pub const MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED_RSEQ: c_int = 1 << 8; - pub const PTHREAD_MUTEX_INITIALIZER: crate::pthread_mutex_t = crate::pthread_mutex_t { size: [0; crate::__SIZEOF_PTHREAD_MUTEX_T], }; @@ -2653,70 +2616,8 @@ pub const NDA_VNI: c_ushort = 7; pub const NDA_IFINDEX: c_ushort = 8; // linux/netlink.h -pub const NLA_ALIGNTO: c_int = 4; - -pub const NETLINK_ROUTE: c_int = 0; -pub const NETLINK_UNUSED: c_int = 1; -pub const NETLINK_USERSOCK: c_int = 2; -pub const NETLINK_FIREWALL: c_int = 3; -pub const NETLINK_SOCK_DIAG: c_int = 4; -pub const NETLINK_NFLOG: c_int = 5; -pub const NETLINK_XFRM: c_int = 6; -pub const NETLINK_SELINUX: c_int = 7; -pub const NETLINK_ISCSI: c_int = 8; -pub const NETLINK_AUDIT: c_int = 9; -pub const NETLINK_FIB_LOOKUP: c_int = 10; -pub const NETLINK_CONNECTOR: c_int = 11; -pub const NETLINK_NETFILTER: c_int = 12; -pub const NETLINK_IP6_FW: c_int = 13; -pub const NETLINK_DNRTMSG: c_int = 14; -pub const NETLINK_KOBJECT_UEVENT: c_int = 15; -pub const NETLINK_GENERIC: c_int = 16; -pub const NETLINK_SCSITRANSPORT: c_int = 18; -pub const NETLINK_ECRYPTFS: c_int = 19; -pub const NETLINK_RDMA: c_int = 20; -pub const NETLINK_CRYPTO: c_int = 21; -pub const NETLINK_INET_DIAG: c_int = NETLINK_SOCK_DIAG; - -pub const NLM_F_REQUEST: c_int = 1; -pub const NLM_F_MULTI: c_int = 2; -pub const NLM_F_ACK: c_int = 4; -pub const NLM_F_ECHO: c_int = 8; -pub const NLM_F_DUMP_INTR: c_int = 16; -pub const NLM_F_DUMP_FILTERED: c_int = 32; - -pub const NLM_F_ROOT: c_int = 0x100; -pub const NLM_F_MATCH: c_int = 0x200; -pub const NLM_F_ATOMIC: c_int = 0x400; -pub const NLM_F_DUMP: c_int = NLM_F_ROOT | NLM_F_MATCH; - -pub const NLM_F_REPLACE: c_int = 0x100; -pub const NLM_F_EXCL: c_int = 0x200; -pub const NLM_F_CREATE: c_int = 0x400; -pub const NLM_F_APPEND: c_int = 0x800; - -pub const NLM_F_NONREC: c_int = 0x100; -pub const NLM_F_BULK: c_int = 0x200; -pub const NLM_F_CAPPED: c_int = 0x100; -pub const NLM_F_ACK_TLVS: c_int = 0x200; - -pub const NETLINK_ADD_MEMBERSHIP: c_int = 1; -pub const NETLINK_DROP_MEMBERSHIP: c_int = 2; -pub const NETLINK_PKTINFO: c_int = 3; -pub const NETLINK_BROADCAST_ERROR: c_int = 4; -pub const NETLINK_NO_ENOBUFS: c_int = 5; -pub const NETLINK_RX_RING: c_int = 6; -pub const NETLINK_TX_RING: c_int = 7; -pub const NETLINK_LISTEN_ALL_NSID: c_int = 8; -pub const NETLINK_LIST_MEMBERSHIPS: c_int = 9; -pub const NETLINK_CAP_ACK: c_int = 10; -pub const NETLINK_EXT_ACK: c_int = 11; -pub const NETLINK_GET_STRICT_CHK: c_int = 12; - -pub const NLA_F_NESTED: c_int = 1 << 15; -pub const NLA_F_NET_BYTEORDER: c_int = 1 << 14; -pub const NLA_TYPE_MASK: c_int = !(NLA_F_NESTED | NLA_F_NET_BYTEORDER); +pub const NLM_F_BULK: c_int = 0x200; // linux/rtnetlink.h pub const TCA_UNSPEC: c_ushort = 0; @@ -4056,10 +3957,6 @@ pub const SI_DETHREAD: c_int = -7; pub const TRAP_PERF: c_int = 6; f! { - pub fn NLA_ALIGN(len: c_int) -> c_int { - return ((len) + NLA_ALIGNTO - 1) & !(NLA_ALIGNTO - 1); - } - pub fn SCTP_PR_INDEX(policy: c_int) -> c_int { policy >> (4 - 1) } diff --git a/src/unix/linux_like/linux/musl/b32/arm/mod.rs b/src/unix/linux_like/linux/musl/b32/arm/mod.rs index 0f96453fde4f4..ae8e4939bbcb2 100644 --- a/src/unix/linux_like/linux/musl/b32/arm/mod.rs +++ b/src/unix/linux_like/linux/musl/b32/arm/mod.rs @@ -27,12 +27,18 @@ s! { #[cfg(musl32_time64)] __st_ctim32: Padding<__c_anonymous_timespec32>, - #[cfg(not(musl32_time64))] - pub st_atim: crate::timespec, - #[cfg(not(musl32_time64))] - pub st_mtim: crate::timespec, - #[cfg(not(musl32_time64))] - pub st_ctim: crate::timespec, + #[cfg(not(musl_v1_2_3))] + pub st_atime: crate::time_t, + #[cfg(not(musl_v1_2_3))] + pub st_atime_nsec: c_long, + #[cfg(not(musl_v1_2_3))] + pub st_mtime: crate::time_t, + #[cfg(not(musl_v1_2_3))] + pub st_mtime_nsec: c_long, + #[cfg(not(musl_v1_2_3))] + pub st_ctime: crate::time_t, + #[cfg(not(musl_v1_2_3))] + pub st_ctime_nsec: c_long, pub st_ino: crate::ino_t, diff --git a/src/unix/linux_like/linux/musl/b32/mips/mod.rs b/src/unix/linux_like/linux/musl/b32/mips/mod.rs index 0771a7f67c888..8c7ccbfc07450 100644 --- a/src/unix/linux_like/linux/musl/b32/mips/mod.rs +++ b/src/unix/linux_like/linux/musl/b32/mips/mod.rs @@ -25,12 +25,18 @@ s! { #[cfg(musl32_time64)] __st_ctim32: Padding<__c_anonymous_timespec32>, - #[cfg(not(musl32_time64))] - pub st_atim: crate::timespec, - #[cfg(not(musl32_time64))] - pub st_mtim: crate::timespec, - #[cfg(not(musl32_time64))] - pub st_ctim: crate::timespec, + #[cfg(not(musl_v1_2_3))] + pub st_atime: crate::time_t, + #[cfg(not(musl_v1_2_3))] + pub st_atime_nsec: c_long, + #[cfg(not(musl_v1_2_3))] + pub st_mtime: crate::time_t, + #[cfg(not(musl_v1_2_3))] + pub st_mtime_nsec: c_long, + #[cfg(not(musl_v1_2_3))] + pub st_ctime: crate::time_t, + #[cfg(not(musl_v1_2_3))] + pub st_ctime_nsec: c_long, pub st_blksize: crate::blksize_t, __st_padding3: Padding, diff --git a/src/unix/linux_like/linux/musl/b32/powerpc.rs b/src/unix/linux_like/linux/musl/b32/powerpc.rs index 64a2719abbc11..cd11a44e43cd4 100644 --- a/src/unix/linux_like/linux/musl/b32/powerpc.rs +++ b/src/unix/linux_like/linux/musl/b32/powerpc.rs @@ -37,12 +37,18 @@ s! { #[cfg(musl32_time64)] __st_ctim32: Padding<__c_anonymous_timespec32>, - #[cfg(not(musl32_time64))] - pub st_atim: crate::timespec, - #[cfg(not(musl32_time64))] - pub st_mtim: crate::timespec, - #[cfg(not(musl32_time64))] - pub st_ctim: crate::timespec, + #[cfg(not(musl_v1_2_3))] + pub st_atime: crate::time_t, + #[cfg(not(musl_v1_2_3))] + pub st_atime_nsec: c_long, + #[cfg(not(musl_v1_2_3))] + pub st_mtime: crate::time_t, + #[cfg(not(musl_v1_2_3))] + pub st_mtime_nsec: c_long, + #[cfg(not(musl_v1_2_3))] + pub st_ctime: crate::time_t, + #[cfg(not(musl_v1_2_3))] + pub st_ctime_nsec: c_long, __unused: Padding<[c_long; 2]>, diff --git a/src/unix/linux_like/linux/musl/b32/x86/mod.rs b/src/unix/linux_like/linux/musl/b32/x86/mod.rs index 3f2145bc266ef..737438a594efb 100644 --- a/src/unix/linux_like/linux/musl/b32/x86/mod.rs +++ b/src/unix/linux_like/linux/musl/b32/x86/mod.rs @@ -27,12 +27,18 @@ s! { #[cfg(musl32_time64)] __st_ctim32: Padding<__c_anonymous_timespec32>, - #[cfg(not(musl32_time64))] - pub st_atim: crate::timespec, - #[cfg(not(musl32_time64))] - pub st_mtim: crate::timespec, - #[cfg(not(musl32_time64))] - pub st_ctim: crate::timespec, + #[cfg(not(musl_v1_2_3))] + pub st_atime: crate::time_t, + #[cfg(not(musl_v1_2_3))] + pub st_atime_nsec: c_long, + #[cfg(not(musl_v1_2_3))] + pub st_mtime: crate::time_t, + #[cfg(not(musl_v1_2_3))] + pub st_mtime_nsec: c_long, + #[cfg(not(musl_v1_2_3))] + pub st_ctime: crate::time_t, + #[cfg(not(musl_v1_2_3))] + pub st_ctime_nsec: c_long, pub st_ino: crate::ino_t, diff --git a/src/unix/linux_like/linux_l4re_shared.rs b/src/unix/linux_like/linux_l4re_shared.rs index bd3cfafeb6e72..d91240a058583 100644 --- a/src/unix/linux_like/linux_l4re_shared.rs +++ b/src/unix/linux_like/linux_l4re_shared.rs @@ -953,7 +953,7 @@ pub const PTHREAD_PROCESS_PRIVATE: c_int = 0; pub const PTHREAD_PROCESS_SHARED: c_int = 1; pub const PTHREAD_INHERIT_SCHED: c_int = 0; pub const PTHREAD_EXPLICIT_SCHED: c_int = 1; -#[cfg(not(target_env = "uclibc"))] +#[cfg(not(all(target_os = "l4re", target_env = "uclibc")))] pub const __SIZEOF_PTHREAD_COND_T: usize = 48; // netinet/in.h @@ -1214,12 +1214,6 @@ cfg_if! { pub const MFD_HUGE_16GB: c_uint = 0x88000000; pub const MFD_HUGE_MASK: c_uint = 63; pub const MFD_HUGE_SHIFT: c_uint = 26; - - pub const NLMSG_NOOP: c_int = 0x1; - pub const NLMSG_ERROR: c_int = 0x2; - pub const NLMSG_DONE: c_int = 0x3; - pub const NLMSG_OVERRUN: c_int = 0x4; - pub const NLMSG_MIN_TYPE: c_int = 0x10; } } @@ -1493,15 +1487,32 @@ f! { if ((*cmsg).cmsg_len as usize) < size_of::() { return core::ptr::null_mut::(); } - let next = - (cmsg as usize + super::CMSG_ALIGN((*cmsg).cmsg_len as usize)) as *mut crate::cmsghdr; - let max = (*mhdr).msg_control as usize + (*mhdr).msg_controllen as usize; - if (next.wrapping_offset(1)) as usize > max - || next as usize + super::CMSG_ALIGN((*next).cmsg_len as usize) > max - { + + // FIXME(msrv): `.wrapping_byte_add()` stabilized in 1.75 + let next_cmsg = cmsg + .cast::() + .wrapping_add(super::CMSG_ALIGN((*cmsg).cmsg_len as usize)) + .cast::(); + + // In case the addition wrapped. `next_addr > max_addr` + // would otherwise not work as intended. + if (next_cmsg as usize) < (cmsg as usize) { + return core::ptr::null_mut(); + } + + let mut max_addr = (*mhdr).msg_control as usize + (*mhdr).msg_controllen as usize; + + if cfg!(any(target_env = "musl", target_env = "ohos")) { + // musl and some of its descendants do `>= max_addr` + // comparisons in the if statement below. + // https://www.openwall.com/lists/musl/2025/12/27/1 + max_addr -= 1; + } + + if next_cmsg as usize + size_of::() > max_addr { core::ptr::null_mut::() } else { - next + next_cmsg as *mut crate::cmsghdr } }