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 12 struct ref_reloc_sym; 13 struct machine; 14 struct map; 15 struct maps; 16 struct thread; 17 18 struct map_rb_node { 19 struct rb_node rb_node; 20 struct map *map; 21 }; 22 23 struct map_rb_node *maps__first(struct maps *maps); 24 struct map_rb_node *map_rb_node__next(struct map_rb_node *node); 25 struct map_rb_node *maps__find_node(struct maps *maps, struct map *map); 26 struct map *maps__find(struct maps *maps, u64 addr); 27 28 #define maps__for_each_entry(maps, map) \ 29 for (map = maps__first(maps); map; map = map_rb_node__next(map)) 30 31 #define maps__for_each_entry_safe(maps, map, next) \ 32 for (map = maps__first(maps), next = map_rb_node__next(map); map; \ 33 map = next, next = map_rb_node__next(map)) 34 35 struct maps { 36 struct rb_root entries; 37 struct rw_semaphore lock; 38 struct machine *machine; 39 struct map *last_search_by_name; 40 struct map **maps_by_name; 41 refcount_t refcnt; 42 unsigned int nr_maps; 43 unsigned int nr_maps_allocated; 44 #ifdef HAVE_LIBUNWIND_SUPPORT 45 void *addr_space; 46 const struct unwind_libunwind_ops *unwind_libunwind_ops; 47 #endif 48 }; 49 50 #define KMAP_NAME_LEN 256 51 52 struct kmap { 53 struct ref_reloc_sym *ref_reloc_sym; 54 struct maps *kmaps; 55 char name[KMAP_NAME_LEN]; 56 }; 57 58 struct maps *maps__new(struct machine *machine); 59 void maps__delete(struct maps *maps); 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 struct rb_root *maps__entries(struct maps *maps) 67 { 68 return &maps->entries; 69 } 70 71 static inline struct machine *maps__machine(struct maps *maps) 72 { 73 return maps->machine; 74 } 75 76 static inline struct rw_semaphore *maps__lock(struct maps *maps) 77 { 78 return &maps->lock; 79 } 80 81 static inline struct map **maps__maps_by_name(struct maps *maps) 82 { 83 return maps->maps_by_name; 84 } 85 86 static inline unsigned int maps__nr_maps(const struct maps *maps) 87 { 88 return maps->nr_maps; 89 } 90 91 #ifdef HAVE_LIBUNWIND_SUPPORT 92 static inline void *maps__addr_space(struct maps *maps) 93 { 94 return maps->addr_space; 95 } 96 97 static inline const struct unwind_libunwind_ops *maps__unwind_libunwind_ops(const struct maps *maps) 98 { 99 return maps->unwind_libunwind_ops; 100 } 101 #endif 102 103 size_t maps__fprintf(struct maps *maps, FILE *fp); 104 105 int maps__insert(struct maps *maps, struct map *map); 106 void maps__remove(struct maps *maps, struct map *map); 107 108 struct symbol *maps__find_symbol(struct maps *maps, u64 addr, struct map **mapp); 109 struct symbol *maps__find_symbol_by_name(struct maps *maps, const char *name, struct map **mapp); 110 111 struct addr_map_symbol; 112 113 int maps__find_ams(struct maps *maps, struct addr_map_symbol *ams); 114 115 int maps__fixup_overlappings(struct maps *maps, struct map *map, FILE *fp); 116 117 struct map *maps__find_by_name(struct maps *maps, const char *name); 118 119 int maps__merge_in(struct maps *kmaps, struct map *new_map); 120 121 void __maps__sort_by_name(struct maps *maps); 122 123 #endif // __PERF_MAPS_H 124