linux-user: Add strace support for printing arguments of truncate()/ftruncate() and getsid()

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>
Message-Id: <20200811164553.27713-3-Filip.Bozuta@syrmia.com>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
This commit is contained in:
Filip Bozuta 2020-08-11 18:45:50 +02:00 committed by Laurent Vivier
parent e400e11941
commit 7c89f34383
4 changed files with 87 additions and 37 deletions

View file

@ -1962,6 +1962,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,