[compiler-rt] r195918 - [sanitizer] Intercept times.

Evgeniy Stepanov eugeni.stepanov at gmail.com
Thu Nov 28 06:41:22 PST 2013


Author: eugenis
Date: Thu Nov 28 08:41:22 2013
New Revision: 195918

URL: http://llvm.org/viewvc/llvm-project?rev=195918&view=rev
Log:
[sanitizer] Intercept times.

Added:
    compiler-rt/trunk/lib/msan/lit_tests/times.cc   (with props)
Modified:
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_posix.cc
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_posix.h
    compiler-rt/trunk/lib/tsan/rtl/tsan_stat.cc
    compiler-rt/trunk/lib/tsan/rtl/tsan_stat.h

Added: compiler-rt/trunk/lib/msan/lit_tests/times.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/lit_tests/times.cc?rev=195918&view=auto
==============================================================================
--- compiler-rt/trunk/lib/msan/lit_tests/times.cc (added)
+++ compiler-rt/trunk/lib/msan/lit_tests/times.cc Thu Nov 28 08:41:22 2013
@@ -0,0 +1,20 @@
+// RUN: %clangxx_msan -m64 -O0 -g %s -o %t && %t
+
+#include <assert.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <sys/times.h>
+
+
+int main(void) {
+  struct tms t;
+  clock_t res = times(&t);
+  assert(res != (clock_t)-1);
+
+  if (t.tms_utime) printf("1\n");
+  if (t.tms_stime) printf("2\n");
+  if (t.tms_cutime) printf("3\n");
+  if (t.tms_cstime) printf("4\n");
+
+  return 0;
+}

Propchange: compiler-rt/trunk/lib/msan/lit_tests/times.cc
------------------------------------------------------------------------------
    svn:eol-style = LF

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc?rev=195918&r1=195917&r2=195918&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc Thu Nov 28 08:41:22 2013
@@ -2878,6 +2878,20 @@ INTERCEPTOR(SIZE_T, iconv, void *cd, cha
 #define INIT_ICONV
 #endif
 
+#if SANITIZER_INTERCEPT_TIMES
+INTERCEPTOR(__sanitizer_clock_t, times, void *tms) {
+  void *ctx;
+  COMMON_INTERCEPTOR_ENTER(ctx, times, tms);
+  __sanitizer_clock_t res = REAL(times)(tms);
+  if (res != (__sanitizer_clock_t)-1 && tms)
+    COMMON_INTERCEPTOR_WRITE_RANGE(ctx, tms, struct_tms_sz);
+  return res;
+}
+#define INIT_TIMES COMMON_INTERCEPT_FUNCTION(times);
+#else
+#define INIT_TIMES
+#endif
+
 #define SANITIZER_COMMON_INTERCEPTORS_INIT \
   INIT_STRCMP;                             \
   INIT_STRNCMP;                            \
@@ -2989,4 +3003,5 @@ INTERCEPTOR(SIZE_T, iconv, void *cd, cha
   INIT_DRAND48_R;                          \
   INIT_GETLINE;                            \
   INIT_ICONV;                              \
+  INIT_TIMES;                              \
 /**/

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h?rev=195918&r1=195917&r2=195918&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h Thu Nov 28 08:41:22 2013
@@ -159,6 +159,7 @@
 # define SANITIZER_INTERCEPT_LGAMMA_R SI_LINUX
 # define SANITIZER_INTERCEPT_DRAND48_R SI_LINUX_NOT_ANDROID
 # define SANITIZER_INTERCEPT_ICONV SI_MAC || SI_LINUX_NOT_ANDROID
+# define SANITIZER_INTERCEPT_TIMES SI_NOT_WINDOWS
 
 // FIXME: getline seems to be available on OSX 10.7
 # define SANITIZER_INTERCEPT_GETLINE SI_LINUX_NOT_ANDROID

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_posix.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_posix.cc?rev=195918&r1=195917&r2=195918&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_posix.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_posix.cc Thu Nov 28 08:41:22 2013
@@ -939,4 +939,6 @@ CHECK_SIZE_AND_OFFSET(shmid_ds, shm_lpid
 CHECK_SIZE_AND_OFFSET(shmid_ds, shm_nattch);
 #endif
 
+CHECK_TYPE_SIZE(clock_t);
+
 #endif  // SANITIZER_LINUX || SANITIZER_MAC

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_posix.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_posix.h?rev=195918&r1=195917&r2=195918&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_posix.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_posix.h Thu Nov 28 08:41:22 2013
@@ -287,6 +287,8 @@ namespace __sanitizer {
   };
 #endif
 
+  typedef long __sanitizer_clock_t;
+
 #if SANITIZER_LINUX
 #if defined(_LP64) || defined(__x86_64__)
   typedef unsigned __sanitizer___kernel_uid_t;

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=195918&r1=195917&r2=195918&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_stat.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_stat.cc Thu Nov 28 08:41:22 2013
@@ -417,6 +417,7 @@ void StatOutput(u64 *stat) {
   name[StatInt_getline]                  = "  getline                         ";
   name[StatInt_getdelim]                 = "  getdelim                        ";
   name[StatInt_iconv]                    = "  iconv                           ";
+  name[StatInt_times]                    = "  times                           ";
 
   name[StatInt_pthread_attr_getdetachstate]  = "  pthread_addr_getdetachstate     ";  // NOLINT
   name[StatInt_pthread_attr_getguardsize]    = "  pthread_addr_getguardsize       ";  // NOLINT

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=195918&r1=195917&r2=195918&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_stat.h (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_stat.h Thu Nov 28 08:41:22 2013
@@ -412,6 +412,7 @@ enum StatType {
   StatInt_getline,
   StatInt_getdelim,
   StatInt_iconv,
+  StatInt_times,
 
   StatInt_pthread_attr_getdetachstate,
   StatInt_pthread_attr_getguardsize,





More information about the llvm-commits mailing list