aya: implement missing bit of retprobes

pull/1/head
Alessandro Decina 4 years ago
parent b7369d2763
commit f11df77f85

@ -15,7 +15,10 @@ use crate::{
btf::{Btf, BtfError}, btf::{Btf, BtfError},
Object, ParseError, Object, ParseError,
}, },
programs::{KProbe, Program, ProgramData, ProgramError, SocketFilter, TracePoint, UProbe, Xdp}, programs::{
probe::ProbeKind, KProbe, Program, ProgramData, ProgramError, SocketFilter, TracePoint,
UProbe, Xdp,
},
sys::bpf_map_update_elem_ptr, sys::bpf_map_update_elem_ptr,
util::{possible_cpus, POSSIBLE_CPUS}, util::{possible_cpus, POSSIBLE_CPUS},
}; };
@ -109,8 +112,22 @@ impl Bpf {
links: Vec::new(), links: Vec::new(),
}; };
let program = match kind { let program = match kind {
crate::obj::ProgramKind::KProbe => Program::KProbe(KProbe { data }), crate::obj::ProgramKind::KProbe => Program::KProbe(KProbe {
crate::obj::ProgramKind::UProbe => Program::UProbe(UProbe { data }), data,
kind: ProbeKind::KProbe,
}),
crate::obj::ProgramKind::KRetProbe => Program::KProbe(KProbe {
data,
kind: ProbeKind::KRetProbe,
}),
crate::obj::ProgramKind::UProbe => Program::UProbe(UProbe {
data,
kind: ProbeKind::UProbe,
}),
crate::obj::ProgramKind::URetProbe => Program::UProbe(UProbe {
data,
kind: ProbeKind::URetProbe,
}),
crate::obj::ProgramKind::TracePoint => Program::TracePoint(TracePoint { data }), crate::obj::ProgramKind::TracePoint => Program::TracePoint(TracePoint { data }),
crate::obj::ProgramKind::SocketFilter => { crate::obj::ProgramKind::SocketFilter => {
Program::SocketFilter(SocketFilter { data }) Program::SocketFilter(SocketFilter { data })

@ -58,7 +58,9 @@ pub(crate) struct Program {
#[derive(Debug, Copy, Clone)] #[derive(Debug, Copy, Clone)]
pub enum ProgramKind { pub enum ProgramKind {
KProbe, KProbe,
KRetProbe,
UProbe, UProbe,
URetProbe,
TracePoint, TracePoint,
SocketFilter, SocketFilter,
Xdp, Xdp,
@ -71,7 +73,9 @@ impl FromStr for ProgramKind {
use ProgramKind::*; use ProgramKind::*;
Ok(match kind { Ok(match kind {
"kprobe" => KProbe, "kprobe" => KProbe,
"kretprobe" => KRetProbe,
"uprobe" => UProbe, "uprobe" => UProbe,
"uretprobe" => URetProbe,
"xdp" => Xdp, "xdp" => Xdp,
"trace_point" => TracePoint, "trace_point" => TracePoint,
"socket_filter" => SocketFilter, "socket_filter" => SocketFilter,
@ -186,7 +190,9 @@ impl Object {
.insert(name.to_string(), parse_map(&section, name)?); .insert(name.to_string(), parse_map(&section, name)?);
} }
&[ty @ "kprobe", name] &[ty @ "kprobe", name]
| &[ty @ "kretprobe", name]
| &[ty @ "uprobe", name] | &[ty @ "uprobe", name]
| &[ty @ "uretprobe", name]
| &[ty @ "socket_filter", name] | &[ty @ "socket_filter", name]
| &[ty @ "xdp", name] | &[ty @ "xdp", name]
| &[ty @ "trace_point", name] => { | &[ty @ "trace_point", name] => {

@ -65,11 +65,13 @@ pub enum UProbeError {
#[derive(Debug)] #[derive(Debug)]
pub struct KProbe { pub struct KProbe {
pub(crate) data: ProgramData, pub(crate) data: ProgramData,
pub(crate) kind: ProbeKind,
} }
#[derive(Debug)] #[derive(Debug)]
pub struct UProbe { pub struct UProbe {
pub(crate) data: ProgramData, pub(crate) data: ProgramData,
pub(crate) kind: ProbeKind,
} }
impl KProbe { impl KProbe {
@ -87,7 +89,7 @@ impl KProbe {
offset: u64, offset: u64,
pid: Option<pid_t>, pid: Option<pid_t>,
) -> Result<LinkRef, ProgramError> { ) -> Result<LinkRef, ProgramError> {
attach(&mut self.data, ProbeKind::KProbe, fn_name, offset, pid) attach(&mut self.data, self.kind, fn_name, offset, pid)
} }
} }
@ -147,17 +149,12 @@ impl UProbe {
0 0
}; };
attach( attach(&mut self.data, self.kind, &path, sym_offset + offset, pid)
&mut self.data,
ProbeKind::UProbe,
&path,
sym_offset + offset,
pid,
)
} }
} }
enum ProbeKind { #[derive(Debug, Copy, Clone)]
pub(crate) enum ProbeKind {
KProbe, KProbe,
KRetProbe, KRetProbe,
UProbe, UProbe,

Loading…
Cancel
Save