]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
FreeBSD: close_range versioning issues
authorPaul Floyd <pjfloyd@wanadoo.fr>
Sun, 10 Sep 2023 08:39:34 +0000 (10:39 +0200)
committerPaul Floyd <pjfloyd@wanadoo.fr>
Sun, 10 Sep 2023 08:39:34 +0000 (10:39 +0200)
I mixed up a bit the syscall wrapper versioning.
Also for some reason the syscall has been backported to FreeBSD 12.2
but not the CLOEXEC flag. So I had to modify the testcase for that.

configure.ac
coregrind/m_syswrap/syswrap-freebsd.c
include/vki/vki-scnums-freebsd.h
memcheck/tests/freebsd/Makefile.am
memcheck/tests/freebsd/close_range.c
memcheck/tests/freebsd/close_range.stderr.exp

index 0ce6cccb6dafca94b8db2b3edf0a5ca24b76998b..e6c3f79956e196183004c6053b630d4bedb71e0a 100755 (executable)
@@ -4911,6 +4911,7 @@ AC_CHECK_FUNCS([     \
         strchrnul    \
         memrchr      \
         strndup      \
+        close_range
         ])
 
 # AC_CHECK_LIB adds any library found to the variable LIBS, and links these
@@ -4938,6 +4939,8 @@ AM_CONDITIONAL([HAVE_MEMFD_CREATE],
                [test x$ac_cv_func_memfd_create = xyes])
 AM_CONDITIONAL([HAVE_GETADDRINFO],
                [test x$ac_cv_func_getaddrinfo = xyes])
+AM_CONDITIONAL([HAVE_CLOSE_RANGE],
+               [test x$ac_cv_func_close_range = xyes])
 
 if test x$VGCONF_PLATFORM_PRI_CAPS = xMIPS32_LINUX \
      -o x$VGCONF_PLATFORM_PRI_CAPS = xMIPS64_LINUX \
index 4f304091e569e8f45b7b57e7559559a4815b735c..ae11d2a78cffb4051070e76683e8c1660fb154dc 100644 (file)
@@ -6667,6 +6667,15 @@ PRE(sys___realpathat)
    PRE_MEM_WRITE("__realpathat(buf)", (Addr)ARG3, ARG4);
 }
 
+POST(sys___realpathat)
+{
+   POST_MEM_WRITE((Addr)ARG3, ARG4);
+}
+
+#endif
+
+#if (FREEBSD_VERS >= FREEBSD_12_2)
+
 // SYS_sys_close_range   575
 // int close_range(close_range(u_int lowfd, u_int highfd, int flags);
 PRE(sys_close_range)
@@ -6735,11 +6744,9 @@ POST(sys_close_range)
           && fd != VG_(xml_output_sink).fd)
          ML_(record_fd_close)(fd);
 }
+#endif
 
-POST(sys___realpathat)
-{
-   POST_MEM_WRITE((Addr)ARG3, ARG4);
-}
+#if (FREEBSD_VERS >= FREEBSD_13_0)
 
 // SYS___specialfd 577
 // syscalls.master
index 9e924c081f17ed2b6acc76dd35512c94fdfc12bc..12ce610007874e0645efe310700ca1df0386e035 100644 (file)
 #define __NR_funlinkat           568
 #define __NR_copy_file_range     569
 #define __NR___sysctlbyname      570
+#if (FREEBSD_VERS >= FREEBSD_13_0)
 #define __NR_shm_open2           571
 #define __NR_shm_rename          572
 #define __NR_sigfastblock        573
 #define __NR___realpathat        574
+#endif
 #define __NR_close_range         575
 
 #endif
index f842feb7e0b926eb030920f37cd0159754b9bad5..ef6cedc03c1937093f153ac66a3c309b1ca0fe7e 100644 (file)
@@ -5,12 +5,25 @@ dist_noinst_SCRIPTS = filter_stderr filter_pts dump_stdout filter_sigwait \
        filter_scalar filter_realpathat filter_fstat filter_eventfd2
 
 EXTRA_DIST = \
+       access.vgtest \
+       access.stderr.exp \
+       aligned_alloc.vgtest aligned_alloc.stderr.exp \
+       aligned_alloc_xml.vgtest aligned_alloc_xml.stderr.exp \
+       aligned_allocs_supp.vgtest \
+       aligned_allocs_supp.stderr.exp \
+       aligned_allocs_supp.supp \
        capsicum.vgtest \
        capsicum.stderr.exp \
        chflags.vgtest\
        chflags.stderr.exp \
                chflags.stderr.exp-x86 \
+       chmod_chown.vgtest \
+       chmod_chown.stderr.exp \
        close_range.vgtest close_range.stderr.exp \
