Skip to content
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

Eliminate more linux_raw_sys types in the public API #1347

Merged
merged 1 commit into from
Feb 22, 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
4 changes: 4 additions & 0 deletions src/check_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ macro_rules! check_struct {
let _test = $name {
$($field: panic!()),*
};
#[allow(unreachable_code)]
let _test = c::$name {
$($field: panic!()),*
};
}

// Check that the fields have the right sizes and offsets.
Expand Down
34 changes: 30 additions & 4 deletions src/io_uring/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ pub use crate::fs::{
Advice, AtFlags, Mode, OFlags, RenameFlags, ResolveFlags, Statx, StatxFlags, XattrFlags,
};
pub use crate::io::ReadWriteFlags;
pub use crate::net::addr::{SocketAddrLen, SocketAddrOpaque, SocketAddrStorage};
pub use crate::net::{RecvFlags, SendFlags, SocketFlags};
pub use crate::sigset::SigSet;
pub use crate::thread::futex::{
Expand All @@ -55,12 +56,25 @@ pub use crate::thread::futex::{
};
pub use crate::timespec::{Nsecs, Secs, Timespec};

pub use net::{__kernel_sockaddr_storage as sockaddr_storage, msghdr, sockaddr, socklen_t};

mod sys {
pub(super) use linux_raw_sys::io_uring::*;
#[cfg(test)]
pub(super) use {crate::backend::c::iovec, linux_raw_sys::general::open_how};
pub(super) use {
crate::backend::c::iovec, linux_raw_sys::general::open_how, linux_raw_sys::net::msghdr,
};
}

/// `msghdr`
#[allow(missing_docs)]
#[repr(C)]
pub struct MsgHdr {
pub msg_name: *mut c_void,
pub msg_namelen: SocketAddrLen,
pub msg_iov: *mut iovec,
pub msg_iovlen: usize,
pub msg_control: *mut c_void,
pub msg_controllen: usize,
pub msg_flags: RecvFlags,
}

/// `io_uring_setup(entries, params)`—Setup a context for performing
Expand Down Expand Up @@ -1567,7 +1581,7 @@ pub struct io_uring_getevents_arg {
#[repr(C)]
#[derive(Debug, Default, Copy, Clone)]
pub struct io_uring_recvmsg_out {
pub namelen: u32,
pub namelen: SocketAddrLen,
pub controllen: u32,
pub payloadlen: u32,
pub flags: RecvmsgOutFlags,
Expand Down Expand Up @@ -1885,5 +1899,17 @@ mod tests {
io_uring_buf_ring__bindgen_ty_1__bindgen_ty_2
);
check_struct_renamed_field!(io_uring_buf_ring, tail_or_bufs, __bindgen_anon_1);

check_renamed_struct!(
MsgHdr,
msghdr,
msg_name,
msg_namelen,
msg_iov,
msg_iovlen,
msg_control,
msg_controllen,
msg_flags
);
}
}
6 changes: 1 addition & 5 deletions src/termios/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1391,11 +1391,7 @@ fn termios_layouts() {
assert_eq_size!(u8, libc::cc_t);
assert_eq_size!(types::tcflag_t, libc::tcflag_t);

check_renamed_type!(Winsize, winsize);
check_renamed_struct_field!(Winsize, winsize, ws_row);
check_renamed_struct_field!(Winsize, winsize, ws_col);
check_renamed_struct_field!(Winsize, winsize, ws_xpixel);
check_renamed_struct_field!(Winsize, winsize, ws_ypixel);
check_renamed_struct!(Winsize, winsize, ws_row, ws_col, ws_xpixel, ws_ypixel);

// On platforms with a termios/termios2 split, check `termios`.
#[cfg(linux_raw)]
Expand Down
5 changes: 1 addition & 4 deletions src/thread/futex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -621,9 +621,6 @@ mod tests {
fn test_layouts() {
use crate::backend::c;

check_renamed_type!(Wait, futex_waitv);
check_renamed_struct_field!(Wait, futex_waitv, val);
check_renamed_struct_field!(Wait, futex_waitv, uaddr);
check_renamed_struct_field!(Wait, futex_waitv, flags);
check_renamed_struct!(Wait, futex_waitv, val, uaddr, flags, __reserved);
}
}
Loading