Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include <stdlib.h>
00016 #include <string.h>
00017
00018 #include "absl/base/dynamic_annotations.h"
00019
00020 #ifndef __has_feature
00021 #define __has_feature(x) 0
00022 #endif
00023
00024
00025
00026
00027
00028 #ifndef DYNAMIC_ANNOTATIONS_EXTERNAL_IMPL
00029 # define DYNAMIC_ANNOTATIONS_EXTERNAL_IMPL 0
00030 #endif
00031
00032
00033
00034
00035 #if DYNAMIC_ANNOTATIONS_EXTERNAL_IMPL == 0 && !defined(__native_client__)
00036
00037 #if __has_feature(memory_sanitizer)
00038 #include <sanitizer/msan_interface.h>
00039 #endif
00040
00041 #ifdef __cplusplus
00042 extern "C" {
00043 #endif
00044
00045 void AnnotateRWLockCreate(const char *, int,
00046 const volatile void *){}
00047 void AnnotateRWLockDestroy(const char *, int,
00048 const volatile void *){}
00049 void AnnotateRWLockAcquired(const char *, int,
00050 const volatile void *, long){}
00051 void AnnotateRWLockReleased(const char *, int,
00052 const volatile void *, long){}
00053 void AnnotateBenignRace(const char *, int,
00054 const volatile void *,
00055 const char *){}
00056 void AnnotateBenignRaceSized(const char *, int,
00057 const volatile void *,
00058 size_t,
00059 const char *) {}
00060 void AnnotateThreadName(const char *, int,
00061 const char *){}
00062 void AnnotateIgnoreReadsBegin(const char *, int){}
00063 void AnnotateIgnoreReadsEnd(const char *, int){}
00064 void AnnotateIgnoreWritesBegin(const char *, int){}
00065 void AnnotateIgnoreWritesEnd(const char *, int){}
00066 void AnnotateEnableRaceDetection(const char *, int, int){}
00067 void AnnotateMemoryIsInitialized(const char *, int,
00068 const volatile void *mem, size_t size) {
00069 #if __has_feature(memory_sanitizer)
00070 __msan_unpoison(mem, size);
00071 #else
00072 (void)mem;
00073 (void)size;
00074 #endif
00075 }
00076
00077 void AnnotateMemoryIsUninitialized(const char *, int,
00078 const volatile void *mem, size_t size) {
00079 #if __has_feature(memory_sanitizer)
00080 __msan_allocated_memory(mem, size);
00081 #else
00082 (void)mem;
00083 (void)size;
00084 #endif
00085 }
00086
00087 static int GetRunningOnValgrind(void) {
00088 #ifdef RUNNING_ON_VALGRIND
00089 if (RUNNING_ON_VALGRIND) return 1;
00090 #endif
00091 char *running_on_valgrind_str = getenv("RUNNING_ON_VALGRIND");
00092 if (running_on_valgrind_str) {
00093 return strcmp(running_on_valgrind_str, "0") != 0;
00094 }
00095 return 0;
00096 }
00097
00098
00099 int RunningOnValgrind(void) {
00100 static volatile int running_on_valgrind = -1;
00101 int local_running_on_valgrind = running_on_valgrind;
00102
00103
00104 ANNOTATE_BENIGN_RACE(&running_on_valgrind, "safe hack");
00105 if (local_running_on_valgrind == -1)
00106 running_on_valgrind = local_running_on_valgrind = GetRunningOnValgrind();
00107 return local_running_on_valgrind;
00108 }
00109
00110
00111 double ValgrindSlowdown(void) {
00112
00113 static volatile double slowdown = 0.0;
00114 double local_slowdown = slowdown;
00115 ANNOTATE_BENIGN_RACE(&slowdown, "safe hack");
00116 if (RunningOnValgrind() == 0) {
00117 return 1.0;
00118 }
00119 if (local_slowdown == 0.0) {
00120 char *env = getenv("VALGRIND_SLOWDOWN");
00121 slowdown = local_slowdown = env ? atof(env) : 50.0;
00122 }
00123 return local_slowdown;
00124 }
00125
00126 #ifdef __cplusplus
00127 }
00128 #endif
00129 #endif