[compiler-rt] r179012 - [msan] Intercept glob().

Evgeniy Stepanov eugeni.stepanov at gmail.com
Mon Apr 8 02:03:00 PDT 2013


Author: eugenis
Date: Mon Apr  8 04:03:00 2013
New Revision: 179012

URL: http://llvm.org/viewvc/llvm-project?rev=179012&view=rev
Log:
[msan] Intercept glob().

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/tsan/rtl/tsan_stat.cc
    compiler-rt/trunk/lib/tsan/rtl/tsan_stat.h

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=179012&r1=179011&r2=179012&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc Mon Apr  8 04:03:00 2013
@@ -549,6 +549,53 @@ INTERCEPTOR(int, setitimer, int which, c
 #endif
 
 
+#if SANITIZER_INTERCEPT_GLOB
+struct sanitizer_glob_t {
+  SIZE_T gl_pathc;
+  char **gl_pathv;
+};
+
+static void unpoison_glob_t(void *ctx, sanitizer_glob_t *pglob) {
+  COMMON_INTERCEPTOR_WRITE_RANGE(ctx, pglob, sizeof(*pglob));
+  // +1 for NULL pointer at the end.
+  COMMON_INTERCEPTOR_WRITE_RANGE(
+      ctx, pglob->gl_pathv,
+      (sizeof(pglob->gl_pathc) + 1) * sizeof(*pglob->gl_pathv));
+  for (SIZE_T i = 0; i < pglob->gl_pathc; ++i) {
+    char *p = pglob->gl_pathv[i];
+    COMMON_INTERCEPTOR_WRITE_RANGE(ctx, p, REAL(strlen)(p) + 1);
+  }
+}
+
+INTERCEPTOR(int, glob, const char *pattern, int flags,
+            int (*errfunc)(const char *epath, int eerrno),
+            sanitizer_glob_t *pglob) {
+  void *ctx;
+  COMMON_INTERCEPTOR_ENTER(ctx, glob, pattern, flags, errfunc, pglob);
+  int res = REAL(glob)(pattern, flags, errfunc, pglob);
+  if (res == 0)
+    unpoison_glob_t(ctx, pglob);
+  return res;
+}
+
+INTERCEPTOR(int, glob64, const char *pattern, int flags,
+            int (*errfunc)(const char *epath, int eerrno),
+            sanitizer_glob_t *pglob) {
+  void *ctx;
+  COMMON_INTERCEPTOR_ENTER(ctx, glob64, pattern, flags, errfunc, pglob);
+  int res = REAL(glob64)(pattern, flags, errfunc, pglob);
+  if (res == 0)
+    unpoison_glob_t(ctx, pglob);
+  return res;
+}
+#define INIT_GLOB                               \
+  INTERCEPT_FUNCTION(glob);                     \
+  INTERCEPT_FUNCTION(glob64);
+#else // SANITIZER_INTERCEPT_GLOB
+#define INIT_GLOB
+#endif // SANITIZER_INTERCEPT_GLOB
+
+
 #define SANITIZER_COMMON_INTERCEPTORS_INIT                                     \
   INIT_STRCASECMP;                                                             \
   INIT_STRNCASECMP;                                                            \
@@ -567,4 +614,5 @@ INTERCEPTOR(int, setitimer, int which, c
   INIT_GETPWNAM_R_GETPWUID_R;                                                  \
   INIT_CLOCK_GETTIME;                                                          \
   INIT_GETITIMER;                                                              \
-  INIT_TIME;
+  INIT_TIME;                                                                   \
+  INIT_GLOB;

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=179012&r1=179011&r2=179012&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h Mon Apr  8 04:03:00 2013
@@ -64,3 +64,4 @@
 # define SANITIZER_INTERCEPT_CLOCK_GETTIME SI_LINUX
 # define SANITIZER_INTERCEPT_GETITIMER SI_NOT_WINDOWS
 # define SANITIZER_INTERCEPT_TIME SI_NOT_WINDOWS
+# define SANITIZER_INTERCEPT_GLOB SI_LINUX_NOT_ANDROID

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=179012&r1=179011&r2=179012&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_stat.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_stat.cc Mon Apr  8 04:03:00 2013
@@ -297,6 +297,8 @@ void StatOutput(u64 *stat) {
   name[StatInt_getitimer]                = "  getitimer                       ";
   name[StatInt_setitimer]                = "  setitimer                       ";
   name[StatInt_time]                     = "  time                            ";
+  name[StatInt_glob]                     = "  glob                            ";
+  name[StatInt_glob64]                   = "  glob64                          ";
 
   name[StatAnnotation]                   = "Dynamic annotations               ";
   name[StatAnnotateHappensBefore]        = "  HappensBefore                   ";

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=179012&r1=179011&r2=179012&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_stat.h (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_stat.h Mon Apr  8 04:03:00 2013
@@ -292,6 +292,8 @@ enum StatType {
   StatInt_getitimer,
   StatInt_setitimer,
   StatInt_time,
+  StatInt_glob,
+  StatInt_glob64,
 
   // Dynamic annotations.
   StatAnnotation,





More information about the llvm-commits mailing list