Struct dynasmrt::x64::Assembler
[−]
[src]
pub struct Assembler { /* fields omitted */ }
This struct is an implementation of a dynasm runtime. It supports incremental compilation as well as multithreaded execution with simultaneous compilation. Its implementation ensures that no memory is writeable and executable at the same time.
Methods
impl Assembler
[src]
pub fn new() -> Result<Assembler>
[src]
Create a new Assembler
instance
This function will return an error if it was not
able to map the required executable memory. However, further methods
on the Assembler
will simply panic if an error occurs during memory
remapping as otherwise it would violate the invariants of the assembler.
This behaviour could be improved but currently the underlying memmap crate
does not return the original mappings if a call to mprotect/VirtualProtect
fails so there is no reliable way to error out if a call fails while leaving
the logic of the Assembler
intact.
pub fn new_dynamic_label(&mut self) -> DynamicLabel
[src]
Create a new dynamic label that can be referenced and defined.
pub fn alter<F>(&mut self, f: F) where
F: FnOnce(&mut AssemblyModifier),
[src]
F: FnOnce(&mut AssemblyModifier),
To allow already committed code to be altered, this method allows modification
of the internal ExecutableBuffer directly. When this method is called, all
data will be committed and access to the internal ExecutableBuffer
will be locked.
The passed function will then be called with an AssemblyModifier
as argument.
Using this AssemblyModifier
changes can be made to the committed code.
After this function returns, any labels in these changes will be resolved
and the ExecutableBuffer
will be unlocked again.
pub fn alter_uncommitted(&mut self) -> UncommittedModifier
[src]
Similar to Assembler::alter
, this method allows modification of the yet to be
committed assembing buffer. Note that it is not possible to use labels in this
context, and overriding labels will cause corruption when the assembler tries to
resolve the labels at commit time.
pub fn commit(&mut self)
[src]
Commit the assembled code from a temporary buffer to the executable buffer. This method requires write access to the execution buffer and therefore has to obtain a lock on the datastructure. When this method is called, all labels will be resolved, and the result can no longer be changed.
pub fn finalize(self) -> Result<ExecutableBuffer, Assembler>
[src]
Consumes the assembler to return the internal ExecutableBuffer. This
method will only fail if an Executor
currently holds a lock on the datastructure,
in which case it will return itself.
pub fn reader(&self) -> Executor
[src]
Creates a read-only reference to the internal ExecutableBuffer
that must
be locked to access it. Multiple of such read-only locks can be obtained
at the same time, but as long as they are alive they will block any self.commit()
calls.
Trait Implementations
impl Debug for Assembler
[src]
fn fmt(&self, __arg_0: &mut Formatter) -> Result
[src]
Formats the value using the given formatter. Read more
impl DynasmApi for Assembler
[src]
fn offset(&self) -> AssemblyOffset
[src]
Report the current offset into the assembling target
fn push(&mut self, value: u8)
[src]
Push a byte into the assembling target
fn push_i8(&mut self, value: i8)
[src]
Push a signed byte into the assembling target
fn push_i16(&mut self, value: i16)
[src]
Push a signed word into the assembling target
fn push_i32(&mut self, value: i32)
[src]
Push a signed doubleword into the assembling target
fn push_i64(&mut self, value: i64)
[src]
Push a signed quadword into the assembling target
fn push_u16(&mut self, value: u16)
[src]
Push an usigned word into the assembling target
fn push_u32(&mut self, value: u32)
[src]
Push an usigned doubleword into the assembling target
fn push_u64(&mut self, value: u64)
[src]
Push an usigned quadword into the assembling target
fn runtime_error(&self, msg: &'static str) -> !
[src]
This function is called in when a runtime error has to be generated. It panics.
impl DynasmLabelApi for Assembler
[src]
type Relocation = (u8, u8)
tuple of encoded (offset, size)
fn align(&mut self, alignment: usize)
[src]
Push nops until the assembling target end is aligned to the given alignment
fn global_label(&mut self, name: &'static str)
[src]
Record the definition of a global label
fn global_reloc(&mut self, name: &'static str, kind: Self::Relocation)
[src]
Record a relocation spot for a reference to a global label
fn dynamic_label(&mut self, id: DynamicLabel)
[src]
Record the definition of a dynamic label
fn dynamic_reloc(&mut self, id: DynamicLabel, kind: Self::Relocation)
[src]
Record a relocation spot for a reference to a dynamic label
fn local_label(&mut self, name: &'static str)
[src]
Record the definition of a local label
fn forward_reloc(&mut self, name: &'static str, kind: Self::Relocation)
[src]
Record a relocation spot for a forward reference to a local label
fn backward_reloc(&mut self, name: &'static str, kind: Self::Relocation)
[src]
Record a relocation spot for a backward reference to a local label
fn bare_reloc(&mut self, target: usize, kind: Self::Relocation)
[src]
Record a relocation spot to an arbitrary target
impl Extend<u8> for Assembler
[src]
fn extend<T>(&mut self, iter: T) where
T: IntoIterator<Item = u8>,
[src]
T: IntoIterator<Item = u8>,
Extends a collection with the contents of an iterator. Read more
impl<'a> Extend<&'a u8> for Assembler
[src]
fn extend<T>(&mut self, iter: T) where
T: IntoIterator<Item = &'a u8>,
[src]
T: IntoIterator<Item = &'a u8>,
Extends a collection with the contents of an iterator. Read more