[compiler-rt] r215112 - [sanitizer] Intercept timerfd_settime, timerfd_gettime.

Evgeniy Stepanov eugeni.stepanov at gmail.com
Thu Aug 7 07:21:42 PDT 2014


Author: eugenis
Date: Thu Aug  7 09:21:42 2014
New Revision: 215112

URL: http://llvm.org/viewvc/llvm-project?rev=215112&view=rev
Log:
[sanitizer] Intercept timerfd_settime, timerfd_gettime.

Added:
    compiler-rt/trunk/test/sanitizer_common/TestCases/Linux/timerfd.cc   (with props)
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=215112&r1=215111&r2=215112&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc Thu Aug  7 09:21:42 2014
@@ -4657,6 +4657,34 @@ INTERCEPTOR(char *, getpass, const char
 #define INIT_GETPASS
 #endif
 
+#if SANITIZER_INTERCEPT_TIMERFD
+INTERCEPTOR(int, timerfd_settime, int fd, int flags, void *new_value,
+            void *old_value) {
+  void *ctx;
+  COMMON_INTERCEPTOR_ENTER(ctx, timerfd_settime, fd, flags, new_value,
+                           old_value);
+  COMMON_INTERCEPTOR_READ_RANGE(ctx, new_value, struct_itimerspec_sz);
+  int res = REAL(timerfd_settime)(fd, flags, new_value, old_value);
+  if (res != -1 && old_value)
+    COMMON_INTERCEPTOR_WRITE_RANGE(ctx, old_value, struct_itimerspec_sz);
+  return res;
+}
+
+INTERCEPTOR(int, timerfd_gettime, int fd, void *curr_value) {
+  void *ctx;
+  COMMON_INTERCEPTOR_ENTER(ctx, timerfd_gettime, fd, curr_value);
+  int res = REAL(timerfd_gettime)(fd, curr_value);
+  if (res != -1 && curr_value)
+    COMMON_INTERCEPTOR_WRITE_RANGE(ctx, curr_value, struct_itimerspec_sz);
+  return res;
+}
+#define INIT_TIMERFD                          \
+  COMMON_INTERCEPT_FUNCTION(timerfd_settime); \
+  COMMON_INTERCEPT_FUNCTION(timerfd_gettime);
+#else
+#define INIT_TIMERFD
+#endif
+
 static void InitializeCommonInterceptors() {
   static u64 metadata_mem[sizeof(MetadataHashMap) / sizeof(u64) + 1];
   interceptor_metadata_map = new((void *)&metadata_mem) MetadataHashMap();
@@ -4816,4 +4844,5 @@ static void InitializeCommonInterceptors
   INIT_FCLOSE;
   INIT_DLOPEN_DLCLOSE;
   INIT_GETPASS;
+  INIT_TIMERFD;
 }

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=215112&r1=215111&r2=215112&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h Thu Aug  7 09:21:42 2014
@@ -223,5 +223,6 @@
 #define SANITIZER_INTERCEPT_FCLOSE SI_NOT_WINDOWS
 #define SANITIZER_INTERCEPT_DLOPEN_DLCLOSE SI_LINUX_NOT_ANDROID || SI_MAC
 #define SANITIZER_INTERCEPT_GETPASS SI_LINUX_NOT_ANDROID || SI_MAC
+#define SANITIZER_INTERCEPT_TIMERFD SI_LINUX_NOT_ANDROID
 
 #endif  // #ifndef SANITIZER_PLATFORM_INTERCEPTORS_H

Added: compiler-rt/trunk/test/sanitizer_common/TestCases/Linux/timerfd.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/sanitizer_common/TestCases/Linux/timerfd.cc?rev=215112&view=auto
==============================================================================
--- compiler-rt/trunk/test/sanitizer_common/TestCases/Linux/timerfd.cc (added)
+++ compiler-rt/trunk/test/sanitizer_common/TestCases/Linux/timerfd.cc Thu Aug  7 09:21:42 2014
@@ -0,0 +1,52 @@
+// RUN: %clangxx -O0 -g %s -o %t && %run %t | FileCheck %s
+#include <assert.h>
+#include <stdio.h>
+#include <string.h>
+#include <time.h>
+#include <sys/timerfd.h>
+#include <unistd.h>
+
+int main (int argc, char** argv)
+{
+  int fd = timerfd_create(CLOCK_REALTIME, 0);
+  assert(fd >= 0);
+
+  struct itimerspec its;
+  its.it_value.tv_sec = 0;
+  its.it_value.tv_nsec = 1000000;
+  its.it_interval.tv_sec = its.it_value.tv_sec;
+  its.it_interval.tv_nsec = its.it_value.tv_nsec;
+
+  int res = timerfd_settime(fd, 0, &its, NULL);
+  assert(res != -1);
+
+  struct itimerspec its2;
+  res = timerfd_settime(fd, 0, &its, &its2);
+  assert(res != -1);
+  assert(its2.it_interval.tv_sec == its.it_interval.tv_sec);
+  assert(its2.it_interval.tv_nsec == its.it_interval.tv_nsec);
+  assert(its2.it_value.tv_sec <= its.it_value.tv_sec);
+  assert(its2.it_value.tv_nsec <= its.it_value.tv_nsec);
+
+  struct itimerspec its3;
+  res = timerfd_gettime(fd, &its3);
+  assert(res != -1);
+  assert(its3.it_interval.tv_sec == its.it_interval.tv_sec);
+  assert(its3.it_interval.tv_nsec == its.it_interval.tv_nsec);
+  assert(its3.it_value.tv_sec <= its.it_value.tv_sec);
+  assert(its3.it_value.tv_nsec <= its.it_value.tv_nsec);
+
+
+  unsigned long long buf;
+  res = read(fd, &buf, sizeof(buf));
+  assert(res == 8);
+  assert(buf >= 1);
+
+  res = close(fd);
+  assert(res != -1);
+
+  printf("DONE\n");
+  // CHECK: DONE
+  
+  return 0;
+}

Propchange: compiler-rt/trunk/test/sanitizer_common/TestCases/Linux/timerfd.cc
------------------------------------------------------------------------------
    svn:eol-style = LF





More information about the llvm-commits mailing list