summaryrefslogtreecommitdiff
path: root/tools/testing/selftests/bpf/progs/test_subprogs_extable.c
blob: e2a21fbd4e4423859bcbf0e25e284a2611796a96 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// SPDX-License-Identifier: GPL-2.0

#include "vmlinux.h"
#include <bpf/bpf_helpers.h>
#include <bpf/bpf_tracing.h>

struct {
	__uint(type, BPF_MAP_TYPE_ARRAY);
	__uint(max_entries, 8);
	__type(key, __u32);
	__type(value, __u64);
} test_array SEC(".maps");

unsigned int triggered;

static __u64 test_cb(struct bpf_map *map, __u32 *key, __u64 *val, void *data)
{
	return 1;
}

SEC("fexit/bpf_testmod_return_ptr")
int BPF_PROG(handle_fexit_ret_subprogs, int arg, struct file *ret)
{
	*(volatile long *)ret;
	*(volatile int *)&ret->f_mode;
	bpf_for_each_map_elem(&test_array, test_cb, NULL, 0);
	triggered++;
	return 0;
}

SEC("fexit/bpf_testmod_return_ptr")
int BPF_PROG(handle_fexit_ret_subprogs2, int arg, struct file *ret)
{
	*(volatile long *)ret;
	*(volatile int *)&ret->f_mode;
	bpf_for_each_map_elem(&test_array, test_cb, NULL, 0);
	triggered++;
	return 0;
}

SEC("fexit/bpf_testmod_return_ptr")
int BPF_PROG(handle_fexit_ret_subprogs3, int arg, struct file *ret)
{
	*(volatile long *)ret;
	*(volatile int *)&ret->f_mode;
	bpf_for_each_map_elem(&test_array, test_cb, NULL, 0);
	triggered++;
	return 0;
}

char _license[] SEC("license") = "GPL";