BpfSyscallAccessor

Struct BpfSyscallAccessor 

Source
pub struct BpfSyscallAccessor { /* private fields */ }
Expand description

Live-host BPF map accessor.

Construction enumerates every map id reachable via BPF_MAP_GET_NEXT_ID, opens an fd for each via BPF_MAP_GET_FD_BY_ID, and caches the metadata. The fd vector is held for the accessor’s lifetime so the maps cannot be freed underneath us — even if the scheduler exits and tears down its struct_ops link mid-walk.

Selectively populating the cache is intentional: the same trait surface accepts a BpfMapInfo argument on every method, so an accessor that holds only the maps a particular failure dump cares about (filtered by name suffix at construction time) is just as valid as one that holds every map on the system. The from_running_kernel_filtered constructor exposes that knob.

Implementations§

Source§

impl BpfSyscallAccessor

Source

pub fn from_running_kernel() -> Result<Self>

Discover and pin every BPF map currently visible to the running kernel.

Walks the kernel’s id space via BPF_MAP_GET_NEXT_ID (starting from id 0), pinning each map with BPF_MAP_GET_FD_BY_ID and fetching its metadata via BPF_OBJ_GET_INFO_BY_FD. Maps that disappear between the NEXT_ID and GET_FD_BY_ID calls (a concurrent scheduler unload, for instance) are silently skipped — that race is inherent to live-host enumeration and is not an error.

Requires CAP_SYS_ADMIN. ktstr always runs as root in the test environment so this is a non-issue for the primary consumer; live-host CLI users that hit EPERM will see it in the returned error.

Source

pub fn from_running_kernel_filtered<F>(predicate: F) -> Result<Self>
where F: FnMut(&BpfMapInfo) -> bool,

Discover and pin every BPF map for which predicate returns true. Maps that fail the predicate are closed (their fds drop) so the kernel can free them as usual.

Useful when the caller knows which maps the failure dump will touch — typically the scheduler’s named maps that match a specific suffix — and wants to avoid pinning hundreds of unrelated maps that happen to be alive (cilium, systemd, other workloads).

Trait Implementations§

Source§

impl BpfMapAccessor for BpfSyscallAccessor

Source§

fn maps(&self) -> Vec<BpfMapInfo>

Enumerate every BPF map visible to this accessor. Read more
Source§

fn read_value( &self, map: &BpfMapInfo, offset: usize, len: usize, ) -> Option<Vec<u8>>

Read a contiguous byte range from a map’s value region. Read more
Source§

fn read_array(&self, map: &BpfMapInfo, key: u32) -> Option<Vec<u8>>

Read the value bytes of one entry of a BPF_MAP_TYPE_ARRAY map by entry index. Read more
Source§

fn iter_hash_map(&self, map: &BpfMapInfo) -> Vec<(Vec<u8>, Vec<u8>)>

Iterate every entry in a BPF_MAP_TYPE_HASH or BPF_MAP_TYPE_LRU_HASH map. Read more
Source§

fn read_percpu_array( &self, map: &BpfMapInfo, key: u32, num_cpus: u32, ) -> Vec<Option<Vec<u8>>>

Read every CPU’s value for a key in a BPF_MAP_TYPE_PERCPU_ARRAY map. Read more
Source§

fn iter_percpu_hash_map( &self, map: &BpfMapInfo, num_cpus: u32, ) -> Vec<(Vec<u8>, Vec<Option<Vec<u8>>>)>

Iterate every entry in a BPF_MAP_TYPE_PERCPU_HASH or BPF_MAP_TYPE_LRU_PERCPU_HASH map. Returns (key_bytes, per_cpu_values) where per_cpu_values is one entry per CPU indexed by CPU number; Some(bytes) when the CPU’s slot is readable, None otherwise (unmapped page or out-of-range CPU). Read more
Source§

fn read_arena_pages( &self, map: &BpfMapInfo, _arena_offsets: &BpfArenaOffsets, ) -> ArenaSnapshot

Snapshot every mapped page of a BPF_MAP_TYPE_ARENA map. Read more
Source§

fn load_program_btf(&self, map: &BpfMapInfo, base_btf: &Btf) -> Option<Btf>

Load the program BTF object referenced by a map. Read more
Source§

fn find_map(&self, name_suffix: &str) -> Option<BpfMapInfo>

Find the first BPF map whose name ends with name_suffix. Read more
Source§

fn iter_task_storage(&self, _map: &BpfMapInfo) -> Vec<(Vec<u8>, Vec<u8>)>

Iterate every entry in a BPF_MAP_TYPE_TASK_STORAGE map (and the shape-identical INODE_STORAGE / SK_STORAGE / CGRP_STORAGE variants — they all use super::btf_offsets::TaskStorageOffsets). Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<T> MaybeSend for T
where T: Send,

§

impl<T> MaybeSend for T
where T: Send,