Struct dynasmrt::VecAssembler

source ·
pub struct VecAssembler<R: Relocation> { /* private fields */ }
Expand description

An assembler that assembles into a Vec<u8>, while supporting labels. To support the different types of relocations it requires a base address of the to be assembled code to be specified.

Implementations§

source§

impl<R: Relocation> VecAssembler<R>

source

pub fn new(baseaddr: usize) -> VecAssembler<R>

Creates a new VecAssembler, with the specified base address.

source

pub fn new_with_capacity(
    baseaddr: usize,
    ops_capacity: usize,
    local_labels: usize,
    global_labels: usize,
    dynamic_labels: usize,
    static_references: usize,
    dynamic_references: usize
) -> VecAssembler<R>

Creates a new VecAssembler, with the specified base address. Preallocates vec_capacity bytes to the internal vector, and label_capacity label locations of each type. Allows the user to specify the initial capacity of the internal datastructures. ops_capacity is the amount of bytes preallocated for the assembling buffer. local_labels determines the preallocated space for local labels definitions. global_labels determines the preallocated space for global labels definitions. dynamic_labels determines the preallocated space for dynamic labels definitions. static_references determines the preallocated space for references to local/global labels. dynamic_references determines the preallocated space for references to dynamic labels.

source

pub fn reserve_ops(&mut self, additional: usize)

Reserve capacity for at least additional instruction bytes to be inserted

source

pub fn new_dynamic_label(&mut self) -> DynamicLabel

Create a new dynamic label ID

source

pub fn commit(&mut self) -> Result<(), DynasmError>

Resolves any relocations emitted to the assembler before this point. If an impossible relocation was specified before this point, returns them here.

source

pub fn alter(&mut self) -> UncommittedModifier<'_>

Use an UncommittedModifier to alter uncommitted code. This does not allow the user to change labels/relocations.

source

pub fn labels(&self) -> &LabelRegistry

Provides access to the assemblers internal labels registry

source

pub fn labels_mut(&mut self) -> &mut LabelRegistry

Provides mutable access to the assemblers internal labels registry

source

pub fn finalize(self) -> Result<Vec<u8>, DynasmError>

Finalizes the VecAssembler, returning the resulting Vec<u8> containing all assembled data. this implicitly commits any relocations beforehand and returns an error if required.

source

pub fn take(&mut self) -> Result<Vec<u8>, DynasmError>

Equivalent of finalize, but allows the VecAssembler’s internal allocations to be reused for the next assembler.

source

pub fn drain<'a>(
    &'a mut self
) -> Result<impl Iterator<Item = u8> + 'a, DynasmError>

Equivalent of take, but instead of allocating a new vector it simply provides a draining iterator over the internal contents.

Trait Implementations§

source§

impl<R: Debug + Relocation> Debug for VecAssembler<R>

source§

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

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

impl<R: Relocation> DynasmApi for VecAssembler<R>

source§

fn offset(&self) -> AssemblyOffset

Report the current offset into the assembling target
source§

fn push(&mut self, byte: u8)

Push a byte into the assembling target
source§

fn align(&mut self, alignment: usize, with: u8)

Push filler until the assembling target end is aligned to the given alignment.
source§

fn push_i8(&mut self, value: i8)

Push a signed byte into the assembling target
source§

fn push_i16(&mut self, value: i16)

Push a signed word into the assembling target
source§

fn push_i32(&mut self, value: i32)

Push a signed doubleword into the assembling target
source§

fn push_i64(&mut self, value: i64)

Push a signed quadword into the assembling target
source§

fn push_u16(&mut self, value: u16)

Push an usigned word into the assembling target
source§

fn push_u32(&mut self, value: u32)

Push an usigned doubleword into the assembling target
source§

fn push_u64(&mut self, value: u64)

Push an usigned quadword into the assembling target
source§

