|
From: Paul F. <pa...@so...> - 2026-02-28 11:06:16
|
https://sourceware.org/cgit/valgrind/commit/?id=8811654d17236842acd1703ef23869e8e3578c92 commit 8811654d17236842acd1703ef23869e8e3578c92 Author: Paul Floyd <pj...@wa...> Date: Sat Feb 28 12:01:31 2026 +0100 FreeBSD syscall: add wrapper for pdwait system call Also add 516748 to NEWS. It's done for FreeBSD and finding syscalls like that is quite hard. Diff: --- NEWS | 4 ++- coregrind/m_syswrap/syswrap-freebsd.c | 52 +++++++++++++++++++++++----- memcheck/tests/freebsd/scalar.c | 35 +++++++++++++++++++ memcheck/tests/freebsd/scalar.stderr.exp | 30 ++++++++++++++++ memcheck/tests/freebsd/scalar.stderr.exp-x86 | 30 ++++++++++++++++ 5 files changed, 141 insertions(+), 10 deletions(-) diff --git a/NEWS b/NEWS index 88a2d9be93..eee47e3402 100644 --- a/NEWS +++ b/NEWS @@ -73,7 +73,7 @@ are not entered into bugzilla tend to get forgotten about or ignored. '-Wno-alloc-size-larger-than=18446744073709551615' 512030 s390x: bfp-convert testcase fails 512037 malloc trace does not print free size or alignment -512571 regtest problems with darwin dsymuti +512571 regtest problems with darwin dsymutil 513257 Add missing syswraps for lsm_list_modules 513522 m_libcassert.c: 'ordered comparison of pointer with integer zero' compiler warning @@ -95,6 +95,8 @@ are not entered into bugzilla tend to get forgotten about or ignored. 515810 Update the LTP version in valgrind testsuite to 20260130 515992 Add FreeBSD /proc virtualisation for cmdline and file 516090 Regression : Linux FreeBSD and Darwin: refactor *at syscall dirfd checks +516748 Incorrect use of SET_STATUS_Failure for syscall wrappers that return + error codes rather than -1 on error To see details of a given bug, visit https://bugs.kde.org/show_bug.cgi?id=XXXXXX diff --git a/coregrind/m_syswrap/syswrap-freebsd.c b/coregrind/m_syswrap/syswrap-freebsd.c index ac7243d453..c2e2f50dc9 100644 --- a/coregrind/m_syswrap/syswrap-freebsd.c +++ b/coregrind/m_syswrap/syswrap-freebsd.c @@ -6168,13 +6168,13 @@ POST(sys_rctl_remove_rule) } // SYS_posix_fallocate 530 -// x86/amd64 +// x86/amd64/arm64 // SYS_posix_fadvise 531 -// x86/amd64 +// x86/amd64/arm64 // SYS_wait6 532 -// amd64 / x86 +// x86/amd64/arm64 // SYS_cap_rights_limit 533 //int cap_rights_limit(int fd, const cap_rights_t *rights); @@ -7360,6 +7360,39 @@ PRE(sys_jail_remove_jd) SET_STATUS_Failure(VKI_EBADF); } +// SYS_pdwait 601 +// pid_t pdwait(int fd, int *status, int options, +// struct __wrusage *wrusage, siginfo_t *infop); +PRE(sys_pdwait) +{ + PRINT("sys_pdwait ( %" FMT_REGWORD "d, %#" FMT_REGWORD "x, %" FMT_REGWORD "d, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x )", + SARG1, ARG2, SARG3, ARG4, ARG5); + PRE_REG_READ5(pid_t, "pdwait", int, fd, int *, status, int, options, + struct vki___wrusage *, wrusage, vki_siginfo_t *,infop); + PRE_MEM_WRITE("pdwait(status)", ARG2, sizeof(int)); + if (ARG5) { + PRE_MEM_WRITE("pdwait(wrusage)", ARG4, sizeof(struct vki___wrusage)); + } + if (ARG6) { + PRE_MEM_WRITE("pdwait(infop)", ARG5, sizeof(vki_siginfo_t)); + } + if (!ML_(fd_allowed)(ARG1, "pdwait", tid, False)) { + SET_STATUS_Failure(VKI_EBADF); + } +} + +POST(sys_pdwait) +{ + POST_MEM_WRITE(ARG2, sizeof(int)); + if (ARG5) { + POST_MEM_WRITE(ARG4, sizeof(struct vki___wrusage)); + } + + if (ARG6) { + POST_MEM_WRITE(ARG5, sizeof(vki_siginfo_t)); + } +} + #undef PRE #undef POST @@ -8075,12 +8108,13 @@ const SyscallTableEntry ML_(syscall_table)[] = { GENXY(__NR_getgroups, sys_getgroups), // 596 #endif - BSDX_(__NR_jail_attach_jd, sys_jail_attach_jd), // 597 - BSDX_(__NR_jail_remove_jd, sys_jail_remove_jd), // 598 - BSDX_(__NR_kexec_load, sys_kexec_load), // 599 - // we only have partial support for rfork, so mark pdrfork - // as not implemented for the moment - GENX_(__NR_pdrfork, sys_ni_syscall), // 600 + BSDX_(__NR_jail_attach_jd, sys_jail_attach_jd), // 597 + BSDX_(__NR_jail_remove_jd, sys_jail_remove_jd), // 598 + BSDX_(__NR_kexec_load, sys_kexec_load), // 599 + // we only have partial support for rfork, so mark pdrfork + // as not implemented for the moment + GENX_(__NR_pdrfork, sys_ni_syscall), // 600 + BSDXY(__NR_pdwait, sys_pdwait), // 601 BSDX_(__NR_freebsd_fake_sigreturn, sys_fake_sigreturn), // 1000, fake sigreturn diff --git a/memcheck/tests/freebsd/scalar.c b/memcheck/tests/freebsd/scalar.c index 08272c1fad..5d42d1da5e 100644 --- a/memcheck/tests/freebsd/scalar.c +++ b/memcheck/tests/freebsd/scalar.c @@ -2629,6 +2629,41 @@ int main(void) FAKE_SY("\n"); #endif + /* SYS_pdwait 601 */ +#if defined(SYS_pdwait) + GO(SYS_pdwait, "5s 3m"); + SY(SYS_pdwait, x0+10000000, x0+1, x0, x0+1, x0+1); FAIL; +#else + FAKE_GO("601: SYS_pdwait 5s 3m"); + FAKE_SY("Syscall param pdwait(fd) contains uninitialised byte(s)\n"); + FAKE_SY(" ...\n"); + FAKE_SY("\n"); + FAKE_SY("Syscall param pdwait(status) contains uninitialised byte(s)\n"); + FAKE_SY(" ...\n"); + FAKE_SY("\n"); + FAKE_SY("Syscall param pdwait(options) contains uninitialised byte(s)\n"); + FAKE_SY(" ...\n"); + FAKE_SY("\n"); + FAKE_SY("Syscall param pdwait(wrusage) contains uninitialised byte(s)\n"); + FAKE_SY(" ...\n"); + FAKE_SY("\n"); + FAKE_SY("Syscall param pdwait(infop) contains uninitialised byte(s)\n"); + FAKE_SY(" ...\n"); + FAKE_SY("\n"); + FAKE_SY("Syscall param pdwait(status) points to unaddressable byte(s)\n"); + FAKE_SY(" ...\n"); + FAKE_SY(" Address 0x........ is not stack'd, malloc'd or (recently) free'd\n"); + FAKE_SY("\n"); + FAKE_SY("Syscall param pdwait(wrusage) points to unaddressable byte(s)\n"); + FAKE_SY(" ...\n"); + FAKE_SY(" Address 0x........ is not stack'd, malloc'd or (recently) free'd\n"); + FAKE_SY("\n"); + FAKE_SY("Syscall param pdwait(infop) points to unaddressable byte(s)\n"); + FAKE_SY(" ...\n"); + FAKE_SY(" Address 0x........ is not stack'd, malloc'd or (recently) free'd\n"); + FAKE_SY("\n"); +#endif + // no such syscall... GO(9999, "1e"); SY(9999); FAIL; diff --git a/memcheck/tests/freebsd/scalar.stderr.exp b/memcheck/tests/freebsd/scalar.stderr.exp index f83467ce2d..365413c66a 100644 --- a/memcheck/tests/freebsd/scalar.stderr.exp +++ b/memcheck/tests/freebsd/scalar.stderr.exp @@ -5920,6 +5920,36 @@ Syscall param kexec_load(segments) points to unaddressable byte(s) ... Address 0x........ is not stack'd, malloc'd or (recently) free'd +--------------------------------------------------------- +601: SYS_pdwait 5s 3m +--------------------------------------------------------- +Syscall param pdwait(fd) contains uninitialised byte(s) + ... + +Syscall param pdwait(status) contains uninitialised byte(s) + ... + +Syscall param pdwait(options) contains uninitialised byte(s) + ... + +Syscall param pdwait(wrusage) contains uninitialised byte(s) + ... + +Syscall param pdwait(infop) contains uninitialised byte(s) + ... + +Syscall param pdwait(status) points to unaddressable byte(s) + ... + Address 0x........ is not stack'd, malloc'd or (recently) free'd + +Syscall param pdwait(wrusage) points to unaddressable byte(s) + ... + Address 0x........ is not stack'd, malloc'd or (recently) free'd + +Syscall param pdwait(infop) points to unaddressable byte(s) + ... + Address 0x........ is not stack'd, malloc'd or (recently) free'd + --------------------------------------------------------- 9999: 9999 1e --------------------------------------------------------- diff --git a/memcheck/tests/freebsd/scalar.stderr.exp-x86 b/memcheck/tests/freebsd/scalar.stderr.exp-x86 index 805bc19c72..8f3f5e1651 100644 --- a/memcheck/tests/freebsd/scalar.stderr.exp-x86 +++ b/memcheck/tests/freebsd/scalar.stderr.exp-x86 @@ -5992,6 +5992,36 @@ Syscall param kexec_load(segments) points to unaddressable byte(s) ... Address 0x........ is not stack'd, malloc'd or (recently) free'd +--------------------------------------------------------- +601: SYS_pdwait 5s 3m +--------------------------------------------------------- +Syscall param pdwait(fd) contains uninitialised byte(s) + ... + +Syscall param pdwait(status) contains uninitialised byte(s) + ... + +Syscall param pdwait(options) contains uninitialised byte(s) + ... + +Syscall param pdwait(wrusage) contains uninitialised byte(s) + ... + +Syscall param pdwait(infop) contains uninitialised byte(s) + ... + +Syscall param pdwait(status) points to unaddressable byte(s) + ... + Address 0x........ is not stack'd, malloc'd or (recently) free'd + +Syscall param pdwait(wrusage) points to unaddressable byte(s) + ... + Address 0x........ is not stack'd, malloc'd or (recently) free'd + +Syscall param pdwait(infop) points to unaddressable byte(s) + ... + Address 0x........ is not stack'd, malloc'd or (recently) free'd + --------------------------------------------------------- 9999: 9999 1e --------------------------------------------------------- |