[llvm-commits] [compiler-rt] r170184 - in /compiler-rt/trunk/lib/tsan: lit_tests/fd_socketpair_norace.cc rtl/tsan_interceptors.cc rtl/tsan_stat.cc rtl/tsan_stat.h
Dmitry Vyukov
dvyukov at google.com
Fri Dec 14 01:57:43 PST 2012
Author: dvyukov
Date: Fri Dec 14 03:57:42 2012
New Revision: 170184
URL: http://llvm.org/viewvc/llvm-project?rev=170184&view=rev
Log:
tsan: add socketpair() interceptor and test
Added:
compiler-rt/trunk/lib/tsan/lit_tests/fd_socketpair_norace.cc
Modified:
compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc
compiler-rt/trunk/lib/tsan/rtl/tsan_stat.cc
compiler-rt/trunk/lib/tsan/rtl/tsan_stat.h
Added: compiler-rt/trunk/lib/tsan/lit_tests/fd_socketpair_norace.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/lit_tests/fd_socketpair_norace.cc?rev=170184&view=auto
==============================================================================
--- compiler-rt/trunk/lib/tsan/lit_tests/fd_socketpair_norace.cc (added)
+++ compiler-rt/trunk/lib/tsan/lit_tests/fd_socketpair_norace.cc Fri Dec 14 03:57:42 2012
@@ -0,0 +1,36 @@
+// RUN: %clangxx_tsan -O1 %s -o %t && %t 2>&1 | FileCheck %s
+#include <pthread.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+
+int fds[2];
+int X;
+
+void *Thread1(void *x) {
+ X = 42;
+ write(fds[1], "a", 1);
+ close(fds[1]);
+ return NULL;
+}
+
+void *Thread2(void *x) {
+ char buf;
+ while (read(fds[0], &buf, 1) != 1) {
+ }
+ X = 43;
+ close(fds[0]);
+ return NULL;
+}
+
+int main() {
+ socketpair(AF_UNIX, SOCK_STREAM, 0, fds);
+ pthread_t t[2];
+ pthread_create(&t[0], NULL, Thread1, NULL);
+ pthread_create(&t[1], NULL, Thread2, NULL);
+ pthread_join(t[0], NULL);
+ pthread_join(t[1], NULL);
+}
+
+// CHECK-NOT: WARNING: ThreadSanitizer: data race
Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc?rev=170184&r1=170183&r2=170184&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc Fri Dec 14 03:57:42 2012
@@ -1136,6 +1136,14 @@
return fd;
}
+TSAN_INTERCEPTOR(int, socketpair, int domain, int type, int protocol, int *fd) {
+ SCOPED_TSAN_INTERCEPTOR(socketpair, domain, type, protocol, fd);
+ int res = REAL(socketpair)(domain, type, protocol, fd);
+ if (res == 0 && fd[0] >= 0 && fd[1] >= 0)
+ FdPipeCreate(thr, pc, fd[0], fd[1]);
+ return res;
+}
+
TSAN_INTERCEPTOR(int, connect, int fd, void *addr, unsigned addrlen) {
SCOPED_TSAN_INTERCEPTOR(connect, fd, addr, addrlen);
int res = REAL(connect)(fd, addr, addrlen);
@@ -1735,6 +1743,7 @@
TSAN_INTERCEPT(dup3);
TSAN_INTERCEPT(eventfd);
TSAN_INTERCEPT(socket);
+ TSAN_INTERCEPT(socketpair);
TSAN_INTERCEPT(connect);
TSAN_INTERCEPT(accept);
TSAN_INTERCEPT(accept4);
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=170184&r1=170183&r2=170184&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_stat.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_stat.cc Fri Dec 14 03:57:42 2012
@@ -190,6 +190,7 @@
name[StatInt_dup3] = " dup3 ";
name[StatInt_eventfd] = " eventfd ";
name[StatInt_socket] = " socket ";
+ name[StatInt_socketpair] = " socketpair ";
name[StatInt_connect] = " connect ";
name[StatInt_accept] = " accept ";
name[StatInt_accept4] = " accept4 ";
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=170184&r1=170183&r2=170184&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_stat.h (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_stat.h Fri Dec 14 03:57:42 2012
@@ -185,6 +185,7 @@
StatInt_dup3,
StatInt_eventfd,
StatInt_socket,
+ StatInt_socketpair,
StatInt_connect,
StatInt_accept,
StatInt_accept4,
More information about the llvm-commits
mailing list