Skip to content

Commit 564e0ef

Browse files
committed
musl: Switch to the new structure for socket.h
Move `struct msghdr`, `struct cmsghdr`, `sendmmsg`, and `recvmmsg` over at this time, as well as two `SOCK_*` constants that were in the musl module. Link: https://github.com/kraj/musl/blob/9f204467e88c75e36105d1359951c5857c20fe0b/include/sys/socket.h
1 parent b30e714 commit 564e0ef

File tree

27 files changed

+144
-104
lines changed

27 files changed

+144
-104
lines changed

src/new/mod.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ cfg_if! {
150150
mod glibc;
151151
pub(crate) use glibc::*;
152152
} else if #[cfg(any(target_env = "musl", target_env = "ohos"))] {
153+
// OhOS also uses the musl libc
153154
mod musl;
154155
pub(crate) use musl::*;
155156
} else if #[cfg(target_env = "newlib")] {
@@ -167,7 +168,7 @@ cfg_if! {
167168
}
168169
}
169170

170-
// Headers we export
171+
// Per-OS headers we export
171172
cfg_if! {
172173
if #[cfg(target_os = "android")] {
173174
pub use sys::socket::*;
@@ -184,5 +185,12 @@ cfg_if! {
184185
}
185186
}
186187

188+
// Per-env headers we export
189+
cfg_if! {
190+
if #[cfg(any(target_env = "musl", target_env = "ohos"))] {
191+
pub use sys::socket::*;
192+
}
193+
}
194+
187195
#[cfg(target_family = "unix")]
188196
pub use unistd::*;

src/new/musl/arch/generic/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
//! Source directory: `arch/generic/`
2+
//!
3+
//! <https://github.com/kraj/musl/tree/master/arch/generic>
4+
5+
pub(crate) mod bits {
6+
// Currently unused
7+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
use crate::prelude::*;
2+
3+
pub const SOCK_STREAM: c_int = 2;
4+
pub const SOCK_DGRAM: c_int = 1;

src/new/musl/arch/mips/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
//! Source directory: `arch/mips/`
2+
//!
3+
//! <https://github.com/kraj/musl/tree/master/arch/mips>
4+
5+
pub(crate) mod bits {
6+
pub(crate) mod socket;
7+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
use crate::prelude::*;
2+
3+
pub const SOCK_STREAM: c_int = 2;
4+
pub const SOCK_DGRAM: c_int = 1;

src/new/musl/arch/mips64/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
//! Source directory: `arch/mips64/`
2+
//!
3+
//! <https://github.com/kraj/musl/tree/master/arch/mips64>
4+
5+
pub(crate) mod bits {
6+
pub(crate) mod socket;
7+
}

src/new/musl/arch/mod.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
//! Source directory: `arch/`
2+
//!
3+
//! <https://github.com/kraj/musl/tree/master/arch>
4+
5+
pub(crate) mod generic;
6+
7+
#[cfg(target_arch = "mips")]
8+
pub(crate) mod mips;
9+
#[cfg(target_arch = "mips64")]
10+
pub(crate) mod mips64;

src/new/musl/mod.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,28 @@
33
//! * Headers: <https://git.musl-libc.org/cgit/musl> (official)
44
//! * Headers: <https://github.com/kraj/musl> (mirror)
55
6+
// The musl build system includes `arch/$(ARCH)` (preferred if it exists) and `arch/generic` (used
7+
// as the fallback). We can't exactly mirror this with glob exports, so instead we selectively
8+
// reexport in a new module.
9+
mod arch;
10+
11+
pub(crate) mod bits {
12+
cfg_if! {
13+
if #[cfg(target_arch = "mips")] {
14+
pub(crate) use super::arch::mips::bits::socket;
15+
} else if #[cfg(target_arch = "mips64")] {
16+
pub(crate) use super::arch::mips64::bits::socket;
17+
} else {
18+
// Reexports from generic will live here once we need them.
19+
}
20+
}
21+
}
22+
23+
/// Directory: `sys/`
24+
///
25+
/// <https://github.com/kraj/musl/tree/kraj/master/include/sys>
26+
pub(crate) mod sys {
27+
pub(crate) mod socket;
28+
}
29+
630
pub(crate) mod unistd;

