[llvm-commits] [compiler-rt] r158655 - in /compiler-rt/trunk/lib: sanitizer_common/sanitizer_common.h sanitizer_common/sanitizer_libc.h sanitizer_common/sanitizer_linux.cc sanitizer_common/sanitizer_mac.cc sanitizer_common/sanitizer_posix.cc sanitizer_common/sanitizer_win.cc tsan/rtl/tsan_mutex.cc tsan/rtl/tsan_platform.h tsan/rtl/tsan_platform_linux.cc tsan/rtl/tsan_rtl.cc tsan/rtl/tsan_suppressions.cc

Alexey Samsonov samsonov at google.com
Mon Jun 18 01:44:30 PDT 2012


Author: samsonov
Date: Mon Jun 18 03:44:30 2012
New Revision: 158655

URL: http://llvm.org/viewvc/llvm-project?rev=158655&view=rev
Log:
[Sanitizer] move different wrappers from TSan to common sanitizer runtime

Modified:
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_libc.h
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_posix.cc
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_win.cc
    compiler-rt/trunk/lib/tsan/rtl/tsan_mutex.cc
    compiler-rt/trunk/lib/tsan/rtl/tsan_platform.h
    compiler-rt/trunk/lib/tsan/rtl/tsan_platform_linux.cc
    compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.cc
    compiler-rt/trunk/lib/tsan/rtl/tsan_suppressions.cc

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h?rev=158655&r1=158654&r2=158655&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h Mon Jun 18 03:44:30 2012
@@ -62,11 +62,13 @@
 uptr ReadFileToBuffer(const char *file_name, char **buff,
                       uptr *buff_size, uptr max_len);
 const char *GetEnv(const char *name);
+const char *GetPwd();
 
 // Other
 void DisableCoreDumper();
 void DumpProcessMap();
 void SleepForSeconds(int seconds);
+void SleepForMillis(int millis);
 void NORETURN Exit(int exitcode);
 void NORETURN Abort();
 int Atexit(void (*function)(void));

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_libc.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_libc.h?rev=158655&r1=158654&r2=158655&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_libc.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_libc.h Mon Jun 18 03:44:30 2012
@@ -57,6 +57,9 @@
 int internal_dup2(int oldfd, int newfd);
 int internal_sscanf(const char *str, const char *format, ...);
 
+// Threading
+int internal_sched_yield();
+
 }  // namespace __sanitizer
 
 #endif  // SANITIZER_LIBC_H

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc?rev=158655&r1=158654&r2=158655&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc Mon Jun 18 03:44:30 2012
@@ -20,6 +20,7 @@
 
 #include <fcntl.h>
 #include <pthread.h>
+#include <sched.h>
 #include <sys/mman.h>
 #include <sys/resource.h>
 #include <sys/stat.h>
@@ -72,6 +73,10 @@
   return syscall(__NR_dup2, oldfd, newfd);
 }
 
+int internal_sched_yield() {
+  return syscall(__NR_sched_yield);
+}
+
 // ----------------- sanitizer_common.h
 void GetThreadStackTopAndBottom(bool at_initialization, uptr *stack_top,
                                 uptr *stack_bottom) {

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc?rev=158655&r1=158654&r2=158655&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc Mon Jun 18 03:44:30 2012
@@ -24,6 +24,7 @@
 #include <mach-o/dyld.h>
 #include <mach-o/loader.h>
 #include <pthread.h>
+#include <sched.h>
 #include <sys/mman.h>
 #include <sys/resource.h>
 #include <sys/stat.h>
@@ -70,6 +71,10 @@
   return dup2(oldfd, newfd);
 }
 
+int internal_sched_yield() {
+  return sched_yield();
+}
+
 // ----------------- sanitizer_common.h
 void GetThreadStackTopAndBottom(bool at_initialization, uptr *stack_top,
                                 uptr *stack_bottom) {

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_posix.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_posix.cc?rev=158655&r1=158654&r2=158655&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_posix.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_posix.cc Mon Jun 18 03:44:30 2012
@@ -116,6 +116,10 @@
   UnmapOrDie(filename, kBufSize);
 }
 
+const char *GetPwd() {
+  return GetEnv("PWD");
+}
+
 void DisableCoreDumper() {
   struct rlimit nocore;
   nocore.rlim_cur = 0;
@@ -127,6 +131,10 @@
   sleep(seconds);
 }
 
+void SleepForMillis(int millis) {
+  usleep(millis * 1000);
+}
+
 void Exit(int exitcode) {
   _exit(exitcode);
 }

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_win.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_win.cc?rev=158655&r1=158654&r2=158655&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_win.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_win.cc Mon Jun 18 03:44:30 2012
@@ -91,6 +91,10 @@
   return 0;
 }
 
