xref: /linux/tools/testing/selftests/bpf/progs/bpf_iter_test_kern3.c (revision 95298d63c67673c654c08952672d016212b26054)
1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (c) 2020 Facebook */
3 #define bpf_iter_meta bpf_iter_meta___not_used
4 #define bpf_iter__task bpf_iter__task___not_used
5 #include "vmlinux.h"
6 #undef bpf_iter_meta
7 #undef bpf_iter__task
8 #include <bpf/bpf_helpers.h>
9 
10 char _license[] SEC("license") = "GPL";
11 
12 struct bpf_iter_meta {
13 	struct seq_file *seq;
14 	__u64 session_id;
15 	__u64 seq_num;
16 } __attribute__((preserve_access_index));
17 
18 struct bpf_iter__task {
19 	struct bpf_iter_meta *meta;
20 	struct task_struct *task;
21 } __attribute__((preserve_access_index));
22 
23 SEC("iter/task")
24 int dump_task(struct bpf_iter__task *ctx)
25 {
26 	struct seq_file *seq = ctx->meta->seq;
27 	struct task_struct *task = ctx->task;
28 	int tgid;
29 
30 	tgid = task->tgid;
31 	bpf_seq_write(seq, &tgid, sizeof(tgid));
32 	return 0;
33 }
34