[llvm-commits] [compiler-rt] r163602 - in /compiler-rt/trunk/lib/tsan/rtl: tsan_interceptors.cc tsan_stat.cc tsan_stat.h

Alexander Potapenko glider at google.com
Tue Sep 11 02:26:35 PDT 2012


Author: glider
Date: Tue Sep 11 04:26:35 2012
New Revision: 163602

URL: http://llvm.org/viewvc/llvm-project?rev=163602&view=rev
Log:
Interceptors for lockf and lockf64, minor calloc() fix.

Modified:
    compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc
    compiler-rt/trunk/lib/tsan/rtl/tsan_stat.cc
    compiler-rt/trunk/lib/tsan/rtl/tsan_stat.h

Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc?rev=163602&r1=163601&r2=163602&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc Tue Sep 11 04:26:35 2012
@@ -68,6 +68,12 @@
 const int MAP_FIXED = 0x10;
 typedef long long_t;  // NOLINT
 
+// From /usr/include/unistd.h
+# define F_ULOCK 0      /* Unlock a previously locked region.  */
+# define F_LOCK  1      /* Lock a region for exclusive use.  */
+# define F_TLOCK 2      /* Test and lock a region for exclusive use.  */
+# define F_TEST  3      /* Test a region for other processes locks.  */
+
 typedef void (*sighandler_t)(int sig);
 
 #define errno (*__errno_location())
@@ -353,7 +359,7 @@
   {
     SCOPED_INTERCEPTOR_RAW(calloc, size, n);
     p = user_alloc(thr, pc, n * size);
-    internal_memset(p, 0, n * size);
+    if (p) internal_memset(p, 0, n * size);
   }
   invoke_malloc_hook(p, n * size);
   return p;
@@ -1198,6 +1204,38 @@
   return res;
 }
 
+// |func| is either lockf or lockf64.
+#define LOCKF_BODY(func) \
+  SCOPED_TSAN_INTERCEPTOR(func, fd, cmd, len); \
+  int res = -1; \
+  switch (cmd) { \
+    case F_ULOCK: { \
+      Release(thr, pc, fd2addr(fd)); \
+      res = REAL(func)(fd, cmd, len); \
+      break; \
+    } \
+    case F_LOCK: \
+    case F_TLOCK: { \
+      res = REAL(func)(fd, cmd, len); \
+      if (res != -1) Acquire(thr, pc, fd2addr(fd)); \
+      break; \
+    } \
+    default: { \
+      res = REAL(func)(fd, cmd, len); \
+      break; \
+    } \
+  } \
+  return res; \
+/**/
+
+TSAN_INTERCEPTOR(int, lockf, int fd, int cmd, unsigned len) {
+  LOCKF_BODY(lockf);
+}
+
+TSAN_INTERCEPTOR(int, lockf64, int fd, int cmd, u64 len) {
+  LOCKF_BODY(lockf64);
+}
+
 TSAN_INTERCEPTOR(long_t, send, int fd, void *buf, long_t len, int flags) {
   SCOPED_TSAN_INTERCEPTOR(send, fd, buf, len, flags);
   Release(thr, pc, fd2addr(fd));
@@ -1571,6 +1609,8 @@
   TSAN_INTERCEPT(pwrite64);
   TSAN_INTERCEPT(writev);
   TSAN_INTERCEPT(pwritev64);
+  TSAN_INTERCEPT(lockf);
+  TSAN_INTERCEPT(lockf64);
   TSAN_INTERCEPT(send);
   TSAN_INTERCEPT(sendmsg);
   TSAN_INTERCEPT(recv);

Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_stat.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_stat.cc?rev=163602&r1=163601&r2=163602&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_stat.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_stat.cc Tue Sep 11 04:26:35 2012
@@ -183,6 +183,8 @@
   name[StatInt_pwrite64]                 = "  pwrite64                        ";
   name[StatInt_writev]                   = "  writev                          ";
   name[StatInt_pwritev64]                = "  pwritev64                       ";
+  name[StatInt_lockf]                    = "  lockf                           ";
+  name[StatInt_lockf64]                  = "  lockf64                         ";
   name[StatInt_send]                     = "  send                            ";
   name[StatInt_sendmsg]                  = "  sendmsg                         ";
   name[StatInt_recv]                     = "  recv                            ";

Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_stat.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_stat.h?rev=163602&r1=163601&r2=163602&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_stat.h (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_stat.h Tue Sep 11 04:26:35 2012
@@ -181,6 +181,8 @@
   StatInt_pwrite64,
   StatInt_writev,
   StatInt_pwritev64,
+  StatInt_lockf,
+  StatInt_lockf64,
   StatInt_send,
   StatInt_sendmsg,
   StatInt_recv,





More information about the llvm-commits mailing list