src/new/musl/sys/socket.rs

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
//! Header: `sys/socket.h`
2+
//!
3+
//! <https://github.com/kraj/musl/blob/kraj/master/include/sys/socket.h>
4+
5+
use crate::prelude::*;
6+
7+
s! {
8+
pub struct msghdr {
9+
pub msg_name: *mut c_void,
10+
pub msg_namelen: crate::socklen_t,
11+
pub msg_iov: *mut crate::iovec,
12+
#[cfg(all(target_pointer_width = "64", target_endian = "big"))]
13+
__pad1: c_int,
14+
pub msg_iovlen: c_int,
15+
#[cfg(all(target_pointer_width = "64", target_endian = "little"))]
16+
__pad1: c_int,
17+
pub msg_control: *mut c_void,
18+
#[cfg(all(target_pointer_width = "64", target_endian = "big"))]
19+
__pad2: c_int,
20+
pub msg_controllen: crate::socklen_t,
21+
#[cfg(all(target_pointer_width = "64", target_endian = "little"))]
22+
__pad2: c_int,
23+
pub msg_flags: c_int,
24+
}
25+
26+
pub struct cmsghdr {
27+
#[cfg(all(target_pointer_width = "64", target_endian = "big"))]
28+
pub __pad1: c_int,
29+
pub cmsg_len: crate::socklen_t,
30+
#[cfg(all(target_pointer_width = "64", target_endian = "little"))]
31+
pub __pad1: c_int,
32+
pub cmsg_level: c_int,
33+
pub cmsg_type: c_int,
34+
}
35+
}
36+
37+
extern "C" {
38+
pub fn sendmmsg(
39+
sockfd: c_int,
40+
msgvec: *mut crate::mmsghdr,
41+
vlen: c_uint,
42+
flags: c_uint,
43+
) -> c_int;
44+
pub fn recvmmsg(
45+
sockfd: c_int,
46+
msgvec: *mut crate::mmsghdr,
47+
vlen: c_uint,
48+
flags: c_uint,
49+
timeout: *mut crate::timespec,
50+
) -> c_int;
51+
}
52+
53+
cfg_if! {
54+
if #[cfg(any(target_arch = "mips", target_arch = "mips64"))] {
55+
pub use crate::bits::socket::{
56+
SOCK_DGRAM,
57+
SOCK_STREAM,
58+
};
59+
} else {
60+
pub const SOCK_STREAM: c_int = 1;
61+
pub const SOCK_DGRAM: c_int = 2;
62+
}
63+
}

src/unix/linux_like/linux/mod.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5710,16 +5710,20 @@ f! {
57105710
return ((len) + NLA_ALIGNTO - 1) & !(NLA_ALIGNTO - 1);
57115711
}
57125712

5713-
pub fn CMSG_NXTHDR(mhdr: *const msghdr, cmsg: *const cmsghdr) -> *mut cmsghdr {
5714-
if ((*cmsg).cmsg_len as usize) < size_of::<cmsghdr>() {
5715-
return core::ptr::null_mut::<cmsghdr>();
5713+
pub fn CMSG_NXTHDR(
5714+
mhdr: *const crate::msghdr,
5715+
cmsg: *const crate::cmsghdr,
5716+
) -> *mut crate::cmsghdr {
5717+
if ((*cmsg).cmsg_len as usize) < size_of::<crate::cmsghdr>() {
5718+
return core::ptr::null_mut::<crate::cmsghdr>();
57165719
}
5717-
let next = (cmsg as usize + super::CMSG_ALIGN((*cmsg).cmsg_len as usize)) as *mut cmsghdr;
5720+
let next =
5721+
(cmsg as usize + super::CMSG_ALIGN((*cmsg).cmsg_len as usize)) as *mut crate::cmsghdr;
57185722
let max = (*mhdr).msg_control as usize + (*mhdr).msg_controllen as usize;
57195723
if (next.wrapping_offset(1)) as usize > max
57205724
|| next as usize + super::CMSG_ALIGN((*next).cmsg_len as usize) > max
57215725
{
5722-
core::ptr::null_mut::<cmsghdr>()
5726+
core::ptr::null_mut::<crate::cmsghdr>()
57235727
} else {
57245728
next
57255729
}

0 commit comments

Comments
 (0)