diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2013-03-25 09:56:45 +0000 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2013-03-25 09:56:45 +0000 |
| commit | 510ad118001e5e04200cba12310fb20a83f1573a (patch) | |
| tree | dac7047a5068da3ba53c4ed1222c0b701473ac11 /compiler-rt/lib | |
| parent | 9c383d68cff64209e3a226148eb5f83ccc55f897 (diff) | |
| download | bcm5719-llvm-510ad118001e5e04200cba12310fb20a83f1573a.tar.gz bcm5719-llvm-510ad118001e5e04200cba12310fb20a83f1573a.zip | |
tsan: add SetEnv() function that can be used in frontends
llvm-svn: 177857
Diffstat (limited to 'compiler-rt/lib')
| -rw-r--r-- | compiler-rt/lib/sanitizer_common/sanitizer_common.h | 1 | ||||
| -rw-r--r-- | compiler-rt/lib/sanitizer_common/sanitizer_linux.cc | 14 |
2 files changed, 15 insertions, 0 deletions
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common.h b/compiler-rt/lib/sanitizer_common/sanitizer_common.h index 53a43b4050c..cd7e2ffdaf2 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_common.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_common.h @@ -127,6 +127,7 @@ void DisableCoreDumper(); void DumpProcessMap(); bool FileExists(const char *filename); const char *GetEnv(const char *name); +bool SetEnv(const char *name, const char *value); const char *GetPwd(); u32 GetUid(); void ReExec(); diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_linux.cc b/compiler-rt/lib/sanitizer_common/sanitizer_linux.cc index 5f490145c0c..901d76bddc0 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_linux.cc +++ b/compiler-rt/lib/sanitizer_common/sanitizer_linux.cc @@ -264,6 +264,20 @@ const char *GetEnv(const char *name) { return 0; // Not found. } +// Does not compile for Go because dlsym() requires -ldl +#ifndef SANITIZER_GO +bool SetEnv(const char *name, const char *value) { + void *f = dlsym(RTLD_NEXT, "setenv"); + if (f == 0) + return false; + typedef int(*setenv_ft)(const char *name, const char *value, int overwrite); + setenv_ft setenv_f; + CHECK_EQ(sizeof(setenv_f), sizeof(f)); + internal_memcpy(&setenv_f, &f, sizeof(f)); + return setenv_f(name, value, 1) == 0; +} +#endif + #ifdef __GLIBC__ extern "C" { |

