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
Report the current offset into the assembling target
sourcefn align(&mut self, alignment: usize, with: u8)
fn align(&mut self, alignment: usize, with: u8)
Push filler until the assembling target end is aligned to the given alignment.
sourcefn runtime_error(&self, msg: &'static str) -> !
fn runtime_error(&self, msg: &'static str) -> !
This function is called in when a runtime error has to be generated. It panics.
sourceimpl<R: Relocation> DynasmLabelApi for Assembler<R>
impl<R: Relocation> DynasmLabelApi for Assembler<R>
type Relocation = R
type Relocation = R
The relocation info type this assembler uses.
sourcefn local_label(&mut self, name: &'static str)
fn local_label(&mut self, name: &'static str)
Record the definition of a local label
sourcefn global_label(&mut self, name: &'static str)
fn global_label(&mut self, name: &'static str)
Record the definition of a global label
sourcefn dynamic_label(&mut self, id: DynamicLabel)
fn dynamic_label(&mut self, id: DynamicLabel)
Record the definition of a dynamic label
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
)
Equivalent of global_reloc, but takes a non-encoded relocation
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
)
Equivalent of dynamic_reloc, but takes a non-encoded relocation
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
)
Equivalent of forward_reloc, but takes a non-encoded relocation
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
)
Equivalent of backward_reloc, but takes a non-encoded relocation
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
)
Equivalent of bare_reloc, but takes a non-encoded relocation
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
)
Record a relocation spot for a forward reference to a local label
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
)
Record a relocation spot for a backward reference to a local label
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
)
Record a relocation spot for a reference to a global label
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
)
Record a relocation spot for a reference to a dynamic label
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
)
Record a relocation spot to an arbitrary target.
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>,
Extends a collection with the contents of an iterator. Read more
sourcefn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)Extends a collection with exactly one element.
sourcefn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)Reserves capacity in a collection for the given number of additional elements. Read more
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>,
Extends a collection with the contents of an iterator. Read more
sourcefn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)Extends a collection with exactly one element.
sourcefn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)Reserves capacity in a collection for the given number of additional elements. Read more
Auto Trait Implementations
impl<R> RefUnwindSafe for Assembler<R> where
R: RefUnwindSafe,
impl<R> Send for Assembler<R> where
R: Send,
impl<R> Sync for Assembler<R> where
R: Sync,
impl<R> Unpin for Assembler<R> where
R: Unpin,
impl<R> UnwindSafe for Assembler<R> where
R: UnwindSafe + RefUnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more