Lines Matching full:maps

8 #include "maps.h"
13 static void __maps__insert(struct maps *maps, struct map *map);
15 static void maps__init(struct maps *maps, struct machine *machine) in maps__init() argument
17 maps->entries = RB_ROOT; in maps__init()
18 init_rwsem(&maps->lock); in maps__init()
19 maps->machine = machine; in maps__init()
20 maps->last_search_by_name = NULL; in maps__init()
21 maps->nr_maps = 0; in maps__init()
22 maps->maps_by_name = NULL; in maps__init()
23 refcount_set(&maps->refcnt, 1); in maps__init()
26 static void __maps__free_maps_by_name(struct maps *maps) in __maps__free_maps_by_name() argument
31 zfree(&maps->maps_by_name); in __maps__free_maps_by_name()
32 maps->nr_maps_allocated = 0; in __maps__free_maps_by_name()
35 void maps__insert(struct maps *maps, struct map *map) in maps__insert() argument
37 down_write(&maps->lock); in maps__insert()
38 __maps__insert(maps, map); in maps__insert()
39 ++maps->nr_maps; in maps__insert()
45 kmap->kmaps = maps; in maps__insert()
55 if (maps->maps_by_name) { in maps__insert()
56 if (maps->nr_maps > maps->nr_maps_allocated) { in maps__insert()
57 int nr_allocate = maps->nr_maps * 2; in maps__insert()
58 struct map **maps_by_name = realloc(maps->maps_by_name, nr_allocate * sizeof(map)); in maps__insert()
61 __maps__free_maps_by_name(maps); in maps__insert()
62 up_write(&maps->lock); in maps__insert()
66 maps->maps_by_name = maps_by_name; in maps__insert()
67 maps->nr_maps_allocated = nr_allocate; in maps__insert()
69 maps->maps_by_name[maps->nr_maps - 1] = map; in maps__insert()
70 __maps__sort_by_name(maps); in maps__insert()
72 up_write(&maps->lock); in maps__insert()
75 static void __maps__remove(struct maps *maps, struct map *map) in __maps__remove() argument
77 rb_erase_init(&map->rb_node, &maps->entries); in __maps__remove()
81 void maps__remove(struct maps *maps, struct map *map) in maps__remove() argument
83 down_write(&maps->lock); in maps__remove()
84 if (maps->last_search_by_name == map) in maps__remove()
85 maps->last_search_by_name = NULL; in maps__remove()
87 __maps__remove(maps, map); in maps__remove()
88 --maps->nr_maps; in maps__remove()
89 if (maps->maps_by_name) in maps__remove()
90 __maps__free_maps_by_name(maps); in maps__remove()
91 up_write(&maps->lock); in maps__remove()
94 static void __maps__purge(struct maps *maps) in __maps__purge() argument
98 maps__for_each_entry_safe(maps, pos, next) { in __maps__purge()
99 rb_erase_init(&pos->rb_node, &maps->entries); in __maps__purge()
104 static void maps__exit(struct maps *maps) in maps__exit() argument
106 down_write(&maps->lock); in maps__exit()
107 __maps__purge(maps); in maps__exit()
108 up_write(&maps->lock); in maps__exit()
111 bool maps__empty(struct maps *maps) in maps__empty() argument
113 return !maps__first(maps); in maps__empty()
116 struct maps *maps__new(struct machine *machine) in maps__new()
118 struct maps *maps = zalloc(sizeof(*maps)); in maps__new() local
120 if (maps != NULL) in maps__new()
121 maps__init(maps, machine); in maps__new()
123 return maps; in maps__new()
126 void maps__delete(struct maps *maps) in maps__delete() argument
128 maps__exit(maps); in maps__delete()
129 unwind__finish_access(maps); in maps__delete()
130 free(maps); in maps__delete()
133 void maps__put(struct maps *maps) in maps__put() argument
135 if (maps && refcount_dec_and_test(&maps->refcnt)) in maps__put()
136 maps__delete(maps); in maps__put()
139 struct symbol *maps__find_symbol(struct maps *maps, u64 addr, struct map **mapp) in maps__find_symbol() argument
141 struct map *map = maps__find(maps, addr); in maps__find_symbol()
153 struct symbol *maps__find_symbol_by_name(struct maps *maps, const char *name, struct map **mapp) in maps__find_symbol_by_name() argument
158 down_read(&maps->lock); in maps__find_symbol_by_name()
160 maps__for_each_entry(maps, pos) { in maps__find_symbol_by_name()
176 up_read(&maps->lock); in maps__find_symbol_by_name()
180 int maps__find_ams(struct maps *maps, struct addr_map_symbol *ams) in maps__find_ams() argument
183 if (maps == NULL) in maps__find_ams()
185 ams->ms.map = maps__find(maps, ams->addr); in maps__find_ams()
196 size_t maps__fprintf(struct maps *maps, FILE *fp) in maps__fprintf() argument
201 down_read(&maps->lock); in maps__fprintf()
203 maps__for_each_entry(maps, pos) { in maps__fprintf()
212 up_read(&maps->lock); in maps__fprintf()
217 int maps__fixup_overlappings(struct maps *maps, struct map *map, FILE *fp) in maps__fixup_overlappings() argument
223 down_write(&maps->lock); in maps__fixup_overlappings()
225 root = &maps->entries; in maps__fixup_overlappings()
252 * Maps are ordered by start: next will not overlap for sure. in maps__fixup_overlappings()
260 pr_debug("overlapping maps in %s (disable tui for more info)\n", in maps__fixup_overlappings()
263 fputs("overlapping maps:\n", fp); in maps__fixup_overlappings()
271 * Now check if we need to create new maps for areas not in maps__fixup_overlappings()
283 __maps__insert(maps, before); in maps__fixup_overlappings()
300 __maps__insert(maps, after); in maps__fixup_overlappings()
314 up_write(&maps->lock); in maps__fixup_overlappings()
319 * XXX This should not really _copy_ te maps, but refcount them.
321 int maps__clone(struct thread *thread, struct maps *parent) in maps__clone()
323 struct maps *maps = thread->maps; in maps__clone() local
337 err = unwind__prepare_access(maps, new, NULL); in maps__clone()
341 maps__insert(maps, new); in maps__clone()
351 static void __maps__insert(struct maps *maps, struct map *map) in __maps__insert() argument
353 struct rb_node **p = &maps->entries.rb_node; in __maps__insert()
368 rb_insert_color(&map->rb_node, &maps->entries); in __maps__insert()
372 struct map *maps__find(struct maps *maps, u64 ip) in maps__find() argument
377 down_read(&maps->lock); in maps__find()
379 p = maps->entries.rb_node; in maps__find()
392 up_read(&maps->lock); in maps__find()
396 struct map *maps__first(struct maps *maps) in maps__first() argument
398 struct rb_node *first = rb_first(&maps->entries); in maps__first()