ExceptionTableBuilder

Struct ExceptionTableBuilder 

Source
pub struct ExceptionTableBuilder {
    pub callsites: Vec<U32Bytes<LittleEndian>>,
    pub ranges: Vec<U32Bytes<LittleEndian>>,
    pub tags: Vec<U32Bytes<LittleEndian>>,
    pub handlers: Vec<U32Bytes<LittleEndian>>,
    /* private fields */
}
Expand description

Collector struct for exception handlers per call site.

§Format

We keep four different arrays (Vecs) that we build as we visit callsites, in ascending offset (address relative to beginning of code segment) order: tags, destination offsets, callsite offsets, and tag/destination ranges.

The callsite offsets and tag/destination ranges logically form a sorted lookup array, allowing us to find information for any single callsite. The range denotes a range of indices in the tag and destination offset arrays, and those are sorted by tag per callsite. Ranges are stored with the (exclusive) end index only; the start index is implicit as the previous end, or zero if first element.

§Example

An example of this data format:

callsites: [0x10, 0x50, 0xf0] // callsites (return addrs) at offsets 0x10, 0x50, 0xf0
ranges: [2, 4, 5]             // corresponding ranges for each callsite
tags: [1, 5, 1, -1, -1]       // tags for each handler at each callsite
handlers: [0x40, 0x42, 0x6f, 0x71, 0xf5] // handler destinations at each callsite

Expanding this out:

callsites: [0x10, 0x50, 0xf0],  # PCs relative to some start of return-points.
ranges: [
    2,  # callsite 0x10 has tags/handlers indices 0..2
    4,  # callsite 0x50 has tags/handlers indices 2..4
    5,  # callsite 0xf0 has tags/handlers indices 4..5
],
tags: [
    # tags for callsite 0x10:
    1,
    5,
    # tags for callsite 0x50:
    1,
    -1,  # "catch-all"
    # tags for callsite 0xf0:
    -1,  # "catch-all"
]
handlers: [
    # handlers for callsite 0x10:
    0x40,  # relative PC to handle tag 1 (above)
    0x42,  # relative PC to handle tag 5
    # handlers for callsite 0x50:
    0x6f,  # relative PC to handle tag 1
    0x71,  # relative PC to handle all other tags
    # handlers for callsite 0xf0:
    0xf5,  # relative PC to handle all other tags
]

Fields§

§callsites: Vec<U32Bytes<LittleEndian>>§ranges: Vec<U32Bytes<LittleEndian>>§tags: Vec<U32Bytes<LittleEndian>>§handlers: Vec<U32Bytes<LittleEndian>>

Implementations§

Source§

impl ExceptionTableBuilder

Source

pub fn add_func<'a>( &mut self, start_offset: CodeOffset, call_sites: impl Iterator<Item = FinalizedMachCallSite<'a>>, ) -> Result<()>

Add a function at a given offset from the start of the compiled code section, recording information about its call sites.

Functions must be added in ascending offset order.

Source

pub fn serialize<F: FnMut(&[u8])>(&self, f: F)

Serialize the exception-handler data section, taking a closure to consume slices.

Source

pub fn to_vec(&self) -> Vec<u8>

Serialize the exception-handler data section to a vector of bytes.

Trait Implementations§

Source§

impl Clone for ExceptionTableBuilder

Source§

fn clone(&self) -> ExceptionTableBuilder

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for ExceptionTableBuilder

Source§

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

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

impl Default for ExceptionTableBuilder

Source§

fn default() -> ExceptionTableBuilder

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

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