diff options
author | Johannes Stoelp <johannes.stoelp@gmail.com> | 2021-12-10 23:47:04 +0100 |
---|---|---|
committer | Johannes Stoelp <johannes.stoelp@gmail.com> | 2021-12-10 23:47:04 +0100 |
commit | 1be06acc235878253977ae75467db591763f31bf (patch) | |
tree | 25b80c85f69ab515939cc059c7bec3eb04771a38 /examples/long_mode.rs | |
parent | 25b430f13a828f6e83c309e6bff9b5d2f0d85b0d (diff) | |
download | mini-kvm-rs-1be06acc235878253977ae75467db591763f31bf.tar.gz mini-kvm-rs-1be06acc235878253977ae75467db591763f31bf.zip |
example:long_mode: Assert phys memory against bytes written from guest to virt address.
Diffstat (limited to 'examples/long_mode.rs')
-rw-r--r-- | examples/long_mode.rs | 10 |
1 files changed, 10 insertions, 0 deletions
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(()) } |