diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common_syscalls.inc b/compiler-rt/lib/sanitizer_common/sanitizer_common_syscalls.inc --- a/compiler-rt/lib/sanitizer_common/sanitizer_common_syscalls.inc +++ b/compiler-rt/lib/sanitizer_common/sanitizer_common_syscalls.inc @@ -2107,7 +2107,7 @@ (long res, long epfd, void *events, long maxevents, long timeout) { if (res >= 0) { if (events) - POST_WRITE(events, struct_epoll_event_sz); + POST_WRITE(events, res * struct_epoll_event_sz); } } @@ -2123,7 +2123,7 @@ const void *sigmask, long sigsetsize) { if (res >= 0) { if (events) - POST_WRITE(events, struct_epoll_event_sz); + POST_WRITE(events, res * struct_epoll_event_sz); } } diff --git a/compiler-rt/test/msan/Linux/syscalls.cpp b/compiler-rt/test/msan/Linux/syscalls.cpp --- a/compiler-rt/test/msan/Linux/syscalls.cpp +++ b/compiler-rt/test/msan/Linux/syscalls.cpp @@ -9,6 +9,7 @@ #include #include +#include #include #include #include @@ -128,5 +129,17 @@ __sanitizer_syscall_post_sigaltstack(0, nullptr, (stack_t *)buf); assert(__msan_test_shadow(buf, sizeof(buf)) == sizeof(stack_t)); + __msan_poison(buf, sizeof(buf)); + long max_events = sizeof(buf) / sizeof(epoll_event); + __sanitizer_syscall_pre_epoll_wait(0, buf, max_events, 0); + __sanitizer_syscall_post_epoll_wait(max_events, 0, buf, max_events, 0); + assert(__msan_test_shadow(buf, sizeof(buf)) == max_events * sizeof(epoll_event)); + + __msan_poison(buf, sizeof(buf)); + sigset_t sigset = {}; + __sanitizer_syscall_pre_epoll_pwait(0, buf, max_events, 0, &sigset, sizeof(sigset)); + __sanitizer_syscall_post_epoll_pwait(max_events, 0, buf, max_events, 0, &sigset, sizeof(sigset)); + assert(__msan_test_shadow(buf, sizeof(buf)) == max_events * sizeof(epoll_event)); + return 0; }