-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdumpvdso.c
56 lines (46 loc) · 1.08 KB
/
dumpvdso.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <asm/prctl.h>
#include <err.h>
#include <getopt.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/prctl.h>
#include <unistd.h>
#include <sys/auxv.h>
#include <sys/mman.h>
#define ARRSZE(X) (sizeof(X) / sizeof(*(X)))
#define K 1024
#define M (1024 * K)
struct {
const char* str;
int val;
} aliases[] = {
{ "x32", ARCH_MAP_VDSO_X32 },
{ "32", ARCH_MAP_VDSO_32 },
{ "64", ARCH_MAP_VDSO_32 },
};
static int get_kind(const char* str) {
for (size_t i = 0; i < ARRSZE(aliases); i++) {
if (!strcmp(aliases[i].str, str))
return aliases[i].val;
}
errx(1, "Alias \"%s\" not found", str);
}
int main(int argc, const char** argv) {
const char* argv_default[] = {
argv[0], "64", NULL
};
if (argc < 2) {
argc = ARRSZE(argv_default);
argv = argv_default;
}
unsigned long sysinfo_ehdr = getauxval(AT_SYSINFO_EHDR);
if (!sysinfo_ehdr)
err(1, "getauxval(AT_SYSINFO_EHDR)");
if (munmap(sysinfo_ehdr - 4 * M, 16 * M) < 0)
err(1, "munmap");
int kind = get_kind(argv[1]);
long size = arch_prctl(kind, 0);
if (size < 0)
err(1, "ARCH_MAP_VDSO");
}