blob: 7b2300588ece08c6f5a29de1527300772efa9174 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001// SPDX-License-Identifier: GPL-2.0
Florian Fainelli01153232018-12-20 19:43:36 -08002static int find_map(void **start, void **end, const char *name)
Adrian Huntere477f3f2014-10-23 18:16:03 -03003{
4 FILE *maps;
5 char line[128];
6 int found = 0;
7
8 maps = fopen("/proc/self/maps", "r");
9 if (!maps) {
Florian Fainelli01153232018-12-20 19:43:36 -080010 fprintf(stderr, "cannot open maps\n");
Adrian Huntere477f3f2014-10-23 18:16:03 -030011 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
Florian Fainelli01153232018-12-20 19:43:36 -080024 if (!strncmp(&line[m], name, strlen(name)))
Adrian Huntere477f3f2014-10-23 18:16:03 -030025 found = 1;
26 }
27
28 fclose(maps);
29 return !found;
30}