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
This commit is contained in:
Dmitry Vyukov 2022-11-23 16:20:29 +01:00
parent 875adb4007
commit fbcdf4a4fb
2 changed files with 21 additions and 6 deletions

View File

@ -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);
}

View File

@ -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