qemu/linux-user/strace.c
<<
>>
Prefs
   1#include "qemu/osdep.h"
   2#include <sys/ipc.h>
   3#include <sys/msg.h>
   4#include <sys/sem.h>
   5#include <sys/shm.h>
   6#include <sys/select.h>
   7#include <sys/mount.h>
   8#include <arpa/inet.h>
   9#include <netinet/tcp.h>
  10#include <linux/if_packet.h>
  11#include <linux/netlink.h>
  12#include <sched.h>
  13#include "qemu.h"
  14
  15int do_strace=0;
  16
  17struct syscallname {
  18    int nr;
  19    const char *name;
  20    const char *format;
  21    void (*call)(const struct syscallname *,
  22                 abi_long, abi_long, abi_long,
  23                 abi_long, abi_long, abi_long);
  24    void (*result)(const struct syscallname *, abi_long);
  25};
  26
  27#ifdef __GNUC__
  28/*
  29 * It is possible that target doesn't have syscall that uses
  30 * following flags but we don't want the compiler to warn
  31 * us about them being unused.  Same applies to utility print
  32 * functions.  It is ok to keep them while not used.
  33 */
  34#define UNUSED __attribute__ ((unused))
  35#else
  36#define UNUSED
  37#endif
  38
  39/*
  40 * Structure used to translate flag values into strings.  This is
  41 * similar that is in the actual strace tool.
  42 */
  43struct flags {
  44    abi_long    f_value;  /* flag */
  45    const char  *f_string; /* stringified flag */
  46};
  47
  48/* common flags for all architectures */
  49#define FLAG_GENERIC(name) { name, #name }
  50/* target specific flags (syscall_defs.h has TARGET_<flag>) */
  51#define FLAG_TARGET(name)  { TARGET_ ## name, #name }
  52/* end of flags array */
  53#define FLAG_END           { 0, NULL }
  54
  55UNUSED static const char *get_comma(int);
  56UNUSED static void print_pointer(abi_long, int);
  57UNUSED static void print_flags(const struct flags *, abi_long, int);
  58UNUSED static void print_at_dirfd(abi_long, int);
  59UNUSED static void print_file_mode(abi_long, int);
  60UNUSED static void print_open_flags(abi_long, int);
  61UNUSED static void print_syscall_prologue(const struct syscallname *);
  62UNUSED static void print_syscall_epilogue(const struct syscallname *);
  63UNUSED static void print_string(abi_long, int);
  64UNUSED static void print_buf(abi_long addr, abi_long len, int last);
  65UNUSED static void print_raw_param(const char *, abi_long, int);
  66UNUSED static void print_timeval(abi_ulong, int);
  67UNUSED static void print_timezone(abi_ulong, int);
  68UNUSED static void print_number(abi_long, int);
  69UNUSED static void print_signal(abi_ulong, int);
  70UNUSED static void print_sockaddr(abi_ulong, abi_long, int);
  71UNUSED static void print_socket_domain(int domain);
  72UNUSED static void print_socket_type(int type);
  73UNUSED static void print_socket_protocol(int domain, int type, int protocol);
  74
  75/*
  76 * Utility functions
  77 */
  78static void
  79print_ipc_cmd(int cmd)
  80{
  81#define output_cmd(val) \
  82if( cmd == val ) { \
  83    gemu_log(#val); \
  84    return; \
  85}
  86
  87    cmd &= 0xff;
  88
  89    /* General IPC commands */
  90    output_cmd( IPC_RMID );
  91    output_cmd( IPC_SET );
  92    output_cmd( IPC_STAT );
  93    output_cmd( IPC_INFO );
  94    /* msgctl() commands */
  95    output_cmd( MSG_STAT );
  96    output_cmd( MSG_INFO );
  97    /* shmctl() commands */
  98    output_cmd( SHM_LOCK );
  99    output_cmd( SHM_UNLOCK );
 100    output_cmd( SHM_STAT );
 101    output_cmd( SHM_INFO );
 102    /* semctl() commands */
 103    output_cmd( GETPID );
 104    output_cmd( GETVAL );
 105    output_cmd( GETALL );
 106    output_cmd( GETNCNT );
 107    output_cmd( GETZCNT );
 108    output_cmd( SETVAL );
 109    output_cmd( SETALL );
 110    output_cmd( SEM_STAT );
 111    output_cmd( SEM_INFO );
 112    output_cmd( IPC_RMID );
 113    output_cmd( IPC_RMID );
 114    output_cmd( IPC_RMID );
 115    output_cmd( IPC_RMID );
 116    output_cmd( IPC_RMID );
 117    output_cmd( IPC_RMID );
 118    output_cmd( IPC_RMID );
 119    output_cmd( IPC_RMID );
 120    output_cmd( IPC_RMID );
 121
 122    /* Some value we don't recognize */
 123    gemu_log("%d",cmd);
 124}
 125
 126static void
 127print_signal(abi_ulong arg, int last)
 128{
 129    const char *signal_name = NULL;
 130    switch(arg) {
 131    case TARGET_SIGHUP: signal_name = "SIGHUP"; break;
 132    case TARGET_SIGINT: signal_name = "SIGINT"; break;
 133    case TARGET_SIGQUIT: signal_name = "SIGQUIT"; break;
 134    case TARGET_SIGILL: signal_name = "SIGILL"; break;
 135    case TARGET_SIGABRT: signal_name = "SIGABRT"; break;
 136    case TARGET_SIGFPE: signal_name = "SIGFPE"; break;
 137    case TARGET_SIGKILL: signal_name = "SIGKILL"; break;
 138    case TARGET_SIGSEGV: signal_name = "SIGSEGV"; break;
 139    case TARGET_SIGPIPE: signal_name = "SIGPIPE"; break;
 140    case TARGET_SIGALRM: signal_name = "SIGALRM"; break;
 141    case TARGET_SIGTERM: signal_name = "SIGTERM"; break;
 142    case TARGET_SIGUSR1: signal_name = "SIGUSR1"; break;
 143    case TARGET_SIGUSR2: signal_name = "SIGUSR2"; break;
 144    case TARGET_SIGCHLD: signal_name = "SIGCHLD"; break;
 145    case TARGET_SIGCONT: signal_name = "SIGCONT"; break;
 146    case TARGET_SIGSTOP: signal_name = "SIGSTOP"; break;
 147    case TARGET_SIGTTIN: signal_name = "SIGTTIN"; break;
 148    case TARGET_SIGTTOU: signal_name = "SIGTTOU"; break;
 149    }
 150    if (signal_name == NULL) {
 151        print_raw_param("%ld", arg, last);
 152        return;
 153    }
 154    gemu_log("%s%s", signal_name, get_comma(last));
 155}
 156
 157static void print_si_code(int arg)
 158{
 159    const char *codename = NULL;
 160
 161    switch (arg) {
 162    case SI_USER:
 163        codename = "SI_USER";
 164        break;
 165    case SI_KERNEL:
 166        codename = "SI_KERNEL";
 167        break;
 168    case SI_QUEUE:
 169        codename = "SI_QUEUE";
 170        break;
 171    case SI_TIMER:
 172        codename = "SI_TIMER";
 173        break;
 174    case SI_MESGQ:
 175        codename = "SI_MESGQ";
 176        break;
 177    case SI_ASYNCIO:
 178        codename = "SI_ASYNCIO";
 179        break;
 180    case SI_SIGIO:
 181        codename = "SI_SIGIO";
 182        break;
 183    case SI_TKILL:
 184        codename = "SI_TKILL";
 185        break;
 186    default:
 187        gemu_log("%d", arg);
 188        return;
 189    }
 190    gemu_log("%s", codename);
 191}
 192
 193static void get_target_siginfo(target_siginfo_t *tinfo,
 194                                const target_siginfo_t *info)
 195{
 196    abi_ulong sival_ptr;
 197
 198    int sig;
 199    int si_errno;
 200    int si_code;
 201    int si_type;
 202
 203    __get_user(sig, &info->si_signo);
 204    __get_user(si_errno, &tinfo->si_errno);
 205    __get_user(si_code, &info->si_code);
 206
 207    tinfo->si_signo = sig;
 208    tinfo->si_errno = si_errno;
 209    tinfo->si_code = si_code;
 210
 211    /* Ensure we don't leak random junk to the guest later */
 212    memset(tinfo->_sifields._pad, 0, sizeof(tinfo->_sifields._pad));
 213
 214    /* This is awkward, because we have to use a combination of
 215     * the si_code and si_signo to figure out which of the union's
 216     * members are valid. (Within the host kernel it is always possible
 217     * to tell, but the kernel carefully avoids giving userspace the
 218     * high 16 bits of si_code, so we don't have the information to
 219     * do this the easy way...) We therefore make our best guess,
 220     * bearing in mind that a guest can spoof most of the si_codes
 221     * via rt_sigqueueinfo() if it likes.
 222     *
 223     * Once we have made our guess, we record it in the top 16 bits of
 224     * the si_code, so that print_siginfo() later can use it.
 225     * print_siginfo() will strip these top bits out before printing
 226     * the si_code.
 227     */
 228
 229    switch (si_code) {
 230    case SI_USER:
 231    case SI_TKILL:
 232    case SI_KERNEL:
 233        /* Sent via kill(), tkill() or tgkill(), or direct from the kernel.
 234         * These are the only unspoofable si_code values.
 235         */
 236        __get_user(tinfo->_sifields._kill._pid, &info->_sifields._kill._pid);
 237        __get_user(tinfo->_sifields._kill._uid, &info->_sifields._kill._uid);
 238        si_type = QEMU_SI_KILL;
 239        break;
 240    default:
 241        /* Everything else is spoofable. Make best guess based on signal */
 242        switch (sig) {
 243        case TARGET_SIGCHLD:
 244            __get_user(tinfo->_sifields._sigchld._pid,
 245                       &info->_sifields._sigchld._pid);
 246            __get_user(tinfo->_sifields._sigchld._uid,
 247                       &info->_sifields._sigchld._uid);
 248            __get_user(tinfo->_sifields._sigchld._status,
 249                       &info->_sifields._sigchld._status);
 250            __get_user(tinfo->_sifields._sigchld._utime,
 251                       &info->_sifields._sigchld._utime);
 252            __get_user(tinfo->_sifields._sigchld._stime,
 253                       &info->_sifields._sigchld._stime);
 254            si_type = QEMU_SI_CHLD;
 255            break;
 256        case TARGET_SIGIO:
 257            __get_user(tinfo->_sifields._sigpoll._band,
 258                       &info->_sifields._sigpoll._band);
 259            __get_user(tinfo->_sifields._sigpoll._fd,
 260                       &info->_sifields._sigpoll._fd);
 261            si_type = QEMU_SI_POLL;
 262            break;
 263        default:
 264            /* Assume a sigqueue()/mq_notify()/rt_sigqueueinfo() source. */
 265            __get_user(tinfo->_sifields._rt._pid, &info->_sifields._rt._pid);
 266            __get_user(tinfo->_sifields._rt._uid, &info->_sifields._rt._uid);
 267            /* XXX: potential problem if 64 bit */
 268            __get_user(sival_ptr, &info->_sifields._rt._sigval.sival_ptr);
 269            tinfo->_sifields._rt._sigval.sival_ptr = sival_ptr;
 270
 271            si_type = QEMU_SI_RT;
 272            break;
 273        }
 274        break;
 275    }
 276
 277    tinfo->si_code = deposit32(si_code, 16, 16, si_type);
 278}
 279
 280static void print_siginfo(const target_siginfo_t *tinfo)
 281{
 282    /* Print a target_siginfo_t in the format desired for printing
 283     * signals being taken. We assume the target_siginfo_t is in the
 284     * internal form where the top 16 bits of si_code indicate which
 285     * part of the union is valid, rather than in the guest-visible
 286     * form where the bottom 16 bits are sign-extended into the top 16.
 287     */
 288    int si_type = extract32(tinfo->si_code, 16, 16);
 289    int si_code = sextract32(tinfo->si_code, 0, 16);
 290
 291    gemu_log("{si_signo=");
 292    print_signal(tinfo->si_signo, 1);
 293    gemu_log(", si_code=");
 294    print_si_code(si_code);
 295
 296    switch (si_type) {
 297    case QEMU_SI_KILL:
 298        gemu_log(", si_pid=%u, si_uid=%u",
 299                 (unsigned int)tinfo->_sifields._kill._pid,
 300                 (unsigned int)tinfo->_sifields._kill._uid);
 301        break;
 302    case QEMU_SI_TIMER:
 303        gemu_log(", si_timer1=%u, si_timer2=%u",
 304                 tinfo->_sifields._timer._timer1,
 305                 tinfo->_sifields._timer._timer2);
 306        break;
 307    case QEMU_SI_POLL:
 308        gemu_log(", si_band=%d, si_fd=%d",
 309                 tinfo->_sifields._sigpoll._band,
 310                 tinfo->_sifields._sigpoll._fd);
 311        break;
 312    case QEMU_SI_FAULT:
 313        gemu_log(", si_addr=");
 314        print_pointer(tinfo->_sifields._sigfault._addr, 1);
 315        break;
 316    case QEMU_SI_CHLD:
 317        gemu_log(", si_pid=%u, si_uid=%u, si_status=%d"
 318                 ", si_utime=" TARGET_ABI_FMT_ld
 319                 ", si_stime=" TARGET_ABI_FMT_ld,
 320                 (unsigned int)(tinfo->_sifields._sigchld._pid),
 321                 (unsigned int)(tinfo->_sifields._sigchld._uid),
 322                 tinfo->_sifields._sigchld._status,
 323                 tinfo->_sifields._sigchld._utime,
 324                 tinfo->_sifields._sigchld._stime);
 325        break;
 326    case QEMU_SI_RT:
 327        gemu_log(", si_pid=%u, si_uid=%u, si_sigval=" TARGET_ABI_FMT_ld,
 328                 (unsigned int)tinfo->_sifields._rt._pid,
 329                 (unsigned int)tinfo->_sifields._rt._uid,
 330                 tinfo->_sifields._rt._sigval.sival_ptr);
 331        break;
 332    default:
 333        g_assert_not_reached();
 334    }
 335    gemu_log("}");
 336}
 337
 338static void
 339print_sockaddr(abi_ulong addr, abi_long addrlen, int last)
 340{
 341    struct target_sockaddr *sa;
 342    int i;
 343    int sa_family;
 344
 345    sa = lock_user(VERIFY_READ, addr, addrlen, 1);
 346    if (sa) {
 347        sa_family = tswap16(sa->sa_family);
 348        switch (sa_family) {
 349        case AF_UNIX: {
 350            struct target_sockaddr_un *un = (struct target_sockaddr_un *)sa;
 351            int i;
 352            gemu_log("{sun_family=AF_UNIX,sun_path=\"");
 353            for (i = 0; i < addrlen -
 354                            offsetof(struct target_sockaddr_un, sun_path) &&
 355                 un->sun_path[i]; i++) {
 356                gemu_log("%c", un->sun_path[i]);
 357            }
 358            gemu_log("\"}");
 359            break;
 360        }
 361        case AF_INET: {
 362            struct target_sockaddr_in *in = (struct target_sockaddr_in *)sa;
 363            uint8_t *c = (uint8_t *)&in->sin_addr.s_addr;
 364            gemu_log("{sin_family=AF_INET,sin_port=htons(%d),",
 365                     ntohs(in->sin_port));
 366            gemu_log("sin_addr=inet_addr(\"%d.%d.%d.%d\")",
 367                     c[0], c[1], c[2], c[3]);
 368            gemu_log("}");
 369            break;
 370        }
 371        case AF_PACKET: {
 372            struct target_sockaddr_ll *ll = (struct target_sockaddr_ll *)sa;
 373            uint8_t *c = (uint8_t *)&ll->sll_addr;
 374            gemu_log("{sll_family=AF_PACKET,"
 375                     "sll_protocol=htons(0x%04x),if%d,pkttype=",
 376                     ntohs(ll->sll_protocol), ll->sll_ifindex);
 377            switch (ll->sll_pkttype) {
 378            case PACKET_HOST:
 379                gemu_log("PACKET_HOST");
 380                break;
 381            case PACKET_BROADCAST:
 382                gemu_log("PACKET_BROADCAST");
 383                break;
 384            case PACKET_MULTICAST:
 385                gemu_log("PACKET_MULTICAST");
 386                break;
 387            case PACKET_OTHERHOST:
 388                gemu_log("PACKET_OTHERHOST");
 389                break;
 390            case PACKET_OUTGOING:
 391                gemu_log("PACKET_OUTGOING");
 392                break;
 393            default:
 394                gemu_log("%d", ll->sll_pkttype);
 395                break;
 396            }
 397            gemu_log(",sll_addr=%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x",
 398                     c[0], c[1], c[2], c[3], c[4], c[5], c[6], c[7]);
 399            gemu_log("}");
 400            break;
 401        }
 402        case AF_NETLINK: {
 403            struct target_sockaddr_nl *nl = (struct target_sockaddr_nl *)sa;
 404            gemu_log("{nl_family=AF_NETLINK,nl_pid=%u,nl_groups=%u}",
 405                     tswap32(nl->nl_pid), tswap32(nl->nl_groups));
 406            break;
 407        }
 408        default:
 409            gemu_log("{sa_family=%d, sa_data={", sa->sa_family);
 410            for (i = 0; i < 13; i++) {
 411                gemu_log("%02x, ", sa->sa_data[i]);
 412            }
 413            gemu_log("%02x}", sa->sa_data[i]);
 414            gemu_log("}");
 415            break;
 416        }
 417        unlock_user(sa, addr, 0);
 418    } else {
 419        print_raw_param("0x"TARGET_ABI_FMT_lx, addr, 0);
 420    }
 421    gemu_log(", "TARGET_ABI_FMT_ld"%s", addrlen, get_comma(last));
 422}
 423
 424static void
 425print_socket_domain(int domain)
 426{
 427    switch (domain) {
 428    case PF_UNIX:
 429        gemu_log("PF_UNIX");
 430        break;
 431    case PF_INET:
 432        gemu_log("PF_INET");
 433        break;
 434    case PF_NETLINK:
 435        gemu_log("PF_NETLINK");
 436        break;
 437    case PF_PACKET:
 438        gemu_log("PF_PACKET");
 439        break;
 440    default:
 441        gemu_log("%d", domain);
 442        break;
 443    }
 444}
 445
 446static void
 447print_socket_type(int type)
 448{
 449    switch (type) {
 450    case TARGET_SOCK_DGRAM:
 451        gemu_log("SOCK_DGRAM");
 452        break;
 453    case TARGET_SOCK_STREAM:
 454        gemu_log("SOCK_STREAM");
 455        break;
 456    case TARGET_SOCK_RAW:
 457        gemu_log("SOCK_RAW");
 458        break;
 459    case TARGET_SOCK_RDM:
 460        gemu_log("SOCK_RDM");
 461        break;
 462    case TARGET_SOCK_SEQPACKET:
 463        gemu_log("SOCK_SEQPACKET");
 464        break;
 465    case TARGET_SOCK_PACKET:
 466        gemu_log("SOCK_PACKET");
 467        break;
 468    }
 469}
 470
 471static void
 472print_socket_protocol(int domain, int type, int protocol)
 473{
 474    if (domain == AF_PACKET ||
 475        (domain == AF_INET && type == TARGET_SOCK_PACKET)) {
 476        switch (protocol) {
 477        case 0x0003:
 478            gemu_log("ETH_P_ALL");
 479            break;
 480        default:
 481            gemu_log("%d", protocol);
 482        }
 483        return;
 484    }
 485
 486    if (domain == PF_NETLINK) {
 487        switch (protocol) {
 488        case NETLINK_ROUTE:
 489            gemu_log("NETLINK_ROUTE");
 490            break;
 491        case NETLINK_AUDIT:
 492            gemu_log("NETLINK_AUDIT");
 493            break;
 494        case NETLINK_NETFILTER:
 495            gemu_log("NETLINK_NETFILTER");
 496            break;
 497        case NETLINK_KOBJECT_UEVENT:
 498            gemu_log("NETLINK_KOBJECT_UEVENT");
 499            break;
 500        case NETLINK_RDMA:
 501            gemu_log("NETLINK_RDMA");
 502            break;
 503        case NETLINK_CRYPTO:
 504            gemu_log("NETLINK_CRYPTO");
 505            break;
 506        default:
 507            gemu_log("%d", protocol);
 508            break;
 509        }
 510        return;
 511    }
 512
 513    switch (protocol) {
 514    case IPPROTO_IP:
 515        gemu_log("IPPROTO_IP");
 516        break;
 517    case IPPROTO_TCP:
 518        gemu_log("IPPROTO_TCP");
 519        break;
 520    case IPPROTO_UDP:
 521        gemu_log("IPPROTO_UDP");
 522        break;
 523    case IPPROTO_RAW:
 524        gemu_log("IPPROTO_RAW");
 525        break;
 526    default:
 527        gemu_log("%d", protocol);
 528        break;
 529    }
 530}
 531
 532
 533#ifdef TARGET_NR__newselect
 534static void
 535print_fdset(int n, abi_ulong target_fds_addr)
 536{
 537    int i;
 538
 539    gemu_log("[");
 540    if( target_fds_addr ) {
 541        abi_long *target_fds;
 542
 543        target_fds = lock_user(VERIFY_READ,
 544                               target_fds_addr,
 545                               sizeof(*target_fds)*(n / TARGET_ABI_BITS + 1),
 546                               1);
 547
 548        if (!target_fds)
 549            return;
 550
 551        for (i=n; i>=0; i--) {
 552            if ((tswapal(target_fds[i / TARGET_ABI_BITS]) >> (i & (TARGET_ABI_BITS - 1))) & 1)
 553                gemu_log("%d,", i );
 554            }
 555        unlock_user(target_fds, target_fds_addr, 0);
 556    }
 557    gemu_log("]");
 558}
 559#endif
 560
 561#ifdef TARGET_NR_clock_adjtime
 562/* IDs of the various system clocks */
 563#define TARGET_CLOCK_REALTIME              0
 564#define TARGET_CLOCK_MONOTONIC             1
 565#define TARGET_CLOCK_PROCESS_CPUTIME_ID    2
 566#define TARGET_CLOCK_THREAD_CPUTIME_ID     3
 567#define TARGET_CLOCK_MONOTONIC_RAW         4
 568#define TARGET_CLOCK_REALTIME_COARSE       5
 569#define TARGET_CLOCK_MONOTONIC_COARSE      6
 570#define TARGET_CLOCK_BOOTTIME              7
 571#define TARGET_CLOCK_REALTIME_ALARM        8
 572#define TARGET_CLOCK_BOOTTIME_ALARM        9
 573#define TARGET_CLOCK_SGI_CYCLE             10
 574#define TARGET_CLOCK_TAI                   11
 575
 576static void
 577print_clockid(int clockid, int last)
 578{
 579    switch (clockid) {
 580    case TARGET_CLOCK_REALTIME:
 581        gemu_log("CLOCK_REALTIME");
 582        break;
 583    case TARGET_CLOCK_MONOTONIC:
 584        gemu_log("CLOCK_MONOTONIC");
 585        break;
 586    case TARGET_CLOCK_PROCESS_CPUTIME_ID:
 587        gemu_log("CLOCK_PROCESS_CPUTIME_ID");
 588        break;
 589    case TARGET_CLOCK_THREAD_CPUTIME_ID:
 590        gemu_log("CLOCK_THREAD_CPUTIME_ID");
 591        break;
 592    case TARGET_CLOCK_MONOTONIC_RAW:
 593        gemu_log("CLOCK_MONOTONIC_RAW");
 594        break;
 595    case TARGET_CLOCK_REALTIME_COARSE:
 596        gemu_log("CLOCK_REALTIME_COARSE");
 597        break;
 598    case TARGET_CLOCK_MONOTONIC_COARSE:
 599        gemu_log("CLOCK_MONOTONIC_COARSE");
 600        break;
 601    case TARGET_CLOCK_BOOTTIME:
 602        gemu_log("CLOCK_BOOTTIME");
 603        break;
 604    case TARGET_CLOCK_REALTIME_ALARM:
 605        gemu_log("CLOCK_REALTIME_ALARM");
 606        break;
 607    case TARGET_CLOCK_BOOTTIME_ALARM:
 608        gemu_log("CLOCK_BOOTTIME_ALARM");
 609        break;
 610    case TARGET_CLOCK_SGI_CYCLE:
 611        gemu_log("CLOCK_SGI_CYCLE");
 612        break;
 613    case TARGET_CLOCK_TAI:
 614        gemu_log("CLOCK_TAI");
 615        break;
 616    default:
 617        gemu_log("%d", clockid);
 618        break;
 619    }
 620    gemu_log("%s", get_comma(last));
 621}
 622#endif
 623
 624/*
 625 * Sysycall specific output functions
 626 */
 627
 628/* select */
 629#ifdef TARGET_NR__newselect
 630static long newselect_arg1 = 0;
 631static long newselect_arg2 = 0;
 632static long newselect_arg3 = 0;
 633static long newselect_arg4 = 0;
 634static long newselect_arg5 = 0;
 635
 636static void
 637print_newselect(const struct syscallname *name,
 638                abi_long arg1, abi_long arg2, abi_long arg3,
 639                abi_long arg4, abi_long arg5, abi_long arg6)
 640{
 641    gemu_log("%s(" TARGET_ABI_FMT_ld ",", name->name, arg1);
 642    print_fdset(arg1, arg2);
 643    gemu_log(",");
 644    print_fdset(arg1, arg3);
 645    gemu_log(",");
 646    print_fdset(arg1, arg4);
 647    gemu_log(",");
 648    print_timeval(arg5, 1);
 649    gemu_log(")");
 650
 651    /* save for use in the return output function below */
 652    newselect_arg1=arg1;
 653    newselect_arg2=arg2;
 654    newselect_arg3=arg3;
 655    newselect_arg4=arg4;
 656    newselect_arg5=arg5;
 657}
 658#endif
 659
 660#ifdef TARGET_NR_semctl
 661static void
 662print_semctl(const struct syscallname *name,
 663             abi_long arg1, abi_long arg2, abi_long arg3,
 664             abi_long arg4, abi_long arg5, abi_long arg6)
 665{
 666    gemu_log("%s(" TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld ",", name->name, arg1, arg2);
 667    print_ipc_cmd(arg3);
 668    gemu_log(",0x" TARGET_ABI_FMT_lx ")", arg4);
 669}
 670#endif
 671
 672static void
 673print_execve(const struct syscallname *name,
 674             abi_long arg1, abi_long arg2, abi_long arg3,
 675             abi_long arg4, abi_long arg5, abi_long arg6)
 676{
 677    abi_ulong arg_ptr_addr;
 678    char *s;
 679
 680    if (!(s = lock_user_string(arg1)))
 681        return;
 682    gemu_log("%s(\"%s\",{", name->name, s);
 683    unlock_user(s, arg1, 0);
 684
 685    for (arg_ptr_addr = arg2; ; arg_ptr_addr += sizeof(abi_ulong)) {
 686        abi_ulong *arg_ptr, arg_addr;
 687
 688        arg_ptr = lock_user(VERIFY_READ, arg_ptr_addr, sizeof(abi_ulong), 1);
 689        if (!arg_ptr)
 690            return;
 691    arg_addr = tswapal(*arg_ptr);
 692        unlock_user(arg_ptr, arg_ptr_addr, 0);
 693        if (!arg_addr)
 694            break;
 695        if ((s = lock_user_string(arg_addr))) {
 696            gemu_log("\"%s\",", s);
 697            unlock_user(s, arg_addr, 0);
 698        }
 699    }
 700
 701    gemu_log("NULL})");
 702}
 703
 704#ifdef TARGET_NR_ipc
 705static void
 706print_ipc(const struct syscallname *name,
 707          abi_long arg1, abi_long arg2, abi_long arg3,
 708          abi_long arg4, abi_long arg5, abi_long arg6)
 709{
 710    switch(arg1) {
 711    case IPCOP_semctl:
 712        gemu_log("semctl(" TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld ",", arg1, arg2);
 713        print_ipc_cmd(arg3);
 714        gemu_log(",0x" TARGET_ABI_FMT_lx ")", arg4);
 715        break;
 716    default:
 717        gemu_log("%s(" TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld ")",
 718                 name->name, arg1, arg2, arg3, arg4);
 719    }
 720}
 721#endif
 722
 723/*
 724 * Variants for the return value output function
 725 */
 726
 727static void
 728print_syscall_ret_addr(const struct syscallname *name, abi_long ret)
 729{
 730    const char *errstr = NULL;
 731
 732    if (ret < 0) {
 733        errstr = target_strerror(-ret);
 734    }
 735    if (errstr) {
 736        gemu_log(" = -1 errno=%d (%s)\n", (int)-ret, errstr);
 737    } else {
 738        gemu_log(" = 0x" TARGET_ABI_FMT_lx "\n", ret);
 739    }
 740}
 741
 742#if 0 /* currently unused */
 743static void
 744print_syscall_ret_raw(struct syscallname *name, abi_long ret)
 745{
 746        gemu_log(" = 0x" TARGET_ABI_FMT_lx "\n", ret);
 747}
 748#endif
 749
 750#ifdef TARGET_NR__newselect
 751static void
 752print_syscall_ret_newselect(const struct syscallname *name, abi_long ret)
 753{
 754    gemu_log(" = 0x" TARGET_ABI_FMT_lx " (", ret);
 755    print_fdset(newselect_arg1,newselect_arg2);
 756    gemu_log(",");
 757    print_fdset(newselect_arg1,newselect_arg3);
 758    gemu_log(",");
 759    print_fdset(newselect_arg1,newselect_arg4);
 760    gemu_log(",");
 761    print_timeval(newselect_arg5, 1);
 762    gemu_log(")\n");
 763}
 764#endif
 765
 766/* special meanings of adjtimex()' non-negative return values */
 767#define TARGET_TIME_OK       0   /* clock synchronized, no leap second */
 768#define TARGET_TIME_INS      1   /* insert leap second */
 769#define TARGET_TIME_DEL      2   /* delete leap second */
 770#define TARGET_TIME_OOP      3   /* leap second in progress */
 771#define TARGET_TIME_WAIT     4   /* leap second has occurred */
 772#define TARGET_TIME_ERROR    5   /* clock not synchronized */
 773static void
 774print_syscall_ret_adjtimex(const struct syscallname *name, abi_long ret)
 775{
 776    const char *errstr = NULL;
 777
 778    gemu_log(" = ");
 779    if (ret < 0) {
 780        gemu_log("-1 errno=%d", errno);
 781        errstr = target_strerror(-ret);
 782        if (errstr) {
 783            gemu_log(" (%s)", errstr);
 784        }
 785    } else {
 786        gemu_log(TARGET_ABI_FMT_ld, ret);
 787        switch (ret) {
 788        case TARGET_TIME_OK:
 789            gemu_log(" TIME_OK (clock synchronized, no leap second)");
 790            break;
 791        case TARGET_TIME_INS:
 792            gemu_log(" TIME_INS (insert leap second)");
 793            break;
 794        case TARGET_TIME_DEL:
 795            gemu_log(" TIME_DEL (delete leap second)");
 796            break;
 797        case TARGET_TIME_OOP:
 798            gemu_log(" TIME_OOP (leap second in progress)");
 799            break;
 800        case TARGET_TIME_WAIT:
 801            gemu_log(" TIME_WAIT (leap second has occurred)");
 802            break;
 803        case TARGET_TIME_ERROR:
 804            gemu_log(" TIME_ERROR (clock not synchronized)");
 805            break;
 806        }
 807    }
 808
 809    gemu_log("\n");
 810}
 811
 812UNUSED static struct flags access_flags[] = {
 813    FLAG_GENERIC(F_OK),
 814    FLAG_GENERIC(R_OK),
 815    FLAG_GENERIC(W_OK),
 816    FLAG_GENERIC(X_OK),
 817    FLAG_END,
 818};
 819
 820UNUSED static struct flags at_file_flags[] = {
 821#ifdef AT_EACCESS
 822    FLAG_GENERIC(AT_EACCESS),
 823#endif
 824#ifdef AT_SYMLINK_NOFOLLOW
 825    FLAG_GENERIC(AT_SYMLINK_NOFOLLOW),
 826#endif
 827    FLAG_END,
 828};
 829
 830UNUSED static struct flags unlinkat_flags[] = {
 831#ifdef AT_REMOVEDIR
 832    FLAG_GENERIC(AT_REMOVEDIR),
 833#endif
 834    FLAG_END,
 835};
 836
 837UNUSED static struct flags mode_flags[] = {
 838    FLAG_GENERIC(S_IFSOCK),
 839    FLAG_GENERIC(S_IFLNK),
 840    FLAG_GENERIC(S_IFREG),
 841    FLAG_GENERIC(S_IFBLK),
 842    FLAG_GENERIC(S_IFDIR),
 843    FLAG_GENERIC(S_IFCHR),
 844    FLAG_GENERIC(S_IFIFO),
 845    FLAG_END,
 846};
 847
 848UNUSED static struct flags open_access_flags[] = {
 849    FLAG_TARGET(O_RDONLY),
 850    FLAG_TARGET(O_WRONLY),
 851    FLAG_TARGET(O_RDWR),
 852    FLAG_END,
 853};
 854
 855UNUSED static struct flags open_flags[] = {
 856    FLAG_TARGET(O_APPEND),
 857    FLAG_TARGET(O_CREAT),
 858    FLAG_TARGET(O_DIRECTORY),
 859    FLAG_TARGET(O_EXCL),
 860    FLAG_TARGET(O_LARGEFILE),
 861    FLAG_TARGET(O_NOCTTY),
 862    FLAG_TARGET(O_NOFOLLOW),
 863    FLAG_TARGET(O_NONBLOCK),      /* also O_NDELAY */
 864    FLAG_TARGET(O_DSYNC),
 865    FLAG_TARGET(__O_SYNC),
 866    FLAG_TARGET(O_TRUNC),
 867#ifdef O_DIRECT
 868    FLAG_TARGET(O_DIRECT),
 869#endif
 870#ifdef O_NOATIME
 871    FLAG_TARGET(O_NOATIME),
 872#endif
 873#ifdef O_CLOEXEC
 874    FLAG_TARGET(O_CLOEXEC),
 875#endif
 876#ifdef O_PATH
 877    FLAG_TARGET(O_PATH),
 878#endif
 879#ifdef O_TMPFILE
 880    FLAG_TARGET(O_TMPFILE),
 881    FLAG_TARGET(__O_TMPFILE),
 882#endif
 883    FLAG_END,
 884};
 885
 886UNUSED static struct flags mount_flags[] = {
 887#ifdef MS_BIND
 888    FLAG_GENERIC(MS_BIND),
 889#endif
 890#ifdef MS_DIRSYNC
 891    FLAG_GENERIC(MS_DIRSYNC),
 892#endif
 893    FLAG_GENERIC(MS_MANDLOCK),
 894#ifdef MS_MOVE
 895    FLAG_GENERIC(MS_MOVE),
 896#endif
 897    FLAG_GENERIC(MS_NOATIME),
 898    FLAG_GENERIC(MS_NODEV),
 899    FLAG_GENERIC(MS_NODIRATIME),
 900    FLAG_GENERIC(MS_NOEXEC),
 901    FLAG_GENERIC(MS_NOSUID),
 902    FLAG_GENERIC(MS_RDONLY),
 903#ifdef MS_RELATIME
 904    FLAG_GENERIC(MS_RELATIME),
 905#endif
 906    FLAG_GENERIC(MS_REMOUNT),
 907    FLAG_GENERIC(MS_SYNCHRONOUS),
 908    FLAG_END,
 909};
 910
 911UNUSED static struct flags umount2_flags[] = {
 912#ifdef MNT_FORCE
 913    FLAG_GENERIC(MNT_FORCE),
 914#endif
 915#ifdef MNT_DETACH
 916    FLAG_GENERIC(MNT_DETACH),
 917#endif
 918#ifdef MNT_EXPIRE
 919    FLAG_GENERIC(MNT_EXPIRE),
 920#endif
 921    FLAG_END,
 922};
 923
 924UNUSED static struct flags mmap_prot_flags[] = {
 925    FLAG_GENERIC(PROT_NONE),
 926    FLAG_GENERIC(PROT_EXEC),
 927    FLAG_GENERIC(PROT_READ),
 928    FLAG_GENERIC(PROT_WRITE),
 929    FLAG_TARGET(PROT_SEM),
 930    FLAG_GENERIC(PROT_GROWSDOWN),
 931    FLAG_GENERIC(PROT_GROWSUP),
 932    FLAG_END,
 933};
 934
 935UNUSED static struct flags mmap_flags[] = {
 936    FLAG_TARGET(MAP_SHARED),
 937    FLAG_TARGET(MAP_PRIVATE),
 938    FLAG_TARGET(MAP_ANONYMOUS),
 939    FLAG_TARGET(MAP_DENYWRITE),
 940    FLAG_TARGET(MAP_FIXED),
 941    FLAG_TARGET(MAP_GROWSDOWN),
 942    FLAG_TARGET(MAP_EXECUTABLE),
 943#ifdef MAP_LOCKED
 944    FLAG_TARGET(MAP_LOCKED),
 945#endif
 946#ifdef MAP_NONBLOCK
 947    FLAG_TARGET(MAP_NONBLOCK),
 948#endif
 949    FLAG_TARGET(MAP_NORESERVE),
 950#ifdef MAP_POPULATE
 951    FLAG_TARGET(MAP_POPULATE),
 952#endif
 953#ifdef TARGET_MAP_UNINITIALIZED
 954    FLAG_TARGET(MAP_UNINITIALIZED),
 955#endif
 956    FLAG_END,
 957};
 958
 959UNUSED static struct flags clone_flags[] = {
 960    FLAG_GENERIC(CLONE_VM),
 961    FLAG_GENERIC(CLONE_FS),
 962    FLAG_GENERIC(CLONE_FILES),
 963    FLAG_GENERIC(CLONE_SIGHAND),
 964    FLAG_GENERIC(CLONE_PTRACE),
 965    FLAG_GENERIC(CLONE_VFORK),
 966    FLAG_GENERIC(CLONE_PARENT),
 967    FLAG_GENERIC(CLONE_THREAD),
 968    FLAG_GENERIC(CLONE_NEWNS),
 969    FLAG_GENERIC(CLONE_SYSVSEM),
 970    FLAG_GENERIC(CLONE_SETTLS),
 971    FLAG_GENERIC(CLONE_PARENT_SETTID),
 972    FLAG_GENERIC(CLONE_CHILD_CLEARTID),
 973    FLAG_GENERIC(CLONE_DETACHED),
 974    FLAG_GENERIC(CLONE_UNTRACED),
 975    FLAG_GENERIC(CLONE_CHILD_SETTID),
 976#if defined(CLONE_NEWUTS)
 977    FLAG_GENERIC(CLONE_NEWUTS),
 978#endif
 979#if defined(CLONE_NEWIPC)
 980    FLAG_GENERIC(CLONE_NEWIPC),
 981#endif
 982#if defined(CLONE_NEWUSER)
 983    FLAG_GENERIC(CLONE_NEWUSER),
 984#endif
 985#if defined(CLONE_NEWPID)
 986    FLAG_GENERIC(CLONE_NEWPID),
 987#endif
 988#if defined(CLONE_NEWNET)
 989    FLAG_GENERIC(CLONE_NEWNET),
 990#endif
 991#if defined(CLONE_IO)
 992    FLAG_GENERIC(CLONE_IO),
 993#endif
 994    FLAG_END,
 995};
 996
 997UNUSED static struct flags msg_flags[] = {
 998    /* send */
 999    FLAG_GENERIC(MSG_CONFIRM),
1000    FLAG_GENERIC(MSG_DONTROUTE),
1001    FLAG_GENERIC(MSG_DONTWAIT),
1002    FLAG_GENERIC(MSG_EOR),
1003    FLAG_GENERIC(MSG_MORE),
1004    FLAG_GENERIC(MSG_NOSIGNAL),
1005    FLAG_GENERIC(MSG_OOB),
1006    /* recv */
1007    FLAG_GENERIC(MSG_CMSG_CLOEXEC),
1008    FLAG_GENERIC(MSG_ERRQUEUE),
1009    FLAG_GENERIC(MSG_PEEK),
1010    FLAG_GENERIC(MSG_TRUNC),
1011    FLAG_GENERIC(MSG_WAITALL),
1012    /* recvmsg */
1013    FLAG_GENERIC(MSG_CTRUNC),
1014    FLAG_END,
1015};
1016
1017UNUSED static struct flags statx_flags[] = {
1018#ifdef AT_EMPTY_PATH
1019    FLAG_GENERIC(AT_EMPTY_PATH),
1020#endif
1021#ifdef AT_NO_AUTOMOUNT
1022    FLAG_GENERIC(AT_NO_AUTOMOUNT),
1023#endif
1024#ifdef AT_SYMLINK_NOFOLLOW
1025    FLAG_GENERIC(AT_SYMLINK_NOFOLLOW),
1026#endif
1027#ifdef AT_STATX_SYNC_AS_STAT
1028    FLAG_GENERIC(AT_STATX_SYNC_AS_STAT),
1029#endif
1030#ifdef AT_STATX_FORCE_SYNC
1031    FLAG_GENERIC(AT_STATX_FORCE_SYNC),
1032#endif
1033#ifdef AT_STATX_DONT_SYNC
1034    FLAG_GENERIC(AT_STATX_DONT_SYNC),
1035#endif
1036    FLAG_END,
1037};
1038
1039UNUSED static struct flags statx_mask[] = {
1040/* This must come first, because it includes everything.  */
1041#ifdef STATX_ALL
1042    FLAG_GENERIC(STATX_ALL),
1043#endif
1044/* This must come second; it includes everything except STATX_BTIME.  */
1045#ifdef STATX_BASIC_STATS
1046    FLAG_GENERIC(STATX_BASIC_STATS),
1047#endif
1048#ifdef STATX_TYPE
1049    FLAG_GENERIC(STATX_TYPE),
1050#endif
1051#ifdef STATX_MODE
1052    FLAG_GENERIC(STATX_MODE),
1053#endif
1054#ifdef STATX_NLINK
1055    FLAG_GENERIC(STATX_NLINK),
1056#endif
1057#ifdef STATX_UID
1058    FLAG_GENERIC(STATX_UID),
1059#endif
1060#ifdef STATX_GID
1061    FLAG_GENERIC(STATX_GID),
1062#endif
1063#ifdef STATX_ATIME
1064    FLAG_GENERIC(STATX_ATIME),
1065#endif
1066#ifdef STATX_MTIME
1067    FLAG_GENERIC(STATX_MTIME),
1068#endif
1069#ifdef STATX_CTIME
1070    FLAG_GENERIC(STATX_CTIME),
1071#endif
1072#ifdef STATX_INO
1073    FLAG_GENERIC(STATX_INO),
1074#endif
1075#ifdef STATX_SIZE
1076    FLAG_GENERIC(STATX_SIZE),
1077#endif
1078#ifdef STATX_BLOCKS
1079    FLAG_GENERIC(STATX_BLOCKS),
1080#endif
1081#ifdef STATX_BTIME
1082    FLAG_GENERIC(STATX_BTIME),
1083#endif
1084    FLAG_END,
1085};
1086
1087/*
1088 * print_xxx utility functions.  These are used to print syscall
1089 * parameters in certain format.  All of these have parameter
1090 * named 'last'.  This parameter is used to add comma to output
1091 * when last == 0.
1092 */
1093
1094static const char *
1095get_comma(int last)
1096{
1097    return ((last) ? "" : ",");
1098}
1099
1100static void
1101print_flags(const struct flags *f, abi_long flags, int last)
1102{
1103    const char *sep = "";
1104    int n;
1105
1106    if ((flags == 0) && (f->f_value == 0)) {
1107        gemu_log("%s%s", f->f_string, get_comma(last));
1108        return;
1109    }
1110    for (n = 0; f->f_string != NULL; f++) {
1111        if ((f->f_value != 0) && ((flags & f->f_value) == f->f_value)) {
1112            gemu_log("%s%s", sep, f->f_string);
1113            flags &= ~f->f_value;
1114            sep = "|";
1115            n++;
1116        }
1117    }
1118
1119    if (n > 0) {
1120        /* print rest of the flags as numeric */
1121        if (flags != 0) {
1122            gemu_log("%s%#x%s", sep, (unsigned int)flags, get_comma(last));
1123        } else {
1124            gemu_log("%s", get_comma(last));
1125        }
1126    } else {
1127        /* no string version of flags found, print them in hex then */
1128        gemu_log("%#x%s", (unsigned int)flags, get_comma(last));
1129    }
1130}
1131
1132static void
1133print_at_dirfd(abi_long dirfd, int last)
1134{
1135#ifdef AT_FDCWD
1136    if (dirfd == AT_FDCWD) {
1137        gemu_log("AT_FDCWD%s", get_comma(last));
1138        return;
1139    }
1140#endif
1141    gemu_log("%d%s", (int)dirfd, get_comma(last));
1142}
1143
1144static void
1145print_file_mode(abi_long mode, int last)
1146{
1147    const char *sep = "";
1148    const struct flags *m;
1149
1150    for (m = &mode_flags[0]; m->f_string != NULL; m++) {
1151        if ((m->f_value & mode) == m->f_value) {
1152            gemu_log("%s%s", m->f_string, sep);
1153            sep = "|";
1154            mode &= ~m->f_value;
1155            break;
1156        }
1157    }
1158
1159    mode &= ~S_IFMT;
1160    /* print rest of the mode as octal */
1161    if (mode != 0)
1162        gemu_log("%s%#o", sep, (unsigned int)mode);
1163
1164    gemu_log("%s", get_comma(last));
1165}
1166
1167static void
1168print_open_flags(abi_long flags, int last)
1169{
1170    print_flags(open_access_flags, flags & TARGET_O_ACCMODE, 1);
1171    flags &= ~TARGET_O_ACCMODE;
1172    if (flags == 0) {
1173        gemu_log("%s", get_comma(last));
1174        return;
1175    }
1176    gemu_log("|");
1177    print_flags(open_flags, flags, last);
1178}
1179
1180static void
1181print_syscall_prologue(const struct syscallname *sc)
1182{
1183    gemu_log("%s(", sc->name);
1184}
1185
1186/*ARGSUSED*/
1187static void
1188print_syscall_epilogue(const struct syscallname *sc)
1189{
1190    (void)sc;
1191    gemu_log(")");
1192}
1193
1194static void
1195print_string(abi_long addr, int last)
1196{
1197    char *s;
1198
1199    if ((s = lock_user_string(addr)) != NULL) {
1200        gemu_log("\"%s\"%s", s, get_comma(last));
1201        unlock_user(s, addr, 0);
1202    } else {
1203        /* can't get string out of it, so print it as pointer */
1204        print_pointer(addr, last);
1205    }
1206}
1207
1208#define MAX_PRINT_BUF 40
1209static void
1210print_buf(abi_long addr, abi_long len, int last)
1211{
1212    uint8_t *s;
1213    int i;
1214
1215    s = lock_user(VERIFY_READ, addr, len, 1);
1216    if (s) {
1217        gemu_log("\"");
1218        for (i = 0; i < MAX_PRINT_BUF && i < len; i++) {
1219            if (isprint(s[i])) {
1220                gemu_log("%c", s[i]);
1221            } else {
1222                gemu_log("\\%o", s[i]);
1223            }
1224        }
1225        gemu_log("\"");
1226        if (i != len) {
1227            gemu_log("...");
1228        }
1229        if (!last) {
1230            gemu_log(",");
1231        }
1232        unlock_user(s, addr, 0);
1233    } else {
1234        print_pointer(addr, last);
1235    }
1236}
1237
1238/*
1239 * Prints out raw parameter using given format.  Caller needs
1240 * to do byte swapping if needed.
1241 */
1242static void
1243print_raw_param(const char *fmt, abi_long param, int last)
1244{
1245    char format[64];
1246
1247    (void) snprintf(format, sizeof (format), "%s%s", fmt, get_comma(last));
1248    gemu_log(format, param);
1249}
1250
1251static void
1252print_pointer(abi_long p, int last)
1253{
1254    if (p == 0)
1255        gemu_log("NULL%s", get_comma(last));
1256    else
1257        gemu_log("0x" TARGET_ABI_FMT_lx "%s", p, get_comma(last));
1258}
1259
1260/*
1261 * Reads 32-bit (int) number from guest address space from
1262 * address 'addr' and prints it.
1263 */
1264static void
1265print_number(abi_long addr, int last)
1266{
1267    if (addr == 0) {
1268        gemu_log("NULL%s", get_comma(last));
1269    } else {
1270        int num;
1271
1272        get_user_s32(num, addr);
1273        gemu_log("[%d]%s", num, get_comma(last));
1274    }
1275}
1276
1277static void
1278print_timeval(abi_ulong tv_addr, int last)
1279{
1280    if( tv_addr ) {
1281        struct target_timeval *tv;
1282
1283        tv = lock_user(VERIFY_READ, tv_addr, sizeof(*tv), 1);
1284        if (!tv) {
1285            print_pointer(tv_addr, last);
1286            return;
1287        }
1288        gemu_log("{" TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld "}%s",
1289            tswapal(tv->tv_sec), tswapal(tv->tv_usec), get_comma(last));
1290        unlock_user(tv, tv_addr, 0);
1291    } else
1292        gemu_log("NULL%s", get_comma(last));
1293}
1294
1295static void
1296print_timezone(abi_ulong tz_addr, int last)
1297{
1298    if (tz_addr) {
1299        struct target_timezone *tz;
1300
1301        tz = lock_user(VERIFY_READ, tz_addr, sizeof(*tz), 1);
1302        if (!tz) {
1303            print_pointer(tz_addr, last);
1304            return;
1305        }
1306        gemu_log("{%d,%d}%s", tswap32(tz->tz_minuteswest),
1307                 tswap32(tz->tz_dsttime), get_comma(last));
1308        unlock_user(tz, tz_addr, 0);
1309    } else {
1310        gemu_log("NULL%s", get_comma(last));
1311    }
1312}
1313
1314#undef UNUSED
1315
1316#ifdef TARGET_NR_accept
1317static void
1318print_accept(const struct syscallname *name,
1319    abi_long arg0, abi_long arg1, abi_long arg2,
1320    abi_long arg3, abi_long arg4, abi_long arg5)
1321{
1322    print_syscall_prologue(name);
1323    print_raw_param("%d", arg0, 0);
1324    print_pointer(arg1, 0);
1325    print_number(arg2, 1);
1326    print_syscall_epilogue(name);
1327}
1328#endif
1329
1330#ifdef TARGET_NR_access
1331static void
1332print_access(const struct syscallname *name,
1333    abi_long arg0, abi_long arg1, abi_long arg2,
1334    abi_long arg3, abi_long arg4, abi_long arg5)
1335{
1336    print_syscall_prologue(name);
1337    print_string(arg0, 0);
1338    print_flags(access_flags, arg1, 1);
1339    print_syscall_epilogue(name);
1340}
1341#endif
1342
1343#ifdef TARGET_NR_brk
1344static void
1345print_brk(const struct syscallname *name,
1346    abi_long arg0, abi_long arg1, abi_long arg2,
1347    abi_long arg3, abi_long arg4, abi_long arg5)
1348{
1349    print_syscall_prologue(name);
1350    print_pointer(arg0, 1);
1351    print_syscall_epilogue(name);
1352}
1353#endif
1354
1355#ifdef TARGET_NR_chdir
1356static void
1357print_chdir(const struct syscallname *name,
1358    abi_long arg0, abi_long arg1, abi_long arg2,
1359    abi_long arg3, abi_long arg4, abi_long arg5)
1360{
1361    print_syscall_prologue(name);
1362    print_string(arg0, 1);
1363    print_syscall_epilogue(name);
1364}
1365#endif
1366
1367#ifdef TARGET_NR_chroot
1368static void
1369print_chroot(const struct syscallname *name,
1370    abi_long arg0, abi_long arg1, abi_long arg2,
1371    abi_long arg3, abi_long arg4, abi_long arg5)
1372{
1373    print_syscall_prologue(name);
1374    print_string(arg0, 1);
1375    print_syscall_epilogue(name);
1376}
1377#endif
1378
1379#ifdef TARGET_NR_chmod
1380static void
1381print_chmod(const struct syscallname *name,
1382    abi_long arg0, abi_long arg1, abi_long arg2,
1383    abi_long arg3, abi_long arg4, abi_long arg5)
1384{
1385    print_syscall_prologue(name);
1386    print_string(arg0, 0);
1387    print_file_mode(arg1, 1);
1388    print_syscall_epilogue(name);
1389}
1390#endif
1391
1392#ifdef TARGET_NR_clock_adjtime
1393static void
1394print_clock_adjtime(const struct syscallname *name,
1395    abi_long arg0, abi_long arg1, abi_long arg2,
1396    abi_long arg3, abi_long arg4, abi_long arg5)
1397{
1398    print_syscall_prologue(name);
1399    print_clockid(arg0, 0);
1400    print_pointer(arg1, 1);
1401    print_syscall_epilogue(name);
1402}
1403#endif
1404
1405#ifdef TARGET_NR_clone
1406static void do_print_clone(unsigned int flags, abi_ulong newsp,
1407                           abi_ulong parent_tidptr, target_ulong newtls,
1408                           abi_ulong child_tidptr)
1409{
1410    print_flags(clone_flags, flags, 0);
1411    print_raw_param("child_stack=0x" TARGET_ABI_FMT_lx, newsp, 0);
1412    print_raw_param("parent_tidptr=0x" TARGET_ABI_FMT_lx, parent_tidptr, 0);
1413    print_raw_param("tls=0x" TARGET_ABI_FMT_lx, newtls, 0);
1414    print_raw_param("child_tidptr=0x" TARGET_ABI_FMT_lx, child_tidptr, 1);
1415}
1416
1417static void
1418print_clone(const struct syscallname *name,
1419    abi_long arg1, abi_long arg2, abi_long arg3,
1420    abi_long arg4, abi_long arg5, abi_long arg6)
1421{
1422    print_syscall_prologue(name);
1423#if defined(TARGET_MICROBLAZE)
1424    do_print_clone(arg1, arg2, arg4, arg6, arg5);
1425#elif defined(TARGET_CLONE_BACKWARDS)
1426    do_print_clone(arg1, arg2, arg3, arg4, arg5);
1427#elif defined(TARGET_CLONE_BACKWARDS2)
1428    do_print_clone(arg2, arg1, arg3, arg5, arg4);
1429#else
1430    do_print_clone(arg1, arg2, arg3, arg5, arg4);
1431#endif
1432    print_syscall_epilogue(name);
1433}
1434#endif
1435
1436#ifdef TARGET_NR_creat
1437static void
1438print_creat(const struct syscallname *name,
1439    abi_long arg0, abi_long arg1, abi_long arg2,
1440    abi_long arg3, abi_long arg4, abi_long arg5)
1441{
1442    print_syscall_prologue(name);
1443    print_string(arg0, 0);
1444    print_file_mode(arg1, 1);
1445    print_syscall_epilogue(name);
1446}
1447#endif
1448
1449#ifdef TARGET_NR_execv
1450static void
1451print_execv(const struct syscallname *name,
1452    abi_long arg0, abi_long arg1, abi_long arg2,
1453    abi_long arg3, abi_long arg4, abi_long arg5)
1454{
1455    print_syscall_prologue(name);
1456    print_string(arg0, 0);
1457    print_raw_param("0x" TARGET_ABI_FMT_lx, arg1, 1);
1458    print_syscall_epilogue(name);
1459}
1460#endif
1461
1462#ifdef TARGET_NR_faccessat
1463static void
1464print_faccessat(const struct syscallname *name,
1465    abi_long arg0, abi_long arg1, abi_long arg2,
1466    abi_long arg3, abi_long arg4, abi_long arg5)
1467{
1468    print_syscall_prologue(name);
1469    print_at_dirfd(arg0, 0);
1470    print_string(arg1, 0);
1471    print_flags(access_flags, arg2, 0);
1472    print_flags(at_file_flags, arg3, 1);
1473    print_syscall_epilogue(name);
1474}
1475#endif
1476
1477#ifdef TARGET_NR_fchmodat
1478static void
1479print_fchmodat(const struct syscallname *name,
1480    abi_long arg0, abi_long arg1, abi_long arg2,
1481    abi_long arg3, abi_long arg4, abi_long arg5)
1482{
1483    print_syscall_prologue(name);
1484    print_at_dirfd(arg0, 0);
1485    print_string(arg1, 0);
1486    print_file_mode(arg2, 0);
1487    print_flags(at_file_flags, arg3, 1);
1488    print_syscall_epilogue(name);
1489}
1490#endif
1491
1492#ifdef TARGET_NR_fchownat
1493static void
1494print_fchownat(const struct syscallname *name,
1495    abi_long arg0, abi_long arg1, abi_long arg2,
1496    abi_long arg3, abi_long arg4, abi_long arg5)
1497{
1498    print_syscall_prologue(name);
1499    print_at_dirfd(arg0, 0);
1500    print_string(arg1, 0);
1501    print_raw_param("%d", arg2, 0);
1502    print_raw_param("%d", arg3, 0);
1503    print_flags(at_file_flags, arg4, 1);
1504    print_syscall_epilogue(name);
1505}
1506#endif
1507
1508#if defined(TARGET_NR_fcntl) || defined(TARGET_NR_fcntl64)
1509static void
1510print_fcntl(const struct syscallname *name,
1511    abi_long arg0, abi_long arg1, abi_long arg2,
1512    abi_long arg3, abi_long arg4, abi_long arg5)
1513{
1514    print_syscall_prologue(name);
1515    print_raw_param("%d", arg0, 0);
1516    switch(arg1) {
1517    case TARGET_F_DUPFD:
1518        gemu_log("F_DUPFD,");
1519        print_raw_param(TARGET_ABI_FMT_ld, arg2, 1);
1520        break;
1521    case TARGET_F_GETFD:
1522        gemu_log("F_GETFD");
1523        break;
1524    case TARGET_F_SETFD:
1525        gemu_log("F_SETFD,");
1526        print_raw_param(TARGET_ABI_FMT_ld, arg2, 1);
1527        break;
1528    case TARGET_F_GETFL:
1529        gemu_log("F_GETFL");
1530        break;
1531    case TARGET_F_SETFL:
1532        gemu_log("F_SETFL,");
1533        print_open_flags(arg2, 1);
1534        break;
1535    case TARGET_F_GETLK:
1536        gemu_log("F_GETLK,");
1537        print_pointer(arg2, 1);
1538        break;
1539    case TARGET_F_SETLK:
1540        gemu_log("F_SETLK,");
1541        print_pointer(arg2, 1);
1542        break;
1543    case TARGET_F_SETLKW:
1544        gemu_log("F_SETLKW,");
1545        print_pointer(arg2, 1);
1546        break;
1547    case TARGET_F_GETOWN:
1548        gemu_log("F_GETOWN");
1549        break;
1550    case TARGET_F_SETOWN:
1551        gemu_log("F_SETOWN,");
1552        print_raw_param(TARGET_ABI_FMT_ld, arg2, 0);
1553        break;
1554    case TARGET_F_GETSIG:
1555        gemu_log("F_GETSIG");
1556        break;
1557    case TARGET_F_SETSIG:
1558        gemu_log("F_SETSIG,");
1559        print_raw_param(TARGET_ABI_FMT_ld, arg2, 0);
1560        break;
1561#if TARGET_ABI_BITS == 32
1562    case TARGET_F_GETLK64:
1563        gemu_log("F_GETLK64,");
1564        print_pointer(arg2, 1);
1565        break;
1566    case TARGET_F_SETLK64:
1567        gemu_log("F_SETLK64,");
1568        print_pointer(arg2, 1);
1569        break;
1570    case TARGET_F_SETLKW64:
1571        gemu_log("F_SETLKW64,");
1572        print_pointer(arg2, 1);
1573        break;
1574#endif
1575    case TARGET_F_SETLEASE:
1576        gemu_log("F_SETLEASE,");
1577        print_raw_param(TARGET_ABI_FMT_ld, arg2, 0);
1578        break;
1579    case TARGET_F_GETLEASE:
1580        gemu_log("F_GETLEASE");
1581        break;
1582    case TARGET_F_SETPIPE_SZ:
1583        gemu_log("F_SETPIPE_SZ,");
1584        print_raw_param(TARGET_ABI_FMT_ld, arg2, 1);
1585        break;
1586    case TARGET_F_GETPIPE_SZ:
1587        gemu_log("F_GETPIPE_SZ");
1588        break;
1589    case TARGET_F_DUPFD_CLOEXEC:
1590        gemu_log("F_DUPFD_CLOEXEC,");
1591        print_raw_param(TARGET_ABI_FMT_ld, arg2, 1);
1592        break;
1593    case TARGET_F_NOTIFY:
1594        gemu_log("F_NOTIFY,");
1595        print_raw_param(TARGET_ABI_FMT_ld, arg2, 0);
1596        break;
1597    default:
1598        print_raw_param(TARGET_ABI_FMT_ld, arg1, 0);
1599        print_pointer(arg2, 1);
1600        break;
1601    }
1602    print_syscall_epilogue(name);
1603}
1604#define print_fcntl64   print_fcntl
1605#endif
1606
1607
1608#ifdef TARGET_NR_futimesat
1609static void
1610print_futimesat(const struct syscallname *name,
1611    abi_long arg0, abi_long arg1, abi_long arg2,
1612    abi_long arg3, abi_long arg4, abi_long arg5)
1613{
1614    print_syscall_prologue(name);
1615    print_at_dirfd(arg0, 0);
1616    print_string(arg1, 0);
1617    print_timeval(arg2, 0);
1618    print_timeval(arg2 + sizeof (struct target_timeval), 1);
1619    print_syscall_epilogue(name);
1620}
1621#endif
1622
1623#ifdef TARGET_NR_settimeofday
1624static void
1625print_settimeofday(const struct syscallname *name,
1626                abi_long arg0, abi_long arg1, abi_long arg2,
1627                abi_long arg3, abi_long arg4, abi_long arg5)
1628{
1629    print_syscall_prologue(name);
1630    print_timeval(arg0, 0);
1631    print_timezone(arg1, 1);
1632    print_syscall_epilogue(name);
1633}
1634#endif
1635
1636#ifdef TARGET_NR_link
1637static void
1638print_link(const struct syscallname *name,
1639    abi_long arg0, abi_long arg1, abi_long arg2,
1640    abi_long arg3, abi_long arg4, abi_long arg5)
1641{
1642    print_syscall_prologue(name);
1643    print_string(arg0, 0);
1644    print_string(arg1, 1);
1645    print_syscall_epilogue(name);
1646}
1647#endif
1648
1649#ifdef TARGET_NR_linkat
1650static void
1651print_linkat(const struct syscallname *name,
1652    abi_long arg0, abi_long arg1, abi_long arg2,
1653    abi_long arg3, abi_long arg4, abi_long arg5)
1654{
1655    print_syscall_prologue(name);
1656    print_at_dirfd(arg0, 0);
1657    print_string(arg1, 0);
1658    print_at_dirfd(arg2, 0);
1659    print_string(arg3, 0);
1660    print_flags(at_file_flags, arg4, 1);
1661    print_syscall_epilogue(name);
1662}
1663#endif
1664
1665#ifdef TARGET_NR__llseek
1666static void
1667print__llseek(const struct syscallname *name,
1668    abi_long arg0, abi_long arg1, abi_long arg2,
1669    abi_long arg3, abi_long arg4, abi_long arg5)
1670{
1671    const char *whence = "UNKNOWN";
1672    print_syscall_prologue(name);
1673    print_raw_param("%d", arg0, 0);
1674    print_raw_param("%ld", arg1, 0);
1675    print_raw_param("%ld", arg2, 0);
1676    print_pointer(arg3, 0);
1677    switch(arg4) {
1678    case SEEK_SET: whence = "SEEK_SET"; break;
1679    case SEEK_CUR: whence = "SEEK_CUR"; break;
1680    case SEEK_END: whence = "SEEK_END"; break;
1681    }
1682    gemu_log("%s",whence);
1683    print_syscall_epilogue(name);
1684}
1685#endif
1686
1687#if defined(TARGET_NR_socket)
1688static void
1689print_socket(const struct syscallname *name,
1690             abi_long arg0, abi_long arg1, abi_long arg2,
1691             abi_long arg3, abi_long arg4, abi_long arg5)
1692{
1693    abi_ulong domain = arg0, type = arg1, protocol = arg2;
1694
1695    print_syscall_prologue(name);
1696    print_socket_domain(domain);
1697    gemu_log(",");
1698    print_socket_type(type);
1699    gemu_log(",");
1700    if (domain == AF_PACKET ||
1701        (domain == AF_INET && type == TARGET_SOCK_PACKET)) {
1702        protocol = tswap16(protocol);
1703    }
1704    print_socket_protocol(domain, type, protocol);
1705    print_syscall_epilogue(name);
1706}
1707
1708#endif
1709
1710#if defined(TARGET_NR_socketcall) || defined(TARGET_NR_bind)
1711
1712static void print_sockfd(abi_long sockfd, int last)
1713{
1714    print_raw_param(TARGET_ABI_FMT_ld, sockfd, last);
1715}
1716
1717#endif
1718
1719#if defined(TARGET_NR_socketcall)
1720
1721#define get_user_ualx(x, gaddr, idx) \
1722        get_user_ual(x, (gaddr) + (idx) * sizeof(abi_long))
1723
1724static void do_print_socket(const char *name, abi_long arg1)
1725{
1726    abi_ulong domain, type, protocol;
1727
1728    get_user_ualx(domain, arg1, 0);
1729    get_user_ualx(type, arg1, 1);
1730    get_user_ualx(protocol, arg1, 2);
1731    gemu_log("%s(", name);
1732    print_socket_domain(domain);
1733    gemu_log(",");
1734    print_socket_type(type);
1735    gemu_log(",");
1736    if (domain == AF_PACKET ||
1737        (domain == AF_INET && type == TARGET_SOCK_PACKET)) {
1738        protocol = tswap16(protocol);
1739    }
1740    print_socket_protocol(domain, type, protocol);
1741    gemu_log(")");
1742}
1743
1744static void do_print_sockaddr(const char *name, abi_long arg1)
1745{
1746    abi_ulong sockfd, addr, addrlen;
1747
1748    get_user_ualx(sockfd, arg1, 0);
1749    get_user_ualx(addr, arg1, 1);
1750    get_user_ualx(addrlen, arg1, 2);
1751
1752    gemu_log("%s(", name);
1753    print_sockfd(sockfd, 0);
1754    print_sockaddr(addr, addrlen, 0);
1755    gemu_log(")");
1756}
1757
1758static void do_print_listen(const char *name, abi_long arg1)
1759{
1760    abi_ulong sockfd, backlog;
1761
1762    get_user_ualx(sockfd, arg1, 0);
1763    get_user_ualx(backlog, arg1, 1);
1764
1765    gemu_log("%s(", name);
1766    print_sockfd(sockfd, 0);
1767    print_raw_param(TARGET_ABI_FMT_ld, backlog, 1);
1768    gemu_log(")");
1769}
1770
1771static void do_print_socketpair(const char *name, abi_long arg1)
1772{
1773    abi_ulong domain, type, protocol, tab;
1774
1775    get_user_ualx(domain, arg1, 0);
1776    get_user_ualx(type, arg1, 1);
1777    get_user_ualx(protocol, arg1, 2);
1778    get_user_ualx(tab, arg1, 3);
1779
1780    gemu_log("%s(", name);
1781    print_socket_domain(domain);
1782    gemu_log(",");
1783    print_socket_type(type);
1784    gemu_log(",");
1785    print_socket_protocol(domain, type, protocol);
1786    gemu_log(",");
1787    print_raw_param(TARGET_ABI_FMT_lx, tab, 1);
1788    gemu_log(")");
1789}
1790
1791static void do_print_sendrecv(const char *name, abi_long arg1)
1792{
1793    abi_ulong sockfd, msg, len, flags;
1794
1795    get_user_ualx(sockfd, arg1, 0);
1796    get_user_ualx(msg, arg1, 1);
1797    get_user_ualx(len, arg1, 2);
1798    get_user_ualx(flags, arg1, 3);
1799
1800    gemu_log("%s(", name);
1801    print_sockfd(sockfd, 0);
1802    print_buf(msg, len, 0);
1803    print_raw_param(TARGET_ABI_FMT_ld, len, 0);
1804    print_flags(msg_flags, flags, 1);
1805    gemu_log(")");
1806}
1807
1808static void do_print_msgaddr(const char *name, abi_long arg1)
1809{
1810    abi_ulong sockfd, msg, len, flags, addr, addrlen;
1811
1812    get_user_ualx(sockfd, arg1, 0);
1813    get_user_ualx(msg, arg1, 1);
1814    get_user_ualx(len, arg1, 2);
1815    get_user_ualx(flags, arg1, 3);
1816    get_user_ualx(addr, arg1, 4);
1817    get_user_ualx(addrlen, arg1, 5);
1818
1819    gemu_log("%s(", name);
1820    print_sockfd(sockfd, 0);
1821    print_buf(msg, len, 0);
1822    print_raw_param(TARGET_ABI_FMT_ld, len, 0);
1823    print_flags(msg_flags, flags, 0);
1824    print_sockaddr(addr, addrlen, 0);
1825    gemu_log(")");
1826}
1827
1828static void do_print_shutdown(const char *name, abi_long arg1)
1829{
1830    abi_ulong sockfd, how;
1831
1832    get_user_ualx(sockfd, arg1, 0);
1833    get_user_ualx(how, arg1, 1);
1834
1835    gemu_log("shutdown(");
1836    print_sockfd(sockfd, 0);
1837    switch (how) {
1838    case SHUT_RD:
1839        gemu_log("SHUT_RD");
1840        break;
1841    case SHUT_WR:
1842        gemu_log("SHUT_WR");
1843        break;
1844    case SHUT_RDWR:
1845        gemu_log("SHUT_RDWR");
1846        break;
1847    default:
1848        print_raw_param(TARGET_ABI_FMT_ld, how, 1);
1849        break;
1850    }
1851    gemu_log(")");
1852}
1853
1854static void do_print_msg(const char *name, abi_long arg1)
1855{
1856    abi_ulong sockfd, msg, flags;
1857
1858    get_user_ualx(sockfd, arg1, 0);
1859    get_user_ualx(msg, arg1, 1);
1860    get_user_ualx(flags, arg1, 2);
1861
1862    gemu_log("%s(", name);
1863    print_sockfd(sockfd, 0);
1864    print_pointer(msg, 0);
1865    print_flags(msg_flags, flags, 1);
1866    gemu_log(")");
1867}
1868
1869static void do_print_sockopt(const char *name, abi_long arg1)
1870{
1871    abi_ulong sockfd, level, optname, optval, optlen;
1872
1873    get_user_ualx(sockfd, arg1, 0);
1874    get_user_ualx(level, arg1, 1);
1875    get_user_ualx(optname, arg1, 2);
1876    get_user_ualx(optval, arg1, 3);
1877    get_user_ualx(optlen, arg1, 4);
1878
1879    gemu_log("%s(", name);
1880    print_sockfd(sockfd, 0);
1881    switch (level) {
1882    case SOL_TCP:
1883        gemu_log("SOL_TCP,");
1884        print_raw_param(TARGET_ABI_FMT_ld, optname, 0);
1885        print_pointer(optval, 0);
1886        break;
1887    case SOL_IP:
1888        gemu_log("SOL_IP,");
1889        print_raw_param(TARGET_ABI_FMT_ld, optname, 0);
1890        print_pointer(optval, 0);
1891        break;
1892    case SOL_RAW:
1893        gemu_log("SOL_RAW,");
1894        print_raw_param(TARGET_ABI_FMT_ld, optname, 0);
1895        print_pointer(optval, 0);
1896        break;
1897    case TARGET_SOL_SOCKET:
1898        gemu_log("SOL_SOCKET,");
1899        switch (optname) {
1900        case TARGET_SO_DEBUG:
1901            gemu_log("SO_DEBUG,");
1902print_optint:
1903            print_number(optval, 0);
1904            break;
1905        case TARGET_SO_REUSEADDR:
1906            gemu_log("SO_REUSEADDR,");
1907            goto print_optint;
1908        case TARGET_SO_REUSEPORT:
1909            gemu_log("SO_REUSEPORT,");
1910            goto print_optint;
1911        case TARGET_SO_TYPE:
1912            gemu_log("SO_TYPE,");
1913            goto print_optint;
1914        case TARGET_SO_ERROR:
1915            gemu_log("SO_ERROR,");
1916            goto print_optint;
1917        case TARGET_SO_DONTROUTE:
1918            gemu_log("SO_DONTROUTE,");
1919            goto print_optint;
1920        case TARGET_SO_BROADCAST:
1921            gemu_log("SO_BROADCAST,");
1922            goto print_optint;
1923        case TARGET_SO_SNDBUF:
1924            gemu_log("SO_SNDBUF,");
1925            goto print_optint;
1926        case TARGET_SO_RCVBUF:
1927            gemu_log("SO_RCVBUF,");
1928            goto print_optint;
1929        case TARGET_SO_KEEPALIVE:
1930            gemu_log("SO_KEEPALIVE,");
1931            goto print_optint;
1932        case TARGET_SO_OOBINLINE:
1933            gemu_log("SO_OOBINLINE,");
1934            goto print_optint;
1935        case TARGET_SO_NO_CHECK:
1936            gemu_log("SO_NO_CHECK,");
1937            goto print_optint;
1938        case TARGET_SO_PRIORITY:
1939            gemu_log("SO_PRIORITY,");
1940            goto print_optint;
1941        case TARGET_SO_BSDCOMPAT:
1942            gemu_log("SO_BSDCOMPAT,");
1943            goto print_optint;
1944        case TARGET_SO_PASSCRED:
1945            gemu_log("SO_PASSCRED,");
1946            goto print_optint;
1947        case TARGET_SO_TIMESTAMP:
1948            gemu_log("SO_TIMESTAMP,");
1949            goto print_optint;
1950        case TARGET_SO_RCVLOWAT:
1951            gemu_log("SO_RCVLOWAT,");
1952            goto print_optint;
1953        case TARGET_SO_RCVTIMEO:
1954            gemu_log("SO_RCVTIMEO,");
1955            print_timeval(optval, 0);
1956            break;
1957        case TARGET_SO_SNDTIMEO:
1958            gemu_log("SO_SNDTIMEO,");
1959            print_timeval(optval, 0);
1960            break;
1961        case TARGET_SO_ATTACH_FILTER: {
1962            struct target_sock_fprog *fprog;
1963
1964            gemu_log("SO_ATTACH_FILTER,");
1965
1966            if (lock_user_struct(VERIFY_READ, fprog, optval,  0)) {
1967                struct target_sock_filter *filter;
1968                gemu_log("{");
1969                if (lock_user_struct(VERIFY_READ, filter,
1970                                     tswapal(fprog->filter),  0)) {
1971                    int i;
1972                    for (i = 0; i < tswap16(fprog->len) - 1; i++) {
1973                        gemu_log("[%d]{0x%x,%d,%d,0x%x},",
1974                                 i, tswap16(filter[i].code),
1975                                 filter[i].jt, filter[i].jf,
1976                                 tswap32(filter[i].k));
1977                    }
1978                    gemu_log("[%d]{0x%x,%d,%d,0x%x}",
1979                             i, tswap16(filter[i].code),
1980                             filter[i].jt, filter[i].jf,
1981                             tswap32(filter[i].k));
1982                } else {
1983                    gemu_log(TARGET_ABI_FMT_lx, tswapal(fprog->filter));
1984                }
1985                gemu_log(",%d},", tswap16(fprog->len));
1986                unlock_user(fprog, optval, 0);
1987            } else {
1988                print_pointer(optval, 0);
1989            }
1990            break;
1991        }
1992        default:
1993            print_raw_param(TARGET_ABI_FMT_ld, optname, 0);
1994            print_pointer(optval, 0);
1995            break;
1996        }
1997        break;
1998    default:
1999        print_raw_param(TARGET_ABI_FMT_ld, level, 0);
2000        print_raw_param(TARGET_ABI_FMT_ld, optname, 0);
2001        print_pointer(optval, 0);
2002        break;
2003    }
2004    print_raw_param(TARGET_ABI_FMT_ld, optlen, 1);
2005    gemu_log(")");
2006}
2007
2008#define PRINT_SOCKOP(name, func) \
2009    [TARGET_SYS_##name] = { #name, func }
2010
2011static struct {
2012    const char *name;
2013    void (*print)(const char *, abi_long);
2014} scall[] = {
2015    PRINT_SOCKOP(SOCKET, do_print_socket),
2016    PRINT_SOCKOP(BIND, do_print_sockaddr),
2017    PRINT_SOCKOP(CONNECT, do_print_sockaddr),
2018    PRINT_SOCKOP(LISTEN, do_print_listen),
2019    PRINT_SOCKOP(ACCEPT, do_print_sockaddr),
2020    PRINT_SOCKOP(GETSOCKNAME, do_print_sockaddr),
2021    PRINT_SOCKOP(GETPEERNAME, do_print_sockaddr),
2022    PRINT_SOCKOP(SOCKETPAIR, do_print_socketpair),
2023    PRINT_SOCKOP(SEND, do_print_sendrecv),
2024    PRINT_SOCKOP(RECV, do_print_sendrecv),
2025    PRINT_SOCKOP(SENDTO, do_print_msgaddr),
2026    PRINT_SOCKOP(RECVFROM, do_print_msgaddr),
2027    PRINT_SOCKOP(SHUTDOWN, do_print_shutdown),
2028    PRINT_SOCKOP(SETSOCKOPT, do_print_sockopt),
2029    PRINT_SOCKOP(GETSOCKOPT, do_print_sockopt),
2030    PRINT_SOCKOP(SENDMSG, do_print_msg),
2031    PRINT_SOCKOP(RECVMSG, do_print_msg),
2032    PRINT_SOCKOP(ACCEPT4, NULL),
2033    PRINT_SOCKOP(RECVMMSG, NULL),
2034    PRINT_SOCKOP(SENDMMSG, NULL),
2035};
2036
2037static void
2038print_socketcall(const struct syscallname *name,
2039                 abi_long arg0, abi_long arg1, abi_long arg2,
2040                 abi_long arg3, abi_long arg4, abi_long arg5)
2041{
2042    if (arg0 >= 0 && arg0 < ARRAY_SIZE(scall) && scall[arg0].print) {
2043        scall[arg0].print(scall[arg0].name, arg1);
2044        return;
2045    }
2046    print_syscall_prologue(name);
2047    print_raw_param(TARGET_ABI_FMT_ld, arg0, 0);
2048    print_raw_param(TARGET_ABI_FMT_ld, arg1, 0);
2049    print_raw_param(TARGET_ABI_FMT_ld, arg2, 0);
2050    print_raw_param(TARGET_ABI_FMT_ld, arg3, 0);
2051    print_raw_param(TARGET_ABI_FMT_ld, arg4, 0);
2052    print_raw_param(TARGET_ABI_FMT_ld, arg5, 0);
2053    print_syscall_epilogue(name);
2054}
2055#endif
2056
2057#if defined(TARGET_NR_bind)
2058static void
2059print_bind(const struct syscallname *name,
2060           abi_long arg0, abi_long arg1, abi_long arg2,
2061           abi_long arg3, abi_long arg4, abi_long arg5)
2062{
2063    print_syscall_prologue(name);
2064    print_sockfd(arg0, 0);
2065    print_sockaddr(arg1, arg2, 1);
2066    print_syscall_epilogue(name);
2067}
2068#endif
2069
2070#if defined(TARGET_NR_stat) || defined(TARGET_NR_stat64) || \
2071    defined(TARGET_NR_lstat) || defined(TARGET_NR_lstat64)
2072static void
2073print_stat(const struct syscallname *name,
2074    abi_long arg0, abi_long arg1, abi_long arg2,
2075    abi_long arg3, abi_long arg4, abi_long arg5)
2076{
2077    print_syscall_prologue(name);
2078    print_string(arg0, 0);
2079    print_pointer(arg1, 1);
2080    print_syscall_epilogue(name);
2081}
2082#define print_lstat     print_stat
2083#define print_stat64    print_stat
2084#define print_lstat64   print_stat
2085#endif
2086
2087#if defined(TARGET_NR_fstat) || defined(TARGET_NR_fstat64)
2088static void
2089print_fstat(const struct syscallname *name,
2090    abi_long arg0, abi_long arg1, abi_long arg2,
2091    abi_long arg3, abi_long arg4, abi_long arg5)
2092{
2093    print_syscall_prologue(name);
2094    print_raw_param("%d", arg0, 0);
2095    print_pointer(arg1, 1);
2096    print_syscall_epilogue(name);
2097}
2098#define print_fstat64     print_fstat
2099#endif
2100
2101#ifdef TARGET_NR_mkdir
2102static void
2103print_mkdir(const struct syscallname *name,
2104    abi_long arg0, abi_long arg1, abi_long arg2,
2105    abi_long arg3, abi_long arg4, abi_long arg5)
2106{
2107    print_syscall_prologue(name);
2108    print_string(arg0, 0);
2109    print_file_mode(arg1, 1);
2110    print_syscall_epilogue(name);
2111}
2112#endif
2113
2114#ifdef TARGET_NR_mkdirat
2115static void
2116print_mkdirat(const struct syscallname *name,
2117    abi_long arg0, abi_long arg1, abi_long arg2,
2118    abi_long arg3, abi_long arg4, abi_long arg5)
2119{
2120    print_syscall_prologue(name);
2121    print_at_dirfd(arg0, 0);
2122    print_string(arg1, 0);
2123    print_file_mode(arg2, 1);
2124    print_syscall_epilogue(name);
2125}
2126#endif
2127
2128#ifdef TARGET_NR_rmdir
2129static void
2130print_rmdir(const struct syscallname *name,
2131    abi_long arg0, abi_long arg1, abi_long arg2,
2132    abi_long arg3, abi_long arg4, abi_long arg5)
2133{
2134    print_syscall_prologue(name);
2135    print_string(arg0, 0);
2136    print_syscall_epilogue(name);
2137}
2138#endif
2139
2140#ifdef TARGET_NR_rt_sigaction
2141static void
2142print_rt_sigaction(const struct syscallname *name,
2143    abi_long arg0, abi_long arg1, abi_long arg2,
2144    abi_long arg3, abi_long arg4, abi_long arg5)
2145{
2146    print_syscall_prologue(name);
2147    print_signal(arg0, 0);
2148    print_pointer(arg1, 0);
2149    print_pointer(arg2, 1);
2150    print_syscall_epilogue(name);
2151}
2152#endif
2153
2154#ifdef TARGET_NR_rt_sigprocmask
2155static void
2156print_rt_sigprocmask(const struct syscallname *name,
2157    abi_long arg0, abi_long arg1, abi_long arg2,
2158    abi_long arg3, abi_long arg4, abi_long arg5)
2159{
2160    const char *how = "UNKNOWN";
2161    print_syscall_prologue(name);
2162    switch(arg0) {
2163    case TARGET_SIG_BLOCK: how = "SIG_BLOCK"; break;
2164    case TARGET_SIG_UNBLOCK: how = "SIG_UNBLOCK"; break;
2165    case TARGET_SIG_SETMASK: how = "SIG_SETMASK"; break;
2166    }
2167    gemu_log("%s,",how);
2168    print_pointer(arg1, 0);
2169    print_pointer(arg2, 1);
2170    print_syscall_epilogue(name);
2171}
2172#endif
2173
2174#ifdef TARGET_NR_rt_sigqueueinfo
2175static void
2176print_rt_sigqueueinfo(const struct syscallname *name,
2177    abi_long arg0, abi_long arg1, abi_long arg2,
2178    abi_long arg3, abi_long arg4, abi_long arg5)
2179{
2180    void *p;
2181    target_siginfo_t uinfo;
2182
2183    print_syscall_prologue(name);
2184    print_raw_param("%d", arg0, 0);
2185    print_signal(arg1, 0);
2186    p = lock_user(VERIFY_READ, arg2, sizeof(target_siginfo_t), 1);
2187    if (p) {
2188        get_target_siginfo(&uinfo, p);
2189        print_siginfo(&uinfo);
2190
2191        unlock_user(p, arg2, 0);
2192    } else {
2193        print_pointer(arg2, 1);
2194    }
2195    print_syscall_epilogue(name);
2196}
2197#endif
2198
2199#ifdef TARGET_NR_rt_tgsigqueueinfo
2200static void
2201print_rt_tgsigqueueinfo(const struct syscallname *name,
2202    abi_long arg0, abi_long arg1, abi_long arg2,
2203    abi_long arg3, abi_long arg4, abi_long arg5)
2204{
2205    void *p;
2206    target_siginfo_t uinfo;
2207
2208    print_syscall_prologue(name);
2209    print_raw_param("%d", arg0, 0);
2210    print_raw_param("%d", arg1, 0);
2211    print_signal(arg2, 0);
2212    p = lock_user(VERIFY_READ, arg3, sizeof(target_siginfo_t), 1);
2213    if (p) {
2214        get_target_siginfo(&uinfo, p);
2215        print_siginfo(&uinfo);
2216
2217        unlock_user(p, arg3, 0);
2218    } else {
2219        print_pointer(arg3, 1);
2220    }
2221    print_syscall_epilogue(name);
2222}
2223#endif
2224
2225#ifdef TARGET_NR_syslog
2226static void
2227print_syslog_action(abi_ulong arg, int last)
2228{
2229    const char *type;
2230
2231    switch (arg) {
2232        case TARGET_SYSLOG_ACTION_CLOSE: {
2233            type = "SYSLOG_ACTION_CLOSE";
2234            break;
2235        }
2236        case TARGET_SYSLOG_ACTION_OPEN: {
2237            type = "SYSLOG_ACTION_OPEN";
2238            break;
2239        }
2240        case TARGET_SYSLOG_ACTION_READ: {
2241            type = "SYSLOG_ACTION_READ";
2242            break;
2243        }
2244        case TARGET_SYSLOG_ACTION_READ_ALL: {
2245            type = "SYSLOG_ACTION_READ_ALL";
2246            break;
2247        }
2248        case TARGET_SYSLOG_ACTION_READ_CLEAR: {
2249            type = "SYSLOG_ACTION_READ_CLEAR";
2250            break;
2251        }
2252        case TARGET_SYSLOG_ACTION_CLEAR: {
2253            type = "SYSLOG_ACTION_CLEAR";
2254            break;
2255        }
2256        case TARGET_SYSLOG_ACTION_CONSOLE_OFF: {
2257            type = "SYSLOG_ACTION_CONSOLE_OFF";
2258            break;
2259        }
2260        case TARGET_SYSLOG_ACTION_CONSOLE_ON: {
2261            type = "SYSLOG_ACTION_CONSOLE_ON";
2262            break;
2263        }
2264        case TARGET_SYSLOG_ACTION_CONSOLE_LEVEL: {
2265            type = "SYSLOG_ACTION_CONSOLE_LEVEL";
2266            break;
2267        }
2268        case TARGET_SYSLOG_ACTION_SIZE_UNREAD: {
2269            type = "SYSLOG_ACTION_SIZE_UNREAD";
2270            break;
2271        }
2272        case TARGET_SYSLOG_ACTION_SIZE_BUFFER: {
2273            type = "SYSLOG_ACTION_SIZE_BUFFER";
2274            break;
2275        }
2276        default: {
2277            print_raw_param("%ld", arg, last);
2278            return;
2279        }
2280    }
2281    gemu_log("%s%s", type, get_comma(last));
2282}
2283
2284static void
2285print_syslog(const struct syscallname *name,
2286    abi_long arg0, abi_long arg1, abi_long arg2,
2287    abi_long arg3, abi_long arg4, abi_long arg5)
2288{
2289    print_syscall_prologue(name);
2290    print_syslog_action(arg0, 0);
2291    print_pointer(arg1, 0);
2292    print_raw_param("%d", arg2, 1);
2293    print_syscall_epilogue(name);
2294}
2295#endif
2296
2297#ifdef TARGET_NR_mknod
2298static void
2299print_mknod(const struct syscallname *name,
2300    abi_long arg0, abi_long arg1, abi_long arg2,
2301    abi_long arg3, abi_long arg4, abi_long arg5)
2302{
2303    int hasdev = (arg1 & (S_IFCHR|S_IFBLK));
2304
2305    print_syscall_prologue(name);
2306    print_string(arg0, 0);
2307    print_file_mode(arg1, (hasdev == 0));
2308    if (hasdev) {
2309        print_raw_param("makedev(%d", major(arg2), 0);
2310        print_raw_param("%d)", minor(arg2), 1);
2311    }
2312    print_syscall_epilogue(name);
2313}
2314#endif
2315
2316#ifdef TARGET_NR_mknodat
2317static void
2318print_mknodat(const struct syscallname *name,
2319    abi_long arg0, abi_long arg1, abi_long arg2,
2320    abi_long arg3, abi_long arg4, abi_long arg5)
2321{
2322    int hasdev = (arg2 & (S_IFCHR|S_IFBLK));
2323
2324    print_syscall_prologue(name);
2325    print_at_dirfd(arg0, 0);
2326    print_string(arg1, 0);
2327    print_file_mode(arg2, (hasdev == 0));
2328    if (hasdev) {
2329        print_raw_param("makedev(%d", major(arg3), 0);
2330        print_raw_param("%d)", minor(arg3), 1);
2331    }
2332    print_syscall_epilogue(name);
2333}
2334#endif
2335
2336#ifdef TARGET_NR_mq_open
2337static void
2338print_mq_open(const struct syscallname *name,
2339    abi_long arg0, abi_long arg1, abi_long arg2,
2340    abi_long arg3, abi_long arg4, abi_long arg5)
2341{
2342    int is_creat = (arg1 & TARGET_O_CREAT);
2343
2344    print_syscall_prologue(name);
2345    print_string(arg0, 0);
2346    print_open_flags(arg1, (is_creat == 0));
2347    if (is_creat) {
2348        print_file_mode(arg2, 0);
2349        print_pointer(arg3, 1);
2350    }
2351    print_syscall_epilogue(name);
2352}
2353#endif
2354
2355#ifdef TARGET_NR_open
2356static void
2357print_open(const struct syscallname *name,
2358    abi_long arg0, abi_long arg1, abi_long arg2,
2359    abi_long arg3, abi_long arg4, abi_long arg5)
2360{
2361    int is_creat = (arg1 & TARGET_O_CREAT);
2362
2363    print_syscall_prologue(name);
2364    print_string(arg0, 0);
2365    print_open_flags(arg1, (is_creat == 0));
2366    if (is_creat)
2367        print_file_mode(arg2, 1);
2368    print_syscall_epilogue(name);
2369}
2370#endif
2371
2372#ifdef TARGET_NR_openat
2373static void
2374print_openat(const struct syscallname *name,
2375    abi_long arg0, abi_long arg1, abi_long arg2,
2376    abi_long arg3, abi_long arg4, abi_long arg5)
2377{
2378    int is_creat = (arg2 & TARGET_O_CREAT);
2379
2380    print_syscall_prologue(name);
2381    print_at_dirfd(arg0, 0);
2382    print_string(arg1, 0);
2383    print_open_flags(arg2, (is_creat == 0));
2384    if (is_creat)
2385        print_file_mode(arg3, 1);
2386    print_syscall_epilogue(name);
2387}
2388#endif
2389
2390#ifdef TARGET_NR_mq_unlink
2391static void
2392print_mq_unlink(const struct syscallname *name,
2393    abi_long arg0, abi_long arg1, abi_long arg2,
2394    abi_long arg3, abi_long arg4, abi_long arg5)
2395{
2396    print_syscall_prologue(name);
2397    print_string(arg0, 1);
2398    print_syscall_epilogue(name);
2399}
2400#endif
2401
2402#if defined(TARGET_NR_fstatat64) || defined(TARGET_NR_newfstatat)
2403static void
2404print_fstatat64(const struct syscallname *name,
2405    abi_long arg0, abi_long arg1, abi_long arg2,
2406    abi_long arg3, abi_long arg4, abi_long arg5)
2407{
2408    print_syscall_prologue(name);
2409    print_at_dirfd(arg0, 0);
2410    print_string(arg1, 0);
2411    print_pointer(arg2, 0);
2412    print_flags(at_file_flags, arg3, 1);
2413    print_syscall_epilogue(name);
2414}
2415#define print_newfstatat    print_fstatat64
2416#endif
2417
2418#ifdef TARGET_NR_readlink
2419static void
2420print_readlink(const struct syscallname *name,
2421    abi_long arg0, abi_long arg1, abi_long arg2,
2422    abi_long arg3, abi_long arg4, abi_long arg5)
2423{
2424    print_syscall_prologue(name);
2425    print_string(arg0, 0);
2426    print_pointer(arg1, 0);
2427    print_raw_param("%u", arg2, 1);
2428    print_syscall_epilogue(name);
2429}
2430#endif
2431
2432#ifdef TARGET_NR_readlinkat
2433static void
2434print_readlinkat(const struct syscallname *name,
2435    abi_long arg0, abi_long arg1, abi_long arg2,
2436    abi_long arg3, abi_long arg4, abi_long arg5)
2437{
2438    print_syscall_prologue(name);
2439    print_at_dirfd(arg0, 0);
2440    print_string(arg1, 0);
2441    print_pointer(arg2, 0);
2442    print_raw_param("%u", arg3, 1);
2443    print_syscall_epilogue(name);
2444}
2445#endif
2446
2447#ifdef TARGET_NR_rename
2448static void
2449print_rename(const struct syscallname *name,
2450    abi_long arg0, abi_long arg1, abi_long arg2,
2451    abi_long arg3, abi_long arg4, abi_long arg5)
2452{
2453    print_syscall_prologue(name);
2454    print_string(arg0, 0);
2455    print_string(arg1, 1);
2456    print_syscall_epilogue(name);
2457}
2458#endif
2459
2460#ifdef TARGET_NR_renameat
2461static void
2462print_renameat(const struct syscallname *name,
2463    abi_long arg0, abi_long arg1, abi_long arg2,
2464    abi_long arg3, abi_long arg4, abi_long arg5)
2465{
2466    print_syscall_prologue(name);
2467    print_at_dirfd(arg0, 0);
2468    print_string(arg1, 0);
2469    print_at_dirfd(arg2, 0);
2470    print_string(arg3, 1);
2471    print_syscall_epilogue(name);
2472}
2473#endif
2474
2475#ifdef TARGET_NR_statfs
2476static void
2477print_statfs(const struct syscallname *name,
2478    abi_long arg0, abi_long arg1, abi_long arg2,
2479    abi_long arg3, abi_long arg4, abi_long arg5)
2480{
2481    print_syscall_prologue(name);
2482    print_string(arg0, 0);
2483    print_pointer(arg1, 1);
2484    print_syscall_epilogue(name);
2485}
2486#endif
2487
2488#ifdef TARGET_NR_statfs64
2489static void
2490print_statfs64(const struct syscallname *name,
2491    abi_long arg0, abi_long arg1, abi_long arg2,
2492    abi_long arg3, abi_long arg4, abi_long arg5)
2493{
2494    print_syscall_prologue(name);
2495    print_string(arg0, 0);
2496    print_pointer(arg1, 1);
2497    print_syscall_epilogue(name);
2498}
2499#endif
2500
2501#ifdef TARGET_NR_symlink
2502static void
2503print_symlink(const struct syscallname *name,
2504    abi_long arg0, abi_long arg1, abi_long arg2,
2505    abi_long arg3, abi_long arg4, abi_long arg5)
2506{
2507    print_syscall_prologue(name);
2508    print_string(arg0, 0);
2509    print_string(arg1, 1);
2510    print_syscall_epilogue(name);
2511}
2512#endif
2513
2514#ifdef TARGET_NR_symlinkat
2515static void
2516print_symlinkat(const struct syscallname *name,
2517    abi_long arg0, abi_long arg1, abi_long arg2,
2518    abi_long arg3, abi_long arg4, abi_long arg5)
2519{
2520    print_syscall_prologue(name);
2521    print_string(arg0, 0);
2522    print_at_dirfd(arg1, 0);
2523    print_string(arg2, 1);
2524    print_syscall_epilogue(name);
2525}
2526#endif
2527
2528#ifdef TARGET_NR_mount
2529static void
2530print_mount(const struct syscallname *name,
2531    abi_long arg0, abi_long arg1, abi_long arg2,
2532    abi_long arg3, abi_long arg4, abi_long arg5)
2533{
2534    print_syscall_prologue(name);
2535    print_string(arg0, 0);
2536    print_string(arg1, 0);
2537    print_string(arg2, 0);
2538    print_flags(mount_flags, arg3, 0);
2539    print_pointer(arg4, 1);
2540    print_syscall_epilogue(name);
2541}
2542#endif
2543
2544#ifdef TARGET_NR_umount
2545static void
2546print_umount(const struct syscallname *name,
2547    abi_long arg0, abi_long arg1, abi_long arg2,
2548    abi_long arg3, abi_long arg4, abi_long arg5)
2549{
2550    print_syscall_prologue(name);
2551    print_string(arg0, 1);
2552    print_syscall_epilogue(name);
2553}
2554#endif
2555
2556#ifdef TARGET_NR_umount2
2557static void
2558print_umount2(const struct syscallname *name,
2559    abi_long arg0, abi_long arg1, abi_long arg2,
2560    abi_long arg3, abi_long arg4, abi_long arg5)
2561{
2562    print_syscall_prologue(name);
2563    print_string(arg0, 0);
2564    print_flags(umount2_flags, arg1, 1);
2565    print_syscall_epilogue(name);
2566}
2567#endif
2568
2569#ifdef TARGET_NR_unlink
2570static void
2571print_unlink(const struct syscallname *name,
2572    abi_long arg0, abi_long arg1, abi_long arg2,
2573    abi_long arg3, abi_long arg4, abi_long arg5)
2574{
2575    print_syscall_prologue(name);
2576    print_string(arg0, 1);
2577    print_syscall_epilogue(name);
2578}
2579#endif
2580
2581#ifdef TARGET_NR_unlinkat
2582static void
2583print_unlinkat(const struct syscallname *name,
2584    abi_long arg0, abi_long arg1, abi_long arg2,
2585    abi_long arg3, abi_long arg4, abi_long arg5)
2586{
2587    print_syscall_prologue(name);
2588    print_at_dirfd(arg0, 0);
2589    print_string(arg1, 0);
2590    print_flags(unlinkat_flags, arg2, 1);
2591    print_syscall_epilogue(name);
2592}
2593#endif
2594
2595#ifdef TARGET_NR_utime
2596static void
2597print_utime(const struct syscallname *name,
2598    abi_long arg0, abi_long arg1, abi_long arg2,
2599    abi_long arg3, abi_long arg4, abi_long arg5)
2600{
2601    print_syscall_prologue(name);
2602    print_string(arg0, 0);
2603    print_pointer(arg1, 1);
2604    print_syscall_epilogue(name);
2605}
2606#endif
2607
2608#ifdef TARGET_NR_utimes
2609static void
2610print_utimes(const struct syscallname *name,
2611    abi_long arg0, abi_long arg1, abi_long arg2,
2612    abi_long arg3, abi_long arg4, abi_long arg5)
2613{
2614    print_syscall_prologue(name);
2615    print_string(arg0, 0);
2616    print_pointer(arg1, 1);
2617    print_syscall_epilogue(name);
2618}
2619#endif
2620
2621#ifdef TARGET_NR_utimensat
2622static void
2623print_utimensat(const struct syscallname *name,
2624    abi_long arg0, abi_long arg1, abi_long arg2,
2625    abi_long arg3, abi_long arg4, abi_long arg5)
2626{
2627    print_syscall_prologue(name);
2628    print_at_dirfd(arg0, 0);
2629    print_string(arg1, 0);
2630    print_pointer(arg2, 0);
2631    print_flags(at_file_flags, arg3, 1);
2632    print_syscall_epilogue(name);
2633}
2634#endif
2635
2636#if defined(TARGET_NR_mmap) || defined(TARGET_NR_mmap2)
2637static void
2638print_mmap(const struct syscallname *name,
2639    abi_long arg0, abi_long arg1, abi_long arg2,
2640    abi_long arg3, abi_long arg4, abi_long arg5)
2641{
2642    print_syscall_prologue(name);
2643    print_pointer(arg0, 0);
2644    print_raw_param("%d", arg1, 0);
2645    print_flags(mmap_prot_flags, arg2, 0);
2646    print_flags(mmap_flags, arg3, 0);
2647    print_raw_param("%d", arg4, 0);
2648    print_raw_param("%#x", arg5, 1);
2649    print_syscall_epilogue(name);
2650}
2651#define print_mmap2     print_mmap
2652#endif
2653
2654#ifdef TARGET_NR_mprotect
2655static void
2656print_mprotect(const struct syscallname *name,
2657    abi_long arg0, abi_long arg1, abi_long arg2,
2658    abi_long arg3, abi_long arg4, abi_long arg5)
2659{
2660    print_syscall_prologue(name);
2661    print_pointer(arg0, 0);
2662    print_raw_param("%d", arg1, 0);
2663    print_flags(mmap_prot_flags, arg2, 1);
2664    print_syscall_epilogue(name);
2665}
2666#endif
2667
2668#ifdef TARGET_NR_munmap
2669static void
2670print_munmap(const struct syscallname *name,
2671    abi_long arg0, abi_long arg1, abi_long arg2,
2672    abi_long arg3, abi_long arg4, abi_long arg5)
2673{
2674    print_syscall_prologue(name);
2675    print_pointer(arg0, 0);
2676    print_raw_param("%d", arg1, 1);
2677    print_syscall_epilogue(name);
2678}
2679#endif
2680
2681#ifdef TARGET_NR_futex
2682static void print_futex_op(abi_long tflag, int last)
2683{
2684#define print_op(val) \
2685if( cmd == val ) { \
2686    gemu_log(#val); \
2687    return; \
2688}
2689
2690    int cmd = (int)tflag;
2691#ifdef FUTEX_PRIVATE_FLAG
2692    if (cmd & FUTEX_PRIVATE_FLAG) {
2693        gemu_log("FUTEX_PRIVATE_FLAG|");
2694        cmd &= ~FUTEX_PRIVATE_FLAG;
2695    }
2696#endif
2697#ifdef FUTEX_CLOCK_REALTIME
2698    if (cmd & FUTEX_CLOCK_REALTIME) {
2699        gemu_log("FUTEX_CLOCK_REALTIME|");
2700        cmd &= ~FUTEX_CLOCK_REALTIME;
2701    }
2702#endif
2703    print_op(FUTEX_WAIT)
2704    print_op(FUTEX_WAKE)
2705    print_op(FUTEX_FD)
2706    print_op(FUTEX_REQUEUE)
2707    print_op(FUTEX_CMP_REQUEUE)
2708    print_op(FUTEX_WAKE_OP)
2709    print_op(FUTEX_LOCK_PI)
2710    print_op(FUTEX_UNLOCK_PI)
2711    print_op(FUTEX_TRYLOCK_PI)
2712#ifdef FUTEX_WAIT_BITSET
2713    print_op(FUTEX_WAIT_BITSET)
2714#endif
2715#ifdef FUTEX_WAKE_BITSET
2716    print_op(FUTEX_WAKE_BITSET)
2717#endif
2718    /* unknown values */
2719    gemu_log("%d",cmd);
2720}
2721
2722static void
2723print_futex(const struct syscallname *name,
2724    abi_long arg0, abi_long arg1, abi_long arg2,
2725    abi_long arg3, abi_long arg4, abi_long arg5)
2726{
2727    print_syscall_prologue(name);
2728    print_pointer(arg0, 0);
2729    print_futex_op(arg1, 0);
2730    print_raw_param(",%d", arg2, 0);
2731    print_pointer(arg3, 0); /* struct timespec */
2732    print_pointer(arg4, 0);
2733    print_raw_param("%d", arg4, 1);
2734    print_syscall_epilogue(name);
2735}
2736#endif
2737
2738#ifdef TARGET_NR_kill
2739static void
2740print_kill(const struct syscallname *name,
2741    abi_long arg0, abi_long arg1, abi_long arg2,
2742    abi_long arg3, abi_long arg4, abi_long arg5)
2743{
2744    print_syscall_prologue(name);
2745    print_raw_param("%d", arg0, 0);
2746    print_signal(arg1, 1);
2747    print_syscall_epilogue(name);
2748}
2749#endif
2750
2751#ifdef TARGET_NR_tkill
2752static void
2753print_tkill(const struct syscallname *name,
2754    abi_long arg0, abi_long arg1, abi_long arg2,
2755    abi_long arg3, abi_long arg4, abi_long arg5)
2756{
2757    print_syscall_prologue(name);
2758    print_raw_param("%d", arg0, 0);
2759    print_signal(arg1, 1);
2760    print_syscall_epilogue(name);
2761}
2762#endif
2763
2764#ifdef TARGET_NR_tgkill
2765static void
2766print_tgkill(const struct syscallname *name,
2767    abi_long arg0, abi_long arg1, abi_long arg2,
2768    abi_long arg3, abi_long arg4, abi_long arg5)
2769{
2770    print_syscall_prologue(name);
2771    print_raw_param("%d", arg0, 0);
2772    print_raw_param("%d", arg1, 0);
2773    print_signal(arg2, 1);
2774    print_syscall_epilogue(name);
2775}
2776#endif
2777
2778#ifdef TARGET_NR_statx
2779static void
2780print_statx(const struct syscallname *name,
2781            abi_long arg0, abi_long arg1, abi_long arg2,
2782            abi_long arg3, abi_long arg4, abi_long arg5)
2783{
2784    print_syscall_prologue(name);
2785    print_at_dirfd(arg0, 0);
2786    print_string(arg1, 0);
2787    print_flags(statx_flags, arg2, 0);
2788    print_flags(statx_mask, arg3, 0);
2789    print_pointer(arg4, 1);
2790    print_syscall_epilogue(name);
2791}
2792#endif
2793
2794/*
2795 * An array of all of the syscalls we know about
2796 */
2797
2798static const struct syscallname scnames[] = {
2799#include "strace.list"
2800};
2801
2802static int nsyscalls = ARRAY_SIZE(scnames);
2803
2804/*
2805 * The public interface to this module.
2806 */
2807void
2808print_syscall(int num,
2809              abi_long arg1, abi_long arg2, abi_long arg3,
2810              abi_long arg4, abi_long arg5, abi_long arg6)
2811{
2812    int i;
2813    const char *format="%s(" TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld ")";
2814
2815    gemu_log("%d ", getpid() );
2816
2817    for(i=0;i<nsyscalls;i++)
2818        if( scnames[i].nr == num ) {
2819            if( scnames[i].call != NULL ) {
2820                scnames[i].call(&scnames[i],arg1,arg2,arg3,arg4,arg5,arg6);
2821            } else {
2822                /* XXX: this format system is broken because it uses
2823                   host types and host pointers for strings */
2824                if( scnames[i].format != NULL )
2825                    format = scnames[i].format;
2826                gemu_log(format,scnames[i].name, arg1,arg2,arg3,arg4,arg5,arg6);
2827            }
2828            return;
2829        }
2830    gemu_log("Unknown syscall %d\n", num);
2831}
2832
2833
2834void
2835print_syscall_ret(int num, abi_long ret)
2836{
2837    int i;
2838    const char *errstr = NULL;
2839
2840    for(i=0;i<nsyscalls;i++)
2841        if( scnames[i].nr == num ) {
2842            if( scnames[i].result != NULL ) {
2843                scnames[i].result(&scnames[i],ret);
2844            } else {
2845                if (ret < 0) {
2846                    errstr = target_strerror(-ret);
2847                }
2848                if (errstr) {
2849                    gemu_log(" = -1 errno=" TARGET_ABI_FMT_ld " (%s)\n",
2850                             -ret, errstr);
2851                } else {
2852                    gemu_log(" = " TARGET_ABI_FMT_ld "\n", ret);
2853                }
2854            }
2855            break;
2856        }
2857}
2858
2859void print_taken_signal(int target_signum, const target_siginfo_t *tinfo)
2860{
2861    /* Print the strace output for a signal being taken:
2862     * --- SIGSEGV {si_signo=SIGSEGV, si_code=SI_KERNEL, si_addr=0} ---
2863     */
2864    gemu_log("--- ");
2865    print_signal(target_signum, 1);
2866    gemu_log(" ");
2867    print_siginfo(tinfo);
2868    gemu_log(" ---\n");
2869}
2870