18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci#ifndef __UNWIND_H 38c2ecf20Sopenharmony_ci#define __UNWIND_H 48c2ecf20Sopenharmony_ci 58c2ecf20Sopenharmony_ci#include <linux/compiler.h> 68c2ecf20Sopenharmony_ci#include <linux/types.h> 78c2ecf20Sopenharmony_ci#include "util/map_symbol.h" 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_cistruct maps; 108c2ecf20Sopenharmony_cistruct perf_sample; 118c2ecf20Sopenharmony_cistruct thread; 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_cistruct unwind_entry { 148c2ecf20Sopenharmony_ci struct map_symbol ms; 158c2ecf20Sopenharmony_ci u64 ip; 168c2ecf20Sopenharmony_ci}; 178c2ecf20Sopenharmony_ci 188c2ecf20Sopenharmony_citypedef int (*unwind_entry_cb_t)(struct unwind_entry *entry, void *arg); 198c2ecf20Sopenharmony_ci 208c2ecf20Sopenharmony_cistruct unwind_libunwind_ops { 218c2ecf20Sopenharmony_ci int (*prepare_access)(struct maps *maps); 228c2ecf20Sopenharmony_ci void (*flush_access)(struct maps *maps); 238c2ecf20Sopenharmony_ci void (*finish_access)(struct maps *maps); 248c2ecf20Sopenharmony_ci int (*get_entries)(unwind_entry_cb_t cb, void *arg, 258c2ecf20Sopenharmony_ci struct thread *thread, 268c2ecf20Sopenharmony_ci struct perf_sample *data, int max_stack); 278c2ecf20Sopenharmony_ci}; 288c2ecf20Sopenharmony_ci 298c2ecf20Sopenharmony_ci#ifdef HAVE_DWARF_UNWIND_SUPPORT 308c2ecf20Sopenharmony_ciint unwind__get_entries(unwind_entry_cb_t cb, void *arg, 318c2ecf20Sopenharmony_ci struct thread *thread, 328c2ecf20Sopenharmony_ci struct perf_sample *data, int max_stack); 338c2ecf20Sopenharmony_ci/* libunwind specific */ 348c2ecf20Sopenharmony_ci#ifdef HAVE_LIBUNWIND_SUPPORT 358c2ecf20Sopenharmony_ci#ifndef LIBUNWIND__ARCH_REG_ID 368c2ecf20Sopenharmony_ci#define LIBUNWIND__ARCH_REG_ID(regnum) libunwind__arch_reg_id(regnum) 378c2ecf20Sopenharmony_ci#endif 388c2ecf20Sopenharmony_ci 398c2ecf20Sopenharmony_ci#ifndef LIBUNWIND__ARCH_REG_SP 408c2ecf20Sopenharmony_ci#define LIBUNWIND__ARCH_REG_SP PERF_REG_SP 418c2ecf20Sopenharmony_ci#endif 428c2ecf20Sopenharmony_ci 438c2ecf20Sopenharmony_ci#ifndef LIBUNWIND__ARCH_REG_IP 448c2ecf20Sopenharmony_ci#define LIBUNWIND__ARCH_REG_IP PERF_REG_IP 458c2ecf20Sopenharmony_ci#endif 468c2ecf20Sopenharmony_ci 478c2ecf20Sopenharmony_ciint LIBUNWIND__ARCH_REG_ID(int regnum); 488c2ecf20Sopenharmony_ciint unwind__prepare_access(struct maps *maps, struct map *map, bool *initialized); 498c2ecf20Sopenharmony_civoid unwind__flush_access(struct maps *maps); 508c2ecf20Sopenharmony_civoid unwind__finish_access(struct maps *maps); 518c2ecf20Sopenharmony_ci#else 528c2ecf20Sopenharmony_cistatic inline int unwind__prepare_access(struct maps *maps __maybe_unused, 538c2ecf20Sopenharmony_ci struct map *map __maybe_unused, 548c2ecf20Sopenharmony_ci bool *initialized __maybe_unused) 558c2ecf20Sopenharmony_ci{ 568c2ecf20Sopenharmony_ci return 0; 578c2ecf20Sopenharmony_ci} 588c2ecf20Sopenharmony_ci 598c2ecf20Sopenharmony_cistatic inline void unwind__flush_access(struct maps *maps __maybe_unused) {} 608c2ecf20Sopenharmony_cistatic inline void unwind__finish_access(struct maps *maps __maybe_unused) {} 618c2ecf20Sopenharmony_ci#endif 628c2ecf20Sopenharmony_ci#else 638c2ecf20Sopenharmony_cistatic inline int 648c2ecf20Sopenharmony_ciunwind__get_entries(unwind_entry_cb_t cb __maybe_unused, 658c2ecf20Sopenharmony_ci void *arg __maybe_unused, 668c2ecf20Sopenharmony_ci struct thread *thread __maybe_unused, 678c2ecf20Sopenharmony_ci struct perf_sample *data __maybe_unused, 688c2ecf20Sopenharmony_ci int max_stack __maybe_unused) 698c2ecf20Sopenharmony_ci{ 708c2ecf20Sopenharmony_ci return 0; 718c2ecf20Sopenharmony_ci} 728c2ecf20Sopenharmony_ci 738c2ecf20Sopenharmony_cistatic inline int unwind__prepare_access(struct maps *maps __maybe_unused, 748c2ecf20Sopenharmony_ci struct map *map __maybe_unused, 758c2ecf20Sopenharmony_ci bool *initialized __maybe_unused) 768c2ecf20Sopenharmony_ci{ 778c2ecf20Sopenharmony_ci return 0; 788c2ecf20Sopenharmony_ci} 798c2ecf20Sopenharmony_ci 808c2ecf20Sopenharmony_cistatic inline void unwind__flush_access(struct maps *maps __maybe_unused) {} 818c2ecf20Sopenharmony_cistatic inline void unwind__finish_access(struct maps *maps __maybe_unused) {} 828c2ecf20Sopenharmony_ci#endif /* HAVE_DWARF_UNWIND_SUPPORT */ 838c2ecf20Sopenharmony_ci#endif /* __UNWIND_H */ 84