summary refs log tree commit diff
diff options
context:
space:
mode:
authorAlyssa Ross <hi@alyssa.is>2020-07-01 12:39:39 +0000
committerAlyssa Ross <hi@alyssa.is>2020-07-02 12:33:11 +0000
commit21dc37aee5c37235f5c473fa86cb0df0a41fa840 (patch)
treedc86b979312d8bc74d87a9932fefad1447cf9928
parent1e3229aba9dedd68b639403a15961585cf12bbcf (diff)
downloadcrosvm-21dc37aee5c37235f5c473fa86cb0df0a41fa840.tar
crosvm-21dc37aee5c37235f5c473fa86cb0df0a41fa840.tar.gz
crosvm-21dc37aee5c37235f5c473fa86cb0df0a41fa840.tar.bz2
crosvm-21dc37aee5c37235f5c473fa86cb0df0a41fa840.tar.lz
crosvm-21dc37aee5c37235f5c473fa86cb0df0a41fa840.tar.xz
crosvm-21dc37aee5c37235f5c473fa86cb0df0a41fa840.tar.zst
crosvm-21dc37aee5c37235f5c473fa86cb0df0a41fa840.zip
Make wayland socket names byte arrays
-rw-r--r--devices/src/virtio/wl.rs33
-rw-r--r--src/crosvm.rs2
-rw-r--r--src/linux.rs2
-rw-r--r--src/main.rs10
-rw-r--r--vm_control/src/lib.rs2
5 files changed, 25 insertions, 24 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,
diff --git a/src/crosvm.rs b/src/crosvm.rs
index ab4429a..ad257d3 100644
--- a/src/crosvm.rs
+++ b/src/crosvm.rs
@@ -181,7 +181,7 @@ pub struct Config {
     pub tap_fd: Vec<RawFd>,
     pub cid: Option<u64>,
     pub wl_memfd: bool,
-    pub wayland_socket_paths: BTreeMap<String, PathBuf>,
+    pub wayland_socket_paths: BTreeMap<Vec<u8>, PathBuf>,
     pub remote_wayland_device_socket_path: Option<PathBuf>,
     pub wayland_dmabuf: bool,
     pub x_display: Option<String>,
diff --git a/src/linux.rs b/src/linux.rs
index e9ee659..9d1f547 100644
--- a/src/linux.rs
+++ b/src/linux.rs
@@ -779,7 +779,7 @@ fn create_wayland_device(
     let mut wayland_socket_paths = cfg.wayland_socket_paths.clone();
 
     if let Some(memfd_socket_path) = memfd_socket_path {
-        wayland_socket_paths.insert("__crosvm_memfd".to_string(), memfd_socket_path.into());
+        wayland_socket_paths.insert(b"__crosvm_memfd".to_vec(), memfd_socket_path.into());
     }
 
     let wayland_socket_dirs = wayland_socket_paths
diff --git a/src/main.rs b/src/main.rs
index 81f1b50..7b47d3c 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -841,7 +841,7 @@ fn set_argument(cfg: &mut Config, name: &str, value: Option<&str>) -> argument::
                             expected: String::from("missing socket path"),
                         })?,
                 );
-            let mut name = "";
+            let mut name: &[u8] = b"";
             for c in components {
                 let mut kv = c.splitn(2, '=');
                 let (kind, value) = match (kv.next(), kv.next()) {
@@ -854,7 +854,7 @@ fn set_argument(cfg: &mut Config, name: &str, value: Option<&str>) -> argument::
                     }
                 };
                 match kind {
-                    "name" => name = value,
+                    "name" => name = value.as_bytes(),
                     _ => {
                         return Err(argument::Error::InvalidValue {
                             value: kind.to_owned(),
@@ -866,10 +866,10 @@ fn set_argument(cfg: &mut Config, name: &str, value: Option<&str>) -> argument::
             if cfg.wayland_socket_paths.contains_key(name) {
                 return Err(argument::Error::TooManyArguments(format!(
                     "wayland socket name already used: '{}'",
-                    name
+                    String::from_utf8_lossy(&name)
                 )));
             }
-            cfg.wayland_socket_paths.insert(name.to_string(), path);
+            cfg.wayland_socket_paths.insert(name.to_vec(), path);
         }
         "wayland-device-sock" => {
             let path = PathBuf::from(value.unwrap());
@@ -2190,7 +2190,7 @@ fn wl_cmd(mut args: std::env::Args) -> std::result::Result<(), ()> {
 
     let request = match subcommand {
         "add" => {
-            let name = args.next().unwrap();
+            let name = args.next().unwrap().as_bytes().to_vec();
             let path = args.next().unwrap().into();
             VmRequest::WlCommand(WlControlCommand::AddSocket { name, path })
         }
diff --git a/vm_control/src/lib.rs b/vm_control/src/lib.rs
index e800624..b2e328c 100644
--- a/vm_control/src/lib.rs
+++ b/vm_control/src/lib.rs
@@ -514,7 +514,7 @@ impl VmMsyncRequest {
 
 #[derive(MsgOnSocket, Debug)]
 pub enum WlControlCommand {
-    AddSocket { name: String, path: PathBuf },
+    AddSocket { name: Vec<u8>, path: PathBuf },
 }
 
 #[derive(MsgOnSocket, Debug)]