Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ci/verify-build.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
14 changes: 10 additions & 4 deletions libc-test/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1737,7 +1737,6 @@ fn test_dragonflybsd(target: &str) {
"sem_t" => true,
// mqd_t is a pointer on DragonFly
"mqd_t" => true,

_ => false,
}
});
Expand Down Expand Up @@ -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
Expand Down
4 changes: 0 additions & 4 deletions libc-test/semver/linux-gnu.txt
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ LOGIN_PROCESS
Lmid_t
MADV_COLLAPSE
MAXTC
MAX_LINKS
MINIX2_SUPER_MAGIC
MINIX2_SUPER_MAGIC2
MINIX3_SUPER_MAGIC
Expand Down Expand Up @@ -637,9 +636,6 @@ malloc_usable_size
mallopt
mempcpy
mq_notify
nl_mmap_hdr
nl_mmap_req
nl_pktinfo
ntp_adjtime
ntp_gettime
ntptimeval
Expand Down
5 changes: 5 additions & 0 deletions libc-test/semver/linux.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1641,6 +1641,7 @@ MAP_TYPE
MAXTTL
MAX_ADDR_LEN
MAX_IPOPTLEN
MAX_LINKS
MCAST_BLOCK_SOURCE
MCAST_EXCLUDE
MCAST_INCLUDE
Expand Down Expand Up @@ -4085,6 +4086,7 @@ madvise
major
makedev
memalign
membarrier_cmd
memmem
memrchr
mincore
Expand Down Expand Up @@ -4128,6 +4130,9 @@ nice
nl_item
nl_langinfo
nl_langinfo_l
nl_mmap_hdr
nl_mmap_req
nl_pktinfo
nlattr
nlmsgerr
nlmsghdr
Expand Down
65 changes: 40 additions & 25 deletions libc-test/tests/cmsg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand All @@ -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::<cmsghdr>();

let mut mhdr: msghdr = unsafe { mem::zeroed() };
for start_ofs in 0..64 {
let pcmsghdr = buffer.0.as_mut_ptr().cast::<cmsghdr>();
mhdr.msg_control = pcmsghdr.cast::<c_void>();
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::<cmsghdr>() != 0 {
mhdr.msg_control = pcmsghdr.cast::<c_void>();

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::<cmsghdr>() != 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::<u8>().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::<u8>().write_bytes(0, CAPACITY);
}
}
}
}
Expand Down
20 changes: 20 additions & 0 deletions src/new/linux_uapi/linux/membarrier.rs
Original file line number Diff line number Diff line change
@@ -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,
}
}
2 changes: 2 additions & 0 deletions src/new/linux_uapi/linux/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@

pub(crate) mod can;
pub(crate) mod keyctl;
pub(crate) mod membarrier;
pub(crate) mod netlink;
136 changes: 136 additions & 0 deletions src/new/linux_uapi/linux/netlink.rs
Original file line number Diff line number Diff line change
@@ -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<c_ushort>,
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);
}
}
4 changes: 3 additions & 1 deletion src/new/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand Down Expand Up @@ -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")] {
Expand Down
Loading