Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef __PERF_MAP_H
0003 #define __PERF_MAP_H
0004 
0005 #include <linux/refcount.h>
0006 #include <linux/compiler.h>
0007 #include <linux/list.h>
0008 #include <linux/rbtree.h>
0009 #include <stdio.h>
0010 #include <string.h>
0011 #include <stdbool.h>
0012 #include <linux/types.h>
0013 
0014 struct dso;
0015 struct maps;
0016 struct machine;
0017 
0018 struct map {
0019     union {
0020         struct rb_node  rb_node;
0021         struct list_head node;
0022     };
0023     u64         start;
0024     u64         end;
0025     bool            erange_warned:1;
0026     bool            priv:1;
0027     u32         prot;
0028     u64         pgoff;
0029     u64         reloc;
0030 
0031     /* ip -> dso rip */
0032     u64         (*map_ip)(const struct map *, u64);
0033     /* dso rip -> ip */
0034     u64         (*unmap_ip)(const struct map *, u64);
0035 
0036     struct dso      *dso;
0037     refcount_t      refcnt;
0038     u32         flags;
0039 };
0040 
0041 struct kmap;
0042 
0043 struct kmap *__map__kmap(struct map *map);
0044 struct kmap *map__kmap(struct map *map);
0045 struct maps *map__kmaps(struct map *map);
0046 
0047 /* ip -> dso rip */
0048 u64 map__map_ip(const struct map *map, u64 ip);
0049 /* dso rip -> ip */
0050 u64 map__unmap_ip(const struct map *map, u64 ip);
0051 /* Returns ip */
0052 u64 identity__map_ip(const struct map *map __maybe_unused, u64 ip);
0053 
0054 static inline size_t map__size(const struct map *map)
0055 {
0056     return map->end - map->start;
0057 }
0058 
0059 /* rip/ip <-> addr suitable for passing to `objdump --start-address=` */
0060 u64 map__rip_2objdump(struct map *map, u64 rip);
0061 
0062 /* objdump address -> memory address */
0063 u64 map__objdump_2mem(struct map *map, u64 ip);
0064 
0065 struct symbol;
0066 struct thread;
0067 
0068 /* map__for_each_symbol - iterate over the symbols in the given map
0069  *
0070  * @map: the 'struct map *' in which symbols are iterated
0071  * @pos: the 'struct symbol *' to use as a loop cursor
0072  * @n: the 'struct rb_node *' to use as a temporary storage
0073  * Note: caller must ensure map->dso is not NULL (map is loaded).
0074  */
0075 #define map__for_each_symbol(map, pos, n)   \
0076     dso__for_each_symbol(map->dso, pos, n)
0077 
0078 /* map__for_each_symbol_with_name - iterate over the symbols in the given map
0079  *                                  that have the given name
0080  *
0081  * @map: the 'struct map *' in which symbols are iterated
0082  * @sym_name: the symbol name
0083  * @pos: the 'struct symbol *' to use as a loop cursor
0084  */
0085 #define __map__for_each_symbol_by_name(map, sym_name, pos)  \
0086     for (pos = map__find_symbol_by_name(map, sym_name); \
0087          pos &&                     \
0088          !symbol__match_symbol_name(pos->name, sym_name,    \
0089                     SYMBOL_TAG_INCLUDE__DEFAULT_ONLY); \
0090          pos = symbol__next_by_name(pos))
0091 
0092 #define map__for_each_symbol_by_name(map, sym_name, pos)        \
0093     __map__for_each_symbol_by_name(map, sym_name, (pos))
0094 
0095 void map__init(struct map *map,
0096            u64 start, u64 end, u64 pgoff, struct dso *dso);
0097 
0098 struct dso_id;
0099 struct build_id;
0100 
0101 struct map *map__new(struct machine *machine, u64 start, u64 len,
0102              u64 pgoff, struct dso_id *id, u32 prot, u32 flags,
0103              struct build_id *bid, char *filename, struct thread *thread);
0104 struct map *map__new2(u64 start, struct dso *dso);
0105 void map__delete(struct map *map);
0106 struct map *map__clone(struct map *map);
0107 
0108 static inline struct map *map__get(struct map *map)
0109 {
0110     if (map)
0111         refcount_inc(&map->refcnt);
0112     return map;
0113 }
0114 
0115 void map__put(struct map *map);
0116 
0117 static inline void __map__zput(struct map **map)
0118 {
0119     map__put(*map);
0120     *map = NULL;
0121 }
0122 
0123 #define map__zput(map) __map__zput(&map)
0124 
0125 size_t map__fprintf(struct map *map, FILE *fp);
0126 size_t map__fprintf_dsoname(struct map *map, FILE *fp);
0127 char *map__srcline(struct map *map, u64 addr, struct symbol *sym);
0128 int map__fprintf_srcline(struct map *map, u64 addr, const char *prefix,
0129              FILE *fp);
0130 
0131 int map__load(struct map *map);
0132 struct symbol *map__find_symbol(struct map *map, u64 addr);
0133 struct symbol *map__find_symbol_by_name(struct map *map, const char *name);
0134 void map__fixup_start(struct map *map);
0135 void map__fixup_end(struct map *map);
0136 
0137 int map__set_kallsyms_ref_reloc_sym(struct map *map, const char *symbol_name,
0138                     u64 addr);
0139 
0140 bool __map__is_kernel(const struct map *map);
0141 bool __map__is_extra_kernel_map(const struct map *map);
0142 bool __map__is_bpf_prog(const struct map *map);
0143 bool __map__is_bpf_image(const struct map *map);
0144 bool __map__is_ool(const struct map *map);
0145 
0146 static inline bool __map__is_kmodule(const struct map *map)
0147 {
0148     return !__map__is_kernel(map) && !__map__is_extra_kernel_map(map) &&
0149            !__map__is_bpf_prog(map) && !__map__is_ool(map) &&
0150            !__map__is_bpf_image(map);
0151 }
0152 
0153 bool map__has_symbols(const struct map *map);
0154 
0155 bool map__contains_symbol(const struct map *map, const struct symbol *sym);
0156 
0157 #define ENTRY_TRAMPOLINE_NAME "__entry_SYSCALL_64_trampoline"
0158 
0159 static inline bool is_entry_trampoline(const char *name)
0160 {
0161     return !strcmp(name, ENTRY_TRAMPOLINE_NAME);
0162 }
0163 
0164 static inline bool is_bpf_image(const char *name)
0165 {
0166     return strncmp(name, "bpf_trampoline_", sizeof("bpf_trampoline_") - 1) == 0 ||
0167            strncmp(name, "bpf_dispatcher_", sizeof("bpf_dispatcher_") - 1) == 0;
0168 }
0169 
0170 static inline int is_anon_memory(const char *filename)
0171 {
0172     return !strcmp(filename, "//anon") ||
0173            !strncmp(filename, "/dev/zero", sizeof("/dev/zero") - 1) ||
0174            !strncmp(filename, "/anon_hugepage", sizeof("/anon_hugepage") - 1);
0175 }
0176 
0177 static inline int is_no_dso_memory(const char *filename)
0178 {
0179     return !strncmp(filename, "[stack", 6) ||
0180            !strncmp(filename, "/SYSV", 5)  ||
0181            !strcmp(filename, "[heap]");
0182 }
0183 #endif /* __PERF_MAP_H */