[compiler-rt] r185626 - [sanitizer] Intercept tcgetattr.

Evgeniy Stepanov eugeni.stepanov at gmail.com
Thu Jul 4 07:03:31 PDT 2013


Author: eugenis
Date: Thu Jul  4 09:03:31 2013
New Revision: 185626

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

Added:
    compiler-rt/trunk/lib/msan/lit_tests/Linux/tcgetattr.cc   (with props)
Modified:
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h
    compiler-rt/trunk/lib/tsan/rtl/tsan_stat.cc
    compiler-rt/trunk/lib/tsan/rtl/tsan_stat.h

Added: compiler-rt/trunk/lib/msan/lit_tests/Linux/tcgetattr.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/lit_tests/Linux/tcgetattr.cc?rev=185626&view=auto
==============================================================================
--- compiler-rt/trunk/lib/msan/lit_tests/Linux/tcgetattr.cc (added)
+++ compiler-rt/trunk/lib/msan/lit_tests/Linux/tcgetattr.cc Thu Jul  4 09:03:31 2013
@@ -0,0 +1,21 @@
+// RUN: %clangxx_msan -m64 -O0 %s -o %t && %t %p
+
+#include <assert.h>
+#include <glob.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <termios.h>
+#include <unistd.h>
+
+int main(int argc, char *argv[]) {
+  int fd = getpt();
+  assert(fd >= 0);
+  
+  struct termios t;
+  int res = tcgetattr(fd, &t);
+  assert(!res);
+
+  if (t.c_iflag == 0)
+    exit(0);
+  return 0;
+}

Propchange: compiler-rt/trunk/lib/msan/lit_tests/Linux/tcgetattr.cc
------------------------------------------------------------------------------
    svn:eol-style = LF

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=185626&r1=185625&r2=185626&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc Thu Jul  4 09:03:31 2013
@@ -1495,7 +1495,6 @@ INTERCEPTOR(SIZE_T, mbsrtowcs, wchar_t *
 #endif
 
 #if SANITIZER_INTERCEPT_MBSNRTOWCS
-
 INTERCEPTOR(SIZE_T, mbsnrtowcs, wchar_t *dest, const char **src, SIZE_T nms,
             SIZE_T len, void *ps) {
   void *ctx;
@@ -1546,7 +1545,6 @@ INTERCEPTOR(SIZE_T, wcsrtombs, char *des
 #endif
 
 #if SANITIZER_INTERCEPT_WCSNRTOMBS
-
 INTERCEPTOR(SIZE_T, wcsnrtombs, char *dest, const wchar_t **src, SIZE_T nms,
             SIZE_T len, void *ps) {
   void *ctx;
@@ -1566,6 +1564,22 @@ INTERCEPTOR(SIZE_T, wcsnrtombs, char *de
 #define INIT_WCSNRTOMBS
 #endif
 
+
+#if SANITIZER_INTERCEPT_TCGETATTR
+INTERCEPTOR(int, tcgetattr, int fd, void *termios_p) {
+  void *ctx;
+  COMMON_INTERCEPTOR_ENTER(ctx, tcgetattr, fd, termios_p);
+  int res = REAL(tcgetattr)(fd, termios_p);
+  if (!res && termios_p)
+    COMMON_INTERCEPTOR_WRITE_RANGE(ctx, termios_p, struct_termios_sz);
+  return res;
+}
+
+#define INIT_TCGETATTR INTERCEPT_FUNCTION(tcgetattr);
+#else
+#define INIT_TCGETATTR
+#endif
+
 #define SANITIZER_COMMON_INTERCEPTORS_INIT \
   INIT_STRCASECMP;                         \
   INIT_STRNCASECMP;                        \
@@ -1619,4 +1633,5 @@ INTERCEPTOR(SIZE_T, wcsnrtombs, char *de
   INIT_MBSTOWCS;                           \
   INIT_MBSNRTOWCS;                         \
   INIT_WCSTOMBS;                           \
-  INIT_WCSNRTOMBS;
+  INIT_WCSNRTOMBS;                         \
+  INIT_TCGETATTR;

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=185626&r1=185625&r2=185626&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h Thu Jul  4 09:03:31 2013
@@ -104,5 +104,6 @@
 # define SANITIZER_INTERCEPT_MBSNRTOWCS SI_MAC || SI_LINUX_NOT_ANDROID
 # define SANITIZER_INTERCEPT_WCSTOMBS SI_NOT_WINDOWS
 # define SANITIZER_INTERCEPT_WCSNRTOMBS SI_MAC || SI_LINUX_NOT_ANDROID
+# define SANITIZER_INTERCEPT_TCGETATTR SI_LINUX
 
 #endif  // #ifndef SANITIZER_PLATFORM_INTERCEPTORS_H

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=185626&r1=185625&r2=185626&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_stat.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_stat.cc Thu Jul  4 09:03:31 2013
@@ -348,6 +348,7 @@ void StatOutput(u64 *stat) {
   name[StatInt_wcstombs]                 = "  wcstombs                        ";
   name[StatInt_wcsrtombs]                = "  wcsrtombs                       ";
   name[StatInt_wcsnrtombs]               = "  wcsnrtombs                      ";
+  name[StatInt_tcgetattr]                = "  tcgetattr                       ";
 
   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=185626&r1=185625&r2=185626&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_stat.h (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_stat.h Thu Jul  4 09:03:31 2013
@@ -343,6 +343,7 @@ enum StatType {
   StatInt_wcstombs,
   StatInt_wcsrtombs,
   StatInt_wcsnrtombs,
+  StatInt_tcgetattr,
 
   // Dynamic annotations.
   StatAnnotation,





More information about the llvm-commits mailing list