1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (C) 2021. Huawei Technologies Co., Ltd */
3 #include <linux/bpf.h>
4 #include <bpf/bpf_helpers.h>
5 #include <bpf/bpf_tracing.h>
6 
7 struct bpf_dummy_ops_state {
8 	int val;
9 } __attribute__((preserve_access_index));
10 
11 struct bpf_dummy_ops {
12 	int (*test_1)(struct bpf_dummy_ops_state *state);
13 	int (*test_2)(struct bpf_dummy_ops_state *state, int a1, unsigned short a2,
14 		      char a3, unsigned long a4);
15 };
16 
17 char _license[] SEC("license") = "GPL";
18 
19 SEC("struct_ops/test_1")
BPF_PROG(test_1,struct bpf_dummy_ops_state * state)20 int BPF_PROG(test_1, struct bpf_dummy_ops_state *state)
21 {
22 	int ret;
23 
24 	if (!state)
25 		return 0xf2f3f4f5;
26 
27 	ret = state->val;
28 	state->val = 0x5a;
29 	return ret;
30 }
31 
32 __u64 test_2_args[5];
33 
34 SEC("struct_ops/test_2")
BPF_PROG(test_2,struct bpf_dummy_ops_state * state,int a1,unsigned short a2,char a3,unsigned long a4)35 int BPF_PROG(test_2, struct bpf_dummy_ops_state *state, int a1, unsigned short a2,
36 	     char a3, unsigned long a4)
37 {
38 	test_2_args[0] = (unsigned long)state;
39 	test_2_args[1] = a1;
40 	test_2_args[2] = a2;
41 	test_2_args[3] = a3;
42 	test_2_args[4] = a4;
43 	return 0;
44 }
45 
46 SEC(".struct_ops")
47 struct bpf_dummy_ops dummy_1 = {
48 	.test_1 = (void *)test_1,
49 	.test_2 = (void *)test_2,
50 };
51