samples/bpf/syscall_tp_user.c
Source file repositories/reference/linux-study-clean/samples/bpf/syscall_tp_user.c
File Facts
- System
- Linux kernel
- Corpus path
samples/bpf/syscall_tp_user.c- Extension
.c- Size
- 3522 bytes
- Lines
- 156
- Domain
- Support Tooling And Documentation
- Bucket
- samples
- Inferred role
- Support Tooling And Documentation: syscall or user/kernel boundary
- Status
- core 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 participates in a user/kernel boundary; inspect argument validation, copy_from_user/copy_to_user, credentials, and dispatch target.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
stdio.hunistd.hfcntl.hstdlib.hstring.hlinux/perf_event.herrno.hbpf/libbpf.hbpf/bpf.h
Detected Declarations
function usagefunction verify_mapfunction testfunction bpf_object__for_each_programfunction main
Annotated Snippet
if (libbpf_get_error(objs[i])) {
fprintf(stderr, "opening BPF object file failed\n");
objs[i] = NULL;
goto cleanup;
}
/* One-time initialization */
if (!links) {
int nr_progs = 0;
bpf_object__for_each_program(prog, objs[i])
nr_progs += 1;
links = calloc(nr_progs * nr_tests, sizeof(struct bpf_link *));
if (!links)
goto cleanup;
}
/* load BPF program */
if (bpf_object__load(objs[i])) {
fprintf(stderr, "loading BPF object file failed\n");
goto cleanup;
}
map0_fds[i] = bpf_object__find_map_fd_by_name(objs[i],
"enter_open_map");
map1_fds[i] = bpf_object__find_map_fd_by_name(objs[i],
"exit_open_map");
if (map0_fds[i] < 0 || map1_fds[i] < 0) {
fprintf(stderr, "finding a map in obj file failed\n");
goto cleanup;
}
bpf_object__for_each_program(prog, objs[i]) {
links[j] = bpf_program__attach(prog);
if (libbpf_get_error(links[j])) {
fprintf(stderr, "bpf_program__attach failed\n");
links[j] = NULL;
goto cleanup;
}
j++;
}
printf("prog #%d: map ids %d %d\n", i, map0_fds[i], map1_fds[i]);
}
/* current load_bpf_file has perf_event_open default pid = -1
* and cpu = 0, which permits attached bpf execution on
* all cpus for all pid's. bpf program execution ignores
* cpu affinity.
*/
/* trigger some "open" operations */
fd = open(filename, O_RDONLY);
if (fd < 0) {
fprintf(stderr, "open failed: %s\n", strerror(errno));
return 1;
}
close(fd);
/* verify the map */
for (i = 0; i < nr_tests; i++) {
verify_map(map0_fds[i]);
verify_map(map1_fds[i]);
}
cleanup:
if (links) {
for (j--; j >= 0; j--)
bpf_link__destroy(links[j]);
free(links);
}
for (i--; i >= 0; i--)
bpf_object__close(objs[i]);
return 0;
}
int main(int argc, char **argv)
{
int opt, nr_tests = 1;
char filename[256];
while ((opt = getopt(argc, argv, "i:h")) != -1) {
switch (opt) {
case 'i':
nr_tests = atoi(optarg);
break;
case 'h':
default:
Annotation
- Immediate include surface: `stdio.h`, `unistd.h`, `fcntl.h`, `stdlib.h`, `string.h`, `linux/perf_event.h`, `errno.h`, `bpf/libbpf.h`.
- Detected declarations: `function usage`, `function verify_map`, `function test`, `function bpf_object__for_each_program`, `function main`.
- Atlas domain: Support Tooling And Documentation / samples.
- Implementation status: core 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.