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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions libc-test/tests/cmsg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@

#[cfg(unix)]
mod t {

use std::mem;

use libc::{
self,
c_uchar,
c_uint,
c_void,
Expand Down Expand Up @@ -50,9 +48,7 @@ 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) });
}
}

Expand Down Expand Up @@ -108,10 +104,8 @@ mod t {

#[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) });
}
}
}
51 changes: 2 additions & 49 deletions src/fuchsia/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")] {
Expand All @@ -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;
Expand Down Expand Up @@ -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::<cmsghdr>() {
core::ptr::null_mut::<cmsghdr>()
} else if __CMSG_NEXT(cmsg).add(size_of::<cmsghdr>()) >= __MHDR_END(mhdr) {
core::ptr::null_mut::<cmsghdr>()
} else {
__CMSG_NEXT(cmsg).cast()
}
}

pub fn CMSG_FIRSTHDR(mhdr: *const msghdr) -> *mut cmsghdr {
if (*mhdr).msg_controllen as size_t >= size_of::<cmsghdr>() {
(*mhdr).msg_control.cast()
} else {
core::ptr::null_mut::<cmsghdr>()
}
}

pub const fn CMSG_ALIGN(len: size_t) -> size_t {
(len + size_of::<size_t>() - 1) & !(size_of::<size_t>() - 1)
}

pub const fn CMSG_SPACE(len: c_uint) -> c_uint {
(CMSG_ALIGN(len as size_t) + CMSG_ALIGN(size_of::<cmsghdr>())) as c_uint
}

pub const fn CMSG_LEN(len: c_uint) -> c_uint {
(CMSG_ALIGN(size_of::<cmsghdr>()) + len as size_t) as c_uint
}
}

safe_f! {
Expand Down Expand Up @@ -3168,19 +3134,6 @@ safe_f! {
}
}

fn __CMSG_LEN(cmsg: *const cmsghdr) -> ssize_t {
((unsafe { (*cmsg).cmsg_len as size_t } + size_of::<c_long>() - 1) & !(size_of::<c_long>() - 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")]
Expand Down
1 change: 1 addition & 0 deletions src/new/aix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
//! * Headers are not public
//! * Manual pages: <https://www.ibm.com/docs/en/aix> (under "Technical reference" for that version)

pub(crate) mod sys;
pub(crate) mod unistd;
3 changes: 3 additions & 0 deletions src/new/aix/sys/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
//! Directory: `sys/`

pub(crate) mod socket;
9 changes: 9 additions & 0 deletions src/new/aix/sys/socket.rs
Original file line number Diff line number Diff line change
@@ -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,
};
6 changes: 6 additions & 0 deletions src/new/apple/libc/mod.rs
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this one actually getting picked up? The module is defined here

mod libc {
pub(crate) mod signal;
pub(crate) mod unistd;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There's a pub(crate) use libc::*; a bit further down :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hah, see what you mean. I seem to have made it into a mod.rs whilst keeping the mod libc {} somehow. I probably did when adding a libc/sys/socket.rs, realizing later on that it should be under xnu/, (hence the out-of-place freebsd copy-pasta).

Anyhow, I've now removed the libc/sys/socket.rs, making the mod.rs creation irrelevant to this PR... Do you want med to keep it anyway?

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//! Entrypoint for Apple headers, usually found as part of the Xcode SDK.
//!
//! <https://github.com/apple-oss-distributions/Libc/tree/main/include>

pub(crate) mod signal;
pub(crate) mod unistd;
14 changes: 4 additions & 10 deletions src/new/apple/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,12 @@
//! The Xcode SDK includes interfaces that are split across a couple of different libraries. Most
//! of these are available at <https://github.com/apple-oss-distributions>.

/// Entrypoint for Apple headers, usually found as part of the Xcode SDK.
///
/// <https://github.com/apple-oss-distributions/Libc/tree/main/include>
mod libc {
pub(crate) mod signal;
pub(crate) mod unistd;
}
mod libc;
pub(crate) use libc::*;

mod libpthread;
mod xnu;

pub(crate) use libc::*;
pub(crate) use libpthread::pthread_;
pub(crate) use pthread_::pthread;

mod xnu;
pub(crate) use xnu::*;
1 change: 1 addition & 0 deletions src/new/apple/xnu/sys/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
//! <https://github.com/apple-oss-distributions/xnu/tree/main/bsd/sys>

pub(crate) mod signal;
pub(crate) mod socket;

/// Directory: `sys/_types`
///
Expand Down
11 changes: 11 additions & 0 deletions src/new/apple/xnu/sys/socket.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//! Header: `sys/socket.h`
//!
//! <https://github.com/apple-oss-distributions/xnu/blob/main/bsd/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,
};
11 changes: 11 additions & 0 deletions src/new/bionic_libc/sys/socket.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
//! Header: `sys/socket.h`
//!
//! <https://android.googlesource.com/platform/bionic/+/refs/heads/main/libc/include/sys/socket.h>

use crate::prelude::*;

Expand Down Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions src/new/common/bsd.rs → src/new/common/bsd/mod.rs
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
//! Interfaces common across the BSD family.

pub(crate) mod sys;
1 change: 1 addition & 0 deletions src/new/common/bsd/sys/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub(crate) mod socket;
11 changes: 11 additions & 0 deletions src/new/common/bsd/sys/socket.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#[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)
}
2 changes: 2 additions & 0 deletions src/new/common/posix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@
))]
pub(crate) mod pthread;
pub(crate) mod unistd;

pub(crate) mod sys;
3 changes: 3 additions & 0 deletions src/new/common/posix/sys/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
//! Directory: `sys/`

pub(crate) mod socket;
Loading