Segment

Struct Segment 

Source
pub struct Segment {
    pub kind: SegmentKind,
    pub flags: SegmentFlags,
    pub offset: u64,
    pub virtual_address: u64,
    pub physical_address: u64,
    pub file_size: u64,
    pub memory_size: u64,
    pub align: u64,
}
Expand description

Segment.

Dynamic loader maps segments into virtual address space of a program. Usually segments consists of sections, however, some segment types exist on their own.

Fields§

§kind: SegmentKind

Segment type.

§flags: SegmentFlags

Flags.

§offset: u64

In-file offset.

§virtual_address: u64

Virtual address (in-memory offset).

§physical_address: u64

Physical address (in-memory offset).

Usually physical address is the same as virtual address.

§file_size: u64

In-file size.

§memory_size: u64

In-memory size.

§align: u64

Alignment.

  • Offset and virtual address must have congruent values, i.e. offset % align == virtual_address % align.
  • LOAD segments boundaries are expanded to the nearest page boundaries, i.e. offset is rounded down to a multiple of page size and offset + memory_size is rounded up to a multiple of page size.

Implementations§

Source§

impl Segment

Source

pub fn read_content<R: ElfRead + ElfSeek, T: BlockRead>( &self, reader: &mut R, class: Class, byte_order: ByteOrder, ) -> Result<T, Error>

Read segment contents as bytes.

Source

pub fn write_content<W: ElfWrite + ElfSeek, T: BlockWrite + ?Sized>( &self, writer: &mut W, class: Class, byte_order: ByteOrder, content: &T, ) -> Result<(), Error>

Write segment contents.

Source

pub fn clear_content<W: ElfWrite + ElfSeek>( &self, writer: &mut W, ) -> Result<(), Error>

Zero out the entry’s content.

Source

pub const fn physical_address_range(&self) -> Range<u64>

Physical address range.

Source

pub const fn virtual_address_range(&self) -> Range<u64>

Virtual address range.

Source

pub const fn file_offset_range(&self) -> Range<u64>

In-file location of the segment.

Source

pub fn check(&self, class: Class) -> Result<(), Error>

Check segment.

Trait Implementations§

Source§

impl Debug for Segment

Source§

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

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

impl EntityIo for Segment

Source§

fn read<R: ElfRead>( reader: &mut R, class: Class, byte_order: ByteOrder, ) -> Result<Self, Error>

Read the entity from the reader.
Source§

fn write<W: ElfWrite>( &self, writer: &mut W, class: Class, byte_order: ByteOrder, ) -> Result<(), Error>

Write the entity to the writer.

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
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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.