strace.c 56.7 KB
Newer Older
P
Peter Maydell 已提交
1
#include "qemu/osdep.h"
2 3 4 5 6
#include <sys/ipc.h>
#include <sys/msg.h>
#include <sys/sem.h>
#include <sys/shm.h>
#include <sys/select.h>
7
#include <sys/mount.h>
8 9 10
#include <arpa/inet.h>
#include <netinet/tcp.h>
#include <linux/if_packet.h>
L
Laurent Vivier 已提交
11
#include <sched.h>
12 13 14 15 16 17
#include "qemu.h"

int do_strace=0;

struct syscallname {
    int nr;
18 19 20
    const char *name;
    const char *format;
    void (*call)(const struct syscallname *,
B
bellard 已提交
21 22
                 abi_long, abi_long, abi_long,
                 abi_long, abi_long, abi_long);
23
    void (*result)(const struct syscallname *, abi_long);
24 25
};

26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
#ifdef __GNUC__
/*
 * It is possible that target doesn't have syscall that uses
 * following flags but we don't want the compiler to warn
 * us about them being unused.  Same applies to utility print
 * functions.  It is ok to keep them while not used.
 */
#define UNUSED __attribute__ ((unused))
#else
#define UNUSED
#endif

/*
 * Structure used to translate flag values into strings.  This is
 * similar that is in the actual strace tool.
 */
struct flags {
    abi_long    f_value;  /* flag */
    const char  *f_string; /* stringified flag */
};

/* common flags for all architectures */
#define FLAG_GENERIC(name) { name, #name }
/* target specific flags (syscall_defs.h has TARGET_<flag>) */
#define FLAG_TARGET(name)  { TARGET_ ## name, #name }
/* end of flags array */
#define FLAG_END           { 0, NULL }

UNUSED static const char *get_comma(int);
UNUSED static void print_pointer(abi_long, int);
UNUSED static void print_flags(const struct flags *, abi_long, int);
UNUSED static void print_at_dirfd(abi_long, int);
UNUSED static void print_file_mode(abi_long, int);
UNUSED static void print_open_flags(abi_long, int);
UNUSED static void print_syscall_prologue(const struct syscallname *);
UNUSED static void print_syscall_epilogue(const struct syscallname *);
UNUSED static void print_string(abi_long, int);
63
UNUSED static void print_buf(abi_long addr, abi_long len, int last);
64 65 66
UNUSED static void print_raw_param(const char *, abi_long, int);
UNUSED static void print_timeval(abi_ulong, int);
UNUSED static void print_number(abi_long, int);
L
Laurent Vivier 已提交
67
UNUSED static void print_signal(abi_ulong, int);
68 69 70 71
UNUSED static void print_sockaddr(abi_ulong addr, abi_long addrlen);
UNUSED static void print_socket_domain(int domain);
UNUSED static void print_socket_type(int type);
UNUSED static void print_socket_protocol(int domain, int type, int protocol);
72

73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
/*
 * Utility functions
 */
