1#ifndef __PERF_MAP_H
2#define __PERF_MAP_H
3
4#include <linux/compiler.h>
5#include <linux/list.h>
6#include <linux/rbtree.h>
7#include <stdio.h>
8#include <stdbool.h>
9#include <linux/types.h>
10
11enum map_type {
12 MAP__FUNCTION = 0,
13 MAP__VARIABLE,
14};
15
16#define MAP__NR_TYPES (MAP__VARIABLE + 1)
17
18extern const char *map_type__name[MAP__NR_TYPES];
19
20struct dso;
21struct ip_callchain;
22struct ref_reloc_sym;
23struct map_groups;
24struct machine;
25struct perf_evsel;
26
27struct map {
28 union {
29 struct rb_node rb_node;
30 struct list_head node;
31 };
32 u64 start;
33 u64 end;
34 u8 type;
35 bool referenced;
36 bool erange_warned;
37 u32 priv;
38 u32 prot;
39 u32 flags;
40 u64 pgoff;
41 u64 reloc;
42 u32 maj, min;
43 u64 ino;
44 u64 ino_generation;
45
46
47 u64 (*map_ip)(struct map *, u64);
48
49 u64 (*unmap_ip)(struct map *, u64);
50
51 struct dso *dso;
52 struct map_groups *groups;
53};
54
55struct kmap {
56 struct ref_reloc_sym *ref_reloc_sym;
57 struct map_groups *kmaps;
58};
59
60struct map_groups {
61 struct rb_root maps[MAP__NR_TYPES];
62 struct list_head removed_maps[MAP__NR_TYPES];
63 struct machine *machine;
64 int refcnt;
65};
66
67struct map_groups *map_groups__new(void);
68void map_groups__delete(struct map_groups *mg);
69
70static inline struct map_groups *map_groups__get(struct map_groups *mg)
71{
72 ++mg->refcnt;
73 return mg;
74}
75
76void map_groups__put(struct map_groups *mg);
77
78static inline struct kmap *map__kmap(struct map *map)
79{
80 return (struct kmap *)(map + 1);
81}
82
83static inline u64 map__map_ip(struct map *map, u64 ip)
84{
85 return ip - map->start + map->pgoff;
86}
87
88static inline u64 map__unmap_ip(struct map *map, u64 ip)
89{
90 return ip + map->start - map->pgoff;
91}
92
93static inline u64 identity__map_ip(struct map *map __maybe_unused, u64 ip)
94{
95 return ip;
96}
97
98
99
100u64 map__rip_2objdump(struct map *map, u64 rip);
101
102
103u64 map__objdump_2mem(struct map *map, u64 ip);
104
105struct symbol;
106
107
108
109
110
111
112
113
114#define map__for_each_symbol(map, pos, n) \
115 dso__for_each_symbol(map->dso, pos, n, map->type)
116
117typedef int (*symbol_filter_t)(struct map *map, struct symbol *sym);
118
119void map__init(struct map *map, enum map_type type,
120 u64 start, u64 end, u64 pgoff, struct dso *dso);
121struct map *map__new(struct list_head *dsos__list, u64 start, u64 len,
122 u64 pgoff, u32 pid, u32 d_maj, u32 d_min, u64 ino,
123 u64 ino_gen, u32 prot, u32 flags,
124 char *filename, enum map_type type);
125struct map *map__new2(u64 start, struct dso *dso, enum map_type type);
126void map__delete(struct map *map);
127struct map *map__clone(struct map *map);
128int map__overlap(struct map *l, struct map *r);
129size_t map__fprintf(struct map *map, FILE *fp);
130size_t map__fprintf_dsoname(struct map *map, FILE *fp);
131int map__fprintf_srcline(struct map *map, u64 addr, const char *prefix,
132 FILE *fp);
133
134int map__load(struct map *map, symbol_filter_t filter);
135struct symbol *map__find_symbol(struct map *map,
136 u64 addr, symbol_filter_t filter);
137struct symbol *map__find_symbol_by_name(struct map *map, const char *name,
138 symbol_filter_t filter);
139void map__fixup_start(struct map *map);
140void map__fixup_end(struct map *map);
141
142void map__reloc_vmlinux(struct map *map);
143
144size_t __map_groups__fprintf_maps(struct map_groups *mg,
145 enum map_type type, int verbose, FILE *fp);
146void maps__insert(struct rb_root *maps, struct map *map);
147void maps__remove(struct rb_root *maps, struct map *map);
148struct map *maps__find(struct rb_root *maps, u64 addr);
149struct map *maps__first(struct rb_root *maps);
150struct map *maps__next(struct map *map);
151void map_groups__init(struct map_groups *mg);
152void map_groups__exit(struct map_groups *mg);
153int map_groups__clone(struct map_groups *mg,
154 struct map_groups *parent, enum map_type type);
155size_t map_groups__fprintf(struct map_groups *mg, int verbose, FILE *fp);
156size_t map_groups__fprintf_maps(struct map_groups *mg, int verbose, FILE *fp);
157
158int maps__set_kallsyms_ref_reloc_sym(struct map **maps, const char *symbol_name,
159 u64 addr);
160
161static inline void map_groups__insert(struct map_groups *mg, struct map *map)
162{
163 maps__insert(&mg->maps[map->type], map);
164 map->groups = mg;
165}
166
167static inline void map_groups__remove(struct map_groups *mg, struct map *map)
168{
169 maps__remove(&mg->maps[map->type], map);
170}
171
172static inline struct map *map_groups__find(struct map_groups *mg,
173 enum map_type type, u64 addr)
174{
175 return maps__find(&mg->maps[type], addr);
176}
177
178static inline struct map *map_groups__first(struct map_groups *mg,
179 enum map_type type)
180{
181 return maps__first(&mg->maps[type]);
182}
183
184static inline struct map *map_groups__next(struct map *map)
185{
186 return maps__next(map);
187}
188
189struct symbol *map_groups__find_symbol(struct map_groups *mg,
190 enum map_type type, u64 addr,
191 struct map **mapp,
192 symbol_filter_t filter);
193
194struct symbol *map_groups__find_symbol_by_name(struct map_groups *mg,
195 enum map_type type,
196 const char *name,
197 struct map **mapp,
198 symbol_filter_t filter);
199
200struct addr_map_symbol;
201
202int map_groups__find_ams(struct addr_map_symbol *ams, symbol_filter_t filter);
203
204static inline
205struct symbol *map_groups__find_function_by_name(struct map_groups *mg,
206 const char *name, struct map **mapp,
207 symbol_filter_t filter)
208{
209 return map_groups__find_symbol_by_name(mg, MAP__FUNCTION, name, mapp, filter);
210}
211
212int map_groups__fixup_overlappings(struct map_groups *mg, struct map *map,
213 int verbose, FILE *fp);
214
215struct map *map_groups__find_by_name(struct map_groups *mg,
216 enum map_type type, const char *name);
217
218void map_groups__flush(struct map_groups *mg);
219
220#endif
221