[compiler-rt] r184739 - [sanitizer] Intercept sysinfo.

Evgeniy Stepanov eugeni.stepanov at gmail.com
Mon Jun 24 07:25:33 PDT 2013


Author: eugenis
Date: Mon Jun 24 09:25:33 2013
New Revision: 184739

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

Modified:
    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/tests/msan_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/tests/msan_test.cc?rev=184739&r1=184738&r2=184739&view=diff
==============================================================================
--- compiler-rt/trunk/lib/msan/tests/msan_test.cc (original)
+++ compiler-rt/trunk/lib/msan/tests/msan_test.cc Mon Jun 24 09:25:33 2013
@@ -38,6 +38,7 @@
 #include <fcntl.h>
 #include <sys/resource.h>
 #include <sys/ioctl.h>
+#include <sys/sysinfo.h>
 #include <sys/utsname.h>
 #include <sys/mman.h>
 #include <sys/vfs.h>
@@ -1977,6 +1978,13 @@ TEST(MemorySanitizer, gethostname) {
   EXPECT_NOT_POISONED(strlen(buf));
 }
 
+TEST(MemorySanitizer, sysinfo) {
+  struct sysinfo info;
+  int res = sysinfo(&info);
+  assert(!res);
+  EXPECT_NOT_POISONED(info);
+}
+
 TEST(MemorySanitizer, getpwuid) {
   struct passwd *p = getpwuid(0); // root
   assert(p);

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=184739&r1=184738&r2=184739&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc Mon Jun 24 09:25:33 2013
@@ -1253,6 +1253,20 @@ INTERCEPTOR(int, getpeername, int sockfd
 #define INIT_GETPEERNAME
 #endif
 
+#if SANITIZER_INTERCEPT_SYSINFO
+INTERCEPTOR(int, sysinfo, void *info) {
+  void *ctx;
+  COMMON_INTERCEPTOR_ENTER(ctx, sysinfo, info);
+  int res = REAL(sysinfo)(info);
+  if (!res && info)
+    COMMON_INTERCEPTOR_WRITE_RANGE(ctx, info, struct_sysinfo_sz);
+  return res;
+}
+#define INIT_SYSINFO INTERCEPT_FUNCTION(sysinfo);
+#else
+#define INIT_SYSINFO
+#endif
+
 #define SANITIZER_COMMON_INTERCEPTORS_INIT \
   INIT_STRCASECMP;                         \
   INIT_STRNCASECMP;                        \
@@ -1293,4 +1307,5 @@ INTERCEPTOR(int, getpeername, int sockfd
   INIT_RECVMSG;                            \
   INIT_GETPEERNAME;                        \
   INIT_IOCTL;                              \
-  INIT_INET_ATON;
+  INIT_INET_ATON;                          \
+  INIT_SYSINFO;

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=184739&r1=184738&r2=184739&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h Mon Jun 24 09:25:33 2013
@@ -91,5 +91,6 @@
 # define SANITIZER_INTERCEPT_GETPEERNAME SI_NOT_WINDOWS
 # define SANITIZER_INTERCEPT_IOCTL SI_NOT_WINDOWS
 # define SANITIZER_INTERCEPT_INET_ATON SI_NOT_WINDOWS
+# define SANITIZER_INTERCEPT_SYSINFO SI_LINUX
 
 #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=184739&r1=184738&r2=184739&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 Mon Jun 24 09:25:33 2013
@@ -41,6 +41,7 @@
 
 #if SANITIZER_LINUX
 #include <sys/mount.h>
+#include <sys/sysinfo.h>
 #include <sys/vt.h>
 #include <linux/cdrom.h>
 #include <linux/fd.h>
@@ -117,6 +118,7 @@ namespace __sanitizer {
   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);
   unsigned struct_timespec_sz = sizeof(struct timespec);
 #endif // SANITIZER_LINUX
 

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=184739&r1=184738&r2=184739&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 Mon Jun 24 09:25:33 2013
@@ -42,6 +42,7 @@ namespace __sanitizer {
   extern unsigned struct_dirent_sz;
   extern unsigned struct_statfs_sz;
   extern unsigned struct_epoll_event_sz;
+  extern unsigned struct_sysinfo_sz;
   extern unsigned struct_timespec_sz;
 #endif // SANITIZER_LINUX
 

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=184739&r1=184738&r2=184739&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_stat.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_stat.cc Mon Jun 24 09:25:33 2013
@@ -330,6 +330,7 @@ void StatOutput(u64 *stat) {
   name[StatInt_modfl]                    = "  modfl                           ";
   name[StatInt_getpeername]              = "  getpeername                     ";
   name[StatInt_ioctl]                    = "  ioctl                           ";
+  name[StatInt_sysinfo]                  = "  sysinfo                         ";
 
   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=184739&r1=184738&r2=184739&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_stat.h (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_stat.h Mon Jun 24 09:25:33 2013
@@ -325,6 +325,7 @@ enum StatType {
   StatInt_modfl,
   StatInt_getpeername,
   StatInt_ioctl,
+  StatInt_sysinfo,
 
   // Dynamic annotations.
   StatAnnotation,





More information about the llvm-commits mailing list