Struct object::build::elf::Segment

source ·
pub struct Segment<'data> {
    pub delete: bool,
    pub p_type: u32,
    pub p_flags: u32,
    pub p_offset: u64,
    pub p_vaddr: u64,
    pub p_paddr: u64,
    pub p_filesz: u64,
    pub p_memsz: u64,
    pub p_align: u64,
    pub sections: Vec<SectionId>,
    /* private fields */
}
Expand description

A segment in Segments.

This corresponds to elf::ProgramHeader32 or elf::ProgramHeader64.

Fields§

§delete: bool

Ignore this segment when writing the ELF file.

§p_type: u32

The p_type field in the ELF program header.

One of the PT_* constants.

§p_flags: u32

The p_flags field in the ELF program header.

A combination of the PF_* constants.

§p_offset: u64

The p_offset field in the ELF program header.

This is the file offset of the data in the segment. This should correspond to the file offset of the sections that are placed in this segment. Currently there is no support for section data that is not contained in sections.

§p_vaddr: u64

The p_vaddr field in the ELF program header.

§p_paddr: u64

The p_paddr field in the ELF program header.

§p_filesz: u64

The p_filesz field in the ELF program header.

§p_memsz: u64

The p_memsz field in the ELF program header.

§p_align: u64

The p_align field in the ELF program header.

§sections: Vec<SectionId>

The sections contained in this segment.

Implementations§

source§

impl<'data> Segment<'data>

source

pub fn id(&self) -> SegmentId

The ID used for referring to this segment.

source

pub fn is_load(&self) -> bool

Returns true if the segment type is PT_LOAD.

source

pub fn contains_offset(&self, offset: u64) -> bool

Returns true if the segment contains the given file offset.

source

pub fn address_from_offset(&self, offset: u64) -> u64

Return the address corresponding to the given file offset.

This will return a meaningless value if contains_offset is false.

source

pub fn contains_address(&self, address: u64) -> bool

Returns true if the segment contains the given address.

source

pub fn remove_sections(&mut self)

Remove all sections from the segment, and set its size to zero.

source

pub fn append_section(&mut self, section: &mut Section<'_>)

Add a section to the segment.

If this is a elf::PT_LOAD segment, then the file offset and address of the section is changed to be at the end of the segment.

The segment’s file and address ranges are extended to include the section. This uses the sh_size field of the section, not the size of the section data.

The section’s id is added to the segment’s list of sections.

source

pub fn append_section_range(&mut self, section: &Section<'_>)

Extend this segment’s file and address ranges to include the given section.

If the segment’s p_memsz is zero, then this signifies that the segment has no file or address range yet. In this case, the segment’s file and address ranges are set equal to the section. Otherwise, the segment’s file and address ranges are extended to include the section.

This uses the sh_size field of the section, not the size of the section data.

source

pub fn recalculate_ranges(&mut self, sections: &Sections<'data>)

Recalculate the file and address ranges of the segment.

Resets the segment’s file and address ranges to zero, and then calls append_section_range for each section in the segment.

Trait Implementations§

source§

impl<'data> Debug for Segment<'data>

source§

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

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

impl<'data> Item for Segment<'data>

§

type Id = SegmentId

The type of identifier for the item.
source§

fn is_deleted(&self) -> bool

Return True if the item is deleted.

Auto Trait Implementations§

§

impl<'data> Freeze for Segment<'data>

§

impl<'data> RefUnwindSafe for Segment<'data>

§

impl<'data> Send for Segment<'data>

§

impl<'data> Sync for Segment<'data>

§

impl<'data> Unpin for Segment<'data>

§

impl<'data> UnwindSafe for Segment<'data>

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

§

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

§

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.