summary refs log tree commit diff
path: root/devices
diff options
context:
space:
mode:
authorDaniel Verkamp <dverkamp@chromium.org>2018-09-20 10:59:06 -0700
committerchrome-bot <chrome-bot@chromium.org>2018-10-01 11:30:00 -0700
commitc5a6762081979e3a1e16028a6542deda27465534 (patch)
tree2a24f14708c87648bc1ba246b59a677d0691b534 /devices
parent4f228cb2033b8e8bf94864574b37fe719b1a7930 (diff)
downloadcrosvm-c5a6762081979e3a1e16028a6542deda27465534.tar
crosvm-c5a6762081979e3a1e16028a6542deda27465534.tar.gz
crosvm-c5a6762081979e3a1e16028a6542deda27465534.tar.bz2
crosvm-c5a6762081979e3a1e16028a6542deda27465534.tar.lz
crosvm-c5a6762081979e3a1e16028a6542deda27465534.tar.xz
crosvm-c5a6762081979e3a1e16028a6542deda27465534.tar.zst
crosvm-c5a6762081979e3a1e16028a6542deda27465534.zip
devices: pci: add keep_fds to PciDevice
PciDevice implementations will have file descriptors that need to be
preserved across the minijail fork.

Change-Id: I0b1f5b827b55c4d8960ffa95331b82f9c692f304
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1237359
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Diffstat (limited to 'devices')
-rw-r--r--devices/src/pci/pci_device.rs7
-rw-r--r--devices/src/pci/pci_root.rs4
2 files changed, 11 insertions, 0 deletions
diff --git a/devices/src/pci/pci_device.rs b/devices/src/pci/pci_device.rs
index 7803a55..3e02db3 100644
--- a/devices/src/pci/pci_device.rs
+++ b/devices/src/pci/pci_device.rs
@@ -5,6 +5,7 @@
 use byteorder::{ByteOrder, LittleEndian};
 
 use std;
+use std::os::unix::io::RawFd;
 
 use pci::pci_configuration::PciConfiguration;
 use pci::PciInterruptPin;
@@ -23,6 +24,9 @@ pub enum Error {
 pub type Result<T> = std::result::Result<T, Error>;
 
 pub trait PciDevice: Send {
+    /// A vector of device-specific file descriptors that must be kept open
+    /// after jailing. Must be called before the process is jailed.
+    fn keep_fds(&self) -> Vec<RawFd>;
     /// Assign a legacy PCI IRQ to this device.
     fn assign_irq(&mut self, _irq_evt: EventFd, _irq_num: u32, _irq_pin: PciInterruptPin) {}
     /// Allocates the needed IO BAR space using the `allocate` function which takes a size and
@@ -80,6 +84,9 @@ impl<T: PciDevice> BusDevice for T {
 }
 
 impl<T: PciDevice + ?Sized> PciDevice for Box<T> {
+    fn keep_fds(&self) -> Vec<RawFd> {
+        (**self).keep_fds()
+    }
     fn assign_irq(&mut self, irq_evt: EventFd, irq_num: u32, irq_pin: PciInterruptPin) {
      (**self).assign_irq(irq_evt, irq_num, irq_pin)
     }
diff --git a/devices/src/pci/pci_root.rs b/devices/src/pci/pci_root.rs
index 34e4f2a..c500f71 100644
--- a/devices/src/pci/pci_root.rs
+++ b/devices/src/pci/pci_root.rs
@@ -2,6 +2,7 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
+use std::os::unix::io::RawFd;
 use std::sync::{Arc, Mutex};
 
 use byteorder::{ByteOrder, LittleEndian};
@@ -19,6 +20,9 @@ struct PciRootConfiguration {
 }
 
 impl PciDevice for PciRootConfiguration {
+    fn keep_fds(&self) -> Vec<RawFd> {
+        Vec::new()
+    }
     fn config_registers(&self) -> &PciConfiguration {
         &self.config
     }