1 // These counters are used to get a delta between leak counts at startup
2 // (eg. due to libc) and later on. Necessary to get reliable leak tests
3 // across different platforms.
4 #define DECLARE_LEAK_COUNTERS \
5 long L0_bytes = 0, L_bytes = 0, L0_blocks = 0, L_blocks = 0; \
6 long D0_bytes = 0, D_bytes = 0, D0_blocks = 0, D_blocks = 0; \
7 long R0_bytes = 0, R_bytes = 0, R0_blocks = 0, R_blocks = 0; \
8 long S0_bytes = 0, S_bytes = 0, S0_blocks = 0, S_blocks = 0
10 // Set a baseline, in case allocations have already happened.
11 #define GET_INITIAL_LEAK_COUNTS \
13 VALGRIND_DO_QUICK_LEAK_CHECK; \
14 VALGRIND_COUNT_LEAKS( L0_bytes, D0_bytes, R0_bytes, S0_bytes );\
15 VALGRIND_COUNT_LEAK_BLOCKS(L0_blocks, D0_blocks, R0_blocks, S0_blocks); \
18 // Set a baseline, in case allocations have already happened.
19 #define GET_FINAL_LEAK_COUNTS \
21 VALGRIND_DO_QUICK_LEAK_CHECK; \
22 VALGRIND_COUNT_LEAKS( L_bytes, D_bytes, R_bytes, S_bytes ); \
23 VALGRIND_COUNT_LEAK_BLOCKS(L_blocks, D_blocks, R_blocks, S_blocks); \
24 L_bytes -= L0_bytes; L_blocks -= L0_blocks; \
25 D_bytes -= D0_bytes; D_blocks -= D0_blocks; \
26 R_bytes -= R0_bytes; R_blocks -= R0_blocks; \
27 S_bytes -= S0_bytes; S_blocks -= S0_blocks; \
30 // Print leak counts. When used in conjunction with -q the normal counts
31 // aren't shown, which is what we want.
32 #define PRINT_LEAK_COUNTS(where) \
34 fprintf(where,"leaked: %3ld bytes in %2ld blocks\n", \
36 fprintf(where,"dubious: %3ld bytes in %2ld blocks\n", \
38 fprintf(where,"reachable: %3ld bytes in %2ld blocks\n", \
40 fprintf(where,"suppressed: %3ld bytes in %2ld blocks\n", \
44 /* Upon a call to a function, some architectures store pointers into
45 * into registers. Valgrind may consider these registers when determining
46 * whether an address is reachable, so we need to zero-out these registers
49 #if defined __powerpc__
50 #define CLEAR_CALLER_SAVED_REGS \
52 __asm__ __volatile__( "li 3, 0" : : :/*trash*/"r3" ); \
53 __asm__ __volatile__( "li 4, 0" : : :/*trash*/"r4" ); \
54 __asm__ __volatile__( "li 5, 0" : : :/*trash*/"r5" ); \
55 __asm__ __volatile__( "li 6, 0" : : :/*trash*/"r6" ); \
56 __asm__ __volatile__( "li 7, 0" : : :/*trash*/"r7" ); \
57 __asm__ __volatile__( "li 8, 0" : : :/*trash*/"r8" ); \
58 __asm__ __volatile__( "li 9, 0" : : :/*trash*/"r9" ); \
59 __asm__ __volatile__( "li 10, 0" : : :/*trash*/"r10" ); \
60 __asm__ __volatile__( "li 11, 0" : : :/*trash*/"r11" ); \
61 __asm__ __volatile__( "li 12, 0" : : :/*trash*/"r12" ); \
63 #elif defined(__nanomips__)
64 #define CLEAR_CALLER_SAVED_REGS \
66 __asm__ __volatile__ (".set push \n\t" \
68 "move $at, $zero \n\t" \
69 "move $t4, $zero \n\t" \
70 "move $t5, $zero \n\t" \
71 "move $a0, $zero \n\t" \
72 "move $a1, $zero \n\t" \
73 "move $a2, $zero \n\t" \
74 "move $a3, $zero \n\t" \
75 "move $a4, $zero \n\t" \
76 "move $a5, $zero \n\t" \
77 "move $a6, $zero \n\t" \
78 "move $a7, $zero \n\t" \
79 "move $t0, $zero \n\t" \
80 "move $t1, $zero \n\t" \
81 "move $t2, $zero \n\t" \
82 "move $t3, $zero \n\t" \
83 "move $t8, $zero \n\t" \
84 "move $t9, $zero \n\t" \
86 : : : "$at", "$t4", "$t5", "$a0", "$a1", "$a2", \
87 "$a3", "$a4", "$a5", "$a6", "$a7", "$t0", \
88 "$t1", "$t2", "$t3", "$t8", "$t9"); \
91 #define CLEAR_CALLER_SAVED_REGS \
93 __asm__ __volatile__ (".set push \n\t" \
95 "move $1, $0 \n\t" /* at = 0 */ \
96 "move $2, $0 \n\t" /* v0 = 0 */ \
97 "move $3, $0 \n\t" /* v1 = 0 */ \
98 "move $4, $0 \n\t" /* a0 = 0 */ \
99 "move $5, $0 \n\t" /* a1 = 0 */ \
100 "move $6, $0 \n\t" /* a2 = 0 */ \
101 "move $7, $0 \n\t" /* a3 = 0 */ \
102 "move $8, $0 \n\t" /* t0 = 0 */ \
103 "move $9, $0 \n\t" /* t1 = 0 */ \
104 "move $10, $0 \n\t" /* t2 = 0 */ \
105 "move $11, $0 \n\t" /* t3 = 0 */ \
106 "move $12, $0 \n\t" /* t4 = 0 */ \
107 "move $13, $0 \n\t" /* t5 = 0 */ \
108 "move $14, $0 \n\t" /* t6 = 0 */ \
109 "move $15, $0 \n\t" /* t7 = 0 */ \
110 "move $24, $0 \n\t" /* t8 = 0 */ \
111 "move $25, $0 \n\t" /* t9 = 0 */ \
112 "move $31, $0 \n\t" /* ra = 0 */ \
114 : : : "$1", "$2", "$3", "$4", "$5", "$6", "$7", \
115 "$8", "$9", "$10", "$11", "$12", "$13", \
116 "$14", "$15", "$24", "$25", "$31"); \
119 #define CLEAR_CALLER_SAVED_REGS \
121 __asm__ __volatile__ (".set push \n\t" \
123 "move $1, $0 \n\t" /* at = 0 */ \
124 "move $2, $0 \n\t" /* v0 = 0 */ \
125 "move $3, $0 \n\t" /* v1 = 0 */ \
126 "move $4, $0 \n\t" /* a0 = 0 */ \
127 "move $5, $0 \n\t" /* a1 = 0 */ \
128 "move $6, $0 \n\t" /* a2 = 0 */ \
129 "move $7, $0 \n\t" /* a3 = 0 */ \
130 "move $8, $0 \n\t" /* a4 = 0 */ \
131 "move $9, $0 \n\t" /* a5 = 0 */ \
132 "move $10, $0 \n\t" /* a6 = 0 */ \
133 "move $11, $0 \n\t" /* a7 = 0 */ \
134 "move $12, $0 \n\t" /* t0 = 0 */ \
135 "move $13, $0 \n\t" /* t1 = 0 */ \
136 "move $14, $0 \n\t" /* t2 = 0 */ \
137 "move $15, $0 \n\t" /* t3 = 0 */ \
138 "move $24, $0 \n\t" /* t8 = 0 */ \
139 "move $25, $0 \n\t" /* t9 = 0 */ \
140 "move $31, $0 \n\t" /* ra = 0 */ \
142 : : : "$1", "$2", "$3", "$4", "$5", "$6", "$7", \
143 "$8", "$9", "$10", "$11", "$12", "$13", \
144 "$14", "$15", "$24", "$25", "$31"); \
146 #elif defined (__clang__) && defined(VGA_x86)
147 #define CLEAR_CALLER_SAVED_REGS \
149 __asm__ __volatile__ ("movl $0, %ecx\n\t"); \
151 #elif defined(__arm__)
153 #define CLEAR_CALLER_SAVED_REGS \
155 __asm__ __volatile__ ("mov %r0, $0\n\t"); \
156 __asm__ __volatile__ ("mov %r1, $0\n\t"); \
157 __asm__ __volatile__ ("mov %r2, $0\n\t"); \
158 __asm__ __volatile__ ("mov %r3, $0\n\t"); \
160 #elif defined(__aarch64__)
162 #define CLEAR_CALLER_SAVED_REGS \
164 __asm__ __volatile__ ("mov x0, 0\n\t"); \
165 __asm__ __volatile__ ("mov x1, 0\n\t"); \
166 __asm__ __volatile__ ("mov x2, 0\n\t"); \
167 __asm__ __volatile__ ("mov x3, 0\n\t"); \
168 __asm__ __volatile__ ("mov x4, 0\n\t"); \
169 __asm__ __volatile__ ("mov x5, 0\n\t"); \
170 __asm__ __volatile__ ("mov x6, 0\n\t"); \
171 __asm__ __volatile__ ("mov x7, 0\n\t"); \
172 __asm__ __volatile__ ("mov x8, 0\n\t"); \
173 __asm__ __volatile__ ("mov x9, 0\n\t"); \
174 __asm__ __volatile__ ("mov x10, 0\n\t"); \
175 __asm__ __volatile__ ("mov x11, 0\n\t"); \
176 __asm__ __volatile__ ("mov x12, 0\n\t"); \
177 __asm__ __volatile__ ("mov x13, 0\n\t"); \
178 __asm__ __volatile__ ("mov x14, 0\n\t"); \
179 __asm__ __volatile__ ("mov x15, 0\n\t"); \
180 __asm__ __volatile__ ("mov x16, 0\n\t"); \
181 __asm__ __volatile__ ("mov x17, 0\n\t"); \
182 __asm__ __volatile__ ("mov x18, 0\n\t"); \
185 #define CLEAR_CALLER_SAVED_REGS /*nothing*/