Applied cargo fmt to fix formatting

pull/968/head
martinsoees 5 months ago
parent c3084fd6a7
commit b05ab1599d

@ -32,7 +32,7 @@
//!
//! ```no_run
//! use aya_obj::{generated::bpf_insn, Object, Map};
//!
//!
//! // Parse the object file
//! let bytes = std::fs::read("program.o").unwrap();
//! let mut object = Object::parse(&bytes).unwrap();

@ -228,7 +228,6 @@ fn relocate_maps<'a, I: Iterator<Item = &'a Relocation>>(
index: rel.symbol_index,
})?;
let Some(section_index) = sym.section_index else {
// this is not a map relocation
continue;
@ -240,7 +239,7 @@ fn relocate_maps<'a, I: Iterator<Item = &'a Relocation>>(
}
let (_name, fd, map) = if ignored_by_symbol.contains(&rel.symbol_index) {
continue
continue;
} else if let Some(m) = maps_by_symbol.get(&rel.symbol_index) {
let map = &m.2;
debug!(
@ -252,7 +251,7 @@ fn relocate_maps<'a, I: Iterator<Item = &'a Relocation>>(
debug_assert_eq!(map.symbol_index().unwrap(), rel.symbol_index);
m
} else if ignored_by_section.contains(&section_index) {
continue
continue;
} else {
let Some(m) = maps_by_section.get(&section_index) else {
debug!("failed relocating map by section index {}", section_index);

@ -21,8 +21,8 @@ use thiserror::Error;
use crate::{
generated::{
bpf_map_type::{self, *}, AYA_PERF_EVENT_IOC_DISABLE, AYA_PERF_EVENT_IOC_ENABLE,
AYA_PERF_EVENT_IOC_SET_BPF,
bpf_map_type::{self, *},
AYA_PERF_EVENT_IOC_DISABLE, AYA_PERF_EVENT_IOC_ENABLE, AYA_PERF_EVENT_IOC_SET_BPF,
},
maps::{Map, MapData, MapError},
obj::{
@ -230,19 +230,19 @@ impl<'a> EbpfLoader<'a> {
/// Allows programs containing unsupported maps for the current kernel to be loaded
/// by skipping map creation and relocation before loading.
///
///
/// This is useful when you have a single ebpf program containing e.g. a `RingBuf`
/// and a `PerfEventArray` and you decide which one to use before loading the bytecode.
///
///
/// Must be used with `.set_global()` to signal if the map is supported in the ebpf program.
///
///
/// # Example
///
///
/// ```no_run
/// use aya::EbpfLoader;
/// use aya_obj::generated::bpf_map_type;
/// use std::collections::HashSet;
///
///
/// let ringbuf_supported = 0;
/// let mut set = HashSet::new();
/// set.insert(bpf_map_type::BPF_MAP_TYPE_RINGBUF);
@ -252,7 +252,7 @@ impl<'a> EbpfLoader<'a> {
/// .load_file("file.o")?;
/// # Ok::<(), aya::EbpfError>(())
/// ```
///
///
pub fn ignore_maps_by_type(&mut self, set: HashSet<bpf_map_type>) -> &mut Self {
self.ignore_maps_by_type = set;
self
@ -260,17 +260,17 @@ impl<'a> EbpfLoader<'a> {
/// Allows programs containing unsupported maps for the current kernel to be loaded
/// by skipping map creation and relocation before loading.
///
///
/// This is useful when you have a single ebpf program containing e.g. a `RingBuf`
/// and a `PerfEventArray` and you decide which one to use before loading the bytecode.
///
///
/// Must be used with `.set_global()` to signal if the map is supported in the ebpf program.
///
///
/// # Example
///
///
/// ```no_run
/// use aya::EbpfLoader;
///
///
/// let ringbuf_supported = 0;
/// let ebpf = EbpfLoader::new()
/// .ignore_maps_by_name(&["RINGBUF"])
@ -278,7 +278,7 @@ impl<'a> EbpfLoader<'a> {
/// .load_file("file.o")?;
/// # Ok::<(), aya::EbpfError>(())
/// ```
///
///
pub fn ignore_maps_by_name(&mut self, name: &'a [&'a str]) -> &mut Self {
self.ignore_maps_by_name = name;
self
@ -531,7 +531,9 @@ impl<'a> EbpfLoader<'a> {
}
let map_type: bpf_map_type = obj.map_type().try_into().map_err(MapError::from)?;
if ignore_maps_by_type.contains(&map_type) || ignore_maps_by_name.contains(&name.as_str()) {
if ignore_maps_by_type.contains(&map_type)
|| ignore_maps_by_name.contains(&name.as_str())
{
ignored_maps.insert(name, obj);
// ignore map creation. The map is saved in `ignored_maps` and filtered out
// in `relocate_maps()` later on

@ -11,13 +11,15 @@ enum DisableMapRelocation<'a> {
#[test]
fn test_ignored_map_relocation_by_type() {
let mut ebpf = relocation_load_and_attach("test_ignored_map_relocation", crate::IGNORE_MAP, DisableMapRelocation::ByType(bpf_map_type::BPF_MAP_TYPE_RINGBUF));
let mut ebpf = relocation_load_and_attach(
"test_ignored_map_relocation",
crate::IGNORE_MAP,
DisableMapRelocation::ByType(bpf_map_type::BPF_MAP_TYPE_RINGBUF),
);
let perf = ebpf
.take_map("PERFBUF");
let perf = ebpf.take_map("PERFBUF");
let ring = ebpf
.take_map("RINGBUF");
let ring = ebpf.take_map("RINGBUF");
assert!(perf.is_some());
assert!(ring.is_none());
@ -25,13 +27,15 @@ fn test_ignored_map_relocation_by_type() {
#[test]
fn test_ignored_map_relocation_by_name() {
let mut ebpf = relocation_load_and_attach("test_ignored_map_relocation", crate::IGNORE_MAP, DisableMapRelocation::ByName("RINGBUF"));
let mut ebpf = relocation_load_and_attach(
"test_ignored_map_relocation",
crate::IGNORE_MAP,
DisableMapRelocation::ByName("RINGBUF"),
);
let perf = ebpf
.take_map("PERFBUF");
let perf = ebpf.take_map("PERFBUF");
let ring = ebpf
.take_map("RINGBUF");
let ring = ebpf.take_map("RINGBUF");
assert!(perf.is_some());
assert!(ring.is_none());
@ -69,7 +73,11 @@ fn text_64_64_reloc() {
assert_eq!(m.get(&1, 0).unwrap(), 3);
}
fn relocation_load_and_attach(name: &str, bytes: &[u8], disable_type: DisableMapRelocation) -> Ebpf {
fn relocation_load_and_attach(
name: &str,
bytes: &[u8],
disable_type: DisableMapRelocation,
) -> Ebpf {
let mut ebpf = match disable_type {
DisableMapRelocation::ByType(bmt) => {
let mut set = HashSet::new();
@ -80,13 +88,11 @@ fn relocation_load_and_attach(name: &str, bytes: &[u8], disable_type: DisableMap
.load(bytes)
.unwrap()
}
DisableMapRelocation::ByName(name) => {
EbpfLoader::new()
.ignore_maps_by_name(&[name])
.set_global("RINGBUF_SUPPORTED", &0, true)
.load(bytes)
.unwrap()
}
DisableMapRelocation::ByName(name) => EbpfLoader::new()
.ignore_maps_by_name(&[name])
.set_global("RINGBUF_SUPPORTED", &0, true)
.load(bytes)
.unwrap(),
};
let prog: &mut UProbe = ebpf.program_mut(name).unwrap().try_into().unwrap();

Loading…
Cancel
Save