Skip to content

Commit aa37f15

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 ba461bd commit aa37f15

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
@@ -506,11 +506,12 @@ fn validate_file(file_offset: &Option<FileOffset>) -> Result<(i32, u64)> {
506506
trait MmapXenTrait: std::fmt::Debug {
507507
fn mmap_slice(&self, addr: *const u8, prot: i32, len: usize) -> Result<MmapXenSlice>;
508508
fn addr(&self) -> *mut u8;
509+
fn guest_base(&self) -> GuestAddress;
509510
}
510511

511512
// Standard Unix memory mapping for testing other crates.
512513
#[derive(Clone, Debug, PartialEq)]
513-
struct MmapXenUnix(MmapUnix);
514+
struct MmapXenUnix(MmapUnix, GuestAddress);
514515

515516
impl MmapXenUnix {
516517
fn new(range: &MmapRange) -> Result<Self> {
@@ -521,13 +522,16 @@ impl MmapXenUnix {
521522
(-1, 0)
522523
};
523524

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

@@ -540,6 +544,10 @@ impl MmapXenTrait for MmapXenUnix {
540544
fn addr(&self) -> *mut u8 {
541545
self.0.addr()
542546
}
547+
548+
fn guest_base(&self) -> GuestAddress {
549+
self.1
550+
}
543551
}
544552

545553
// Privcmd mmap batch v2 command
@@ -650,6 +658,10 @@ impl MmapXenTrait for MmapXenForeign {
650658
fn addr(&self) -> *mut u8 {
651659
self.unix_mmap.addr()
652660
}
661+
662+
fn guest_base(&self) -> GuestAddress {
663+
self.guest_base
664+
}
653665
}
654666

655667
// Xen Grant memory mapping interface.
@@ -885,6 +897,10 @@ impl MmapXenTrait for MmapXenGrant {
885897
null_mut()
886898
}
887899
}
900+
901+
fn guest_base(&self) -> GuestAddress {
902+
self.guest_base
903+
}
888904
}
889905

890906
impl Drop for MmapXenGrant {

0 commit comments

Comments
 (0)