Lines Matching refs:maps

13 static void maps__init(struct maps *maps, struct machine *machine)  in maps__init()  argument
15 refcount_set(maps__refcnt(maps), 1); in maps__init()
16 init_rwsem(maps__lock(maps)); in maps__init()
17 RC_CHK_ACCESS(maps)->entries = RB_ROOT; in maps__init()
18 RC_CHK_ACCESS(maps)->machine = machine; in maps__init()
19 RC_CHK_ACCESS(maps)->last_search_by_name = NULL; in maps__init()
20 RC_CHK_ACCESS(maps)->nr_maps = 0; in maps__init()
21 RC_CHK_ACCESS(maps)->maps_by_name = NULL; in maps__init()
24 static void __maps__free_maps_by_name(struct maps *maps) in __maps__free_maps_by_name() argument
29 for (unsigned int i = 0; i < maps__nr_maps(maps); i++) in __maps__free_maps_by_name()
30 map__put(maps__maps_by_name(maps)[i]); in __maps__free_maps_by_name()
32 zfree(&RC_CHK_ACCESS(maps)->maps_by_name); in __maps__free_maps_by_name()
33 RC_CHK_ACCESS(maps)->nr_maps_allocated = 0; in __maps__free_maps_by_name()
36 static int __maps__insert(struct maps *maps, struct map *map) in __maps__insert() argument
38 struct rb_node **p = &maps__entries(maps)->rb_node; in __maps__insert()
60 rb_insert_color(&new_rb_node->rb_node, maps__entries(maps)); in __maps__insert()
64 int maps__insert(struct maps *maps, struct map *map) in maps__insert() argument
69 down_write(maps__lock(maps)); in maps__insert()
70 err = __maps__insert(maps, map); in maps__insert()
74 ++RC_CHK_ACCESS(maps)->nr_maps; in maps__insert()
80 kmap->kmaps = maps; in maps__insert()
90 if (maps__maps_by_name(maps)) { in maps__insert()
91 if (maps__nr_maps(maps) > RC_CHK_ACCESS(maps)->nr_maps_allocated) { in maps__insert()
92 int nr_allocate = maps__nr_maps(maps) * 2; in maps__insert()
93 struct map **maps_by_name = realloc(maps__maps_by_name(maps), in maps__insert()
97 __maps__free_maps_by_name(maps); in maps__insert()
102 RC_CHK_ACCESS(maps)->maps_by_name = maps_by_name; in maps__insert()
103 RC_CHK_ACCESS(maps)->nr_maps_allocated = nr_allocate; in maps__insert()
105 maps__maps_by_name(maps)[maps__nr_maps(maps) - 1] = map__get(map); in maps__insert() local
106 __maps__sort_by_name(maps); in maps__insert()
109 up_write(maps__lock(maps)); in maps__insert()
113 static void __maps__remove(struct maps *maps, struct map_rb_node *rb_node) in __maps__remove() argument
115 rb_erase_init(&rb_node->rb_node, maps__entries(maps)); in __maps__remove()
120 void maps__remove(struct maps *maps, struct map *map) in maps__remove() argument
124 down_write(maps__lock(maps)); in maps__remove()
125 if (RC_CHK_ACCESS(maps)->last_search_by_name == map) in maps__remove()
126 RC_CHK_ACCESS(maps)->last_search_by_name = NULL; in maps__remove()
128 rb_node = maps__find_node(maps, map); in maps__remove()
130 __maps__remove(maps, rb_node); in maps__remove()
131 if (maps__maps_by_name(maps)) in maps__remove()
132 __maps__free_maps_by_name(maps); in maps__remove()
133 --RC_CHK_ACCESS(maps)->nr_maps; in maps__remove()
134 up_write(maps__lock(maps)); in maps__remove()
137 static void __maps__purge(struct maps *maps) in __maps__purge() argument
141 if (maps__maps_by_name(maps)) in __maps__purge()
142 __maps__free_maps_by_name(maps); in __maps__purge()
144 maps__for_each_entry_safe(maps, pos, next) { in __maps__purge()
145 rb_erase_init(&pos->rb_node, maps__entries(maps)); in __maps__purge()
151 static void maps__exit(struct maps *maps) in maps__exit() argument
153 down_write(maps__lock(maps)); in maps__exit()
154 __maps__purge(maps); in maps__exit()
155 up_write(maps__lock(maps)); in maps__exit()
158 bool maps__empty(struct maps *maps) in maps__empty() argument
160 return !maps__first(maps); in maps__empty()
163 struct maps *maps__new(struct machine *machine) in maps__new()
165 struct maps *result; in maps__new()
166 RC_STRUCT(maps) *maps = zalloc(sizeof(*maps)); in maps__new()
168 if (ADD_RC_CHK(result, maps)) in maps__new()
174 static void maps__delete(struct maps *maps) in maps__delete() argument
176 maps__exit(maps); in maps__delete()
177 unwind__finish_access(maps); in maps__delete()
178 RC_CHK_FREE(maps); in maps__delete()
181 struct maps *maps__get(struct maps *maps) in maps__get() argument
183 struct maps *result; in maps__get()
185 if (RC_CHK_GET(result, maps)) in maps__get()
186 refcount_inc(maps__refcnt(maps)); in maps__get()
191 void maps__put(struct maps *maps) in maps__put() argument
193 if (maps && refcount_dec_and_test(maps__refcnt(maps))) in maps__put()
194 maps__delete(maps); in maps__put()
196 RC_CHK_PUT(maps); in maps__put()
199 struct symbol *maps__find_symbol(struct maps *maps, u64 addr, struct map **mapp) in maps__find_symbol() argument
201 struct map *map = maps__find(maps, addr); in maps__find_symbol()
213 struct symbol *maps__find_symbol_by_name(struct maps *maps, const char *name, struct map **mapp) in maps__find_symbol_by_name() argument
218 down_read(maps__lock(maps)); in maps__find_symbol_by_name()
220 maps__for_each_entry(maps, pos) { in maps__find_symbol_by_name()
236 up_read(maps__lock(maps)); in maps__find_symbol_by_name()
240 int maps__find_ams(struct maps *maps, struct addr_map_symbol *ams) in maps__find_ams() argument
243 if (maps == NULL) in maps__find_ams()
245 ams->ms.map = maps__find(maps, ams->addr); in maps__find_ams()
256 size_t maps__fprintf(struct maps *maps, FILE *fp) in maps__fprintf() argument
261 down_read(maps__lock(maps)); in maps__fprintf()
263 maps__for_each_entry(maps, pos) { in maps__fprintf()
272 up_read(maps__lock(maps)); in maps__fprintf()
277 int maps__fixup_overlappings(struct maps *maps, struct map *map, FILE *fp) in maps__fixup_overlappings() argument
283 down_write(maps__lock(maps)); in maps__fixup_overlappings()
285 root = maps__entries(maps); in maps__fixup_overlappings()
343 err = __maps__insert(maps, before); in maps__fixup_overlappings()
366 err = __maps__insert(maps, after); in maps__fixup_overlappings()
379 up_write(maps__lock(maps)); in maps__fixup_overlappings()
386 int maps__clone(struct thread *thread, struct maps *parent) in maps__clone()
388 struct maps *maps = thread__maps(thread); in maps__clone() local
402 err = unwind__prepare_access(maps, new, NULL); in maps__clone()
406 err = maps__insert(maps, new); in maps__clone()
419 struct map_rb_node *maps__find_node(struct maps *maps, struct map *map) in maps__find_node() argument
423 maps__for_each_entry(maps, rb_node) { in maps__find_node()
430 struct map *maps__find(struct maps *maps, u64 ip) in maps__find() argument
436 down_read(maps__lock(maps)); in maps__find()
438 p = maps__entries(maps)->rb_node; in maps__find()
451 up_read(maps__lock(maps)); in maps__find()
455 struct map_rb_node *maps__first(struct maps *maps) in maps__first() argument
457 struct rb_node *first = rb_first(maps__entries(maps)); in maps__first()