pub struct WorldMemory {
second_level: SecondLevelMemory,
map: GuestMap,
frames: Vec<PhysFrame>,
}Expand description
Guest memory of a world.
Fields§
§second_level: SecondLevelMemory§map: GuestMap§frames: Vec<PhysFrame>Implementations§
Source§impl WorldMemory
impl WorldMemory
Sourcepub fn map(
&mut self,
_caps: &HwCaps,
gpa: u64,
len: u64,
perms_bits: u32,
memtype: u8,
) -> Result<u64, VmError>
pub fn map( &mut self, _caps: &HwCaps, gpa: u64, len: u64, perms_bits: u32, memtype: u8, ) -> Result<u64, VmError>
Maps a GPA range into guest RAM (frames allocated and pinned).
memtype must be 0 (default write-back); the other types are not yet
supported and are rejected by the caller.
§Granularity
The range is split by [memmap::plan_map]: a 2 MiB-aligned middle is
mapped with 2 MiB second-level leaves when the 512 newly allocated
host frames are 2 MiB aligned and physically contiguous, while a
partial head or tail stays on 4 KiB pages. A 2 MiB segment whose frames
are not contiguous (fragmented allocator) falls back to 4 KiB pages for
that segment, so correctness never depends on host contiguity.
Large leaves reduce second-level table memory and TLB pressure; the fallback keeps the mapping usable when the allocator cannot provide a contiguous block.
On failure, every mapping and every frame allocated during the call is undone: the world’s memory stays consistent. Quota accounting is unchanged: a 2 MiB leaf still counts as 512 pages.
Sourcepub fn alias(
&mut self,
gpa: u64,
source_gpa: u64,
len: u64,
perms_bits: u32,
) -> Result<u64, VmError>
pub fn alias( &mut self, gpa: u64, source_gpa: u64, len: u64, perms_bits: u32, ) -> Result<u64, VmError>
Maps a GPA range as an alias of already-mapped guest memory.
The source pages are translated through the second-level tables and the
destination GPA is mapped to the same host frames; no frame is
allocated or freed. This is how the PC maps the BIOS ROM at both
0xC0000 and the top-of-4GiB alias (0xFFFC0000) that the reset
vector and SeaBIOS’ high code use.
Sourcefn rollback_alias(&mut self, installed: &[u64], gpa: u64)
fn rollback_alias(&mut self, installed: &[u64], gpa: u64)
Undoes an alias mapping without touching the source frames.
Sourcefn rollback_mapping(
&mut self,
installed: &[(u64, u64, bool)],
frames: Vec<PhysFrame>,
)
fn rollback_mapping( &mut self, installed: &[(u64, u64, bool)], frames: Vec<PhysFrame>, )
Undoes installed mappings and frees every frame of a failed map.
Mappings are torn down in reverse installation order; 2 MiB leaves use
unmap_2m, 4 KiB pages use unmap_4k. The frame list is then returned
to the allocator exactly once (it is moved in, so no double free is
possible).
Sourcepub fn regions(&self) -> impl Iterator<Item = &Region>
pub fn regions(&self) -> impl Iterator<Item = &Region>
Reserved guest-physical ranges, in address order.
Sourcepub fn second_level_pointer(&self, caps: &HwCaps) -> u64
pub fn second_level_pointer(&self, caps: &HwCaps) -> u64
Value of the translation pointer (EPTP) for the control block.
Auto Trait Implementations§
impl Forget for WorldMemory
impl Freeze for WorldMemory
impl Move for WorldMemory
impl RefUnwindSafe for WorldMemory
impl Send for WorldMemory
impl Sync for WorldMemory
impl Unpin for WorldMemory
impl UnsafeUnpin for WorldMemory
impl UnwindSafe for WorldMemory
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more