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
use core::ffi::c_void;
use crate::{args::FromBtfArgument, EbpfContext};
pub struct FEntryContext {
ctx: *mut c_void,
}
impl FEntryContext {
pub fn new(ctx: *mut c_void) -> FEntryContext {
FEntryContext { ctx }
}
/// Returns the `n`th argument to passed to the probe function, starting from 0.
///
/// # Examples
///
/// ```no_run
/// # #![allow(non_camel_case_types)]
/// # #![allow(dead_code)]
/// # use aya_ebpf::{cty::c_int, programs::FEntryContext};
/// # type pid_t = c_int;
/// # struct task_struct {
/// # pid: pid_t,
/// # }
/// unsafe fn try_fentry_try_to_wake_up(ctx: FEntryContext) -> Result<u32, u32> {
/// let tp: *const task_struct = ctx.arg(0);
///
/// // Do something with tp
///
/// Ok(0)
/// }
/// ```
pub unsafe fn arg<T: FromBtfArgument>(&self, n: usize) -> T {
T::from_argument(self.ctx as *const _, n)
}
}
impl EbpfContext for FEntryContext {
fn as_ptr(&self) -> *mut c_void {
self.ctx
}
}