aya_ebpf/programs/fexit.rs
1use core::ffi::c_void;
2
3use crate::{args::FromBtfArgument, EbpfContext};
4
5pub struct FExitContext {
6 ctx: *mut c_void,
7}
8
9impl FExitContext {
10 pub fn new(ctx: *mut c_void) -> FExitContext {
11 FExitContext { ctx }
12 }
13
14 /// Returns the `n`th argument to passed to the probe function, starting from 0.
15 ///
16 /// # Examples
17 ///
18 /// ```no_run
19 /// # #![allow(non_camel_case_types)]
20 /// # #![allow(dead_code)]
21 /// # use aya_ebpf::{cty::c_int, programs::FExitContext};
22 /// # type pid_t = c_int;
23 /// # struct task_struct {
24 /// # pid: pid_t,
25 /// # }
26 /// unsafe fn try_filename_lookup(ctx: FExitContext) -> Result<u32, u32> {
27 /// let tp: *const task_struct = ctx.arg(0);
28 ///
29 /// // Do something with tp
30 ///
31 /// Ok(0)
32 /// }
33 /// ```
34 pub unsafe fn arg<T: FromBtfArgument>(&self, n: usize) -> T {
35 T::from_argument(self.ctx as *const _, n)
36 }
37}
38
39impl EbpfContext for FExitContext {
40 fn as_ptr(&self) -> *mut c_void {
41 self.ctx
42 }
43}