bpf_loader_lib/
btf_container.rs1use anyhow::{anyhow, Result};
8use btf::types::Btf;
9use ouroboros::self_referencing;
10
11use crate::elf_container::ElfContainer;
12#[self_referencing]
16pub struct BtfContainer {
17 pub(crate) elf_container: ElfContainer,
18 #[borrows(elf_container)]
19 #[covariant]
20 pub(crate) btf: Btf<'this>,
21}
22
23impl BtfContainer {
24 pub fn new_from_binary(bin: &[u8]) -> Result<Self> {
26 let elf = ElfContainer::new_from_binary(bin)?;
27 let val = BtfContainerTryBuilder {
28 elf_container: elf,
29 btf_builder: |elf: &ElfContainer| {
30 Btf::load(elf.borrow_elf()).map_err(|e| anyhow!("Failed to build btf: {}", e))
31 },
32 }
33 .try_build()?;
34 Ok(val)
35 }
36}