1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
//! Fexit programs.
use ;
use crate;
/// A program that can be attached to the exit point of (almost) any kernel
/// function.
///
/// [`FExit`] programs are similar to [kretprobes](crate::programs::KProbe),
/// but the difference is that fexit has practically zero overhead to call
/// after the kernel function returns. Fexit programs can also be attached to
/// other eBPF programs.
///
/// # Minimum kernel version
///
/// The minimum kernel version required to use this feature is 5.5.
///
/// # Test runs
///
/// [`TestRun`](crate::programs::TestRun) support for [`FExit`] programs uses
/// the kernel's tracing `BPF_PROG_TEST_RUN` handler. That handler does not call
/// the function passed to [`FExit::load`]. Instead, it runs the kernel's fixed
/// `bpf_fentry_test*` sequence, so the [`FExit`] program is executed only when
/// it is attached to one of those built-in test targets.
/// <https://github.com/torvalds/linux/blob/v7.1-rc4/net/bpf/test_run.c#L702-L715>
///
/// A successful test-run syscall means the kernel sequence completed. To check
/// that an [`FExit`] program ran, record and verify an explicit side effect such
/// as a map update. `Ok(())` does not mean this [`FExit`] program ran.
///
/// # Examples
///
/// ```no_run
/// # #[derive(thiserror::Error, Debug)]
/// # enum Error {
/// # #[error(transparent)]
/// # BtfError(#[from] aya::BtfError),
/// # #[error(transparent)]
/// # Program(#[from] aya::programs::ProgramError),
/// # #[error(transparent)]
/// # Ebpf(#[from] aya::EbpfError),
/// # }
/// # let mut bpf = Ebpf::load_file("ebpf_programs.o")?;
/// use aya::{Ebpf, programs::FExit, BtfError, Btf};
///
/// let btf = Btf::from_sys_fs()?;
/// let program: &mut FExit = bpf.program_mut("filename_lookup").unwrap().try_into()?;
/// program.load("filename_lookup", &btf)?;
/// program.attach()?;
/// # Ok::<(), Error>(())
/// ```
define_link_wrapper!;