fn runtime_error(&self, msg: &'static str) -> !

This function is called in when a runtime error has to be generated. It panics.
source§

impl<R: Relocation> DynasmLabelApi for VecAssembler<R>

§

type Relocation = R

The relocation info type this assembler uses.
source§

fn local_label(&mut self, name: &'static str)

Record the definition of a local label
source§

fn global_label(&mut self, name: &'static str)

Record the definition of a global label
source§

fn dynamic_label(&mut self, id: DynamicLabel)

Record the definition of a dynamic label
source§

fn global_relocation(
    &mut self,
    name: &'static str,
    target_offset: isize,
    field_offset: u8,
    ref_offset: u8,
    kind: R
)

Equivalent of global_reloc, but takes a non-encoded relocation
source§

fn dynamic_relocation(
    &mut self,
    id: DynamicLabel,
    target_offset: isize,
    field_offset: u8,
    ref_offset: u8,
    kind: R
)

Equivalent of dynamic_reloc, but takes a non-encoded relocation
source§

fn forward_relocation(
    &mut self,
    name: &'static str,
    target_offset: isize,
    field_offset: u8,
    ref_offset: u8,
    kind: R
)

Equivalent of forward_reloc, but takes a non-encoded relocation
source§

fn backward_relocation(
    &mut self,
    name: &'static str,
    target_offset: isize,
    field_offset: u8,
    ref_offset: u8,
    kind: R
)

Equivalent of backward_reloc, but takes a non-encoded relocation
source§

fn bare_relocation(
    &mut self,
    target: usize,
    field_offset: u8,
    ref_offset: u8,
    kind: R
)

Equivalent of bare_reloc, but takes a non-encoded relocation
source§

fn forward_reloc(
    &mut self,
    name: &'static str,
    target_offset: isize,
    field_offset: u8,
    ref_offset: u8,
    kind: <Self::Relocation as Relocation>::Encoding
)

Record a relocation spot for a forward reference to a local label
source§

fn backward_reloc(
    &mut self,
    name: &'static str,
    target_offset: isize,
    field_offset: u8,
    ref_offset: u8,
    kind: <Self::Relocation as Relocation>::Encoding
)

Record a relocation spot for a backward reference to a local label
source§

fn global_reloc(
    &mut self,
    name: &'static str,
    target_offset: isize,
    field_offset: u8,
    ref_offset: u8,
    kind: <Self::Relocation as Relocation>::Encoding
)

Record a relocation spot for a reference to a global label
source§

fn dynamic_reloc(
    &mut self,
    id: DynamicLabel,
    target_offset: isize,
    field_offset: u8,
    ref_offset: u8,
    kind: <Self::Relocation as Relocation>::Encoding
)

Record a relocation spot for a reference to a dynamic label
source§

fn bare_reloc(
    &mut self,
    target: usize,
    field_offset: u8,
    ref_offset: u8,
    kind: <Self::Relocation as Relocation>::Encoding
)

Record a relocation spot to an arbitrary target.
source§

impl<'a, R: Relocation> Extend<&'a u8> for VecAssembler<R>

source§

fn extend<T>(&mut self, iter: T)where
    T: IntoIterator<Item = &'a u8>,

Extends a collection with the contents of an iterator. Read more
source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
source§

impl<R: Relocation> Extend<u8> for VecAssembler<R>

source§

fn extend<T>(&mut self, iter: T)where
    T: IntoIterator<Item = u8>,

Extends a collection with the contents of an iterator. Read more
source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more

Auto Trait Implementations§

§

impl<R> RefUnwindSafe for VecAssembler<R>where
    R: RefUnwindSafe,

§

impl<R> Send for VecAssembler<R>where
    R: Send,

§

impl<R> Sync for VecAssembler<R>where
    R: Sync,

§

impl<R> Unpin for VecAssembler<R>where
    R: Unpin,

§

impl<R> UnwindSafe for VecAssembler<R>where
    R: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere
    T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere
    T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere
    T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere
    U: From<T>,

const: unstable · 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 Twhere
    U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere
    U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.