19c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov/* Copyright (c) 2011, Google Inc. 29c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov * All rights reserved. 39c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov * 49c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov * Redistribution and use in source and binary forms, with or without 59c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov * modification, are permitted provided that the following conditions are 69c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov * met: 79c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov * 89c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov * * Redistributions of source code must retain the above copyright 99c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov * notice, this list of conditions and the following disclaimer. 109c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov * * Neither the name of Google Inc. nor the names of its 119c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov * contributors may be used to endorse or promote products derived from 129c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov * this software without specific prior written permission. 139c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov * 149c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 159c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 169c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 179c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 189c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 199c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 209c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 219c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 229c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 239c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 249c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 259c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov */ 269c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov 279c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov/* This file defines dynamic annotations for use with dynamic analysis 289c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov tool such as valgrind, PIN, etc. 299c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov 309c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov Dynamic annotation is a source code annotation that affects 319c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov the generated code (that is, the annotation is not a comment). 329c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov Each such annotation is attached to a particular 339c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov instruction and/or to a particular object (address) in the program. 349c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov 359c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov The annotations that should be used by users are macros in all upper-case 369c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov (e.g., ANNOTATE_NEW_MEMORY). 379c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov 389c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov Actual implementation of these macros may differ depending on the 399c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov dynamic analysis tool being used. 409c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov 419c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov See http://code.google.com/p/data-race-test/ for more information. 429c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov 439c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov This file supports the following dynamic analysis tools: 449c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov - None (DYNAMIC_ANNOTATIONS_ENABLED is not defined or zero). 459c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov Macros are defined empty. 469c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov - ThreadSanitizer, Helgrind, DRD (DYNAMIC_ANNOTATIONS_ENABLED is 1). 479c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov Macros are defined as calls to non-inlinable empty functions 489c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov that are intercepted by Valgrind. */ 499c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov 509c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov#ifndef __DYNAMIC_ANNOTATIONS_H__ 519c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov#define __DYNAMIC_ANNOTATIONS_H__ 529c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov 539c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov#ifndef DYNAMIC_ANNOTATIONS_PREFIX 549c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov# define DYNAMIC_ANNOTATIONS_PREFIX 559c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov#endif 569c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov 579c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov#ifndef DYNAMIC_ANNOTATIONS_PROVIDE_RUNNING_ON_VALGRIND 589c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov# define DYNAMIC_ANNOTATIONS_PROVIDE_RUNNING_ON_VALGRIND 1 599c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov#endif 609c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov 619c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov#ifdef DYNAMIC_ANNOTATIONS_WANT_ATTRIBUTE_WEAK 629c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov# ifdef __GNUC__ 639c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov# define DYNAMIC_ANNOTATIONS_ATTRIBUTE_WEAK __attribute__((weak)) 649c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov# else 659c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov/* TODO(glider): for Windows support we may want to change this macro in order 669c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov to prepend __declspec(selectany) to the annotations' declarations. */ 679c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov# error weak annotations are not supported for your compiler 689c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov# endif 699c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov#else 709c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov# define DYNAMIC_ANNOTATIONS_ATTRIBUTE_WEAK 719c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov#endif 729c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov 739c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov/* The following preprocessor magic prepends the value of 749c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov DYNAMIC_ANNOTATIONS_PREFIX to annotation function names. */ 759c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov#define DYNAMIC_ANNOTATIONS_GLUE0(A, B) A##B 769c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov#define DYNAMIC_ANNOTATIONS_GLUE(A, B) DYNAMIC_ANNOTATIONS_GLUE0(A, B) 779c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov#define DYNAMIC_ANNOTATIONS_NAME(name) \ 789c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov DYNAMIC_ANNOTATIONS_GLUE(DYNAMIC_ANNOTATIONS_PREFIX, name) 799c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov 809c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov#ifndef DYNAMIC_ANNOTATIONS_ENABLED 819c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov# define DYNAMIC_ANNOTATIONS_ENABLED 0 829c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov#endif 839c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov 849c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov#if DYNAMIC_ANNOTATIONS_ENABLED != 0 859c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov 869c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov /* ------------------------------------------------------------- 879c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov Annotations useful when implementing condition variables such as CondVar, 889c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov using conditional critical sections (Await/LockWhen) and when constructing 899c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov user-defined synchronization mechanisms. 909c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov 919c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov The annotations ANNOTATE_HAPPENS_BEFORE() and ANNOTATE_HAPPENS_AFTER() can 929c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov be used to define happens-before arcs in user-defined synchronization 939c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov mechanisms: the race detector will infer an arc from the former to the 949c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov latter when they share the same argument pointer. 959c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov 969c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov Example 1 (reference counting): 979c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov 989c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov void Unref() { 999c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov ANNOTATE_HAPPENS_BEFORE(&refcount_); 1009c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov if (AtomicDecrementByOne(&refcount_) == 0) { 1019c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov ANNOTATE_HAPPENS_AFTER(&refcount_); 1029c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov delete this; 1039c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov } 1049c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov } 1059c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov 1069c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov Example 2 (message queue): 1079c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov 1089c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov void MyQueue::Put(Type *e) { 1099c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov MutexLock lock(&mu_); 1109c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov ANNOTATE_HAPPENS_BEFORE(e); 1119c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov PutElementIntoMyQueue(e); 1129c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov } 1139c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov 1149c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov Type *MyQueue::Get() { 1159c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov MutexLock lock(&mu_); 1169c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov Type *e = GetElementFromMyQueue(); 1179c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov ANNOTATE_HAPPENS_AFTER(e); 1189c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov return e; 1199c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov } 1209c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov 1219c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov Note: when possible, please use the existing reference counting and message 1229c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov queue implementations instead of inventing new ones. */ 1239c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov 1249c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov /* Report that wait on the condition variable at address "cv" has succeeded 1259c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov and the lock at address "lock" is held. */ 1269c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov #define ANNOTATE_CONDVAR_LOCK_WAIT(cv, lock) \ 1279c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov DYNAMIC_ANNOTATIONS_NAME(AnnotateCondVarWait)(__FILE__, __LINE__, cv, lock) 1289c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov 1299c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov /* Report that wait on the condition variable at "cv" has succeeded. Variant 1309c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov w/o lock. */ 1319c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov #define ANNOTATE_CONDVAR_WAIT(cv) \ 1329c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov DYNAMIC_ANNOTATIONS_NAME(AnnotateCondVarWait)(__FILE__, __LINE__, cv, NULL) 1339c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov 1349c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov /* Report that we are about to signal on the condition variable at address 1359c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov "cv". */ 1369c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov #define ANNOTATE_CONDVAR_SIGNAL(cv) \ 1379c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov DYNAMIC_ANNOTATIONS_NAME(AnnotateCondVarSignal)(__FILE__, __LINE__, cv) 1389c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov 1399c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov /* Report that we are about to signal_all on the condition variable at address 1409c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov "cv". */ 1419c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov #define ANNOTATE_CONDVAR_SIGNAL_ALL(cv) \ 1429c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov DYNAMIC_ANNOTATIONS_NAME(AnnotateCondVarSignalAll)(__FILE__, __LINE__, cv) 1439c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov 1449c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov /* Annotations for user-defined synchronization mechanisms. */ 1459c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov #define ANNOTATE_HAPPENS_BEFORE(obj) \ 1469c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov DYNAMIC_ANNOTATIONS_NAME(AnnotateHappensBefore)(__FILE__, __LINE__, obj) 1479c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov #define ANNOTATE_HAPPENS_AFTER(obj) \ 1489c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov DYNAMIC_ANNOTATIONS_NAME(AnnotateHappensAfter)(__FILE__, __LINE__, obj) 1499c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov 1509c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov /* DEPRECATED. Don't use it. */ 1519c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov #define ANNOTATE_PUBLISH_MEMORY_RANGE(pointer, size) \ 1529c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov DYNAMIC_ANNOTATIONS_NAME(AnnotatePublishMemoryRange)(__FILE__, __LINE__, \ 1539c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov pointer, size) 1549c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov 1559c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov /* DEPRECATED. Don't use it. */ 1569c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov #define ANNOTATE_UNPUBLISH_MEMORY_RANGE(pointer, size) \ 1579c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov DYNAMIC_ANNOTATIONS_NAME(AnnotateUnpublishMemoryRange)(__FILE__, __LINE__, \ 1589c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov pointer, size) 1599c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov 1609c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov /* DEPRECATED. Don't use it. */ 1619c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov #define ANNOTATE_SWAP_MEMORY_RANGE(pointer, size) \ 1629c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov do { \ 1639c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov ANNOTATE_UNPUBLISH_MEMORY_RANGE(pointer, size); \ 1649c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov ANNOTATE_PUBLISH_MEMORY_RANGE(pointer, size); \ 1659c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov } while (0) 1669c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov 1679c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov /* Instruct the tool to create a happens-before arc between mu->Unlock() and 1689c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov mu->Lock(). This annotation may slow down the race detector and hide real 1699c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov races. Normally it is used only when it would be difficult to annotate each 1709c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov of the mutex's critical sections individually using the annotations above. 1719c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov This annotation makes sense only for hybrid race detectors. For pure 1729c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov happens-before detectors this is a no-op. For more details see 1739c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov http://code.google.com/p/data-race-test/wiki/PureHappensBeforeVsHybrid . */ 1749c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov #define ANNOTATE_PURE_HAPPENS_BEFORE_MUTEX(mu) \ 1759c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov DYNAMIC_ANNOTATIONS_NAME(AnnotateMutexIsUsedAsCondVar)(__FILE__, __LINE__, \ 1769c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov mu) 1779c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov 1789c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov /* Opposite to ANNOTATE_PURE_HAPPENS_BEFORE_MUTEX. 1799c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov Instruct the tool to NOT create h-b arcs between Unlock and Lock, even in 1809c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov pure happens-before mode. For a hybrid mode this is a no-op. */ 1819c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov #define ANNOTATE_NOT_HAPPENS_BEFORE_MUTEX(mu) \ 1829c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov DYNAMIC_ANNOTATIONS_NAME(AnnotateMutexIsNotPHB)(__FILE__, __LINE__, mu) 1839c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov 1849c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov /* Deprecated. Use ANNOTATE_PURE_HAPPENS_BEFORE_MUTEX. */ 1859c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov #define ANNOTATE_MUTEX_IS_USED_AS_CONDVAR(mu) \ 1869c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov DYNAMIC_ANNOTATIONS_NAME(AnnotateMutexIsUsedAsCondVar)(__FILE__, __LINE__, \ 1879c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov mu) 1889c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov 1899c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov /* ------------------------------------------------------------- 1909c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov Annotations useful when defining memory allocators, or when memory that 1919c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov was protected in one way starts to be protected in another. */ 1929c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov 1939c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov /* Report that a new memory at "address" of size "size" has been allocated. 1949c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov This might be used when the memory has been retrieved from a free list and 1959c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov is about to be reused, or when a the locking discipline for a variable 1969c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov changes. */ 1979c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov #define ANNOTATE_NEW_MEMORY(address, size) \ 1989c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov DYNAMIC_ANNOTATIONS_NAME(AnnotateNewMemory)(__FILE__, __LINE__, address, \ 1999c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov size) 2009c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov 2019c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov /* ------------------------------------------------------------- 2029c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov Annotations useful when defining FIFO queues that transfer data between 2039c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov threads. */ 2049c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov 2059c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov /* Report that the producer-consumer queue (such as ProducerConsumerQueue) at 2069c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov address "pcq" has been created. The ANNOTATE_PCQ_* annotations 2079c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov should be used only for FIFO queues. For non-FIFO queues use 2089c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov ANNOTATE_HAPPENS_BEFORE (for put) and ANNOTATE_HAPPENS_AFTER (for get). */ 2099c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov #define ANNOTATE_PCQ_CREATE(pcq) \ 2109c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov DYNAMIC_ANNOTATIONS_NAME(AnnotatePCQCreate)(__FILE__, __LINE__, pcq) 2119c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov 2129c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov /* Report that the queue at address "pcq" is about to be destroyed. */ 2139c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov #define ANNOTATE_PCQ_DESTROY(pcq) \ 2149c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov DYNAMIC_ANNOTATIONS_NAME(AnnotatePCQDestroy)(__FILE__, __LINE__, pcq) 2159c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov 2169c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov /* Report that we are about to put an element into a FIFO queue at address 2179c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov "pcq". */ 2189c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov #define ANNOTATE_PCQ_PUT(pcq) \ 2199c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov DYNAMIC_ANNOTATIONS_NAME(AnnotatePCQPut)(__FILE__, __LINE__, pcq) 2209c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov 2219c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov /* Report that we've just got an element from a FIFO queue at address 2229c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov "pcq". */ 2239c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov #define ANNOTATE_PCQ_GET(pcq) \ 2249c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov DYNAMIC_ANNOTATIONS_NAME(AnnotatePCQGet)(__FILE__, __LINE__, pcq) 2259c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov 2269c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov /* ------------------------------------------------------------- 2279c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov Annotations that suppress errors. It is usually better to express the 2289c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov program's synchronization using the other annotations, but these can 2299c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov be used when all else fails. */ 2309c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov 2319c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov /* Report that we may have a benign race at "pointer", with size 2329c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov "sizeof(*(pointer))". "pointer" must be a non-void* pointer. Insert at the 2339c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov point where "pointer" has been allocated, preferably close to the point 2349c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov where the race happens. See also ANNOTATE_BENIGN_RACE_STATIC. */ 2359c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov #define ANNOTATE_BENIGN_RACE(pointer, description) \ 2369c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov DYNAMIC_ANNOTATIONS_NAME(AnnotateBenignRaceSized)(__FILE__, __LINE__, \ 2379c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov pointer, sizeof(*(pointer)), description) 2389c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov 2399c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov /* Same as ANNOTATE_BENIGN_RACE(address, description), but applies to 2409c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov the memory range [address, address+size). */ 2419c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov #define ANNOTATE_BENIGN_RACE_SIZED(address, size, description) \ 2429c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov DYNAMIC_ANNOTATIONS_NAME(AnnotateBenignRaceSized)(__FILE__, __LINE__, \ 2439c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov address, size, description) 2449c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov 2459c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov /* Request the analysis tool to ignore all reads in the current thread 2469c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov until ANNOTATE_IGNORE_READS_END is called. 2479c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov Useful to ignore intentional racey reads, while still checking 2489c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov other reads and all writes. 2499c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov See also ANNOTATE_UNPROTECTED_READ. */ 2509c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov #define ANNOTATE_IGNORE_READS_BEGIN() \ 2519c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov DYNAMIC_ANNOTATIONS_NAME(AnnotateIgnoreReadsBegin)(__FILE__, __LINE__) 2529c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov 2539c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov /* Stop ignoring reads. */ 2549c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov #define ANNOTATE_IGNORE_READS_END() \ 2559c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov DYNAMIC_ANNOTATIONS_NAME(AnnotateIgnoreReadsEnd)(__FILE__, __LINE__) 2569c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov 2579c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov /* Similar to ANNOTATE_IGNORE_READS_BEGIN, but ignore writes. */ 2589c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov #define ANNOTATE_IGNORE_WRITES_BEGIN() \ 2599c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov DYNAMIC_ANNOTATIONS_NAME(AnnotateIgnoreWritesBegin)(__FILE__, __LINE__) 2609c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov 2619c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov /* Stop ignoring writes. */ 2629c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov #define ANNOTATE_IGNORE_WRITES_END() \ 2639c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov DYNAMIC_ANNOTATIONS_NAME(AnnotateIgnoreWritesEnd)(__FILE__, __LINE__) 2649c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov 2659c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov /* Start ignoring all memory accesses (reads and writes). */ 2669c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov #define ANNOTATE_IGNORE_READS_AND_WRITES_BEGIN() \ 2679c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov do {\ 2689c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov ANNOTATE_IGNORE_READS_BEGIN();\ 2699c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov ANNOTATE_IGNORE_WRITES_BEGIN();\ 2709c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov }while(0)\ 2719c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov 2729c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov /* Stop ignoring all memory accesses. */ 2739c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov #define ANNOTATE_IGNORE_READS_AND_WRITES_END() \ 2749c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov do {\ 2759c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov ANNOTATE_IGNORE_WRITES_END();\ 2769c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov ANNOTATE_IGNORE_READS_END();\ 2779c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov }while(0)\ 2789c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov 2799c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov /* Similar to ANNOTATE_IGNORE_READS_BEGIN, but ignore synchronization events: 2809c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov RWLOCK* and CONDVAR*. */ 2819c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov #define ANNOTATE_IGNORE_SYNC_BEGIN() \ 2829c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov DYNAMIC_ANNOTATIONS_NAME(AnnotateIgnoreSyncBegin)(__FILE__, __LINE__) 2839c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov 2849c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov /* Stop ignoring sync events. */ 2859c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov #define ANNOTATE_IGNORE_SYNC_END() \ 2869c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov DYNAMIC_ANNOTATIONS_NAME(AnnotateIgnoreSyncEnd)(__FILE__, __LINE__) 2879c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov 2889c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov 2899c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov /* Enable (enable!=0) or disable (enable==0) race detection for all threads. 2909c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov This annotation could be useful if you want to skip expensive race analysis 2919c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov during some period of program execution, e.g. during initialization. */ 2929c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov #define ANNOTATE_ENABLE_RACE_DETECTION(enable) \ 2939c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov DYNAMIC_ANNOTATIONS_NAME(AnnotateEnableRaceDetection)(__FILE__, __LINE__, \ 2949c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov enable) 2959c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov 2969c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov /* ------------------------------------------------------------- 2979c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov Annotations useful for debugging. */ 2989c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov 2999c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov /* Request to trace every access to "address". */ 3009c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov #define ANNOTATE_TRACE_MEMORY(address) \ 3019c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov DYNAMIC_ANNOTATIONS_NAME(AnnotateTraceMemory)(__FILE__, __LINE__, address) 3029c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov 3039c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov /* Report the current thread name to a race detector. */ 3049c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov #define ANNOTATE_THREAD_NAME(name) \ 3059c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov DYNAMIC_ANNOTATIONS_NAME(AnnotateThreadName)(__FILE__, __LINE__, name) 3069c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov 3079c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov /* ------------------------------------------------------------- 3089c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov Annotations useful when implementing locks. They are not 3099c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov normally needed by modules that merely use locks. 3109c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov The "lock" argument is a pointer to the lock object. */ 3119c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov 3129c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov /* Report that a lock has been created at address "lock". */ 3139c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov #define ANNOTATE_RWLOCK_CREATE(lock) \ 3149c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov DYNAMIC_ANNOTATIONS_NAME(AnnotateRWLockCreate)(__FILE__, __LINE__, lock) 3159c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov 3169c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov /* Report that the lock at address "lock" is about to be destroyed. */ 3179c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov #define ANNOTATE_RWLOCK_DESTROY(lock) \ 3189c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov DYNAMIC_ANNOTATIONS_NAME(AnnotateRWLockDestroy)(__FILE__, __LINE__, lock) 3199c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov 3209c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov /* Report that the lock at address "lock" has been acquired. 3219c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov is_w=1 for writer lock, is_w=0 for reader lock. */ 3229c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov #define ANNOTATE_RWLOCK_ACQUIRED(lock, is_w) \ 3239c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov DYNAMIC_ANNOTATIONS_NAME(AnnotateRWLockAcquired)(__FILE__, __LINE__, lock, \ 3249c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov is_w) 3259c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov 3269c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov /* Report that the lock at address "lock" is about to be released. */ 3279c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov #define ANNOTATE_RWLOCK_RELEASED(lock, is_w) \ 3289c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov DYNAMIC_ANNOTATIONS_NAME(AnnotateRWLockReleased)(__FILE__, __LINE__, lock, \ 3299c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov is_w) 3309c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov 3319c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov /* ------------------------------------------------------------- 3329c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov Annotations useful when implementing barriers. They are not 3339c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov normally needed by modules that merely use barriers. 3349c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov The "barrier" argument is a pointer to the barrier object. */ 3359c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov 3369c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov /* Report that the "barrier" has been initialized with initial "count". 3379c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov If 'reinitialization_allowed' is true, initialization is allowed to happen 3389c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov multiple times w/o calling barrier_destroy() */ 3399c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov #define ANNOTATE_BARRIER_INIT(barrier, count, reinitialization_allowed) \ 3409c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov DYNAMIC_ANNOTATIONS_NAME(AnnotateBarrierInit)(__FILE__, __LINE__, barrier, \ 3419c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov count, reinitialization_allowed) 3429c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov 3439c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov /* Report that we are about to enter barrier_wait("barrier"). */ 3449c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov #define ANNOTATE_BARRIER_WAIT_BEFORE(barrier) \ 3459c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov DYNAMIC_ANNOTATIONS_NAME(AnnotateBarrierWaitBefore)(__FILE__, __LINE__, \ 3469c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov barrier) 3479c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov 3489c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov /* Report that we just exited barrier_wait("barrier"). */ 3499c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov #define ANNOTATE_BARRIER_WAIT_AFTER(barrier) \ 3509c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov DYNAMIC_ANNOTATIONS_NAME(AnnotateBarrierWaitAfter)(__FILE__, __LINE__, \ 3519c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov barrier) 3529c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov 3539c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov /* Report that the "barrier" has been destroyed. */ 3549c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov #define ANNOTATE_BARRIER_DESTROY(barrier) \ 3559c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov DYNAMIC_ANNOTATIONS_NAME(AnnotateBarrierDestroy)(__FILE__, __LINE__, \ 3569c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov barrier) 3579c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov 3589c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov /* ------------------------------------------------------------- 3599c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov Annotations useful for testing race detectors. */ 3609c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov 3619c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov /* Report that we expect a race on the variable at "address". 3629c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov Use only in unit tests for a race detector. */ 3639c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov #define ANNOTATE_EXPECT_RACE(address, description) \ 3649c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov DYNAMIC_ANNOTATIONS_NAME(AnnotateExpectRace)(__FILE__, __LINE__, address, \ 3659c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov description) 3669c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov 3679c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov #define ANNOTATE_FLUSH_EXPECTED_RACES() \ 3689c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov DYNAMIC_ANNOTATIONS_NAME(AnnotateFlushExpectedRaces)(__FILE__, __LINE__) 3699c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov 3709c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov /* A no-op. Insert where you like to test the interceptors. */ 3719c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov #define ANNOTATE_NO_OP(arg) \ 3729c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov DYNAMIC_ANNOTATIONS_NAME(AnnotateNoOp)(__FILE__, __LINE__, arg) 3739c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov 3749c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov /* Force the race detector to flush its state. The actual effect depends on 3759c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov * the implementation of the detector. */ 3769c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov #define ANNOTATE_FLUSH_STATE() \ 3779c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov DYNAMIC_ANNOTATIONS_NAME(AnnotateFlushState)(__FILE__, __LINE__) 3789c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov 3799c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov 3809c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov#else /* DYNAMIC_ANNOTATIONS_ENABLED == 0 */ 3819c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov 3829c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov #define ANNOTATE_RWLOCK_CREATE(lock) /* empty */ 3839c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov #define ANNOTATE_RWLOCK_DESTROY(lock) /* empty */ 3849c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov #define ANNOTATE_RWLOCK_ACQUIRED(lock, is_w) /* empty */ 3859c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov #define ANNOTATE_RWLOCK_RELEASED(lock, is_w) /* empty */ 3869c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov #define ANNOTATE_BARRIER_INIT(barrier, count, reinitialization_allowed) /* */ 3879c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov #define ANNOTATE_BARRIER_WAIT_BEFORE(barrier) /* empty */ 3889c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov #define ANNOTATE_BARRIER_WAIT_AFTER(barrier) /* empty */ 3899c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov #define ANNOTATE_BARRIER_DESTROY(barrier) /* empty */ 3909c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov #define ANNOTATE_CONDVAR_LOCK_WAIT(cv, lock) /* empty */ 3919c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov #define ANNOTATE_CONDVAR_WAIT(cv) /* empty */ 3929c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov #define ANNOTATE_CONDVAR_SIGNAL(cv) /* empty */ 3939c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov #define ANNOTATE_CONDVAR_SIGNAL_ALL(cv) /* empty */ 3949c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov #define ANNOTATE_HAPPENS_BEFORE(obj) /* empty */ 3959c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov #define ANNOTATE_HAPPENS_AFTER(obj) /* empty */ 3969c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov #define ANNOTATE_PUBLISH_MEMORY_RANGE(address, size) /* empty */ 3979c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov #define ANNOTATE_UNPUBLISH_MEMORY_RANGE(address, size) /* empty */ 3989c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov #define ANNOTATE_SWAP_MEMORY_RANGE(address, size) /* empty */ 3999c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov #define ANNOTATE_PCQ_CREATE(pcq) /* empty */ 4009c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov #define ANNOTATE_PCQ_DESTROY(pcq) /* empty */ 4019c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov #define ANNOTATE_PCQ_PUT(pcq) /* empty */ 4029c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov #define ANNOTATE_PCQ_GET(pcq) /* empty */ 4039c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov #define ANNOTATE_NEW_MEMORY(address, size) /* empty */ 4049c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov #define ANNOTATE_EXPECT_RACE(address, description) /* empty */ 4059c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov #define ANNOTATE_FLUSH_EXPECTED_RACES(address, description) /* empty */ 4069c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov #define ANNOTATE_BENIGN_RACE(address, description) /* empty */ 4079c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov #define ANNOTATE_BENIGN_RACE_SIZED(address, size, description) /* empty */ 4089c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov #define ANNOTATE_PURE_HAPPENS_BEFORE_MUTEX(mu) /* empty */ 4099c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov #define ANNOTATE_MUTEX_IS_USED_AS_CONDVAR(mu) /* empty */ 4109c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov #define ANNOTATE_TRACE_MEMORY(arg) /* empty */ 4119c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov #define ANNOTATE_THREAD_NAME(name) /* empty */ 4129c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov #define ANNOTATE_IGNORE_READS_BEGIN() /* empty */ 4139c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov #define ANNOTATE_IGNORE_READS_END() /* empty */ 4149c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov #define ANNOTATE_IGNORE_WRITES_BEGIN() /* empty */ 4159c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov #define ANNOTATE_IGNORE_WRITES_END() /* empty */ 4169c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov #define ANNOTATE_IGNORE_READS_AND_WRITES_BEGIN() /* empty */ 4179c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov #define ANNOTATE_IGNORE_READS_AND_WRITES_END() /* empty */ 4189c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov #define ANNOTATE_IGNORE_SYNC_BEGIN() /* empty */ 4199c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov #define ANNOTATE_IGNORE_SYNC_END() /* empty */ 4209c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov #define ANNOTATE_ENABLE_RACE_DETECTION(enable) /* empty */ 4219c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov #define ANNOTATE_NO_OP(arg) /* empty */ 4229c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov #define ANNOTATE_FLUSH_STATE() /* empty */ 4239c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov 4249c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov#endif /* DYNAMIC_ANNOTATIONS_ENABLED */ 4259c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov 4269c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov/* Use the macros above rather than using these functions directly. */ 4279c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov#ifdef __cplusplus 4289c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanovextern "C" { 4299c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov#endif 4309c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov 4319c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov 4329c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanovvoid DYNAMIC_ANNOTATIONS_NAME(AnnotateRWLockCreate)( 4339c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov const char *file, int line, 4349c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov const volatile void *lock) DYNAMIC_ANNOTATIONS_ATTRIBUTE_WEAK; 4359c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanovvoid DYNAMIC_ANNOTATIONS_NAME(AnnotateRWLockDestroy)( 4369c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov const char *file, int line, 4379c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov const volatile void *lock) DYNAMIC_ANNOTATIONS_ATTRIBUTE_WEAK; 4389c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanovvoid DYNAMIC_ANNOTATIONS_NAME(AnnotateRWLockAcquired)( 4399c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov const char *file, int line, 4409c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov const volatile void *lock, long is_w) DYNAMIC_ANNOTATIONS_ATTRIBUTE_WEAK; 4419c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanovvoid DYNAMIC_ANNOTATIONS_NAME(AnnotateRWLockReleased)( 4429c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov const char *file, int line, 4439c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov const volatile void *lock, long is_w) DYNAMIC_ANNOTATIONS_ATTRIBUTE_WEAK; 4449c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanovvoid DYNAMIC_ANNOTATIONS_NAME(AnnotateBarrierInit)( 4459c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov const char *file, int line, const volatile void *barrier, long count, 4469c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov long reinitialization_allowed) DYNAMIC_ANNOTATIONS_ATTRIBUTE_WEAK; 4479c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanovvoid DYNAMIC_ANNOTATIONS_NAME(AnnotateBarrierWaitBefore)( 4489c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov const char *file, int line, 4499c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov const volatile void *barrier) DYNAMIC_ANNOTATIONS_ATTRIBUTE_WEAK; 4509c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanovvoid DYNAMIC_ANNOTATIONS_NAME(AnnotateBarrierWaitAfter)( 4519c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov const char *file, int line, 4529c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov const volatile void *barrier) DYNAMIC_ANNOTATIONS_ATTRIBUTE_WEAK; 4539c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanovvoid DYNAMIC_ANNOTATIONS_NAME(AnnotateBarrierDestroy)( 4549c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov const char *file, int line, 4559c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov const volatile void *barrier) DYNAMIC_ANNOTATIONS_ATTRIBUTE_WEAK; 4569c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanovvoid DYNAMIC_ANNOTATIONS_NAME(AnnotateCondVarWait)( 4579c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov const char *file, int line, const volatile void *cv, 4589c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov const volatile void *lock) DYNAMIC_ANNOTATIONS_ATTRIBUTE_WEAK; 4599c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanovvoid DYNAMIC_ANNOTATIONS_NAME(AnnotateCondVarSignal)( 4609c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov const char *file, int line, 4619c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov const volatile void *cv) DYNAMIC_ANNOTATIONS_ATTRIBUTE_WEAK; 4629c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanovvoid DYNAMIC_ANNOTATIONS_NAME(AnnotateCondVarSignalAll)( 4639c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov const char *file, int line, 4649c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov const volatile void *cv) DYNAMIC_ANNOTATIONS_ATTRIBUTE_WEAK; 4659c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanovvoid DYNAMIC_ANNOTATIONS_NAME(AnnotateHappensBefore)( 4669c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov const char *file, int line, 4679c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov const volatile void *obj) DYNAMIC_ANNOTATIONS_ATTRIBUTE_WEAK; 4689c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanovvoid DYNAMIC_ANNOTATIONS_NAME(AnnotateHappensAfter)( 4699c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov const char *file, int line, 4709c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov const volatile void *obj) DYNAMIC_ANNOTATIONS_ATTRIBUTE_WEAK; 4719c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanovvoid DYNAMIC_ANNOTATIONS_NAME(AnnotatePublishMemoryRange)( 4729c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov const char *file, int line, 4739c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov const volatile void *address, long size) DYNAMIC_ANNOTATIONS_ATTRIBUTE_WEAK; 4749c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanovvoid DYNAMIC_ANNOTATIONS_NAME(AnnotateUnpublishMemoryRange)( 4759c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov const char *file, int line, 4769c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov const volatile void *address, long size) DYNAMIC_ANNOTATIONS_ATTRIBUTE_WEAK; 4779c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanovvoid DYNAMIC_ANNOTATIONS_NAME(AnnotatePCQCreate)( 4789c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov const char *file, int line, 4799c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov const volatile void *pcq) DYNAMIC_ANNOTATIONS_ATTRIBUTE_WEAK; 4809c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanovvoid DYNAMIC_ANNOTATIONS_NAME(AnnotatePCQDestroy)( 4819c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov const char *file, int line, 4829c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov const volatile void *pcq) DYNAMIC_ANNOTATIONS_ATTRIBUTE_WEAK; 4839c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanovvoid DYNAMIC_ANNOTATIONS_NAME(AnnotatePCQPut)( 4849c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov const char *file, int line, 4859c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov const volatile void *pcq) DYNAMIC_ANNOTATIONS_ATTRIBUTE_WEAK; 4869c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanovvoid DYNAMIC_ANNOTATIONS_NAME(AnnotatePCQGet)( 4879c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov const char *file, int line, 4889c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov const volatile void *pcq) DYNAMIC_ANNOTATIONS_ATTRIBUTE_WEAK; 4899c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanovvoid DYNAMIC_ANNOTATIONS_NAME(AnnotateNewMemory)( 4909c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov const char *file, int line, 4919c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov const volatile void *mem, long size) DYNAMIC_ANNOTATIONS_ATTRIBUTE_WEAK; 4929c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanovvoid DYNAMIC_ANNOTATIONS_NAME(AnnotateExpectRace)( 4939c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov const char *file, int line, const volatile void *mem, 4949c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov const char *description) DYNAMIC_ANNOTATIONS_ATTRIBUTE_WEAK; 4959c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanovvoid DYNAMIC_ANNOTATIONS_NAME(AnnotateFlushExpectedRaces)( 4969c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov const char *file, int line) DYNAMIC_ANNOTATIONS_ATTRIBUTE_WEAK; 4979c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanovvoid DYNAMIC_ANNOTATIONS_NAME(AnnotateBenignRace)( 4989c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov const char *file, int line, const volatile void *mem, 4999c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov const char *description) DYNAMIC_ANNOTATIONS_ATTRIBUTE_WEAK; 5009c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanovvoid DYNAMIC_ANNOTATIONS_NAME(AnnotateBenignRaceSized)( 5019c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov const char *file, int line, const volatile void *mem, long size, 5029c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov const char *description) DYNAMIC_ANNOTATIONS_ATTRIBUTE_WEAK; 5039c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanovvoid DYNAMIC_ANNOTATIONS_NAME(AnnotateMutexIsUsedAsCondVar)( 5049c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov const char *file, int line, 5059c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov const volatile void *mu) DYNAMIC_ANNOTATIONS_ATTRIBUTE_WEAK; 5069c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanovvoid DYNAMIC_ANNOTATIONS_NAME(AnnotateMutexIsNotPHB)( 5079c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov const char *file, int line, 5089c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov const volatile void *mu) DYNAMIC_ANNOTATIONS_ATTRIBUTE_WEAK; 5099c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanovvoid DYNAMIC_ANNOTATIONS_NAME(AnnotateTraceMemory)( 5109c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov const char *file, int line, 5119c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov const volatile void *arg) DYNAMIC_ANNOTATIONS_ATTRIBUTE_WEAK; 5129c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanovvoid DYNAMIC_ANNOTATIONS_NAME(AnnotateThreadName)( 5139c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov const char *file, int line, 5149c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov const char *name) DYNAMIC_ANNOTATIONS_ATTRIBUTE_WEAK; 5159c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanovvoid DYNAMIC_ANNOTATIONS_NAME(AnnotateIgnoreReadsBegin)( 5169c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov const char *file, int line) DYNAMIC_ANNOTATIONS_ATTRIBUTE_WEAK; 5179c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanovvoid DYNAMIC_ANNOTATIONS_NAME(AnnotateIgnoreReadsEnd)( 5189c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov const char *file, int line) DYNAMIC_ANNOTATIONS_ATTRIBUTE_WEAK; 5199c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanovvoid DYNAMIC_ANNOTATIONS_NAME(AnnotateIgnoreWritesBegin)( 5209c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov const char *file, int line) DYNAMIC_ANNOTATIONS_ATTRIBUTE_WEAK; 5219c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanovvoid DYNAMIC_ANNOTATIONS_NAME(AnnotateIgnoreWritesEnd)( 5229c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov const char *file, int line) DYNAMIC_ANNOTATIONS_ATTRIBUTE_WEAK; 5239c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanovvoid DYNAMIC_ANNOTATIONS_NAME(AnnotateIgnoreSyncBegin)( 5249c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov const char *file, int line) DYNAMIC_ANNOTATIONS_ATTRIBUTE_WEAK; 5259c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanovvoid DYNAMIC_ANNOTATIONS_NAME(AnnotateIgnoreSyncEnd)( 5269c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov const char *file, int line) DYNAMIC_ANNOTATIONS_ATTRIBUTE_WEAK; 5279c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanovvoid DYNAMIC_ANNOTATIONS_NAME(AnnotateEnableRaceDetection)( 5289c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov const char *file, int line, int enable) DYNAMIC_ANNOTATIONS_ATTRIBUTE_WEAK; 5299c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanovvoid DYNAMIC_ANNOTATIONS_NAME(AnnotateNoOp)( 5309c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov const char *file, int line, 5319c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov const volatile void *arg) DYNAMIC_ANNOTATIONS_ATTRIBUTE_WEAK; 5329c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanovvoid DYNAMIC_ANNOTATIONS_NAME(AnnotateFlushState)( 5339c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov const char *file, int line) DYNAMIC_ANNOTATIONS_ATTRIBUTE_WEAK; 5349c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov 5359c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov#if DYNAMIC_ANNOTATIONS_PROVIDE_RUNNING_ON_VALGRIND == 1 5369c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov/* Return non-zero value if running under valgrind. 5379c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov 5389c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov If "valgrind.h" is included into dynamic_annotations.c, 5399c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov the regular valgrind mechanism will be used. 5409c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov See http://valgrind.org/docs/manual/manual-core-adv.html about 5419c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov RUNNING_ON_VALGRIND and other valgrind "client requests". 5429c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov The file "valgrind.h" may be obtained by doing 5439c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov svn co svn://svn.valgrind.org/valgrind/trunk/include 5449c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov 5459c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov If for some reason you can't use "valgrind.h" or want to fake valgrind, 5469c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov there are two ways to make this function return non-zero: 5479c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov - Use environment variable: export RUNNING_ON_VALGRIND=1 5489c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov - Make your tool intercept the function RunningOnValgrind() and 5499c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov change its return value. 5509c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov */ 5519c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanovint RunningOnValgrind(void); 5529c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov#endif /* DYNAMIC_ANNOTATIONS_PROVIDE_RUNNING_ON_VALGRIND == 1 */ 5539c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov 5549c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov#ifdef __cplusplus 5559c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov} 5569c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov#endif 5579c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov 5589c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov#if DYNAMIC_ANNOTATIONS_ENABLED != 0 && defined(__cplusplus) 5599c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov 5609c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov /* ANNOTATE_UNPROTECTED_READ is the preferred way to annotate racey reads. 5619c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov 5629c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov Instead of doing 5639c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov ANNOTATE_IGNORE_READS_BEGIN(); 5649c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov ... = x; 5659c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov ANNOTATE_IGNORE_READS_END(); 5669c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov one can use 5679c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov ... = ANNOTATE_UNPROTECTED_READ(x); */ 5689c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov template <class T> 5699c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov inline T ANNOTATE_UNPROTECTED_READ(const volatile T &x) { 5709c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov ANNOTATE_IGNORE_READS_BEGIN(); 5719c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov T res = x; 5729c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov ANNOTATE_IGNORE_READS_END(); 5739c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov return res; 5749c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov } 5759c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov /* Apply ANNOTATE_BENIGN_RACE_SIZED to a static variable. */ 5769c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov #define ANNOTATE_BENIGN_RACE_STATIC(static_var, description) \ 5779c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov namespace { \ 5789c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov class static_var ## _annotator { \ 5799c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov public: \ 5809c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov static_var ## _annotator() { \ 5819c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov ANNOTATE_BENIGN_RACE_SIZED(&static_var, \ 5829c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov sizeof(static_var), \ 5839c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov # static_var ": " description); \ 5849c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov } \ 5859c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov }; \ 5869c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov static static_var ## _annotator the ## static_var ## _annotator;\ 5879c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov } 5889c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov#else /* DYNAMIC_ANNOTATIONS_ENABLED == 0 */ 5899c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov 5909c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov #define ANNOTATE_UNPROTECTED_READ(x) (x) 5919c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov #define ANNOTATE_BENIGN_RACE_STATIC(static_var, description) /* empty */ 5929c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov 5939c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov#endif /* DYNAMIC_ANNOTATIONS_ENABLED */ 5949c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov 5959c8ac6f6cdd9881b64a84b20889d4ad20a6f0670Evgeniy Stepanov#endif /* __DYNAMIC_ANNOTATIONS_H__ */ 596