1 // Copyright (C) 2012-2013
2 // Free Software Foundation
4 // This file is part of GCC.
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)
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.
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.
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/>.
26 #define _VTV_MALLOC_H 1
30 /* Alignment mask for any object returned by the VTV memory pool */
32 #define VTV_ALIGNMENT_MASK (0x7)
34 #define VTV_ALIGNMENT_MASK (0x3)
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. */
42 static inline unsigned long
45 unsigned long long hi
, lo
;
47 asm volatile ("rdtsc" : "=a" (lo
), "=d" (hi
));
50 #elif defined (__i386__)
51 static inline unsigned long long
54 unsigned long long var
;
56 asm volatile ("rdtsc" : "=A" (var
));
61 static inline unsigned long long
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);
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. */
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
;
87 /* Function declarations. */
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);
98 #endif /* vtv_malloc.h */