Commit | Line | Data |
---|---|---|
b2441318 | 1 | // SPDX-License-Identifier: GPL-2.0 |
01153237 | 2 | static int find_map(void **start, void **end, const char *name) |
e477f3f0 AH |
3 | { |
4 | FILE *maps; | |
5 | char line[128]; | |
6 | int found = 0; | |
7 | ||
8 | maps = fopen("/proc/self/maps", "r"); | |
9 | if (!maps) { | |
01153237 | 10 | fprintf(stderr, "cannot open maps\n"); |
e477f3f0 AH |
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 | ||
01153237 | 24 | if (!strncmp(&line[m], name, strlen(name))) |
e477f3f0 AH |
25 | found = 1; |
26 | } | |
27 | ||
28 | fclose(maps); | |
29 | return !found; | |
30 | } |