Mark Wielaard 3e6dff
commit 5f00db054a6f59502e9deeeb59ace2261207ee31
Mark Wielaard 3e6dff
Author: Alexandra Hajkova <ahajkova@redhat.com>
Mark Wielaard 3e6dff
Date:   Thu May 2 08:24:02 2019 -0400
Mark Wielaard 3e6dff
Mark Wielaard 3e6dff
    Add support for the copy_file_range syscall
Mark Wielaard 3e6dff
    
Mark Wielaard 3e6dff
    Support amd64, x86, arm64, ppc64, ppc32 and s390x architectures.
Mark Wielaard 3e6dff
    Also add sys-copy_file_range test case.
Mark Wielaard 3e6dff
Mark Wielaard 3e6dff
diff --git a/configure.ac b/configure.ac
Mark Wielaard 3e6dff
index d043ce3..3528925 100755
Mark Wielaard 3e6dff
--- a/configure.ac
Mark Wielaard 3e6dff
+++ b/configure.ac
Mark Wielaard 3e6dff
@@ -4172,6 +4172,7 @@ AC_CHECK_FUNCS([     \
Mark Wielaard 3e6dff
         utimensat    \
Mark Wielaard 3e6dff
         process_vm_readv  \
Mark Wielaard 3e6dff
         process_vm_writev \
Mark Wielaard 3e6dff
+        copy_file_range \
Mark Wielaard 3e6dff
         ])
Mark Wielaard 3e6dff
 
Mark Wielaard 3e6dff
 # AC_CHECK_LIB adds any library found to the variable LIBS, and links these
Mark Wielaard 3e6dff
@@ -4187,6 +4188,8 @@ AM_CONDITIONAL([HAVE_PTHREAD_SPINLOCK],
Mark Wielaard 3e6dff
                [test x$ac_cv_func_pthread_spin_lock = xyes])
Mark Wielaard 3e6dff
 AM_CONDITIONAL([HAVE_PTHREAD_SETNAME_NP],
Mark Wielaard 3e6dff
                [test x$ac_cv_func_pthread_setname_np = xyes])
Mark Wielaard 3e6dff
+AM_CONDITIONAL([HAVE_COPY_FILE_RANGE],
Mark Wielaard 3e6dff
+               [test x$ac_cv_func_copy_file_range = xyes])
Mark Wielaard 3e6dff
 
Mark Wielaard 3e6dff
 if test x$VGCONF_PLATFORM_PRI_CAPS = xMIPS32_LINUX \
Mark Wielaard 3e6dff
      -o x$VGCONF_PLATFORM_PRI_CAPS = xMIPS64_LINUX ; then
Mark Wielaard 3e6dff
diff --git a/coregrind/m_syswrap/priv_syswrap-linux.h b/coregrind/m_syswrap/priv_syswrap-linux.h
Mark Wielaard 3e6dff
index f76191a..1edf9eb 100644
Mark Wielaard 3e6dff
--- a/coregrind/m_syswrap/priv_syswrap-linux.h
Mark Wielaard 3e6dff
+++ b/coregrind/m_syswrap/priv_syswrap-linux.h
Mark Wielaard 3e6dff
@@ -379,6 +379,7 @@ DECL_TEMPLATE(linux, sys_getsockname);
Mark Wielaard 3e6dff
 DECL_TEMPLATE(linux, sys_getpeername);
Mark Wielaard 3e6dff
 DECL_TEMPLATE(linux, sys_socketpair);
Mark Wielaard 3e6dff
 DECL_TEMPLATE(linux, sys_kcmp);
Mark Wielaard 3e6dff
+DECL_TEMPLATE(linux, sys_copy_file_range);
Mark Wielaard 3e6dff
 
Mark Wielaard 3e6dff
 // Some arch specific functions called from syswrap-linux.c
