]>
Commit | Line | Data |
---|---|---|
2077db1b CT |
1 | // Copyright (C) 2012-2013 |
2 | // Free Software Foundation | |
3 | // | |
4 | // This file is part of GCC. | |
5 | // | |
6 | // GCC is free software; you can redistribute it and/or modify | |
7 | // it under the terms of the GNU General Public License as published by | |
8 | // the Free Software Foundation; either version 3, or (at your option) | |
9 | // any later version. | |
10 | ||
11 | // GCC is distributed in the hope that it will be useful, | |
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | // GNU General Public License for more details. | |
15 | ||
16 | // Under Section 7 of GPL version 3, you are granted additional | |
17 | // permissions described in the GCC Runtime Library Exception, version | |
18 | // 3.1, as published by the Free Software Foundation. | |
19 | ||
20 | // You should have received a copy of the GNU General Public License and | |
21 | // a copy of the GCC Runtime Library Exception along with this program; | |
22 | // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see | |
23 | // <http://www.gnu.org/licenses/>. | |
24 | ||
25 | #ifndef _VTV_MALLOC_H | |
26 | #define _VTV_MALLOC_H 1 | |
27 | ||
28 | #include <stdlib.h> | |
29 | ||
30 | /* Alignment mask for any object returned by the VTV memory pool */ | |
31 | #ifdef __LP64__ | |
32 | #define VTV_ALIGNMENT_MASK (0x7) | |
33 | #else | |
34 | #define VTV_ALIGNMENT_MASK (0x3) | |
35 | #endif | |
36 | ||
37 | /* The following function is used to instrument the compiler and find | |
38 | out how many cycles are being spent in various vtable verification | |
39 | runtime library functions. */ | |
40 | ||
41 | #ifdef __x86_64__ | |
42 | static inline unsigned long | |
43 | rdtsc () | |
44 | { | |
45 | unsigned long long hi, lo; | |
46 | ||
47 | asm volatile ("rdtsc" : "=a" (lo), "=d" (hi)); | |
48 | return hi << 32 | lo; | |
49 | } | |
50 | #elif defined (__i386__) | |
51 | static inline unsigned long long | |
52 | rdtsc () | |
53 | { | |
54 | unsigned long long var; | |
55 | ||
56 | asm volatile ("rdtsc" : "=A" (var)); | |
57 | ||
58 | return var; | |
59 | } | |
60 | #else | |
61 | static inline unsigned long long | |
62 | rdtsc () | |
63 | { | |
64 | /* Create an empty function for unknown architectures, so that the | |
65 | calls to this function in vtv_malloc.cc and vtv_rts.cc do not cause | |
66 | compilation errors. */ | |
67 | return ((unsigned long long) 0); | |
68 | } | |
69 | #endif | |
70 | ||
71 | ||
72 | /* The following variables are used only for debugging and performance tuning | |
73 | purposes. Therefore they do not need to be "protected". They cannot be used | |
74 | to attack the vtable verification system and if they become corrupted it will | |
75 | not affect the correctness or security of any of the rest of the vtable | |
76 | verification feature. */ | |
77 | ||
78 | extern unsigned int num_calls_to_mprotect; | |
79 | extern unsigned int num_pages_protected; | |
80 | extern unsigned int num_calls_to_regset; | |
81 | extern unsigned int num_calls_to_regpair; | |
82 | extern unsigned long long mprotect_cycles; | |
83 | extern unsigned long long regset_cycles; | |
84 | extern unsigned long long regpair_cycles; | |
85 | ||
86 | ||
87 | /* Function declarations. */ | |
88 | ||
89 | extern void __vtv_malloc_init (void); | |
90 | extern void *__vtv_malloc (size_t size) __attribute__ ((malloc)); | |
91 | extern void __vtv_free (void * ptr); | |
92 | extern void __vtv_malloc_protect (void); | |
93 | extern void __vtv_malloc_unprotect (void); | |
94 | extern void __vtv_malloc_stats (void); | |
95 | extern void __vtv_malloc_dump_stats (void); | |
96 | extern int __vtv_count_mmapped_pages (void); | |
97 | ||
98 | #endif /* vtv_malloc.h */ |