From cf878fd3e01cd141ad1e095764d64c410c0ce763 Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Tue, 13 Aug 2013 16:51:27 +0000 Subject: [PATCH] tsan: intercept getaddrinfo This is necessary to prevent false positives, see: https://code.google.com/p/thread-sanitizer/issues/detail?id=25 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@188291 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/tsan/rtl/tsan_interceptors.cc | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/lib/tsan/rtl/tsan_interceptors.cc b/lib/tsan/rtl/tsan_interceptors.cc index ad69de0e7..9d6d3e030 100644 --- a/lib/tsan/rtl/tsan_interceptors.cc +++ b/lib/tsan/rtl/tsan_interceptors.cc @@ -1735,6 +1735,20 @@ TSAN_INTERCEPTOR(int, gettimeofday, void *tv, void *tz) { return REAL(gettimeofday)(tv, tz); } +TSAN_INTERCEPTOR(int, getaddrinfo, void *node, void *service, + void *hints, void *rv) { + SCOPED_TSAN_INTERCEPTOR(getaddrinfo, node, service, hints, rv); + // We miss atomic synchronization in getaddrinfo, + // and can report false race between malloc and free + // inside of getaddrinfo. So ignore memory accesses. + IgnoreCtl(thr, true, true); + IgnoreCtl(thr, false, true); + int res = REAL(getaddrinfo)(node, service, hints, rv); + IgnoreCtl(thr, true, false); + IgnoreCtl(thr, false, false); + return res; +} + // Linux kernel has a bug that leads to kernel deadlock if a process // maps TBs of memory and then calls mlock(). static void MlockIsUnsupported() { @@ -2056,6 +2070,7 @@ void InitializeInterceptors() { TSAN_INTERCEPT(usleep); TSAN_INTERCEPT(nanosleep); TSAN_INTERCEPT(gettimeofday); + TSAN_INTERCEPT(getaddrinfo); TSAN_INTERCEPT(mlock); TSAN_INTERCEPT(munlock); -- 2.11.4.GIT