tools/testing/selftests/bpf/progs/uprobe_multi.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/progs/uprobe_multi.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/progs/uprobe_multi.c- Extension
.c- Size
- 3353 bytes
- Lines
- 144
- 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.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
vmlinux.hbpf/bpf_helpers.hbpf/bpf_tracing.hbpf/usdt.bpf.h
Detected Declarations
function verify_sleepable_user_copyfunction uprobe_multi_checkfunction uprobefunction uretprobefunction uprobe_sleepfunction uretprobe_sleepfunction uprobe_extrafunction usdt_pidfunction usdt_extra
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
#include "vmlinux.h"
#include <bpf/bpf_helpers.h>
#include <bpf/bpf_tracing.h>
#include <bpf/usdt.bpf.h>
char _license[] SEC("license") = "GPL";
__u64 uprobe_multi_func_1_addr = 0;
__u64 uprobe_multi_func_2_addr = 0;
__u64 uprobe_multi_func_3_addr = 0;
__u64 uprobe_multi_func_1_result = 0;
__u64 uprobe_multi_func_2_result = 0;
__u64 uprobe_multi_func_3_result = 0;
__u64 uretprobe_multi_func_1_result = 0;
__u64 uretprobe_multi_func_2_result = 0;
__u64 uretprobe_multi_func_3_result = 0;
__u64 uprobe_multi_sleep_result = 0;
int pid = 0;
int child_pid = 0;
int child_tid = 0;
int child_pid_usdt = 0;
int child_tid_usdt = 0;
int expect_pid = 0;
bool bad_pid_seen = false;
bool bad_pid_seen_usdt = false;
bool test_cookie = false;
void *user_ptr = 0;
static __always_inline bool verify_sleepable_user_copy(void)
{
char data[9];
bpf_copy_from_user(data, sizeof(data), user_ptr);
return bpf_strncmp(data, sizeof(data), "test_data") == 0;
}
static void uprobe_multi_check(void *ctx, bool is_return, bool is_sleep)
{
__u64 cur_pid_tgid = bpf_get_current_pid_tgid();
__u32 cur_pid;
cur_pid = cur_pid_tgid >> 32;
if (pid && cur_pid != pid)
return;
if (expect_pid && cur_pid != expect_pid)
bad_pid_seen = true;
child_pid = cur_pid_tgid >> 32;
child_tid = (__u32)cur_pid_tgid;
__u64 cookie = test_cookie ? bpf_get_attach_cookie(ctx) : 0;
__u64 addr = bpf_get_func_ip(ctx);
#define SET(__var, __addr, __cookie) ({ \
if (addr == __addr && \
(!test_cookie || (cookie == __cookie))) \
__var += 1; \
})
if (is_return) {
SET(uretprobe_multi_func_1_result, uprobe_multi_func_1_addr, 2);
SET(uretprobe_multi_func_2_result, uprobe_multi_func_2_addr, 3);
SET(uretprobe_multi_func_3_result, uprobe_multi_func_3_addr, 1);
} else {
SET(uprobe_multi_func_1_result, uprobe_multi_func_1_addr, 3);
SET(uprobe_multi_func_2_result, uprobe_multi_func_2_addr, 1);
SET(uprobe_multi_func_3_result, uprobe_multi_func_3_addr, 2);
}
#undef SET
if (is_sleep && verify_sleepable_user_copy())
uprobe_multi_sleep_result += 1;
}
SEC("uprobe.multi//proc/self/exe:uprobe_multi_func_*")
int uprobe(struct pt_regs *ctx)
{
uprobe_multi_check(ctx, false, false);
return 0;
}
Annotation
- Immediate include surface: `vmlinux.h`, `bpf/bpf_helpers.h`, `bpf/bpf_tracing.h`, `bpf/usdt.bpf.h`.
- Detected declarations: `function verify_sleepable_user_copy`, `function uprobe_multi_check`, `function uprobe`, `function uretprobe`, `function uprobe_sleep`, `function uretprobe_sleep`, `function uprobe_extra`, `function usdt_pid`, `function usdt_extra`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
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.