Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
1// SPDX-License-Identifier: GPL-2.0
2/* Copyright (c) 2022 Meta Platforms, Inc. and affiliates. */
3
4#include <vmlinux.h>
5#include <bpf/bpf_tracing.h>
6#include <bpf/bpf_helpers.h>
7
8struct bpf_testmod_struct_arg_1 {
9 int a;
10};
11struct bpf_testmod_struct_arg_2 {
12 long a;
13 long b;
14};
15
16struct bpf_testmod_struct_arg_3 {
17 int a;
18 int b[];
19};
20
21union bpf_testmod_union_arg_1 {
22 char a;
23 short b;
24 struct bpf_testmod_struct_arg_1 arg;
25};
26
27union bpf_testmod_union_arg_2 {
28 int a;
29 long b;
30 struct bpf_testmod_struct_arg_2 arg;
31};
32
33long t1_a_a, t1_a_b, t1_b, t1_c, t1_ret, t1_nregs;
34__u64 t1_reg0, t1_reg1, t1_reg2, t1_reg3;
35long t2_a, t2_b_a, t2_b_b, t2_c, t2_ret;
36long t3_a, t3_b, t3_c_a, t3_c_b, t3_ret;
37long t4_a_a, t4_b, t4_c, t4_d, t4_e_a, t4_e_b, t4_ret;
38long t5_ret;
39int t6;
40
41long ut1_a_a, ut1_b, ut1_c;
42long ut2_a, ut2_b_a, ut2_b_b;
43
44SEC("fentry/bpf_testmod_test_struct_arg_1")
45int BPF_PROG2(test_struct_arg_1, struct bpf_testmod_struct_arg_2, a, int, b, int, c)
46{
47 t1_a_a = a.a;
48 t1_a_b = a.b;
49 t1_b = b;
50 t1_c = c;
51 return 0;
52}
53
54SEC("fexit/bpf_testmod_test_struct_arg_1")
55int BPF_PROG2(test_struct_arg_2, struct bpf_testmod_struct_arg_2, a, int, b, int, c, int, ret)
56{
57 t1_nregs = bpf_get_func_arg_cnt(ctx);
58 /* a.a */
59 bpf_get_func_arg(ctx, 0, &t1_reg0);
60 /* a.b */
61 bpf_get_func_arg(ctx, 1, &t1_reg1);
62 /* b */
63 bpf_get_func_arg(ctx, 2, &t1_reg2);
64 t1_reg2 = (int)t1_reg2;
65 /* c */
66 bpf_get_func_arg(ctx, 3, &t1_reg3);
67 t1_reg3 = (int)t1_reg3;
68
69 t1_ret = ret;
70 return 0;
71}
72
73SEC("fentry/bpf_testmod_test_struct_arg_2")
74int BPF_PROG2(test_struct_arg_3, int, a, struct bpf_testmod_struct_arg_2, b, int, c)
75{
76 t2_a = a;
77 t2_b_a = b.a;
78 t2_b_b = b.b;
79 t2_c = c;
80 return 0;
81}
82
83SEC("fexit/bpf_testmod_test_struct_arg_2")
84int BPF_PROG2(test_struct_arg_4, int, a, struct bpf_testmod_struct_arg_2, b, int, c, int, ret)
85{
86 t2_ret = ret;
87 return 0;
88}
89
90SEC("fentry/bpf_testmod_test_struct_arg_3")
91int BPF_PROG2(test_struct_arg_5, int, a, int, b, struct bpf_testmod_struct_arg_2, c)
92{
93 t3_a = a;
94 t3_b = b;
95 t3_c_a = c.a;
96 t3_c_b = c.b;
97 return 0;
98}
99
100SEC("fexit/bpf_testmod_test_struct_arg_3")
101int BPF_PROG2(test_struct_arg_6, int, a, int, b, struct bpf_testmod_struct_arg_2, c, int, ret)
102{
103 t3_ret = ret;
104 return 0;
105}
106
107SEC("fentry/bpf_testmod_test_struct_arg_4")
108int BPF_PROG2(test_struct_arg_7, struct bpf_testmod_struct_arg_1, a, int, b,
109 int, c, int, d, struct bpf_testmod_struct_arg_2, e)
110{
111 t4_a_a = a.a;
112 t4_b = b;
113 t4_c = c;
114 t4_d = d;
115 t4_e_a = e.a;
116 t4_e_b = e.b;
117 return 0;
118}
119
120SEC("fexit/bpf_testmod_test_struct_arg_4")
121int BPF_PROG2(test_struct_arg_8, struct bpf_testmod_struct_arg_1, a, int, b,
122 int, c, int, d, struct bpf_testmod_struct_arg_2, e, int, ret)
123{
124 t4_ret = ret;
125 return 0;
126}
127
128SEC("fentry/bpf_testmod_test_struct_arg_5")
129int BPF_PROG2(test_struct_arg_9)
130{
131 return 0;
132}
133
134SEC("fexit/bpf_testmod_test_struct_arg_5")
135int BPF_PROG2(test_struct_arg_10, int, ret)
136{
137 t5_ret = ret;
138 return 0;
139}
140
141SEC("fentry/bpf_testmod_test_struct_arg_6")
142int BPF_PROG2(test_struct_arg_11, struct bpf_testmod_struct_arg_3 *, a)
143{
144 t6 = a->b[0];
145 return 0;
146}
147
148SEC("fexit/bpf_testmod_test_union_arg_1")
149int BPF_PROG2(test_union_arg_1, union bpf_testmod_union_arg_1, a, int, b, int, c)
150{
151 ut1_a_a = a.arg.a;
152 ut1_b = b;
153 ut1_c = c;
154 return 0;
155}
156
157SEC("fexit/bpf_testmod_test_union_arg_2")
158int BPF_PROG2(test_union_arg_2, int, a, union bpf_testmod_union_arg_2, b)
159{
160 ut2_a = a;
161 ut2_b_a = b.arg.a;
162 ut2_b_b = b.arg.b;
163 return 0;
164}
165
166char _license[] SEC("license") = "GPL";