[compiler-rt] r347355 - [Sanitizer] intercept setvbuf on other platforms where it is supported

David Carlier via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 20 14:17:24 PST 2018


Author: devnexen
Date: Tue Nov 20 14:17:23 2018
New Revision: 347355

URL: http://llvm.org/viewvc/llvm-project?rev=347355&view=rev
Log:
[Sanitizer] intercept setvbuf on other platforms where it is supported

Unit tests enabled only in platform tested.

Reviewers: krytarowski, vitalybuka

Reviewed By: krytarowski, vitalybuka

Differential Revision: https://reviews.llvm.org/D54739

Added:
    compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/setvbuf.cc
Removed:
    compiler-rt/trunk/test/sanitizer_common/TestCases/NetBSD/setvbuf.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=347355&r1=347354&r2=347355&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc Tue Nov 20 14:17:23 2018
@@ -7306,6 +7306,8 @@ INTERCEPTOR(int, setvbuf, __sanitizer_FI
   int ret = REAL(setvbuf)(stream, buf, mode, size);
   if (buf)
     COMMON_INTERCEPTOR_WRITE_RANGE(ctx, buf, size);
+  if (ret == 0)
+    unpoison_file(stream);
   return ret;
 }
 #define INIT_SETVBUF COMMON_INTERCEPT_FUNCTION(setvbuf)

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=347355&r1=347354&r2=347355&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h Tue Nov 20 14:17:23 2018
@@ -516,7 +516,8 @@
 #define SANITIZER_INTERCEPT_TTYENT SI_NETBSD
 #define SANITIZER_INTERCEPT_PROTOENT SI_NETBSD
 #define SANITIZER_INTERCEPT_NETENT SI_NETBSD
-#define SANITIZER_INTERCEPT_SETVBUF SI_NETBSD
+#define SANITIZER_INTERCEPT_SETVBUF (SI_NETBSD || SI_FREEBSD || \
+  SI_LINUX || SI_MAC)
 #define SANITIZER_INTERCEPT_GETMNTINFO SI_NETBSD
 #define SANITIZER_INTERCEPT_MI_VECTOR_HASH SI_NETBSD
 

Removed: compiler-rt/trunk/test/sanitizer_common/TestCases/NetBSD/setvbuf.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/sanitizer_common/TestCases/NetBSD/setvbuf.cc?rev=347354&view=auto
==============================================================================
--- compiler-rt/trunk/test/sanitizer_common/TestCases/NetBSD/setvbuf.cc (original)
+++ compiler-rt/trunk/test/sanitizer_common/TestCases/NetBSD/setvbuf.cc (removed)
@@ -1,69 +0,0 @@
-// RUN: %clangxx -O0 -g %s -o %t && %run %t 2>&1 | FileCheck %s
-
-#include <stdio.h>
-
-void print_something() {
-  for (size_t i = 0; i < 10 * BUFSIZ; i++)
-    printf("Hello world %zu\n", i);
-}
-
-void test_setbuf() {
-  char buf[BUFSIZ];
-
-  setbuf(stdout, NULL);
-
-  print_something();
-
-  setbuf(stdout, buf);
-
-  print_something();
-}
-
-void test_setbuffer() {
-  char buf[BUFSIZ];
-
-  setbuffer(stdout, NULL, 0);
-
-  print_something();
-
-  setbuffer(stdout, buf, BUFSIZ);
-
-  print_something();
-}
-
-void test_setlinebuf() {
-  char buf[BUFSIZ];
-
-  setlinebuf(stdout);
-
-  print_something();
-}
-
-void test_setvbuf() {
-  char buf[BUFSIZ];
-
-  setvbuf(stdout, NULL, _IONBF, 0);
-
-  print_something();
-
-  setvbuf(stdout, buf, _IOLBF, BUFSIZ);
-
-  print_something();
-
-  setvbuf(stdout, buf, _IOFBF, BUFSIZ);
-
-  print_something();
-}
-
-int main(void) {
-  printf("setvbuf\n");
-
-  test_setbuf();
-  test_setbuffer();
-  test_setlinebuf();
-  test_setvbuf();
-
-  // CHECK: setvbuf
-
-  return 0;
-}

Added: compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/setvbuf.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/setvbuf.cc?rev=347355&view=auto
==============================================================================
--- compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/setvbuf.cc (added)
+++ compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/setvbuf.cc Tue Nov 20 14:17:23 2018
@@ -0,0 +1,73 @@
+// RUN: %clangxx -O0 -g %s -o %t && %run %t 2>&1 | FileCheck %s
+
+// UNSUPPORTED: solaris
+
+#include <stdio.h>
+
+void print_something() {
+  for (size_t i = 0; i < 10 * BUFSIZ; i++)
+    printf("Hello world %zu\n", i);
+}
+
+// setbuffer/setlinebuf/setbuf uses setvbuf
+// internally on NetBSD
+#if defined(__NetBSD__)
+void test_setbuf() {
+  char buf[BUFSIZ];
+
+  setbuf(stdout, NULL);
+
+  print_something();
+
+  setbuf(stdout, buf);
+
+  print_something();
+}
+
+void test_setbuffer() {
+  char buf[BUFSIZ];
+
+  setbuffer(stdout, NULL, 0);
+
+  print_something();
+
+  setbuffer(stdout, buf, BUFSIZ);
+
+  print_something();
+}
+
+void test_setlinebuf() {
+  setlinebuf(stdout);
+
+  print_something();
+}
+#endif
+
+void test_setvbuf() {
+  char buf[BUFSIZ];
+
+  setvbuf(stdout, NULL, _IONBF, 0);
+
+  print_something();
+
+  setvbuf(stdout, buf, _IOLBF, BUFSIZ);
+
+  print_something();
+
+  setvbuf(stdout, buf, _IOFBF, BUFSIZ);
+
+  print_something();
+}
+
+int main(void) {
+  printf("setvbuf\n");
+
+  test_setbuf();
+  test_setbuffer();
+  test_setlinebuf();
+  test_setvbuf();
+
+  // CHECK: setvbuf
+
+  return 0;
+}




More information about the llvm-commits mailing list