xref: /linux/tools/testing/selftests/bpf/progs/struct_ops_module.c (revision e6a901a00822659181c93c86d8bbc2a17779fddc)
1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (c) 2024 Meta Platforms, Inc. and affiliates. */
3 #include <vmlinux.h>
4 #include <bpf/bpf_helpers.h>
5 #include <bpf/bpf_tracing.h>
6 #include "../bpf_testmod/bpf_testmod.h"
7 
8 char _license[] SEC("license") = "GPL";
9 
10 int test_1_result = 0;
11 int test_2_result = 0;
12 
13 SEC("struct_ops/test_1")
14 int BPF_PROG(test_1)
15 {
16 	test_1_result = 0xdeadbeef;
17 	return 0;
18 }
19 
20 SEC("struct_ops/test_2")
21 void BPF_PROG(test_2, int a, int b)
22 {
23 	test_2_result = a + b;
24 }
25 
26 SEC("struct_ops/test_3")
27 int BPF_PROG(test_3, int a, int b)
28 {
29 	test_2_result = a + b + 3;
30 	return a + b + 3;
31 }
32 
33 SEC(".struct_ops.link")
34 struct bpf_testmod_ops testmod_1 = {
35 	.test_1 = (void *)test_1,
36 	.test_2 = (void *)test_2,
37 	.data = 0x1,
38 };
39 
40 SEC("struct_ops/test_2")
41 void BPF_PROG(test_2_v2, int a, int b)
42 {
43 	test_2_result = a * b;
44 }
45 
46 struct bpf_testmod_ops___v2 {
47 	int (*test_1)(void);
48 	void (*test_2)(int a, int b);
49 	int (*test_maybe_null)(int dummy, struct task_struct *task);
50 };
51 
52 SEC(".struct_ops.link")
53 struct bpf_testmod_ops___v2 testmod_2 = {
54 	.test_1 = (void *)test_1,
55 	.test_2 = (void *)test_2_v2,
56 };
57