Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
# Changelog

## [Unreleased]

### Added

### Changed
- \[[#373](https://github.com/rust-vmm/vm-memory/pull/373)\] Make the 'rawfd' feature a NOP on Windows

### Fixed

### Removed

### Deprecated

## 0.18.0

### Changed
Expand Down
12 changes: 6 additions & 6 deletions benches/mmap/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
extern crate criterion;
extern crate vm_memory;

#[cfg(feature = "rawfd")]
#[cfg(all(feature = "rawfd", not(target_os = "windows")))]
use std::fs::{File, OpenOptions};
use std::mem::size_of;

#[cfg(feature = "rawfd")]
#[cfg(all(feature = "rawfd", not(target_os = "windows")))]
use std::path::Path;

use core::hint::black_box;
Expand Down Expand Up @@ -88,9 +88,9 @@ pub fn benchmark_for_mmap(c: &mut Criterion) {
let mut image = make_image(ACCESS_SIZE);
let buf = &mut [0u8; ACCESS_SIZE];

#[cfg(feature = "rawfd")]
#[cfg(all(feature = "rawfd", not(target_os = "windows")))]
let mut file = File::open(Path::new("/dev/zero")).expect("Could not open /dev/zero");
#[cfg(feature = "rawfd")]
#[cfg(all(feature = "rawfd", not(target_os = "windows")))]
let mut file_to_write = OpenOptions::new()
.write(true)
.open("/dev/null")
Expand All @@ -116,7 +116,7 @@ pub fn benchmark_for_mmap(c: &mut Criterion) {
})
});

