qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v4 2/5] linux-user: Add strace support for printing arguments


From: Laurent Vivier
Subject: Re: [PATCH v4 2/5] linux-user: Add strace support for printing arguments of truncate()/ftruncate() and getsid()
Date: Mon, 24 Aug 2020 22:45:45 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0

Le 11/08/2020 à 18:45, Filip Bozuta a écrit :
> This patch implements strace argument printing functionality for following 
> syscalls:
> 
>     * truncate, ftruncate - truncate a file to a specified length
> 
>         int truncate/truncate64(const char *path, off_t length)
>         int ftruncate/ftruncate64(int fd, off_t length)
>         man page: https://man7.org/linux/man-pages/man2/truncate.2.html
> 
>     * getsid - get session ID
> 
>         pid_t getsid(pid_t pid)
>         man page: https://man7.org/linux/man-pages/man2/getsid.2.html
> 
> Implementation notes:
> 
>     Syscalls truncate/truncate64 take string argument types and thus a
>     separate print function "print_truncate/print_truncate64" is stated in
>     file "strace.list". This function is defined and implemented in "strace.c"
>     by using an existing function used to print string arguments: 
> "print_string()".
>     For syscall ftruncate64, a separate printing function was also stated in
>     "strace.c" as it requires a special kind of handling.
>     The other syscalls have only primitive argument types, so the rest of the
>     implementation was handled by stating an appropriate printing format in 
> file
>     "strace.list".
>     Function "regpairs_aligned()" was cut & pasted from "syscall.c" to 
> "qemu.h"
>     as it is used by functions "print_truncate64()" and "print_ftruncate64()"
>     to print the offset arguments of "truncate64()" and "ftruncate64()".
> 
> Signed-off-by: Filip Bozuta <Filip.Bozuta@syrmia.com>
> Reviewed-by: Laurent Vivier <laurent@vivier.eu>
> ---
>  linux-user/qemu.h      | 35 +++++++++++++++++++++++++++++++
>  linux-user/strace.c    | 47 ++++++++++++++++++++++++++++++++++++++++++
>  linux-user/strace.list | 10 ++++-----
>  linux-user/syscall.c   | 32 ----------------------------
>  4 files changed, 87 insertions(+), 37 deletions(-)
> 
> diff --git a/linux-user/qemu.h b/linux-user/qemu.h
> index 63ddfe86fd..f431805e57 100644
> --- a/linux-user/qemu.h
> +++ b/linux-user/qemu.h
> @@ -706,6 +706,41 @@ static inline uint64_t target_offset64(uint64_t word0, 
> uint64_t word1)
>  }
>  #endif /* TARGET_ABI_BITS != 32 */
>  
> +
> +/* ARM EABI and MIPS expect 64bit types aligned even on pairs or registers */
> +#ifdef TARGET_ARM
> +static inline int regpairs_aligned(void *cpu_env, int num)
> +{
> +    return ((((CPUARMState *)cpu_env)->eabi) == 1) ;
> +}
> +#elif defined(TARGET_MIPS) && (TARGET_ABI_BITS == 32)
> +static inline int regpairs_aligned(void *cpu_env, int num) { return 1; }
> +#elif defined(TARGET_PPC) && !defined(TARGET_PPC64)
> +/*
> + * SysV AVI for PPC32 expects 64bit parameters to be passed on odd/even pairs
> + * of registers which translates to the same as ARM/MIPS, because we start 
> with
> + * r3 as arg1
> + */
> +static inline int regpairs_aligned(void *cpu_env, int num) { return 1; }
> +#elif defined(TARGET_SH4)
> +/* SH4 doesn't align register pairs, except for p{read,write}64 */
> +static inline int regpairs_aligned(void *cpu_env, int num)
> +{
> +    switch (num) {
> +    case TARGET_NR_pread64:
> +    case TARGET_NR_pwrite64:
> +        return 1;
> +
> +    default:
> +        return 0;
> +    }
> +}
> +#elif defined(TARGET_XTENSA)
> +static inline int regpairs_aligned(void *cpu_env, int num) { return 1; }
> +#else
> +static inline int regpairs_aligned(void *cpu_env, int num) { return 0; }
> +#endif
> +
>  /**
>   * preexit_cleanup: housekeeping before the guest exits
>   *
> diff --git a/linux-user/strace.c b/linux-user/strace.c
> index f0624b6206..7dc239b9f1 100644
> --- a/linux-user/strace.c
> +++ b/linux-user/strace.c
> @@ -1958,6 +1958,53 @@ print_lseek(void *cpu_env, const struct syscallname 
> *name,
>  }
>  #endif
>  
> +#ifdef TARGET_NR_truncate
> +static void
> +print_truncate(void *cpu_env, const struct syscallname *name,
> +               abi_long arg0, abi_long arg1, abi_long arg2,
> +               abi_long arg3, abi_long arg4, abi_long arg5)
> +{
> +    print_syscall_prologue(name);
> +    print_string(arg0, 0);
> +    print_raw_param(TARGET_ABI_FMT_ld, arg1, 1);
> +    print_syscall_epilogue(name);
> +}
> +#endif
> +
> +#ifdef TARGET_NR_truncate64
> +static void
> +print_truncate64(void *cpu_env, const struct syscallname *name,
> +                 abi_long arg0, abi_long arg1, abi_long arg2,
> +                 abi_long arg3, abi_long arg4, abi_long arg5)
> +{
> +    print_syscall_prologue(name);
> +    print_string(arg0, 0);
> +    if (regpairs_aligned(cpu_env, TARGET_NR_truncate64)) {
> +        arg1 = arg2;
> +        arg2 = arg3;
> +    }
> +    print_raw_param("%" PRIu64, target_offset64(arg1, arg2), 1);
> +    print_syscall_epilogue(name);
> +}
> +#endif
> +
> +#ifdef TARGET_NR_ftruncate64
> +static void
> +print_ftruncate64(void *cpu_env, const struct syscallname *name,
> +                  abi_long arg0, abi_long arg1, abi_long arg2,
> +                  abi_long arg3, abi_long arg4, abi_long arg5)
> +{
> +    print_syscall_prologue(name);
> +    print_raw_param("%d", arg0, 0);
> +    if (regpairs_aligned(cpu_env, TARGET_NR_ftruncate64)) {
> +        arg1 = arg2;
> +        arg2 = arg3;
> +    }
> +    print_raw_param("%" PRIu64, target_offset64(arg1, arg2), 1);
> +    print_syscall_epilogue(name);
> +}
> +#endif
> +
>  #if defined(TARGET_NR_socket)
>  static void
>  print_socket(void *cpu_env, const struct syscallname *name,
> diff --git a/linux-user/strace.list b/linux-user/strace.list
> index a04706a524..8e5303d035 100644
> --- a/linux-user/strace.list
> +++ b/linux-user/strace.list
> @@ -258,10 +258,10 @@
>  { TARGET_NR_ftime, "ftime" , NULL, NULL, NULL },
>  #endif
>  #ifdef TARGET_NR_ftruncate
> -{ TARGET_NR_ftruncate, "ftruncate" , NULL, NULL, NULL },
> +{ TARGET_NR_ftruncate, "ftruncate" , "%s(%d," TARGET_ABI_FMT_ld ")", NULL, 
> NULL },
>  #endif
>  #ifdef TARGET_NR_ftruncate64
> -{ TARGET_NR_ftruncate64, "ftruncate64" , NULL, NULL, NULL },
> +{ TARGET_NR_ftruncate64, "ftruncate64" , NULL, print_ftruncate64, NULL },
>  #endif
>  #ifdef TARGET_NR_futex
>  { TARGET_NR_futex, "futex" , NULL, print_futex, NULL },
> @@ -372,7 +372,7 @@
>  { TARGET_NR_getrusage, "getrusage" , NULL, NULL, NULL },
>  #endif
>  #ifdef TARGET_NR_getsid
> -{ TARGET_NR_getsid, "getsid" , NULL, NULL, NULL },
> +{ TARGET_NR_getsid, "getsid" , "%s(%d)", NULL, NULL },
>  #endif
>  #ifdef TARGET_NR_getsockname
>  { TARGET_NR_getsockname, "getsockname" , NULL, NULL, NULL },
> @@ -1535,10 +1535,10 @@
>  { TARGET_NR_tkill, "tkill" , NULL, print_tkill, NULL },
>  #endif
>  #ifdef TARGET_NR_truncate
> -{ TARGET_NR_truncate, "truncate" , NULL, NULL, NULL },
> +{ TARGET_NR_truncate, "truncate" , NULL, print_truncate, NULL },
>  #endif
>  #ifdef TARGET_NR_truncate64
> -{ TARGET_NR_truncate64, "truncate64" , NULL, NULL, NULL },
> +{ TARGET_NR_truncate64, "truncate64" , NULL, print_truncate64, NULL },
>  #endif
>  #ifdef TARGET_NR_tuxcall
>  { TARGET_NR_tuxcall, "tuxcall" , NULL, NULL, NULL },
> diff --git a/linux-user/syscall.c b/linux-user/syscall.c
> index cc76ac61ba..1517096a9b 100644
> --- a/linux-user/syscall.c
> +++ b/linux-user/syscall.c
> @@ -501,38 +501,6 @@ static inline int next_free_host_timer(void)
>  }
>  #endif
>  
> -/* ARM EABI and MIPS expect 64bit types aligned even on pairs or registers */
> -#ifdef TARGET_ARM
> -static inline int regpairs_aligned(void *cpu_env, int num)
> -{
> -    return ((((CPUARMState *)cpu_env)->eabi) == 1) ;
> -}
> -#elif defined(TARGET_MIPS) && (TARGET_ABI_BITS == 32)
> -static inline int regpairs_aligned(void *cpu_env, int num) { return 1; }
> -#elif defined(TARGET_PPC) && !defined(TARGET_PPC64)
> -/* SysV AVI for PPC32 expects 64bit parameters to be passed on odd/even pairs
> - * of registers which translates to the same as ARM/MIPS, because we start 
> with
> - * r3 as arg1 */
> -static inline int regpairs_aligned(void *cpu_env, int num) { return 1; }
> -#elif defined(TARGET_SH4)
> -/* SH4 doesn't align register pairs, except for p{read,write}64 */
> -static inline int regpairs_aligned(void *cpu_env, int num)
> -{
> -    switch (num) {
> -    case TARGET_NR_pread64:
> -    case TARGET_NR_pwrite64:
> -        return 1;
> -
> -    default:
> -        return 0;
> -    }
> -}
> -#elif defined(TARGET_XTENSA)
> -static inline int regpairs_aligned(void *cpu_env, int num) { return 1; }
> -#else
> -static inline int regpairs_aligned(void *cpu_env, int num) { return 0; }
> -#endif
> -
>  #define ERRNO_TABLE_SIZE 1200
>  
>  /* target_to_host_errno_table[] is initialized from
> 


Applied to my linux-user-for-5.2 branch.

Thanks,
Laurent




reply via email to

[Prev in Thread] Current Thread [Next in Thread]