blob: d63b3dd2072b56fc97a2422a7b254eec528be658 [file] [log] [blame]
bart3c1e9d82008-06-30 17:10:29 +00001/*
bartbedfd232009-03-26 19:07:15 +00002 ----------------------------------------------------------------
bart3c1e9d82008-06-30 17:10:29 +00003
bartbedfd232009-03-26 19:07:15 +00004 Notice that the following BSD-style license applies to this one
5 file (drd.h) only. The rest of Valgrind is licensed under the
6 terms of the GNU General Public License, version 2, unless
7 otherwise indicated. See the COPYING file in the source
8 distribution for details.
bart3c1e9d82008-06-30 17:10:29 +00009
bartbedfd232009-03-26 19:07:15 +000010 ----------------------------------------------------------------
bart3c1e9d82008-06-30 17:10:29 +000011
bartd45d9952009-05-31 18:53:54 +000012 This file is part of DRD, a Valgrind tool for verification of
bartbedfd232009-03-26 19:07:15 +000013 multithreaded programs.
bart3c1e9d82008-06-30 17:10:29 +000014
Elliott Hughesed398002017-06-21 14:41:24 -070015 Copyright (C) 2006-2017 Bart Van Assche <bvanassche@acm.org>.
bartbedfd232009-03-26 19:07:15 +000016 All rights reserved.
bart3c1e9d82008-06-30 17:10:29 +000017
bartbedfd232009-03-26 19:07:15 +000018 Redistribution and use in source and binary forms, with or without
19 modification, are permitted provided that the following conditions
20 are met:
bart3c1e9d82008-06-30 17:10:29 +000021
bartbedfd232009-03-26 19:07:15 +000022 1. Redistributions of source code must retain the above copyright
23 notice, this list of conditions and the following disclaimer.
bart3c1e9d82008-06-30 17:10:29 +000024
bartbedfd232009-03-26 19:07:15 +000025 2. The origin of this software must not be misrepresented; you must
26 not claim that you wrote the original software. If you use this
27 software in a product, an acknowledgment in the product
28 documentation would be appreciated but is not required.
bart3c1e9d82008-06-30 17:10:29 +000029
bartbedfd232009-03-26 19:07:15 +000030 3. Altered source versions must be plainly marked as such, and must
31 not be misrepresented as being the original software.
bart3c1e9d82008-06-30 17:10:29 +000032
bartbedfd232009-03-26 19:07:15 +000033 4. The name of the author may not be used to endorse or promote
34 products derived from this software without specific prior written
35 permission.
bart3c1e9d82008-06-30 17:10:29 +000036
bartbedfd232009-03-26 19:07:15 +000037 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
38 OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
39 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
40 ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
41 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
42 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
43 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
44 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
45 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
46 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
47 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
bart3c1e9d82008-06-30 17:10:29 +000048
bartbedfd232009-03-26 19:07:15 +000049 ----------------------------------------------------------------
bart3c1e9d82008-06-30 17:10:29 +000050
bartbedfd232009-03-26 19:07:15 +000051 Notice that the above BSD-style license applies to this one file
52 (drd.h) only. The entire rest of Valgrind is licensed under
53 the terms of the GNU General Public License, version 2. See the
54 COPYING file in the source distribution for details.
bart3c1e9d82008-06-30 17:10:29 +000055
bartbedfd232009-03-26 19:07:15 +000056 ----------------------------------------------------------------
bart3c1e9d82008-06-30 17:10:29 +000057*/
58
59#ifndef __VALGRIND_DRD_H
60#define __VALGRIND_DRD_H
61
62
63#include "valgrind.h"
64
65
bartd45d9952009-05-31 18:53:54 +000066/** Obtain the thread ID assigned by Valgrind's core. */
bart575ce8e2011-05-15 07:04:03 +000067#define DRD_GET_VALGRIND_THREADID \
68 (unsigned)VALGRIND_DO_CLIENT_REQUEST_EXPR(0, \
69 VG_USERREQ__DRD_GET_VALGRIND_THREAD_ID, \
barta7103ba2010-09-02 09:38:55 +000070 0, 0, 0, 0, 0)
bartd45d9952009-05-31 18:53:54 +000071
72/** Obtain the thread ID assigned by DRD. */
bart575ce8e2011-05-15 07:04:03 +000073#define DRD_GET_DRD_THREADID \
74 (unsigned)VALGRIND_DO_CLIENT_REQUEST_EXPR(0, \
75 VG_USERREQ__DRD_GET_DRD_THREAD_ID, \
barta7103ba2010-09-02 09:38:55 +000076 0, 0, 0, 0, 0)
77
bartd45d9952009-05-31 18:53:54 +000078
79/** Tell DRD not to complain about data races for the specified variable. */
barta7103ba2010-09-02 09:38:55 +000080#define DRD_IGNORE_VAR(x) ANNOTATE_BENIGN_RACE_SIZED(&(x), sizeof(x), "")
bartd45d9952009-05-31 18:53:54 +000081
bartd9b8eb72009-07-26 15:46:47 +000082/** Tell DRD to no longer ignore data races for the specified variable. */
sewardj4b3a7422011-10-24 13:21:57 +000083#define DRD_STOP_IGNORING_VAR(x) \
84 VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DRD_FINISH_SUPPRESSION, \
barta7103ba2010-09-02 09:38:55 +000085 &(x), sizeof(x), 0, 0, 0)
bartd9b8eb72009-07-26 15:46:47 +000086
bartd45d9952009-05-31 18:53:54 +000087/**
bart37013cf2011-12-12 19:04:28 +000088 * Tell DRD to trace all memory accesses for the specified variable
bartd45d9952009-05-31 18:53:54 +000089 * until the memory that was allocated for the variable is freed.
90 */
sewardj4b3a7422011-10-24 13:21:57 +000091#define DRD_TRACE_VAR(x) \
92 VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DRD_START_TRACE_ADDR, \
barta7103ba2010-09-02 09:38:55 +000093 &(x), sizeof(x), 0, 0, 0)
bartd45d9952009-05-31 18:53:54 +000094
bart1c8cc402009-07-01 18:45:45 +000095/**
bart37013cf2011-12-12 19:04:28 +000096 * Tell DRD to stop tracing memory accesses for the specified variable.
97 */
bartd6780542012-01-21 18:33:56 +000098#define DRD_STOP_TRACING_VAR(x) \
bart37013cf2011-12-12 19:04:28 +000099 VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DRD_STOP_TRACE_ADDR, \
100 &(x), sizeof(x), 0, 0, 0)
101
102/**
bart1c8cc402009-07-01 18:45:45 +0000103 * @defgroup RaceDetectionAnnotations Data race detection annotations.
104 *
bart733db9e2010-03-07 10:44:46 +0000105 * @see See also the source file <a href="http://code.google.com/p/data-race-test/source/browse/trunk/dynamic_annotations/dynamic_annotations.h</a>
106
bart1c8cc402009-07-01 18:45:45 +0000107 * in the ThreadSanitizer project.
108 */
109/*@{*/
bart44afe932009-06-01 10:49:38 +0000110
bart88d75842012-03-08 14:44:57 +0000111#ifndef __HELGRIND_H
112
bartd45d9952009-05-31 18:53:54 +0000113/**
bart733db9e2010-03-07 10:44:46 +0000114 * Tell DRD to insert a happens-before mark. addr is the address of an object
115 * that is not a pthread synchronization object.
bartd45d9952009-05-31 18:53:54 +0000116 */
sewardj4b3a7422011-10-24 13:21:57 +0000117#define ANNOTATE_HAPPENS_BEFORE(addr) \
118 VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DRD_ANNOTATE_HAPPENS_BEFORE, \
barta7103ba2010-09-02 09:38:55 +0000119 addr, 0, 0, 0, 0)
bartd45d9952009-05-31 18:53:54 +0000120
121/**
bart733db9e2010-03-07 10:44:46 +0000122 * Tell DRD that the memory accesses executed after this annotation will
123 * happen after all memory accesses performed before all preceding
bartdf5a1e22009-06-03 08:11:02 +0000124 * ANNOTATE_HAPPENS_BEFORE(addr). addr is the address of an object that is not
bart733db9e2010-03-07 10:44:46 +0000125 * a pthread synchronization object. Inserting a happens-after annotation
126 * before any other thread has passed by a happens-before annotation for the
bartdf5a1e22009-06-03 08:11:02 +0000127 * same address is an error.
bartd45d9952009-05-31 18:53:54 +0000128 */
sewardj4b3a7422011-10-24 13:21:57 +0000129#define ANNOTATE_HAPPENS_AFTER(addr) \
130 VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DRD_ANNOTATE_HAPPENS_AFTER, \
barta7103ba2010-09-02 09:38:55 +0000131 addr, 0, 0, 0, 0)
bartd45d9952009-05-31 18:53:54 +0000132
bart88d75842012-03-08 14:44:57 +0000133#else /* __HELGRIND_H */
134
135#undef ANNOTATE_CONDVAR_LOCK_WAIT
136#undef ANNOTATE_CONDVAR_WAIT
137#undef ANNOTATE_CONDVAR_SIGNAL
138#undef ANNOTATE_CONDVAR_SIGNAL_ALL
139#undef ANNOTATE_PURE_HAPPENS_BEFORE_MUTEX
140#undef ANNOTATE_PUBLISH_MEMORY_RANGE
141#undef ANNOTATE_BARRIER_INIT
142#undef ANNOTATE_BARRIER_WAIT_BEFORE
143#undef ANNOTATE_BARRIER_WAIT_AFTER
144#undef ANNOTATE_BARRIER_DESTROY
145#undef ANNOTATE_PCQ_CREATE
146#undef ANNOTATE_PCQ_DESTROY
147#undef ANNOTATE_PCQ_PUT
148#undef ANNOTATE_PCQ_GET
149#undef ANNOTATE_BENIGN_RACE
150#undef ANNOTATE_BENIGN_RACE_SIZED
151#undef ANNOTATE_IGNORE_READS_BEGIN
152#undef ANNOTATE_IGNORE_READS_END
153#undef ANNOTATE_IGNORE_WRITES_BEGIN
154#undef ANNOTATE_IGNORE_WRITES_END
155#undef ANNOTATE_IGNORE_READS_AND_WRITES_BEGIN
156#undef ANNOTATE_IGNORE_READS_AND_WRITES_END
157#undef ANNOTATE_NEW_MEMORY
158#undef ANNOTATE_TRACE_MEMORY
159#undef ANNOTATE_THREAD_NAME
160
161#endif /* __HELGRIND_H */
162
bartd45d9952009-05-31 18:53:54 +0000163/**
bartd45d9952009-05-31 18:53:54 +0000164 * Tell DRD that waiting on the condition variable at address cv has succeeded
165 * and a lock on the mutex at address mtx is now held. Since DRD always inserts
166 * a happens before relation between the pthread_cond_signal() or
167 * pthread_cond_broadcast() call that wakes up a pthread_cond_wait() or
168 * pthread_cond_timedwait() call and the woken up thread, this macro has been
bartdf5a1e22009-06-03 08:11:02 +0000169 * defined such that it has no effect.
bartd45d9952009-05-31 18:53:54 +0000170 */
bartdf5a1e22009-06-03 08:11:02 +0000171#define ANNOTATE_CONDVAR_LOCK_WAIT(cv, mtx) do { } while(0)
bartd45d9952009-05-31 18:53:54 +0000172
173/**
174 * Tell DRD that the condition variable at address cv is about to be signaled.
bartd45d9952009-05-31 18:53:54 +0000175 */
bartdf5a1e22009-06-03 08:11:02 +0000176#define ANNOTATE_CONDVAR_SIGNAL(cv) do { } while(0)
bartd45d9952009-05-31 18:53:54 +0000177
178/**
bart141a7ed2010-03-21 17:28:10 +0000179 * Tell DRD that the condition variable at address cv is about to be signaled.
180 */
181#define ANNOTATE_CONDVAR_SIGNAL_ALL(cv) do { } while(0)
182
183/**
bartdf5a1e22009-06-03 08:11:02 +0000184 * Tell DRD that waiting on condition variable at address cv succeeded and that
185 * the memory operations performed after this annotation should be considered
186 * to happen after the matching ANNOTATE_CONDVAR_SIGNAL(cv). Since this is the
187 * default behavior of DRD, this macro and the macro above have been defined
188 * such that they have no effect.
bartd45d9952009-05-31 18:53:54 +0000189 */
bartdf5a1e22009-06-03 08:11:02 +0000190#define ANNOTATE_CONDVAR_WAIT(cv) do { } while(0)
bartd45d9952009-05-31 18:53:54 +0000191
bart141a7ed2010-03-21 17:28:10 +0000192/**
193 * Tell DRD to consider the memory operations that happened before a mutex
194 * unlock event and after the subsequent mutex lock event on the same mutex as
195 * ordered. This is how DRD always behaves, so this macro has been defined
196 * such that it has no effect.
197 */
198#define ANNOTATE_PURE_HAPPENS_BEFORE_MUTEX(mtx) do { } while(0)
199
bartcfb039e2010-03-08 07:55:23 +0000200/** Deprecated -- don't use this annotation. */
bartdf5a1e22009-06-03 08:11:02 +0000201#define ANNOTATE_MUTEX_IS_USED_AS_CONDVAR(mtx) do { } while(0)
202
203/**
204 * Tell DRD to handle the specified memory range like a pure happens-before
205 * detector would do. Since this is how DRD always behaves, this annotation
206 * has been defined such that it has no effect.
207 */
208#define ANNOTATE_PUBLISH_MEMORY_RANGE(addr, size) do { } while(0)
209
bartcfb039e2010-03-08 07:55:23 +0000210/** Deprecated -- don't use this annotation. */
bartdf5a1e22009-06-03 08:11:02 +0000211#define ANNOTATE_UNPUBLISH_MEMORY_RANGE(addr, size) do { } while(0)
bartd45d9952009-05-31 18:53:54 +0000212
bartcfb039e2010-03-08 07:55:23 +0000213/** Deprecated -- don't use this annotation. */
214#define ANNOTATE_SWAP_MEMORY_RANGE(addr, size) do { } while(0)
215
bart88d75842012-03-08 14:44:57 +0000216#ifndef __HELGRIND_H
217
bartd45d9952009-05-31 18:53:54 +0000218/** Tell DRD that a reader-writer lock object has been initialized. */
sewardj4b3a7422011-10-24 13:21:57 +0000219#define ANNOTATE_RWLOCK_CREATE(rwlock) \
220 VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DRD_ANNOTATE_RWLOCK_CREATE, \
barta7103ba2010-09-02 09:38:55 +0000221 rwlock, 0, 0, 0, 0);
bartd45d9952009-05-31 18:53:54 +0000222
223/** Tell DRD that a reader-writer lock object has been destroyed. */
sewardj4b3a7422011-10-24 13:21:57 +0000224#define ANNOTATE_RWLOCK_DESTROY(rwlock) \
225 VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DRD_ANNOTATE_RWLOCK_DESTROY, \
barta7103ba2010-09-02 09:38:55 +0000226 rwlock, 0, 0, 0, 0);
bartd45d9952009-05-31 18:53:54 +0000227
228/**
229 * Tell DRD that a reader-writer lock has been acquired. is_w == 1 means that
230 * a write lock has been obtained, is_w == 0 means that a read lock has been
231 * obtained.
232 */
sewardj4b3a7422011-10-24 13:21:57 +0000233#define ANNOTATE_RWLOCK_ACQUIRED(rwlock, is_w) \
234 VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DRD_ANNOTATE_RWLOCK_ACQUIRED, \
barta7103ba2010-09-02 09:38:55 +0000235 rwlock, is_w, 0, 0, 0)
bartd45d9952009-05-31 18:53:54 +0000236
bart88d75842012-03-08 14:44:57 +0000237#endif /* __HELGRIND_H */
238
bartd45d9952009-05-31 18:53:54 +0000239/**
bart1c8cc402009-07-01 18:45:45 +0000240 * Tell DRD that a reader lock has been acquired on a reader-writer
241 * synchronization object.
242 */
243#define ANNOTATE_READERLOCK_ACQUIRED(rwlock) ANNOTATE_RWLOCK_ACQUIRED(rwlock, 0)
244
245/**
246 * Tell DRD that a writer lock has been acquired on a reader-writer
247 * synchronization object.
248 */
249#define ANNOTATE_WRITERLOCK_ACQUIRED(rwlock) ANNOTATE_RWLOCK_ACQUIRED(rwlock, 1)
250
bart88d75842012-03-08 14:44:57 +0000251#ifndef __HELGRIND_H
252
bart1c8cc402009-07-01 18:45:45 +0000253/**
bartd45d9952009-05-31 18:53:54 +0000254 * Tell DRD that a reader-writer lock is about to be released. is_w == 1 means
255 * that a write lock is about to be released, is_w == 0 means that a read lock
256 * is about to be released.
257 */
barta7103ba2010-09-02 09:38:55 +0000258#define ANNOTATE_RWLOCK_RELEASED(rwlock, is_w) \
sewardj4b3a7422011-10-24 13:21:57 +0000259 VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DRD_ANNOTATE_RWLOCK_RELEASED, \
barta7103ba2010-09-02 09:38:55 +0000260 rwlock, is_w, 0, 0, 0);
bartd45d9952009-05-31 18:53:54 +0000261
bart88d75842012-03-08 14:44:57 +0000262#endif /* __HELGRIND_H */
263
bart82c54c42009-06-03 20:01:44 +0000264/**
bart1c8cc402009-07-01 18:45:45 +0000265 * Tell DRD that a reader lock is about to be released.
266 */
267#define ANNOTATE_READERLOCK_RELEASED(rwlock) ANNOTATE_RWLOCK_RELEASED(rwlock, 0)
268
269/**
270 * Tell DRD that a writer lock is about to be released.
271 */
272#define ANNOTATE_WRITERLOCK_RELEASED(rwlock) ANNOTATE_RWLOCK_RELEASED(rwlock, 1)
273
bartcb486722014-05-18 19:32:26 +0000274/** Tell DRD that a semaphore object is going to be initialized. */
275#define ANNOTATE_SEM_INIT_PRE(sem, value) \
276 VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DRD_ANNOTATE_SEM_INIT_PRE, \
277 sem, value, 0, 0, 0);
278
279/** Tell DRD that a semaphore object has been destroyed. */
280#define ANNOTATE_SEM_DESTROY_POST(sem) \
281 VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DRD_ANNOTATE_SEM_DESTROY_POST, \
282 sem, 0, 0, 0, 0);
283
284/** Tell DRD that a semaphore is going to be acquired. */
285#define ANNOTATE_SEM_WAIT_PRE(sem) \
286 VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DRD_ANNOTATE_SEM_WAIT_PRE, \
287 sem, 0, 0, 0, 0)
288
289/** Tell DRD that a semaphore has been acquired. */
290#define ANNOTATE_SEM_WAIT_POST(sem) \
291 VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DRD_ANNOTATE_SEM_WAIT_POST, \
292 sem, 0, 0, 0, 0)
293
294/** Tell DRD that a semaphore is going to be released. */
295#define ANNOTATE_SEM_POST_PRE(sem) \
296 VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DRD_ANNOTATE_SEM_POST_PRE, \
297 sem, 0, 0, 0, 0)
298
bart141a7ed2010-03-21 17:28:10 +0000299/*
300 * Report that a barrier has been initialized with a given barrier count. The
301 * third argument specifies whether or not reinitialization is allowed, that
302 * is, whether or not it is allowed to call barrier_init() several times
303 * without calling barrier_destroy().
304 */
sewardj4b3a7422011-10-24 13:21:57 +0000305#define ANNOTATE_BARRIER_INIT(barrier, count, reinitialization_allowed) \
306 VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DRD_ANNOTATION_UNIMP, \
307 "ANNOTATE_BARRIER_INIT", barrier, \
barta7103ba2010-09-02 09:38:55 +0000308 count, reinitialization_allowed, 0)
bart141a7ed2010-03-21 17:28:10 +0000309
310/* Report that a barrier has been destroyed. */
sewardj4b3a7422011-10-24 13:21:57 +0000311#define ANNOTATE_BARRIER_DESTROY(barrier) \
312 VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DRD_ANNOTATION_UNIMP, \
313 "ANNOTATE_BARRIER_DESTROY", \
barta7103ba2010-09-02 09:38:55 +0000314 barrier, 0, 0, 0)
bart141a7ed2010-03-21 17:28:10 +0000315
316/* Report that the calling thread is about to start waiting for a barrier. */
sewardj4b3a7422011-10-24 13:21:57 +0000317#define ANNOTATE_BARRIER_WAIT_BEFORE(barrier) \
318 VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DRD_ANNOTATION_UNIMP, \
319 "ANNOTATE_BARRIER_WAIT_BEFORE", \
barta7103ba2010-09-02 09:38:55 +0000320 barrier, 0, 0, 0)
bart141a7ed2010-03-21 17:28:10 +0000321
322/* Report that the calling thread has just finished waiting for a barrier. */
sewardj4b3a7422011-10-24 13:21:57 +0000323#define ANNOTATE_BARRIER_WAIT_AFTER(barrier) \
324 VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DRD_ANNOTATION_UNIMP, \
325 "ANNOTATE_BARRIER_WAIT_AFTER", \
barta7103ba2010-09-02 09:38:55 +0000326 barrier, 0, 0, 0)
bart141a7ed2010-03-21 17:28:10 +0000327
bart1c8cc402009-07-01 18:45:45 +0000328/**
bart82c54c42009-06-03 20:01:44 +0000329 * Tell DRD that a FIFO queue has been created. The abbreviation PCQ stands for
330 * <em>producer-consumer</em>.
331 */
bartdf5a1e22009-06-03 08:11:02 +0000332#define ANNOTATE_PCQ_CREATE(pcq) do { } while(0)
333
bart82c54c42009-06-03 20:01:44 +0000334/** Tell DRD that a FIFO queue has been destroyed. */
bartdf5a1e22009-06-03 08:11:02 +0000335#define ANNOTATE_PCQ_DESTROY(pcq) do { } while(0)
336
bart82c54c42009-06-03 20:01:44 +0000337/**
338 * Tell DRD that an element has been added to the FIFO queue at address pcq.
339 */
bartdf5a1e22009-06-03 08:11:02 +0000340#define ANNOTATE_PCQ_PUT(pcq) do { } while(0)
341
bart82c54c42009-06-03 20:01:44 +0000342/**
343 * Tell DRD that an element has been removed from the FIFO queue at address pcq,
344 * and that DRD should insert a happens-before relationship between the memory
345 * accesses that occurred before the corresponding ANNOTATE_PCQ_PUT(pcq)
346 * annotation and the memory accesses after this annotation. Correspondence
347 * between PUT and GET annotations happens in FIFO order. Since locking
348 * of the queue is needed anyway to add elements to or to remove elements from
349 * the queue, for DRD all four FIFO annotations are defined as no-ops.
350 */
bartdf5a1e22009-06-03 08:11:02 +0000351#define ANNOTATE_PCQ_GET(pcq) do { } while(0)
352
bartd45d9952009-05-31 18:53:54 +0000353/**
barte08eb5f2010-02-28 09:51:00 +0000354 * Tell DRD that data races at the specified address are expected and must not
355 * be reported.
bartd45d9952009-05-31 18:53:54 +0000356 */
barte08eb5f2010-02-28 09:51:00 +0000357#define ANNOTATE_BENIGN_RACE(addr, descr) \
barta7103ba2010-09-02 09:38:55 +0000358 ANNOTATE_BENIGN_RACE_SIZED(addr, sizeof(*addr), descr)
bartd45d9952009-05-31 18:53:54 +0000359
barta7103ba2010-09-02 09:38:55 +0000360/* Same as ANNOTATE_BENIGN_RACE(addr, descr), but applies to
361 the memory range [addr, addr + size). */
sewardj4b3a7422011-10-24 13:21:57 +0000362#define ANNOTATE_BENIGN_RACE_SIZED(addr, size, descr) \
363 VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DRD_START_SUPPRESSION, \
barta7103ba2010-09-02 09:38:55 +0000364 addr, size, 0, 0, 0)
bart141a7ed2010-03-21 17:28:10 +0000365
bartd45d9952009-05-31 18:53:54 +0000366/** Tell DRD to ignore all reads performed by the current thread. */
barta7103ba2010-09-02 09:38:55 +0000367#define ANNOTATE_IGNORE_READS_BEGIN() \
sewardj4b3a7422011-10-24 13:21:57 +0000368 VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DRD_RECORD_LOADS, \
barta7103ba2010-09-02 09:38:55 +0000369 0, 0, 0, 0, 0);
370
bartd45d9952009-05-31 18:53:54 +0000371
372/** Tell DRD to no longer ignore the reads performed by the current thread. */
barta7103ba2010-09-02 09:38:55 +0000373#define ANNOTATE_IGNORE_READS_END() \
sewardj4b3a7422011-10-24 13:21:57 +0000374 VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DRD_RECORD_LOADS, \
barta7103ba2010-09-02 09:38:55 +0000375 1, 0, 0, 0, 0);
bartd45d9952009-05-31 18:53:54 +0000376
377/** Tell DRD to ignore all writes performed by the current thread. */
barta7103ba2010-09-02 09:38:55 +0000378#define ANNOTATE_IGNORE_WRITES_BEGIN() \
sewardj4b3a7422011-10-24 13:21:57 +0000379 VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DRD_RECORD_STORES, \
barta7103ba2010-09-02 09:38:55 +0000380 0, 0, 0, 0, 0)
bartd45d9952009-05-31 18:53:54 +0000381
382/** Tell DRD to no longer ignore the writes performed by the current thread. */
barta7103ba2010-09-02 09:38:55 +0000383#define ANNOTATE_IGNORE_WRITES_END() \
sewardj4b3a7422011-10-24 13:21:57 +0000384 VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DRD_RECORD_STORES, \
barta7103ba2010-09-02 09:38:55 +0000385 1, 0, 0, 0, 0)
bartd45d9952009-05-31 18:53:54 +0000386
387/** Tell DRD to ignore all memory accesses performed by the current thread. */
388#define ANNOTATE_IGNORE_READS_AND_WRITES_BEGIN() \
barta7103ba2010-09-02 09:38:55 +0000389 do { ANNOTATE_IGNORE_READS_BEGIN(); ANNOTATE_IGNORE_WRITES_BEGIN(); } while(0)
bartd45d9952009-05-31 18:53:54 +0000390
391/**
392 * Tell DRD to no longer ignore the memory accesses performed by the current
393 * thread.
394 */
395#define ANNOTATE_IGNORE_READS_AND_WRITES_END() \
barta7103ba2010-09-02 09:38:55 +0000396 do { ANNOTATE_IGNORE_READS_END(); ANNOTATE_IGNORE_WRITES_END(); } while(0)
bartd45d9952009-05-31 18:53:54 +0000397
398/**
399 * Tell DRD that size bytes starting at addr has been allocated by a custom
400 * memory allocator.
401 */
sewardj4b3a7422011-10-24 13:21:57 +0000402#define ANNOTATE_NEW_MEMORY(addr, size) \
403 VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DRD_CLEAN_MEMORY, \
barta7103ba2010-09-02 09:38:55 +0000404 addr, size, 0, 0, 0)
bartd45d9952009-05-31 18:53:54 +0000405
barta7103ba2010-09-02 09:38:55 +0000406/** Ask DRD to report every access to the specified address. */
407#define ANNOTATE_TRACE_MEMORY(addr) DRD_TRACE_VAR(*(char*)(addr))
bartd45d9952009-05-31 18:53:54 +0000408
409/**
410 * Tell DRD to assign the specified name to the current thread. This name will
411 * be used in error messages printed by DRD.
412 */
barta7103ba2010-09-02 09:38:55 +0000413#define ANNOTATE_THREAD_NAME(name) \
sewardj4b3a7422011-10-24 13:21:57 +0000414 VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DRD_SET_THREAD_NAME, \
barta7103ba2010-09-02 09:38:55 +0000415 name, 0, 0, 0, 0)
bartd45d9952009-05-31 18:53:54 +0000416
bart1c8cc402009-07-01 18:45:45 +0000417/*@}*/
bart44afe932009-06-01 10:49:38 +0000418
bartd45d9952009-05-31 18:53:54 +0000419
bart3c1e9d82008-06-30 17:10:29 +0000420/* !! ABIWARNING !! ABIWARNING !! ABIWARNING !! ABIWARNING !!
421 This enum comprises an ABI exported by Valgrind to programs
422 which use client requests. DO NOT CHANGE THE ORDER OF THESE
423 ENTRIES, NOR DELETE ANY -- add new ones at the end.
bartbedfd232009-03-26 19:07:15 +0000424*/
bartd45d9952009-05-31 18:53:54 +0000425enum {
426 /* Ask the DRD tool to discard all information about memory accesses */
427 /* and client objects for the specified range. This client request is */
428 /* binary compatible with the similarly named Helgrind client request. */
429 VG_USERREQ__DRD_CLEAN_MEMORY = VG_USERREQ_TOOL_BASE('H','G'),
430 /* args: Addr, SizeT. */
bart3c1e9d82008-06-30 17:10:29 +0000431
bartd45d9952009-05-31 18:53:54 +0000432 /* Ask the DRD tool the thread ID assigned by Valgrind. */
433 VG_USERREQ__DRD_GET_VALGRIND_THREAD_ID = VG_USERREQ_TOOL_BASE('D','R'),
434 /* args: none. */
435 /* Ask the DRD tool the thread ID assigned by DRD. */
436 VG_USERREQ__DRD_GET_DRD_THREAD_ID,
437 /* args: none. */
bart3c1e9d82008-06-30 17:10:29 +0000438
bartd45d9952009-05-31 18:53:54 +0000439 /* To tell the DRD tool to suppress data race detection on the */
440 /* specified address range. */
441 VG_USERREQ__DRD_START_SUPPRESSION,
442 /* args: start address, size in bytes */
443 /* To tell the DRD tool no longer to suppress data race detection on */
444 /* the specified address range. */
445 VG_USERREQ__DRD_FINISH_SUPPRESSION,
446 /* args: start address, size in bytes */
barte7471762009-03-11 18:51:22 +0000447
bartd45d9952009-05-31 18:53:54 +0000448 /* To ask the DRD tool to trace all accesses to the specified range. */
449 VG_USERREQ__DRD_START_TRACE_ADDR,
450 /* args: Addr, SizeT. */
451 /* To ask the DRD tool to stop tracing accesses to the specified range. */
452 VG_USERREQ__DRD_STOP_TRACE_ADDR,
453 /* args: Addr, SizeT. */
454
455 /* Tell DRD whether or not to record memory loads in the calling thread. */
456 VG_USERREQ__DRD_RECORD_LOADS,
457 /* args: Bool. */
458 /* Tell DRD whether or not to record memory stores in the calling thread. */
459 VG_USERREQ__DRD_RECORD_STORES,
460 /* args: Bool. */
461
462 /* Set the name of the thread that performs this client request. */
463 VG_USERREQ__DRD_SET_THREAD_NAME,
464 /* args: null-terminated character string. */
465
bart141a7ed2010-03-21 17:28:10 +0000466 /* Tell DRD that a DRD annotation has not yet been implemented. */
467 VG_USERREQ__DRD_ANNOTATION_UNIMP,
florian19f91bb2012-11-10 22:29:54 +0000468 /* args: char*. */
bart141a7ed2010-03-21 17:28:10 +0000469
bartcb486722014-05-18 19:32:26 +0000470 /* Tell DRD that a user-defined semaphore synchronization object
471 * is about to be created. */
472 VG_USERREQ__DRD_ANNOTATE_SEM_INIT_PRE,
473 /* args: Addr, UInt value. */
474 /* Tell DRD that a user-defined semaphore synchronization object
475 * has been destroyed. */
476 VG_USERREQ__DRD_ANNOTATE_SEM_DESTROY_POST,
477 /* args: Addr. */
478 /* Tell DRD that a user-defined semaphore synchronization
479 * object is going to be acquired (semaphore wait). */
480 VG_USERREQ__DRD_ANNOTATE_SEM_WAIT_PRE,
481 /* args: Addr. */
482 /* Tell DRD that a user-defined semaphore synchronization
483 * object has been acquired (semaphore wait). */
484 VG_USERREQ__DRD_ANNOTATE_SEM_WAIT_POST,
485 /* args: Addr. */
486 /* Tell DRD that a user-defined semaphore synchronization
487 * object is about to be released (semaphore post). */
488 VG_USERREQ__DRD_ANNOTATE_SEM_POST_PRE,
489 /* args: Addr. */
490
bart3cc26202014-06-09 09:19:26 +0000491 /* Tell DRD to ignore the inter-thread ordering introduced by a mutex. */
492 VG_USERREQ__DRD_IGNORE_MUTEX_ORDERING,
493 /* args: Addr. */
494
bart66f196d2009-08-15 10:50:35 +0000495 /* Tell DRD that a user-defined reader-writer synchronization object
496 * has been created. */
497 VG_USERREQ__DRD_ANNOTATE_RWLOCK_CREATE
498 = VG_USERREQ_TOOL_BASE('H','G') + 256 + 14,
499 /* args: Addr. */
500 /* Tell DRD that a user-defined reader-writer synchronization object
501 * is about to be destroyed. */
502 VG_USERREQ__DRD_ANNOTATE_RWLOCK_DESTROY
503 = VG_USERREQ_TOOL_BASE('H','G') + 256 + 15,
504 /* args: Addr. */
505 /* Tell DRD that a lock on a user-defined reader-writer synchronization
506 * object has been acquired. */
507 VG_USERREQ__DRD_ANNOTATE_RWLOCK_ACQUIRED
508 = VG_USERREQ_TOOL_BASE('H','G') + 256 + 17,
509 /* args: Addr, Int is_rw. */
510 /* Tell DRD that a lock on a user-defined reader-writer synchronization
511 * object is about to be released. */
512 VG_USERREQ__DRD_ANNOTATE_RWLOCK_RELEASED
513 = VG_USERREQ_TOOL_BASE('H','G') + 256 + 18,
514 /* args: Addr, Int is_rw. */
515
bart141a7ed2010-03-21 17:28:10 +0000516 /* Tell DRD that a Helgrind annotation has not yet been implemented. */
517 VG_USERREQ__HELGRIND_ANNOTATION_UNIMP
bart66f196d2009-08-15 10:50:35 +0000518 = VG_USERREQ_TOOL_BASE('H','G') + 256 + 32,
florian19f91bb2012-11-10 22:29:54 +0000519 /* args: char*. */
bart66f196d2009-08-15 10:50:35 +0000520
bart733db9e2010-03-07 10:44:46 +0000521 /* Tell DRD to insert a happens-before annotation. */
bartf64a8aa2009-08-14 13:25:38 +0000522 VG_USERREQ__DRD_ANNOTATE_HAPPENS_BEFORE
523 = VG_USERREQ_TOOL_BASE('H','G') + 256 + 33,
bartd45d9952009-05-31 18:53:54 +0000524 /* args: Addr. */
bart733db9e2010-03-07 10:44:46 +0000525 /* Tell DRD to insert a happens-after annotation. */
bartf64a8aa2009-08-14 13:25:38 +0000526 VG_USERREQ__DRD_ANNOTATE_HAPPENS_AFTER
527 = VG_USERREQ_TOOL_BASE('H','G') + 256 + 34,
bartd45d9952009-05-31 18:53:54 +0000528 /* args: Addr. */
bartd45d9952009-05-31 18:53:54 +0000529
bartd45d9952009-05-31 18:53:54 +0000530};
bart3c1e9d82008-06-30 17:10:29 +0000531
532
bart141a7ed2010-03-21 17:28:10 +0000533/**
534 * @addtogroup RaceDetectionAnnotations
535 */
536/*@{*/
537
538#ifdef __cplusplus
539/* ANNOTATE_UNPROTECTED_READ is the preferred way to annotate racy reads.
540
541 Instead of doing
542 ANNOTATE_IGNORE_READS_BEGIN();
543 ... = x;
544 ANNOTATE_IGNORE_READS_END();
545 one can use
546 ... = ANNOTATE_UNPROTECTED_READ(x); */
547template <typename T>
548inline T ANNOTATE_UNPROTECTED_READ(const volatile T& x) {
549 ANNOTATE_IGNORE_READS_BEGIN();
550 const T result = x;
551 ANNOTATE_IGNORE_READS_END();
552 return result;
553}
554/* Apply ANNOTATE_BENIGN_RACE_SIZED to a static variable. */
555#define ANNOTATE_BENIGN_RACE_STATIC(static_var, description) \
556 namespace { \
557 static class static_var##_annotator \
558 { \
559 public: \
560 static_var##_annotator() \
561 { \
bart12dca002010-10-10 18:53:00 +0000562 ANNOTATE_BENIGN_RACE_SIZED(&static_var, sizeof(static_var), \
563 #static_var ": " description); \
bart141a7ed2010-03-21 17:28:10 +0000564 } \
565 } the_##static_var##_annotator; \
566 }
567#endif
568
569/*@}*/
570
bart3c1e9d82008-06-30 17:10:29 +0000571#endif /* __VALGRIND_DRD_H */