static void
print_ipc_cmd(int cmd)
{
#define output_cmd(val) \
if( cmd == val ) { \
    gemu_log(#val); \
    return; \
}

    cmd &= 0xff;

    /* General IPC commands */
    output_cmd( IPC_RMID );
    output_cmd( IPC_SET );
    output_cmd( IPC_STAT );
    output_cmd( IPC_INFO );
    /* msgctl() commands */
    #ifdef __USER_MISC
    output_cmd( MSG_STAT );
    output_cmd( MSG_INFO );
    #endif
    /* shmctl() commands */
    output_cmd( SHM_LOCK );
    output_cmd( SHM_UNLOCK );
    output_cmd( SHM_STAT );
    output_cmd( SHM_INFO );
    /* semctl() commands */
    output_cmd( GETPID );
    output_cmd( GETVAL );
    output_cmd( GETALL );
    output_cmd( GETNCNT );
    output_cmd( GETZCNT );
    output_cmd( SETVAL );
    output_cmd( SETALL );
    output_cmd( SEM_STAT );
    output_cmd( SEM_INFO );
    output_cmd( IPC_RMID );
    output_cmd( IPC_RMID );
    output_cmd( IPC_RMID );
    output_cmd( IPC_RMID );
    output_cmd( IPC_RMID );
    output_cmd( IPC_RMID );
    output_cmd( IPC_RMID );
    output_cmd( IPC_RMID );
    output_cmd( IPC_RMID );

    /* Some value we don't recognize */
    gemu_log("%d",cmd);
}

L
Laurent Vivier 已提交
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
static void
print_signal(abi_ulong arg, int last)
{
    const char *signal_name = NULL;
    switch(arg) {
    case TARGET_SIGHUP: signal_name = "SIGHUP"; break;
    case TARGET_SIGINT: signal_name = "SIGINT"; break;
    case TARGET_SIGQUIT: signal_name = "SIGQUIT"; break;
    case TARGET_SIGILL: signal_name = "SIGILL"; break;
    case TARGET_SIGABRT: signal_name = "SIGABRT"; break;
    case TARGET_SIGFPE: signal_name = "SIGFPE"; break;
    case TARGET_SIGKILL: signal_name = "SIGKILL"; break;
    case TARGET_SIGSEGV: signal_name = "SIGSEGV"; break;
    case TARGET_SIGPIPE: signal_name = "SIGPIPE"; break;
    case TARGET_SIGALRM: signal_name = "SIGALRM"; break;
    case TARGET_SIGTERM: signal_name = "SIGTERM"; break;
    case TARGET_SIGUSR1: signal_name = "SIGUSR1"; break;
    case TARGET_SIGUSR2: signal_name = "SIGUSR2"; break;
    case TARGET_SIGCHLD: signal_name = "SIGCHLD"; break;
    case TARGET_SIGCONT: signal_name = "SIGCONT"; break;
    case TARGET_SIGSTOP: signal_name = "SIGSTOP"; break;
    case TARGET_SIGTTIN: signal_name = "SIGTTIN"; break;
    case TARGET_SIGTTOU: signal_name = "SIGTTOU"; break;
    }
    if (signal_name == NULL) {
151
        print_raw_param("%ld", arg, last);
L
Laurent Vivier 已提交
152 153 154 155 156
        return;
    }
    gemu_log("%s%s", signal_name, get_comma(last));
}

157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315
static void
print_sockaddr(abi_ulong addr, abi_long addrlen)
{
    struct target_sockaddr *sa;
    int i;
    int sa_family;

    sa = lock_user(VERIFY_READ, addr, addrlen, 1);
    if (sa) {
        sa_family = tswap16(sa->sa_family);
        switch (sa_family) {
        case AF_UNIX: {
            struct target_sockaddr_un *un = (struct target_sockaddr_un *)sa;
            int i;
            gemu_log("{sun_family=AF_UNIX,sun_path=\"");
            for (i = 0; i < addrlen -
                            offsetof(struct target_sockaddr_un, sun_path) &&
                 un->sun_path[i]; i++) {
                gemu_log("%c", un->sun_path[i]);
            }
            gemu_log("\"}");
            break;
        }
        case AF_INET: {
            struct target_sockaddr_in *in = (struct target_sockaddr_in *)sa;
            uint8_t *c = (uint8_t *)&in->sin_addr.s_addr;
            gemu_log("{sin_family=AF_INET,sin_port=htons(%d),",
                     ntohs(in->sin_port));
            gemu_log("sin_addr=inet_addr(\"%d.%d.%d.%d\")",
                     c[0], c[1], c[2], c[3]);
            gemu_log("}");
            break;
        }
        case AF_PACKET: {
            struct target_sockaddr_ll *ll = (struct target_sockaddr_ll *)sa;
            uint8_t *c = (uint8_t *)&ll->sll_addr;
            gemu_log("{sll_family=AF_PACKET,"
                     "sll_protocol=htons(0x%04x),if%d,pkttype=",
                     ntohs(ll->sll_protocol), ll->sll_ifindex);
            switch (ll->sll_pkttype) {
            case PACKET_HOST:
                gemu_log("PACKET_HOST");
                break;
            case PACKET_BROADCAST:
                gemu_log("PACKET_BROADCAST");
                break;
            case PACKET_MULTICAST:
                gemu_log("PACKET_MULTICAST");
                break;
            case PACKET_OTHERHOST:
                gemu_log("PACKET_OTHERHOST");
                break;
            case PACKET_OUTGOING:
                gemu_log("PACKET_OUTGOING");
                break;
            default:
                gemu_log("%d", ll->sll_pkttype);
                break;
            }
            gemu_log(",sll_addr=%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x",
                     c[0], c[1], c[2], c[3], c[4], c[5], c[6], c[7]);
            gemu_log("}");
            break;
        }
        default:
            gemu_log("{sa_family=%d, sa_data={", sa->sa_family);
            for (i = 0; i < 13; i++) {
                gemu_log("%02x, ", sa->sa_data[i]);
            }
            gemu_log("%02x}", sa->sa_data[i]);
            gemu_log("}");
            break;
        }
        unlock_user(sa, addr, 0);
    } else {
        print_raw_param("0x"TARGET_ABI_FMT_lx, addr, 0);
    }
    gemu_log(", "TARGET_ABI_FMT_ld, addrlen);
}

static void
print_socket_domain(int domain)
{
    switch (domain) {
    case PF_UNIX:
        gemu_log("PF_UNIX");
        break;
    case PF_INET:
        gemu_log("PF_INET");
        break;
    case PF_PACKET:
        gemu_log("PF_PACKET");
        break;
    default:
        gemu_log("%d", domain);
        break;
    }
}

static void
print_socket_type(int type)
{
    switch (type) {
    case TARGET_SOCK_DGRAM:
        gemu_log("SOCK_DGRAM");
        break;
    case TARGET_SOCK_STREAM:
        gemu_log("SOCK_STREAM");
        break;
    case TARGET_SOCK_RAW:
        gemu_log("SOCK_RAW");
        break;
    case TARGET_SOCK_RDM:
        gemu_log("SOCK_RDM");
        break;
    case TARGET_SOCK_SEQPACKET:
        gemu_log("SOCK_SEQPACKET");
        break;
    case TARGET_SOCK_PACKET:
        gemu_log("SOCK_PACKET");
        break;
    }
}

static void
print_socket_protocol(int domain, int type, int protocol)
{
    if (domain == AF_PACKET ||
        (domain == AF_INET && type == TARGET_SOCK_PACKET)) {
        switch (protocol) {
        case 0x0003:
            gemu_log("ETH_P_ALL");
            break;
        default:
            gemu_log("%d", protocol);
        }
        return;
    }

    switch (protocol) {
    case IPPROTO_IP:
        gemu_log("IPPROTO_IP");
        break;
    case IPPROTO_TCP:
        gemu_log("IPPROTO_TCP");
        break;
    case IPPROTO_UDP:
        gemu_log("IPPROTO_UDP");
        break;
    case IPPROTO_RAW:
        gemu_log("IPPROTO_RAW");
        break;
    default:
        gemu_log("%d", protocol);
        break;
    }
}


B
bellard 已提交
316
#ifdef TARGET_NR__newselect
317
static void
B
bellard 已提交
318
print_fdset(int n, abi_ulong target_fds_addr)
319 320 321 322 323
{
    int i;

    gemu_log("[");
    if( target_fds_addr ) {
324
        abi_long *target_fds;
325

326 327 328 329 330 331
        target_fds = lock_user(VERIFY_READ,
                               target_fds_addr,
                               sizeof(*target_fds)*(n / TARGET_ABI_BITS + 1),
                               1);

        if (!target_fds)
332 333 334
            return;

        for (i=n; i>=0; i--) {
335
            if ((tswapal(target_fds[i / TARGET_ABI_BITS]) >> (i & (TARGET_ABI_BITS - 1))) & 1)
336 337 338 339 340 341
                gemu_log("%d,", i );
            }
        unlock_user(target_fds, target_fds_addr, 0);
    }
    gemu_log("]");
}
B
bellard 已提交
342
#endif
343 344 345 346 347 348

/*
 * Sysycall specific output functions
 */

/* select */
B
bellard 已提交
349
#ifdef TARGET_NR__newselect
350 351 352 353 354 355 356
static long newselect_arg1 = 0;
static long newselect_arg2 = 0;
static long newselect_arg3 = 0;
static long newselect_arg4 = 0;
static long newselect_arg5 = 0;

static void
357
print_newselect(const struct syscallname *name,
B
bellard 已提交
358 359
                abi_long arg1, abi_long arg2, abi_long arg3,
                abi_long arg4, abi_long arg5, abi_long arg6)
360
{
B
bellard 已提交
361
    gemu_log("%s(" TARGET_ABI_FMT_ld ",", name->name, arg1);
362 363 364 365 366 367
    print_fdset(arg1, arg2);
    gemu_log(",");
    print_fdset(arg1, arg3);
    gemu_log(",");
    print_fdset(arg1, arg4);
    gemu_log(",");
368
    print_timeval(arg5, 1);
369 370 371 372 373 374 375 376 377
    gemu_log(")");

    /* save for use in the return output function below */
    newselect_arg1=arg1;
    newselect_arg2=arg2;
    newselect_arg3=arg3;
    newselect_arg4=arg4;
    newselect_arg5=arg5;
}
B
bellard 已提交
378
#endif
379

B
blueswir1 已提交
380
#ifdef TARGET_NR_semctl
381
static void
382
print_semctl(const struct syscallname *name,
B
bellard 已提交
383 384
             abi_long arg1, abi_long arg2, abi_long arg3,
             abi_long arg4, abi_long arg5, abi_long arg6)
385
{
B
bellard 已提交
386
    gemu_log("%s(" TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld ",", name->name, arg1, arg2);
387
    print_ipc_cmd(arg3);
B
bellard 已提交
388
    gemu_log(",0x" TARGET_ABI_FMT_lx ")", arg4);
389
}
B
blueswir1 已提交
390
#endif
391 392

static void
393
print_execve(const struct syscallname *name,
B
bellard 已提交
394 395
             abi_long arg1, abi_long arg2, abi_long arg3,
             abi_long arg4, abi_long arg5, abi_long arg6)
396
{
B
bellard 已提交
397
    abi_ulong arg_ptr_addr;
398 399
    char *s;

400
    if (!(s = lock_user_string(arg1)))
401 402 403 404
        return;
    gemu_log("%s(\"%s\",{", name->name, s);
    unlock_user(s, arg1, 0);

B
bellard 已提交
405
    for (arg_ptr_addr = arg2; ; arg_ptr_addr += sizeof(abi_ulong)) {
406
        abi_ulong *arg_ptr, arg_addr;
407

B
bellard 已提交
408
	arg_ptr = lock_user(VERIFY_READ, arg_ptr_addr, sizeof(abi_ulong), 1);
409
        if (!arg_ptr)
410
            return;
411
    arg_addr = tswapal(*arg_ptr);
412 413 414
	unlock_user(arg_ptr, arg_ptr_addr, 0);
        if (!arg_addr)
            break;
415 416
        if ((s = lock_user_string(arg_addr))) {
            gemu_log("\"%s\",", s);
417
            unlock_user(s, arg_addr, 0);
418
        }
419 420 421 422 423
    }

    gemu_log("NULL})");
}

B
bellard 已提交
424
#ifdef TARGET_NR_ipc
425
static void
426
print_ipc(const struct syscallname *name,
B
bellard 已提交
427 428
          abi_long arg1, abi_long arg2, abi_long arg3,
          abi_long arg4, abi_long arg5, abi_long arg6)
429 430 431
{
    switch(arg1) {
    case IPCOP_semctl:
432 433 434
        gemu_log("semctl(" TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld ",", arg1, arg2);
        print_ipc_cmd(arg3);
        gemu_log(",0x" TARGET_ABI_FMT_lx ")", arg4);
435 436
        break;
    default:
B
bellard 已提交
437
        gemu_log("%s(" TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld ")",
438 439 440
                 name->name, arg1, arg2, arg3, arg4);
    }
}
B
bellard 已提交
441
#endif
442 443 444 445 446 447

/*
 * Variants for the return value output function
 */

static void
448
print_syscall_ret_addr(const struct syscallname *name, abi_long ret)
449
{
450
    const char *errstr = NULL;
451

452 453
    if (ret < 0) {
        errstr = target_strerror(-ret);
454
    }
455 456
    if (errstr) {
        gemu_log(" = -1 errno=%d (%s)\n", (int)-ret, errstr);
457
    } else {
B
bellard 已提交
458
        gemu_log(" = 0x" TARGET_ABI_FMT_lx "\n", ret);
459 460 461
    }
}

T
ths 已提交
462
#if 0 /* currently unused */
463
static void
B
bellard 已提交
464
print_syscall_ret_raw(struct syscallname *name, abi_long ret)
465
{
B
bellard 已提交
466
        gemu_log(" = 0x" TARGET_ABI_FMT_lx "\n", ret);
467
}
T
ths 已提交
468
#endif
469

T
ths 已提交
470
#ifdef TARGET_NR__newselect
471
static void
472
print_syscall_ret_newselect(const struct syscallname *name, abi_long ret)
473
{
B
bellard 已提交
474
    gemu_log(" = 0x" TARGET_ABI_FMT_lx " (", ret);
475 476 477 478 479 480
    print_fdset(newselect_arg1,newselect_arg2);
    gemu_log(",");
    print_fdset(newselect_arg1,newselect_arg3);
    gemu_log(",");
    print_fdset(newselect_arg1,newselect_arg4);
    gemu_log(",");
481
    print_timeval(newselect_arg5, 1);
482 483
    gemu_log(")\n");
}
T
ths 已提交
484
#endif
485

486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537
UNUSED static struct flags access_flags[] = {
    FLAG_GENERIC(F_OK),
    FLAG_GENERIC(R_OK),
    FLAG_GENERIC(W_OK),
    FLAG_GENERIC(X_OK),
    FLAG_END,
};

UNUSED static struct flags at_file_flags[] = {
#ifdef AT_EACCESS
    FLAG_GENERIC(AT_EACCESS),
#endif
#ifdef AT_SYMLINK_NOFOLLOW
    FLAG_GENERIC(AT_SYMLINK_NOFOLLOW),
#endif
    FLAG_END,
};

UNUSED static struct flags unlinkat_flags[] = {
#ifdef AT_REMOVEDIR
    FLAG_GENERIC(AT_REMOVEDIR),
#endif
    FLAG_END,
};

UNUSED static struct flags mode_flags[] = {
    FLAG_GENERIC(S_IFSOCK),
    FLAG_GENERIC(S_IFLNK),
    FLAG_GENERIC(S_IFREG),
    FLAG_GENERIC(S_IFBLK),
    FLAG_GENERIC(S_IFDIR),
    FLAG_GENERIC(S_IFCHR),
    FLAG_GENERIC(S_IFIFO),
    FLAG_END,
};

UNUSED static struct flags open_access_flags[] = {
    FLAG_TARGET(O_RDONLY),
    FLAG_TARGET(O_WRONLY),
    FLAG_TARGET(O_RDWR),
    FLAG_END,
};

UNUSED static struct flags open_flags[] = {
    FLAG_TARGET(O_APPEND),
    FLAG_TARGET(O_CREAT),
    FLAG_TARGET(O_DIRECTORY),
    FLAG_TARGET(O_EXCL),
    FLAG_TARGET(O_LARGEFILE),
    FLAG_TARGET(O_NOCTTY),
    FLAG_TARGET(O_NOFOLLOW),
    FLAG_TARGET(O_NONBLOCK),      /* also O_NDELAY */
538 539
    FLAG_TARGET(O_DSYNC),
    FLAG_TARGET(__O_SYNC),
540 541 542
    FLAG_TARGET(O_TRUNC),
#ifdef O_DIRECT
    FLAG_TARGET(O_DIRECT),
543 544 545 546 547 548 549 550 551
#endif
#ifdef O_NOATIME
    FLAG_TARGET(O_NOATIME),
#endif
#ifdef O_CLOEXEC
    FLAG_TARGET(O_CLOEXEC),
#endif
#ifdef O_PATH
    FLAG_TARGET(O_PATH),
552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598
#endif
    FLAG_END,
};

UNUSED static struct flags mount_flags[] = {
#ifdef MS_BIND
    FLAG_GENERIC(MS_BIND),
#endif
#ifdef MS_DIRSYNC
    FLAG_GENERIC(MS_DIRSYNC),
#endif
    FLAG_GENERIC(MS_MANDLOCK),
#ifdef MS_MOVE
    FLAG_GENERIC(MS_MOVE),
#endif
    FLAG_GENERIC(MS_NOATIME),
    FLAG_GENERIC(MS_NODEV),
    FLAG_GENERIC(MS_NODIRATIME),
    FLAG_GENERIC(MS_NOEXEC),
    FLAG_GENERIC(MS_NOSUID),
    FLAG_GENERIC(MS_RDONLY),
#ifdef MS_RELATIME
    FLAG_GENERIC(MS_RELATIME),
#endif
    FLAG_GENERIC(MS_REMOUNT),
    FLAG_GENERIC(MS_SYNCHRONOUS),
    FLAG_END,
};

UNUSED static struct flags umount2_flags[] = {
#ifdef MNT_FORCE
    FLAG_GENERIC(MNT_FORCE),
#endif
#ifdef MNT_DETACH
    FLAG_GENERIC(MNT_DETACH),
#endif
#ifdef MNT_EXPIRE
    FLAG_GENERIC(MNT_EXPIRE),
#endif
    FLAG_END,
};

UNUSED static struct flags mmap_prot_flags[] = {
    FLAG_GENERIC(PROT_NONE),
    FLAG_GENERIC(PROT_EXEC),
    FLAG_GENERIC(PROT_READ),
    FLAG_GENERIC(PROT_WRITE),
P
Paul Brook 已提交
599 600 601
    FLAG_TARGET(PROT_SEM),
    FLAG_GENERIC(PROT_GROWSDOWN),
    FLAG_GENERIC(PROT_GROWSUP),
602 603 604 605 606 607 608 609 610 611
    FLAG_END,
};

UNUSED static struct flags mmap_flags[] = {
    FLAG_TARGET(MAP_SHARED),
    FLAG_TARGET(MAP_PRIVATE),
    FLAG_TARGET(MAP_ANONYMOUS),
    FLAG_TARGET(MAP_DENYWRITE),
    FLAG_TARGET(MAP_FIXED),
    FLAG_TARGET(MAP_GROWSDOWN),
612
    FLAG_TARGET(MAP_EXECUTABLE),
613 614 615 616 617 618 619 620 621
#ifdef MAP_LOCKED
    FLAG_TARGET(MAP_LOCKED),
#endif
#ifdef MAP_NONBLOCK
    FLAG_TARGET(MAP_NONBLOCK),
#endif
    FLAG_TARGET(MAP_NORESERVE),
#ifdef MAP_POPULATE
    FLAG_TARGET(MAP_POPULATE),
622 623 624
#endif
#ifdef TARGET_MAP_UNINITIALIZED
    FLAG_TARGET(MAP_UNINITIALIZED),
625 626 627 628
#endif
    FLAG_END,
};

L
Laurent Vivier 已提交
629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645
UNUSED static struct flags clone_flags[] = {
    FLAG_GENERIC(CLONE_VM),
    FLAG_GENERIC(CLONE_FS),
    FLAG_GENERIC(CLONE_FILES),
    FLAG_GENERIC(CLONE_SIGHAND),
    FLAG_GENERIC(CLONE_PTRACE),
    FLAG_GENERIC(CLONE_VFORK),
    FLAG_GENERIC(CLONE_PARENT),
    FLAG_GENERIC(CLONE_THREAD),
    FLAG_GENERIC(CLONE_NEWNS),
    FLAG_GENERIC(CLONE_SYSVSEM),
    FLAG_GENERIC(CLONE_SETTLS),
    FLAG_GENERIC(CLONE_PARENT_SETTID),
    FLAG_GENERIC(CLONE_CHILD_CLEARTID),
    FLAG_GENERIC(CLONE_DETACHED),
    FLAG_GENERIC(CLONE_UNTRACED),
    FLAG_GENERIC(CLONE_CHILD_SETTID),
646
#if defined(CLONE_NEWUTS)
L
Laurent Vivier 已提交
647
    FLAG_GENERIC(CLONE_NEWUTS),
648 649
#endif
#if defined(CLONE_NEWIPC)
L
Laurent Vivier 已提交
650
    FLAG_GENERIC(CLONE_NEWIPC),
651 652
#endif
#if defined(CLONE_NEWUSER)
L
Laurent Vivier 已提交
653
    FLAG_GENERIC(CLONE_NEWUSER),
654 655
#endif
#if defined(CLONE_NEWPID)
L
Laurent Vivier 已提交
656
    FLAG_GENERIC(CLONE_NEWPID),
657 658
#endif
#if defined(CLONE_NEWNET)
L
Laurent Vivier 已提交
659
    FLAG_GENERIC(CLONE_NEWNET),
660 661
#endif
#if defined(CLONE_IO)
L
Laurent Vivier 已提交
662
    FLAG_GENERIC(CLONE_IO),
663
#endif
L
Laurent Vivier 已提交
664 665 666
    FLAG_END,
};

667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686
UNUSED static struct flags msg_flags[] = {
    /* send */
    FLAG_GENERIC(MSG_CONFIRM),
    FLAG_GENERIC(MSG_DONTROUTE),
    FLAG_GENERIC(MSG_DONTWAIT),
    FLAG_GENERIC(MSG_EOR),
    FLAG_GENERIC(MSG_MORE),
    FLAG_GENERIC(MSG_NOSIGNAL),
    FLAG_GENERIC(MSG_OOB),
    /* recv */
    FLAG_GENERIC(MSG_CMSG_CLOEXEC),
    FLAG_GENERIC(MSG_ERRQUEUE),
    FLAG_GENERIC(MSG_PEEK),
    FLAG_GENERIC(MSG_TRUNC),
    FLAG_GENERIC(MSG_WAITALL),
    /* recvmsg */
    FLAG_GENERIC(MSG_CTRUNC),
    FLAG_END,
};

687 688 689 690 691 692 693 694 695 696 697 698 699 700
/*
 * print_xxx utility functions.  These are used to print syscall
 * parameters in certain format.  All of these have parameter
 * named 'last'.  This parameter is used to add comma to output
 * when last == 0.
 */

static const char *
get_comma(int last)
{
    return ((last) ? "" : ",");
}

static void
701
print_flags(const struct flags *f, abi_long flags, int last)
702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721
{
    const char *sep = "";
    int n;

    if ((flags == 0) && (f->f_value == 0)) {
        gemu_log("%s%s", f->f_string, get_comma(last));
        return;
    }
    for (n = 0; f->f_string != NULL; f++) {
        if ((f->f_value != 0) && ((flags & f->f_value) == f->f_value)) {
            gemu_log("%s%s", sep, f->f_string);
            flags &= ~f->f_value;
            sep = "|";
            n++;
        }
    }

    if (n > 0) {
        /* print rest of the flags as numeric */
        if (flags != 0) {
722
            gemu_log("%s%#x%s", sep, (unsigned int)flags, get_comma(last));
723 724 725 726 727
        } else {
            gemu_log("%s", get_comma(last));
        }
    } else {
        /* no string version of flags found, print them in hex then */
728
        gemu_log("%#x%s", (unsigned int)flags, get_comma(last));
729 730 731 732
    }
}

static void
733
print_at_dirfd(abi_long dirfd, int last)
734 735 736 737 738 739 740
{
#ifdef AT_FDCWD
    if (dirfd == AT_FDCWD) {
        gemu_log("AT_FDCWD%s", get_comma(last));
        return;
    }
#endif
741
    gemu_log("%d%s", (int)dirfd, get_comma(last));
742 743 744
}

static void
745
print_file_mode(abi_long mode, int last)
746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761
{
    const char *sep = "";
    const struct flags *m;

    for (m = &mode_flags[0]; m->f_string != NULL; m++) {
        if ((m->f_value & mode) == m->f_value) {
            gemu_log("%s%s", m->f_string, sep);
            sep = "|";
            mode &= ~m->f_value;
            break;
        }
    }

    mode &= ~S_IFMT;
    /* print rest of the mode as octal */
    if (mode != 0)
762
        gemu_log("%s%#o", sep, (unsigned int)mode);
763 764 765 766 767

    gemu_log("%s", get_comma(last));
}

static void
768
print_open_flags(abi_long flags, int last)
769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807
{
    print_flags(open_access_flags, flags & TARGET_O_ACCMODE, 1);
    flags &= ~TARGET_O_ACCMODE;
    if (flags == 0) {
        gemu_log("%s", get_comma(last));
        return;
    }
    gemu_log("|");
    print_flags(open_flags, flags, last);
}

static void
print_syscall_prologue(const struct syscallname *sc)
{
    gemu_log("%s(", sc->name);
}

/*ARGSUSED*/
static void
print_syscall_epilogue(const struct syscallname *sc)
{
    (void)sc;
    gemu_log(")");
}

static void
print_string(abi_long addr, int last)
{
    char *s;

    if ((s = lock_user_string(addr)) != NULL) {
        gemu_log("\"%s\"%s", s, get_comma(last));
        unlock_user(s, addr, 0);
    } else {
        /* can't get string out of it, so print it as pointer */
        print_pointer(addr, last);
    }
}

808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837
#define MAX_PRINT_BUF 40
static void
print_buf(abi_long addr, abi_long len, int last)
{
    uint8_t *s;
    int i;

    s = lock_user(VERIFY_READ, addr, len, 1);
    if (s) {
        gemu_log("\"");
        for (i = 0; i < MAX_PRINT_BUF && i < len; i++) {
            if (isprint(s[i])) {
                gemu_log("%c", s[i]);
            } else {
                gemu_log("\\%o", s[i]);
            }
        }
        gemu_log("\"");
        if (i != len) {
            gemu_log("...");
        }
        if (!last) {
            gemu_log(",");
        }
        unlock_user(s, addr, 0);
    } else {
        print_pointer(addr, last);
    }
}

838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886
/*
 * Prints out raw parameter using given format.  Caller needs
 * to do byte swapping if needed.
 */
static void
print_raw_param(const char *fmt, abi_long param, int last)
{
    char format[64];

    (void) snprintf(format, sizeof (format), "%s%s", fmt, get_comma(last));
    gemu_log(format, param);
}

static void
print_pointer(abi_long p, int last)
{
    if (p == 0)
        gemu_log("NULL%s", get_comma(last));
    else
        gemu_log("0x" TARGET_ABI_FMT_lx "%s", p, get_comma(last));
}

/*
 * Reads 32-bit (int) number from guest address space from
 * address 'addr' and prints it.
 */
static void
print_number(abi_long addr, int last)
{
    if (addr == 0) {
        gemu_log("NULL%s", get_comma(last));
    } else {
        int num;

        get_user_s32(num, addr);
        gemu_log("[%d]%s", num, get_comma(last));
    }
}

static void
print_timeval(abi_ulong tv_addr, int last)
{
    if( tv_addr ) {
        struct target_timeval *tv;

        tv = lock_user(VERIFY_READ, tv_addr, sizeof(*tv), 1);
        if (!tv)
            return;
        gemu_log("{" TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld "}%s",
887
            tswapal(tv->tv_sec), tswapal(tv->tv_usec), get_comma(last));
888 889 890 891 892 893 894 895 896 897 898 899 900 901
        unlock_user(tv, tv_addr, 0);
    } else
        gemu_log("NULL%s", get_comma(last));
}

#undef UNUSED

#ifdef TARGET_NR_accept
static void
print_accept(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);
902
    print_raw_param("%d", arg0, 0);
903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958
    print_pointer(arg1, 0);
    print_number(arg2, 1);
    print_syscall_epilogue(name);
}
#endif

