91 lines · c
1// SPDX-License-Identifier: GPL-2.02/* Copyright (c) 2024 Meta Platforms, Inc. and affiliates. */3#include <vmlinux.h>4#include <bpf/bpf_helpers.h>5#include <bpf/bpf_tracing.h>6#include "../bpf_testmod/bpf_testmod.h"7 8char _license[] SEC("license") = "GPL";9 10int test_1_result = 0;11int test_2_result = 0;12 13SEC("struct_ops/test_1")14int BPF_PROG(test_1)15{16 test_1_result = 0xdeadbeef;17 return 0;18}19 20SEC("struct_ops/test_2")21void BPF_PROG(test_2, int a, int b)22{23 test_2_result = a + b;24}25 26SEC("?struct_ops/test_3")27int BPF_PROG(test_3, int a, int b)28{29 test_2_result = a + b + 3;30 return a + b + 3;31}32 33SEC(".struct_ops.link")34struct bpf_testmod_ops testmod_1 = {35 .test_1 = (void *)test_1,36 .test_2 = (void *)test_2,37 .data = 0x1,38};39 40SEC("struct_ops/test_2")41void BPF_PROG(test_2_v2, int a, int b)42{43 test_2_result = a * b;44}45 46struct bpf_testmod_ops___v2 {47 int (*test_1)(void);48 void (*test_2)(int a, int b);49 int (*test_maybe_null)(int dummy, struct task_struct *task);50};51 52SEC(".struct_ops.link")53struct bpf_testmod_ops___v2 testmod_2 = {54 .test_1 = (void *)test_1,55 .test_2 = (void *)test_2_v2,56};57 58struct bpf_testmod_ops___zeroed {59 int (*test_1)(void);60 void (*test_2)(int a, int b);61 int (*test_maybe_null)(int dummy, struct task_struct *task);62 void (*zeroed_op)(int a, int b);63 int zeroed;64};65 66SEC("struct_ops/test_3")67int BPF_PROG(zeroed_op)68{69 return 1;70}71 72SEC(".struct_ops.link")73struct bpf_testmod_ops___zeroed testmod_zeroed = {74 .test_1 = (void *)test_1,75 .test_2 = (void *)test_2_v2,76 .zeroed_op = (void *)zeroed_op,77};78 79struct bpf_testmod_ops___incompatible {80 int (*test_1)(void);81 void (*test_2)(int *a);82 int data;83};84 85SEC(".struct_ops.link")86struct bpf_testmod_ops___incompatible testmod_incompatible = {87 .test_1 = (void *)test_1,88 .test_2 = (void *)test_2,89 .data = 3,90};91