xref: /linux/tools/testing/selftests/bpf/progs/stacktrace_ips.c (revision cbba5d1b53fb82209feacb459edecb1ef8427119)
1 // SPDX-License-Identifier: GPL-2.0
2 // Copyright (c) 2018 Facebook
3 
4 #include <vmlinux.h>
5 #include <bpf/bpf_helpers.h>
6 #include <bpf/bpf_tracing.h>
7 
8 #ifndef PERF_MAX_STACK_DEPTH
9 #define PERF_MAX_STACK_DEPTH         127
10 #endif
11 
12 typedef __u64 stack_trace_t[PERF_MAX_STACK_DEPTH];
13 
14 struct {
15 	__uint(type, BPF_MAP_TYPE_STACK_TRACE);
16 	__uint(max_entries, 16384);
17 	__type(key, __u32);
18 	__type(value, stack_trace_t);
19 } stackmap SEC(".maps");
20 
21 extern bool CONFIG_UNWINDER_ORC __kconfig __weak;
22 
23 /*
24  * This function is here to have CONFIG_UNWINDER_ORC
25  * used and added to object BTF.
26  */
unused(void)27 int unused(void)
28 {
29 	return CONFIG_UNWINDER_ORC ? 0 : 1;
30 }
31 
32 __u32 stack_key;
33 
34 SEC("kprobe.multi")
kprobe_multi_test(struct pt_regs * ctx)35 int kprobe_multi_test(struct pt_regs *ctx)
36 {
37 	stack_key = bpf_get_stackid(ctx, &stackmap, 0);
38 	return 0;
39 }
40 
41 SEC("raw_tp/bpf_testmod_test_read")
rawtp_test(void * ctx)42 int rawtp_test(void *ctx)
43 {
44 	/* Skip ebpf program entry in the stack. */
45 	stack_key = bpf_get_stackid(ctx, &stackmap, 0);
46 	return 0;
47 }
48 
49 char _license[] SEC("license") = "GPL";
50