Skip to content

Commit b228704

Browse files
committed
Source reorganization of Android socket.h
Create a bionic module and move some things over from `linux_like`. Source: https://cs.android.com/android/platform/superproject/main/+/main:bionic/libc/include/sys/socket.h;drc=dc6e2fb4857f05bfee435cfd4f3859e74c746811 (backport <#4541>) (cherry picked from commit bce7db1)
1 parent 5a7955e commit b228704

File tree

6 files changed

+66
-50
lines changed

6 files changed

+66
-50
lines changed

src/new/bionic/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
mod sys;
2+
pub use sys::*;

src/new/bionic/sys/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
mod socket;
2+
pub use socket::*;

src/new/bionic/sys/socket.rs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
//! Header: `bionic/libc/include/sys/socket.h`
2+
3+
use crate::prelude::*;
4+
5+
s! {
6+
pub struct msghdr {
7+
pub msg_name: *mut c_void,
8+
pub msg_namelen: crate::socklen_t,
9+
pub msg_iov: *mut crate::iovec,
10+
pub msg_iovlen: size_t,
11+
pub msg_control: *mut c_void,
12+
pub msg_controllen: size_t,
13+
pub msg_flags: c_int,
14+
}
15+
16+
pub struct cmsghdr {
17+
pub cmsg_len: size_t,
18+
pub cmsg_level: c_int,
19+
pub cmsg_type: c_int,
20+
}
21+
22+
pub struct ucred {
23+
pub pid: crate::pid_t,
24+
pub uid: crate::uid_t,
25+
pub gid: crate::gid_t,
26+
}
27+
}
28+
29+
extern "C" {
30+
pub fn recvmmsg(
31+
sockfd: c_int,
32+
msgvec: *mut crate::mmsghdr,
33+
vlen: c_uint,
34+
flags: c_int,
35+
timeout: *const crate::timespec,
36+
) -> c_int;
37+
pub fn sendmmsg(
38+
sockfd: c_int,
39+
msgvec: *const crate::mmsghdr,
40+
vlen: c_uint,
41+
flags: c_int,
42+
) -> c_int;
43+
pub fn recvfrom(
44+
socket: c_int,
45+
buf: *mut c_void,
46+
len: size_t,
47+
flags: c_int,
48+
addr: *mut crate::sockaddr,
49+
addrlen: *mut crate::socklen_t,
50+
) -> ssize_t;
51+
}

src/new/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,8 @@ cfg_if! {
88
if #[cfg(target_os = "linux")] {
99
mod linux_uapi;
1010
pub use linux_uapi::*;
11+
} else if #[cfg(target_os = "android")] {
12+
mod bionic;
13+
pub use bionic::*;
1114
}
1215
}

src/unix/linux_like/android/mod.rs

Lines changed: 1 addition & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! Android-specific definitions for linux-like values
22
33
use crate::prelude::*;
4+
use crate::{cmsghdr, msghdr};
45

56
cfg_if! {
67
if #[cfg(doc)] {
@@ -74,22 +75,6 @@ s! {
7475
__val: [c_int; 2],
7576
}
7677

77-
pub struct msghdr {
78-
pub msg_name: *mut c_void,
79-
pub msg_namelen: crate::socklen_t,
80-
pub msg_iov: *mut crate::iovec,
81-
pub msg_iovlen: size_t,
82-
pub msg_control: *mut c_void,
83-
pub msg_controllen: size_t,
84-
pub msg_flags: c_int,
85-
}
86-
87-
pub struct cmsghdr {
88-
pub cmsg_len: size_t,
89-
pub cmsg_level: c_int,
90-
pub cmsg_type: c_int,
91-
}
92-
9378
pub struct termios {
9479
pub c_iflag: crate::tcflag_t,
9580
pub c_oflag: crate::tcflag_t,
@@ -203,12 +188,6 @@ s! {
203188
pub it_value: crate::timespec,
204189
}
205190

206-
pub struct ucred {
207-
pub pid: crate::pid_t,
208-
pub uid: crate::uid_t,
209-
pub gid: crate::gid_t,
210-
}
211-
212191
pub struct genlmsghdr {
213192
pub cmd: u8,
214193
pub version: u8,
@@ -3501,14 +3480,6 @@ extern "C" {
35013480
pub fn madvise(addr: *mut c_void, len: size_t, advice: c_int) -> c_int;
35023481
pub fn msync(addr: *mut c_void, len: size_t, flags: c_int) -> c_int;
35033482
pub fn mprotect(addr: *mut c_void, len: size_t, prot: c_int) -> c_int;
3504-
pub fn recvfrom(
3505-
socket: c_int,
3506-
buf: *mut c_void,
3507-
len: size_t,
3508-
flags: c_int,
3509-
addr: *mut crate::sockaddr,
3510-
addrlen: *mut crate::socklen_t,
3511-
) -> ssize_t;
35123483
pub fn getnameinfo(
35133484
sa: *const crate::sockaddr,
35143485
salen: crate::socklen_t,
@@ -3821,19 +3792,6 @@ extern "C" {
38213792
) -> c_int;
38223793
pub fn __errno() -> *mut c_int;
38233794
pub fn inotify_rm_watch(fd: c_int, wd: u32) -> c_int;
3824-
pub fn sendmmsg(
3825-
sockfd: c_int,
3826-
msgvec: *const crate::mmsghdr,
3827-
vlen: c_uint,
3828-
flags: c_int,
3829-
) -> c_int;
3830-
pub fn recvmmsg(
3831-
sockfd: c_int,
3832-
msgvec: *mut crate::mmsghdr,
3833-
vlen: c_uint,
3834-
flags: c_int,
3835-
timeout: *const crate::timespec,
3836-
) -> c_int;
38373795
pub fn inotify_init() -> c_int;
38383796
pub fn inotify_init1(flags: c_int) -> c_int;
38393797
pub fn inotify_add_watch(fd: c_int, path: *const c_char, mask: u32) -> c_int;

src/unix/linux_like/mod.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1792,24 +1792,24 @@ const_fn! {
17921792
}
17931793

17941794
f! {
1795-
pub fn CMSG_FIRSTHDR(mhdr: *const msghdr) -> *mut cmsghdr {
1796-
if (*mhdr).msg_controllen as usize >= size_of::<cmsghdr>() {
1797-
(*mhdr).msg_control.cast::<cmsghdr>()
1795+
pub fn CMSG_FIRSTHDR(mhdr: *const crate::msghdr) -> *mut crate::cmsghdr {
1796+
if (*mhdr).msg_controllen as usize >= size_of::<crate::cmsghdr>() {
1797+
(*mhdr).msg_control.cast::<crate::cmsghdr>()
17981798
} else {
1799-
core::ptr::null_mut::<cmsghdr>()
1799+
core::ptr::null_mut::<crate::cmsghdr>()
18001800
}
18011801
}
18021802

1803-
pub fn CMSG_DATA(cmsg: *const cmsghdr) -> *mut c_uchar {
1803+
pub fn CMSG_DATA(cmsg: *const crate::cmsghdr) -> *mut c_uchar {
18041804
cmsg.offset(1) as *mut c_uchar
18051805
}
18061806

18071807
pub {const} fn CMSG_SPACE(length: c_uint) -> c_uint {
1808-
(CMSG_ALIGN(length as usize) + CMSG_ALIGN(size_of::<cmsghdr>())) as c_uint
1808+
(CMSG_ALIGN(length as usize) + CMSG_ALIGN(size_of::<crate::cmsghdr>())) as c_uint
18091809
}
18101810

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

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

0 commit comments

Comments
 (0)