diff options
Diffstat (limited to 'tools/perf/util/find-map.c')
| -rw-r--r-- | tools/perf/util/find-map.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/tools/perf/util/find-map.c b/tools/perf/util/find-map.c new file mode 100644 index 000000000000..7b2300588ece --- /dev/null +++ b/tools/perf/util/find-map.c | |||
| @@ -0,0 +1,30 @@ | |||
| 1 | // SPDX-License-Identifier: GPL-2.0 | ||
| 2 | static int find_map(void **start, void **end, const char *name) | ||
| 3 | { | ||
| 4 | FILE *maps; | ||
| 5 | char line[128]; | ||
| 6 | int found = 0; | ||
| 7 | |||
| 8 | maps = fopen("/proc/self/maps", "r"); | ||
| 9 | if (!maps) { | ||
| 10 | fprintf(stderr, "cannot open maps\n"); | ||
| 11 | return -1; | ||
| 12 | } | ||
| 13 | |||
| 14 | while (!found && fgets(line, sizeof(line), maps)) { | ||
| 15 | int m = -1; | ||
| 16 | |||
| 17 | /* We care only about private r-x mappings. */ | ||
| 18 | if (2 != sscanf(line, "%p-%p r-xp %*x %*x:%*x %*u %n", | ||
| 19 | start, end, &m)) | ||
| 20 | continue; | ||
| 21 | if (m < 0) | ||
| 22 | continue; | ||
| 23 | |||
| 24 | if (!strncmp(&line[m], name, strlen(name))) | ||
| 25 | found = 1; | ||
| 26 | } | ||
| 27 | |||
| 28 | fclose(maps); | ||
| 29 | return !found; | ||
| 30 | } | ||
