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
10 changes: 9 additions & 1 deletion src/new/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ cfg_if! {
mod glibc;
pub(crate) use glibc::*;
} else if #[cfg(any(target_env = "musl", target_env = "ohos"))] {
// OhOS also uses the musl libc
mod musl;
pub(crate) use musl::*;
} else if #[cfg(target_env = "newlib")] {
Expand All @@ -167,7 +168,7 @@ cfg_if! {
}
}

// Headers we export
// Per-OS headers we export
cfg_if! {
if #[cfg(target_os = "android")] {
pub use sys::socket::*;
Expand All @@ -184,5 +185,12 @@ cfg_if! {
}
}

// Per-env headers we export
cfg_if! {
if #[cfg(any(target_env = "musl", target_env = "ohos"))] {
pub use sys::socket::*;
}
}

#[cfg(target_family = "unix")]
pub use unistd::*;
7 changes: 7 additions & 0 deletions src/new/musl/arch/generic/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//! Source directory: `arch/generic/`
//!
//! <https://github.com/kraj/musl/tree/master/arch/generic>

pub(crate) mod bits {
// Currently unused
}
4 changes: 4 additions & 0 deletions src/new/musl/arch/mips/bits/socket.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
use crate::prelude::*;

pub const SOCK_STREAM: c_int = 2;
pub const SOCK_DGRAM: c_int = 1;
7 changes: 7 additions & 0 deletions src/new/musl/arch/mips/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//! Source directory: `arch/mips/`
//!
//! <https://github.com/kraj/musl/tree/master/arch/mips>

pub(crate) mod bits {
pub(crate) mod socket;
}
4 changes: 4 additions & 0 deletions src/new/musl/arch/mips64/bits/socket.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
use crate::prelude::*;

pub const SOCK_STREAM: c_int = 2;
pub const SOCK_DGRAM: c_int = 1;
7 changes: 7 additions & 0 deletions src/new/musl/arch/mips64/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//! Source directory: `arch/mips64/`
//!
//! <https://github.com/kraj/musl/tree/master/arch/mips64>

pub(crate) mod bits {
pub(crate) mod socket;
}
10 changes: 10 additions & 0 deletions src/new/musl/arch/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//! Source directory: `arch/`
//!
//! <https://github.com/kraj/musl/tree/master/arch>

pub(crate) mod generic;

#[cfg(target_arch = "mips")]
pub(crate) mod mips;
#[cfg(target_arch = "mips64")]
pub(crate) mod mips64;
24 changes: 24 additions & 0 deletions src/new/musl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,28 @@
//! * Headers: <https://git.musl-libc.org/cgit/musl> (official)
//! * Headers: <https://github.com/kraj/musl> (mirror)

// The musl build system includes `arch/$(ARCH)` (preferred if it exists) and `arch/generic` (used
// as the fallback). We can't exactly mirror this with glob exports, so instead we selectively
// reexport in a new module.
mod arch;
Copy link
Contributor

@neuschaefer neuschaefer Aug 14, 2025

Choose a reason for hiding this comment

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

This could use a comment that mentions:

  • this is musl-libc
  • how it relates to the musl-libc source tree

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It has some much more detailed comments now


pub(crate) mod bits {
cfg_if! {
if #[cfg(target_arch = "mips")] {
pub(crate) use super::arch::mips::bits::socket;
} else if #[cfg(target_arch = "mips64")] {
pub(crate) use super::arch::mips64::bits::socket;
} else {
// Reexports from generic will live here once we need them.
}
}
}

/// Directory: `sys/`
///
/// <https://github.com/kraj/musl/tree/kraj/master/include/sys>
pub(crate) mod sys {
pub(crate) mod socket;
}

pub(crate) mod unistd;
63 changes: 63 additions & 0 deletions src/new/musl/sys/socket.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
//! Header: `sys/socket.h`
//!
//! <https://github.com/kraj/musl/blob/kraj/master/include/sys/socket.h>

use crate::prelude::*;

s! {
pub struct msghdr {
pub msg_name: *mut c_void,
pub msg_namelen: crate::socklen_t,
pub msg_iov: *mut crate::iovec,
#[cfg(all(target_pointer_width = "64", target_endian = "big"))]
__pad1: c_int,
pub msg_iovlen: c_int,
#[cfg(all(target_pointer_width = "64", target_endian = "little"))]
__pad1: c_int,
pub msg_control: *mut c_void,
#[cfg(all(target_pointer_width = "64", target_endian = "big"))]
__pad2: c_int,
pub msg_controllen: crate::socklen_t,
#[cfg(all(target_pointer_width = "64", target_endian = "little"))]
__pad2: c_int,
pub msg_flags: c_int,
}

pub struct cmsghdr {
#[cfg(all(target_pointer_width = "64", target_endian = "big"))]
pub __pad1: c_int,
pub cmsg_len: crate::socklen_t,
#[cfg(all(target_pointer_width = "64", target_endian = "little"))]
pub __pad1: c_int,
pub cmsg_level: c_int,
pub cmsg_type: c_int,
}
}

extern "C" {
pub fn sendmmsg(
sockfd: c_int,
msgvec: *mut crate::mmsghdr,
vlen: c_uint,
flags: c_uint,
) -> c_int;
pub fn recvmmsg(
sockfd: c_int,
msgvec: *mut crate::mmsghdr,
vlen: c_uint,
flags: c_uint,
timeout: *mut crate::timespec,
) -> c_int;
}

cfg_if! {
if #[cfg(any(target_arch = "mips", target_arch = "mips64"))] {
pub use crate::bits::socket::{
SOCK_DGRAM,
SOCK_STREAM,
};
} else {
pub const SOCK_STREAM: c_int = 1;
pub const SOCK_DGRAM: c_int = 2;
}
}
14 changes: 9 additions & 5 deletions src/unix/linux_like/linux/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5710,16 +5710,20 @@ f! {
return ((len) + NLA_ALIGNTO - 1) & !(NLA_ALIGNTO - 1);
}

