From: Paul Floyd Date: Sun, 17 Sep 2023 09:50:54 +0000 (+0200) Subject: FreeBSD: add syscall wrapper for membarrier (added in FreeBSD 15) X-Git-Tag: VALGRIND_3_22_0~61 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=22069cd2da980dd88a9c3e36c9a3b371c67e1857;p=thirdparty%2Fvalgrind.git FreeBSD: add syscall wrapper for membarrier (added in FreeBSD 15) I also noticed that the Linux membarrier syscall wrapper is out of date. It only takes one argument. Depending on the kernel version it can also take 2 or 3 arguments (3 being the latest). --- diff --git a/NEWS b/NEWS index 736e33baf5..cf0b93ca4e 100644 --- a/NEWS +++ b/NEWS @@ -22,8 +22,8 @@ AMD64/macOS 10.13 and nanoMIPS/Linux. * Support has been added for FreeBSD 14 and FreeBSD 15. * Add support for the folllowing FreeBSD system calls: - close_range, kqueuex, timerfd_create, timerfd_settime and - timerfd_gettime (all added in FreeBSD 15). + close_range, kqueuex, membarrier, timerfd_create, + timerfd_settime and timerfd_gettime (all added in FreeBSD 15). * ==================== TOOL CHANGES =================== diff --git a/coregrind/m_syswrap/priv_syswrap-freebsd.h b/coregrind/m_syswrap/priv_syswrap-freebsd.h index b02d9fb4a5..5dcdc376a3 100644 --- a/coregrind/m_syswrap/priv_syswrap-freebsd.h +++ b/coregrind/m_syswrap/priv_syswrap-freebsd.h @@ -563,7 +563,7 @@ DECL_TEMPLATE(freebsd, sys_swapoff) // 582 #if (FREEBSD_VERS >= FREEBSD_15) DECL_TEMPLATE(freebsd, sys_kqueuex); // 583 -// unimpl __NR_membarrier 584 +DECL_TEMPLATE(freebsd, sys_membarrier); // 584 DECL_TEMPLATE(freebsd, sys_timerfd_create); // 585 DECL_TEMPLATE(freebsd, sys_timerfd_gettime); // 586 DECL_TEMPLATE(freebsd, sys_timerfd_settime); // 587 diff --git a/coregrind/m_syswrap/syswrap-freebsd.c b/coregrind/m_syswrap/syswrap-freebsd.c index fda60920c2..3efb64a43f 100644 --- a/coregrind/m_syswrap/syswrap-freebsd.c +++ b/coregrind/m_syswrap/syswrap-freebsd.c @@ -6798,7 +6798,17 @@ POST(sys_kqueuex) } } -// SYS_membarrier 584 unimpl +// SYS_membarrier 584 +// syscalls.master +// int membarrier(int cmd, unsigned flags, int cpu_id); +PRE(sys_membarrier) +{ + // cmd is signed int but the constants in the headers + // are hex so print in hex + PRINT("sys_membarrier(%#" FMT_REGWORD "x, %#" FMT_REGWORD "x, %" FMT_REGWORD "d)", + ARG1, ARG2, SARG3); + PRE_REG_READ3(int, "membarrier", int, cmd, unsigned, flags, int, cpu_id); +} // SYS_timerfd_create 585 // int timerfd_create(int clockid, int flags); @@ -7593,8 +7603,8 @@ const SyscallTableEntry ML_(syscall_table)[] = { #endif #if (FREEBSD_VERS >= FREEBSD_15) - BSDXY( __NR_kqueuex, sys_kqueuex), // 583 - // unimpl __NR_membarrier 584 + BSDXY(__NR_kqueuex, sys_kqueuex), // 583 + BSDX_(__NR_membarrier, sys_membarrier), // 584 BSDXY(__NR_timerfd_create, sys_timerfd_create), // 585 BSDXY(__NR_timerfd_settime, sys_timerfd_settime), // 586 BSDXY(__NR_timerfd_gettime, sys_timerfd_gettime), // 587 diff --git a/memcheck/tests/freebsd/scalar_15_plus.c b/memcheck/tests/freebsd/scalar_15_plus.c index 2945060c29..d3d8af2c0c 100644 --- a/memcheck/tests/freebsd/scalar_15_plus.c +++ b/memcheck/tests/freebsd/scalar_15_plus.c @@ -11,7 +11,8 @@ int main(void) SY(SYS_kqueuex, x0+123); FAIL; /* SYS_membarrier 584 */ - /* unimpl */ + GO(SYS_membarrier, " 3s 0m"); + SY(SYS_membarrier, x0+123, x0+456, x0+789); FAIL; /* SYS_timerfd_create 585 */ GO(SYS_timerfd_create, " 2s 0m"); diff --git a/memcheck/tests/freebsd/scalar_15_plus.stderr.exp b/memcheck/tests/freebsd/scalar_15_plus.stderr.exp index 5717326f32..af4069c473 100644 --- a/memcheck/tests/freebsd/scalar_15_plus.stderr.exp +++ b/memcheck/tests/freebsd/scalar_15_plus.stderr.exp @@ -4,6 +4,18 @@ Syscall param kqueuex(flags) contains uninitialised byte(s) ... +--------------------------------------------------------- +584: SYS_membarrier 3s 0m +--------------------------------------------------------- +Syscall param membarrier(cmd) contains uninitialised byte(s) + ... + +Syscall param membarrier(flags) contains uninitialised byte(s) + ... + +Syscall param membarrier(cpu_id) contains uninitialised byte(s) + ... + --------------------------------------------------------- 585: SYS_timerfd_create 2s 0m ---------------------------------------------------------