OLD | NEW |
1 /* Copyright (c) 2008-2009, Google Inc. | 1 /* Copyright (c) 2008-2009, 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 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 | 43 |
44 #ifdef __GNUC__ | 44 #ifdef __GNUC__ |
45 /* valgrind.h uses gcc extensions so it won't build with other compilers */ | 45 /* valgrind.h uses gcc extensions so it won't build with other compilers */ |
46 # ifdef HAVE_VALGRIND_H /* prefer the user's copy if they have it */ | 46 # ifdef HAVE_VALGRIND_H /* prefer the user's copy if they have it */ |
47 # include <valgrind.h> | 47 # include <valgrind.h> |
48 # else /* otherwise just use the copy that we have */ | 48 # else /* otherwise just use the copy that we have */ |
49 # include "third_party/valgrind.h" | 49 # include "third_party/valgrind.h" |
50 # endif | 50 # endif |
51 #endif | 51 #endif |
52 | 52 |
53 /* Compiler-based ThreadSanitizer defines | |
54 DYNAMIC_ANNOTATIONS_EXTERNAL_IMPL = 1 | |
55 and provides its own definitions of the functions. */ | |
56 | |
57 #ifndef DYNAMIC_ANNOTATIONS_EXTERNAL_IMPL | |
58 # define DYNAMIC_ANNOTATIONS_EXTERNAL_IMPL 0 | |
59 #endif | |
60 | |
61 /* Each function is empty and called (via a macro) only in debug mode. | 53 /* Each function is empty and called (via a macro) only in debug mode. |
62 The arguments are captured by dynamic tools at runtime. */ | 54 The arguments are captured by dynamic tools at runtime. */ |
63 | 55 |
64 #if DYNAMIC_ANNOTATIONS_ENABLED == 1 \ | 56 #if DYNAMIC_ANNOTATIONS_ENABLED == 1 |
65 && DYNAMIC_ANNOTATIONS_EXTERNAL_IMPL == 0 | |
66 | 57 |
67 void AnnotateRWLockCreate(const char *file, int line, | 58 void AnnotateRWLockCreate(const char *file, int line, |
68 const volatile void *lock){} | 59 const volatile void *lock){} |
69 void AnnotateRWLockDestroy(const char *file, int line, | 60 void AnnotateRWLockDestroy(const char *file, int line, |
70 const volatile void *lock){} | 61 const volatile void *lock){} |
71 void AnnotateRWLockAcquired(const char *file, int line, | 62 void AnnotateRWLockAcquired(const char *file, int line, |
72 const volatile void *lock, long is_w){} | 63 const volatile void *lock, long is_w){} |
73 void AnnotateRWLockReleased(const char *file, int line, | 64 void AnnotateRWLockReleased(const char *file, int line, |
74 const volatile void *lock, long is_w){} | 65 const volatile void *lock, long is_w){} |
75 void AnnotateBarrierInit(const char *file, int line, | 66 void AnnotateBarrierInit(const char *file, int line, |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 const char *name){} | 115 const char *name){} |
125 void AnnotateIgnoreReadsBegin(const char *file, int line){} | 116 void AnnotateIgnoreReadsBegin(const char *file, int line){} |
126 void AnnotateIgnoreReadsEnd(const char *file, int line){} | 117 void AnnotateIgnoreReadsEnd(const char *file, int line){} |
127 void AnnotateIgnoreWritesBegin(const char *file, int line){} | 118 void AnnotateIgnoreWritesBegin(const char *file, int line){} |
128 void AnnotateIgnoreWritesEnd(const char *file, int line){} | 119 void AnnotateIgnoreWritesEnd(const char *file, int line){} |
129 void AnnotateEnableRaceDetection(const char *file, int line, int enable){} | 120 void AnnotateEnableRaceDetection(const char *file, int line, int enable){} |
130 void AnnotateNoOp(const char *file, int line, | 121 void AnnotateNoOp(const char *file, int line, |
131 const volatile void *arg){} | 122 const volatile void *arg){} |
132 void AnnotateFlushState(const char *file, int line){} | 123 void AnnotateFlushState(const char *file, int line){} |
133 | 124 |
134 #endif /* DYNAMIC_ANNOTATIONS_ENABLED == 1 | 125 #endif /* DYNAMIC_ANNOTATIONS_ENABLED == 1 */ |
135 && DYNAMIC_ANNOTATIONS_EXTERNAL_IMPL == 0 */ | |
136 | |
137 #if DYNAMIC_ANNOTATIONS_EXTERNAL_IMPL == 0 | |
138 | 126 |
139 static int GetRunningOnValgrind(void) { | 127 static int GetRunningOnValgrind(void) { |
140 #ifdef RUNNING_ON_VALGRIND | 128 #ifdef RUNNING_ON_VALGRIND |
141 if (RUNNING_ON_VALGRIND) return 1; | 129 if (RUNNING_ON_VALGRIND) return 1; |
142 #endif | 130 #endif |
143 #ifdef _MSC_VER | 131 #ifdef _MSC_VER |
144 /* Visual Studio can complain about getenv, so use a windows equivalent. */ | 132 /* Visual Studio can complain about getenv, so use a windows equivalent. */ |
145 char value[100] = "1"; /* something that is not "0" */ | 133 char value[100] = "1"; /* something that is not "0" */ |
146 int res = GetEnvironmentVariableA("RUNNING_ON_VALGRIND", | 134 int res = GetEnvironmentVariableA("RUNNING_ON_VALGRIND", |
147 value, sizeof(value)); | 135 value, sizeof(value)); |
(...skipping 16 matching lines...) Expand all Loading... |
164 static volatile int running_on_valgrind = -1; | 152 static volatile int running_on_valgrind = -1; |
165 int local_running_on_valgrind = running_on_valgrind; | 153 int local_running_on_valgrind = running_on_valgrind; |
166 /* C doesn't have thread-safe initialization of statics, and we | 154 /* C doesn't have thread-safe initialization of statics, and we |
167 don't want to depend on pthread_once here, so hack it. */ | 155 don't want to depend on pthread_once here, so hack it. */ |
168 ANNOTATE_BENIGN_RACE(&running_on_valgrind, "safe hack"); | 156 ANNOTATE_BENIGN_RACE(&running_on_valgrind, "safe hack"); |
169 if (local_running_on_valgrind == -1) | 157 if (local_running_on_valgrind == -1) |
170 running_on_valgrind = local_running_on_valgrind = GetRunningOnValgrind(); | 158 running_on_valgrind = local_running_on_valgrind = GetRunningOnValgrind(); |
171 return local_running_on_valgrind; | 159 return local_running_on_valgrind; |
172 } | 160 } |
173 | 161 |
174 #endif /* DYNAMIC_ANNOTATIONS_EXTERNAL_IMPL == 0 */ | |
175 | |
176 /* See the comments in dynamic_annotations.h */ | 162 /* See the comments in dynamic_annotations.h */ |
177 double ValgrindSlowdown(void) { | 163 double ValgrindSlowdown(void) { |
178 /* Same initialization hack as in RunningOnValgrind(). */ | 164 /* Same initialization hack as in RunningOnValgrind(). */ |
179 static volatile double slowdown = 0.0; | 165 static volatile double slowdown = 0.0; |
180 double local_slowdown = slowdown; | 166 double local_slowdown = slowdown; |
181 ANNOTATE_BENIGN_RACE(&slowdown, "safe hack"); | 167 ANNOTATE_BENIGN_RACE(&slowdown, "safe hack"); |
182 if (RunningOnValgrind() == 0) { | 168 if (RunningOnValgrind() == 0) { |
183 return 1.0; | 169 return 1.0; |
184 } | 170 } |
185 if (local_slowdown == 0.0) { | 171 if (local_slowdown == 0.0) { |
186 char *env = getenv("VALGRIND_SLOWDOWN"); | 172 char *env = getenv("VALGRIND_SLOWDOWN"); |
187 slowdown = local_slowdown = env ? atof(env) : 50.0; | 173 slowdown = local_slowdown = env ? atof(env) : 50.0; |
188 } | 174 } |
189 return local_slowdown; | 175 return local_slowdown; |
190 } | 176 } |
OLD | NEW |