pub struct Image<'a> {
bytes: &'a [u8],
kind: ImageKind,
entry: u64,
base_vaddr: u64,
span_len: u64,
segments: [Segment; 32],
count: usize,
}Expand description
A parsed guest image.
Borrows the image bytes; the returned plan is valid as long as the slice is. Copying the structure is cheap (the segment table is inline).
Fields§
§bytes: &'a [u8]§kind: ImageKind§entry: u64§base_vaddr: u64§span_len: u64§segments: [Segment; 32]§count: usizeImplementations§
Source§impl<'a> Image<'a>
impl<'a> Image<'a>
Sourcepub fn parse(bytes: &'a [u8]) -> Result<Self, ImageError>
pub fn parse(bytes: &'a [u8]) -> Result<Self, ImageError>
Parses and validates a guest image.
Never panics: every malformed input yields an ImageError.
Sourcepub const fn segment_count(&self) -> usize
pub const fn segment_count(&self) -> usize
Number of loadable segments.
Sourcepub const fn base_vaddr(&self) -> u64
pub const fn base_vaddr(&self) -> u64
Lowest page-aligned virtual address covered by the image.
Sourcepub fn total_pages(&self) -> u64
pub fn total_pages(&self) -> u64
Total number of 4 KiB pages covered by the image.
Sourcepub fn bytes_for_segment(&self, segment: &Segment) -> Option<&'a [u8]>
pub fn bytes_for_segment(&self, segment: &Segment) -> Option<&'a [u8]>
File-backed bytes of a segment.
Returns None only if the caller passes a segment that does not belong
to this image; parsed segments are always in bounds.
Sourcepub fn load_span(&self, load_base_gpa: u64) -> Option<(u64, u64)>
pub fn load_span(&self, load_base_gpa: u64) -> Option<(u64, u64)>
Guest-physical span of the image when loaded at load_base_gpa.
Returns (min, max) with max exclusive. load_base_gpa must be
page-aligned (the kernel layer enforces it); the span is page-aligned on
both ends. None when the span does not fit in a 64-bit address.
Sourcepub fn segment_gpa(&self, load_base_gpa: u64, segment: &Segment) -> Option<u64>
pub fn segment_gpa(&self, load_base_gpa: u64, segment: &Segment) -> Option<u64>
Guest-physical address of the first page of segment when the image is
loaded at load_base_gpa (page-aligned).
Sourcepub fn entry_gpa(&self, load_base_gpa: u64) -> Option<u64>
pub fn entry_gpa(&self, load_base_gpa: u64) -> Option<u64>
Guest-physical entry point when the image is loaded at load_base_gpa.
None when the entry point lies below the image base or when the
relocation overflows.
Sourcepub fn entry_is_mapped(&self) -> bool
pub fn entry_is_mapped(&self) -> bool
True if the entry point lies inside a loadable segment.
Sourcepub fn entry_is_executable(&self) -> bool
pub fn entry_is_executable(&self) -> bool
True if the entry point lies inside an executable segment.
Trait Implementations§
impl<'a> Copy for Image<'a>
impl<'a> Eq for Image<'a>
impl<'a> StructuralPartialEq for Image<'a>
Auto Trait Implementations§
impl<'a> Forget for Image<'a>
impl<'a> Freeze for Image<'a>
impl<'a> Move for Image<'a>
impl<'a> RefUnwindSafe for Image<'a>
impl<'a> Send for Image<'a>
impl<'a> Sync for Image<'a>
impl<'a> Unpin for Image<'a>
impl<'a> UnsafeUnpin for Image<'a>
impl<'a> UnwindSafe for Image<'a>
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.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