#ifdef TARGET_NR_access
static void
print_access(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_flags(access_flags, arg1, 1);
    print_syscall_epilogue(name);
}
#endif

#ifdef TARGET_NR_brk
static void
print_brk(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_pointer(arg0, 1);
    print_syscall_epilogue(name);
}
#endif

#ifdef TARGET_NR_chdir
static void
print_chdir(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, 1);
    print_syscall_epilogue(name);
}
#endif

#ifdef TARGET_NR_chmod
static void
print_chmod(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_file_mode(arg1, 1);
    print_syscall_epilogue(name);
}
#endif

L
Laurent Vivier 已提交
959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991
#ifdef TARGET_NR_clone
static void
print_clone(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);
#if defined(TARGET_M68K)
    print_flags(clone_flags, arg0, 0);
    print_raw_param("newsp=0x" TARGET_ABI_FMT_lx, arg1, 1);
#elif defined(TARGET_SH4) || defined(TARGET_ALPHA)
    print_flags(clone_flags, arg0, 0);
    print_raw_param("child_stack=0x" TARGET_ABI_FMT_lx, arg1, 0);
    print_raw_param("parent_tidptr=0x" TARGET_ABI_FMT_lx, arg2, 0);
    print_raw_param("child_tidptr=0x" TARGET_ABI_FMT_lx, arg3, 0);
    print_raw_param("tls=0x" TARGET_ABI_FMT_lx, arg4, 1);
