| 1 | n/a | /* Copyright (c) 2008-2009, Google Inc. |
|---|
| 2 | n/a | * All rights reserved. |
|---|
| 3 | n/a | * |
|---|
| 4 | n/a | * Redistribution and use in source and binary forms, with or without |
|---|
| 5 | n/a | * modification, are permitted provided that the following conditions are |
|---|
| 6 | n/a | * met: |
|---|
| 7 | n/a | * |
|---|
| 8 | n/a | * * Redistributions of source code must retain the above copyright |
|---|
| 9 | n/a | * notice, this list of conditions and the following disclaimer. |
|---|
| 10 | n/a | * * Neither the name of Google Inc. nor the names of its |
|---|
| 11 | n/a | * contributors may be used to endorse or promote products derived from |
|---|
| 12 | n/a | * this software without specific prior written permission. |
|---|
| 13 | n/a | * |
|---|
| 14 | n/a | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|---|
| 15 | n/a | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|---|
| 16 | n/a | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
|---|
| 17 | n/a | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
|---|
| 18 | n/a | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|---|
| 19 | n/a | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|---|
| 20 | n/a | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|---|
| 21 | n/a | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
|---|
| 22 | n/a | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|---|
| 23 | n/a | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|---|
| 24 | n/a | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|---|
| 25 | n/a | * |
|---|
| 26 | n/a | * --- |
|---|
| 27 | n/a | * Author: Kostya Serebryany |
|---|
| 28 | n/a | */ |
|---|
| 29 | n/a | |
|---|
| 30 | n/a | #ifdef _MSC_VER |
|---|
| 31 | n/a | # include <windows.h> |
|---|
| 32 | n/a | #endif |
|---|
| 33 | n/a | |
|---|
| 34 | n/a | #ifdef __cplusplus |
|---|
| 35 | n/a | # error "This file should be built as pure C to avoid name mangling" |
|---|
| 36 | n/a | #endif |
|---|
| 37 | n/a | |
|---|
| 38 | n/a | #include <stdlib.h> |
|---|
| 39 | n/a | #include <string.h> |
|---|
| 40 | n/a | |
|---|
| 41 | n/a | #include "dynamic_annotations.h" |
|---|
| 42 | n/a | |
|---|
| 43 | n/a | /* Each function is empty and called (via a macro) only in debug mode. |
|---|
| 44 | n/a | The arguments are captured by dynamic tools at runtime. */ |
|---|
| 45 | n/a | |
|---|
| 46 | n/a | #if DYNAMIC_ANNOTATIONS_ENABLED == 1 |
|---|
| 47 | n/a | |
|---|
| 48 | n/a | void AnnotateRWLockCreate(const char *file, int line, |
|---|
| 49 | n/a | const volatile void *lock){} |
|---|
| 50 | n/a | void AnnotateRWLockDestroy(const char *file, int line, |
|---|
| 51 | n/a | const volatile void *lock){} |
|---|
| 52 | n/a | void AnnotateRWLockAcquired(const char *file, int line, |
|---|
| 53 | n/a | const volatile void *lock, long is_w){} |
|---|
| 54 | n/a | void AnnotateRWLockReleased(const char *file, int line, |
|---|
| 55 | n/a | const volatile void *lock, long is_w){} |
|---|
| 56 | n/a | void AnnotateBarrierInit(const char *file, int line, |
|---|
| 57 | n/a | const volatile void *barrier, long count, |
|---|
| 58 | n/a | long reinitialization_allowed) {} |
|---|
| 59 | n/a | void AnnotateBarrierWaitBefore(const char *file, int line, |
|---|
| 60 | n/a | const volatile void *barrier) {} |
|---|
| 61 | n/a | void AnnotateBarrierWaitAfter(const char *file, int line, |
|---|
| 62 | n/a | const volatile void *barrier) {} |
|---|
| 63 | n/a | void AnnotateBarrierDestroy(const char *file, int line, |
|---|
| 64 | n/a | const volatile void *barrier) {} |
|---|
| 65 | n/a | |
|---|
| 66 | n/a | void AnnotateCondVarWait(const char *file, int line, |
|---|
| 67 | n/a | const volatile void *cv, |
|---|
| 68 | n/a | const volatile void *lock){} |
|---|
| 69 | n/a | void AnnotateCondVarSignal(const char *file, int line, |
|---|
| 70 | n/a | const volatile void *cv){} |
|---|
| 71 | n/a | void AnnotateCondVarSignalAll(const char *file, int line, |
|---|
| 72 | n/a | const volatile void *cv){} |
|---|
| 73 | n/a | void AnnotatePublishMemoryRange(const char *file, int line, |
|---|
| 74 | n/a | const volatile void *address, |
|---|
| 75 | n/a | long size){} |
|---|
| 76 | n/a | void AnnotateUnpublishMemoryRange(const char *file, int line, |
|---|
| 77 | n/a | const volatile void *address, |
|---|
| 78 | n/a | long size){} |
|---|
| 79 | n/a | void AnnotatePCQCreate(const char *file, int line, |
|---|
| 80 | n/a | const volatile void *pcq){} |
|---|
| 81 | n/a | void AnnotatePCQDestroy(const char *file, int line, |
|---|
| 82 | n/a | const volatile void *pcq){} |
|---|
| 83 | n/a | void AnnotatePCQPut(const char *file, int line, |
|---|
| 84 | n/a | const volatile void *pcq){} |
|---|
| 85 | n/a | void AnnotatePCQGet(const char *file, int line, |
|---|
| 86 | n/a | const volatile void *pcq){} |
|---|
| 87 | n/a | void AnnotateNewMemory(const char *file, int line, |
|---|
| 88 | n/a | const volatile void *mem, |
|---|
| 89 | n/a | long size){} |
|---|
| 90 | n/a | void AnnotateExpectRace(const char *file, int line, |
|---|
| 91 | n/a | const volatile void *mem, |
|---|
| 92 | n/a | const char *description){} |
|---|
| 93 | n/a | void AnnotateBenignRace(const char *file, int line, |
|---|
| 94 | n/a | const volatile void *mem, |
|---|
| 95 | n/a | const char *description){} |
|---|
| 96 | n/a | void AnnotateBenignRaceSized(const char *file, int line, |
|---|
| 97 | n/a | const volatile void *mem, |
|---|
| 98 | n/a | long size, |
|---|
| 99 | n/a | const char *description) {} |
|---|
| 100 | n/a | void AnnotateMutexIsUsedAsCondVar(const char *file, int line, |
|---|
| 101 | n/a | const volatile void *mu){} |
|---|
| 102 | n/a | void AnnotateTraceMemory(const char *file, int line, |
|---|
| 103 | n/a | const volatile void *arg){} |
|---|
| 104 | n/a | void AnnotateThreadName(const char *file, int line, |
|---|
| 105 | n/a | const char *name){} |
|---|
| 106 | n/a | void AnnotateIgnoreReadsBegin(const char *file, int line){} |
|---|
| 107 | n/a | void AnnotateIgnoreReadsEnd(const char *file, int line){} |
|---|
| 108 | n/a | void AnnotateIgnoreWritesBegin(const char *file, int line){} |
|---|
| 109 | n/a | void AnnotateIgnoreWritesEnd(const char *file, int line){} |
|---|
| 110 | n/a | void AnnotateIgnoreSyncBegin(const char *file, int line){} |
|---|
| 111 | n/a | void AnnotateIgnoreSyncEnd(const char *file, int line){} |
|---|
| 112 | n/a | void AnnotateEnableRaceDetection(const char *file, int line, int enable){} |
|---|
| 113 | n/a | void AnnotateNoOp(const char *file, int line, |
|---|
| 114 | n/a | const volatile void *arg){} |
|---|
| 115 | n/a | void AnnotateFlushState(const char *file, int line){} |
|---|
| 116 | n/a | |
|---|
| 117 | n/a | static int GetRunningOnValgrind(void) { |
|---|
| 118 | n/a | #ifdef RUNNING_ON_VALGRIND |
|---|
| 119 | n/a | if (RUNNING_ON_VALGRIND) return 1; |
|---|
| 120 | n/a | #endif |
|---|
| 121 | n/a | |
|---|
| 122 | n/a | #ifndef _MSC_VER |
|---|
| 123 | n/a | char *running_on_valgrind_str = getenv("RUNNING_ON_VALGRIND"); |
|---|
| 124 | n/a | if (running_on_valgrind_str) { |
|---|
| 125 | n/a | return strcmp(running_on_valgrind_str, "0") != 0; |
|---|
| 126 | n/a | } |
|---|
| 127 | n/a | #else |
|---|
| 128 | n/a | /* Visual Studio issues warnings if we use getenv, |
|---|
| 129 | n/a | * so we use GetEnvironmentVariableA instead. |
|---|
| 130 | n/a | */ |
|---|
| 131 | n/a | char value[100] = "1"; |
|---|
| 132 | n/a | int res = GetEnvironmentVariableA("RUNNING_ON_VALGRIND", |
|---|
| 133 | n/a | value, sizeof(value)); |
|---|
| 134 | n/a | /* value will remain "1" if res == 0 or res >= sizeof(value). The latter |
|---|
| 135 | n/a | * can happen only if the given value is long, in this case it can't be "0". |
|---|
| 136 | n/a | */ |
|---|
| 137 | n/a | if (res > 0 && !strcmp(value, "0")) |
|---|
| 138 | n/a | return 1; |
|---|
| 139 | n/a | #endif |
|---|
| 140 | n/a | return 0; |
|---|
| 141 | n/a | } |
|---|
| 142 | n/a | |
|---|
| 143 | n/a | /* See the comments in dynamic_annotations.h */ |
|---|
| 144 | n/a | int RunningOnValgrind(void) { |
|---|
| 145 | n/a | static volatile int running_on_valgrind = -1; |
|---|
| 146 | n/a | /* C doesn't have thread-safe initialization of statics, and we |
|---|
| 147 | n/a | don't want to depend on pthread_once here, so hack it. */ |
|---|
| 148 | n/a | int local_running_on_valgrind = running_on_valgrind; |
|---|
| 149 | n/a | if (local_running_on_valgrind == -1) |
|---|
| 150 | n/a | running_on_valgrind = local_running_on_valgrind = GetRunningOnValgrind(); |
|---|
| 151 | n/a | return local_running_on_valgrind; |
|---|
| 152 | n/a | } |
|---|
| 153 | n/a | |
|---|
| 154 | n/a | #endif /* DYNAMIC_ANNOTATIONS_ENABLED == 1 */ |
|---|