Loading...
1/* SPDX-License-Identifier: GPL-2.0 */
2#ifndef __PERF_MAPS_H
3#define __PERF_MAPS_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#include <internal/rc_check.h>
12
13struct ref_reloc_sym;
14struct machine;
15struct map;
16struct maps;
17
18struct map_list_node {
19 struct list_head node;
20 struct map *map;
21};
22
23static inline struct map_list_node *map_list_node__new(void)
24{
25 return malloc(sizeof(struct map_list_node));
26}
27
28struct map *maps__find(struct maps *maps, u64 addr);
29
30DECLARE_RC_STRUCT(maps) {
31 struct rb_root entries;
32 struct rw_semaphore lock;
33 struct machine *machine;
34 struct map *last_search_by_name;
35 struct map **maps_by_name;
36 refcount_t refcnt;
37 unsigned int nr_maps;
38 unsigned int nr_maps_allocated;
39#ifdef HAVE_LIBUNWIND_SUPPORT
40 void *addr_space;
41 const struct unwind_libunwind_ops *unwind_libunwind_ops;
42#endif
43};
44
45#define KMAP_NAME_LEN 256
46
47struct kmap {
48 struct ref_reloc_sym *ref_reloc_sym;
49 struct maps *kmaps;
50 char name[KMAP_NAME_LEN];
51};
52
53struct maps *maps__new(struct machine *machine);
54bool maps__empty(struct maps *maps);
55int maps__copy_from(struct maps *maps, struct maps *parent);
56
57struct maps *maps__get(struct maps *maps);
58void maps__put(struct maps *maps);
59
60static inline void __maps__zput(struct maps **map)
61{
62 maps__put(*map);
63 *map = NULL;
64}
65
66#define maps__zput(map) __maps__zput(&map)
67
68/* Iterate over map calling cb for each entry. */
69int maps__for_each_map(struct maps *maps, int (*cb)(struct map *map, void *data), void *data);
70/* Iterate over map removing an entry if cb returns true. */
71void maps__remove_maps(struct maps *maps, bool (*cb)(struct map *map, void *data), void *data);
72
73static inline struct machine *maps__machine(struct maps *maps)
74{
75 return RC_CHK_ACCESS(maps)->machine;
76}
77
78static inline unsigned int maps__nr_maps(const struct maps *maps)
79{
80 return RC_CHK_ACCESS(maps)->nr_maps;
81}
82
83static inline refcount_t *maps__refcnt(struct maps *maps)
84{
85 return &RC_CHK_ACCESS(maps)->refcnt;
86}
87
88#ifdef HAVE_LIBUNWIND_SUPPORT
89static inline void *maps__addr_space(struct maps *maps)
90{
91 return RC_CHK_ACCESS(maps)->addr_space;
92}
93
94static inline const struct unwind_libunwind_ops *maps__unwind_libunwind_ops(const struct maps *maps)
95{
96 return RC_CHK_ACCESS(maps)->unwind_libunwind_ops;
97}
98#endif
99
100size_t maps__fprintf(struct maps *maps, FILE *fp);
101
102int maps__insert(struct maps *maps, struct map *map);
103void maps__remove(struct maps *maps, struct map *map);
104
105struct symbol *maps__find_symbol(struct maps *maps, u64 addr, struct map **mapp);
106struct symbol *maps__find_symbol_by_name(struct maps *maps, const char *name, struct map **mapp);
107
108struct addr_map_symbol;
109
110int maps__find_ams(struct maps *maps, struct addr_map_symbol *ams);
111
112int maps__fixup_overlap_and_insert(struct maps *maps, struct map *new);
113
114struct map *maps__find_by_name(struct maps *maps, const char *name);
115
116struct map *maps__find_next_entry(struct maps *maps, struct map *map);
117
118int maps__merge_in(struct maps *kmaps, struct map *new_map);
119
120void __maps__sort_by_name(struct maps *maps);
121
122void maps__fixup_end(struct maps *maps);
123
124void maps__load_first(struct maps *maps);
125
126#endif // __PERF_MAPS_H
1/* SPDX-License-Identifier: GPL-2.0 */
2#ifndef __PERF_MAPS_H
3#define __PERF_MAPS_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
12struct ref_reloc_sym;
13struct machine;
14struct map;
15struct maps;
16struct thread;
17
18struct map *maps__find(struct maps *maps, u64 addr);
19struct map *maps__first(struct maps *maps);
20struct map *map__next(struct map *map);
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
28struct maps {
29 struct rb_root entries;
30 struct rw_semaphore lock;
31 struct machine *machine;
32 struct map *last_search_by_name;
33 struct map **maps_by_name;
34 refcount_t refcnt;
35 unsigned int nr_maps;
36 unsigned int nr_maps_allocated;
37#ifdef HAVE_LIBUNWIND_SUPPORT
38 void *addr_space;
39 struct unwind_libunwind_ops *unwind_libunwind_ops;
40#endif
41};
42
43#define KMAP_NAME_LEN 256
44
45struct kmap {
46 struct ref_reloc_sym *ref_reloc_sym;
47 struct maps *kmaps;
48 char name[KMAP_NAME_LEN];
49};
50
51struct maps *maps__new(struct machine *machine);
52void maps__delete(struct maps *maps);
53bool maps__empty(struct maps *maps);
54
55static inline struct maps *maps__get(struct maps *maps)
56{
57 if (maps)
58 refcount_inc(&maps->refcnt);
59 return maps;
60}
61
62void maps__put(struct maps *maps);
63int maps__clone(struct thread *thread, struct maps *parent);
64size_t maps__fprintf(struct maps *maps, FILE *fp);
65
66void maps__insert(struct maps *maps, struct map *map);
67
68void maps__remove(struct maps *maps, struct map *map);
69
70struct symbol *maps__find_symbol(struct maps *maps, u64 addr, struct map **mapp);
71struct symbol *maps__find_symbol_by_name(struct maps *maps, const char *name, struct map **mapp);
72
73struct addr_map_symbol;
74
75int maps__find_ams(struct maps *maps, struct addr_map_symbol *ams);
76
77int maps__fixup_overlappings(struct maps *maps, struct map *map, FILE *fp);
78
79struct map *maps__find_by_name(struct maps *maps, const char *name);
80
81int maps__merge_in(struct maps *kmaps, struct map *new_map);
82
83void __maps__sort_by_name(struct maps *maps);
84
85#endif // __PERF_MAPS_H