Skip to content

Commit 471935d

Browse files
authored
Eliminate more linux_raw_sys types in the public API (#1347)
1 parent 28036de commit 471935d

4 files changed

Lines changed: 36 additions & 13 deletions

File tree

src/check_types.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@ macro_rules! check_struct {
100100
let _test = $name {
101101
$($field: panic!()),*
102102
};
103+
#[allow(unreachable_code)]
104+
let _test = c::$name {
105+
$($field: panic!()),*
106+
};
103107
}
104108

105109
// Check that the fields have the right sizes and offsets.

src/io_uring/mod.rs

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ pub use crate::fs::{
4747
Advice, AtFlags, Mode, OFlags, RenameFlags, ResolveFlags, Statx, StatxFlags, XattrFlags,
4848
};
4949
pub use crate::io::ReadWriteFlags;
50+
pub use crate::net::addr::{SocketAddrLen, SocketAddrOpaque, SocketAddrStorage};
5051
pub use crate::net::{RecvFlags, SendFlags, SocketFlags};
5152
pub use crate::sigset::SigSet;
5253
pub use crate::thread::futex::{
@@ -55,12 +56,25 @@ pub use crate::thread::futex::{
5556
};
5657
pub use crate::timespec::{Nsecs, Secs, Timespec};
5758

58-
pub use net::{__kernel_sockaddr_storage as sockaddr_storage, msghdr, sockaddr, socklen_t};
59-
6059
mod sys {
6160
pub(super) use linux_raw_sys::io_uring::*;
6261
#[cfg(test)]
63-
pub(super) use {crate::backend::c::iovec, linux_raw_sys::general::open_how};
62+
pub(super) use {
63+
crate::backend::c::iovec, linux_raw_sys::general::open_how, linux_raw_sys::net::msghdr,
64+
};
65+
}
66+
67+
/// `msghdr`
68+
#[allow(missing_docs)]
69+
#[repr(C)]
70+
pub struct MsgHdr {
71+
pub msg_name: *mut c_void,
72+
pub msg_namelen: SocketAddrLen,
73+
pub msg_iov: *mut iovec,
74+
pub msg_iovlen: usize,
75+
pub msg_control: *mut c_void,
76+
pub msg_controllen: usize,
77+
pub msg_flags: RecvFlags,
6478
}
6579

6680
/// `io_uring_setup(entries, params)`—Setup a context for performing
@@ -1567,7 +1581,7 @@ pub struct io_uring_getevents_arg {
15671581
#[repr(C)]
15681582
#[derive(Debug, Default, Copy, Clone)]
15691583
pub struct io_uring_recvmsg_out {
1570-
pub namelen: u32,
1584+
pub namelen: SocketAddrLen,
15711585
pub controllen: u32,
15721586
pub payloadlen: u32,
15731587
pub flags: RecvmsgOutFlags,
@@ -1885,5 +1899,17 @@ mod tests {
18851899
io_uring_buf_ring__bindgen_ty_1__bindgen_ty_2
18861900
);
18871901
check_struct_renamed_field!(io_uring_buf_ring, tail_or_bufs, __bindgen_anon_1);
1902+
1903+
check_renamed_struct!(
1904+
MsgHdr,
1905+
msghdr,
1906+
msg_name,
1907+
msg_namelen,
1908+
msg_iov,
1909+
msg_iovlen,
1910+
msg_control,
1911+
msg_controllen,
1912+
msg_flags
1913+
);
18881914
}
18891915
}

src/termios/types.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1391,11 +1391,7 @@ fn termios_layouts() {
13911391
assert_eq_size!(u8, libc::cc_t);
13921392
assert_eq_size!(types::tcflag_t, libc::tcflag_t);
13931393

1394-
check_renamed_type!(Winsize, winsize);
1395-
check_renamed_struct_field!(Winsize, winsize, ws_row);
1396-
check_renamed_struct_field!(Winsize, winsize, ws_col);
1397-
check_renamed_struct_field!(Winsize, winsize, ws_xpixel);
1398-
check_renamed_struct_field!(Winsize, winsize, ws_ypixel);
1394+
check_renamed_struct!(Winsize, winsize, ws_row, ws_col, ws_xpixel, ws_ypixel);
13991395

14001396
// On platforms with a termios/termios2 split, check `termios`.
14011397
#[cfg(linux_raw)]

src/thread/futex.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -621,9 +621,6 @@ mod tests {
621621
fn test_layouts() {
622622
use crate::backend::c;
623623

624-
check_renamed_type!(Wait, futex_waitv);
625-
check_renamed_struct_field!(Wait, futex_waitv, val);
626-
check_renamed_struct_field!(Wait, futex_waitv, uaddr);
627-
check_renamed_struct_field!(Wait, futex_waitv, flags);
624+
check_renamed_struct!(Wait, futex_waitv, val, uaddr, flags, __reserved);
628625
}
629626
}

0 commit comments

Comments
 (0)