Skip to content

Commit 56feda9

Browse files
committed
volatile_memory: avoid undefined symbols on Windows
Windows does not have PROT_READ or PROT_WRITE, remove them. Signed-off-by: Paolo Bonzini <[email protected]>
1 parent f27f29a commit 56feda9

File tree

1 file changed

+25
-7
lines changed

1 file changed

+25
-7
lines changed

src/volatile_memory.rs

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -315,15 +315,33 @@ pub struct PtrGuard {
315315
_slice: MmapXenSlice,
316316
}
317317

318+
#[cfg(all(feature = "xen", unix))]
319+
impl PtrGuard {
320+
const PROT_READ: i32 = libc::PROT_READ;
321+
const PROT_WRITE: i32 = libc::PROT_WRITE;
322+
323+
fn map(mmap: Option<&MmapInfo>, addr: *mut u8, prot: i32, len: usize) -> (*mut u8, MmapXenSlice) {
324+
let slice = MmapInfo::mmap(mmap, addr, prot, len);
325+
(slice.addr(), slice)
326+
}
327+
}
328+
329+
#[cfg(not(all(feature = "xen", unix)))]
330+
impl PtrGuard {
331+
pub(self) const PROT_READ: i32 = 0
332+
pub(self) const PROT_WRITE: i32 = 0;
333+
334+
fn map(_mmap: Option<&MmapInfo>, addr: *mut u8, _prot: i32, _len: usize) -> (*mut u8, ()) {
335+
(addr, ())
336+
}
337+
}
338+
318339
#[allow(clippy::len_without_is_empty)]
319340
impl PtrGuard {
341+
320342
#[allow(unused_variables)]
321343
fn new(mmap: Option<&MmapInfo>, addr: *mut u8, prot: i32, len: usize) -> Self {
322-
#[cfg(all(feature = "xen", unix))]
323-
let (addr, _slice) = {
324-
let slice = MmapInfo::mmap(mmap, addr, prot, len);
325-
(slice.addr(), slice)
326-
};
344+
let (addr, _slice) = Self::map(mmap, addr, prot, len);
327345

328346
Self {
329347
addr,
@@ -335,7 +353,7 @@ impl PtrGuard {
335353
}
336354

337355
fn read(mmap: Option<&MmapInfo>, addr: *mut u8, len: usize) -> Self {
338-
Self::new(mmap, addr, libc::PROT_READ, len)
356+
Self::new(mmap, addr, PtrGuard::PROT_READ, len)
339357
}
340358

341359
/// Returns a non-mutable pointer to the beginning of the slice.
@@ -356,7 +374,7 @@ pub struct PtrGuardMut(PtrGuard);
356374
#[allow(clippy::len_without_is_empty)]
357375
impl PtrGuardMut {
358376
fn write(mmap: Option<&MmapInfo>, addr: *mut u8, len: usize) -> Self {
359-
Self(PtrGuard::new(mmap, addr, libc::PROT_WRITE, len))
377+
Self(PtrGuard::new(mmap, addr, PtrGuard::PROT_WRITE, len))
360378
}
361379

362380
/// Returns a mutable pointer to the beginning of the slice. Mutable accesses performed

0 commit comments

Comments
 (0)