diff options
author | Alyssa Ross <hi@alyssa.is> | 2020-05-08 15:27:56 +0000 |
---|---|---|
committer | Alyssa Ross <hi@alyssa.is> | 2020-05-10 02:39:28 +0000 |
commit | 2f8d50adc97cc7fca6f710bd575b4f71ccb40f6b (patch) | |
tree | fefaf2c13796f8f2fa9a13b99b09c3b40ab5966b /src/plugin | |
parent | 00c41c28bbc44b37fc8dcf5d2a5b4679f2aa4297 (diff) | |
parent | 03a54abf852984f696e7a101ff9590f05ebcba5b (diff) | |
download | crosvm-2f8d50adc97cc7fca6f710bd575b4f71ccb40f6b.tar crosvm-2f8d50adc97cc7fca6f710bd575b4f71ccb40f6b.tar.gz crosvm-2f8d50adc97cc7fca6f710bd575b4f71ccb40f6b.tar.bz2 crosvm-2f8d50adc97cc7fca6f710bd575b4f71ccb40f6b.tar.lz crosvm-2f8d50adc97cc7fca6f710bd575b4f71ccb40f6b.tar.xz crosvm-2f8d50adc97cc7fca6f710bd575b4f71ccb40f6b.tar.zst crosvm-2f8d50adc97cc7fca6f710bd575b4f71ccb40f6b.zip |
Merge remote-tracking branch 'origin/master'
Diffstat (limited to 'src/plugin')
-rw-r--r-- | src/plugin/mod.rs | 6 | ||||
-rw-r--r-- | src/plugin/process.rs | 19 | ||||
-rw-r--r-- | src/plugin/vcpu.rs | 1 |
3 files changed, 13 insertions, 13 deletions
diff --git a/src/plugin/mod.rs b/src/plugin/mod.rs index ae7e19c..470d5f0 100644 --- a/src/plugin/mod.rs +++ b/src/plugin/mod.rs @@ -8,7 +8,7 @@ mod vcpu; use std::fmt::{self, Display}; use std::fs::File; use std::io; -use std::os::unix::io::{AsRawFd, FromRawFd, IntoRawFd}; +use std::os::unix::io::{AsRawFd, FromRawFd}; use std::os::unix::net::UnixDatagram; use std::path::Path; use std::result; @@ -181,10 +181,6 @@ impl Display for Error { type Result<T> = result::Result<T, Error>; -fn downcast_file<F: IntoRawFd>(f: F) -> File { - unsafe { File::from_raw_fd(f.into_raw_fd()) } -} - fn new_seqpacket_pair() -> SysResult<(UnixDatagram, UnixDatagram)> { let mut fds = [0, 0]; unsafe { diff --git a/src/plugin/process.rs b/src/plugin/process.rs index 51fc892..783239a 100644 --- a/src/plugin/process.rs +++ b/src/plugin/process.rs @@ -7,19 +7,17 @@ use std::env::set_var; use std::fs::File; use std::io::Write; use std::mem::transmute; -use std::os::unix::io::{AsRawFd, RawFd}; +use std::os::unix::io::{IntoRawFd, RawFd}; use std::os::unix::net::UnixDatagram; use std::path::Path; use std::process::Command; use std::sync::{Arc, RwLock}; use std::thread::JoinHandle; -use net_util; use net_util::Error as NetError; use libc::{pid_t, waitpid, EINVAL, ENODATA, ENOTTY, WEXITSTATUS, WIFEXITED, WNOHANG, WTERMSIG}; -use protobuf; use protobuf::Message; use io_jail::Minijail; @@ -348,7 +346,7 @@ impl Process { read_only: bool, dirty_log: bool, ) -> SysResult<()> { - let shm = SharedMemory::from_raw_fd(memfd)?; + let shm = SharedMemory::from_file(memfd)?; // Checking the seals ensures the plugin process won't shrink the mmapped file, causing us // to SIGBUS in the future. let seals = shm.get_seals()?; @@ -517,7 +515,14 @@ impl Process { let request = protobuf::parse_from_bytes::<MainRequest>(&self.request_buffer[..msg_size]) .map_err(Error::DecodeRequest)?; - let mut response_files = Vec::new(); + /// Use this to make it easier to stuff various kinds of File-like objects into the + /// `boxed_fds` list. + fn box_owned_fd<F: IntoRawFd + 'static>(f: F) -> Box<dyn IntoRawFd> { + Box::new(f) + } + + // This vec is used to extend ownership of certain FDs until the end of this function. + let mut boxed_fds = Vec::new(); let mut response_fds = Vec::new(); let mut response = MainResponse::new(); let res = if request.has_create() { @@ -559,7 +564,7 @@ impl Process { Ok(()) => { response_fds.push(evt.as_raw_fd()); response_fds.push(resample_evt.as_raw_fd()); - response_files.push(downcast_file(resample_evt)); + boxed_fds.push(box_owned_fd(resample_evt)); entry.insert(PluginObject::IrqEvent { irq_id: irq_event.irq_id, evt, @@ -588,7 +593,7 @@ impl Process { Ok((request_socket, child_socket)) => { self.request_sockets.push(request_socket); response_fds.push(child_socket.as_raw_fd()); - response_files.push(downcast_file(child_socket)); + boxed_fds.push(box_owned_fd(child_socket)); Ok(()) } Err(e) => Err(e), diff --git a/src/plugin/vcpu.rs b/src/plugin/vcpu.rs index a5bf73c..4bd3ea8 100644 --- a/src/plugin/vcpu.rs +++ b/src/plugin/vcpu.rs @@ -13,7 +13,6 @@ use std::sync::{Arc, RwLock}; use libc::{EINVAL, ENOENT, ENOTTY, EPERM, EPIPE, EPROTO}; -use protobuf; use protobuf::Message; use assertions::const_assert; |