tools/testing/selftests/bpf/progs/find_vma.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/progs/find_vma.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/progs/find_vma.c- Extension
.c- Size
- 1535 bytes
- Lines
- 70
- 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_tracing.h
Detected Declarations
struct callback_ctxfunction check_vmafunction handle_getpidfunction handle_pe
Annotated Snippet
struct callback_ctx {
int dummy;
};
#define VM_EXEC 0x00000004
#define DNAME_INLINE_LEN 32
pid_t target_pid = 0;
char d_iname[DNAME_INLINE_LEN] = {0};
__u32 found_vm_exec = 0;
__u64 addr = 0;
int find_zero_ret = -1;
int find_addr_ret = -1;
static long check_vma(struct task_struct *task, struct vm_area_struct *vma,
struct callback_ctx *data)
{
if (vma->vm_file)
bpf_probe_read_kernel_str(d_iname, DNAME_INLINE_LEN - 1,
vma->vm_file->f_path.dentry->d_shortname.string);
/* check for VM_EXEC */
if (vma->vm_flags & VM_EXEC)
found_vm_exec = 1;
return 0;
}
SEC("raw_tp/sys_enter")
int handle_getpid(void)
{
struct task_struct *task = bpf_get_current_task_btf();
struct callback_ctx data = {};
if (task->pid != target_pid)
return 0;
find_addr_ret = bpf_find_vma(task, addr, check_vma, &data, 0);
/* this should return -ENOENT */
find_zero_ret = bpf_find_vma(task, 0, check_vma, &data, 0);
return 0;
}
SEC("perf_event")
int handle_pe(void)
{
struct task_struct *task = bpf_get_current_task_btf();
struct callback_ctx data = {};
if (task->pid != target_pid)
return 0;
find_addr_ret = bpf_find_vma(task, addr, check_vma, &data, 0);
/* In NMI, this should return -EBUSY, as the previous call is using
* the irq_work.
*/
find_zero_ret = bpf_find_vma(task, 0, check_vma, &data, 0);
return 0;
}
Annotation
- Immediate include surface: `vmlinux.h`, `bpf/bpf_helpers.h`, `bpf/bpf_tracing.h`.
- Detected declarations: `struct callback_ctx`, `function check_vma`, `function handle_getpid`, `function handle_pe`.
- 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.