0001
0002 static int find_map(void **start, void **end, const char *name)
0003 {
0004 FILE *maps;
0005 char line[128];
0006 int found = 0;
0007
0008 maps = fopen("/proc/self/maps", "r");
0009 if (!maps) {
0010 fprintf(stderr, "cannot open maps\n");
0011 return -1;
0012 }
0013
0014 while (!found && fgets(line, sizeof(line), maps)) {
0015 int m = -1;
0016
0017
0018 if (2 != sscanf(line, "%p-%p r-xp %*x %*x:%*x %*u %n",
0019 start, end, &m))
0020 continue;
0021 if (m < 0)
0022 continue;
0023
0024 if (!strncmp(&line[m], name, strlen(name)))
0025 found = 1;
0026 }
0027
0028 fclose(maps);
0029 return !found;
0030 }