155714Skris// SPDX-License-Identifier: GPL-2.0 255714Skris/* Copyright (c) 2022 Meta Platforms, Inc. and affiliates. */ 355714Skris 455714Skris#include <vmlinux.h> 555714Skris#include <bpf/bpf_tracing.h> 655714Skris#include <bpf/bpf_helpers.h> 755714Skris 855714Skrisstruct bpf_testmod_struct_arg_1 { 955714Skris int a; 1055714Skris}; 1155714Skrisstruct bpf_testmod_struct_arg_2 { 1255714Skris long a; 1355714Skris long b; 1455714Skris}; 1555714Skris 1655714Skrisstruct bpf_testmod_struct_arg_3 { 1755714Skris int a; 1855714Skris int b[]; 1955714Skris}; 2055714Skris 2155714Skrisstruct bpf_testmod_struct_arg_4 { 2255714Skris u64 a; 2355714Skris int b; 2455714Skris}; 2555714Skris 2655714Skrislong t1_a_a, t1_a_b, t1_b, t1_c, t1_ret, t1_nregs; 2755714Skris__u64 t1_reg0, t1_reg1, t1_reg2, t1_reg3; 2855714Skrislong t2_a, t2_b_a, t2_b_b, t2_c, t2_ret; 2955714Skrislong t3_a, t3_b, t3_c_a, t3_c_b, t3_ret; 3059191Skrislong t4_a_a, t4_b, t4_c, t4_d, t4_e_a, t4_e_b, t4_ret; 3155714Skrislong t5_ret; 3255714Skrisint t6; 3355714Skrislong t7_a, t7_b, t7_c, t7_d, t7_e, t7_f_a, t7_f_b, t7_ret; 3455714Skrislong t8_a, t8_b, t8_c, t8_d, t8_e, t8_f_a, t8_f_b, t8_g, t8_ret; 3555714Skris 3655714Skris 3755714SkrisSEC("fentry/bpf_testmod_test_struct_arg_1") 3855714Skrisint BPF_PROG2(test_struct_arg_1, struct bpf_testmod_struct_arg_2, a, int, b, int, c) 3955714Skris{ 4055714Skris t1_a_a = a.a; 4155714Skris t1_a_b = a.b; 4255714Skris t1_b = b; 4355714Skris t1_c = c; 4455714Skris return 0; 4555714Skris} 4655714Skris 4755714SkrisSEC("fexit/bpf_testmod_test_struct_arg_1") 4855714Skrisint BPF_PROG2(test_struct_arg_2, struct bpf_testmod_struct_arg_2, a, int, b, int, c, int, ret) 4955714Skris{ 5055714Skris t1_nregs = bpf_get_func_arg_cnt(ctx); 5155714Skris /* a.a */ 5276866Skris bpf_get_func_arg(ctx, 0, &t1_reg0); 5376866Skris /* a.b */ 5476866Skris bpf_get_func_arg(ctx, 1, &t1_reg1); 5576866Skris /* b */ 5676866Skris bpf_get_func_arg(ctx, 2, &t1_reg2); 5776866Skris t1_reg2 = (int)t1_reg2; 5876866Skris /* c */ 5955714Skris bpf_get_func_arg(ctx, 3, &t1_reg3); 6059191Skris t1_reg3 = (int)t1_reg3; 6159191Skris 6276866Skris t1_ret = ret; 6376866Skris return 0; 6455714Skris} 6555714Skris 6655714SkrisSEC("fentry/bpf_testmod_test_struct_arg_2") 6755714Skrisint BPF_PROG2(test_struct_arg_3, int, a, struct bpf_testmod_struct_arg_2, b, int, c) 6855714Skris{ 6955714Skris t2_a = a; 7055714Skris t2_b_a = b.a; 7189837Skris t2_b_b = b.b; 7289837Skris t2_c = c; 7389837Skris return 0; 7489837Skris} 7589837Skris 7659191SkrisSEC("fexit/bpf_testmod_test_struct_arg_2") 7759191Skrisint BPF_PROG2(test_struct_arg_4, int, a, struct bpf_testmod_struct_arg_2, b, int, c, int, ret) 7859191Skris{ 7959191Skris t2_ret = ret; 8059191Skris return 0; 8155714Skris} 8255714Skris 8355714SkrisSEC("fentry/bpf_testmod_test_struct_arg_3") 8455714Skrisint BPF_PROG2(test_struct_arg_5, int, a, int, b, struct bpf_testmod_struct_arg_2, c) 8555714Skris{ 8655714Skris t3_a = a; 8768651Skris t3_b = b; 8868651Skris t3_c_a = c.a; 8968651Skris t3_c_b = c.b; 9068651Skris return 0; 9155714Skris} 9255714Skris 9355714SkrisSEC("fexit/bpf_testmod_test_struct_arg_3") 9455714Skrisint BPF_PROG2(test_struct_arg_6, int, a, int, b, struct bpf_testmod_struct_arg_2, c, int, ret) 9576866Skris{ 9676866Skris t3_ret = ret; 9776866Skris return 0; 9876866Skris} 9976866Skris 10076866SkrisSEC("fentry/bpf_testmod_test_struct_arg_4") 10176866Skrisint BPF_PROG2(test_struct_arg_7, struct bpf_testmod_struct_arg_1, a, int, b, 10276866Skris int, c, int, d, struct bpf_testmod_struct_arg_2, e) 10355714Skris{ 10455714Skris t4_a_a = a.a; 10555714Skris t4_b = b; 10655714Skris t4_c = c; 10755714Skris t4_d = d; 10855714Skris t4_e_a = e.a; 10955714Skris t4_e_b = e.b; 11055714Skris return 0; 11155714Skris} 11255714Skris 11355714SkrisSEC("fexit/bpf_testmod_test_struct_arg_4") 11455714Skrisint BPF_PROG2(test_struct_arg_8, struct bpf_testmod_struct_arg_1, a, int, b, 11555714Skris int, c, int, d, struct bpf_testmod_struct_arg_2, e, int, ret) 11655714Skris{ 11755714Skris t4_ret = ret; 11855714Skris return 0; 11955714Skris} 12055714Skris 12155714SkrisSEC("fentry/bpf_testmod_test_struct_arg_5") 12255714Skrisint BPF_PROG2(test_struct_arg_9) 12355714Skris{ 12455714Skris return 0; 12555714Skris} 12655714Skris 12755714SkrisSEC("fexit/bpf_testmod_test_struct_arg_5") 12855714Skrisint BPF_PROG2(test_struct_arg_10, int, ret) 12955714Skris{ 13055714Skris t5_ret = ret; 13155714Skris return 0; 13255714Skris} 13355714Skris 13455714SkrisSEC("fentry/bpf_testmod_test_struct_arg_6") 13555714Skrisint BPF_PROG2(test_struct_arg_11, struct bpf_testmod_struct_arg_3 *, a) 13655714Skris{ 13755714Skris t6 = a->b[0]; 13855714Skris return 0; 13955714Skris} 14055714Skris 14155714SkrisSEC("fentry/bpf_testmod_test_struct_arg_7") 14255714Skrisint BPF_PROG2(test_struct_arg_12, __u64, a, void *, b, short, c, int, d, 14355714Skris void *, e, struct bpf_testmod_struct_arg_4, f) 14455714Skris{ 14555714Skris t7_a = a; 14655714Skris t7_b = (long)b; 14755714Skris t7_c = c; 14855714Skris t7_d = d; 14955714Skris t7_e = (long)e; 15055714Skris t7_f_a = f.a; 15155714Skris t7_f_b = f.b; 15255714Skris return 0; 15355714Skris} 15455714Skris 15555714SkrisSEC("fexit/bpf_testmod_test_struct_arg_7") 15655714Skrisint BPF_PROG2(test_struct_arg_13, __u64, a, void *, b, short, c, int, d, 15755714Skris void *, e, struct bpf_testmod_struct_arg_4, f, int, ret) 15855714Skris{ 15955714Skris t7_ret = ret; 16055714Skris return 0; 16155714Skris} 16255714Skris 16355714SkrisSEC("fentry/bpf_testmod_test_struct_arg_8") 16455714Skrisint BPF_PROG2(test_struct_arg_14, __u64, a, void *, b, short, c, int, d, 16555714Skris void *, e, struct bpf_testmod_struct_arg_4, f, int, g) 16655714Skris{ 16755714Skris t8_a = a; 16855714Skris t8_b = (long)b; 16955714Skris t8_c = c; 17055714Skris t8_d = d; 17155714Skris t8_e = (long)e; 17255714Skris t8_f_a = f.a; 17355714Skris t8_f_b = f.b; 17455714Skris t8_g = g; 17555714Skris return 0; 17655714Skris} 17755714Skris 17855714SkrisSEC("fexit/bpf_testmod_test_struct_arg_8") 17955714Skrisint BPF_PROG2(test_struct_arg_15, __u64, a, void *, b, short, c, int, d, 18055714Skris void *, e, struct bpf_testmod_struct_arg_4, f, int, g, 18155714Skris int, ret) 18255714Skris{ 18355714Skris t8_ret = ret; 18455714Skris return 0; 18555714Skris} 18655714Skris 18755714Skrischar _license[] SEC("license") = "GPL"; 18855714Skris