Mark Wielaard 3e6dff
 extern Int do_syscall_clone_x86_linux ( Word (*fn)(void *), 
Mark Wielaard 3e6dff
diff --git a/coregrind/m_syswrap/syswrap-amd64-linux.c b/coregrind/m_syswrap/syswrap-amd64-linux.c
Mark Wielaard 3e6dff
index 30e7d0e..0c1d8d1 100644
Mark Wielaard 3e6dff
--- a/coregrind/m_syswrap/syswrap-amd64-linux.c
Mark Wielaard 3e6dff
+++ b/coregrind/m_syswrap/syswrap-amd64-linux.c
Mark Wielaard 3e6dff
@@ -863,6 +863,8 @@ static SyscallTableEntry syscall_table[] = {
Mark Wielaard 3e6dff
    LINXY(__NR_statx,             sys_statx),             // 332
Mark Wielaard 3e6dff
 
Mark Wielaard 3e6dff
    LINX_(__NR_membarrier,        sys_membarrier),        // 324
Mark Wielaard 3e6dff
+
Mark Wielaard 3e6dff
+   LINX_(__NR_copy_file_range,   sys_copy_file_range),   // 326
Mark Wielaard 3e6dff
 };
Mark Wielaard 3e6dff
 
Mark Wielaard 3e6dff
 SyscallTableEntry* ML_(get_linux_syscall_entry) ( UInt sysno )
Mark Wielaard 3e6dff
diff --git a/coregrind/m_syswrap/syswrap-arm64-linux.c b/coregrind/m_syswrap/syswrap-arm64-linux.c
Mark Wielaard 3e6dff
index 290320a..f66be2d 100644
Mark Wielaard 3e6dff
--- a/coregrind/m_syswrap/syswrap-arm64-linux.c
Mark Wielaard 3e6dff
+++ b/coregrind/m_syswrap/syswrap-arm64-linux.c
Mark Wielaard 3e6dff
@@ -819,7 +819,7 @@ static SyscallTableEntry syscall_main_table[] = {
Mark Wielaard 3e6dff
    //   (__NR_userfaultfd,       sys_ni_syscall),        // 282
Mark Wielaard 3e6dff
    LINX_(__NR_membarrier,        sys_membarrier),        // 283
Mark Wielaard 3e6dff
    //   (__NR_mlock2,            sys_ni_syscall),        // 284
Mark Wielaard 3e6dff
-   //   (__NR_copy_file_range,   sys_ni_syscall),        // 285
Mark Wielaard 3e6dff
+   LINX_(__NR_copy_file_range,   sys_copy_file_range),   // 285
Mark Wielaard 3e6dff
    //   (__NR_preadv2,           sys_ni_syscall),        // 286
Mark Wielaard 3e6dff
    //   (__NR_pwritev2,          sys_ni_syscall),        // 287
Mark Wielaard 3e6dff
    //   (__NR_pkey_mprotect,     sys_ni_syscall),        // 288
Mark Wielaard 3e6dff
diff --git a/coregrind/m_syswrap/syswrap-linux.c b/coregrind/m_syswrap/syswrap-linux.c
Mark Wielaard 3e6dff
index 73ef98d..cd0ee74 100644
Mark Wielaard 3e6dff
--- a/coregrind/m_syswrap/syswrap-linux.c
Mark Wielaard 3e6dff
+++ b/coregrind/m_syswrap/syswrap-linux.c
Mark Wielaard 3e6dff
@@ -12093,6 +12093,36 @@ POST(sys_bpf)
Mark Wielaard 3e6dff
    }
Mark Wielaard 3e6dff
 }
Mark Wielaard 3e6dff
 
