pub struct KProbe(/* private fields */);Expand description
Kernel-space probe event.
Kprobes allow you to dynamically insert breakpoints into kernel functions. This can be used to count function executions or to attach eBPF programs that run during those breakpoints.
There are two types of kprobes:
kprobes trigger when the relevant function is called (or, potentially, executed at an offset within that function).kretprobes trigger just before the relevant function returns.
Kprobes can be create either for a named function or at a raw address in kernel space.
The internal documentation on how kprobes work is available here.
Implementations§
Source§impl KProbe
impl KProbe
Sourcepub fn for_function(retprobe: bool, func: CString, offset: u64) -> Result<Self>
pub fn for_function(retprobe: bool, func: CString, offset: u64) -> Result<Self>
Create a kprobe or kretprobe for a named kernel function.
§Errors
This will attempt to read the kprobe PMU type from
/sys/bus/event_source. It will return an error if the kprobe PMU is
not available or the filesystem exposed by the kernel there is otherwise
unparseable.
Sourcepub fn for_addr(retprobe: bool, addr: u64) -> Result<Self>
pub fn for_addr(retprobe: bool, addr: u64) -> Result<Self>
Create a kprobe or kretprobe for a kernel address.
§Errors
This will attempt to read the kprobe PMU type from
/sys/bus/event_source. It will return an error if the kprobe PMU is
not available or the filesystem exposed by the kernel there is otherwise
unparseable.
Sourcepub fn probe(func: impl AsRef<[u8]>, offset: u64) -> Result<Self>
pub fn probe(func: impl AsRef<[u8]>, offset: u64) -> Result<Self>
Create a kprobe on the given function at offset.
§Errors
This will attempt to read the kprobe PMU type from
/sys/bus/event_source. It will return an error if the kprobe PMU is
not available or the filesystem exposed by the kernel there is otherwise
unparseable.
§Panics
Panics if func contains a nul byte other than at the very end.
Sourcepub fn retprobe(func: impl AsRef<[u8]>, offset: u64) -> Result<Self>
pub fn retprobe(func: impl AsRef<[u8]>, offset: u64) -> Result<Self>
Create a kretprobe on the given function at offset.
§Errors
This will attempt to read the kprobe PMU type from
/sys/bus/event_source. It will return an error if the kprobe PMU is
not available or the filesystem exposed by the kernel there is otherwise
unparseable.
§Panics
Panics if func contains a nul byte other than at the very end.
Trait Implementations§
Source§impl Event for KProbe
impl Event for KProbe
Source§fn update_attrs(self, attr: &mut perf_event_attr)
fn update_attrs(self, attr: &mut perf_event_attr)
perf_event_attr struct so that it will record the
requested event. Read moreSource§fn update_attrs_with_data(
self,
attr: &mut perf_event_attr,
) -> Option<Arc<dyn EventData>>
fn update_attrs_with_data( self, attr: &mut perf_event_attr, ) -> Option<Arc<dyn EventData>>
perf_event_attr struct so that it will record the
requested event. Read more