#elif defined(TARGET_CRIS)
    print_raw_param("child_stack=0x" TARGET_ABI_FMT_lx, arg0, 0);
    print_flags(clone_flags, arg1, 0);
    print_raw_param("parent_tidptr=0x" TARGET_ABI_FMT_lx, arg2, 0);
    print_raw_param("tls=0x" TARGET_ABI_FMT_lx, arg3, 0);
    print_raw_param("child_tidptr=0x" TARGET_ABI_FMT_lx, arg4, 1);
#else
    print_flags(clone_flags, arg0, 0);
    print_raw_param("child_stack=0x" TARGET_ABI_FMT_lx, arg1, 0);
    print_raw_param("parent_tidptr=0x" TARGET_ABI_FMT_lx, arg2, 0);
    print_raw_param("tls=0x" TARGET_ABI_FMT_lx, arg3, 0);
    print_raw_param("child_tidptr=0x" TARGET_ABI_FMT_lx, arg4, 1);
#endif
    print_syscall_epilogue(name);
}
#endif

992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012
#ifdef TARGET_NR_creat
static void
print_creat(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_file_mode(arg1, 1);
    print_syscall_epilogue(name);
}
#endif

#ifdef TARGET_NR_execv
static void
print_execv(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);
1013
    print_raw_param("0x" TARGET_ABI_FMT_lx, arg1, 1);
