blob: 3dd000ddf925c4d71d4371855f1b1172d5e7001e [file] [log] [blame]
Arnaldo Carvalho de Melo41f30912019-01-27 13:44:29 +01001/* SPDX-License-Identifier: GPL-2.0 */
Arnaldo Carvalho de Meloc54d2412019-11-25 22:24:10 -03002#ifndef __PERF_MAPS_H
3#define __PERF_MAPS_H
Arnaldo Carvalho de Melo41f30912019-01-27 13:44:29 +01004
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
12struct ref_reloc_sym;
13struct machine;
14struct map;
Arnaldo Carvalho de Melo79b6bb72019-11-25 21:58:33 -030015struct maps;
Arnaldo Carvalho de Melo41f30912019-01-27 13:44:29 +010016struct thread;
17
Arnaldo Carvalho de Melo41f30912019-01-27 13:44:29 +010018struct map *maps__find(struct maps *maps, u64 addr);
19struct map *maps__first(struct maps *maps);
20struct map *map__next(struct map *map);
Arnaldo Carvalho de Melo8efc4f02019-10-28 11:31:38 -030021
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 Melo79b6bb72019-11-25 21:58:33 -030028struct maps {
29 struct rb_root entries;
30 struct rw_semaphore lock;
Arnaldo Carvalho de Melo41f30912019-01-27 13:44:29 +010031 struct machine *machine;
Arnaldo Carvalho de Melo1ae14512019-11-13 16:33:33 -030032 struct map *last_search_by_name;
Arnaldo Carvalho de Meloa7c2b572019-11-17 11:38:13 -030033 struct map **maps_by_name;
Arnaldo Carvalho de Melo41f30912019-01-27 13:44:29 +010034 refcount_t refcnt;
Arnaldo Carvalho de Meloa7c2b572019-11-17 11:38:13 -030035 unsigned int nr_maps;
36 unsigned int nr_maps_allocated;
John Keepinge8ba2902019-08-15 11:01:45 +010037#ifdef HAVE_LIBUNWIND_SUPPORT
38 void *addr_space;
39 struct unwind_libunwind_ops *unwind_libunwind_ops;
40#endif
Arnaldo Carvalho de Melo41f30912019-01-27 13:44:29 +010041};
42
43#define KMAP_NAME_LEN 256
44
45struct kmap {
46 struct ref_reloc_sym *ref_reloc_sym;
Arnaldo Carvalho de Melo79b6bb72019-11-25 21:58:33 -030047 struct maps *kmaps;
Arnaldo Carvalho de Melo41f30912019-01-27 13:44:29 +010048 char name[KMAP_NAME_LEN];
49};
50
Arnaldo Carvalho de Melo79b6bb72019-11-25 21:58:33 -030051struct maps *maps__new(struct machine *machine);
Arnaldo Carvalho de Melo9a29cee2019-11-25 22:21:28 -030052void maps__delete(struct maps *maps);
53bool maps__empty(struct maps *maps);
Arnaldo Carvalho de Melo41f30912019-01-27 13:44:29 +010054
Arnaldo Carvalho de Melo9a29cee2019-11-25 22:21:28 -030055static inline struct maps *maps__get(struct maps *maps)
Arnaldo Carvalho de Melo41f30912019-01-27 13:44:29 +010056{
Arnaldo Carvalho de Melo9a29cee2019-11-25 22:21:28 -030057 if (maps)
58 refcount_inc(&maps->refcnt);
59 return maps;
Arnaldo Carvalho de Melo41f30912019-01-27 13:44:29 +010060}
61
Arnaldo Carvalho de Melo9a29cee2019-11-25 22:21:28 -030062void maps__put(struct maps *maps);
63void maps__init(struct maps *maps, struct machine *machine);
64void maps__exit(struct maps *maps);
Arnaldo Carvalho de Melo79b6bb72019-11-25 21:58:33 -030065int maps__clone(struct thread *thread, struct maps *parent);
Arnaldo Carvalho de Melo9a29cee2019-11-25 22:21:28 -030066size_t maps__fprintf(struct maps *maps, FILE *fp);
Arnaldo Carvalho de Melo41f30912019-01-27 13:44:29 +010067
Arnaldo Carvalho de Melo9a29cee2019-11-25 22:21:28 -030068void maps__insert(struct maps *maps, struct map *map);
Arnaldo Carvalho de Melo41f30912019-01-27 13:44:29 +010069
Arnaldo Carvalho de Melo9a29cee2019-11-25 22:21:28 -030070void maps__remove(struct maps *maps, struct map *map);
Arnaldo Carvalho de Melo41f30912019-01-27 13:44:29 +010071
Arnaldo Carvalho de Melo9a29cee2019-11-25 22:21:28 -030072struct symbol *maps__find_symbol(struct maps *maps, u64 addr, struct map **mapp);
73struct symbol *maps__find_symbol_by_name(struct maps *maps, const char *name, struct map **mapp);
Arnaldo Carvalho de Melo41f30912019-01-27 13:44:29 +010074
75struct addr_map_symbol;
76
Arnaldo Carvalho de Melo9a29cee2019-11-25 22:21:28 -030077int maps__find_ams(struct maps *maps, struct addr_map_symbol *ams);
Arnaldo Carvalho de Melo41f30912019-01-27 13:44:29 +010078
Arnaldo Carvalho de Melo9a29cee2019-11-25 22:21:28 -030079int maps__fixup_overlappings(struct maps *maps, struct map *map, FILE *fp);
Arnaldo Carvalho de Melo41f30912019-01-27 13:44:29 +010080
Arnaldo Carvalho de Melo9a29cee2019-11-25 22:21:28 -030081struct map *maps__find_by_name(struct maps *maps, const char *name);
Arnaldo Carvalho de Melo41f30912019-01-27 13:44:29 +010082
Arnaldo Carvalho de Melo79b6bb72019-11-25 21:58:33 -030083int maps__merge_in(struct maps *kmaps, struct map *new_map);
Jiri Olsa4f600bc2019-05-08 15:20:07 +020084
Arnaldo Carvalho de Melo9a29cee2019-11-25 22:21:28 -030085void __maps__sort_by_name(struct maps *maps);
Arnaldo Carvalho de Meloa7c2b572019-11-17 11:38:13 -030086
Arnaldo Carvalho de Meloc54d2412019-11-25 22:24:10 -030087#endif // __PERF_MAPS_H