1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/security/sandbox/chromium/base/third_party/dynamic_annotations/dynamic_annotations.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,595 @@ 1.4 +/* Copyright (c) 2011, Google Inc. 1.5 + * All rights reserved. 1.6 + * 1.7 + * Redistribution and use in source and binary forms, with or without 1.8 + * modification, are permitted provided that the following conditions are 1.9 + * met: 1.10 + * 1.11 + * * Redistributions of source code must retain the above copyright 1.12 + * notice, this list of conditions and the following disclaimer. 1.13 + * * Neither the name of Google Inc. nor the names of its 1.14 + * contributors may be used to endorse or promote products derived from 1.15 + * this software without specific prior written permission. 1.16 + * 1.17 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1.18 + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1.19 + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1.20 + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 1.21 + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 1.22 + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 1.23 + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 1.24 + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 1.25 + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 1.26 + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 1.27 + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 1.28 + */ 1.29 + 1.30 +/* This file defines dynamic annotations for use with dynamic analysis 1.31 + tool such as valgrind, PIN, etc. 1.32 + 1.33 + Dynamic annotation is a source code annotation that affects 1.34 + the generated code (that is, the annotation is not a comment). 1.35 + Each such annotation is attached to a particular 1.36 + instruction and/or to a particular object (address) in the program. 1.37 + 1.38 + The annotations that should be used by users are macros in all upper-case 1.39 + (e.g., ANNOTATE_NEW_MEMORY). 1.40 + 1.41 + Actual implementation of these macros may differ depending on the 1.42 + dynamic analysis tool being used. 1.43 + 1.44 + See http://code.google.com/p/data-race-test/ for more information. 1.45 + 1.46 + This file supports the following dynamic analysis tools: 1.47 + - None (DYNAMIC_ANNOTATIONS_ENABLED is not defined or zero). 1.48 + Macros are defined empty. 1.49 + - ThreadSanitizer, Helgrind, DRD (DYNAMIC_ANNOTATIONS_ENABLED is 1). 1.50 + Macros are defined as calls to non-inlinable empty functions 1.51 + that are intercepted by Valgrind. */ 1.52 + 1.53 +#ifndef __DYNAMIC_ANNOTATIONS_H__ 1.54 +#define __DYNAMIC_ANNOTATIONS_H__ 1.55 + 1.56 +#ifndef DYNAMIC_ANNOTATIONS_PREFIX 1.57 +# define DYNAMIC_ANNOTATIONS_PREFIX 1.58 +#endif 1.59 + 1.60 +#ifndef DYNAMIC_ANNOTATIONS_PROVIDE_RUNNING_ON_VALGRIND 1.61 +# define DYNAMIC_ANNOTATIONS_PROVIDE_RUNNING_ON_VALGRIND 1 1.62 +#endif 1.63 + 1.64 +#ifdef DYNAMIC_ANNOTATIONS_WANT_ATTRIBUTE_WEAK 1.65 +# ifdef __GNUC__ 1.66 +# define DYNAMIC_ANNOTATIONS_ATTRIBUTE_WEAK __attribute__((weak)) 1.67 +# else 1.68 +/* TODO(glider): for Windows support we may want to change this macro in order 1.69 + to prepend __declspec(selectany) to the annotations' declarations. */ 1.70 +# error weak annotations are not supported for your compiler 1.71 +# endif 1.72 +#else 1.73 +# define DYNAMIC_ANNOTATIONS_ATTRIBUTE_WEAK 1.74 +#endif 1.75 + 1.76 +/* The following preprocessor magic prepends the value of 1.77 + DYNAMIC_ANNOTATIONS_PREFIX to annotation function names. */ 1.78 +#define DYNAMIC_ANNOTATIONS_GLUE0(A, B) A##B 1.79 +#define DYNAMIC_ANNOTATIONS_GLUE(A, B) DYNAMIC_ANNOTATIONS_GLUE0(A, B) 1.80 +#define DYNAMIC_ANNOTATIONS_NAME(name) \ 1.81 + DYNAMIC_ANNOTATIONS_GLUE(DYNAMIC_ANNOTATIONS_PREFIX, name) 1.82 + 1.83 +#ifndef DYNAMIC_ANNOTATIONS_ENABLED 1.84 +# define DYNAMIC_ANNOTATIONS_ENABLED 0 1.85 +#endif 1.86 + 1.87 +#if DYNAMIC_ANNOTATIONS_ENABLED != 0 1.88 + 1.89 + /* ------------------------------------------------------------- 1.90 + Annotations useful when implementing condition variables such as CondVar, 1.91 + using conditional critical sections (Await/LockWhen) and when constructing 1.92 + user-defined synchronization mechanisms. 1.93 + 1.94 + The annotations ANNOTATE_HAPPENS_BEFORE() and ANNOTATE_HAPPENS_AFTER() can 1.95 + be used to define happens-before arcs in user-defined synchronization 1.96 + mechanisms: the race detector will infer an arc from the former to the 1.97 + latter when they share the same argument pointer. 1.98 + 1.99 + Example 1 (reference counting): 1.100 + 1.101 + void Unref() { 1.102 + ANNOTATE_HAPPENS_BEFORE(&refcount_); 1.103 + if (AtomicDecrementByOne(&refcount_) == 0) { 1.104 + ANNOTATE_HAPPENS_AFTER(&refcount_); 1.105 + delete this; 1.106 + } 1.107 + } 1.108 + 1.109 + Example 2 (message queue): 1.110 + 1.111 + void MyQueue::Put(Type *e) { 1.112 + MutexLock lock(&mu_); 1.113 + ANNOTATE_HAPPENS_BEFORE(e); 1.114 + PutElementIntoMyQueue(e); 1.115 + } 1.116 + 1.117 + Type *MyQueue::Get() { 1.118 + MutexLock lock(&mu_); 1.119 + Type *e = GetElementFromMyQueue(); 1.120 + ANNOTATE_HAPPENS_AFTER(e); 1.121 + return e; 1.122 + } 1.123 + 1.124 + Note: when possible, please use the existing reference counting and message 1.125 + queue implementations instead of inventing new ones. */ 1.126 + 1.127 + /* Report that wait on the condition variable at address "cv" has succeeded 1.128 + and the lock at address "lock" is held. */ 1.129 + #define ANNOTATE_CONDVAR_LOCK_WAIT(cv, lock) \ 1.130 + DYNAMIC_ANNOTATIONS_NAME(AnnotateCondVarWait)(__FILE__, __LINE__, cv, lock) 1.131 + 1.132 + /* Report that wait on the condition variable at "cv" has succeeded. Variant 1.133 + w/o lock. */ 1.134 + #define ANNOTATE_CONDVAR_WAIT(cv) \ 1.135 + DYNAMIC_ANNOTATIONS_NAME(AnnotateCondVarWait)(__FILE__, __LINE__, cv, NULL) 1.136 + 1.137 + /* Report that we are about to signal on the condition variable at address 1.138 + "cv". */ 1.139 + #define ANNOTATE_CONDVAR_SIGNAL(cv) \ 1.140 + DYNAMIC_ANNOTATIONS_NAME(AnnotateCondVarSignal)(__FILE__, __LINE__, cv) 1.141 + 1.142 + /* Report that we are about to signal_all on the condition variable at address 1.143 + "cv". */ 1.144 + #define ANNOTATE_CONDVAR_SIGNAL_ALL(cv) \ 1.145 + DYNAMIC_ANNOTATIONS_NAME(AnnotateCondVarSignalAll)(__FILE__, __LINE__, cv) 1.146 + 1.147 + /* Annotations for user-defined synchronization mechanisms. */ 1.148 + #define ANNOTATE_HAPPENS_BEFORE(obj) \ 1.149 + DYNAMIC_ANNOTATIONS_NAME(AnnotateHappensBefore)(__FILE__, __LINE__, obj) 1.150 + #define ANNOTATE_HAPPENS_AFTER(obj) \ 1.151 + DYNAMIC_ANNOTATIONS_NAME(AnnotateHappensAfter)(__FILE__, __LINE__, obj) 1.152 + 1.153 + /* DEPRECATED. Don't use it. */ 1.154 + #define ANNOTATE_PUBLISH_MEMORY_RANGE(pointer, size) \ 1.155 + DYNAMIC_ANNOTATIONS_NAME(AnnotatePublishMemoryRange)(__FILE__, __LINE__, \ 1.156 + pointer, size) 1.157 + 1.158 + /* DEPRECATED. Don't use it. */ 1.159 + #define ANNOTATE_UNPUBLISH_MEMORY_RANGE(pointer, size) \ 1.160 + DYNAMIC_ANNOTATIONS_NAME(AnnotateUnpublishMemoryRange)(__FILE__, __LINE__, \ 1.161 + pointer, size) 1.162 + 1.163 + /* DEPRECATED. Don't use it. */ 1.164 + #define ANNOTATE_SWAP_MEMORY_RANGE(pointer, size) \ 1.165 + do { \ 1.166 + ANNOTATE_UNPUBLISH_MEMORY_RANGE(pointer, size); \ 1.167 + ANNOTATE_PUBLISH_MEMORY_RANGE(pointer, size); \ 1.168 + } while (0) 1.169 + 1.170 + /* Instruct the tool to create a happens-before arc between mu->Unlock() and 1.171 + mu->Lock(). This annotation may slow down the race detector and hide real 1.172 + races. Normally it is used only when it would be difficult to annotate each 1.173 + of the mutex's critical sections individually using the annotations above. 1.174 + This annotation makes sense only for hybrid race detectors. For pure 1.175 + happens-before detectors this is a no-op. For more details see 1.176 + http://code.google.com/p/data-race-test/wiki/PureHappensBeforeVsHybrid . */ 1.177 + #define ANNOTATE_PURE_HAPPENS_BEFORE_MUTEX(mu) \ 1.178 + DYNAMIC_ANNOTATIONS_NAME(AnnotateMutexIsUsedAsCondVar)(__FILE__, __LINE__, \ 1.179 + mu) 1.180 + 1.181 + /* Opposite to ANNOTATE_PURE_HAPPENS_BEFORE_MUTEX. 1.182 + Instruct the tool to NOT create h-b arcs between Unlock and Lock, even in 1.183 + pure happens-before mode. For a hybrid mode this is a no-op. */ 1.184 + #define ANNOTATE_NOT_HAPPENS_BEFORE_MUTEX(mu) \ 1.185 + DYNAMIC_ANNOTATIONS_NAME(AnnotateMutexIsNotPHB)(__FILE__, __LINE__, mu) 1.186 + 1.187 + /* Deprecated. Use ANNOTATE_PURE_HAPPENS_BEFORE_MUTEX. */ 1.188 + #define ANNOTATE_MUTEX_IS_USED_AS_CONDVAR(mu) \ 1.189 + DYNAMIC_ANNOTATIONS_NAME(AnnotateMutexIsUsedAsCondVar)(__FILE__, __LINE__, \ 1.190 + mu) 1.191 + 1.192 + /* ------------------------------------------------------------- 1.193 + Annotations useful when defining memory allocators, or when memory that 1.194 + was protected in one way starts to be protected in another. */ 1.195 + 1.196 + /* Report that a new memory at "address" of size "size" has been allocated. 1.197 + This might be used when the memory has been retrieved from a free list and 1.198 + is about to be reused, or when a the locking discipline for a variable 1.199 + changes. */ 1.200 + #define ANNOTATE_NEW_MEMORY(address, size) \ 1.201 + DYNAMIC_ANNOTATIONS_NAME(AnnotateNewMemory)(__FILE__, __LINE__, address, \ 1.202 + size) 1.203 + 1.204 + /* ------------------------------------------------------------- 1.205 + Annotations useful when defining FIFO queues that transfer data between 1.206 + threads. */ 1.207 + 1.208 + /* Report that the producer-consumer queue (such as ProducerConsumerQueue) at 1.209 + address "pcq" has been created. The ANNOTATE_PCQ_* annotations 1.210 + should be used only for FIFO queues. For non-FIFO queues use 1.211 + ANNOTATE_HAPPENS_BEFORE (for put) and ANNOTATE_HAPPENS_AFTER (for get). */ 1.212 + #define ANNOTATE_PCQ_CREATE(pcq) \ 1.213 + DYNAMIC_ANNOTATIONS_NAME(AnnotatePCQCreate)(__FILE__, __LINE__, pcq) 1.214 + 1.215 + /* Report that the queue at address "pcq" is about to be destroyed. */ 1.216 + #define ANNOTATE_PCQ_DESTROY(pcq) \ 1.217 + DYNAMIC_ANNOTATIONS_NAME(AnnotatePCQDestroy)(__FILE__, __LINE__, pcq) 1.218 + 1.219 + /* Report that we are about to put an element into a FIFO queue at address 1.220 + "pcq". */ 1.221 + #define ANNOTATE_PCQ_PUT(pcq) \ 1.222 + DYNAMIC_ANNOTATIONS_NAME(AnnotatePCQPut)(__FILE__, __LINE__, pcq) 1.223 + 1.224 + /* Report that we've just got an element from a FIFO queue at address 1.225 + "pcq". */ 1.226 + #define ANNOTATE_PCQ_GET(pcq) \ 1.227 + DYNAMIC_ANNOTATIONS_NAME(AnnotatePCQGet)(__FILE__, __LINE__, pcq) 1.228 + 1.229 + /* ------------------------------------------------------------- 1.230 + Annotations that suppress errors. It is usually better to express the 1.231 + program's synchronization using the other annotations, but these can 1.232 + be used when all else fails. */ 1.233 + 1.234 + /* Report that we may have a benign race at "pointer", with size 1.235 + "sizeof(*(pointer))". "pointer" must be a non-void* pointer. Insert at the 1.236 + point where "pointer" has been allocated, preferably close to the point 1.237 + where the race happens. See also ANNOTATE_BENIGN_RACE_STATIC. */ 1.238 + #define ANNOTATE_BENIGN_RACE(pointer, description) \ 1.239 + DYNAMIC_ANNOTATIONS_NAME(AnnotateBenignRaceSized)(__FILE__, __LINE__, \ 1.240 + pointer, sizeof(*(pointer)), description) 1.241 + 1.242 + /* Same as ANNOTATE_BENIGN_RACE(address, description), but applies to 1.243 + the memory range [address, address+size). */ 1.244 + #define ANNOTATE_BENIGN_RACE_SIZED(address, size, description) \ 1.245 + DYNAMIC_ANNOTATIONS_NAME(AnnotateBenignRaceSized)(__FILE__, __LINE__, \ 1.246 + address, size, description) 1.247 + 1.248 + /* Request the analysis tool to ignore all reads in the current thread 1.249 + until ANNOTATE_IGNORE_READS_END is called. 1.250 + Useful to ignore intentional racey reads, while still checking 1.251 + other reads and all writes. 1.252 + See also ANNOTATE_UNPROTECTED_READ. */ 1.253 + #define ANNOTATE_IGNORE_READS_BEGIN() \ 1.254 + DYNAMIC_ANNOTATIONS_NAME(AnnotateIgnoreReadsBegin)(__FILE__, __LINE__) 1.255 + 1.256 + /* Stop ignoring reads. */ 1.257 + #define ANNOTATE_IGNORE_READS_END() \ 1.258 + DYNAMIC_ANNOTATIONS_NAME(AnnotateIgnoreReadsEnd)(__FILE__, __LINE__) 1.259 + 1.260 + /* Similar to ANNOTATE_IGNORE_READS_BEGIN, but ignore writes. */ 1.261 + #define ANNOTATE_IGNORE_WRITES_BEGIN() \ 1.262 + DYNAMIC_ANNOTATIONS_NAME(AnnotateIgnoreWritesBegin)(__FILE__, __LINE__) 1.263 + 1.264 + /* Stop ignoring writes. */ 1.265 + #define ANNOTATE_IGNORE_WRITES_END() \ 1.266 + DYNAMIC_ANNOTATIONS_NAME(AnnotateIgnoreWritesEnd)(__FILE__, __LINE__) 1.267 + 1.268 + /* Start ignoring all memory accesses (reads and writes). */ 1.269 + #define ANNOTATE_IGNORE_READS_AND_WRITES_BEGIN() \ 1.270 + do {\ 1.271 + ANNOTATE_IGNORE_READS_BEGIN();\ 1.272 + ANNOTATE_IGNORE_WRITES_BEGIN();\ 1.273 + }while(0)\ 1.274 + 1.275 + /* Stop ignoring all memory accesses. */ 1.276 + #define ANNOTATE_IGNORE_READS_AND_WRITES_END() \ 1.277 + do {\ 1.278 + ANNOTATE_IGNORE_WRITES_END();\ 1.279 + ANNOTATE_IGNORE_READS_END();\ 1.280 + }while(0)\ 1.281 + 1.282 + /* Similar to ANNOTATE_IGNORE_READS_BEGIN, but ignore synchronization events: 1.283 + RWLOCK* and CONDVAR*. */ 1.284 + #define ANNOTATE_IGNORE_SYNC_BEGIN() \ 1.285 + DYNAMIC_ANNOTATIONS_NAME(AnnotateIgnoreSyncBegin)(__FILE__, __LINE__) 1.286 + 1.287 + /* Stop ignoring sync events. */ 1.288 + #define ANNOTATE_IGNORE_SYNC_END() \ 1.289 + DYNAMIC_ANNOTATIONS_NAME(AnnotateIgnoreSyncEnd)(__FILE__, __LINE__) 1.290 + 1.291 + 1.292 + /* Enable (enable!=0) or disable (enable==0) race detection for all threads. 1.293 + This annotation could be useful if you want to skip expensive race analysis 1.294 + during some period of program execution, e.g. during initialization. */ 1.295 + #define ANNOTATE_ENABLE_RACE_DETECTION(enable) \ 1.296 + DYNAMIC_ANNOTATIONS_NAME(AnnotateEnableRaceDetection)(__FILE__, __LINE__, \ 1.297 + enable) 1.298 + 1.299 + /* ------------------------------------------------------------- 1.300 + Annotations useful for debugging. */ 1.301 + 1.302 + /* Request to trace every access to "address". */ 1.303 + #define ANNOTATE_TRACE_MEMORY(address) \ 1.304 + DYNAMIC_ANNOTATIONS_NAME(AnnotateTraceMemory)(__FILE__, __LINE__, address) 1.305 + 1.306 + /* Report the current thread name to a race detector. */ 1.307 + #define ANNOTATE_THREAD_NAME(name) \ 1.308 + DYNAMIC_ANNOTATIONS_NAME(AnnotateThreadName)(__FILE__, __LINE__, name) 1.309 + 1.310 + /* ------------------------------------------------------------- 1.311 + Annotations useful when implementing locks. They are not 1.312 + normally needed by modules that merely use locks. 1.313 + The "lock" argument is a pointer to the lock object. */ 1.314 + 1.315 + /* Report that a lock has been created at address "lock". */ 1.316 + #define ANNOTATE_RWLOCK_CREATE(lock) \ 1.317 + DYNAMIC_ANNOTATIONS_NAME(AnnotateRWLockCreate)(__FILE__, __LINE__, lock) 1.318 + 1.319 + /* Report that the lock at address "lock" is about to be destroyed. */ 1.320 + #define ANNOTATE_RWLOCK_DESTROY(lock) \ 1.321 + DYNAMIC_ANNOTATIONS_NAME(AnnotateRWLockDestroy)(__FILE__, __LINE__, lock) 1.322 + 1.323 + /* Report that the lock at address "lock" has been acquired. 1.324 + is_w=1 for writer lock, is_w=0 for reader lock. */ 1.325 + #define ANNOTATE_RWLOCK_ACQUIRED(lock, is_w) \ 1.326 + DYNAMIC_ANNOTATIONS_NAME(AnnotateRWLockAcquired)(__FILE__, __LINE__, lock, \ 1.327 + is_w) 1.328 + 1.329 + /* Report that the lock at address "lock" is about to be released. */ 1.330 + #define ANNOTATE_RWLOCK_RELEASED(lock, is_w) \ 1.331 + DYNAMIC_ANNOTATIONS_NAME(AnnotateRWLockReleased)(__FILE__, __LINE__, lock, \ 1.332 + is_w) 1.333 + 1.334 + /* ------------------------------------------------------------- 1.335 + Annotations useful when implementing barriers. They are not 1.336 + normally needed by modules that merely use barriers. 1.337 + The "barrier" argument is a pointer to the barrier object. */ 1.338 + 1.339 + /* Report that the "barrier" has been initialized with initial "count". 1.340 + If 'reinitialization_allowed' is true, initialization is allowed to happen 1.341 + multiple times w/o calling barrier_destroy() */ 1.342 + #define ANNOTATE_BARRIER_INIT(barrier, count, reinitialization_allowed) \ 1.343 + DYNAMIC_ANNOTATIONS_NAME(AnnotateBarrierInit)(__FILE__, __LINE__, barrier, \ 1.344 + count, reinitialization_allowed) 1.345 + 1.346 + /* Report that we are about to enter barrier_wait("barrier"). */ 1.347 + #define ANNOTATE_BARRIER_WAIT_BEFORE(barrier) \ 1.348 + DYNAMIC_ANNOTATIONS_NAME(AnnotateBarrierWaitBefore)(__FILE__, __LINE__, \ 1.349 + barrier) 1.350 + 1.351 + /* Report that we just exited barrier_wait("barrier"). */ 1.352 + #define ANNOTATE_BARRIER_WAIT_AFTER(barrier) \ 1.353 + DYNAMIC_ANNOTATIONS_NAME(AnnotateBarrierWaitAfter)(__FILE__, __LINE__, \ 1.354 + barrier) 1.355 + 1.356 + /* Report that the "barrier" has been destroyed. */ 1.357 + #define ANNOTATE_BARRIER_DESTROY(barrier) \ 1.358 + DYNAMIC_ANNOTATIONS_NAME(AnnotateBarrierDestroy)(__FILE__, __LINE__, \ 1.359 + barrier) 1.360 + 1.361 + /* ------------------------------------------------------------- 1.362 + Annotations useful for testing race detectors. */ 1.363 + 1.364 + /* Report that we expect a race on the variable at "address". 1.365 + Use only in unit tests for a race detector. */ 1.366 + #define ANNOTATE_EXPECT_RACE(address, description) \ 1.367 + DYNAMIC_ANNOTATIONS_NAME(AnnotateExpectRace)(__FILE__, __LINE__, address, \ 1.368 + description) 1.369 + 1.370 + #define ANNOTATE_FLUSH_EXPECTED_RACES() \ 1.371 + DYNAMIC_ANNOTATIONS_NAME(AnnotateFlushExpectedRaces)(__FILE__, __LINE__) 1.372 + 1.373 + /* A no-op. Insert where you like to test the interceptors. */ 1.374 + #define ANNOTATE_NO_OP(arg) \ 1.375 + DYNAMIC_ANNOTATIONS_NAME(AnnotateNoOp)(__FILE__, __LINE__, arg) 1.376 + 1.377 + /* Force the race detector to flush its state. The actual effect depends on 1.378 + * the implementation of the detector. */ 1.379 + #define ANNOTATE_FLUSH_STATE() \ 1.380 + DYNAMIC_ANNOTATIONS_NAME(AnnotateFlushState)(__FILE__, __LINE__) 1.381 + 1.382 + 1.383 +#else /* DYNAMIC_ANNOTATIONS_ENABLED == 0 */ 1.384 + 1.385 + #define ANNOTATE_RWLOCK_CREATE(lock) /* empty */ 1.386 + #define ANNOTATE_RWLOCK_DESTROY(lock) /* empty */ 1.387 + #define ANNOTATE_RWLOCK_ACQUIRED(lock, is_w) /* empty */ 1.388 + #define ANNOTATE_RWLOCK_RELEASED(lock, is_w) /* empty */ 1.389 + #define ANNOTATE_BARRIER_INIT(barrier, count, reinitialization_allowed) /* */ 1.390 + #define ANNOTATE_BARRIER_WAIT_BEFORE(barrier) /* empty */ 1.391 + #define ANNOTATE_BARRIER_WAIT_AFTER(barrier) /* empty */ 1.392 + #define ANNOTATE_BARRIER_DESTROY(barrier) /* empty */ 1.393 + #define ANNOTATE_CONDVAR_LOCK_WAIT(cv, lock) /* empty */ 1.394 + #define ANNOTATE_CONDVAR_WAIT(cv) /* empty */ 1.395 + #define ANNOTATE_CONDVAR_SIGNAL(cv) /* empty */ 1.396 + #define ANNOTATE_CONDVAR_SIGNAL_ALL(cv) /* empty */ 1.397 + #define ANNOTATE_HAPPENS_BEFORE(obj) /* empty */ 1.398 + #define ANNOTATE_HAPPENS_AFTER(obj) /* empty */ 1.399 + #define ANNOTATE_PUBLISH_MEMORY_RANGE(address, size) /* empty */ 1.400 + #define ANNOTATE_UNPUBLISH_MEMORY_RANGE(address, size) /* empty */ 1.401 + #define ANNOTATE_SWAP_MEMORY_RANGE(address, size) /* empty */ 1.402 + #define ANNOTATE_PCQ_CREATE(pcq) /* empty */ 1.403 + #define ANNOTATE_PCQ_DESTROY(pcq) /* empty */ 1.404 + #define ANNOTATE_PCQ_PUT(pcq) /* empty */ 1.405 + #define ANNOTATE_PCQ_GET(pcq) /* empty */ 1.406 + #define ANNOTATE_NEW_MEMORY(address, size) /* empty */ 1.407 + #define ANNOTATE_EXPECT_RACE(address, description) /* empty */ 1.408 + #define ANNOTATE_FLUSH_EXPECTED_RACES(address, description) /* empty */ 1.409 + #define ANNOTATE_BENIGN_RACE(address, description) /* empty */ 1.410 + #define ANNOTATE_BENIGN_RACE_SIZED(address, size, description) /* empty */ 1.411 + #define ANNOTATE_PURE_HAPPENS_BEFORE_MUTEX(mu) /* empty */ 1.412 + #define ANNOTATE_MUTEX_IS_USED_AS_CONDVAR(mu) /* empty */ 1.413 + #define ANNOTATE_TRACE_MEMORY(arg) /* empty */ 1.414 + #define ANNOTATE_THREAD_NAME(name) /* empty */ 1.415 + #define ANNOTATE_IGNORE_READS_BEGIN() /* empty */ 1.416 + #define ANNOTATE_IGNORE_READS_END() /* empty */ 1.417 + #define ANNOTATE_IGNORE_WRITES_BEGIN() /* empty */ 1.418 + #define ANNOTATE_IGNORE_WRITES_END() /* empty */ 1.419 + #define ANNOTATE_IGNORE_READS_AND_WRITES_BEGIN() /* empty */ 1.420 + #define ANNOTATE_IGNORE_READS_AND_WRITES_END() /* empty */ 1.421 + #define ANNOTATE_IGNORE_SYNC_BEGIN() /* empty */ 1.422 + #define ANNOTATE_IGNORE_SYNC_END() /* empty */ 1.423 + #define ANNOTATE_ENABLE_RACE_DETECTION(enable) /* empty */ 1.424 + #define ANNOTATE_NO_OP(arg) /* empty */ 1.425 + #define ANNOTATE_FLUSH_STATE() /* empty */ 1.426 + 1.427 +#endif /* DYNAMIC_ANNOTATIONS_ENABLED */ 1.428 + 1.429 +/* Use the macros above rather than using these functions directly. */ 1.430 +#ifdef __cplusplus 1.431 +extern "C" { 1.432 +#endif 1.433 + 1.434 + 1.435 +void DYNAMIC_ANNOTATIONS_NAME(AnnotateRWLockCreate)( 1.436 + const char *file, int line, 1.437 + const volatile void *lock) DYNAMIC_ANNOTATIONS_ATTRIBUTE_WEAK; 1.438 +void DYNAMIC_ANNOTATIONS_NAME(AnnotateRWLockDestroy)( 1.439 + const char *file, int line, 1.440 + const volatile void *lock) DYNAMIC_ANNOTATIONS_ATTRIBUTE_WEAK; 1.441 +void DYNAMIC_ANNOTATIONS_NAME(AnnotateRWLockAcquired)( 1.442 + const char *file, int line, 1.443 + const volatile void *lock, long is_w) DYNAMIC_ANNOTATIONS_ATTRIBUTE_WEAK; 1.444 +void DYNAMIC_ANNOTATIONS_NAME(AnnotateRWLockReleased)( 1.445 + const char *file, int line, 1.446 + const volatile void *lock, long is_w) DYNAMIC_ANNOTATIONS_ATTRIBUTE_WEAK; 1.447 +void DYNAMIC_ANNOTATIONS_NAME(AnnotateBarrierInit)( 1.448 + const char *file, int line, const volatile void *barrier, long count, 1.449 + long reinitialization_allowed) DYNAMIC_ANNOTATIONS_ATTRIBUTE_WEAK; 1.450 +void DYNAMIC_ANNOTATIONS_NAME(AnnotateBarrierWaitBefore)( 1.451 + const char *file, int line, 1.452 + const volatile void *barrier) DYNAMIC_ANNOTATIONS_ATTRIBUTE_WEAK; 1.453 +void DYNAMIC_ANNOTATIONS_NAME(AnnotateBarrierWaitAfter)( 1.454 + const char *file, int line, 1.455 + const volatile void *barrier) DYNAMIC_ANNOTATIONS_ATTRIBUTE_WEAK; 1.456 +void DYNAMIC_ANNOTATIONS_NAME(AnnotateBarrierDestroy)( 1.457 + const char *file, int line, 1.458 + const volatile void *barrier) DYNAMIC_ANNOTATIONS_ATTRIBUTE_WEAK; 1.459 +void DYNAMIC_ANNOTATIONS_NAME(AnnotateCondVarWait)( 1.460 + const char *file, int line, const volatile void *cv, 1.461 + const volatile void *lock) DYNAMIC_ANNOTATIONS_ATTRIBUTE_WEAK; 1.462 +void DYNAMIC_ANNOTATIONS_NAME(AnnotateCondVarSignal)( 1.463 + const char *file, int line, 1.464 + const volatile void *cv) DYNAMIC_ANNOTATIONS_ATTRIBUTE_WEAK; 1.465 +void DYNAMIC_ANNOTATIONS_NAME(AnnotateCondVarSignalAll)( 1.466 + const char *file, int line, 1.467 + const volatile void *cv) DYNAMIC_ANNOTATIONS_ATTRIBUTE_WEAK; 1.468 +void DYNAMIC_ANNOTATIONS_NAME(AnnotateHappensBefore)( 1.469 + const char *file, int line, 1.470 + const volatile void *obj) DYNAMIC_ANNOTATIONS_ATTRIBUTE_WEAK; 1.471 +void DYNAMIC_ANNOTATIONS_NAME(AnnotateHappensAfter)( 1.472 + const char *file, int line, 1.473 + const volatile void *obj) DYNAMIC_ANNOTATIONS_ATTRIBUTE_WEAK; 1.474 +void DYNAMIC_ANNOTATIONS_NAME(AnnotatePublishMemoryRange)( 1.475 + const char *file, int line, 1.476 + const volatile void *address, long size) DYNAMIC_ANNOTATIONS_ATTRIBUTE_WEAK; 1.477 +void DYNAMIC_ANNOTATIONS_NAME(AnnotateUnpublishMemoryRange)( 1.478 + const char *file, int line, 1.479 + const volatile void *address, long size) DYNAMIC_ANNOTATIONS_ATTRIBUTE_WEAK; 1.480 +void DYNAMIC_ANNOTATIONS_NAME(AnnotatePCQCreate)( 1.481 + const char *file, int line, 1.482 + const volatile void *pcq) DYNAMIC_ANNOTATIONS_ATTRIBUTE_WEAK; 1.483 +void DYNAMIC_ANNOTATIONS_NAME(AnnotatePCQDestroy)( 1.484 + const char *file, int line, 1.485 + const volatile void *pcq) DYNAMIC_ANNOTATIONS_ATTRIBUTE_WEAK; 1.486 +void DYNAMIC_ANNOTATIONS_NAME(AnnotatePCQPut)( 1.487 + const char *file, int line, 1.488 + const volatile void *pcq) DYNAMIC_ANNOTATIONS_ATTRIBUTE_WEAK; 1.489 +void DYNAMIC_ANNOTATIONS_NAME(AnnotatePCQGet)( 1.490 + const char *file, int line, 1.491 + const volatile void *pcq) DYNAMIC_ANNOTATIONS_ATTRIBUTE_WEAK; 1.492 +void DYNAMIC_ANNOTATIONS_NAME(AnnotateNewMemory)( 1.493 + const char *file, int line, 1.494 + const volatile void *mem, long size) DYNAMIC_ANNOTATIONS_ATTRIBUTE_WEAK; 1.495 +void DYNAMIC_ANNOTATIONS_NAME(AnnotateExpectRace)( 1.496 + const char *file, int line, const volatile void *mem, 1.497 + const char *description) DYNAMIC_ANNOTATIONS_ATTRIBUTE_WEAK; 1.498 +void DYNAMIC_ANNOTATIONS_NAME(AnnotateFlushExpectedRaces)( 1.499 + const char *file, int line) DYNAMIC_ANNOTATIONS_ATTRIBUTE_WEAK; 1.500 +void DYNAMIC_ANNOTATIONS_NAME(AnnotateBenignRace)( 1.501 + const char *file, int line, const volatile void *mem, 1.502 + const char *description) DYNAMIC_ANNOTATIONS_ATTRIBUTE_WEAK; 1.503 +void DYNAMIC_ANNOTATIONS_NAME(AnnotateBenignRaceSized)( 1.504 + const char *file, int line, const volatile void *mem, long size, 1.505 + const char *description) DYNAMIC_ANNOTATIONS_ATTRIBUTE_WEAK; 1.506 +void DYNAMIC_ANNOTATIONS_NAME(AnnotateMutexIsUsedAsCondVar)( 1.507 + const char *file, int line, 1.508 + const volatile void *mu) DYNAMIC_ANNOTATIONS_ATTRIBUTE_WEAK; 1.509 +void DYNAMIC_ANNOTATIONS_NAME(AnnotateMutexIsNotPHB)( 1.510 + const char *file, int line, 1.511 + const volatile void *mu) DYNAMIC_ANNOTATIONS_ATTRIBUTE_WEAK; 1.512 +void DYNAMIC_ANNOTATIONS_NAME(AnnotateTraceMemory)( 1.513 + const char *file, int line, 1.514 + const volatile void *arg) DYNAMIC_ANNOTATIONS_ATTRIBUTE_WEAK; 1.515 +void DYNAMIC_ANNOTATIONS_NAME(AnnotateThreadName)( 1.516 + const char *file, int line, 1.517 + const char *name) DYNAMIC_ANNOTATIONS_ATTRIBUTE_WEAK; 1.518 +void DYNAMIC_ANNOTATIONS_NAME(AnnotateIgnoreReadsBegin)( 1.519 + const char *file, int line) DYNAMIC_ANNOTATIONS_ATTRIBUTE_WEAK; 1.520 +void DYNAMIC_ANNOTATIONS_NAME(AnnotateIgnoreReadsEnd)( 1.521 + const char *file, int line) DYNAMIC_ANNOTATIONS_ATTRIBUTE_WEAK; 1.522 +void DYNAMIC_ANNOTATIONS_NAME(AnnotateIgnoreWritesBegin)( 1.523 + const char *file, int line) DYNAMIC_ANNOTATIONS_ATTRIBUTE_WEAK; 1.524 +void DYNAMIC_ANNOTATIONS_NAME(AnnotateIgnoreWritesEnd)( 1.525 + const char *file, int line) DYNAMIC_ANNOTATIONS_ATTRIBUTE_WEAK; 1.526 +void DYNAMIC_ANNOTATIONS_NAME(AnnotateIgnoreSyncBegin)( 1.527 + const char *file, int line) DYNAMIC_ANNOTATIONS_ATTRIBUTE_WEAK; 1.528 +void DYNAMIC_ANNOTATIONS_NAME(AnnotateIgnoreSyncEnd)( 1.529 + const char *file, int line) DYNAMIC_ANNOTATIONS_ATTRIBUTE_WEAK; 1.530 +void DYNAMIC_ANNOTATIONS_NAME(AnnotateEnableRaceDetection)( 1.531 + const char *file, int line, int enable) DYNAMIC_ANNOTATIONS_ATTRIBUTE_WEAK; 1.532 +void DYNAMIC_ANNOTATIONS_NAME(AnnotateNoOp)( 1.533 + const char *file, int line, 1.534 + const volatile void *arg) DYNAMIC_ANNOTATIONS_ATTRIBUTE_WEAK; 1.535 +void DYNAMIC_ANNOTATIONS_NAME(AnnotateFlushState)( 1.536 + const char *file, int line) DYNAMIC_ANNOTATIONS_ATTRIBUTE_WEAK; 1.537 + 1.538 +#if DYNAMIC_ANNOTATIONS_PROVIDE_RUNNING_ON_VALGRIND == 1 1.539 +/* Return non-zero value if running under valgrind. 1.540 + 1.541 + If "valgrind.h" is included into dynamic_annotations.c, 1.542 + the regular valgrind mechanism will be used. 1.543 + See http://valgrind.org/docs/manual/manual-core-adv.html about 1.544 + RUNNING_ON_VALGRIND and other valgrind "client requests". 1.545 + The file "valgrind.h" may be obtained by doing 1.546 + svn co svn://svn.valgrind.org/valgrind/trunk/include 1.547 + 1.548 + If for some reason you can't use "valgrind.h" or want to fake valgrind, 1.549 + there are two ways to make this function return non-zero: 1.550 + - Use environment variable: export RUNNING_ON_VALGRIND=1 1.551 + - Make your tool intercept the function RunningOnValgrind() and 1.552 + change its return value. 1.553 + */ 1.554 +int RunningOnValgrind(void) DYNAMIC_ANNOTATIONS_ATTRIBUTE_WEAK; 1.555 +#endif /* DYNAMIC_ANNOTATIONS_PROVIDE_RUNNING_ON_VALGRIND == 1 */ 1.556 + 1.557 +#ifdef __cplusplus 1.558 +} 1.559 +#endif 1.560 + 1.561 +#if DYNAMIC_ANNOTATIONS_ENABLED != 0 && defined(__cplusplus) 1.562 + 1.563 + /* ANNOTATE_UNPROTECTED_READ is the preferred way to annotate racey reads. 1.564 + 1.565 + Instead of doing 1.566 + ANNOTATE_IGNORE_READS_BEGIN(); 1.567 + ... = x; 1.568 + ANNOTATE_IGNORE_READS_END(); 1.569 + one can use 1.570 + ... = ANNOTATE_UNPROTECTED_READ(x); */ 1.571 + template <class T> 1.572 + inline T ANNOTATE_UNPROTECTED_READ(const volatile T &x) { 1.573 + ANNOTATE_IGNORE_READS_BEGIN(); 1.574 + T res = x; 1.575 + ANNOTATE_IGNORE_READS_END(); 1.576 + return res; 1.577 + } 1.578 + /* Apply ANNOTATE_BENIGN_RACE_SIZED to a static variable. */ 1.579 + #define ANNOTATE_BENIGN_RACE_STATIC(static_var, description) \ 1.580 + namespace { \ 1.581 + class static_var ## _annotator { \ 1.582 + public: \ 1.583 + static_var ## _annotator() { \ 1.584 + ANNOTATE_BENIGN_RACE_SIZED(&static_var, \ 1.585 + sizeof(static_var), \ 1.586 + # static_var ": " description); \ 1.587 + } \ 1.588 + }; \ 1.589 + static static_var ## _annotator the ## static_var ## _annotator;\ 1.590 + } 1.591 +#else /* DYNAMIC_ANNOTATIONS_ENABLED == 0 */ 1.592 + 1.593 + #define ANNOTATE_UNPROTECTED_READ(x) (x) 1.594 + #define ANNOTATE_BENIGN_RACE_STATIC(static_var, description) /* empty */ 1.595 + 1.596 +#endif /* DYNAMIC_ANNOTATIONS_ENABLED */ 1.597 + 1.598 +#endif /* __DYNAMIC_ANNOTATIONS_H__ */