Lines Matching refs:map
12 #include "map.h"
105 void map__init(struct map *map, u64 start, u64 end, u64 pgoff, struct dso *dso)
107 map__set_start(map, start);
108 map__set_end(map, end);
109 map__set_pgoff(map, pgoff);
110 map__set_reloc(map, 0);
111 map__set_dso(map, dso__get(dso));
112 map__set_map_ip(map, map__dso_map_ip);
113 map__set_unmap_ip(map, map__dso_unmap_ip);
114 map__set_erange_warned(map, false);
115 refcount_set(map__refcnt(map), 1);
118 struct map *map__new(struct machine *machine, u64 start, u64 len,
123 struct map *result;
124 RC_STRUCT(map) *map;
128 map = malloc(sizeof(*map));
129 if (ADD_RC_CHK(result, map)) {
138 map->prot = prot;
139 map->flags = flags;
144 "/tmp/perf-%d.map", nsinfo__pid(nsi));
175 map->map_ip = map->unmap_ip = identity__map_ip;
221 struct map *map__new2(u64 start, struct dso *dso)
223 struct map *result;
224 RC_STRUCT(map) *map;
226 map = calloc(1, sizeof(*map) + (dso->kernel ? sizeof(struct kmap) : 0));
227 if (ADD_RC_CHK(result, map)) {
237 bool __map__is_kernel(const struct map *map)
239 if (!map__dso(map)->kernel)
241 return machine__kernel_map(maps__machine(map__kmaps((struct map *)map))) == map;
244 bool __map__is_extra_kernel_map(const struct map *map)
246 struct kmap *kmap = __map__kmap((struct map *)map);
251 bool __map__is_bpf_prog(const struct map *map)
254 struct dso *dso = map__dso(map);
268 bool __map__is_bpf_image(const struct map *map)
271 struct dso *dso = map__dso(map);
285 bool __map__is_ool(const struct map *map)
287 const struct dso *dso = map__dso(map);
292 bool map__has_symbols(const struct map *map)
294 return dso__has_symbols(map__dso(map));
297 static void map__exit(struct map *map)
299 BUG_ON(refcount_read(map__refcnt(map)) != 0);
300 dso__zput(RC_CHK_ACCESS(map)->dso);
303 void map__delete(struct map *map)
305 map__exit(map);
306 RC_CHK_FREE(map);
309 void map__put(struct map *map)
311 if (map && refcount_dec_and_test(map__refcnt(map)))
312 map__delete(map);
314 RC_CHK_PUT(map);
317 void map__fixup_start(struct map *map)
319 struct dso *dso = map__dso(map);
326 map__set_start(map, sym->start);
330 void map__fixup_end(struct map *map)
332 struct dso *dso = map__dso(map);
338 map__set_end(map, sym->end);
344 int map__load(struct map *map)
346 struct dso *dso = map__dso(map);
353 nr = dso__load(dso, map);
385 struct symbol *map__find_symbol(struct map *map, u64 addr)
387 if (map__load(map) < 0)
390 return dso__find_symbol(map__dso(map), addr);
393 struct symbol *map__find_symbol_by_name_idx(struct map *map, const char *name, size_t *idx)
397 if (map__load(map) < 0)
400 dso = map__dso(map);
406 struct symbol *map__find_symbol_by_name(struct map *map, const char *name)
410 return map__find_symbol_by_name_idx(map, name, &idx);
413 struct map *map__clone(struct map *from)
415 struct map *result;
416 RC_STRUCT(map) *map;
417 size_t size = sizeof(RC_STRUCT(map));
423 map = memdup(RC_CHK_ACCESS(from), size);
424 if (ADD_RC_CHK(result, map)) {
425 refcount_set(&map->refcnt, 1);
426 map->dso = dso__get(dso);
432 size_t map__fprintf(struct map *map, FILE *fp)
434 const struct dso *dso = map__dso(map);
437 map__start(map), map__end(map), map__pgoff(map), dso->name);
447 static size_t __map__fprintf_dsoname(struct map *map, bool print_off, FILE *fp)
451 const struct dso *dso = map ? map__dso(map) : NULL;
468 size_t map__fprintf_dsoname(struct map *map, FILE *fp)
470 return __map__fprintf_dsoname(map, false, fp);
473 size_t map__fprintf_dsoname_dsoff(struct map *map, bool print_off, u64 addr, FILE *fp)
475 const struct dso *dso = map ? map__dso(map) : NULL;
481 printed += __map__fprintf_dsoname(map, print_off, fp);
489 char *map__srcline(struct map *map, u64 addr, struct symbol *sym)
491 if (map == NULL)
494 return get_srcline(map__dso(map), map__rip_2objdump(map, addr), sym, true, true, addr);
497 int map__fprintf_srcline(struct map *map, u64 addr, const char *prefix,
500 const struct dso *dso = map ? map__dso(map) : NULL;
504 char *srcline = map__srcline(map, addr, NULL);
520 * @map: memory map
524 * map->dso->adjust_symbols==1 for ET_EXEC-like cases except ET_REL which is
529 u64 map__rip_2objdump(struct map *map, u64 rip)
531 struct kmap *kmap = __map__kmap(map);
532 const struct dso *dso = map__dso(map);
537 * main kernel map, so just use that instead.
543 struct map *kernel_map = machine__kernel_map(machine);
546 map = kernel_map;
554 return rip - map__pgoff(map);
563 return map__unmap_ip(map, rip) - map__reloc(map);
568 * @map: memory map
572 * objdump and converts it to a memory address. Note this assumes that @map
574 * e.g. map__rip_2objdump(map__map_ip(map, map__objdump_2mem(map, ip))) == ip
578 u64 map__objdump_2mem(struct map *map, u64 ip)
580 const struct dso *dso = map__dso(map);
583 return map__unmap_ip(map, ip);
586 return map__unmap_ip(map, ip + map__pgoff(map));
593 return map__unmap_ip(map, ip - dso->text_offset);
595 return ip + map__reloc(map);
598 bool map__contains_symbol(const struct map *map, const struct symbol *sym)
600 u64 ip = map__unmap_ip(map, sym->start);
602 return ip >= map__start(map) && ip < map__end(map);
605 struct kmap *__map__kmap(struct map *map)
607 const struct dso *dso = map__dso(map);
611 return (struct kmap *)(&RC_CHK_ACCESS(map)[1]);
614 struct kmap *map__kmap(struct map *map)
616 struct kmap *kmap = __map__kmap(map);
619 pr_err("Internal error: map__kmap with a non-kernel map\n");
623 struct maps *map__kmaps(struct map *map)
625 struct kmap *kmap = map__kmap(map);
628 pr_err("Internal error: map__kmaps with a non-kernel map\n");
634 u64 map__dso_map_ip(const struct map *map, u64 ip)
636 return ip - map__start(map) + map__pgoff(map);
639 u64 map__dso_unmap_ip(const struct map *map, u64 ip)
641 return ip + map__start(map) - map__pgoff(map);
644 u64 identity__map_ip(const struct map *map __maybe_unused, u64 ip)