1/* SPDX-License-Identifier: GPL-2.0 */ 2#ifndef __PERF_MAPS_H 3#define __PERF_MAPS_H 4 5#include <linux/refcount.h> 6#include <linux/rbtree.h> 7#include <stdio.h> 8#include <stdbool.h> 9#include <linux/types.h> 10#include "rwsem.h" 11#include <internal/rc_check.h> 12 13struct ref_reloc_sym; 14struct machine; 15struct map; 16struct maps; 17struct thread; 18 19struct map_rb_node { 20 struct rb_node rb_node; 21 struct map *map; 22}; 23 24struct map_rb_node *maps__first(struct maps *maps); 25struct map_rb_node *map_rb_node__next(struct map_rb_node *node); 26struct map_rb_node *maps__find_node(struct maps *maps, struct map *map); 27struct map *maps__find(struct maps *maps, u64 addr); 28 29#define maps__for_each_entry(maps, map) \ 30 for (map = maps__first(maps); map; map = map_rb_node__next(map)) 31 32#define maps__for_each_entry_safe(maps, map, next) \ 33 for (map = maps__first(maps), next = map_rb_node__next(map); map; \ 34 map = next, next = map_rb_node__next(map)) 35 36DECLARE_RC_STRUCT(maps) { 37 struct rb_root entries; 38 struct rw_semaphore lock; 39 struct machine *machine; 40 struct map *last_search_by_name; 41 struct map **maps_by_name; 42 refcount_t refcnt; 43 unsigned int nr_maps; 44 unsigned int nr_maps_allocated; 45#ifdef HAVE_LIBUNWIND_SUPPORT 46 void *addr_space; 47 const struct unwind_libunwind_ops *unwind_libunwind_ops; 48#endif 49}; 50 51#define KMAP_NAME_LEN 256 52 53struct kmap { 54 struct ref_reloc_sym *ref_reloc_sym; 55 struct maps *kmaps; 56 char name[KMAP_NAME_LEN]; 57}; 58 59struct maps *maps__new(struct machine *machine); 60bool maps__empty(struct maps *maps); 61int maps__clone(struct thread *thread, struct maps *parent); 62 63struct maps *maps__get(struct maps *maps); 64void maps__put(struct maps *maps); 65 66static inline void __maps__zput(struct maps **map) 67{ 68 maps__put(*map); 69 *map = NULL; 70} 71 72#define maps__zput(map) __maps__zput(&map) 73 74static inline struct rb_root *maps__entries(struct maps *maps) 75{ 76 return &RC_CHK_ACCESS(maps)->entries; 77} 78 79static inline struct machine *maps__machine(struct maps *maps) 80{ 81 return RC_CHK_ACCESS(maps)->machine; 82} 83 84static inline struct rw_semaphore *maps__lock(struct maps *maps) 85{ 86 return &RC_CHK_ACCESS(maps)->lock; 87} 88 89static inline struct map **maps__maps_by_name(struct maps *maps) 90{ 91 return RC_CHK_ACCESS(maps)->maps_by_name; 92} 93 94static inline unsigned int maps__nr_maps(const struct maps *maps) 95{ 96 return RC_CHK_ACCESS(maps)->nr_maps; 97} 98 99static inline refcount_t *maps__refcnt(struct maps *maps) 100{ 101 return &RC_CHK_ACCESS(maps)->refcnt; 102} 103 104#ifdef HAVE_LIBUNWIND_SUPPORT 105static inline void *maps__addr_space(struct maps *maps) 106{ 107 return RC_CHK_ACCESS(maps)->addr_space; 108} 109 110static inline const struct unwind_libunwind_ops *maps__unwind_libunwind_ops(const struct maps *maps) 111{ 112 return RC_CHK_ACCESS(maps)->unwind_libunwind_ops; 113} 114#endif 115 116size_t maps__fprintf(struct maps *maps, FILE *fp); 117 118int maps__insert(struct maps *maps, struct map *map); 119void maps__remove(struct maps *maps, struct map *map); 120 121struct symbol *maps__find_symbol(struct maps *maps, u64 addr, struct map **mapp); 122struct symbol *maps__find_symbol_by_name(struct maps *maps, const char *name, struct map **mapp); 123 124struct addr_map_symbol; 125 126int maps__find_ams(struct maps *maps, struct addr_map_symbol *ams); 127 128int maps__fixup_overlappings(struct maps *maps, struct map *map, FILE *fp); 129 130struct map *maps__find_by_name(struct maps *maps, const char *name); 131 132int maps__merge_in(struct maps *kmaps, struct map *new_map); 133 134void __maps__sort_by_name(struct maps *maps); 135 136#endif // __PERF_MAPS_H 137