1 // SPDX-License-Identifier: GPL-2.0 2 /* Copyright (c) 2020 Facebook */ 3 /* "undefine" structs in vmlinux.h, because we "override" them below */ 4 #define bpf_iter_meta bpf_iter_meta___not_used 5 #define bpf_iter__task bpf_iter__task___not_used 6 #include "vmlinux.h" 7 #undef bpf_iter_meta 8 #undef bpf_iter__task 9 #include <bpf/bpf_helpers.h> 10 #include <bpf/bpf_tracing.h> 11 12 char _license[] SEC("license") = "GPL"; 13 14 struct bpf_iter_meta { 15 struct seq_file *seq; 16 __u64 session_id; 17 __u64 seq_num; 18 } __attribute__((preserve_access_index)); 19 20 struct bpf_iter__task { 21 struct bpf_iter_meta *meta; 22 struct task_struct *task; 23 } __attribute__((preserve_access_index)); 24 25 SEC("iter/task") 26 int dump_task(struct bpf_iter__task *ctx) 27 { 28 struct seq_file *seq = ctx->meta->seq; 29 struct task_struct *task = ctx->task; 30 31 if (task == (void *)0) { 32 BPF_SEQ_PRINTF(seq, " === END ===\n"); 33 return 0; 34 } 35 36 if (ctx->meta->seq_num == 0) 37 BPF_SEQ_PRINTF(seq, " tgid gid\n"); 38 39 BPF_SEQ_PRINTF(seq, "%8d %8d\n", task->tgid, task->pid); 40 return 0; 41 } 42