tools/testing/selftests/bpf/progs/test_core_reloc_type_id.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/progs/test_core_reloc_type_id.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/progs/test_core_reloc_type_id.c- Extension
.c- Size
- 3334 bytes
- Lines
- 116
- 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.hstdbool.hbpf/bpf_helpers.hbpf/bpf_core_read.h
Detected Declarations
struct a_structstruct core_reloc_type_id_outputenum an_enumfunction test_core_type_id
Annotated Snippet
struct a_struct {
int x;
};
union a_union {
int y;
int z;
};
enum an_enum {
AN_ENUM_VAL1 = 1,
AN_ENUM_VAL2 = 2,
AN_ENUM_VAL3 = 3,
};
typedef struct a_struct named_struct_typedef;
typedef int (*func_proto_typedef)(long);
typedef char arr_typedef[20];
struct core_reloc_type_id_output {
int local_anon_struct;
int local_anon_union;
int local_anon_enum;
int local_anon_func_proto_ptr;
int local_anon_void_ptr;
int local_anon_arr;
int local_struct;
int local_union;
int local_enum;
int local_int;
int local_struct_typedef;
int local_func_proto_typedef;
int local_arr_typedef;
int targ_struct;
int targ_union;
int targ_enum;
int targ_int;
int targ_struct_typedef;
int targ_func_proto_typedef;
int targ_arr_typedef;
};
/* preserve types even if Clang doesn't support built-in */
struct a_struct t1 = {};
union a_union t2 = {};
enum an_enum t3 = 0;
named_struct_typedef t4 = {};
func_proto_typedef t5 = 0;
arr_typedef t6 = {};
SEC("raw_tracepoint/sys_enter")
int test_core_type_id(void *ctx)
{
/* We use __builtin_btf_type_id() in this tests, but up until the time
* __builtin_preserve_type_info() was added it contained a bug that
* would make this test fail. The bug was fixed ([0]) with addition of
* __builtin_preserve_type_info(), though, so that's what we are using
* to detect whether this test has to be executed, however strange
* that might look like.
*
* [0] https://github.com/llvm/llvm-project/commit/00602ee7ef0bf6c68d690a2bd729c12b95c95c99
*/
#if __has_builtin(__builtin_preserve_type_info)
struct core_reloc_type_id_output *out = (void *)&data.out;
out->local_anon_struct = bpf_core_type_id_local(struct { int marker_field; });
out->local_anon_union = bpf_core_type_id_local(union { int marker_field; });
out->local_anon_enum = bpf_core_type_id_local(enum { MARKER_ENUM_VAL = 123 });
out->local_anon_func_proto_ptr = bpf_core_type_id_local(_Bool(*)(int));
out->local_anon_void_ptr = bpf_core_type_id_local(void *);
out->local_anon_arr = bpf_core_type_id_local(_Bool[47]);
out->local_struct = bpf_core_type_id_local(struct a_struct);
out->local_union = bpf_core_type_id_local(union a_union);
out->local_enum = bpf_core_type_id_local(enum an_enum);
out->local_int = bpf_core_type_id_local(int);
out->local_struct_typedef = bpf_core_type_id_local(named_struct_typedef);
out->local_func_proto_typedef = bpf_core_type_id_local(func_proto_typedef);
out->local_arr_typedef = bpf_core_type_id_local(arr_typedef);
out->targ_struct = bpf_core_type_id_kernel(struct a_struct);
out->targ_union = bpf_core_type_id_kernel(union a_union);
out->targ_enum = bpf_core_type_id_kernel(enum an_enum);
out->targ_int = bpf_core_type_id_kernel(int);
out->targ_struct_typedef = bpf_core_type_id_kernel(named_struct_typedef);
out->targ_func_proto_typedef = bpf_core_type_id_kernel(func_proto_typedef);
Annotation
- Immediate include surface: `linux/bpf.h`, `stdint.h`, `stdbool.h`, `bpf/bpf_helpers.h`, `bpf/bpf_core_read.h`.
- Detected declarations: `struct a_struct`, `struct core_reloc_type_id_output`, `enum an_enum`, `function test_core_type_id`.
- 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.