[compiler-rt] r273748 - [msan] Intercept eventfd_read, eventfd_write.

Evgeniy Stepanov via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 24 16:32:30 PDT 2016


Author: eugenis
Date: Fri Jun 24 18:32:30 2016
New Revision: 273748

URL: http://llvm.org/viewvc/llvm-project?rev=273748&view=rev
Log:
[msan] Intercept eventfd_read, eventfd_write.

Added:
    compiler-rt/trunk/test/msan/Linux/eventfd.cc
Modified:
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.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=273748&r1=273747&r2=273748&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc Fri Jun 24 18:32:30 2016
@@ -5667,6 +5667,35 @@ INTERCEPTOR(SSIZE_T, sendto, int fd, voi
 #define INIT_SEND_SENDTO
 #endif
 
+#if SANITIZER_INTERCEPT_EVENTFD_READ_WRITE
+INTERCEPTOR(int, eventfd_read, int fd, u64 *value) {
+  void *ctx;
+  COMMON_INTERCEPTOR_ENTER(ctx, eventfd_read, fd, value);
+  COMMON_INTERCEPTOR_FD_ACCESS(ctx, fd);
+  int res = REAL(eventfd_read)(fd, value);
+  if (res == 0) {
+    COMMON_INTERCEPTOR_WRITE_RANGE(ctx, value, sizeof(*value));
+    if (fd >= 0) COMMON_INTERCEPTOR_FD_ACQUIRE(ctx, fd);
+  }
+  return res;
+}
+INTERCEPTOR(int, eventfd_write, int fd, u64 value) {
+  void *ctx;
+  COMMON_INTERCEPTOR_ENTER(ctx, eventfd_write, fd, value);
+  if (fd >= 0) {
+    COMMON_INTERCEPTOR_FD_ACCESS(ctx, fd);
+    COMMON_INTERCEPTOR_FD_RELEASE(ctx, fd);
+  }
+  int res = REAL(eventfd_write)(fd, value);
+  return res;
+}
+#define INIT_EVENTFD_READ_WRITE            \
+  COMMON_INTERCEPT_FUNCTION(eventfd_read); \
+  COMMON_INTERCEPT_FUNCTION(eventfd_write)
+#else
+#define INIT_EVENTFD_READ_WRITE
+#endif
+
 #if SANITIZER_INTERCEPT_STAT
 INTERCEPTOR(int, stat, const char *path, void *buf) {
   void *ctx;
@@ -5937,6 +5966,7 @@ static void InitializeCommonInterceptors
   INIT_RECV_RECVFROM;
   INIT_SEND_SENDTO;
   INIT_STAT;
+  INIT_EVENTFD_READ_WRITE;
   INIT___XSTAT;
   INIT___XSTAT64;
   INIT___LXSTAT;

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=273748&r1=273747&r2=273748&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h Fri Jun 24 18:32:30 2016
@@ -310,6 +310,7 @@
 #define SANITIZER_INTERCEPTOR_HOOKS SI_LINUX
 #define SANITIZER_INTERCEPT_RECV_RECVFROM SI_NOT_WINDOWS
 #define SANITIZER_INTERCEPT_SEND_SENDTO SI_NOT_WINDOWS
+#define SANITIZER_INTERCEPT_EVENTFD_READ_WRITE SI_LINUX
 
 #define SANITIZER_INTERCEPT_STAT (SI_FREEBSD || SI_MAC || SI_ANDROID)
 #define SANITIZER_INTERCEPT___XSTAT !SANITIZER_INTERCEPT_STAT && SI_NOT_WINDOWS

Added: compiler-rt/trunk/test/msan/Linux/eventfd.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/msan/Linux/eventfd.cc?rev=273748&view=auto
==============================================================================
--- compiler-rt/trunk/test/msan/Linux/eventfd.cc (added)
+++ compiler-rt/trunk/test/msan/Linux/eventfd.cc Fri Jun 24 18:32:30 2016
@@ -0,0 +1,18 @@
+// RUN: %clangxx_msan -O0 %s -o %t && %run %t 2>&1
+
+#include <assert.h>
+#include <sys/eventfd.h>
+
+#include <sanitizer/msan_interface.h>
+
+int main(int argc, char *argv[]) {
+  int efd = eventfd(42, 0);
+  assert(efd >= 0);
+
+  eventfd_t v;
+  int ret = eventfd_read(efd, &v);
+  assert(ret == 0);
+  __msan_check_mem_is_initialized(&v, sizeof(v));
+
+  assert(v == 42);
+}




More information about the llvm-commits mailing list