Skip to content

Commit ce075a2

Browse files
committed
refactor(xen): allow extracting guest_base from MmapXen
Currently, on xen the guest base in tracked in two different places. GuestRegionMmap, defined in mmap.rs, and (almost) each of the implemented of XenMmapTrait. As a first step for eliminating this duplication, add getters so that the guest base stored in the XenMmapTrait trait object stored in MmapXen can be extracted. Signed-off-by: Patrick Roy <[email protected]>
1 parent 5eb996a commit ce075a2

File tree

1 file changed

+24
-8
lines changed

1 file changed

+24
-8
lines changed

src/mmap/xen.rs

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -508,11 +508,12 @@ fn validate_file(file_offset: &Option<FileOffset>) -> Result<(i32, u64)> {
508508
trait MmapXenTrait: std::fmt::Debug {
509509
fn mmap_slice(&self, addr: *const u8, prot: i32, len: usize) -> Result<MmapXenSlice>;
510510
fn addr(&self) -> *mut u8;
511+
fn guest_base(&self) -> GuestAddress;
511512
}
512513

513514
// Standard Unix memory mapping for testing other crates.
514515
#[derive(Clone, Debug, PartialEq)]
515-
struct MmapXenUnix(MmapUnix);
516+
struct MmapXenUnix(MmapUnix, GuestAddress);
516517

517518
impl MmapXenUnix {
518519
fn new(range: &MmapRange) -> Result<Self> {
@@ -522,13 +523,16 @@ impl MmapXenUnix {
522523
(-1, 0)
523524
};
524525

525-
Ok(Self(MmapUnix::new(
526-
range.size,
527-
range.prot.ok_or(Error::UnexpectedError)?,
528-
range.flags.ok_or(Error::UnexpectedError)?,
529-
fd,
530-
offset,
531-
)?))
526+
Ok(Self(
527+
MmapUnix::new(
528+
range.size,
529+
range.prot.ok_or(Error::UnexpectedError)?,
530+
range.flags.ok_or(Error::UnexpectedError)?,
531+
fd,
532+
offset,
533+
)?,
534+
range.addr,
535+
))
532536
}
533537
}
534538

@@ -541,6 +545,10 @@ impl MmapXenTrait for MmapXenUnix {
541545
fn addr(&self) -> *mut u8 {
542546
self.0.addr()
543547
}
548+
549+
fn guest_base(&self) -> GuestAddress {
550+
self.1
551+
}
544552
}
545553

546554
// Privcmd mmap batch v2 command
@@ -651,6 +659,10 @@ impl MmapXenTrait for MmapXenForeign {
651659
fn addr(&self) -> *mut u8 {
652660
self.unix_mmap.addr()
653661
}
662+
663+
fn guest_base(&self) -> GuestAddress {
664+
self.guest_base
665+
}
654666
}
655667

656668
// Xen Grant memory mapping interface.
@@ -886,6 +898,10 @@ impl MmapXenTrait for MmapXenGrant {
886898
null_mut()
887899
}
888900
}
901+
902+
fn guest_base(&self) -> GuestAddress {
903+
self.guest_base
904+
}
889905
}
890906

891907
impl Drop for MmapXenGrant {

0 commit comments

Comments
 (0)