From: Mark W. <ma...@so...> - 2025-07-17 11:19:29
|
https://sourceware.org/cgit/valgrind/commit/?id=a4d893c6ef133fdf8255860aa8ca0a8460e105b1 commit a4d893c6ef133fdf8255860aa8ca0a8460e105b1 Author: Martin Cermak <mc...@re...> Date: Thu Jul 17 09:16:53 2025 +0200 Wrap linux specific syscall 22 (ustat) The ustat syscall comes from pre-git linux history. It is deprecated in favor of statfs. But in some cases it may still be used. int ustat(dev_t dev, struct ustat *ubuf); returns information about a mounted filesystem. dev is a device number identifying a device containing a mounted filesystem. ubuf is a pointer to a ustat structure. Declare a sys_ustat wrapper in priv_syswrap-linux.h and hook it for {amd64,arm,arm64,mips64,nanomips,ppc32,ppc64,riscv64,\ s390x,x86}-linux using LINXY with PRE and POST handler in syswrap-linux.c https://bugs.kde.org/show_bug.cgi?id=506928 Diff: --- NEWS | 1 + coregrind/m_syswrap/priv_syswrap-linux.h | 1 + coregrind/m_syswrap/syswrap-amd64-linux.c | 2 +- coregrind/m_syswrap/syswrap-arm-linux.c | 2 +- coregrind/m_syswrap/syswrap-linux.c | 13 +++++++++++++ coregrind/m_syswrap/syswrap-mips32-linux.c | 2 +- coregrind/m_syswrap/syswrap-mips64-linux.c | 9 +-------- coregrind/m_syswrap/syswrap-ppc32-linux.c | 2 +- coregrind/m_syswrap/syswrap-ppc64-linux.c | 2 +- coregrind/m_syswrap/syswrap-s390x-linux.c | 2 +- coregrind/m_syswrap/syswrap-x86-linux.c | 2 +- include/vki/vki-linux.h | 19 +++++++++++++++++++ 12 files changed, 42 insertions(+), 15 deletions(-) diff --git a/NEWS b/NEWS index 868d4218fe..e61b56baf9 100644 --- a/NEWS +++ b/NEWS @@ -55,6 +55,7 @@ are not entered into bugzilla tend to get forgotten about or ignored. 506076 unimplemented fcntl command: 1028 (F_CREATED_QUERY) 506499 Unhandled syscall 592 (exterrctl - FreeBSD 506795 Better report which clone flags are problematic +506928 Wrap (deprecated) linux specific ustat syscall 506930 valgrind allows SIGKILL being reset to SIG_DFL 506970 mmap needs an EBADF fd_allowed check diff --git a/coregrind/m_syswrap/priv_syswrap-linux.h b/coregrind/m_syswrap/priv_syswrap-linux.h index 9e6cb89811..ce10a35f6a 100644 --- a/coregrind/m_syswrap/priv_syswrap-linux.h +++ b/coregrind/m_syswrap/priv_syswrap-linux.h @@ -40,6 +40,7 @@ extern void ML_(call_on_new_stack_0_1) ( Addr stack, Addr retaddr, // Linux-specific (but non-arch-specific) syscalls +DECL_TEMPLATE(linux, sys_ustat); DECL_TEMPLATE(linux, sys_clone) DECL_TEMPLATE(linux, sys_mount); DECL_TEMPLATE(linux, sys_oldumount); diff --git a/coregrind/m_syswrap/syswrap-amd64-linux.c b/coregrind/m_syswrap/syswrap-amd64-linux.c index 22989f9fa5..c80286f00b 100644 --- a/coregrind/m_syswrap/syswrap-amd64-linux.c +++ b/coregrind/m_syswrap/syswrap-amd64-linux.c @@ -633,7 +633,7 @@ static SyscallTableEntry syscall_table[] = { // (__NR_uselib, sys_uselib), // 134 LINX_(__NR_personality, sys_personality), // 135 - // (__NR_ustat, sys_ustat), // 136 + LINXY(__NR_ustat, sys_ustat), // 136 GENXY(__NR_statfs, sys_statfs), // 137 GENXY(__NR_fstatfs, sys_fstatfs), // 138 // (__NR_sysfs, sys_sysfs), // 139 diff --git a/coregrind/m_syswrap/syswrap-arm-linux.c b/coregrind/m_syswrap/syswrap-arm-linux.c index 7bd69b6817..c5fb08dcc6 100644 --- a/coregrind/m_syswrap/syswrap-arm-linux.c +++ b/coregrind/m_syswrap/syswrap-arm-linux.c @@ -621,7 +621,7 @@ static SyscallTableEntry syscall_main_table[] = { //zz GENX_(__NR_umask, sys_umask), // 60 GENX_(__NR_chroot, sys_chroot), // 61 -//zz // (__NR_ustat, sys_ustat) // 62 SVr4 -- deprecated + LINXY(__NR_ustat, sys_ustat), // 62 SVr4 -- deprecated GENXY(__NR_dup2, sys_dup2), // 63 GENX_(__NR_getppid, sys_getppid), // 64 diff --git a/coregrind/m_syswrap/syswrap-linux.c b/coregrind/m_syswrap/syswrap-linux.c index 306c3a2f8b..bd563d9894 100644 --- a/coregrind/m_syswrap/syswrap-linux.c +++ b/coregrind/m_syswrap/syswrap-linux.c @@ -14204,6 +14204,19 @@ POST(sys_userfaultfd) } } +PRE(sys_ustat) +{ + FUSE_COMPATIBLE_MAY_BLOCK(); + PRINT("sys_ustat ( %#" FMT_REGWORD "x, %#" FMT_REGWORD "x)", ARG1, ARG2); + PRE_REG_READ2(long, "ustat", __vki_u32, dev, struct vki_ustat *, ubuf); + PRE_MEM_WRITE( "ustat(ubuf)", ARG2, sizeof(struct vki_ustat) ); +} + +POST(sys_ustat) +{ + POST_MEM_WRITE( ARG2, sizeof(struct vki_ustat) ); +} + #undef PRE #undef POST diff --git a/coregrind/m_syswrap/syswrap-mips32-linux.c b/coregrind/m_syswrap/syswrap-mips32-linux.c index 4e5e91e15b..684bda4b9a 100644 --- a/coregrind/m_syswrap/syswrap-mips32-linux.c +++ b/coregrind/m_syswrap/syswrap-mips32-linux.c @@ -826,7 +826,7 @@ static SyscallTableEntry syscall_main_table[] = { //.. // (__NR_oldolduname, sys_olduname), // 59 GENX_ (__NR_umask, sys_umask), // 60 GENX_ (__NR_chroot, sys_chroot), // 61 - //.. // (__NR_ustat, sys_ustat) // 62 + LINXY (__NR_ustat, sys_ustat), // 62 GENXY (__NR_dup2, sys_dup2), // 63 GENX_ (__NR_getppid, sys_getppid), // 64 GENX_ (__NR_getpgrp, sys_getpgrp), // 65 diff --git a/coregrind/m_syswrap/syswrap-mips64-linux.c b/coregrind/m_syswrap/syswrap-mips64-linux.c index 67e5c0b37d..8e2dcbe93c 100644 --- a/coregrind/m_syswrap/syswrap-mips64-linux.c +++ b/coregrind/m_syswrap/syswrap-mips64-linux.c @@ -216,7 +216,6 @@ SysRes sys_set_tls ( ThreadId tid, Addr tlsptr ) DECL_TEMPLATE (mips_linux, sys_set_thread_area); DECL_TEMPLATE (mips_linux, sys_vmsplice); -DECL_TEMPLATE (mips_linux, sys_ustat); DECL_TEMPLATE (mips_linux, sys_sysfs); DECL_TEMPLATE (mips_linux, sys_swapon); DECL_TEMPLATE (mips_linux, sys_swapoff); @@ -248,12 +247,6 @@ PRE(sys_sched_rr_get_interval) *flags |= SfMayBlock; } -PRE(sys_ustat) -{ - PRINT("sys_ustat ( %#" FMT_REGWORD "x, %#" FMT_REGWORD "x)", ARG1, ARG2); - PRE_REG_READ2(long, "ustat", int, flags, const void *, path); -} - PRE(sys_swapon) { PRINT("sys_swapon ( %#" FMT_REGWORD "x, %#" FMT_REGWORD "x )", ARG1, ARG2); @@ -649,7 +642,7 @@ static SyscallTableEntry syscall_main_table[] = { LINX_ (__NR_utime, sys_utime), GENX_ (__NR_mknod, sys_mknod), LINX_ (__NR_personality, sys_personality), - PLAX_ (__NR_ustat, sys_ustat), + LINXY (__NR_ustat, sys_ustat), GENXY (__NR_statfs, sys_statfs), GENXY (__NR_fstatfs, sys_fstatfs), PLAX_ (__NR_sysfs, sys_sysfs), diff --git a/coregrind/m_syswrap/syswrap-ppc32-linux.c b/coregrind/m_syswrap/syswrap-ppc32-linux.c index b5d45e1094..d2b59786c4 100644 --- a/coregrind/m_syswrap/syswrap-ppc32-linux.c +++ b/coregrind/m_syswrap/syswrap-ppc32-linux.c @@ -685,7 +685,7 @@ static SyscallTableEntry syscall_table[] = { GENX_(__NR_umask, sys_umask), // 60 GENX_(__NR_chroot, sys_chroot), // 61 -//.. // (__NR_ustat, sys_ustat) // 62 SVr4 -- deprecated + LINXY(__NR_ustat, sys_ustat), // 62 SVr4 -- deprecated GENXY(__NR_dup2, sys_dup2), // 63 GENX_(__NR_getppid, sys_getppid), // 64 diff --git a/coregrind/m_syswrap/syswrap-ppc64-linux.c b/coregrind/m_syswrap/syswrap-ppc64-linux.c index 764fb557ec..3d6c2e4eda 100644 --- a/coregrind/m_syswrap/syswrap-ppc64-linux.c +++ b/coregrind/m_syswrap/syswrap-ppc64-linux.c @@ -674,7 +674,7 @@ static SyscallTableEntry syscall_table[] = { GENX_(__NR_umask, sys_umask), // 60 GENX_(__NR_chroot, sys_chroot), // 61 -// _____(__NR_ustat, sys_ustat), // 62 + LINXY(__NR_ustat, sys_ustat), // 62 GENXY(__NR_dup2, sys_dup2), // 63 GENX_(__NR_getppid, sys_getppid), // 64 diff --git a/coregrind/m_syswrap/syswrap-s390x-linux.c b/coregrind/m_syswrap/syswrap-s390x-linux.c index 8202c1922d..65a26a02da 100644 --- a/coregrind/m_syswrap/syswrap-s390x-linux.c +++ b/coregrind/m_syswrap/syswrap-s390x-linux.c @@ -485,7 +485,7 @@ static SyscallTableEntry syscall_table[] = { GENX_(__NR_umask, sys_umask), // 60 GENX_(__NR_chroot, sys_chroot), // 61 -// ?????(__NR_ustat, sys_ustat), /* deprecated in favor of statfs */ // 62 + LINXY(__NR_ustat, sys_ustat), /* deprecated in favor of statfs */ // 62 GENXY(__NR_dup2, sys_dup2), // 63 GENX_(__NR_getppid, sys_getppid), // 64 diff --git a/coregrind/m_syswrap/syswrap-x86-linux.c b/coregrind/m_syswrap/syswrap-x86-linux.c index 45216b45f4..0b8373ffa8 100644 --- a/coregrind/m_syswrap/syswrap-x86-linux.c +++ b/coregrind/m_syswrap/syswrap-x86-linux.c @@ -1230,7 +1230,7 @@ static SyscallTableEntry syscall_table[] = { //zz GENX_(__NR_umask, sys_umask), // 60 GENX_(__NR_chroot, sys_chroot), // 61 -//zz // (__NR_ustat, sys_ustat) // 62 SVr4 -- deprecated + LINXY(__NR_ustat, sys_ustat), // 62 SVr4 -- deprecated GENXY(__NR_dup2, sys_dup2), // 63 GENX_(__NR_getppid, sys_getppid), // 64 diff --git a/include/vki/vki-linux.h b/include/vki/vki-linux.h index 8c919845bc..c31035cbbe 100644 --- a/include/vki/vki-linux.h +++ b/include/vki/vki-linux.h @@ -171,6 +171,25 @@ typedef struct { typedef int __vki_kernel_key_t; typedef int __vki_kernel_mqd_t; +//---------------------------------------------------------------------- +// From pre-git history /include/linux/types.h +//---------------------------------------------------------------------- + +struct vki_ustat { +#if defined(VGA_mips32) || defined(VGA_mips64) || defined(VGA_nanomips) + long f_tfree; +#else + int f_tfree; +#endif +#if defined(VGA_s390x) + unsigned int f_tinode; +#else + unsigned long f_tinode; +#endif + char f_fname[6]; + char f_fpack[6]; +}; + //---------------------------------------------------------------------- // From linux-2.6.8.1/include/linux/types.h //---------------------------------------------------------------------- |