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 */ 27 int unused(void) 28 { 29 return CONFIG_UNWINDER_ORC ? 0 : 1; 30 } 31 32 __u32 stack_key; 33 34 SEC("kprobe") 35 int kprobe_test(struct pt_regs *ctx) 36 { 37 stack_key = bpf_get_stackid(ctx, &stackmap, 0); 38 return 0; 39 } 40 41 SEC("kprobe.multi") 42 int kprobe_multi_test(struct pt_regs *ctx) 43 { 44 stack_key = bpf_get_stackid(ctx, &stackmap, 0); 45 return 0; 46 } 47 48 SEC("raw_tp/bpf_testmod_test_read") 49 int rawtp_test(void *ctx) 50 { 51 /* Skip ebpf program entry in the stack. */ 52 stack_key = bpf_get_stackid(ctx, &stackmap, 0); 53 return 0; 54 } 55 56 SEC("fentry/bpf_testmod_stacktrace_test") 57 int fentry_test(struct pt_regs *ctx) 58 { 59 /* 60 * Skip 2 bpf_program/trampoline stack entries: 61 * - bpf_prog_bd1f7a949f55fb03_fentry_test 62 * - bpf_trampoline_182536277701 63 */ 64 stack_key = bpf_get_stackid(ctx, &stackmap, 2); 65 return 0; 66 } 67 68 SEC("fexit/bpf_testmod_stacktrace_test") 69 int fexit_test(struct pt_regs *ctx) 70 { 71 /* Skip 2 bpf_program/trampoline stack entries, check fentry_test. */ 72 stack_key = bpf_get_stackid(ctx, &stackmap, 2); 73 return 0; 74 } 75 76 char _license[] SEC("license") = "GPL"; 77