tools/testing/selftests/bpf/trace_helpers.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/trace_helpers.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/trace_helpers.c- Extension
.c- Size
- 16878 bytes
- Lines
- 758
- 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
ctype.hstdio.hstdlib.hstring.hassert.herrno.hfcntl.hpoll.hpthread.hunistd.hlinux/perf_event.hlinux/fs.hsys/ioctl.hsys/mman.htrace_helpers.hlinux/limits.hlibelf.hgelf.hbpf/hashmap.hbpf/libbpf_internal.hbpf_util.h
Detected Declarations
function ksyms__add_symbolfunction free_kallsyms_localfunction ksym_cmpfunction load_kallsymsfunction ksym_get_addr_localfunction ksym_get_addrfunction kallsyms_findfunction procmap_queryfunction procmap_queryfunction get_uprobe_offsetfunction get_rel_offsetfunction parse_build_id_buffunction read_build_idfunction read_trace_pipe_iterfunction trace_pipe_cbfunction read_trace_pipefunction symbol_hashfunction symbol_equalfunction is_invalid_entryfunction is_unsafe_functionfunction compare_namefunction load_kallsyms_comparefunction search_kallsyms_comparefunction bpf_get_ksymsfunction bpf_get_addrs
Annotated Snippet
if (type == 'd') {
match = strstr(name, ".llvm.");
if (match)
*match = '\0';
}
if (strcmp(name, sym) == 0) {
*addr = value;
goto out;
}
}
err = -ENOENT;
out:
fclose(f);
return err;
}
#ifdef PROCMAP_QUERY
int env_verbosity __weak = 0;
static int procmap_query(int fd, const void *addr, __u32 query_flags, size_t *start, size_t *offset, int *flags)
{
char path_buf[PATH_MAX], build_id_buf[20];
struct procmap_query q;
int err;
memset(&q, 0, sizeof(q));
q.size = sizeof(q);
q.query_flags = query_flags;
q.query_addr = (__u64)addr;
q.vma_name_addr = (__u64)path_buf;
q.vma_name_size = sizeof(path_buf);
q.build_id_addr = (__u64)build_id_buf;
q.build_id_size = sizeof(build_id_buf);
err = ioctl(fd, PROCMAP_QUERY, &q);
if (err < 0) {
err = -errno;
if (err == -ENOTTY)
return -EOPNOTSUPP; /* ioctl() not implemented yet */
if (err == -ENOENT)
return -ESRCH; /* vma not found */
return err;
}
if (env_verbosity >= 1) {
printf("VMA FOUND (addr %08lx): %08lx-%08lx %c%c%c%c %08lx %02x:%02x %ld %s (build ID: %s, %d bytes)\n",
(long)addr, (long)q.vma_start, (long)q.vma_end,
(q.vma_flags & PROCMAP_QUERY_VMA_READABLE) ? 'r' : '-',
(q.vma_flags & PROCMAP_QUERY_VMA_WRITABLE) ? 'w' : '-',
(q.vma_flags & PROCMAP_QUERY_VMA_EXECUTABLE) ? 'x' : '-',
(q.vma_flags & PROCMAP_QUERY_VMA_SHARED) ? 's' : 'p',
(long)q.vma_offset, q.dev_major, q.dev_minor, (long)q.inode,
q.vma_name_size ? path_buf : "",
q.build_id_size ? "YES" : "NO",
q.build_id_size);
}
*start = q.vma_start;
*offset = q.vma_offset;
*flags = q.vma_flags;
return 0;
}
#else
# ifndef PROCMAP_QUERY_VMA_EXECUTABLE
# define PROCMAP_QUERY_VMA_EXECUTABLE 0x04
# endif
static int procmap_query(int fd, const void *addr, __u32 query_flags, size_t *start, size_t *offset, int *flags)
{
return -EOPNOTSUPP;
}
#endif
ssize_t get_uprobe_offset(const void *addr)
{
size_t start, base, end;
FILE *f;
char buf[256];
int err, flags;
f = fopen("/proc/self/maps", "r");
if (!f)
return -errno;
/* requested executable VMA only */
err = procmap_query(fileno(f), addr, PROCMAP_QUERY_VMA_EXECUTABLE, &start, &base, &flags);
if (err == -EOPNOTSUPP) {
bool found = false;
Annotation
- Immediate include surface: `ctype.h`, `stdio.h`, `stdlib.h`, `string.h`, `assert.h`, `errno.h`, `fcntl.h`, `poll.h`.
- Detected declarations: `function ksyms__add_symbol`, `function free_kallsyms_local`, `function ksym_cmp`, `function load_kallsyms`, `function ksym_get_addr_local`, `function ksym_get_addr`, `function kallsyms_find`, `function procmap_query`, `function procmap_query`, `function get_uprobe_offset`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.