47f764c191
This commit adds a new probe for bpf_attach_cookie, which would be used to implement USDT probes. Since USDT probes aren't currently supported, we this triggers a dead_code warning in clippy. There are cases where exposing FEATURES - our lazy static - is actually helpful to users of the library. For example, they may wish to choose to load a different version of their bytecode based on current features. Or, in the case of an orchestrator like bpfd, we might want to allow users to describe which features their program needs and return nice error message is one or more nodes in their cluster doesn't support the necessary feature set. To do this without breaking the API, we make all the internal members of the `Features` and `BtfFeatures` structs private, and add accessors for them. We then add a `features()` API to avoid leaking the lazy_static. Signed-off-by: Dave Tucker <dave@dtucker.co.uk> |
1 year ago | |
---|---|---|
.. | ||
include | 2 years ago | |
src | 1 year ago | |
Cargo.toml | 1 year ago | |
README.md | 2 years ago |
README.md
aya-obj
Status
This crate includes code that started as internal API used by the aya crate. It has been split out so that it can be used by other projects that deal with eBPF object files. Unless you're writing low level eBPF plumbing tools, you should not need to use this crate but see the aya crate instead.
The API as it is today has a few rough edges and is generally not as polished nor stable as the main aya crate API. As always, improvements welcome!
Overview
eBPF programs written with libbpf or aya-bpf are usually compiled into an ELF object file, using various sections to store information about the eBPF programs.
aya-obj
is a library for parsing such eBPF object files, with BTF and
relocation support.
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 instructions = &object.programs["prog_name"].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();