Skip to content

Commit 7f91807

Browse files
authored
Merge pull request #4541 from tgross35/libc-reorg-android
Source reorganization of Android `socket.h`
2 parents 475e60f + bce7db1 commit 7f91807

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,
@@ -3467,14 +3446,6 @@ extern "C" {
34673446
pub fn madvise(addr: *mut c_void, len: size_t, advice: c_int) -> c_int;
34683447
pub fn msync(addr: *mut c_void, len: size_t, flags: c_int) -> c_int;
34693448
pub fn mprotect(addr: *mut c_void, len: size_t, prot: c_int) -> c_int;
3470-
pub fn recvfrom(
3471-
socket: c_int,
3472-
buf: *mut c_void,
3473-
len: size_t,
3474-
flags: c_int,
3475-
addr: *mut crate::sockaddr,
3476-
addrlen: *mut crate::socklen_t,
3477-
) -> ssize_t;
34783449
pub fn getnameinfo(
34793450
sa: *const crate::sockaddr,
34803451
salen: crate::socklen_t,
@@ -3787,19 +3758,6 @@ extern "C" {
37873758
) -> c_int;
37883759
pub fn __errno() -> *mut c_int;
37893760
pub fn inotify_rm_watch(fd: c_int, wd: u32) -> c_int;
3790-
pub fn sendmmsg(
3791-
sockfd: c_int,
3792-
msgvec: *const crate::mmsghdr,
3793-
vlen: c_uint,
3794-
flags: c_int,
3795-
) -> c_int;
3796-
pub fn recvmmsg(
3797-
sockfd: c_int,
3798-
msgvec: *mut crate::mmsghdr,
3799-
vlen: c_uint,
3800-
flags: c_int,
3801-
timeout: *const crate::timespec,
3802-
) -> c_int;
38033761
pub fn inotify_init() -> c_int;
38043762
pub fn inotify_init1(flags: c_int) -> c_int;
38053763
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
@@ -1791,24 +1791,24 @@ const_fn! {
17911791
}
17921792

17931793
f! {
1794-
pub fn CMSG_FIRSTHDR(mhdr: *const msghdr) -> *mut cmsghdr {
1795-
if (*mhdr).msg_controllen as usize >= size_of::<cmsghdr>() {
1796-
(*mhdr).msg_control.cast::<cmsghdr>()
1794+
pub fn CMSG_FIRSTHDR(mhdr: *const crate::msghdr) -> *mut crate::cmsghdr {
1795+
if (*mhdr).msg_controllen as usize >= size_of::<crate::cmsghdr>() {
1796+
(*mhdr).msg_control.cast::<crate::cmsghdr>()
17971797
} else {
1798-
core::ptr::null_mut::<cmsghdr>()
1798+
core::ptr::null_mut::<crate::cmsghdr>()
17991799
}
18001800
}
18011801

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

18061806
pub {const} fn CMSG_SPACE(length: c_uint) -> c_uint {
1807-
(CMSG_ALIGN(length as usize) + CMSG_ALIGN(size_of::<cmsghdr>())) as c_uint
1807+
(CMSG_ALIGN(length as usize) + CMSG_ALIGN(size_of::<crate::cmsghdr>())) as c_uint
18081808
}
18091809

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

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

0 commit comments

Comments
 (0)