Merge tag 'block-5.11-2021-01-10' of git://git.kernel.dk/linux-block
[linux/fpc-iii.git] / tools / perf / util / map.c
blobf44ede437dc7f5a2bfe28893e2b09f456091533b
1 // SPDX-License-Identifier: GPL-2.0
2 #include "symbol.h"
3 #include <assert.h>
4 #include <errno.h>
5 #include <inttypes.h>
6 #include <limits.h>
7 #include <stdlib.h>
8 #include <string.h>
9 #include <stdio.h>
10 #include <unistd.h>
11 #include <uapi/linux/mman.h> /* To get things like MAP_HUGETLB even on older libc headers */
12 #include "dso.h"
13 #include "map.h"
14 #include "map_symbol.h"
15 #include "thread.h"
16 #include "vdso.h"
17 #include "build-id.h"
18 #include "debug.h"
19 #include "machine.h"
20 #include <linux/string.h>
21 #include <linux/zalloc.h>
22 #include "srcline.h"
23 #include "namespaces.h"
24 #include "unwind.h"
25 #include "srccode.h"
26 #include "ui/ui.h"
28 static void __maps__insert(struct maps *maps, struct map *map);
30 static inline int is_android_lib(const char *filename)
32 return strstarts(filename, "/data/app-lib/") ||
33 strstarts(filename, "/system/lib/");
36 static inline bool replace_android_lib(const char *filename, char *newfilename)
38 const char *libname;
39 char *app_abi;
40 size_t app_abi_length, new_length;
41 size_t lib_length = 0;
43 libname = strrchr(filename, '/');
44 if (libname)
45 lib_length = strlen(libname);
47 app_abi = getenv("APP_ABI");
48 if (!app_abi)
49 return false;
51 app_abi_length = strlen(app_abi);
53 if (strstarts(filename, "/data/app-lib/")) {
54 char *apk_path;
56 if (!app_abi_length)
57 return false;
59 new_length = 7 + app_abi_length + lib_length;
61 apk_path = getenv("APK_PATH");
62 if (apk_path) {
63 new_length += strlen(apk_path) + 1;
64 if (new_length > PATH_MAX)
65 return false;
66 snprintf(newfilename, new_length,
67 "%s/libs/%s/%s", apk_path, app_abi, libname);
68 } else {
69 if (new_length > PATH_MAX)
70 return false;
71 snprintf(newfilename, new_length,
72 "libs/%s/%s", app_abi, libname);
74 return true;
77 if (strstarts(filename, "/system/lib/")) {
78 char *ndk, *app;
79 const char *arch;
80 size_t ndk_length;
81 size_t app_length;
83 ndk = getenv("NDK_ROOT");
84 app = getenv("APP_PLATFORM");
86 if (!(ndk && app))
87 return false;
89 ndk_length = strlen(ndk);
90 app_length = strlen(app);
92 if (!(ndk_length && app_length && app_abi_length))
93 return false;
95 arch = !strncmp(app_abi, "arm", 3) ? "arm" :
96 !strncmp(app_abi, "mips", 4) ? "mips" :
97 !strncmp(app_abi, "x86", 3) ? "x86" : NULL;
99 if (!arch)
100 return false;
102 new_length = 27 + ndk_length +
103 app_length + lib_length
104 + strlen(arch);
106 if (new_length > PATH_MAX)
107 return false;
108 snprintf(newfilename, new_length,
109 "%s/platforms/%s/arch-%s/usr/lib/%s",
110 ndk, app, arch, libname);
112 return true;
114 return false;
117 void map__init(struct map *map, u64 start, u64 end, u64 pgoff, struct dso *dso)
119 map->start = start;
120 map->end = end;
121 map->pgoff = pgoff;
122 map->reloc = 0;
123 map->dso = dso__get(dso);
124 map->map_ip = map__map_ip;
125 map->unmap_ip = map__unmap_ip;
126 RB_CLEAR_NODE(&map->rb_node);
127 map->erange_warned = false;
128 refcount_set(&map->refcnt, 1);
131 struct map *map__new(struct machine *machine, u64 start, u64 len,
132 u64 pgoff, struct dso_id *id,
133 u32 prot, u32 flags, char *filename,
134 struct thread *thread)
136 struct map *map = malloc(sizeof(*map));
137 struct nsinfo *nsi = NULL;
138 struct nsinfo *nnsi;
140 if (map != NULL) {
141 char newfilename[PATH_MAX];
142 struct dso *dso;
143 int anon, no_dso, vdso, android;
145 android = is_android_lib(filename);
146 anon = is_anon_memory(filename) || flags & MAP_HUGETLB;
147 vdso = is_vdso_map(filename);
148 no_dso = is_no_dso_memory(filename);
149 map->prot = prot;
150 map->flags = flags;
151 nsi = nsinfo__get(thread->nsinfo);
153 if ((anon || no_dso) && nsi && (prot & PROT_EXEC)) {
154 snprintf(newfilename, sizeof(newfilename),
155 "/tmp/perf-%d.map", nsi->pid);
156 filename = newfilename;
159 if (android) {
160 if (replace_android_lib(filename, newfilename))
161 filename = newfilename;
164 if (vdso) {
165 /* The vdso maps are always on the host and not the
166 * container. Ensure that we don't use setns to look
167 * them up.
169 nnsi = nsinfo__copy(nsi);
170 if (nnsi) {
171 nsinfo__put(nsi);
172 nnsi->need_setns = false;
173 nsi = nnsi;
175 pgoff = 0;
176 dso = machine__findnew_vdso(machine, thread);
177 } else
178 dso = machine__findnew_dso_id(machine, filename, id);
180 if (dso == NULL)
181 goto out_delete;
183 map__init(map, start, start + len, pgoff, dso);
185 if (anon || no_dso) {
186 map->map_ip = map->unmap_ip = identity__map_ip;
189 * Set memory without DSO as loaded. All map__find_*
190 * functions still return NULL, and we avoid the
191 * unnecessary map__load warning.
193 if (!(prot & PROT_EXEC))
194 dso__set_loaded(dso);
196 dso->nsinfo = nsi;
197 dso__put(dso);
199 return map;
200 out_delete:
201 nsinfo__put(nsi);
202 free(map);
203 return NULL;
207 * Constructor variant for modules (where we know from /proc/modules where
208 * they are loaded) and for vmlinux, where only after we load all the
209 * symbols we'll know where it starts and ends.
211 struct map *map__new2(u64 start, struct dso *dso)
213 struct map *map = calloc(1, (sizeof(*map) +
214 (dso->kernel ? sizeof(struct kmap) : 0)));
215 if (map != NULL) {
217 * ->end will be filled after we load all the symbols
219 map__init(map, start, 0, 0, dso);
222 return map;
225 bool __map__is_kernel(const struct map *map)
227 if (!map->dso->kernel)
228 return false;
229 return machine__kernel_map(map__kmaps((struct map *)map)->machine) == map;
232 bool __map__is_extra_kernel_map(const struct map *map)
234 struct kmap *kmap = __map__kmap((struct map *)map);
236 return kmap && kmap->name[0];
239 bool __map__is_bpf_prog(const struct map *map)
241 const char *name;
243 if (map->dso->binary_type == DSO_BINARY_TYPE__BPF_PROG_INFO)
244 return true;
247 * If PERF_RECORD_BPF_EVENT is not included, the dso will not have
248 * type of DSO_BINARY_TYPE__BPF_PROG_INFO. In such cases, we can
249 * guess the type based on name.
251 name = map->dso->short_name;
252 return name && (strstr(name, "bpf_prog_") == name);
255 bool __map__is_bpf_image(const struct map *map)
257 const char *name;
259 if (map->dso->binary_type == DSO_BINARY_TYPE__BPF_IMAGE)
260 return true;
263 * If PERF_RECORD_KSYMBOL is not included, the dso will not have
264 * type of DSO_BINARY_TYPE__BPF_IMAGE. In such cases, we can
265 * guess the type based on name.
267 name = map->dso->short_name;
268 return name && is_bpf_image(name);
271 bool __map__is_ool(const struct map *map)
273 return map->dso && map->dso->binary_type == DSO_BINARY_TYPE__OOL;
276 bool map__has_symbols(const struct map *map)
278 return dso__has_symbols(map->dso);
281 static void map__exit(struct map *map)
283 BUG_ON(refcount_read(&map->refcnt) != 0);
284 dso__zput(map->dso);
287 void map__delete(struct map *map)
289 map__exit(map);
290 free(map);
293 void map__put(struct map *map)
295 if (map && refcount_dec_and_test(&map->refcnt))
296 map__delete(map);
299 void map__fixup_start(struct map *map)
301 struct rb_root_cached *symbols = &map->dso->symbols;
302 struct rb_node *nd = rb_first_cached(symbols);
303 if (nd != NULL) {
304 struct symbol *sym = rb_entry(nd, struct symbol, rb_node);
305 map->start = sym->start;
309 void map__fixup_end(struct map *map)
311 struct rb_root_cached *symbols = &map->dso->symbols;
312 struct rb_node *nd = rb_last(&symbols->rb_root);
313 if (nd != NULL) {
314 struct symbol *sym = rb_entry(nd, struct symbol, rb_node);
315 map->end = sym->end;
319 #define DSO__DELETED "(deleted)"
321 int map__load(struct map *map)
323 const char *name = map->dso->long_name;
324 int nr;
326 if (dso__loaded(map->dso))
327 return 0;
329 nr = dso__load(map->dso, map);
330 if (nr < 0) {
331 if (map->dso->has_build_id) {
332 char sbuild_id[SBUILD_ID_SIZE];
334 build_id__sprintf(&map->dso->bid, sbuild_id);
335 pr_debug("%s with build id %s not found", name, sbuild_id);
336 } else
337 pr_debug("Failed to open %s", name);
339 pr_debug(", continuing without symbols\n");
340 return -1;
341 } else if (nr == 0) {
342 #ifdef HAVE_LIBELF_SUPPORT
343 const size_t len = strlen(name);
344 const size_t real_len = len - sizeof(DSO__DELETED);
346 if (len > sizeof(DSO__DELETED) &&
347 strcmp(name + real_len + 1, DSO__DELETED) == 0) {
348 pr_debug("%.*s was updated (is prelink enabled?). "
349 "Restart the long running apps that use it!\n",
350 (int)real_len, name);
351 } else {
352 pr_debug("no symbols found in %s, maybe install a debug package?\n", name);
354 #endif
355 return -1;
358 return 0;
361 struct symbol *map__find_symbol(struct map *map, u64 addr)
363 if (map__load(map) < 0)
364 return NULL;
366 return dso__find_symbol(map->dso, addr);
369 struct symbol *map__find_symbol_by_name(struct map *map, const char *name)
371 if (map__load(map) < 0)
372 return NULL;
374 if (!dso__sorted_by_name(map->dso))
375 dso__sort_by_name(map->dso);
377 return dso__find_symbol_by_name(map->dso, name);
380 struct map *map__clone(struct map *from)
382 size_t size = sizeof(struct map);
383 struct map *map;
385 if (from->dso && from->dso->kernel)
386 size += sizeof(struct kmap);
388 map = memdup(from, size);
389 if (map != NULL) {
390 refcount_set(&map->refcnt, 1);
391 RB_CLEAR_NODE(&map->rb_node);
392 dso__get(map->dso);
395 return map;
398 size_t map__fprintf(struct map *map, FILE *fp)
400 return fprintf(fp, " %" PRIx64 "-%" PRIx64 " %" PRIx64 " %s\n",
401 map->start, map->end, map->pgoff, map->dso->name);
404 size_t map__fprintf_dsoname(struct map *map, FILE *fp)
406 char buf[symbol_conf.pad_output_len_dso + 1];
407 const char *dsoname = "[unknown]";
409 if (map && map->dso) {
410 if (symbol_conf.show_kernel_path && map->dso->long_name)
411 dsoname = map->dso->long_name;
412 else
413 dsoname = map->dso->name;
416 if (symbol_conf.pad_output_len_dso) {
417 scnprintf_pad(buf, symbol_conf.pad_output_len_dso, "%s", dsoname);
418 dsoname = buf;
421 return fprintf(fp, "%s", dsoname);
424 char *map__srcline(struct map *map, u64 addr, struct symbol *sym)
426 if (map == NULL)
427 return SRCLINE_UNKNOWN;
428 return get_srcline(map->dso, map__rip_2objdump(map, addr), sym, true, true, addr);
431 int map__fprintf_srcline(struct map *map, u64 addr, const char *prefix,
432 FILE *fp)
434 int ret = 0;
436 if (map && map->dso) {
437 char *srcline = map__srcline(map, addr, NULL);
438 if (strncmp(srcline, SRCLINE_UNKNOWN, strlen(SRCLINE_UNKNOWN)) != 0)
439 ret = fprintf(fp, "%s%s", prefix, srcline);
440 free_srcline(srcline);
442 return ret;
445 void srccode_state_free(struct srccode_state *state)
447 zfree(&state->srcfile);
448 state->line = 0;
452 * map__rip_2objdump - convert symbol start address to objdump address.
453 * @map: memory map
454 * @rip: symbol start address
456 * objdump wants/reports absolute IPs for ET_EXEC, and RIPs for ET_DYN.
457 * map->dso->adjust_symbols==1 for ET_EXEC-like cases except ET_REL which is
458 * relative to section start.
460 * Return: Address suitable for passing to "objdump --start-address="
462 u64 map__rip_2objdump(struct map *map, u64 rip)
464 struct kmap *kmap = __map__kmap(map);
467 * vmlinux does not have program headers for PTI entry trampolines and
468 * kcore may not either. However the trampoline object code is on the
469 * main kernel map, so just use that instead.
471 if (kmap && is_entry_trampoline(kmap->name) && kmap->kmaps && kmap->kmaps->machine) {
472 struct map *kernel_map = machine__kernel_map(kmap->kmaps->machine);
474 if (kernel_map)
475 map = kernel_map;
478 if (!map->dso->adjust_symbols)
479 return rip;
481 if (map->dso->rel)
482 return rip - map->pgoff;
485 * kernel modules also have DSO_TYPE_USER in dso->kernel,
486 * but all kernel modules are ET_REL, so won't get here.
488 if (map->dso->kernel == DSO_SPACE__USER)
489 return rip + map->dso->text_offset;
491 return map->unmap_ip(map, rip) - map->reloc;
495 * map__objdump_2mem - convert objdump address to a memory address.
496 * @map: memory map
497 * @ip: objdump address
499 * Closely related to map__rip_2objdump(), this function takes an address from
500 * objdump and converts it to a memory address. Note this assumes that @map
501 * contains the address. To be sure the result is valid, check it forwards
502 * e.g. map__rip_2objdump(map->map_ip(map, map__objdump_2mem(map, ip))) == ip
504 * Return: Memory address.
506 u64 map__objdump_2mem(struct map *map, u64 ip)
508 if (!map->dso->adjust_symbols)
509 return map->unmap_ip(map, ip);
511 if (map->dso->rel)
512 return map->unmap_ip(map, ip + map->pgoff);
515 * kernel modules also have DSO_TYPE_USER in dso->kernel,
516 * but all kernel modules are ET_REL, so won't get here.
518 if (map->dso->kernel == DSO_SPACE__USER)
519 return map->unmap_ip(map, ip - map->dso->text_offset);
521 return ip + map->reloc;
524 void maps__init(struct maps *maps, struct machine *machine)
526 maps->entries = RB_ROOT;
527 init_rwsem(&maps->lock);
528 maps->machine = machine;
529 maps->last_search_by_name = NULL;
530 maps->nr_maps = 0;
531 maps->maps_by_name = NULL;
532 refcount_set(&maps->refcnt, 1);
535 static void __maps__free_maps_by_name(struct maps *maps)
538 * Free everything to try to do it from the rbtree in the next search
540 zfree(&maps->maps_by_name);
541 maps->nr_maps_allocated = 0;
544 void maps__insert(struct maps *maps, struct map *map)
546 down_write(&maps->lock);
547 __maps__insert(maps, map);
548 ++maps->nr_maps;
550 if (map->dso && map->dso->kernel) {
551 struct kmap *kmap = map__kmap(map);
553 if (kmap)
554 kmap->kmaps = maps;
555 else
556 pr_err("Internal error: kernel dso with non kernel map\n");
561 * If we already performed some search by name, then we need to add the just
562 * inserted map and resort.
564 if (maps->maps_by_name) {
565 if (maps->nr_maps > maps->nr_maps_allocated) {
566 int nr_allocate = maps->nr_maps * 2;
567 struct map **maps_by_name = realloc(maps->maps_by_name, nr_allocate * sizeof(map));
569 if (maps_by_name == NULL) {
570 __maps__free_maps_by_name(maps);
571 up_write(&maps->lock);
572 return;
575 maps->maps_by_name = maps_by_name;
576 maps->nr_maps_allocated = nr_allocate;
578 maps->maps_by_name[maps->nr_maps - 1] = map;
579 __maps__sort_by_name(maps);
581 up_write(&maps->lock);
584 static void __maps__remove(struct maps *maps, struct map *map)
586 rb_erase_init(&map->rb_node, &maps->entries);
587 map__put(map);
590 void maps__remove(struct maps *maps, struct map *map)
592 down_write(&maps->lock);
593 if (maps->last_search_by_name == map)
594 maps->last_search_by_name = NULL;
596 __maps__remove(maps, map);
597 --maps->nr_maps;
598 if (maps->maps_by_name)
599 __maps__free_maps_by_name(maps);
600 up_write(&maps->lock);
603 static void __maps__purge(struct maps *maps)
605 struct map *pos, *next;
607 maps__for_each_entry_safe(maps, pos, next) {
608 rb_erase_init(&pos->rb_node, &maps->entries);
609 map__put(pos);
613 void maps__exit(struct maps *maps)
615 down_write(&maps->lock);
616 __maps__purge(maps);
617 up_write(&maps->lock);
620 bool maps__empty(struct maps *maps)
622 return !maps__first(maps);
625 struct maps *maps__new(struct machine *machine)
627 struct maps *maps = zalloc(sizeof(*maps));
629 if (maps != NULL)
630 maps__init(maps, machine);
632 return maps;
635 void maps__delete(struct maps *maps)
637 maps__exit(maps);
638 unwind__finish_access(maps);
639 free(maps);
642 void maps__put(struct maps *maps)
644 if (maps && refcount_dec_and_test(&maps->refcnt))
645 maps__delete(maps);
648 struct symbol *maps__find_symbol(struct maps *maps, u64 addr, struct map **mapp)
650 struct map *map = maps__find(maps, addr);
652 /* Ensure map is loaded before using map->map_ip */
653 if (map != NULL && map__load(map) >= 0) {
654 if (mapp != NULL)
655 *mapp = map;
656 return map__find_symbol(map, map->map_ip(map, addr));
659 return NULL;
662 static bool map__contains_symbol(struct map *map, struct symbol *sym)
664 u64 ip = map->unmap_ip(map, sym->start);
666 return ip >= map->start && ip < map->end;
669 struct symbol *maps__find_symbol_by_name(struct maps *maps, const char *name, struct map **mapp)
671 struct symbol *sym;
672 struct map *pos;
674 down_read(&maps->lock);
676 maps__for_each_entry(maps, pos) {
677 sym = map__find_symbol_by_name(pos, name);
679 if (sym == NULL)
680 continue;
681 if (!map__contains_symbol(pos, sym)) {
682 sym = NULL;
683 continue;
685 if (mapp != NULL)
686 *mapp = pos;
687 goto out;
690 sym = NULL;
691 out:
692 up_read(&maps->lock);
693 return sym;
696 int maps__find_ams(struct maps *maps, struct addr_map_symbol *ams)
698 if (ams->addr < ams->ms.map->start || ams->addr >= ams->ms.map->end) {
699 if (maps == NULL)
700 return -1;
701 ams->ms.map = maps__find(maps, ams->addr);
702 if (ams->ms.map == NULL)
703 return -1;
706 ams->al_addr = ams->ms.map->map_ip(ams->ms.map, ams->addr);
707 ams->ms.sym = map__find_symbol(ams->ms.map, ams->al_addr);
709 return ams->ms.sym ? 0 : -1;
712 size_t maps__fprintf(struct maps *maps, FILE *fp)
714 size_t printed = 0;
715 struct map *pos;
717 down_read(&maps->lock);
719 maps__for_each_entry(maps, pos) {
720 printed += fprintf(fp, "Map:");
721 printed += map__fprintf(pos, fp);
722 if (verbose > 2) {
723 printed += dso__fprintf(pos->dso, fp);
724 printed += fprintf(fp, "--\n");
728 up_read(&maps->lock);
730 return printed;
733 int maps__fixup_overlappings(struct maps *maps, struct map *map, FILE *fp)
735 struct rb_root *root;
736 struct rb_node *next, *first;
737 int err = 0;
739 down_write(&maps->lock);
741 root = &maps->entries;
744 * Find first map where end > map->start.
745 * Same as find_vma() in kernel.
747 next = root->rb_node;
748 first = NULL;
749 while (next) {
750 struct map *pos = rb_entry(next, struct map, rb_node);
752 if (pos->end > map->start) {
753 first = next;
754 if (pos->start <= map->start)
755 break;
756 next = next->rb_left;
757 } else
758 next = next->rb_right;
761 next = first;
762 while (next) {
763 struct map *pos = rb_entry(next, struct map, rb_node);
764 next = rb_next(&pos->rb_node);
767 * Stop if current map starts after map->end.
768 * Maps are ordered by start: next will not overlap for sure.
770 if (pos->start >= map->end)
771 break;
773 if (verbose >= 2) {
775 if (use_browser) {
776 pr_debug("overlapping maps in %s (disable tui for more info)\n",
777 map->dso->name);
778 } else {
779 fputs("overlapping maps:\n", fp);
780 map__fprintf(map, fp);
781 map__fprintf(pos, fp);
785 rb_erase_init(&pos->rb_node, root);
787 * Now check if we need to create new maps for areas not
788 * overlapped by the new map:
790 if (map->start > pos->start) {
791 struct map *before = map__clone(pos);
793 if (before == NULL) {
794 err = -ENOMEM;
795 goto put_map;
798 before->end = map->start;
799 __maps__insert(maps, before);
800 if (verbose >= 2 && !use_browser)
801 map__fprintf(before, fp);
802 map__put(before);
805 if (map->end < pos->end) {
806 struct map *after = map__clone(pos);
808 if (after == NULL) {
809 err = -ENOMEM;
810 goto put_map;
813 after->start = map->end;
814 after->pgoff += map->end - pos->start;
815 assert(pos->map_ip(pos, map->end) == after->map_ip(after, map->end));
816 __maps__insert(maps, after);
817 if (verbose >= 2 && !use_browser)
818 map__fprintf(after, fp);
819 map__put(after);
821 put_map:
822 map__put(pos);
824 if (err)
825 goto out;
828 err = 0;
829 out:
830 up_write(&maps->lock);
831 return err;
835 * XXX This should not really _copy_ te maps, but refcount them.
837 int maps__clone(struct thread *thread, struct maps *parent)
839 struct maps *maps = thread->maps;
840 int err = -ENOMEM;
841 struct map *map;
843 down_read(&parent->lock);
845 maps__for_each_entry(parent, map) {
846 struct map *new = map__clone(map);
847 if (new == NULL)
848 goto out_unlock;
850 err = unwind__prepare_access(maps, new, NULL);
851 if (err)
852 goto out_unlock;
854 maps__insert(maps, new);
855 map__put(new);
858 err = 0;
859 out_unlock:
860 up_read(&parent->lock);
861 return err;
864 static void __maps__insert(struct maps *maps, struct map *map)
866 struct rb_node **p = &maps->entries.rb_node;
867 struct rb_node *parent = NULL;
868 const u64 ip = map->start;
869 struct map *m;
871 while (*p != NULL) {
872 parent = *p;
873 m = rb_entry(parent, struct map, rb_node);
874 if (ip < m->start)
875 p = &(*p)->rb_left;
876 else
877 p = &(*p)->rb_right;
880 rb_link_node(&map->rb_node, parent, p);
881 rb_insert_color(&map->rb_node, &maps->entries);
882 map__get(map);
885 struct map *maps__find(struct maps *maps, u64 ip)
887 struct rb_node *p;
888 struct map *m;
890 down_read(&maps->lock);
892 p = maps->entries.rb_node;
893 while (p != NULL) {
894 m = rb_entry(p, struct map, rb_node);
895 if (ip < m->start)
896 p = p->rb_left;
897 else if (ip >= m->end)
898 p = p->rb_right;
899 else
900 goto out;
903 m = NULL;
904 out:
905 up_read(&maps->lock);
906 return m;
909 struct map *maps__first(struct maps *maps)
911 struct rb_node *first = rb_first(&maps->entries);
913 if (first)
914 return rb_entry(first, struct map, rb_node);
915 return NULL;
918 static struct map *__map__next(struct map *map)
920 struct rb_node *next = rb_next(&map->rb_node);
922 if (next)
923 return rb_entry(next, struct map, rb_node);
924 return NULL;
927 struct map *map__next(struct map *map)
929 return map ? __map__next(map) : NULL;
932 struct kmap *__map__kmap(struct map *map)
934 if (!map->dso || !map->dso->kernel)
935 return NULL;
936 return (struct kmap *)(map + 1);
939 struct kmap *map__kmap(struct map *map)
941 struct kmap *kmap = __map__kmap(map);
943 if (!kmap)
944 pr_err("Internal error: map__kmap with a non-kernel map\n");
945 return kmap;
948 struct maps *map__kmaps(struct map *map)
950 struct kmap *kmap = map__kmap(map);
952 if (!kmap || !kmap->kmaps) {
953 pr_err("Internal error: map__kmaps with a non-kernel map\n");
954 return NULL;
956 return kmap->kmaps;