]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blob - tools/testing/selftests/bpf/progs/test_core_reloc_bitfields_direct.c
Merge git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net
[mirror_ubuntu-jammy-kernel.git] / tools / testing / selftests / bpf / progs / test_core_reloc_bitfields_direct.c
1 // SPDX-License-Identifier: GPL-2.0
2 // Copyright (c) 2019 Facebook
3
4 #include <linux/bpf.h>
5 #include <stdint.h>
6 #include "bpf_helpers.h"
7 #include "bpf_core_read.h"
8
9 char _license[] SEC("license") = "GPL";
10
11 struct {
12 char in[256];
13 char out[256];
14 } data = {};
15
16 struct core_reloc_bitfields {
17 /* unsigned bitfields */
18 uint8_t ub1: 1;
19 uint8_t ub2: 2;
20 uint32_t ub7: 7;
21 /* signed bitfields */
22 int8_t sb4: 4;
23 int32_t sb20: 20;
24 /* non-bitfields */
25 uint32_t u32;
26 int32_t s32;
27 };
28
29 /* bitfield read results, all as plain integers */
30 struct core_reloc_bitfields_output {
31 int64_t ub1;
32 int64_t ub2;
33 int64_t ub7;
34 int64_t sb4;
35 int64_t sb20;
36 int64_t u32;
37 int64_t s32;
38 };
39
40 struct pt_regs;
41
42 struct trace_sys_enter {
43 struct pt_regs *regs;
44 long id;
45 };
46
47 SEC("tp_btf/sys_enter")
48 int test_core_bitfields_direct(void *ctx)
49 {
50 struct core_reloc_bitfields *in = (void *)&data.in;
51 struct core_reloc_bitfields_output *out = (void *)&data.out;
52
53 out->ub1 = BPF_CORE_READ_BITFIELD(in, ub1);
54 out->ub2 = BPF_CORE_READ_BITFIELD(in, ub2);
55 out->ub7 = BPF_CORE_READ_BITFIELD(in, ub7);
56 out->sb4 = BPF_CORE_READ_BITFIELD(in, sb4);
57 out->sb20 = BPF_CORE_READ_BITFIELD(in, sb20);
58 out->u32 = BPF_CORE_READ_BITFIELD(in, u32);
59 out->s32 = BPF_CORE_READ_BITFIELD(in, s32);
60
61 return 0;
62 }
63