Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /* Copyright (c) 2020 Facebook */
0003 #include "bpf_iter.h"
0004 #include <bpf/bpf_helpers.h>
0005 
0006 char _license[] SEC("license") = "GPL";
0007 
0008 int count = 0;
0009 int tgid = 0;
0010 
0011 SEC("iter/task_file")
0012 int dump_task_file(struct bpf_iter__task_file *ctx)
0013 {
0014     struct seq_file *seq = ctx->meta->seq;
0015     struct task_struct *task = ctx->task;
0016     __u32 fd = ctx->fd;
0017     struct file *file = ctx->file;
0018 
0019     if (task == (void *)0 || file == (void *)0)
0020         return 0;
0021 
0022     if (ctx->meta->seq_num == 0) {
0023         count = 0;
0024         BPF_SEQ_PRINTF(seq, "    tgid      gid       fd      file\n");
0025     }
0026 
0027     if (tgid == task->tgid && task->tgid != task->pid)
0028         count++;
0029 
0030     BPF_SEQ_PRINTF(seq, "%8d %8d %8d %lx\n", task->tgid, task->pid, fd,
0031                (long)file->f_op);
0032     return 0;
0033 }