Skip to content

ioncodes/machina

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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
}

About

Manage and execute assembly at runtime.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages