1+ use crate :: base_helper:: termination_check;
12use crate :: bindings:: uapi:: linux:: bpf:: {
23 bpf_map_type, BPF_PROG_TYPE_TRACEPOINT ,
34} ;
45use crate :: ffi;
6+ use crate :: map:: RexPerfEventArray ;
57use crate :: prog_type:: rex_prog;
68use crate :: task_struct:: TaskStruct ;
9+ use crate :: utils:: { to_result, NoRef , PerfEventMaskedCPU , StreamableProgram } ;
710use crate :: Result ;
811
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+
948/// First 3 fields should always be rtti, prog_fn, and name
1049///
1150/// rtti should be u64, therefore after compiling the
@@ -50,30 +89,7 @@ impl rex_prog for tracepoint {
5089}
5190
5291impl 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 ;
7793 fn output_event < T : Copy + NoRef > (
7894 & self ,
7995 ctx : & Self :: Context ,
@@ -89,7 +105,7 @@ impl StreamableProgram for tracepoint {
89105 map_kptr,
90106 cpu. masked_cpu,
91107 data as * const T as * const ( ) ,
92- mem:: size_of:: <T >( ) as u64 ,
108+ core :: mem:: size_of:: <T >( ) as u64 ,
93109 ) )
94110 } )
95111 }
0 commit comments