[compiler-rt] r184950 - [sanitizer] readdir and readdir_r interceptors.
Evgeniy Stepanov
eugeni.stepanov at gmail.com
Wed Jun 26 08:00:53 PDT 2013
Author: eugenis
Date: Wed Jun 26 10:00:53 2013
New Revision: 184950
URL: http://llvm.org/viewvc/llvm-project?rev=184950&view=rev
Log:
[sanitizer] readdir and readdir_r interceptors.
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=184950&r1=184949&r2=184950&view=diff
==============================================================================
--- compiler-rt/trunk/lib/msan/msan_interceptors.cc (original)
+++ compiler-rt/trunk/lib/msan/msan_interceptors.cc Wed Jun 26 10:00:53 2013
@@ -101,20 +101,6 @@ INTERCEPTOR(SSIZE_T, readlink, const cha
return res;
}
-INTERCEPTOR(void *, readdir, void *a) {
- ENSURE_MSAN_INITED();
- void *res = REAL(readdir)(a);
- __msan_unpoison(res, __sanitizer::struct_dirent_sz);
- return res;
-}
-
-INTERCEPTOR(void *, readdir64, void *a) {
- ENSURE_MSAN_INITED();
- void *res = REAL(readdir)(a);
- __msan_unpoison(res, __sanitizer::struct_dirent64_sz);
- return res;
-}
-
INTERCEPTOR(void *, memcpy, void *dest, const void *src, SIZE_T n) {
return __msan_memcpy(dest, src, n);
}
@@ -1138,8 +1124,6 @@ void InitializeInterceptors() {
INTERCEPT_FUNCTION(fread);
INTERCEPT_FUNCTION(fread_unlocked);
INTERCEPT_FUNCTION(readlink);
- INTERCEPT_FUNCTION(readdir);
- INTERCEPT_FUNCTION(readdir64);
INTERCEPT_FUNCTION(memcpy);
INTERCEPT_FUNCTION(memset);
INTERCEPT_FUNCTION(memmove);
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=184950&r1=184949&r2=184950&view=diff
==============================================================================
--- compiler-rt/trunk/lib/msan/tests/msan_test.cc (original)
+++ compiler-rt/trunk/lib/msan/tests/msan_test.cc Wed Jun 26 10:00:53 2013
@@ -889,6 +889,17 @@ TEST(MemorySanitizer, readdir) {
closedir(dir);
}
+TEST(MemorySanitizer, readdir_r) {
+ DIR *dir = opendir(".");
+ struct dirent d;
+ struct dirent *pd;
+ int res = readdir_r(dir, &d, &pd);
+ assert(!res);
+ EXPECT_NOT_POISONED(pd);
+ EXPECT_NOT_POISONED(d.d_name[0]);
+ closedir(dir);
+}
+
TEST(MemorySanitizer, realpath) {
const char* relpath = ".";
char path[PATH_MAX + 1];
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=184950&r1=184949&r2=184950&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc Wed Jun 26 10:00:53 2013
@@ -1268,6 +1268,66 @@ INTERCEPTOR(int, sysinfo, void *info) {
#define INIT_SYSINFO
#endif
+#if SANITIZER_INTERCEPT_READDIR
+INTERCEPTOR(void *, readdir, void *dirp) {
+ void *ctx;
+ COMMON_INTERCEPTOR_ENTER(ctx, readdir, dirp);
+ void *res = REAL(readdir)(dirp);
+ if (res)
+ COMMON_INTERCEPTOR_WRITE_RANGE(ctx, res, struct_dirent_sz);
+ return res;
+}
+
+INTERCEPTOR(int, readdir_r, void *dirp, void *entry, void **result) {
+ void *ctx;
+ COMMON_INTERCEPTOR_ENTER(ctx, readdir_r, dirp, entry, result);
+ int res = REAL(readdir_r)(dirp, entry, result);
+ if (!res) {
+ if (result)
+ COMMON_INTERCEPTOR_WRITE_RANGE(ctx, result, sizeof(*result));
+ if (entry)
+ COMMON_INTERCEPTOR_WRITE_RANGE(ctx, entry, struct_dirent_sz);
+ }
+ return res;
+}
+
+#define INIT_READDIR \
+ INTERCEPT_FUNCTION(readdir); \
+ INTERCEPT_FUNCTION(readdir_r);
+#else
+#define INIT_READDIR
+#endif
+
+#if SANITIZER_INTERCEPT_READDIR64
+INTERCEPTOR(void *, readdir64, void *dirp) {
+ void *ctx;
+ COMMON_INTERCEPTOR_ENTER(ctx, readdir64, dirp);
+ void *res = REAL(readdir64)(dirp);
+ if (res)
+ COMMON_INTERCEPTOR_WRITE_RANGE(ctx, res, struct_dirent64_sz);
+ return res;
+}
+
+INTERCEPTOR(int, readdir64_r, void *dirp, void *entry, void **result) {
+ void *ctx;
+ COMMON_INTERCEPTOR_ENTER(ctx, readdir64_r, dirp, entry, result);
+ int res = REAL(readdir64_r)(dirp, entry, result);
+ if (!res) {
+ if (result)
+ COMMON_INTERCEPTOR_WRITE_RANGE(ctx, result, sizeof(*result));
+ if (entry)
+ COMMON_INTERCEPTOR_WRITE_RANGE(ctx, entry, struct_dirent64_sz);
+ }
+ return res;
+}
+#define INIT_READDIR64 \
+ INTERCEPT_FUNCTION(readdir64); \
+ INTERCEPT_FUNCTION(readdir64_r);
+#else
+#define INIT_READDIR64
+#endif
+
+
#define SANITIZER_COMMON_INTERCEPTORS_INIT \
INIT_STRCASECMP; \
INIT_STRNCASECMP; \
@@ -1309,4 +1369,6 @@ INTERCEPTOR(int, sysinfo, void *info) {
INIT_GETPEERNAME; \
INIT_IOCTL; \
INIT_INET_ATON; \
- INIT_SYSINFO;
+ INIT_SYSINFO; \
+ INIT_READDIR; \
+ INIT_READDIR64;
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=184950&r1=184949&r2=184950&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h Wed Jun 26 10:00:53 2013
@@ -92,5 +92,7 @@
# define SANITIZER_INTERCEPT_IOCTL SI_NOT_WINDOWS
# define SANITIZER_INTERCEPT_INET_ATON SI_NOT_WINDOWS
# define SANITIZER_INTERCEPT_SYSINFO SI_LINUX
+# define SANITIZER_INTERCEPT_READDIR SI_NOT_WINDOWS
+# define SANITIZER_INTERCEPT_READDIR64 SI_LINUX_NOT_ANDROID
#endif // #ifndef SANITIZER_PLATFORM_INTERCEPTORS_H
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=184950&r1=184949&r2=184950&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 Wed Jun 26 10:00:53 2013
@@ -94,6 +94,7 @@
#endif
namespace __sanitizer {
+ unsigned struct_dirent_sz = sizeof(struct dirent);
unsigned struct_utsname_sz = sizeof(struct utsname);
unsigned struct_stat_sz = sizeof(struct stat);
unsigned struct_stat64_sz = sizeof(struct stat64);
@@ -115,7 +116,6 @@ namespace __sanitizer {
#if SANITIZER_LINUX
unsigned struct_rlimit_sz = sizeof(struct rlimit);
- unsigned struct_dirent_sz = sizeof(struct dirent);
unsigned struct_statfs_sz = sizeof(struct statfs);
unsigned struct_epoll_event_sz = sizeof(struct epoll_event);
unsigned struct_sysinfo_sz = sizeof(struct sysinfo);
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=184950&r1=184949&r2=184950&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 Wed Jun 26 10:00:53 2013
@@ -18,6 +18,7 @@
#include "sanitizer_platform.h"
namespace __sanitizer {
+ extern unsigned struct_dirent_sz;
extern unsigned struct_utsname_sz;
extern unsigned struct_stat_sz;
extern unsigned struct_stat64_sz;
@@ -39,7 +40,6 @@ namespace __sanitizer {
#if SANITIZER_LINUX
extern unsigned struct_rlimit_sz;
- extern unsigned struct_dirent_sz;
extern unsigned struct_statfs_sz;
extern unsigned struct_epoll_event_sz;
extern unsigned struct_sysinfo_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=184950&r1=184949&r2=184950&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_stat.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_stat.cc Wed Jun 26 10:00:53 2013
@@ -331,6 +331,10 @@ void StatOutput(u64 *stat) {
name[StatInt_getpeername] = " getpeername ";
name[StatInt_ioctl] = " ioctl ";
name[StatInt_sysinfo] = " sysinfo ";
+ name[StatInt_readdir] = " readdir ";
+ name[StatInt_readdir64] = " readdir64 ";
+ name[StatInt_readdir_r] = " readdir_r ";
+ name[StatInt_readdir64_r] = " readdir64_r ";
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=184950&r1=184949&r2=184950&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_stat.h (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_stat.h Wed Jun 26 10:00:53 2013
@@ -326,6 +326,10 @@ enum StatType {
StatInt_getpeername,
StatInt_ioctl,
StatInt_sysinfo,
+ StatInt_readdir,
+ StatInt_readdir64,
+ StatInt_readdir_r,
+ StatInt_readdir64_r,
// Dynamic annotations.
StatAnnotation,
More information about the llvm-commits
mailing list