1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056
    print_syscall_epilogue(name);
}
#endif

#ifdef TARGET_NR_faccessat
static void
print_faccessat(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_at_dirfd(arg0, 0);
    print_string(arg1, 0);
    print_flags(access_flags, arg2, 0);
    print_flags(at_file_flags, arg3, 1);
    print_syscall_epilogue(name);
}
#endif

#ifdef TARGET_NR_fchmodat
static void
print_fchmodat(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_at_dirfd(arg0, 0);
    print_string(arg1, 0);
    print_file_mode(arg2, 0);
    print_flags(at_file_flags, arg3, 1);
    print_syscall_epilogue(name);
}
#endif

#ifdef TARGET_NR_fchownat
static void
print_fchownat(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_at_dirfd(arg0, 0);
    print_string(arg1, 0);
1057 1058
    print_raw_param("%d", arg2, 0);
    print_raw_param("%d", arg3, 0);
1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070
    print_flags(at_file_flags, arg4, 1);
    print_syscall_epilogue(name);
}
#endif

#if defined(TARGET_NR_fcntl) || defined(TARGET_NR_fcntl64)
static void
print_fcntl(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);
1071
    print_raw_param("%d", arg0, 0);
1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137
    switch(arg1) {
    case TARGET_F_DUPFD:
        gemu_log("F_DUPFD,");
        print_raw_param(TARGET_ABI_FMT_ld, arg2, 1);
        break;
    case TARGET_F_GETFD:
        gemu_log("F_GETFD");
        break;
    case TARGET_F_SETFD:
        gemu_log("F_SETFD,");
        print_raw_param(TARGET_ABI_FMT_ld, arg2, 1);
        break;
    case TARGET_F_GETFL:
        gemu_log("F_GETFL");
        break;
    case TARGET_F_SETFL:
        gemu_log("F_SETFL,");
        print_open_flags(arg2, 1);
        break;
    case TARGET_F_GETLK:
        gemu_log("F_GETLK,");
        print_pointer(arg2, 1);
        break;
    case TARGET_F_SETLK:
        gemu_log("F_SETLK,");
        print_pointer(arg2, 1);
        break;
    case TARGET_F_SETLKW:
        gemu_log("F_SETLKW,");
        print_pointer(arg2, 1);
        break;
    case TARGET_F_GETOWN:
        gemu_log("F_GETOWN");
        break;
    case TARGET_F_SETOWN:
        gemu_log("F_SETOWN,");
        print_raw_param(TARGET_ABI_FMT_ld, arg2, 0);
        break;
    case TARGET_F_GETSIG:
        gemu_log("F_GETSIG");
        break;
    case TARGET_F_SETSIG:
        gemu_log("F_SETSIG,");
        print_raw_param(TARGET_ABI_FMT_ld, arg2, 0);
        break;
#if TARGET_ABI_BITS == 32
    case TARGET_F_GETLK64:
        gemu_log("F_GETLK64,");
        print_pointer(arg2, 1);
        break;
    case TARGET_F_SETLK64:
        gemu_log("F_SETLK64,");
        print_pointer(arg2, 1);
        break;
    case TARGET_F_SETLKW64:
        gemu_log("F_SETLKW64,");
        print_pointer(arg2, 1);
        break;
#endif
    case TARGET_F_SETLEASE:
        gemu_log("F_SETLEASE,");
        print_raw_param(TARGET_ABI_FMT_ld, arg2, 0);
        break;
    case TARGET_F_GETLEASE:
        gemu_log("F_GETLEASE");
        break;
1138 1139 1140 1141 1142 1143 1144
    case TARGET_F_SETPIPE_SZ:
        gemu_log("F_SETPIPE_SZ,");
        print_raw_param(TARGET_ABI_FMT_ld, arg2, 1);
        break;
    case TARGET_F_GETPIPE_SZ:
        gemu_log("F_GETPIPE_SZ");
        break;
1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157
    case TARGET_F_DUPFD_CLOEXEC:
        gemu_log("F_DUPFD_CLOEXEC,");
        print_raw_param(TARGET_ABI_FMT_ld, arg2, 1);
        break;
    case TARGET_F_NOTIFY:
        gemu_log("F_NOTIFY,");
        print_raw_param(TARGET_ABI_FMT_ld, arg2, 0);
        break;
    default:
        print_raw_param(TARGET_ABI_FMT_ld, arg1, 0);
        print_pointer(arg2, 1);
        break;
    }
1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207
    print_syscall_epilogue(name);
}
#define print_fcntl64   print_fcntl
#endif


#ifdef TARGET_NR_futimesat
static void
print_futimesat(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_at_dirfd(arg0, 0);
    print_string(arg1, 0);
    print_timeval(arg2, 0);
    print_timeval(arg2 + sizeof (struct target_timeval), 1);
    print_syscall_epilogue(name);
}
#endif

#ifdef TARGET_NR_link
static void
print_link(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_string(arg1, 1);
    print_syscall_epilogue(name);
}
#endif

#ifdef TARGET_NR_linkat
static void
print_linkat(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_at_dirfd(arg0, 0);
    print_string(arg1, 0);
    print_at_dirfd(arg2, 0);
    print_string(arg3, 0);
    print_flags(at_file_flags, arg4, 1);
    print_syscall_epilogue(name);
}
#endif

L
Laurent Vivier 已提交
1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229
#ifdef TARGET_NR__llseek
static void
print__llseek(const struct syscallname *name,
    abi_long arg0, abi_long arg1, abi_long arg2,
    abi_long arg3, abi_long arg4, abi_long arg5)
{
    const char *whence = "UNKNOWN";
    print_syscall_prologue(name);
    print_raw_param("%d", arg0, 0);
    print_raw_param("%ld", arg1, 0);
    print_raw_param("%ld", arg2, 0);
    print_pointer(arg3, 0);
    switch(arg4) {
    case SEEK_SET: whence = "SEEK_SET"; break;
    case SEEK_CUR: whence = "SEEK_CUR"; break;
    case SEEK_END: whence = "SEEK_END"; break;
    }
    gemu_log("%s",whence);
    print_syscall_epilogue(name);
}
#endif

1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561
#if defined(TARGET_NR_socketcall)

#define get_user_ualx(x, gaddr, idx) \
        get_user_ual(x, (gaddr) + (idx) * sizeof(abi_long))

static void do_print_socket(const char *name, abi_long arg1)
{
    abi_ulong domain, type, protocol;

    get_user_ualx(domain, arg1, 0);
    get_user_ualx(type, arg1, 1);
    get_user_ualx(protocol, arg1, 2);
    gemu_log("%s(", name);
    print_socket_domain(domain);
    gemu_log(",");
    print_socket_type(type);
    gemu_log(",");
    if (domain == AF_PACKET ||
        (domain == AF_INET && type == TARGET_SOCK_PACKET)) {
        protocol = tswap16(protocol);
    }
    print_socket_protocol(domain, type, protocol);
    gemu_log(")");
}

static void do_print_sockaddr(const char *name, abi_long arg1)
{
    abi_ulong sockfd, addr, addrlen;

    get_user_ualx(sockfd, arg1, 0);
    get_user_ualx(addr, arg1, 1);
    get_user_ualx(addrlen, arg1, 2);

    gemu_log("%s(", name);
    print_raw_param(TARGET_ABI_FMT_ld, sockfd, 0);
    print_sockaddr(addr, addrlen);
    gemu_log(")");
}

static void do_print_listen(const char *name, abi_long arg1)
{
    abi_ulong sockfd, backlog;

    get_user_ualx(sockfd, arg1, 0);
    get_user_ualx(backlog, arg1, 1);

    gemu_log("%s(", name);
    print_raw_param(TARGET_ABI_FMT_ld, sockfd, 0);
    print_raw_param(TARGET_ABI_FMT_ld, backlog, 1);
    gemu_log(")");
}