Mark Wielaard 3e6dff
+PRE(sys_copy_file_range)
Mark Wielaard 3e6dff
+{
Mark Wielaard 3e6dff
+  PRINT("sys_copy_file_range (%lu, %lu, %lu, %lu, %lu, %lu)", ARG1, ARG2, ARG3,
Mark Wielaard 3e6dff
+        ARG4, ARG5, ARG6);
Mark Wielaard 3e6dff
+
Mark Wielaard 3e6dff
+  PRE_REG_READ6(vki_size_t, "copy_file_range",
Mark Wielaard 3e6dff
+                int, "fd_in",
Mark Wielaard 3e6dff
+                vki_loff_t *, "off_in",
Mark Wielaard 3e6dff
+                int, "fd_out",
Mark Wielaard 3e6dff
+                vki_loff_t *, "off_out",
Mark Wielaard 3e6dff
+                vki_size_t, "len",
Mark Wielaard 3e6dff
+                unsigned int, "flags");
Mark Wielaard 3e6dff
+
Mark Wielaard 3e6dff
+  /* File descriptors are "specially" tracked by valgrind.
Mark Wielaard 3e6dff
+     valgrind itself uses some, so make sure someone didn't
Mark Wielaard 3e6dff
+     put in one of our own...  */
Mark Wielaard 3e6dff
+  if (!ML_(fd_allowed)(ARG1, "copy_file_range(fd_in)", tid, False) ||
Mark Wielaard 3e6dff
+      !ML_(fd_allowed)(ARG3, "copy_file_range(fd_in)", tid, False)) {
Mark Wielaard 3e6dff
+     SET_STATUS_Failure( VKI_EBADF );
Mark Wielaard 3e6dff
+  } else {
Mark Wielaard 3e6dff
+     /* Now see if the offsets are defined. PRE_MEM_READ will
Mark Wielaard 3e6dff
+        double check it can dereference them. */
Mark Wielaard 3e6dff
+     if (ARG2 != 0)
Mark Wielaard 3e6dff
+        PRE_MEM_READ( "copy_file_range(off_in)", ARG2, sizeof(vki_loff_t));
Mark Wielaard 3e6dff
+     if (ARG4 != 0)
Mark Wielaard 3e6dff
+        PRE_MEM_READ( "copy_file_range(off_out)", ARG4, sizeof(vki_loff_t));
Mark Wielaard 3e6dff
+  }
Mark Wielaard 3e6dff
+}
Mark Wielaard 3e6dff
+
Mark Wielaard 3e6dff
+
Mark Wielaard 3e6dff
 #undef PRE
Mark Wielaard 3e6dff
 #undef POST
Mark Wielaard 3e6dff
 
Mark Wielaard 3e6dff
diff --git a/coregrind/m_syswrap/syswrap-ppc32-linux.c b/coregrind/m_syswrap/syswrap-ppc32-linux.c
Mark Wielaard 3e6dff
index f812f1f..71f208d 100644
Mark Wielaard 3e6dff
--- a/coregrind/m_syswrap/syswrap-ppc32-linux.c
Mark Wielaard 3e6dff
+++ b/coregrind/m_syswrap/syswrap-ppc32-linux.c
Mark Wielaard 3e6dff
@@ -1021,6 +1021,8 @@ static SyscallTableEntry syscall_table[] = {
Mark Wielaard 3e6dff
    LINXY(__NR_getrandom,         sys_getrandom),        // 359
Mark Wielaard 3e6dff
    LINXY(__NR_memfd_create,      sys_memfd_create),     // 360
Mark Wielaard 3e6dff
 
Mark Wielaard 3e6dff
+   LINX_(__NR_copy_file_range,   sys_copy_file_range),  // 379
Mark Wielaard 3e6dff
+
Mark Wielaard 3e6dff
    LINXY(__NR_statx,             sys_statx),            // 383
Mark Wielaard 3e6dff
 };
Mark Wielaard 3e6dff
 
Mark Wielaard 3e6dff
diff --git a/coregrind/m_syswrap/syswrap-ppc64-linux.c b/coregrind/m_syswrap/syswrap-ppc64-linux.c
Mark Wielaard 3e6dff
index eada099..1a42c1f 100644
Mark Wielaard 3e6dff
--- a/coregrind/m_syswrap/syswrap-ppc64-linux.c
Mark Wielaard 3e6dff
+++ b/coregrind/m_syswrap/syswrap-ppc64-linux.c
Mark Wielaard 3e6dff
@@ -1007,6 +1007,8 @@ static SyscallTableEntry syscall_table[] = {
Mark Wielaard 3e6dff
 
Mark Wielaard 3e6dff
    LINX_(__NR_membarrier,        sys_membarrier),       // 365
Mark Wielaard 3e6dff
 
Mark Wielaard 3e6dff
+   LINX_(__NR_copy_file_range,   sys_copy_file_range),  // 379
Mark Wielaard 3e6dff
+
Mark Wielaard 3e6dff
    LINXY(__NR_statx,             sys_statx),            // 383
Mark Wielaard 3e6dff
 };