+const char *GetPwd() {
+  UNIMPLEMENTED();
+}
+
 void DumpProcessMap() {
   UNIMPLEMENTED();
 }
@@ -103,6 +107,10 @@
   Sleep(seconds * 1000);
 }
 
+void SleepForMillis(int millis) {
+  Sleep(millis);
+}
+
 void Exit(int exitcode) {
   _exit(exitcode);
 }
@@ -182,6 +190,10 @@
   UNIMPLEMENTED();
 }
 
+int internal_sched_yield() {
+  UNIMPLEMENTED();
+}
+
 int internal_sscanf(const char *str, const char *format, ...) {
   UNIMPLEMENTED();
 }

Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_mutex.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_mutex.cc?rev=158655&r1=158654&r2=158655&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_mutex.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_mutex.cc Mon Jun 18 03:44:30 2012
@@ -10,6 +10,7 @@
 // This file is a part of ThreadSanitizer (TSan), a race detector.
 //
 //===----------------------------------------------------------------------===//
+#include "sanitizer_common/sanitizer_libc.h"
 #include "tsan_mutex.h"
 #include "tsan_platform.h"
 #include "tsan_rtl.h"
@@ -164,7 +165,7 @@
     if (iter_++ < kActiveSpinIters)
       proc_yield(kActiveSpinCnt);
     else
-      internal_yield();
+      internal_sched_yield();
     return true;
   }
 

Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_platform.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_platform.h?rev=158655&r1=158654&r2=158655&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_platform.h (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_platform.h Mon Jun 18 03:44:30 2012
@@ -80,13 +80,8 @@
 const char *InitializePlatform();
 void FinalizePlatform();
 
-void internal_yield();
-void internal_sleep_ms(u32 ms);
-
 void internal_start_thread(void(*func)(void*), void *arg);
 
-const char *internal_getpwd();
-
 uptr GetTlsSize();
 void GetThreadStackAndTls(bool main, uptr *stk_addr, uptr *stk_size,
                           uptr *tls_addr, uptr *tls_size);

Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_platform_linux.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_platform_linux.cc?rev=158655&r1=158654&r2=158655&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_platform_linux.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_platform_linux.cc Mon Jun 18 03:44:30 2012
@@ -74,19 +74,6 @@
           MADV_DONTNEED);
 }
 
-void internal_yield() {
-  ScopedInRtl in_rtl;
-  syscall(__NR_sched_yield);
-}
-
-void internal_sleep_ms(u32 ms) {
-  usleep(ms * 1000);
-}
-
-const char *internal_getpwd() {
-  return getenv("PWD");
-}
-
 static void ProtectRange(uptr beg, uptr end) {
   ScopedInRtl in_rtl;
   CHECK_LE(beg, end);

Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.cc?rev=158655&r1=158654&r2=158655&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.cc Mon Jun 18 03:44:30 2012
@@ -12,6 +12,7 @@
 // Main file (entry points) for the TSan run-time.
 //===----------------------------------------------------------------------===//
 
+#include "sanitizer_common/sanitizer_common.h"
 #include "sanitizer_common/sanitizer_libc.h"
 #include "sanitizer_common/sanitizer_placement_new.h"
 #include "tsan_defs.h"
@@ -120,7 +121,7 @@
     InternalScopedBuf<char> buf(4096);
     WriteMemoryProfile(buf.Ptr(), buf.Size(), i);
     internal_write(fd, buf.Ptr(), internal_strlen(buf.Ptr()));
-    internal_sleep_ms(1000);
+    SleepForSeconds(1);
   }
 }
 
@@ -141,7 +142,7 @@
 static void MemoryFlushThread(void *arg) {
   ScopedInRtl in_rtl;
   for (int i = 0; ; i++) {
-    internal_sleep_ms(flags()->flush_memory_ms);
+    SleepForMillis(flags()->flush_memory_ms);
     FlushShadowMemory();
   }
 }

Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_suppressions.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_suppressions.cc?rev=158655&r1=158654&r2=158655&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_suppressions.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_suppressions.cc Mon Jun 18 03:44:30 2012
@@ -11,6 +11,7 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "sanitizer_common/sanitizer_common.h"
 #include "sanitizer_common/sanitizer_libc.h"
 #include "tsan_suppressions.h"
 #include "tsan_rtl.h"
@@ -29,7 +30,7 @@
   if (filename[0] == '/')
     SNPrintf(tmp, tmp.Size(), "%s", filename);
   else
-    SNPrintf(tmp, tmp.Size(), "%s/%s", internal_getpwd(), filename);
+    SNPrintf(tmp, tmp.Size(), "%s/%s", GetPwd(), filename);
   fd_t fd = internal_open(tmp, false);
   if (fd == kInvalidFd) {
     TsanPrintf("ThreadSanitizer: failed to open suppressions file '%s'\n",





More information about the llvm-commits mailing list