You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
aya/aya-obj
Shenghui Ye 30f1fabc05 aya-obj: add no_std feature
The crate has few libstd dependencies. Since it should be platform-
independent in principle, making it no_std like the object crate would
seem reasonable.

However, the feature `error_in_core` is not yet stabilized, and the
thiserror crate currently offers no no_std support. When the feature
no_std is selected, we enable the `error_in_core` feature, switch to
thiserror-core and replace the HashMap with the one in hashbrown.
2 years ago
..
include aya-obj: migrate bindgen destination 2 years ago
src aya-obj: add no_std feature 2 years ago
Cargo.toml aya-obj: add no_std feature 2 years ago
README.md aya-obj: add no_std feature 2 years ago

README.md

aya-obj - an eBPF object file loading library

Overview

eBPF programs written with libbpf or aya-bpf are usually compiled into an ELF object file, using various section to store information about the eBPF programs.

aya-obj is a library that loads, parses and processes such eBPF object files.

Example

This example loads a simple eBPF program and runs it with rbpf.

use aya_obj::{generated::bpf_insn, Object};

// Parse the object file
let bytes = std::fs::read("program.o").unwrap();
let mut object = Object::parse(&bytes).unwrap();
// Relocate the programs
object.relocate_calls().unwrap();
object.relocate_maps(std::iter::empty()).unwrap();

// Run with rbpf
let program = object.programs.iter().next().unwrap().1;
let instructions = &program.function.instructions;
let data = unsafe {
    core::slice::from_raw_parts(
        instructions.as_ptr() as *const u8,
        instructions.len() * core::mem::size_of::<bpf_insn>(),
    )
};
let vm = rbpf::EbpfVmNoData::new(Some(data)).unwrap();
let _return = vm.execute_program().unwrap();