static void do_print_socketpair(const char *name, abi_long arg1)
{
    abi_ulong domain, type, protocol, tab;

    get_user_ualx(domain, arg1, 0);
    get_user_ualx(type, arg1, 1);
    get_user_ualx(protocol, arg1, 2);
    get_user_ualx(tab, arg1, 3);

    gemu_log("%s(", name);
    print_socket_domain(domain);
    gemu_log(",");
    print_socket_type(type);
    gemu_log(",");
    print_socket_protocol(domain, type, protocol);
    gemu_log(",");
    print_raw_param(TARGET_ABI_FMT_lx, tab, 1);
    gemu_log(")");
}

static void do_print_sendrecv(const char *name, abi_long arg1)
{
    abi_ulong sockfd, msg, len, flags;

    get_user_ualx(sockfd, arg1, 0);
    get_user_ualx(msg, arg1, 1);
    get_user_ualx(len, arg1, 2);
    get_user_ualx(flags, arg1, 3);

    gemu_log("%s(", name);
    print_raw_param(TARGET_ABI_FMT_ld, sockfd, 0);
    print_buf(msg, len, 0);
    print_raw_param(TARGET_ABI_FMT_ld, len, 0);
    print_flags(msg_flags, flags, 1);
    gemu_log(")");
}

static void do_print_msgaddr(const char *name, abi_long arg1)
{
    abi_ulong sockfd, msg, len, flags, addr, addrlen;

    get_user_ualx(sockfd, arg1, 0);
    get_user_ualx(msg, arg1, 1);
    get_user_ualx(len, arg1, 2);
    get_user_ualx(flags, arg1, 3);
    get_user_ualx(addr, arg1, 4);
    get_user_ualx(addrlen, arg1, 5);

    gemu_log("%s(", name);
    print_raw_param(TARGET_ABI_FMT_ld, sockfd, 0);
    print_buf(msg, len, 0);
    print_raw_param(TARGET_ABI_FMT_ld, len, 0);
    print_flags(msg_flags, flags, 0);
    print_sockaddr(addr, addrlen);
    gemu_log(")");
}

static void do_print_shutdown(const char *name, abi_long arg1)
{
    abi_ulong sockfd, how;

    get_user_ualx(sockfd, arg1, 0);
    get_user_ualx(how, arg1, 1);

    gemu_log("shutdown(");
    print_raw_param(TARGET_ABI_FMT_ld, sockfd, 0);
    switch (how) {
    case SHUT_RD:
        gemu_log("SHUT_RD");
        break;
    case SHUT_WR:
        gemu_log("SHUT_WR");
        break;
    case SHUT_RDWR:
        gemu_log("SHUT_RDWR");
        break;
    default:
        print_raw_param(TARGET_ABI_FMT_ld, how, 1);
        break;
    }
    gemu_log(")");
}

static void do_print_msg(const char *name, abi_long arg1)
{
    abi_ulong sockfd, msg, flags;

    get_user_ualx(sockfd, arg1, 0);
    get_user_ualx(msg, arg1, 1);
    get_user_ualx(flags, arg1, 2);

    gemu_log("%s(", name);
    print_raw_param(TARGET_ABI_FMT_ld, sockfd, 0);
    print_pointer(msg, 0);
    print_flags(msg_flags, flags, 1);
    gemu_log(")");
}

static void do_print_sockopt(const char *name, abi_long arg1)
{
    abi_ulong sockfd, level, optname, optval, optlen;

    get_user_ualx(sockfd, arg1, 0);
    get_user_ualx(level, arg1, 1);
    get_user_ualx(optname, arg1, 2);
    get_user_ualx(optval, arg1, 3);
    get_user_ualx(optlen, arg1, 4);

    gemu_log("%s(", name);
    print_raw_param(TARGET_ABI_FMT_ld, sockfd, 0);
    switch (level) {
    case SOL_TCP:
        gemu_log("SOL_TCP,");
        print_raw_param(TARGET_ABI_FMT_ld, optname, 0);
        print_pointer(optval, 0);
        break;
    case SOL_IP:
        gemu_log("SOL_IP,");
        print_raw_param(TARGET_ABI_FMT_ld, optname, 0);
        print_pointer(optval, 0);
        break;
    case SOL_RAW:
        gemu_log("SOL_RAW,");
        print_raw_param(TARGET_ABI_FMT_ld, optname, 0);
        print_pointer(optval, 0);
        break;
    case TARGET_SOL_SOCKET:
        gemu_log("SOL_SOCKET,");
        switch (optname) {
        case TARGET_SO_DEBUG:
            gemu_log("SO_DEBUG,");
print_optint:
            print_number(optval, 0);
            break;
        case TARGET_SO_REUSEADDR:
            gemu_log("SO_REUSEADDR,");
            goto print_optint;
        case TARGET_SO_TYPE:
            gemu_log("SO_TYPE,");
            goto print_optint;
        case TARGET_SO_ERROR:
            gemu_log("SO_ERROR,");
            goto print_optint;
        case TARGET_SO_DONTROUTE:
            gemu_log("SO_DONTROUTE,");
            goto print_optint;
        case TARGET_SO_BROADCAST:
            gemu_log("SO_BROADCAST,");
            goto print_optint;
        case TARGET_SO_SNDBUF:
            gemu_log("SO_SNDBUF,");
            goto print_optint;
        case TARGET_SO_RCVBUF:
            gemu_log("SO_RCVBUF,");
            goto print_optint;
        case TARGET_SO_KEEPALIVE:
            gemu_log("SO_KEEPALIVE,");
            goto print_optint;
        case TARGET_SO_OOBINLINE:
            gemu_log("SO_OOBINLINE,");
            goto print_optint;
        case TARGET_SO_NO_CHECK:
            gemu_log("SO_NO_CHECK,");
            goto print_optint;
        case TARGET_SO_PRIORITY:
            gemu_log("SO_PRIORITY,");
            goto print_optint;
        case TARGET_SO_BSDCOMPAT:
            gemu_log("SO_BSDCOMPAT,");
            goto print_optint;
        case TARGET_SO_PASSCRED:
            gemu_log("SO_PASSCRED,");
            goto print_optint;
        case TARGET_SO_TIMESTAMP:
            gemu_log("SO_TIMESTAMP,");
            goto print_optint;
        case TARGET_SO_RCVLOWAT:
            gemu_log("SO_RCVLOWAT,");
            goto print_optint;
        case TARGET_SO_RCVTIMEO:
            gemu_log("SO_RCVTIMEO,");
            print_timeval(optval, 0);
            break;
        case TARGET_SO_SNDTIMEO:
            gemu_log("SO_SNDTIMEO,");
            print_timeval(optval, 0);
            break;
        case TARGET_SO_ATTACH_FILTER: {
            struct target_sock_fprog *fprog;

            gemu_log("SO_ATTACH_FILTER,");

            if (lock_user_struct(VERIFY_READ, fprog, optval,  0)) {
                struct target_sock_filter *filter;
                gemu_log("{");
                if (lock_user_struct(VERIFY_READ, filter,
                                     tswapal(fprog->filter),  0)) {
                    int i;
                    for (i = 0; i < tswap16(fprog->len) - 1; i++) {
                        gemu_log("[%d]{0x%x,%d,%d,0x%x},",
                                 i, tswap16(filter[i].code),
                                 filter[i].jt, filter[i].jf,
                                 tswap32(filter[i].k));
                    }
                    gemu_log("[%d]{0x%x,%d,%d,0x%x}",
                             i, tswap16(filter[i].code),
                             filter[i].jt, filter[i].jf,
                             tswap32(filter[i].k));
                } else {
                    gemu_log(TARGET_ABI_FMT_lx, tswapal(fprog->filter));
                }
                gemu_log(",%d},", tswap16(fprog->len));
                unlock_user(fprog, optval, 0);
            } else {
                print_pointer(optval, 0);
            }
            break;
        }
        default:
            print_raw_param(TARGET_ABI_FMT_ld, optname, 0);
            print_pointer(optval, 0);
            break;
        }
        break;
    default:
        print_raw_param(TARGET_ABI_FMT_ld, level, 0);
        print_raw_param(TARGET_ABI_FMT_ld, optname, 0);
        print_pointer(optval, 0);
        break;
    }
    print_raw_param(TARGET_ABI_FMT_ld, optlen, 1);
    gemu_log(")");
}

