Crates.io | dynasm |
lib.rs | dynasm |
version | 3.0.1 |
source | src |
created_at | 2016-08-29 19:22:57.198818 |
updated_at | 2024-10-29 01:25:50.950479 |
description | A plugin for assembling code at runtime. Combined with the runtime crate dynasmrt it can be used to write JIT compilers easily. |
homepage | |
repository | https://github.com/CensoredUsername/dynasm-rs |
max_upload_size | |
id | 6178 |
size | 802,659 |
The purpose of this tool is to ease the creation of programs that require run-time assembling.
It is compatible with stable rustc
1.77 and higher.
##dynasm-rs
on irc.libera.chat
Vec.push
and Vec.extend
statements.use dynasmrt::{dynasm, DynasmApi, DynasmLabelApi};
use std::{io, slice, mem};
use std::io::Write;
fn main() {
let mut ops = dynasmrt::x64::Assembler::new().unwrap();
let string = "Hello World!";
dynasm!(ops
; .arch x64
; ->hello:
; .bytes string.as_bytes()
);
let hello = ops.offset();
dynasm!(ops
; .arch x64
; lea rcx, [->hello]
; xor edx, edx
; mov dl, BYTE string.len() as _
; mov rax, QWORD print as _
; sub rsp, BYTE 0x28
; call rax
; add rsp, BYTE 0x28
; ret
);
let buf = ops.finalize().unwrap();
let hello_fn: extern "win64" fn() -> bool = unsafe { mem::transmute(buf.ptr(hello)) };
assert!(hello_fn());
}
pub extern "win64" fn print(buffer: *const u8, length: u64) -> bool {
io::stdout()
.write_all(unsafe { slice::from_raw_parts(buffer, length as usize) })
.is_ok()
}
This project is heavily inspired by Dynasm
The development of the Aarch64 assembler backend has been sponsored by Wasmer.
Mozilla Public License, v. 2.0, see LICENSE
Copyright 2016 CensoredUsername
This project used to be a compiler plugin, so for old compilers, here's a list of which version of dynasm was guaranteed to work with which compiler. As the project has since transitioned to be a proc macro, this is not relevant for modern versions of the compiler.
v0.2.0
: rustc 1.27.0-nightly (ac3c2288f 2018-04-18)
v0.2.1
: rustc 1.28.0-nightly (a1d4a9503 2018-05-20)
v0.2.3
: rustc 1.31.0-nightly (96cafc53c 2018-10-09)