OLD | NEW |
1 /* Copyright (c) 2008-2009, Google Inc. | 1 /* Copyright (c) 2011, Google Inc. |
2 * All rights reserved. | 2 * All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Neither the name of Google Inc. nor the names of its | 10 * * Neither the name of Google Inc. nor the names of its |
11 * contributors may be used to endorse or promote products derived from | 11 * contributors may be used to endorse or promote products derived from |
12 * this software without specific prior written permission. | 12 * this software without specific prior written permission. |
13 * | 13 * |
14 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 14 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
15 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 15 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
16 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 16 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
17 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 17 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
18 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 18 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
19 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 19 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
20 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 20 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
25 * | |
26 * --- | |
27 * Author: Kostya Serebryany | |
28 */ | 25 */ |
29 | 26 |
30 #ifdef _MSC_VER | 27 #ifdef _MSC_VER |
31 # include <windows.h> | 28 # include <windows.h> |
32 #endif | 29 #endif |
33 | 30 |
34 #ifdef __cplusplus | 31 #ifdef __cplusplus |
35 # error "This file should be built as pure C to avoid name mangling" | 32 # error "This file should be built as pure C to avoid name mangling" |
36 #endif | 33 #endif |
37 | 34 |
38 #include <stdlib.h> | 35 #include <stdlib.h> |
39 #include <string.h> | 36 #include <string.h> |
40 | 37 |
41 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" | 38 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" |
42 | 39 |
43 #ifdef __GNUC__ | 40 #ifdef __GNUC__ |
44 /* valgrind.h uses gcc extensions so it won't build with other compilers */ | 41 /* valgrind.h uses gcc extensions so it won't build with other compilers */ |
45 # include "base/third_party/valgrind/valgrind.h" | 42 # include "base/third_party/valgrind/valgrind.h" |
46 #endif | 43 #endif |
47 | 44 |
48 /* Each function is empty and called (via a macro) only in debug mode. | 45 /* Each function is empty and called (via a macro) only in debug mode. |
49 The arguments are captured by dynamic tools at runtime. */ | 46 The arguments are captured by dynamic tools at runtime. */ |
50 | 47 |
51 #if DYNAMIC_ANNOTATIONS_ENABLED == 1 | 48 #if DYNAMIC_ANNOTATIONS_ENABLED == 1 |
52 | 49 |
| 50 /* Identical code folding(-Wl,--icf=all) countermeasures. |
| 51 This makes all Annotate* functions different, which prevents the linker from |
| 52 folding them. */ |
| 53 #ifdef __COUNTER__ |
| 54 #define DYNAMIC_ANNOTATIONS_IMPL \ |
| 55 volatile short lineno = (__LINE__ << 8) + __COUNTER__; (void)lineno; |
| 56 #else |
| 57 #define DYNAMIC_ANNOTATIONS_IMPL \ |
| 58 volatile short lineno = (__LINE__ << 8); (void)lineno; |
| 59 #endif |
| 60 |
| 61 /* WARNING: always add new annotations to the end of the list. |
| 62 Otherwise, lineno (see above) numbers for different Annotate* functions may |
| 63 conflict. */ |
53 void DYNAMIC_ANNOTATIONS_NAME(AnnotateRWLockCreate)( | 64 void DYNAMIC_ANNOTATIONS_NAME(AnnotateRWLockCreate)( |
54 const char *file, int line, const volatile void *lock){} | 65 const char *file, int line, const volatile void *lock) |
| 66 {DYNAMIC_ANNOTATIONS_IMPL} |
| 67 |
55 void DYNAMIC_ANNOTATIONS_NAME(AnnotateRWLockDestroy)( | 68 void DYNAMIC_ANNOTATIONS_NAME(AnnotateRWLockDestroy)( |
56 const char *file, int line, const volatile void *lock){} | 69 const char *file, int line, const volatile void *lock) |
| 70 {DYNAMIC_ANNOTATIONS_IMPL} |
| 71 |
57 void DYNAMIC_ANNOTATIONS_NAME(AnnotateRWLockAcquired)( | 72 void DYNAMIC_ANNOTATIONS_NAME(AnnotateRWLockAcquired)( |
58 const char *file, int line, const volatile void *lock, long is_w){} | 73 const char *file, int line, const volatile void *lock, long is_w) |
| 74 {DYNAMIC_ANNOTATIONS_IMPL} |
| 75 |
59 void DYNAMIC_ANNOTATIONS_NAME(AnnotateRWLockReleased)( | 76 void DYNAMIC_ANNOTATIONS_NAME(AnnotateRWLockReleased)( |
60 const char *file, int line, const volatile void *lock, long is_w){} | 77 const char *file, int line, const volatile void *lock, long is_w) |
| 78 {DYNAMIC_ANNOTATIONS_IMPL} |
| 79 |
61 void DYNAMIC_ANNOTATIONS_NAME(AnnotateBarrierInit)( | 80 void DYNAMIC_ANNOTATIONS_NAME(AnnotateBarrierInit)( |
62 const char *file, int line, const volatile void *barrier, long count, | 81 const char *file, int line, const volatile void *barrier, long count, |
63 long reinitialization_allowed) {} | 82 long reinitialization_allowed) |
| 83 {DYNAMIC_ANNOTATIONS_IMPL} |
| 84 |
64 void DYNAMIC_ANNOTATIONS_NAME(AnnotateBarrierWaitBefore)( | 85 void DYNAMIC_ANNOTATIONS_NAME(AnnotateBarrierWaitBefore)( |
65 const char *file, int line, const volatile void *barrier) {} | 86 const char *file, int line, const volatile void *barrier) |
| 87 {DYNAMIC_ANNOTATIONS_IMPL} |
| 88 |
66 void DYNAMIC_ANNOTATIONS_NAME(AnnotateBarrierWaitAfter)( | 89 void DYNAMIC_ANNOTATIONS_NAME(AnnotateBarrierWaitAfter)( |
67 const char *file, int line, const volatile void *barrier) {} | 90 const char *file, int line, const volatile void *barrier) |
| 91 {DYNAMIC_ANNOTATIONS_IMPL} |
| 92 |
68 void DYNAMIC_ANNOTATIONS_NAME(AnnotateBarrierDestroy)( | 93 void DYNAMIC_ANNOTATIONS_NAME(AnnotateBarrierDestroy)( |
69 const char *file, int line, const volatile void *barrier) {} | 94 const char *file, int line, const volatile void *barrier) |
| 95 {DYNAMIC_ANNOTATIONS_IMPL} |
70 | 96 |
71 void DYNAMIC_ANNOTATIONS_NAME(AnnotateCondVarWait)( | 97 void DYNAMIC_ANNOTATIONS_NAME(AnnotateCondVarWait)( |
72 const char *file, int line, const volatile void *cv, | 98 const char *file, int line, const volatile void *cv, |
73 const volatile void *lock){} | 99 const volatile void *lock) |
| 100 {DYNAMIC_ANNOTATIONS_IMPL} |
| 101 |
74 void DYNAMIC_ANNOTATIONS_NAME(AnnotateCondVarSignal)( | 102 void DYNAMIC_ANNOTATIONS_NAME(AnnotateCondVarSignal)( |
75 const char *file, int line, const volatile void *cv){} | 103 const char *file, int line, const volatile void *cv) |
| 104 {DYNAMIC_ANNOTATIONS_IMPL} |
| 105 |
76 void DYNAMIC_ANNOTATIONS_NAME(AnnotateCondVarSignalAll)( | 106 void DYNAMIC_ANNOTATIONS_NAME(AnnotateCondVarSignalAll)( |
77 const char *file, int line, const volatile void *cv){} | 107 const char *file, int line, const volatile void *cv) |
| 108 {DYNAMIC_ANNOTATIONS_IMPL} |
| 109 |
| 110 void DYNAMIC_ANNOTATIONS_NAME(AnnotateHappensBefore)( |
| 111 const char *file, int line, const volatile void *obj) |
| 112 {DYNAMIC_ANNOTATIONS_IMPL}; |
| 113 |
| 114 void DYNAMIC_ANNOTATIONS_NAME(AnnotateHappensAfter)( |
| 115 const char *file, int line, const volatile void *obj) |
| 116 {DYNAMIC_ANNOTATIONS_IMPL}; |
| 117 |
78 void DYNAMIC_ANNOTATIONS_NAME(AnnotatePublishMemoryRange)( | 118 void DYNAMIC_ANNOTATIONS_NAME(AnnotatePublishMemoryRange)( |
79 const char *file, int line, const volatile void *address, long size){} | 119 const char *file, int line, const volatile void *address, long size) |
| 120 {DYNAMIC_ANNOTATIONS_IMPL} |
| 121 |
80 void DYNAMIC_ANNOTATIONS_NAME(AnnotateUnpublishMemoryRange)( | 122 void DYNAMIC_ANNOTATIONS_NAME(AnnotateUnpublishMemoryRange)( |
81 const char *file, int line, const volatile void *address, long size){} | 123 const char *file, int line, const volatile void *address, long size) |
| 124 {DYNAMIC_ANNOTATIONS_IMPL} |
| 125 |
82 void DYNAMIC_ANNOTATIONS_NAME(AnnotatePCQCreate)( | 126 void DYNAMIC_ANNOTATIONS_NAME(AnnotatePCQCreate)( |
83 const char *file, int line, const volatile void *pcq){} | 127 const char *file, int line, const volatile void *pcq) |
| 128 {DYNAMIC_ANNOTATIONS_IMPL} |
| 129 |
84 void DYNAMIC_ANNOTATIONS_NAME(AnnotatePCQDestroy)( | 130 void DYNAMIC_ANNOTATIONS_NAME(AnnotatePCQDestroy)( |
85 const char *file, int line, const volatile void *pcq){} | 131 const char *file, int line, const volatile void *pcq) |
| 132 {DYNAMIC_ANNOTATIONS_IMPL} |
| 133 |
86 void DYNAMIC_ANNOTATIONS_NAME(AnnotatePCQPut)( | 134 void DYNAMIC_ANNOTATIONS_NAME(AnnotatePCQPut)( |
87 const char *file, int line, const volatile void *pcq){} | 135 const char *file, int line, const volatile void *pcq) |
| 136 {DYNAMIC_ANNOTATIONS_IMPL} |
| 137 |
88 void DYNAMIC_ANNOTATIONS_NAME(AnnotatePCQGet)( | 138 void DYNAMIC_ANNOTATIONS_NAME(AnnotatePCQGet)( |
89 const char *file, int line, const volatile void *pcq){} | 139 const char *file, int line, const volatile void *pcq) |
| 140 {DYNAMIC_ANNOTATIONS_IMPL} |
| 141 |
90 void DYNAMIC_ANNOTATIONS_NAME(AnnotateNewMemory)( | 142 void DYNAMIC_ANNOTATIONS_NAME(AnnotateNewMemory)( |
91 const char *file, int line, const volatile void *mem, long size){} | 143 const char *file, int line, const volatile void *mem, long size) |
| 144 {DYNAMIC_ANNOTATIONS_IMPL} |
| 145 |
92 void DYNAMIC_ANNOTATIONS_NAME(AnnotateExpectRace)( | 146 void DYNAMIC_ANNOTATIONS_NAME(AnnotateExpectRace)( |
93 const char *file, int line, const volatile void *mem, | 147 const char *file, int line, const volatile void *mem, |
94 const char *description){} | 148 const char *description) |
| 149 {DYNAMIC_ANNOTATIONS_IMPL} |
| 150 |
95 void DYNAMIC_ANNOTATIONS_NAME(AnnotateFlushExpectedRaces)( | 151 void DYNAMIC_ANNOTATIONS_NAME(AnnotateFlushExpectedRaces)( |
96 const char *file, int line){} | 152 const char *file, int line) |
| 153 {DYNAMIC_ANNOTATIONS_IMPL} |
| 154 |
97 void DYNAMIC_ANNOTATIONS_NAME(AnnotateBenignRace)( | 155 void DYNAMIC_ANNOTATIONS_NAME(AnnotateBenignRace)( |
98 const char *file, int line, const volatile void *mem, | 156 const char *file, int line, const volatile void *mem, |
99 const char *description){} | 157 const char *description) |
| 158 {DYNAMIC_ANNOTATIONS_IMPL} |
| 159 |
100 void DYNAMIC_ANNOTATIONS_NAME(AnnotateBenignRaceSized)( | 160 void DYNAMIC_ANNOTATIONS_NAME(AnnotateBenignRaceSized)( |
101 const char *file, int line, const volatile void *mem, long size, | 161 const char *file, int line, const volatile void *mem, long size, |
102 const char *description){} | 162 const char *description) |
| 163 {DYNAMIC_ANNOTATIONS_IMPL} |
| 164 |
103 void DYNAMIC_ANNOTATIONS_NAME(AnnotateMutexIsUsedAsCondVar)( | 165 void DYNAMIC_ANNOTATIONS_NAME(AnnotateMutexIsUsedAsCondVar)( |
104 const char *file, int line, const volatile void *mu){} | 166 const char *file, int line, const volatile void *mu) |
| 167 {DYNAMIC_ANNOTATIONS_IMPL} |
| 168 |
105 void DYNAMIC_ANNOTATIONS_NAME(AnnotateMutexIsNotPHB)( | 169 void DYNAMIC_ANNOTATIONS_NAME(AnnotateMutexIsNotPHB)( |
106 const char *file, int line, const volatile void *mu){} | 170 const char *file, int line, const volatile void *mu) |
| 171 {DYNAMIC_ANNOTATIONS_IMPL} |
| 172 |
107 void DYNAMIC_ANNOTATIONS_NAME(AnnotateTraceMemory)( | 173 void DYNAMIC_ANNOTATIONS_NAME(AnnotateTraceMemory)( |
108 const char *file, int line, const volatile void *arg){} | 174 const char *file, int line, const volatile void *arg) |
| 175 {DYNAMIC_ANNOTATIONS_IMPL} |
| 176 |
109 void DYNAMIC_ANNOTATIONS_NAME(AnnotateThreadName)( | 177 void DYNAMIC_ANNOTATIONS_NAME(AnnotateThreadName)( |
110 const char *file, int line, const char *name){} | 178 const char *file, int line, const char *name) |
| 179 {DYNAMIC_ANNOTATIONS_IMPL} |
| 180 |
111 void DYNAMIC_ANNOTATIONS_NAME(AnnotateIgnoreReadsBegin)( | 181 void DYNAMIC_ANNOTATIONS_NAME(AnnotateIgnoreReadsBegin)( |
112 const char *file, int line){} | 182 const char *file, int line) |
| 183 {DYNAMIC_ANNOTATIONS_IMPL} |
| 184 |
113 void DYNAMIC_ANNOTATIONS_NAME(AnnotateIgnoreReadsEnd)( | 185 void DYNAMIC_ANNOTATIONS_NAME(AnnotateIgnoreReadsEnd)( |
114 const char *file, int line){} | 186 const char *file, int line) |
| 187 {DYNAMIC_ANNOTATIONS_IMPL} |
| 188 |
115 void DYNAMIC_ANNOTATIONS_NAME(AnnotateIgnoreWritesBegin)( | 189 void DYNAMIC_ANNOTATIONS_NAME(AnnotateIgnoreWritesBegin)( |
116 const char *file, int line){} | 190 const char *file, int line) |
| 191 {DYNAMIC_ANNOTATIONS_IMPL} |
| 192 |
117 void DYNAMIC_ANNOTATIONS_NAME(AnnotateIgnoreWritesEnd)( | 193 void DYNAMIC_ANNOTATIONS_NAME(AnnotateIgnoreWritesEnd)( |
118 const char *file, int line){} | 194 const char *file, int line) |
| 195 {DYNAMIC_ANNOTATIONS_IMPL} |
| 196 |
119 void DYNAMIC_ANNOTATIONS_NAME(AnnotateIgnoreSyncBegin)( | 197 void DYNAMIC_ANNOTATIONS_NAME(AnnotateIgnoreSyncBegin)( |
120 const char *file, int line){} | 198 const char *file, int line) |
| 199 {DYNAMIC_ANNOTATIONS_IMPL} |
| 200 |
121 void DYNAMIC_ANNOTATIONS_NAME(AnnotateIgnoreSyncEnd)( | 201 void DYNAMIC_ANNOTATIONS_NAME(AnnotateIgnoreSyncEnd)( |
122 const char *file, int line){} | 202 const char *file, int line) |
| 203 {DYNAMIC_ANNOTATIONS_IMPL} |
| 204 |
123 void DYNAMIC_ANNOTATIONS_NAME(AnnotateEnableRaceDetection)( | 205 void DYNAMIC_ANNOTATIONS_NAME(AnnotateEnableRaceDetection)( |
124 const char *file, int line, int enable){} | 206 const char *file, int line, int enable) |
| 207 {DYNAMIC_ANNOTATIONS_IMPL} |
| 208 |
125 void DYNAMIC_ANNOTATIONS_NAME(AnnotateNoOp)( | 209 void DYNAMIC_ANNOTATIONS_NAME(AnnotateNoOp)( |
126 const char *file, int line, const volatile void *arg){} | 210 const char *file, int line, const volatile void *arg) |
| 211 {DYNAMIC_ANNOTATIONS_IMPL} |
| 212 |
127 void DYNAMIC_ANNOTATIONS_NAME(AnnotateFlushState)( | 213 void DYNAMIC_ANNOTATIONS_NAME(AnnotateFlushState)( |
128 const char *file, int line){} | 214 const char *file, int line) |
| 215 {DYNAMIC_ANNOTATIONS_IMPL} |
129 | 216 |
130 #endif /* DYNAMIC_ANNOTATIONS_ENABLED == 1 */ | 217 #endif /* DYNAMIC_ANNOTATIONS_ENABLED == 1 */ |
131 | 218 |
132 #if DYNAMIC_ANNOTATIONS_PROVIDE_RUNNING_ON_VALGRIND == 1 | 219 #if DYNAMIC_ANNOTATIONS_PROVIDE_RUNNING_ON_VALGRIND == 1 |
133 static int GetRunningOnValgrind(void) { | 220 static int GetRunningOnValgrind(void) { |
134 #ifdef RUNNING_ON_VALGRIND | 221 #ifdef RUNNING_ON_VALGRIND |
135 if (RUNNING_ON_VALGRIND) return 1; | 222 if (RUNNING_ON_VALGRIND) return 1; |
136 #endif | 223 #endif |
137 | 224 |
138 #ifndef _MSC_VER | 225 #ifndef _MSC_VER |
(...skipping 22 matching lines...) Expand all Loading... |
161 static volatile int running_on_valgrind = -1; | 248 static volatile int running_on_valgrind = -1; |
162 /* C doesn't have thread-safe initialization of statics, and we | 249 /* C doesn't have thread-safe initialization of statics, and we |
163 don't want to depend on pthread_once here, so hack it. */ | 250 don't want to depend on pthread_once here, so hack it. */ |
164 int local_running_on_valgrind = running_on_valgrind; | 251 int local_running_on_valgrind = running_on_valgrind; |
165 if (local_running_on_valgrind == -1) | 252 if (local_running_on_valgrind == -1) |
166 running_on_valgrind = local_running_on_valgrind = GetRunningOnValgrind(); | 253 running_on_valgrind = local_running_on_valgrind = GetRunningOnValgrind(); |
167 return local_running_on_valgrind; | 254 return local_running_on_valgrind; |
168 } | 255 } |
169 | 256 |
170 #endif /* DYNAMIC_ANNOTATIONS_PROVIDE_RUNNING_ON_VALGRIND == 1 */ | 257 #endif /* DYNAMIC_ANNOTATIONS_PROVIDE_RUNNING_ON_VALGRIND == 1 */ |
OLD | NEW |