Skip to main content

Image

Struct Image 

Source
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: usize

Implementations§

Source§

impl<'a> Image<'a>

Source

pub fn parse(bytes: &'a [u8]) -> Result<Self, ImageError>

Parses and validates a guest image.

Never panics: every malformed input yields an ImageError.

Source

pub const fn kind(&self) -> ImageKind

Kind of executable.

Source

pub const fn entry(&self) -> u64

Entry point, as a guest virtual address encoded in the image.

Source

pub fn segments(&self) -> &[Segment]

Loadable segments, sorted by increasing virtual address.

Source

pub const fn segment_count(&self) -> usize

Number of loadable segments.

Source

pub const fn base_vaddr(&self) -> u64

Lowest page-aligned virtual address covered by the image.

Source

pub const fn span_len(&self) -> u64

Length in bytes of the page-aligned image footprint.

Source

pub fn total_pages(&self) -> u64

Total number of 4 KiB pages covered by the image.

Source

pub const fn file_size(&self) -> usize

Size of the image file in bytes.

Source

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.

Source

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.

Source

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

Source

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.

Source

pub fn entry_is_mapped(&self) -> bool

True if the entry point lies inside a loadable segment.

Source

pub fn entry_is_executable(&self) -> bool

True if the entry point lies inside an executable segment.

Trait Implementations§

Source§

impl<'a> Clone for Image<'a>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Copy for Image<'a>

Source§

impl<'a> Debug for Image<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a> Eq for Image<'a>

Source§

impl<'a> PartialEq for Image<'a>

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

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> 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.