#include <vmlinux.h>
#include <bpf/bpf_helpers.h>
#include <bpf/bpf_tracing.h>
#include <errno.h>
char _license[] SEC("license") = "GPL";
__u64 test1_result = 0;
SEC("fentry/bpf_fentry_test1")
int BPF_PROG(test1)
{
__u64 cnt = bpf_get_func_arg_cnt(ctx);
__u64 a = 0, z = 0, ret = 0;
__s64 err;
test1_result = cnt == 1;
err = bpf_get_func_arg(ctx, 0, &a);
test1_result &= err == 0 && ((int) a == 1);
err = bpf_get_func_arg(ctx, 1, &z);
test1_result &= err == -EINVAL;
err = bpf_get_func_ret(ctx, &ret);
test1_result &= err == -EOPNOTSUPP;
return 0;
}
__u64 test2_result = 0;
SEC("fexit/bpf_fentry_test2")
int BPF_PROG(test2)
{
__u64 cnt = bpf_get_func_arg_cnt(ctx);
__u64 a = 0, b = 0, z = 0, ret = 0;
__s64 err;
test2_result = cnt == 2;
err = bpf_get_func_arg(ctx, 0, &a);
test2_result &= err == 0 && (int) a == 2;
err = bpf_get_func_arg(ctx, 1, &b);
test2_result &= err == 0 && b == 3;
err = bpf_get_func_arg(ctx, 2, &z);
test2_result &= err == -EINVAL;
err = bpf_get_func_ret(ctx, &ret);
test2_result &= err == 0 && ret == 5;
return 0;
}
__u64 test3_result = 0;
SEC("fmod_ret/bpf_modify_return_test")
int BPF_PROG(fmod_ret_test, int _a, int *_b, int _ret)
{
__u64 cnt = bpf_get_func_arg_cnt(ctx);
__u64 a = 0, b = 0, z = 0, ret = 0;
__s64 err;
test3_result = cnt == 2;
err = bpf_get_func_arg(ctx, 0, &a);
test3_result &= err == 0 && ((int) a == 1);
err = bpf_get_func_arg(ctx, 1, &b);
test3_result &= err == 0 && ((int *) b == _b);
err = bpf_get_func_arg(ctx, 2, &z);
test3_result &= err == -EINVAL;
err = bpf_get_func_ret(ctx, &ret);
test3_result &= err == 0 && ret == 0;
return 1234;
}
__u64 test4_result = 0;
SEC("fexit/bpf_modify_return_test")
int BPF_PROG(fexit_test, int _a, int *_b, int _ret)
{
__u64 cnt = bpf_get_func_arg_cnt(ctx);
__u64 a = 0, b = 0, z = 0, ret = 0;
__s64 err;
test4_result = cnt == 2;
err = bpf_get_func_arg(ctx, 0, &a);
test4_result &= err == 0 && ((int) a == 1);
err = bpf_get_func_arg(ctx, 1, &b);
test4_result &= err == 0 && ((int *) b == _b);
err = bpf_get_func_arg(ctx, 2, &z);
test4_result &= err == -EINVAL;
err = bpf_get_func_ret(ctx, &ret);
test4_result &= err == 0 && ret == 1234;
return 0;
}
__u64 test5_result = 0;
SEC("tp_btf/bpf_testmod_fentry_test1_tp")
int BPF_PROG(tp_test1)
{
__u64 cnt = bpf_get_func_arg_cnt(ctx);
__u64 a = 0, z = 0;
__s64 err;
test5_result = cnt == 1;
err = bpf_get_func_arg(ctx, 0, &a);
test5_result &= err == 0 && ((int) a == 1);
err = bpf_get_func_arg(ctx, 1, &z);
test5_result &= err == -EINVAL;
return 0;
}
__u64 test6_result = 0;
SEC("tp_btf/bpf_testmod_fentry_test2_tp")
int BPF_PROG(tp_test2)
{
__u64 cnt = bpf_get_func_arg_cnt(ctx);
__u64 a = 0, b = 0, z = 0;
__s64 err;
test6_result = cnt == 2;
err = bpf_get_func_arg(ctx, 0, &a);
test6_result &= err == 0 && (int) a == 2;
err = bpf_get_func_arg(ctx, 1, &b);
test6_result &= err == 0 && b == 3;
err = bpf_get_func_arg(ctx, 2, &z);
test6_result &= err == -EINVAL;
return 0;
}
__u64 test7_result = 0;
#if defined(bpf_target_x86) || defined(bpf_target_arm64) || defined(bpf_target_riscv)
SEC("fsession/bpf_fentry_test1")
int BPF_PROG(test7)
{
__u64 cnt = bpf_get_func_arg_cnt(ctx);
__u64 a = 0, z = 0, ret = 0;
__s64 err;
test7_result = cnt == 1;
err = bpf_get_func_arg(ctx, 0, &a);
test7_result &= err == 0 && ((int) a == 1);
err = bpf_get_func_arg(ctx, 1, &z);
test7_result &= err == -EINVAL;
if (bpf_session_is_return(ctx)) {
err = bpf_get_func_ret(ctx, &ret);
test7_result &= err == 0 && ret == 2;
} else {
err = bpf_get_func_ret(ctx, &ret);
test7_result &= err == 0 && ret == 0;
}
return 0;
}
#else
SEC("fentry/bpf_fentry_test1")
int BPF_PROG(test7)
{
test7_result = 1;
return 0;
}
#endif