0001
0002
0003 #include <linux/bpf.h>
0004 #include <bpf/bpf_helpers.h>
0005 #include <bpf/bpf_tracing.h>
0006
0007 struct bpf_dummy_ops_state {
0008 int val;
0009 } __attribute__((preserve_access_index));
0010
0011 struct bpf_dummy_ops {
0012 int (*test_1)(struct bpf_dummy_ops_state *state);
0013 int (*test_2)(struct bpf_dummy_ops_state *state, int a1, unsigned short a2,
0014 char a3, unsigned long a4);
0015 };
0016
0017 char _license[] SEC("license") = "GPL";
0018
0019 SEC("struct_ops/test_1")
0020 int BPF_PROG(test_1, struct bpf_dummy_ops_state *state)
0021 {
0022 int ret;
0023
0024 if (!state)
0025 return 0xf2f3f4f5;
0026
0027 ret = state->val;
0028 state->val = 0x5a;
0029 return ret;
0030 }
0031
0032 __u64 test_2_args[5];
0033
0034 SEC("struct_ops/test_2")
0035 int BPF_PROG(test_2, struct bpf_dummy_ops_state *state, int a1, unsigned short a2,
0036 char a3, unsigned long a4)
0037 {
0038 test_2_args[0] = (unsigned long)state;
0039 test_2_args[1] = a1;
0040 test_2_args[2] = a2;
0041 test_2_args[3] = a3;
0042 test_2_args[4] = a4;
0043 return 0;
0044 }
0045
0046 SEC(".struct_ops")
0047 struct bpf_dummy_ops dummy_1 = {
0048 .test_1 = (void *)test_1,
0049 .test_2 = (void *)test_2,
0050 };