xref: /openbmc/linux/tools/perf/util/maps.h (revision ffcdf473)
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 void maps__delete(struct maps *maps);
61 bool maps__empty(struct maps *maps);
62 int maps__clone(struct thread *thread, struct maps *parent);
63 
64 struct maps *maps__get(struct maps *maps);
65 void maps__put(struct maps *maps);
66 
67 static inline struct rb_root *maps__entries(struct maps *maps)
68 {
69 	return &RC_CHK_ACCESS(maps)->entries;
70 }
71 
72 static inline struct machine *maps__machine(struct maps *maps)
73 {
74 	return RC_CHK_ACCESS(maps)->machine;
75 }
76 
77 static inline struct rw_semaphore *maps__lock(struct maps *maps)
78 {
79 	return &RC_CHK_ACCESS(maps)->lock;
80 }
81 
82 static inline struct map **maps__maps_by_name(struct maps *maps)
83 {
84 	return RC_CHK_ACCESS(maps)->maps_by_name;
85 }
86 
87 static inline unsigned int maps__nr_maps(const struct maps *maps)
88 {
89 	return RC_CHK_ACCESS(maps)->nr_maps;
90 }
91 
92 static inline refcount_t *maps__refcnt(struct maps *maps)
93 {
94 	return &RC_CHK_ACCESS(maps)->refcnt;
95 }
96 
97 #ifdef HAVE_LIBUNWIND_SUPPORT
98 static inline void *maps__addr_space(struct maps *maps)
99 {
100 	return RC_CHK_ACCESS(maps)->addr_space;
101 }
102 
103 static inline const struct unwind_libunwind_ops *maps__unwind_libunwind_ops(const struct maps *maps)
104 {
105 	return RC_CHK_ACCESS(maps)->unwind_libunwind_ops;
106 }
107 #endif
108 
109 size_t maps__fprintf(struct maps *maps, FILE *fp);
110 
111 int maps__insert(struct maps *maps, struct map *map);
112 void maps__remove(struct maps *maps, struct map *map);
113 
114 struct symbol *maps__find_symbol(struct maps *maps, u64 addr, struct map **mapp);
115 struct symbol *maps__find_symbol_by_name(struct maps *maps, const char *name, struct map **mapp);
116 
117 struct addr_map_symbol;
118 
119 int maps__find_ams(struct maps *maps, struct addr_map_symbol *ams);
120 
121 int maps__fixup_overlappings(struct maps *maps, struct map *map, FILE *fp);
122 
123 struct map *maps__find_by_name(struct maps *maps, const char *name);
124 
125 int maps__merge_in(struct maps *kmaps, struct map *new_map);
126 
127 void __maps__sort_by_name(struct maps *maps);
128 
129 #endif // __PERF_MAPS_H
130