pub fn CMSG_NXTHDR(mhdr: *const msghdr, cmsg: *const cmsghdr) -> *mut cmsghdr {
if ((*cmsg).cmsg_len as usize) < size_of::<cmsghdr>() {
return core::ptr::null_mut::<cmsghdr>();
pub fn CMSG_NXTHDR(
mhdr: *const crate::msghdr,
cmsg: *const crate::cmsghdr,
) -> *mut crate::cmsghdr {
if ((*cmsg).cmsg_len as usize) < size_of::<crate::cmsghdr>() {
return core::ptr::null_mut::<crate::cmsghdr>();
}
let next = (cmsg as usize + super::CMSG_ALIGN((*cmsg).cmsg_len as usize)) as *mut cmsghdr;
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::<cmsghdr>()
core::ptr::null_mut::<crate::cmsghdr>()
} else {
next
}
Expand Down
3 changes: 0 additions & 3 deletions src/unix/linux_like/linux/musl/b32/arm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,9 +272,6 @@ pub const MAP_NONBLOCK: c_int = 0x010000;
pub const MAP_STACK: c_int = 0x020000;
pub const MAP_SYNC: c_int = 0x080000;

pub const SOCK_STREAM: c_int = 1;
pub const SOCK_DGRAM: c_int = 2;

pub const EDEADLK: c_int = 35;
pub const ENAMETOOLONG: c_int = 36;
pub const ENOLCK: c_int = 37;
Expand Down
2 changes: 0 additions & 2 deletions src/unix/linux_like/linux/musl/b32/hexagon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,6 @@ pub const SIGXFSZ: c_int = 25;
pub const SIG_SETMASK: c_int = 2; // FIXME(musl) check these
pub const SIG_BLOCK: c_int = 0x000000;
pub const SIG_UNBLOCK: c_int = 0x01;
pub const SOCK_DGRAM: c_int = 2;
pub const SOCK_STREAM: c_int = 1;
pub const SOL_CAIF: c_int = 278;
pub const SOL_IUCV: c_int = 277;
pub const SOL_KCM: c_int = 281;
Expand Down
3 changes: 0 additions & 3 deletions src/unix/linux_like/linux/musl/b32/mips/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,9 +338,6 @@ pub const ENOTRECOVERABLE: c_int = 166;
pub const EHWPOISON: c_int = 168;
pub const ERFKILL: c_int = 167;

pub const SOCK_STREAM: c_int = 2;
pub const SOCK_DGRAM: c_int = 1;

pub const SA_ONSTACK: c_int = 0x08000000;
pub const SA_SIGINFO: c_int = 8;
pub const SA_NOCLDWAIT: c_int = 0x10000;
Expand Down
16 changes: 0 additions & 16 deletions src/unix/linux_like/linux/musl/b32/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,6 @@ s! {
__val: [c_ulong; 32],
}

pub struct msghdr {
pub msg_name: *mut c_void,
pub msg_namelen: crate::socklen_t,
pub msg_iov: *mut crate::iovec,
pub msg_iovlen: c_int,
pub msg_control: *mut c_void,
pub msg_controllen: crate::socklen_t,
pub msg_flags: c_int,
}

pub struct cmsghdr {
pub cmsg_len: crate::socklen_t,
pub cmsg_level: c_int,
pub cmsg_type: c_int,
}

pub struct sem_t {
__val: [c_int; 4],
}
Expand Down
3 changes: 0 additions & 3 deletions src/unix/linux_like/linux/musl/b32/powerpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,6 @@ pub const MAP_SYNC: c_int = 0x080000;
pub const PTRACE_SYSEMU: c_int = 0x1d;
pub const PTRACE_SYSEMU_SINGLESTEP: c_int = 0x1e;

pub const SOCK_STREAM: c_int = 1;
pub const SOCK_DGRAM: c_int = 2;

pub const EDEADLK: c_int = 35;
pub const ENAMETOOLONG: c_int = 36;
pub const ENOLCK: c_int = 37;
Expand Down
2 changes: 0 additions & 2 deletions src/unix/linux_like/linux/musl/b32/riscv32/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,6 @@ pub const ENOTRECOVERABLE: c_int = 131;
pub const EHWPOISON: c_int = 133;
pub const ERFKILL: c_int = 132;

pub const SOCK_STREAM: c_int = 1;
pub const SOCK_DGRAM: c_int = 2;
pub const SA_ONSTACK: c_int = 0x08000000;
pub const SA_SIGINFO: c_int = 4;
pub const SA_NOCLDWAIT: c_int = 2;
Expand Down
3 changes: 0 additions & 3 deletions src/unix/linux_like/linux/musl/b32/x86/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,9 +314,6 @@ pub const MAP_NONBLOCK: c_int = 0x010000;
pub const MAP_STACK: c_int = 0x020000;
pub const MAP_SYNC: c_int = 0x080000;

pub const SOCK_STREAM: c_int = 1;
pub const SOCK_DGRAM: c_int = 2;

pub const EDEADLK: c_int = 35;
pub const ENAMETOOLONG: c_int = 36;
pub const ENOLCK: c_int = 37;
Expand Down
3 changes: 0 additions & 3 deletions src/unix/linux_like/linux/musl/b64/aarch64/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,9 +279,6 @@ pub const MAP_STACK: c_int = 0x020000;
pub const MAP_HUGETLB: c_int = 0x040000;
pub const MAP_SYNC: c_int = 0x080000;

pub const SOCK_STREAM: c_int = 1;
pub const SOCK_DGRAM: c_int = 2;

pub const SA_ONSTACK: c_int = 0x08000000;
pub const SA_SIGINFO: c_int = 0x00000004;
pub const SA_NOCLDWAIT: c_int = 0x00000002;
Expand Down
3 changes: 0 additions & 3 deletions src/unix/linux_like/linux/musl/b64/loongarch64/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -573,9 +573,6 @@ pub const VEOF: usize = 4;
pub const POLLWRNORM: c_short = 0x100;
pub const POLLWRBAND: c_short = 0x200;

pub const SOCK_STREAM: c_int = 1;
pub const SOCK_DGRAM: c_int = 2;

pub const MAP_ANON: c_int = 0x0020;
pub const MAP_GROWSDOWN: c_int = 0x0100;
pub const MAP_DENYWRITE: c_int = 0x0800;
Expand Down
3 changes: 0 additions & 3 deletions src/unix/linux_like/linux/musl/b64/mips64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -584,9 +584,6 @@ pub const MAP_NONBLOCK: c_int = 0x20000;
pub const MAP_STACK: c_int = 0x40000;
pub const MAP_HUGETLB: c_int = 0x080000;

pub const SOCK_STREAM: c_int = 2;
pub const SOCK_DGRAM: c_int = 1;

pub const SA_ONSTACK: c_int = 0x08000000;
pub const SA_SIGINFO: c_int = 0x00000008;
pub const SA_NOCLDWAIT: c_int = 0x00010000;
Expand Down
28 changes: 0 additions & 28 deletions src/unix/linux_like/linux/musl/b64/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,34 +48,6 @@ s! {
__pad2: c_ulong,
}

pub struct msghdr {
pub msg_name: *mut c_void,
pub msg_namelen: crate::socklen_t,
pub msg_iov: *mut crate::iovec,
#[cfg(target_endian = "big")]
__pad1: c_int,
pub msg_iovlen: c_int,
#[cfg(target_endian = "little")]
__pad1: c_int,
pub msg_control: *mut c_void,
#[cfg(target_endian = "big")]
__pad2: c_int,
pub msg_controllen: crate::socklen_t,
#[cfg(target_endian = "little")]
__pad2: c_int,
pub msg_flags: c_int,
}

pub struct cmsghdr {
#[cfg(target_endian = "big")]
pub __pad1: c_int,
pub cmsg_len: crate::socklen_t,
#[cfg(target_endian = "little")]
pub __pad1: c_int,
pub cmsg_level: c_int,
pub cmsg_type: c_int,
}

pub struct sem_t {
__val: [c_int; 8],
}
Expand Down
3 changes: 0 additions & 3 deletions src/unix/linux_like/linux/musl/b64/powerpc64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,6 @@ pub const MAP_SYNC: c_int = 0x080000;
pub const PTRACE_SYSEMU: c_int = 0x1d;
pub const PTRACE_SYSEMU_SINGLESTEP: c_int = 0x1e;

pub const SOCK_STREAM: c_int = 1;
pub const SOCK_DGRAM: c_int = 2;

pub const SA_ONSTACK: c_int = 0x08000000;
pub const SA_SIGINFO: c_int = 0x00000004;
pub const SA_NOCLDWAIT: c_int = 0x00000002;
Expand Down
3 changes: 0 additions & 3 deletions src/unix/linux_like/linux/musl/b64/riscv64/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -567,9 +567,6 @@ pub const VEOF: usize = 4;
pub const POLLWRNORM: c_short = 0x100;
pub const POLLWRBAND: c_short = 0x200;

pub const SOCK_STREAM: c_int = 1;
pub const SOCK_DGRAM: c_int = 2;

pub const MADV_SOFT_OFFLINE: c_int = 101;
pub const MAP_ANON: c_int = 0x0020;
pub const MAP_GROWSDOWN: c_int = 0x0100;
Expand Down
3 changes: 0 additions & 3 deletions src/unix/linux_like/linux/musl/b64/s390x.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,6 @@ pub const SIGSTKSZ: size_t = 0x2000;
pub const MINSIGSTKSZ: size_t = 2048;
pub const SIG_SETMASK: c_int = 2;

pub const SOCK_STREAM: c_int = 1;
pub const SOCK_DGRAM: c_int = 2;

pub const O_NOCTTY: c_int = 256;
pub const O_SYNC: c_int = 1052672;
pub const O_RSYNC: c_int = 1052672;
Expand Down
3 changes: 0 additions & 3 deletions src/unix/linux_like/linux/musl/b64/wasm32/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -584,9 +584,6 @@ pub const VEOF: usize = 4;
pub const POLLWRNORM: c_short = 0x100;
pub const POLLWRBAND: c_short = 0x200;

pub const SOCK_STREAM: c_int = 1;
pub const SOCK_DGRAM: c_int = 2;

pub const MAP_ANON: c_int = 0x0020;
pub const MAP_GROWSDOWN: c_int = 0x0100;
pub const MAP_DENYWRITE: c_int = 0x0800;
Expand Down
3 changes: 0 additions & 3 deletions src/unix/linux_like/linux/musl/b64/x86_64/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -818,9 +818,6 @@ pub const VEOF: usize = 4;
pub const POLLWRNORM: c_short = 0x100;
pub const POLLWRBAND: c_short = 0x200;

pub const SOCK_STREAM: c_int = 1;
pub const SOCK_DGRAM: c_int = 2;

pub const MAP_ANON: c_int = 0x0020;
pub const MAP_GROWSDOWN: c_int = 0x0100;
pub const MAP_DENYWRITE: c_int = 0x0800;
Expand Down
Loading