1 b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */ 2 71ad0f5eSJiri Olsa #ifndef __UNWIND_H 3 71ad0f5eSJiri Olsa #define __UNWIND_H 4 71ad0f5eSJiri Olsa 5 3dfed910SArnaldo Carvalho de Melo #include <linux/compiler.h> 6 d944c4eeSBorislav Petkov #include <linux/types.h> 7 *c1529738SArnaldo Carvalho de Melo #include "util/map_symbol.h" 8 3dfed910SArnaldo Carvalho de Melo 9 e8ba2906SJohn Keeping struct map_groups; 10 3dfed910SArnaldo Carvalho de Melo struct perf_sample; 11 3dfed910SArnaldo Carvalho de Melo struct thread; 12 71ad0f5eSJiri Olsa 13 71ad0f5eSJiri Olsa struct unwind_entry { 14 *c1529738SArnaldo Carvalho de Melo struct map_symbol ms; 15 71ad0f5eSJiri Olsa u64 ip; 16 71ad0f5eSJiri Olsa }; 17 71ad0f5eSJiri Olsa 18 71ad0f5eSJiri Olsa typedef int (*unwind_entry_cb_t)(struct unwind_entry *entry, void *arg); 19 71ad0f5eSJiri Olsa 20 f83c0415SHe Kuang struct unwind_libunwind_ops { 21 e8ba2906SJohn Keeping int (*prepare_access)(struct map_groups *mg); 22 e8ba2906SJohn Keeping void (*flush_access)(struct map_groups *mg); 23 e8ba2906SJohn Keeping void (*finish_access)(struct map_groups *mg); 24 f83c0415SHe Kuang int (*get_entries)(unwind_entry_cb_t cb, void *arg, 25 f83c0415SHe Kuang struct thread *thread, 26 f83c0415SHe Kuang struct perf_sample *data, int max_stack); 27 f83c0415SHe Kuang }; 28 f83c0415SHe Kuang 29 9ff125d1SJiri Olsa #ifdef HAVE_DWARF_UNWIND_SUPPORT 30 71ad0f5eSJiri Olsa int unwind__get_entries(unwind_entry_cb_t cb, void *arg, 31 71ad0f5eSJiri Olsa struct thread *thread, 32 37676af1SArnaldo Carvalho de Melo struct perf_sample *data, int max_stack); 33 9ff125d1SJiri Olsa /* libunwind specific */ 34 9ff125d1SJiri Olsa #ifdef HAVE_LIBUNWIND_SUPPORT 35 eeb118c5SHe Kuang #ifndef LIBUNWIND__ARCH_REG_ID 36 eeb118c5SHe Kuang #define LIBUNWIND__ARCH_REG_ID(regnum) libunwind__arch_reg_id(regnum) 37 eeb118c5SHe Kuang #endif 38 78ff1d6dSHe Kuang 39 78ff1d6dSHe Kuang #ifndef LIBUNWIND__ARCH_REG_SP 40 78ff1d6dSHe Kuang #define LIBUNWIND__ARCH_REG_SP PERF_REG_SP 41 78ff1d6dSHe Kuang #endif 42 78ff1d6dSHe Kuang 43 78ff1d6dSHe Kuang #ifndef LIBUNWIND__ARCH_REG_IP 44 78ff1d6dSHe Kuang #define LIBUNWIND__ARCH_REG_IP PERF_REG_IP 45 78ff1d6dSHe Kuang #endif 46 78ff1d6dSHe Kuang 47 eeb118c5SHe Kuang int LIBUNWIND__ARCH_REG_ID(int regnum); 48 e8ba2906SJohn Keeping int unwind__prepare_access(struct map_groups *mg, struct map *map, 49 a2873325SJiri Olsa bool *initialized); 50 e8ba2906SJohn Keeping void unwind__flush_access(struct map_groups *mg); 51 e8ba2906SJohn Keeping void unwind__finish_access(struct map_groups *mg); 52 66f066d8SNamhyung Kim #else 53 e8ba2906SJohn Keeping static inline int unwind__prepare_access(struct map_groups *mg __maybe_unused, 54 a2873325SJiri Olsa struct map *map __maybe_unused, 55 a2873325SJiri Olsa bool *initialized __maybe_unused) 56 66f066d8SNamhyung Kim { 57 66f066d8SNamhyung Kim return 0; 58 66f066d8SNamhyung Kim } 59 66f066d8SNamhyung Kim 60 e8ba2906SJohn Keeping static inline void unwind__flush_access(struct map_groups *mg __maybe_unused) {} 61 e8ba2906SJohn Keeping static inline void unwind__finish_access(struct map_groups *mg __maybe_unused) {} 62 9ff125d1SJiri Olsa #endif 63 71ad0f5eSJiri Olsa #else 64 71ad0f5eSJiri Olsa static inline int 65 1d037ca1SIrina Tirdea unwind__get_entries(unwind_entry_cb_t cb __maybe_unused, 66 1d037ca1SIrina Tirdea void *arg __maybe_unused, 67 1d037ca1SIrina Tirdea struct thread *thread __maybe_unused, 68 37676af1SArnaldo Carvalho de Melo struct perf_sample *data __maybe_unused, 69 37676af1SArnaldo Carvalho de Melo int max_stack __maybe_unused) 70 71ad0f5eSJiri Olsa { 71 71ad0f5eSJiri Olsa return 0; 72 71ad0f5eSJiri Olsa } 73 66f066d8SNamhyung Kim 74 e8ba2906SJohn Keeping static inline int unwind__prepare_access(struct map_groups *mg __maybe_unused, 75 a2873325SJiri Olsa struct map *map __maybe_unused, 76 a2873325SJiri Olsa bool *initialized __maybe_unused) 77 66f066d8SNamhyung Kim { 78 66f066d8SNamhyung Kim return 0; 79 66f066d8SNamhyung Kim } 80 66f066d8SNamhyung Kim 81 e8ba2906SJohn Keeping static inline void unwind__flush_access(struct map_groups *mg __maybe_unused) {} 82 e8ba2906SJohn Keeping static inline void unwind__finish_access(struct map_groups *mg __maybe_unused) {} 83 9ff125d1SJiri Olsa #endif /* HAVE_DWARF_UNWIND_SUPPORT */ 84 71ad0f5eSJiri Olsa #endif /* __UNWIND_H */ 85