Skip to content

Commit 971e14c

Browse files
committed
Replace cfg unix/windows with target_family
cfg flags "unix" and "windows" are now aliases to target_family = "unix" and target_family = "windows" respectively for backwards compatibility, so use the non-legacy way of targeting those OS families. Signed-off-by: Manos Pitsidianakis <[email protected]>
1 parent fdcea40 commit 971e14c

File tree

6 files changed

+25
-25
lines changed

6 files changed

+25
-25
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ bitflags = { version = "2.4.0", optional = true }
2626
thiserror = "1.0.40"
2727
vmm-sys-util = { version = "0.12.1", optional = true }
2828

29-
[target.'cfg(windows)'.dependencies.winapi]
29+
[target.'cfg(target_family = "windows")'.dependencies.winapi]
3030
version = "0.3"
3131
features = ["errhandlingapi", "sysinfoapi"]
3232

src/bitmap/backend/atomic_bitmap.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,11 +194,11 @@ impl Default for AtomicBitmap {
194194
#[cfg(feature = "backend-mmap")]
195195
impl NewBitmap for AtomicBitmap {
196196
fn with_len(len: usize) -> Self {
197-
#[cfg(unix)]
197+
#[cfg(target_family = "unix")]
198198
// SAFETY: There's no unsafe potential in calling this function.
199199
let page_size = unsafe { libc::sysconf(libc::_SC_PAGE_SIZE) };
200200

201-
#[cfg(windows)]
201+
#[cfg(target_family = "windows")]
202202
let page_size = {
203203
use winapi::um::sysinfoapi::{GetSystemInfo, LPSYSTEM_INFO, SYSTEM_INFO};
204204
let mut sysinfo = std::mem::MaybeUninit::zeroed();

src/bytes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ pub trait Bytes<A> {
340340
/// # let gm = GuestMemoryMmap::<()>::from_ranges(&vec![(start_addr, 0x400)])
341341
/// # .expect("Could not create guest memory");
342342
/// # let addr = GuestAddress(0x1010);
343-
/// # let mut file = if cfg!(unix) {
343+
/// # let mut file = if cfg!(target_family = "unix") {
344344
/// let mut file = File::open(Path::new("/dev/urandom")).expect("Could not open /dev/urandom");
345345
/// # file
346346
/// # } else {

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ pub mod mmap;
5858

5959
#[cfg(feature = "backend-mmap")]
6060
pub use mmap::{Error, GuestMemoryMmap, GuestRegionMmap, MmapRegion};
61-
#[cfg(all(feature = "backend-mmap", feature = "xen", unix))]
61+
#[cfg(all(feature = "backend-mmap", feature = "xen", target_family = "unix"))]
6262
pub use mmap::{MmapRange, MmapXenFlags};
6363

6464
pub mod volatile_memory;

src/mmap.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
//! This implementation is mmap-ing the memory of the guest into the current process.
1414
1515
use std::borrow::Borrow;
16-
#[cfg(unix)]
16+
#[cfg(target_family = "unix")]
1717
use std::io::{Seek, SeekFrom};
1818
use std::ops::Deref;
1919
use std::result;
@@ -28,24 +28,24 @@ use crate::guest_memory::{
2828
use crate::volatile_memory::{VolatileMemory, VolatileSlice};
2929
use crate::{AtomicAccess, Bytes, ReadVolatile, WriteVolatile};
3030

31-
#[cfg(all(not(feature = "xen"), unix))]
31+
#[cfg(all(not(feature = "xen"), target_family = "unix"))]
3232
mod unix;
3333

34-
#[cfg(all(feature = "xen", unix))]
34+
#[cfg(all(feature = "xen", target_family = "unix"))]
3535
pub(crate) mod xen;
3636

37-
#[cfg(windows)]
37+
#[cfg(target_family = "windows")]
3838
mod windows;
3939

40-
#[cfg(all(not(feature = "xen"), unix))]
40+
#[cfg(all(not(feature = "xen"), target_family = "unix"))]
4141
pub use unix::{Error as MmapRegionError, MmapRegion, MmapRegionBuilder};
4242

43-
#[cfg(all(feature = "xen", unix))]
43+
#[cfg(all(feature = "xen", target_family = "unix"))]
4444
pub use xen::{Error as MmapRegionError, MmapRange, MmapRegion, MmapXenFlags};
4545

46-
#[cfg(windows)]
46+
#[cfg(target_family = "windows")]
4747
pub use std::io::Error as MmapRegionError;
48-
#[cfg(windows)]
48+
#[cfg(target_family = "windows")]
4949
pub use windows::MmapRegion;
5050

5151
/// A `Bitmap` that can be created starting from an initial size.
@@ -80,7 +80,7 @@ pub enum Error {
8080
}
8181

8282
// TODO: use this for Windows as well after we redefine the Error type there.
83-
#[cfg(unix)]
83+
#[cfg(target_family = "unix")]
8484
/// Checks if a mapping of `size` bytes fits at the provided `file_offset`.
8585
///
8686
/// For a borrowed `FileOffset` and size, this function checks whether the mapping does not
@@ -1042,7 +1042,7 @@ mod tests {
10421042
let gm_list = [gm, gm_backed_by_file];
10431043
for gm in gm_list.iter() {
10441044
let addr = GuestAddress(0x1010);
1045-
let mut file = if cfg!(unix) {
1045+
let mut file = if cfg!(target_family = "unix") {
10461046
File::open(Path::new("/dev/zero")).unwrap()
10471047
} else {
10481048
File::open(Path::new("c:\\Windows\\system32\\ntoskrnl.exe")).unwrap()
@@ -1051,7 +1051,7 @@ mod tests {
10511051
gm.read_exact_volatile_from(addr, &mut file, mem::size_of::<u32>())
10521052
.unwrap();
10531053
let value: u32 = gm.read_obj(addr).unwrap();
1054-
if cfg!(unix) {
1054+
if cfg!(target_family = "unix") {
10551055
assert_eq!(value, 0);
10561056
} else {
10571057
assert_eq!(value, 0x0090_5a4d);
@@ -1060,7 +1060,7 @@ mod tests {
10601060
let mut sink = vec![0; mem::size_of::<u32>()];
10611061
gm.write_all_volatile_to(addr, &mut sink.as_mut_slice(), mem::size_of::<u32>())
10621062
.unwrap();
1063-
if cfg!(unix) {
1063+
if cfg!(target_family = "unix") {
10641064
assert_eq!(sink, vec![0; mem::size_of::<u32>()]);
10651065
} else {
10661066
assert_eq!(sink, vec![0x4d, 0x5a, 0x90, 0x00]);
@@ -1179,7 +1179,7 @@ mod tests {
11791179
// used for the backing file. Refer to Microsoft docs here:
11801180
// https://docs.microsoft.com/en-us/windows/desktop/api/memoryapi/nf-memoryapi-mapviewoffile
11811181
#[test]
1182-
#[cfg(unix)]
1182+
#[cfg(target_family = "unix")]
11831183
fn test_retrieve_offset_from_fd_backing_memory_region() {
11841184
let f = TempFile::new().unwrap().into_file();
11851185
f.set_len(0x1400).unwrap();

src/volatile_memory.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ use crate::atomic_integer::AtomicInteger;
3939
use crate::bitmap::{Bitmap, BitmapSlice, BS};
4040
use crate::{AtomicAccess, ByteValued, Bytes};
4141

42-
#[cfg(all(feature = "backend-mmap", feature = "xen", unix))]
42+
#[cfg(all(feature = "backend-mmap", feature = "xen", target_family = "unix"))]
4343
use crate::mmap::xen::{MmapXen as MmapInfo, MmapXenSlice};
4444

4545
#[cfg(not(feature = "xen"))]
@@ -322,15 +322,15 @@ pub struct PtrGuard {
322322

323323
// This isn't used anymore, but it protects the slice from getting unmapped while in use.
324324
// Once this goes out of scope, the memory is unmapped automatically.
325-
#[cfg(all(feature = "xen", unix))]
325+
#[cfg(all(feature = "xen", target_family = "unix"))]
326326
_slice: MmapXenSlice,
327327
}
328328

329329
#[allow(clippy::len_without_is_empty)]
330330
impl PtrGuard {
331331
#[allow(unused_variables)]
332332
fn new(mmap: Option<&MmapInfo>, addr: *mut u8, write: bool, len: usize) -> Self {
333-
#[cfg(all(feature = "xen", unix))]
333+
#[cfg(all(feature = "xen", target_family = "unix"))]
334334
let (addr, _slice) = {
335335
let prot = if write {
336336
libc::PROT_WRITE
@@ -345,7 +345,7 @@ impl PtrGuard {
345345
addr,
346346
len,
347347

348-
#[cfg(all(feature = "xen", unix))]
348+
#[cfg(all(feature = "xen", target_family = "unix"))]
349349
_slice,
350350
}
351351
}
@@ -1952,7 +1952,7 @@ mod tests {
19521952
let a = VolatileSlice::from(backing.as_mut_slice());
19531953
let s = a.as_volatile_slice();
19541954
assert!(s.write_obj(!0u32, 1).is_ok());
1955-
let mut file = if cfg!(unix) {
1955+
let mut file = if cfg!(target_family = "unix") {
19561956
File::open(Path::new("/dev/zero")).unwrap()
19571957
} else {
19581958
File::open(Path::new("c:\\Windows\\system32\\ntoskrnl.exe")).unwrap()
@@ -1968,7 +1968,7 @@ mod tests {
19681968
.is_err());
19691969

19701970
let value = s.read_obj::<u32>(1).unwrap();
1971-
if cfg!(unix) {
1971+
if cfg!(target_family = "unix") {
19721972
assert_eq!(value, 0);
19731973
} else {
19741974
assert_eq!(value, 0x0090_5a4d);
@@ -1980,7 +1980,7 @@ mod tests {
19801980
.write_all_volatile(&s.get_slice(1, size_of::<u32>()).unwrap())
19811981
.is_ok());
19821982

1983-
if cfg!(unix) {
1983+
if cfg!(target_family = "unix") {
19841984
assert_eq!(sink, vec![0; size_of::<u32>()]);
19851985
} else {
19861986
assert_eq!(sink, vec![0x4d, 0x5a, 0x90, 0x00]);

0 commit comments

Comments
 (0)