]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Add syscall wrappers for FreeBSD funlinkat and copy_file_range
authorPaul Floyd <pjfloyd@wanadoo.fr>
Mon, 6 Jun 2022 20:32:53 +0000 (22:32 +0200)
committerPaul Floyd <pjfloyd@wanadoo.fr>
Mon, 6 Jun 2022 20:37:47 +0000 (22:37 +0200)
Aslo add a smoketest for /bin/cp, which uses copy_file_range

coregrind/m_syswrap/priv_syswrap-freebsd.h
coregrind/m_syswrap/syswrap-freebsd.c
none/tests/freebsd/Makefile.am
none/tests/freebsd/cp.stderr.exp [new file with mode: 0644]
none/tests/freebsd/cp.vgtest [new file with mode: 0644]

index 70fc431cc006cce15eec7e96e35698fcb38ec6f1..437047c5333aed44027498d3860a5c9285fbfba9 100644 (file)
@@ -526,8 +526,8 @@ DECL_TEMPLATE(freebsd, sys_fhreadlink) // 567
 
 #if (FREEBSD_VERS >= FREEBSD_12_2)
 
-// unimpl __NR_funlinkat           568
-// unimpl __NR_copy_file_range     569
+DECL_TEMPLATE(freebsd, sys_funlinkat) // 568
+DECL_TEMPLATE(freebsd, sys_copy_file_range) // 569
 DECL_TEMPLATE(freebsd, sys___sysctlbyname) // 570
 
 #if (FREEBSD_VERS >= FREEBSD_13_0)
index b8f5250b9474b8ed54762100ac1abad6f39c7b67..20718badd6556d0de48949a4bba85a7f0f20b274 100644 (file)
@@ -5200,7 +5200,8 @@ PRE(sys_symlinkat)
 PRE(sys_unlinkat)
 {
    *flags |= SfMayBlock;
-   PRINT("sys_unlinkat ( %" FMT_REGWORD "u, %#" FMT_REGWORD "x(%s) )", ARG1,ARG2,(char*)ARG2);
+   PRINT("sys_unlinkat ( %" FMT_REGWORD "u, %#" FMT_REGWORD "x(%s), %" FMT_REGWORD "u ",
+         ARG1, ARG2, (char*)ARG2, ARG3);
    PRE_REG_READ3(int, "unlinkat", int, fd, const char *, path, int, flag);
    PRE_MEM_RASCIIZ( "unlinkat(path)", ARG2 );
 }
@@ -6185,6 +6186,50 @@ POST(sys_fhreadlink)
 
 #if (FREEBSD_VERS >= FREEBSD_12_2)
 
+// SYS_unlinkat   568
+// int funlinkat(int dfd, const char *path, int fd, int flag);
+PRE(sys_funlinkat)
+{
+   *flags |= SfMayBlock;
+   PRINT("sys_funlinkat ( %" FMT_REGWORD "d, %#" FMT_REGWORD "x(%s), %" FMT_REGWORD "u, %" FMT_REGWORD"u )",
+         SARG1, ARG2, (char*)ARG2, ARG4, ARG5);
+   PRE_REG_READ4(int, "funlinkat", int, dfd, const char *, path, int, fd, int, flag);
+   PRE_MEM_RASCIIZ( "funlinkat(path)", ARG2 );
+}
+
+// SYS_copy_file_range 569
+// ssize_t copy_file_range(int infd, off_t *inoffp, int outfd, off_t *outoffp,
+//                         size_t len, unsigned int flags);
+PRE(sys_copy_file_range)
+{
+  PRINT("sys_copy_file_range (%" FMT_REGWORD"d, %#" FMT_REGWORD "x, %" FMT_REGWORD "d, %#" FMT_REGWORD "x(%s), %" FMT_REGWORD "d, %" FMT_REGWORD "d)",
+        SARG1, ARG2, SARG3, ARG4, (char*)ARG4, SARG5, SARG6);
+
+  PRE_REG_READ6(vki_ssize_t, "copy_file_range",
+                int, "infd",
+                vki_off_t *, "inoffp",
+                int, "outfd",
+                vki_off_t *, "outoffp",
+                vki_size_t, "len",
+                unsigned int, "flags");
+
+  /* File descriptors are "specially" tracked by valgrind.
+     valgrind itself uses some, so make sure someone didn't
+     put in one of our own...  */
+  if (!ML_(fd_allowed)(ARG1, "copy_file_range(infd)", tid, False) ||
+      !ML_(fd_allowed)(ARG3, "copy_file_range(infd)", tid, False)) {
+     SET_STATUS_Failure( VKI_EBADF );
+  } else {
+     /* Now see if the offsets are defined. PRE_MEM_READ will
+        double check it can dereference them. */
+     if (ARG2 != 0)
+        PRE_MEM_READ( "copy_file_range(inoffp)", ARG2, sizeof(vki_off_t));
+     if (ARG4 != 0)
+        PRE_MEM_READ( "copy_file_range(outoffp)", ARG4, sizeof(vki_off_t));
+  }
+}
+
+
 // SYS___sysctlbyname 570
 // int sysctlbyname(const char *name, void *oldp, size_t *oldlenp,
 //                  const void *newp, size_t newlen);
@@ -7031,8 +7076,8 @@ const SyscallTableEntry ML_(syscall_table)[] = {
 #endif // FREEBSD_VERS >= FREEBSD_12
 
 #if (FREEBSD_VERS >= FREEBSD_12_2)
-   // unimpl __NR_funlinkat           568
-   // unimpl __NR_copy_file_range     569
+   BSDX_(__NR_funlinkat,        sys_funlinkat),         // 568
+   BSDX_(__NR_copy_file_range,  sys_copy_file_range),   // 569
    BSDXY(__NR___sysctlbyname,   sys___sysctlbyname),    // 570
 
 #if (FREEBSD_VERS >= FREEBSD_13_0)
index 4b94071b4bc924eb4731475f958a1381e23332ee..4a29928238107a48d93b5fe250afd540995793a9 100644 (file)
@@ -8,6 +8,8 @@ EXTRA_DIST = \
        auxv.stderr.exp-32on64 \
        auxv.stderr.exp-freebsd13 \
        auxv.stderr.exp-freebsd131 \
+       cp.vgtest \
+       cp.stderr.exp \
        osrel.vgtest \
        osrel.stderr.exp \
        osrel.stdout.exp \
diff --git a/none/tests/freebsd/cp.stderr.exp b/none/tests/freebsd/cp.stderr.exp
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/none/tests/freebsd/cp.vgtest b/none/tests/freebsd/cp.vgtest
new file mode 100644 (file)
index 0000000..931fffb
--- /dev/null
@@ -0,0 +1,7 @@
+# basic smoke test, but even this can fail
+# the copy_file_range syscall was added in FreeBSD 12
+# and then used in the cp command
+prog: /bin/cp
+args: cp.vgtest cp.out
+vgopts: -q
+cleanup: rm cp.out