[][src]Crate assembler

#assembler

This is a new code base to efficiently assemble 64-bit x86 (AMD64 long mode) machine code at runtime.

Instructions are emitted by using the mnemonic-like methods on the InstructionStream. These are designed to work with Rust's release build optimizations to compile down to just a sequence of byte stores to memory.

In addition, labels are supported; use of short (8-bit) labelled jumps is supported, and, where possible, are used.

Example Usage

extern crate assembler;

use ::assembler::*;
use ::assembler::mnemonic_parameter_types::BranchHint;
use ::assembler::mnemonic_parameter_types::Label;
use ::assembler::mnemonic_parameter_types::memory_operands::*;
use ::assembler::mnemonic_parameter_types::immediates::*;
use ::assembler::mnemonic_parameter_types::registers::*;

fn main()
{
    // SOME_LENGTH will be rounded up to the nearest power of two, with a minimum of the page size (4Kb).
    const SOME_LENGTH: usize = 4096;
    let memory_map = ExecutableAnonymousMemoryMap::new(SOME_LENGTH).unwrap();

    const SOME_LIKELY_NUMBER_OF_LABELS: usize = 512;
    let instruction_stream = memory_map.instruction_stream(SOME_LIKELY_NUMBER_OF_LABELS);

    instruction_stream.mov_...();

    let label = instruction_stream.create_and_attach_label();

    instruction_stream.jmp_Label(label)?;

    let function_pointer = instruction_stream.nullary_function::<()>():

    instruction_stream.finish();

    function_pointer();
}

Modules

mnemonic_parameter_types

Mnemonic parameter types.

Structs

ExecutableAnonymousMemoryMap

Represents an executable memory map that can be used to generate program code into.

InstructionStream

An instruction stream.

Type Definitions

ShortJmpResult

Represents the result of attempting a mnemonic with a short jump.