bpf_iter_test_kern3.c 775 字节
Newer Older
1 2
// SPDX-License-Identifier: GPL-2.0
/* Copyright (c) 2020 Facebook */
3 4
#define bpf_iter_meta bpf_iter_meta___not_used
#define bpf_iter__task bpf_iter__task___not_used
5
#include "vmlinux.h"
6 7
#undef bpf_iter_meta
#undef bpf_iter__task
8 9 10 11
#include <bpf/bpf_helpers.h>

char _license[] SEC("license") = "GPL";

12 13 14 15 16 17 18 19 20 21 22
struct bpf_iter_meta {
	struct seq_file *seq;
	__u64 session_id;
	__u64 seq_num;
} __attribute__((preserve_access_index));

struct bpf_iter__task {
	struct bpf_iter_meta *meta;
	struct task_struct *task;
} __attribute__((preserve_access_index));

23 24 25 26 27 28 29 30 31 32 33
SEC("iter/task")
int dump_task(struct bpf_iter__task *ctx)
{
	struct seq_file *seq = ctx->meta->seq;
	struct task_struct *task = ctx->task;
	int tgid;

	tgid = task->tgid;
	bpf_seq_write(seq, &tgid, sizeof(tgid));
	return 0;
}