tools/testing/selftests/bpf/prog_tests/fill_link_info.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/prog_tests/fill_link_info.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/prog_tests/fill_link_info.c- Extension
.c- Size
- 19666 bytes
- Lines
- 653
- 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
string.hlinux/bpf.hlinux/limits.htest_progs.htrace_helpers.htest_fill_link_info.skel.hbpf/libbpf_internal.h
Detected Declarations
function uprobe_funcfunction verify_perf_link_infofunction kprobe_fill_invalid_user_bufferfunction test_kprobe_fill_link_infofunction test_tp_fill_link_infofunction test_event_fill_link_infofunction test_uprobe_fill_link_infofunction verify_kmulti_link_infofunction verify_kmulti_invalid_user_bufferfunction symbols_cmp_rfunction test_kprobe_multi_fill_link_infofunction uprobe_link_info_func_1function uprobe_link_info_func_2function uprobe_link_info_func_3function verify_umulti_link_infofunction verify_umulti_invalid_user_bufferfunction test_uprobe_multi_fill_link_infofunction test_fill_link_info
Annotated Snippet
if (!info.perf_event.kprobe.func_name) {
info.perf_event.kprobe.func_name = ptr_to_u64(&buf);
info.perf_event.kprobe.name_len = sizeof(buf);
goto again;
}
err = strncmp(u64_to_ptr(info.perf_event.kprobe.func_name), KPROBE_FUNC,
strlen(KPROBE_FUNC));
ASSERT_EQ(err, 0, "cmp_kprobe_func_name");
break;
case BPF_PERF_EVENT_TRACEPOINT:
ASSERT_EQ(info.perf_event.tracepoint.name_len, strlen(TP_NAME) + 1,
"name_len");
if (!info.perf_event.tracepoint.tp_name) {
info.perf_event.tracepoint.tp_name = ptr_to_u64(&buf);
info.perf_event.tracepoint.name_len = sizeof(buf);
goto again;
}
ASSERT_EQ(info.perf_event.tracepoint.cookie, PERF_EVENT_COOKIE, "tracepoint_cookie");
err = strncmp(u64_to_ptr(info.perf_event.tracepoint.tp_name), TP_NAME,
strlen(TP_NAME));
ASSERT_EQ(err, 0, "cmp_tp_name");
break;
case BPF_PERF_EVENT_UPROBE:
case BPF_PERF_EVENT_URETPROBE:
ASSERT_EQ(info.perf_event.uprobe.offset, offset, "uprobe_offset");
ASSERT_EQ(info.perf_event.uprobe.ref_ctr_offset, ref_ctr_offset, "uprobe_ref_ctr_offset");
ASSERT_EQ(info.perf_event.uprobe.name_len, strlen(UPROBE_FILE) + 1,
"name_len");
if (!info.perf_event.uprobe.file_name) {
info.perf_event.uprobe.file_name = ptr_to_u64(&buf);
info.perf_event.uprobe.name_len = sizeof(buf);
goto again;
}
ASSERT_EQ(info.perf_event.uprobe.cookie, PERF_EVENT_COOKIE, "uprobe_cookie");
err = strncmp(u64_to_ptr(info.perf_event.uprobe.file_name), UPROBE_FILE,
strlen(UPROBE_FILE));
ASSERT_EQ(err, 0, "cmp_file_name");
break;
case BPF_PERF_EVENT_EVENT:
ASSERT_EQ(info.perf_event.event.type, PERF_TYPE_SOFTWARE, "event_type");
ASSERT_EQ(info.perf_event.event.config, PERF_COUNT_SW_PAGE_FAULTS, "event_config");
ASSERT_EQ(info.perf_event.event.cookie, PERF_EVENT_COOKIE, "event_cookie");
break;
default:
err = -1;
break;
}
return err;
}
static void kprobe_fill_invalid_user_buffer(int fd)
{
struct bpf_link_info info;
__u32 len = sizeof(info);
int err;
memset(&info, 0, sizeof(info));
info.perf_event.kprobe.func_name = 0x1; /* invalid address */
err = bpf_link_get_info_by_fd(fd, &info, &len);
ASSERT_EQ(err, -EINVAL, "invalid_buff_and_len");
info.perf_event.kprobe.name_len = 64;
err = bpf_link_get_info_by_fd(fd, &info, &len);
ASSERT_EQ(err, -EFAULT, "invalid_buff");
info.perf_event.kprobe.func_name = 0;
err = bpf_link_get_info_by_fd(fd, &info, &len);
ASSERT_EQ(err, -EINVAL, "invalid_len");
ASSERT_EQ(info.perf_event.kprobe.addr, 0, "func_addr");
ASSERT_EQ(info.perf_event.kprobe.offset, 0, "func_offset");
ASSERT_EQ(info.perf_event.type, 0, "type");
}
static void test_kprobe_fill_link_info(struct test_fill_link_info *skel,
enum bpf_perf_event_type type,
bool invalid)
{
DECLARE_LIBBPF_OPTS(bpf_kprobe_opts, opts,
.attach_mode = PROBE_ATTACH_MODE_LINK,
.retprobe = type == BPF_PERF_EVENT_KRETPROBE,
.bpf_cookie = PERF_EVENT_COOKIE,
);
Annotation
- Immediate include surface: `string.h`, `linux/bpf.h`, `linux/limits.h`, `test_progs.h`, `trace_helpers.h`, `test_fill_link_info.skel.h`, `bpf/libbpf_internal.h`.
- Detected declarations: `function uprobe_func`, `function verify_perf_link_info`, `function kprobe_fill_invalid_user_buffer`, `function test_kprobe_fill_link_info`, `function test_tp_fill_link_info`, `function test_event_fill_link_info`, `function test_uprobe_fill_link_info`, `function verify_kmulti_link_info`, `function verify_kmulti_invalid_user_buffer`, `function symbols_cmp_r`.
- 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.