diff options
author | Evgeniy Stepanov <eugeni.stepanov@gmail.com> | 2013-10-18 11:14:16 +0000 |
---|---|---|
committer | Evgeniy Stepanov <eugeni.stepanov@gmail.com> | 2013-10-18 11:14:16 +0000 |
commit | 5cee73e486aaa617a9627bb69a6447d3369b62cc (patch) | |
tree | 5c8c1975418d3a9c0c7bf87a1eb3d4527cce7251 | |
parent | 00dc24362d11540c39d57d27de846ce5823110cd (diff) | |
download | compiler-rt-5cee73e486aaa617a9627bb69a6447d3369b62cc.tar.gz compiler-rt-5cee73e486aaa617a9627bb69a6447d3369b62cc.tar.bz2 compiler-rt-5cee73e486aaa617a9627bb69a6447d3369b62cc.tar.xz |
[sanitizer] Move statfs/fstatfs to common interceptors and add statvfs/fstatvfs.
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@192965 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/msan/msan_interceptors.cc | 36 | ||||
-rw-r--r-- | lib/msan/tests/msan_test.cc | 33 | ||||
-rw-r--r-- | lib/sanitizer_common/sanitizer_common_interceptors.inc | 95 | ||||
-rw-r--r-- | lib/sanitizer_common/sanitizer_platform_interceptors.h | 4 | ||||
-rw-r--r-- | lib/sanitizer_common/sanitizer_platform_limits_posix.cc | 3 | ||||
-rw-r--r-- | lib/sanitizer_common/sanitizer_platform_limits_posix.h | 2 | ||||
-rw-r--r-- | lib/tsan/rtl/tsan_stat.cc | 8 | ||||
-rw-r--r-- | lib/tsan/rtl/tsan_stat.h | 8 |
8 files changed, 148 insertions, 41 deletions
diff --git a/lib/msan/msan_interceptors.cc b/lib/msan/msan_interceptors.cc index 700d7cfe..46f5dd2a 100644 --- a/lib/msan/msan_interceptors.cc +++ b/lib/msan/msan_interceptors.cc @@ -751,38 +751,6 @@ INTERCEPTOR(int, getrlimit64, int resource, void *rlim) { 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); diff --git a/lib/msan/tests/msan_test.cc b/lib/msan/tests/msan_test.cc index 73114aeb..0d3fd2a5 100644 --- a/lib/msan/tests/msan_test.cc +++ b/lib/msan/tests/msan_test.cc @@ -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) { diff --git a/lib/sanitizer_common/sanitizer_common_interceptors.inc b/lib/sanitizer_common/sanitizer_common_interceptors.inc index b34756d0..db7db33e 100644 --- a/lib/sanitizer_common/sanitizer_common_interceptors.inc +++ b/lib/sanitizer_common/sanitizer_common_interceptors.inc @@ -2316,6 +2316,97 @@ INTERCEPTOR(__sanitizer_mntent *, getmntent_r, void *fp, #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 *, getmntent_r, void *fp, INIT_PTHREAD_COND_BROADCAST; \ INIT_GETMNTENT; \ INIT_GETMNTENT_R; \ + INIT_STATFS; \ + INIT_STATFS64; \ + INIT_STATVFS; \ + INIT_STATVFS64; \ /**/ diff --git a/lib/sanitizer_common/sanitizer_platform_interceptors.h b/lib/sanitizer_common/sanitizer_platform_interceptors.h index e2ae57b4..312b073b 100644 --- a/lib/sanitizer_common/sanitizer_platform_interceptors.h +++ b/lib/sanitizer_common/sanitizer_platform_interceptors.h @@ -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 diff --git a/lib/sanitizer_common/sanitizer_platform_limits_posix.cc b/lib/sanitizer_common/sanitizer_platform_limits_posix.cc index cf1c7cd3..010a1a4f 100644 --- a/lib/sanitizer_common/sanitizer_platform_limits_posix.cc +++ b/lib/sanitizer_common/sanitizer_platform_limits_posix.cc @@ -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; diff --git a/lib/sanitizer_common/sanitizer_platform_limits_posix.h b/lib/sanitizer_common/sanitizer_platform_limits_posix.h index 4c51380e..640002fc 100644 --- a/lib/sanitizer_common/sanitizer_platform_limits_posix.h +++ b/lib/sanitizer_common/sanitizer_platform_limits_posix.h @@ -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; diff --git a/lib/tsan/rtl/tsan_stat.cc b/lib/tsan/rtl/tsan_stat.cc index 922a5f44..bc1ce9d0 100644 --- a/lib/tsan/rtl/tsan_stat.cc +++ b/lib/tsan/rtl/tsan_stat.cc @@ -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 "; diff --git a/lib/tsan/rtl/tsan_stat.h b/lib/tsan/rtl/tsan_stat.h index c98ad6bc..a3deef85 100644 --- a/lib/tsan/rtl/tsan_stat.h +++ b/lib/tsan/rtl/tsan_stat.h @@ -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, |