1
+ use crate :: base_helper:: termination_check;
1
2
use crate :: bindings:: uapi:: linux:: bpf:: {
2
3
bpf_map_type, BPF_PROG_TYPE_TRACEPOINT ,
3
4
} ;
4
5
use crate :: ffi;
6
+ use crate :: map:: RexPerfEventArray ;
5
7
use crate :: prog_type:: rex_prog;
6
8
use crate :: task_struct:: TaskStruct ;
9
+ use crate :: utils:: { to_result, NoRef , PerfEventMaskedCPU , StreamableProgram } ;
7
10
use crate :: Result ;
8
11
12
+ use super :: binding:: * ;
13
+
14
+ pub enum TracepointContext {
15
+ SyscallsEnterOpen ( & ' static SyscallsEnterOpenCtx ) ,
16
+ SyscallsEnterOpenat ( & ' static SyscallsEnterOpenatCtx ) ,
17
+ SyscallsExitOpen ( & ' static SyscallsExitOpenCtx ) ,
18
+ SyscallsExitOpenat ( & ' static SyscallsExitOpenatCtx ) ,
19
+ SyscallsEnterDup ( & ' static SyscallsEnterDupCtx ) ,
20
+ RawSyscallsEnter ( & ' static RawSyscallsEnterCtx ) ,
21
+ }
22
+
23
+ impl TracepointContext {
24
+ unsafe fn get_ptr ( & self ) -> * const ( ) {
25
+ match self {
26
+ TracepointContext :: SyscallsEnterOpen ( ctx) => {
27
+ * ctx as * const SyscallsEnterOpenCtx as * const ( )
28
+ }
29
+ TracepointContext :: SyscallsEnterOpenat ( ctx) => {
30
+ * ctx as * const SyscallsEnterOpenatCtx as * const ( )
31
+ }
32
+ TracepointContext :: SyscallsExitOpen ( ctx) => {
33
+ * ctx as * const SyscallsExitOpenCtx as * const ( )
34
+ }
35
+ TracepointContext :: SyscallsExitOpenat ( ctx) => {
36
+ * ctx as * const SyscallsExitOpenatCtx as * const ( )
37
+ }
38
+ TracepointContext :: SyscallsEnterDup ( ctx) => {
39
+ * ctx as * const SyscallsEnterDupCtx as * const ( )
40
+ }
41
+ TracepointContext :: RawSyscallsEnter ( ctx) => {
42
+ * ctx as * const RawSyscallsEnterCtx as * const ( )
43
+ }
44
+ }
45
+ }
46
+ }
47
+
9
48
/// First 3 fields should always be rtti, prog_fn, and name
10
49
///
11
50
/// rtti should be u64, therefore after compiling the
@@ -50,30 +89,7 @@ impl rex_prog for tracepoint {
50
89
}
51
90
52
91
impl StreamableProgram for tracepoint {
53
- type Context = tp_ctx ;
54
- fn output_event < T : Copy + NoRef > (
55
- & self ,
56
- ctx : & Self :: Context ,
57
- map : & ' static RexPerfEventArray < T > ,
58
- data : & T ,
59
- cpu : PerfEventMaskedCPU ,
60
- ) -> Result {
61
- let map_kptr = unsafe { core:: ptr:: read_volatile ( & map. kptr ) } ;
62
- let ctx_ptr = unsafe { ctx. get_ptr ( ) } ;
63
- termination_check ! ( unsafe {
64
- to_result!( ffi:: bpf_perf_event_output_tp(
65
- ctx_ptr,
66
- map_kptr,
67
- cpu. masked_cpu,
68
- data as * const T as * const ( ) ,
69
- mem:: size_of:: <T >( ) as u64 ,
70
- ) )
71
- } )
72
- }
73
- }
74
-
75
- impl StreamableProgram for tracepoint {
76
- type Context = tp_ctx ;
92
+ type Context = TracepointContext ;
77
93
fn output_event < T : Copy + NoRef > (
78
94
& self ,
79
95
ctx : & Self :: Context ,
@@ -89,7 +105,7 @@ impl StreamableProgram for tracepoint {
89
105
map_kptr,
90
106
cpu. masked_cpu,
91
107
data as * const T as * const ( ) ,
92
- mem:: size_of:: <T >( ) as u64 ,
108
+ core :: mem:: size_of:: <T >( ) as u64 ,
93
109
) )
94
110
} )
95
111
}
0 commit comments