Branch data Line data Source code
1 : : #include <stdlib.h>
2 : : #include <stdio.h>
3 : : #include <string.h>
4 : : #include <unistd.h>
5 : :
6 : : #include "vdso.h"
7 : : #include "log.h"
8 : : #include "util.h"
9 : :
10 : : #ifdef LOG_PREFIX
11 : : # undef LOG_PREFIX
12 : : #endif
13 : : #define LOG_PREFIX "vdso: "
14 : :
15 : :
16 : : struct vdso_symtable vdso_sym_rt = VDSO_SYMTABLE_INIT;
17 : : u64 vdso_pfn = VDSO_BAD_PFN;
18 : :
19 : 2805 : static int vdso_fill_self_symtable(struct vdso_symtable *s)
20 : : {
21 : : char buf[512];
22 : : int ret = -1;
23 : : FILE *maps;
24 : :
25 : 2805 : VDSO_INIT_SYMTABLE(s);
26 : :
27 : 2805 : maps = fopen("/proc/self/maps", "r");
28 [ + - ]: 2805 : if (!maps) {
29 : 0 : pr_perror("Can't open self-vma");
30 : 0 : return -1;
31 : : }
32 : :
33 [ + - ]: 93569 : while (fgets(buf, sizeof(buf), maps)) {
34 : : unsigned long start, end;
35 : :
36 [ + + ]: 93569 : if (strstr(buf, "[vdso]") == NULL)
37 : 90764 : continue;
38 : :
39 : 2805 : ret = sscanf(buf, "%lx-%lx", &start, &end);
40 [ - + ]: 2805 : if (ret != 2) {
41 : : ret = -1;
42 : 0 : pr_err("Can't find vDSO bounds\n");
43 : 2805 : break;
44 : : }
45 : :
46 : 2805 : s->vma_start = start;
47 : 2805 : s->vma_end = end;
48 : :
49 : 2805 : ret = vdso_fill_symtable((void *)start, end - start, s);
50 : 2805 : break;
51 : : }
52 : :
53 : 2805 : fclose(maps);
54 : 2805 : return ret;
55 : : }
56 : :
57 : 2805 : int vdso_init(void)
58 : : {
59 [ + - ]: 2805 : if (vdso_fill_self_symtable(&vdso_sym_rt))
60 : : return -1;
61 : :
62 : 2805 : return vaddr_to_pfn(vdso_sym_rt.vma_start, &vdso_pfn);
63 : : }
64 : :
|