summary refs log tree commit diff
path: root/devices/src/virtio/wl.rs
diff options
context:
space:
mode:
Diffstat (limited to 'devices/src/virtio/wl.rs')
-rw-r--r--devices/src/virtio/wl.rs33
1 files changed, 17 insertions, 16 deletions
diff --git a/devices/src/virtio/wl.rs b/devices/src/virtio/wl.rs
index 13471f4..955ca76 100644
--- a/devices/src/virtio/wl.rs
+++ b/devices/src/virtio/wl.rs
@@ -279,8 +279,7 @@ enum WlError {
     PollContextAdd(Error),
     DmabufSync(io::Error),
     WriteResponse(io::Error),
-    InvalidString(std::str::Utf8Error),
-    UnknownSocketName(String),
+    UnknownSocketName(Vec<u8>),
 }
 
 impl Display for WlError {
@@ -306,8 +305,11 @@ impl Display for WlError {
             PollContextAdd(e) => write!(f, "failed to listen to FD on poll context: {}", e),
             DmabufSync(e) => write!(f, "failed to synchronize DMABuf access: {}", e),
             WriteResponse(e) => write!(f, "failed to write response: {}", e),
-            InvalidString(e) => write!(f, "invalid string: {}", e),
-            UnknownSocketName(name) => write!(f, "unknown socket name: {}", name),
+            UnknownSocketName(name) => write!(
+                f,
+                "unknown socket name: '{}'",
+                String::from_utf8_lossy(name)
+            ),
         }
     }
 }
@@ -820,7 +822,7 @@ enum WlRecv {
 }
 
 struct WlState {
-    wayland_paths: Map<String, PathBuf>,
+    wayland_paths: Map<Vec<u8>, PathBuf>,
     vm: VmRequester,
     resource_bridge: Option<ResourceRequestSocket>,
     use_transition_flags: bool,
@@ -835,7 +837,7 @@ struct WlState {
 
 impl WlState {
     fn new(
-        wayland_paths: Map<String, PathBuf>,
+        wayland_paths: Map<Vec<u8>, PathBuf>,
         vm_socket: VmMemoryControlRequestSocket,
         use_transition_flags: bool,
         resource_bridge: Option<ResourceRequestSocket>,
@@ -962,7 +964,7 @@ impl WlState {
         }
     }
 
-    fn new_context(&mut self, id: u32, name: &str) -> WlResult<WlResp> {
+    fn new_context(&mut self, id: u32, name: &[u8]) -> WlResult<WlResp> {
         if id & VFD_ID_HOST_MASK != 0 {
             return Ok(WlResp::InvalidId);
         }
@@ -979,7 +981,7 @@ impl WlState {
                     &self
                         .wayland_paths
                         .get(name)
-                        .ok_or(WlError::UnknownSocketName(name.to_string()))?,
+                        .ok_or(WlError::UnknownSocketName(name.to_vec()))?,
                 )?);
                 self.poll_ctx
                     .add(vfd.poll_fd().unwrap(), id)
@@ -996,8 +998,8 @@ impl WlState {
         }
     }
 
-    fn add_path(&mut self, name: String, path: PathBuf) -> Result<(), Error> {
-        if name.bytes().len() > 32 {
+    fn add_path(&mut self, name: Vec<u8>, path: PathBuf) -> Result<(), Error> {
+        if name.len() > 32 {
             return Err(Error::new(libc::EINVAL));
         }
 
@@ -1226,7 +1228,7 @@ impl WlState {
             }
             VIRTIO_WL_CMD_VFD_NEW_CTX => {
                 let ctrl = reader.read_obj::<CtrlVfd>().map_err(WlError::ParseDesc)?;
-                self.new_context(ctrl.id.into(), "")
+                self.new_context(ctrl.id.into(), b"")
             }
             VIRTIO_WL_CMD_VFD_NEW_PIPE => {
                 let ctrl = reader
@@ -1262,8 +1264,7 @@ impl WlState {
                     .iter()
                     .position(|x| x == &0)
                     .unwrap_or(ctrl.name.len());
-                let name =
-                    std::str::from_utf8(&ctrl.name[..name_len]).map_err(WlError::InvalidString)?;
+                let ref name = ctrl.name[..name_len];
                 self.new_context(ctrl.id.into(), name)
             }
             op_type => {
@@ -1369,7 +1370,7 @@ impl Worker {
         interrupt: Interrupt,
         in_queue: Queue,
         out_queue: Queue,
-        wayland_paths: Map<String, PathBuf>,
+        wayland_paths: Map<Vec<u8>, PathBuf>,
         vm_socket: VmMemoryControlRequestSocket,
         use_transition_flags: bool,
         resource_bridge: Option<ResourceRequestSocket>,
@@ -1580,7 +1581,7 @@ impl Worker {
 pub struct Wl {
     kill_evt: Option<EventFd>,
     worker_thread: Option<thread::JoinHandle<()>>,
-    wayland_paths: Map<String, PathBuf>,
+    wayland_paths: Map<Vec<u8>, PathBuf>,
     vm_socket: Option<VmMemoryControlRequestSocket>,
     resource_bridge: Option<ResourceRequestSocket>,
     use_transition_flags: bool,
@@ -1597,7 +1598,7 @@ use super::VirtioDeviceNew;
 
 #[derive(Debug)]
 pub struct Params {
-    pub wayland_paths: Map<String, PathBuf>,
+    pub wayland_paths: Map<Vec<u8>, PathBuf>,
     pub vm_socket: VmMemoryControlRequestSocket,
     pub resource_bridge: Option<ResourceRequestSocket>,
     pub control_socket: WlControlResponseSocket,