From: Martin Cermak Date: Thu, 17 Jul 2025 07:16:53 +0000 (+0200) Subject: Wrap linux specific syscall 22 (ustat) X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a4d893c6ef133fdf8255860aa8ca0a8460e105b1;p=thirdparty%2Fvalgrind.git 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 --git a/NEWS b/NEWS index 868d4218f..e61b56baf 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 9e6cb8981..ce10a35f6 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 22989f9fa..c80286f00 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 7bd69b681..c5fb08dcc 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 306c3a2f8..bd563d989 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 4e5e91e15..684bda4b9 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 67e5c0b37..8e2dcbe93 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 b5d45e109..d2b59786c 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 764fb557e..3d6c2e4ed 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 8202c1922..65a26a02d 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 45216b45f..0b8373ffa 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 8c919845b..c31035cbb 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 //----------------------------------------------------------------------