#emulation #risc-v #vm #risc-v-emulator

libriscv

Safe wrapper for libriscv_sys, a fast RISC-V sandbox emulator

3 releases (breaking)

Uses new Rust 2024

0.3.0 Jan 24, 2026
0.2.0 Dec 20, 2025
0.1.0 Dec 20, 2025

#65 in Emulators

Download history 6/week @ 2025-12-14 98/week @ 2025-12-21 76/week @ 2025-12-28 107/week @ 2026-01-04 95/week @ 2026-01-11 96/week @ 2026-01-18 85/week @ 2026-01-25 91/week @ 2026-02-01 111/week @ 2026-02-08 98/week @ 2026-02-15 93/week @ 2026-02-22 84/week @ 2026-03-01 85/week @ 2026-03-08

369 downloads per month

BSD-3-Clause

39KB
935 lines

libriscv

Safe Rust wrapper around libriscv_sys, a fast RISC-V sandbox emulator.

How to use

Add the crate to your dependencies and run a RISC-V ELF:

use libriscv::{Machine, Options, SyscallRegistry};

let elf = std::fs::read("program").unwrap();
let options = Options::builder().build().unwrap();
let registry = SyscallRegistry::empty();
let mut machine = Machine::new(&elf, options, &registry).unwrap();
machine.run(1_000_000).unwrap();

You can also define registries using the macros:

use libriscv::{syscall, syscall_registry, SyscallContext, SyscallResult};

#[syscall_registry]
mod host_syscalls {
    use super::*;

    #[syscall(id = 1)]
    fn write(_ctx: &mut SyscallContext) -> SyscallResult<()> {
        Ok(())
    }
}

let registry = host_syscalls::registry().unwrap();

See examples/ for more usage patterns.

Credits

The directory examples/advanced/riscv_program is copied from the upstream repository.

Dependencies

~1–1.7MB
~39K SLoC