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