mirror of
https://github.com/aya-rs/aya.git
synced 2026-10-12 21:49:58 +02:00
BPF iterators[0] are a way to dump kernel data into user-space and an alternative to `/proc` filesystem. This change adds support for BPF iterators on the user-space side. It provides a possibility to retrieve the outputs of BPF iterator programs both from sync and async Rust code. [0] https://docs.kernel.org/bpf/bpf_iterators.html
24 lines
530 B
C
24 lines
530 B
C
// clang-format off
|
|
#include <vmlinux.h>
|
|
#include <bpf/bpf_helpers.h>
|
|
// clang-format on
|
|
|
|
char _license[] SEC("license") = "GPL";
|
|
|
|
SEC("iter/task")
|
|
int iter_task(struct bpf_iter__task *ctx) {
|
|
struct seq_file *seq = ctx->meta->seq;
|
|
struct task_struct *task = ctx->task;
|
|
// Verifier requires this check.
|
|
if (task == NULL) {
|
|
return 0;
|
|
}
|
|
|
|
if (ctx->meta->seq_num == 0) {
|
|
BPF_SEQ_PRINTF(seq, "tgid pid name\n");
|
|
}
|
|
BPF_SEQ_PRINTF(seq, "%-8d %-8d %s\n", task->tgid, task->pid, task->comm);
|
|
|
|
return 0;
|
|
}
|