blob: 71a7e0d33305356fd4e758d41e031db26b0c3c09 [file] [log] [blame]
sewardjb5f6f512005-03-10 23:59:00 +00001/* -*- c -*-
njn25e49d8e72002-09-23 09:36:25 +00002 ----------------------------------------------------------------
3
4 Notice that the following BSD-style license applies to this one
5 file (valgrind.h) only. The entire rest of Valgrind is licensed
6 under the terms of the GNU General Public License, version 2. See
7 the COPYING file in the source distribution for details.
8
9 ----------------------------------------------------------------
10
njnb9c427c2004-12-01 14:14:42 +000011 This file is part of Valgrind, a dynamic binary instrumentation
12 framework.
sewardjde4a1d02002-03-22 01:27:54 +000013
njn53612422005-03-12 16:22:54 +000014 Copyright (C) 2000-2005 Julian Seward. All rights reserved.
sewardjde4a1d02002-03-22 01:27:54 +000015
njn25e49d8e72002-09-23 09:36:25 +000016 Redistribution and use in source and binary forms, with or without
17 modification, are permitted provided that the following conditions
18 are met:
sewardjde4a1d02002-03-22 01:27:54 +000019
njn25e49d8e72002-09-23 09:36:25 +000020 1. Redistributions of source code must retain the above copyright
21 notice, this list of conditions and the following disclaimer.
sewardjde4a1d02002-03-22 01:27:54 +000022
njn25e49d8e72002-09-23 09:36:25 +000023 2. The origin of this software must not be misrepresented; you must
24 not claim that you wrote the original software. If you use this
25 software in a product, an acknowledgment in the product
26 documentation would be appreciated but is not required.
sewardjde4a1d02002-03-22 01:27:54 +000027
njn25e49d8e72002-09-23 09:36:25 +000028 3. Altered source versions must be plainly marked as such, and must
29 not be misrepresented as being the original software.
30
31 4. The name of the author may not be used to endorse or promote
32 products derived from this software without specific prior written
33 permission.
34
35 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
36 OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
37 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
38 ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
39 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
40 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
41 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
42 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
43 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
44 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
45 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
46
47 ----------------------------------------------------------------
48
49 Notice that the above BSD-style license applies to this one file
50 (valgrind.h) only. The entire rest of Valgrind is licensed under
51 the terms of the GNU General Public License, version 2. See the
52 COPYING file in the source distribution for details.
53
54 ----------------------------------------------------------------
sewardjde4a1d02002-03-22 01:27:54 +000055*/
56
57
njn30d76c62005-06-18 15:07:39 +000058/* This file is for inclusion into client (your!) code.
59
60 You can use these macros to manipulate and query Valgrind's
61 execution inside your own programs.
62
63 The resulting executables will still run without Valgrind, just a
64 little bit more slowly than they otherwise would, but otherwise
65 unchanged. When not running on valgrind, each client request
66 consumes very few (eg. < 10) instructions, so the resulting performance
67 loss is negligible unless you plan to execute client requests
68 millions of times per second. Nevertheless, if that is still a
69 problem, you can compile with the NVALGRIND symbol defined (gcc
70 -DNVALGRIND) so that client requests are not even compiled in. */
71
sewardjde4a1d02002-03-22 01:27:54 +000072#ifndef __VALGRIND_H
73#define __VALGRIND_H
74
fitzhardinge39de4b42003-10-31 07:12:21 +000075#include <stdarg.h>
76
sewardjb5f6f512005-03-10 23:59:00 +000077/* If we're not compiling for our target architecture, don't generate
njn26aba4d2005-05-16 13:31:23 +000078 any inline asms. Note that in this file we're using the compiler's
79 CPP symbols for identifying architectures, which are different to
80 the ones we use within the rest of Valgrind. */
81#if !defined(__i386__) && !defined(__x86_64__)
sewardjb5f6f512005-03-10 23:59:00 +000082# ifndef NVALGRIND
83# define NVALGRIND 1
84# endif /* NVALGRIND */
85#endif
86
njn30d76c62005-06-18 15:07:39 +000087/* ------------------------------------------------------------------ */
88/* The architecture-specific part */
89/* ------------------------------------------------------------------ */
sewardjde4a1d02002-03-22 01:27:54 +000090
njn26aba4d2005-05-16 13:31:23 +000091#ifdef NVALGRIND
92
93/* Define NVALGRIND to completely remove the Valgrind magic sequence
94 from the compiled code (analogous to NDEBUG's effects on assert()) */
95#define VALGRIND_MAGIC_SEQUENCE( \
96 _zzq_rlval, _zzq_default, _zzq_request, \
97 _zzq_arg1, _zzq_arg2, _zzq_arg3, _zzq_arg4) \
98 { \
99 (_zzq_rlval) = (_zzq_default); \
100 }
101
102#else /* NVALGRIND */
nethercotee90c6832004-10-18 18:07:49 +0000103
nethercote54265442004-10-26 12:56:58 +0000104/* The following defines the magic code sequences which the JITter spots and
105 handles magically. Don't look too closely at them; they will rot
nethercotee90c6832004-10-18 18:07:49 +0000106 your brain. We must ensure that the default value gets put in the return
107 slot, so that everything works when this is executed not under Valgrind.
108 Args are passed in a memory block, and so there's no intrinsic limit to
109 the number that could be passed, but it's currently four.
110
nethercote54265442004-10-26 12:56:58 +0000111 The macro args are:
112 _zzq_rlval result lvalue
113 _zzq_default default value (result returned when running on real CPU)
114 _zzq_request request code
115 _zzq_arg1..4 request params
116
nethercotee90c6832004-10-18 18:07:49 +0000117 Nb: we put the assembly code sequences for all architectures in this one
njn26aba4d2005-05-16 13:31:23 +0000118 file. This is because this file must be stand-alone, and we don't want
119 to have multiple files.
nethercotee90c6832004-10-18 18:07:49 +0000120*/
121
njn26aba4d2005-05-16 13:31:23 +0000122#ifdef __x86_64__
sewardjde4a4ab2005-03-23 13:10:32 +0000123extern int printf (__const char *__restrict __format, ...);
124extern void exit (int __status);
125#define VALGRIND_MAGIC_SEQUENCE( \
126 _zzq_rlval, _zzq_default, _zzq_request, \
127 _zzq_arg1, _zzq_arg2, _zzq_arg3, _zzq_arg4) \
128 \
129 { volatile unsigned long long _zzq_args[5]; \
130 _zzq_args[0] = (volatile unsigned long long)(_zzq_request); \
131 _zzq_args[1] = (volatile unsigned long long)(_zzq_arg1); \
132 _zzq_args[2] = (volatile unsigned long long)(_zzq_arg2); \
133 _zzq_args[3] = (volatile unsigned long long)(_zzq_arg3); \
134 _zzq_args[4] = (volatile unsigned long long)(_zzq_arg4); \
135 asm volatile("roll $29, %%eax ; roll $3, %%eax\n\t" \
136 "rorl $27, %%eax ; rorl $5, %%eax\n\t" \
137 "roll $13, %%eax ; roll $19, %%eax" \
138 : "=d" (_zzq_rlval) \
139 : "a" (&_zzq_args[0]), "0" (_zzq_default) \
140 : "cc", "memory" \
141 ); \
142 }
njn26aba4d2005-05-16 13:31:23 +0000143#endif // __x86_64__
sewardjde4a4ab2005-03-23 13:10:32 +0000144
145#ifdef __i386__
146#define VALGRIND_MAGIC_SEQUENCE( \
147 _zzq_rlval, _zzq_default, _zzq_request, \
148 _zzq_arg1, _zzq_arg2, _zzq_arg3, _zzq_arg4) \
149 \
150 { unsigned int _zzq_args[5]; \
151 _zzq_args[0] = (unsigned int)(_zzq_request); \
152 _zzq_args[1] = (unsigned int)(_zzq_arg1); \
153 _zzq_args[2] = (unsigned int)(_zzq_arg2); \
154 _zzq_args[3] = (unsigned int)(_zzq_arg3); \
155 _zzq_args[4] = (unsigned int)(_zzq_arg4); \
156 asm volatile("roll $29, %%eax ; roll $3, %%eax\n\t" \
157 "rorl $27, %%eax ; rorl $5, %%eax\n\t" \
158 "roll $13, %%eax ; roll $19, %%eax" \
159 : "=d" (_zzq_rlval) \
160 : "a" (&_zzq_args[0]), "0" (_zzq_default) \
161 : "cc", "memory" \
162 ); \
163 }
164#endif // __i386__
sewardjde4a4ab2005-03-23 13:10:32 +0000165
njnc6168192004-11-29 13:54:10 +0000166#ifdef __arm__
njn26aba4d2005-05-16 13:31:23 +0000167// XXX: temporary, until MAGIC_SEQUENCE is written properly
njnc6168192004-11-29 13:54:10 +0000168extern int printf (__const char *__restrict __format, ...);
169extern void exit (int __status);
170#define VALGRIND_MAGIC_SEQUENCE( \
171 _zzq_rlval, _zzq_default, _zzq_request, \
172 _zzq_arg1, _zzq_arg2, _zzq_arg3, _zzq_arg4) \
173 \
174 { volatile unsigned int _zzq_args[5]; \
175 _zzq_args[0] = (volatile unsigned int)(_zzq_request); \
176 _zzq_args[1] = (volatile unsigned int)(_zzq_arg1); \
177 _zzq_args[2] = (volatile unsigned int)(_zzq_arg2); \
178 _zzq_args[3] = (volatile unsigned int)(_zzq_arg3); \
179 _zzq_args[4] = (volatile unsigned int)(_zzq_arg4); \
180 (_zzq_rlval) = (_zzq_default);/* temporary only */ \
181 printf("argh: MAGIC_SEQUENCE"); exit(1); \
182 asm volatile(""); \
183 }
184// XXX: make sure that the register holding the args and the register taking
njn26aba4d2005-05-16 13:31:23 +0000185// the return value match what the scheduler is expecting.
njnc6168192004-11-29 13:54:10 +0000186#endif // __arm__
nethercotee90c6832004-10-18 18:07:49 +0000187
njn26aba4d2005-05-16 13:31:23 +0000188// Insert assembly code for other architectures here...
189
sewardj37091fb2002-11-16 11:06:50 +0000190#endif /* NVALGRIND */
sewardj2e93c502002-04-12 11:12:52 +0000191
nethercote69d9c462004-10-26 13:00:12 +0000192
njn30d76c62005-06-18 15:07:39 +0000193/* ------------------------------------------------------------------ */
194/* The architecture-independent part */
195/* ------------------------------------------------------------------ */
196
sewardj2e93c502002-04-12 11:12:52 +0000197/* Some request codes. There are many more of these, but most are not
198 exposed to end-user view. These are the public ones, all of the
njn25e49d8e72002-09-23 09:36:25 +0000199 form 0x1000 + small_number.
njnd7994182003-10-02 13:44:04 +0000200
201 Core ones are in the range 0x00000000--0x0000ffff. The non-public ones
202 start at 0x2000.
sewardj2e93c502002-04-12 11:12:52 +0000203*/
204
njnfc26ff92004-11-22 19:12:49 +0000205// These macros are used by tools -- they must be public, but don't embed them
206// into other programs.
207#define VG_USERREQ_TOOL_BASE(a,b) \
njn4c791212003-05-02 17:53:54 +0000208 ((unsigned int)(((a)&0xff) << 24 | ((b)&0xff) << 16))
njnfc26ff92004-11-22 19:12:49 +0000209#define VG_IS_TOOL_USERREQ(a, b, v) \
210 (VG_USERREQ_TOOL_BASE(a,b) == ((v) & 0xffff0000))
sewardj34042512002-10-22 04:14:35 +0000211
njn25e49d8e72002-09-23 09:36:25 +0000212typedef
njn4c791212003-05-02 17:53:54 +0000213 enum { VG_USERREQ__RUNNING_ON_VALGRIND = 0x1001,
214 VG_USERREQ__DISCARD_TRANSLATIONS = 0x1002,
njn3e884182003-04-15 13:03:23 +0000215
njnd4795be2004-11-24 11:57:51 +0000216 /* These allow any function to be called from the
217 simulated CPU but run on the real CPU.
218 Nb: the first arg passed to the function is always the ThreadId of
219 the running thread! So CLIENT_CALL0 actually requires a 1 arg
220 function, etc. */
njn4c791212003-05-02 17:53:54 +0000221 VG_USERREQ__CLIENT_CALL0 = 0x1101,
222 VG_USERREQ__CLIENT_CALL1 = 0x1102,
223 VG_USERREQ__CLIENT_CALL2 = 0x1103,
224 VG_USERREQ__CLIENT_CALL3 = 0x1104,
njn3e884182003-04-15 13:03:23 +0000225
njn47363ab2003-04-21 13:24:40 +0000226 /* Can be useful in regression testing suites -- eg. can send
227 Valgrind's output to /dev/null and still count errors. */
njn4c791212003-05-02 17:53:54 +0000228 VG_USERREQ__COUNT_ERRORS = 0x1201,
njn47363ab2003-04-21 13:24:40 +0000229
nethercote7cc9c232004-01-21 15:08:04 +0000230 /* These are useful and can be interpreted by any tool that tracks
njnd7994182003-10-02 13:44:04 +0000231 malloc() et al, by using vg_replace_malloc.c. */
232 VG_USERREQ__MALLOCLIKE_BLOCK = 0x1301,
233 VG_USERREQ__FREELIKE_BLOCK = 0x1302,
rjwalshbc0bb832004-06-19 18:12:36 +0000234 /* Memory pool support. */
235 VG_USERREQ__CREATE_MEMPOOL = 0x1303,
236 VG_USERREQ__DESTROY_MEMPOOL = 0x1304,
237 VG_USERREQ__MEMPOOL_ALLOC = 0x1305,
238 VG_USERREQ__MEMPOOL_FREE = 0x1306,
njnd7994182003-10-02 13:44:04 +0000239
fitzhardinge39de4b42003-10-31 07:12:21 +0000240 /* Allow printfs to valgrind log. */
njn30d76c62005-06-18 15:07:39 +0000241 VG_USERREQ__PRINTF = 0x1401,
rjwalsh0140af52005-06-04 20:42:33 +0000242 VG_USERREQ__PRINTF_BACKTRACE = 0x1402,
243
244 /* Stack support. */
245 VG_USERREQ__STACK_REGISTER = 0x1501,
246 VG_USERREQ__STACK_DEREGISTER = 0x1502,
247 VG_USERREQ__STACK_CHANGE = 0x1503,
njn25e49d8e72002-09-23 09:36:25 +0000248 } Vg_ClientRequest;
sewardj2e93c502002-04-12 11:12:52 +0000249
muellerc9b36552003-12-31 14:32:23 +0000250#ifndef __GNUC__
251#define __extension__
252#endif
sewardj2e93c502002-04-12 11:12:52 +0000253
njnf09745a2005-05-10 03:01:23 +0000254/* Returns the number of Valgrinds this code is running under. That is,
255 0 if running natively, 1 if running under Valgrind, 2 if running under
256 Valgrind which is running under another Valgrind, etc. */
muellerc9b36552003-12-31 14:32:23 +0000257#define RUNNING_ON_VALGRIND __extension__ \
sewardj2e93c502002-04-12 11:12:52 +0000258 ({unsigned int _qzz_res; \
259 VALGRIND_MAGIC_SEQUENCE(_qzz_res, 0 /* returned if not */, \
260 VG_USERREQ__RUNNING_ON_VALGRIND, \
261 0, 0, 0, 0); \
262 _qzz_res; \
sewardjde4a1d02002-03-22 01:27:54 +0000263 })
264
265
sewardj18d75132002-05-16 11:06:21 +0000266/* Discard translation of code in the range [_qzz_addr .. _qzz_addr +
267 _qzz_len - 1]. Useful if you are debugging a JITter or some such,
268 since it provides a way to make sure valgrind will retranslate the
269 invalidated area. Returns no value. */
270#define VALGRIND_DISCARD_TRANSLATIONS(_qzz_addr,_qzz_len) \
271 {unsigned int _qzz_res; \
272 VALGRIND_MAGIC_SEQUENCE(_qzz_res, 0, \
273 VG_USERREQ__DISCARD_TRANSLATIONS, \
274 _qzz_addr, _qzz_len, 0, 0); \
275 }
276
njn26aba4d2005-05-16 13:31:23 +0000277#ifdef NVALGRIND
278
279#define VALGRIND_PRINTF(...)
280#define VALGRIND_PRINTF_BACKTRACE(...)
281
282#else /* NVALGRIND */
fitzhardinge39de4b42003-10-31 07:12:21 +0000283
fitzhardingea09a1b52003-11-07 23:09:48 +0000284int VALGRIND_PRINTF(const char *format, ...)
285 __attribute__((format(__printf__, 1, 2)));
fitzhardinge39de4b42003-10-31 07:12:21 +0000286__attribute__((weak))
287int
fitzhardingea09a1b52003-11-07 23:09:48 +0000288VALGRIND_PRINTF(const char *format, ...)
fitzhardinge39de4b42003-10-31 07:12:21 +0000289{
njnc6168192004-11-29 13:54:10 +0000290 unsigned long _qzz_res;
fitzhardinge39de4b42003-10-31 07:12:21 +0000291 va_list vargs;
292 va_start(vargs, format);
293 VALGRIND_MAGIC_SEQUENCE(_qzz_res, 0, VG_USERREQ__PRINTF,
njnc6168192004-11-29 13:54:10 +0000294 (unsigned long)format, (unsigned long)vargs, 0, 0);
fitzhardinge39de4b42003-10-31 07:12:21 +0000295 va_end(vargs);
njnc6168192004-11-29 13:54:10 +0000296 return (int)_qzz_res;
fitzhardinge39de4b42003-10-31 07:12:21 +0000297}
298
fitzhardingea09a1b52003-11-07 23:09:48 +0000299int VALGRIND_PRINTF_BACKTRACE(const char *format, ...)
300 __attribute__((format(__printf__, 1, 2)));
fitzhardinge39de4b42003-10-31 07:12:21 +0000301__attribute__((weak))
302int
fitzhardingea09a1b52003-11-07 23:09:48 +0000303VALGRIND_PRINTF_BACKTRACE(const char *format, ...)
fitzhardinge39de4b42003-10-31 07:12:21 +0000304{
njnc6168192004-11-29 13:54:10 +0000305 unsigned long _qzz_res;
fitzhardinge39de4b42003-10-31 07:12:21 +0000306 va_list vargs;
307 va_start(vargs, format);
308 VALGRIND_MAGIC_SEQUENCE(_qzz_res, 0, VG_USERREQ__PRINTF_BACKTRACE,
njnc6168192004-11-29 13:54:10 +0000309 (unsigned long)format, (unsigned long)vargs, 0, 0);
fitzhardinge39de4b42003-10-31 07:12:21 +0000310 va_end(vargs);
njnc6168192004-11-29 13:54:10 +0000311 return (int)_qzz_res;
fitzhardinge39de4b42003-10-31 07:12:21 +0000312}
313
fitzhardinge39de4b42003-10-31 07:12:21 +0000314#endif /* NVALGRIND */
sewardj18d75132002-05-16 11:06:21 +0000315
njn3e884182003-04-15 13:03:23 +0000316/* These requests allow control to move from the simulated CPU to the
317 real CPU, calling an arbitary function */
njn057c65f2003-04-21 13:30:55 +0000318#define VALGRIND_NON_SIMD_CALL0(_qyy_fn) \
njnc6168192004-11-29 13:54:10 +0000319 ({unsigned long _qyy_res; \
njn3e884182003-04-15 13:03:23 +0000320 VALGRIND_MAGIC_SEQUENCE(_qyy_res, 0 /* default return */, \
321 VG_USERREQ__CLIENT_CALL0, \
322 _qyy_fn, \
323 0, 0, 0); \
324 _qyy_res; \
325 })
326
njn057c65f2003-04-21 13:30:55 +0000327#define VALGRIND_NON_SIMD_CALL1(_qyy_fn, _qyy_arg1) \
njnc6168192004-11-29 13:54:10 +0000328 ({unsigned long _qyy_res; \
njn3e884182003-04-15 13:03:23 +0000329 VALGRIND_MAGIC_SEQUENCE(_qyy_res, 0 /* default return */, \
330 VG_USERREQ__CLIENT_CALL1, \
331 _qyy_fn, \
332 _qyy_arg1, 0, 0); \
333 _qyy_res; \
334 })
335
njn057c65f2003-04-21 13:30:55 +0000336#define VALGRIND_NON_SIMD_CALL2(_qyy_fn, _qyy_arg1, _qyy_arg2) \
njnc6168192004-11-29 13:54:10 +0000337 ({unsigned long _qyy_res; \
njn3e884182003-04-15 13:03:23 +0000338 VALGRIND_MAGIC_SEQUENCE(_qyy_res, 0 /* default return */, \
339 VG_USERREQ__CLIENT_CALL2, \
340 _qyy_fn, \
341 _qyy_arg1, _qyy_arg2, 0); \
342 _qyy_res; \
343 })
344
njn057c65f2003-04-21 13:30:55 +0000345#define VALGRIND_NON_SIMD_CALL3(_qyy_fn, _qyy_arg1, _qyy_arg2, _qyy_arg3) \
njnc6168192004-11-29 13:54:10 +0000346 ({unsigned long _qyy_res; \
njn3e884182003-04-15 13:03:23 +0000347 VALGRIND_MAGIC_SEQUENCE(_qyy_res, 0 /* default return */, \
348 VG_USERREQ__CLIENT_CALL3, \
349 _qyy_fn, \
350 _qyy_arg1, _qyy_arg2, _qyy_arg3); \
351 _qyy_res; \
352 })
353
354
nethercote7cc9c232004-01-21 15:08:04 +0000355/* Counts the number of errors that have been recorded by a tool. Nb:
356 the tool must record the errors with VG_(maybe_record_error)() or
njn47363ab2003-04-21 13:24:40 +0000357 VG_(unique_error)() for them to be counted. */
358#define VALGRIND_COUNT_ERRORS \
359 ({unsigned int _qyy_res; \
360 VALGRIND_MAGIC_SEQUENCE(_qyy_res, 0 /* default return */, \
361 VG_USERREQ__COUNT_ERRORS, \
362 0, 0, 0, 0); \
363 _qyy_res; \
364 })
365
njnd7994182003-10-02 13:44:04 +0000366/* Mark a block of memory as having been allocated by a malloc()-like
367 function. `addr' is the start of the usable block (ie. after any
368 redzone) `rzB' is redzone size if the allocator can apply redzones;
369 use '0' if not. Adding redzones makes it more likely Valgrind will spot
370 block overruns. `is_zeroed' indicates if the memory is zeroed, as it is
371 for calloc(). Put it immediately after the point where a block is
372 allocated.
373
374 If you're allocating memory via superblocks, and then handing out small
375 chunks of each superblock, if you don't have redzones on your small
376 blocks, it's worth marking the superblock with VALGRIND_MAKE_NOACCESS
377 when it's created, so that block overruns are detected. But if you can
378 put redzones on, it's probably better to not do this, so that messages
379 for small overruns are described in terms of the small block rather than
380 the superblock (but if you have a big overrun that skips over a redzone,
381 you could miss an error this way). See memcheck/tests/custom_alloc.c
382 for an example.
383
384 Nb: block must be freed via a free()-like function specified
385 with VALGRIND_FREELIKE_BLOCK or mismatch errors will occur. */
386#define VALGRIND_MALLOCLIKE_BLOCK(addr, sizeB, rzB, is_zeroed) \
387 {unsigned int _qzz_res; \
388 VALGRIND_MAGIC_SEQUENCE(_qzz_res, 0, \
389 VG_USERREQ__MALLOCLIKE_BLOCK, \
390 addr, sizeB, rzB, is_zeroed); \
391 }
392
393/* Mark a block of memory as having been freed by a free()-like function.
394 `rzB' is redzone size; it must match that given to
395 VALGRIND_MALLOCLIKE_BLOCK. Memory not freed will be detected by the leak
396 checker. Put it immediately after the point where the block is freed. */
397#define VALGRIND_FREELIKE_BLOCK(addr, rzB) \
398 {unsigned int _qzz_res; \
399 VALGRIND_MAGIC_SEQUENCE(_qzz_res, 0, \
400 VG_USERREQ__FREELIKE_BLOCK, \
401 addr, rzB, 0, 0); \
402 }
403
rjwalshbc0bb832004-06-19 18:12:36 +0000404/* Create a memory pool. */
405#define VALGRIND_CREATE_MEMPOOL(pool, rzB, is_zeroed) \
406 {unsigned int _qzz_res; \
407 VALGRIND_MAGIC_SEQUENCE(_qzz_res, 0, \
408 VG_USERREQ__CREATE_MEMPOOL, \
409 pool, rzB, is_zeroed, 0); \
410 }
411
412/* Destroy a memory pool. */
413#define VALGRIND_DESTROY_MEMPOOL(pool) \
414 {unsigned int _qzz_res; \
415 VALGRIND_MAGIC_SEQUENCE(_qzz_res, 0, \
416 VG_USERREQ__DESTROY_MEMPOOL, \
417 pool, 0, 0, 0); \
418 }
419
420/* Associate a piece of memory with a memory pool. */
421#define VALGRIND_MEMPOOL_ALLOC(pool, addr, size) \
422 {unsigned int _qzz_res; \
423 VALGRIND_MAGIC_SEQUENCE(_qzz_res, 0, \
424 VG_USERREQ__MEMPOOL_ALLOC, \
425 pool, addr, size, 0); \
426 }
427
428/* Disassociate a piece of memory from a memory pool. */
429#define VALGRIND_MEMPOOL_FREE(pool, addr) \
430 {unsigned int _qzz_res; \
431 VALGRIND_MAGIC_SEQUENCE(_qzz_res, 0, \
432 VG_USERREQ__MEMPOOL_FREE, \
433 pool, addr, 0, 0); \
434 }
435
rjwalsh0140af52005-06-04 20:42:33 +0000436/* Mark a piece of memory as being a stack. Returns a stack id. */
437#define VALGRIND_STACK_REGISTER(start, end) \
438 ({unsigned int _qzz_res; \
439 VALGRIND_MAGIC_SEQUENCE(_qzz_res, 0, \
440 VG_USERREQ__STACK_REGISTER, \
441 start, end, 0, 0); \
442 _qzz_res; \
443 })
444
445/* Unmark the piece of memory associated with a stack id as being a
446 stack. */
447#define VALGRIND_STACK_DEREGISTER(id) \
448 {unsigned int _qzz_res; \
449 VALGRIND_MAGIC_SEQUENCE(_qzz_res, 0, \
450 VG_USERREQ__STACK_DEREGISTER, \
451 id, 0, 0, 0); \
452 }
453
454/* Change the start and end address of the stack id. */
455#define VALGRIND_STACK_CHANGE(id, start, end) \
456 {unsigned int _qzz_res; \
457 VALGRIND_MAGIC_SEQUENCE(_qzz_res, 0, \
458 VG_USERREQ__STACK_CHANGE, \
459 id, start, end, 0); \
460 }
461
njn3e884182003-04-15 13:03:23 +0000462#endif /* __VALGRIND_H */