From: Paul Floyd Date: Sun, 10 Sep 2023 08:39:34 +0000 (+0200) Subject: FreeBSD: close_range versioning issues X-Git-Tag: VALGRIND_3_22_0~70 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ec86369da5e2404dbf265d06cc7ba8798c92b457;p=thirdparty%2Fvalgrind.git FreeBSD: close_range versioning issues 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. --- diff --git a/configure.ac b/configure.ac index 0ce6cccb6d..e6c3f79956 100755 --- a/configure.ac +++ b/configure.ac @@ -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 \ diff --git a/coregrind/m_syswrap/syswrap-freebsd.c b/coregrind/m_syswrap/syswrap-freebsd.c index 4f304091e5..ae11d2a78c 100644 --- a/coregrind/m_syswrap/syswrap-freebsd.c +++ b/coregrind/m_syswrap/syswrap-freebsd.c @@ -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 diff --git a/include/vki/vki-scnums-freebsd.h b/include/vki/vki-scnums-freebsd.h index 9e924c081f..12ce610007 100644 --- a/include/vki/vki-scnums-freebsd.h +++ b/include/vki/vki-scnums-freebsd.h @@ -645,10 +645,12 @@ #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 diff --git a/memcheck/tests/freebsd/Makefile.am b/memcheck/tests/freebsd/Makefile.am index f842feb7e0..ef6cedc03c 100644 --- a/memcheck/tests/freebsd/Makefile.am +++ b/memcheck/tests/freebsd/Makefile.am @@ -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@ diff --git a/memcheck/tests/freebsd/close_range.c b/memcheck/tests/freebsd/close_range.c index 5490c80ef6..1821648b72 100644 --- a/memcheck/tests/freebsd/close_range.c +++ b/memcheck/tests/freebsd/close_range.c @@ -6,6 +6,15 @@ #include #include +/* 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; diff --git a/memcheck/tests/freebsd/close_range.stderr.exp b/memcheck/tests/freebsd/close_range.stderr.exp index a7e9db6378..d286837060 100644 --- a/memcheck/tests/freebsd/close_range.stderr.exp +++ b/memcheck/tests/freebsd/close_range.stderr.exp @@ -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)