1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __PERF_MAP_GROUPS_H
3 #define __PERF_MAP_GROUPS_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 thread;
16
17 struct maps {
18 struct rb_root entries;
19 struct rb_root names;
20 struct rw_semaphore lock;
21 };
22
23 void maps__insert(struct maps *maps, struct map *map);
24 void maps__remove(struct maps *maps, struct map *map);
25 struct map *maps__find(struct maps *maps, u64 addr);
26 struct map *maps__first(struct maps *maps);
27 struct map *map__next(struct map *map);
28 struct symbol *maps__find_symbol_by_name(struct maps *maps, const char *name, struct map **mapp);
29
30 struct map_groups {
31 struct maps maps;
32 struct machine *machine;
33 refcount_t refcnt;
34 #ifdef HAVE_LIBUNWIND_SUPPORT
35 void *addr_space;
36 struct unwind_libunwind_ops *unwind_libunwind_ops;
37 #endif
38 };
39
40 #define KMAP_NAME_LEN 256
41
42 struct kmap {
43 struct ref_reloc_sym *ref_reloc_sym;
44 struct map_groups *kmaps;
45 char name[KMAP_NAME_LEN];
46 };
47
48 struct map_groups *map_groups__new(struct machine *machine);
49 void map_groups__delete(struct map_groups *mg);
50 bool map_groups__empty(struct map_groups *mg);
51
map_groups__get(struct map_groups * mg)52 static inline struct map_groups *map_groups__get(struct map_groups *mg)
53 {
54 if (mg)
55 refcount_inc(&mg->refcnt);
56 return mg;
57 }
58
59 void map_groups__put(struct map_groups *mg);
60 void map_groups__init(struct map_groups *mg, struct machine *machine);
61 void map_groups__exit(struct map_groups *mg);
62 int map_groups__clone(struct thread *thread, struct map_groups *parent);
63 size_t map_groups__fprintf(struct map_groups *mg, FILE *fp);
64
65 void map_groups__insert(struct map_groups *mg, struct map *map);
66
map_groups__remove(struct map_groups * mg,struct map * map)67 static inline void map_groups__remove(struct map_groups *mg, struct map *map)
68 {
69 maps__remove(&mg->maps, map);
70 }
71
map_groups__find(struct map_groups * mg,u64 addr)72 static inline struct map *map_groups__find(struct map_groups *mg, u64 addr)
73 {
74 return maps__find(&mg->maps, addr);
75 }
76
77 struct map *map_groups__first(struct map_groups *mg);
78
map_groups__next(struct map * map)79 static inline struct map *map_groups__next(struct map *map)
80 {
81 return map__next(map);
82 }
83
84 struct symbol *map_groups__find_symbol(struct map_groups *mg, u64 addr, struct map **mapp);
85 struct symbol *map_groups__find_symbol_by_name(struct map_groups *mg, const char *name, struct map **mapp);
86
87 struct addr_map_symbol;
88
89 int map_groups__find_ams(struct addr_map_symbol *ams);
90
91 int map_groups__fixup_overlappings(struct map_groups *mg, struct map *map, FILE *fp);
92
93 struct map *map_groups__find_by_name(struct map_groups *mg, const char *name);
94
95 int map_groups__merge_in(struct map_groups *kmaps, struct map *new_map);
96
97 #endif // __PERF_MAP_GROUPS_H
98