[compiler-rt] r191129 - tsan: intercept close syscall
Dmitry Vyukov
dvyukov at google.com
Fri Sep 20 20:47:35 PDT 2013
Author: dvyukov
Date: Fri Sep 20 22:47:35 2013
New Revision: 191129
URL: http://llvm.org/viewvc/llvm-project?rev=191129&view=rev
Log:
tsan: intercept close syscall
Modified:
compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_syscalls.inc
compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_syscalls.inc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_syscalls.inc?rev=191129&r1=191128&r2=191129&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_syscalls.inc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_syscalls.inc Fri Sep 20 22:47:35 2013
@@ -25,6 +25,8 @@
// COMMON_SYSCALL_POST_WRITE_RANGE
// Called in posthook for regions that were written to by the kernel
// and are now initialized.
+// COMMON_SYSCALL_FD_CLOSE(fd)
+// Called before closing file descriptor fd.
//===----------------------------------------------------------------------===//
#include "sanitizer_platform.h"
@@ -42,6 +44,9 @@
#define POST_READ(p, s) COMMON_SYSCALL_POST_READ_RANGE(p, s)
#define POST_WRITE(p, s) COMMON_SYSCALL_POST_WRITE_RANGE(p, s)
+#ifndef COMMON_SYSCALL_FD_CLOSE
+# define COMMON_SYSCALL_FD_CLOSE(fd)
+#endif
// FIXME: do some kind of PRE_READ for all syscall arguments (int(s) and such).
@@ -1312,7 +1317,9 @@ PRE_SYSCALL(open)(const void *filename,
POST_SYSCALL(open)(long res, const void *filename, long flags, long mode) {}
-PRE_SYSCALL(close)(long fd) {}
+PRE_SYSCALL(close)(long fd) {
+ COMMON_SYSCALL_FD_CLOSE((int)fd);
+}
POST_SYSCALL(close)(long res, long fd) {}
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=191129&r1=191128&r2=191129&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc Fri Sep 20 22:47:35 2013
@@ -1857,6 +1857,19 @@ static void syscall_access_range(uptr pc
ProcessPendingSignals(thr);
}
+static void syscall_fd_close(uptr pc, int fd) {
+ if (fd < 0)
+ return;
+ ThreadState *thr = cur_thread();
+ if (thr->in_rtl == 0)
+ Initialize(thr);
+ thr->in_rtl++;
+ FdClose(thr, pc, fd);
+ thr->in_rtl--;
+ if (thr->in_rtl == 0)
+ ProcessPendingSignals(thr);
+}
+
#define COMMON_SYSCALL_PRE_READ_RANGE(p, s) \
syscall_access_range(GET_CALLER_PC(), (uptr)(p), (uptr)(s), false)
#define COMMON_SYSCALL_PRE_WRITE_RANGE(p, s) \
@@ -1865,6 +1878,8 @@ static void syscall_access_range(uptr pc
do { } while (false)
#define COMMON_SYSCALL_POST_WRITE_RANGE(p, s) \
do { } while (false)
+#define COMMON_SYSCALL_FD_CLOSE(fd) \
+ syscall_fd_close(GET_CALLER_PC(), fd)
#include "sanitizer_common/sanitizer_common_syscalls.inc"
namespace __tsan {
More information about the llvm-commits
mailing list