diff --git a/libc-test/tests/cmsg.rs b/libc-test/tests/cmsg.rs index b9573e1d040a..35a8bb01d5f3 100644 --- a/libc-test/tests/cmsg.rs +++ b/libc-test/tests/cmsg.rs @@ -3,11 +3,9 @@ #[cfg(unix)] mod t { - use std::mem; use libc::{ - self, c_uchar, c_uint, c_void, @@ -17,8 +15,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; @@ -52,15 +48,10 @@ mod t { #[test] fn test_cmsg_len() { for l in 0..128 { - unsafe { - assert_eq!(libc::CMSG_LEN(l) as usize, cmsg_len(l)); - } + assert_eq!(libc::CMSG_LEN(l) as usize, unsafe { cmsg_len(l) }); } } - // 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. @@ -69,42 +60,48 @@ 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 { - continue; - } - for next_cmsg_len in 0..32 { + mhdr.msg_control = pcmsghdr.cast::(); + + for trunc in 0..64 { + mhdr.msg_controllen = (160 - trunc) as _; + + for cmsg_payload_len in 0..64 { + let mut current_cmsghdr_ptr = pcmsghdr; + assert!(!current_cmsghdr_ptr.is_null()); + let mut count = 0; + + 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); + } } } } #[test] fn test_cmsg_space() { - unsafe { - for l in 0..128 { - assert_eq!(libc::CMSG_SPACE(l) as usize, cmsg_space(l)); - } + for l in 0..128 { + assert_eq!(libc::CMSG_SPACE(l) as usize, unsafe { cmsg_space(l) }); } } } diff --git a/src/fuchsia/mod.rs b/src/fuchsia/mod.rs index d02f3f87ae5c..a27c49bc497b 100644 --- a/src/fuchsia/mod.rs +++ b/src/fuchsia/mod.rs @@ -3000,6 +3000,8 @@ pub const O_NOFOLLOW: c_int = 0x00000080; pub const HUGETLB_FLAG_ENCODE_SHIFT: u32 = 26; pub const MAP_HUGE_SHIFT: u32 = 26; +// END_PUB_CONST + // intentionally not public, only used for fd_set cfg_if! { if #[cfg(target_pointer_width = "32")] { @@ -3011,8 +3013,6 @@ cfg_if! { } } -// END_PUB_CONST - f! { pub fn FD_CLR(fd: c_int, set: *mut fd_set) -> () { let fd = fd as usize; @@ -3069,40 +3069,6 @@ f! { pub fn CPU_EQUAL(set1: &cpu_set_t, set2: &cpu_set_t) -> bool { set1.bits == set2.bits } - - pub fn CMSG_DATA(cmsg: *const cmsghdr) -> *mut c_uchar { - cmsg.offset(1) as *mut c_uchar - } - - pub fn CMSG_NXTHDR(mhdr: *const msghdr, cmsg: *const cmsghdr) -> *mut cmsghdr { - if ((*cmsg).cmsg_len as size_t) < size_of::() { - core::ptr::null_mut::() - } else if __CMSG_NEXT(cmsg).add(size_of::()) >= __MHDR_END(mhdr) { - core::ptr::null_mut::() - } else { - __CMSG_NEXT(cmsg).cast() - } - } - - pub fn CMSG_FIRSTHDR(mhdr: *const msghdr) -> *mut cmsghdr { - if (*mhdr).msg_controllen as size_t >= size_of::() { - (*mhdr).msg_control.cast() - } else { - core::ptr::null_mut::() - } - } - - pub const fn CMSG_ALIGN(len: size_t) -> size_t { - (len + size_of::() - 1) & !(size_of::() - 1) - } - - pub const fn CMSG_SPACE(len: c_uint) -> c_uint { - (CMSG_ALIGN(len as size_t) + CMSG_ALIGN(size_of::())) as c_uint - } - - pub const fn CMSG_LEN(len: c_uint) -> c_uint { - (CMSG_ALIGN(size_of::()) + len as size_t) as c_uint - } } safe_f! { @@ -3168,19 +3134,6 @@ safe_f! { } } -fn __CMSG_LEN(cmsg: *const cmsghdr) -> ssize_t { - ((unsafe { (*cmsg).cmsg_len as size_t } + size_of::() - 1) & !(size_of::() - 1)) - as ssize_t -} - -fn __CMSG_NEXT(cmsg: *const cmsghdr) -> *mut c_uchar { - (unsafe { cmsg.offset(__CMSG_LEN(cmsg)) }) as *mut c_uchar -} - -fn __MHDR_END(mhdr: *const msghdr) -> *mut c_uchar { - unsafe { (*mhdr).msg_control.offset((*mhdr).msg_controllen as isize) }.cast() -} - // EXTERN_FN #[link(name = "c")] diff --git a/src/new/aix/mod.rs b/src/new/aix/mod.rs index c99b206b7168..fbfe1a7b28d7 100644 --- a/src/new/aix/mod.rs +++ b/src/new/aix/mod.rs @@ -3,4 +3,5 @@ //! * Headers are not public //! * Manual pages: (under "Technical reference" for that version) +pub(crate) mod sys; pub(crate) mod unistd; diff --git a/src/new/aix/sys/mod.rs b/src/new/aix/sys/mod.rs new file mode 100644 index 000000000000..a882cbd99fca --- /dev/null +++ b/src/new/aix/sys/mod.rs @@ -0,0 +1,3 @@ +//! Directory: `sys/` + +pub(crate) mod socket; diff --git a/src/new/aix/sys/socket.rs b/src/new/aix/sys/socket.rs new file mode 100644 index 000000000000..62fd36b8c637 --- /dev/null +++ b/src/new/aix/sys/socket.rs @@ -0,0 +1,9 @@ +//! Header: `sys/socket.h` + +pub use crate::new::common::posix::sys::socket::{ + CMSG_DATA, + CMSG_FIRSTHDR, + CMSG_LEN, + CMSG_NXTHDR, + CMSG_SPACE, +}; diff --git a/src/new/apple/libc/mod.rs b/src/new/apple/libc/mod.rs new file mode 100644 index 000000000000..e8f6a3bb6f5b --- /dev/null +++ b/src/new/apple/libc/mod.rs @@ -0,0 +1,7 @@ +//! Entrypoint for Apple headers, usually found as part of the Xcode SDK. +//! +//! + +pub(crate) mod signal; +pub(crate) mod sys; +pub(crate) mod unistd; diff --git a/src/new/apple/libc/sys/mod.rs b/src/new/apple/libc/sys/mod.rs new file mode 100644 index 000000000000..a882cbd99fca --- /dev/null +++ b/src/new/apple/libc/sys/mod.rs @@ -0,0 +1,3 @@ +//! Directory: `sys/` + +pub(crate) mod socket; diff --git a/src/new/apple/libc/sys/socket.rs b/src/new/apple/libc/sys/socket.rs new file mode 100644 index 000000000000..3e7552ecff1d --- /dev/null +++ b/src/new/apple/libc/sys/socket.rs @@ -0,0 +1,20 @@ +//! Header: `sys/socket.h` +//! +//! + +pub(crate) type __ALIGN_BOUNDARY = c_long; + +pub use crate::new::common::posix::sys::socket::{ + CMSG_DATA, + CMSG_FIRSTHDR, + CMSG_LEN, + CMSG_SPACE, +}; + +pub unsafe fn CMSG_NXTHDR(mhdr: *const msghdr, cmsg: *const crate::cmsghdr) -> *mut crate::cmsghdr { + if cmsg.is_null() { + return CMSG_FIRSTHDR(mhdr); + } + + crate::new::common::posix::sys::socket::CMSG_NXTHDR(mhdr, cmsg) +} diff --git a/src/new/apple/xnu/sys/mod.rs b/src/new/apple/xnu/sys/mod.rs index ad4a204898cb..e1ce9e6d60cd 100644 --- a/src/new/apple/xnu/sys/mod.rs +++ b/src/new/apple/xnu/sys/mod.rs @@ -3,6 +3,7 @@ //! pub(crate) mod signal; +pub(crate) mod socket; /// Directory: `sys/_types` /// diff --git a/src/new/apple/xnu/sys/socket.rs b/src/new/apple/xnu/sys/socket.rs new file mode 100644 index 000000000000..a34e6fa47950 --- /dev/null +++ b/src/new/apple/xnu/sys/socket.rs @@ -0,0 +1,11 @@ +//! Header: `sys/socket.h` +//! +//! + +pub use crate::new::common::bsd::sys::socket::CMSG_NXTHDR; +pub use crate::new::common::posix::sys::socket::{ + CMSG_DATA, + CMSG_FIRSTHDR, + CMSG_LEN, + CMSG_SPACE, +}; diff --git a/src/new/bionic_libc/sys/socket.rs b/src/new/bionic_libc/sys/socket.rs index c4a4e781275d..019ab296a481 100644 --- a/src/new/bionic_libc/sys/socket.rs +++ b/src/new/bionic_libc/sys/socket.rs @@ -1,4 +1,6 @@ //! Header: `sys/socket.h` +//! +//! use crate::prelude::*; @@ -26,6 +28,15 @@ s! { } } +pub use crate::new::common::posix::sys::socket::{ + CMSG_ALIGN, + CMSG_DATA, + CMSG_FIRSTHDR, + CMSG_LEN, + CMSG_NXTHDR, + CMSG_SPACE, +}; + extern "C" { pub fn recvmmsg( sockfd: c_int, diff --git a/src/new/common/bsd.rs b/src/new/common/bsd.rs index 818daf93489c..3f3aed916bfd 100644 --- a/src/new/common/bsd.rs +++ b/src/new/common/bsd.rs @@ -1 +1,17 @@ //! Interfaces common across the BSD family. + +pub(crate) mod sys { + pub(crate) mod socket { + #[cfg(not(target_os = "dragonfly"))] + pub unsafe fn CMSG_NXTHDR( + mhdr: *const crate::msghdr, + cmsg: *const crate::cmsghdr, + ) -> *mut crate::cmsghdr { + if cmsg.is_null() { + return crate::CMSG_FIRSTHDR(mhdr); + } + + crate::new::common::posix::sys::socket::CMSG_NXTHDR(mhdr, cmsg) + } + } +} diff --git a/src/new/common/posix/mod.rs b/src/new/common/posix/mod.rs index 44ae64a98022..32d04420d0aa 100644 --- a/src/new/common/posix/mod.rs +++ b/src/new/common/posix/mod.rs @@ -13,3 +13,5 @@ ))] pub(crate) mod pthread; pub(crate) mod unistd; + +pub(crate) mod sys; diff --git a/src/new/common/posix/sys/mod.rs b/src/new/common/posix/sys/mod.rs new file mode 100644 index 000000000000..a882cbd99fca --- /dev/null +++ b/src/new/common/posix/sys/mod.rs @@ -0,0 +1,3 @@ +//! Directory: `sys/` + +pub(crate) mod socket; diff --git a/src/new/common/posix/sys/socket.rs b/src/new/common/posix/sys/socket.rs new file mode 100644 index 000000000000..a6ad7ee67c20 --- /dev/null +++ b/src/new/common/posix/sys/socket.rs @@ -0,0 +1,285 @@ +//! Header: `sys/socket.h` +//! +//! + +// TEMP: until allow(unsafe_op_in_unsafe_fn) is removed in global level. +#![deny(unsafe_op_in_unsafe_fn)] + +use core::mem::size_of; + +use crate::prelude::*; +use crate::{ + cmsghdr, + msghdr, +}; + +/// Rounds `len` *up* to the next alignment boundary. +pub const fn CMSG_ALIGN(len: size_t) -> size_t { + align_impl(len, size_of::<__ALIGN_BOUNDARY>()) +} + +pub(crate) const fn align_impl(len: usize, align: usize) -> usize { + let mask = align - 1; + (len + mask) & !mask +} + +// TODO(#3240): consider changing signatures to `CMSG_{SPACE,LEN}(length: size_t) -> size_` + +/// Total length of a non-padded control message for a payload of size `length`. +/// +/// This function is almost exclusively used setting [`cmsghdr::cmsg_len`]. +/// It should *not* be used for determining the actual ancillary data buffer +/// size. [`CMSG_SPACE`] should instead be for that. +#[cfg(not(any(target_os = "illumos", target_os = "solaris")))] +pub const fn CMSG_LEN(length: c_uint) -> c_uint { + let length = length as size_t; + + // See `CMSG_SPACE` impl about this sometimes being a no-op. + let len = CMSG_ALIGN(size_of::()) + length; + + len as c_uint +} + +/// Total length of a padded control message for a payload of size `length`. +/// +/// This can be used to allocate space dynamically for the ancillary data. +/// It should should *not* be used to initialize [cmsghdr::cmsg_len], given +/// that the returned value includes padding bytes. Use instead [`CMSG_LEN`] +/// for that. +pub const fn CMSG_SPACE(length: c_uint) -> c_uint { + let length = length as size_t; + + // NB: left hand side `align` is no-op when `size_of::() % + // size_of::<__ALIGN_BOUNDARY>() == 0`. Such is the case on Linux, and + // probably why some implementations there don't bother with the lhs + // align. + let space = CMSG_ALIGN(size_of::()) + CMSG_ALIGN(length); + + space as c_uint +} + +/// Returns a pointer to the payload data array associated with for the provided header. +/// +/// # Safety +/// +/// Safety in calling this function are based on the safety conditions needed for calling `ptr.offset()`. +/// +/// * `cmsg` must point to some allocation and the resulting offset may not wrap around an address space. +// +// TODO: From https://man7.org/linux/man-pages/man3/cmsg.3.html, include it for the rest? +// +// The pointer returned cannot be assumed to be suitably aligned for +// accessing arbitrary payload data types. Applications should not cast it +// to a pointer type matching the payload, but should instead use `memcpy` +// to copy data to or from a suitably declared object. +#[cfg(not(any(target_os = "illumos", target_os = "solaris")))] +pub const unsafe fn CMSG_DATA(cmsg: *const cmsghdr) -> *mut c_uchar { + let ptr = cmsg as *mut crate::c_uchar; + // See `CMSG_SPACE` impl about this sometimes being a no-op. + let byte_offset = CMSG_ALIGN(size_of::()) as isize; + + // SAFETY: + // - Offset fits in isize (at most size_of::() = 16) + // - Caller must uphold the safety contract of non-wrapping offset + unsafe { ptr.offset(byte_offset) } +} + +/// Return a pointer to the first [`cmsghdr`] in [`msghdr`]. +/// +/// A null pointer is returned if [`msghdr::msg_controllen`] is less than +/// `size_of::()`. This can mean that there was no ancillary data +/// in the first place (msg_controllen is zero), or that the ancillary data +/// has been truncated. +pub const unsafe fn CMSG_FIRSTHDR(mhdr: *const msghdr) -> *mut cmsghdr { + // TODO: take mhdr by ref and make CMSG_FIRSTHDR safe? + let msghdr = unsafe { *mhdr }; + + // Linux's syscall interface uses `size_t` for `msg_controllen` even if + // POSIX dictates it being `socklen_t` (>=u32). The cast accommodates + // for both, even if redundant for Linux. + #[allow(clippy::unnecessary_cast)] + let msg_controllen = msghdr.msg_controllen as size_t; + + if msg_controllen < size_of::() { + core::ptr::null_mut() + } else { + msghdr.msg_control.cast() + } +} + +/// # SAFETY +/// +/// Safety in calling this function are based on the safety conditions needed for dereferencing `cmsg`: +/// +/// * Caller must enure `cmsg` is not null. +/// +/// * `cmsg` is returned from a previous call to `CMSG_NXTHDR`, or +/// originally retrieved from a call to `CMSG_FIRSTHDR`. +#[cfg(not(any( + target_env = "musl", + target_env = "ohos", + target_os = "emscripten", + target_os = "fuchsia" +)))] +pub unsafe fn CMSG_NXTHDR(mhdr: *const msghdr, cmsg: *const cmsghdr) -> *mut cmsghdr { + unsafe { next_impl(mhdr, cmsg, true) } +} + +pub(crate) unsafe fn next_impl( + mhdr: *const msghdr, + cmsg: *const cmsghdr, + allow_zero_sized_payload: bool, +) -> *mut cmsghdr { + // TODO: why not take mhdr by ref? + let msghdr = unsafe { *mhdr }; + + // SAFETY: + // - Caller ensured pointer is not null. + // - Pointer retrieved from either CMSG_FIRSTHDR or CMSG_NXTDR, + // thus ensuring that is lies between mhdr_addr and mhdr_addr + + // msg_controllen. + let cmsghdr = unsafe { *cmsg }; + + if (cmsghdr.cmsg_len as usize) < size_of::() { + return core::ptr::null_mut(); + } + + let next_addr = cmsg as usize + CMSG_ALIGN(cmsghdr.cmsg_len as usize); + let mut max_addr = msghdr.msg_control as usize + msghdr.msg_controllen as usize; + + if !allow_zero_sized_payload { + max_addr -= 1; + } + + if next_addr + CMSG_ALIGN(size_of::()) > max_addr { + core::ptr::null_mut() + } else { + next_addr as _ + } +} + +// HACK: AIX does not use any alignment/padding for ancillary data. Setting +// this to 1 it makes possible to reuse the CMSG_* implementatinos as the extra +// CMSG_ALIGN calls become no-op. +#[cfg(target_os = "aix")] +pub(crate) type __ALIGN_BOUNDARY = u8; + +#[cfg(target_os = "android")] +pub(crate) type __ALIGN_BOUNDARY = usize; + +#[cfg(target_vendor = "apple")] +pub(crate) type __ALIGN_BOUNDARY = u32; + +#[cfg(target_os = "hurd")] +pub(crate) type __ALIGN_BOUNDARY = usize; + +#[cfg(target_os = "cygwin")] +pub(crate) type __ALIGN_BOUNDARY = usize; + +#[cfg(target_os = "dragonfly")] +pub(crate) type __ALIGN_BOUNDARY = c_long; + +#[cfg(target_os = "emscripten")] +pub(crate) type __ALIGN_BOUNDARY = usize; + +#[cfg(target_os = "fuchsia")] +pub(crate) type __ALIGN_BOUNDARY = c_long; + +#[cfg(target_os = "haiku")] +pub(crate) type __ALIGN_BOUNDARY = usize; + +#[cfg(target_os = "l4re")] +pub(crate) type __ALIGN_BOUNDARY = usize; + +#[cfg(target_os = "linux")] +pub(crate) type __ALIGN_BOUNDARY = usize; + +#[cfg(target_os = "nto")] +pub(crate) type __ALIGN_BOUNDARY = usize; + +#[cfg(target_os = "redox")] +pub(crate) type __ALIGN_BOUNDARY = size_t; + +#[cfg(target_os = "vxworks")] +pub(crate) type __ALIGN_BOUNDARY = usize; + +cfg_if! { + if #[cfg(any(target_os = "illumos", target_os = "solaris"))] { + #[cfg(target_arch = "sparc64")] + pub(crate) type __ALIGN_BOUNDARY = u64; + #[cfg(not(target_arch = "sparc64"))] + pub(crate) type __ALIGN_BOUNDARY = u32; + } +} + +cfg_if! { + if #[cfg(target_os = "netbsd")] { + cfg_if! { + if #[cfg(target_arch = "x86")] { + pub(crate) type __ALIGN_BOUNDARY = c_int; + } else if #[cfg(target_arch = "x86_64")] { + pub(crate) type __ALIGN_BOUNDARY = c_long; + } else if #[cfg(target_arch = "aarch64")] { + pub(crate) type __ALIGN_BOUNDARY = c_int; + } else if #[cfg(target_arch = "arm")] { + pub(crate) type __ALIGN_BOUNDARY = c_longlong; + } else if #[cfg(target_arch = "mips")] { + pub(crate) type __ALIGN_BOUNDARY = c_longlong; + } else if #[cfg(target_arch = "powerpc")] { + pub(crate) type __ALIGN_BOUNDARY = c_double; + } else if #[cfg(target_arch = "riscv64")] { + pub(crate) type __ALIGN_BOUNDARY = c_long; + } else if #[cfg(target_arch = "sparc64")] { + pub(crate) type __ALIGN_BOUNDARY = u128; + } + } + } +} + +cfg_if! { + if #[cfg(target_os = "freebsd")] { + cfg_if! { + if #[cfg(target_arch = "x86")] { + pub(crate) type __ALIGN_BOUNDARY = c_long; + } else if #[cfg(target_arch = "x86_64")] { + pub(crate) type __ALIGN_BOUNDARY = c_long; + } else if #[cfg(target_arch = "aarch64")] { + pub(crate) type __ALIGN_BOUNDARY = c_longlong; + } else if #[cfg(target_arch = "arm")] { + pub(crate) type __ALIGN_BOUNDARY = c_int; + } else if #[cfg(target_arch = "powerpc")] { + pub(crate) type __ALIGN_BOUNDARY = c_int; + } else if #[cfg(target_arch = "powerpc64")] { + pub(crate) type __ALIGN_BOUNDARY = c_long; + } else if #[cfg(target_arch = "riscv64")] { + pub(crate) type __ALIGN_BOUNDARY = c_longlong; + } + } + } +} + +cfg_if! { + if #[cfg(target_os = "openbsd")] { + cfg_if! { + if #[cfg(target_arch = "x86")] { + pub(crate) type __ALIGN_BOUNDARY = c_int; + } else if #[cfg(target_arch = "x86_64")] { + pub(crate) type __ALIGN_BOUNDARY = c_long; + } else if #[cfg(target_arch = "aarch64")] { + pub(crate) type __ALIGN_BOUNDARY = c_long; + } else if #[cfg(target_arch = "arm")] { + pub(crate) type __ALIGN_BOUNDARY = c_double; + } else if #[cfg(target_arch = "mips64")] { + pub(crate) type __ALIGN_BOUNDARY = u64; + } else if #[cfg(target_arch = "powerpc")] { + pub(crate) type __ALIGN_BOUNDARY = c_double; + } else if #[cfg(target_arch = "powerpc64")] { + pub(crate) type __ALIGN_BOUNDARY = c_long; + } else if #[cfg(target_arch = "riscv64")] { + pub(crate) type __ALIGN_BOUNDARY = c_long; + } else if #[cfg(target_arch = "sparc64")] { + pub(crate) type __ALIGN_BOUNDARY = u128; + } + } + } +} diff --git a/src/new/common/solarish.rs b/src/new/common/solarish.rs index f966114e370a..d074f8a9c1d7 100644 --- a/src/new/common/solarish.rs +++ b/src/new/common/solarish.rs @@ -1 +1,31 @@ //! Interfaces common in solaris-derived operating systems. This includes Solaris and Illumos. + +pub(crate) mod sys { + pub(crate) mod socket { + use crate::prelude::*; + use crate::{ + cmsghdr, + msghdr, + }; + + const fn _CMSG_DATA_ALIGN(p: usize) -> usize { + crate::new::common::posix::sys::socket::align_impl(p, size_of::()) + } + + pub const fn CMSG_LEN(length: c_uint) -> c_uint { + _CMSG_DATA_ALIGN(size_of::()) as c_uint + length + } + + pub unsafe fn CMSG_DATA(cmsg: *const cmsghdr) -> *mut c_uchar { + _CMSG_DATA_ALIGN(cmsg.offset(1) as usize) as *mut c_uchar + } + + pub unsafe fn CMSG_NXTHDR(mhdr: *const msghdr, cmsg: *const cmsghdr) -> *mut cmsghdr { + if cmsg.is_null() { + return crate::CMSG_FIRSTHDR(mhdr); + } + + crate::new::common::posix::sys::socket::CMSG_NXTHDR(mhdr, cmsg) + } + } +} diff --git a/src/new/cygwin/mod.rs b/src/new/cygwin/mod.rs index 356ae587653d..1428cdebd4d9 100644 --- a/src/new/cygwin/mod.rs +++ b/src/new/cygwin/mod.rs @@ -2,4 +2,5 @@ //! //! * Headers: +pub(crate) mod sys; pub(crate) mod unistd; diff --git a/src/new/cygwin/sys/mod.rs b/src/new/cygwin/sys/mod.rs new file mode 100644 index 000000000000..a882cbd99fca --- /dev/null +++ b/src/new/cygwin/sys/mod.rs @@ -0,0 +1,3 @@ +//! Directory: `sys/` + +pub(crate) mod socket; diff --git a/src/new/cygwin/sys/socket.rs b/src/new/cygwin/sys/socket.rs new file mode 100644 index 000000000000..7c8857505bc7 --- /dev/null +++ b/src/new/cygwin/sys/socket.rs @@ -0,0 +1,12 @@ +//! Header: `sys/socket.h` +//! +//! + +pub use crate::new::common::posix::sys::socket::{ + CMSG_ALIGN, + CMSG_DATA, + CMSG_FIRSTHDR, + CMSG_LEN, + CMSG_NXTHDR, + CMSG_SPACE, +}; diff --git a/src/new/dragonfly/mod.rs b/src/new/dragonfly/mod.rs index 4a1b2c4998d0..e4f1723d3703 100644 --- a/src/new/dragonfly/mod.rs +++ b/src/new/dragonfly/mod.rs @@ -3,4 +3,5 @@ //! * Headers: //! * Manual pages: +pub(crate) mod sys; pub(crate) mod unistd; diff --git a/src/new/dragonfly/sys/mod.rs b/src/new/dragonfly/sys/mod.rs new file mode 100644 index 000000000000..a882cbd99fca --- /dev/null +++ b/src/new/dragonfly/sys/mod.rs @@ -0,0 +1,3 @@ +//! Directory: `sys/` + +pub(crate) mod socket; diff --git a/src/new/dragonfly/sys/socket.rs b/src/new/dragonfly/sys/socket.rs new file mode 100644 index 000000000000..56722da5901b --- /dev/null +++ b/src/new/dragonfly/sys/socket.rs @@ -0,0 +1,11 @@ +//! Header: `sys/socket.h` +//! +//! + +pub use crate::new::common::posix::sys::socket::{ + CMSG_DATA, + CMSG_FIRSTHDR, + CMSG_LEN, + CMSG_NXTHDR, + CMSG_SPACE, +}; diff --git a/src/new/emscripten/mod.rs b/src/new/emscripten/mod.rs index 9b74464059bb..f9572bad8347 100644 --- a/src/new/emscripten/mod.rs +++ b/src/new/emscripten/mod.rs @@ -4,4 +4,5 @@ pub(crate) mod pthread; pub(crate) mod sched; +pub(crate) mod sys; pub(crate) mod unistd; diff --git a/src/new/emscripten/sys/mod.rs b/src/new/emscripten/sys/mod.rs new file mode 100644 index 000000000000..a882cbd99fca --- /dev/null +++ b/src/new/emscripten/sys/mod.rs @@ -0,0 +1,3 @@ +//! Directory: `sys/` + +pub(crate) mod socket; diff --git a/src/new/emscripten/sys/socket.rs b/src/new/emscripten/sys/socket.rs new file mode 100644 index 000000000000..bb503adf0168 --- /dev/null +++ b/src/new/emscripten/sys/socket.rs @@ -0,0 +1,18 @@ +//! Header: `sys/socket.h` +//! +//! + +pub use crate::new::common::posix::sys::socket::{ + CMSG_ALIGN, + CMSG_DATA, + CMSG_FIRSTHDR, + CMSG_LEN, + CMSG_SPACE, +}; + +pub unsafe fn CMSG_NXTHDR( + mhdr: *const crate::msghdr, + cmsg: *const crate::cmsghdr, +) -> *mut crate::cmsghdr { + crate::new::common::posix::sys::socket::next_impl(mhdr, cmsg, false) +} diff --git a/src/new/freebsd/mod.rs b/src/new/freebsd/mod.rs index 87c2e487560b..eedf235d1e23 100644 --- a/src/new/freebsd/mod.rs +++ b/src/new/freebsd/mod.rs @@ -3,4 +3,5 @@ //! * Headers: //! * Symbol map: +pub(crate) mod sys; pub(crate) mod unistd; diff --git a/src/new/freebsd/sys/mod.rs b/src/new/freebsd/sys/mod.rs new file mode 100644 index 000000000000..a882cbd99fca --- /dev/null +++ b/src/new/freebsd/sys/mod.rs @@ -0,0 +1,3 @@ +//! Directory: `sys/` + +pub(crate) mod socket; diff --git a/src/new/freebsd/sys/socket.rs b/src/new/freebsd/sys/socket.rs new file mode 100644 index 000000000000..de45efa9cdf8 --- /dev/null +++ b/src/new/freebsd/sys/socket.rs @@ -0,0 +1,11 @@ +//! Header: `sys/socket.h` +//! +//! + +pub use crate::new::common::bsd::sys::socket::CMSG_NXTHDR; +pub use crate::new::common::posix::sys::socket::{ + CMSG_DATA, + CMSG_FIRSTHDR, + CMSG_LEN, + CMSG_SPACE, +}; diff --git a/src/new/fuchsia/mod.rs b/src/new/fuchsia/mod.rs index b3a908349bf3..e7326181477a 100644 --- a/src/new/fuchsia/mod.rs +++ b/src/new/fuchsia/mod.rs @@ -1,4 +1,6 @@ -//! Fuschia libc. -// FIXME(fuchsia): link to headers needed. +//! Fuchsia libc. +//! +//! Header files: +pub(crate) mod sys; pub(crate) mod unistd; diff --git a/src/new/fuchsia/sys/mod.rs b/src/new/fuchsia/sys/mod.rs new file mode 100644 index 000000000000..a882cbd99fca --- /dev/null +++ b/src/new/fuchsia/sys/mod.rs @@ -0,0 +1,3 @@ +//! Directory: `sys/` + +pub(crate) mod socket; diff --git a/src/new/fuchsia/sys/socket.rs b/src/new/fuchsia/sys/socket.rs new file mode 100644 index 000000000000..e8977ab850d1 --- /dev/null +++ b/src/new/fuchsia/sys/socket.rs @@ -0,0 +1,18 @@ +//! Header: `sys/socket.h` +//! +//! + +pub use crate::new::common::posix::sys::socket::{ + CMSG_ALIGN, + CMSG_DATA, + CMSG_FIRSTHDR, + CMSG_LEN, + CMSG_SPACE, +}; + +pub unsafe fn CMSG_NXTHDR( + mhdr: *const crate::msghdr, + cmsg: *const crate::cmsghdr, +) -> *mut crate::cmsghdr { + crate::new::common::posix::sys::socket::next_impl(mhdr, cmsg, false) +} diff --git a/src/new/glibc/sysdeps/unix/linux/mod.rs b/src/new/glibc/sysdeps/unix/linux/mod.rs index 0ecee596c5b1..1188b332324b 100644 --- a/src/new/glibc/sysdeps/unix/linux/mod.rs +++ b/src/new/glibc/sysdeps/unix/linux/mod.rs @@ -8,3 +8,21 @@ pub(crate) mod net { pub(crate) mod route; } + +/// Directory: `sys/` +pub(crate) mod sys { + pub(crate) mod socket { + //! Header: `sys/socket.h` + //! + //! + + pub use crate::new::common::posix::sys::socket::{ + CMSG_ALIGN, + CMSG_DATA, + CMSG_FIRSTHDR, + CMSG_LEN, + CMSG_NXTHDR, + CMSG_SPACE, + }; + } +} diff --git a/src/new/haiku/mod.rs b/src/new/haiku/mod.rs index a565afe10d9c..c31a36b5bc26 100644 --- a/src/new/haiku/mod.rs +++ b/src/new/haiku/mod.rs @@ -1,4 +1,6 @@ //! Haiku OS libc. -// FIXME(haiku): link to headers needed. +//! +//! +pub(crate) mod sys; pub(crate) mod unistd; diff --git a/src/new/haiku/sys/mod.rs b/src/new/haiku/sys/mod.rs new file mode 100644 index 000000000000..a882cbd99fca --- /dev/null +++ b/src/new/haiku/sys/mod.rs @@ -0,0 +1,3 @@ +//! Directory: `sys/` + +pub(crate) mod socket; diff --git a/src/new/haiku/sys/socket.rs b/src/new/haiku/sys/socket.rs new file mode 100644 index 000000000000..4eb7125f5967 --- /dev/null +++ b/src/new/haiku/sys/socket.rs @@ -0,0 +1,21 @@ +//! Header: `sys/socket.h` +//! +//! + +pub use crate::new::common::posix::sys::socket::{ + CMSG_DATA, + CMSG_FIRSTHDR, + CMSG_LEN, + CMSG_SPACE, +}; + +pub unsafe fn CMSG_NXTHDR( + mhdr: *const crate::msghdr, + cmsg: *const crate::cmsghdr, +) -> *mut crate::cmsghdr { + if cmsg.is_null() { + return CMSG_FIRSTHDR(mhdr); + } + + crate::new::common::posix::sys::socket::CMSG_NXTHDR(mhdr, cmsg) +} diff --git a/src/new/hurd/mod.rs b/src/new/hurd/mod.rs index 12198d58bd58..03d016d85f90 100644 --- a/src/new/hurd/mod.rs +++ b/src/new/hurd/mod.rs @@ -1,2 +1,5 @@ //! GNU Hurd libc. -// FIXME(hurd): link to headers needed. +//! +//! Header files: + +pub(crate) mod sys; diff --git a/src/new/hurd/sys/mod.rs b/src/new/hurd/sys/mod.rs new file mode 100644 index 000000000000..a882cbd99fca --- /dev/null +++ b/src/new/hurd/sys/mod.rs @@ -0,0 +1,3 @@ +//! Directory: `sys/` + +pub(crate) mod socket; diff --git a/src/new/hurd/sys/socket.rs b/src/new/hurd/sys/socket.rs new file mode 100644 index 000000000000..81144a0b823e --- /dev/null +++ b/src/new/hurd/sys/socket.rs @@ -0,0 +1,12 @@ +//! Header: `sys/socket.h` +//! +//! + +pub use crate::new::common::posix::sys::socket::{ + CMSG_ALIGN, + CMSG_DATA, + CMSG_FIRSTHDR, + CMSG_LEN, + CMSG_NXTHDR, + CMSG_SPACE, +}; diff --git a/src/new/illumos/mod.rs b/src/new/illumos/mod.rs index 83d15da8801f..99fa0cc1f0b1 100644 --- a/src/new/illumos/mod.rs +++ b/src/new/illumos/mod.rs @@ -1,4 +1,6 @@ //! Illumos libc. -// FIXME(illumos): link to headers needed. +//! +//! Header files: +pub(crate) mod sys; pub(crate) mod unistd; diff --git a/src/new/illumos/sys/mod.rs b/src/new/illumos/sys/mod.rs new file mode 100644 index 000000000000..a882cbd99fca --- /dev/null +++ b/src/new/illumos/sys/mod.rs @@ -0,0 +1,3 @@ +//! Directory: `sys/` + +pub(crate) mod socket; diff --git a/src/new/illumos/sys/socket.rs b/src/new/illumos/sys/socket.rs new file mode 100644 index 000000000000..972e8e34dcc0 --- /dev/null +++ b/src/new/illumos/sys/socket.rs @@ -0,0 +1,13 @@ +//! Header: `sys/socket.h` +//! +//! + +pub use crate::new::common::posix::sys::socket::{ + CMSG_FIRSTHDR, + CMSG_SPACE, +}; +pub use crate::new::common::solarish::sys::socket::{ + CMSG_DATA, + CMSG_LEN, + CMSG_NXTHDR, +}; diff --git a/src/new/l4re/mod.rs b/src/new/l4re/mod.rs index cbf725f406b6..d511e1039791 100644 --- a/src/new/l4re/mod.rs +++ b/src/new/l4re/mod.rs @@ -1,3 +1,5 @@ //! L4re. //! //! * Headers: + +pub(crate) mod sys; diff --git a/src/new/l4re/sys/mod.rs b/src/new/l4re/sys/mod.rs new file mode 100644 index 000000000000..a882cbd99fca --- /dev/null +++ b/src/new/l4re/sys/mod.rs @@ -0,0 +1,3 @@ +//! Directory: `sys/` + +pub(crate) mod socket; diff --git a/src/new/l4re/sys/socket.rs b/src/new/l4re/sys/socket.rs new file mode 100644 index 000000000000..14dc8bbf3899 --- /dev/null +++ b/src/new/l4re/sys/socket.rs @@ -0,0 +1,12 @@ +//! Header: `sys/socket.h` +//! +//! + +pub use crate::new::common::posix::sys::socket::{ + CMSG_ALIGN, + CMSG_DATA, + CMSG_FIRSTHDR, + CMSG_LEN, + CMSG_NXTHDR, + CMSG_SPACE, +}; diff --git a/src/new/mod.rs b/src/new/mod.rs index d4d2636601e1..da03ae21b363 100644 --- a/src/new/mod.rs +++ b/src/new/mod.rs @@ -80,13 +80,13 @@ cfg_if! { // pub(crate) use horizon::*; } else if #[cfg(target_os = "hurd")] { mod hurd; - // pub(crate) use hurd::*; + pub(crate) use hurd::*; } else if #[cfg(target_os = "illumos")] { mod illumos; pub(crate) use illumos::*; } else if #[cfg(target_os = "l4re")] { mod l4re; - // pub(crate) use l4re::*; + pub(crate) use l4re::*; } else if #[cfg(target_os = "linux")] { mod linux_uapi; pub(crate) use linux_uapi::*; @@ -107,7 +107,7 @@ cfg_if! { pub(crate) use qurt::*; } else if #[cfg(target_os = "redox")] { mod redox; - // pub(crate) use redox::*; + pub(crate) use redox::*; } else if #[cfg(target_os = "rtems")] { mod rtems; pub(crate) use rtems::*; @@ -173,16 +173,10 @@ cfg_if! { // Per-OS headers we export cfg_if! { - if #[cfg(target_os = "android")] { + if #[cfg(target_os = "aix")] { + pub use sys::socket::*; + } else if #[cfg(target_os = "android")] { pub use sys::socket::*; - } else if #[cfg(target_os = "linux")] { - pub use linux::can::bcm::*; - pub use linux::can::j1939::*; - pub use linux::can::raw::*; - pub use linux::can::*; - pub use linux::keyctl::*; - #[cfg(target_env = "gnu")] - pub use net::route::*; } else if #[cfg(target_vendor = "apple")] { pub use pthread::*; pub use pthread_::introspection::*; @@ -190,23 +184,63 @@ cfg_if! { pub use pthread_::spawn::*; pub use pthread_::stack_np::*; pub use signal::*; + pub use sys::socket::*; + } else if #[cfg(target_os = "cygwin")] { + pub use sys::socket::*; + } else if #[cfg(target_os = "dragonfly")] { + pub use sys::socket::*; + } else if #[cfg(target_os = "emscripten")] { + pub use sys::socket::*; + } else if #[cfg(target_os = "freebsd")] { + pub use sys::socket::*; + } else if #[cfg(target_os = "fuchsia")] { + pub use sys::socket::*; + } else if #[cfg(target_os = "haiku")] { + pub use sys::socket::*; + } else if #[cfg(target_os = "hurd")] { + pub use sys::socket::*; + } else if #[cfg(target_os = "illumos")] { + pub use sys::socket::*; + } else if #[cfg(target_os = "l4re")] { + pub use sys::socket::*; + } else if #[cfg(target_os = "linux")] { + pub use linux::can::bcm::*; + pub use linux::can::j1939::*; + pub use linux::can::raw::*; + pub use linux::can::*; + pub use linux::keyctl::*; + + // per-linux-env headers + cfg_if! { + if #[cfg(any(target_env = "musl", target_env = "ohos"))] { + // ./musl + pub use sys::socket::*; + } else if #[cfg(target_env = "gnu")] { + // ./glibc/sysdeps/unix/linux + pub use net::route::*; + pub use sys::socket::*; + } + } } else if #[cfg(target_os = "netbsd")] { pub use net::if_::*; pub use sys::ipc::*; + pub use sys::socket::*; pub use sys::statvfs::*; pub use sys::time::*; pub use sys::timex::*; pub use sys::types::*; pub use utmp_::*; pub use utmpx_::*; + } else if #[cfg(target_os = "nto")] { + pub use sys::socket::*; } else if #[cfg(target_os = "openbsd")] { pub use sys::ipc::*; - } -} - -// Per-env headers we export -cfg_if! { - if #[cfg(any(target_env = "musl", target_env = "ohos"))] { + pub use sys::socket::*; + } else if #[cfg(target_os = "redox")] { + pub use sys::socket::*; + } else if #[cfg(target_os = "solaris")] { + pub use sys::socket::*; + } else if #[cfg(target_os = "vxworks")] { pub use sys::socket::*; } } diff --git a/src/new/musl/sys/socket.rs b/src/new/musl/sys/socket.rs index e723043dc0a3..969207e4406f 100644 --- a/src/new/musl/sys/socket.rs +++ b/src/new/musl/sys/socket.rs @@ -34,6 +34,18 @@ s! { } } +pub use crate::new::common::posix::sys::socket::{ + CMSG_ALIGN, + CMSG_DATA, + CMSG_FIRSTHDR, + CMSG_LEN, + CMSG_SPACE, +}; + +pub unsafe fn CMSG_NXTHDR(mhdr: *const msghdr, cmsg: *const cmsghdr) -> *mut cmsghdr { + crate::new::common::posix::sys::socket::next_impl(mhdr, cmsg, false) +} + extern "C" { pub fn sendmmsg( sockfd: c_int, diff --git a/src/new/netbsd/sys/mod.rs b/src/new/netbsd/sys/mod.rs index 185c1f1c2cba..a2f15f6816a3 100644 --- a/src/new/netbsd/sys/mod.rs +++ b/src/new/netbsd/sys/mod.rs @@ -3,6 +3,7 @@ //! https://github.com/NetBSD/src/tree/trunk/sys/sys pub(crate) mod ipc; +pub(crate) mod socket; pub(crate) mod statvfs; pub(crate) mod time; pub(crate) mod timex; diff --git a/src/new/netbsd/sys/socket.rs b/src/new/netbsd/sys/socket.rs new file mode 100644 index 000000000000..950a454301e6 --- /dev/null +++ b/src/new/netbsd/sys/socket.rs @@ -0,0 +1,11 @@ +//! Header: `sys/socket.h` +//! +//! + +pub use crate::new::common::bsd::sys::socket::CMSG_NXTHDR; +pub use crate::new::common::posix::sys::socket::{ + CMSG_DATA, + CMSG_FIRSTHDR, + CMSG_LEN, + CMSG_SPACE, +}; diff --git a/src/new/nto/mod.rs b/src/new/nto/mod.rs index df8ec183bd78..054bcb8c3409 100644 --- a/src/new/nto/mod.rs +++ b/src/new/nto/mod.rs @@ -1,4 +1,6 @@ //! QNX Neutrino libc. -// FIXME(nto): link to manpages needed. +//! +//! Manual pages: +pub(crate) mod sys; pub(crate) mod unistd; diff --git a/src/new/nto/sys/mod.rs b/src/new/nto/sys/mod.rs new file mode 100644 index 000000000000..a882cbd99fca --- /dev/null +++ b/src/new/nto/sys/mod.rs @@ -0,0 +1,3 @@ +//! Directory: `sys/` + +pub(crate) mod socket; diff --git a/src/new/nto/sys/socket.rs b/src/new/nto/sys/socket.rs new file mode 100644 index 000000000000..60810665e57b --- /dev/null +++ b/src/new/nto/sys/socket.rs @@ -0,0 +1,11 @@ +//! Header: `sys/socket.h` +//! +//! Manual pages: + +pub use crate::new::common::posix::sys::socket::{ + CMSG_DATA, + CMSG_FIRSTHDR, + CMSG_LEN, + CMSG_NXTHDR, + CMSG_SPACE, +}; diff --git a/src/new/openbsd/sys/mod.rs b/src/new/openbsd/sys/mod.rs index 7ba77c537356..27201a4a1ffb 100644 --- a/src/new/openbsd/sys/mod.rs +++ b/src/new/openbsd/sys/mod.rs @@ -3,3 +3,4 @@ //! https://github.com/openbsd/src/tree/trunk/sys/sys pub(crate) mod ipc; +pub(crate) mod socket; diff --git a/src/new/openbsd/sys/socket.rs b/src/new/openbsd/sys/socket.rs new file mode 100644 index 000000000000..b36a2e992012 --- /dev/null +++ b/src/new/openbsd/sys/socket.rs @@ -0,0 +1,11 @@ +//! Header: `sys/socket.h` +//! +//! + +pub use crate::new::common::bsd::sys::socket::CMSG_NXTHDR; +pub use crate::new::common::posix::sys::socket::{ + CMSG_DATA, + CMSG_FIRSTHDR, + CMSG_LEN, + CMSG_SPACE, +}; diff --git a/src/new/redox/mod.rs b/src/new/redox/mod.rs index cf7806a2437a..2e419f5d94ca 100644 --- a/src/new/redox/mod.rs +++ b/src/new/redox/mod.rs @@ -1,3 +1,5 @@ //! Redox libc. //! //! * Headers: + +pub(crate) mod sys; diff --git a/src/new/redox/sys/mod.rs b/src/new/redox/sys/mod.rs new file mode 100644 index 000000000000..c7827a4f9b66 --- /dev/null +++ b/src/new/redox/sys/mod.rs @@ -0,0 +1 @@ +pub(crate) mod socket; diff --git a/src/new/redox/sys/socket.rs b/src/new/redox/sys/socket.rs new file mode 100644 index 000000000000..400fc63e59e4 --- /dev/null +++ b/src/new/redox/sys/socket.rs @@ -0,0 +1,12 @@ +//! Header: `sys/socket.h` +//! +//! + +pub use crate::new::common::posix::sys::socket::{ + CMSG_ALIGN, + CMSG_DATA, + CMSG_FIRSTHDR, + CMSG_LEN, + CMSG_NXTHDR, + CMSG_SPACE, +}; diff --git a/src/new/solaris/mod.rs b/src/new/solaris/mod.rs index 97ae47333deb..a54006431aa9 100644 --- a/src/new/solaris/mod.rs +++ b/src/new/solaris/mod.rs @@ -2,4 +2,5 @@ //! //! * Manual pages: (under "Reference Manuals") +pub(crate) mod sys; pub(crate) mod unistd; diff --git a/src/new/solaris/sys/mod.rs b/src/new/solaris/sys/mod.rs new file mode 100644 index 000000000000..a882cbd99fca --- /dev/null +++ b/src/new/solaris/sys/mod.rs @@ -0,0 +1,3 @@ +//! Directory: `sys/` + +pub(crate) mod socket; diff --git a/src/new/solaris/sys/socket.rs b/src/new/solaris/sys/socket.rs new file mode 100644 index 000000000000..7dcecca55a62 --- /dev/null +++ b/src/new/solaris/sys/socket.rs @@ -0,0 +1,11 @@ +//! Header: `sys/socket.h` + +pub use crate::new::common::posix::sys::socket::{ + CMSG_FIRSTHDR, + CMSG_SPACE, +}; +pub use crate::new::common::solarish::sys::socket::{ + CMSG_DATA, + CMSG_LEN, + CMSG_NXTHDR, +}; diff --git a/src/new/vxworks/mod.rs b/src/new/vxworks/mod.rs index 65630565e53e..ede7d3b8d2ff 100644 --- a/src/new/vxworks/mod.rs +++ b/src/new/vxworks/mod.rs @@ -2,3 +2,5 @@ // FIXME(vxworks): link to headers needed. pub(crate) mod unistd; + +pub(crate) mod sys; diff --git a/src/new/vxworks/sys/mod.rs b/src/new/vxworks/sys/mod.rs new file mode 100644 index 000000000000..5945f453c27e --- /dev/null +++ b/src/new/vxworks/sys/mod.rs @@ -0,0 +1,3 @@ +//! Directory: `sys` + +pub(crate) mod socket; diff --git a/src/new/vxworks/sys/socket.rs b/src/new/vxworks/sys/socket.rs new file mode 100644 index 000000000000..349a8bd4498b --- /dev/null +++ b/src/new/vxworks/sys/socket.rs @@ -0,0 +1,10 @@ +//! Header: `sys/socket.h` + +pub use crate::new::common::posix::sys::socket::{ + CMSG_ALIGN, + CMSG_DATA, + CMSG_FIRSTHDR, + CMSG_LEN, + CMSG_NXTHDR, + CMSG_SPACE, +}; diff --git a/src/posix.rs b/src/posix.rs new file mode 100644 index 000000000000..8b137891791f --- /dev/null +++ b/src/posix.rs @@ -0,0 +1 @@ + diff --git a/src/unix/aix/mod.rs b/src/unix/aix/mod.rs index 775061bdbd87..065d9c51c709 100644 --- a/src/unix/aix/mod.rs +++ b/src/unix/aix/mod.rs @@ -2420,41 +2420,6 @@ pub const DEAD_PROCESS: c_short = 8; pub const ACCOUNTING: c_short = 9; f! { - pub fn CMSG_FIRSTHDR(mhdr: *const msghdr) -> *mut cmsghdr { - if (*mhdr).msg_controllen as usize >= size_of::() { - (*mhdr).msg_control as *mut cmsghdr - } else { - core::ptr::null_mut::() - } - } - - pub fn CMSG_NXTHDR(mhdr: *const msghdr, cmsg: *const cmsghdr) -> *mut cmsghdr { - if cmsg.is_null() { - CMSG_FIRSTHDR(mhdr) - } else { - if (cmsg as usize + (*cmsg).cmsg_len as usize + size_of::()) - > ((*mhdr).msg_control as usize + (*mhdr).msg_controllen as usize) - { - core::ptr::null_mut::() - } else { - // AIX does not have any alignment/padding for ancillary data, so we don't need _CMSG_ALIGN here. - (cmsg as usize + (*cmsg).cmsg_len as usize) as *mut cmsghdr - } - } - } - - pub fn CMSG_DATA(cmsg: *const cmsghdr) -> *mut c_uchar { - (cmsg as *mut c_uchar).offset(size_of::() as isize) - } - - pub const fn CMSG_LEN(length: c_uint) -> c_uint { - size_of::() as c_uint + length - } - - pub const fn CMSG_SPACE(length: c_uint) -> c_uint { - size_of::() as c_uint + length - } - pub fn FD_ZERO(set: *mut fd_set) -> () { for slot in (*set).fds_bits.iter_mut() { *slot = 0; diff --git a/src/unix/bsd/apple/mod.rs b/src/unix/bsd/apple/mod.rs index 7b084251d3b8..d2af3df44826 100644 --- a/src/unix/bsd/apple/mod.rs +++ b/src/unix/bsd/apple/mod.rs @@ -2,11 +2,8 @@ //! //! This covers *-apple-* triples currently +use crate::off_t; use crate::prelude::*; -use crate::{ - cmsghdr, - off_t, -}; pub type wchar_t = i32; pub type clock_t = c_ulong; @@ -3965,11 +3962,6 @@ pub const VMADDR_CID_RESERVED: c_uint = 1; pub const VMADDR_CID_HOST: c_uint = 2; pub const VMADDR_PORT_ANY: c_uint = 0xFFFFFFFF; -const fn __DARWIN_ALIGN32(p: usize) -> usize { - const __DARWIN_ALIGNBYTES32: usize = size_of::() - 1; - (p + __DARWIN_ALIGNBYTES32) & !__DARWIN_ALIGNBYTES32 -} - pub const THREAD_EXTENDED_POLICY_COUNT: mach_msg_type_number_t = (size_of::() / size_of::()) as mach_msg_type_number_t; pub const THREAD_TIME_CONSTRAINT_POLICY_COUNT: mach_msg_type_number_t = @@ -4033,32 +4025,6 @@ pub const DOT3COMPLIANCE_COLLS: c_int = 2; pub const MAX_KCTL_NAME: usize = 96; f! { - pub fn CMSG_NXTHDR(mhdr: *const crate::msghdr, cmsg: *const cmsghdr) -> *mut cmsghdr { - if cmsg.is_null() { - return crate::CMSG_FIRSTHDR(mhdr); - } - let cmsg_len = (*cmsg).cmsg_len as usize; - let next = cmsg as usize + __DARWIN_ALIGN32(cmsg_len); - let max = (*mhdr).msg_control as usize + (*mhdr).msg_controllen as usize; - if next + __DARWIN_ALIGN32(size_of::()) > max { - core::ptr::null_mut() - } else { - next as *mut cmsghdr - } - } - - pub fn CMSG_DATA(cmsg: *const cmsghdr) -> *mut c_uchar { - (cmsg as *mut c_uchar).add(__DARWIN_ALIGN32(size_of::())) - } - - pub const fn CMSG_SPACE(length: c_uint) -> c_uint { - (__DARWIN_ALIGN32(size_of::()) + __DARWIN_ALIGN32(length as usize)) as c_uint - } - - pub const fn CMSG_LEN(length: c_uint) -> c_uint { - (__DARWIN_ALIGN32(size_of::()) + length as usize) as c_uint - } - pub const fn VM_MAKE_TAG(id: u8) -> u32 { (id as u32) << 24u32 } diff --git a/src/unix/bsd/freebsdlike/dragonfly/mod.rs b/src/unix/bsd/freebsdlike/dragonfly/mod.rs index 2e3d333f7a4d..6fec2acb8190 100644 --- a/src/unix/bsd/freebsdlike/dragonfly/mod.rs +++ b/src/unix/bsd/freebsdlike/dragonfly/mod.rs @@ -1,8 +1,5 @@ +use crate::off_t; use crate::prelude::*; -use crate::{ - cmsghdr, - off_t, -}; pub type dev_t = u32; pub type wchar_t = i32; @@ -1170,35 +1167,7 @@ pub const RTAX_MPLS2: c_int = 9; pub const RTAX_MPLS3: c_int = 10; pub const RTAX_MAX: c_int = 11; -const fn _CMSG_ALIGN(n: usize) -> usize { - (n + (size_of::() - 1)) & !(size_of::() - 1) -} - f! { - pub fn CMSG_DATA(cmsg: *const cmsghdr) -> *mut c_uchar { - (cmsg as *mut c_uchar).offset(_CMSG_ALIGN(size_of::()) as isize) - } - - pub const fn CMSG_LEN(length: c_uint) -> c_uint { - (_CMSG_ALIGN(size_of::()) + length as usize) as c_uint - } - - pub fn CMSG_NXTHDR(mhdr: *const crate::msghdr, cmsg: *const cmsghdr) -> *mut cmsghdr { - let next = cmsg as usize - + _CMSG_ALIGN((*cmsg).cmsg_len as usize) - + _CMSG_ALIGN(size_of::()); - let max = (*mhdr).msg_control as usize + (*mhdr).msg_controllen as usize; - if next <= max { - (cmsg as usize + _CMSG_ALIGN((*cmsg).cmsg_len as usize)) as *mut cmsghdr - } else { - core::ptr::null_mut::() - } - } - - pub const fn CMSG_SPACE(length: c_uint) -> c_uint { - (_CMSG_ALIGN(size_of::()) + _CMSG_ALIGN(length as usize)) as c_uint - } - pub fn CPU_ZERO(cpuset: &mut cpu_set_t) -> () { for slot in cpuset.ary.iter_mut() { *slot = 0; diff --git a/src/unix/bsd/freebsdlike/freebsd/aarch64.rs b/src/unix/bsd/freebsdlike/freebsd/aarch64.rs index 232770f6e00f..ddd6cc43c909 100644 --- a/src/unix/bsd/freebsdlike/freebsd/aarch64.rs +++ b/src/unix/bsd/freebsdlike/freebsd/aarch64.rs @@ -33,8 +33,6 @@ s! { } } -pub(crate) const _ALIGNBYTES: usize = size_of::() - 1; - pub const BIOCSRTIMEOUT: c_ulong = 0x8010426d; pub const BIOCGRTIMEOUT: c_ulong = 0x4010426e; pub const MAP_32BIT: c_int = 0x00080000; diff --git a/src/unix/bsd/freebsdlike/freebsd/arm.rs b/src/unix/bsd/freebsdlike/freebsd/arm.rs index a0f51834d45d..3f65321fadea 100644 --- a/src/unix/bsd/freebsdlike/freebsd/arm.rs +++ b/src/unix/bsd/freebsdlike/freebsd/arm.rs @@ -17,8 +17,6 @@ s! { } } -pub(crate) const _ALIGNBYTES: usize = size_of::() - 1; - pub const BIOCSRTIMEOUT: c_ulong = 0x8010426d; pub const BIOCGRTIMEOUT: c_ulong = 0x4010426e; diff --git a/src/unix/bsd/freebsdlike/freebsd/mod.rs b/src/unix/bsd/freebsdlike/freebsd/mod.rs index 136a29e6b419..453f4ede9862 100644 --- a/src/unix/bsd/freebsdlike/freebsd/mod.rs +++ b/src/unix/bsd/freebsdlike/freebsd/mod.rs @@ -1,8 +1,5 @@ +use crate::off_t; use crate::prelude::*; -use crate::{ - cmsghdr, - off_t, -}; pub type fflags_t = u32; @@ -4178,36 +4175,7 @@ pub const fn MAP_ALIGNED(a: c_int) -> c_int { a << 24 } -const fn _ALIGN(p: usize) -> usize { - (p + _ALIGNBYTES) & !_ALIGNBYTES -} - f! { - pub fn CMSG_DATA(cmsg: *const cmsghdr) -> *mut c_uchar { - (cmsg as *mut c_uchar).add(_ALIGN(size_of::())) - } - - pub const fn CMSG_LEN(length: c_uint) -> c_uint { - _ALIGN(size_of::()) as c_uint + length - } - - pub fn CMSG_NXTHDR(mhdr: *const crate::msghdr, cmsg: *const cmsghdr) -> *mut cmsghdr { - if cmsg.is_null() { - return crate::CMSG_FIRSTHDR(mhdr); - } - let next = cmsg as usize + _ALIGN((*cmsg).cmsg_len as usize) + _ALIGN(size_of::()); - let max = (*mhdr).msg_control as usize + (*mhdr).msg_controllen as usize; - if next > max { - core::ptr::null_mut::() - } else { - (cmsg as usize + _ALIGN((*cmsg).cmsg_len as usize)) as *mut cmsghdr - } - } - - pub const fn CMSG_SPACE(length: c_uint) -> c_uint { - (_ALIGN(size_of::()) + _ALIGN(length as usize)) as c_uint - } - pub fn MALLOCX_ALIGN(lg: c_uint) -> c_int { ffsl(lg as c_long - 1) } diff --git a/src/unix/bsd/freebsdlike/freebsd/powerpc.rs b/src/unix/bsd/freebsdlike/freebsd/powerpc.rs index 4c0e165af9d2..a3ad6562a13a 100644 --- a/src/unix/bsd/freebsdlike/freebsd/powerpc.rs +++ b/src/unix/bsd/freebsdlike/freebsd/powerpc.rs @@ -21,8 +21,6 @@ s! { } } -pub(crate) const _ALIGNBYTES: usize = size_of::() - 1; - pub const BIOCSRTIMEOUT: c_ulong = 0x8010426d; pub const BIOCGRTIMEOUT: c_ulong = 0x4010426e; pub const MAP_32BIT: c_int = 0x00080000; diff --git a/src/unix/bsd/freebsdlike/freebsd/powerpc64.rs b/src/unix/bsd/freebsdlike/freebsd/powerpc64.rs index bfc6d5c2ccc2..08cf31cca90c 100644 --- a/src/unix/bsd/freebsdlike/freebsd/powerpc64.rs +++ b/src/unix/bsd/freebsdlike/freebsd/powerpc64.rs @@ -21,8 +21,6 @@ s! { } } -pub(crate) const _ALIGNBYTES: usize = size_of::() - 1; - pub const BIOCSRTIMEOUT: c_ulong = 0x8010426d; pub const BIOCGRTIMEOUT: c_ulong = 0x4010426e; diff --git a/src/unix/bsd/freebsdlike/freebsd/riscv64.rs b/src/unix/bsd/freebsdlike/freebsd/riscv64.rs index e2d7920541d9..88b22c7e739a 100644 --- a/src/unix/bsd/freebsdlike/freebsd/riscv64.rs +++ b/src/unix/bsd/freebsdlike/freebsd/riscv64.rs @@ -35,8 +35,6 @@ s! { } } -pub(crate) const _ALIGNBYTES: usize = size_of::() - 1; - pub const BIOCSRTIMEOUT: c_ulong = 0x8010426d; pub const BIOCGRTIMEOUT: c_ulong = 0x4010426e; pub const MAP_32BIT: c_int = 0x00080000; diff --git a/src/unix/bsd/freebsdlike/freebsd/x86.rs b/src/unix/bsd/freebsdlike/freebsd/x86.rs index a95914d8a49a..1675b269ff91 100644 --- a/src/unix/bsd/freebsdlike/freebsd/x86.rs +++ b/src/unix/bsd/freebsdlike/freebsd/x86.rs @@ -42,8 +42,6 @@ s! { } } -pub(crate) const _ALIGNBYTES: usize = size_of::() - 1; - pub const MINSIGSTKSZ: size_t = 2048; // 512 * 4 pub const BIOCSRTIMEOUT: c_ulong = 0x8008426d; diff --git a/src/unix/bsd/freebsdlike/freebsd/x86_64/mod.rs b/src/unix/bsd/freebsdlike/freebsd/x86_64/mod.rs index 2d7a2b66621c..0ac6f44cd1e9 100644 --- a/src/unix/bsd/freebsdlike/freebsd/x86_64/mod.rs +++ b/src/unix/bsd/freebsdlike/freebsd/x86_64/mod.rs @@ -164,8 +164,6 @@ cfg_if! { } } -pub(crate) const _ALIGNBYTES: usize = size_of::() - 1; - pub const BIOCSRTIMEOUT: c_ulong = 0x8010426d; pub const BIOCGRTIMEOUT: c_ulong = 0x4010426e; diff --git a/src/unix/bsd/mod.rs b/src/unix/bsd/mod.rs index 754272a852c4..2826ef3fad71 100644 --- a/src/unix/bsd/mod.rs +++ b/src/unix/bsd/mod.rs @@ -507,14 +507,6 @@ pub const RTAX_AUTHOR: c_int = 6; pub const RTAX_BRD: c_int = 7; f! { - pub fn CMSG_FIRSTHDR(mhdr: *const crate::msghdr) -> *mut cmsghdr { - if (*mhdr).msg_controllen as usize >= size_of::() { - (*mhdr).msg_control.cast::() - } else { - core::ptr::null_mut() - } - } - pub fn FD_CLR(fd: c_int, set: *mut fd_set) -> () { let bits = size_of_val(&(*set).fds_bits[0]) * 8; let fd = fd as usize; diff --git a/src/unix/bsd/netbsdlike/netbsd/aarch64.rs b/src/unix/bsd/netbsdlike/netbsd/aarch64.rs index e0206af04f8f..003ba4cdd6c3 100644 --- a/src/unix/bsd/netbsdlike/netbsd/aarch64.rs +++ b/src/unix/bsd/netbsdlike/netbsd/aarch64.rs @@ -65,8 +65,6 @@ cfg_if! { } } -pub(crate) const _ALIGNBYTES: usize = size_of::() - 1; - pub const PT_GETREGS: c_int = PT_FIRSTMACH + 0; pub const PT_SETREGS: c_int = PT_FIRSTMACH + 1; pub const PT_GETFPREGS: c_int = PT_FIRSTMACH + 2; diff --git a/src/unix/bsd/netbsdlike/netbsd/arm.rs b/src/unix/bsd/netbsdlike/netbsd/arm.rs index 9ff44bd40826..25b73d47aca9 100644 --- a/src/unix/bsd/netbsdlike/netbsd/arm.rs +++ b/src/unix/bsd/netbsdlike/netbsd/arm.rs @@ -3,8 +3,6 @@ use crate::PT_FIRSTMACH; pub type __cpu_simple_lock_nv_t = c_int; -pub(crate) const _ALIGNBYTES: usize = size_of::() - 1; - pub const PT_GETREGS: c_int = PT_FIRSTMACH + 1; pub const PT_SETREGS: c_int = PT_FIRSTMACH + 2; pub const PT_GETFPREGS: c_int = PT_FIRSTMACH + 3; diff --git a/src/unix/bsd/netbsdlike/netbsd/mips.rs b/src/unix/bsd/netbsdlike/netbsd/mips.rs index 1b24b4f6e315..f88d571645d4 100644 --- a/src/unix/bsd/netbsdlike/netbsd/mips.rs +++ b/src/unix/bsd/netbsdlike/netbsd/mips.rs @@ -3,8 +3,6 @@ use crate::PT_FIRSTMACH; pub type __cpu_simple_lock_nv_t = c_int; -pub(crate) const _ALIGNBYTES: usize = size_of::() - 1; - pub const PT_GETREGS: c_int = PT_FIRSTMACH + 1; pub const PT_SETREGS: c_int = PT_FIRSTMACH + 2; pub const PT_GETFPREGS: c_int = PT_FIRSTMACH + 3; diff --git a/src/unix/bsd/netbsdlike/netbsd/mod.rs b/src/unix/bsd/netbsdlike/netbsd/mod.rs index f04997cf5aea..80cc7f53e3d1 100644 --- a/src/unix/bsd/netbsdlike/netbsd/mod.rs +++ b/src/unix/bsd/netbsdlike/netbsd/mod.rs @@ -1,6 +1,5 @@ use crate::prelude::*; use crate::{ - cmsghdr, cpuid_t, lwpid_t, off_t, @@ -1754,36 +1753,7 @@ pub const TFD_NONBLOCK: i32 = crate::O_NONBLOCK; pub const TFD_TIMER_ABSTIME: i32 = crate::O_WRONLY; pub const TFD_TIMER_CANCEL_ON_SET: i32 = crate::O_RDWR; -const fn _ALIGN(p: usize) -> usize { - (p + _ALIGNBYTES) & !_ALIGNBYTES -} - f! { - pub fn CMSG_DATA(cmsg: *const cmsghdr) -> *mut c_uchar { - (cmsg as *mut c_uchar).add(_ALIGN(size_of::())) - } - - pub const fn CMSG_LEN(length: c_uint) -> c_uint { - _ALIGN(size_of::()) as c_uint + length - } - - pub fn CMSG_NXTHDR(mhdr: *const crate::msghdr, cmsg: *const cmsghdr) -> *mut cmsghdr { - if cmsg.is_null() { - return crate::CMSG_FIRSTHDR(mhdr); - } - let next = cmsg as usize + _ALIGN((*cmsg).cmsg_len as usize) + _ALIGN(size_of::()); - let max = (*mhdr).msg_control as usize + (*mhdr).msg_controllen as usize; - if next > max { - core::ptr::null_mut::() - } else { - (cmsg as usize + _ALIGN((*cmsg).cmsg_len as usize)) as *mut cmsghdr - } - } - - pub const fn CMSG_SPACE(length: c_uint) -> c_uint { - (_ALIGN(size_of::()) + _ALIGN(length as usize)) as c_uint - } - // dirfd() is a macro on netbsd to access // the first field of the struct where dirp points to: // http://cvsweb.netbsd.org/bsdweb.cgi/src/include/dirent.h?rev=1.36 diff --git a/src/unix/bsd/netbsdlike/netbsd/powerpc.rs b/src/unix/bsd/netbsdlike/netbsd/powerpc.rs index f8f2d56c0d37..04c928e2cf53 100644 --- a/src/unix/bsd/netbsdlike/netbsd/powerpc.rs +++ b/src/unix/bsd/netbsdlike/netbsd/powerpc.rs @@ -3,8 +3,6 @@ use crate::PT_FIRSTMACH; pub type __cpu_simple_lock_nv_t = c_int; -pub(crate) const _ALIGNBYTES: usize = size_of::() - 1; - pub const PT_STEP: c_int = PT_FIRSTMACH + 0; pub const PT_GETREGS: c_int = PT_FIRSTMACH + 1; pub const PT_SETREGS: c_int = PT_FIRSTMACH + 2; diff --git a/src/unix/bsd/netbsdlike/netbsd/riscv64.rs b/src/unix/bsd/netbsdlike/netbsd/riscv64.rs index 8cacb7250edd..ac011a614d2c 100644 --- a/src/unix/bsd/netbsdlike/netbsd/riscv64.rs +++ b/src/unix/bsd/netbsdlike/netbsd/riscv64.rs @@ -37,8 +37,6 @@ cfg_if! { } } -pub(crate) const _ALIGNBYTES: usize = size_of::() - 1; - pub const PT_GETREGS: c_int = PT_FIRSTMACH + 0; pub const PT_SETREGS: c_int = PT_FIRSTMACH + 1; pub const PT_GETFPREGS: c_int = PT_FIRSTMACH + 2; diff --git a/src/unix/bsd/netbsdlike/netbsd/sparc64.rs b/src/unix/bsd/netbsdlike/netbsd/sparc64.rs index 91622f7eea3f..24d0651dd577 100644 --- a/src/unix/bsd/netbsdlike/netbsd/sparc64.rs +++ b/src/unix/bsd/netbsdlike/netbsd/sparc64.rs @@ -1,7 +1,3 @@ use crate::prelude::*; pub type __cpu_simple_lock_nv_t = c_uchar; - -// should be pub(crate), but that requires Rust 1.18.0 -#[doc(hidden)] -pub const _ALIGNBYTES: usize = 0xf; diff --git a/src/unix/bsd/netbsdlike/netbsd/x86.rs b/src/unix/bsd/netbsdlike/netbsd/x86.rs index 95f55768973c..24d0651dd577 100644 --- a/src/unix/bsd/netbsdlike/netbsd/x86.rs +++ b/src/unix/bsd/netbsdlike/netbsd/x86.rs @@ -1,5 +1,3 @@ use crate::prelude::*; pub type __cpu_simple_lock_nv_t = c_uchar; - -pub(crate) const _ALIGNBYTES: usize = size_of::() - 1; diff --git a/src/unix/bsd/netbsdlike/netbsd/x86_64.rs b/src/unix/bsd/netbsdlike/netbsd/x86_64.rs index 801b326b70fa..b2f78ccf1cef 100644 --- a/src/unix/bsd/netbsdlike/netbsd/x86_64.rs +++ b/src/unix/bsd/netbsdlike/netbsd/x86_64.rs @@ -23,8 +23,6 @@ s! { } } -pub(crate) const _ALIGNBYTES: usize = size_of::() - 1; - pub const PT_STEP: c_int = PT_FIRSTMACH + 0; pub const PT_GETREGS: c_int = PT_FIRSTMACH + 1; pub const PT_SETREGS: c_int = PT_FIRSTMACH + 2; diff --git a/src/unix/bsd/netbsdlike/openbsd/aarch64.rs b/src/unix/bsd/netbsdlike/openbsd/aarch64.rs index 13142ea0f936..525b8585b79e 100644 --- a/src/unix/bsd/netbsdlike/openbsd/aarch64.rs +++ b/src/unix/bsd/netbsdlike/openbsd/aarch64.rs @@ -15,6 +15,4 @@ s! { } } -pub(crate) const _ALIGNBYTES: usize = size_of::() - 1; - pub const _MAX_PAGE_SHIFT: u32 = 12; diff --git a/src/unix/bsd/netbsdlike/openbsd/arm.rs b/src/unix/bsd/netbsdlike/openbsd/arm.rs index 8b3f72139d86..500afbeebd86 100644 --- a/src/unix/bsd/netbsdlike/openbsd/arm.rs +++ b/src/unix/bsd/netbsdlike/openbsd/arm.rs @@ -1,5 +1 @@ -use crate::prelude::*; - -pub(crate) const _ALIGNBYTES: usize = size_of::() - 1; - pub const _MAX_PAGE_SHIFT: u32 = 12; diff --git a/src/unix/bsd/netbsdlike/openbsd/mips64.rs b/src/unix/bsd/netbsdlike/openbsd/mips64.rs index 162ceda265df..01ca197c0dea 100644 --- a/src/unix/bsd/netbsdlike/openbsd/mips64.rs +++ b/src/unix/bsd/netbsdlike/openbsd/mips64.rs @@ -1,4 +1 @@ -#[doc(hidden)] -pub const _ALIGNBYTES: usize = 7; - pub const _MAX_PAGE_SHIFT: u32 = 14; diff --git a/src/unix/bsd/netbsdlike/openbsd/mod.rs b/src/unix/bsd/netbsdlike/openbsd/mod.rs index 55abf0b411c4..1f95782a44fb 100644 --- a/src/unix/bsd/netbsdlike/openbsd/mod.rs +++ b/src/unix/bsd/netbsdlike/openbsd/mod.rs @@ -1,9 +1,6 @@ +use crate::off_t; use crate::prelude::*; use crate::unix::bsd::O_SYNC; -use crate::{ - cmsghdr, - off_t, -}; pub type clock_t = i64; pub type suseconds_t = c_long; @@ -1684,37 +1681,6 @@ pub const RTAX_STATIC: c_int = 13; pub const RTAX_SEARCH: c_int = 14; pub const RTAX_MAX: c_int = 15; -const fn _ALIGN(p: usize) -> usize { - (p + _ALIGNBYTES) & !_ALIGNBYTES -} - -f! { - pub fn CMSG_DATA(cmsg: *const cmsghdr) -> *mut c_uchar { - (cmsg as *mut c_uchar).offset(_ALIGN(size_of::()) as isize) - } - - pub const fn CMSG_LEN(length: c_uint) -> c_uint { - _ALIGN(size_of::()) as c_uint + length - } - - pub fn CMSG_NXTHDR(mhdr: *const crate::msghdr, cmsg: *const cmsghdr) -> *mut cmsghdr { - if cmsg.is_null() { - return crate::CMSG_FIRSTHDR(mhdr); - } - let next = cmsg as usize + _ALIGN((*cmsg).cmsg_len as usize) + _ALIGN(size_of::()); - let max = (*mhdr).msg_control as usize + (*mhdr).msg_controllen as usize; - if next > max { - core::ptr::null_mut::() - } else { - (cmsg as usize + _ALIGN((*cmsg).cmsg_len as usize)) as *mut cmsghdr - } - } - - pub const fn CMSG_SPACE(length: c_uint) -> c_uint { - (_ALIGN(size_of::()) + _ALIGN(length as usize)) as c_uint - } -} - safe_f! { pub const fn WSTOPSIG(status: c_int) -> c_int { status >> 8 diff --git a/src/unix/bsd/netbsdlike/openbsd/powerpc.rs b/src/unix/bsd/netbsdlike/openbsd/powerpc.rs index 8b3f72139d86..500afbeebd86 100644 --- a/src/unix/bsd/netbsdlike/openbsd/powerpc.rs +++ b/src/unix/bsd/netbsdlike/openbsd/powerpc.rs @@ -1,5 +1 @@ -use crate::prelude::*; - -pub(crate) const _ALIGNBYTES: usize = size_of::() - 1; - pub const _MAX_PAGE_SHIFT: u32 = 12; diff --git a/src/unix/bsd/netbsdlike/openbsd/powerpc64.rs b/src/unix/bsd/netbsdlike/openbsd/powerpc64.rs index 5ebe85741454..500afbeebd86 100644 --- a/src/unix/bsd/netbsdlike/openbsd/powerpc64.rs +++ b/src/unix/bsd/netbsdlike/openbsd/powerpc64.rs @@ -1,5 +1 @@ -use crate::prelude::*; - -pub(crate) const _ALIGNBYTES: usize = size_of::() - 1; - pub const _MAX_PAGE_SHIFT: u32 = 12; diff --git a/src/unix/bsd/netbsdlike/openbsd/riscv64.rs b/src/unix/bsd/netbsdlike/openbsd/riscv64.rs index e0ecf2ac28b5..3e2f58b5ca05 100644 --- a/src/unix/bsd/netbsdlike/openbsd/riscv64.rs +++ b/src/unix/bsd/netbsdlike/openbsd/riscv64.rs @@ -20,6 +20,4 @@ s! { } } -pub(crate) const _ALIGNBYTES: usize = size_of::() - 1; - pub const _MAX_PAGE_SHIFT: u32 = 12; diff --git a/src/unix/bsd/netbsdlike/openbsd/sparc64.rs b/src/unix/bsd/netbsdlike/openbsd/sparc64.rs index 88481f4f014e..18f46b467340 100644 --- a/src/unix/bsd/netbsdlike/openbsd/sparc64.rs +++ b/src/unix/bsd/netbsdlike/openbsd/sparc64.rs @@ -1,4 +1 @@ -#[doc(hidden)] -pub const _ALIGNBYTES: usize = 0xf; - pub const _MAX_PAGE_SHIFT: u32 = 13; diff --git a/src/unix/bsd/netbsdlike/openbsd/x86.rs b/src/unix/bsd/netbsdlike/openbsd/x86.rs index 97dc58327d22..500afbeebd86 100644 --- a/src/unix/bsd/netbsdlike/openbsd/x86.rs +++ b/src/unix/bsd/netbsdlike/openbsd/x86.rs @@ -1,5 +1 @@ -use crate::prelude::*; - -pub(crate) const _ALIGNBYTES: usize = size_of::() - 1; - pub const _MAX_PAGE_SHIFT: u32 = 12; diff --git a/src/unix/bsd/netbsdlike/openbsd/x86_64.rs b/src/unix/bsd/netbsdlike/openbsd/x86_64.rs index 74889a743b9a..345e9b67d102 100644 --- a/src/unix/bsd/netbsdlike/openbsd/x86_64.rs +++ b/src/unix/bsd/netbsdlike/openbsd/x86_64.rs @@ -54,8 +54,6 @@ s! { } } -pub(crate) const _ALIGNBYTES: usize = size_of::() - 1; - pub const _MAX_PAGE_SHIFT: u32 = 12; pub const PT_STEP: c_int = PT_FIRSTMACH + 0; diff --git a/src/unix/cygwin/mod.rs b/src/unix/cygwin/mod.rs index 9d3a3b55cfea..9f73a0e567f8 100644 --- a/src/unix/cygwin/mod.rs +++ b/src/unix/cygwin/mod.rs @@ -1748,36 +1748,6 @@ f! { pub fn CPU_EQUAL(set1: &cpu_set_t, set2: &cpu_set_t) -> bool { set1.bits == set2.bits } - - pub fn CMSG_LEN(length: c_uint) -> c_uint { - CMSG_ALIGN(size_of::()) as c_uint + length - } - - pub const fn CMSG_SPACE(length: c_uint) -> c_uint { - (CMSG_ALIGN(length as usize) + CMSG_ALIGN(size_of::())) as c_uint - } - - pub fn CMSG_FIRSTHDR(mhdr: *const msghdr) -> *mut cmsghdr { - if (*mhdr).msg_controllen as usize >= size_of::() { - (*mhdr).msg_control.cast() - } else { - core::ptr::null_mut() - } - } - - pub fn CMSG_NXTHDR(mhdr: *const msghdr, cmsg: *const cmsghdr) -> *mut cmsghdr { - let next = (cmsg as usize + CMSG_ALIGN((*cmsg).cmsg_len as usize)) as *mut cmsghdr; - let max = (*mhdr).msg_control as usize + (*mhdr).msg_controllen as usize; - if next as usize + CMSG_ALIGN(size_of::()) as usize > max { - core::ptr::null_mut() - } else { - next - } - } - - pub fn CMSG_DATA(cmsg: *const cmsghdr) -> *mut c_uchar { - cmsg.offset(1).cast_mut().cast() - } } safe_f! { @@ -1828,10 +1798,6 @@ safe_f! { } } -const fn CMSG_ALIGN(len: usize) -> usize { - len + size_of::() - 1 & !(size_of::() - 1) -} - extern "C" { pub fn sigwait(set: *const sigset_t, sig: *mut c_int) -> c_int; pub fn sigwaitinfo(set: *const sigset_t, info: *mut siginfo_t) -> c_int; diff --git a/src/unix/haiku/mod.rs b/src/unix/haiku/mod.rs index c1259fe6e0c9..601b38d8e732 100644 --- a/src/unix/haiku/mod.rs +++ b/src/unix/haiku/mod.rs @@ -1376,46 +1376,7 @@ pub const POSIX_SPAWN_SETSIGDEF: c_short = 0x10; pub const POSIX_SPAWN_SETSIGMASK: c_short = 0x20; pub const POSIX_SPAWN_SETSID: c_short = 0x40; -const fn CMSG_ALIGN(len: usize) -> usize { - len + size_of::() - 1 & !(size_of::() - 1) -} - f! { - pub fn CMSG_FIRSTHDR(mhdr: *const msghdr) -> *mut cmsghdr { - if (*mhdr).msg_controllen as usize >= size_of::() { - (*mhdr).msg_control as *mut cmsghdr - } else { - core::ptr::null_mut::() - } - } - - pub fn CMSG_DATA(cmsg: *const cmsghdr) -> *mut c_uchar { - (cmsg as *mut c_uchar).offset(CMSG_ALIGN(size_of::()) as isize) - } - - pub const fn CMSG_SPACE(length: c_uint) -> c_uint { - (CMSG_ALIGN(length as usize) + CMSG_ALIGN(size_of::())) as c_uint - } - - pub const fn CMSG_LEN(length: c_uint) -> c_uint { - CMSG_ALIGN(size_of::()) as c_uint + length - } - - pub fn CMSG_NXTHDR(mhdr: *const msghdr, cmsg: *const cmsghdr) -> *mut cmsghdr { - if cmsg.is_null() { - return crate::CMSG_FIRSTHDR(mhdr); - } - let next = cmsg as usize - + CMSG_ALIGN((*cmsg).cmsg_len as usize) - + CMSG_ALIGN(size_of::()); - let max = (*mhdr).msg_control as usize + (*mhdr).msg_controllen as usize; - if next > max { - core::ptr::null_mut::() - } else { - (cmsg as usize + CMSG_ALIGN((*cmsg).cmsg_len as usize)) as *mut cmsghdr - } - } - pub fn FD_CLR(fd: c_int, set: *mut fd_set) -> () { let fd = fd as usize; let size = size_of_val(&(*set).fds_bits[0]) * 8; diff --git a/src/unix/hurd/mod.rs b/src/unix/hurd/mod.rs index 3f2e3dd65b7f..6e5e5d1a21ef 100644 --- a/src/unix/hurd/mod.rs +++ b/src/unix/hurd/mod.rs @@ -3354,47 +3354,8 @@ pub const PTHREAD_STACK_MIN: size_t = 0; // Non-public helper constants const _UTSNAME_LENGTH: usize = 1024; -const fn CMSG_ALIGN(len: usize) -> usize { - (len + size_of::() - 1) & !(size_of::() - 1) -} - // functions f! { - pub fn CMSG_FIRSTHDR(mhdr: *const msghdr) -> *mut cmsghdr { - if (*mhdr).msg_controllen as usize >= size_of::() { - (*mhdr).msg_control.cast::() - } else { - core::ptr::null_mut::() - } - } - - pub fn CMSG_DATA(cmsg: *const cmsghdr) -> *mut c_uchar { - (cmsg as *mut c_uchar).offset(CMSG_ALIGN(size_of::()) as isize) - } - - pub const fn CMSG_SPACE(length: c_uint) -> c_uint { - (CMSG_ALIGN(length as usize) + CMSG_ALIGN(size_of::())) as c_uint - } - - pub const fn CMSG_LEN(length: c_uint) -> c_uint { - CMSG_ALIGN(size_of::()) as c_uint + length - } - - pub fn CMSG_NXTHDR(mhdr: *const msghdr, cmsg: *const cmsghdr) -> *mut cmsghdr { - if ((*cmsg).cmsg_len as usize) < size_of::() { - return core::ptr::null_mut::(); - } - let next = (cmsg as usize + 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 - || next as usize + CMSG_ALIGN((*next).cmsg_len as usize) > max - { - core::ptr::null_mut::() - } else { - next.cast::() - } - } - pub fn CPU_ALLOC_SIZE(count: c_int) -> size_t { let _dummy: cpu_set_t = mem::zeroed(); let size_in_bits = 8 * size_of_val(&_dummy.bits[0]); diff --git a/src/unix/linux_like/android/mod.rs b/src/unix/linux_like/android/mod.rs index e39abe6b9ecb..2528b9197aee 100644 --- a/src/unix/linux_like/android/mod.rs +++ b/src/unix/linux_like/android/mod.rs @@ -1,10 +1,6 @@ //! Android-specific definitions for linux-like values use crate::prelude::*; -use crate::{ - cmsghdr, - msghdr, -}; cfg_if! { if #[cfg(doc)] { @@ -3269,16 +3265,6 @@ cfg_if! { } f! { - pub fn CMSG_NXTHDR(mhdr: *const msghdr, cmsg: *const cmsghdr) -> *mut cmsghdr { - 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 { - core::ptr::null_mut::() - } else { - next as *mut cmsghdr - } - } - pub fn CPU_ALLOC_SIZE(count: c_int) -> size_t { let _dummy: cpu_set_t = mem::zeroed(); let size_in_bits = 8 * size_of_val(&_dummy.__bits[0]); diff --git a/src/unix/linux_like/emscripten/mod.rs b/src/unix/linux_like/emscripten/mod.rs index 35d7001ff5f5..732642941894 100644 --- a/src/unix/linux_like/emscripten/mod.rs +++ b/src/unix/linux_like/emscripten/mod.rs @@ -1251,19 +1251,6 @@ pub const PRIO_USER: c_int = 2; pub const SOMAXCONN: c_int = 128; f! { - pub fn CMSG_NXTHDR(mhdr: *const msghdr, cmsg: *const cmsghdr) -> *mut cmsghdr { - 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 cmsghdr; - let max = (*mhdr).msg_control as usize + (*mhdr).msg_controllen as usize; - if (next.offset(1)) as usize > max { - core::ptr::null_mut::() - } else { - next as *mut cmsghdr - } - } - pub fn CPU_ZERO(cpuset: &mut cpu_set_t) -> () { for slot in cpuset.bits.iter_mut() { *slot = 0; diff --git a/src/unix/linux_like/linux_l4re_shared.rs b/src/unix/linux_like/linux_l4re_shared.rs index bd3cfafeb6e7..52b845b25119 100644 --- a/src/unix/linux_like/linux_l4re_shared.rs +++ b/src/unix/linux_like/linux_l4re_shared.rs @@ -1486,25 +1486,6 @@ pub const NT_PRFPXREG: c_int = 20; pub const MS_NOUSER: c_ulong = 0xffffffff80000000; f! { - pub fn CMSG_NXTHDR( - mhdr: *const crate::msghdr, - cmsg: *const crate::cmsghdr, - ) -> *mut crate::cmsghdr { - 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 - { - core::ptr::null_mut::() - } else { - next - } - } - pub fn CPU_ALLOC_SIZE(count: c_int) -> size_t { let _dummy: cpu_set_t = mem::zeroed(); let size_in_bits = 8 * size_of_val(&_dummy.bits[0]); diff --git a/src/unix/linux_like/mod.rs b/src/unix/linux_like/mod.rs index 30bad55e032f..f978ac9750d6 100644 --- a/src/unix/linux_like/mod.rs +++ b/src/unix/linux_like/mod.rs @@ -1782,31 +1782,7 @@ cfg_if! { } } -const fn CMSG_ALIGN(len: usize) -> usize { - (len + size_of::() - 1) & !(size_of::() - 1) -} - f! { - pub fn CMSG_FIRSTHDR(mhdr: *const crate::msghdr) -> *mut crate::cmsghdr { - if (*mhdr).msg_controllen as usize >= size_of::() { - (*mhdr).msg_control.cast::() - } else { - core::ptr::null_mut::() - } - } - - pub fn CMSG_DATA(cmsg: *const crate::cmsghdr) -> *mut c_uchar { - cmsg.offset(1) as *mut c_uchar - } - - pub const fn CMSG_SPACE(length: c_uint) -> c_uint { - (CMSG_ALIGN(length as usize) + CMSG_ALIGN(size_of::())) as c_uint - } - - pub const fn CMSG_LEN(length: c_uint) -> c_uint { - CMSG_ALIGN(size_of::()) as c_uint + length - } - pub fn FD_CLR(fd: c_int, set: *mut fd_set) -> () { let fd = fd as usize; let size = size_of_val(&(*set).fds_bits[0]) * 8; diff --git a/src/unix/nto/mod.rs b/src/unix/nto/mod.rs index 60202cddd7b9..9425c7af611b 100644 --- a/src/unix/nto/mod.rs +++ b/src/unix/nto/mod.rs @@ -2389,45 +2389,12 @@ pub const PTHREAD_RWLOCK_INITIALIZER: pthread_rwlock_t = pthread_rwlock_t { __spare: 0, }; -const fn _CMSG_ALIGN(len: usize) -> usize { - len + size_of::() - 1 & !(size_of::() - 1) -} - +// IMPROVEMENT: reuse crate::new::common::posix::sys::socket::align_impl? const fn _ALIGN(p: usize, b: usize) -> usize { (p + b - 1) & !(b - 1) } f! { - pub fn CMSG_FIRSTHDR(mhdr: *const msghdr) -> *mut cmsghdr { - if (*mhdr).msg_controllen as usize >= size_of::() { - (*mhdr).msg_control as *mut cmsghdr - } else { - core::ptr::null_mut::() - } - } - - pub fn CMSG_NXTHDR(mhdr: *const crate::msghdr, cmsg: *const cmsghdr) -> *mut cmsghdr { - let msg = _CMSG_ALIGN((*cmsg).cmsg_len as usize); - let next = cmsg as usize + msg + _CMSG_ALIGN(size_of::()); - if next > (*mhdr).msg_control as usize + (*mhdr).msg_controllen as usize { - core::ptr::null_mut::() - } else { - (cmsg as usize + msg) as *mut cmsghdr - } - } - - pub fn CMSG_DATA(cmsg: *const cmsghdr) -> *mut c_uchar { - (cmsg as *mut c_uchar).offset(_CMSG_ALIGN(size_of::()) as isize) - } - - pub const fn CMSG_LEN(length: c_uint) -> c_uint { - _CMSG_ALIGN(size_of::()) as c_uint + length - } - - pub const fn CMSG_SPACE(length: c_uint) -> c_uint { - (_CMSG_ALIGN(size_of::()) + _CMSG_ALIGN(length as usize)) as c_uint - } - pub fn FD_CLR(fd: c_int, set: *mut fd_set) -> () { let fd = fd as usize; let size = size_of_val(&(*set).fds_bits[0]) * 8; diff --git a/src/unix/redox/mod.rs b/src/unix/redox/mod.rs index 6dc5fcc1198e..cfb3b4574d56 100644 --- a/src/unix/redox/mod.rs +++ b/src/unix/redox/mod.rs @@ -1091,17 +1091,6 @@ pub const PRIO_PGRP: c_int = 1; pub const PRIO_USER: c_int = 2; f! { - //sys/socket.h - pub const fn CMSG_ALIGN(len: size_t) -> size_t { - (len + size_of::() - 1) & !(size_of::() - 1) - } - pub const fn CMSG_LEN(length: c_uint) -> c_uint { - (CMSG_ALIGN(size_of::()) + length as usize) as c_uint - } - pub const fn CMSG_SPACE(len: c_uint) -> c_uint { - (CMSG_ALIGN(len as size_t) + CMSG_ALIGN(size_of::())) as c_uint - } - // wait.h pub fn FD_CLR(fd: c_int, set: *mut fd_set) -> () { let fd = fd as usize; @@ -1331,10 +1320,6 @@ extern "C" { pub fn getrlimit(resource: c_int, rlim: *mut crate::rlimit) -> c_int; pub fn setrlimit(resource: c_int, rlim: *const crate::rlimit) -> c_int; - // sys/socket.h - pub fn CMSG_DATA(cmsg: *const cmsghdr) -> *mut c_uchar; - pub fn CMSG_FIRSTHDR(mhdr: *const msghdr) -> *mut cmsghdr; - pub fn CMSG_NXTHDR(mhdr: *const msghdr, cmsg: *const cmsghdr) -> *mut cmsghdr; pub fn bind( socket: c_int, address: *const crate::sockaddr, diff --git a/src/unix/solarish/mod.rs b/src/unix/solarish/mod.rs index 963246732c43..b5faf7768ae2 100644 --- a/src/unix/solarish/mod.rs +++ b/src/unix/solarish/mod.rs @@ -2185,63 +2185,12 @@ pub const PI_FPUTYPE: c_int = 32; // sys/auxv.h pub const AT_SUN_HWCAP: c_uint = 2009; -// As per sys/socket.h, header alignment must be 8 bytes on SPARC -// and 4 bytes everywhere else: -#[cfg(target_arch = "sparc64")] -const _CMSG_HDR_ALIGNMENT: usize = 8; -#[cfg(not(target_arch = "sparc64"))] -const _CMSG_HDR_ALIGNMENT: usize = 4; - -const _CMSG_DATA_ALIGNMENT: usize = size_of::(); - const NEWDEV: c_int = 1; // sys/sendfile.h pub const SFV_FD_SELF: c_int = -2; -const fn _CMSG_HDR_ALIGN(p: usize) -> usize { - (p + _CMSG_HDR_ALIGNMENT - 1) & !(_CMSG_HDR_ALIGNMENT - 1) -} - -const fn _CMSG_DATA_ALIGN(p: usize) -> usize { - (p + _CMSG_DATA_ALIGNMENT - 1) & !(_CMSG_DATA_ALIGNMENT - 1) -} - f! { - pub fn CMSG_DATA(cmsg: *const cmsghdr) -> *mut c_uchar { - _CMSG_DATA_ALIGN(cmsg.offset(1) as usize) as *mut c_uchar - } - - pub const fn CMSG_LEN(length: c_uint) -> c_uint { - _CMSG_DATA_ALIGN(size_of::()) as c_uint + length - } - - pub fn CMSG_FIRSTHDR(mhdr: *const crate::msghdr) -> *mut cmsghdr { - if ((*mhdr).msg_controllen as usize) < size_of::() { - core::ptr::null_mut::() - } else { - (*mhdr).msg_control as *mut cmsghdr - } - } - - pub fn CMSG_NXTHDR(mhdr: *const crate::msghdr, cmsg: *const cmsghdr) -> *mut cmsghdr { - if cmsg.is_null() { - return crate::CMSG_FIRSTHDR(mhdr); - } - let next = - _CMSG_HDR_ALIGN(cmsg as usize + (*cmsg).cmsg_len as usize + size_of::()); - let max = (*mhdr).msg_control as usize + (*mhdr).msg_controllen as usize; - if next > max { - core::ptr::null_mut::() - } else { - _CMSG_HDR_ALIGN(cmsg as usize + (*cmsg).cmsg_len as usize) as *mut cmsghdr - } - } - - pub const fn CMSG_SPACE(length: c_uint) -> c_uint { - _CMSG_HDR_ALIGN(size_of::() as usize + length as usize) as c_uint - } - pub fn FD_CLR(fd: c_int, set: *mut fd_set) -> () { let bits = size_of_val(&(*set).fds_bits[0]) * 8; let fd = fd as usize; diff --git a/src/vxworks/mod.rs b/src/vxworks/mod.rs index ad1b0f9d0981..6bd464479470 100644 --- a/src/vxworks/mod.rs +++ b/src/vxworks/mod.rs @@ -1418,44 +1418,6 @@ extern_ty! { pub enum fpos_t {} // FIXME(vxworks): fill this out with a struct } -f! { - pub const fn CMSG_ALIGN(len: usize) -> usize { - len + size_of::() - 1 & !(size_of::() - 1) - } - - pub fn CMSG_NXTHDR(mhdr: *const msghdr, cmsg: *const cmsghdr) -> *mut cmsghdr { - let next = cmsg as usize - + CMSG_ALIGN((*cmsg).cmsg_len as usize) - + CMSG_ALIGN(size_of::()); - let max = (*mhdr).msg_control as usize + (*mhdr).msg_controllen as usize; - if next <= max { - (cmsg as usize + CMSG_ALIGN((*cmsg).cmsg_len as usize)) as *mut cmsghdr - } else { - core::ptr::null_mut::() - } - } - - pub fn CMSG_FIRSTHDR(mhdr: *const msghdr) -> *mut cmsghdr { - if (*mhdr).msg_controllen as usize > 0 { - (*mhdr).msg_control as *mut cmsghdr - } else { - core::ptr::null_mut::() - } - } - - pub fn CMSG_DATA(cmsg: *const cmsghdr) -> *mut c_uchar { - (cmsg as *mut c_uchar).offset(CMSG_ALIGN(size_of::()) as isize) - } - - pub const fn CMSG_SPACE(length: c_uint) -> c_uint { - (CMSG_ALIGN(length as usize) + CMSG_ALIGN(size_of::())) as c_uint - } - - pub const fn CMSG_LEN(length: c_uint) -> c_uint { - CMSG_ALIGN(size_of::()) as c_uint + length - } -} - extern "C" { pub fn isalnum(c: c_int) -> c_int; pub fn isalpha(c: c_int) -> c_int; diff --git a/tests/const_fn.rs b/tests/const_fn.rs index d9b41b8073c7..0e39291dd42b 100644 --- a/tests/const_fn.rs +++ b/tests/const_fn.rs @@ -1,3 +1,3 @@ #[cfg(target_os = "linux")] -const _FOO: libc::c_uint = unsafe { libc::CMSG_SPACE(1) }; +const _FOO: libc::c_uint = libc::CMSG_SPACE(1); //^ if CMSG_SPACE is not const, this will fail to compile