tools/testing/selftests/bpf/prog_tests/attach_probe.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/prog_tests/attach_probe.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/prog_tests/attach_probe.c- Extension
.c- Size
- 22278 bytes
- Lines
- 655
- 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
test_progs.htest_attach_kprobe_sleepable.skel.htest_attach_probe_manual.skel.htest_attach_probe.skel.hkprobe_write_ctx.skel.h
Detected Declarations
function trigger_funcfunction trigger_func2function trigger_func3function trigger_func4function test_attach_probe_manualfunction test_attach_kprobe_by_addrfunction test_attach_kprobe_legacy_by_addr_rejectfunction vmlinuxfunction test_attach_uprobe_long_event_namefunction test_attach_kprobe_long_event_namefunction test_attach_kprobe_write_ctxfunction test_freplace_kprobe_write_ctxfunction test_attach_kprobe_write_ctxfunction test_freplace_kprobe_write_ctxfunction test_attach_probe_autofunction test_uprobe_libfunction test_uprobe_ref_ctrfunction test_kprobe_sleepablefunction test_uprobe_sleepablefunction test_attach_probe
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
#include <test_progs.h>
#include "test_attach_kprobe_sleepable.skel.h"
#include "test_attach_probe_manual.skel.h"
#include "test_attach_probe.skel.h"
#include "kprobe_write_ctx.skel.h"
/* this is how USDT semaphore is actually defined, except volatile modifier */
volatile unsigned short uprobe_ref_ctr __attribute__((unused)) __attribute((section(".probes")));
/* uprobe attach point */
static noinline void trigger_func(void)
{
asm volatile ("");
}
/* attach point for byname uprobe */
static noinline void trigger_func2(void)
{
asm volatile ("");
}
/* attach point for byname sleepable uprobe */
static noinline void trigger_func3(void)
{
asm volatile ("");
}
/* attach point for ref_ctr */
static noinline void trigger_func4(void)
{
asm volatile ("");
}
static char test_data[] = "test_data";
/* manual attach kprobe/kretprobe/uprobe/uretprobe testings */
static void test_attach_probe_manual(enum probe_attach_mode attach_mode)
{
DECLARE_LIBBPF_OPTS(bpf_uprobe_opts, uprobe_opts);
DECLARE_LIBBPF_OPTS(bpf_kprobe_opts, kprobe_opts);
struct bpf_link *kprobe_link, *kretprobe_link;
struct bpf_link *uprobe_link, *uretprobe_link;
struct test_attach_probe_manual *skel;
ssize_t uprobe_offset;
skel = test_attach_probe_manual__open_and_load();
if (!ASSERT_OK_PTR(skel, "skel_kprobe_manual_open_and_load"))
return;
uprobe_offset = get_uprobe_offset(&trigger_func);
if (!ASSERT_GE(uprobe_offset, 0, "uprobe_offset"))
goto cleanup;
/* manual-attach kprobe/kretprobe */
kprobe_opts.attach_mode = attach_mode;
kprobe_opts.retprobe = false;
kprobe_link = bpf_program__attach_kprobe_opts(skel->progs.handle_kprobe,
SYS_NANOSLEEP_KPROBE_NAME,
&kprobe_opts);
if (!ASSERT_OK_PTR(kprobe_link, "attach_kprobe"))
goto cleanup;
skel->links.handle_kprobe = kprobe_link;
kprobe_opts.retprobe = true;
kretprobe_link = bpf_program__attach_kprobe_opts(skel->progs.handle_kretprobe,
SYS_NANOSLEEP_KPROBE_NAME,
&kprobe_opts);
if (!ASSERT_OK_PTR(kretprobe_link, "attach_kretprobe"))
goto cleanup;
skel->links.handle_kretprobe = kretprobe_link;
/* manual-attach uprobe/uretprobe */
uprobe_opts.attach_mode = attach_mode;
uprobe_opts.ref_ctr_offset = 0;
uprobe_opts.retprobe = false;
uprobe_link = bpf_program__attach_uprobe_opts(skel->progs.handle_uprobe,
0 /* self pid */,
"/proc/self/exe",
uprobe_offset,
&uprobe_opts);
if (!ASSERT_OK_PTR(uprobe_link, "attach_uprobe"))
goto cleanup;
skel->links.handle_uprobe = uprobe_link;
uprobe_opts.retprobe = true;
uretprobe_link = bpf_program__attach_uprobe_opts(skel->progs.handle_uretprobe,
-1 /* any pid */,
"/proc/self/exe",
uprobe_offset, &uprobe_opts);
Annotation
- Immediate include surface: `test_progs.h`, `test_attach_kprobe_sleepable.skel.h`, `test_attach_probe_manual.skel.h`, `test_attach_probe.skel.h`, `kprobe_write_ctx.skel.h`.
- Detected declarations: `function trigger_func`, `function trigger_func2`, `function trigger_func3`, `function trigger_func4`, `function test_attach_probe_manual`, `function test_attach_kprobe_by_addr`, `function test_attach_kprobe_legacy_by_addr_reject`, `function vmlinux`, `function test_attach_uprobe_long_event_name`, `function test_attach_kprobe_long_event_name`.
- 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.