#[cfg(feature = "rawfd")]
#[cfg(all(feature = "rawfd", not(target_os = "windows")))]
c.bench_function(format!("read_from_file_{offset:#0X}").as_str(), |b| {
b.iter(|| {
black_box(&memory)
Expand Down Expand Up @@ -165,7 +165,7 @@ pub fn benchmark_for_mmap(c: &mut Criterion) {
})
});

#[cfg(feature = "rawfd")]
#[cfg(all(feature = "rawfd", not(target_os = "windows")))]
c.bench_function(format!("write_to_file_{offset:#0X}").as_str(), |b| {
b.iter(|| {
black_box(&memory)
Expand Down
36 changes: 18 additions & 18 deletions src/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ use crate::volatile_memory::copy_slice_impl::{copy_from_volatile_slice, copy_to_
use crate::{VolatileMemoryError, VolatileSlice};
use std::io::{Cursor, ErrorKind};

#[cfg(feature = "rawfd")]
#[cfg(all(feature = "rawfd", not(target_os = "windows")))]
use std::io::Stdout;

#[cfg(feature = "rawfd")]
#[cfg(all(feature = "rawfd", not(target_os = "windows")))]
use std::os::fd::{AsFd, AsRawFd, BorrowedFd};

macro_rules! retry_eintr {
Expand Down Expand Up @@ -131,7 +131,7 @@ pub trait WriteVolatile {

macro_rules! impl_read_write_volatile_for_raw_fd {
($raw_fd_ty:ty) => {
#[cfg(feature = "rawfd")]
#[cfg(all(feature = "rawfd", not(target_os = "windows")))]
impl ReadVolatile for $raw_fd_ty {
fn read_volatile<B: BitmapSlice>(
&mut self,
Expand All @@ -141,7 +141,7 @@ macro_rules! impl_read_write_volatile_for_raw_fd {
}
}

#[cfg(feature = "rawfd")]
#[cfg(all(feature = "rawfd", not(target_os = "windows")))]
impl ReadVolatile for &$raw_fd_ty {
fn read_volatile<B: BitmapSlice>(
&mut self,
Expand All @@ -151,7 +151,7 @@ macro_rules! impl_read_write_volatile_for_raw_fd {
}
}

#[cfg(feature = "rawfd")]
#[cfg(all(feature = "rawfd", not(target_os = "windows")))]
impl ReadVolatile for &mut $raw_fd_ty {
fn read_volatile<B: BitmapSlice>(
&mut self,
Expand All @@ -161,7 +161,7 @@ macro_rules! impl_read_write_volatile_for_raw_fd {
}
}

#[cfg(feature = "rawfd")]
#[cfg(all(feature = "rawfd", not(target_os = "windows")))]
impl WriteVolatile for $raw_fd_ty {
fn write_volatile<B: BitmapSlice>(
&mut self,
Expand All @@ -171,7 +171,7 @@ macro_rules! impl_read_write_volatile_for_raw_fd {
}
}

#[cfg(feature = "rawfd")]
#[cfg(all(feature = "rawfd", not(target_os = "windows")))]
impl WriteVolatile for &$raw_fd_ty {
fn write_volatile<B: BitmapSlice>(
&mut self,
Expand All @@ -181,7 +181,7 @@ macro_rules! impl_read_write_volatile_for_raw_fd {
}
}

#[cfg(feature = "rawfd")]
#[cfg(all(feature = "rawfd", not(target_os = "windows")))]
impl WriteVolatile for &mut $raw_fd_ty {
fn write_volatile<B: BitmapSlice>(
&mut self,
Expand All @@ -193,7 +193,7 @@ macro_rules! impl_read_write_volatile_for_raw_fd {
};
}

#[cfg(feature = "rawfd")]
#[cfg(all(feature = "rawfd", not(target_os = "windows")))]
impl WriteVolatile for Stdout {
fn write_volatile<B: BitmapSlice>(
&mut self,
Expand All @@ -203,7 +203,7 @@ impl WriteVolatile for Stdout {
}
}

#[cfg(feature = "rawfd")]
#[cfg(all(feature = "rawfd", not(target_os = "windows")))]
impl WriteVolatile for &Stdout {
fn write_volatile<B: BitmapSlice>(
&mut self,
Expand All @@ -223,7 +223,7 @@ impl_read_write_volatile_for_raw_fd!(std::os::fd::BorrowedFd<'_>);
/// the given [`VolatileSlice`].
///
/// Returns the numbers of bytes read.
#[cfg(feature = "rawfd")]
#[cfg(all(feature = "rawfd", not(target_os = "windows")))]
fn read_volatile_raw_fd(
raw_fd: BorrowedFd<'_>,
buf: &mut VolatileSlice<impl BitmapSlice>,
Expand Down Expand Up @@ -254,7 +254,7 @@ fn read_volatile_raw_fd(
/// data stored in the given [`VolatileSlice`].
///
/// Returns the numbers of bytes written.
#[cfg(feature = "rawfd")]
#[cfg(all(feature = "rawfd", not(target_os = "windows")))]
fn write_volatile_raw_fd(
raw_fd: BorrowedFd<'_>,
buf: &VolatileSlice<impl BitmapSlice>,
Expand Down Expand Up @@ -435,9 +435,9 @@ mod tests {
use crate::io::{ReadVolatile, WriteVolatile};
use crate::{VolatileMemoryError, VolatileSlice};
use std::io::{Cursor, ErrorKind};
#[cfg(feature = "rawfd")]
#[cfg(all(feature = "rawfd", not(target_os = "windows")))]
use std::io::{Read, Seek, Write};
#[cfg(feature = "rawfd")]
#[cfg(all(feature = "rawfd", not(target_os = "windows")))]
use vmm_sys_util::tempfile::TempFile;

// ---- Test ReadVolatile for &[u8] ----
Expand Down Expand Up @@ -474,7 +474,7 @@ mod tests {
}

// ---- Test ReadVolatile for File ----
#[cfg(all(feature = "rawfd", not(miri)))]
#[cfg(all(feature = "rawfd", not(miri), not(target_os = "windows")))]
fn read_4_bytes_from_file(source: Vec<u8>, expected_output: [u8; 5]) {
let mut temp_file = TempFile::new().unwrap().into_file();
temp_file.write_all(source.as_ref()).unwrap();
Expand Down Expand Up @@ -518,7 +518,7 @@ mod tests {

for (input, output) in test_cases {
read_4_bytes_to_5_byte_memory(input.clone(), output);
#[cfg(all(feature = "rawfd", not(miri)))]
#[cfg(all(feature = "rawfd", not(miri), not(target_os = "windows")))]
read_4_bytes_from_file(input, output);
}
}
Expand Down Expand Up @@ -559,7 +559,7 @@ mod tests {
}

// ---- Test ẂriteVolatile for File works ----
#[cfg(all(feature = "rawfd", not(miri)))]
#[cfg(all(feature = "rawfd", not(miri), not(target_os = "windows")))]
fn write_5_bytes_to_file(mut source: Vec<u8>) {
// Test write_volatile for File works
let mut temp_file = TempFile::new().unwrap().into_file();
Expand Down Expand Up @@ -603,7 +603,7 @@ mod tests {

for (input, output) in test_cases {
write_4_bytes_to_5_byte_vec(input.clone(), output);
#[cfg(all(feature = "rawfd", not(miri)))]
#[cfg(all(feature = "rawfd", not(miri), not(target_os = "windows")))]
write_5_bytes_to_file(input);
}
}
Expand Down
3 changes: 0 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@
#[cfg(not(target_pointer_width = "64"))]
compile_error!("vm-memory only supports 64-bit targets!");

#[cfg(all(target_family = "windows", feature = "rawfd"))]
compile_error!("rawfd feature is not supported on Windows targets!");

#[cfg(all(target_family = "windows", feature = "xen"))]
compile_error!("xen feature is not supported on Windows targets!");

Expand Down
4 changes: 2 additions & 2 deletions src/mmap/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ mod tests {
use crate::{Bytes, GuestMemoryBackend, GuestMemoryError};

use std::io::Write;
#[cfg(feature = "rawfd")]
#[cfg(all(feature = "rawfd", not(target_os = "windows")))]
use std::{fs::File, path::Path};
use vmm_sys_util::tempfile::TempFile;

Expand Down Expand Up @@ -473,7 +473,7 @@ mod tests {
}

#[test]
#[cfg(feature = "rawfd")]
#[cfg(all(feature = "rawfd", not(target_os = "windows")))]
#[cfg(not(miri))]
fn read_to_and_write_from_mem() {
use std::mem;
Expand Down
8 changes: 4 additions & 4 deletions src/volatile_memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1466,11 +1466,11 @@ mod tests {
use super::*;
use std::alloc::Layout;

#[cfg(feature = "rawfd")]
#[cfg(all(feature = "rawfd", not(target_os = "windows")))]
use std::fs::File;
#[cfg(feature = "backend-bitmap")]
use std::mem::size_of_val;
#[cfg(feature = "rawfd")]
#[cfg(all(feature = "rawfd", not(target_os = "windows")))]
use std::path::Path;
use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::{Arc, Barrier};
Expand All @@ -1479,7 +1479,7 @@ mod tests {
use matches::assert_matches;
#[cfg(feature = "backend-bitmap")]
use std::num::NonZeroUsize;
#[cfg(feature = "rawfd")]
#[cfg(all(feature = "rawfd", not(target_os = "windows")))]
use vmm_sys_util::tempfile::TempFile;

#[cfg(feature = "backend-bitmap")]
Expand Down Expand Up @@ -1972,7 +1972,7 @@ mod tests {
}

#[test]
#[cfg(feature = "rawfd")]
#[cfg(all(feature = "rawfd", not(target_os = "windows")))]
fn mem_read_and_write() {
let mut backing = vec![0u8; 5];
let a = VolatileSlice::from(backing.as_mut_slice());
Expand Down