1af9e5
commit 79865f0eed7cf0e0ad687ee0a59d59a1d505b514
1af9e5
Author: mjw <mjw@a5019735-40e9-0310-863c-91ae7b9d1cf9>
1af9e5
Date:   Sat Jun 17 13:49:22 2017 +0000
1af9e5
1af9e5
    epoll_pwait can have a NULL sigmask.
1af9e5
    
1af9e5
    According to the epoll_pwait(2) man page:
1af9e5
    
1af9e5
           The  sigmask  argument  may  be  specified  as  NULL,  in  which  case
1af9e5
           epoll_pwait() is equivalent to epoll_wait().
1af9e5
    
1af9e5
    But doing that under valgrind gives:
1af9e5
    
1af9e5
    ==13887== Syscall param epoll_pwait(sigmask) points to unaddressable byte(s)
1af9e5
    ==13887==    at 0x4F2B940: epoll_pwait (epoll_pwait.c:43)
1af9e5
    ==13887==    by 0x400ADE: main (syscalls-2007.c:89)
1af9e5
    ==13887==  Address 0x0 is not stack'd, malloc'd or (recently) free'd
1af9e5
    
1af9e5
    This is because the sys_epoll_pwait wrapper has:
1af9e5
    
1af9e5
       if (ARG4)
1af9e5
          PRE_MEM_READ( "epoll_pwait(sigmask)", ARG5, sizeof(vki_sigset_t) );
1af9e5
    
1af9e5
    Which looks like a typo (ARG4 is timeout and ARG5 is sigmask).
1af9e5
    
1af9e5
    This shows up with newer glibc which translates an epoll_wait call into
1af9e5
    an epoll_pwait call with NULL sigmask.
1af9e5
    
1af9e5
    Fix typo and add a testcase.
1af9e5
    
1af9e5
    https://bugs.kde.org/show_bug.cgi?id=381289
1af9e5
    
1af9e5
    git-svn-id: svn://svn.valgrind.org/valgrind/trunk@16451 a5019735-40e9-0310-863c-91ae7b9d1cf9
1af9e5
1af9e5
diff --git a/coregrind/m_syswrap/syswrap-linux.c b/coregrind/m_syswrap/syswrap-linux.c
1af9e5
index 26e02fd..4120c1d 100644
1af9e5
--- a/coregrind/m_syswrap/syswrap-linux.c
1af9e5
+++ b/coregrind/m_syswrap/syswrap-linux.c
1af9e5
@@ -1901,7 +1901,7 @@ PRE(sys_epoll_pwait)
1af9e5
                  int, maxevents, int, timeout, vki_sigset_t *, sigmask,
1af9e5
                  vki_size_t, sigsetsize);
1af9e5
    PRE_MEM_WRITE( "epoll_pwait(events)", ARG2, sizeof(struct vki_epoll_event)*ARG3);
1af9e5
-   if (ARG4)
1af9e5
+   if (ARG5)
1af9e5
       PRE_MEM_READ( "epoll_pwait(sigmask)", ARG5, sizeof(vki_sigset_t) );
1af9e5
 }
1af9e5
 POST(sys_epoll_pwait)
1af9e5
diff --git a/memcheck/tests/linux/syscalls-2007.c b/memcheck/tests/linux/syscalls-2007.c
1af9e5
index b61c6d5..5494623 100644
1af9e5
--- a/memcheck/tests/linux/syscalls-2007.c
1af9e5
+++ b/memcheck/tests/linux/syscalls-2007.c
1af9e5
@@ -79,5 +79,16 @@ int main (void)
1af9e5
   }
1af9e5
 #endif
1af9e5
 
1af9e5
+#if defined(HAVE_EPOLL_CREATE) && defined(HAVE_EPOLL_PWAIT)
1af9e5
+  {
1af9e5
+    int fd3;
1af9e5
+    struct epoll_event evs[10];
1af9e5
+
1af9e5
+    fd3 = epoll_create (10);
1af9e5
+    /* epoll_pwait can take a NULL sigmask. */
1af9e5
+    epoll_pwait (fd3, evs, 10, 1, NULL);
1af9e5
+  }
1af9e5
+#endif
1af9e5
+
1af9e5
   return 0;
1af9e5
 }