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/bpf_helpers.h> |
7 | #include <bpf/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 | SEC("raw_tracepoint/sys_enter") |
41 | int test_core_bitfields(void *ctx) |
42 | { |
43 | struct core_reloc_bitfields *in = (void *)&data.in; |
44 | struct core_reloc_bitfields_output *out = (void *)&data.out; |
45 | |
46 | out->ub1 = BPF_CORE_READ_BITFIELD_PROBED(in, ub1); |
47 | out->ub2 = BPF_CORE_READ_BITFIELD_PROBED(in, ub2); |
48 | out->ub7 = BPF_CORE_READ_BITFIELD_PROBED(in, ub7); |
49 | out->sb4 = BPF_CORE_READ_BITFIELD_PROBED(in, sb4); |
50 | out->sb20 = BPF_CORE_READ_BITFIELD_PROBED(in, sb20); |
51 | out->u32 = BPF_CORE_READ_BITFIELD_PROBED(in, u32); |
52 | out->s32 = BPF_CORE_READ_BITFIELD_PROBED(in, s32); |
53 | |
54 | return 0; |
55 | } |
56 | |
57 |