| 35153 |
tlumley |
1 |
|
|
|
2 |
/*
|
|
|
3 |
----------------------------------------------------------------
|
|
|
4 |
|
|
|
5 |
Notice that the following BSD-style license applies to this one
|
|
|
6 |
file (memcheck.h) only. The entire rest of Valgrind is licensed
|
|
|
7 |
under the terms of the GNU General Public License, version 2. See
|
|
|
8 |
the COPYING file in the source distribution for details.
|
|
|
9 |
|
|
|
10 |
----------------------------------------------------------------
|
|
|
11 |
|
|
|
12 |
This file is part of MemCheck, a heavyweight Valgrind tool for
|
|
|
13 |
detecting memory errors.
|
|
|
14 |
|
|
|
15 |
Copyright (C) 2000-2005 Julian Seward. All rights reserved.
|
|
|
16 |
|
|
|
17 |
Redistribution and use in source and binary forms, with or without
|
|
|
18 |
modification, are permitted provided that the following conditions
|
|
|
19 |
are met:
|
|
|
20 |
|
|
|
21 |
1. Redistributions of source code must retain the above copyright
|
|
|
22 |
notice, this list of conditions and the following disclaimer.
|
|
|
23 |
|
|
|
24 |
2. The origin of this software must not be misrepresented; you must
|
|
|
25 |
not claim that you wrote the original software. If you use this
|
|
|
26 |
software in a product, an acknowledgment in the product
|
|
|
27 |
documentation would be appreciated but is not required.
|
|
|
28 |
|
|
|
29 |
3. Altered source versions must be plainly marked as such, and must
|
|
|
30 |
not be misrepresented as being the original software.
|
|
|
31 |
|
|
|
32 |
4. The name of the author may not be used to endorse or promote
|
|
|
33 |
products derived from this software without specific prior written
|
|
|
34 |
permission.
|
|
|
35 |
|
|
|
36 |
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
|
|
|
37 |
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
38 |
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
39 |
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
|
|
40 |
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
41 |
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
|
|
42 |
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
43 |
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
|
|
44 |
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
|
45 |
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
|
46 |
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
47 |
|
|
|
48 |
----------------------------------------------------------------
|
|
|
49 |
|
|
|
50 |
Notice that the above BSD-style license applies to this one file
|
|
|
51 |
(memcheck.h) only. The entire rest of Valgrind is licensed under
|
|
|
52 |
the terms of the GNU General Public License, version 2. See the
|
|
|
53 |
COPYING file in the source distribution for details.
|
|
|
54 |
|
|
|
55 |
----------------------------------------------------------------
|
|
|
56 |
*/
|
|
|
57 |
|
|
|
58 |
|
|
|
59 |
#ifndef __MEMCHECK_H
|
|
|
60 |
#define __MEMCHECK_H
|
|
|
61 |
|
|
|
62 |
|
|
|
63 |
/* This file is for inclusion into client (your!) code.
|
|
|
64 |
|
|
|
65 |
You can use these macros to manipulate and query memory permissions
|
|
|
66 |
inside your own programs.
|
|
|
67 |
|
|
|
68 |
See comment near the top of valgrind.h on how to use them.
|
|
|
69 |
*/
|
|
|
70 |
|
|
|
71 |
#include "valgrind.h"
|
|
|
72 |
|
|
|
73 |
typedef
|
|
|
74 |
enum {
|
|
|
75 |
VG_USERREQ__MAKE_NOACCESS = VG_USERREQ_TOOL_BASE('M','C'),
|
|
|
76 |
VG_USERREQ__MAKE_WRITABLE,
|
|
|
77 |
VG_USERREQ__MAKE_READABLE,
|
|
|
78 |
VG_USERREQ__DISCARD,
|
|
|
79 |
VG_USERREQ__CHECK_WRITABLE,
|
|
|
80 |
VG_USERREQ__CHECK_READABLE,
|
|
|
81 |
VG_USERREQ__DO_LEAK_CHECK,
|
|
|
82 |
VG_USERREQ__COUNT_LEAKS,
|
|
|
83 |
|
|
|
84 |
/* These two have been moved into core, because they are useful for
|
|
|
85 |
any tool that tracks heap blocks. Hence the suffix. But they're
|
|
|
86 |
still here for backwards compatibility, although Valgrind will
|
|
|
87 |
abort with an explanatory message if you use them. */
|
|
|
88 |
VG_USERREQ__MALLOCLIKE_BLOCK__OLD_DO_NOT_USE,
|
|
|
89 |
VG_USERREQ__FREELIKE_BLOCK__OLD_DO_NOT_USE,
|
|
|
90 |
|
|
|
91 |
VG_USERREQ__GET_VBITS,
|
|
|
92 |
VG_USERREQ__SET_VBITS,
|
|
|
93 |
|
|
|
94 |
VG_USERREQ__CREATE_BLOCK,
|
|
|
95 |
|
|
|
96 |
/* This is just for memcheck's internal use - don't use it */
|
|
|
97 |
_VG_USERREQ__MEMCHECK_RECORD_OVERLAP_ERROR
|
|
|
98 |
= VG_USERREQ_TOOL_BASE('M','C') + 256
|
|
|
99 |
} Vg_MemCheckClientRequest;
|
|
|
100 |
|
|
|
101 |
|
|
|
102 |
|
|
|
103 |
/* Client-code macros to manipulate the state of memory. */
|
|
|
104 |
|
|
|
105 |
/* Mark memory at _qzz_addr as unaddressible and undefined for
|
|
|
106 |
_qzz_len bytes. */
|
|
|
107 |
#define VALGRIND_MAKE_NOACCESS(_qzz_addr,_qzz_len) \
|
|
|
108 |
(__extension__({unsigned int _qzz_res; \
|
|
|
109 |
VALGRIND_MAGIC_SEQUENCE(_qzz_res, 0 /* default return */, \
|
|
|
110 |
VG_USERREQ__MAKE_NOACCESS, \
|
|
|
111 |
_qzz_addr, _qzz_len, 0, 0); \
|
|
|
112 |
_qzz_res; \
|
|
|
113 |
}))
|
|
|
114 |
|
|
|
115 |
/* Similarly, mark memory at _qzz_addr as addressible but undefined
|
|
|
116 |
for _qzz_len bytes. */
|
|
|
117 |
#define VALGRIND_MAKE_WRITABLE(_qzz_addr,_qzz_len) \
|
|
|
118 |
(__extension__({unsigned int _qzz_res; \
|
|
|
119 |
VALGRIND_MAGIC_SEQUENCE(_qzz_res, 0 /* default return */, \
|
|
|
120 |
VG_USERREQ__MAKE_WRITABLE, \
|
|
|
121 |
_qzz_addr, _qzz_len, 0, 0); \
|
|
|
122 |
_qzz_res; \
|
|
|
123 |
}))
|
|
|
124 |
|
|
|
125 |
/* Similarly, mark memory at _qzz_addr as addressible and defined
|
|
|
126 |
for _qzz_len bytes. */
|
|
|
127 |
#define VALGRIND_MAKE_READABLE(_qzz_addr,_qzz_len) \
|
|
|
128 |
(__extension__({unsigned int _qzz_res; \
|
|
|
129 |
VALGRIND_MAGIC_SEQUENCE(_qzz_res, 0 /* default return */, \
|
|
|
130 |
VG_USERREQ__MAKE_READABLE, \
|
|
|
131 |
_qzz_addr, _qzz_len, 0, 0); \
|
|
|
132 |
_qzz_res; \
|
|
|
133 |
}))
|
|
|
134 |
|
|
|
135 |
/* Create a block-description handle. The description is an ascii
|
|
|
136 |
string which is included in any messages pertaining to addresses
|
|
|
137 |
within the specified memory range. Has no other effect on the
|
|
|
138 |
properties of the memory range. */
|
|
|
139 |
#define VALGRIND_CREATE_BLOCK(_qzz_addr,_qzz_len, _qzz_desc) \
|
|
|
140 |
(__extension__({unsigned int _qzz_res; \
|
|
|
141 |
VALGRIND_MAGIC_SEQUENCE(_qzz_res, 0 /* default return */, \
|
|
|
142 |
VG_USERREQ__CREATE_BLOCK, \
|
|
|
143 |
_qzz_addr, _qzz_len, _qzz_desc, 0); \
|
|
|
144 |
_qzz_res; \
|
|
|
145 |
}))
|
|
|
146 |
|
|
|
147 |
/* Discard a block-description-handle. Returns 1 for an
|
|
|
148 |
invalid handle, 0 for a valid handle. */
|
|
|
149 |
#define VALGRIND_DISCARD(_qzz_blkindex) \
|
|
|
150 |
(__extension__ ({unsigned int _qzz_res; \
|
|
|
151 |
VALGRIND_MAGIC_SEQUENCE(_qzz_res, 0 /* default return */, \
|
|
|
152 |
VG_USERREQ__DISCARD, \
|
|
|
153 |
0, _qzz_blkindex, 0, 0); \
|
|
|
154 |
_qzz_res; \
|
|
|
155 |
}))
|
|
|
156 |
|
|
|
157 |
|
|
|
158 |
/* Client-code macros to check the state of memory. */
|
|
|
159 |
|
|
|
160 |
/* Check that memory at _qzz_addr is addressible for _qzz_len bytes.
|
|
|
161 |
If suitable addressibility is not established, Valgrind prints an
|
|
|
162 |
error message and returns the address of the first offending byte.
|
|
|
163 |
Otherwise it returns zero. */
|
|
|
164 |
#define VALGRIND_CHECK_WRITABLE(_qzz_addr,_qzz_len) \
|
|
|
165 |
(__extension__({unsigned int _qzz_res; \
|
|
|
166 |
VALGRIND_MAGIC_SEQUENCE(_qzz_res, 0, \
|
|
|
167 |
VG_USERREQ__CHECK_WRITABLE, \
|
|
|
168 |
_qzz_addr, _qzz_len, 0, 0); \
|
|
|
169 |
_qzz_res; \
|
|
|
170 |
}))
|
|
|
171 |
|
|
|
172 |
/* Check that memory at _qzz_addr is addressible and defined for
|
|
|
173 |
_qzz_len bytes. If suitable addressibility and definedness are not
|
|
|
174 |
established, Valgrind prints an error message and returns the
|
|
|
175 |
address of the first offending byte. Otherwise it returns zero. */
|
|
|
176 |
#define VALGRIND_CHECK_READABLE(_qzz_addr,_qzz_len) \
|
|
|
177 |
(__extension__({unsigned int _qzz_res; \
|
|
|
178 |
VALGRIND_MAGIC_SEQUENCE(_qzz_res, 0, \
|
|
|
179 |
VG_USERREQ__CHECK_READABLE, \
|
|
|
180 |
_qzz_addr, _qzz_len, 0, 0); \
|
|
|
181 |
_qzz_res; \
|
|
|
182 |
}))
|
|
|
183 |
|
|
|
184 |
/* Use this macro to force the definedness and addressibility of a
|
|
|
185 |
value to be checked. If suitable addressibility and definedness
|
|
|
186 |
are not established, Valgrind prints an error message and returns
|
|
|
187 |
the address of the first offending byte. Otherwise it returns
|
|
|
188 |
zero. */
|
|
|
189 |
#define VALGRIND_CHECK_DEFINED(__lvalue) \
|
|
|
190 |
VALGRIND_CHECK_READABLE( \
|
|
|
191 |
(volatile unsigned char *)&(__lvalue), \
|
|
|
192 |
(unsigned int)(sizeof (__lvalue)))
|
|
|
193 |
|
|
|
194 |
/* Do a memory leak check mid-execution. */
|
|
|
195 |
#define VALGRIND_DO_LEAK_CHECK \
|
|
|
196 |
{unsigned int _qzz_res; \
|
|
|
197 |
VALGRIND_MAGIC_SEQUENCE(_qzz_res, 0, \
|
|
|
198 |
VG_USERREQ__DO_LEAK_CHECK, \
|
|
|
199 |
0, 0, 0, 0); \
|
|
|
200 |
}
|
|
|
201 |
|
|
|
202 |
/* Just display summaries of leaked memory, rather than all the
|
|
|
203 |
details */
|
|
|
204 |
#define VALGRIND_DO_QUICK_LEAK_CHECK \
|
|
|
205 |
{unsigned int _qzz_res; \
|
|
|
206 |
VALGRIND_MAGIC_SEQUENCE(_qzz_res, 0, \
|
|
|
207 |
VG_USERREQ__DO_LEAK_CHECK, \
|
|
|
208 |
1, 0, 0, 0); \
|
|
|
209 |
}
|
|
|
210 |
|
|
|
211 |
/* Return number of leaked, dubious, reachable and suppressed bytes found by
|
|
|
212 |
all previous leak checks. They must be lvalues. */
|
|
|
213 |
#define VALGRIND_COUNT_LEAKS(leaked, dubious, reachable, suppressed) \
|
|
|
214 |
{unsigned int _qzz_res; \
|
|
|
215 |
VALGRIND_MAGIC_SEQUENCE(_qzz_res, 0, \
|
|
|
216 |
VG_USERREQ__COUNT_LEAKS, \
|
|
|
217 |
&leaked, &dubious, &reachable, &suppressed);\
|
|
|
218 |
}
|
|
|
219 |
|
|
|
220 |
|
|
|
221 |
/* These two have been moved to valgrind.h; still here so that a warning can
|
|
|
222 |
be printed out for any programs using the old ones. */
|
|
|
223 |
#define VALGRIND_MALLOCLIKE_BLOCK__OLD_DO_NOT_USE(addr, sizeB, rzB, is_zeroed)\
|
|
|
224 |
{unsigned int _qzz_res; \
|
|
|
225 |
VALGRIND_MAGIC_SEQUENCE(_qzz_res, 0, \
|
|
|
226 |
VG_USERREQ__MALLOCLIKE_BLOCK, \
|
|
|
227 |
addr, sizeB, rzB, is_zeroed); \
|
|
|
228 |
}
|
|
|
229 |
#define VALGRIND_FREELIKE_BLOCK__OLD_DO_NOT_USE(addr, rzB) \
|
|
|
230 |
{unsigned int _qzz_res; \
|
|
|
231 |
VALGRIND_MAGIC_SEQUENCE(_qzz_res, 0, \
|
|
|
232 |
VG_USERREQ__FREELIKE_BLOCK, \
|
|
|
233 |
addr, rzB, 0, 0); \
|
|
|
234 |
}
|
|
|
235 |
|
|
|
236 |
|
|
|
237 |
/* Get in zzvbits the validity data for the zznbytes starting at
|
|
|
238 |
zzsrc. Return values:
|
|
|
239 |
|
|
|
240 |
1 success
|
|
|
241 |
2 if zzsrc/zzvbits arrays are not aligned 0 % 4, or
|
|
|
242 |
zznbytes is not 0 % 4.
|
|
|
243 |
3 if any parts of zzsrc/zzvbits are not addressible.
|
|
|
244 |
The metadata is not copied in cases 0, 2 or 3 so it should be
|
|
|
245 |
impossible to segfault your system by using this call.
|
|
|
246 |
*/
|
|
|
247 |
#define VALGRIND_GET_VBITS(zzsrc,zzvbits,zznbytes) \
|
|
|
248 |
(__extension__({unsigned int _qzz_res; \
|
|
|
249 |
char* czzsrc = (char*)zzsrc; \
|
|
|
250 |
char* czzvbits = (char*)zzvbits; \
|
|
|
251 |
VALGRIND_MAGIC_SEQUENCE(_qzz_res, 0, \
|
|
|
252 |
VG_USERREQ__GET_VBITS, \
|
|
|
253 |
czzsrc, czzvbits, zznbytes,0 ); \
|
|
|
254 |
_qzz_res; \
|
|
|
255 |
}))
|
|
|
256 |
|
|
|
257 |
/* Apply the validity data in zzvbits to the zznbytes starting at
|
|
|
258 |
zzdst. Return values:
|
|
|
259 |
|
|
|
260 |
1 success
|
|
|
261 |
2 if zzdst/zzvbits arrays are not aligned 0 % 4, or
|
|
|
262 |
zznbytes is not 0 % 4.
|
|
|
263 |
3 if any parts of zzdst/zzvbits are not addressible.
|
|
|
264 |
The metadata is not copied in cases 0, 2 or 3 so it should be
|
|
|
265 |
impossible to segfault your system by using this call.
|
|
|
266 |
*/
|
|
|
267 |
#define VALGRIND_SET_VBITS(zzdst,zzvbits,zznbytes) \
|
|
|
268 |
(__extension__({unsigned int _qzz_res; \
|
|
|
269 |
char* czzdst = (char*)zzdst; \
|
|
|
270 |
char* czzvbits = (char*)zzvbits; \
|
|
|
271 |
VALGRIND_MAGIC_SEQUENCE(_qzz_res, 0, \
|
|
|
272 |
VG_USERREQ__SET_VBITS, \
|
|
|
273 |
czzdst, czzvbits, zznbytes,0 ); \
|
|
|
274 |
_qzz_res; \
|
|
|
275 |
}))
|
|
|
276 |
|
|
|
277 |
#endif
|
|
|
278 |
|