Mark Wielaard 3e6dff
 
Mark Wielaard 3e6dff
diff --git a/coregrind/m_syswrap/syswrap-s390x-linux.c b/coregrind/m_syswrap/syswrap-s390x-linux.c
Mark Wielaard 3e6dff
index ad78384..41ada8d 100644
Mark Wielaard 3e6dff
--- a/coregrind/m_syswrap/syswrap-s390x-linux.c
Mark Wielaard 3e6dff
+++ b/coregrind/m_syswrap/syswrap-s390x-linux.c
Mark Wielaard 3e6dff
@@ -854,6 +854,8 @@ static SyscallTableEntry syscall_table[] = {
Mark Wielaard 3e6dff
    LINXY(__NR_recvmsg, sys_recvmsg),                                  // 372
Mark Wielaard 3e6dff
    LINX_(__NR_shutdown, sys_shutdown),                                // 373
Mark Wielaard 3e6dff
 
Mark Wielaard 3e6dff
+   LINX_(__NR_copy_file_range, sys_copy_file_range),                  // 375
Mark Wielaard 3e6dff
+
Mark Wielaard 3e6dff
    LINXY(__NR_statx, sys_statx),                                      // 379
Mark Wielaard 3e6dff
 };
Mark Wielaard 3e6dff
 
