dummy_st_ops.c (1088B)
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 7struct bpf_dummy_ops_state { 8 int val; 9} __attribute__((preserve_access_index)); 10 11struct 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 17char _license[] SEC("license") = "GPL"; 18 19SEC("struct_ops/test_1") 20int 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 34SEC("struct_ops/test_2") 35int 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 46SEC(".struct_ops") 47struct bpf_dummy_ops dummy_1 = { 48 .test_1 = (void *)test_1, 49 .test_2 = (void *)test_2, 50};