mirror of
https://chromium.googlesource.com/crosvm/crosvm
synced 2025-01-12 16:45:31 +00:00
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>
This commit is contained in:
parent
4f228cb203
commit
c5a6762081
3 changed files with 12 additions and 1 deletions
|
@ -142,7 +142,7 @@ pub fn generate_pci_root(devices: Vec<(Box<PciDevice + 'static>, Minijail)>,
|
|||
let mut root = PciRoot::new();
|
||||
let mut pci_irqs = Vec::new();
|
||||
for (dev_idx, (mut device, jail)) in devices.into_iter().enumerate() {
|
||||
let mut keep_fds = Vec::new();
|
||||
let mut keep_fds = device.keep_fds();
|
||||
syslog::push_fds(&mut keep_fds);
|
||||
|
||||
let irqfd = EventFd::new().map_err(DeviceRegistrationError::EventFdCreate)?;
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue