5 unstable releases

Uses old Rust 2015

0.6.1 Feb 14, 2018
0.6.0 Feb 7, 2018
0.5.1 Feb 7, 2018
0.5.0 Feb 6, 2018
0.4.0 Feb 6, 2018

#991 in Programming languages

MIT license

14KB
198 lines

machina crates.io docs.rs

Manage and execute assembly at runtime.

Crossplatform?

Yap.

Why?

Emulators, JIT, dynarec, etc.

Install

To build the tests you need sam.
In Cargo.toml:

[dependencies]
machina = "*"

If you work with many instructions, you may want to enable optimization (only applied to Cache):

[dependencies.machina]
version = "*"
features = ["optimize"]

Example

extern crate machina;
#[macro_use]
extern crate sam; // just to keep it simple

use machina::cache::{Cache, STUB};
use machina::memory::Memory;

fn main() {
    let asm = format!("mov rax, {}", STUB); // fill in a dummy address
    let dummy = 64;
    let address = &dummy as *const _; // address of dummy

    let cache = Cache::new();
    let memory = Memory::new(1); // 1 page = 1024 bytes
    cache.insert("mov_rax_x".to_string(), sam!(x64 => &asm)); // create the bytes at compile time via sam

    memory.emit_bytes(cache.get_stub("mov_rax_x".to_string(), address as u64)) // get "mov_rax_x" and fill in a dynamic address
    let rax = memory.execute(); // returns rax
}

Dependencies

~240–550KB