Loading...
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
7char _license[] SEC("license") = "GPL";
8
9SEC("struct_ops/test_1")
10int BPF_PROG(test_1, struct bpf_dummy_ops_state *state)
11{
12 int ret;
13
14 /* Check that 'state' nullable status is detected correctly.
15 * If 'state' argument would be assumed non-null by verifier
16 * the code below would be deleted as dead (which it shouldn't).
17 * Hide it from the compiler behind 'asm' block to avoid
18 * unnecessary optimizations.
19 */
20 asm volatile (
21 "if %[state] != 0 goto +2;"
22 "r0 = 0xf2f3f4f5;"
23 "exit;"
24 ::[state]"p"(state));
25
26 ret = state->val;
27 state->val = 0x5a;
28 return ret;
29}
30
31__u64 test_2_args[5];
32
33SEC("struct_ops/test_2")
34int BPF_PROG(test_2, struct bpf_dummy_ops_state *state, int a1, unsigned short a2,
35 char a3, unsigned long a4)
36{
37 test_2_args[0] = state->val;
38 test_2_args[1] = a1;
39 test_2_args[2] = a2;
40 test_2_args[3] = a3;
41 test_2_args[4] = a4;
42 return 0;
43}
44
45SEC("struct_ops.s/test_sleepable")
46int BPF_PROG(test_sleepable, struct bpf_dummy_ops_state *state)
47{
48 return 0;
49}
50
51SEC(".struct_ops")
52struct bpf_dummy_ops dummy_1 = {
53 .test_1 = (void *)test_1,
54 .test_2 = (void *)test_2,
55 .test_sleepable = (void *)test_sleepable,
56};
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
7char _license[] SEC("license") = "GPL";
8
9SEC("struct_ops/test_1")
10int 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
24SEC("struct_ops/test_2")
25int 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
36SEC("struct_ops.s/test_sleepable")
37int BPF_PROG(test_sleepable, struct bpf_dummy_ops_state *state)
38{
39 return 0;
40}
41
42SEC(".struct_ops")
43struct bpf_dummy_ops dummy_1 = {
44 .test_1 = (void *)test_1,
45 .test_2 = (void *)test_2,
46 .test_sleepable = (void *)test_sleepable,
47};