tools/testing/selftests/bpf/progs/test_core_reloc_module.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/progs/test_core_reloc_module.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/progs/test_core_reloc_module.c- Extension
.c- Size
- 2789 bytes
- Lines
- 105
- 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
vmlinux.hbpf/bpf_helpers.hbpf/bpf_core_read.hbpf/bpf_tracing.h
Detected Declarations
struct bpf_testmod_test_read_ctxstruct core_reloc_module_outputfunction BPF_PROGfunction BPF_PROG
Annotated Snippet
struct bpf_testmod_test_read_ctx {
/* field order is mixed up */
size_t len;
char *buf;
loff_t off;
} __attribute__((preserve_access_index));
struct {
char in[256];
char out[256];
bool skip;
uint64_t my_pid_tgid;
} data = {};
struct core_reloc_module_output {
long long len;
long long off;
int read_ctx_sz;
bool read_ctx_exists;
bool buf_exists;
bool len_exists;
bool off_exists;
/* we have test_progs[-flavor], so cut flavor part */
char comm[sizeof("test_progs")];
int comm_len;
};
SEC("raw_tp/bpf_testmod_test_read")
int BPF_PROG(test_core_module_probed,
struct task_struct *task,
struct bpf_testmod_test_read_ctx *read_ctx)
{
#if __has_builtin(__builtin_preserve_enum_value)
struct core_reloc_module_output *out = (void *)&data.out;
__u64 pid_tgid = bpf_get_current_pid_tgid();
__s32 real_tgid = (__s32)(pid_tgid >> 32);
__s32 real_pid = (__s32)pid_tgid;
if (data.my_pid_tgid != pid_tgid)
return 0;
if (BPF_CORE_READ(task, pid) != real_pid || BPF_CORE_READ(task, tgid) != real_tgid)
return 0;
out->len = BPF_CORE_READ(read_ctx, len);
out->off = BPF_CORE_READ(read_ctx, off);
out->read_ctx_sz = bpf_core_type_size(struct bpf_testmod_test_read_ctx);
out->read_ctx_exists = bpf_core_type_exists(struct bpf_testmod_test_read_ctx);
out->buf_exists = bpf_core_field_exists(read_ctx->buf);
out->off_exists = bpf_core_field_exists(read_ctx->off);
out->len_exists = bpf_core_field_exists(read_ctx->len);
out->comm_len = BPF_CORE_READ_STR_INTO(&out->comm, task, comm);
#else
data.skip = true;
#endif
return 0;
}
SEC("tp_btf/bpf_testmod_test_read")
int BPF_PROG(test_core_module_direct,
struct task_struct *task,
struct bpf_testmod_test_read_ctx *read_ctx)
{
#if __has_builtin(__builtin_preserve_enum_value)
struct core_reloc_module_output *out = (void *)&data.out;
__u64 pid_tgid = bpf_get_current_pid_tgid();
__s32 real_tgid = (__s32)(pid_tgid >> 32);
__s32 real_pid = (__s32)pid_tgid;
if (data.my_pid_tgid != pid_tgid)
return 0;
if (task->pid != real_pid || task->tgid != real_tgid)
return 0;
out->len = read_ctx->len;
out->off = read_ctx->off;
out->read_ctx_sz = bpf_core_type_size(struct bpf_testmod_test_read_ctx);
out->read_ctx_exists = bpf_core_type_exists(struct bpf_testmod_test_read_ctx);
out->buf_exists = bpf_core_field_exists(read_ctx->buf);
out->off_exists = bpf_core_field_exists(read_ctx->off);
out->len_exists = bpf_core_field_exists(read_ctx->len);
out->comm_len = BPF_CORE_READ_STR_INTO(&out->comm, task, comm);
#else
data.skip = true;
Annotation
- Immediate include surface: `vmlinux.h`, `bpf/bpf_helpers.h`, `bpf/bpf_core_read.h`, `bpf/bpf_tracing.h`.
- Detected declarations: `struct bpf_testmod_test_read_ctx`, `struct core_reloc_module_output`, `function BPF_PROG`, `function BPF_PROG`.
- 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.