1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (c) 2021 Facebook */
4 #include <bpf/bpf_helpers.h>
5 #include "../bpf_testmod/bpf_testmod_kfunc.h"
8 int kfunc_call_test4(struct __sk_buff *skb)
10 struct bpf_sock *sk = skb->sk;
16 sk = bpf_sk_fullsock(sk);
20 tmp = bpf_kfunc_call_test4(-3, -30, -200, -1000);
21 return (tmp >> 32) + tmp;
25 int kfunc_call_test2(struct __sk_buff *skb)
27 struct bpf_sock *sk = skb->sk;
32 sk = bpf_sk_fullsock(sk);
36 return bpf_kfunc_call_test2((struct sock *)sk, 1, 2);
40 int kfunc_call_test1(struct __sk_buff *skb)
42 struct bpf_sock *sk = skb->sk;
49 sk = bpf_sk_fullsock(sk);
53 a = bpf_kfunc_call_test1((struct sock *)sk, 1, a | 2, 3, a | 4);
54 ret = a >> 32; /* ret should be 2 */
55 ret += (__u32)a; /* ret should be 12 */
61 int kfunc_call_test_ref_btf_id(struct __sk_buff *skb)
63 struct prog_test_ref_kfunc *pt;
67 pt = bpf_kfunc_call_test_acquire(&s);
69 if (pt->a != 42 || pt->b != 108)
71 bpf_kfunc_call_test_release(pt);
77 int kfunc_call_test_pass(struct __sk_buff *skb)
79 struct prog_test_pass1 p1 = {};
80 struct prog_test_pass2 p2 = {};
87 bpf_kfunc_call_test_pass_ctx(skb);
88 bpf_kfunc_call_test_pass1(&p1);
89 bpf_kfunc_call_test_pass2(&p2);
91 bpf_kfunc_call_test_mem_len_pass1(&a, sizeof(a));
92 bpf_kfunc_call_test_mem_len_pass1(&b, sizeof(b));
93 bpf_kfunc_call_test_mem_len_pass1(&c, sizeof(c));
94 bpf_kfunc_call_test_mem_len_pass1(&d, sizeof(d));
95 bpf_kfunc_call_test_mem_len_pass1(&e, sizeof(e));
96 bpf_kfunc_call_test_mem_len_fail2(&b, -1);
101 struct syscall_test_args {
107 int kfunc_syscall_test(struct syscall_test_args *args)
109 const long size = args->size;
111 if (size > sizeof(args->data))
112 return -7; /* -E2BIG */
114 bpf_kfunc_call_test_mem_len_pass1(&args->data, sizeof(args->data));
115 bpf_kfunc_call_test_mem_len_pass1(&args->data, sizeof(*args));
116 bpf_kfunc_call_test_mem_len_pass1(&args->data, size);
122 int kfunc_syscall_test_null(struct syscall_test_args *args)
124 /* Must be called with args as a NULL pointer
125 * we do not check for it to have the verifier consider that
126 * the pointer might not be null, and so we can load it.
128 * So the following can not be added:
134 bpf_kfunc_call_test_mem_len_pass1(args, 0);
140 int kfunc_call_test_get_mem(struct __sk_buff *skb)
142 struct prog_test_ref_kfunc *pt;
147 pt = bpf_kfunc_call_test_acquire(&s);
149 p = bpf_kfunc_call_test_get_rdwr_mem(pt, 2 * sizeof(int));
152 ret = p[1]; /* 108 */
158 p = bpf_kfunc_call_test_get_rdonly_mem(pt, 2 * sizeof(int));
165 bpf_kfunc_call_test_release(pt);
171 int kfunc_call_test_static_unused_arg(struct __sk_buff *skb)
174 u32 expected = 5, actual;
176 actual = bpf_kfunc_call_test_static_unused_arg(expected, 0xdeadbeef);
177 return actual != expected ? -1 : 0;
180 char _license[] SEC("license") = "GPL";