+       eventfd1.vgtest \
+       eventfd1.stderr.exp eventfd1.stdout.exp \
+       eventfd2.vgtest \
+       eventfd2.stderr.exp \
        extattr.vgtest \
        extattr.stderr.exp \
        get_set_login.vgtest \
@@ -56,10 +69,6 @@ EXTRA_DIST = \
        file_locking_wait6.stderr.exp \
        utimens.vgtest \
        utimens.stderr.exp \
-       access.vgtest \
-       access.stderr.exp \
-       chmod_chown.vgtest \
-       chmod_chown.stderr.exp \
        misc.vgtest \
        misc.stderr.exp \
        get_set_context.vgtest \
@@ -76,10 +85,6 @@ EXTRA_DIST = \
        realpathat.stderr.exp \
        scalar_13_plus.vgtest \
        scalar_13_plus.stderr.exp \
-       eventfd1.vgtest \
-       eventfd1.stderr.exp eventfd1.stdout.exp \
-       eventfd2.vgtest \
-       eventfd2.stderr.exp \
        errno_aligned_allocs.vgtest \
        errno_aligned_allocs.stderr.exp \
        setproctitle.vgtest \
@@ -103,20 +108,15 @@ EXTRA_DIST = \
         memalign.vgtest memalign.stderr.exp \
        bug470713.vgtest bug470713.stderr.exp \
                bug470713.stdout.exp \
-        aligned_allocs_supp.vgtest \
-       aligned_allocs_supp.stderr.exp \
-       aligned_allocs_supp.supp \
        memalign_supp.vgtest memalign_supp.stderr.exp \
        memalign_supp.supp \
-       aligned_alloc.vgtest aligned_alloc.stderr.exp \
-       aligned_alloc_xml.vgtest aligned_alloc_xml.stderr.exp \
        delete_sized_mismatch.vgtest \
        delete_sized_mismatch.stderr.exp \
        delete_sized_mismatch_xml.vgtest \
        delete_sized_mismatch_xml.stderr.exp
 
 check_PROGRAMS = \
-       close_range statfs pdfork_pdkill getfsstat inlinfo inlinfo_nested.so extattr \
+       statfs pdfork_pdkill getfsstat inlinfo inlinfo_nested.so extattr \
        sigwait chflags get_set_login revoke scalar capsicum getfh \
        linkat scalar_fork scalar_thr_exit scalar_abort2 scalar_pdfork \
        scalar_vfork stat file_locking_wait6 utimens access chmod_chown \
@@ -144,6 +144,10 @@ check_PROGRAMS += realpathat scalar_13_plus eventfd1 eventfd2
 scalar_13_plus_CFLAGS = ${AM_CFLAGS} -g
 endif
 
+if HAVE_CLOSE_RANGE
+check_PROGRAMS += close_range
+endif
+
 scalar_CFLAGS = ${AM_CFLAGS} -g
 
 aligned_alloc_CFLAGS = ${AM_CFLAGS} @FLAG_W_NO_NON_POWER_OF_TWO_ALIGNMENT@
index 5490c80ef67ae067c30d300188e284649c32e0ef..1821648b72a599e78cbab020beb539d06ca16e07 100644 (file)
@@ -6,6 +6,15 @@
 #include <fcntl.h>
 #include <assert.h>
 
+/* It looks like close_range was initially implemented for FreeBSD 13
+ * but without CLOSE_RANGE_CLOEXEC
+ * That implementation got back ported to FreeBSD 12.2
+ * And then CLOSE_RANGE_CLOEXEC added to 13 but not backported
+ * so 12 has close_range but not CLOSE_RANGE_CLOEXEC */
+#if !defined(CLOSE_RANGE_CLOEXEC)
+#define CLOSE_RANGE_CLOEXEC 1
+#endif
+
 int main(void)
 {
    struct rlimit rl;
index a7e9db63789db71112a4e1966112a28bfca12761..d286837060e43c841a4effe8744e624d4c0f4214 100644 (file)
@@ -1,12 +1,12 @@
 Syscall param close_range(lowfd) contains uninitialised byte(s)
    at 0x........: close_range (in /...libc...)
-   by 0x........: main (close_range.c:74)
+   by 0x........: main (close_range.c:83)
 
 Syscall param close_range(highfd) contains uninitialised byte(s)
    at 0x........: close_range (in /...libc...)
-   by 0x........: main (close_range.c:74)
+   by 0x........: main (close_range.c:83)
 
 Syscall param close_range(flags) contains uninitialised byte(s)
    at 0x........: close_range (in /...libc...)
-   by 0x........: main (close_range.c:74)
+   by 0x........: main (close_range.c:83)