tools/testing/selftests/bpf/progs/verifier_bitfield_write.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/progs/verifier_bitfield_write.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/progs/verifier_bitfield_write.c- Extension
.c- Size
- 2426 bytes
- Lines
- 101
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: implementation source
- Status
- source implementation candidate
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/bpf.hstdint.hbpf/bpf_helpers.hbpf/bpf_core_read.hbpf_misc.h
Detected Declarations
struct core_reloc_bitfieldsfunction __retvalfunction __retvalfunction __retvalfunction __retval
Annotated Snippet
struct core_reloc_bitfields {
/* unsigned bitfields */
uint8_t ub1: 1;
uint8_t ub2: 2;
uint32_t ub7: 7;
/* signed bitfields */
int8_t sb4: 4;
int32_t sb20: 20;
/* non-bitfields */
uint32_t u32;
int32_t s32;
} __attribute__((preserve_access_index));
SEC("tc")
__description("single CO-RE bitfield roundtrip")
__btf_path("btf__core_reloc_bitfields.bpf.o")
__success
__retval(3)
int single_field_roundtrip(struct __sk_buff *ctx)
{
struct core_reloc_bitfields bitfields;
__builtin_memset(&bitfields, 0, sizeof(bitfields));
BPF_CORE_WRITE_BITFIELD(&bitfields, ub2, 3);
return BPF_CORE_READ_BITFIELD(&bitfields, ub2);
}
SEC("tc")
__description("multiple CO-RE bitfield roundtrip")
__btf_path("btf__core_reloc_bitfields.bpf.o")
__success
__retval(0x3FD)
int multiple_field_roundtrip(struct __sk_buff *ctx)
{
struct core_reloc_bitfields bitfields;
uint8_t ub2;
int8_t sb4;
__builtin_memset(&bitfields, 0, sizeof(bitfields));
BPF_CORE_WRITE_BITFIELD(&bitfields, ub2, 1);
BPF_CORE_WRITE_BITFIELD(&bitfields, sb4, -1);
ub2 = BPF_CORE_READ_BITFIELD(&bitfields, ub2);
sb4 = BPF_CORE_READ_BITFIELD(&bitfields, sb4);
return (((uint8_t)sb4) << 2) | ub2;
}
SEC("tc")
__description("adjacent CO-RE bitfield roundtrip")
__btf_path("btf__core_reloc_bitfields.bpf.o")
__success
__retval(7)
int adjacent_field_roundtrip(struct __sk_buff *ctx)
{
struct core_reloc_bitfields bitfields;
uint8_t ub1, ub2;
__builtin_memset(&bitfields, 0, sizeof(bitfields));
BPF_CORE_WRITE_BITFIELD(&bitfields, ub1, 1);
BPF_CORE_WRITE_BITFIELD(&bitfields, ub2, 3);
ub1 = BPF_CORE_READ_BITFIELD(&bitfields, ub1);
ub2 = BPF_CORE_READ_BITFIELD(&bitfields, ub2);
return (ub2 << 1) | ub1;
}
SEC("tc")
__description("multibyte CO-RE bitfield roundtrip")
__btf_path("btf__core_reloc_bitfields.bpf.o")
__success
__retval(0x21)
int multibyte_field_roundtrip(struct __sk_buff *ctx)
{
struct core_reloc_bitfields bitfields;
uint32_t ub7;
uint8_t ub1;
__builtin_memset(&bitfields, 0, sizeof(bitfields));
BPF_CORE_WRITE_BITFIELD(&bitfields, ub1, 1);
BPF_CORE_WRITE_BITFIELD(&bitfields, ub7, 16);
ub1 = BPF_CORE_READ_BITFIELD(&bitfields, ub1);
ub7 = BPF_CORE_READ_BITFIELD(&bitfields, ub7);
return (ub7 << 1) | ub1;
}
char _license[] SEC("license") = "GPL";
Annotation
- Immediate include surface: `linux/bpf.h`, `stdint.h`, `bpf/bpf_helpers.h`, `bpf/bpf_core_read.h`, `bpf_misc.h`.
- Detected declarations: `struct core_reloc_bitfields`, `function __retval`, `function __retval`, `function __retval`, `function __retval`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.