[compiler-rt] r347426 - [Sanitizer] Adding setvbuf in supported platforms and other stream buffer functions
David Carlier via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 21 13:17:46 PST 2018
Author: devnexen
Date: Wed Nov 21 13:17:46 2018
New Revision: 347426
URL: http://llvm.org/viewvc/llvm-project?rev=347426&view=rev
Log:
[Sanitizer] Adding setvbuf in supported platforms and other stream buffer functions
- Enabling setvbuf interceptions for non NetBSD platforms.
- setbuf, setbuffer, setlinebuf as well.
Reviewers: vitalybuka, krytarowski
Reviewed By: vitalybuka
Differential Revision: https://reviews.llvm.org/D54779
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
compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_netbsd.cc
compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_netbsd.h
compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_posix.cc
compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_posix.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=347426&r1=347425&r2=347426&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc Wed Nov 21 13:17:46 2018
@@ -7306,9 +7306,44 @@ INTERCEPTOR(int, setvbuf, __sanitizer_FI
int ret = REAL(setvbuf)(stream, buf, mode, size);
if (buf)
COMMON_INTERCEPTOR_WRITE_RANGE(ctx, buf, size);
+ if (stream)
+ unpoison_file(stream);
return ret;
}
-#define INIT_SETVBUF COMMON_INTERCEPT_FUNCTION(setvbuf)
+
+INTERCEPTOR(void, setbuf, __sanitizer_FILE *stream, char *buf) {
+ void *ctx;
+ COMMON_INTERCEPTOR_ENTER(ctx, setbuf, stream, buf);
+ REAL(setbuf)(stream, buf);
+ if (buf) {
+ COMMON_INTERCEPTOR_WRITE_RANGE(ctx, buf, __sanitizer_bufsiz);
+ }
+ if (stream)
+ unpoison_file(stream);
+}
+
+INTERCEPTOR(void, setbuffer, __sanitizer_FILE *stream, char *buf, int mode) {
+ void *ctx;
+ COMMON_INTERCEPTOR_ENTER(ctx, setbuffer, stream, buf, mode);
+ REAL(setbuffer)(stream, buf, mode);
+ if (buf) {
+ COMMON_INTERCEPTOR_WRITE_RANGE(ctx, buf, __sanitizer_bufsiz);
+ }
+ if (stream)
+ unpoison_file(stream);
+}
+
+INTERCEPTOR(void, setlinebuf, __sanitizer_FILE *stream) {
+ void *ctx;
+ COMMON_INTERCEPTOR_ENTER(ctx, setlinebuf, stream);
+ REAL(setlinebuf)(stream);
+ if (stream)
+ unpoison_file(stream);
+}
+#define INIT_SETVBUF COMMON_INTERCEPT_FUNCTION(setvbuf); \
+ COMMON_INTERCEPT_FUNCTION(setbuf); \
+ COMMON_INTERCEPT_FUNCTION(setbuffer); \
+ COMMON_INTERCEPT_FUNCTION(setlinebuf)
#else
#define INIT_SETVBUF
#endif
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=347426&r1=347425&r2=347426&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h Wed Nov 21 13:17:46 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
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_netbsd.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_netbsd.cc?rev=347426&r1=347425&r2=347426&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_netbsd.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_netbsd.cc Wed Nov 21 13:17:46 2018
@@ -266,6 +266,8 @@ const uptr sig_dfl = (uptr)SIG_DFL;
const uptr sig_err = (uptr)SIG_ERR;
const uptr sa_siginfo = (uptr)SA_SIGINFO;
+const unsigned long __sanitizer_bufsiz = BUFSIZ;
+
int ptrace_pt_io = PT_IO;
int ptrace_pt_lwpinfo = PT_LWPINFO;
int ptrace_pt_set_event_mask = PT_SET_EVENT_MASK;
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_netbsd.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_netbsd.h?rev=347426&r1=347425&r2=347426&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_netbsd.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_netbsd.h Wed Nov 21 13:17:46 2018
@@ -460,6 +460,8 @@ struct __sanitizer_ttyent {
char *ty_class;
};
+extern const unsigned long __sanitizer_bufsiz;
+
#define IOC_NRBITS 8
#define IOC_TYPEBITS 8
#define IOC_SIZEBITS 14
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=347426&r1=347425&r2=347426&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 Wed Nov 21 13:17:46 2018
@@ -501,6 +501,8 @@ unsigned struct_ElfW_Phdr_sz = sizeof(El
unsigned struct_sioc_vif_req_sz = sizeof(struct sioc_vif_req);
#endif
+ const unsigned long __sanitizer_bufsiz = BUFSIZ;
+
const unsigned IOCTL_NOT_PRESENT = 0;
unsigned IOCTL_FIOASYNC = FIOASYNC;
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=347426&r1=347425&r2=347426&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 Wed Nov 21 13:17:46 2018
@@ -1073,6 +1073,8 @@ struct __sanitizer_cookie_io_functions_t
extern unsigned struct_unimapinit_sz;
#endif // SANITIZER_LINUX && !SANITIZER_ANDROID
+ extern const unsigned long __sanitizer_bufsiz;
+
#if (SANITIZER_LINUX || SANITIZER_FREEBSD) && !SANITIZER_ANDROID
extern unsigned struct_audio_buf_info_sz;
extern unsigned struct_ppp_stats_sz;
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=347425&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,67 +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() {
- 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=347426&view=auto
==============================================================================
--- compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/setvbuf.cc (added)
+++ compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/setvbuf.cc Wed Nov 21 13:17:46 2018
@@ -0,0 +1,81 @@
+// 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);
+}
+
+void print_one_byte(char *buf) {
+ printf("First byte is %c\n", buf[0]);
+}
+
+void test_setbuf() {
+ char buf[BUFSIZ];
+
+ setbuf(stdout, NULL);
+
+ print_something();
+
+ setbuf(stdout, buf);
+
+ print_something();
+
+ print_one_byte(buf);
+}
+
+void test_setbuffer() {
+ char buf[BUFSIZ];
+
+ setbuffer(stdout, NULL, 0);
+
+ print_something();
+
+ setbuffer(stdout, buf, BUFSIZ);
+
+ print_something();
+
+ print_one_byte(buf);
+}
+
+void test_setlinebuf() {
+ setlinebuf(stdout);
+
+ print_something();
+}
+
+void test_setvbuf() {
+ char buf[BUFSIZ];
+
+ setvbuf(stdout, NULL, _IONBF, 0);
+
+ print_something();
+
+ setvbuf(stdout, buf, _IOLBF, BUFSIZ);
+
+ print_something();
+
+ print_one_byte(buf);
+
+ setvbuf(stdout, buf, _IOFBF, BUFSIZ);
+
+ print_something();
+
+ print_one_byte(buf);
+}
+
+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