bart | 3c1e9d8 | 2008-06-30 17:10:29 +0000 | [diff] [blame] | 1 | /* |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 2 | ---------------------------------------------------------------- |
bart | 3c1e9d8 | 2008-06-30 17:10:29 +0000 | [diff] [blame] | 3 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 4 | 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. |
bart | 3c1e9d8 | 2008-06-30 17:10:29 +0000 | [diff] [blame] | 9 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 10 | ---------------------------------------------------------------- |
bart | 3c1e9d8 | 2008-06-30 17:10:29 +0000 | [diff] [blame] | 11 | |
bart | d45d995 | 2009-05-31 18:53:54 +0000 | [diff] [blame] | 12 | This file is part of DRD, a Valgrind tool for verification of |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 13 | multithreaded programs. |
bart | 3c1e9d8 | 2008-06-30 17:10:29 +0000 | [diff] [blame] | 14 | |
bart | 922304f | 2011-03-13 12:02:44 +0000 | [diff] [blame] | 15 | Copyright (C) 2006-2011 Bart Van Assche <bvanassche@acm.org>. |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 16 | All rights reserved. |
bart | 3c1e9d8 | 2008-06-30 17:10:29 +0000 | [diff] [blame] | 17 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 18 | Redistribution and use in source and binary forms, with or without |
| 19 | modification, are permitted provided that the following conditions |
| 20 | are met: |
bart | 3c1e9d8 | 2008-06-30 17:10:29 +0000 | [diff] [blame] | 21 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 22 | 1. Redistributions of source code must retain the above copyright |
| 23 | notice, this list of conditions and the following disclaimer. |
bart | 3c1e9d8 | 2008-06-30 17:10:29 +0000 | [diff] [blame] | 24 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 25 | 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. |
bart | 3c1e9d8 | 2008-06-30 17:10:29 +0000 | [diff] [blame] | 29 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 30 | 3. Altered source versions must be plainly marked as such, and must |
| 31 | not be misrepresented as being the original software. |
bart | 3c1e9d8 | 2008-06-30 17:10:29 +0000 | [diff] [blame] | 32 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 33 | 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. |
bart | 3c1e9d8 | 2008-06-30 17:10:29 +0000 | [diff] [blame] | 36 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 37 | 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. |
bart | 3c1e9d8 | 2008-06-30 17:10:29 +0000 | [diff] [blame] | 48 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 49 | ---------------------------------------------------------------- |
bart | 3c1e9d8 | 2008-06-30 17:10:29 +0000 | [diff] [blame] | 50 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 51 | 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. |
bart | 3c1e9d8 | 2008-06-30 17:10:29 +0000 | [diff] [blame] | 55 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 56 | ---------------------------------------------------------------- |
bart | 3c1e9d8 | 2008-06-30 17:10:29 +0000 | [diff] [blame] | 57 | */ |
| 58 | |
| 59 | #ifndef __VALGRIND_DRD_H |
| 60 | #define __VALGRIND_DRD_H |
| 61 | |
| 62 | |
| 63 | #include "valgrind.h" |
| 64 | |
| 65 | |
bart | d45d995 | 2009-05-31 18:53:54 +0000 | [diff] [blame] | 66 | /** Obtain the thread ID assigned by Valgrind's core. */ |
bart | 575ce8e | 2011-05-15 07:04:03 +0000 | [diff] [blame] | 67 | #define DRD_GET_VALGRIND_THREADID \ |
| 68 | (unsigned)VALGRIND_DO_CLIENT_REQUEST_EXPR(0, \ |
| 69 | VG_USERREQ__DRD_GET_VALGRIND_THREAD_ID, \ |
bart | a7103ba | 2010-09-02 09:38:55 +0000 | [diff] [blame] | 70 | 0, 0, 0, 0, 0) |
bart | d45d995 | 2009-05-31 18:53:54 +0000 | [diff] [blame] | 71 | |
| 72 | /** Obtain the thread ID assigned by DRD. */ |
bart | 575ce8e | 2011-05-15 07:04:03 +0000 | [diff] [blame] | 73 | #define DRD_GET_DRD_THREADID \ |
| 74 | (unsigned)VALGRIND_DO_CLIENT_REQUEST_EXPR(0, \ |
| 75 | VG_USERREQ__DRD_GET_DRD_THREAD_ID, \ |
bart | a7103ba | 2010-09-02 09:38:55 +0000 | [diff] [blame] | 76 | 0, 0, 0, 0, 0) |
| 77 | |
bart | d45d995 | 2009-05-31 18:53:54 +0000 | [diff] [blame] | 78 | |
| 79 | /** Tell DRD not to complain about data races for the specified variable. */ |
bart | a7103ba | 2010-09-02 09:38:55 +0000 | [diff] [blame] | 80 | #define DRD_IGNORE_VAR(x) ANNOTATE_BENIGN_RACE_SIZED(&(x), sizeof(x), "") |
bart | d45d995 | 2009-05-31 18:53:54 +0000 | [diff] [blame] | 81 | |
bart | d9b8eb7 | 2009-07-26 15:46:47 +0000 | [diff] [blame] | 82 | /** Tell DRD to no longer ignore data races for the specified variable. */ |
sewardj | 4b3a742 | 2011-10-24 13:21:57 +0000 | [diff] [blame] | 83 | #define DRD_STOP_IGNORING_VAR(x) \ |
| 84 | VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DRD_FINISH_SUPPRESSION, \ |
bart | a7103ba | 2010-09-02 09:38:55 +0000 | [diff] [blame] | 85 | &(x), sizeof(x), 0, 0, 0) |
bart | d9b8eb7 | 2009-07-26 15:46:47 +0000 | [diff] [blame] | 86 | |
bart | d45d995 | 2009-05-31 18:53:54 +0000 | [diff] [blame] | 87 | /** |
bart | 37013cf | 2011-12-12 19:04:28 +0000 | [diff] [blame] | 88 | * Tell DRD to trace all memory accesses for the specified variable |
bart | d45d995 | 2009-05-31 18:53:54 +0000 | [diff] [blame] | 89 | * until the memory that was allocated for the variable is freed. |
| 90 | */ |
sewardj | 4b3a742 | 2011-10-24 13:21:57 +0000 | [diff] [blame] | 91 | #define DRD_TRACE_VAR(x) \ |
| 92 | VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DRD_START_TRACE_ADDR, \ |
bart | a7103ba | 2010-09-02 09:38:55 +0000 | [diff] [blame] | 93 | &(x), sizeof(x), 0, 0, 0) |
bart | d45d995 | 2009-05-31 18:53:54 +0000 | [diff] [blame] | 94 | |
bart | 1c8cc40 | 2009-07-01 18:45:45 +0000 | [diff] [blame] | 95 | /** |
bart | 37013cf | 2011-12-12 19:04:28 +0000 | [diff] [blame] | 96 | * Tell DRD to stop tracing memory accesses for the specified variable. |
| 97 | */ |
| 98 | #define DRD_STOP_TRACE_VAR(x) \ |
| 99 | VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DRD_STOP_TRACE_ADDR, \ |
| 100 | &(x), sizeof(x), 0, 0, 0) |
| 101 | |
| 102 | /** |
bart | 1c8cc40 | 2009-07-01 18:45:45 +0000 | [diff] [blame] | 103 | * @defgroup RaceDetectionAnnotations Data race detection annotations. |
| 104 | * |
bart | 733db9e | 2010-03-07 10:44:46 +0000 | [diff] [blame] | 105 | * @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 | |
bart | 1c8cc40 | 2009-07-01 18:45:45 +0000 | [diff] [blame] | 107 | * in the ThreadSanitizer project. |
| 108 | */ |
| 109 | /*@{*/ |
bart | 44afe93 | 2009-06-01 10:49:38 +0000 | [diff] [blame] | 110 | |
bart | d45d995 | 2009-05-31 18:53:54 +0000 | [diff] [blame] | 111 | /** |
bart | 733db9e | 2010-03-07 10:44:46 +0000 | [diff] [blame] | 112 | * Tell DRD to insert a happens-before mark. addr is the address of an object |
| 113 | * that is not a pthread synchronization object. |
bart | d45d995 | 2009-05-31 18:53:54 +0000 | [diff] [blame] | 114 | */ |
sewardj | 4b3a742 | 2011-10-24 13:21:57 +0000 | [diff] [blame] | 115 | #define ANNOTATE_HAPPENS_BEFORE(addr) \ |
| 116 | VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DRD_ANNOTATE_HAPPENS_BEFORE, \ |
bart | a7103ba | 2010-09-02 09:38:55 +0000 | [diff] [blame] | 117 | addr, 0, 0, 0, 0) |
bart | d45d995 | 2009-05-31 18:53:54 +0000 | [diff] [blame] | 118 | |
| 119 | /** |
bart | 733db9e | 2010-03-07 10:44:46 +0000 | [diff] [blame] | 120 | * Tell DRD that the memory accesses executed after this annotation will |
| 121 | * happen after all memory accesses performed before all preceding |
bart | df5a1e2 | 2009-06-03 08:11:02 +0000 | [diff] [blame] | 122 | * 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] | 123 | * a pthread synchronization object. Inserting a happens-after annotation |
| 124 | * before any other thread has passed by a happens-before annotation for the |
bart | df5a1e2 | 2009-06-03 08:11:02 +0000 | [diff] [blame] | 125 | * same address is an error. |
bart | d45d995 | 2009-05-31 18:53:54 +0000 | [diff] [blame] | 126 | */ |
sewardj | 4b3a742 | 2011-10-24 13:21:57 +0000 | [diff] [blame] | 127 | #define ANNOTATE_HAPPENS_AFTER(addr) \ |
| 128 | VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DRD_ANNOTATE_HAPPENS_AFTER, \ |
bart | a7103ba | 2010-09-02 09:38:55 +0000 | [diff] [blame] | 129 | addr, 0, 0, 0, 0) |
bart | d45d995 | 2009-05-31 18:53:54 +0000 | [diff] [blame] | 130 | |
| 131 | /** |
bart | d45d995 | 2009-05-31 18:53:54 +0000 | [diff] [blame] | 132 | * Tell DRD that waiting on the condition variable at address cv has succeeded |
| 133 | * and a lock on the mutex at address mtx is now held. Since DRD always inserts |
| 134 | * a happens before relation between the pthread_cond_signal() or |
| 135 | * pthread_cond_broadcast() call that wakes up a pthread_cond_wait() or |
| 136 | * pthread_cond_timedwait() call and the woken up thread, this macro has been |
bart | df5a1e2 | 2009-06-03 08:11:02 +0000 | [diff] [blame] | 137 | * defined such that it has no effect. |
bart | d45d995 | 2009-05-31 18:53:54 +0000 | [diff] [blame] | 138 | */ |
bart | df5a1e2 | 2009-06-03 08:11:02 +0000 | [diff] [blame] | 139 | #define ANNOTATE_CONDVAR_LOCK_WAIT(cv, mtx) do { } while(0) |
bart | d45d995 | 2009-05-31 18:53:54 +0000 | [diff] [blame] | 140 | |
| 141 | /** |
| 142 | * 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] | 143 | */ |
bart | df5a1e2 | 2009-06-03 08:11:02 +0000 | [diff] [blame] | 144 | #define ANNOTATE_CONDVAR_SIGNAL(cv) do { } while(0) |
bart | d45d995 | 2009-05-31 18:53:54 +0000 | [diff] [blame] | 145 | |
| 146 | /** |
bart | 141a7ed | 2010-03-21 17:28:10 +0000 | [diff] [blame] | 147 | * Tell DRD that the condition variable at address cv is about to be signaled. |
| 148 | */ |
| 149 | #define ANNOTATE_CONDVAR_SIGNAL_ALL(cv) do { } while(0) |
| 150 | |
| 151 | /** |
bart | df5a1e2 | 2009-06-03 08:11:02 +0000 | [diff] [blame] | 152 | * Tell DRD that waiting on condition variable at address cv succeeded and that |
| 153 | * the memory operations performed after this annotation should be considered |
| 154 | * to happen after the matching ANNOTATE_CONDVAR_SIGNAL(cv). Since this is the |
| 155 | * default behavior of DRD, this macro and the macro above have been defined |
| 156 | * such that they have no effect. |
bart | d45d995 | 2009-05-31 18:53:54 +0000 | [diff] [blame] | 157 | */ |
bart | df5a1e2 | 2009-06-03 08:11:02 +0000 | [diff] [blame] | 158 | #define ANNOTATE_CONDVAR_WAIT(cv) do { } while(0) |
bart | d45d995 | 2009-05-31 18:53:54 +0000 | [diff] [blame] | 159 | |
bart | 141a7ed | 2010-03-21 17:28:10 +0000 | [diff] [blame] | 160 | /** |
| 161 | * Tell DRD to consider the memory operations that happened before a mutex |
| 162 | * unlock event and after the subsequent mutex lock event on the same mutex as |
| 163 | * ordered. This is how DRD always behaves, so this macro has been defined |
| 164 | * such that it has no effect. |
| 165 | */ |
| 166 | #define ANNOTATE_PURE_HAPPENS_BEFORE_MUTEX(mtx) do { } while(0) |
| 167 | |
bart | cfb039e | 2010-03-08 07:55:23 +0000 | [diff] [blame] | 168 | /** Deprecated -- don't use this annotation. */ |
bart | df5a1e2 | 2009-06-03 08:11:02 +0000 | [diff] [blame] | 169 | #define ANNOTATE_MUTEX_IS_USED_AS_CONDVAR(mtx) do { } while(0) |
| 170 | |
| 171 | /** |
| 172 | * Tell DRD to handle the specified memory range like a pure happens-before |
| 173 | * detector would do. Since this is how DRD always behaves, this annotation |
| 174 | * has been defined such that it has no effect. |
| 175 | */ |
| 176 | #define ANNOTATE_PUBLISH_MEMORY_RANGE(addr, size) do { } while(0) |
| 177 | |
bart | cfb039e | 2010-03-08 07:55:23 +0000 | [diff] [blame] | 178 | /** Deprecated -- don't use this annotation. */ |
bart | df5a1e2 | 2009-06-03 08:11:02 +0000 | [diff] [blame] | 179 | #define ANNOTATE_UNPUBLISH_MEMORY_RANGE(addr, size) do { } while(0) |
bart | d45d995 | 2009-05-31 18:53:54 +0000 | [diff] [blame] | 180 | |
bart | cfb039e | 2010-03-08 07:55:23 +0000 | [diff] [blame] | 181 | /** Deprecated -- don't use this annotation. */ |
| 182 | #define ANNOTATE_SWAP_MEMORY_RANGE(addr, size) do { } while(0) |
| 183 | |
bart | d45d995 | 2009-05-31 18:53:54 +0000 | [diff] [blame] | 184 | /** Tell DRD that a reader-writer lock object has been initialized. */ |
sewardj | 4b3a742 | 2011-10-24 13:21:57 +0000 | [diff] [blame] | 185 | #define ANNOTATE_RWLOCK_CREATE(rwlock) \ |
| 186 | VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DRD_ANNOTATE_RWLOCK_CREATE, \ |
bart | a7103ba | 2010-09-02 09:38:55 +0000 | [diff] [blame] | 187 | rwlock, 0, 0, 0, 0); |
bart | d45d995 | 2009-05-31 18:53:54 +0000 | [diff] [blame] | 188 | |
| 189 | /** Tell DRD that a reader-writer lock object has been destroyed. */ |
sewardj | 4b3a742 | 2011-10-24 13:21:57 +0000 | [diff] [blame] | 190 | #define ANNOTATE_RWLOCK_DESTROY(rwlock) \ |
| 191 | VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DRD_ANNOTATE_RWLOCK_DESTROY, \ |
bart | a7103ba | 2010-09-02 09:38:55 +0000 | [diff] [blame] | 192 | rwlock, 0, 0, 0, 0); |
bart | d45d995 | 2009-05-31 18:53:54 +0000 | [diff] [blame] | 193 | |
| 194 | /** |
| 195 | * Tell DRD that a reader-writer lock has been acquired. is_w == 1 means that |
| 196 | * a write lock has been obtained, is_w == 0 means that a read lock has been |
| 197 | * obtained. |
| 198 | */ |
sewardj | 4b3a742 | 2011-10-24 13:21:57 +0000 | [diff] [blame] | 199 | #define ANNOTATE_RWLOCK_ACQUIRED(rwlock, is_w) \ |
| 200 | VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DRD_ANNOTATE_RWLOCK_ACQUIRED, \ |
bart | a7103ba | 2010-09-02 09:38:55 +0000 | [diff] [blame] | 201 | rwlock, is_w, 0, 0, 0) |
bart | d45d995 | 2009-05-31 18:53:54 +0000 | [diff] [blame] | 202 | |
| 203 | /** |
bart | 1c8cc40 | 2009-07-01 18:45:45 +0000 | [diff] [blame] | 204 | * Tell DRD that a reader lock has been acquired on a reader-writer |
| 205 | * synchronization object. |
| 206 | */ |
| 207 | #define ANNOTATE_READERLOCK_ACQUIRED(rwlock) ANNOTATE_RWLOCK_ACQUIRED(rwlock, 0) |
| 208 | |
| 209 | /** |
| 210 | * Tell DRD that a writer lock has been acquired on a reader-writer |
| 211 | * synchronization object. |
| 212 | */ |
| 213 | #define ANNOTATE_WRITERLOCK_ACQUIRED(rwlock) ANNOTATE_RWLOCK_ACQUIRED(rwlock, 1) |
| 214 | |
| 215 | /** |
bart | d45d995 | 2009-05-31 18:53:54 +0000 | [diff] [blame] | 216 | * Tell DRD that a reader-writer lock is about to be released. is_w == 1 means |
| 217 | * that a write lock is about to be released, is_w == 0 means that a read lock |
| 218 | * is about to be released. |
| 219 | */ |
bart | a7103ba | 2010-09-02 09:38:55 +0000 | [diff] [blame] | 220 | #define ANNOTATE_RWLOCK_RELEASED(rwlock, is_w) \ |
sewardj | 4b3a742 | 2011-10-24 13:21:57 +0000 | [diff] [blame] | 221 | VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DRD_ANNOTATE_RWLOCK_RELEASED, \ |
bart | a7103ba | 2010-09-02 09:38:55 +0000 | [diff] [blame] | 222 | rwlock, is_w, 0, 0, 0); |
bart | d45d995 | 2009-05-31 18:53:54 +0000 | [diff] [blame] | 223 | |
bart | 82c54c4 | 2009-06-03 20:01:44 +0000 | [diff] [blame] | 224 | /** |
bart | 1c8cc40 | 2009-07-01 18:45:45 +0000 | [diff] [blame] | 225 | * Tell DRD that a reader lock is about to be released. |
| 226 | */ |
| 227 | #define ANNOTATE_READERLOCK_RELEASED(rwlock) ANNOTATE_RWLOCK_RELEASED(rwlock, 0) |
| 228 | |
| 229 | /** |
| 230 | * Tell DRD that a writer lock is about to be released. |
| 231 | */ |
| 232 | #define ANNOTATE_WRITERLOCK_RELEASED(rwlock) ANNOTATE_RWLOCK_RELEASED(rwlock, 1) |
| 233 | |
bart | 141a7ed | 2010-03-21 17:28:10 +0000 | [diff] [blame] | 234 | /* |
| 235 | * Report that a barrier has been initialized with a given barrier count. The |
| 236 | * third argument specifies whether or not reinitialization is allowed, that |
| 237 | * is, whether or not it is allowed to call barrier_init() several times |
| 238 | * without calling barrier_destroy(). |
| 239 | */ |
sewardj | 4b3a742 | 2011-10-24 13:21:57 +0000 | [diff] [blame] | 240 | #define ANNOTATE_BARRIER_INIT(barrier, count, reinitialization_allowed) \ |
| 241 | VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DRD_ANNOTATION_UNIMP, \ |
| 242 | "ANNOTATE_BARRIER_INIT", barrier, \ |
bart | a7103ba | 2010-09-02 09:38:55 +0000 | [diff] [blame] | 243 | count, reinitialization_allowed, 0) |
bart | 141a7ed | 2010-03-21 17:28:10 +0000 | [diff] [blame] | 244 | |
| 245 | /* Report that a barrier has been destroyed. */ |
sewardj | 4b3a742 | 2011-10-24 13:21:57 +0000 | [diff] [blame] | 246 | #define ANNOTATE_BARRIER_DESTROY(barrier) \ |
| 247 | VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DRD_ANNOTATION_UNIMP, \ |
| 248 | "ANNOTATE_BARRIER_DESTROY", \ |
bart | a7103ba | 2010-09-02 09:38:55 +0000 | [diff] [blame] | 249 | barrier, 0, 0, 0) |
bart | 141a7ed | 2010-03-21 17:28:10 +0000 | [diff] [blame] | 250 | |
| 251 | /* Report that the calling thread is about to start waiting for a barrier. */ |
sewardj | 4b3a742 | 2011-10-24 13:21:57 +0000 | [diff] [blame] | 252 | #define ANNOTATE_BARRIER_WAIT_BEFORE(barrier) \ |
| 253 | VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DRD_ANNOTATION_UNIMP, \ |
| 254 | "ANNOTATE_BARRIER_WAIT_BEFORE", \ |
bart | a7103ba | 2010-09-02 09:38:55 +0000 | [diff] [blame] | 255 | barrier, 0, 0, 0) |
bart | 141a7ed | 2010-03-21 17:28:10 +0000 | [diff] [blame] | 256 | |
| 257 | /* Report that the calling thread has just finished waiting for a barrier. */ |
sewardj | 4b3a742 | 2011-10-24 13:21:57 +0000 | [diff] [blame] | 258 | #define ANNOTATE_BARRIER_WAIT_AFTER(barrier) \ |
| 259 | VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DRD_ANNOTATION_UNIMP, \ |
| 260 | "ANNOTATE_BARRIER_WAIT_AFTER", \ |
bart | a7103ba | 2010-09-02 09:38:55 +0000 | [diff] [blame] | 261 | barrier, 0, 0, 0) |
bart | 141a7ed | 2010-03-21 17:28:10 +0000 | [diff] [blame] | 262 | |
bart | 1c8cc40 | 2009-07-01 18:45:45 +0000 | [diff] [blame] | 263 | /** |
bart | 82c54c4 | 2009-06-03 20:01:44 +0000 | [diff] [blame] | 264 | * Tell DRD that a FIFO queue has been created. The abbreviation PCQ stands for |
| 265 | * <em>producer-consumer</em>. |
| 266 | */ |
bart | df5a1e2 | 2009-06-03 08:11:02 +0000 | [diff] [blame] | 267 | #define ANNOTATE_PCQ_CREATE(pcq) do { } while(0) |
| 268 | |
bart | 82c54c4 | 2009-06-03 20:01:44 +0000 | [diff] [blame] | 269 | /** Tell DRD that a FIFO queue has been destroyed. */ |
bart | df5a1e2 | 2009-06-03 08:11:02 +0000 | [diff] [blame] | 270 | #define ANNOTATE_PCQ_DESTROY(pcq) do { } while(0) |
| 271 | |
bart | 82c54c4 | 2009-06-03 20:01:44 +0000 | [diff] [blame] | 272 | /** |
| 273 | * Tell DRD that an element has been added to the FIFO queue at address pcq. |
| 274 | */ |
bart | df5a1e2 | 2009-06-03 08:11:02 +0000 | [diff] [blame] | 275 | #define ANNOTATE_PCQ_PUT(pcq) do { } while(0) |
| 276 | |
bart | 82c54c4 | 2009-06-03 20:01:44 +0000 | [diff] [blame] | 277 | /** |
| 278 | * Tell DRD that an element has been removed from the FIFO queue at address pcq, |
| 279 | * and that DRD should insert a happens-before relationship between the memory |
| 280 | * accesses that occurred before the corresponding ANNOTATE_PCQ_PUT(pcq) |
| 281 | * annotation and the memory accesses after this annotation. Correspondence |
| 282 | * between PUT and GET annotations happens in FIFO order. Since locking |
| 283 | * of the queue is needed anyway to add elements to or to remove elements from |
| 284 | * the queue, for DRD all four FIFO annotations are defined as no-ops. |
| 285 | */ |
bart | df5a1e2 | 2009-06-03 08:11:02 +0000 | [diff] [blame] | 286 | #define ANNOTATE_PCQ_GET(pcq) do { } while(0) |
| 287 | |
bart | d45d995 | 2009-05-31 18:53:54 +0000 | [diff] [blame] | 288 | /** |
bart | e08eb5f | 2010-02-28 09:51:00 +0000 | [diff] [blame] | 289 | * Tell DRD that data races at the specified address are expected and must not |
| 290 | * be reported. |
bart | d45d995 | 2009-05-31 18:53:54 +0000 | [diff] [blame] | 291 | */ |
bart | e08eb5f | 2010-02-28 09:51:00 +0000 | [diff] [blame] | 292 | #define ANNOTATE_BENIGN_RACE(addr, descr) \ |
bart | a7103ba | 2010-09-02 09:38:55 +0000 | [diff] [blame] | 293 | ANNOTATE_BENIGN_RACE_SIZED(addr, sizeof(*addr), descr) |
bart | d45d995 | 2009-05-31 18:53:54 +0000 | [diff] [blame] | 294 | |
bart | a7103ba | 2010-09-02 09:38:55 +0000 | [diff] [blame] | 295 | /* Same as ANNOTATE_BENIGN_RACE(addr, descr), but applies to |
| 296 | the memory range [addr, addr + size). */ |
sewardj | 4b3a742 | 2011-10-24 13:21:57 +0000 | [diff] [blame] | 297 | #define ANNOTATE_BENIGN_RACE_SIZED(addr, size, descr) \ |
| 298 | VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DRD_START_SUPPRESSION, \ |
bart | a7103ba | 2010-09-02 09:38:55 +0000 | [diff] [blame] | 299 | addr, size, 0, 0, 0) |
bart | 141a7ed | 2010-03-21 17:28:10 +0000 | [diff] [blame] | 300 | |
bart | d45d995 | 2009-05-31 18:53:54 +0000 | [diff] [blame] | 301 | /** Tell DRD to ignore all reads performed by the current thread. */ |
bart | a7103ba | 2010-09-02 09:38:55 +0000 | [diff] [blame] | 302 | #define ANNOTATE_IGNORE_READS_BEGIN() \ |
sewardj | 4b3a742 | 2011-10-24 13:21:57 +0000 | [diff] [blame] | 303 | VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DRD_RECORD_LOADS, \ |
bart | a7103ba | 2010-09-02 09:38:55 +0000 | [diff] [blame] | 304 | 0, 0, 0, 0, 0); |
| 305 | |
bart | d45d995 | 2009-05-31 18:53:54 +0000 | [diff] [blame] | 306 | |
| 307 | /** Tell DRD to no longer ignore the reads performed by the current thread. */ |
bart | a7103ba | 2010-09-02 09:38:55 +0000 | [diff] [blame] | 308 | #define ANNOTATE_IGNORE_READS_END() \ |
sewardj | 4b3a742 | 2011-10-24 13:21:57 +0000 | [diff] [blame] | 309 | VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DRD_RECORD_LOADS, \ |
bart | a7103ba | 2010-09-02 09:38:55 +0000 | [diff] [blame] | 310 | 1, 0, 0, 0, 0); |
bart | d45d995 | 2009-05-31 18:53:54 +0000 | [diff] [blame] | 311 | |
| 312 | /** Tell DRD to ignore all writes performed by the current thread. */ |
bart | a7103ba | 2010-09-02 09:38:55 +0000 | [diff] [blame] | 313 | #define ANNOTATE_IGNORE_WRITES_BEGIN() \ |
sewardj | 4b3a742 | 2011-10-24 13:21:57 +0000 | [diff] [blame] | 314 | VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DRD_RECORD_STORES, \ |
bart | a7103ba | 2010-09-02 09:38:55 +0000 | [diff] [blame] | 315 | 0, 0, 0, 0, 0) |
bart | d45d995 | 2009-05-31 18:53:54 +0000 | [diff] [blame] | 316 | |
| 317 | /** Tell DRD to no longer ignore the writes performed by the current thread. */ |
bart | a7103ba | 2010-09-02 09:38:55 +0000 | [diff] [blame] | 318 | #define ANNOTATE_IGNORE_WRITES_END() \ |
sewardj | 4b3a742 | 2011-10-24 13:21:57 +0000 | [diff] [blame] | 319 | VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DRD_RECORD_STORES, \ |
bart | a7103ba | 2010-09-02 09:38:55 +0000 | [diff] [blame] | 320 | 1, 0, 0, 0, 0) |
bart | d45d995 | 2009-05-31 18:53:54 +0000 | [diff] [blame] | 321 | |
| 322 | /** Tell DRD to ignore all memory accesses performed by the current thread. */ |
| 323 | #define ANNOTATE_IGNORE_READS_AND_WRITES_BEGIN() \ |
bart | a7103ba | 2010-09-02 09:38:55 +0000 | [diff] [blame] | 324 | do { ANNOTATE_IGNORE_READS_BEGIN(); ANNOTATE_IGNORE_WRITES_BEGIN(); } while(0) |
bart | d45d995 | 2009-05-31 18:53:54 +0000 | [diff] [blame] | 325 | |
| 326 | /** |
| 327 | * Tell DRD to no longer ignore the memory accesses performed by the current |
| 328 | * thread. |
| 329 | */ |
| 330 | #define ANNOTATE_IGNORE_READS_AND_WRITES_END() \ |
bart | a7103ba | 2010-09-02 09:38:55 +0000 | [diff] [blame] | 331 | do { ANNOTATE_IGNORE_READS_END(); ANNOTATE_IGNORE_WRITES_END(); } while(0) |
bart | d45d995 | 2009-05-31 18:53:54 +0000 | [diff] [blame] | 332 | |
| 333 | /** |
| 334 | * Tell DRD that size bytes starting at addr has been allocated by a custom |
| 335 | * memory allocator. |
| 336 | */ |
sewardj | 4b3a742 | 2011-10-24 13:21:57 +0000 | [diff] [blame] | 337 | #define ANNOTATE_NEW_MEMORY(addr, size) \ |
| 338 | VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DRD_CLEAN_MEMORY, \ |
bart | a7103ba | 2010-09-02 09:38:55 +0000 | [diff] [blame] | 339 | addr, size, 0, 0, 0) |
bart | d45d995 | 2009-05-31 18:53:54 +0000 | [diff] [blame] | 340 | |
bart | a7103ba | 2010-09-02 09:38:55 +0000 | [diff] [blame] | 341 | /** Ask DRD to report every access to the specified address. */ |
| 342 | #define ANNOTATE_TRACE_MEMORY(addr) DRD_TRACE_VAR(*(char*)(addr)) |
bart | d45d995 | 2009-05-31 18:53:54 +0000 | [diff] [blame] | 343 | |
| 344 | /** |
| 345 | * Tell DRD to assign the specified name to the current thread. This name will |
| 346 | * be used in error messages printed by DRD. |
| 347 | */ |
bart | a7103ba | 2010-09-02 09:38:55 +0000 | [diff] [blame] | 348 | #define ANNOTATE_THREAD_NAME(name) \ |
sewardj | 4b3a742 | 2011-10-24 13:21:57 +0000 | [diff] [blame] | 349 | VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DRD_SET_THREAD_NAME, \ |
bart | a7103ba | 2010-09-02 09:38:55 +0000 | [diff] [blame] | 350 | name, 0, 0, 0, 0) |
bart | d45d995 | 2009-05-31 18:53:54 +0000 | [diff] [blame] | 351 | |
bart | 1c8cc40 | 2009-07-01 18:45:45 +0000 | [diff] [blame] | 352 | /*@}*/ |
bart | 44afe93 | 2009-06-01 10:49:38 +0000 | [diff] [blame] | 353 | |
bart | d45d995 | 2009-05-31 18:53:54 +0000 | [diff] [blame] | 354 | |
bart | 3c1e9d8 | 2008-06-30 17:10:29 +0000 | [diff] [blame] | 355 | /* !! ABIWARNING !! ABIWARNING !! ABIWARNING !! ABIWARNING !! |
| 356 | This enum comprises an ABI exported by Valgrind to programs |
| 357 | which use client requests. DO NOT CHANGE THE ORDER OF THESE |
| 358 | ENTRIES, NOR DELETE ANY -- add new ones at the end. |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 359 | */ |
bart | d45d995 | 2009-05-31 18:53:54 +0000 | [diff] [blame] | 360 | enum { |
| 361 | /* Ask the DRD tool to discard all information about memory accesses */ |
| 362 | /* and client objects for the specified range. This client request is */ |
| 363 | /* binary compatible with the similarly named Helgrind client request. */ |
| 364 | VG_USERREQ__DRD_CLEAN_MEMORY = VG_USERREQ_TOOL_BASE('H','G'), |
| 365 | /* args: Addr, SizeT. */ |
bart | 3c1e9d8 | 2008-06-30 17:10:29 +0000 | [diff] [blame] | 366 | |
bart | d45d995 | 2009-05-31 18:53:54 +0000 | [diff] [blame] | 367 | /* Ask the DRD tool the thread ID assigned by Valgrind. */ |
| 368 | VG_USERREQ__DRD_GET_VALGRIND_THREAD_ID = VG_USERREQ_TOOL_BASE('D','R'), |
| 369 | /* args: none. */ |
| 370 | /* Ask the DRD tool the thread ID assigned by DRD. */ |
| 371 | VG_USERREQ__DRD_GET_DRD_THREAD_ID, |
| 372 | /* args: none. */ |
bart | 3c1e9d8 | 2008-06-30 17:10:29 +0000 | [diff] [blame] | 373 | |
bart | d45d995 | 2009-05-31 18:53:54 +0000 | [diff] [blame] | 374 | /* To tell the DRD tool to suppress data race detection on the */ |
| 375 | /* specified address range. */ |
| 376 | VG_USERREQ__DRD_START_SUPPRESSION, |
| 377 | /* args: start address, size in bytes */ |
| 378 | /* To tell the DRD tool no longer to suppress data race detection on */ |
| 379 | /* the specified address range. */ |
| 380 | VG_USERREQ__DRD_FINISH_SUPPRESSION, |
| 381 | /* args: start address, size in bytes */ |
bart | e747176 | 2009-03-11 18:51:22 +0000 | [diff] [blame] | 382 | |
bart | d45d995 | 2009-05-31 18:53:54 +0000 | [diff] [blame] | 383 | /* To ask the DRD tool to trace all accesses to the specified range. */ |
| 384 | VG_USERREQ__DRD_START_TRACE_ADDR, |
| 385 | /* args: Addr, SizeT. */ |
| 386 | /* To ask the DRD tool to stop tracing accesses to the specified range. */ |
| 387 | VG_USERREQ__DRD_STOP_TRACE_ADDR, |
| 388 | /* args: Addr, SizeT. */ |
| 389 | |
| 390 | /* Tell DRD whether or not to record memory loads in the calling thread. */ |
| 391 | VG_USERREQ__DRD_RECORD_LOADS, |
| 392 | /* args: Bool. */ |
| 393 | /* Tell DRD whether or not to record memory stores in the calling thread. */ |
| 394 | VG_USERREQ__DRD_RECORD_STORES, |
| 395 | /* args: Bool. */ |
| 396 | |
| 397 | /* Set the name of the thread that performs this client request. */ |
| 398 | VG_USERREQ__DRD_SET_THREAD_NAME, |
| 399 | /* args: null-terminated character string. */ |
| 400 | |
bart | 141a7ed | 2010-03-21 17:28:10 +0000 | [diff] [blame] | 401 | /* Tell DRD that a DRD annotation has not yet been implemented. */ |
| 402 | VG_USERREQ__DRD_ANNOTATION_UNIMP, |
| 403 | /* args: Char*. */ |
| 404 | |
bart | 66f196d | 2009-08-15 10:50:35 +0000 | [diff] [blame] | 405 | /* Tell DRD that a user-defined reader-writer synchronization object |
| 406 | * has been created. */ |
| 407 | VG_USERREQ__DRD_ANNOTATE_RWLOCK_CREATE |
| 408 | = VG_USERREQ_TOOL_BASE('H','G') + 256 + 14, |
| 409 | /* args: Addr. */ |
| 410 | /* Tell DRD that a user-defined reader-writer synchronization object |
| 411 | * is about to be destroyed. */ |
| 412 | VG_USERREQ__DRD_ANNOTATE_RWLOCK_DESTROY |
| 413 | = VG_USERREQ_TOOL_BASE('H','G') + 256 + 15, |
| 414 | /* args: Addr. */ |
| 415 | /* Tell DRD that a lock on a user-defined reader-writer synchronization |
| 416 | * object has been acquired. */ |
| 417 | VG_USERREQ__DRD_ANNOTATE_RWLOCK_ACQUIRED |
| 418 | = VG_USERREQ_TOOL_BASE('H','G') + 256 + 17, |
| 419 | /* args: Addr, Int is_rw. */ |
| 420 | /* Tell DRD that a lock on a user-defined reader-writer synchronization |
| 421 | * object is about to be released. */ |
| 422 | VG_USERREQ__DRD_ANNOTATE_RWLOCK_RELEASED |
| 423 | = VG_USERREQ_TOOL_BASE('H','G') + 256 + 18, |
| 424 | /* args: Addr, Int is_rw. */ |
| 425 | |
bart | 141a7ed | 2010-03-21 17:28:10 +0000 | [diff] [blame] | 426 | /* Tell DRD that a Helgrind annotation has not yet been implemented. */ |
| 427 | VG_USERREQ__HELGRIND_ANNOTATION_UNIMP |
bart | 66f196d | 2009-08-15 10:50:35 +0000 | [diff] [blame] | 428 | = VG_USERREQ_TOOL_BASE('H','G') + 256 + 32, |
| 429 | /* args: Char*. */ |
| 430 | |
bart | 733db9e | 2010-03-07 10:44:46 +0000 | [diff] [blame] | 431 | /* Tell DRD to insert a happens-before annotation. */ |
bart | f64a8aa | 2009-08-14 13:25:38 +0000 | [diff] [blame] | 432 | VG_USERREQ__DRD_ANNOTATE_HAPPENS_BEFORE |
| 433 | = VG_USERREQ_TOOL_BASE('H','G') + 256 + 33, |
bart | d45d995 | 2009-05-31 18:53:54 +0000 | [diff] [blame] | 434 | /* args: Addr. */ |
bart | 733db9e | 2010-03-07 10:44:46 +0000 | [diff] [blame] | 435 | /* Tell DRD to insert a happens-after annotation. */ |
bart | f64a8aa | 2009-08-14 13:25:38 +0000 | [diff] [blame] | 436 | VG_USERREQ__DRD_ANNOTATE_HAPPENS_AFTER |
| 437 | = VG_USERREQ_TOOL_BASE('H','G') + 256 + 34, |
bart | d45d995 | 2009-05-31 18:53:54 +0000 | [diff] [blame] | 438 | /* args: Addr. */ |
bart | d45d995 | 2009-05-31 18:53:54 +0000 | [diff] [blame] | 439 | |
bart | d45d995 | 2009-05-31 18:53:54 +0000 | [diff] [blame] | 440 | }; |
bart | 3c1e9d8 | 2008-06-30 17:10:29 +0000 | [diff] [blame] | 441 | |
| 442 | |
bart | 141a7ed | 2010-03-21 17:28:10 +0000 | [diff] [blame] | 443 | /** |
| 444 | * @addtogroup RaceDetectionAnnotations |
| 445 | */ |
| 446 | /*@{*/ |
| 447 | |
| 448 | #ifdef __cplusplus |
| 449 | /* ANNOTATE_UNPROTECTED_READ is the preferred way to annotate racy reads. |
| 450 | |
| 451 | Instead of doing |
| 452 | ANNOTATE_IGNORE_READS_BEGIN(); |
| 453 | ... = x; |
| 454 | ANNOTATE_IGNORE_READS_END(); |
| 455 | one can use |
| 456 | ... = ANNOTATE_UNPROTECTED_READ(x); */ |
| 457 | template <typename T> |
| 458 | inline T ANNOTATE_UNPROTECTED_READ(const volatile T& x) { |
| 459 | ANNOTATE_IGNORE_READS_BEGIN(); |
| 460 | const T result = x; |
| 461 | ANNOTATE_IGNORE_READS_END(); |
| 462 | return result; |
| 463 | } |
| 464 | /* Apply ANNOTATE_BENIGN_RACE_SIZED to a static variable. */ |
| 465 | #define ANNOTATE_BENIGN_RACE_STATIC(static_var, description) \ |
| 466 | namespace { \ |
| 467 | static class static_var##_annotator \ |
| 468 | { \ |
| 469 | public: \ |
| 470 | static_var##_annotator() \ |
| 471 | { \ |
bart | 12dca00 | 2010-10-10 18:53:00 +0000 | [diff] [blame] | 472 | ANNOTATE_BENIGN_RACE_SIZED(&static_var, sizeof(static_var), \ |
| 473 | #static_var ": " description); \ |
bart | 141a7ed | 2010-03-21 17:28:10 +0000 | [diff] [blame] | 474 | } \ |
| 475 | } the_##static_var##_annotator; \ |
| 476 | } |
| 477 | #endif |
| 478 | |
| 479 | /*@}*/ |
| 480 | |
bart | 3c1e9d8 | 2008-06-30 17:10:29 +0000 | [diff] [blame] | 481 | #endif /* __VALGRIND_DRD_H */ |