From: Paul Floyd Date: Mon, 9 May 2022 09:05:49 +0000 (+0200) Subject: Add FreeBSD shm_open2 syscall wrapper X-Git-Tag: VALGRIND_3_20_0~88 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3a883a6c1d46782e8f1d7c1b2bb773728ed61355;p=thirdparty%2Fvalgrind.git Add FreeBSD shm_open2 syscall wrapper --- diff --git a/coregrind/m_syswrap/priv_syswrap-freebsd.h b/coregrind/m_syswrap/priv_syswrap-freebsd.h index 36a48ac1ff..5d6bec529c 100644 --- a/coregrind/m_syswrap/priv_syswrap-freebsd.h +++ b/coregrind/m_syswrap/priv_syswrap-freebsd.h @@ -533,7 +533,7 @@ DECL_TEMPLATE(freebsd, sys___sysctlbyname) // 570 #if (FREEBSD_VERS >= FREEBSD_13_0) // looks like close_range got backported // to 12.2 leaving these 4 marked as UNIMPL in 12.2 -// unimpl __NR_shm_open2 571 +DECL_TEMPLATE(freebsd, sys_shm_open2) // 571 // unimpl __NR_shm_rename 572 // unimpl __NR_sigfastblock 573 DECL_TEMPLATE(freebsd, sys___realpathat) // 574 diff --git a/coregrind/m_syswrap/syswrap-freebsd.c b/coregrind/m_syswrap/syswrap-freebsd.c index 64260f8a9a..eed1b5a6da 100644 --- a/coregrind/m_syswrap/syswrap-freebsd.c +++ b/coregrind/m_syswrap/syswrap-freebsd.c @@ -6221,7 +6221,43 @@ POST(sys___sysctlbyname) #if (FREEBSD_VERS >= FREEBSD_13_0) -// SYS___realpathat 474 +// SYS_shm_open2 571 +// from syscalls.master +// int shm_open2(_In_z_ const char *path, +// int flags, +// mode_t mode, +// int shmflags, +// _In_z_ const char *name); +PRE(sys_shm_open2) +{ + PRE_REG_READ5(int, "shm_open2", + const char *, path, int, flags, vki_mode_t, mode, int, shmflags, const char*, name); + if (ARG1 == VKI_SHM_ANON) { + PRINT("sys_shm_open2(%#" FMT_REGWORD "x(SHM_ANON), %" FMT_REGWORD "u, %hu, %d, %#" FMT_REGWORD "x(%s))", + ARG1, ARG2, (vki_mode_t)ARG3, (Int)ARG4, ARG5, (HChar*)ARG5); + } else { + PRINT("sys_shm_open2(%#" FMT_REGWORD "x(%s), %" FMT_REGWORD "u, %hu, %d, %#" FMT_REGWORD "x(%s))", + ARG1, (HChar *)ARG1, ARG2, (vki_mode_t)ARG3, (Int)ARG4, ARG5, (HChar*)ARG5); + PRE_MEM_RASCIIZ( "shm_open2(path)", ARG1 ); + } + + PRE_MEM_RASCIIZ( "shm_open2(name)", ARG5 ); + *flags |= SfMayBlock; +} + +POST(sys_shm_open2) +{ + vg_assert(SUCCESS); + if (!ML_(fd_allowed)(RES, "shm_open2", tid, True)) { + VG_(close)(RES); + SET_STATUS_Failure( VKI_EMFILE ); + } else { + if (VG_(clo_track_fds)) + ML_(record_fd_open_with_given_name)(tid, RES, (HChar*)ARG1); + } +} + +// SYS___realpathat 574 // from syscalls.master // int __realpathat(int fd, // _In_z_ const char *path, @@ -6969,7 +7005,7 @@ const SyscallTableEntry ML_(syscall_table)[] = { BSDXY(__NR___sysctlbyname, sys___sysctlbyname), // 570 #if (FREEBSD_VERS >= FREEBSD_13_0) - // unimpl __NR_shm_open2 571 + BSDXY(__NR_shm_open2, sys_shm_open2), // 571 // unimpl __NR_shm_rename 572 // unimpl __NR_sigfastblock 573 BSDXY( __NR___realpathat, sys___realpathat), // 574 diff --git a/memcheck/tests/freebsd/scalar_13_plus.c b/memcheck/tests/freebsd/scalar_13_plus.c index 5cb8102465..a0f5dfe363 100644 --- a/memcheck/tests/freebsd/scalar_13_plus.c +++ b/memcheck/tests/freebsd/scalar_13_plus.c @@ -5,6 +5,10 @@ int main(void) long *px = malloc(2*sizeof(long)); x0 = px[0]; + /* SYS_shm_open2 571 */ + GO(SYS_shm_open2, " 5s 2m"); + SY(SYS_shm_open2, x0, x0+1, x0+2, x0+3, x0); FAIL; + /* SYS___realpathat 574 */ GO(SYS___realpathat, " 5s 2m"); SY(SYS___realpathat, x0+0xffff, x0, x0, x0+100, x0+2); FAIL; diff --git a/memcheck/tests/freebsd/scalar_13_plus.stderr.exp b/memcheck/tests/freebsd/scalar_13_plus.stderr.exp index 91721fc7af..02447b53ae 100644 --- a/memcheck/tests/freebsd/scalar_13_plus.stderr.exp +++ b/memcheck/tests/freebsd/scalar_13_plus.stderr.exp @@ -1,3 +1,29 @@ +--------------------------------------------------------- +571: SYS_shm_open2 5s 2m +--------------------------------------------------------- +Syscall param shm_open2(path) contains uninitialised byte(s) + ... + +Syscall param shm_open2(flags) contains uninitialised byte(s) + ... + +Syscall param shm_open2(mode) contains uninitialised byte(s) + ... + +Syscall param shm_open2(shmflags) contains uninitialised byte(s) + ... + +Syscall param shm_open2(name) contains uninitialised byte(s) + ... + +Syscall param shm_open2(path) points to unaddressable byte(s) + ... + Address 0x........ is not stack'd, malloc'd or (recently) free'd + +Syscall param shm_open2(name) points to unaddressable byte(s) + ... + Address 0x........ is not stack'd, malloc'd or (recently) free'd + --------------------------------------------------------- 574: SYS___realpathat 5s 2m ---------------------------------------------------------