From e9be3d9023478b0132779267dcd88222f69feef5 Mon Sep 17 00:00:00 2001 From: Mary Date: Thu, 1 Jun 2023 14:55:42 +0200 Subject: [PATCH] aya: Make probe event_alias unique This fixes issues when trying to attach the same kernel function multiple times on 4.17 and lower (possibly upper too?) --- aya/src/programs/probe.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/aya/src/programs/probe.rs b/aya/src/programs/probe.rs index b1690ecd..44b93790 100644 --- a/aya/src/programs/probe.rs +++ b/aya/src/programs/probe.rs @@ -4,6 +4,7 @@ use std::{ io::{self, Write}, path::Path, process, + sync::atomic::{AtomicUsize, Ordering}, }; use crate::{ @@ -15,6 +16,8 @@ use crate::{ sys::{kernel_version, perf_event_open_probe, perf_event_open_trace_point}, }; +static PROBE_NAME_INDEX: AtomicUsize = AtomicUsize::new(0); + /// Kind of probe program #[derive(Debug, Copy, Clone)] pub enum ProbeKind { @@ -158,11 +161,12 @@ fn create_probe_event( KRetProbe | URetProbe => 'r', }; let event_alias = format!( - "aya_{}_{}_{}_{:#x}", + "aya_{}_{}_{}_{:#x}_{}", process::id(), probe_type_prefix, fn_name, - offset + offset, + PROBE_NAME_INDEX.fetch_add(1, Ordering::SeqCst) ); let offset_suffix = match kind { KProbe => format!("+{offset}"),