File Index
Files and directories
Sign in
FILE

bpf_test_no_cfi.c

File preview with syntax highlighting.

linux-6.19.14/tools/testing/selftests/bpf/test_kmods/bpf_test_no_cfi.c C
 1// SPDX-License-Identifier: GPL-2.0
 2/* Copyright (c) 2024 Meta Platforms, Inc. and affiliates. */
 3#include <linux/bpf.h>
 4#include <linux/btf.h>
 5#include <linux/init.h>
 6#include <linux/module.h>
 7
 8struct bpf_test_no_cfi_ops {
 9	void (*fn_1)(void);
10	void (*fn_2)(void);
11};
12
13static int dummy_init(struct btf *btf)
14{
15	return 0;
16}
17
18static int dummy_init_member(const struct btf_type *t,
19			     const struct btf_member *member,
20			     void *kdata, const void *udata)
21{
22	return 0;
23}
24
25static int dummy_reg(void *kdata, struct bpf_link *link)
26{
27	return 0;
28}
29
30static void dummy_unreg(void *kdata, struct bpf_link *link)
31{
32}
33
34static const struct bpf_verifier_ops dummy_verifier_ops;
35
36static void bpf_test_no_cfi_ops__fn_1(void)
37{
38}
39
40static void bpf_test_no_cfi_ops__fn_2(void)
41{
42}
43
44static struct bpf_test_no_cfi_ops __test_no_cif_ops = {
45	.fn_1 = bpf_test_no_cfi_ops__fn_1,
46	.fn_2 = bpf_test_no_cfi_ops__fn_2,
47};
48
49static struct bpf_struct_ops test_no_cif_ops = {
50	.verifier_ops = &dummy_verifier_ops,
51	.init = dummy_init,
52	.init_member = dummy_init_member,
53	.reg = dummy_reg,
54	.unreg = dummy_unreg,
55	.name = "bpf_test_no_cfi_ops",
56	.owner = THIS_MODULE,
57};
58
59static int bpf_test_no_cfi_init(void)
60{
61	int ret;
62
63	ret = register_bpf_struct_ops(&test_no_cif_ops,
64				      bpf_test_no_cfi_ops);
65	if (!ret)
66		return -EINVAL;
67
68	test_no_cif_ops.cfi_stubs = &__test_no_cif_ops;
69	ret = register_bpf_struct_ops(&test_no_cif_ops,
70				      bpf_test_no_cfi_ops);
71	return ret;
72}
73
74static void bpf_test_no_cfi_exit(void)
75{
76}
77
78module_init(bpf_test_no_cfi_init);
79module_exit(bpf_test_no_cfi_exit);
80
81MODULE_AUTHOR("Kuifeng Lee");
82MODULE_DESCRIPTION("BPF no cfi_stubs test module");
83MODULE_LICENSE("Dual BSD/GPL");
84
~/ Read-only file preview.