From 1be06acc235878253977ae75467db591763f31bf Mon Sep 17 00:00:00 2001 From: Johannes Stoelp Date: Fri, 10 Dec 2021 23:47:04 +0100 Subject: example:long_mode: Assert phys memory against bytes written from guest to virt address. --- examples/long_mode.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'examples/long_mode.rs') diff --git a/examples/long_mode.rs b/examples/long_mode.rs index 6d52abe..06af791 100644 --- a/examples/long_mode.rs +++ b/examples/long_mode.rs @@ -6,6 +6,7 @@ use kvm_rs::{PhysAddr, UserMem}; fn setup_long_mode_segments(sregs: &mut kvm_sys::kvm_sregs) { let code_seg = |seg: &mut kvm_sys::kvm_segment| { + // Segment base address (unused in 64bit). seg.base = 0x0; // Limit (unused in 64bit). seg.limit = 0x0; @@ -28,6 +29,7 @@ fn setup_long_mode_segments(sregs: &mut kvm_sys::kvm_sregs) { }; let data_seg = |seg: &mut kvm_sys::kvm_segment| { + // Segment base address (unused in 64bit). seg.base = 0x0; // Limit (unused in 64bit). seg.limit = 0x0; @@ -182,5 +184,13 @@ fn main() -> std::io::Result<()> { }; } + // The guest writes at virtual address [0x2000 - 0x2003] which will be visible in physical + // memory at [0x6000 - 0x6003] due to the paging structure we setup. + // See `setup_long_mode_4level_paging` above for details. + assert_eq!( + &mem.as_ref()[0x4000 + 0x2000..][..4], + &[0xaa, 0xbb, 0xcc, 0xdd] + ); + Ok(()) } -- cgit v1.2.3