mirror of
https://github.com/aya-rs/aya.git
synced 2026-06-09 15:37:10 +02:00
aya: kprobe: remove pid argument
Kprobes can only be attached globally. Per-pid logic needs to be implemented on the BPF side with bpf_get_current_pid_tgid.
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
//! Kernel space probes.
|
||||
use libc::pid_t;
|
||||
use std::io;
|
||||
use thiserror::Error;
|
||||
|
||||
@@ -33,7 +32,7 @@ use crate::{
|
||||
///
|
||||
/// let program: &mut KProbe = bpf.program_mut("intercept_wakeups")?.try_into()?;
|
||||
/// program.load()?;
|
||||
/// program.attach("try_to_wake_up", 0, None)?;
|
||||
/// program.attach("try_to_wake_up", 0)?;
|
||||
/// # Ok::<(), aya::BpfError>(())
|
||||
/// ```
|
||||
#[derive(Debug)]
|
||||
@@ -66,19 +65,13 @@ impl KProbe {
|
||||
///
|
||||
/// Attaches the probe to the given function name inside the kernel. If
|
||||
/// `offset` is non-zero, it is added to the address of the target
|
||||
/// function. If `pid` is not `None`, the program executes only when the
|
||||
/// target function is triggered by the given `pid`.
|
||||
/// function.
|
||||
///
|
||||
/// If the program is a `kprobe`, it is attached to the *start* address of the target function.
|
||||
/// Conversely if the program is a `kretprobe`, it is attached to the return address of the
|
||||
/// target function.
|
||||
pub fn attach(
|
||||
&mut self,
|
||||
fn_name: &str,
|
||||
offset: u64,
|
||||
pid: Option<pid_t>,
|
||||
) -> Result<LinkRef, ProgramError> {
|
||||
attach(&mut self.data, self.kind, fn_name, offset, pid)
|
||||
pub fn attach(&mut self, fn_name: &str, offset: u64) -> Result<LinkRef, ProgramError> {
|
||||
attach(&mut self.data, self.kind, fn_name, offset, None)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
//! program.load()?;
|
||||
//! // intercept_wakeups will be called every time try_to_wake_up() is called
|
||||
//! // inside the kernel
|
||||
//! program.attach("try_to_wake_up", 0, None)?;
|
||||
//! program.attach("try_to_wake_up", 0)?;
|
||||
//! # Ok::<(), aya::BpfError>(())
|
||||
//! ```
|
||||
//!
|
||||
|
||||
Reference in New Issue
Block a user