11642a394SYonghong Song // SPDX-License-Identifier: GPL-2.0
21642a394SYonghong Song /* Copyright (c) 2022 Meta Platforms, Inc. and affiliates. */
31642a394SYonghong Song 
41642a394SYonghong Song #include <vmlinux.h>
51642a394SYonghong Song #include <bpf/bpf_tracing.h>
61642a394SYonghong Song #include <bpf/bpf_helpers.h>
71642a394SYonghong Song 
81642a394SYonghong Song struct bpf_testmod_struct_arg_1 {
91642a394SYonghong Song 	int a;
101642a394SYonghong Song };
111642a394SYonghong Song struct bpf_testmod_struct_arg_2 {
121642a394SYonghong Song 	long a;
131642a394SYonghong Song 	long b;
141642a394SYonghong Song };
151642a394SYonghong Song 
165ff54dedSFeng Zhou struct bpf_testmod_struct_arg_3 {
175ff54dedSFeng Zhou 	int a;
185ff54dedSFeng Zhou 	int b[];
195ff54dedSFeng Zhou };
205ff54dedSFeng Zhou 
21*5e9cf77dSMenglong Dong struct bpf_testmod_struct_arg_4 {
22*5e9cf77dSMenglong Dong 	u64 a;
23*5e9cf77dSMenglong Dong 	int b;
24*5e9cf77dSMenglong Dong };
25*5e9cf77dSMenglong Dong 
261642a394SYonghong Song long t1_a_a, t1_a_b, t1_b, t1_c, t1_ret, t1_nregs;
271642a394SYonghong Song __u64 t1_reg0, t1_reg1, t1_reg2, t1_reg3;
281642a394SYonghong Song long t2_a, t2_b_a, t2_b_b, t2_c, t2_ret;
291642a394SYonghong Song long t3_a, t3_b, t3_c_a, t3_c_b, t3_ret;
301642a394SYonghong Song long t4_a_a, t4_b, t4_c, t4_d, t4_e_a, t4_e_b, t4_ret;
311642a394SYonghong Song long t5_ret;
325ff54dedSFeng Zhou int t6;
33*5e9cf77dSMenglong Dong long t7_a, t7_b, t7_c, t7_d, t7_e, t7_f_a, t7_f_b, t7_ret;
34*5e9cf77dSMenglong Dong long t8_a, t8_b, t8_c, t8_d, t8_e, t8_f_a, t8_f_b, t8_g, t8_ret;
35*5e9cf77dSMenglong Dong 
361642a394SYonghong Song 
371642a394SYonghong Song SEC("fentry/bpf_testmod_test_struct_arg_1")
BPF_PROG2(test_struct_arg_1,struct bpf_testmod_struct_arg_2,a,int,b,int,c)381642a394SYonghong Song int BPF_PROG2(test_struct_arg_1, struct bpf_testmod_struct_arg_2, a, int, b, int, c)
391642a394SYonghong Song {
401642a394SYonghong Song 	t1_a_a = a.a;
411642a394SYonghong Song 	t1_a_b = a.b;
421642a394SYonghong Song 	t1_b = b;
431642a394SYonghong Song 	t1_c = c;
441642a394SYonghong Song 	return 0;
451642a394SYonghong Song }
461642a394SYonghong Song 
471642a394SYonghong Song SEC("fexit/bpf_testmod_test_struct_arg_1")
BPF_PROG2(test_struct_arg_2,struct bpf_testmod_struct_arg_2,a,int,b,int,c,int,ret)481642a394SYonghong Song int BPF_PROG2(test_struct_arg_2, struct bpf_testmod_struct_arg_2, a, int, b, int, c, int, ret)
491642a394SYonghong Song {
501642a394SYonghong Song 	t1_nregs =  bpf_get_func_arg_cnt(ctx);
511642a394SYonghong Song 	/* a.a */
521642a394SYonghong Song 	bpf_get_func_arg(ctx, 0, &t1_reg0);
531642a394SYonghong Song 	/* a.b */
541642a394SYonghong Song 	bpf_get_func_arg(ctx, 1, &t1_reg1);
551642a394SYonghong Song 	/* b */
561642a394SYonghong Song 	bpf_get_func_arg(ctx, 2, &t1_reg2);
571642a394SYonghong Song 	t1_reg2 = (int)t1_reg2;
581642a394SYonghong Song 	/* c */
591642a394SYonghong Song 	bpf_get_func_arg(ctx, 3, &t1_reg3);
601642a394SYonghong Song 	t1_reg3 = (int)t1_reg3;
611642a394SYonghong Song 
621642a394SYonghong Song 	t1_ret = ret;
631642a394SYonghong Song 	return 0;
641642a394SYonghong Song }
651642a394SYonghong Song 
661642a394SYonghong Song SEC("fentry/bpf_testmod_test_struct_arg_2")
BPF_PROG2(test_struct_arg_3,int,a,struct bpf_testmod_struct_arg_2,b,int,c)671642a394SYonghong Song int BPF_PROG2(test_struct_arg_3, int, a, struct bpf_testmod_struct_arg_2, b, int, c)
681642a394SYonghong Song {
691642a394SYonghong Song 	t2_a = a;
701642a394SYonghong Song 	t2_b_a = b.a;
711642a394SYonghong Song 	t2_b_b = b.b;
721642a394SYonghong Song 	t2_c = c;
731642a394SYonghong Song 	return 0;
741642a394SYonghong Song }
751642a394SYonghong Song 
761642a394SYonghong Song SEC("fexit/bpf_testmod_test_struct_arg_2")
BPF_PROG2(test_struct_arg_4,int,a,struct bpf_testmod_struct_arg_2,b,int,c,int,ret)771642a394SYonghong Song int BPF_PROG2(test_struct_arg_4, int, a, struct bpf_testmod_struct_arg_2, b, int, c, int, ret)
781642a394SYonghong Song {
791642a394SYonghong Song 	t2_ret = ret;
801642a394SYonghong Song 	return 0;
811642a394SYonghong Song }
821642a394SYonghong Song 
831642a394SYonghong Song SEC("fentry/bpf_testmod_test_struct_arg_3")
BPF_PROG2(test_struct_arg_5,int,a,int,b,struct bpf_testmod_struct_arg_2,c)841642a394SYonghong Song int BPF_PROG2(test_struct_arg_5, int, a, int, b, struct bpf_testmod_struct_arg_2, c)
851642a394SYonghong Song {
861642a394SYonghong Song 	t3_a = a;
871642a394SYonghong Song 	t3_b = b;
881642a394SYonghong Song 	t3_c_a = c.a;
891642a394SYonghong Song 	t3_c_b = c.b;
901642a394SYonghong Song 	return 0;
911642a394SYonghong Song }
921642a394SYonghong Song 
931642a394SYonghong Song SEC("fexit/bpf_testmod_test_struct_arg_3")
BPF_PROG2(test_struct_arg_6,int,a,int,b,struct bpf_testmod_struct_arg_2,c,int,ret)941642a394SYonghong Song int BPF_PROG2(test_struct_arg_6, int, a, int, b, struct bpf_testmod_struct_arg_2, c, int, ret)
951642a394SYonghong Song {
961642a394SYonghong Song 	t3_ret = ret;
971642a394SYonghong Song 	return 0;
981642a394SYonghong Song }
991642a394SYonghong Song 
1001642a394SYonghong Song SEC("fentry/bpf_testmod_test_struct_arg_4")
BPF_PROG2(test_struct_arg_7,struct bpf_testmod_struct_arg_1,a,int,b,int,c,int,d,struct bpf_testmod_struct_arg_2,e)1011642a394SYonghong Song int BPF_PROG2(test_struct_arg_7, struct bpf_testmod_struct_arg_1, a, int, b,
1021642a394SYonghong Song 	     int, c, int, d, struct bpf_testmod_struct_arg_2, e)
1031642a394SYonghong Song {
1041642a394SYonghong Song 	t4_a_a = a.a;
1051642a394SYonghong Song 	t4_b = b;
1061642a394SYonghong Song 	t4_c = c;
1071642a394SYonghong Song 	t4_d = d;
1081642a394SYonghong Song 	t4_e_a = e.a;
1091642a394SYonghong Song 	t4_e_b = e.b;
1101642a394SYonghong Song 	return 0;
1111642a394SYonghong Song }
1121642a394SYonghong Song 
1131642a394SYonghong Song SEC("fexit/bpf_testmod_test_struct_arg_4")
BPF_PROG2(test_struct_arg_8,struct bpf_testmod_struct_arg_1,a,int,b,int,c,int,d,struct bpf_testmod_struct_arg_2,e,int,ret)1141642a394SYonghong Song int BPF_PROG2(test_struct_arg_8, struct bpf_testmod_struct_arg_1, a, int, b,
1151642a394SYonghong Song 	     int, c, int, d, struct bpf_testmod_struct_arg_2, e, int, ret)
1161642a394SYonghong Song {
1171642a394SYonghong Song 	t4_ret = ret;
1181642a394SYonghong Song 	return 0;
1191642a394SYonghong Song }
1201642a394SYonghong Song 
1211642a394SYonghong Song SEC("fentry/bpf_testmod_test_struct_arg_5")
BPF_PROG2(test_struct_arg_9)1221642a394SYonghong Song int BPF_PROG2(test_struct_arg_9)
1231642a394SYonghong Song {
1241642a394SYonghong Song 	return 0;
1251642a394SYonghong Song }
1261642a394SYonghong Song 
1271642a394SYonghong Song SEC("fexit/bpf_testmod_test_struct_arg_5")
BPF_PROG2(test_struct_arg_10,int,ret)1281642a394SYonghong Song int BPF_PROG2(test_struct_arg_10, int, ret)
1291642a394SYonghong Song {
1301642a394SYonghong Song 	t5_ret = ret;
1311642a394SYonghong Song 	return 0;
1321642a394SYonghong Song }
1331642a394SYonghong Song 
1345ff54dedSFeng Zhou SEC("fentry/bpf_testmod_test_struct_arg_6")
BPF_PROG2(test_struct_arg_11,struct bpf_testmod_struct_arg_3 *,a)1355ff54dedSFeng Zhou int BPF_PROG2(test_struct_arg_11, struct bpf_testmod_struct_arg_3 *, a)
1365ff54dedSFeng Zhou {
1375ff54dedSFeng Zhou 	t6 = a->b[0];
1385ff54dedSFeng Zhou 	return 0;
1395ff54dedSFeng Zhou }
1405ff54dedSFeng Zhou 
141*5e9cf77dSMenglong Dong SEC("fentry/bpf_testmod_test_struct_arg_7")
BPF_PROG2(test_struct_arg_12,__u64,a,void *,b,short,c,int,d,void *,e,struct bpf_testmod_struct_arg_4,f)142*5e9cf77dSMenglong Dong int BPF_PROG2(test_struct_arg_12, __u64, a, void *, b, short, c, int, d,
143*5e9cf77dSMenglong Dong 	      void *, e, struct bpf_testmod_struct_arg_4, f)
144*5e9cf77dSMenglong Dong {
145*5e9cf77dSMenglong Dong 	t7_a = a;
146*5e9cf77dSMenglong Dong 	t7_b = (long)b;
147*5e9cf77dSMenglong Dong 	t7_c = c;
148*5e9cf77dSMenglong Dong 	t7_d = d;
149*5e9cf77dSMenglong Dong 	t7_e = (long)e;
150*5e9cf77dSMenglong Dong 	t7_f_a = f.a;
151*5e9cf77dSMenglong Dong 	t7_f_b = f.b;
152*5e9cf77dSMenglong Dong 	return 0;
153*5e9cf77dSMenglong Dong }
154*5e9cf77dSMenglong Dong 
155*5e9cf77dSMenglong Dong SEC("fexit/bpf_testmod_test_struct_arg_7")
BPF_PROG2(test_struct_arg_13,__u64,a,void *,b,short,c,int,d,void *,e,struct bpf_testmod_struct_arg_4,f,int,ret)156*5e9cf77dSMenglong Dong int BPF_PROG2(test_struct_arg_13, __u64, a, void *, b, short, c, int, d,
157*5e9cf77dSMenglong Dong 	      void *, e, struct bpf_testmod_struct_arg_4, f, int, ret)
158*5e9cf77dSMenglong Dong {
159*5e9cf77dSMenglong Dong 	t7_ret = ret;
160*5e9cf77dSMenglong Dong 	return 0;
161*5e9cf77dSMenglong Dong }
162*5e9cf77dSMenglong Dong 
163*5e9cf77dSMenglong Dong SEC("fentry/bpf_testmod_test_struct_arg_8")
BPF_PROG2(test_struct_arg_14,__u64,a,void *,b,short,c,int,d,void *,e,struct bpf_testmod_struct_arg_4,f,int,g)164*5e9cf77dSMenglong Dong int BPF_PROG2(test_struct_arg_14, __u64, a, void *, b, short, c, int, d,
165*5e9cf77dSMenglong Dong 	      void *, e, struct bpf_testmod_struct_arg_4, f, int, g)
166*5e9cf77dSMenglong Dong {
167*5e9cf77dSMenglong Dong 	t8_a = a;
168*5e9cf77dSMenglong Dong 	t8_b = (long)b;
169*5e9cf77dSMenglong Dong 	t8_c = c;
170*5e9cf77dSMenglong Dong 	t8_d = d;
171*5e9cf77dSMenglong Dong 	t8_e = (long)e;
172*5e9cf77dSMenglong Dong 	t8_f_a = f.a;
173*5e9cf77dSMenglong Dong 	t8_f_b = f.b;
174*5e9cf77dSMenglong Dong 	t8_g = g;
175*5e9cf77dSMenglong Dong 	return 0;
176*5e9cf77dSMenglong Dong }
177*5e9cf77dSMenglong Dong 
178*5e9cf77dSMenglong Dong SEC("fexit/bpf_testmod_test_struct_arg_8")
BPF_PROG2(test_struct_arg_15,__u64,a,void *,b,short,c,int,d,void *,e,struct bpf_testmod_struct_arg_4,f,int,g,int,ret)179*5e9cf77dSMenglong Dong int BPF_PROG2(test_struct_arg_15, __u64, a, void *, b, short, c, int, d,
180*5e9cf77dSMenglong Dong 	      void *, e, struct bpf_testmod_struct_arg_4, f, int, g,
181*5e9cf77dSMenglong Dong 	      int, ret)
182*5e9cf77dSMenglong Dong {
183*5e9cf77dSMenglong Dong 	t8_ret = ret;
184*5e9cf77dSMenglong Dong 	return 0;
185*5e9cf77dSMenglong Dong }
186*5e9cf77dSMenglong Dong 
1871642a394SYonghong Song char _license[] SEC("license") = "GPL";
188