Mark Wielaard 3e6dff
diff --git a/coregrind/m_syswrap/syswrap-x86-linux.c b/coregrind/m_syswrap/syswrap-x86-linux.c
Mark Wielaard 3e6dff
index f05619e..f8d97ea 100644
Mark Wielaard 3e6dff
--- a/coregrind/m_syswrap/syswrap-x86-linux.c
Mark Wielaard 3e6dff
+++ b/coregrind/m_syswrap/syswrap-x86-linux.c
Mark Wielaard 3e6dff
@@ -1608,6 +1608,8 @@ static SyscallTableEntry syscall_table[] = {
Mark Wielaard 3e6dff
 
Mark Wielaard 3e6dff
    LINX_(__NR_membarrier,        sys_membarrier),       // 375
Mark Wielaard 3e6dff
 
Mark Wielaard 3e6dff
+   LINX_(__NR_copy_file_range,   sys_copy_file_range),   // 377
Mark Wielaard 3e6dff
+
Mark Wielaard 3e6dff
    LINXY(__NR_statx,             sys_statx),            // 383
Mark Wielaard 3e6dff
 
Mark Wielaard 3e6dff
    /* Explicitly not supported on i386 yet. */
Mark Wielaard 3e6dff
diff --git a/memcheck/tests/linux/Makefile.am b/memcheck/tests/linux/Makefile.am
Mark Wielaard 3e6dff
index d7515d9..00e99a5 100644
Mark Wielaard 3e6dff
--- a/memcheck/tests/linux/Makefile.am
Mark Wielaard 3e6dff
+++ b/memcheck/tests/linux/Makefile.am
Mark Wielaard 3e6dff
@@ -20,6 +20,7 @@ EXTRA_DIST = \
Mark Wielaard 3e6dff
 	stack_switch.stderr.exp stack_switch.vgtest \
Mark Wielaard 3e6dff
 	syscalls-2007.vgtest syscalls-2007.stderr.exp \
Mark Wielaard 3e6dff
 	syslog-syscall.vgtest syslog-syscall.stderr.exp \
Mark Wielaard 3e6dff
+	sys-copy_file_range.vgtest sys-copy_file_range.stderr.exp \
Mark Wielaard 3e6dff
 	sys-openat.vgtest sys-openat.stderr.exp sys-openat.stdout.exp \
Mark Wielaard 3e6dff
 	sys-statx.vgtest sys-statx.stderr.exp \
Mark Wielaard 3e6dff
 	timerfd-syscall.vgtest timerfd-syscall.stderr.exp \
Mark Wielaard 3e6dff
@@ -49,6 +50,10 @@ if HAVE_AT_FDCWD
Mark Wielaard 3e6dff
 check_PROGRAMS += sys-openat
Mark Wielaard 3e6dff
 endif
Mark Wielaard 3e6dff
 
Mark Wielaard 3e6dff
+if HAVE_COPY_FILE_RANGE
Mark Wielaard 3e6dff
+        check_PROGRAMS += sys-copy_file_range
Mark Wielaard 3e6dff
+endif
Mark Wielaard 3e6dff
+
Mark Wielaard 3e6dff
 AM_CFLAGS   += $(AM_FLAG_M3264_PRI)
Mark Wielaard 3e6dff
 AM_CXXFLAGS += $(AM_FLAG_M3264_PRI)
Mark Wielaard 3e6dff
 
Mark Wielaard 3e6dff
diff --git a/memcheck/tests/linux/sys-copy_file_range.c b/memcheck/tests/linux/sys-copy_file_range.c
Mark Wielaard 3e6dff
new file mode 100644
Mark Wielaard 3e6dff
index 0000000..83981c6
Mark Wielaard 3e6dff
--- /dev/null
Mark Wielaard 3e6dff
+++ b/memcheck/tests/linux/sys-copy_file_range.c
Mark Wielaard 3e6dff
@@ -0,0 +1,67 @@
Mark Wielaard 3e6dff
+#define _GNU_SOURCE
Mark Wielaard 3e6dff
+#include <fcntl.h>
Mark Wielaard 3e6dff
+#include <stdio.h>
Mark Wielaard 3e6dff
+#include <stdlib.h>
Mark Wielaard 3e6dff
+#include <sys/stat.h>
Mark Wielaard 3e6dff
+#include <sys/syscall.h>
Mark Wielaard 3e6dff
+#include <unistd.h>
Mark Wielaard 3e6dff
+
Mark Wielaard 3e6dff
+int main(int argc, char **argv)
Mark Wielaard 3e6dff
+{
Mark Wielaard 3e6dff
+    int fd_in, fd_out;
Mark Wielaard 3e6dff
+    struct stat stat;
Mark Wielaard 3e6dff
+    loff_t len, ret;
Mark Wielaard 3e6dff
+
Mark Wielaard 3e6dff
+    fd_in = open("copy_file_range_source", O_CREAT | O_RDWR);
Mark Wielaard 3e6dff
+    if (fd_in == -1) {
Mark Wielaard 3e6dff
+        perror("open copy_file_range_source");
Mark Wielaard 3e6dff
+        exit(EXIT_FAILURE);
Mark Wielaard 3e6dff
+    }
Mark Wielaard 3e6dff
+
Mark Wielaard 3e6dff
+    if (write(fd_in, "foo bar\n", 8) != 8) {
Mark Wielaard 3e6dff
+        perror("writing to the copy_file_range_source");
Mark Wielaard 3e6dff
+        exit(EXIT_FAILURE);
Mark Wielaard 3e6dff
+    }
Mark Wielaard 3e6dff
+    lseek(fd_in, 0, SEEK_SET);
Mark Wielaard 3e6dff
+
Mark Wielaard 3e6dff
+    if (fstat(fd_in, &stat) == -1) {
Mark Wielaard 3e6dff
+        perror("fstat");
Mark Wielaard 3e6dff
+        exit(EXIT_FAILURE);
Mark Wielaard 3e6dff
+    }
Mark Wielaard 3e6dff
+
Mark Wielaard 3e6dff
+    len = stat.st_size;
Mark Wielaard 3e6dff
+
Mark Wielaard 3e6dff
+    fd_out = open("copy_file_range_dest", O_CREAT | O_WRONLY | O_TRUNC, 0644);
Mark Wielaard 3e6dff
+    if (fd_out == -1) {
Mark Wielaard 3e6dff
+        perror("open copy_file_range_dest");
Mark Wielaard 3e6dff
+        exit(EXIT_FAILURE);
Mark Wielaard 3e6dff
+    }
Mark Wielaard 3e6dff
+
Mark Wielaard 3e6dff
+    /* Check copy_file_range called with the correct arguments works. */
Mark Wielaard 3e6dff
+    do {
Mark Wielaard 3e6dff
+        ret = copy_file_range(fd_in, NULL, fd_out, NULL, len, 0);
Mark Wielaard 3e6dff
+        if (ret == -1) {
Mark Wielaard 3e6dff
+            perror("copy_file_range");
Mark Wielaard 3e6dff
+            exit(EXIT_FAILURE);
Mark Wielaard 3e6dff
+        }
Mark Wielaard 3e6dff
+
Mark Wielaard 3e6dff
+        len -= ret;
Mark Wielaard 3e6dff
+    } while (len > 0);
Mark Wielaard 3e6dff
+
Mark Wielaard 3e6dff
+    /* Check valgrind will produce expected warnings for the
Mark Wielaard 3e6dff
+       various wrong arguments. */
Mark Wielaard 3e6dff
+    do {
Mark Wielaard 3e6dff
+        void *t;
Mark Wielaard 3e6dff
+        void *z = (void *) -1;
Mark Wielaard 3e6dff
+
Mark Wielaard 3e6dff
+        ret = copy_file_range(fd_in, t, fd_out, NULL, len, 0);
Mark Wielaard 3e6dff
+        ret = copy_file_range(fd_in, NULL, fd_out, z, len, 0);
Mark Wielaard 3e6dff
+        ret = copy_file_range(- 1, NULL, - 1, NULL, len, 0);
Mark Wielaard 3e6dff
+    } while (0);
Mark Wielaard 3e6dff
+
Mark Wielaard 3e6dff
+    close(fd_in);
Mark Wielaard 3e6dff
+    close(fd_out);
Mark Wielaard 3e6dff
+    unlink("copy_file_range_source");
Mark Wielaard 3e6dff
+    unlink("copy_file_range_dest");
Mark Wielaard 3e6dff
+    exit(EXIT_SUCCESS);
Mark Wielaard 3e6dff
+}
Mark Wielaard 3e6dff
diff --git a/memcheck/tests/linux/sys-copy_file_range.stderr.exp b/memcheck/tests/linux/sys-copy_file_range.stderr.exp
Mark Wielaard 3e6dff
new file mode 100644
Mark Wielaard 3e6dff
index 0000000..1aa4dc2
Mark Wielaard 3e6dff
--- /dev/null
Mark Wielaard 3e6dff
+++ b/memcheck/tests/linux/sys-copy_file_range.stderr.exp
Mark Wielaard 3e6dff
@@ -0,0 +1,21 @@
Mark Wielaard 3e6dff
+
Mark Wielaard 3e6dff
+Syscall param copy_file_range("off_in") contains uninitialised byte(s)
Mark Wielaard 3e6dff
+   ...
Mark Wielaard 3e6dff
+   by 0x........: main (sys-copy_file_range.c:57)
Mark Wielaard 3e6dff
+
Mark Wielaard 3e6dff
+Syscall param copy_file_range(off_out) points to unaddressable byte(s)
Mark Wielaard 3e6dff
+   ...
Mark Wielaard 3e6dff
+   by 0x........: main (sys-copy_file_range.c:58)
Mark Wielaard 3e6dff
+ Address 0x........ is not stack'd, malloc'd or (recently) free'd
Mark Wielaard 3e6dff
+
Mark Wielaard 3e6dff
+Warning: invalid file descriptor -1 in syscall copy_file_range(fd_in)()
Mark Wielaard 3e6dff
+
Mark Wielaard 3e6dff
+HEAP SUMMARY:
Mark Wielaard 3e6dff
+    in use at exit: 0 bytes in 0 blocks
Mark Wielaard 3e6dff
+  total heap usage: 0 allocs, 0 frees, 0 bytes allocated
Mark Wielaard 3e6dff
+
Mark Wielaard 3e6dff
+For a detailed leak analysis, rerun with: --leak-check=full
Mark Wielaard 3e6dff
+
Mark Wielaard 3e6dff
+Use --track-origins=yes to see where uninitialised values come from
Mark Wielaard 3e6dff
+For lists of detected and suppressed errors, rerun with: -s
Mark Wielaard 3e6dff
+ERROR SUMMARY: 2 errors from 2 contexts (suppressed: 0 from 0)
Mark Wielaard 3e6dff
diff --git a/memcheck/tests/linux/sys-copy_file_range.vgtest b/memcheck/tests/linux/sys-copy_file_range.vgtest
Mark Wielaard 3e6dff
new file mode 100644
Mark Wielaard 3e6dff
index 0000000..b7741e8
Mark Wielaard 3e6dff
--- /dev/null
Mark Wielaard 3e6dff
+++ b/memcheck/tests/linux/sys-copy_file_range.vgtest
Mark Wielaard 3e6dff
@@ -0,0 +1,2 @@
Mark Wielaard 3e6dff
+prereq: test -e sys-copy_file_range
Mark Wielaard 3e6dff
+prog: sys-copy_file_range
Mark Wielaard 3e6dff
commit bd27ad3ff31555484b7fdb310c4b033620882e44
Mark Wielaard 3e6dff
Author: Mark Wielaard <mark@klomp.org>
Mark Wielaard 3e6dff
Date:   Sun May 5 16:01:41 2019 +0200
Mark Wielaard 3e6dff
Mark Wielaard 3e6dff
    Hook linux copy_file_range syscall on arm.
Mark Wielaard 3e6dff
Mark Wielaard 3e6dff
diff --git a/coregrind/m_syswrap/syswrap-arm-linux.c b/coregrind/m_syswrap/syswrap-arm-linux.c
Mark Wielaard 3e6dff
index 9f1bdab..9ba0665 100644
Mark Wielaard 3e6dff
--- a/coregrind/m_syswrap/syswrap-arm-linux.c
Mark Wielaard 3e6dff
+++ b/coregrind/m_syswrap/syswrap-arm-linux.c
Mark Wielaard 3e6dff
@@ -1016,6 +1016,8 @@ static SyscallTableEntry syscall_main_table[] = {
Mark Wielaard 3e6dff
    LINXY(__NR_getrandom,         sys_getrandom),        // 384
Mark Wielaard 3e6dff
    LINXY(__NR_memfd_create,      sys_memfd_create),     // 385
Mark Wielaard 3e6dff
 
Mark Wielaard 3e6dff
+   LINX_(__NR_copy_file_range,   sys_copy_file_range),  // 391
Mark Wielaard 3e6dff
+
Mark Wielaard 3e6dff
    LINXY(__NR_statx,             sys_statx),            // 397
Mark Wielaard 3e6dff
 };
Mark Wielaard 3e6dff
 
Mark Wielaard cf1bb9
commit c212b72a63e43be323a4e028bbdbe8b023c22be8
Mark Wielaard cf1bb9
Author: Mark Wielaard <mark@klomp.org>
Mark Wielaard cf1bb9
Date:   Wed May 15 21:30:00 2019 +0200
Mark Wielaard cf1bb9
Mark Wielaard cf1bb9
    Explicitly make testcase variable for sys-copy_file_range undefined.
Mark Wielaard cf1bb9
    
Mark Wielaard cf1bb9
    On some systems an extra warning could occur when a variable in
Mark Wielaard cf1bb9
    the memcheck/tests/linux/sys-copy_file_range testcase was undefined,
Mark Wielaard cf1bb9
    but (accidentially) pointed to known bad memory. Fix by defining the
Mark Wielaard cf1bb9
    variable as 0, but then marking it explicitly undefined using memcheck
Mark Wielaard cf1bb9
    VALGRIND_MAKE_MEM_UNDEFINED.
Mark Wielaard cf1bb9
    
Mark Wielaard cf1bb9
    Followup for https://bugs.kde.org/show_bug.cgi?id=407218
Mark Wielaard cf1bb9
Mark Wielaard cf1bb9
diff --git a/memcheck/tests/linux/sys-copy_file_range.c b/memcheck/tests/linux/sys-copy_file_range.c
Mark Wielaard cf1bb9
index 83981c6..589399c 100644
Mark Wielaard cf1bb9
--- a/memcheck/tests/linux/sys-copy_file_range.c
Mark Wielaard cf1bb9
+++ b/memcheck/tests/linux/sys-copy_file_range.c
Mark Wielaard cf1bb9
@@ -3,8 +3,8 @@
Mark Wielaard cf1bb9
 #include <stdio.h>
Mark Wielaard cf1bb9
 #include <stdlib.h>
Mark Wielaard cf1bb9
 #include <sys/stat.h>
Mark Wielaard cf1bb9
-#include <sys/syscall.h>
Mark Wielaard cf1bb9
 #include <unistd.h>
Mark Wielaard cf1bb9
+#include "../../memcheck.h"
Mark Wielaard cf1bb9
 
Mark Wielaard cf1bb9
 int main(int argc, char **argv)
Mark Wielaard cf1bb9
 {
Mark Wielaard cf1bb9
@@ -51,7 +51,7 @@ int main(int argc, char **argv)
Mark Wielaard cf1bb9
     /* Check valgrind will produce expected warnings for the
Mark Wielaard cf1bb9
        various wrong arguments. */
Mark Wielaard cf1bb9
     do {
Mark Wielaard cf1bb9
-        void *t;
Mark Wielaard cf1bb9
+        void *t = 0; VALGRIND_MAKE_MEM_UNDEFINED (&t, sizeof (void *));
Mark Wielaard cf1bb9
         void *z = (void *) -1;
Mark Wielaard cf1bb9
 
Mark Wielaard cf1bb9
         ret = copy_file_range(fd_in, t, fd_out, NULL, len, 0);
Mark Wielaard cf1bb9
commit 033d013bebeb3471c0da47060deb9a5771e6c913
Mark Wielaard cf1bb9
Author: Mark Wielaard <mark@klomp.org>
Mark Wielaard cf1bb9
Date:   Fri May 24 21:51:31 2019 +0200
Mark Wielaard cf1bb9
Mark Wielaard cf1bb9
    Fix memcheck/tests/linux/sys-copy_file_range open call (mode).
Mark Wielaard cf1bb9
    
Mark Wielaard cf1bb9
    sys-copy_file_range.c calls open with O_CREAT flag and so must provide
Mark Wielaard cf1bb9
    a mode argument. valgrind memcheck actually caught this ommission on
Mark Wielaard cf1bb9
    some arches (fedora rawhide i686 specifically).
Mark Wielaard cf1bb9
    
Mark Wielaard cf1bb9
    This is a small additional fixup for
Mark Wielaard cf1bb9
    https://bugs.kde.org/show_bug.cgi?id=407218
Mark Wielaard cf1bb9
Mark Wielaard cf1bb9
diff --git a/memcheck/tests/linux/sys-copy_file_range.c b/memcheck/tests/linux/sys-copy_file_range.c
Mark Wielaard cf1bb9
index 589399c..3022fa1 100644
Mark Wielaard cf1bb9
--- a/memcheck/tests/linux/sys-copy_file_range.c
Mark Wielaard cf1bb9
+++ b/memcheck/tests/linux/sys-copy_file_range.c
Mark Wielaard cf1bb9
@@ -12,7 +12,7 @@ int main(int argc, char **argv)
Mark Wielaard cf1bb9
     struct stat stat;
Mark Wielaard cf1bb9
     loff_t len, ret;
Mark Wielaard cf1bb9
 
Mark Wielaard cf1bb9
-    fd_in = open("copy_file_range_source", O_CREAT | O_RDWR);
Mark Wielaard cf1bb9
+    fd_in = open("copy_file_range_source", O_CREAT | O_RDWR, 0644);
Mark Wielaard cf1bb9
     if (fd_in == -1) {
Mark Wielaard cf1bb9
         perror("open copy_file_range_source");
Mark Wielaard cf1bb9
         exit(EXIT_FAILURE);