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")
BPF_PROG(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")
BPF_PROG(test_2,int a,int b)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")
BPF_PROG(test_3,int a,int b)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")
BPF_PROG(test_2_v2,int a,int b)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  
58  struct bpf_testmod_ops___zeroed {
59  	int (*test_1)(void);
60  	void (*test_2)(int a, int b);
61  	int (*test_maybe_null)(int dummy, struct task_struct *task);
62  	void (*zeroed_op)(int a, int b);
63  	int zeroed;
64  };
65  
66  SEC("struct_ops/test_3")
BPF_PROG(zeroed_op)67  int BPF_PROG(zeroed_op)
68  {
69  	return 1;
70  }
71  
72  SEC(".struct_ops.link")
73  struct bpf_testmod_ops___zeroed testmod_zeroed = {
74  	.test_1 = (void *)test_1,
75  	.test_2 = (void *)test_2_v2,
76  	.zeroed_op = (void *)zeroed_op,
77  };
78  
79  struct bpf_testmod_ops___incompatible {
80  	int (*test_1)(void);
81  	void (*test_2)(int *a);
82  	int data;
83  };
84  
85  SEC(".struct_ops.link")
86  struct bpf_testmod_ops___incompatible testmod_incompatible = {
87  	.test_1 = (void *)test_1,
88  	.test_2 = (void *)test_2,
89  	.data = 3,
90  };
91