Arnaldo Carvalho de Melo | 41f3091 | 2019-01-27 13:44:29 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Arnaldo Carvalho de Melo | c54d241 | 2019-11-25 22:24:10 -0300 | [diff] [blame] | 2 | #ifndef __PERF_MAPS_H |
| 3 | #define __PERF_MAPS_H |
Arnaldo Carvalho de Melo | 41f3091 | 2019-01-27 13:44:29 +0100 | [diff] [blame] | 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; |
Arnaldo Carvalho de Melo | 79b6bb7 | 2019-11-25 21:58:33 -0300 | [diff] [blame] | 15 | struct maps; |
Arnaldo Carvalho de Melo | 41f3091 | 2019-01-27 13:44:29 +0100 | [diff] [blame] | 16 | struct thread; |
| 17 | |
Arnaldo Carvalho de Melo | 41f3091 | 2019-01-27 13:44:29 +0100 | [diff] [blame] | 18 | struct map *maps__find(struct maps *maps, u64 addr); |
| 19 | struct map *maps__first(struct maps *maps); |
| 20 | struct map *map__next(struct map *map); |
Arnaldo Carvalho de Melo | 8efc4f0 | 2019-10-28 11:31:38 -0300 | [diff] [blame] | 21 | |
| 22 | #define maps__for_each_entry(maps, map) \ |
| 23 | for (map = maps__first(maps); map; map = map__next(map)) |
| 24 | |
| 25 | #define maps__for_each_entry_safe(maps, map, next) \ |
| 26 | for (map = maps__first(maps), next = map__next(map); map; map = next, next = map__next(map)) |
| 27 | |
Arnaldo Carvalho de Melo | 79b6bb7 | 2019-11-25 21:58:33 -0300 | [diff] [blame] | 28 | struct maps { |
| 29 | struct rb_root entries; |
| 30 | struct rw_semaphore lock; |
Arnaldo Carvalho de Melo | 41f3091 | 2019-01-27 13:44:29 +0100 | [diff] [blame] | 31 | struct machine *machine; |
Arnaldo Carvalho de Melo | 1ae1451 | 2019-11-13 16:33:33 -0300 | [diff] [blame] | 32 | struct map *last_search_by_name; |
Arnaldo Carvalho de Melo | a7c2b57 | 2019-11-17 11:38:13 -0300 | [diff] [blame] | 33 | struct map **maps_by_name; |
Arnaldo Carvalho de Melo | 41f3091 | 2019-01-27 13:44:29 +0100 | [diff] [blame] | 34 | refcount_t refcnt; |
Arnaldo Carvalho de Melo | a7c2b57 | 2019-11-17 11:38:13 -0300 | [diff] [blame] | 35 | unsigned int nr_maps; |
| 36 | unsigned int nr_maps_allocated; |
John Keeping | e8ba290 | 2019-08-15 11:01:45 +0100 | [diff] [blame] | 37 | #ifdef HAVE_LIBUNWIND_SUPPORT |
| 38 | void *addr_space; |
| 39 | struct unwind_libunwind_ops *unwind_libunwind_ops; |
| 40 | #endif |
Arnaldo Carvalho de Melo | 41f3091 | 2019-01-27 13:44:29 +0100 | [diff] [blame] | 41 | }; |
| 42 | |
| 43 | #define KMAP_NAME_LEN 256 |
| 44 | |
| 45 | struct kmap { |
| 46 | struct ref_reloc_sym *ref_reloc_sym; |
Arnaldo Carvalho de Melo | 79b6bb7 | 2019-11-25 21:58:33 -0300 | [diff] [blame] | 47 | struct maps *kmaps; |
Arnaldo Carvalho de Melo | 41f3091 | 2019-01-27 13:44:29 +0100 | [diff] [blame] | 48 | char name[KMAP_NAME_LEN]; |
| 49 | }; |
| 50 | |
Arnaldo Carvalho de Melo | 79b6bb7 | 2019-11-25 21:58:33 -0300 | [diff] [blame] | 51 | struct maps *maps__new(struct machine *machine); |
Arnaldo Carvalho de Melo | 9a29cee | 2019-11-25 22:21:28 -0300 | [diff] [blame] | 52 | void maps__delete(struct maps *maps); |
| 53 | bool maps__empty(struct maps *maps); |
Arnaldo Carvalho de Melo | 41f3091 | 2019-01-27 13:44:29 +0100 | [diff] [blame] | 54 | |
Arnaldo Carvalho de Melo | 9a29cee | 2019-11-25 22:21:28 -0300 | [diff] [blame] | 55 | static inline struct maps *maps__get(struct maps *maps) |
Arnaldo Carvalho de Melo | 41f3091 | 2019-01-27 13:44:29 +0100 | [diff] [blame] | 56 | { |
Arnaldo Carvalho de Melo | 9a29cee | 2019-11-25 22:21:28 -0300 | [diff] [blame] | 57 | if (maps) |
| 58 | refcount_inc(&maps->refcnt); |
| 59 | return maps; |
Arnaldo Carvalho de Melo | 41f3091 | 2019-01-27 13:44:29 +0100 | [diff] [blame] | 60 | } |
| 61 | |
Arnaldo Carvalho de Melo | 9a29cee | 2019-11-25 22:21:28 -0300 | [diff] [blame] | 62 | void maps__put(struct maps *maps); |
| 63 | void maps__init(struct maps *maps, struct machine *machine); |
| 64 | void maps__exit(struct maps *maps); |
Arnaldo Carvalho de Melo | 79b6bb7 | 2019-11-25 21:58:33 -0300 | [diff] [blame] | 65 | int maps__clone(struct thread *thread, struct maps *parent); |
Arnaldo Carvalho de Melo | 9a29cee | 2019-11-25 22:21:28 -0300 | [diff] [blame] | 66 | size_t maps__fprintf(struct maps *maps, FILE *fp); |
Arnaldo Carvalho de Melo | 41f3091 | 2019-01-27 13:44:29 +0100 | [diff] [blame] | 67 | |
Arnaldo Carvalho de Melo | 9a29cee | 2019-11-25 22:21:28 -0300 | [diff] [blame] | 68 | void maps__insert(struct maps *maps, struct map *map); |
Arnaldo Carvalho de Melo | 41f3091 | 2019-01-27 13:44:29 +0100 | [diff] [blame] | 69 | |
Arnaldo Carvalho de Melo | 9a29cee | 2019-11-25 22:21:28 -0300 | [diff] [blame] | 70 | void maps__remove(struct maps *maps, struct map *map); |
Arnaldo Carvalho de Melo | 41f3091 | 2019-01-27 13:44:29 +0100 | [diff] [blame] | 71 | |
Arnaldo Carvalho de Melo | 9a29cee | 2019-11-25 22:21:28 -0300 | [diff] [blame] | 72 | struct symbol *maps__find_symbol(struct maps *maps, u64 addr, struct map **mapp); |
| 73 | struct symbol *maps__find_symbol_by_name(struct maps *maps, const char *name, struct map **mapp); |
Arnaldo Carvalho de Melo | 41f3091 | 2019-01-27 13:44:29 +0100 | [diff] [blame] | 74 | |
| 75 | struct addr_map_symbol; |
| 76 | |
Arnaldo Carvalho de Melo | 9a29cee | 2019-11-25 22:21:28 -0300 | [diff] [blame] | 77 | int maps__find_ams(struct maps *maps, struct addr_map_symbol *ams); |
Arnaldo Carvalho de Melo | 41f3091 | 2019-01-27 13:44:29 +0100 | [diff] [blame] | 78 | |
Arnaldo Carvalho de Melo | 9a29cee | 2019-11-25 22:21:28 -0300 | [diff] [blame] | 79 | int maps__fixup_overlappings(struct maps *maps, struct map *map, FILE *fp); |
Arnaldo Carvalho de Melo | 41f3091 | 2019-01-27 13:44:29 +0100 | [diff] [blame] | 80 | |
Arnaldo Carvalho de Melo | 9a29cee | 2019-11-25 22:21:28 -0300 | [diff] [blame] | 81 | struct map *maps__find_by_name(struct maps *maps, const char *name); |
Arnaldo Carvalho de Melo | 41f3091 | 2019-01-27 13:44:29 +0100 | [diff] [blame] | 82 | |
Arnaldo Carvalho de Melo | 79b6bb7 | 2019-11-25 21:58:33 -0300 | [diff] [blame] | 83 | int maps__merge_in(struct maps *kmaps, struct map *new_map); |
Jiri Olsa | 4f600bc | 2019-05-08 15:20:07 +0200 | [diff] [blame] | 84 | |
Arnaldo Carvalho de Melo | 9a29cee | 2019-11-25 22:21:28 -0300 | [diff] [blame] | 85 | void __maps__sort_by_name(struct maps *maps); |
Arnaldo Carvalho de Melo | a7c2b57 | 2019-11-17 11:38:13 -0300 | [diff] [blame] | 86 | |
Arnaldo Carvalho de Melo | c54d241 | 2019-11-25 22:24:10 -0300 | [diff] [blame] | 87 | #endif // __PERF_MAPS_H |