diff options
author | Daniel Verkamp <dverkamp@chromium.org> | 2019-09-19 10:26:05 -0700 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2019-11-05 19:26:35 +0000 |
commit | 21556bf5d8dbf49f9aa29782a96e12b5579e5e58 (patch) | |
tree | 78050b7d00510ce73711f43eaa9d374ae3d608bb /sys_util/src/sock_ctrl_msg.rs | |
parent | 5d0415bc798807454824d79cd17376dc6464a0d0 (diff) | |
download | crosvm-21556bf5d8dbf49f9aa29782a96e12b5579e5e58.tar crosvm-21556bf5d8dbf49f9aa29782a96e12b5579e5e58.tar.gz crosvm-21556bf5d8dbf49f9aa29782a96e12b5579e5e58.tar.bz2 crosvm-21556bf5d8dbf49f9aa29782a96e12b5579e5e58.tar.lz crosvm-21556bf5d8dbf49f9aa29782a96e12b5579e5e58.tar.xz crosvm-21556bf5d8dbf49f9aa29782a96e12b5579e5e58.tar.zst crosvm-21556bf5d8dbf49f9aa29782a96e12b5579e5e58.zip |
sys_util: make IntoIovec return an actual vector
Allow IntoIovec to produce an iovec with more than one entry. BUG=None TEST=./build_test.py Change-Id: I21e8512f3edb06d9c0be4a1707432dde9fda6e9e Signed-off-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1815316 Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Zach Reizner <zachr@chromium.org>
Diffstat (limited to 'sys_util/src/sock_ctrl_msg.rs')
-rw-r--r-- | sys_util/src/sock_ctrl_msg.rs | 38 |
1 files changed, 14 insertions, 24 deletions
diff --git a/sys_util/src/sock_ctrl_msg.rs b/sys_util/src/sock_ctrl_msg.rs index 96a072d..13b9b0c 100644 --- a/sys_util/src/sock_ctrl_msg.rs +++ b/sys_util/src/sock_ctrl_msg.rs @@ -107,15 +107,12 @@ fn raw_sendmsg<D: IntoIovec>(fd: RawFd, out_data: D, out_fds: &[RawFd]) -> Resul let cmsg_capacity = CMSG_SPACE!(size_of::<RawFd>() * out_fds.len()); let mut cmsg_buffer = CmsgBuffer::with_capacity(cmsg_capacity); - let mut iovec = iovec { - iov_base: out_data.as_ptr() as *mut c_void, - iov_len: out_data.size(), - }; + let mut iovec = out_data.into_iovec(); let mut msg = msghdr { msg_name: null_mut(), msg_namelen: 0, - msg_iov: &mut iovec as *mut iovec, + msg_iov: iovec.as_mut_ptr(), msg_iovlen: 1, msg_control: null_mut(), msg_controllen: 0, @@ -307,36 +304,29 @@ impl ScmSocket for UnixSeqpacket { /// This trait is unsafe because interfaces that use this trait depend on the base pointer and size /// being accurate. pub unsafe trait IntoIovec { - /// Gets the base pointer of this `iovec`. - fn as_ptr(&self) -> *const c_void; - - /// Gets the size in bytes of this `iovec`. - fn size(&self) -> usize; + /// Gets a vector of structures describing each contiguous region of a memory buffer. + fn into_iovec(&self) -> Vec<libc::iovec>; } // Safe because this slice can not have another mutable reference and it's pointer and size are // guaranteed to be valid. unsafe impl<'a> IntoIovec for &'a [u8] { - // Clippy false positive: https://github.com/rust-lang/rust-clippy/issues/3480 - #[allow(clippy::useless_asref)] - fn as_ptr(&self) -> *const c_void { - self.as_ref().as_ptr() as *const c_void - } - - fn size(&self) -> usize { - self.len() + fn into_iovec(&self) -> Vec<libc::iovec> { + vec![libc::iovec { + iov_base: self.as_ref().as_ptr() as *const c_void as *mut c_void, + iov_len: self.len(), + }] } } // Safe because volatile slices are only ever accessed with other volatile interfaces and the // pointer and size are guaranteed to be accurate. unsafe impl<'a> IntoIovec for VolatileSlice<'a> { - fn as_ptr(&self) -> *const c_void { - self.as_ptr() as *const c_void - } - - fn size(&self) -> usize { - self.size() as usize + fn into_iovec(&self) -> Vec<libc::iovec> { + vec![libc::iovec { + iov_base: self.as_ptr() as *const c_void as *mut c_void, + iov_len: self.size() as usize, + }] } } |