Skip to main content

Segment

Struct Segment 

Source
pub struct Segment {
    pub vaddr: u64,
    pub memsz: u64,
    pub filesz: u64,
    pub file_offset: u64,
    pub flags: u32,
}
Expand description

One loadable segment of a guest image.

All addresses are guest virtual addresses as encoded in the image; the kernel layer relocates them through Image::segment_gpa.

Fields§

§vaddr: u64

First guest virtual address of the segment.

§memsz: u64

Size in memory, including the zero-filled tail (BSS).

§filesz: u64

Size of the file-backed prefix.

§file_offset: u64

Offset of the file-backed prefix in the image file.

§flags: u32

Raw ELF p_flags bits (PF_X, PF_W, PF_R).

Implementations§

Source§

impl Segment

Source

pub const fn page_start(&self) -> u64

First virtual address of the segment, page-aligned down.

Source

pub const fn page_offset(&self) -> u64

Offset of the segment start inside its first page.

Source

pub fn page_count(&self) -> u64

Number of 4 KiB pages covered by the segment.

Source

pub fn page_len(&self) -> u64

Length in bytes of the page-aligned footprint.

Only meaningful for a segment parsed by Image::parse (the length is then always a non-zero multiple of PAGE_SIZE); a segment built by hand with overflowing values yields 0 instead of panicking.

Source

pub const fn end_vaddr(&self) -> u64

End virtual address (exclusive); valid because parsing checked for overflow.

Source

pub const fn file_end(&self) -> u64

End offset of the file-backed prefix (exclusive).

Source

pub const fn is_readable(&self) -> bool

True if the segment is readable.

Source

pub const fn is_writable(&self) -> bool

True if the segment is writable.

Source

pub const fn is_executable(&self) -> bool

True if the segment is executable.

Source

pub const fn perms_bits(&self) -> u32

Permissions encoded for the world memory map (s9vm::memmap): bit 1 = read, bit 2 = write, bit 4 = execute.

A segment without any ELF permission maps to 0, which the ABI layer interprets as implicit read; this is harmless because such a segment cannot be used as intended anyway.

Trait Implementations§

Source§

impl Clone for Segment

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 Copy for Segment

Source§

impl Debug for Segment

Source§

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

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

impl Default for Segment

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Eq for Segment

Source§

impl PartialEq for Segment

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 StructuralPartialEq for Segment

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