feat(aya-obj)!: Rename BpfSectionKind to EbpfSectionKind

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
pull/528/head
Dave Tucker 11 months ago
parent ea8073793e
commit cf3e2ca677

@ -5,7 +5,7 @@ use core::mem;
#[cfg(not(feature = "std"))] #[cfg(not(feature = "std"))]
use crate::std; use crate::std;
use crate::BpfSectionKind; use crate::EbpfSectionKind;
/// Invalid map type encontered /// Invalid map type encontered
pub struct InvalidMapTypeError { pub struct InvalidMapTypeError {
@ -240,10 +240,10 @@ impl Map {
} }
/// Returns the section kind. /// Returns the section kind.
pub fn section_kind(&self) -> BpfSectionKind { pub fn section_kind(&self) -> EbpfSectionKind {
match self { match self {
Map::Legacy(m) => m.section_kind, Map::Legacy(m) => m.section_kind,
Map::Btf(_) => BpfSectionKind::BtfMaps, Map::Btf(_) => EbpfSectionKind::BtfMaps,
} }
} }
@ -270,7 +270,7 @@ pub struct LegacyMap {
/// The section index /// The section index
pub section_index: usize, pub section_index: usize,
/// The section kind /// The section kind
pub section_kind: BpfSectionKind, pub section_kind: EbpfSectionKind,
/// The symbol index. /// The symbol index.
/// ///
/// This is None for data maps (.bss .data and .rodata). We don't need /// This is None for data maps (.bss .data and .rodata). We don't need

@ -820,15 +820,15 @@ impl Object {
self.section_infos self.section_infos
.insert(section.name.to_owned(), (section.index, section.size)); .insert(section.name.to_owned(), (section.index, section.size));
match section.kind { match section.kind {
BpfSectionKind::Data | BpfSectionKind::Rodata | BpfSectionKind::Bss => { EbpfSectionKind::Data | EbpfSectionKind::Rodata | EbpfSectionKind::Bss => {
self.maps self.maps
.insert(section.name.to_string(), parse_data_map_section(&section)?); .insert(section.name.to_string(), parse_data_map_section(&section)?);
} }
BpfSectionKind::Text => self.parse_text_section(section)?, EbpfSectionKind::Text => self.parse_text_section(section)?,
BpfSectionKind::Btf => self.parse_btf(&section)?, EbpfSectionKind::Btf => self.parse_btf(&section)?,
BpfSectionKind::BtfExt => self.parse_btf_ext(&section)?, EbpfSectionKind::BtfExt => self.parse_btf_ext(&section)?,
BpfSectionKind::BtfMaps => self.parse_btf_maps(&section)?, EbpfSectionKind::BtfMaps => self.parse_btf_maps(&section)?,
BpfSectionKind::Maps => { EbpfSectionKind::Maps => {
// take out self.maps so we can borrow the iterator below // take out self.maps so we can borrow the iterator below
// without cloning or collecting // without cloning or collecting
let mut maps = mem::take(&mut self.maps); let mut maps = mem::take(&mut self.maps);
@ -850,7 +850,7 @@ impl Object {
res? res?
} }
BpfSectionKind::Program => { EbpfSectionKind::Program => {
self.parse_programs(&section)?; self.parse_programs(&section)?;
if !section.relocations.is_empty() { if !section.relocations.is_empty() {
self.relocations.insert( self.relocations.insert(
@ -863,7 +863,7 @@ impl Object {
); );
} }
} }
BpfSectionKind::Undefined | BpfSectionKind::License | BpfSectionKind::Version => {} EbpfSectionKind::Undefined | EbpfSectionKind::License | EbpfSectionKind::Version => {}
} }
Ok(()) Ok(())
@ -989,7 +989,7 @@ pub enum ParseError {
/// The kind of an ELF section. /// The kind of an ELF section.
#[derive(Debug, Copy, Clone, Eq, PartialEq)] #[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub enum BpfSectionKind { pub enum EbpfSectionKind {
/// Undefined /// Undefined
Undefined, Undefined,
/// `maps` /// `maps`
@ -1016,30 +1016,30 @@ pub enum BpfSectionKind {
Version, Version,
} }
impl BpfSectionKind { impl EbpfSectionKind {
fn from_name(name: &str) -> BpfSectionKind { fn from_name(name: &str) -> EbpfSectionKind {
if name.starts_with("license") { if name.starts_with("license") {
BpfSectionKind::License EbpfSectionKind::License
} else if name.starts_with("version") { } else if name.starts_with("version") {
BpfSectionKind::Version EbpfSectionKind::Version
} else if name.starts_with("maps") { } else if name.starts_with("maps") {
BpfSectionKind::Maps EbpfSectionKind::Maps
} else if name.starts_with(".maps") { } else if name.starts_with(".maps") {
BpfSectionKind::BtfMaps EbpfSectionKind::BtfMaps
} else if name.starts_with(".text") { } else if name.starts_with(".text") {
BpfSectionKind::Text EbpfSectionKind::Text
} else if name.starts_with(".bss") { } else if name.starts_with(".bss") {
BpfSectionKind::Bss EbpfSectionKind::Bss
} else if name.starts_with(".data") { } else if name.starts_with(".data") {
BpfSectionKind::Data EbpfSectionKind::Data
} else if name.starts_with(".rodata") { } else if name.starts_with(".rodata") {
BpfSectionKind::Rodata EbpfSectionKind::Rodata
} else if name == ".BTF" { } else if name == ".BTF" {
BpfSectionKind::Btf EbpfSectionKind::Btf
} else if name == ".BTF.ext" { } else if name == ".BTF.ext" {
BpfSectionKind::BtfExt EbpfSectionKind::BtfExt
} else { } else {
BpfSectionKind::Undefined EbpfSectionKind::Undefined
} }
} }
} }
@ -1047,7 +1047,7 @@ impl BpfSectionKind {
#[derive(Debug)] #[derive(Debug)]
struct Section<'a> { struct Section<'a> {
index: SectionIndex, index: SectionIndex,
kind: BpfSectionKind, kind: EbpfSectionKind,
address: u64, address: u64,
name: &'a str, name: &'a str,
data: &'a [u8], data: &'a [u8],
@ -1065,12 +1065,12 @@ impl<'data, 'file, 'a> TryFrom<&'a ObjSection<'data, 'file>> for Section<'a> {
error, error,
}; };
let name = section.name().map_err(map_err)?; let name = section.name().map_err(map_err)?;
let kind = match BpfSectionKind::from_name(name) { let kind = match EbpfSectionKind::from_name(name) {
BpfSectionKind::Undefined => { EbpfSectionKind::Undefined => {
if section.kind() == SectionKind::Text && section.size() > 0 { if section.kind() == SectionKind::Text && section.size() > 0 {
BpfSectionKind::Program EbpfSectionKind::Program
} else { } else {
BpfSectionKind::Undefined EbpfSectionKind::Undefined
} }
} }
k => k, k => k,
@ -1168,7 +1168,7 @@ fn get_map_field(btf: &Btf, type_id: u32) -> Result<u32, BtfError> {
// bytes and are relocated based on their section index. // bytes and are relocated based on their section index.
fn parse_data_map_section(section: &Section) -> Result<Map, ParseError> { fn parse_data_map_section(section: &Section) -> Result<Map, ParseError> {
let (def, data) = match section.kind { let (def, data) = match section.kind {
BpfSectionKind::Bss | BpfSectionKind::Data | BpfSectionKind::Rodata => { EbpfSectionKind::Bss | EbpfSectionKind::Data | EbpfSectionKind::Rodata => {
let def = bpf_map_def { let def = bpf_map_def {
map_type: BPF_MAP_TYPE_ARRAY as u32, map_type: BPF_MAP_TYPE_ARRAY as u32,
key_size: mem::size_of::<u32>() as u32, key_size: mem::size_of::<u32>() as u32,
@ -1176,7 +1176,7 @@ fn parse_data_map_section(section: &Section) -> Result<Map, ParseError> {
// .bss will always have data.len() == 0 // .bss will always have data.len() == 0
value_size: section.size as u32, value_size: section.size as u32,
max_entries: 1, max_entries: 1,
map_flags: if section.kind == BpfSectionKind::Rodata { map_flags: if section.kind == EbpfSectionKind::Rodata {
BPF_F_RDONLY_PROG BPF_F_RDONLY_PROG
} else { } else {
0 0
@ -1327,7 +1327,7 @@ pub fn parse_map_info(info: bpf_map_info, pinned: PinningType) -> Map {
}, },
section_index: 0, section_index: 0,
symbol_index: None, symbol_index: None,
section_kind: BpfSectionKind::Undefined, section_kind: EbpfSectionKind::Undefined,
data: Vec::new(), data: Vec::new(),
}) })
} }
@ -1400,7 +1400,7 @@ mod tests {
const FAKE_INS_LEN: u64 = 8; const FAKE_INS_LEN: u64 = 8;
fn fake_section<'a>( fn fake_section<'a>(
kind: BpfSectionKind, kind: EbpfSectionKind,
name: &'a str, name: &'a str,
data: &'a [u8], data: &'a [u8],
index: Option<usize>, index: Option<usize>,
@ -1563,7 +1563,7 @@ mod tests {
assert_matches!( assert_matches!(
parse_data_map_section( parse_data_map_section(
&fake_section( &fake_section(
BpfSectionKind::Data, EbpfSectionKind::Data,
".bss", ".bss",
map_data, map_data,
None, None,
@ -1571,7 +1571,7 @@ mod tests {
), ),
Ok(Map::Legacy(LegacyMap { Ok(Map::Legacy(LegacyMap {
section_index: 0, section_index: 0,
section_kind: BpfSectionKind::Data, section_kind: EbpfSectionKind::Data,
symbol_index: None, symbol_index: None,
def: bpf_map_def { def: bpf_map_def {
map_type: _map_type, map_type: _map_type,
@ -1595,7 +1595,7 @@ mod tests {
fn sanitizes_empty_btf_files_to_none() { fn sanitizes_empty_btf_files_to_none() {
let mut obj = fake_obj(); let mut obj = fake_obj();
obj.parse_section(fake_section( obj.parse_section(fake_section(
BpfSectionKind::Btf, EbpfSectionKind::Btf,
".BTF", ".BTF",
&[ &[
159, 235, 1, 0, 24, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 159, 235, 1, 0, 24, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0,
@ -1604,7 +1604,7 @@ mod tests {
)) ))
.unwrap(); .unwrap();
obj.parse_section(fake_section( obj.parse_section(fake_section(
BpfSectionKind::BtfExt, EbpfSectionKind::BtfExt,
".BTF.ext", ".BTF.ext",
&[ &[
159, 235, 1, 0, 24, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 4, 0, 0, 0, 4, 0, 0, 0, 8, 0, 159, 235, 1, 0, 24, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 4, 0, 0, 0, 4, 0, 0, 0, 8, 0,
@ -1624,7 +1624,7 @@ mod tests {
fake_sym(&mut obj, 0, 0, "foo", 1); fake_sym(&mut obj, 0, 0, "foo", 1);
assert_matches!( assert_matches!(
obj.parse_programs(&fake_section( obj.parse_programs(&fake_section(
BpfSectionKind::Program, EbpfSectionKind::Program,
"kprobe/foo", "kprobe/foo",
&42u32.to_ne_bytes(), &42u32.to_ne_bytes(),
None, None,
@ -1639,7 +1639,7 @@ mod tests {
fake_sym(&mut obj, 0, 0, "foo", FAKE_INS_LEN); fake_sym(&mut obj, 0, 0, "foo", FAKE_INS_LEN);
obj.parse_programs(&fake_section( obj.parse_programs(&fake_section(
BpfSectionKind::Program, EbpfSectionKind::Program,
"kprobe/foo", "kprobe/foo",
bytes_of(&fake_ins()), bytes_of(&fake_ins()),
None, None,
@ -1673,7 +1673,7 @@ mod tests {
fake_sym(&mut obj, 0, 0, "foo", mem::size_of::<bpf_map_def>() as u64); fake_sym(&mut obj, 0, 0, "foo", mem::size_of::<bpf_map_def>() as u64);
assert_matches!( assert_matches!(
obj.parse_section(fake_section( obj.parse_section(fake_section(
BpfSectionKind::Maps, EbpfSectionKind::Maps,
"maps/foo", "maps/foo",
bytes_of(&bpf_map_def { bytes_of(&bpf_map_def {
map_type: 1, map_type: 1,
@ -1699,7 +1699,12 @@ mod tests {
let insns = [fake_ins(), fake_ins()]; let insns = [fake_ins(), fake_ins()];
let data = bytes_of(&insns); let data = bytes_of(&insns);
obj.parse_programs(&fake_section(BpfSectionKind::Program, "kprobe", data, None)) obj.parse_programs(&fake_section(
EbpfSectionKind::Program,
"kprobe",
data,
None,
))
.unwrap(); .unwrap();
let prog_foo = obj.programs.get("foo").unwrap(); let prog_foo = obj.programs.get("foo").unwrap();
@ -1767,7 +1772,7 @@ mod tests {
buf.extend(&map_data); buf.extend(&map_data);
assert_matches!( assert_matches!(
obj.parse_section(fake_section( obj.parse_section(fake_section(
BpfSectionKind::Maps, EbpfSectionKind::Maps,
"maps", "maps",
buf.as_slice(), buf.as_slice(),
None None
@ -1789,7 +1794,7 @@ mod tests {
let mut obj = fake_obj(); let mut obj = fake_obj();
assert_matches!( assert_matches!(
obj.parse_section(fake_section( obj.parse_section(fake_section(
BpfSectionKind::Data, EbpfSectionKind::Data,
".bss", ".bss",
b"map data", b"map data",
None None
@ -1800,7 +1805,7 @@ mod tests {
assert_matches!( assert_matches!(
obj.parse_section(fake_section( obj.parse_section(fake_section(
BpfSectionKind::Data, EbpfSectionKind::Data,
".rodata", ".rodata",
b"map data", b"map data",
None None
@ -1811,7 +1816,7 @@ mod tests {
assert_matches!( assert_matches!(
obj.parse_section(fake_section( obj.parse_section(fake_section(
BpfSectionKind::Data, EbpfSectionKind::Data,
".rodata.boo", ".rodata.boo",
b"map data", b"map data",
None None
@ -1822,7 +1827,7 @@ mod tests {
assert_matches!( assert_matches!(
obj.parse_section(fake_section( obj.parse_section(fake_section(
BpfSectionKind::Data, EbpfSectionKind::Data,
".data", ".data",
b"map data", b"map data",
None None
@ -1833,7 +1838,7 @@ mod tests {
assert_matches!( assert_matches!(
obj.parse_section(fake_section( obj.parse_section(fake_section(
BpfSectionKind::Data, EbpfSectionKind::Data,
".data.boo", ".data.boo",
b"map data", b"map data",
None None
@ -1850,7 +1855,7 @@ mod tests {
assert_matches!( assert_matches!(
obj.parse_section(fake_section( obj.parse_section(fake_section(
BpfSectionKind::Program, EbpfSectionKind::Program,
"kprobe/foo", "kprobe/foo",
bytes_of(&fake_ins()), bytes_of(&fake_ins()),
None None
@ -1873,7 +1878,7 @@ mod tests {
assert_matches!( assert_matches!(
obj.parse_section(fake_section( obj.parse_section(fake_section(
BpfSectionKind::Program, EbpfSectionKind::Program,
"uprobe/foo", "uprobe/foo",
bytes_of(&fake_ins()), bytes_of(&fake_ins()),
None None
@ -1896,7 +1901,7 @@ mod tests {
assert_matches!( assert_matches!(
obj.parse_section(fake_section( obj.parse_section(fake_section(
BpfSectionKind::Program, EbpfSectionKind::Program,
"uprobe.s/foo", "uprobe.s/foo",
bytes_of(&fake_ins()), bytes_of(&fake_ins()),
None None
@ -1922,7 +1927,7 @@ mod tests {
assert_matches!( assert_matches!(
obj.parse_section(fake_section( obj.parse_section(fake_section(
BpfSectionKind::Program, EbpfSectionKind::Program,
"uretprobe/foo", "uretprobe/foo",
bytes_of(&fake_ins()), bytes_of(&fake_ins()),
None None
@ -1945,7 +1950,7 @@ mod tests {
assert_matches!( assert_matches!(
obj.parse_section(fake_section( obj.parse_section(fake_section(
BpfSectionKind::Program, EbpfSectionKind::Program,
"uretprobe.s/foo", "uretprobe.s/foo",
bytes_of(&fake_ins()), bytes_of(&fake_ins()),
None None
@ -1972,7 +1977,7 @@ mod tests {
assert_matches!( assert_matches!(
obj.parse_section(fake_section( obj.parse_section(fake_section(
BpfSectionKind::Program, EbpfSectionKind::Program,
"tracepoint/foo", "tracepoint/foo",
bytes_of(&fake_ins()), bytes_of(&fake_ins()),
None None
@ -1989,7 +1994,7 @@ mod tests {
assert_matches!( assert_matches!(
obj.parse_section(fake_section( obj.parse_section(fake_section(
BpfSectionKind::Program, EbpfSectionKind::Program,
"tp/foo/bar", "tp/foo/bar",
bytes_of(&fake_ins()), bytes_of(&fake_ins()),
Some(1), Some(1),
@ -2012,7 +2017,7 @@ mod tests {
assert_matches!( assert_matches!(
obj.parse_section(fake_section( obj.parse_section(fake_section(
BpfSectionKind::Program, EbpfSectionKind::Program,
"socket/foo", "socket/foo",
bytes_of(&fake_ins()), bytes_of(&fake_ins()),
None None
@ -2035,7 +2040,7 @@ mod tests {
assert_matches!( assert_matches!(
obj.parse_section(fake_section( obj.parse_section(fake_section(
BpfSectionKind::Program, EbpfSectionKind::Program,
"xdp", "xdp",
bytes_of(&fake_ins()), bytes_of(&fake_ins()),
None None
@ -2058,7 +2063,7 @@ mod tests {
assert_matches!( assert_matches!(
obj.parse_section(fake_section( obj.parse_section(fake_section(
BpfSectionKind::Program, EbpfSectionKind::Program,
"xdp.frags", "xdp.frags",
bytes_of(&fake_ins()), bytes_of(&fake_ins()),
None None
@ -2082,7 +2087,7 @@ mod tests {
assert_matches!( assert_matches!(
obj.parse_section(fake_section( obj.parse_section(fake_section(
BpfSectionKind::Program, EbpfSectionKind::Program,
"raw_tp/foo", "raw_tp/foo",
bytes_of(&fake_ins()), bytes_of(&fake_ins()),
None None
@ -2099,7 +2104,7 @@ mod tests {
assert_matches!( assert_matches!(
obj.parse_section(fake_section( obj.parse_section(fake_section(
BpfSectionKind::Program, EbpfSectionKind::Program,
"raw_tracepoint/bar", "raw_tracepoint/bar",
bytes_of(&fake_ins()), bytes_of(&fake_ins()),
Some(1) Some(1)
@ -2122,7 +2127,7 @@ mod tests {
assert_matches!( assert_matches!(
obj.parse_section(fake_section( obj.parse_section(fake_section(
BpfSectionKind::Program, EbpfSectionKind::Program,
"lsm/foo", "lsm/foo",
bytes_of(&fake_ins()), bytes_of(&fake_ins()),
None None
@ -2148,7 +2153,7 @@ mod tests {
assert_matches!( assert_matches!(
obj.parse_section(fake_section( obj.parse_section(fake_section(
BpfSectionKind::Program, EbpfSectionKind::Program,
"lsm.s/foo", "lsm.s/foo",
bytes_of(&fake_ins()), bytes_of(&fake_ins()),
None None
@ -2174,7 +2179,7 @@ mod tests {
assert_matches!( assert_matches!(
obj.parse_section(fake_section( obj.parse_section(fake_section(
BpfSectionKind::Program, EbpfSectionKind::Program,
"tp_btf/foo", "tp_btf/foo",
bytes_of(&fake_ins()), bytes_of(&fake_ins()),
None None
@ -2197,7 +2202,7 @@ mod tests {
assert_matches!( assert_matches!(
obj.parse_section(fake_section( obj.parse_section(fake_section(
BpfSectionKind::Program, EbpfSectionKind::Program,
"sk_skb/stream_parser", "sk_skb/stream_parser",
bytes_of(&fake_ins()), bytes_of(&fake_ins()),
None None
@ -2220,7 +2225,7 @@ mod tests {
assert_matches!( assert_matches!(
obj.parse_section(fake_section( obj.parse_section(fake_section(
BpfSectionKind::Program, EbpfSectionKind::Program,
"sk_skb/stream_parser/my_parser", "sk_skb/stream_parser/my_parser",
bytes_of(&fake_ins()), bytes_of(&fake_ins()),
None None
@ -2243,7 +2248,7 @@ mod tests {
assert_matches!( assert_matches!(
obj.parse_section(fake_section( obj.parse_section(fake_section(
BpfSectionKind::Program, EbpfSectionKind::Program,
"fentry/foo", "fentry/foo",
bytes_of(&fake_ins()), bytes_of(&fake_ins()),
None None
@ -2266,7 +2271,7 @@ mod tests {
assert_matches!( assert_matches!(
obj.parse_section(fake_section( obj.parse_section(fake_section(
BpfSectionKind::Program, EbpfSectionKind::Program,
"fentry.s/foo", "fentry.s/foo",
bytes_of(&fake_ins()), bytes_of(&fake_ins()),
None None
@ -2292,7 +2297,7 @@ mod tests {
assert_matches!( assert_matches!(
obj.parse_section(fake_section( obj.parse_section(fake_section(
BpfSectionKind::Program, EbpfSectionKind::Program,
"fexit/foo", "fexit/foo",
bytes_of(&fake_ins()), bytes_of(&fake_ins()),
None None
@ -2315,7 +2320,7 @@ mod tests {
assert_matches!( assert_matches!(
obj.parse_section(fake_section( obj.parse_section(fake_section(
BpfSectionKind::Program, EbpfSectionKind::Program,
"fexit.s/foo", "fexit.s/foo",
bytes_of(&fake_ins()), bytes_of(&fake_ins()),
None None
@ -2341,7 +2346,7 @@ mod tests {
assert_matches!( assert_matches!(
obj.parse_section(fake_section( obj.parse_section(fake_section(
BpfSectionKind::Program, EbpfSectionKind::Program,
"cgroup_skb/ingress", "cgroup_skb/ingress",
bytes_of(&fake_ins()), bytes_of(&fake_ins()),
None None
@ -2364,7 +2369,7 @@ mod tests {
assert_matches!( assert_matches!(
obj.parse_section(fake_section( obj.parse_section(fake_section(
BpfSectionKind::Program, EbpfSectionKind::Program,
"cgroup_skb/ingress/foo", "cgroup_skb/ingress/foo",
bytes_of(&fake_ins()), bytes_of(&fake_ins()),
None None
@ -2387,7 +2392,7 @@ mod tests {
assert_matches!( assert_matches!(
obj.parse_section(fake_section( obj.parse_section(fake_section(
BpfSectionKind::Program, EbpfSectionKind::Program,
"cgroup/skb", "cgroup/skb",
bytes_of(&fake_ins()), bytes_of(&fake_ins()),
None None
@ -2410,7 +2415,7 @@ mod tests {
assert_matches!( assert_matches!(
obj.parse_section(fake_section( obj.parse_section(fake_section(
BpfSectionKind::Program, EbpfSectionKind::Program,
"cgroup/skb/foo", "cgroup/skb/foo",
bytes_of(&fake_ins()), bytes_of(&fake_ins()),
None None
@ -2433,7 +2438,7 @@ mod tests {
assert_matches!( assert_matches!(
obj.parse_section(fake_section( obj.parse_section(fake_section(
BpfSectionKind::Program, EbpfSectionKind::Program,
"cgroup/connect4/foo", "cgroup/connect4/foo",
bytes_of(&fake_ins()), bytes_of(&fake_ins()),
None None
@ -2459,7 +2464,7 @@ mod tests {
assert_matches!( assert_matches!(
obj.parse_section(fake_section( obj.parse_section(fake_section(
BpfSectionKind::Program, EbpfSectionKind::Program,
"cgroup/connect4", "cgroup/connect4",
bytes_of(&fake_ins()), bytes_of(&fake_ins()),
None None
@ -2485,7 +2490,7 @@ mod tests {
assert_matches!( assert_matches!(
obj.parse_section(fake_section( obj.parse_section(fake_section(
BpfSectionKind::Program, EbpfSectionKind::Program,
"cgroup/getsockopt/foo", "cgroup/getsockopt/foo",
bytes_of(&fake_ins()), bytes_of(&fake_ins()),
None None
@ -2511,7 +2516,7 @@ mod tests {
assert_matches!( assert_matches!(
obj.parse_section(fake_section( obj.parse_section(fake_section(
BpfSectionKind::Program, EbpfSectionKind::Program,
"cgroup/getsockopt", "cgroup/getsockopt",
bytes_of(&fake_ins()), bytes_of(&fake_ins()),
None None
@ -2546,7 +2551,7 @@ mod tests {
pinning: PinningType::None, pinning: PinningType::None,
}, },
section_index: 1, section_index: 1,
section_kind: BpfSectionKind::Rodata, section_kind: EbpfSectionKind::Rodata,
symbol_index: Some(1), symbol_index: Some(1),
data: vec![0, 0, 0], data: vec![0, 0, 0],
}), }),
@ -2656,10 +2661,10 @@ mod tests {
0x2E, 0x6D, 0x61, 0x70, 0x73, 0x00, 0x6C, 0x69, 0x63, 0x65, 0x6E, 0x73, 0x65, 0x00, 0x2E, 0x6D, 0x61, 0x70, 0x73, 0x00, 0x6C, 0x69, 0x63, 0x65, 0x6E, 0x73, 0x65, 0x00,
]; ];
let btf_section = fake_section(BpfSectionKind::Btf, ".BTF", data, None); let btf_section = fake_section(EbpfSectionKind::Btf, ".BTF", data, None);
obj.parse_section(btf_section).unwrap(); obj.parse_section(btf_section).unwrap();
let map_section = fake_section(BpfSectionKind::BtfMaps, ".maps", &[], None); let map_section = fake_section(EbpfSectionKind::BtfMaps, ".maps", &[], None);
obj.parse_section(map_section).unwrap(); obj.parse_section(map_section).unwrap();
let map = obj.maps.get("map_1").unwrap(); let map = obj.maps.get("map_1").unwrap();

@ -16,7 +16,7 @@ use crate::{
maps::Map, maps::Map,
obj::{Function, Object}, obj::{Function, Object},
util::{HashMap, HashSet}, util::{HashMap, HashSet},
BpfSectionKind, EbpfSectionKind,
}; };
pub(crate) const INS_SIZE: usize = mem::size_of::<bpf_insn>(); pub(crate) const INS_SIZE: usize = mem::size_of::<bpf_insn>();
@ -250,7 +250,7 @@ fn relocate_maps<'a, I: Iterator<Item = &'a Relocation>>(
debug_assert_eq!(map.symbol_index(), None); debug_assert_eq!(map.symbol_index(), None);
debug_assert!(matches!( debug_assert!(matches!(
map.section_kind(), map.section_kind(),
BpfSectionKind::Bss | BpfSectionKind::Data | BpfSectionKind::Rodata EbpfSectionKind::Bss | EbpfSectionKind::Data | EbpfSectionKind::Rodata
)); ));
m m
}; };
@ -520,7 +520,7 @@ mod test {
Map::Legacy(LegacyMap { Map::Legacy(LegacyMap {
def: Default::default(), def: Default::default(),
section_index: 0, section_index: 0,
section_kind: BpfSectionKind::Undefined, section_kind: EbpfSectionKind::Undefined,
symbol_index: Some(symbol_index), symbol_index: Some(symbol_index),
data: Vec::new(), data: Vec::new(),
}) })

@ -14,7 +14,7 @@ use aya_obj::{
btf::{BtfFeatures, BtfRelocationError}, btf::{BtfFeatures, BtfRelocationError},
generated::{BPF_F_SLEEPABLE, BPF_F_XDP_HAS_FRAGS}, generated::{BPF_F_SLEEPABLE, BPF_F_XDP_HAS_FRAGS},
relocation::BpfRelocationError, relocation::BpfRelocationError,
BpfSectionKind, Features, EbpfSectionKind, Features,
}; };
use log::{debug, warn}; use log::{debug, warn};
use thiserror::Error; use thiserror::Error;
@ -456,7 +456,7 @@ impl<'a> BpfLoader<'a> {
} }
let mut maps = HashMap::new(); let mut maps = HashMap::new();
for (name, mut obj) in obj.maps.drain() { for (name, mut obj) in obj.maps.drain() {
if let (false, BpfSectionKind::Bss | BpfSectionKind::Data | BpfSectionKind::Rodata) = if let (false, EbpfSectionKind::Bss | EbpfSectionKind::Data | EbpfSectionKind::Rodata) =
(FEATURES.bpf_global_data(), obj.section_kind()) (FEATURES.bpf_global_data(), obj.section_kind())
{ {
continue; continue;

@ -92,7 +92,7 @@ mod tests {
bpf_map_type::{BPF_MAP_TYPE_BLOOM_FILTER, BPF_MAP_TYPE_PERF_EVENT_ARRAY}, bpf_map_type::{BPF_MAP_TYPE_BLOOM_FILTER, BPF_MAP_TYPE_PERF_EVENT_ARRAY},
}, },
maps::Map, maps::Map,
obj::{self, maps::LegacyMap, BpfSectionKind}, obj::{self, maps::LegacyMap, EbpfSectionKind},
sys::{override_syscall, SysResult, Syscall}, sys::{override_syscall, SysResult, Syscall},
}; };
@ -106,7 +106,7 @@ mod tests {
..Default::default() ..Default::default()
}, },
section_index: 0, section_index: 0,
section_kind: BpfSectionKind::Maps, section_kind: EbpfSectionKind::Maps,
symbol_index: None, symbol_index: None,
data: Vec::new(), data: Vec::new(),
}) })
@ -150,7 +150,7 @@ mod tests {
..Default::default() ..Default::default()
}, },
section_index: 0, section_index: 0,
section_kind: BpfSectionKind::Maps, section_kind: EbpfSectionKind::Maps,
symbol_index: None, symbol_index: None,
data: Vec::new(), data: Vec::new(),
})); }));

@ -50,7 +50,7 @@ mod test_utils {
bpf_map_def, bpf_map_def,
generated::{bpf_cmd, bpf_map_type}, generated::{bpf_cmd, bpf_map_type},
maps::MapData, maps::MapData,
obj::{self, maps::LegacyMap, BpfSectionKind}, obj::{self, maps::LegacyMap, EbpfSectionKind},
sys::{override_syscall, Syscall}, sys::{override_syscall, Syscall},
}; };
@ -75,7 +75,7 @@ mod test_utils {
..Default::default() ..Default::default()
}, },
section_index: 0, section_index: 0,
section_kind: BpfSectionKind::Maps, section_kind: EbpfSectionKind::Maps,
data: Vec::new(), data: Vec::new(),
symbol_index: None, symbol_index: None,
}) })

@ -209,7 +209,7 @@ mod tests {
bpf_map_type::{BPF_MAP_TYPE_LPM_TRIE, BPF_MAP_TYPE_PERF_EVENT_ARRAY}, bpf_map_type::{BPF_MAP_TYPE_LPM_TRIE, BPF_MAP_TYPE_PERF_EVENT_ARRAY},
}, },
maps::Map, maps::Map,
obj::{self, maps::LegacyMap, BpfSectionKind}, obj::{self, maps::LegacyMap, EbpfSectionKind},
sys::{override_syscall, SysResult, Syscall}, sys::{override_syscall, SysResult, Syscall},
}; };
@ -223,7 +223,7 @@ mod tests {
..Default::default() ..Default::default()
}, },
section_index: 0, section_index: 0,
section_kind: BpfSectionKind::Maps, section_kind: EbpfSectionKind::Maps,
symbol_index: None, symbol_index: None,
data: Vec::new(), data: Vec::new(),
}) })
@ -279,7 +279,7 @@ mod tests {
..Default::default() ..Default::default()
}, },
section_index: 0, section_index: 0,
section_kind: BpfSectionKind::Maps, section_kind: EbpfSectionKind::Maps,
symbol_index: None, symbol_index: None,
data: Vec::new(), data: Vec::new(),
})); }));

@ -66,7 +66,7 @@ use thiserror::Error;
use crate::{ use crate::{
generated::bpf_map_info, generated::bpf_map_info,
obj::{self, parse_map_info, BpfSectionKind}, obj::{self, parse_map_info, EbpfSectionKind},
pin::PinError, pin::PinError,
sys::{ sys::{
bpf_create_map, bpf_get_object, bpf_map_freeze, bpf_map_get_fd_by_id, bpf_create_map, bpf_get_object, bpf_map_freeze, bpf_map_get_fd_by_id,
@ -602,7 +602,7 @@ impl MapData {
pub(crate) fn finalize(&mut self) -> Result<(), MapError> { pub(crate) fn finalize(&mut self) -> Result<(), MapError> {
let Self { obj, fd } = self; let Self { obj, fd } = self;
if !obj.data().is_empty() && obj.section_kind() != BpfSectionKind::Bss { if !obj.data().is_empty() && obj.section_kind() != EbpfSectionKind::Bss {
bpf_map_update_elem_ptr(fd.as_fd(), &0 as *const _, obj.data_mut().as_mut_ptr(), 0) bpf_map_update_elem_ptr(fd.as_fd(), &0 as *const _, obj.data_mut().as_mut_ptr(), 0)
.map_err(|(_, io_error)| SyscallError { .map_err(|(_, io_error)| SyscallError {
call: "bpf_map_update_elem", call: "bpf_map_update_elem",
@ -610,7 +610,7 @@ impl MapData {
}) })
.map_err(MapError::from)?; .map_err(MapError::from)?;
} }
if obj.section_kind() == BpfSectionKind::Rodata { if obj.section_kind() == EbpfSectionKind::Rodata {
bpf_map_freeze(fd.as_fd()) bpf_map_freeze(fd.as_fd())
.map_err(|(_, io_error)| SyscallError { .map_err(|(_, io_error)| SyscallError {
call: "bpf_map_freeze", call: "bpf_map_freeze",
@ -1045,7 +1045,7 @@ mod tests {
..Default::default() ..Default::default()
}, },
section_index: 0, section_index: 0,
section_kind: BpfSectionKind::Maps, section_kind: EbpfSectionKind::Maps,
symbol_index: Some(0), symbol_index: Some(0),
data: Vec::new(), data: Vec::new(),
}) })

@ -12,7 +12,7 @@ use libc::{ENOENT, ENOSPC};
use obj::{ use obj::{
btf::{BtfEnum64, Enum64}, btf::{BtfEnum64, Enum64},
maps::{bpf_map_def, LegacyMap}, maps::{bpf_map_def, LegacyMap},
BpfSectionKind, VerifierLog, EbpfSectionKind, VerifierLog,
}; };
use crate::{ use crate::{
@ -766,7 +766,7 @@ pub(crate) fn is_bpf_global_data_supported() -> bool {
..Default::default() ..Default::default()
}, },
section_index: 0, section_index: 0,
section_kind: BpfSectionKind::Maps, section_kind: EbpfSectionKind::Maps,
symbol_index: None, symbol_index: None,
data: Vec::new(), data: Vec::new(),
}), }),

Loading…
Cancel
Save