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