Skip to main content

WorldMemory

Struct WorldMemory 

Source
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

Source

pub fn new(quota_pages: u64) -> Result<Self, VmError>

Creates empty guest memory.

Source

pub fn pages(&self) -> u64

Reserved pages.

Source

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.

Source

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.

Source

fn rollback_alias(&mut self, installed: &[u64], gpa: u64)

Undoes an alias mapping without touching the source frames.

Source

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).

Source

pub fn translate(&self, gpa: u64) -> Option<u64>

Translates a GPA (diagnostic).

Source

pub fn regions(&self) -> impl Iterator<Item = &Region>

Reserved guest-physical ranges, in address order.

Source

pub fn second_level_pointer(&self, caps: &HwCaps) -> u64

Value of the translation pointer (EPTP) for the control block.

Source

pub fn destroy(self)

Frees the translation tables, then the guest frames.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.