1#[cfg(any(target_os = "android", target_os = "linux"))]
6use std::collections::BTreeSet;
7
8use anyhow::Result;
9#[cfg(any(target_os = "android", target_os = "linux"))]
10use base::Pid;
11use hypervisor::ProtectionType;
12use hypervisor::Vm;
13#[cfg(any(target_os = "android", target_os = "linux"))]
14use jail::JailConfig;
15#[cfg(any(target_os = "android", target_os = "linux"))]
16pub use minijail::Minijail;
17use resources::SystemAllocator;
18use vm_control::AnyControlTube;
19
20use crate::virtio::VirtioDevice;
21
22pub struct VirtioDeviceArgs<'a> {
24 pub vm: &'a dyn Vm,
25 pub resources: &'a mut SystemAllocator,
26 pub add_control_tube: &'a mut dyn FnMut(AnyControlTube),
27 pub protection_type: ProtectionType,
28 #[cfg(any(target_os = "android", target_os = "linux"))]
29 pub jail_config: Option<&'a JailConfig>,
30 #[cfg(any(target_os = "android", target_os = "linux"))]
32 pub worker_process_pids: &'a mut BTreeSet<Pid>,
33}
34
35pub trait VirtioDeviceModule: serde::Serialize + serde::de::DeserializeOwned {
48 fn sort_name(&self) -> &'static str;
50
51 fn create(&self, cx: &mut VirtioDeviceArgs<'_>) -> Result<Box<dyn VirtioDevice>>;
53
54 #[cfg(any(target_os = "android", target_os = "linux"))]
56 fn create_jail(&self, jail_config: Option<&JailConfig>) -> Result<Option<Minijail>>;
57}