aya_ebpf/programs/
retprobe.rs1use core::ffi::c_void;
2
3#[cfg(any(
4 bpf_target_arch = "x86_64",
5 bpf_target_arch = "arm",
6 bpf_target_arch = "powerpc64"
7))]
8use crate::bindings::pt_regs;
9#[cfg(any(bpf_target_arch = "aarch64", bpf_target_arch = "s390x"))]
11use crate::bindings::user_pt_regs as pt_regs;
12#[cfg(bpf_target_arch = "riscv64")]
14use crate::bindings::user_regs_struct as pt_regs;
15use crate::{args::FromPtRegs, EbpfContext};
16
17pub struct RetProbeContext {
18 pub regs: *mut pt_regs,
19}
20
21impl RetProbeContext {
22 pub fn new(ctx: *mut c_void) -> RetProbeContext {
23 RetProbeContext {
24 regs: ctx as *mut pt_regs,
25 }
26 }
27
28 pub fn ret<T: FromPtRegs>(&self) -> Option<T> {
44 T::from_retval(unsafe { &*self.regs })
45 }
46}
47
48impl EbpfContext for RetProbeContext {
49 fn as_ptr(&self) -> *mut c_void {
50 self.regs as *mut c_void
51 }
52}