Skip to content
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
12 changes: 12 additions & 0 deletions litebox_common_linux/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1778,6 +1778,10 @@ pub struct UserMsgHdr<Platform: litebox::platform::RawPointerProvider> {
pub msg_name: Platform::RawConstPointer<u8>,
/// size of socket address structure
pub msg_namelen: u32,
/// Explicit padding to match the 4-byte gap that Linux's naturally-aligned
/// `struct user_msghdr` has between `msg_namelen` and `msg_iov` on 64-bit.
#[cfg(target_pointer_width = "64")]
_pad: u32,
/// ptr to an array of `iovec` structures
pub msg_iov: Platform::RawConstPointer<IoVec<Platform::RawMutPointer<u8>>>,
/// number of elements in msg_iov
Expand All @@ -1788,18 +1792,26 @@ pub struct UserMsgHdr<Platform: litebox::platform::RawPointerProvider> {
pub msg_controllen: usize,
/// flags on received message
pub msg_flags: SendFlags,
/// Explicit trailing padding to match the 4-byte gap after `msg_flags` in
/// Linux's naturally-aligned `struct user_msghdr` on 64-bit (total size 56).
#[cfg(target_pointer_width = "64")]
_pad2: u32,
}

impl<Platform: litebox::platform::RawPointerProvider> Clone for UserMsgHdr<Platform> {
fn clone(&self) -> Self {
Self {
msg_name: self.msg_name,
msg_namelen: self.msg_namelen,
#[cfg(target_pointer_width = "64")]
_pad: 0,
msg_iov: self.msg_iov,
msg_iovlen: self.msg_iovlen,
msg_control: self.msg_control,
msg_controllen: self.msg_controllen,
msg_flags: self.msg_flags,
#[cfg(target_pointer_width = "64")]
_pad2: 0,
}
}
}
Expand Down
20 changes: 12 additions & 8 deletions litebox_shim_linux/src/syscalls/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1868,6 +1868,12 @@ mod tests {
extern crate alloc;
extern crate std;

// Compile-time layout check: UserMsgHdr must match Linux's struct user_msghdr.
const _USER_MSG_HDR_SIZE: () = assert!(
core::mem::size_of::<litebox_common_linux::UserMsgHdr<crate::Platform>>()
== core::mem::size_of::<libc::msghdr>()
);

const TUN_IP_ADDR: [u8; 4] = [10, 0, 0, 2];
const TUN_IP_ADDR_STR: &str = "10.0.0.2";
const TUN_DEVICE_NAME: &str = "tun99";
Expand Down Expand Up @@ -2044,14 +2050,12 @@ mod tests {
iov_len: buf2.len(),
},
];
let hdr = litebox_common_linux::UserMsgHdr {
msg_name: ConstPtr::from_usize(0),
msg_namelen: 0,
msg_iov: ConstPtr::from_usize(iovec.as_ptr() as usize),
msg_iovlen: iovec.len(),
msg_control: ConstPtr::from_usize(0),
msg_controllen: 0,
msg_flags: SendFlags::empty(),
let hdr = {
use zerocopy::FromZeros as _;
let mut h = litebox_common_linux::UserMsgHdr::<crate::Platform>::new_zeroed();
h.msg_iov = ConstPtr::from_usize(iovec.as_ptr() as usize);
h.msg_iovlen = iovec.len();
h
};
assert_eq!(
task.do_sendmsg(client_fd, &hdr, SendFlags::empty())
Expand Down
Loading