tools/testing/selftests/bpf/progs/test_bpf_cookie.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/progs/test_bpf_cookie.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/progs/test_bpf_cookie.c- Extension
.c- Size
- 2507 bytes
- Lines
- 138
- 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.herrno.h
Detected Declarations
function updatefunction handle_kprobefunction handle_kretprobefunction handle_uprobefunction handle_uretprobefunction hookfunction handle_tp2function handle_tp3function handle_pefunction handle_raw_tpfunction handle_tp_btffunction BPF_PROGfunction BPF_PROGfunction BPF_PROGfunction BPF_PROG
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
/* Copyright (c) 2021 Facebook */
#include "vmlinux.h"
#include <bpf/bpf_helpers.h>
#include <bpf/bpf_tracing.h>
#include <errno.h>
int my_tid;
__u64 kprobe_res;
__u64 kprobe_multi_res;
__u64 kretprobe_res;
__u64 uprobe_res;
__u64 uretprobe_res;
__u64 tp_res;
__u64 pe_res;
__u64 raw_tp_res;
__u64 tp_btf_res;
__u64 fentry_res;
__u64 fexit_res;
__u64 fmod_ret_res;
__u64 lsm_res;
static void update(void *ctx, __u64 *res)
{
if (my_tid != (u32)bpf_get_current_pid_tgid())
return;
*res |= bpf_get_attach_cookie(ctx);
}
SEC("kprobe")
int handle_kprobe(struct pt_regs *ctx)
{
update(ctx, &kprobe_res);
return 0;
}
SEC("kretprobe")
int handle_kretprobe(struct pt_regs *ctx)
{
update(ctx, &kretprobe_res);
return 0;
}
SEC("uprobe")
int handle_uprobe(struct pt_regs *ctx)
{
update(ctx, &uprobe_res);
return 0;
}
SEC("uretprobe")
int handle_uretprobe(struct pt_regs *ctx)
{
update(ctx, &uretprobe_res);
return 0;
}
/* bpf_prog_array, used by kernel internally to keep track of attached BPF
* programs to a given BPF hook (e.g., for tracepoints) doesn't allow the same
* BPF program to be attached multiple times. So have three identical copies
* ready to attach to the same tracepoint.
*/
SEC("tp/syscalls/sys_enter_nanosleep")
int handle_tp1(struct pt_regs *ctx)
{
update(ctx, &tp_res);
return 0;
}
SEC("tp/syscalls/sys_enter_nanosleep")
int handle_tp2(struct pt_regs *ctx)
{
update(ctx, &tp_res);
return 0;
}
SEC("tp/syscalls/sys_enter_nanosleep")
int handle_tp3(void *ctx)
{
update(ctx, &tp_res);
return 1;
}
SEC("perf_event")
int handle_pe(struct pt_regs *ctx)
{
update(ctx, &pe_res);
return 0;
}
Annotation
- Immediate include surface: `vmlinux.h`, `bpf/bpf_helpers.h`, `bpf/bpf_tracing.h`, `errno.h`.
- Detected declarations: `function update`, `function handle_kprobe`, `function handle_kretprobe`, `function handle_uprobe`, `function handle_uretprobe`, `function hook`, `function handle_tp2`, `function handle_tp3`, `function handle_pe`, `function handle_raw_tp`.
- 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.