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.
pull/20/head
Alessandro Decina 4 years ago
parent 35f15f70e0
commit 08c71dfeb1

@ -1,5 +1,4 @@
//! Kernel space probes. //! Kernel space probes.
use libc::pid_t;
use std::io; use std::io;
use thiserror::Error; use thiserror::Error;
@ -33,7 +32,7 @@ use crate::{
/// ///
/// let program: &mut KProbe = bpf.program_mut("intercept_wakeups")?.try_into()?; /// let program: &mut KProbe = bpf.program_mut("intercept_wakeups")?.try_into()?;
/// program.load()?; /// program.load()?;
/// program.attach("try_to_wake_up", 0, None)?; /// program.attach("try_to_wake_up", 0)?;
/// # Ok::<(), aya::BpfError>(()) /// # Ok::<(), aya::BpfError>(())
/// ``` /// ```
#[derive(Debug)] #[derive(Debug)]
@ -66,19 +65,13 @@ impl KProbe {
/// ///
/// Attaches the probe to the given function name inside the kernel. If /// 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 /// `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 /// function.
/// target function is triggered by the given `pid`.
/// ///
/// If the program is a `kprobe`, it is attached to the *start* address of the target 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 /// Conversely if the program is a `kretprobe`, it is attached to the return address of the
/// target function. /// target function.
pub fn attach( pub fn attach(&mut self, fn_name: &str, offset: u64) -> Result<LinkRef, ProgramError> {
&mut self, attach(&mut self.data, self.kind, fn_name, offset, None)
fn_name: &str,
offset: u64,
pid: Option<pid_t>,
) -> Result<LinkRef, ProgramError> {
attach(&mut self.data, self.kind, fn_name, offset, pid)
} }
} }

@ -23,7 +23,7 @@
//! program.load()?; //! program.load()?;
//! // intercept_wakeups will be called every time try_to_wake_up() is called //! // intercept_wakeups will be called every time try_to_wake_up() is called
//! // inside the kernel //! // inside the kernel
//! program.attach("try_to_wake_up", 0, None)?; //! program.attach("try_to_wake_up", 0)?;
//! # Ok::<(), aya::BpfError>(()) //! # Ok::<(), aya::BpfError>(())
//! ``` //! ```
//! //!

Loading…
Cancel
Save