Skip to content

Commit 1755d1d

Browse files
committed
volatile_memory: avoid undefined symbols on Windows
Windows does not have PROT_READ or PROT_WRITE, remove them from PtrGuard's API and only reference them inside the `cfg` block. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1 parent 188ce1d commit 1755d1d

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/volatile_memory.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -318,9 +318,14 @@ pub struct PtrGuard {
318318
#[allow(clippy::len_without_is_empty)]
319319
impl PtrGuard {
320320
#[allow(unused_variables)]
321-
fn new(mmap: Option<&MmapInfo>, addr: *mut u8, prot: i32, len: usize) -> Self {
321+
fn new(mmap: Option<&MmapInfo>, addr: *mut u8, write: bool, len: usize) -> Self {
322322
#[cfg(all(feature = "xen", unix))]
323323
let (addr, _slice) = {
324+
let prot = if write {
325+
libc::PROT_WRITE
326+
} else {
327+
libc::PROT_READ
328+
};
324329
let slice = MmapInfo::mmap(mmap, addr, prot, len);
325330
(slice.addr(), slice)
326331
};
@@ -335,7 +340,7 @@ impl PtrGuard {
335340
}
336341

337342
fn read(mmap: Option<&MmapInfo>, addr: *mut u8, len: usize) -> Self {
338-
Self::new(mmap, addr, libc::PROT_READ, len)
343+
Self::new(mmap, addr, false, len)
339344
}
340345

341346
/// Returns a non-mutable pointer to the beginning of the slice.
@@ -356,7 +361,7 @@ pub struct PtrGuardMut(PtrGuard);
356361
#[allow(clippy::len_without_is_empty)]
357362
impl PtrGuardMut {
358363
fn write(mmap: Option<&MmapInfo>, addr: *mut u8, len: usize) -> Self {
359-
Self(PtrGuard::new(mmap, addr, libc::PROT_WRITE, len))
364+
Self(PtrGuard::new(mmap, addr, true, len))
360365
}
361366

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

0 commit comments

Comments
 (0)