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