pub struct Object { /* private fields */ }
Expand description
Represents a loaded BPF object file.
An Object
is logically in charge of all the contained Program
s and Map
s as well as
the associated metadata and runtime state that underpins the userspace portions of BPF program
execution. As a libbpf-rs user, you must keep the Object
alive during the entire lifetime
of your interaction with anything inside the Object
.
Note that this is an explanation of the motivation – Rust’s lifetime system should already be enforcing this invariant.
Implementations§
source§impl Object
impl Object
sourcepub unsafe fn from_ptr(ptr: NonNull<bpf_object>) -> Result<Self>
pub unsafe fn from_ptr(ptr: NonNull<bpf_object>) -> Result<Self>
Takes ownership from pointer.
§Safety
If ptr
is not already loaded then further operations on the returned object are
undefined.
It is not safe to manipulate ptr
after this operation.
sourcepub fn btf(&self) -> Result<Option<Btf<'_>>>
pub fn btf(&self) -> Result<Option<Btf<'_>>>
Parse the btf information associated with this bpf object.
sourcepub fn map<T: AsRef<str>>(&self, name: T) -> Option<&Map>
pub fn map<T: AsRef<str>>(&self, name: T) -> Option<&Map>
Get a reference to Map
with the name name
, if one exists.
sourcepub fn map_mut<T: AsRef<str>>(&mut self, name: T) -> Option<&mut Map>
pub fn map_mut<T: AsRef<str>>(&mut self, name: T) -> Option<&mut Map>
Get a mutable reference to Map
with the name name
, if one exists.
sourcepub fn maps_iter(&self) -> impl Iterator<Item = &Map>
pub fn maps_iter(&self) -> impl Iterator<Item = &Map>
Get an iterator over references to all Map
s.
Note that this will include automatically generated .data, .rodata, .bss, and
.kconfig maps. You may wish to filter this.
sourcepub fn maps_iter_mut(&mut self) -> impl Iterator<Item = &mut Map>
pub fn maps_iter_mut(&mut self) -> impl Iterator<Item = &mut Map>
Get an iterator over mutable references to all Map
s.
Note that this will include automatically generated .data, .rodata, .bss, and
.kconfig maps. You may wish to filter this.
sourcepub fn prog<T: AsRef<str>>(&self, name: T) -> Option<&Program>
pub fn prog<T: AsRef<str>>(&self, name: T) -> Option<&Program>
Get a reference to Program
with the name name
, if one exists.
sourcepub fn prog_mut<T: AsRef<str>>(&mut self, name: T) -> Option<&mut Program>
pub fn prog_mut<T: AsRef<str>>(&mut self, name: T) -> Option<&mut Program>
Get a mutable reference to Program
with the name name
, if one exists.
sourcepub fn progs_iter(&self) -> impl Iterator<Item = &Program>
pub fn progs_iter(&self) -> impl Iterator<Item = &Program>
Get an iterator over references to all Program
s.
sourcepub fn progs_iter_mut(&mut self) -> impl Iterator<Item = &mut Program>
pub fn progs_iter_mut(&mut self) -> impl Iterator<Item = &mut Program>
Get an iterator over mutable references to all Program
s.
Trait Implementations§
source§impl AsRawLibbpf for Object
impl AsRawLibbpf for Object
source§fn as_libbpf_object(&self) -> NonNull<Self::LibbpfType>
fn as_libbpf_object(&self) -> NonNull<Self::LibbpfType>
Retrieve the underlying libbpf_sys::bpf_object
.
§type LibbpfType = bpf_object
type LibbpfType = bpf_object
libbpf
type.