2 #include <bpf/bpf_helpers.h>
3 #include <bpf/bpf_core_read.h>
5 const char LICENSE
[] SEC("license") = "GPL";
7 __noinline
int sub1(int x
)
12 static __noinline
int sub5(int v
);
14 __noinline
int sub2(int y
)
19 static __noinline
int sub3(int z
)
21 return z
+ 3 + sub1(4);
24 static __noinline
int sub4(int w
)
26 return w
+ sub3(5) + sub1(6);
29 /* sub5() is an identitify function, just to test weirder functions layout and
32 static __noinline
int sub5(int v
)
34 return sub1(v
) - 1; /* compensates sub1()'s + 1 */
37 /* unfortunately verifier rejects `struct task_struct *t` as an unkown pointer
38 * type, so we need to accept pointer as integer and then cast it inside the
41 __noinline
int get_task_tgid(uintptr_t t
)
43 /* this ensures that CO-RE relocs work in multi-subprogs .text */
44 return BPF_CORE_READ((struct task_struct
*)(void *)t
, tgid
);
52 SEC("raw_tp/sys_enter")
55 /* perform some CO-RE relocations to ensure they work with multi-prog
58 struct task_struct
*t
= (void *)bpf_get_current_task();
60 if (!BPF_CORE_READ(t
, pid
) || !get_task_tgid((uintptr_t)t
))
63 res1
= sub1(1) + sub3(2); /* (1 + 1) + (2 + 3 + (4 + 1)) = 12 */
67 SEC("raw_tp/sys_exit")
70 struct task_struct
*t
= (void *)bpf_get_current_task();
72 if (!BPF_CORE_READ(t
, pid
) || !get_task_tgid((uintptr_t)t
))
75 res2
= sub2(3) + sub3(4); /* (3 + 2) + (4 + 3 + (4 + 1)) = 17 */
79 /* prog3 has the same section name as prog1 */
80 SEC("raw_tp/sys_enter")
83 struct task_struct
*t
= (void *)bpf_get_current_task();
85 if (!BPF_CORE_READ(t
, pid
) || !get_task_tgid((uintptr_t)t
))
88 res3
= sub3(5) + 6; /* (5 + 3 + (4 + 1)) + 6 = 19 */
92 /* prog4 has the same section name as prog2 */
93 SEC("raw_tp/sys_exit")
96 struct task_struct
*t
= (void *)bpf_get_current_task();
98 if (!BPF_CORE_READ(t
, pid
) || !get_task_tgid((uintptr_t)t
))
101 res4
= sub4(7) + sub1(8); /* (7 + (5 + 3 + (4 + 1)) + (6 + 1)) + (8 + 1) = 36 */