[compiler-rt] r192965 - [sanitizer] Move statfs/fstatfs to common interceptors and add statvfs/fstatvfs.

Evgeniy Stepanov eugeni.stepanov at gmail.com
Fri Oct 18 04:14:16 PDT 2013


Author: eugenis
Date: Fri Oct 18 06:14:16 2013
New Revision: 192965

URL: http://llvm.org/viewvc/llvm-project?rev=192965&view=rev
Log:
[sanitizer] Move statfs/fstatfs to common interceptors and add statvfs/fstatvfs.

Modified:
    compiler-rt/trunk/lib/msan/msan_interceptors.cc
    compiler-rt/trunk/lib/msan/tests/msan_test.cc
    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

Modified: compiler-rt/trunk/lib/msan/msan_interceptors.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/msan_interceptors.cc?rev=192965&r1=192964&r2=192965&view=diff
==============================================================================
--- compiler-rt/trunk/lib/msan/msan_interceptors.cc (original)
+++ compiler-rt/trunk/lib/msan/msan_interceptors.cc Fri Oct 18 06:14:16 2013
@@ -751,38 +751,6 @@ INTERCEPTOR(int, getrlimit64, int resour
   return res;
 }
 
-INTERCEPTOR(int, statfs, const char *s, void *buf) {
-  ENSURE_MSAN_INITED();
-  int res = REAL(statfs)(s, buf);
-  if (!res)
-    __msan_unpoison(buf, __sanitizer::struct_statfs_sz);
-  return res;
-}
-
-INTERCEPTOR(int, fstatfs, int fd, void *buf) {
-  ENSURE_MSAN_INITED();
-  int res = REAL(fstatfs)(fd, buf);
-  if (!res)
-    __msan_unpoison(buf, __sanitizer::struct_statfs_sz);
-  return res;
-}
-
-INTERCEPTOR(int, statfs64, const char *s, void *buf) {
-  ENSURE_MSAN_INITED();
-  int res = REAL(statfs64)(s, buf);
-  if (!res)
-    __msan_unpoison(buf, __sanitizer::struct_statfs64_sz);
-  return res;
-}
-
-INTERCEPTOR(int, fstatfs64, int fd, void *buf) {
-  ENSURE_MSAN_INITED();
-  int res = REAL(fstatfs64)(fd, buf);
-  if (!res)
-    __msan_unpoison(buf, __sanitizer::struct_statfs64_sz);
-  return res;
-}
-
 INTERCEPTOR(int, uname, void *utsname) {
   ENSURE_MSAN_INITED();
   int res = REAL(uname)(utsname);
@@ -1402,10 +1370,6 @@ void InitializeInterceptors() {
   INTERCEPT_FUNCTION(fgets_unlocked);
   INTERCEPT_FUNCTION(getrlimit);
   INTERCEPT_FUNCTION(getrlimit64);
-  INTERCEPT_FUNCTION(statfs);
-  INTERCEPT_FUNCTION(fstatfs);
-  INTERCEPT_FUNCTION(statfs64);
-  INTERCEPT_FUNCTION(fstatfs64);
   INTERCEPT_FUNCTION(uname);
   INTERCEPT_FUNCTION(gethostname);
   INTERCEPT_FUNCTION(epoll_wait);

Modified: compiler-rt/trunk/lib/msan/tests/msan_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/tests/msan_test.cc?rev=192965&r1=192964&r2=192965&view=diff
==============================================================================
--- compiler-rt/trunk/lib/msan/tests/msan_test.cc (original)
+++ compiler-rt/trunk/lib/msan/tests/msan_test.cc Fri Oct 18 06:14:16 2013
@@ -41,6 +41,7 @@
 #include <fcntl.h>
 #include <sys/resource.h>
 #include <sys/ioctl.h>
+#include <sys/statvfs.h>
 #include <sys/sysinfo.h>
 #include <sys/utsname.h>
 #include <sys/mman.h>
@@ -687,12 +688,34 @@ TEST(MemorySanitizer, fstatat) {
 }
 
 TEST(MemorySanitizer, statfs) {
-  struct statfs* st = new struct statfs;
-  int res = statfs("/", st);
+  struct statfs st;
+  int res = statfs("/", &st);
   assert(!res);
-  EXPECT_NOT_POISONED(st->f_type);
-  EXPECT_NOT_POISONED(st->f_bfree);
-  EXPECT_NOT_POISONED(st->f_namelen);
+  EXPECT_NOT_POISONED(st.f_type);
+  EXPECT_NOT_POISONED(st.f_bfree);
+  EXPECT_NOT_POISONED(st.f_namelen);
+}
+
+TEST(MemorySanitizer, statvfs) {
+  struct statvfs st;
+  int res = statvfs("/", &st);
+  assert(!res);
+  EXPECT_NOT_POISONED(st.f_bsize);
+  EXPECT_NOT_POISONED(st.f_blocks);
+  EXPECT_NOT_POISONED(st.f_bfree);
+  EXPECT_NOT_POISONED(st.f_namemax);
+}
+
+TEST(MemorySanitizer, fstatvfs) {
+  struct statvfs st;
+  int fd = open("/", O_RDONLY | O_DIRECTORY);
+  int res = fstatvfs(fd, &st);
+  assert(!res);
+  EXPECT_NOT_POISONED(st.f_bsize);
+  EXPECT_NOT_POISONED(st.f_blocks);
+  EXPECT_NOT_POISONED(st.f_bfree);
+  EXPECT_NOT_POISONED(st.f_namemax);
+  close(fd);
 }
 
 TEST(MemorySanitizer, pipe) {

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=192965&r1=192964&r2=192965&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc Fri Oct 18 06:14:16 2013
@@ -2316,6 +2316,97 @@ INTERCEPTOR(__sanitizer_mntent *, getmnt
 #define INIT_GETMNTENT_R
 #endif
 
+#if SANITIZER_INTERCEPT_STATFS
+INTERCEPTOR(int, statfs, char *path, void *buf) {
+  void *ctx;
+  COMMON_INTERCEPTOR_ENTER(ctx, statfs, path, buf);
+  if (path) COMMON_INTERCEPTOR_READ_RANGE(ctx, path, REAL(strlen)(path) + 1);
+  int res = REAL(statfs)(path, buf);
+  if (!res) COMMON_INTERCEPTOR_WRITE_RANGE(ctx, buf, struct_statfs_sz);
+  return res;
+}
+INTERCEPTOR(int, fstatfs, int fd, void *buf) {
+  void *ctx;
+  COMMON_INTERCEPTOR_ENTER(ctx, fstatfs, fd, buf);
+  int res = REAL(fstatfs)(fd, buf);
+  if (!res) COMMON_INTERCEPTOR_WRITE_RANGE(ctx, buf, struct_statfs_sz);
+  return res;
+}
+#define INIT_STATFS           \
+  INTERCEPT_FUNCTION(statfs); \
+  INTERCEPT_FUNCTION(fstatfs);
+#else
+#define INIT_STATFS
+#endif
+
+#if SANITIZER_INTERCEPT_STATFS64
+INTERCEPTOR(int, statfs64, char *path, void *buf) {
+  void *ctx;
+  COMMON_INTERCEPTOR_ENTER(ctx, statfs64, path, buf);
+  if (path) COMMON_INTERCEPTOR_READ_RANGE(ctx, path, REAL(strlen)(path) + 1);
+  int res = REAL(statfs64)(path, buf);
+  if (!res) COMMON_INTERCEPTOR_WRITE_RANGE(ctx, buf, struct_statfs64_sz);
+  return res;
+}
+INTERCEPTOR(int, fstatfs64, int fd, void *buf) {
+  void *ctx;
+  COMMON_INTERCEPTOR_ENTER(ctx, fstatfs64, fd, buf);
+  int res = REAL(fstatfs64)(fd, buf);
+  if (!res) COMMON_INTERCEPTOR_WRITE_RANGE(ctx, buf, struct_statfs64_sz);
+  return res;
+}
+#define INIT_STATFS64           \
+  INTERCEPT_FUNCTION(statfs64); \
+  INTERCEPT_FUNCTION(fstatfs64);
+#else
+#define INIT_STATFS64
+#endif
+
+#if SANITIZER_INTERCEPT_STATVFS
+INTERCEPTOR(int, statvfs, char *path, void *buf) {
+  void *ctx;
+  COMMON_INTERCEPTOR_ENTER(ctx, statvfs, path, buf);
+  if (path) COMMON_INTERCEPTOR_READ_RANGE(ctx, path, REAL(strlen)(path) + 1);
+  int res = REAL(statvfs)(path, buf);
+  if (!res) COMMON_INTERCEPTOR_WRITE_RANGE(ctx, buf, struct_statvfs_sz);
+  return res;
+}
+INTERCEPTOR(int, fstatvfs, int fd, void *buf) {
+  void *ctx;
+  COMMON_INTERCEPTOR_ENTER(ctx, fstatvfs, fd, buf);
+  int res = REAL(fstatvfs)(fd, buf);
+  if (!res) COMMON_INTERCEPTOR_WRITE_RANGE(ctx, buf, struct_statvfs_sz);
+  return res;
+}
+#define INIT_STATVFS           \
+  INTERCEPT_FUNCTION(statvfs); \
+  INTERCEPT_FUNCTION(fstatvfs);
+#else
+#define INIT_STATVFS
+#endif
+
+#if SANITIZER_INTERCEPT_STATVFS64
+INTERCEPTOR(int, statvfs64, char *path, void *buf) {
+  void *ctx;
+  COMMON_INTERCEPTOR_ENTER(ctx, statvfs64, path, buf);
+  if (path) COMMON_INTERCEPTOR_READ_RANGE(ctx, path, REAL(strlen)(path) + 1);
+  int res = REAL(statvfs64)(path, buf);
+  if (!res) COMMON_INTERCEPTOR_WRITE_RANGE(ctx, buf, struct_statvfs64_sz);
+  return res;
+}
+INTERCEPTOR(int, fstatvfs64, int fd, void *buf) {
+  void *ctx;
+  COMMON_INTERCEPTOR_ENTER(ctx, fstatvfs64, fd, buf);
+  int res = REAL(fstatvfs64)(fd, buf);
+  if (!res) COMMON_INTERCEPTOR_WRITE_RANGE(ctx, buf, struct_statvfs64_sz);
+  return res;
+}
+#define INIT_STATVFS64           \
+  INTERCEPT_FUNCTION(statvfs64); \
+  INTERCEPT_FUNCTION(fstatvfs64);
+#else
+#define INIT_STATVFS64
+#endif
 
 #define SANITIZER_COMMON_INTERCEPTORS_INIT \
   INIT_STRCMP;                             \
@@ -2403,4 +2494,8 @@ INTERCEPTOR(__sanitizer_mntent *, getmnt
   INIT_PTHREAD_COND_BROADCAST;             \
   INIT_GETMNTENT;                          \
   INIT_GETMNTENT_R;                        \
+  INIT_STATFS;                             \
+  INIT_STATFS64;                           \
+  INIT_STATVFS;                            \
+  INIT_STATVFS64;                          \
 /**/

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=192965&r1=192964&r2=192965&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h Fri Oct 18 06:14:16 2013
@@ -128,6 +128,10 @@
 # define SANITIZER_INTERCEPT_BACKTRACE SI_LINUX_NOT_ANDROID
 # define SANITIZER_INTERCEPT_GETMNTENT SI_LINUX
 # define SANITIZER_INTERCEPT_GETMNTENT_R SI_LINUX_NOT_ANDROID
+# define SANITIZER_INTERCEPT_STATFS SI_NOT_WINDOWS
+# define SANITIZER_INTERCEPT_STATFS64 SI_MAC || SI_LINUX_NOT_ANDROID
+# define SANITIZER_INTERCEPT_STATVFS SI_LINUX_NOT_ANDROID
+# define SANITIZER_INTERCEPT_STATVFS64 SI_LINUX_NOT_ANDROID
 
 # define SANITIZER_INTERCEPT__EXIT SI_LINUX
 

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=192965&r1=192964&r2=192965&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 Fri Oct 18 06:14:16 2013
@@ -78,6 +78,7 @@
 #include <sys/mtio.h>
 #include <sys/kd.h>
 #include <sys/shm.h>
+#include <sys/statvfs.h>
 #include <sys/timex.h>
 #include <sys/user.h>
 #include <sys/ustat.h>
@@ -164,6 +165,8 @@ namespace __sanitizer {
   unsigned struct_msqid_ds_sz = sizeof(struct msqid_ds);
   unsigned struct_shmid_ds_sz = sizeof(struct shmid_ds);
   unsigned struct_mq_attr_sz = sizeof(struct mq_attr);
+  unsigned struct_statvfs_sz = sizeof(struct statvfs);
+  unsigned struct_statvfs64_sz = sizeof(struct statvfs64);
 #endif // SANITIZER_LINUX && !SANITIZER_ANDROID
 
   uptr sig_ign = (uptr)SIG_IGN;

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=192965&r1=192964&r2=192965&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 Fri Oct 18 06:14:16 2013
@@ -38,6 +38,8 @@ namespace __sanitizer {
   extern unsigned struct_itimerspec_sz;
   extern unsigned struct_sigevent_sz;
   extern unsigned struct_sched_param_sz;
+  extern unsigned struct_statvfs_sz;
+  extern unsigned struct_statvfs64_sz;
 
 #if !SANITIZER_ANDROID
   extern unsigned ucontext_t_sz;

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=192965&r1=192964&r2=192965&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_stat.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_stat.cc Fri Oct 18 06:14:16 2013
@@ -376,6 +376,14 @@ void StatOutput(u64 *stat) {
   name[StatInt_dlclose]                  = "  dlclose                         ";
   name[StatInt_getmntent]                = "  getmntent                       ";
   name[StatInt_getmntent_r]              = "  getmntent_r                     ";
+  name[StatInt_statfs]                   = "  statfs                          ";
+  name[StatInt_statfs64]                 = "  statfs64                        ";
+  name[StatInt_fstatfs]                  = "  fstatfs                         ";
+  name[StatInt_fstatfs64]                = "  fstatfs64                       ";
+  name[StatInt_statvfs]                  = "  statvfs                         ";
+  name[StatInt_statvfs64]                = "  statvfs64                       ";
+  name[StatInt_fstatvfs]                 = "  fstatvfs                        ";
+  name[StatInt_fstatvfs64]               = "  fstatvfs64                      ";
 
   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=192965&r1=192964&r2=192965&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_stat.h (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_stat.h Fri Oct 18 06:14:16 2013
@@ -371,6 +371,14 @@ enum StatType {
   StatInt_dlclose,
   StatInt_getmntent,
   StatInt_getmntent_r,
+  StatInt_statfs,
+  StatInt_statfs64,
+  StatInt_fstatfs,
+  StatInt_fstatfs64,
+  StatInt_statvfs,
+  StatInt_statvfs64,
+  StatInt_fstatvfs,
+  StatInt_fstatvfs64,
 
   // Dynamic annotations.
   StatAnnotation,





More information about the llvm-commits mailing list