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 compiltion. Its implementation guarantees no memory is executable and writable at the same time.
Implementations
sourceimpl<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>where
F: FnOnce(&mut Modifier<'_, R>) -> O,
pub fn alter<F, O>(&mut self, f: F) -> Result<O, DynasmError>where
F: FnOnce(&mut Modifier<'_, R>) -> O,
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
sourceimpl<R: Debug + Relocation> Debug for Assembler<R>
impl<R: Debug + Relocation> Debug for Assembler<R>
sourceimpl<R: Relocation> DynasmApi for Assembler<R>
impl<R: Relocation> DynasmApi for Assembler<R>
sourcefn offset(&self) -> AssemblyOffset
fn offset(&self) -> AssemblyOffset
sourcefn align(&mut self, alignment: usize, with: u8)
fn align(&mut self, alignment: usize, with: u8)
sourcefn runtime_error(&self, msg: &'static str) -> !
fn runtime_error(&self, msg: &'static str) -> !
sourceimpl<R: Relocation> DynasmLabelApi for Assembler<R>
impl<R: Relocation> DynasmLabelApi for Assembler<R>
type Relocation = R
type Relocation = R
sourcefn local_label(&mut self, name: &'static str)
fn local_label(&mut self, name: &'static str)
sourcefn global_label(&mut self, name: &'static str)
fn global_label(&mut self, name: &'static str)
sourcefn dynamic_label(&mut self, id: DynamicLabel)
fn dynamic_label(&mut self, id: DynamicLabel)
sourcefn 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
)
sourcefn 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
)
sourcefn 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
)
sourcefn 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
)
sourcefn 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
)
sourcefn 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
)
sourcefn 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
)
sourcefn 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
)
sourcefn 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
)
sourcefn 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
)
sourceimpl<'a, R: Relocation> Extend<&'a u8> for Assembler<R>
impl<'a, R: Relocation> Extend<&'a u8> for Assembler<R>
sourcefn 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>,
sourcefn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)sourcefn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)sourceimpl<R: Relocation> Extend<u8> for Assembler<R>
impl<R: Relocation> Extend<u8> for Assembler<R>
sourcefn extend<T>(&mut self, iter: T)where
T: IntoIterator<Item = u8>,
fn extend<T>(&mut self, iter: T)where
T: IntoIterator<Item = u8>,
sourcefn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)sourcefn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)