From 08c71dfeb19b2b4358d75baf5b95f8d4e6521935 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alessandro=C2=A0Decina?= Date: Sat, 26 Jun 2021 23:59:39 +0000 Subject: [PATCH] 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. --- aya/src/programs/kprobe.rs | 15 ++++----------- aya/src/programs/mod.rs | 2 +- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/aya/src/programs/kprobe.rs b/aya/src/programs/kprobe.rs index 32f5bd8c..9dddf6f8 100644 --- a/aya/src/programs/kprobe.rs +++ b/aya/src/programs/kprobe.rs @@ -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, - ) -> Result { - attach(&mut self.data, self.kind, fn_name, offset, pid) + pub fn attach(&mut self, fn_name: &str, offset: u64) -> Result { + attach(&mut self.data, self.kind, fn_name, offset, None) } } diff --git a/aya/src/programs/mod.rs b/aya/src/programs/mod.rs index 88552af9..b15ce0b4 100644 --- a/aya/src/programs/mod.rs +++ b/aya/src/programs/mod.rs @@ -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>(()) //! ``` //!