#define PRINT_SOCKOP(name, func) \
    [SOCKOP_##name] = { #name, func }

static struct {
    const char *name;
    void (*print)(const char *, abi_long);
} scall[] = {
    PRINT_SOCKOP(socket, do_print_socket),
    PRINT_SOCKOP(bind, do_print_sockaddr),
    PRINT_SOCKOP(connect, do_print_sockaddr),
    PRINT_SOCKOP(listen, do_print_listen),
    PRINT_SOCKOP(accept, do_print_sockaddr),
    PRINT_SOCKOP(getsockname, do_print_sockaddr),
    PRINT_SOCKOP(getpeername, do_print_sockaddr),
    PRINT_SOCKOP(socketpair, do_print_socketpair),
    PRINT_SOCKOP(send, do_print_sendrecv),
    PRINT_SOCKOP(recv, do_print_sendrecv),
    PRINT_SOCKOP(sendto, do_print_msgaddr),
    PRINT_SOCKOP(recvfrom, do_print_msgaddr),
    PRINT_SOCKOP(shutdown, do_print_shutdown),
    PRINT_SOCKOP(sendmsg, do_print_msg),
    PRINT_SOCKOP(recvmsg, do_print_msg),
    PRINT_SOCKOP(setsockopt, do_print_sockopt),
    PRINT_SOCKOP(getsockopt, do_print_sockopt),
};

static void
print_socketcall(const struct syscallname *name,
                 abi_long arg0, abi_long arg1, abi_long arg2,
                 abi_long arg3, abi_long arg4, abi_long arg5)
{
    if (arg0 >= 0 && arg0 < ARRAY_SIZE(scall) && scall[arg0].print) {
        scall[arg0].print(scall[arg0].name, arg1);
        return;
    }
    print_syscall_prologue(name);
    print_raw_param(TARGET_ABI_FMT_ld, arg0, 0);
    print_raw_param(TARGET_ABI_FMT_ld, arg1, 0);
    print_raw_param(TARGET_ABI_FMT_ld, arg2, 0);
    print_raw_param(TARGET_ABI_FMT_ld, arg3, 0);
    print_raw_param(TARGET_ABI_FMT_ld, arg4, 0);
    print_raw_param(TARGET_ABI_FMT_ld, arg5, 0);
    print_syscall_epilogue(name);
}
#endif

1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585
#if defined(TARGET_NR_stat) || defined(TARGET_NR_stat64) || \
    defined(TARGET_NR_lstat) || defined(TARGET_NR_lstat64)
static void
print_stat(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_pointer(arg1, 1);
    print_syscall_epilogue(name);
}
#define print_lstat     print_stat
#define print_stat64	print_stat
#define print_lstat64   print_stat
#endif

#if defined(TARGET_NR_fstat) || defined(TARGET_NR_fstat64)
static void
print_fstat(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);
1586
    print_raw_param("%d", arg0, 0);
1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619
    print_pointer(arg1, 1);
    print_syscall_epilogue(name);
}
#define print_fstat64     print_fstat
#endif

#ifdef TARGET_NR_mkdir
static void
print_mkdir(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_file_mode(arg1, 1);
    print_syscall_epilogue(name);
}
#endif

#ifdef TARGET_NR_mkdirat
static void
print_mkdirat(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_at_dirfd(arg0, 0);
    print_string(arg1, 0);
    print_file_mode(arg2, 1);
    print_syscall_epilogue(name);
}
#endif

L
Laurent Vivier 已提交
1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631
#ifdef TARGET_NR_rmdir
static void
print_rmdir(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_syscall_epilogue(name);
}
#endif

L
Laurent Vivier 已提交
1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665
#ifdef TARGET_NR_rt_sigaction
static void
print_rt_sigaction(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_signal(arg0, 0);
    print_pointer(arg1, 0);
    print_pointer(arg2, 1);
    print_syscall_epilogue(name);
}
#endif

#ifdef TARGET_NR_rt_sigprocmask
static void
print_rt_sigprocmask(const struct syscallname *name,
    abi_long arg0, abi_long arg1, abi_long arg2,
    abi_long arg3, abi_long arg4, abi_long arg5)
{
    const char *how = "UNKNOWN";
    print_syscall_prologue(name);
    switch(arg0) {
    case TARGET_SIG_BLOCK: how = "SIG_BLOCK"; break;
    case TARGET_SIG_UNBLOCK: how = "SIG_UNBLOCK"; break;
    case TARGET_SIG_SETMASK: how = "SIG_SETMASK"; break;
    }
    gemu_log("%s,",how);
    print_pointer(arg1, 0);
    print_pointer(arg2, 1);
    print_syscall_epilogue(name);
}
#endif

1666 1667 1668 1669 1670 1671
#ifdef TARGET_NR_mknod
static void
print_mknod(const struct syscallname *name,
    abi_long arg0, abi_long arg1, abi_long arg2,
    abi_long arg3, abi_long arg4, abi_long arg5)
{
1672
    int hasdev = (arg1 & (S_IFCHR|S_IFBLK));
1673 1674 1675 1676 1677

    print_syscall_prologue(name);
    print_string(arg0, 0);
    print_file_mode(arg1, (hasdev == 0));
    if (hasdev) {
1678 1679
        print_raw_param("makedev(%d", major(arg2), 0);
        print_raw_param("%d)", minor(arg2), 1);
1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690
    }
    print_syscall_epilogue(name);
}
#endif

#ifdef TARGET_NR_mknodat
static void
print_mknodat(const struct syscallname *name,
    abi_long arg0, abi_long arg1, abi_long arg2,
    abi_long arg3, abi_long arg4, abi_long arg5)
{
1691
    int hasdev = (arg2 & (S_IFCHR|S_IFBLK));
1692 1693 1694 1695 1696 1697

    print_syscall_prologue(name);
    print_at_dirfd(arg0, 0);
    print_string(arg1, 0);
    print_file_mode(arg2, (hasdev == 0));
    if (hasdev) {
1698 1699
        print_raw_param("makedev(%d", major(arg3), 0);
        print_raw_param("%d)", minor(arg3), 1);
1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710
    }
    print_syscall_epilogue(name);
}
#endif

#ifdef TARGET_NR_mq_open
static void
print_mq_open(const struct syscallname *name,
    abi_long arg0, abi_long arg1, abi_long arg2,
    abi_long arg3, abi_long arg4, abi_long arg5)
{
1711
    int is_creat = (arg1 & TARGET_O_CREAT);
1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729

    print_syscall_prologue(name);
    print_string(arg0, 0);
    print_open_flags(arg1, (is_creat == 0));
    if (is_creat) {
        print_file_mode(arg2, 0);
        print_pointer(arg3, 1);
    }
    print_syscall_epilogue(name);
}
#endif

#ifdef TARGET_NR_open
static void
print_open(const struct syscallname *name,
    abi_long arg0, abi_long arg1, abi_long arg2,
    abi_long arg3, abi_long arg4, abi_long arg5)
{
1730
    int is_creat = (arg1 & TARGET_O_CREAT);
1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746

    print_syscall_prologue(name);
    print_string(arg0, 0);
    print_open_flags(arg1, (is_creat == 0));
    if (is_creat)
        print_file_mode(arg2, 1);
    print_syscall_epilogue(name);
}
#endif

#ifdef TARGET_NR_openat
static void
print_openat(const struct syscallname *name,
    abi_long arg0, abi_long arg1, abi_long arg2,
    abi_long arg3, abi_long arg4, abi_long arg5)
{
1747
    int is_creat = (arg2 & TARGET_O_CREAT);
1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795

    print_syscall_prologue(name);
    print_at_dirfd(arg0, 0);
    print_string(arg1, 0);
    print_open_flags(arg2, (is_creat == 0));
    if (is_creat)
        print_file_mode(arg3, 1);
    print_syscall_epilogue(name);
}
#endif

#ifdef TARGET_NR_mq_unlink
static void
print_mq_unlink(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, 1);
    print_syscall_epilogue(name);
}
#endif

#if defined(TARGET_NR_fstatat64) || defined(TARGET_NR_newfstatat)
static void
print_fstatat64(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_at_dirfd(arg0, 0);
    print_string(arg1, 0);
    print_pointer(arg2, 0);
    print_flags(at_file_flags, arg3, 1);
    print_syscall_epilogue(name);
}
#define print_newfstatat    print_fstatat64
#endif

#ifdef TARGET_NR_readlink
static void
print_readlink(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_pointer(arg1, 0);
1796
    print_raw_param("%u", arg2, 1);
1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810
    print_syscall_epilogue(name);
}
#endif

