kernel/trace/trace_btf.c
Source file repositories/reference/linux-study-clean/kernel/trace/trace_btf.c
File Facts
- System
- Linux kernel
- Corpus path
kernel/trace/trace_btf.c- Extension
.c- Size
- 3036 bytes
- Lines
- 123
- Domain
- Core OS
- Bucket
- Scheduler, Processes, Timers, Sync, And Syscalls
- Inferred role
- Core OS: implementation source
- Status
- source implementation candidate
Why This File Exists
Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/btf.hlinux/kernel.hlinux/slab.htrace_btf.h
Detected Declarations
struct btf_anon_stackfunction btf_putfunction for_each_member
Annotated Snippet
struct btf_anon_stack {
u32 tid;
u32 offset;
};
/*
* Find a member of data structure/union by name and return it.
* Return NULL if not found, or -EINVAL if parameter is invalid.
* If the member is an member of anonymous union/structure, the offset
* of that anonymous union/structure is stored into @anon_offset. Caller
* can calculate the correct offset from the root data structure by
* adding anon_offset to the member's offset.
*/
const struct btf_member *btf_find_struct_member(struct btf *btf,
const struct btf_type *type,
const char *member_name,
u32 *anon_offset)
{
struct btf_anon_stack *anon_stack;
const struct btf_member *member;
u32 tid, cur_offset = 0;
const char *name;
int i, top = 0;
anon_stack = kzalloc_objs(*anon_stack, BTF_ANON_STACK_MAX);
if (!anon_stack)
return ERR_PTR(-ENOMEM);
retry:
if (!btf_type_is_struct(type)) {
member = ERR_PTR(-EINVAL);
goto out;
}
for_each_member(i, type, member) {
if (!member->name_off) {
/* Anonymous union/struct: push it for later use */
if (btf_type_skip_modifiers(btf, member->type, &tid) &&
top < BTF_ANON_STACK_MAX) {
anon_stack[top].tid = tid;
anon_stack[top++].offset =
cur_offset + member->offset;
}
} else {
name = btf_name_by_offset(btf, member->name_off);
if (name && !strcmp(member_name, name)) {
if (anon_offset)
*anon_offset = cur_offset;
goto out;
}
}
}
if (top > 0) {
/* Pop from the anonymous stack and retry */
tid = anon_stack[--top].tid;
cur_offset = anon_stack[top].offset;
type = btf_type_by_id(btf, tid);
goto retry;
}
member = NULL;
out:
kfree(anon_stack);
return member;
}
Annotation
- Immediate include surface: `linux/btf.h`, `linux/kernel.h`, `linux/slab.h`, `trace_btf.h`.
- Detected declarations: `struct btf_anon_stack`, `function btf_put`, `function for_each_member`.
- Atlas domain: Core OS / Scheduler, Processes, Timers, Sync, And Syscalls.
- 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.