Skip to content

Source reorganization of Android socket.h #4541

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 8, 2025
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
2 changes: 2 additions & 0 deletions src/new/bionic/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
mod sys;
pub use sys::*;
2 changes: 2 additions & 0 deletions src/new/bionic/sys/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
mod socket;
pub use socket::*;
51 changes: 51 additions & 0 deletions src/new/bionic/sys/socket.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
//! Header: `bionic/libc/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,
pub msg_iovlen: size_t,
pub msg_control: *mut c_void,
pub msg_controllen: size_t,
pub msg_flags: c_int,
}

pub struct cmsghdr {
pub cmsg_len: size_t,
pub cmsg_level: c_int,
pub cmsg_type: c_int,
}

pub struct ucred {
pub pid: crate::pid_t,
pub uid: crate::uid_t,
pub gid: crate::gid_t,
}
}

extern "C" {
pub fn recvmmsg(
sockfd: c_int,
msgvec: *mut crate::mmsghdr,
vlen: c_uint,
flags: c_int,
timeout: *const crate::timespec,
) -> c_int;
pub fn sendmmsg(
sockfd: c_int,
msgvec: *const crate::mmsghdr,
vlen: c_uint,
flags: c_int,
) -> c_int;
pub fn recvfrom(
socket: c_int,
buf: *mut c_void,
len: size_t,
flags: c_int,
addr: *mut crate::sockaddr,
addrlen: *mut crate::socklen_t,
) -> ssize_t;
}
3 changes: 3 additions & 0 deletions src/new/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,8 @@ cfg_if! {
if #[cfg(target_os = "linux")] {
mod linux_uapi;
pub use linux_uapi::*;
} else if #[cfg(target_os = "android")] {
mod bionic;
pub use bionic::*;
}
}
44 changes: 1 addition & 43 deletions src/unix/linux_like/android/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! Android-specific definitions for linux-like values

use crate::prelude::*;
use crate::{cmsghdr, msghdr};

cfg_if! {
if #[cfg(doc)] {
Expand Down Expand Up @@ -74,22 +75,6 @@ s! {
__val: [c_int; 2],
}

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

pub struct cmsghdr {
pub cmsg_len: size_t,
pub cmsg_level: c_int,
pub cmsg_type: c_int,
}

pub struct termios {
pub c_iflag: crate::tcflag_t,
pub c_oflag: crate::tcflag_t,
Expand Down Expand Up @@ -203,12 +188,6 @@ s! {
pub it_value: crate::timespec,
}

pub struct ucred {
pub pid: crate::pid_t,
pub uid: crate::uid_t,
pub gid: crate::gid_t,
}

pub struct genlmsghdr {
pub cmd: u8,
pub version: u8,
Expand Down Expand Up @@ -3467,14 +3446,6 @@ extern "C" {
pub fn madvise(addr: *mut c_void, len: size_t, advice: c_int) -> c_int;
pub fn msync(addr: *mut c_void, len: size_t, flags: c_int) -> c_int;
pub fn mprotect(addr: *mut c_void, len: size_t, prot: c_int) -> c_int;
pub fn recvfrom(
socket: c_int,
buf: *mut c_void,
len: size_t,
flags: c_int,
addr: *mut crate::sockaddr,
addrlen: *mut crate::socklen_t,
) -> ssize_t;
pub fn getnameinfo(
sa: *const crate::sockaddr,
salen: crate::socklen_t,
Expand Down Expand Up @@ -3787,19 +3758,6 @@ extern "C" {
) -> c_int;
pub fn __errno() -> *mut c_int;
pub fn inotify_rm_watch(fd: c_int, wd: u32) -> c_int;
pub fn sendmmsg(
sockfd: c_int,
msgvec: *const crate::mmsghdr,
vlen: c_uint,
flags: c_int,
) -> c_int;
pub fn recvmmsg(
sockfd: c_int,
msgvec: *mut crate::mmsghdr,
vlen: c_uint,
flags: c_int,
timeout: *const crate::timespec,
) -> c_int;
pub fn inotify_init() -> c_int;
pub fn inotify_init1(flags: c_int) -> c_int;
pub fn inotify_add_watch(fd: c_int, path: *const c_char, mask: u32) -> c_int;
Expand Down
14 changes: 7 additions & 7 deletions src/unix/linux_like/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1791,24 +1791,24 @@ const_fn! {
}

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

pub fn CMSG_DATA(cmsg: *const cmsghdr) -> *mut c_uchar {
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::<cmsghdr>())) as c_uint
(CMSG_ALIGN(length as usize) + CMSG_ALIGN(size_of::<crate::cmsghdr>())) as c_uint
}

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

pub fn FD_CLR(fd: c_int, set: *mut fd_set) -> () {
Expand Down
Loading