1 // SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
2 /* Copyright (c) 2020 Facebook */
4 #include <bpf/bpf_helpers.h>
5 #include <bpf/bpf_core_read.h>
6 #include <bpf/bpf_tracing.h>
9 /* keep in sync with the definition in main.h */
18 extern const void bpf_link_fops __ksym
;
19 extern const void bpf_map_fops __ksym
;
20 extern const void bpf_prog_fops __ksym
;
21 extern const void btf_fops __ksym
;
23 const volatile enum bpf_obj_type obj_type
= BPF_OBJ_UNKNOWN
;
25 static __always_inline __u32
get_obj_id(void *ent
, enum bpf_obj_type type
)
29 return BPF_CORE_READ((struct bpf_prog
*)ent
, aux
, id
);
31 return BPF_CORE_READ((struct bpf_map
*)ent
, id
);
33 return BPF_CORE_READ((struct btf
*)ent
, id
);
35 return BPF_CORE_READ((struct bpf_link
*)ent
, id
);
42 int iter(struct bpf_iter__task_file
*ctx
)
44 struct file
*file
= ctx
->file
;
45 struct task_struct
*task
= ctx
->task
;
46 struct pid_iter_entry e
;
54 fops
= &bpf_prog_fops
;
63 fops
= &bpf_link_fops
;
69 if (file
->f_op
!= fops
)
73 e
.id
= get_obj_id(file
->private_data
, obj_type
);
74 bpf_probe_read_kernel(&e
.comm
, sizeof(e
.comm
),
75 task
->group_leader
->comm
);
76 bpf_seq_write(ctx
->meta
->seq
, &e
, sizeof(e
));
81 char LICENSE
[] SEC("license") = "Dual BSD/GPL";