[compiler-rt] fbcdf4a - tsan: intercept epoll_pwait2
Dmitry Vyukov via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 23 22:27:15 PST 2022
Author: Dmitry Vyukov
Date: 2022-11-24T07:27:09+01:00
New Revision: fbcdf4a4fb9e51039877cc92bb18407416a158d7
URL: https://github.com/llvm/llvm-project/commit/fbcdf4a4fb9e51039877cc92bb18407416a158d7
DIFF: https://github.com/llvm/llvm-project/commit/fbcdf4a4fb9e51039877cc92bb18407416a158d7.diff
LOG: tsan: intercept epoll_pwait2
It's a new syscall similar to epoll_pwait.
Add a similar interceptor for it and add synchronization
annotations in epoll_wait* syscall wrappers.
Testing this is problematic b/c it's not present in glibc
and the syscall itself may not be supported by the kernel.
Reviewed By: melver
Differential Revision: https://reviews.llvm.org/D138574
Added:
Modified:
compiler-rt/lib/sanitizer_common/sanitizer_common_syscalls.inc
compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp
Removed:
################################################################################
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common_syscalls.inc b/compiler-rt/lib/sanitizer_common/sanitizer_common_syscalls.inc
index 8c1ff7f65da47..e7cf7cfca1935 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_common_syscalls.inc
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_common_syscalls.inc
@@ -2106,6 +2106,7 @@ PRE_SYSCALL(epoll_wait)
POST_SYSCALL(epoll_wait)
(long res, long epfd, void *events, long maxevents, long timeout) {
if (res >= 0) {
+ COMMON_SYSCALL_FD_ACQUIRE(epfd);
if (events)
POST_WRITE(events, res * struct_epoll_event_sz);
}
@@ -2122,6 +2123,7 @@ POST_SYSCALL(epoll_pwait)
(long res, long epfd, void *events, long maxevents, long timeout,
const void *sigmask, long sigsetsize) {
if (res >= 0) {
+ COMMON_SYSCALL_FD_ACQUIRE(epfd);
if (events)
POST_WRITE(events, res * struct_epoll_event_sz);
}
@@ -2142,6 +2144,7 @@ POST_SYSCALL(epoll_pwait2)
const sanitizer_kernel_timespec *timeout, const void *sigmask,
long sigsetsize) {
if (res >= 0) {
+ COMMON_SYSCALL_FD_ACQUIRE(epfd);
if (events)
POST_WRITE(events, res * struct_epoll_event_sz);
}
diff --git a/compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp b/compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp
index c557d5ddc6abc..72a771d762da6 100644
--- a/compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp
+++ b/compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp
@@ -1943,12 +1943,24 @@ TSAN_INTERCEPTOR(int, epoll_pwait, int epfd, void *ev, int cnt, int timeout,
return res;
}
-#define TSAN_MAYBE_INTERCEPT_EPOLL \
- TSAN_INTERCEPT(epoll_create); \
- TSAN_INTERCEPT(epoll_create1); \
- TSAN_INTERCEPT(epoll_ctl); \
- TSAN_INTERCEPT(epoll_wait); \
- TSAN_INTERCEPT(epoll_pwait)
+TSAN_INTERCEPTOR(int, epoll_pwait2, int epfd, void *ev, int cnt, void *timeout,
+ void *sigmask) {
+ SCOPED_TSAN_INTERCEPTOR(epoll_pwait2, epfd, ev, cnt, timeout, sigmask);
+ if (epfd >= 0)
+ FdAccess(thr, pc, epfd);
+ int res = BLOCK_REAL(epoll_pwait2)(epfd, ev, cnt, timeout, sigmask);
+ if (res > 0 && epfd >= 0)
+ FdAcquire(thr, pc, epfd);
+ return res;
+}
+
+# define TSAN_MAYBE_INTERCEPT_EPOLL \
+ TSAN_INTERCEPT(epoll_create); \
+ TSAN_INTERCEPT(epoll_create1); \
+ TSAN_INTERCEPT(epoll_ctl); \
+ TSAN_INTERCEPT(epoll_wait); \
+ TSAN_INTERCEPT(epoll_pwait); \
+ TSAN_INTERCEPT(epoll_pwait2)
#else
#define TSAN_MAYBE_INTERCEPT_EPOLL
#endif
More information about the llvm-commits
mailing list