1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */ 271ad0f5eSJiri Olsa #ifndef __UNWIND_H 371ad0f5eSJiri Olsa #define __UNWIND_H 471ad0f5eSJiri Olsa 53dfed910SArnaldo Carvalho de Melo #include <linux/compiler.h> 6d944c4eeSBorislav Petkov #include <linux/types.h> 7*c1529738SArnaldo Carvalho de Melo #include "util/map_symbol.h" 83dfed910SArnaldo Carvalho de Melo 9e8ba2906SJohn Keeping struct map_groups; 103dfed910SArnaldo Carvalho de Melo struct perf_sample; 113dfed910SArnaldo Carvalho de Melo struct thread; 1271ad0f5eSJiri Olsa 1371ad0f5eSJiri Olsa struct unwind_entry { 14*c1529738SArnaldo Carvalho de Melo struct map_symbol ms; 1571ad0f5eSJiri Olsa u64 ip; 1671ad0f5eSJiri Olsa }; 1771ad0f5eSJiri Olsa 1871ad0f5eSJiri Olsa typedef int (*unwind_entry_cb_t)(struct unwind_entry *entry, void *arg); 1971ad0f5eSJiri Olsa 20f83c0415SHe Kuang struct unwind_libunwind_ops { 21e8ba2906SJohn Keeping int (*prepare_access)(struct map_groups *mg); 22e8ba2906SJohn Keeping void (*flush_access)(struct map_groups *mg); 23e8ba2906SJohn Keeping void (*finish_access)(struct map_groups *mg); 24f83c0415SHe Kuang int (*get_entries)(unwind_entry_cb_t cb, void *arg, 25f83c0415SHe Kuang struct thread *thread, 26f83c0415SHe Kuang struct perf_sample *data, int max_stack); 27f83c0415SHe Kuang }; 28f83c0415SHe Kuang 299ff125d1SJiri Olsa #ifdef HAVE_DWARF_UNWIND_SUPPORT 3071ad0f5eSJiri Olsa int unwind__get_entries(unwind_entry_cb_t cb, void *arg, 3171ad0f5eSJiri Olsa struct thread *thread, 3237676af1SArnaldo Carvalho de Melo struct perf_sample *data, int max_stack); 339ff125d1SJiri Olsa /* libunwind specific */ 349ff125d1SJiri Olsa #ifdef HAVE_LIBUNWIND_SUPPORT 35eeb118c5SHe Kuang #ifndef LIBUNWIND__ARCH_REG_ID 36eeb118c5SHe Kuang #define LIBUNWIND__ARCH_REG_ID(regnum) libunwind__arch_reg_id(regnum) 37eeb118c5SHe Kuang #endif 3878ff1d6dSHe Kuang 3978ff1d6dSHe Kuang #ifndef LIBUNWIND__ARCH_REG_SP 4078ff1d6dSHe Kuang #define LIBUNWIND__ARCH_REG_SP PERF_REG_SP 4178ff1d6dSHe Kuang #endif 4278ff1d6dSHe Kuang 4378ff1d6dSHe Kuang #ifndef LIBUNWIND__ARCH_REG_IP 4478ff1d6dSHe Kuang #define LIBUNWIND__ARCH_REG_IP PERF_REG_IP 4578ff1d6dSHe Kuang #endif 4678ff1d6dSHe Kuang 47eeb118c5SHe Kuang int LIBUNWIND__ARCH_REG_ID(int regnum); 48e8ba2906SJohn Keeping int unwind__prepare_access(struct map_groups *mg, struct map *map, 49a2873325SJiri Olsa bool *initialized); 50e8ba2906SJohn Keeping void unwind__flush_access(struct map_groups *mg); 51e8ba2906SJohn Keeping void unwind__finish_access(struct map_groups *mg); 5266f066d8SNamhyung Kim #else 53e8ba2906SJohn Keeping static inline int unwind__prepare_access(struct map_groups *mg __maybe_unused, 54a2873325SJiri Olsa struct map *map __maybe_unused, 55a2873325SJiri Olsa bool *initialized __maybe_unused) 5666f066d8SNamhyung Kim { 5766f066d8SNamhyung Kim return 0; 5866f066d8SNamhyung Kim } 5966f066d8SNamhyung Kim 60e8ba2906SJohn Keeping static inline void unwind__flush_access(struct map_groups *mg __maybe_unused) {} 61e8ba2906SJohn Keeping static inline void unwind__finish_access(struct map_groups *mg __maybe_unused) {} 629ff125d1SJiri Olsa #endif 6371ad0f5eSJiri Olsa #else 6471ad0f5eSJiri Olsa static inline int 651d037ca1SIrina Tirdea unwind__get_entries(unwind_entry_cb_t cb __maybe_unused, 661d037ca1SIrina Tirdea void *arg __maybe_unused, 671d037ca1SIrina Tirdea struct thread *thread __maybe_unused, 6837676af1SArnaldo Carvalho de Melo struct perf_sample *data __maybe_unused, 6937676af1SArnaldo Carvalho de Melo int max_stack __maybe_unused) 7071ad0f5eSJiri Olsa { 7171ad0f5eSJiri Olsa return 0; 7271ad0f5eSJiri Olsa } 7366f066d8SNamhyung Kim 74e8ba2906SJohn Keeping static inline int unwind__prepare_access(struct map_groups *mg __maybe_unused, 75a2873325SJiri Olsa struct map *map __maybe_unused, 76a2873325SJiri Olsa bool *initialized __maybe_unused) 7766f066d8SNamhyung Kim { 7866f066d8SNamhyung Kim return 0; 7966f066d8SNamhyung Kim } 8066f066d8SNamhyung Kim 81e8ba2906SJohn Keeping static inline void unwind__flush_access(struct map_groups *mg __maybe_unused) {} 82e8ba2906SJohn Keeping static inline void unwind__finish_access(struct map_groups *mg __maybe_unused) {} 839ff125d1SJiri Olsa #endif /* HAVE_DWARF_UNWIND_SUPPORT */ 8471ad0f5eSJiri Olsa #endif /* __UNWIND_H */ 85