#ifdef TARGET_NR_readlinkat
static void
print_readlinkat(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_at_dirfd(arg0, 0);
    print_string(arg1, 0);
    print_pointer(arg2, 0);
1811
    print_raw_param("%u", arg3, 1);
1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992
    print_syscall_epilogue(name);
}
#endif

#ifdef TARGET_NR_rename
static void
print_rename(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_string(arg1, 1);
    print_syscall_epilogue(name);
}
#endif

#ifdef TARGET_NR_renameat
static void
print_renameat(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_at_dirfd(arg0, 0);
    print_string(arg1, 0);
    print_at_dirfd(arg2, 0);
    print_string(arg3, 1);
    print_syscall_epilogue(name);
}
#endif

#ifdef TARGET_NR_statfs
static void
print_statfs(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_pointer(arg1, 1);
    print_syscall_epilogue(name);
}
#define print_statfs64  print_statfs
#endif

#ifdef TARGET_NR_symlink
static void
print_symlink(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_string(arg1, 1);
    print_syscall_epilogue(name);
}
#endif

#ifdef TARGET_NR_symlinkat
static void
print_symlinkat(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_at_dirfd(arg1, 0);
    print_string(arg2, 1);
    print_syscall_epilogue(name);
}
#endif

#ifdef TARGET_NR_mount
static void
print_mount(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_string(arg1, 0);
    print_string(arg2, 0);
    print_flags(mount_flags, arg3, 0);
    print_pointer(arg4, 1);
    print_syscall_epilogue(name);
}
#endif

#ifdef TARGET_NR_umount
static void
print_umount(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, 1);
    print_syscall_epilogue(name);
}
#endif

#ifdef TARGET_NR_umount2
static void
print_umount2(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_flags(umount2_flags, arg1, 1);
    print_syscall_epilogue(name);
}
#endif

#ifdef TARGET_NR_unlink
static void
print_unlink(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, 1);
    print_syscall_epilogue(name);
}
#endif

#ifdef TARGET_NR_unlinkat
static void
print_unlinkat(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_at_dirfd(arg0, 0);
    print_string(arg1, 0);
    print_flags(unlinkat_flags, arg2, 1);
    print_syscall_epilogue(name);
}
#endif

#ifdef TARGET_NR_utime
static void
print_utime(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_pointer(arg1, 1);
    print_syscall_epilogue(name);
}
#endif

#ifdef TARGET_NR_utimes
static void
print_utimes(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_pointer(arg1, 1);
    print_syscall_epilogue(name);
}
#endif

#ifdef TARGET_NR_utimensat
static void
print_utimensat(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_at_dirfd(arg0, 0);
    print_string(arg1, 0);
    print_pointer(arg2, 0);
    print_flags(at_file_flags, arg3, 1);
    print_syscall_epilogue(name);
}
#endif

1993
#if defined(TARGET_NR_mmap) || defined(TARGET_NR_mmap2)
1994 1995 1996 1997 1998 1999 2000
static void
print_mmap(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_pointer(arg0, 0);
2001
    print_raw_param("%d", arg1, 0);
2002 2003
    print_flags(mmap_prot_flags, arg2, 0);
    print_flags(mmap_flags, arg3, 0);
2004 2005
    print_raw_param("%d", arg4, 0);
    print_raw_param("%#x", arg5, 1);
2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018
    print_syscall_epilogue(name);
}
#define print_mmap2     print_mmap
#endif

#ifdef TARGET_NR_mprotect
static void
print_mprotect(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_pointer(arg0, 0);
2019
    print_raw_param("%d", arg1, 0);
2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032
    print_flags(mmap_prot_flags, arg2, 1);
    print_syscall_epilogue(name);
}
#endif

#ifdef TARGET_NR_munmap
static void
print_munmap(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_pointer(arg0, 0);
2033
    print_raw_param("%d", arg1, 1);
2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046
    print_syscall_epilogue(name);
}
#endif

#ifdef TARGET_NR_futex
static void print_futex_op(abi_long tflag, int last)
{
#define print_op(val) \
if( cmd == val ) { \
    gemu_log(#val); \
    return; \
}

2047
    int cmd = (int)tflag;
2048
#ifdef FUTEX_PRIVATE_FLAG
P
Paul Brook 已提交
2049
    if (cmd & FUTEX_PRIVATE_FLAG) {
2050
        gemu_log("FUTEX_PRIVATE_FLAG|");
P
Paul Brook 已提交
2051 2052
        cmd &= ~FUTEX_PRIVATE_FLAG;
    }
2053 2054 2055 2056 2057 2058
#endif
#ifdef FUTEX_CLOCK_REALTIME
    if (cmd & FUTEX_CLOCK_REALTIME) {
        gemu_log("FUTEX_CLOCK_REALTIME|");
        cmd &= ~FUTEX_CLOCK_REALTIME;
    }
2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086
#endif
    print_op(FUTEX_WAIT)
    print_op(FUTEX_WAKE)
    print_op(FUTEX_FD)
    print_op(FUTEX_REQUEUE)
    print_op(FUTEX_CMP_REQUEUE)
    print_op(FUTEX_WAKE_OP)
    print_op(FUTEX_LOCK_PI)
    print_op(FUTEX_UNLOCK_PI)
    print_op(FUTEX_TRYLOCK_PI)
#ifdef FUTEX_WAIT_BITSET
    print_op(FUTEX_WAIT_BITSET)
#endif
#ifdef FUTEX_WAKE_BITSET
    print_op(FUTEX_WAKE_BITSET)
#endif
    /* unknown values */
    gemu_log("%d",cmd);
}

static void
print_futex(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_pointer(arg0, 0);
    print_futex_op(arg1, 0);
2087
    print_raw_param(",%d", arg2, 0);
2088 2089
    print_pointer(arg3, 0); /* struct timespec */
    print_pointer(arg4, 0);
2090
    print_raw_param("%d", arg4, 1);
2091 2092 2093 2094
    print_syscall_epilogue(name);
}
#endif

L
Laurent Vivier 已提交
2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107
#ifdef TARGET_NR_kill
static void
print_kill(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);
    print_signal(arg1, 1);
    print_syscall_epilogue(name);
}
#endif

2108 2109 2110 2111
/*
 * An array of all of the syscalls we know about
 */

2112
static const struct syscallname scnames[] = {
2113 2114 2115
#include "strace.list"
};

2116
static int nsyscalls = ARRAY_SIZE(scnames);
2117 2118 2119 2120 2121 2122

/*
 * The public interface to this module.
 */
void
print_syscall(int num,
B
bellard 已提交
2123 2124
              abi_long arg1, abi_long arg2, abi_long arg3,
              abi_long arg4, abi_long arg5, abi_long arg6)
2125 2126
{
    int i;
2127
    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 ")";
2128 2129 2130 2131 2132 2133 2134 2135

    gemu_log("%d ", getpid() );

    for(i=0;i<nsyscalls;i++)
        if( scnames[i].nr == num ) {
            if( scnames[i].call != NULL ) {
                scnames[i].call(&scnames[i],arg1,arg2,arg3,arg4,arg5,arg6);
            } else {
B
bellard 已提交
2136 2137
                /* XXX: this format system is broken because it uses
                   host types and host pointers for strings */
2138 2139 2140 2141
                if( scnames[i].format != NULL )
                    format = scnames[i].format;
                gemu_log(format,scnames[i].name, arg1,arg2,arg3,arg4,arg5,arg6);
            }
P
pbrook 已提交
2142
            return;
2143
        }
P
pbrook 已提交
2144
    gemu_log("Unknown syscall %d\n", num);
2145 2146 2147 2148
}


void
B
bellard 已提交
2149
print_syscall_ret(int num, abi_long ret)
2150 2151
{
    int i;
2152
    const char *errstr = NULL;
2153 2154 2155 2156 2157 2158

    for(i=0;i<nsyscalls;i++)
        if( scnames[i].nr == num ) {
            if( scnames[i].result != NULL ) {
                scnames[i].result(&scnames[i],ret);
            } else {
2159 2160 2161 2162 2163 2164
                if (ret < 0) {
                    errstr = target_strerror(-ret);
                }
                if (errstr) {
                    gemu_log(" = -1 errno=" TARGET_ABI_FMT_ld " (%s)\n",
                             -ret, errstr);
2165
                } else {
B
bellard 已提交
2166
                    gemu_log(" = " TARGET_ABI_FMT_ld "\n", ret);
2167 2168 2169 2170 2171
                }
            }
            break;
        }
}