1// SPDX-License-Identifier: GPL-2.0
2static 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}
31

source code of linux/tools/perf/util/find-map.c