perf map: Add map__refcnt() accessor to use in the maps test

To remove one more direct access to 'struct map' so that we can intecept
accesses to its instantiations and refcount check it to catch use after
free, etc.

Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexey Bayduraev <alexey.v.bayduraev@linux.intel.com>
Cc: Dmitriy Vyukov <dvyukov@google.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Stephen Brennan <stephen.s.brennan@oracle.com>
Link: https://lore.kernel.org/lkml/ZDbRIJknafLnDwtO@kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 984abd34
...@@ -30,7 +30,7 @@ static int check_maps(struct map_def *merged, unsigned int size, struct maps *ma ...@@ -30,7 +30,7 @@ static int check_maps(struct map_def *merged, unsigned int size, struct maps *ma
if (map__start(map) != merged[i].start || if (map__start(map) != merged[i].start ||
map__end(map) != merged[i].end || map__end(map) != merged[i].end ||
strcmp(map__dso(map)->name, merged[i].name) || strcmp(map__dso(map)->name, merged[i].name) ||
refcount_read(&map->refcnt) != 1) { refcount_read(map__refcnt(map)) != 1) {
failed = true; failed = true;
} }
i++; i++;
...@@ -50,7 +50,7 @@ static int check_maps(struct map_def *merged, unsigned int size, struct maps *ma ...@@ -50,7 +50,7 @@ static int check_maps(struct map_def *merged, unsigned int size, struct maps *ma
map__start(map), map__start(map),
map__end(map), map__end(map),
map__dso(map)->name, map__dso(map)->name,
refcount_read(&map->refcnt)); refcount_read(map__refcnt(map)));
} }
} }
return failed ? TEST_FAIL : TEST_OK; return failed ? TEST_FAIL : TEST_OK;
......
...@@ -97,6 +97,11 @@ static inline bool map__priv(const struct map *map) ...@@ -97,6 +97,11 @@ static inline bool map__priv(const struct map *map)
return map->priv; return map->priv;
} }
static inline refcount_t *map__refcnt(struct map *map)
{
return &map->refcnt;
}
static inline size_t map__size(const struct map *map) static inline size_t map__size(const struct map *map)
{ {
return map__end(map) - map__start(map); return map__end(map) - map__start(map);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment