pub struct Assembler<R: Relocation> { /* private fields */ }
Expand description
A full assembler implementation. Supports labels, all types of relocations, incremental compilation and multithreaded execution with simultaneous compilation. Its implementation guarantees no memory is executable and writable at the same time.
Implementations§
source§impl<R: Relocation> Assembler<R>
impl<R: Relocation> Assembler<R>
sourcepub fn new() -> Result<Self>
pub fn new() -> Result<Self>
Create a new, empty assembler, with initial allocation size page_size
.
sourcepub fn new_dynamic_label(&mut self) -> DynamicLabel
pub fn new_dynamic_label(&mut self) -> DynamicLabel
Create a new dynamic label ID
sourcepub fn alter_uncommitted(&mut self) -> UncommittedModifier<'_>
pub fn alter_uncommitted(&mut self) -> UncommittedModifier<'_>
Use an UncommittedModifier
to alter uncommitted code.
This does not allow the user to change labels/relocations.
sourcepub fn alter<F, O>(&mut self, f: F) -> Result<O, DynasmError>
pub fn alter<F, O>(&mut self, f: F) -> Result<O, DynasmError>
Use a Modifier
to alter committed code directly. While this is happening
no code can be executed as the relevant pages are remapped as writable.
This API supports defining new labels/relocations, and overwriting previously defined relocations.
sourcepub fn commit(&mut self) -> Result<(), DynasmError>
pub fn commit(&mut self) -> Result<(), DynasmError>
Commit code, flushing the temporary internal assembling buffer to the mapped executable memory. This makes assembled code available for execution.
sourcepub fn finalize(self) -> Result<ExecutableBuffer, Self>
pub fn finalize(self) -> Result<ExecutableBuffer, Self>
Finalize this assembler, returning the internal ExecutableBuffer
if no Executor
instances exist.
This panics if any uncommitted changes caused errors near the end. To handle these, call commit()
explicitly beforehand.
sourcepub fn reader(&self) -> Executor
pub fn reader(&self) -> Executor
Create an executor which can be used to execute code while still assembling code
sourcepub fn labels(&self) -> &LabelRegistry
pub fn labels(&self) -> &LabelRegistry
Provides access to the assemblers internal labels registry
sourcepub fn labels_mut(&mut self) -> &mut LabelRegistry
pub fn labels_mut(&mut self) -> &mut LabelRegistry
Provides mutable access to the assemblers internal labels registry
Trait Implementations§
source§impl<R: Relocation> DynasmApi for Assembler<R>
impl<R: Relocation> DynasmApi for Assembler<R>
source§fn offset(&self) -> AssemblyOffset
fn offset(&self) -> AssemblyOffset
source§fn align(&mut self, alignment: usize, with: u8)
fn align(&mut self, alignment: usize, with: u8)
source§fn runtime_error(&self, msg: &'static str) -> !
fn runtime_error(&self, msg: &'static str) -> !
source§impl<R: Relocation> DynasmLabelApi for Assembler<R>
impl<R: Relocation> DynasmLabelApi for Assembler<R>
§type Relocation = R
type Relocation = R
source§fn local_label(&mut self, name: &'static str)
fn local_label(&mut self, name: &'static str)
source§fn global_label(&mut self, name: &'static str)
fn global_label(&mut self, name: &'static str)
source§fn dynamic_label(&mut self, id: DynamicLabel)
fn dynamic_label(&mut self, id: DynamicLabel)
source§fn global_relocation(
&mut self,
name: &'static str,
target_offset: isize,
field_offset: u8,
ref_offset: u8,
kind: R,
)
fn global_relocation( &mut self, name: &'static str, target_offset: isize, field_offset: u8, ref_offset: u8, kind: R, )
source§fn dynamic_relocation(
&mut self,
id: DynamicLabel,
target_offset: isize,
field_offset: u8,
ref_offset: u8,
kind: R,
)
fn dynamic_relocation( &mut self, id: DynamicLabel, target_offset: isize, field_offset: u8, ref_offset: u8, kind: R, )
source§fn forward_relocation(
&mut self,
name: &'static str,
target_offset: isize,
field_offset: u8,
ref_offset: u8,
kind: R,
)
fn forward_relocation( &mut self, name: &'static str, target_offset: isize, field_offset: u8, ref_offset: u8, kind: R, )
source§fn backward_relocation(
&mut self,
name: &'static str,
target_offset: isize,
field_offset: u8,
ref_offset: u8,
kind: R,
)
fn backward_relocation( &mut self, name: &'static str, target_offset: isize, field_offset: u8, ref_offset: u8, kind: R, )
source§fn bare_relocation(
&mut self,
target: usize,
field_offset: u8,
ref_offset: u8,
kind: R,
)
fn bare_relocation( &mut self, target: usize, field_offset: u8, ref_offset: u8, kind: R, )
source§fn forward_reloc(
&mut self,
name: &'static str,
target_offset: isize,
field_offset: u8,
ref_offset: u8,
kind: <Self::Relocation as Relocation>::Encoding,
)
fn forward_reloc( &mut self, name: &'static str, target_offset: isize, field_offset: u8, ref_offset: u8, kind: <Self::Relocation as Relocation>::Encoding, )
source§fn backward_reloc(
&mut self,
name: &'static str,
target_offset: isize,
field_offset: u8,
ref_offset: u8,
kind: <Self::Relocation as Relocation>::Encoding,
)
fn backward_reloc( &mut self, name: &'static str, target_offset: isize, field_offset: u8, ref_offset: u8, kind: <Self::Relocation as Relocation>::Encoding, )
source§fn global_reloc(
&mut self,
name: &'static str,
target_offset: isize,
field_offset: u8,
ref_offset: u8,
kind: <Self::Relocation as Relocation>::Encoding,
)
fn global_reloc( &mut self, name: &'static str, target_offset: isize, field_offset: u8, ref_offset: u8, kind: <Self::Relocation as Relocation>::Encoding, )
source§fn dynamic_reloc(
&mut self,
id: DynamicLabel,
target_offset: isize,
field_offset: u8,
ref_offset: u8,
kind: <Self::Relocation as Relocation>::Encoding,
)
fn dynamic_reloc( &mut self, id: DynamicLabel, target_offset: isize, field_offset: u8, ref_offset: u8, kind: <Self::Relocation as Relocation>::Encoding, )
source§fn bare_reloc(
&mut self,
target: usize,
field_offset: u8,
ref_offset: u8,
kind: <Self::Relocation as Relocation>::Encoding,
)
fn bare_reloc( &mut self, target: usize, field_offset: u8, ref_offset: u8, kind: <Self::Relocation as Relocation>::Encoding, )
source§impl<'a, R: Relocation> Extend<&'a u8> for Assembler<R>
impl<'a, R: Relocation> Extend<&'a u8> for Assembler<R>
source§fn extend<T>(&mut self, iter: T)where
T: IntoIterator<Item = &'a u8>,
fn extend<T>(&mut self, iter: T)where
T: IntoIterator<Item = &'a u8>,
source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)source§impl<R: Relocation> Extend<u8> for Assembler<R>
impl<R: Relocation> Extend<u8> for Assembler<R>
source§fn extend<T>(&mut self, iter: T)where
T: IntoIterator<Item = u8>,
fn extend<T>(&mut self, iter: T)where
T: IntoIterator<Item = u8>,
source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)