Blame SOURCES/valgrind-3.13.0-epoll_pwait.patch

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