vmm_vhost: mark Endpoint as !Sync

It isn't safe to send or recv messages concurrently. The byte stream
could get mixed up.

Change-Id: I27039d3f44d5d8ec609ce7974c6f2f3fcbd9768c
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5068397
Commit-Queue: Frederick Mayle <fmayle@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
This commit is contained in:
Frederick Mayle 2023-11-28 13:01:28 -08:00 committed by crosvm LUCI
parent 6bfa3f6ce9
commit 78a0f3d042

View file

@ -88,18 +88,26 @@ fn advance_slices_mut(bufs: &mut &mut [&mut [u8]], mut count: usize) {
///
/// Builds on top of `PlatformEndpoint`, which provides methods for sending and receiving raw bytes
/// and file descriptors (a thin cross-platform abstraction for unix domain sockets).
pub struct Endpoint<R: Req>(pub(crate) PlatformEndpoint<R>);
pub struct Endpoint<R: Req>(
pub(crate) PlatformEndpoint<R>,
// Mark `Endpoint` as `!Sync` because message sends and recvs cannot safely be done
// concurrently.
std::marker::PhantomData<std::cell::Cell<()>>,
);
impl<R: Req> From<SystemStream> for Endpoint<R> {
fn from(sock: SystemStream) -> Self {
Self(PlatformEndpoint::from(sock))
Self(PlatformEndpoint::from(sock), std::marker::PhantomData)
}
}
impl<R: Req> Endpoint<R> {
/// Create a new stream by connecting to server at `path`.
pub fn connect<P: AsRef<Path>>(path: P) -> Result<Self> {
PlatformEndpoint::connect(path).map(Self)
Ok(Self(
PlatformEndpoint::connect(path)?,
std::marker::PhantomData,
))
}
/// Constructs the slave request endpoint for self.