bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1 | /* -*- mode: C; c-basic-offset: 3; -*- */ |
bart | 3c1e9d8 | 2008-06-30 17:10:29 +0000 | [diff] [blame] | 2 | |
| 3 | /* |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 4 | ---------------------------------------------------------------- |
bart | 3c1e9d8 | 2008-06-30 17:10:29 +0000 | [diff] [blame] | 5 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 6 | Notice that the following BSD-style license applies to this one |
| 7 | file (drd.h) only. The rest of Valgrind is licensed under the |
| 8 | terms of the GNU General Public License, version 2, unless |
| 9 | otherwise indicated. See the COPYING file in the source |
| 10 | distribution for details. |
bart | 3c1e9d8 | 2008-06-30 17:10:29 +0000 | [diff] [blame] | 11 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 12 | ---------------------------------------------------------------- |
bart | 3c1e9d8 | 2008-06-30 17:10:29 +0000 | [diff] [blame] | 13 | |
bart | d45d995 | 2009-05-31 18:53:54 +0000 | [diff] [blame] | 14 | This file is part of DRD, a Valgrind tool for verification of |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 15 | multithreaded programs. |
bart | 3c1e9d8 | 2008-06-30 17:10:29 +0000 | [diff] [blame] | 16 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 17 | Copyright (C) 2006-2009 Bart Van Assche <bart.vanassche@gmail.com>. |
| 18 | All rights reserved. |
bart | 3c1e9d8 | 2008-06-30 17:10:29 +0000 | [diff] [blame] | 19 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 20 | Redistribution and use in source and binary forms, with or without |
| 21 | modification, are permitted provided that the following conditions |
| 22 | are met: |
bart | 3c1e9d8 | 2008-06-30 17:10:29 +0000 | [diff] [blame] | 23 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 24 | 1. Redistributions of source code must retain the above copyright |
| 25 | notice, this list of conditions and the following disclaimer. |
bart | 3c1e9d8 | 2008-06-30 17:10:29 +0000 | [diff] [blame] | 26 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 27 | 2. The origin of this software must not be misrepresented; you must |
| 28 | not claim that you wrote the original software. If you use this |
| 29 | software in a product, an acknowledgment in the product |
| 30 | documentation would be appreciated but is not required. |
bart | 3c1e9d8 | 2008-06-30 17:10:29 +0000 | [diff] [blame] | 31 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 32 | 3. Altered source versions must be plainly marked as such, and must |
| 33 | not be misrepresented as being the original software. |
bart | 3c1e9d8 | 2008-06-30 17:10:29 +0000 | [diff] [blame] | 34 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 35 | 4. The name of the author may not be used to endorse or promote |
| 36 | products derived from this software without specific prior written |
| 37 | permission. |
bart | 3c1e9d8 | 2008-06-30 17:10:29 +0000 | [diff] [blame] | 38 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 39 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS |
| 40 | OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 41 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 42 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY |
| 43 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 44 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE |
| 45 | GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 46 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 47 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 48 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 49 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
bart | 3c1e9d8 | 2008-06-30 17:10:29 +0000 | [diff] [blame] | 50 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 51 | ---------------------------------------------------------------- |
bart | 3c1e9d8 | 2008-06-30 17:10:29 +0000 | [diff] [blame] | 52 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 53 | Notice that the above BSD-style license applies to this one file |
| 54 | (drd.h) only. The entire rest of Valgrind is licensed under |
| 55 | the terms of the GNU General Public License, version 2. See the |
| 56 | COPYING file in the source distribution for details. |
bart | 3c1e9d8 | 2008-06-30 17:10:29 +0000 | [diff] [blame] | 57 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 58 | ---------------------------------------------------------------- |
bart | 3c1e9d8 | 2008-06-30 17:10:29 +0000 | [diff] [blame] | 59 | */ |
| 60 | |
| 61 | #ifndef __VALGRIND_DRD_H |
| 62 | #define __VALGRIND_DRD_H |
| 63 | |
| 64 | |
| 65 | #include "valgrind.h" |
| 66 | |
| 67 | |
bart | d45d995 | 2009-05-31 18:53:54 +0000 | [diff] [blame] | 68 | /** Prefix for the (inline) functions defined in this header file. */ |
| 69 | #define DRDCL_(str) vgDrdCl_##str |
| 70 | |
| 71 | |
| 72 | /** Obtain the thread ID assigned by Valgrind's core. */ |
| 73 | #define DRD_GET_VALGRIND_THREADID (DRDCL_(get_valgrind_threadid)()) |
| 74 | |
| 75 | /** Obtain the thread ID assigned by DRD. */ |
| 76 | #define DRD_GET_DRD_THREADID (DRDCL_(get_drd_threadid)()) |
| 77 | |
| 78 | /** Tell DRD not to complain about data races for the specified variable. */ |
| 79 | #define DRD_IGNORE_VAR(x) DRDCL_(ignore_range)(&(x), sizeof(x)) |
| 80 | |
bart | d9b8eb7 | 2009-07-26 15:46:47 +0000 | [diff] [blame] | 81 | /** Tell DRD to no longer ignore data races for the specified variable. */ |
| 82 | #define DRD_STOP_IGNORING_VAR(x) DRDCL_(ignore_range)(&(x), sizeof(x)) |
| 83 | |
bart | d45d995 | 2009-05-31 18:53:54 +0000 | [diff] [blame] | 84 | /** |
bart | 31b983d | 2010-02-21 14:52:59 +0000 | [diff] [blame] | 85 | * Tell DRD to trace all memory accesses on the specified variable. |
bart | d45d995 | 2009-05-31 18:53:54 +0000 | [diff] [blame] | 86 | * until the memory that was allocated for the variable is freed. |
| 87 | */ |
| 88 | #define DRD_TRACE_VAR(x) DRDCL_(trace_range)(&(x), sizeof(x)) |
| 89 | |
bart | 1c8cc40 | 2009-07-01 18:45:45 +0000 | [diff] [blame] | 90 | /** |
| 91 | * @defgroup RaceDetectionAnnotations Data race detection annotations. |
| 92 | * |
bart | 733db9e | 2010-03-07 10:44:46 +0000 | [diff] [blame] | 93 | * @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> |
| 94 | |
bart | 1c8cc40 | 2009-07-01 18:45:45 +0000 | [diff] [blame] | 95 | * in the ThreadSanitizer project. |
| 96 | */ |
| 97 | /*@{*/ |
bart | 44afe93 | 2009-06-01 10:49:38 +0000 | [diff] [blame] | 98 | |
bart | d45d995 | 2009-05-31 18:53:54 +0000 | [diff] [blame] | 99 | /** |
bart | 733db9e | 2010-03-07 10:44:46 +0000 | [diff] [blame] | 100 | * Tell DRD to insert a happens-before mark. addr is the address of an object |
| 101 | * that is not a pthread synchronization object. |
bart | d45d995 | 2009-05-31 18:53:54 +0000 | [diff] [blame] | 102 | */ |
| 103 | #define ANNOTATE_HAPPENS_BEFORE(addr) DRDCL_(annotate_happens_before)(addr) |
| 104 | |
| 105 | /** |
bart | 733db9e | 2010-03-07 10:44:46 +0000 | [diff] [blame] | 106 | * Tell DRD that the memory accesses executed after this annotation will |
| 107 | * happen after all memory accesses performed before all preceding |
bart | df5a1e2 | 2009-06-03 08:11:02 +0000 | [diff] [blame] | 108 | * ANNOTATE_HAPPENS_BEFORE(addr). addr is the address of an object that is not |
bart | 733db9e | 2010-03-07 10:44:46 +0000 | [diff] [blame] | 109 | * a pthread synchronization object. Inserting a happens-after annotation |
| 110 | * before any other thread has passed by a happens-before annotation for the |
bart | df5a1e2 | 2009-06-03 08:11:02 +0000 | [diff] [blame] | 111 | * same address is an error. |
bart | d45d995 | 2009-05-31 18:53:54 +0000 | [diff] [blame] | 112 | */ |
| 113 | #define ANNOTATE_HAPPENS_AFTER(addr) DRDCL_(annotate_happens_after)(addr) |
| 114 | |
| 115 | /** |
bart | d45d995 | 2009-05-31 18:53:54 +0000 | [diff] [blame] | 116 | * Tell DRD that waiting on the condition variable at address cv has succeeded |
| 117 | * and a lock on the mutex at address mtx is now held. Since DRD always inserts |
| 118 | * a happens before relation between the pthread_cond_signal() or |
| 119 | * pthread_cond_broadcast() call that wakes up a pthread_cond_wait() or |
| 120 | * pthread_cond_timedwait() call and the woken up thread, this macro has been |
bart | df5a1e2 | 2009-06-03 08:11:02 +0000 | [diff] [blame] | 121 | * defined such that it has no effect. |
bart | d45d995 | 2009-05-31 18:53:54 +0000 | [diff] [blame] | 122 | */ |
bart | df5a1e2 | 2009-06-03 08:11:02 +0000 | [diff] [blame] | 123 | #define ANNOTATE_CONDVAR_LOCK_WAIT(cv, mtx) do { } while(0) |
bart | d45d995 | 2009-05-31 18:53:54 +0000 | [diff] [blame] | 124 | |
| 125 | /** |
| 126 | * Tell DRD that the condition variable at address cv is about to be signaled. |
bart | d45d995 | 2009-05-31 18:53:54 +0000 | [diff] [blame] | 127 | */ |
bart | df5a1e2 | 2009-06-03 08:11:02 +0000 | [diff] [blame] | 128 | #define ANNOTATE_CONDVAR_SIGNAL(cv) do { } while(0) |
bart | d45d995 | 2009-05-31 18:53:54 +0000 | [diff] [blame] | 129 | |
| 130 | /** |
bart | 141a7ed | 2010-03-21 17:28:10 +0000 | [diff] [blame^] | 131 | * Tell DRD that the condition variable at address cv is about to be signaled. |
| 132 | */ |
| 133 | #define ANNOTATE_CONDVAR_SIGNAL_ALL(cv) do { } while(0) |
| 134 | |
| 135 | /** |
bart | df5a1e2 | 2009-06-03 08:11:02 +0000 | [diff] [blame] | 136 | * Tell DRD that waiting on condition variable at address cv succeeded and that |
| 137 | * the memory operations performed after this annotation should be considered |
| 138 | * to happen after the matching ANNOTATE_CONDVAR_SIGNAL(cv). Since this is the |
| 139 | * default behavior of DRD, this macro and the macro above have been defined |
| 140 | * such that they have no effect. |
bart | d45d995 | 2009-05-31 18:53:54 +0000 | [diff] [blame] | 141 | */ |
bart | df5a1e2 | 2009-06-03 08:11:02 +0000 | [diff] [blame] | 142 | #define ANNOTATE_CONDVAR_WAIT(cv) do { } while(0) |
bart | d45d995 | 2009-05-31 18:53:54 +0000 | [diff] [blame] | 143 | |
bart | 141a7ed | 2010-03-21 17:28:10 +0000 | [diff] [blame^] | 144 | /** |
| 145 | * Tell DRD to consider the memory operations that happened before a mutex |
| 146 | * unlock event and after the subsequent mutex lock event on the same mutex as |
| 147 | * ordered. This is how DRD always behaves, so this macro has been defined |
| 148 | * such that it has no effect. |
| 149 | */ |
| 150 | #define ANNOTATE_PURE_HAPPENS_BEFORE_MUTEX(mtx) do { } while(0) |
| 151 | |
bart | cfb039e | 2010-03-08 07:55:23 +0000 | [diff] [blame] | 152 | /** Deprecated -- don't use this annotation. */ |
bart | df5a1e2 | 2009-06-03 08:11:02 +0000 | [diff] [blame] | 153 | #define ANNOTATE_MUTEX_IS_USED_AS_CONDVAR(mtx) do { } while(0) |
| 154 | |
| 155 | /** |
| 156 | * Tell DRD to handle the specified memory range like a pure happens-before |
| 157 | * detector would do. Since this is how DRD always behaves, this annotation |
| 158 | * has been defined such that it has no effect. |
| 159 | */ |
| 160 | #define ANNOTATE_PUBLISH_MEMORY_RANGE(addr, size) do { } while(0) |
| 161 | |
bart | cfb039e | 2010-03-08 07:55:23 +0000 | [diff] [blame] | 162 | /** Deprecated -- don't use this annotation. */ |
bart | df5a1e2 | 2009-06-03 08:11:02 +0000 | [diff] [blame] | 163 | #define ANNOTATE_UNPUBLISH_MEMORY_RANGE(addr, size) do { } while(0) |
bart | d45d995 | 2009-05-31 18:53:54 +0000 | [diff] [blame] | 164 | |
bart | cfb039e | 2010-03-08 07:55:23 +0000 | [diff] [blame] | 165 | /** Deprecated -- don't use this annotation. */ |
| 166 | #define ANNOTATE_SWAP_MEMORY_RANGE(addr, size) do { } while(0) |
| 167 | |
bart | d45d995 | 2009-05-31 18:53:54 +0000 | [diff] [blame] | 168 | /** Tell DRD that a reader-writer lock object has been initialized. */ |
| 169 | #define ANNOTATE_RWLOCK_CREATE(rwlock) \ |
bart | 66f196d | 2009-08-15 10:50:35 +0000 | [diff] [blame] | 170 | DRDCL_(annotate_rwlock_create)(rwlock) |
bart | d45d995 | 2009-05-31 18:53:54 +0000 | [diff] [blame] | 171 | |
| 172 | /** Tell DRD that a reader-writer lock object has been destroyed. */ |
| 173 | #define ANNOTATE_RWLOCK_DESTROY(rwlock) \ |
bart | 66f196d | 2009-08-15 10:50:35 +0000 | [diff] [blame] | 174 | DRDCL_(annotate_rwlock_destroy)(rwlock) |
bart | d45d995 | 2009-05-31 18:53:54 +0000 | [diff] [blame] | 175 | |
| 176 | /** |
| 177 | * Tell DRD that a reader-writer lock has been acquired. is_w == 1 means that |
| 178 | * a write lock has been obtained, is_w == 0 means that a read lock has been |
| 179 | * obtained. |
| 180 | */ |
| 181 | #define ANNOTATE_RWLOCK_ACQUIRED(rwlock, is_w) \ |
bart | 66f196d | 2009-08-15 10:50:35 +0000 | [diff] [blame] | 182 | DRDCL_(annotate_rwlock_acquired)(rwlock, is_w) |
bart | d45d995 | 2009-05-31 18:53:54 +0000 | [diff] [blame] | 183 | |
| 184 | /** |
bart | 1c8cc40 | 2009-07-01 18:45:45 +0000 | [diff] [blame] | 185 | * Tell DRD that a reader lock has been acquired on a reader-writer |
| 186 | * synchronization object. |
| 187 | */ |
| 188 | #define ANNOTATE_READERLOCK_ACQUIRED(rwlock) ANNOTATE_RWLOCK_ACQUIRED(rwlock, 0) |
| 189 | |
| 190 | /** |
| 191 | * Tell DRD that a writer lock has been acquired on a reader-writer |
| 192 | * synchronization object. |
| 193 | */ |
| 194 | #define ANNOTATE_WRITERLOCK_ACQUIRED(rwlock) ANNOTATE_RWLOCK_ACQUIRED(rwlock, 1) |
| 195 | |
| 196 | /** |
bart | d45d995 | 2009-05-31 18:53:54 +0000 | [diff] [blame] | 197 | * Tell DRD that a reader-writer lock is about to be released. is_w == 1 means |
| 198 | * that a write lock is about to be released, is_w == 0 means that a read lock |
| 199 | * is about to be released. |
| 200 | */ |
| 201 | #define ANNOTATE_RWLOCK_RELEASED(rwlock, is_w) \ |
bart | 66f196d | 2009-08-15 10:50:35 +0000 | [diff] [blame] | 202 | DRDCL_(annotate_rwlock_released)(rwlock, is_w) |
bart | d45d995 | 2009-05-31 18:53:54 +0000 | [diff] [blame] | 203 | |
bart | 82c54c4 | 2009-06-03 20:01:44 +0000 | [diff] [blame] | 204 | /** |
bart | 1c8cc40 | 2009-07-01 18:45:45 +0000 | [diff] [blame] | 205 | * Tell DRD that a reader lock is about to be released. |
| 206 | */ |
| 207 | #define ANNOTATE_READERLOCK_RELEASED(rwlock) ANNOTATE_RWLOCK_RELEASED(rwlock, 0) |
| 208 | |
| 209 | /** |
| 210 | * Tell DRD that a writer lock is about to be released. |
| 211 | */ |
| 212 | #define ANNOTATE_WRITERLOCK_RELEASED(rwlock) ANNOTATE_RWLOCK_RELEASED(rwlock, 1) |
| 213 | |
bart | 141a7ed | 2010-03-21 17:28:10 +0000 | [diff] [blame^] | 214 | /* |
| 215 | * Report that a barrier has been initialized with a given barrier count. The |
| 216 | * third argument specifies whether or not reinitialization is allowed, that |
| 217 | * is, whether or not it is allowed to call barrier_init() several times |
| 218 | * without calling barrier_destroy(). |
| 219 | */ |
| 220 | #define ANNOTATE_BARRIER_INIT(barrier, count, reinitialization_allowed) \ |
| 221 | DRDCL_(annotate_barrier_init)(barrier, count, reinitialization_allowed) |
| 222 | |
| 223 | /* Report that a barrier has been destroyed. */ |
| 224 | #define ANNOTATE_BARRIER_DESTROY(barrier) \ |
| 225 | DRDCL_(annotate_barrier_destroy)(barrier) |
| 226 | |
| 227 | /* Report that the calling thread is about to start waiting for a barrier. */ |
| 228 | #define ANNOTATE_BARRIER_WAIT_BEFORE(barrier) \ |
| 229 | DRDCL_(annotate_barrier_wait_before)(barrier) |
| 230 | |
| 231 | /* Report that the calling thread has just finished waiting for a barrier. */ |
| 232 | #define ANNOTATE_BARRIER_WAIT_AFTER(barrier) \ |
| 233 | DRDCL_(annotate_barrier_wait_after)(barrier) |
| 234 | |
bart | 1c8cc40 | 2009-07-01 18:45:45 +0000 | [diff] [blame] | 235 | /** |
bart | 82c54c4 | 2009-06-03 20:01:44 +0000 | [diff] [blame] | 236 | * Tell DRD that a FIFO queue has been created. The abbreviation PCQ stands for |
| 237 | * <em>producer-consumer</em>. |
| 238 | */ |
bart | df5a1e2 | 2009-06-03 08:11:02 +0000 | [diff] [blame] | 239 | #define ANNOTATE_PCQ_CREATE(pcq) do { } while(0) |
| 240 | |
bart | 82c54c4 | 2009-06-03 20:01:44 +0000 | [diff] [blame] | 241 | /** Tell DRD that a FIFO queue has been destroyed. */ |
bart | df5a1e2 | 2009-06-03 08:11:02 +0000 | [diff] [blame] | 242 | #define ANNOTATE_PCQ_DESTROY(pcq) do { } while(0) |
| 243 | |
bart | 82c54c4 | 2009-06-03 20:01:44 +0000 | [diff] [blame] | 244 | /** |
| 245 | * Tell DRD that an element has been added to the FIFO queue at address pcq. |
| 246 | */ |
bart | df5a1e2 | 2009-06-03 08:11:02 +0000 | [diff] [blame] | 247 | #define ANNOTATE_PCQ_PUT(pcq) do { } while(0) |
| 248 | |
bart | 82c54c4 | 2009-06-03 20:01:44 +0000 | [diff] [blame] | 249 | /** |
| 250 | * Tell DRD that an element has been removed from the FIFO queue at address pcq, |
| 251 | * and that DRD should insert a happens-before relationship between the memory |
| 252 | * accesses that occurred before the corresponding ANNOTATE_PCQ_PUT(pcq) |
| 253 | * annotation and the memory accesses after this annotation. Correspondence |
| 254 | * between PUT and GET annotations happens in FIFO order. Since locking |
| 255 | * of the queue is needed anyway to add elements to or to remove elements from |
| 256 | * the queue, for DRD all four FIFO annotations are defined as no-ops. |
| 257 | */ |
bart | df5a1e2 | 2009-06-03 08:11:02 +0000 | [diff] [blame] | 258 | #define ANNOTATE_PCQ_GET(pcq) do { } while(0) |
| 259 | |
bart | d45d995 | 2009-05-31 18:53:54 +0000 | [diff] [blame] | 260 | /** |
bart | e08eb5f | 2010-02-28 09:51:00 +0000 | [diff] [blame] | 261 | * Tell DRD that data races at the specified address are expected and must not |
| 262 | * be reported. |
bart | d45d995 | 2009-05-31 18:53:54 +0000 | [diff] [blame] | 263 | */ |
bart | e08eb5f | 2010-02-28 09:51:00 +0000 | [diff] [blame] | 264 | #define ANNOTATE_BENIGN_RACE(addr, descr) \ |
| 265 | DRDCL_(ignore_range)(addr, sizeof(*addr)) |
bart | d45d995 | 2009-05-31 18:53:54 +0000 | [diff] [blame] | 266 | |
bart | 141a7ed | 2010-03-21 17:28:10 +0000 | [diff] [blame^] | 267 | /* Same as ANNOTATE_BENIGN_RACE(address, description), but applies to |
| 268 | the memory range [address, address+size). */ |
| 269 | #define ANNOTATE_BENIGN_RACE_SIZED(address, size, description) \ |
| 270 | DRDCL_(ignore_range)(addr, size) |
| 271 | |
bart | d45d995 | 2009-05-31 18:53:54 +0000 | [diff] [blame] | 272 | /** Tell DRD to ignore all reads performed by the current thread. */ |
| 273 | #define ANNOTATE_IGNORE_READS_BEGIN() DRDCL_(set_record_loads)(0) |
| 274 | |
| 275 | /** Tell DRD to no longer ignore the reads performed by the current thread. */ |
| 276 | #define ANNOTATE_IGNORE_READS_END() DRDCL_(set_record_loads)(1) |
| 277 | |
| 278 | /** Tell DRD to ignore all writes performed by the current thread. */ |
| 279 | #define ANNOTATE_IGNORE_WRITES_BEGIN() DRDCL_(set_record_stores)(0) |
| 280 | |
| 281 | /** Tell DRD to no longer ignore the writes performed by the current thread. */ |
| 282 | #define ANNOTATE_IGNORE_WRITES_END() DRDCL_(set_record_stores)(1) |
| 283 | |
| 284 | /** Tell DRD to ignore all memory accesses performed by the current thread. */ |
| 285 | #define ANNOTATE_IGNORE_READS_AND_WRITES_BEGIN() \ |
bart | 7fd1f77 | 2009-07-23 19:01:35 +0000 | [diff] [blame] | 286 | do { DRDCL_(set_record_loads)(0); DRDCL_(set_record_stores)(0); } while(0) |
bart | d45d995 | 2009-05-31 18:53:54 +0000 | [diff] [blame] | 287 | |
| 288 | /** |
| 289 | * Tell DRD to no longer ignore the memory accesses performed by the current |
| 290 | * thread. |
| 291 | */ |
| 292 | #define ANNOTATE_IGNORE_READS_AND_WRITES_END() \ |
bart | 7fd1f77 | 2009-07-23 19:01:35 +0000 | [diff] [blame] | 293 | do { DRDCL_(set_record_loads)(1); DRDCL_(set_record_stores)(1); } while(0) |
bart | d45d995 | 2009-05-31 18:53:54 +0000 | [diff] [blame] | 294 | |
| 295 | /** |
| 296 | * Tell DRD that size bytes starting at addr has been allocated by a custom |
| 297 | * memory allocator. |
| 298 | */ |
| 299 | #define ANNOTATE_NEW_MEMORY(addr, size) DRDCL_(clean_memory)(addr, size) |
| 300 | |
| 301 | /** Ask DRD to report every access to the specified address range. */ |
| 302 | #define ANNOTATE_TRACE_MEMORY(addr) DRDCL_(trace_range)(addr, 1) |
| 303 | |
| 304 | /** |
| 305 | * Tell DRD to assign the specified name to the current thread. This name will |
| 306 | * be used in error messages printed by DRD. |
| 307 | */ |
| 308 | #define ANNOTATE_THREAD_NAME(name) DRDCL_(set_thread_name)(name) |
| 309 | |
bart | 1c8cc40 | 2009-07-01 18:45:45 +0000 | [diff] [blame] | 310 | /*@}*/ |
bart | 44afe93 | 2009-06-01 10:49:38 +0000 | [diff] [blame] | 311 | |
bart | d45d995 | 2009-05-31 18:53:54 +0000 | [diff] [blame] | 312 | |
bart | 3c1e9d8 | 2008-06-30 17:10:29 +0000 | [diff] [blame] | 313 | /* !! ABIWARNING !! ABIWARNING !! ABIWARNING !! ABIWARNING !! |
| 314 | This enum comprises an ABI exported by Valgrind to programs |
| 315 | which use client requests. DO NOT CHANGE THE ORDER OF THESE |
| 316 | ENTRIES, NOR DELETE ANY -- add new ones at the end. |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 317 | */ |
bart | d45d995 | 2009-05-31 18:53:54 +0000 | [diff] [blame] | 318 | enum { |
| 319 | /* Ask the DRD tool to discard all information about memory accesses */ |
| 320 | /* and client objects for the specified range. This client request is */ |
| 321 | /* binary compatible with the similarly named Helgrind client request. */ |
| 322 | VG_USERREQ__DRD_CLEAN_MEMORY = VG_USERREQ_TOOL_BASE('H','G'), |
| 323 | /* args: Addr, SizeT. */ |
bart | 3c1e9d8 | 2008-06-30 17:10:29 +0000 | [diff] [blame] | 324 | |
bart | d45d995 | 2009-05-31 18:53:54 +0000 | [diff] [blame] | 325 | /* Ask the DRD tool the thread ID assigned by Valgrind. */ |
| 326 | VG_USERREQ__DRD_GET_VALGRIND_THREAD_ID = VG_USERREQ_TOOL_BASE('D','R'), |
| 327 | /* args: none. */ |
| 328 | /* Ask the DRD tool the thread ID assigned by DRD. */ |
| 329 | VG_USERREQ__DRD_GET_DRD_THREAD_ID, |
| 330 | /* args: none. */ |
bart | 3c1e9d8 | 2008-06-30 17:10:29 +0000 | [diff] [blame] | 331 | |
bart | d45d995 | 2009-05-31 18:53:54 +0000 | [diff] [blame] | 332 | /* To tell the DRD tool to suppress data race detection on the */ |
| 333 | /* specified address range. */ |
| 334 | VG_USERREQ__DRD_START_SUPPRESSION, |
| 335 | /* args: start address, size in bytes */ |
| 336 | /* To tell the DRD tool no longer to suppress data race detection on */ |
| 337 | /* the specified address range. */ |
| 338 | VG_USERREQ__DRD_FINISH_SUPPRESSION, |
| 339 | /* args: start address, size in bytes */ |
bart | e747176 | 2009-03-11 18:51:22 +0000 | [diff] [blame] | 340 | |
bart | d45d995 | 2009-05-31 18:53:54 +0000 | [diff] [blame] | 341 | /* To ask the DRD tool to trace all accesses to the specified range. */ |
| 342 | VG_USERREQ__DRD_START_TRACE_ADDR, |
| 343 | /* args: Addr, SizeT. */ |
| 344 | /* To ask the DRD tool to stop tracing accesses to the specified range. */ |
| 345 | VG_USERREQ__DRD_STOP_TRACE_ADDR, |
| 346 | /* args: Addr, SizeT. */ |
| 347 | |
| 348 | /* Tell DRD whether or not to record memory loads in the calling thread. */ |
| 349 | VG_USERREQ__DRD_RECORD_LOADS, |
| 350 | /* args: Bool. */ |
| 351 | /* Tell DRD whether or not to record memory stores in the calling thread. */ |
| 352 | VG_USERREQ__DRD_RECORD_STORES, |
| 353 | /* args: Bool. */ |
| 354 | |
| 355 | /* Set the name of the thread that performs this client request. */ |
| 356 | VG_USERREQ__DRD_SET_THREAD_NAME, |
| 357 | /* args: null-terminated character string. */ |
| 358 | |
bart | 141a7ed | 2010-03-21 17:28:10 +0000 | [diff] [blame^] | 359 | /* Tell DRD that a DRD annotation has not yet been implemented. */ |
| 360 | VG_USERREQ__DRD_ANNOTATION_UNIMP, |
| 361 | /* args: Char*. */ |
| 362 | |
bart | 66f196d | 2009-08-15 10:50:35 +0000 | [diff] [blame] | 363 | /* Tell DRD that a user-defined reader-writer synchronization object |
| 364 | * has been created. */ |
| 365 | VG_USERREQ__DRD_ANNOTATE_RWLOCK_CREATE |
| 366 | = VG_USERREQ_TOOL_BASE('H','G') + 256 + 14, |
| 367 | /* args: Addr. */ |
| 368 | /* Tell DRD that a user-defined reader-writer synchronization object |
| 369 | * is about to be destroyed. */ |
| 370 | VG_USERREQ__DRD_ANNOTATE_RWLOCK_DESTROY |
| 371 | = VG_USERREQ_TOOL_BASE('H','G') + 256 + 15, |
| 372 | /* args: Addr. */ |
| 373 | /* Tell DRD that a lock on a user-defined reader-writer synchronization |
| 374 | * object has been acquired. */ |
| 375 | VG_USERREQ__DRD_ANNOTATE_RWLOCK_ACQUIRED |
| 376 | = VG_USERREQ_TOOL_BASE('H','G') + 256 + 17, |
| 377 | /* args: Addr, Int is_rw. */ |
| 378 | /* Tell DRD that a lock on a user-defined reader-writer synchronization |
| 379 | * object is about to be released. */ |
| 380 | VG_USERREQ__DRD_ANNOTATE_RWLOCK_RELEASED |
| 381 | = VG_USERREQ_TOOL_BASE('H','G') + 256 + 18, |
| 382 | /* args: Addr, Int is_rw. */ |
| 383 | |
bart | 141a7ed | 2010-03-21 17:28:10 +0000 | [diff] [blame^] | 384 | /* Tell DRD that a Helgrind annotation has not yet been implemented. */ |
| 385 | VG_USERREQ__HELGRIND_ANNOTATION_UNIMP |
bart | 66f196d | 2009-08-15 10:50:35 +0000 | [diff] [blame] | 386 | = VG_USERREQ_TOOL_BASE('H','G') + 256 + 32, |
| 387 | /* args: Char*. */ |
| 388 | |
bart | 733db9e | 2010-03-07 10:44:46 +0000 | [diff] [blame] | 389 | /* Tell DRD to insert a happens-before annotation. */ |
bart | f64a8aa | 2009-08-14 13:25:38 +0000 | [diff] [blame] | 390 | VG_USERREQ__DRD_ANNOTATE_HAPPENS_BEFORE |
| 391 | = VG_USERREQ_TOOL_BASE('H','G') + 256 + 33, |
bart | d45d995 | 2009-05-31 18:53:54 +0000 | [diff] [blame] | 392 | /* args: Addr. */ |
bart | 733db9e | 2010-03-07 10:44:46 +0000 | [diff] [blame] | 393 | /* Tell DRD to insert a happens-after annotation. */ |
bart | f64a8aa | 2009-08-14 13:25:38 +0000 | [diff] [blame] | 394 | VG_USERREQ__DRD_ANNOTATE_HAPPENS_AFTER |
| 395 | = VG_USERREQ_TOOL_BASE('H','G') + 256 + 34, |
bart | d45d995 | 2009-05-31 18:53:54 +0000 | [diff] [blame] | 396 | /* args: Addr. */ |
bart | d45d995 | 2009-05-31 18:53:54 +0000 | [diff] [blame] | 397 | |
bart | d45d995 | 2009-05-31 18:53:54 +0000 | [diff] [blame] | 398 | }; |
bart | 3c1e9d8 | 2008-06-30 17:10:29 +0000 | [diff] [blame] | 399 | |
| 400 | |
bart | d45d995 | 2009-05-31 18:53:54 +0000 | [diff] [blame] | 401 | /* |
| 402 | * Do not call the inline functions below directly but use the macro's defined |
| 403 | * above. The names of these inline functions may change from one release to |
| 404 | * another. |
bart | 8e1033f | 2008-12-25 09:31:40 +0000 | [diff] [blame] | 405 | */ |
bart | 8e1033f | 2008-12-25 09:31:40 +0000 | [diff] [blame] | 406 | |
bart | 3c1e9d8 | 2008-06-30 17:10:29 +0000 | [diff] [blame] | 407 | static __inline__ |
bart | d45d995 | 2009-05-31 18:53:54 +0000 | [diff] [blame] | 408 | void DRDCL_(clean_memory)(const void* const addr, const int size) |
| 409 | { |
| 410 | int res; |
| 411 | VALGRIND_DO_CLIENT_REQUEST(res, 0, VG_USERREQ__DRD_CLEAN_MEMORY, |
| 412 | addr, size, 0, 0, 0); |
| 413 | } |
| 414 | |
| 415 | static __inline__ |
| 416 | int DRDCL_(get_valgrind_threadid)(void) |
bart | 5f57be9 | 2008-07-01 08:48:56 +0000 | [diff] [blame] | 417 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 418 | int res; |
| 419 | VALGRIND_DO_CLIENT_REQUEST(res, 0, VG_USERREQ__DRD_GET_VALGRIND_THREAD_ID, |
| 420 | 0, 0, 0, 0, 0); |
| 421 | return res; |
bart | 5f57be9 | 2008-07-01 08:48:56 +0000 | [diff] [blame] | 422 | } |
| 423 | |
| 424 | static __inline__ |
bart | d45d995 | 2009-05-31 18:53:54 +0000 | [diff] [blame] | 425 | int DRDCL_(get_drd_threadid)(void) |
bart | 3c1e9d8 | 2008-06-30 17:10:29 +0000 | [diff] [blame] | 426 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 427 | int res; |
| 428 | VALGRIND_DO_CLIENT_REQUEST(res, 0, VG_USERREQ__DRD_GET_DRD_THREAD_ID, |
| 429 | 0, 0, 0, 0, 0); |
| 430 | return res; |
bart | 3c1e9d8 | 2008-06-30 17:10:29 +0000 | [diff] [blame] | 431 | } |
| 432 | |
| 433 | static __inline__ |
bart | d45d995 | 2009-05-31 18:53:54 +0000 | [diff] [blame] | 434 | void DRDCL_(ignore_range)(const void* const addr, const int size) |
bart | 3c1e9d8 | 2008-06-30 17:10:29 +0000 | [diff] [blame] | 435 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 436 | int res; |
| 437 | VALGRIND_DO_CLIENT_REQUEST(res, 0, VG_USERREQ__DRD_START_SUPPRESSION, |
bart | d45d995 | 2009-05-31 18:53:54 +0000 | [diff] [blame] | 438 | addr, size, 0, 0, 0); |
bart | 3c1e9d8 | 2008-06-30 17:10:29 +0000 | [diff] [blame] | 439 | } |
| 440 | |
| 441 | static __inline__ |
bart | d9b8eb7 | 2009-07-26 15:46:47 +0000 | [diff] [blame] | 442 | void DRDCL_(stop_ignoring_range)(const void* const addr, const int size) |
| 443 | { |
| 444 | int res; |
| 445 | VALGRIND_DO_CLIENT_REQUEST(res, 0, VG_USERREQ__DRD_FINISH_SUPPRESSION, |
| 446 | addr, size, 0, 0, 0); |
| 447 | } |
| 448 | |
| 449 | static __inline__ |
bart | d45d995 | 2009-05-31 18:53:54 +0000 | [diff] [blame] | 450 | void DRDCL_(trace_range)(const void* const addr, const int size) |
bart | 3c1e9d8 | 2008-06-30 17:10:29 +0000 | [diff] [blame] | 451 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 452 | int res; |
| 453 | VALGRIND_DO_CLIENT_REQUEST(res, 0, VG_USERREQ__DRD_START_TRACE_ADDR, |
bart | d45d995 | 2009-05-31 18:53:54 +0000 | [diff] [blame] | 454 | addr, size, 0, 0, 0); |
bart | 3c1e9d8 | 2008-06-30 17:10:29 +0000 | [diff] [blame] | 455 | } |
| 456 | |
bart | d45d995 | 2009-05-31 18:53:54 +0000 | [diff] [blame] | 457 | static __inline__ |
| 458 | void DRDCL_(set_record_loads)(const int enabled) |
| 459 | { |
| 460 | int res; |
| 461 | VALGRIND_DO_CLIENT_REQUEST(res, 0, VG_USERREQ__DRD_RECORD_LOADS, |
| 462 | enabled, 0, 0, 0, 0); |
| 463 | } |
| 464 | |
| 465 | static __inline__ |
| 466 | void DRDCL_(set_record_stores)(const int enabled) |
| 467 | { |
| 468 | int res; |
| 469 | VALGRIND_DO_CLIENT_REQUEST(res, 0, VG_USERREQ__DRD_RECORD_STORES, |
| 470 | enabled, 0, 0, 0, 0); |
| 471 | } |
| 472 | |
| 473 | static __inline__ |
| 474 | void DRDCL_(set_thread_name)(const char* const name) |
| 475 | { |
| 476 | int res; |
| 477 | VALGRIND_DO_CLIENT_REQUEST(res, 0, VG_USERREQ__DRD_SET_THREAD_NAME, |
| 478 | name, 0, 0, 0, 0); |
| 479 | } |
| 480 | |
| 481 | static __inline__ |
| 482 | void DRDCL_(annotate_happens_before)(const void* const addr) |
| 483 | { |
| 484 | int res; |
| 485 | VALGRIND_DO_CLIENT_REQUEST(res, 0, VG_USERREQ__DRD_ANNOTATE_HAPPENS_BEFORE, |
| 486 | addr, 0, 0, 0, 0); |
| 487 | } |
| 488 | |
| 489 | static __inline__ |
| 490 | void DRDCL_(annotate_happens_after)(const void* const addr) |
| 491 | { |
| 492 | int res; |
| 493 | VALGRIND_DO_CLIENT_REQUEST(res, 0, VG_USERREQ__DRD_ANNOTATE_HAPPENS_AFTER, |
| 494 | addr, 0, 0, 0, 0); |
| 495 | } |
| 496 | |
| 497 | static __inline__ |
bart | 66f196d | 2009-08-15 10:50:35 +0000 | [diff] [blame] | 498 | void DRDCL_(annotate_rwlock_create)(const void* const rwlock) |
bart | d45d995 | 2009-05-31 18:53:54 +0000 | [diff] [blame] | 499 | { |
| 500 | int res; |
| 501 | VALGRIND_DO_CLIENT_REQUEST(res, 0, |
bart | 66f196d | 2009-08-15 10:50:35 +0000 | [diff] [blame] | 502 | VG_USERREQ__DRD_ANNOTATE_RWLOCK_CREATE, |
| 503 | rwlock, 0, 0, 0, 0); |
| 504 | } |
| 505 | |
| 506 | static __inline__ |
| 507 | void DRDCL_(annotate_rwlock_destroy)(const void* const rwlock) |
| 508 | { |
| 509 | int res; |
| 510 | VALGRIND_DO_CLIENT_REQUEST(res, 0, |
| 511 | VG_USERREQ__DRD_ANNOTATE_RWLOCK_DESTROY, |
| 512 | rwlock, 0, 0, 0, 0); |
| 513 | } |
| 514 | |
| 515 | static __inline__ |
| 516 | void DRDCL_(annotate_rwlock_acquired)(const void* const rwlock, const int is_w) |
| 517 | { |
| 518 | int res; |
| 519 | VALGRIND_DO_CLIENT_REQUEST(res, 0, |
| 520 | VG_USERREQ__DRD_ANNOTATE_RWLOCK_ACQUIRED, |
| 521 | rwlock, is_w, 0, 0, 0); |
| 522 | } |
| 523 | |
| 524 | static __inline__ |
| 525 | void DRDCL_(annotate_rwlock_released)(const void* const rwlock, const int is_w) |
| 526 | { |
| 527 | int res; |
| 528 | VALGRIND_DO_CLIENT_REQUEST(res, 0, |
| 529 | VG_USERREQ__DRD_ANNOTATE_RWLOCK_RELEASED, |
| 530 | rwlock, is_w, 0, 0, 0); |
bart | d45d995 | 2009-05-31 18:53:54 +0000 | [diff] [blame] | 531 | } |
bart | 3c1e9d8 | 2008-06-30 17:10:29 +0000 | [diff] [blame] | 532 | |
bart | 141a7ed | 2010-03-21 17:28:10 +0000 | [diff] [blame^] | 533 | static __inline__ |
| 534 | void DRDCL_(annotate_barrier_init)(const void* barrier, const unsigned count, |
| 535 | const int reinitialization_allowed) |
| 536 | { |
| 537 | int res; |
| 538 | VALGRIND_DO_CLIENT_REQUEST(res, 0, |
| 539 | VG_USERREQ__DRD_ANNOTATION_UNIMP, |
| 540 | "ANNOTATE_BARRIER_INIT", 0, 0, 0, 0); |
| 541 | } |
| 542 | |
| 543 | static __inline__ |
| 544 | void DRDCL_(annotate_barrier_destroy)(const void* barrier) |
| 545 | { |
| 546 | int res; |
| 547 | VALGRIND_DO_CLIENT_REQUEST(res, 0, |
| 548 | VG_USERREQ__DRD_ANNOTATION_UNIMP, |
| 549 | "ANNOTATE_BARRIER_DESTROY", 0, 0, 0, 0); |
| 550 | } |
| 551 | |
| 552 | static __inline__ |
| 553 | void DRDCL_(annotate_barrier_wait_before)(const void* barrier) |
| 554 | { |
| 555 | int res; |
| 556 | VALGRIND_DO_CLIENT_REQUEST(res, 0, |
| 557 | VG_USERREQ__DRD_ANNOTATION_UNIMP, |
| 558 | "ANNOTATE_BARRIER_WAIT_BEFORE", 0, 0, 0, 0); |
| 559 | } |
| 560 | |
| 561 | static __inline__ |
| 562 | void DRDCL_(annotate_barrier_wait_after)(const void* barrier) |
| 563 | { |
| 564 | int res; |
| 565 | VALGRIND_DO_CLIENT_REQUEST(res, 0, |
| 566 | VG_USERREQ__DRD_ANNOTATION_UNIMP, |
| 567 | "ANNOTATE_BARRIER_WAIT_AFTER", 0, 0, 0, 0); |
| 568 | } |
| 569 | |
| 570 | |
| 571 | /** |
| 572 | * @addtogroup RaceDetectionAnnotations |
| 573 | */ |
| 574 | /*@{*/ |
| 575 | |
| 576 | #ifdef __cplusplus |
| 577 | /* ANNOTATE_UNPROTECTED_READ is the preferred way to annotate racy reads. |
| 578 | |
| 579 | Instead of doing |
| 580 | ANNOTATE_IGNORE_READS_BEGIN(); |
| 581 | ... = x; |
| 582 | ANNOTATE_IGNORE_READS_END(); |
| 583 | one can use |
| 584 | ... = ANNOTATE_UNPROTECTED_READ(x); */ |
| 585 | template <typename T> |
| 586 | inline T ANNOTATE_UNPROTECTED_READ(const volatile T& x) { |
| 587 | ANNOTATE_IGNORE_READS_BEGIN(); |
| 588 | const T result = x; |
| 589 | ANNOTATE_IGNORE_READS_END(); |
| 590 | return result; |
| 591 | } |
| 592 | /* Apply ANNOTATE_BENIGN_RACE_SIZED to a static variable. */ |
| 593 | #define ANNOTATE_BENIGN_RACE_STATIC(static_var, description) \ |
| 594 | namespace { \ |
| 595 | static class static_var##_annotator \ |
| 596 | { \ |
| 597 | public: \ |
| 598 | static_var##_annotator() \ |
| 599 | { \ |
| 600 | ANNOTATE_BENIGN_RACE(&static_var, #static_var ": " description); \ |
| 601 | } \ |
| 602 | } the_##static_var##_annotator; \ |
| 603 | } |
| 604 | #endif |
| 605 | |
| 606 | /*@}*/ |
| 607 | |
bart | 3c1e9d8 | 2008-06-30 17:10:29 +0000 | [diff] [blame] | 608 | #endif /* __VALGRIND_DRD_H */ |