@@ -153,6 +153,7 @@ use crate::vstate::memory::{
153153use crate :: vstate:: vcpu:: VcpuState ;
154154pub use crate :: vstate:: vcpu:: { Vcpu , VcpuConfig , VcpuEvent , VcpuHandle , VcpuResponse } ;
155155pub use crate :: vstate:: vm:: Vm ;
156+ use serde:: { Deserialize , Serialize } ;
156157
157158/// Shorthand type for the EventManager flavour used by Firecracker.
158159pub type EventManager = BaseEventManager < Arc < Mutex < dyn MutEventSubscriber > > > ;
@@ -191,6 +192,20 @@ pub enum FcExitCode {
191192 ArgParsing = 153 ,
192193}
193194
195+ /// Describes the region of guest memory that can be used for creating the memfile.
196+ #[ derive( Clone , Copy , Debug , Default , PartialEq , Eq , Deserialize , Serialize ) ]
197+ pub struct GuestMemoryRegionMapping {
198+ /// Base host virtual address where the guest memory contents for this region
199+ /// should be copied/populated.
200+ pub base_host_virt_addr : u64 ,
201+ /// Region size.
202+ pub size : usize ,
203+ /// Offset in the backend file/buffer where the region contents are.
204+ pub offset : u64 ,
205+ /// The configured page size for this memory region.
206+ pub page_size : usize ,
207+ }
208+
194209/// Timeout used in recv_timeout, when waiting for a vcpu response on
195210/// Pause/Resume/Save/Restore. A high enough limit that should not be reached during normal usage,
196211/// used to detect a potential vcpu deadlock.
@@ -451,6 +466,21 @@ impl Vmm {
451466 & self . guest_memory
452467 }
453468
469+ pub fn guest_memory_mappings ( & self , vm_info : & VmInfo ) -> Vec < GuestMemoryRegionMapping > {
470+ let mut offset = 0 ;
471+ let mut mappings = Vec :: new ( ) ;
472+ for mem_region in self . guest_memory ( ) . iter ( ) {
473+ mappings. push ( GuestMemoryRegionMapping {
474+ base_host_virt_addr : mem_region. as_ptr ( ) as u64 ,
475+ size : mem_region. size ( ) ,
476+ offset,
477+ page_size : vm_info. huge_pages . page_size_kib ( ) ,
478+ } ) ;
479+ offset += mem_region. size ( ) as u64 ;
480+ }
481+ mappings
482+ }
483+
454484 /// Sets RDA bit in serial console
455485 pub fn emulate_serial_init ( & self ) -> Result < ( ) , EmulateSerialInitError > {
456486 // When restoring from a previously saved state, there is no serial
0 commit comments