xref: /linux/tools/testing/selftests/bpf/progs/kfunc_implicit_args.c (revision 37a93dd5c49b5fda807fd204edf2547c3493319c)
1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (c) 2026 Meta Platforms, Inc. and affiliates. */
3 
4 #include <vmlinux.h>
5 #include <bpf/bpf_helpers.h>
6 #include "bpf_misc.h"
7 
8 extern int bpf_kfunc_implicit_arg(int a) __weak __ksym;
9 extern int bpf_kfunc_implicit_arg_impl(int a, struct bpf_prog_aux *aux) __weak __ksym; /* illegal */
10 extern int bpf_kfunc_implicit_arg_legacy(int a, int b) __weak __ksym;
11 extern int bpf_kfunc_implicit_arg_legacy_impl(int a, int b, struct bpf_prog_aux *aux) __weak __ksym;
12 
13 char _license[] SEC("license") = "GPL";
14 
15 SEC("syscall")
16 __retval(5)
17 int test_kfunc_implicit_arg(void *ctx)
18 {
19 	return bpf_kfunc_implicit_arg(5);
20 }
21 
22 SEC("syscall")
23 __failure __msg("cannot find address for kernel function bpf_kfunc_implicit_arg_impl")
24 int test_kfunc_implicit_arg_impl_illegal(void *ctx)
25 {
26 	return bpf_kfunc_implicit_arg_impl(5, NULL);
27 }
28 
29 SEC("syscall")
30 __retval(7)
31 int test_kfunc_implicit_arg_legacy(void *ctx)
32 {
33 	return bpf_kfunc_implicit_arg_legacy(3, 4);
34 }
35 
36 SEC("syscall")
37 __retval(11)
38 int test_kfunc_implicit_arg_legacy_impl(void *ctx)
39 {
40 	return bpf_kfunc_implicit_arg_legacy_impl(5, 6, NULL);
41 }
42