diff --git a/litebox_common_linux/src/lib.rs b/litebox_common_linux/src/lib.rs index 73ab21d31..abd6eee80 100644 --- a/litebox_common_linux/src/lib.rs +++ b/litebox_common_linux/src/lib.rs @@ -1778,6 +1778,10 @@ pub struct UserMsgHdr { pub msg_name: Platform::RawConstPointer, /// 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>>, /// number of elements in msg_iov @@ -1788,6 +1792,10 @@ pub struct UserMsgHdr { 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 Clone for UserMsgHdr { @@ -1795,11 +1803,15 @@ impl Clone for UserMsgHdr>() + == core::mem::size_of::() + ); + 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"; @@ -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::::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())