diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 2221cd10c..082746361 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -41,8 +41,9 @@ Here is an example of a good commit message: ``` devices: vhost: user: vmm: Add Connection type -This abstracts away the cross-platform differences: cfg(unix) uses a -Unix domain stream socket to connect to the vhost-user backend, and +This abstracts away the cross-platform differences: +cfg(any(target_os = "android", target_os = "linux")) uses a Unix +domain domain stream socket to connect to the vhost-user backend, and cfg(windows) uses a Tube. BUG=b:249361790 diff --git a/Cargo.toml b/Cargo.toml index c7f5bf74c..0c48ed3f9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -453,7 +453,7 @@ x86_64 = { path = "x86_64" } [target.'cfg(any(target_arch = "aarch64", target_arch = "arm"))'.dependencies] aarch64 = { path = "aarch64" } -[target.'cfg(unix)'.dependencies] +[target.'cfg(any(target_os = "android", target_os = "linux"))'.dependencies] minijail = "*" # provided by ebuild p9 = "0.2.3" vhost = { path = "vhost" } diff --git a/aarch64/Cargo.toml b/aarch64/Cargo.toml index 51f8244be..7339598d8 100644 --- a/aarch64/Cargo.toml +++ b/aarch64/Cargo.toml @@ -31,5 +31,5 @@ thiserror = "*" vm_control = { path = "../vm_control" } vm_memory = { path = "../vm_memory" } -[target.'cfg(unix)'.dependencies] +[target.'cfg(any(target_os = "android", target_os = "linux"))'.dependencies] minijail = "*" diff --git a/aarch64/src/lib.rs b/aarch64/src/lib.rs index fd8e50c46..ae864774d 100644 --- a/aarch64/src/lib.rs +++ b/aarch64/src/lib.rs @@ -55,13 +55,13 @@ use hypervisor::VmAArch64; #[cfg(windows)] use jail::FakeMinijailStub as Minijail; use kernel_loader::LoadedKernel; -#[cfg(unix)] +#[cfg(any(target_os = "android", target_os = "linux"))] use minijail::Minijail; use remain::sorted; use resources::AddressRange; use resources::SystemAllocator; use resources::SystemAllocatorConfig; -#[cfg(unix)] +#[cfg(any(target_os = "android", target_os = "linux"))] use sync::Condvar; use sync::Mutex; use thiserror::Error; @@ -392,7 +392,9 @@ impl arch::LinuxArch for AArch64 { dump_device_tree_blob: Option, _debugcon_jail: Option, #[cfg(feature = "swap")] swap_controller: &mut Option, - #[cfg(unix)] _guest_suspended_cvar: Option, Condvar)>>, + #[cfg(any(target_os = "android", target_os = "linux"))] _guest_suspended_cvar: Option< + Arc<(Mutex, Condvar)>, + >, ) -> std::result::Result, Self::Error> where V: VmAArch64, diff --git a/arch/Cargo.toml b/arch/Cargo.toml index e5537722b..bb00015b1 100644 --- a/arch/Cargo.toml +++ b/arch/Cargo.toml @@ -36,7 +36,7 @@ thiserror = "1.0.20" vm_control = { path = "../vm_control" } vm_memory = { path = "../vm_memory" } -[target.'cfg(unix)'.dependencies] +[target.'cfg(any(target_os = "android", target_os = "linux"))'.dependencies] minijail = "*" # provided by ebuild power_monitor = { path = "../power_monitor" } diff --git a/arch/src/lib.rs b/arch/src/lib.rs index cf1a0590b..2d85b51a1 100644 --- a/arch/src/lib.rs +++ b/arch/src/lib.rs @@ -51,7 +51,7 @@ use devices::PciInterruptPin; use devices::PciRoot; use devices::PciRootCommand; use devices::PreferredIrq; -#[cfg(unix)] +#[cfg(any(target_os = "android", target_os = "linux"))] use devices::ProxyDevice; use devices::SerialHardware; use devices::SerialParameters; @@ -62,7 +62,7 @@ use hypervisor::IoEventAddress; use hypervisor::Vm; #[cfg(windows)] use jail::FakeMinijailStub as Minijail; -#[cfg(unix)] +#[cfg(any(target_os = "android", target_os = "linux"))] use minijail::Minijail; use remain::sorted; #[cfg(target_arch = "x86_64")] @@ -78,7 +78,7 @@ pub use serial::get_serial_cmdline; pub use serial::set_default_serial_parameters; pub use serial::GetSerialCmdlineError; pub use serial::SERIAL_ADDR; -#[cfg(unix)] +#[cfg(any(target_os = "android", target_os = "linux"))] use sync::Condvar; use sync::Mutex; use thiserror::Error; @@ -373,7 +373,7 @@ pub struct RunnableLinuxVm { pub mmio_bus: Arc, pub no_smt: bool, pub pid_debug_label_map: BTreeMap, - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] pub platform_devices: Vec>>, pub pm: Option>>, /// Devices to be notified before the system resumes from the S3 suspended state. @@ -460,7 +460,9 @@ pub trait LinuxArch { #[cfg(target_arch = "x86_64")] pflash_jail: Option, #[cfg(target_arch = "x86_64")] fw_cfg_jail: Option, #[cfg(feature = "swap")] swap_controller: &mut Option, - #[cfg(unix)] guest_suspended_cvar: Option, Condvar)>>, + #[cfg(any(target_os = "android", target_os = "linux"))] guest_suspended_cvar: Option< + Arc<(Mutex, Condvar)>, + >, ) -> std::result::Result, Self::Error> where V: VmArch, @@ -493,7 +495,7 @@ pub trait LinuxArch { fn register_pci_device( linux: &mut RunnableLinuxVm, device: Box, - #[cfg(unix)] minijail: Option, + #[cfg(any(target_os = "android", target_os = "linux"))] minijail: Option, resources: &mut SystemAllocator, hp_control_tube: &mpsc::Sender, #[cfg(feature = "swap")] swap_controller: &mut Option, @@ -569,14 +571,14 @@ pub enum DeviceRegistrationError { #[error("Allocating IRQ number")] AllocateIrq, /// Could not allocate IRQ resource for the device. - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] #[error("Allocating IRQ resource: {0}")] AllocateIrqResource(devices::vfio::VfioError), /// Broken pci topology #[error("pci topology is broken")] BrokenPciTopology, /// Unable to clone a jail for the device. - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] #[error("failed to clone jail: {0}")] CloneJail(minijail::Error), /// Appending to kernel command line failed. @@ -615,11 +617,11 @@ pub enum DeviceRegistrationError { /// Failed to insert device into PCI root. #[error("failed to insert device into PCI root: {0}")] PciRootAddDevice(PciDeviceError), - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] /// Failed to initialize proxy device for jailed device. #[error("failed to create proxy device: {0}")] ProxyDeviceCreation(devices::ProxyError), - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] /// Failed to register battery device. #[error("failed to register battery device to VM: {0}")] RegisterBattery(devices::BatteryError), @@ -644,7 +646,7 @@ pub enum DeviceRegistrationError { pub fn configure_pci_device( linux: &mut RunnableLinuxVm, mut device: Box, - #[cfg(unix)] jail: Option, + #[cfg(any(target_os = "android", target_os = "linux"))] jail: Option, resources: &mut SystemAllocator, hp_control_tube: &mpsc::Sender, #[cfg(feature = "swap")] swap_controller: &mut Option, @@ -704,7 +706,7 @@ pub fn configure_pci_device( .register_device_capabilities() .map_err(DeviceRegistrationError::RegisterDeviceCapabilities)?; - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] let arced_dev: Arc> = if let Some(jail) = jail { let proxy = ProxyDevice::new( device, @@ -729,7 +731,7 @@ pub fn configure_pci_device( Arc::new(Mutex::new(device)) }; - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] hp_control_tube .send(PciRootCommand::Add(pci_address, arced_dev.clone())) .map_err(DeviceRegistrationError::RegisterDevice)?; @@ -768,7 +770,7 @@ pub fn generate_virtio_mmio_bus( #[cfg(target_arch = "x86_64")] let mut sdts = sdts; for dev_value in devices.into_iter() { - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] let (mut device, jail) = dev_value; #[cfg(windows)] let (mut device, _) = dev_value; @@ -805,7 +807,7 @@ pub fn generate_virtio_mmio_bus( .ok_or(DeviceRegistrationError::GenerateAcpi)?; } - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] let arced_dev: Arc> = if let Some(jail) = jail { let proxy = ProxyDevice::new( device, @@ -1088,7 +1090,7 @@ pub fn generate_pci_root( let mut amls = BTreeMap::new(); let mut gpe_scope_amls = BTreeMap::new(); for (dev_idx, dev_value) in devices { - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] let (mut device, jail) = dev_value; #[cfg(windows)] let (mut device, _) = dev_value; @@ -1121,7 +1123,7 @@ pub fn generate_pci_root( } let gpe_nr = device.set_gpe(resources); - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] let arced_dev: Arc> = if let Some(jail) = jail { let proxy = ProxyDevice::new( device, diff --git a/arch/src/pstore/sys.rs b/arch/src/pstore/sys.rs index 230cea3ec..d5cdf60e9 100644 --- a/arch/src/pstore/sys.rs +++ b/arch/src/pstore/sys.rs @@ -3,7 +3,7 @@ // found in the LICENSE file. cfg_if::cfg_if! { - if #[cfg(unix)] { + if #[cfg(any(target_os = "android", target_os = "linux"))] { pub(crate) mod unix; use unix as platform; } else if #[cfg(windows)] { diff --git a/arch/src/serial.rs b/arch/src/serial.rs index 1062730f8..f46292a8e 100644 --- a/arch/src/serial.rs +++ b/arch/src/serial.rs @@ -17,7 +17,7 @@ use hypervisor::ProtectionType; use jail::read_jail_addr; #[cfg(windows)] use jail::FakeMinijailStub as Minijail; -#[cfg(unix)] +#[cfg(any(target_os = "android", target_os = "linux"))] use minijail::Minijail; use remain::sorted; use thiserror::Error as ThisError; @@ -123,7 +123,7 @@ pub fn add_serial_devices( .create_serial_device::(protection_type, com_evt, &mut preserved_descriptors) .map_err(DeviceRegistrationError::CreateSerialDevice)?; - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] let serial_jail = if let Some(serial_jail) = serial_jail.as_ref() { let jail_clone = serial_jail .try_clone() diff --git a/arch/src/serial/sys.rs b/arch/src/serial/sys.rs index 24c77ebc5..2c81acb98 100644 --- a/arch/src/serial/sys.rs +++ b/arch/src/serial/sys.rs @@ -3,7 +3,7 @@ // found in the LICENSE file. cfg_if::cfg_if! { - if #[cfg(unix)] { + if #[cfg(any(target_os = "android", target_os = "linux"))] { pub(crate) mod unix; use unix as platform; } else if #[cfg(windows)] { diff --git a/arch/src/sys.rs b/arch/src/sys.rs index d39fc489a..46aae6091 100644 --- a/arch/src/sys.rs +++ b/arch/src/sys.rs @@ -3,7 +3,7 @@ // found in the LICENSE file. cfg_if::cfg_if! { - if #[cfg(unix)] { + if #[cfg(any(target_os = "android", target_os = "linux"))] { pub mod unix; } } diff --git a/arch/src/sys/unix.rs b/arch/src/sys/unix.rs index 457dca865..cd91e0c78 100644 --- a/arch/src/sys/unix.rs +++ b/arch/src/sys/unix.rs @@ -124,7 +124,7 @@ pub fn add_goldfish_battery( } /// Creates a platform device for use by this Vm. -#[cfg(unix)] +#[cfg(any(target_os = "android", target_os = "linux"))] pub fn generate_platform_bus( devices: Vec<(VfioPlatformDevice, Option)>, irq_chip: &mut dyn IrqChip, diff --git a/audio_streams_conformance_test/Cargo.toml b/audio_streams_conformance_test/Cargo.toml index 16d2640c5..e3ea89bce 100644 --- a/audio_streams_conformance_test/Cargo.toml +++ b/audio_streams_conformance_test/Cargo.toml @@ -19,5 +19,5 @@ serde = { version = "1.0", features = ["derive"] } serde_json = "*" thiserror = "1.0.20" -[target.'cfg(unix)'.dependencies] +[target.'cfg(any(target_os = "android", target_os = "linux"))'.dependencies] minijail = "*" diff --git a/audio_streams_conformance_test/src/sys/mod.rs b/audio_streams_conformance_test/src/sys/mod.rs index a4d9e0708..c98396ca2 100644 --- a/audio_streams_conformance_test/src/sys/mod.rs +++ b/audio_streams_conformance_test/src/sys/mod.rs @@ -3,7 +3,7 @@ // found in the LICENSE file. cfg_if::cfg_if! { - if #[cfg(unix)] { + if #[cfg(any(target_os = "android", target_os = "linux"))] { mod unix; use unix as platform; } else if #[cfg(windows)] { diff --git a/base/Cargo.toml b/base/Cargo.toml index 963d946c6..527a385f2 100644 --- a/base/Cargo.toml +++ b/base/Cargo.toml @@ -41,7 +41,7 @@ zerocopy = { version = "0.7", features = ["derive"] } libtest-mimic = "0.6" protos = { path = "../protos", features = ["composite-disk"] } -[target.'cfg(unix)'.dependencies] +[target.'cfg(any(target_os = "android", target_os = "linux"))'.dependencies] minijail = "*" [target.'cfg(windows)'.dependencies] diff --git a/base/src/lib.rs b/base/src/lib.rs index a741f6cdd..ae5b8bd6e 100644 --- a/base/src/lib.rs +++ b/base/src/lib.rs @@ -75,7 +75,7 @@ pub use write_zeroes::WriteZeroesAt; // TODO(b/233233301): reorganize platform specific exports under platform // namespaces instead of exposing them directly in base::. cfg_if::cfg_if! { - if #[cfg(unix)] { + if #[cfg(any(target_os = "android", target_os = "linux"))] { pub use sys::unix; pub use unix::net; diff --git a/base/src/shm.rs b/base/src/shm.rs index 124f6eb35..ef63a4936 100644 --- a/base/src/shm.rs +++ b/base/src/shm.rs @@ -74,7 +74,7 @@ impl audio_streams::shm_streams::SharedMemory for SharedMemory { self.size() } - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] fn as_raw_fd(&self) -> RawDescriptor { self.as_raw_descriptor() } diff --git a/base/src/sys.rs b/base/src/sys.rs index 6159768b1..017a477c1 100644 --- a/base/src/sys.rs +++ b/base/src/sys.rs @@ -2,14 +2,14 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#[cfg(unix)] +#[cfg(any(target_os = "android", target_os = "linux"))] pub mod unix; #[cfg(windows)] pub mod windows; cfg_if::cfg_if! { - if #[cfg(unix)] { + if #[cfg(any(target_os = "android", target_os = "linux"))] { pub use unix as platform; pub use platform::*; } else if #[cfg(windows)] { diff --git a/base/src/tube.rs b/base/src/tube.rs index 57a2a7d9c..56a8479b0 100644 --- a/base/src/tube.rs +++ b/base/src/tube.rs @@ -120,7 +120,7 @@ pub enum Error { #[cfg(windows)] #[error("failed to flush named pipe: {0}")] Flush(io::Error), - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] #[error("byte framing mode is not supported")] InvalidFramingMode, #[error("failed to serialize/deserialize json from packet: {0}")] diff --git a/base/tests/process.rs b/base/tests/process.rs index b7fc82305..c02be664e 100644 --- a/base/tests/process.rs +++ b/base/tests/process.rs @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#[cfg(unix)] +#[cfg(any(target_os = "android", target_os = "linux"))] mod test { use std::thread; use std::time::Duration; @@ -108,27 +108,27 @@ fn main() { }; let tests = vec![ - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] libtest_mimic::Trial::test("pid_diff", move || { test::pid_diff(); Ok(()) }), - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] libtest_mimic::Trial::test("thread_name", move || { test::thread_name(); Ok(()) }), - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] libtest_mimic::Trial::test("thread_name_trimmed", move || { test::thread_name_trimmed(); Ok(()) }), - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] libtest_mimic::Trial::test("wait_for_success", move || { test::wait_for_success(); Ok(()) }), - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] libtest_mimic::Trial::test("wait_for_panic", move || { test::wait_for_panic(); Ok(()) diff --git a/base/tests/unix/main.rs b/base/tests/unix/main.rs index 745347e23..6c346f978 100644 --- a/base/tests/unix/main.rs +++ b/base/tests/unix/main.rs @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#![cfg(unix)] +#![cfg(any(target_os = "android", target_os = "linux"))] use std::path::Path; diff --git a/common/audio_streams/src/async_api.rs b/common/audio_streams/src/async_api.rs index 51e97ddd2..038bec7a7 100644 --- a/common/audio_streams/src/async_api.rs +++ b/common/audio_streams/src/async_api.rs @@ -13,9 +13,9 @@ //! The implementation is provided in `cros_async::audio_streams_async`. use std::io::Result; -#[cfg(unix)] +#[cfg(any(target_os = "android", target_os = "linux"))] use std::os::unix::io::RawFd as RawDescriptor; -#[cfg(unix)] +#[cfg(any(target_os = "android", target_os = "linux"))] use std::os::unix::net::UnixStream; #[cfg(windows)] use std::os::windows::io::RawHandle; @@ -64,7 +64,7 @@ pub type AsyncStream = Box; #[async_trait(?Send)] pub trait AudioStreamsExecutor { /// Create an object to allow async reads/writes from the specified UnixStream. - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] fn async_unix_stream(&self, f: UnixStream) -> Result; /// Wraps an event that will be triggered when the audio backend is ready to read more audio @@ -80,7 +80,7 @@ pub trait AudioStreamsExecutor { async fn delay(&self, dur: Duration) -> Result<()>; // Returns a future that resolves after the provided descriptor is readable. - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] async fn wait_fd_readable(&self, _fd: RawDescriptor) -> Result<()> { Ok(()) } @@ -95,7 +95,7 @@ pub mod test { #[async_trait(?Send)] impl AudioStreamsExecutor for TestExecutor { - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] fn async_unix_stream(&self, _f: UnixStream) -> Result { panic!("Not Implemented"); } @@ -110,7 +110,7 @@ pub mod test { unimplemented!("async_event is not yet implemented on windows"); } - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] async fn wait_fd_readable(&self, _fd: RawDescriptor) -> Result<()> { panic!("Not Implemented"); } diff --git a/common/audio_streams/src/audio_streams.rs b/common/audio_streams/src/audio_streams.rs index e8dcaf231..f8b56f782 100644 --- a/common/audio_streams/src/audio_streams.rs +++ b/common/audio_streams/src/audio_streams.rs @@ -48,7 +48,7 @@ use std::fmt::Display; use std::io; use std::io::Read; use std::io::Write; -#[cfg(unix)] +#[cfg(any(target_os = "android", target_os = "linux"))] use std::os::unix::io::RawFd as RawDescriptor; #[cfg(windows)] use std::os::windows::io::RawHandle as RawDescriptor; diff --git a/common/audio_streams/src/shm_streams.rs b/common/audio_streams/src/shm_streams.rs index c368f8441..d0176fcc6 100644 --- a/common/audio_streams/src/shm_streams.rs +++ b/common/audio_streams/src/shm_streams.rs @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#[cfg(unix)] +#[cfg(any(target_os = "android", target_os = "linux"))] use std::os::unix::io::RawFd; use std::sync::Arc; use std::sync::Condvar; @@ -174,7 +174,7 @@ pub trait SharedMemory { fn size(&self) -> u64; /// Returns the underlying raw fd. - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] fn as_raw_fd(&self) -> RawFd; } @@ -224,7 +224,7 @@ pub trait ShmStreamSource: Send { /// Returns any open file descriptors needed by the implementation. /// This list helps users of the ShmStreamSource enter Linux jails without /// closing needed file descriptors. - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] fn keep_fds(&self) -> Vec { Vec::new() } @@ -500,7 +500,7 @@ pub mod tests { 0 } - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] fn as_raw_fd(&self) -> RawFd { 0 } diff --git a/common/data_model/src/sys.rs b/common/data_model/src/sys.rs index 97c693601..ccb7e2e0a 100644 --- a/common/data_model/src/sys.rs +++ b/common/data_model/src/sys.rs @@ -5,7 +5,7 @@ //! A wrapper module for platform dependent code. cfg_if::cfg_if! { - if #[cfg(unix)] { + if #[cfg(any(target_os = "android", target_os = "linux"))] { mod unix; pub use unix::*; } else if #[cfg(windows)] { diff --git a/cros_async/Cargo.toml b/cros_async/Cargo.toml index f8c3842bb..3bbc882fd 100644 --- a/cros_async/Cargo.toml +++ b/cros_async/Cargo.toml @@ -24,7 +24,7 @@ anyhow = "1.0" serde = "*" serde_keyvalue = { path = "../serde_keyvalue", features = ["argh_derive"] } # provided by ebuild -[target.'cfg(unix)'.dependencies] +[target.'cfg(any(target_os = "android", target_os = "linux"))'.dependencies] io_uring = { path = "../io_uring" } # provided by ebuild [target.'cfg(windows)'.dependencies] diff --git a/cros_async/src/audio_streams_async.rs b/cros_async/src/audio_streams_async.rs index f28e6deb2..894d4c6e6 100644 --- a/cros_async/src/audio_streams_async.rs +++ b/cros_async/src/audio_streams_async.rs @@ -7,30 +7,30 @@ //! It implements the `AudioStreamsExecutor` trait for `Executor`, so it can be passed into //! the audio_streams API. use std::io::Result; -#[cfg(unix)] +#[cfg(any(target_os = "android", target_os = "linux"))] use std::os::unix::net::UnixStream; #[cfg(windows)] use std::os::windows::io::RawHandle; use std::time::Duration; use async_trait::async_trait; -#[cfg(unix)] +#[cfg(any(target_os = "android", target_os = "linux"))] use audio_streams::async_api::AsyncStream; use audio_streams::async_api::AudioStreamsExecutor; use audio_streams::async_api::EventAsyncWrapper; use audio_streams::async_api::ReadAsync; use audio_streams::async_api::ReadWriteAsync; use audio_streams::async_api::WriteAsync; -#[cfg(unix)] +#[cfg(any(target_os = "android", target_os = "linux"))] use base::Descriptor; #[cfg(windows)] use base::Event; #[cfg(windows)] use base::FromRawDescriptor; -#[cfg(unix)] +#[cfg(any(target_os = "android", target_os = "linux"))] use base::RawDescriptor; -#[cfg(unix)] +#[cfg(any(target_os = "android", target_os = "linux"))] use super::AsyncWrapper; use crate::EventAsync; use crate::IntoAsync; @@ -82,7 +82,7 @@ impl EventAsyncWrapper for EventAsync { #[async_trait(?Send)] impl AudioStreamsExecutor for super::Executor { - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] fn async_unix_stream(&self, stream: UnixStream) -> Result { Ok(Box::new(IoSourceWrapper { source: self.async_from(AsyncWrapper::new(stream))?, @@ -103,7 +103,7 @@ impl AudioStreamsExecutor for super::Executor { TimerAsync::sleep(self, dur).await.map_err(Into::into) } - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] async fn wait_fd_readable(&self, fd: RawDescriptor) -> Result<()> { self.async_from(AsyncWrapper::new(Descriptor(fd)))? .wait_readable() diff --git a/cros_async/src/blocking/sys.rs b/cros_async/src/blocking/sys.rs index 1fddbbc47..f80d48b6f 100644 --- a/cros_async/src/blocking/sys.rs +++ b/cros_async/src/blocking/sys.rs @@ -2,5 +2,5 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#[cfg(unix)] +#[cfg(any(target_os = "android", target_os = "linux"))] pub mod unix; diff --git a/cros_async/src/io_ext.rs b/cros_async/src/io_ext.rs index ee0352dee..c3481d82d 100644 --- a/cros_async/src/io_ext.rs +++ b/cros_async/src/io_ext.rs @@ -9,12 +9,12 @@ use std::ops::DerefMut; use base::AsRawDescriptor; use base::RawDescriptor; -#[cfg(unix)] +#[cfg(any(target_os = "android", target_os = "linux"))] use base::UnixSeqpacket; use remain::sorted; use thiserror::Error as ThisError; -#[cfg(unix)] +#[cfg(any(target_os = "android", target_os = "linux"))] #[sorted] #[derive(ThisError, Debug)] pub enum Error { @@ -49,21 +49,21 @@ pub enum Error { pub type Result = std::result::Result; -#[cfg(unix)] +#[cfg(any(target_os = "android", target_os = "linux"))] impl From for Error { fn from(err: crate::sys::unix::uring_executor::Error) -> Self { Error::Uring(err) } } -#[cfg(unix)] +#[cfg(any(target_os = "android", target_os = "linux"))] impl From for Error { fn from(err: crate::sys::unix::poll_source::Error) -> Self { Error::Poll(err) } } -#[cfg(unix)] +#[cfg(any(target_os = "android", target_os = "linux"))] impl From for io::Error { fn from(e: Error) -> Self { use Error::*; @@ -113,7 +113,7 @@ impl From for Error { pub trait IntoAsync: AsRawDescriptor {} impl IntoAsync for File {} -#[cfg(unix)] +#[cfg(any(target_os = "android", target_os = "linux"))] impl IntoAsync for UnixSeqpacket {} /// Simple wrapper struct to implement IntoAsync on foreign types. diff --git a/cros_async/src/io_source.rs b/cros_async/src/io_source.rs index f1fe7c2fd..f18a52717 100644 --- a/cros_async/src/io_source.rs +++ b/cros_async/src/io_source.rs @@ -6,9 +6,9 @@ use std::sync::Arc; use base::AsRawDescriptor; -#[cfg(unix)] +#[cfg(any(target_os = "android", target_os = "linux"))] use crate::sys::unix::PollSource; -#[cfg(unix)] +#[cfg(any(target_os = "android", target_os = "linux"))] use crate::sys::unix::UringSource; #[cfg(windows)] use crate::sys::windows::HandleSource; @@ -21,9 +21,9 @@ use crate::MemRegion; /// Associates an IO object `F` with cros_async's runtime and exposes an API to perform async IO on /// that object's descriptor. pub enum IoSource { - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] Uring(UringSource), - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] Epoll(PollSource), #[cfg(windows)] Handle(HandleSource), @@ -32,14 +32,14 @@ pub enum IoSource { } pub enum AllocateMode { - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] Allocate, PunchHole, ZeroRange, } // This assume we always want KEEP_SIZE -#[cfg(unix)] +#[cfg(any(target_os = "android", target_os = "linux"))] impl From for u32 { fn from(value: AllocateMode) -> Self { match value { @@ -60,9 +60,9 @@ impl From for u32 { macro_rules! await_on_inner { ($x:ident, $method:ident $(, $args:expr)*) => { match $x { - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] IoSource::Uring(x) => UringSource::$method(x, $($args),*).await, - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] IoSource::Epoll(x) => PollSource::$method(x, $($args),*).await, #[cfg(windows)] IoSource::Handle(x) => HandleSource::$method(x, $($args),*).await, @@ -78,9 +78,9 @@ macro_rules! await_on_inner { macro_rules! on_inner { ($x:ident, $method:ident $(, $args:expr)*) => { match $x { - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] IoSource::Uring(x) => UringSource::$method(x, $($args),*), - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] IoSource::Epoll(x) => PollSource::$method(x, $($args),*), #[cfg(windows)] IoSource::Handle(x) => HandleSource::$method(x, $($args),*), @@ -192,13 +192,13 @@ mod tests { use super::*; use crate::mem::VecIoWrapper; - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] use crate::sys::unix::uring_executor::is_uring_stable; use crate::Executor; use crate::ExecutorKind; use crate::MemRegion; - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] fn all_kinds() -> Vec { let mut kinds = vec![ExecutorKind::Fd]; if is_uring_stable() { diff --git a/cros_async/src/lib.rs b/cros_async/src/lib.rs index a4396e03a..10c48b835 100644 --- a/cros_async/src/lib.rs +++ b/cros_async/src/lib.rs @@ -66,7 +66,7 @@ mod queue; mod select; pub mod sync; pub mod sys; -#[cfg(unix)] +#[cfg(any(target_os = "android", target_os = "linux"))] pub use sys::unix::uring_executor::is_uring_stable; pub use sys::Executor; pub use sys::ExecutorKind; @@ -81,7 +81,7 @@ use std::task::Poll; pub use async_types::*; pub use base::Event; -#[cfg(unix)] +#[cfg(any(target_os = "android", target_os = "linux"))] pub use blocking::sys::unix::block_on::block_on; pub use blocking::unblock; pub use blocking::unblock_disarm; @@ -120,7 +120,7 @@ pub enum Error { #[error("IO error: {0}")] Io(std::io::Error), /// Error from the polled(FD) source, which includes error from the FD executor. - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] #[error("An error with a poll source: {0}")] PollSource(sys::unix::poll_source::Error), /// Error from Timer. @@ -130,7 +130,7 @@ pub enum Error { #[error("Failure in TimerAsync: {0}")] TimerAsync(AsyncError), /// Error from the uring executor. - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] #[error("Failure in the uring executor: {0}")] URingExecutor(sys::unix::uring_executor::Error), } diff --git a/cros_async/src/sync/cv.rs b/cros_async/src/sync/cv.rs index 5fa9b1813..77db21082 100644 --- a/cros_async/src/sync/cv.rs +++ b/cros_async/src/sync/cv.rs @@ -452,7 +452,7 @@ fn cancel_waiter(cv: usize, waiter: &Waiter, wake_next: bool) { } // TODO(b/194338842): Fix tests for windows -#[cfg(unix)] +#[cfg(any(target_os = "android", target_os = "linux"))] #[cfg(test)] mod test { use std::future::Future; diff --git a/cros_async/src/sync/mu.rs b/cros_async/src/sync/mu.rs index 317340405..b3aa508aa 100644 --- a/cros_async/src/sync/mu.rs +++ b/cros_async/src/sync/mu.rs @@ -888,7 +888,7 @@ impl<'a, T: ?Sized> Drop for RwLockReadGuard<'a, T> { } // TODO(b/194338842): Fix tests for windows -#[cfg(unix)] +#[cfg(any(target_os = "android", target_os = "linux"))] #[cfg(test)] mod test { use std::future::Future; diff --git a/cros_async/src/sys.rs b/cros_async/src/sys.rs index 7e613f529..88a633905 100644 --- a/cros_async/src/sys.rs +++ b/cros_async/src/sys.rs @@ -3,7 +3,7 @@ // found in the LICENSE file. cfg_if::cfg_if! { - if #[cfg(unix)] { + if #[cfg(any(target_os = "android", target_os = "linux"))] { pub mod unix; pub use unix as platform; } else if #[cfg(windows)] { diff --git a/cros_async/src/sys/unix/executor.rs b/cros_async/src/sys/unix/executor.rs index 8fdfe7cc6..370d26253 100644 --- a/cros_async/src/sys/unix/executor.rs +++ b/cros_async/src/sys/unix/executor.rs @@ -90,7 +90,7 @@ use crate::IoSource; /// Ok(len) /// } /// -/// #[cfg(unix)] +/// #[cfg(any(target_os = "android", target_os = "linux"))] /// # fn do_it() -> Result<(), Box> { /// let ex = Executor::new()?; /// @@ -119,7 +119,7 @@ use crate::IoSource; /// /// # Ok(()) /// # } -/// #[cfg(unix)] +/// #[cfg(any(target_os = "android", target_os = "linux"))] /// # do_it().unwrap(); /// ``` diff --git a/cros_async/src/sys/unix/uring_source.rs b/cros_async/src/sys/unix/uring_source.rs index 84b468aaf..9b675d9a7 100644 --- a/cros_async/src/sys/unix/uring_source.rs +++ b/cros_async/src/sys/unix/uring_source.rs @@ -399,7 +399,7 @@ mod tests { } } - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] #[test] fn await_uring_from_poll() { if !is_uring_stable() { @@ -434,7 +434,7 @@ mod tests { handle.join().unwrap().unwrap(); } - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] #[test] fn await_poll_from_uring() { if !is_uring_stable() { diff --git a/cros_async/src/sys/windows/executor.rs b/cros_async/src/sys/windows/executor.rs index d5c5bcb2c..06528d317 100644 --- a/cros_async/src/sys/windows/executor.rs +++ b/cros_async/src/sys/windows/executor.rs @@ -82,7 +82,7 @@ use crate::IoSource; /// Ok(len) /// } /// -/// #[cfg(unix)] +/// #[cfg(any(target_os = "android", target_os = "linux"))] /// # fn do_it() -> Result<(), Box> { /// let ex = Executor::new()?; /// @@ -111,7 +111,7 @@ use crate::IoSource; /// /// # Ok(()) /// # } -/// #[cfg(unix)] +/// #[cfg(any(target_os = "android", target_os = "linux"))] /// # do_it().unwrap(); /// ``` diff --git a/cros_async/tests/executor.rs b/cros_async/tests/executor.rs index c2ac57227..6f14f16dc 100644 --- a/cros_async/tests/executor.rs +++ b/cros_async/tests/executor.rs @@ -5,7 +5,7 @@ use cros_async::Executor; use cros_async::ExecutorKind; -#[cfg(unix)] +#[cfg(any(target_os = "android", target_os = "linux"))] fn all_kinds() -> Vec { let mut kinds = vec![ExecutorKind::Fd]; if cros_async::is_uring_stable() { diff --git a/crosvm_control/src/lib.rs b/crosvm_control/src/lib.rs index 18614730a..e8672f767 100644 --- a/crosvm_control/src/lib.rs +++ b/crosvm_control/src/lib.rs @@ -19,7 +19,7 @@ use std::ffi::CStr; use std::panic::catch_unwind; use std::path::Path; use std::path::PathBuf; -#[cfg(unix)] +#[cfg(any(target_os = "android", target_os = "linux"))] use std::time::Duration; use libc::c_char; @@ -166,7 +166,7 @@ pub unsafe extern "C" fn crosvm_client_balloon_vms( } /// See crosvm_client_balloon_vms. -#[cfg(unix)] +#[cfg(any(target_os = "android", target_os = "linux"))] #[no_mangle] pub unsafe extern "C" fn crosvm_client_balloon_vms_wait_with_timeout( socket_path: *const c_char, @@ -702,7 +702,7 @@ pub unsafe extern "C" fn crosvm_client_balloon_stats( ) -> bool { crosvm_client_balloon_stats_impl( socket_path, - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] None, stats, actual, @@ -710,7 +710,7 @@ pub unsafe extern "C" fn crosvm_client_balloon_stats( } /// See crosvm_client_balloon_stats. -#[cfg(unix)] +#[cfg(any(target_os = "android", target_os = "linux"))] #[no_mangle] pub unsafe extern "C" fn crosvm_client_balloon_stats_with_timeout( socket_path: *const c_char, @@ -728,7 +728,7 @@ pub unsafe extern "C" fn crosvm_client_balloon_stats_with_timeout( fn crosvm_client_balloon_stats_impl( socket_path: *const c_char, - #[cfg(unix)] timeout_ms: Option, + #[cfg(any(target_os = "android", target_os = "linux"))] timeout_ms: Option, stats: *mut BalloonStatsFfi, actual: *mut u64, ) -> bool { @@ -737,7 +737,7 @@ fn crosvm_client_balloon_stats_impl( let request = &VmRequest::BalloonCommand(BalloonControlCommand::Stats {}); #[cfg(not(unix))] let resp = handle_request(request, socket_path); - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] let resp = handle_request_with_timeout(request, socket_path, timeout_ms); if let Ok(VmResponse::BalloonStats { stats: ref balloon_stats, diff --git a/crosvm_plugin/src/lib.rs b/crosvm_plugin/src/lib.rs index 76ff56192..84a0430a4 100644 --- a/crosvm_plugin/src/lib.rs +++ b/crosvm_plugin/src/lib.rs @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#![cfg(unix)] +#![cfg(any(target_os = "android", target_os = "linux"))] #![cfg(target_arch = "x86_64")] #![allow(non_camel_case_types)] diff --git a/devices/Cargo.toml b/devices/Cargo.toml index ecf96030b..0207dee07 100644 --- a/devices/Cargo.toml +++ b/devices/Cargo.toml @@ -88,7 +88,7 @@ vm_control = { path = "../vm_control" } vm_memory = { path = "../vm_memory" } zerocopy = { version = "0.7", features = ["derive"] } -[target.'cfg(unix)'.dependencies] +[target.'cfg(any(target_os = "android", target_os = "linux"))'.dependencies] fuse = {path = "../fuse" } libcras = { version = "*", optional = true } minijail = "*" diff --git a/devices/src/bus.rs b/devices/src/bus.rs index 63879997d..c7eb3ee9e 100644 --- a/devices/src/bus.rs +++ b/devices/src/bus.rs @@ -33,7 +33,7 @@ use crate::DeviceId; use crate::PciAddress; use crate::PciDevice; use crate::Suspendable; -#[cfg(unix)] +#[cfg(any(target_os = "android", target_os = "linux"))] use crate::VfioPlatformDevice; use crate::VirtioMmioDevice; @@ -231,15 +231,15 @@ pub trait BusDeviceObj { fn into_pci_device(self: Box) -> Option> { None } - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] fn as_platform_device(&self) -> Option<&VfioPlatformDevice> { None } - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] fn as_platform_device_mut(&mut self) -> Option<&mut VfioPlatformDevice> { None } - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] fn into_platform_device(self: Box) -> Option> { None } diff --git a/devices/src/irqchip/mod.rs b/devices/src/irqchip/mod.rs index 8c8cee925..512607dfc 100644 --- a/devices/src/irqchip/mod.rs +++ b/devices/src/irqchip/mod.rs @@ -22,7 +22,7 @@ use crate::IrqEdgeEvent; use crate::IrqLevelEvent; cfg_if::cfg_if! { - if #[cfg(unix)] { + if #[cfg(any(target_os = "android", target_os = "linux"))] { mod kvm; pub use self::kvm::KvmKernelIrqChip; #[cfg(target_arch = "x86_64")] diff --git a/devices/src/lib.rs b/devices/src/lib.rs index c0ffba747..91150ce7f 100644 --- a/devices/src/lib.rs +++ b/devices/src/lib.rs @@ -134,7 +134,7 @@ pub use self::virtio::VirtioPciDevice; pub use self::vtpm_proxy::VtpmProxy; cfg_if::cfg_if! { - if #[cfg(unix)] { + if #[cfg(any(target_os = "android", target_os = "linux"))] { mod platform; mod proxy; pub mod vmwdt; diff --git a/devices/src/pci/mod.rs b/devices/src/pci/mod.rs index e0e79d647..53a7c4cc4 100644 --- a/devices/src/pci/mod.rs +++ b/devices/src/pci/mod.rs @@ -5,7 +5,7 @@ //! Implements pci devices and busses. mod acpi; -#[cfg(unix)] +#[cfg(any(target_os = "android", target_os = "linux"))] mod coiommu; mod msi; mod msix; @@ -15,12 +15,12 @@ mod pci_device; #[cfg(feature = "pci-hotplug")] mod pci_hotplug; mod pci_root; -#[cfg(unix)] +#[cfg(any(target_os = "android", target_os = "linux"))] mod pcie; mod pm; mod pvpanic; mod stub; -#[cfg(unix)] +#[cfg(any(target_os = "android", target_os = "linux"))] mod vfio_pci; use libc::EINVAL; @@ -31,11 +31,11 @@ pub use self::acpi::DeviceVcfgRegister; pub use self::acpi::DsmMethod; pub use self::acpi::GpeScope; pub use self::acpi::PowerResourceMethod; -#[cfg(unix)] +#[cfg(any(target_os = "android", target_os = "linux"))] pub use self::coiommu::CoIommuDev; -#[cfg(unix)] +#[cfg(any(target_os = "android", target_os = "linux"))] pub use self::coiommu::CoIommuParameters; -#[cfg(unix)] +#[cfg(any(target_os = "android", target_os = "linux"))] pub use self::coiommu::CoIommuUnpinPolicy; pub use self::msi::MsiConfig; pub use self::msix::MsixCap; @@ -77,21 +77,21 @@ pub use self::pci_root::PciConfigMmio; pub use self::pci_root::PciRoot; pub use self::pci_root::PciRootCommand; pub use self::pci_root::PciVirtualConfigMmio; -#[cfg(unix)] +#[cfg(any(target_os = "android", target_os = "linux"))] pub use self::pcie::PciBridge; -#[cfg(unix)] +#[cfg(any(target_os = "android", target_os = "linux"))] pub use self::pcie::PcieDownstreamPort; -#[cfg(unix)] +#[cfg(any(target_os = "android", target_os = "linux"))] pub use self::pcie::PcieHostPort; -#[cfg(unix)] +#[cfg(any(target_os = "android", target_os = "linux"))] pub use self::pcie::PcieRootPort; -#[cfg(unix)] +#[cfg(any(target_os = "android", target_os = "linux"))] pub use self::pcie::PcieUpstreamPort; pub use self::pvpanic::PvPanicCode; pub use self::pvpanic::PvPanicPciDevice; pub use self::stub::StubPciDevice; pub use self::stub::StubPciParameters; -#[cfg(unix)] +#[cfg(any(target_os = "android", target_os = "linux"))] pub use self::vfio_pci::VfioPciDevice; /// PCI has four interrupt pins A->D. diff --git a/devices/src/pci/pci_configuration.rs b/devices/src/pci/pci_configuration.rs index a9d3eb25f..2f15d6160 100644 --- a/devices/src/pci/pci_configuration.rs +++ b/devices/src/pci/pci_configuration.rs @@ -26,7 +26,7 @@ pub const COMMAND_REG_MEMORY_SPACE_MASK: u32 = 0x0000_0002; const STATUS_REG: usize = 1; pub const STATUS_REG_CAPABILITIES_USED_MASK: u32 = 0x0010_0000; #[allow(dead_code)] -#[cfg(unix)] +#[cfg(any(target_os = "android", target_os = "linux"))] pub const CLASS_REG: usize = 2; pub const HEADER_TYPE_REG: usize = 3; pub const HEADER_TYPE_MULTIFUNCTION_MASK: u32 = 0x0080_0000; @@ -40,7 +40,7 @@ pub const NUM_BAR_REGS: usize = 7; // 6 normal BARs + expansion ROM BAR. pub const ROM_BAR_IDX: PciBarIndex = 6; pub const ROM_BAR_REG: usize = 12; pub const CAPABILITY_LIST_HEAD_OFFSET: usize = 0x34; -#[cfg(unix)] +#[cfg(any(target_os = "android", target_os = "linux"))] pub const PCI_CAP_NEXT_POINTER: usize = 0x1; const FIRST_CAPABILITY_OFFSET: usize = 0x40; pub const CAPABILITY_MAX_OFFSET: usize = 255; diff --git a/devices/src/serial/sys.rs b/devices/src/serial/sys.rs index 3a643902f..26ba42610 100644 --- a/devices/src/serial/sys.rs +++ b/devices/src/serial/sys.rs @@ -3,7 +3,7 @@ // found in the LICENSE file. cfg_if::cfg_if! { - if #[cfg(unix)] { + if #[cfg(any(target_os = "android", target_os = "linux"))] { pub(in crate::serial) mod unix; use unix as platform; } else if #[cfg(windows)] { diff --git a/devices/src/serial_device.rs b/devices/src/serial_device.rs index 055fe789a..56b951c9e 100644 --- a/devices/src/serial_device.rs +++ b/devices/src/serial_device.rs @@ -280,7 +280,7 @@ mod tests { assert_eq!(params.type_, SerialType::Sink); let params = from_serial_arg("type=syslog").unwrap(); assert_eq!(params.type_, SerialType::Syslog); - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] let opt = "type=unix"; #[cfg(windows)] let opt = "type=namedpipe"; diff --git a/devices/src/sys.rs b/devices/src/sys.rs index ad84dd94e..d873b0525 100644 --- a/devices/src/sys.rs +++ b/devices/src/sys.rs @@ -3,7 +3,7 @@ // found in the LICENSE file. cfg_if::cfg_if! { - if #[cfg(unix)] { + if #[cfg(any(target_os = "android", target_os = "linux"))] { pub(crate) mod unix; use unix as platform; pub(crate) use unix::*; diff --git a/devices/src/virtio/balloon.rs b/devices/src/virtio/balloon.rs index c7698ff55..a3cd0f98e 100644 --- a/devices/src/virtio/balloon.rs +++ b/devices/src/virtio/balloon.rs @@ -981,7 +981,7 @@ fn run_worker( len, #[cfg(windows)] &vm_memory_client, - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] &mem, ) }, @@ -1060,7 +1060,7 @@ fn run_worker( len, #[cfg(windows)] &vm_memory_client, - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] &mem, ) }, diff --git a/devices/src/virtio/balloon/sys.rs b/devices/src/virtio/balloon/sys.rs index 1d0bcb9ec..28bf34124 100644 --- a/devices/src/virtio/balloon/sys.rs +++ b/devices/src/virtio/balloon/sys.rs @@ -3,7 +3,7 @@ // found in the LICENSE file. cfg_if::cfg_if! { - if #[cfg(unix)] { + if #[cfg(any(target_os = "android", target_os = "linux"))] { mod unix; use unix as platform; } else if #[cfg(windows)] { diff --git a/devices/src/virtio/block/asynchronous.rs b/devices/src/virtio/block/asynchronous.rs index 5228b378f..ceb4506ee 100644 --- a/devices/src/virtio/block/asynchronous.rs +++ b/devices/src/virtio/block/asynchronous.rs @@ -1549,20 +1549,20 @@ mod tests { } // TODO(b/270225199): enable this test on Windows once IoSource::into_source is implemented - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] #[test] fn reset_and_reactivate_single_worker() { reset_and_reactivate(false); } // TODO(b/270225199): enable this test on Windows once IoSource::into_source is implemented - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] #[test] fn reset_and_reactivate_multiple_workers() { reset_and_reactivate(true); } - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] fn reset_and_reactivate(enables_multiple_workers: bool) { // Create an empty disk image let f = tempfile().unwrap(); @@ -1662,7 +1662,7 @@ mod tests { // TODO(b/270225199): enable this test on Windows once IoSource::into_source is implemented, // or after finding a good way to prevent BlockAsync::drop() from panicking due to that. - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] #[test] fn resize_with_single_worker() { resize(false); @@ -1670,7 +1670,7 @@ mod tests { // TODO(b/270225199): enable this test on Windows once IoSource::into_source is implemented, // or after finding a good way to prevent BlockAsync::drop() from panicking due to that. - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] #[test] fn resize_with_multiple_workers() { // Test resize handled by one worker affect the whole state @@ -1789,7 +1789,7 @@ mod tests { // TODO(b/270225199): enable this test on Windows once IoSource::into_source is implemented, // or after finding a good way to prevent BlockAsync::drop() from panicking due to that. - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] #[test] fn run_worker_threads() { // Create an empty duplicable disk image @@ -1906,6 +1906,6 @@ mod tests { ) } - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] suspendable_virtio_tests!(asyncblock, create_device, 2, modify_device); } diff --git a/devices/src/virtio/block/mod.rs b/devices/src/virtio/block/mod.rs index 9d3f0f34f..659d4a0bc 100644 --- a/devices/src/virtio/block/mod.rs +++ b/devices/src/virtio/block/mod.rs @@ -464,7 +464,7 @@ mod tests { // async-executor #[cfg(windows)] let (ex_kind, ex_kind_opt) = (ExecutorKind::Handle, "handle"); - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] let (ex_kind, ex_kind_opt) = (ExecutorKind::Fd, "epoll"); let params = from_block_arg(&format!("/some/path.img,async-executor={ex_kind_opt}")).unwrap(); diff --git a/devices/src/virtio/block/sys/mod.rs b/devices/src/virtio/block/sys/mod.rs index b2e99b6a4..5e5c88dbc 100644 --- a/devices/src/virtio/block/sys/mod.rs +++ b/devices/src/virtio/block/sys/mod.rs @@ -3,7 +3,7 @@ // found in the LICENSE file. cfg_if::cfg_if! { - if #[cfg(unix)] { + if #[cfg(any(target_os = "android", target_os = "linux"))] { mod unix; pub use self::unix::*; } else if #[cfg(windows)] { diff --git a/devices/src/virtio/console.rs b/devices/src/virtio/console.rs index 8496c4415..90d318e1b 100644 --- a/devices/src/virtio/console.rs +++ b/devices/src/virtio/console.rs @@ -5,7 +5,7 @@ //! Legacy console device that uses a polling thread. This is kept because it is still used by //! Windows ; outside of this use-case, please use [[asynchronous::AsyncConsole]] instead. -#[cfg(unix)] +#[cfg(any(target_os = "android", target_os = "linux"))] pub mod asynchronous; mod sys; diff --git a/devices/src/virtio/console/sys.rs b/devices/src/virtio/console/sys.rs index cf0d6ead8..9c9c28405 100644 --- a/devices/src/virtio/console/sys.rs +++ b/devices/src/virtio/console/sys.rs @@ -3,7 +3,7 @@ // found in the LICENSE file. cfg_if::cfg_if! { - if #[cfg(unix)] { + if #[cfg(any(target_os = "android", target_os = "linux"))] { mod unix; use unix as platform; } else if #[cfg(windows)] { diff --git a/devices/src/virtio/gpu/mod.rs b/devices/src/virtio/gpu/mod.rs index 1ecd088b9..72046f393 100644 --- a/devices/src/virtio/gpu/mod.rs +++ b/devices/src/virtio/gpu/mod.rs @@ -21,7 +21,7 @@ use anyhow::anyhow; use anyhow::Context; use base::debug; use base::error; -#[cfg(unix)] +#[cfg(any(target_os = "android", target_os = "linux"))] use base::platform::move_task_to_cgroup; use base::warn; use base::AsRawDescriptor; @@ -800,7 +800,7 @@ enum WorkerToken { CtrlQueue, CursorQueue, Display, - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] GpuControl, InterruptResample, Kill, @@ -857,7 +857,7 @@ impl<'a> EventManager<'a> { struct Worker { interrupt: Interrupt, exit_evt_wrtube: SendTube, - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] gpu_control_tube: Tube, mem: GuestMemory, ctrl_queue: SharedQueueReader, @@ -870,7 +870,7 @@ struct Worker { } struct WorkerReturn { - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] gpu_control_tube: Tube, resource_bridges: ResourceBridges, event_devices: Vec, @@ -915,7 +915,7 @@ impl Worker { (&ctrl_evt, WorkerToken::CtrlQueue), (&cursor_evt, WorkerToken::CursorQueue), (&display_desc, WorkerToken::Display), - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] (&self.gpu_control_tube, WorkerToken::GpuControl), (&self.kill_evt, WorkerToken::Kill), #[cfg(windows)] @@ -1027,7 +1027,7 @@ impl Worker { error!("failed to receive ModifyWaitContext request.") } } - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] WorkerToken::GpuControl => { let req = match self.gpu_control_tube.recv() { Ok(req) => req, @@ -1110,10 +1110,10 @@ impl Worker { /// to use as fallbacks in case some do not work. #[derive(Clone)] pub enum DisplayBackend { - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] /// Use the wayland backend with the given socket path if given. Wayland(Option), - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] /// Open a connection to the X server at the given display if given. X(Option), /// Emulate a display without actually displaying it. @@ -1130,9 +1130,9 @@ impl DisplayBackend { #[cfg(windows)] gpu_display_wait_descriptor_ctrl: SendTube, ) -> std::result::Result { match self { - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] DisplayBackend::Wayland(path) => GpuDisplay::open_wayland(path.as_ref()), - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] DisplayBackend::X(display) => GpuDisplay::open_x(display.as_deref()), DisplayBackend::Stub => GpuDisplay::open_stub(), #[cfg(windows)] @@ -1163,7 +1163,7 @@ struct GpuActivationResources { pub struct Gpu { exit_evt_wrtube: SendTube, - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] gpu_control_tube: Option, mapper: Arc>>>, resource_bridges: Option, @@ -1199,7 +1199,7 @@ pub struct Gpu { /// context. gpu_display_wait_descriptor_ctrl_rd: Option, capset_mask: u64, - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] gpu_cgroup_path: Option, /// Used to differentiate worker kill events that are for shutdown vs sleep. `virtio_sleep` /// sets this to true while stopping the worker. @@ -1210,7 +1210,7 @@ pub struct Gpu { impl Gpu { pub fn new( exit_evt_wrtube: SendTube, - #[cfg(unix)] gpu_control_tube: Tube, + #[cfg(any(target_os = "android", target_os = "linux"))] gpu_control_tube: Tube, resource_bridges: Vec, display_backends: Vec, gpu_parameters: &GpuParameters, @@ -1219,7 +1219,7 @@ impl Gpu { base_features: u64, channels: &BTreeMap, #[cfg(windows)] wndproc_thread: WindowProcedureThread, - #[cfg(unix)] gpu_cgroup_path: Option<&PathBuf>, + #[cfg(any(target_os = "android", target_os = "linux"))] gpu_cgroup_path: Option<&PathBuf>, ) -> Gpu { let mut display_params = gpu_parameters.display_params.clone(); if display_params.is_empty() { @@ -1282,7 +1282,7 @@ impl Gpu { Gpu { exit_evt_wrtube, - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] gpu_control_tube: Some(gpu_control_tube), mapper: Arc::new(Mutex::new(None)), resource_bridges: Some(ResourceBridges::new(resource_bridges)), @@ -1306,7 +1306,7 @@ impl Gpu { #[cfg(windows)] gpu_display_wait_descriptor_ctrl_rd: Some(gpu_display_wait_descriptor_ctrl_rd), capset_mask: gpu_parameters.capset_mask, - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] gpu_cgroup_path: gpu_cgroup_path.cloned(), sleep_requested: Arc::new(AtomicBool::new(false)), worker_snapshot: None, @@ -1366,7 +1366,7 @@ impl Gpu { .context("error cloning exit tube") .unwrap(); - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] let gpu_control_tube = self .gpu_control_tube .take() @@ -1402,7 +1402,7 @@ impl Gpu { .take() .expect("failed to take gpu_display_wait_descriptor_ctrl_rd"); - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] let gpu_cgroup_path = self.gpu_cgroup_path.clone(); let mapper = Arc::clone(&self.mapper); @@ -1417,7 +1417,7 @@ impl Gpu { let sleep_requested = self.sleep_requested.clone(); let worker_thread = WorkerThread::start("v_gpu", move |kill_evt| { - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] if let Some(cgroup_path) = gpu_cgroup_path { move_task_to_cgroup(cgroup_path, base::gettid()) .expect("Failed to move v_gpu into requested cgroup"); @@ -1434,7 +1434,7 @@ impl Gpu { Err(e) => { error!("failed to build rutabaga {}", e); return WorkerReturn { - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] gpu_control_tube, resource_bridges, event_devices, @@ -1459,7 +1459,7 @@ impl Gpu { Some(backend) => backend, None => { return WorkerReturn { - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] gpu_control_tube, resource_bridges, event_devices, @@ -1483,7 +1483,7 @@ impl Gpu { // Other half of channel was dropped. Err(mpsc::RecvError) => { return WorkerReturn { - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] gpu_control_tube, resource_bridges, event_devices: virtio_gpu.display().borrow_mut().take_event_devices(), @@ -1504,7 +1504,7 @@ impl Gpu { let mut worker = Worker { interrupt: activation_resources.interrupt, exit_evt_wrtube, - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] gpu_control_tube, mem: activation_resources.mem, ctrl_queue: activation_resources.ctrl_queue, @@ -1565,7 +1565,7 @@ impl Gpu { None }; WorkerReturn { - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] gpu_control_tube: worker.gpu_control_tube, resource_bridges: worker.resource_bridges, event_devices, @@ -1640,7 +1640,7 @@ impl VirtioDevice for Gpu { // casting the underlying DMA buffer wrapped in File to a copyable RawDescriptor. // TODO(davidriley): Remove once virgl has another path to include // debugging logs. - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] if cfg!(debug_assertions) { keep_rds.push(libc::STDOUT_FILENO); keep_rds.push(libc::STDERR_FILENO); @@ -1658,7 +1658,7 @@ impl VirtioDevice for Gpu { keep_rds.push(self.exit_evt_wrtube.as_raw_descriptor()); - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] if let Some(gpu_control_tube) = &self.gpu_control_tube { keep_rds.push(gpu_control_tube.as_raw_descriptor()); } @@ -1802,7 +1802,7 @@ impl VirtioDevice for Gpu { self.sleep_requested.store(true, Ordering::SeqCst); drop(activate_tx); let WorkerReturn { - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] gpu_control_tube, resource_bridges, event_devices, @@ -1811,7 +1811,7 @@ impl VirtioDevice for Gpu { self.sleep_requested.store(false, Ordering::SeqCst); self.resource_bridges = Some(resource_bridges); - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] { self.gpu_control_tube = Some(gpu_control_tube); } diff --git a/devices/src/virtio/iommu/sys.rs b/devices/src/virtio/iommu/sys.rs index 4da523e79..0439bce94 100644 --- a/devices/src/virtio/iommu/sys.rs +++ b/devices/src/virtio/iommu/sys.rs @@ -3,7 +3,7 @@ // found in the LICENSE file. cfg_if::cfg_if! { - if #[cfg(unix)] { + if #[cfg(any(target_os = "android", target_os = "linux"))] { pub mod unix; use unix as platform; } else if #[cfg(windows)] { diff --git a/devices/src/virtio/mod.rs b/devices/src/virtio/mod.rs index 63ae054aa..892e82c8a 100644 --- a/devices/src/virtio/mod.rs +++ b/devices/src/virtio/mod.rs @@ -105,7 +105,7 @@ pub use self::virtio_pci_device::VirtioPciDevice; pub use self::virtio_pci_device::VirtioPciShmCap; cfg_if::cfg_if! { - if #[cfg(unix)] { + if #[cfg(any(target_os = "android", target_os = "linux"))] { mod p9; mod pmem; diff --git a/devices/src/virtio/net.rs b/devices/src/virtio/net.rs index c1385191d..99763d9a1 100644 --- a/devices/src/virtio/net.rs +++ b/devices/src/virtio/net.rs @@ -64,7 +64,7 @@ use super::VirtioDevice; pub(crate) const MAX_BUFFER_SIZE: usize = 65562; const QUEUE_SIZE: u16 = 256; -#[cfg(unix)] +#[cfg(any(target_os = "android", target_os = "linux"))] pub static VHOST_NET_DEFAULT_PATH: &str = "/dev/vhost-net"; pub(crate) use sys::process_rx; @@ -98,7 +98,7 @@ pub enum NetError { #[error("failed to read control message header: {0}")] ReadCtrlHeader(io::Error), /// There are no more available descriptors to receive into. - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] #[error("no rx descriptors available")] RxDescriptorsExhausted, /// Failure creating the Slirp loop. @@ -145,7 +145,7 @@ pub enum NetError { #[error("failed to write control message ack: {0}")] WriteAck(io::Error), /// Writing to a buffer in the guest failed. - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] #[error("failed to write to guest buffer: {0}")] WriteBuffer(io::Error), } @@ -171,12 +171,12 @@ pub enum NetParametersMode { }, } -#[cfg(unix)] +#[cfg(any(target_os = "android", target_os = "linux"))] fn vhost_net_device_path_default() -> PathBuf { PathBuf::from(VHOST_NET_DEFAULT_PATH) } -#[cfg(unix)] +#[cfg(any(target_os = "android", target_os = "linux"))] #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)] #[serde(rename_all = "kebab-case", deny_unknown_fields)] pub struct VhostNetParameters { @@ -184,7 +184,7 @@ pub struct VhostNetParameters { pub device: PathBuf, } -#[cfg(unix)] +#[cfg(any(target_os = "android", target_os = "linux"))] impl Default for VhostNetParameters { fn default() -> Self { Self { @@ -201,7 +201,7 @@ pub struct NetParameters { pub vq_pairs: Option, // Style-guide asks to refrain against #[cfg] directives in structs, this is an exception due // to the fact this struct is used for argument parsing. - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] pub vhost_net: Option, #[serde(default)] pub packed_queue: bool, @@ -401,7 +401,7 @@ where self.overlapped_wrapper.get_h_event_ref().unwrap(), Token::RxTap, ), - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] (self.tap.get_read_notifier(), Token::RxTap), (self.rx_queue.event(), Token::RxQueue), (self.tx_queue.event(), Token::TxQueue), @@ -906,7 +906,7 @@ mod tests { assert_eq!( params, NetParameters { - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] vhost_net: None, vq_pairs: None, mode: NetParametersMode::TapName { @@ -921,7 +921,7 @@ mod tests { assert_eq!( params, NetParameters { - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] vhost_net: None, vq_pairs: None, mode: NetParametersMode::TapName { @@ -936,7 +936,7 @@ mod tests { assert_eq!( params, NetParameters { - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] vhost_net: None, vq_pairs: None, mode: NetParametersMode::TapFd { @@ -951,7 +951,7 @@ mod tests { assert_eq!( params, NetParameters { - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] vhost_net: None, vq_pairs: None, mode: NetParametersMode::TapFd { @@ -969,7 +969,7 @@ mod tests { assert_eq!( params, NetParameters { - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] vhost_net: None, vq_pairs: None, mode: NetParametersMode::RawConfig { @@ -989,7 +989,7 @@ mod tests { } #[test] - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] fn params_from_key_values_vhost_net() { let params = from_net_arg( "vhost-net=[device=/dev/foo],\ @@ -1061,7 +1061,7 @@ mod tests { assert_eq!( params, NetParameters { - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] vhost_net: None, vq_pairs: None, mode: NetParametersMode::TapName { @@ -1076,7 +1076,7 @@ mod tests { assert_eq!( params, NetParameters { - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] vhost_net: None, vq_pairs: None, mode: NetParametersMode::TapName { diff --git a/devices/src/virtio/net/sys.rs b/devices/src/virtio/net/sys.rs index 1cdd7207a..d2670a59b 100644 --- a/devices/src/virtio/net/sys.rs +++ b/devices/src/virtio/net/sys.rs @@ -3,7 +3,7 @@ // found in the LICENSE file. cfg_if::cfg_if! { - if #[cfg(unix)] { + if #[cfg(any(target_os = "android", target_os = "linux"))] { mod unix; use unix as platform; } else if #[cfg(windows)] { diff --git a/devices/src/virtio/scsi/sys/mod.rs b/devices/src/virtio/scsi/sys/mod.rs index fab337166..bf716befb 100644 --- a/devices/src/virtio/scsi/sys/mod.rs +++ b/devices/src/virtio/scsi/sys/mod.rs @@ -3,7 +3,7 @@ // found in the LICENSE file. cfg_if::cfg_if! { - if #[cfg(unix)] { + if #[cfg(any(target_os = "android", target_os = "linux"))] { mod unix; } else if #[cfg(windows)] { mod windows; diff --git a/devices/src/virtio/snd/common_backend/async_funcs.rs b/devices/src/virtio/snd/common_backend/async_funcs.rs index 45deb57e7..3f8b453a3 100644 --- a/devices/src/virtio/snd/common_backend/async_funcs.rs +++ b/devices/src/virtio/snd/common_backend/async_funcs.rs @@ -376,7 +376,7 @@ async fn pcm_worker_loop( ); #[cfg(windows)] let buffer_writer = &mut buffer_writer_lock; - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] let (stream, buffer_writer) = ( &mut sys_direction_output.async_playback_buffer_stream, &mut sys_direction_output.buffer_writer, diff --git a/devices/src/virtio/snd/mod.rs b/devices/src/virtio/snd/mod.rs index 5498ea461..8f5d56659 100644 --- a/devices/src/virtio/snd/mod.rs +++ b/devices/src/virtio/snd/mod.rs @@ -13,7 +13,7 @@ pub mod file_backend; pub mod null_backend; cfg_if::cfg_if! { - if #[cfg(unix)] { + if #[cfg(any(target_os = "android", target_os = "linux"))] { pub mod vios_backend; pub use vios_backend::new_sound; diff --git a/devices/src/virtio/snd/sys/mod.rs b/devices/src/virtio/snd/sys/mod.rs index 498aff864..89aafa1e0 100644 --- a/devices/src/virtio/snd/sys/mod.rs +++ b/devices/src/virtio/snd/sys/mod.rs @@ -3,7 +3,7 @@ // found in the LICENSE file. cfg_if::cfg_if! { - if #[cfg(unix)] { + if #[cfg(any(target_os = "android", target_os = "linux"))] { mod unix; use unix as platform; } else if #[cfg(windows)] { diff --git a/devices/src/virtio/vhost/mod.rs b/devices/src/virtio/vhost/mod.rs index 67e9970b9..c74e0f400 100644 --- a/devices/src/virtio/vhost/mod.rs +++ b/devices/src/virtio/vhost/mod.rs @@ -9,7 +9,7 @@ use base::TubeError; use net_util::Error as TapError; use remain::sorted; use thiserror::Error; -#[cfg(unix)] +#[cfg(any(target_os = "android", target_os = "linux"))] use vhost::Error as VhostError; mod control_socket; @@ -18,7 +18,7 @@ pub mod user; pub use self::control_socket::*; cfg_if::cfg_if! { - if #[cfg(unix)] { + if #[cfg(any(target_os = "android", target_os = "linux"))] { #[cfg(feature = "net")] mod net; pub mod vsock; @@ -71,7 +71,7 @@ pub enum Error { #[error("failed to set vnet header size: {0}")] TapSetVnetHdrSize(TapError), /// Get features failed. - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] #[error("failed to get features: {0}")] VhostGetFeatures(VhostError), /// Vhost IOTLB required but not supported. @@ -84,51 +84,51 @@ pub enum Error { #[error("failed to read vhost event: {0}")] VhostIrqRead(SysError), /// Net set backend failed. - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] #[error("net set backend failed: {0}")] VhostNetSetBackend(VhostError), /// Failed to open vhost device. - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] #[error("failed to open vhost device: {0}")] VhostOpen(VhostError), /// Set features failed. - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] #[error("failed to set features: {0}")] VhostSetFeatures(VhostError), /// Set mem table failed. - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] #[error("failed to set mem table: {0}")] VhostSetMemTable(VhostError), /// Set owner failed. - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] #[error("failed to set owner: {0}")] VhostSetOwner(VhostError), /// Set vring addr failed. - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] #[error("failed to set vring addr: {0}")] VhostSetVringAddr(VhostError), /// Set vring base failed. - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] #[error("failed to set vring base: {0}")] VhostSetVringBase(VhostError), /// Set vring call failed. - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] #[error("failed to set vring call: {0}")] VhostSetVringCall(VhostError), /// Set vring kick failed. - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] #[error("failed to set vring kick: {0}")] VhostSetVringKick(VhostError), /// Set vring num failed. - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] #[error("failed to set vring num: {0}")] VhostSetVringNum(VhostError), /// Failed to set CID for guest. - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] #[error("failed to set CID for guest: {0}")] VhostVsockSetCid(VhostError), /// Failed to start vhost-vsock driver. - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] #[error("failed to start vhost-vsock driver: {0}")] VhostVsockStart(VhostError), #[error("queue missing vring base")] diff --git a/devices/src/virtio/vhost/user/device/block/sys.rs b/devices/src/virtio/vhost/user/device/block/sys.rs index 31e61259b..611487d38 100644 --- a/devices/src/virtio/vhost/user/device/block/sys.rs +++ b/devices/src/virtio/vhost/user/device/block/sys.rs @@ -3,7 +3,7 @@ // found in the LICENSE file. cfg_if::cfg_if! { - if #[cfg(unix)] { + if #[cfg(any(target_os = "android", target_os = "linux"))] { mod unix; use unix as platform; } else if #[cfg(windows)] { diff --git a/devices/src/virtio/vhost/user/device/fs/sys.rs b/devices/src/virtio/vhost/user/device/fs/sys.rs index de4269bc8..9f75a2308 100644 --- a/devices/src/virtio/vhost/user/device/fs/sys.rs +++ b/devices/src/virtio/vhost/user/device/fs/sys.rs @@ -3,7 +3,7 @@ // found in the LICENSE file. cfg_if::cfg_if! { - if #[cfg(unix)] { + if #[cfg(any(target_os = "android", target_os = "linux"))] { mod unix; use unix as platform; } else if #[cfg(windows)] { diff --git a/devices/src/virtio/vhost/user/device/gpu/sys.rs b/devices/src/virtio/vhost/user/device/gpu/sys.rs index d12b02985..12cd7597b 100644 --- a/devices/src/virtio/vhost/user/device/gpu/sys.rs +++ b/devices/src/virtio/vhost/user/device/gpu/sys.rs @@ -3,7 +3,7 @@ // found in the LICENSE file. cfg_if::cfg_if! { - if #[cfg(unix)] { + if #[cfg(any(target_os = "android", target_os = "linux"))] { pub mod unix; use unix as platform; } else if #[cfg(windows)] { diff --git a/devices/src/virtio/vhost/user/device/handler.rs b/devices/src/virtio/vhost/user/device/handler.rs index aa72f406e..7c0e7ac71 100644 --- a/devices/src/virtio/vhost/user/device/handler.rs +++ b/devices/src/virtio/vhost/user/device/handler.rs @@ -51,13 +51,13 @@ use std::collections::BTreeMap; use std::convert::From; use std::fs::File; use std::num::Wrapping; -#[cfg(unix)] +#[cfg(any(target_os = "android", target_os = "linux"))] use std::os::unix::io::AsRawFd; use std::sync::Arc; use anyhow::bail; use anyhow::Context; -#[cfg(unix)] +#[cfg(any(target_os = "android", target_os = "linux"))] use base::clear_fd_flags; use base::error; use base::Event; @@ -360,7 +360,7 @@ impl VhostUserPlatformOps for VhostUserRegularOps { // Remove O_NONBLOCK from kick_fd. Otherwise, uring_executor will fails when we read // values via `next_val()` later. // This is only required (and can only be done) on Unix platforms. - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] if let Err(e) = clear_fd_flags(file.as_raw_fd(), libc::O_NONBLOCK) { error!("failed to remove O_NONBLOCK for kick fd: {}", e); return Err(VhostError::InvalidParam); diff --git a/devices/src/virtio/vhost/user/device/handler/sys.rs b/devices/src/virtio/vhost/user/device/handler/sys.rs index 9e87ad0cd..eb05c6134 100644 --- a/devices/src/virtio/vhost/user/device/handler/sys.rs +++ b/devices/src/virtio/vhost/user/device/handler/sys.rs @@ -3,7 +3,7 @@ // found in the LICENSE file. cfg_if::cfg_if! { - if #[cfg(unix)] { + if #[cfg(any(target_os = "android", target_os = "linux"))] { pub mod unix; #[cfg(test)] pub use unix::test_helpers; diff --git a/devices/src/virtio/vhost/user/device/listener/sys.rs b/devices/src/virtio/vhost/user/device/listener/sys.rs index a0f40a204..4137daf3b 100644 --- a/devices/src/virtio/vhost/user/device/listener/sys.rs +++ b/devices/src/virtio/vhost/user/device/listener/sys.rs @@ -3,7 +3,7 @@ // found in the LICENSE file. cfg_if::cfg_if! { - if #[cfg(unix)] { + if #[cfg(any(target_os = "android", target_os = "linux"))] { pub mod unix; use unix as platform; } else if #[cfg(windows)] { diff --git a/devices/src/virtio/vhost/user/device/mod.rs b/devices/src/virtio/vhost/user/device/mod.rs index 7b013fda1..75cebecbd 100644 --- a/devices/src/virtio/vhost/user/device/mod.rs +++ b/devices/src/virtio/vhost/user/device/mod.rs @@ -38,7 +38,7 @@ pub use snd::Options as SndOptions; use vmm_vhost::VhostUserSlaveReqHandler; cfg_if::cfg_if! { - if #[cfg(unix)] { + if #[cfg(any(target_os = "android", target_os = "linux"))] { mod console; mod fs; mod vsock; diff --git a/devices/src/virtio/vhost/user/device/net/sys.rs b/devices/src/virtio/vhost/user/device/net/sys.rs index 7e780a894..f6e029a35 100644 --- a/devices/src/virtio/vhost/user/device/net/sys.rs +++ b/devices/src/virtio/vhost/user/device/net/sys.rs @@ -3,7 +3,7 @@ // found in the LICENSE file. cfg_if::cfg_if! { - if #[cfg(unix)] { + if #[cfg(any(target_os = "android", target_os = "linux"))] { pub mod unix; use unix as platform; } else if #[cfg(windows)] { diff --git a/devices/src/virtio/vhost/user/device/snd/sys.rs b/devices/src/virtio/vhost/user/device/snd/sys.rs index c75e89c32..3564f558d 100644 --- a/devices/src/virtio/vhost/user/device/snd/sys.rs +++ b/devices/src/virtio/vhost/user/device/snd/sys.rs @@ -3,7 +3,7 @@ // found in the LICENSE file. cfg_if::cfg_if! { - if #[cfg(unix)] { + if #[cfg(any(target_os = "android", target_os = "linux"))] { pub mod unix; use unix as platform; } else if #[cfg(windows)] { diff --git a/devices/src/virtio/vhost/user/vmm/handler/sys.rs b/devices/src/virtio/vhost/user/vmm/handler/sys.rs index af095a4f8..3a6cee3f2 100644 --- a/devices/src/virtio/vhost/user/vmm/handler/sys.rs +++ b/devices/src/virtio/vhost/user/vmm/handler/sys.rs @@ -3,7 +3,7 @@ // found in the LICENSE file. cfg_if::cfg_if! { - if #[cfg(unix)] { + if #[cfg(any(target_os = "android", target_os = "linux"))] { mod unix; pub(super) use self::unix::*; use unix as platform; diff --git a/devices/src/virtio/vhost/user/vmm/mod.rs b/devices/src/virtio/vhost/user/vmm/mod.rs index e85ab4941..543f9c42e 100644 --- a/devices/src/virtio/vhost/user/vmm/mod.rs +++ b/devices/src/virtio/vhost/user/vmm/mod.rs @@ -25,7 +25,7 @@ use vmm_vhost::Error as VhostError; pub use self::handler::VhostUserHandler; cfg_if::cfg_if! { - if #[cfg(unix)] { + if #[cfg(any(target_os = "android", target_os = "linux"))] { pub type Connection = std::os::unix::net::UnixStream; } else if #[cfg(windows)] { pub type Connection = base::Tube; diff --git a/devices/src/virtio/vsock/sys.rs b/devices/src/virtio/vsock/sys.rs index 16eb60f4d..21c9c017d 100644 --- a/devices/src/virtio/vsock/sys.rs +++ b/devices/src/virtio/vsock/sys.rs @@ -3,7 +3,7 @@ // found in the LICENSE file. cfg_if::cfg_if! { - if #[cfg(unix)] { + if #[cfg(any(target_os = "android", target_os = "linux"))] { mod unix; use unix as platform; pub use crate::virtio::vhost::Vsock; diff --git a/devices/src/virtio/vsock/sys/unix.rs b/devices/src/virtio/vsock/sys/unix.rs index 291ecb77c..3f9614f45 100644 --- a/devices/src/virtio/vsock/sys/unix.rs +++ b/devices/src/virtio/vsock/sys/unix.rs @@ -33,7 +33,7 @@ impl VsockConfig { pub fn new>(cid: u64, vhost_device: Option

) -> Self { Self { cid, - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] vhost_device: vhost_device .map(|p| PathBuf::from(p.as_ref())) .unwrap_or_else(|| PathBuf::from(VHOST_VSOCK_DEFAULT_PATH)), @@ -77,7 +77,7 @@ mod tests { assert_eq!( from_vsock_arg("78").unwrap(), VsockConfig { - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] vhost_device: VHOST_VSOCK_DEFAULT_PATH.into(), cid: 78, } diff --git a/devices/tests/irqchip/kvm/mod.rs b/devices/tests/irqchip/kvm/mod.rs index 73e5afed9..d816cf566 100644 --- a/devices/tests/irqchip/kvm/mod.rs +++ b/devices/tests/irqchip/kvm/mod.rs @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#![cfg(unix)] +#![cfg(any(target_os = "android", target_os = "linux"))] mod x86_64; diff --git a/devices/tests/irqchip/userspace.rs b/devices/tests/irqchip/userspace.rs index b4682e07b..5166f0b47 100644 --- a/devices/tests/irqchip/userspace.rs +++ b/devices/tests/irqchip/userspace.rs @@ -669,7 +669,7 @@ impl Vcpu for FakeVcpu { fn set_immediate_exit(&self, _exit: bool) {} - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] fn signal_handle(&self) -> hypervisor::VcpuSignalHandle { unimplemented!() } diff --git a/disk/src/sys.rs b/disk/src/sys.rs index 3d1506981..dc5fc7e8d 100644 --- a/disk/src/sys.rs +++ b/disk/src/sys.rs @@ -3,7 +3,7 @@ // found in the LICENSE file. cfg_if::cfg_if! { - if #[cfg(unix)] { + if #[cfg(any(target_os = "android", target_os = "linux"))] { pub mod unix; use unix as platform; } else if #[cfg(windows)] { diff --git a/docs/book/src/contributing/style_guide_platform_specific_code.md b/docs/book/src/contributing/style_guide_platform_specific_code.md index 9cd843660..de61102cd 100644 --- a/docs/book/src/contributing/style_guide_platform_specific_code.md +++ b/docs/book/src/contributing/style_guide_platform_specific_code.md @@ -125,7 +125,7 @@ File: `sys.rs` ```rust cfg_if::cfg_if! { - if #[cfg(unix)] { + if #[cfg(any(target_os = "android", target_os = "linux"))] { mod unix; pub use platform_print::UnixPrinter as Printer; } else if #[cfg(windows)] { @@ -137,13 +137,14 @@ cfg_if::cfg_if! { ## Imports -When conditionally importing and using modules, use `cfg(unix)` and `cfg(windows)` for describing -the platform. Order imports such that common comes first followed by unix and windows dependencies. +When conditionally importing and using modules, use +`cfg(any(target_os = "android", target_os = "linux"))` and `cfg(windows)` for describing the +platform. Order imports such that common comes first followed by unix and windows dependencies. ```rust // All other imports -#[cfg(unix)] +#[cfg(any(target_os = "android", target_os = "linux"))] use { std::x::y, base::a::b::{Foo, Bar}, @@ -394,7 +395,7 @@ File: `sys.rs` ```rust cfg_if::cfg_if! { - if #[cfg(unix)] { + if #[cfg(any(target_os = "android", target_os = "linux"))] { pub mod unix; use unix as platform; } else if #[cfg(windows)] { @@ -441,7 +442,7 @@ use mylib::sys::print; fn my_print() { print(); - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] mylib::sys::unix::print_u8(1); #[cfg(windows)] diff --git a/e2e_tests/fixture/src/sys.rs b/e2e_tests/fixture/src/sys.rs index 9264a5200..93209e916 100644 --- a/e2e_tests/fixture/src/sys.rs +++ b/e2e_tests/fixture/src/sys.rs @@ -3,7 +3,7 @@ // found in the LICENSE file. cfg_if::cfg_if! { - if #[cfg(unix)] { + if #[cfg(any(target_os = "android", target_os = "linux"))] { pub(super) mod unix; use unix as platform; } else if #[cfg(windows)] { diff --git a/e2e_tests/fixture/src/utils.rs b/e2e_tests/fixture/src/utils.rs index 7cea5b033..762c379fb 100644 --- a/e2e_tests/fixture/src/utils.rs +++ b/e2e_tests/fixture/src/utils.rs @@ -6,7 +6,7 @@ use std::env; use std::io::ErrorKind; -#[cfg(unix)] +#[cfg(any(target_os = "android", target_os = "linux"))] use std::os::unix::process::ExitStatusExt; use std::path::Path; use std::path::PathBuf; @@ -126,7 +126,7 @@ impl CommandExt for Command { if let Some(code) = output.status.code() { return Err(CommandError::ErrorCode(code)); } else { - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] if let Some(signal) = output.status.signal() { return Err(CommandError::Signal(signal)); } diff --git a/e2e_tests/guest_under_test/rootfs/delegate/src/main.rs b/e2e_tests/guest_under_test/rootfs/delegate/src/main.rs index bb9b6b58f..b5f4bc4e3 100644 --- a/e2e_tests/guest_under_test/rootfs/delegate/src/main.rs +++ b/e2e_tests/guest_under_test/rootfs/delegate/src/main.rs @@ -9,7 +9,7 @@ mod wire_format; use std::fs::File; use std::io; use std::io::prelude::*; -#[cfg(unix)] +#[cfg(any(target_os = "android", target_os = "linux"))] use std::os::unix::process::ExitStatusExt; use std::path::Path; use std::process::Command; @@ -53,7 +53,7 @@ fn listen( stderr: String::from_utf8_lossy(&result.stderr).into_owned(), exit_status: match result.status.code() { Some(code) => wire_format::ExitStatus::Code(code), - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] None => match result.status.signal() { Some(signal) => wire_format::ExitStatus::Signal(signal), None => wire_format::ExitStatus::None, diff --git a/e2e_tests/tests/block.rs b/e2e_tests/tests/block.rs index 7b9d79ad8..edf6e74c4 100644 --- a/e2e_tests/tests/block.rs +++ b/e2e_tests/tests/block.rs @@ -4,7 +4,7 @@ //! Testing virtio-block. -#![cfg(unix)] +#![cfg(any(target_os = "android", target_os = "linux"))] use std::time; diff --git a/e2e_tests/tests/boot.rs b/e2e_tests/tests/boot.rs index 405a9f6c9..14d98ce73 100644 --- a/e2e_tests/tests/boot.rs +++ b/e2e_tests/tests/boot.rs @@ -44,21 +44,21 @@ fn boot_test_vm_uring() -> anyhow::Result<()> { Ok(()) } -#[cfg(unix)] +#[cfg(any(target_os = "android", target_os = "linux"))] #[test] fn boot_test_vm_odirect() { let mut vm = TestVm::new(Config::new().o_direct()).unwrap(); assert_eq!(vm.exec_in_guest("echo 42").unwrap().stdout.trim(), "42"); } -#[cfg(unix)] +#[cfg(any(target_os = "android", target_os = "linux"))] #[test] fn boot_test_vm_config_file() { let mut vm = TestVm::new_with_config_file(Config::new()).unwrap(); assert_eq!(vm.exec_in_guest("echo 42").unwrap().stdout.trim(), "42"); } -#[cfg(unix)] +#[cfg(any(target_os = "android", target_os = "linux"))] #[test] fn boot_test_suspend_resume() { // There is no easy way for us to check if the VM is actually suspended. But at @@ -69,7 +69,7 @@ fn boot_test_suspend_resume() { assert_eq!(vm.exec_in_guest("echo 42").unwrap().stdout.trim(), "42"); } -#[cfg(unix)] +#[cfg(any(target_os = "android", target_os = "linux"))] #[test] fn boot_test_suspend_resume_full() { // There is no easy way for us to check if the VM is actually suspended. But at @@ -88,28 +88,28 @@ fn boot_test_suspend_resume_full() { assert_eq!(vm.exec_in_guest("echo 42").unwrap().stdout.trim(), "42"); } -#[cfg(unix)] +#[cfg(any(target_os = "android", target_os = "linux"))] #[test] fn boot_test_vm_disable_sandbox() { let mut vm = TestVm::new(Config::new().disable_sandbox()).unwrap(); assert_eq!(vm.exec_in_guest("echo 42").unwrap().stdout.trim(), "42"); } -#[cfg(unix)] +#[cfg(any(target_os = "android", target_os = "linux"))] #[test] fn boot_test_vm_disable_sandbox_odirect() { let mut vm = TestVm::new(Config::new().disable_sandbox().o_direct()).unwrap(); assert_eq!(vm.exec_in_guest("echo 42").unwrap().stdout.trim(), "42"); } -#[cfg(unix)] +#[cfg(any(target_os = "android", target_os = "linux"))] #[test] fn boot_test_vm_disable_sandbox_config_file() { let mut vm = TestVm::new_with_config_file(Config::new().disable_sandbox()).unwrap(); assert_eq!(vm.exec_in_guest("echo 42").unwrap().stdout.trim(), "42"); } -#[cfg(unix)] +#[cfg(any(target_os = "android", target_os = "linux"))] #[test] fn boot_test_disable_sandbox_suspend_resume() { // There is no easy way for us to check if the VM is actually suspended. But at diff --git a/e2e_tests/tests/fs.rs b/e2e_tests/tests/fs.rs index 358c8eaca..4d273eaee 100644 --- a/e2e_tests/tests/fs.rs +++ b/e2e_tests/tests/fs.rs @@ -56,7 +56,7 @@ fn copy_file() { /// 3. Start a VM with a virtiofs device for the temporal directory. /// 4. Check that `user_file.txt`'s uid is in the VM. /// 5. Verify gid similarly. -#[cfg(unix)] +#[cfg(any(target_os = "android", target_os = "linux"))] #[test] fn file_ugid() { const FILE_NAME: &str = "user_file.txt"; diff --git a/e2e_tests/tests/suspend_resume.rs b/e2e_tests/tests/suspend_resume.rs index 677c7059d..f33eb1bbd 100644 --- a/e2e_tests/tests/suspend_resume.rs +++ b/e2e_tests/tests/suspend_resume.rs @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#![cfg(unix)] +#![cfg(any(target_os = "android", target_os = "linux"))] use std::io::Write; use std::path::Path; diff --git a/e2e_tests/tests/swap.rs b/e2e_tests/tests/swap.rs index 5b33b81c2..7f05d83cc 100644 --- a/e2e_tests/tests/swap.rs +++ b/e2e_tests/tests/swap.rs @@ -4,7 +4,7 @@ //! Testing vmm-swap -#![cfg(unix)] +#![cfg(any(target_os = "android", target_os = "linux"))] use std::time::Duration; use std::time::Instant; diff --git a/e2e_tests/tests/vsock.rs b/e2e_tests/tests/vsock.rs index eb163e03f..dd314a931 100644 --- a/e2e_tests/tests/vsock.rs +++ b/e2e_tests/tests/vsock.rs @@ -4,7 +4,7 @@ //! Testing vsock. -#![cfg(unix)] +#![cfg(any(target_os = "android", target_os = "linux"))] use std::io::Write; use std::path::Path; diff --git a/fuse/src/lib.rs b/fuse/src/lib.rs index 95e4b2c56..6fe9c437b 100644 --- a/fuse/src/lib.rs +++ b/fuse/src/lib.rs @@ -4,7 +4,7 @@ //! FUSE (Filesystem in Userspace) server and filesystem mounting support. -#![cfg(unix)] +#![cfg(any(target_os = "android", target_os = "linux"))] use std::ffi::FromBytesWithNulError; use std::fs::File; diff --git a/fuzz/fuzz_targets/fs_server_fuzzer.rs b/fuzz/fuzz_targets/fs_server_fuzzer.rs index f6067190c..c49f9bf82 100644 --- a/fuzz/fuzz_targets/fs_server_fuzzer.rs +++ b/fuzz/fuzz_targets/fs_server_fuzzer.rs @@ -5,7 +5,7 @@ #![cfg(not(test))] #![no_main] -#[cfg(unix)] +#[cfg(any(target_os = "android", target_os = "linux"))] mod fuzzer { use std::convert::TryInto; diff --git a/fuzz/fuzz_targets/p9_tframe_fuzzer.rs b/fuzz/fuzz_targets/p9_tframe_fuzzer.rs index 5b86b71e3..d776a3ad4 100644 --- a/fuzz/fuzz_targets/p9_tframe_fuzzer.rs +++ b/fuzz/fuzz_targets/p9_tframe_fuzzer.rs @@ -9,6 +9,6 @@ use crosvm_fuzz::fuzz_target; fuzz_target!(|bytes: &[u8]| { - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] p9::fuzzing::tframe_decode(bytes); }); diff --git a/gpu_display/examples/simple.rs b/gpu_display/examples/simple.rs index 27ed9adb1..f82aba378 100644 --- a/gpu_display/examples/simple.rs +++ b/gpu_display/examples/simple.rs @@ -4,7 +4,7 @@ use std::process::exit; -#[cfg(unix)] +#[cfg(any(target_os = "android", target_os = "linux"))] mod platform { use anyhow::Context; use anyhow::Result; diff --git a/gpu_display/src/lib.rs b/gpu_display/src/lib.rs index c8877d7cf..b350f5757 100644 --- a/gpu_display/src/lib.rs +++ b/gpu_display/src/lib.rs @@ -24,7 +24,7 @@ mod event_device; mod gpu_display_stub; #[cfg(windows)] mod gpu_display_win; -#[cfg(unix)] +#[cfg(any(target_os = "android", target_os = "linux"))] mod gpu_display_wl; #[cfg(feature = "x")] mod gpu_display_x; diff --git a/gpu_display/src/sys/mod.rs b/gpu_display/src/sys/mod.rs index 87334126d..0df919e49 100644 --- a/gpu_display/src/sys/mod.rs +++ b/gpu_display/src/sys/mod.rs @@ -3,7 +3,7 @@ // found in the LICENSE file. cfg_if::cfg_if! { - if #[cfg(unix)] { + if #[cfg(any(target_os = "android", target_os = "linux"))] { pub(crate) mod unix; pub use unix::UnixGpuDisplayExt as SysGpuDisplayExt; pub(crate) use unix::UnixDisplayT as SysDisplayT; diff --git a/hypervisor/Cargo.toml b/hypervisor/Cargo.toml index e8cbf777e..8df30b760 100644 --- a/hypervisor/Cargo.toml +++ b/hypervisor/Cargo.toml @@ -31,7 +31,7 @@ sync = { path = "../common/sync" } base = { path = "../base" } vm_memory = { path = "../vm_memory" } -[target.'cfg(unix)'.dependencies] +[target.'cfg(any(target_os = "android", target_os = "linux"))'.dependencies] kvm = { path = "../kvm" } kvm_sys = { path = "../kvm_sys" } diff --git a/hypervisor/src/geniezone/geniezone_sys/mod.rs b/hypervisor/src/geniezone/geniezone_sys/mod.rs index 1fb8c066a..0a9c57e37 100644 --- a/hypervisor/src/geniezone/geniezone_sys/mod.rs +++ b/hypervisor/src/geniezone/geniezone_sys/mod.rs @@ -4,7 +4,7 @@ //! Bindings for the GZVM (Geniezone Hypervisor) API. -#![cfg(unix)] +#![cfg(any(target_os = "android", target_os = "linux"))] #![allow(non_upper_case_globals)] #![allow(non_camel_case_types)] #![allow(non_snake_case)] diff --git a/hypervisor/src/haxm.rs b/hypervisor/src/haxm.rs index 12d28f558..8492a99f0 100644 --- a/hypervisor/src/haxm.rs +++ b/hypervisor/src/haxm.rs @@ -35,9 +35,9 @@ mod win; #[cfg(windows)] use win::*; -#[cfg(unix)] +#[cfg(any(target_os = "android", target_os = "linux"))] mod unix; -#[cfg(unix)] +#[cfg(any(target_os = "android", target_os = "linux"))] use unix::*; static USE_GHAXM: AtomicBool = AtomicBool::new(true); diff --git a/hypervisor/src/haxm/haxm_sys.rs b/hypervisor/src/haxm/haxm_sys.rs index 1c28f9175..9f1431f9d 100644 --- a/hypervisor/src/haxm/haxm_sys.rs +++ b/hypervisor/src/haxm/haxm_sys.rs @@ -22,7 +22,7 @@ mod win; #[cfg(windows)] pub use win::*; -#[cfg(unix)] +#[cfg(any(target_os = "android", target_os = "linux"))] mod posix; -#[cfg(unix)] +#[cfg(any(target_os = "android", target_os = "linux"))] pub use posix::*; diff --git a/hypervisor/src/lib.rs b/hypervisor/src/lib.rs index 06683d031..9e2c959b0 100644 --- a/hypervisor/src/lib.rs +++ b/hypervisor/src/lib.rs @@ -15,7 +15,7 @@ pub mod caps; pub mod gunyah; #[cfg(all(windows, feature = "haxm"))] pub mod haxm; -#[cfg(unix)] +#[cfg(any(target_os = "android", target_os = "linux"))] pub mod kvm; #[cfg(target_arch = "riscv64")] pub mod riscv64; @@ -235,12 +235,12 @@ pub struct IoParams { } /// Handle to a virtual CPU that may be used to request a VM exit from within a signal handler. -#[cfg(unix)] +#[cfg(any(target_os = "android", target_os = "linux"))] pub struct VcpuSignalHandle { inner: Box, } -#[cfg(unix)] +#[cfg(any(target_os = "android", target_os = "linux"))] impl VcpuSignalHandle { /// Request an immediate exit for this VCPU. /// @@ -253,7 +253,7 @@ impl VcpuSignalHandle { /// Signal-safe mechanism for requesting an immediate VCPU exit. /// /// Each hypervisor backend must implement this for its VCPU type. -#[cfg(unix)] +#[cfg(any(target_os = "android", target_os = "linux"))] pub(crate) trait VcpuSignalHandleInner { /// Signal the associated VCPU to exit if it is currently running. /// @@ -286,7 +286,7 @@ pub trait Vcpu: downcast_rs::DowncastSync { /// Returns a handle that can be used to cause this VCPU to exit from `run()` from a signal /// handler. - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] fn signal_handle(&self) -> VcpuSignalHandle; /// Handles an incoming MMIO request from the guest. diff --git a/hypervisor/tests/dirty_log.rs b/hypervisor/tests/dirty_log.rs index 4d9c4639a..8a2cba610 100644 --- a/hypervisor/tests/dirty_log.rs +++ b/hypervisor/tests/dirty_log.rs @@ -3,7 +3,7 @@ // found in the LICENSE file. // TODO(b/237714823): Currently, only kvm is enabled for this test once LUCI can run windows. -#![cfg(unix)] +#![cfg(any(target_os = "android", target_os = "linux"))] #![cfg(target_arch = "x86_64")] #![cfg(any(feature = "whpx", feature = "gvm", feature = "haxm", unix))] @@ -14,7 +14,7 @@ use vm_memory::GuestAddress; use vm_memory::GuestMemory; #[test] -#[cfg(unix)] +#[cfg(any(target_os = "android", target_os = "linux"))] fn test_kvm_dirty_log() { use hypervisor::kvm::*; test_dirty_log(|guest_mem| { diff --git a/hypervisor/tests/kvm/main.rs b/hypervisor/tests/kvm/main.rs index e970d4884..e4ebc2003 100644 --- a/hypervisor/tests/kvm/main.rs +++ b/hypervisor/tests/kvm/main.rs @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#![cfg(unix)] +#![cfg(any(target_os = "android", target_os = "linux"))] #[cfg(any(target_arch = "arm", target_arch = "aarch64"))] mod aarch64; diff --git a/hypervisor/tests/mmio_and_pio.rs b/hypervisor/tests/mmio_and_pio.rs index 3ad2daa01..2bf748b0f 100644 --- a/hypervisor/tests/mmio_and_pio.rs +++ b/hypervisor/tests/mmio_and_pio.rs @@ -3,7 +3,7 @@ // found in the LICENSE file. // TODO(b/237714823): Currently, only kvm is enabled for this test once LUCI can run windows. -#![cfg(unix)] +#![cfg(any(target_os = "android", target_os = "linux"))] #![cfg(target_arch = "x86_64")] use std::sync::atomic::AtomicU16; @@ -14,7 +14,7 @@ use vm_memory::GuestAddress; use vm_memory::GuestMemory; #[test] -#[cfg(unix)] +#[cfg(any(target_os = "android", target_os = "linux"))] fn test_kvm_mmio_and_pio() { use hypervisor::kvm::*; test_mmio_and_pio(|guest_mem| { diff --git a/hypervisor/tests/read_only_memory.rs b/hypervisor/tests/read_only_memory.rs index 1435380ff..6610f9459 100644 --- a/hypervisor/tests/read_only_memory.rs +++ b/hypervisor/tests/read_only_memory.rs @@ -3,7 +3,7 @@ // found in the LICENSE file. // TODO(b/237714823): Currently, only kvm is enabled for this test once LUCI can run windows. -#![cfg(unix)] +#![cfg(any(target_os = "android", target_os = "linux"))] #![cfg(target_arch = "x86_64")] use std::sync::atomic::AtomicU16; @@ -16,7 +16,7 @@ use vm_memory::GuestAddress; use vm_memory::GuestMemory; #[test] -#[cfg(unix)] +#[cfg(any(target_os = "android", target_os = "linux"))] fn test_kvm_read_only_memory() { use hypervisor::kvm::*; test_read_only_memory(|guest_mem| { diff --git a/hypervisor/tests/real_run_addr.rs b/hypervisor/tests/real_run_addr.rs index 8b2ef10d4..ec3f05071 100644 --- a/hypervisor/tests/real_run_addr.rs +++ b/hypervisor/tests/real_run_addr.rs @@ -3,7 +3,7 @@ // found in the LICENSE file. // TODO(b/237714823): Currently, only kvm is enabled for this test once LUCI can run windows. -#![cfg(unix)] +#![cfg(any(target_os = "android", target_os = "linux"))] #![cfg(target_arch = "x86_64")] use hypervisor::*; @@ -12,7 +12,7 @@ use vm_memory::GuestAddress; use vm_memory::GuestMemory; #[test] -#[cfg(unix)] +#[cfg(any(target_os = "android", target_os = "linux"))] fn test_kvm_real_run_addr() { use hypervisor::kvm::*; test_real_run_addr(|guest_mem| { diff --git a/hypervisor/tests/remove_memory.rs b/hypervisor/tests/remove_memory.rs index e8fcd8b0e..4ca5fcc5a 100644 --- a/hypervisor/tests/remove_memory.rs +++ b/hypervisor/tests/remove_memory.rs @@ -3,7 +3,7 @@ // found in the LICENSE file. // TODO(b/237714823): Currently, only kvm is enabled for this test once LUCI can run windows. -#![cfg(unix)] +#![cfg(any(target_os = "android", target_os = "linux"))] #![cfg(target_arch = "x86_64")] use base::MemoryMappingBuilder; @@ -13,7 +13,7 @@ use vm_memory::GuestAddress; use vm_memory::GuestMemory; #[test] -#[cfg(unix)] +#[cfg(any(target_os = "android", target_os = "linux"))] fn test_kvm_remove_memory() { use hypervisor::kvm::*; test_remove_memory(|guest_mem| { diff --git a/hypervisor/tests/tsc_offsets.rs b/hypervisor/tests/tsc_offsets.rs index e75e0374e..1f4e9d333 100644 --- a/hypervisor/tests/tsc_offsets.rs +++ b/hypervisor/tests/tsc_offsets.rs @@ -3,7 +3,7 @@ // found in the LICENSE file. // TODO(b/237714823): Currently, only kvm is enabled for this test once LUCI can run windows. -#![cfg(unix)] +#![cfg(any(target_os = "android", target_os = "linux"))] #![cfg(target_arch = "x86_64")] use std::arch::x86_64::_rdtsc; @@ -28,7 +28,7 @@ macro_rules! assert_wrapping_close { } #[test] -#[cfg(unix)] +#[cfg(any(target_os = "android", target_os = "linux"))] fn test_kvm_tsc_offsets() { use hypervisor::kvm::*; test_tsc_offsets(|guest_mem| { diff --git a/io_uring/src/lib.rs b/io_uring/src/lib.rs index 54c77348f..ea8c59298 100644 --- a/io_uring/src/lib.rs +++ b/io_uring/src/lib.rs @@ -4,7 +4,7 @@ //! Safe wrapper over the Linux `io_uring` system calls. -#![cfg(unix)] +#![cfg(any(target_os = "android", target_os = "linux"))] mod bindings; mod syscalls; diff --git a/io_uring/tests/uring.rs b/io_uring/tests/uring.rs index 2b2c64013..406aff01d 100644 --- a/io_uring/tests/uring.rs +++ b/io_uring/tests/uring.rs @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#![cfg(unix)] +#![cfg(any(target_os = "android", target_os = "linux"))] use std::collections::BTreeSet; use std::fs::File; diff --git a/jail/Cargo.toml b/jail/Cargo.toml index bb2b179f9..6b1353f25 100644 --- a/jail/Cargo.toml +++ b/jail/Cargo.toml @@ -17,7 +17,7 @@ serde_keyvalue = { path = "../serde_keyvalue", features = ["argh_derive"] } static_assertions = "*" zerocopy = { version = "0.7", features = ["derive"] } -[target.'cfg(unix)'.dependencies] +[target.'cfg(any(target_os = "android", target_os = "linux"))'.dependencies] minijail = "*" [build-dependencies] diff --git a/jail/src/config.rs b/jail/src/config.rs index cb19450ef..681db29a3 100644 --- a/jail/src/config.rs +++ b/jail/src/config.rs @@ -17,7 +17,7 @@ fn jail_config_default_pivot_root() -> PathBuf { pub struct JailConfig { #[serde(default = "jail_config_default_pivot_root")] pub pivot_root: PathBuf, - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] #[serde(default)] pub seccomp_policy_dir: Option, #[serde(default)] @@ -28,7 +28,7 @@ impl Default for JailConfig { fn default() -> Self { JailConfig { pivot_root: jail_config_default_pivot_root(), - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] seccomp_policy_dir: None, seccomp_log_failures: false, } @@ -48,7 +48,7 @@ mod tests { config, JailConfig { pivot_root: jail_config_default_pivot_root(), - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] seccomp_policy_dir: None, seccomp_log_failures: false, } @@ -67,7 +67,7 @@ mod tests { ); cfg_if::cfg_if! { - if #[cfg(unix)] { + if #[cfg(any(target_os = "android", target_os = "linux"))] { let config: JailConfig = from_key_values("seccomp-policy-dir=/path/to/seccomp/dir").unwrap(); assert_eq!(config, JailConfig { diff --git a/jail/src/lib.rs b/jail/src/lib.rs index 6f3a4dd9f..97316dee1 100644 --- a/jail/src/lib.rs +++ b/jail/src/lib.rs @@ -3,11 +3,11 @@ // found in the LICENSE file. mod config; -#[cfg(unix)] +#[cfg(any(target_os = "android", target_os = "linux"))] mod helpers; pub use crate::config::JailConfig; -#[cfg(unix)] +#[cfg(any(target_os = "android", target_os = "linux"))] pub use crate::helpers::*; // TODO(b/268407006): We define Minijail as an empty struct as a stub for minijail::Minijail on diff --git a/kvm/src/lib.rs b/kvm/src/lib.rs index 66d16e8e9..e71373933 100644 --- a/kvm/src/lib.rs +++ b/kvm/src/lib.rs @@ -6,7 +6,7 @@ //! //! New code should use the `hypervisor` crate instead. -#![cfg(unix)] +#![cfg(any(target_os = "android", target_os = "linux"))] mod cap; diff --git a/kvm/tests/dirty_log.rs b/kvm/tests/dirty_log.rs index 485282aa6..1273b0b8f 100644 --- a/kvm/tests/dirty_log.rs +++ b/kvm/tests/dirty_log.rs @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#![cfg(unix)] +#![cfg(any(target_os = "android", target_os = "linux"))] #![cfg(target_arch = "x86_64")] use base::MemoryMappingBuilder; diff --git a/kvm/tests/kvm_tests.rs b/kvm/tests/kvm_tests.rs index 3c7387b57..1b79bcc4e 100644 --- a/kvm/tests/kvm_tests.rs +++ b/kvm/tests/kvm_tests.rs @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#![cfg(unix)] +#![cfg(any(target_os = "android", target_os = "linux"))] use base::pagesize; use base::Event; diff --git a/kvm/tests/read_only_memory.rs b/kvm/tests/read_only_memory.rs index 2052511d6..94be4a9f7 100644 --- a/kvm/tests/read_only_memory.rs +++ b/kvm/tests/read_only_memory.rs @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#![cfg(unix)] +#![cfg(any(target_os = "android", target_os = "linux"))] #![cfg(target_arch = "x86_64")] use base::MemoryMappingBuilder; diff --git a/kvm/tests/real_run_adder.rs b/kvm/tests/real_run_adder.rs index fddddf4f4..26a6ae6eb 100644 --- a/kvm/tests/real_run_adder.rs +++ b/kvm/tests/real_run_adder.rs @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#![cfg(unix)] +#![cfg(any(target_os = "android", target_os = "linux"))] #![cfg(target_arch = "x86_64")] use kvm::*; diff --git a/kvm_sys/src/lib.rs b/kvm_sys/src/lib.rs index ed27e0263..3b4a84836 100644 --- a/kvm_sys/src/lib.rs +++ b/kvm_sys/src/lib.rs @@ -4,7 +4,7 @@ //! Bindings for the Linux KVM (Kernel Virtual Machine) API. -#![cfg(unix)] +#![cfg(any(target_os = "android", target_os = "linux"))] #![allow(non_upper_case_globals)] #![allow(non_camel_case_types)] #![allow(non_snake_case)] diff --git a/media/ffmpeg/src/lib.rs b/media/ffmpeg/src/lib.rs index 4e775ed5c..7ea985652 100644 --- a/media/ffmpeg/src/lib.rs +++ b/media/ffmpeg/src/lib.rs @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#![cfg(unix)] +#![cfg(any(target_os = "android", target_os = "linux"))] pub mod avcodec; mod avutil; diff --git a/media/libvda/src/lib.rs b/media/libvda/src/lib.rs index 5c78174aa..191671996 100644 --- a/media/libvda/src/lib.rs +++ b/media/libvda/src/lib.rs @@ -4,7 +4,7 @@ //! Bindings for the `libvda` video decoder and encoder libraries. -#![cfg(unix)] +#![cfg(any(target_os = "android", target_os = "linux"))] pub mod decode; pub mod encode; diff --git a/media/libvda/tests/decode_tests.rs b/media/libvda/tests/decode_tests.rs index c64934176..e1d8150ba 100644 --- a/media/libvda/tests/decode_tests.rs +++ b/media/libvda/tests/decode_tests.rs @@ -4,7 +4,7 @@ //! Integration tests using LibVDA fake decode implemenation. -#![cfg(unix)] +#![cfg(any(target_os = "android", target_os = "linux"))] use libvda::decode::*; use libvda::*; diff --git a/media/libvda/tests/encode_tests.rs b/media/libvda/tests/encode_tests.rs index e35e98da1..629fe0a42 100644 --- a/media/libvda/tests/encode_tests.rs +++ b/media/libvda/tests/encode_tests.rs @@ -4,7 +4,7 @@ //! Integration tests using LibVDA fake encode implementation. -#![cfg(unix)] +#![cfg(any(target_os = "android", target_os = "linux"))] use libvda::encode::*; use libvda::*; diff --git a/metrics/src/sys.rs b/metrics/src/sys.rs index 150f56184..4c526e303 100644 --- a/metrics/src/sys.rs +++ b/metrics/src/sys.rs @@ -6,7 +6,7 @@ cfg_if::cfg_if! { if #[cfg(windows)] { pub mod windows; pub use windows::*; - } else if #[cfg(unix)] { + } else if #[cfg(any(target_os = "android", target_os = "linux"))] { pub(crate) mod unix; } } diff --git a/net_util/src/sys.rs b/net_util/src/sys.rs index 052a9c6f1..40aa4e48e 100644 --- a/net_util/src/sys.rs +++ b/net_util/src/sys.rs @@ -3,7 +3,7 @@ // found in the LICENSE file. cfg_if::cfg_if! { - if #[cfg(unix)] { + if #[cfg(any(target_os = "android", target_os = "linux"))] { pub mod unix; use unix as platform; } else if #[cfg(windows)] { diff --git a/net_util/tests/unix_tap.rs b/net_util/tests/unix_tap.rs index a81d69a4d..35d491248 100644 --- a/net_util/tests/unix_tap.rs +++ b/net_util/tests/unix_tap.rs @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#![cfg(unix)] +#![cfg(any(target_os = "android", target_os = "linux"))] use std::net; diff --git a/perfetto/build.rs b/perfetto/build.rs index e829777f2..f4e80e058 100644 --- a/perfetto/build.rs +++ b/perfetto/build.rs @@ -9,7 +9,7 @@ fn main() { #[cfg(windows)] main_windows(); - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] main_unix(); // TODO: enable once Perfetto is in third_party/perfetto. @@ -37,7 +37,7 @@ fn main_windows() { */ } -#[cfg(unix)] +#[cfg(any(target_os = "android", target_os = "linux"))] fn main_unix() { // TODO: enable once we have Perfetto libraries available on unix. We may // want to use a prebuilt here too, in which case this would be identical diff --git a/prebuilts/src/lib.rs b/prebuilts/src/lib.rs index c2227f5cf..965d3421e 100644 --- a/prebuilts/src/lib.rs +++ b/prebuilts/src/lib.rs @@ -126,7 +126,7 @@ pub fn download_prebuilt(library: &str, version: u32, filename: &str) -> Result< dest_path.link, dest_path.file ); let _ = std::fs::remove_file(&dest_path.link); - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] std::os::unix::fs::symlink(&dest_path.file, &dest_path.link)?; #[cfg(windows)] let _ = std::fs::copy(&dest_path.file, &dest_path.link)?; diff --git a/prebuilts/src/sys.rs b/prebuilts/src/sys.rs index ad52bf386..f5eb509a9 100644 --- a/prebuilts/src/sys.rs +++ b/prebuilts/src/sys.rs @@ -3,7 +3,7 @@ // found in the LICENSE file. cfg_if::cfg_if! { - if #[cfg(unix)] { + if #[cfg(any(target_os = "android", target_os = "linux"))] { pub(crate) mod unix; pub(crate) use unix::*; } else if #[cfg(windows)] { diff --git a/protos/src/plugin.rs b/protos/src/plugin.rs index b1b1c5db0..c12e60e2a 100644 --- a/protos/src/plugin.rs +++ b/protos/src/plugin.rs @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#![cfg(unix)] +#![cfg(any(target_os = "android", target_os = "linux"))] pub use crate::generated::plugin::*; diff --git a/riscv64/Cargo.toml b/riscv64/Cargo.toml index 89566f61a..6592fbe08 100644 --- a/riscv64/Cargo.toml +++ b/riscv64/Cargo.toml @@ -28,5 +28,5 @@ base = { path = "../base" } vm_control = { path = "../vm_control" } vm_memory = { path = "../vm_memory" } -[target.'cfg(unix)'.dependencies] +[target.'cfg(any(target_os = "android", target_os = "linux"))'.dependencies] minijail = "*" diff --git a/riscv64/src/lib.rs b/riscv64/src/lib.rs index d5620a424..e4f77d82f 100644 --- a/riscv64/src/lib.rs +++ b/riscv64/src/lib.rs @@ -45,13 +45,13 @@ use hypervisor::Vm; use hypervisor::VmRiscv64; #[cfg(windows)] use jail::FakeMinijailStub as Minijail; -#[cfg(unix)] +#[cfg(any(target_os = "android", target_os = "linux"))] use minijail::Minijail; use remain::sorted; use resources::AddressRange; use resources::SystemAllocator; use resources::SystemAllocatorConfig; -#[cfg(unix)] +#[cfg(any(target_os = "android", target_os = "linux"))] use sync::Condvar; use sync::Mutex; use thiserror::Error; @@ -188,7 +188,9 @@ impl arch::LinuxArch for Riscv64 { _dump_device_tree_blob: Option, _debugcon_jail: Option, #[cfg(feature = "swap")] swap_controller: &mut Option, - #[cfg(unix)] _guest_suspended_cvar: Option, Condvar)>>, + #[cfg(any(target_os = "android", target_os = "linux"))] _guest_suspended_cvar: Option< + Arc<(Mutex, Condvar)>, + >, ) -> std::result::Result, Self::Error> where V: VmRiscv64, diff --git a/rutabaga_gfx/Cargo.toml b/rutabaga_gfx/Cargo.toml index 0f5c89ca0..33d3281fa 100644 --- a/rutabaga_gfx/Cargo.toml +++ b/rutabaga_gfx/Cargo.toml @@ -26,7 +26,7 @@ zerocopy = { version = "0.7", features = ["derive"] } log = "0.4" -[target.'cfg(unix)'.dependencies] +[target.'cfg(any(target_os = "android", target_os = "linux"))'.dependencies] nix = "0.26.1" [target.'cfg(windows)'.dependencies] diff --git a/rutabaga_gfx/src/rutabaga_gralloc/vulkano_gralloc/sys.rs b/rutabaga_gfx/src/rutabaga_gralloc/vulkano_gralloc/sys.rs index 7ca32b7e1..369887145 100644 --- a/rutabaga_gfx/src/rutabaga_gralloc/vulkano_gralloc/sys.rs +++ b/rutabaga_gfx/src/rutabaga_gralloc/vulkano_gralloc/sys.rs @@ -3,7 +3,7 @@ // found in the LICENSE file. cfg_if::cfg_if! { - if #[cfg(unix)] { + if #[cfg(any(target_os = "android", target_os = "linux"))] { pub mod unix; } else if #[cfg(windows)] { pub mod windows; diff --git a/rutabaga_gfx/src/rutabaga_utils.rs b/rutabaga_gfx/src/rutabaga_utils.rs index c8cdbdc14..c8215d119 100644 --- a/rutabaga_gfx/src/rutabaga_utils.rs +++ b/rutabaga_gfx/src/rutabaga_utils.rs @@ -14,7 +14,7 @@ use std::path::PathBuf; use std::str::Utf8Error; use std::sync::Arc; -#[cfg(unix)] +#[cfg(any(target_os = "android", target_os = "linux"))] use nix::Error as NixError; use remain::sorted; use thiserror::Error; @@ -268,7 +268,7 @@ pub enum RutabagaError { #[error("The mapping failed with library error: {0}")] MappingFailed(i32), /// Nix crate error. - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] #[error("The errno is {0}")] NixError(NixError), #[error("Nul Error occured {0}")] @@ -315,7 +315,7 @@ pub enum RutabagaError { VkMemoryMapError(MemoryMapError), } -#[cfg(unix)] +#[cfg(any(target_os = "android", target_os = "linux"))] impl From for RutabagaError { fn from(e: NixError) -> RutabagaError { RutabagaError::NixError(e) diff --git a/src/crosvm/cmdline.rs b/src/crosvm/cmdline.rs index 243c305fe..fb2de8078 100644 --- a/src/crosvm/cmdline.rs +++ b/src/crosvm/cmdline.rs @@ -3,7 +3,7 @@ // found in the LICENSE file. cfg_if::cfg_if! { - if #[cfg(unix)] { + if #[cfg(any(target_os = "android", target_os = "linux"))] { use base::RawDescriptor; use devices::virtio::vhost::user::device::parse_wayland_sock; @@ -1028,7 +1028,7 @@ pub struct RunCommand { /// context ID for virtual sockets. pub cid: Option, - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] #[argh( option, arg_name = "unpin_policy=POLICY,unpin_interval=NUM,unpin_limit=NUM,unpin_gen_threshold=NUM" @@ -1432,14 +1432,14 @@ pub struct RunCommand { /// path to a socket from where to read keyboard input events and write status updates to pub keyboard: Vec, - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] #[argh(option, arg_name = "PATH")] #[serde(skip)] // Deprecated - use `hypervisor` instead. #[merge(strategy = overwrite_option)] /// path to the KVM device. (default /dev/kvm) pub kvm_device: Option, - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] #[argh(switch)] #[serde(skip)] // TODO(b/255223604) #[merge(strategy = overwrite_option)] @@ -1611,7 +1611,7 @@ pub struct RunCommand { /// extra kernel or plugin command line arguments. Can be given more than once pub params: Vec, - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] #[argh(option, arg_name = "pci_hotplug_slots")] #[serde(default)] #[merge(strategy = overwrite_option)] @@ -1868,14 +1868,14 @@ pub struct RunCommand { // TODO(b/300580119): Add O_DIRECT and sparse file support. scsi_block: Vec, - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] #[argh(switch)] #[serde(skip)] // TODO(b/255223604) #[merge(strategy = overwrite_option)] /// instead of seccomp filter failures being fatal, they will be logged instead pub seccomp_log_failures: Option, - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] #[argh(option, arg_name = "PATH")] #[serde(skip)] // TODO(b/255223604) #[merge(strategy = overwrite_option)] @@ -1923,7 +1923,7 @@ pub struct RunCommand { /// the service ipc pipe name. (Prefix \\\\.\\pipe\\ not needed. pub service_pipe_name: Option, - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] #[argh( option, arg_name = "PATH:TAG[:type=TYPE:writeback=BOOL:timeout=SECONDS:uidmap=UIDMAP:gidmap=GIDMAP:cache=CACHE:dax=BOOL,posix_acl=BOOL]" @@ -2098,14 +2098,14 @@ pub struct RunCommand { /// when logging to syslog, use the provided tag pub syslog_tag: Option, - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] #[argh(option)] #[serde(skip)] // Deprecated - use `net` instead. #[merge(strategy = append)] /// file descriptor for configured tap device. A different virtual network card will be added each time this argument is given pub tap_fd: Vec, - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] #[argh(option)] #[serde(skip)] // Deprecated - use `net` instead. #[merge(strategy = append)] @@ -2125,7 +2125,7 @@ pub struct RunCommand { /// path to a socket from where to read trackpad input events and write status updates to, optionally followed by screen width and height (defaults to 800x1280) and a name for the input device pub trackpad: Vec, - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] #[argh(switch)] #[serde(skip)] // TODO(b/255223604) #[merge(strategy = overwrite_option)] @@ -2151,7 +2151,7 @@ pub struct RunCommand { /// move all vCPU threads to this CGroup (default: nothing moves) pub vcpu_cgroup_path: Option, - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] #[argh( option, arg_name = "PATH[,guest-address=][,iommu=viommu|coiommu|off]" @@ -2168,35 +2168,35 @@ pub struct RunCommand { /// to use for this device. pub vfio: Vec, - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] #[argh(switch)] #[serde(skip)] // TODO(b/255223604) #[merge(strategy = overwrite_option)] /// isolate all hotplugged passthrough vfio device behind virtio-iommu pub vfio_isolate_hotplug: Option, - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] #[argh(option, arg_name = "PATH")] #[serde(skip)] // Deprecated - use `vfio` instead. #[merge(strategy = append)] /// path to sysfs of platform pass through pub vfio_platform: Vec, - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] #[argh(switch)] #[serde(skip)] // Deprecated - use `net` instead. #[merge(strategy = overwrite_option)] /// use vhost for networking pub vhost_net: Option, - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] #[argh(option, arg_name = "PATH")] #[serde(skip)] // TODO(b/255223604) #[merge(strategy = overwrite_option)] /// path to the vhost-net device. (default /dev/vhost-net) pub vhost_net_device: Option, - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] #[cfg(any(target_arch = "arm", target_arch = "aarch64"))] #[argh(switch)] #[merge(strategy = overwrite_option)] @@ -2267,14 +2267,14 @@ pub struct RunCommand { /// path to a vhost-user socket for wayland pub vhost_user_wl: Option, - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] #[argh(option, arg_name = "SOCKET_PATH")] #[serde(skip)] // Deprecated - use `vsock` instead. #[merge(strategy = overwrite_option)] /// path to the vhost-vsock device. (default /dev/vhost-vsock) pub vhost_vsock_device: Option, - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] #[argh(option, arg_name = "FD")] #[serde(skip)] // Deprecated - use `vsock` instead. #[merge(strategy = overwrite_option)] @@ -2353,14 +2353,14 @@ pub struct RunCommand { /// enable the virtio-tpm connection to vtpm daemon pub vtpm_proxy: Option, - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] #[argh(option, arg_name = "PATH[,name=NAME]", from_str_fn(parse_wayland_sock))] #[serde(skip)] // TODO(b/255223604) #[merge(strategy = append)] /// path to the Wayland socket to use. The unnamed one is used for displaying virtual screens. Named ones are only for IPC pub wayland_sock: Vec<(String, PathBuf)>, - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] #[argh(option, arg_name = "DISPLAY")] #[serde(skip)] // TODO(b/255223604) #[merge(strategy = overwrite_option)] @@ -2415,7 +2415,7 @@ impl TryFrom for super::config::Config { cfg.executable_path = Some(Executable::Kernel(p)); } - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] if let Some(p) = cmd.kvm_device { log::warn!( "`--kvm-device ` is deprecated; use `--hypervisor kvm[device=]` instead" @@ -2534,7 +2534,7 @@ impl TryFrom for super::config::Config { cfg.hypervisor = cmd.hypervisor; } - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] { cfg.lock_guest_memory = cmd.lock_guest_memory.unwrap_or_default(); } @@ -2705,7 +2705,7 @@ impl TryFrom for super::config::Config { cfg.fw_cfg_parameters = cmd.fw_cfg; - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] for (name, params) in cmd.wayland_sock { if cfg.wayland_socket_paths.contains_key(&name) { return Err(format!("wayland socket name already used: '{}'", name)); @@ -2713,7 +2713,7 @@ impl TryFrom for super::config::Config { cfg.wayland_socket_paths.insert(name, params); } - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] { cfg.x_display = cmd.x_display; } @@ -2746,7 +2746,7 @@ impl TryFrom for super::config::Config { let legacy_vsock_config = VsockConfig::new( cid, - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] match (cmd.vhost_vsock_device, cmd.vhost_vsock_fd) { (Some(_), Some(_)) => { return Err( @@ -2812,7 +2812,7 @@ impl TryFrom for super::config::Config { } } - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] #[cfg(any(target_arch = "arm", target_arch = "aarch64"))] { cfg.vhost_scmi = cmd.vhost_scmi.unwrap_or_default(); @@ -2906,7 +2906,7 @@ impl TryFrom for super::config::Config { } } - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] { cfg.gpu_cgroup_path = cmd.gpu_cgroup_path; cfg.gpu_server_cgroup_path = cmd.gpu_server_cgroup_path; @@ -3026,7 +3026,7 @@ impl TryFrom for super::config::Config { } } - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] { cfg.shared_dirs = cmd.shared_dir; @@ -3174,7 +3174,7 @@ impl TryFrom for super::config::Config { cfg.task_profiles = cmd.task_profiles; } - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] { if cmd.unmap_guest_memory_on_fork.unwrap_or_default() && !cmd.disable_sandbox.unwrap_or_default() @@ -3184,7 +3184,7 @@ impl TryFrom for super::config::Config { cfg.unmap_guest_memory_on_fork = cmd.unmap_guest_memory_on_fork.unwrap_or_default(); } - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] { cfg.vfio.extend(cmd.vfio); cfg.vfio.extend(cmd.vfio_platform); diff --git a/src/crosvm/config.rs b/src/crosvm/config.rs index 0910d77ca..dd6cc8466 100644 --- a/src/crosvm/config.rs +++ b/src/crosvm/config.rs @@ -57,11 +57,11 @@ use x86_64::check_host_hybrid_support; use x86_64::CpuIdCall; pub(crate) use super::sys::HypervisorKind; -#[cfg(unix)] +#[cfg(any(target_os = "android", target_os = "linux"))] use crate::crosvm::sys::config::SharedDir; cfg_if::cfg_if! { - if #[cfg(unix)] { + if #[cfg(any(target_os = "android", target_os = "linux"))] { #[cfg(feature = "gpu")] use crate::crosvm::sys::GpuRenderServerParameters; @@ -764,7 +764,7 @@ pub struct Config { pub broker_shutdown_event: Option, #[cfg(all(target_arch = "x86_64", unix))] pub bus_lock_ratelimit: u64, - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] pub coiommu_param: Option, pub core_scheduling: bool, pub cpu_capacity: BTreeMap, // CPU index -> capacity @@ -815,7 +815,7 @@ pub struct Config { pub jail_config: Option, #[cfg(windows)] pub kernel_log_file: Option, - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] pub lock_guest_memory: bool, #[cfg(windows)] pub log_file: Option, @@ -871,7 +871,7 @@ pub struct Config { pub serial_parameters: BTreeMap<(SerialHardware, u8), SerialParameters>, #[cfg(windows)] pub service_pipe_name: Option, - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] #[serde(skip)] pub shared_dirs: Vec, #[cfg(any(feature = "slirp-ring-capture", feature = "slirp-debug"))] @@ -890,7 +890,7 @@ pub struct Config { pub swiotlb: Option, #[cfg(target_os = "android")] pub task_profiles: Vec, - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] pub unmap_guest_memory_on_fork: bool, pub usb: bool, pub vcpu_affinity: Option, @@ -898,14 +898,14 @@ pub struct Config { pub vcpu_count: Option, #[cfg(target_arch = "x86_64")] pub vcpu_hybrid_type: BTreeMap, // CPU index -> hybrid type - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] pub vfio: Vec, - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] pub vfio_isolate_hotplug: bool, - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] #[cfg(any(target_arch = "arm", target_arch = "aarch64"))] pub vhost_scmi: bool, - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] #[cfg(any(target_arch = "arm", target_arch = "aarch64"))] pub vhost_scmi_device: PathBuf, pub vhost_user_blk: Vec, @@ -966,7 +966,7 @@ impl Default for Config { broker_shutdown_event: None, #[cfg(all(target_arch = "x86_64", unix))] bus_lock_ratelimit: 0, - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] coiommu_param: None, core_scheduling: true, #[cfg(feature = "crash-report")] @@ -1025,7 +1025,7 @@ impl Default for Config { }, #[cfg(windows)] kernel_log_file: None, - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] lock_guest_memory: false, #[cfg(windows)] log_file: None, @@ -1075,7 +1075,7 @@ impl Default for Config { scsis: Vec::new(), #[cfg(windows)] service_pipe_name: None, - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] shared_dirs: Vec::new(), #[cfg(any(feature = "slirp-ring-capture", feature = "slirp-debug"))] slirp_capture_file: None, @@ -1093,7 +1093,7 @@ impl Default for Config { swiotlb: None, #[cfg(target_os = "android")] task_profiles: Vec::new(), - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] unmap_guest_memory_on_fork: false, usb: true, vcpu_affinity: None, @@ -1101,14 +1101,14 @@ impl Default for Config { vcpu_count: None, #[cfg(target_arch = "x86_64")] vcpu_hybrid_type: BTreeMap::new(), - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] vfio: Vec::new(), - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] vfio_isolate_hotplug: false, - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] #[cfg(any(target_arch = "arm", target_arch = "aarch64"))] vhost_scmi: false, - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] #[cfg(any(target_arch = "arm", target_arch = "aarch64"))] vhost_scmi_device: PathBuf::from(VHOST_SCMI_PATH), vhost_user_blk: Vec::new(), @@ -1277,7 +1277,7 @@ pub fn validate_config(cfg: &mut Config) -> std::result::Result<(), String> { return Err("'balloon_page_reporting' requires enabled balloon".to_string()); } - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] if cfg.lock_guest_memory && cfg.jail_config.is_none() { return Err("'lock-guest-memory' and 'disable-sandbox' are mutually exclusive".to_string()); } diff --git a/src/crosvm/gpu_config.rs b/src/crosvm/gpu_config.rs index ad5fb94f9..0e99c34db 100644 --- a/src/crosvm/gpu_config.rs +++ b/src/crosvm/gpu_config.rs @@ -711,7 +711,7 @@ mod tests { ); } - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] #[test] fn parse_gpu_options_and_gpu_display_options_multi_display_supported_on_unix() { { diff --git a/src/crosvm/sys.rs b/src/crosvm/sys.rs index a49990a05..473f5806b 100644 --- a/src/crosvm/sys.rs +++ b/src/crosvm/sys.rs @@ -2,14 +2,14 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#[cfg(unix)] +#[cfg(any(target_os = "android", target_os = "linux"))] pub(crate) mod unix; #[cfg(windows)] pub(crate) mod windows; cfg_if::cfg_if! { - if #[cfg(unix)] { + if #[cfg(any(target_os = "android", target_os = "linux"))] { use unix as platform; #[cfg(feature = "gpu")] diff --git a/src/crosvm/sys/unix/cmdline.rs b/src/crosvm/sys/unix/cmdline.rs index ab68b26f2..271ff3f51 100644 --- a/src/crosvm/sys/unix/cmdline.rs +++ b/src/crosvm/sys/unix/cmdline.rs @@ -130,6 +130,6 @@ pub struct DevicesCommand { #[argh(subcommand)] /// Unix Commands pub enum Commands { - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] Devices(DevicesCommand), } diff --git a/src/sys.rs b/src/sys.rs index 3d27c7e59..abcccd77b 100644 --- a/src/sys.rs +++ b/src/sys.rs @@ -3,7 +3,7 @@ // found in the LICENSE file. cfg_if::cfg_if! { - if #[cfg(unix)] { + if #[cfg(any(target_os = "android", target_os = "linux"))] { pub(crate) mod unix; use unix as platform; pub(crate) use crate::crosvm::sys::unix::{run_config, ExitState}; diff --git a/swap/Cargo.toml b/swap/Cargo.toml index 7e5d66432..a261ea4e6 100644 --- a/swap/Cargo.toml +++ b/swap/Cargo.toml @@ -33,7 +33,7 @@ sync = { path = "../common/sync" } # provided by ebuild thiserror = "*" vm_memory = { path = "../vm_memory"} -[target.'cfg(unix)'.dependencies] +[target.'cfg(any(target_os = "android", target_os = "linux"))'.dependencies] libc = "*" [target.'cfg(target_os="linux")'.dependencies] diff --git a/system_api/Cargo.toml b/system_api/Cargo.toml index 7efcc4efc..df0db0cd0 100644 --- a/system_api/Cargo.toml +++ b/system_api/Cargo.toml @@ -7,6 +7,6 @@ edition = "2021" [lib] path = "src/system_api.rs" -[target.'cfg(unix)'.dependencies] +[target.'cfg(any(target_os = "android", target_os = "linux"))'.dependencies] dbus = "0.9" protobuf = "3.2" diff --git a/system_api/src/system_api.rs b/system_api/src/system_api.rs index 9a79cd243..e57fc74b4 100644 --- a/system_api/src/system_api.rs +++ b/system_api/src/system_api.rs @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#![cfg(unix)] +#![cfg(any(target_os = "android", target_os = "linux"))] include!("bindings/include_modules.rs"); include!("protos/include_protos.rs"); diff --git a/third_party/vmm_vhost/src/connection.rs b/third_party/vmm_vhost/src/connection.rs index 5cf25d2f3..18bccfee9 100644 --- a/third_party/vmm_vhost/src/connection.rs +++ b/third_party/vmm_vhost/src/connection.rs @@ -4,7 +4,7 @@ //! Common data structures for listener and endpoint. cfg_if::cfg_if! { - if #[cfg(unix)] { + if #[cfg(any(target_os = "android", target_os = "linux"))] { pub mod socket; mod unix; } else if #[cfg(windows)] { @@ -447,7 +447,7 @@ impl + ?Sized> EndpointExt for E {} pub(crate) mod tests { use super::*; cfg_if::cfg_if! { - if #[cfg(unix)] { + if #[cfg(any(target_os = "android", target_os = "linux"))] { #[cfg(feature = "vmm")] pub(crate) use super::unix::tests::*; } else if #[cfg(windows)] { diff --git a/third_party/vmm_vhost/src/lib.rs b/third_party/vmm_vhost/src/lib.rs index be3b01a8d..e8960ab59 100644 --- a/third_party/vmm_vhost/src/lib.rs +++ b/third_party/vmm_vhost/src/lib.rs @@ -462,7 +462,7 @@ mod tests { let descriptor = unsafe { tube_transporter::packed_tube::pack(tubes.0, std::process::id()).unwrap() }; - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] let descriptor = base::Event::new().unwrap(); master.set_slave_request_fd(&descriptor).unwrap(); diff --git a/third_party/vmm_vhost/src/master_req_handler.rs b/third_party/vmm_vhost/src/master_req_handler.rs index fd5136176..e39258f49 100644 --- a/third_party/vmm_vhost/src/master_req_handler.rs +++ b/third_party/vmm_vhost/src/master_req_handler.rs @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 cfg_if::cfg_if! { - if #[cfg(unix)] { + if #[cfg(any(target_os = "android", target_os = "linux"))] { mod unix; } else if #[cfg(windows)] { mod windows; diff --git a/third_party/vmm_vhost/src/sys.rs b/third_party/vmm_vhost/src/sys.rs index 999acec4c..fdca302b9 100644 --- a/third_party/vmm_vhost/src/sys.rs +++ b/third_party/vmm_vhost/src/sys.rs @@ -4,7 +4,7 @@ //! A wrapper module for platform dependent code. cfg_if::cfg_if! { - if #[cfg(unix)] { + if #[cfg(any(target_os = "android", target_os = "linux"))] { pub mod unix; use unix as platform; } else if #[cfg(windows)] { diff --git a/usb_util/src/lib.rs b/usb_util/src/lib.rs index e816417cc..3963f137b 100644 --- a/usb_util/src/lib.rs +++ b/usb_util/src/lib.rs @@ -5,7 +5,7 @@ //! USB device access and descriptor manipulation. mod descriptor; -#[cfg(unix)] +#[cfg(any(target_os = "android", target_os = "linux"))] mod device; mod error; mod types; @@ -14,17 +14,17 @@ pub use self::descriptor::parse_usbfs_descriptors; pub use self::descriptor::ConfigDescriptorTree; pub use self::descriptor::DeviceDescriptorTree; pub use self::descriptor::InterfaceDescriptorTree; -#[cfg(unix)] +#[cfg(any(target_os = "android", target_os = "linux"))] pub use self::device::Device; -#[cfg(unix)] +#[cfg(any(target_os = "android", target_os = "linux"))] pub use self::device::DmaBuffer; -#[cfg(unix)] +#[cfg(any(target_os = "android", target_os = "linux"))] pub use self::device::Transfer; -#[cfg(unix)] +#[cfg(any(target_os = "android", target_os = "linux"))] pub use self::device::TransferBuffer; -#[cfg(unix)] +#[cfg(any(target_os = "android", target_os = "linux"))] pub use self::device::TransferHandle; -#[cfg(unix)] +#[cfg(any(target_os = "android", target_os = "linux"))] pub use self::device::TransferStatus; pub use self::error::Error; pub use self::error::Result; diff --git a/vendor/generic/crash_report/src/lib.rs b/vendor/generic/crash_report/src/lib.rs index e050c6f34..7e73f262f 100644 --- a/vendor/generic/crash_report/src/lib.rs +++ b/vendor/generic/crash_report/src/lib.rs @@ -13,7 +13,7 @@ use serde::Serialize; #[cfg(windows)] use win_util::ProcessType; -#[cfg(unix)] +#[cfg(any(target_os = "android", target_os = "linux"))] pub enum ProcessType {} /// The reason a SimulatedException crash report is being requested. diff --git a/vhost/src/lib.rs b/vhost/src/lib.rs index 0d9706418..b5c89933e 100644 --- a/vhost/src/lib.rs +++ b/vhost/src/lib.rs @@ -4,10 +4,10 @@ //! Linux vhost kernel API wrapper. -#![cfg(unix)] +#![cfg(any(target_os = "android", target_os = "linux"))] pub mod net; -#[cfg(unix)] +#[cfg(any(target_os = "android", target_os = "linux"))] #[cfg(any(target_arch = "arm", target_arch = "aarch64"))] mod scmi; mod vsock; @@ -30,11 +30,11 @@ use vm_memory::GuestAddress; use vm_memory::GuestMemory; use vm_memory::GuestMemoryError; -#[cfg(unix)] +#[cfg(any(target_os = "android", target_os = "linux"))] pub use crate::net::Net; -#[cfg(unix)] +#[cfg(any(target_os = "android", target_os = "linux"))] pub use crate::net::NetT; -#[cfg(unix)] +#[cfg(any(target_os = "android", target_os = "linux"))] #[cfg(any(target_arch = "arm", target_arch = "aarch64"))] pub use crate::scmi::Scmi; pub use crate::vsock::Vsock; diff --git a/vhost/tests/unix.rs b/vhost/tests/unix.rs index dd3605262..9a6893f02 100644 --- a/vhost/tests/unix.rs +++ b/vhost/tests/unix.rs @@ -3,7 +3,7 @@ // found in the LICENSE file. // TODO(225193541): Enable/add tests for windows. -#![cfg(unix)] +#![cfg(any(target_os = "android", target_os = "linux"))] use std::path::PathBuf; use std::result; diff --git a/vm_control/src/client.rs b/vm_control/src/client.rs index bb164149a..b8ca6a37c 100644 --- a/vm_control/src/client.rs +++ b/vm_control/src/client.rs @@ -16,7 +16,7 @@ use thiserror::Error; #[cfg(feature = "gpu")] pub use crate::gpu::*; pub use crate::sys::handle_request; -#[cfg(unix)] +#[cfg(any(target_os = "android", target_os = "linux"))] pub use crate::sys::handle_request_with_timeout; pub use crate::*; diff --git a/vm_control/src/lib.rs b/vm_control/src/lib.rs index 80dec6cb9..816204e91 100644 --- a/vm_control/src/lib.rs +++ b/vm_control/src/lib.rs @@ -16,7 +16,7 @@ pub mod gdb; #[cfg(feature = "gpu")] pub mod gpu; -#[cfg(unix)] +#[cfg(any(target_os = "android", target_os = "linux"))] use base::MemoryMappingBuilderUnix; #[cfg(windows)] use base::MemoryMappingBuilderWindows; @@ -89,11 +89,11 @@ use serde::Deserialize; use serde::Serialize; use swap::SwapStatus; use sync::Mutex; -#[cfg(unix)] +#[cfg(any(target_os = "android", target_os = "linux"))] pub use sys::FsMappingRequest; -#[cfg(unix)] +#[cfg(any(target_os = "android", target_os = "linux"))] pub use sys::VmMsyncRequest; -#[cfg(unix)] +#[cfg(any(target_os = "android", target_os = "linux"))] pub use sys::VmMsyncResponse; use thiserror::Error; pub use vm_control_product::GpuSendToMain; diff --git a/vm_control/src/sys.rs b/vm_control/src/sys.rs index 7fcd72673..9e59b7b66 100644 --- a/vm_control/src/sys.rs +++ b/vm_control/src/sys.rs @@ -3,7 +3,7 @@ // found in the LICENSE file. cfg_if::cfg_if! { - if #[cfg(unix)] { + if #[cfg(any(target_os = "android", target_os = "linux"))] { pub mod unix; use unix as platform; pub use platform::{VmMsyncRequest, VmMsyncResponse, FsMappingRequest}; diff --git a/vm_memory/src/guest_memory/sys.rs b/vm_memory/src/guest_memory/sys.rs index 0b4ceeeec..e67f6f251 100644 --- a/vm_memory/src/guest_memory/sys.rs +++ b/vm_memory/src/guest_memory/sys.rs @@ -3,7 +3,7 @@ // found in the LICENSE file. cfg_if::cfg_if! { - if #[cfg(unix)] { + if #[cfg(any(target_os = "android", target_os = "linux"))] { pub mod unix; use unix as platform; } else if #[cfg(windows)] { diff --git a/vm_memory/src/udmabuf/sys.rs b/vm_memory/src/udmabuf/sys.rs index 46c0247b7..e66bf4cad 100644 --- a/vm_memory/src/udmabuf/sys.rs +++ b/vm_memory/src/udmabuf/sys.rs @@ -3,7 +3,7 @@ // found in the LICENSE file. cfg_if::cfg_if! { - if #[cfg(unix)] { + if #[cfg(any(target_os = "android", target_os = "linux"))] { pub mod unix; pub use unix::UnixUdmabufDriver as UdmabufDriver; } else if #[cfg(windows)] { diff --git a/x86_64/Cargo.toml b/x86_64/Cargo.toml index f3bac703a..db81275cc 100644 --- a/x86_64/Cargo.toml +++ b/x86_64/Cargo.toml @@ -37,5 +37,5 @@ vm_control = { path = "../vm_control" } vm_memory = { path = "../vm_memory" } zerocopy = { version = "0.7", features = ["derive"] } -[target.'cfg(unix)'.dependencies] +[target.'cfg(any(target_os = "android", target_os = "linux"))'.dependencies] minijail = "*" diff --git a/x86_64/src/lib.rs b/x86_64/src/lib.rs index d64233ae3..fbde8af23 100644 --- a/x86_64/src/lib.rs +++ b/x86_64/src/lib.rs @@ -60,7 +60,7 @@ use arch::VmImage; #[cfg(feature = "seccomp_trace")] use base::debug; use base::warn; -#[cfg(unix)] +#[cfg(any(target_os = "android", target_os = "linux"))] use base::AsRawDescriptors; use base::Event; use base::SendTube; @@ -86,12 +86,12 @@ use devices::PciRoot; use devices::PciRootCommand; use devices::PciVirtualConfigMmio; use devices::Pflash; -#[cfg(unix)] +#[cfg(any(target_os = "android", target_os = "linux"))] use devices::ProxyDevice; use devices::Serial; use devices::SerialHardware; use devices::SerialParameters; -#[cfg(unix)] +#[cfg(any(target_os = "android", target_os = "linux"))] use devices::VirtualPmc; use devices::FW_CFG_BASE_PORT; use devices::FW_CFG_MAX_FILE_SLOTS; @@ -121,7 +121,7 @@ use hypervisor::VmX86_64; use jail::read_jail_addr; #[cfg(windows)] use jail::FakeMinijailStub as Minijail; -#[cfg(unix)] +#[cfg(any(target_os = "android", target_os = "linux"))] use minijail::Minijail; use once_cell::sync::OnceCell; use rand::rngs::OsRng; @@ -130,7 +130,7 @@ use remain::sorted; use resources::AddressRange; use resources::SystemAllocator; use resources::SystemAllocatorConfig; -#[cfg(unix)] +#[cfg(any(target_os = "android", target_os = "linux"))] use sync::Condvar; use sync::Mutex; use thiserror::Error; @@ -160,7 +160,7 @@ pub enum Error { CloneEvent(base::Error), #[error("failed to clone IRQ chip: {0}")] CloneIrqChip(base::Error), - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] #[error("failed to clone jail: {0}")] CloneJail(minijail::Error), #[error("unable to clone a Tube: {0}")] @@ -193,7 +193,7 @@ pub enum Error { CreatePit(base::Error), #[error("unable to make PIT device: {0}")] CreatePitDevice(devices::PitError), - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] #[error("unable to create proxy device: {0}")] CreateProxyDevice(devices::ProxyError), #[error("unable to create serial devices: {0}")] @@ -685,7 +685,9 @@ impl arch::LinuxArch for X8664arch { pflash_jail: Option, fw_cfg_jail: Option, #[cfg(feature = "swap")] swap_controller: &mut Option, - #[cfg(unix)] guest_suspended_cvar: Option, Condvar)>>, + #[cfg(any(target_os = "android", target_os = "linux"))] guest_suspended_cvar: Option< + Arc<(Mutex, Condvar)>, + >, ) -> std::result::Result, Self::Error> where V: VmX86_64, @@ -889,9 +891,9 @@ impl arch::LinuxArch for X8664arch { &mut resume_notify_devices, #[cfg(feature = "swap")] swap_controller, - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] components.ac_adapter, - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] guest_suspended_cvar, &pci_irqs, )?; @@ -1031,7 +1033,7 @@ impl arch::LinuxArch for X8664arch { gdb: components.gdb, pm: Some(acpi_dev_resource.pm), root_config: pci, - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] platform_devices: Vec::new(), hotplug_bus: BTreeMap::new(), devices_thread: None, @@ -1093,7 +1095,7 @@ impl arch::LinuxArch for X8664arch { fn register_pci_device( linux: &mut RunnableLinuxVm, device: Box, - #[cfg(unix)] minijail: Option, + #[cfg(any(target_os = "android", target_os = "linux"))] minijail: Option, resources: &mut SystemAllocator, hp_control_tube: &mpsc::Sender, #[cfg(feature = "swap")] swap_controller: &mut Option, @@ -1101,7 +1103,7 @@ impl arch::LinuxArch for X8664arch { arch::configure_pci_device( linux, device, - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] minijail, resources, hp_control_tube, @@ -1525,12 +1527,12 @@ impl X8664arch { let start = FIRST_ADDR_PAST_32BITS - bios_size - size; let pflash_image = Box::new(pflash_image); - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] let fds = pflash_image.as_raw_descriptors(); let pflash = Pflash::new(pflash_image, block_size).map_err(Error::SetupPflash)?; let pflash: Arc> = match jail { - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] Some(jail) => Arc::new(Mutex::new( ProxyDevice::new( pflash, @@ -1733,7 +1735,7 @@ impl X8664arch { }; let fw_cfg: Arc> = match fw_cfg_jail.as_ref() { - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] Some(jail) => { let jail_clone = jail.try_clone().map_err(Error::CloneJail)?; #[cfg(feature = "seccomp_trace")] @@ -1870,8 +1872,10 @@ impl X8664arch { max_bus: u8, resume_notify_devices: &mut Vec>>, #[cfg(feature = "swap")] swap_controller: &mut Option, - #[cfg(unix)] ac_adapter: bool, - #[cfg(unix)] guest_suspended_cvar: Option, Condvar)>>, + #[cfg(any(target_os = "android", target_os = "linux"))] ac_adapter: bool, + #[cfg(any(target_os = "android", target_os = "linux"))] guest_suspended_cvar: Option< + Arc<(Mutex, Condvar)>, + >, pci_irqs: &[(PciAddress, u32, PciInterruptPin)], ) -> Result<(acpi::AcpiDevResource, Option)> { // The AML data for the acpi devices @@ -1879,7 +1883,7 @@ impl X8664arch { let bat_control = if let Some(battery_type) = battery.0 { match battery_type { - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] BatteryType::Goldfish => { let irq_num = resources.allocate_irq().ok_or(Error::CreateBatDevices( arch::DeviceRegistrationError::AllocateIrq, @@ -1928,7 +1932,7 @@ impl X8664arch { let pm_sci_evt = devices::IrqLevelEvent::new().map_err(Error::CreateEvent)?; - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] let acdc = if ac_adapter { // Allocate GPE for AC adapter notfication let gpe = resources.allocate_gpe().ok_or(Error::AllocateGpe)?; @@ -1961,7 +1965,7 @@ impl X8664arch { let acdc = None; //Virtual PMC - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] if let Some(guest_suspended_cvar) = guest_suspended_cvar { let alloc = resources.get_anon_alloc(); let mmio_base = resources @@ -2182,7 +2186,7 @@ impl X8664arch { .map_err(Error::CreateDebugconDevice)?; let con: Arc> = match debugcon_jail.as_ref() { - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] Some(jail) => { let jail_clone = jail.try_clone().map_err(Error::CloneJail)?; #[cfg(feature = "seccomp_trace")] diff --git a/x86_64/tests/integration/main.rs b/x86_64/tests/integration/main.rs index a91d32db0..3bf4194b1 100644 --- a/x86_64/tests/integration/main.rs +++ b/x86_64/tests/integration/main.rs @@ -215,7 +215,7 @@ where &mut resume_notify_devices, #[cfg(feature = "swap")] &mut None, - #[cfg(unix)] + #[cfg(any(target_os = "android", target_os = "linux"))] false, Default::default(), &pci_irqs, diff --git a/x86_64/tests/integration/sys.rs b/x86_64/tests/integration/sys.rs index 29cd03dff..d91aa8935 100644 --- a/x86_64/tests/integration/sys.rs +++ b/x86_64/tests/integration/sys.rs @@ -3,7 +3,7 @@ // found in the LICENSE file. cfg_if::cfg_if! { - if #[cfg(unix)] { + if #[cfg(any(target_os = "android", target_os = "linux"))] { mod unix; } }