WIP FPC-III support
[linux/fpc-iii.git] / tools / testing / selftests / bpf / progs / bpf_iter_task_stack.c
blob50e59a2e142ea423ddb8c3dfca6a78f6e76f50d4
1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (c) 2020 Facebook */
3 #include "bpf_iter.h"
4 #include <bpf/bpf_helpers.h>
5 #include <bpf/bpf_tracing.h>
7 char _license[] SEC("license") = "GPL";
9 #define MAX_STACK_TRACE_DEPTH 64
10 unsigned long entries[MAX_STACK_TRACE_DEPTH] = {};
11 #define SIZE_OF_ULONG (sizeof(unsigned long))
13 SEC("iter/task")
14 int dump_task_stack(struct bpf_iter__task *ctx)
16 struct seq_file *seq = ctx->meta->seq;
17 struct task_struct *task = ctx->task;
18 long i, retlen;
20 if (task == (void *)0)
21 return 0;
23 retlen = bpf_get_task_stack(task, entries,
24 MAX_STACK_TRACE_DEPTH * SIZE_OF_ULONG, 0);
25 if (retlen < 0)
26 return 0;
28 BPF_SEQ_PRINTF(seq, "pid: %8u num_entries: %8u\n", task->pid,
29 retlen / SIZE_OF_ULONG);
30 for (i = 0; i < MAX_STACK_TRACE_DEPTH; i++) {
31 if (retlen > i * SIZE_OF_ULONG)
32 BPF_SEQ_PRINTF(seq, "[<0>] %pB\n", (void *)entries[i]);
34 BPF_SEQ_PRINTF(seq, "\n");
36 return 0;