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 13 struct ref_reloc_sym; 14 struct machine; 15 struct map; 16 struct maps; 17 struct thread; 18 19 struct map_rb_node { 20 struct rb_node rb_node; 21 struct map *map; 22 }; 23 24 struct map_rb_node *maps__first(struct maps *maps); 25 struct map_rb_node *map_rb_node__next(struct map_rb_node *node); 26 struct map_rb_node *maps__find_node(struct maps *maps, struct map *map); 27 struct 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 36 DECLARE_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 53 struct kmap { 54 struct ref_reloc_sym *ref_reloc_sym; 55 struct maps *kmaps; 56 char name[KMAP_NAME_LEN]; 57 }; 58 59 struct maps *maps__new(struct machine *machine); 60 bool maps__empty(struct maps *maps); 61 int maps__clone(struct thread *thread, struct maps *parent); 62 63 struct maps *maps__get(struct maps *maps); 64 void maps__put(struct maps *maps); 65 66 static 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 74 static inline struct rb_root *maps__entries(struct maps *maps) 75 { 76 return &RC_CHK_ACCESS(maps)->entries; 77 } 78 79 static inline struct machine *maps__machine(struct maps *maps) 80 { 81 return RC_CHK_ACCESS(maps)->machine; 82 } 83 84 static inline struct rw_semaphore *maps__lock(struct maps *maps) 85 { 86 return &RC_CHK_ACCESS(maps)->lock; 87 } 88 89 static inline struct map **maps__maps_by_name(struct maps *maps) 90 { 91 return RC_CHK_ACCESS(maps)->maps_by_name; 92 } 93 94 static inline unsigned int maps__nr_maps(const struct maps *maps) 95 { 96 return RC_CHK_ACCESS(maps)->nr_maps; 97 } 98 99 static inline refcount_t *maps__refcnt(struct maps *maps) 100 { 101 return &RC_CHK_ACCESS(maps)->refcnt; 102 } 103 104 #ifdef HAVE_LIBUNWIND_SUPPORT 105 static inline void *maps__addr_space(struct maps *maps) 106 { 107 return RC_CHK_ACCESS(maps)->addr_space; 108 } 109 110 static 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 116 size_t maps__fprintf(struct maps *maps, FILE *fp); 117 118 int maps__insert(struct maps *maps, struct map *map); 119 void maps__remove(struct maps *maps, struct map *map); 120 121 struct symbol *maps__find_symbol(struct maps *maps, u64 addr, struct map **mapp); 122 struct symbol *maps__find_symbol_by_name(struct maps *maps, const char *name, struct map **mapp); 123 124 struct addr_map_symbol; 125 126 int maps__find_ams(struct maps *maps, struct addr_map_symbol *ams); 127 128 int maps__fixup_overlappings(struct maps *maps, struct map *map, FILE *fp); 129 130 struct map *maps__find_by_name(struct maps *maps, const char *name); 131 132 int maps__merge_in(struct maps *kmaps, struct map *new_map); 133 134 void __maps__sort_by_name(struct maps *maps); 135 136 #endif // __PERF_MAPS_H 137