summaryrefslogtreecommitdiff
path: root/lib/tsan
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2013-10-11 14:13:11 +0000
committerDmitry Vyukov <dvyukov@google.com>2013-10-11 14:13:11 +0000
commit67f5544391c338411b0006bda7dc1b852bbdd4fb (patch)
tree804c0a9557a512eafbe3aad5ea854592401aa0d5 /lib/tsan
parent29cec483b760082e264340072f3245fad37e2255 (diff)
downloadcompiler-rt-67f5544391c338411b0006bda7dc1b852bbdd4fb.tar.gz
tsan: catch more races on file descriptors
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@192452 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/tsan')
-rw-r--r--lib/tsan/rtl/tsan_fd.cc2
-rw-r--r--lib/tsan/rtl/tsan_interceptors.cc12
2 files changed, 12 insertions, 2 deletions
diff --git a/lib/tsan/rtl/tsan_fd.cc b/lib/tsan/rtl/tsan_fd.cc
index 332a12d40..703a487a5 100644
--- a/lib/tsan/rtl/tsan_fd.cc
+++ b/lib/tsan/rtl/tsan_fd.cc
@@ -166,6 +166,8 @@ void FdRelease(ThreadState *thr, uptr pc, int fd) {
}
void FdAccess(ThreadState *thr, uptr pc, int fd) {
+ if (fd < 0)
+ return;
DPrintf("#%d: FdAccess(%d)\n", thr->tid, fd);
FdDesc *d = fddesc(thr, pc, fd);
MemoryRead(thr, pc, (uptr)d, kSizeLog8);
diff --git a/lib/tsan/rtl/tsan_interceptors.cc b/lib/tsan/rtl/tsan_interceptors.cc
index ad7f55914..596664bdf 100644
--- a/lib/tsan/rtl/tsan_interceptors.cc
+++ b/lib/tsan/rtl/tsan_interceptors.cc
@@ -1524,22 +1524,28 @@ TSAN_INTERCEPTOR(int, pipe2, int *pipefd, int flags) {
TSAN_INTERCEPTOR(long_t, send, int fd, void *buf, long_t len, int flags) {
SCOPED_TSAN_INTERCEPTOR(send, fd, buf, len, flags);
- if (fd >= 0)
+ if (fd >= 0) {
+ FdAccess(thr, pc, fd);
FdRelease(thr, pc, fd);
+ }
int res = REAL(send)(fd, buf, len, flags);
return res;
}
TSAN_INTERCEPTOR(long_t, sendmsg, int fd, void *msg, int flags) {
SCOPED_TSAN_INTERCEPTOR(sendmsg, fd, msg, flags);
- if (fd >= 0)
+ if (fd >= 0) {
+ FdAccess(thr, pc, fd);
FdRelease(thr, pc, fd);
+ }
int res = REAL(sendmsg)(fd, msg, flags);
return res;
}
TSAN_INTERCEPTOR(long_t, recv, int fd, void *buf, long_t len, int flags) {
SCOPED_TSAN_INTERCEPTOR(recv, fd, buf, len, flags);
+ if (fd >= 0)
+ FdAccess(thr, pc, fd);
int res = REAL(recv)(fd, buf, len, flags);
if (res >= 0 && fd >= 0) {
FdAcquire(thr, pc, fd);
@@ -1901,6 +1907,8 @@ struct TsanInterceptorContext {
FdAcquire(((TsanInterceptorContext *) ctx)->thr, pc, fd)
#define COMMON_INTERCEPTOR_FD_RELEASE(ctx, fd) \
FdRelease(((TsanInterceptorContext *) ctx)->thr, pc, fd)
+#define COMMON_INTERCEPTOR_FD_ACCESS(ctx, fd) \
+ FdAccess(((TsanInterceptorContext *) ctx)->thr, pc, fd)
#define COMMON_INTERCEPTOR_FD_SOCKET_ACCEPT(ctx, fd, newfd) \
FdSocketAccept(((TsanInterceptorContext *) ctx)->thr, pc, fd, newfd)
#define COMMON_INTERCEPTOR_SET_THREAD_NAME(ctx, name) \