83 releases

new 0.8.1 May 29, 2024
0.8.0 Oct 19, 2023
0.7.2 Sep 25, 2023
0.6.0 Jun 28, 2023
0.1.4 Nov 14, 2018

#14 in Unix APIs

Download history 20665/week @ 2024-02-07 19649/week @ 2024-02-14 22379/week @ 2024-02-21 24974/week @ 2024-02-28 24936/week @ 2024-03-06 26047/week @ 2024-03-13 28383/week @ 2024-03-20 28232/week @ 2024-03-27 72942/week @ 2024-04-03 36820/week @ 2024-04-10 33416/week @ 2024-04-17 31875/week @ 2024-04-24 26422/week @ 2024-05-01 29053/week @ 2024-05-08 26732/week @ 2024-05-15 18088/week @ 2024-05-22

105,663 downloads per month
Used in 560 crates (22 directly)

Apache-2.0

670KB
14K SLoC

Contains (ELF lib, 37KB) tests/elfs/long_section_name.so, (ELF lib, 6KB) tests/elfs/bss_section.so, (ELF lib, 6KB) tests/elfs/data_section.so, (ELF lib, 6KB) tests/elfs/program_headers_overflow.so, (ELF lib, 6KB) tests/elfs/relative_call.so, (ELF lib, 6KB) tests/elfs/reloc_64_64.so and 10 more.

solana_rbpf

Rust (user-space) virtual machine for eBPF

Build Status Crates.io

Description

This is a fork of RBPF by Quentin Monnet.

This crate contains a virtual machine for eBPF program execution. BPF, as in Berkeley Packet Filter, is an assembly-like language initially developed for BSD systems, in order to filter packets in the kernel with tools such as tcpdump so as to avoid useless copies to user-space. It was ported to Linux, where it evolved into eBPF (extended BPF), a faster version with more features. While BPF programs are originally intended to run in the kernel, the virtual machine of this crate enables running it in user-space applications; it contains an interpreter, an x86_64 JIT-compiler for eBPF programs, as well as an assembler, disassembler and verifier.

The crate is supposed to compile and run on Linux, MacOS X, and Windows, although the JIT-compiler does not work with Windows at this time.

This crate is available from crates.io, so it should work out of the box by adding it as a dependency in your Cargo.toml file:

[dependencies]
solana_rbpf = "0.8.1"

You can also use the development version from this GitHub repository. This should be as simple as putting this inside your Cargo.toml:

[dependencies]
solana_rbpf = { git = "https://github.com/solana-labs/rbpf", branch = "main" }

Of course, if you prefer, you can clone it locally, possibly hack the crate, and then indicate the path of your local version in Cargo.toml:

[dependencies]
solana_rbpf = { path = "path/to/solana_rbpf" }

Then indicate in your source code that you want to use the crate:

extern crate solana_rbpf;

API

The API is pretty well documented inside the source code. You should also be able to access an online version of the documentation from here, automatically generated from the crates.io version (may not be up-to-date with master branch). Examples, unit tests and performance benchmarks should also prove helpful.

Here are the steps to follow to run an eBPF program with rbpf:

  1. Create the config and a loader built-in program, add some functions.
  2. Create an executable, either from the bytecode or an ELF.
  3. If you want a JIT-compiled program, compile it.
  4. Create a memory mapping, consisting of multiple memory regions.
  5. Create a context object which will also acts as instruction meter.
  6. Create a virtual machine using all of the previous steps.
  7. Execute your program: Either run the interpreter or call the JIT-compiled function.

Developer

Dependencies

  • rustc version 1.72 or higher

Build and test instructions

  • To build run cargo build
  • To test run cargo test

License

Following the effort of the Rust language project itself in order to ease integration with other projects, the rbpf crate is distributed under the terms of both the MIT license and the Apache License (Version 2.0).

See LICENSE-APACHE and LICENSE-MIT for details.

Dependencies

~2.6–3.5MB
~69K SLoC