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 <sched.h> 12 #include "qemu.h" 13 14 int do_strace=0; 15 16 struct syscallname { 17 int nr; 18 const char *name; 19 const char *format; 20 void (*call)(const struct syscallname *, 21 abi_long, abi_long, abi_long, 22 abi_long, abi_long, abi_long); 23 void (*result)(const struct syscallname *, abi_long); 24 }; 25 26 #ifdef __GNUC__ 27 /* 28 * It is possible that target doesn't have syscall that uses 29 * following flags but we don't want the compiler to warn 30 * us about them being unused. Same applies to utility print 31 * functions. It is ok to keep them while not used. 32 */ 33 #define UNUSED __attribute__ ((unused)) 34 #else 35 #define UNUSED 36 #endif 37 38 /* 39 * Structure used to translate flag values into strings. This is 40 * similar that is in the actual strace tool. 41 */ 42 struct flags { 43 abi_long f_value; /* flag */ 44 const char *f_string; /* stringified flag */ 45 }; 46 47 /* common flags for all architectures */ 48 #define FLAG_GENERIC(name) { name, #name } 49 /* target specific flags (syscall_defs.h has TARGET_<flag>) */ 50 #define FLAG_TARGET(name) { TARGET_ ## name, #name } 51 /* end of flags array */ 52 #define FLAG_END { 0, NULL } 53 54 UNUSED static const char *get_comma(int); 55 UNUSED static void print_pointer(abi_long, int); 56 UNUSED static void print_flags(const struct flags *, abi_long, int); 57 UNUSED static void print_at_dirfd(abi_long, int); 58 UNUSED static void print_file_mode(abi_long, int); 59 UNUSED static void print_open_flags(abi_long, int); 60 UNUSED static void print_syscall_prologue(const struct syscallname *); 61 UNUSED static void print_syscall_epilogue(const struct syscallname *); 62 UNUSED static void print_string(abi_long, int); 63 UNUSED static void print_buf(abi_long addr, abi_long len, int last); 64 UNUSED static void print_raw_param(const char *, abi_long, int); 65 UNUSED static void print_timeval(abi_ulong, int); 66 UNUSED static void print_number(abi_long, int); 67 UNUSED static void print_signal(abi_ulong, int); 68 UNUSED static void print_sockaddr(abi_ulong addr, abi_long addrlen); 69 UNUSED static void print_socket_domain(int domain); 70 UNUSED static void print_socket_type(int type); 71 UNUSED static void print_socket_protocol(int domain, int type, int protocol); 72 73 /* 74 * Utility functions 75 */ 76 static void 77 print_ipc_cmd(int cmd) 78 { 79 #define output_cmd(val) \ 80 if( cmd == val ) { \ 81 gemu_log(#val); \ 82 return; \ 83 } 84 85 cmd &= 0xff; 86 87 /* General IPC commands */ 88 output_cmd( IPC_RMID ); 89 output_cmd( IPC_SET ); 90 output_cmd( IPC_STAT ); 91 output_cmd( IPC_INFO ); 92 /* msgctl() commands */ 93 #ifdef __USER_MISC 94 output_cmd( MSG_STAT ); 95 output_cmd( MSG_INFO ); 96 #endif 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 126 static void 127 print_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 157 static void 158 print_sockaddr(abi_ulong addr, abi_long addrlen) 159 { 160 struct target_sockaddr *sa; 161 int i; 162 int sa_family; 163 164 sa = lock_user(VERIFY_READ, addr, addrlen, 1); 165 if (sa) { 166 sa_family = tswap16(sa->sa_family); 167 switch (sa_family) { 168 case AF_UNIX: { 169 struct target_sockaddr_un *un = (struct target_sockaddr_un *)sa; 170 int i; 171 gemu_log("{sun_family=AF_UNIX,sun_path=\""); 172 for (i = 0; i < addrlen - 173 offsetof(struct target_sockaddr_un, sun_path) && 174 un->sun_path[i]; i++) { 175 gemu_log("%c", un->sun_path[i]); 176 } 177 gemu_log("\"}"); 178 break; 179 } 180 case AF_INET: { 181 struct target_sockaddr_in *in = (struct target_sockaddr_in *)sa; 182 uint8_t *c = (uint8_t *)&in->sin_addr.s_addr; 183 gemu_log("{sin_family=AF_INET,sin_port=htons(%d),", 184 ntohs(in->sin_port)); 185 gemu_log("sin_addr=inet_addr(\"%d.%d.%d.%d\")", 186 c[0], c[1], c[2], c[3]); 187 gemu_log("}"); 188 break; 189 } 190 case AF_PACKET: { 191 struct target_sockaddr_ll *ll = (struct target_sockaddr_ll *)sa; 192 uint8_t *c = (uint8_t *)&ll->sll_addr; 193 gemu_log("{sll_family=AF_PACKET," 194 "sll_protocol=htons(0x%04x),if%d,pkttype=", 195 ntohs(ll->sll_protocol), ll->sll_ifindex); 196 switch (ll->sll_pkttype) { 197 case PACKET_HOST: 198 gemu_log("PACKET_HOST"); 199 break; 200 case PACKET_BROADCAST: 201 gemu_log("PACKET_BROADCAST"); 202 break; 203 case PACKET_MULTICAST: 204 gemu_log("PACKET_MULTICAST"); 205 break; 206 case PACKET_OTHERHOST: 207 gemu_log("PACKET_OTHERHOST"); 208 break; 209 case PACKET_OUTGOING: 210 gemu_log("PACKET_OUTGOING"); 211 break; 212 default: 213 gemu_log("%d", ll->sll_pkttype); 214 break; 215 } 216 gemu_log(",sll_addr=%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x", 217 c[0], c[1], c[2], c[3], c[4], c[5], c[6], c[7]); 218 gemu_log("}"); 219 break; 220 } 221 default: 222 gemu_log("{sa_family=%d, sa_data={", sa->sa_family); 223 for (i = 0; i < 13; i++) { 224 gemu_log("%02x, ", sa->sa_data[i]); 225 } 226 gemu_log("%02x}", sa->sa_data[i]); 227 gemu_log("}"); 228 break; 229 } 230 unlock_user(sa, addr, 0); 231 } else { 232 print_raw_param("0x"TARGET_ABI_FMT_lx, addr, 0); 233 } 234 gemu_log(", "TARGET_ABI_FMT_ld, addrlen); 235 } 236 237 static void 238 print_socket_domain(int domain) 239 { 240 switch (domain) { 241 case PF_UNIX: 242 gemu_log("PF_UNIX"); 243 break; 244 case PF_INET: 245 gemu_log("PF_INET"); 246 break; 247 case PF_PACKET: 248 gemu_log("PF_PACKET"); 249 break; 250 default: 251 gemu_log("%d", domain); 252 break; 253 } 254 } 255 256 static void 257 print_socket_type(int type) 258 { 259 switch (type) { 260 case TARGET_SOCK_DGRAM: 261 gemu_log("SOCK_DGRAM"); 262 break; 263 case TARGET_SOCK_STREAM: 264 gemu_log("SOCK_STREAM"); 265 break; 266 case TARGET_SOCK_RAW: 267 gemu_log("SOCK_RAW"); 268 break; 269 case TARGET_SOCK_RDM: 270 gemu_log("SOCK_RDM"); 271 break; 272 case TARGET_SOCK_SEQPACKET: 273 gemu_log("SOCK_SEQPACKET"); 274 break; 275 case TARGET_SOCK_PACKET: 276 gemu_log("SOCK_PACKET"); 277 break; 278 } 279 } 280 281 static void 282 print_socket_protocol(int domain, int type, int protocol) 283 { 284 if (domain == AF_PACKET || 285 (domain == AF_INET && type == TARGET_SOCK_PACKET)) { 286 switch (protocol) { 287 case 0x0003: 288 gemu_log("ETH_P_ALL"); 289 break; 290 default: 291 gemu_log("%d", protocol); 292 } 293 return; 294 } 295 296 switch (protocol) { 297 case IPPROTO_IP: 298 gemu_log("IPPROTO_IP"); 299 break; 300 case IPPROTO_TCP: 301 gemu_log("IPPROTO_TCP"); 302 break; 303 case IPPROTO_UDP: 304 gemu_log("IPPROTO_UDP"); 305 break; 306 case IPPROTO_RAW: 307 gemu_log("IPPROTO_RAW"); 308 break; 309 default: 310 gemu_log("%d", protocol); 311 break; 312 } 313 } 314 315 316 #ifdef TARGET_NR__newselect 317 static void 318 print_fdset(int n, abi_ulong target_fds_addr) 319 { 320 int i; 321 322 gemu_log("["); 323 if( target_fds_addr ) { 324 abi_long *target_fds; 325 326 target_fds = lock_user(VERIFY_READ, 327 target_fds_addr, 328 sizeof(*target_fds)*(n / TARGET_ABI_BITS + 1), 329 1); 330 331 if (!target_fds) 332 return; 333 334 for (i=n; i>=0; i--) { 335 if ((tswapal(target_fds[i / TARGET_ABI_BITS]) >> (i & (TARGET_ABI_BITS - 1))) & 1) 336 gemu_log("%d,", i ); 337 } 338 unlock_user(target_fds, target_fds_addr, 0); 339 } 340 gemu_log("]"); 341 } 342 #endif 343 344 /* 345 * Sysycall specific output functions 346 */ 347 348 /* select */ 349 #ifdef TARGET_NR__newselect 350 static long newselect_arg1 = 0; 351 static long newselect_arg2 = 0; 352 static long newselect_arg3 = 0; 353 static long newselect_arg4 = 0; 354 static long newselect_arg5 = 0; 355 356 static void 357 print_newselect(const struct syscallname *name, 358 abi_long arg1, abi_long arg2, abi_long arg3, 359 abi_long arg4, abi_long arg5, abi_long arg6) 360 { 361 gemu_log("%s(" TARGET_ABI_FMT_ld ",", name->name, arg1); 362 print_fdset(arg1, arg2); 363 gemu_log(","); 364 print_fdset(arg1, arg3); 365 gemu_log(","); 366 print_fdset(arg1, arg4); 367 gemu_log(","); 368 print_timeval(arg5, 1); 369 gemu_log(")"); 370 371 /* save for use in the return output function below */ 372 newselect_arg1=arg1; 373 newselect_arg2=arg2; 374 newselect_arg3=arg3; 375 newselect_arg4=arg4; 376 newselect_arg5=arg5; 377 } 378 #endif 379 380 #ifdef TARGET_NR_semctl 381 static void 382 print_semctl(const struct syscallname *name, 383 abi_long arg1, abi_long arg2, abi_long arg3, 384 abi_long arg4, abi_long arg5, abi_long arg6) 385 { 386 gemu_log("%s(" TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld ",", name->name, arg1, arg2); 387 print_ipc_cmd(arg3); 388 gemu_log(",0x" TARGET_ABI_FMT_lx ")", arg4); 389 } 390 #endif 391 392 static void 393 print_execve(const struct syscallname *name, 394 abi_long arg1, abi_long arg2, abi_long arg3, 395 abi_long arg4, abi_long arg5, abi_long arg6) 396 { 397 abi_ulong arg_ptr_addr; 398 char *s; 399 400 if (!(s = lock_user_string(arg1))) 401 return; 402 gemu_log("%s(\"%s\",{", name->name, s); 403 unlock_user(s, arg1, 0); 404 405 for (arg_ptr_addr = arg2; ; arg_ptr_addr += sizeof(abi_ulong)) { 406 abi_ulong *arg_ptr, arg_addr; 407 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 unlock_user(arg_ptr, arg_ptr_addr, 0); 413 if (!arg_addr) 414 break; 415 if ((s = lock_user_string(arg_addr))) { 416 gemu_log("\"%s\",", s); 417 unlock_user(s, arg_addr, 0); 418 } 419 } 420 421 gemu_log("NULL})"); 422 } 423 424 #ifdef TARGET_NR_ipc 425 static void 426 print_ipc(const struct syscallname *name, 427 abi_long arg1, abi_long arg2, abi_long arg3, 428 abi_long arg4, abi_long arg5, abi_long arg6) 429 { 430 switch(arg1) { 431 case IPCOP_semctl: 432 gemu_log("semctl(" TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld ",", arg1, arg2); 433 print_ipc_cmd(arg3); 434 gemu_log(",0x" TARGET_ABI_FMT_lx ")", arg4); 435 break; 436 default: 437 gemu_log("%s(" TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld ")", 438 name->name, arg1, arg2, arg3, arg4); 439 } 440 } 441 #endif 442 443 /* 444 * Variants for the return value output function 445 */ 446 447 static void 448 print_syscall_ret_addr(const struct syscallname *name, abi_long ret) 449 { 450 const char *errstr = NULL; 451 452 if (ret < 0) { 453 errstr = target_strerror(-ret); 454 } 455 if (errstr) { 456 gemu_log(" = -1 errno=%d (%s)\n", (int)-ret, errstr); 457 } else { 458 gemu_log(" = 0x" TARGET_ABI_FMT_lx "\n", ret); 459 } 460 } 461 462 #if 0 /* currently unused */ 463 static void 464 print_syscall_ret_raw(struct syscallname *name, abi_long ret) 465 { 466 gemu_log(" = 0x" TARGET_ABI_FMT_lx "\n", ret); 467 } 468 #endif 469 470 #ifdef TARGET_NR__newselect 471 static void 472 print_syscall_ret_newselect(const struct syscallname *name, abi_long ret) 473 { 474 gemu_log(" = 0x" TARGET_ABI_FMT_lx " (", ret); 475 print_fdset(newselect_arg1,newselect_arg2); 476 gemu_log(","); 477 print_fdset(newselect_arg1,newselect_arg3); 478 gemu_log(","); 479 print_fdset(newselect_arg1,newselect_arg4); 480 gemu_log(","); 481 print_timeval(newselect_arg5, 1); 482 gemu_log(")\n"); 483 } 484 #endif 485 486 UNUSED static struct flags access_flags[] = { 487 FLAG_GENERIC(F_OK), 488 FLAG_GENERIC(R_OK), 489 FLAG_GENERIC(W_OK), 490 FLAG_GENERIC(X_OK), 491 FLAG_END, 492 }; 493 494 UNUSED static struct flags at_file_flags[] = { 495 #ifdef AT_EACCESS 496 FLAG_GENERIC(AT_EACCESS), 497 #endif 498 #ifdef AT_SYMLINK_NOFOLLOW 499 FLAG_GENERIC(AT_SYMLINK_NOFOLLOW), 500 #endif 501 FLAG_END, 502 }; 503 504 UNUSED static struct flags unlinkat_flags[] = { 505 #ifdef AT_REMOVEDIR 506 FLAG_GENERIC(AT_REMOVEDIR), 507 #endif 508 FLAG_END, 509 }; 510 511 UNUSED static struct flags mode_flags[] = { 512 FLAG_GENERIC(S_IFSOCK), 513 FLAG_GENERIC(S_IFLNK), 514 FLAG_GENERIC(S_IFREG), 515 FLAG_GENERIC(S_IFBLK), 516 FLAG_GENERIC(S_IFDIR), 517 FLAG_GENERIC(S_IFCHR), 518 FLAG_GENERIC(S_IFIFO), 519 FLAG_END, 520 }; 521 522 UNUSED static struct flags open_access_flags[] = { 523 FLAG_TARGET(O_RDONLY), 524 FLAG_TARGET(O_WRONLY), 525 FLAG_TARGET(O_RDWR), 526 FLAG_END, 527 }; 528 529 UNUSED static struct flags open_flags[] = { 530 FLAG_TARGET(O_APPEND), 531 FLAG_TARGET(O_CREAT), 532 FLAG_TARGET(O_DIRECTORY), 533 FLAG_TARGET(O_EXCL), 534 FLAG_TARGET(O_LARGEFILE), 535 FLAG_TARGET(O_NOCTTY), 536 FLAG_TARGET(O_NOFOLLOW), 537 FLAG_TARGET(O_NONBLOCK), /* also O_NDELAY */ 538 FLAG_TARGET(O_DSYNC), 539 FLAG_TARGET(__O_SYNC), 540 FLAG_TARGET(O_TRUNC), 541 #ifdef O_DIRECT 542 FLAG_TARGET(O_DIRECT), 543 #endif 544 #ifdef O_NOATIME 545 FLAG_TARGET(O_NOATIME), 546 #endif 547 #ifdef O_CLOEXEC 548 FLAG_TARGET(O_CLOEXEC), 549 #endif 550 #ifdef O_PATH 551 FLAG_TARGET(O_PATH), 552 #endif 553 FLAG_END, 554 }; 555 556 UNUSED static struct flags mount_flags[] = { 557 #ifdef MS_BIND 558 FLAG_GENERIC(MS_BIND), 559 #endif 560 #ifdef MS_DIRSYNC 561 FLAG_GENERIC(MS_DIRSYNC), 562 #endif 563 FLAG_GENERIC(MS_MANDLOCK), 564 #ifdef MS_MOVE 565 FLAG_GENERIC(MS_MOVE), 566 #endif 567 FLAG_GENERIC(MS_NOATIME), 568 FLAG_GENERIC(MS_NODEV), 569 FLAG_GENERIC(MS_NODIRATIME), 570 FLAG_GENERIC(MS_NOEXEC), 571 FLAG_GENERIC(MS_NOSUID), 572 FLAG_GENERIC(MS_RDONLY), 573 #ifdef MS_RELATIME 574 FLAG_GENERIC(MS_RELATIME), 575 #endif 576 FLAG_GENERIC(MS_REMOUNT), 577 FLAG_GENERIC(MS_SYNCHRONOUS), 578 FLAG_END, 579 }; 580 581 UNUSED static struct flags umount2_flags[] = { 582 #ifdef MNT_FORCE 583 FLAG_GENERIC(MNT_FORCE), 584 #endif 585 #ifdef MNT_DETACH 586 FLAG_GENERIC(MNT_DETACH), 587 #endif 588 #ifdef MNT_EXPIRE 589 FLAG_GENERIC(MNT_EXPIRE), 590 #endif 591 FLAG_END, 592 }; 593 594 UNUSED static struct flags mmap_prot_flags[] = { 595 FLAG_GENERIC(PROT_NONE), 596 FLAG_GENERIC(PROT_EXEC), 597 FLAG_GENERIC(PROT_READ), 598 FLAG_GENERIC(PROT_WRITE), 599 FLAG_TARGET(PROT_SEM), 600 FLAG_GENERIC(PROT_GROWSDOWN), 601 FLAG_GENERIC(PROT_GROWSUP), 602 FLAG_END, 603 }; 604 605 UNUSED static struct flags mmap_flags[] = { 606 FLAG_TARGET(MAP_SHARED), 607 FLAG_TARGET(MAP_PRIVATE), 608 FLAG_TARGET(MAP_ANONYMOUS), 609 FLAG_TARGET(MAP_DENYWRITE), 610 FLAG_TARGET(MAP_FIXED), 611 FLAG_TARGET(MAP_GROWSDOWN), 612 FLAG_TARGET(MAP_EXECUTABLE), 613 #ifdef MAP_LOCKED 614 FLAG_TARGET(MAP_LOCKED), 615 #endif 616 #ifdef MAP_NONBLOCK 617 FLAG_TARGET(MAP_NONBLOCK), 618 #endif 619 FLAG_TARGET(MAP_NORESERVE), 620 #ifdef MAP_POPULATE 621 FLAG_TARGET(MAP_POPULATE), 622 #endif 623 #ifdef TARGET_MAP_UNINITIALIZED 624 FLAG_TARGET(MAP_UNINITIALIZED), 625 #endif 626 FLAG_END, 627 }; 628 629 UNUSED static struct flags clone_flags[] = { 630 FLAG_GENERIC(CLONE_VM), 631 FLAG_GENERIC(CLONE_FS), 632 FLAG_GENERIC(CLONE_FILES), 633 FLAG_GENERIC(CLONE_SIGHAND), 634 FLAG_GENERIC(CLONE_PTRACE), 635 FLAG_GENERIC(CLONE_VFORK), 636 FLAG_GENERIC(CLONE_PARENT), 637 FLAG_GENERIC(CLONE_THREAD), 638 FLAG_GENERIC(CLONE_NEWNS), 639 FLAG_GENERIC(CLONE_SYSVSEM), 640 FLAG_GENERIC(CLONE_SETTLS), 641 FLAG_GENERIC(CLONE_PARENT_SETTID), 642 FLAG_GENERIC(CLONE_CHILD_CLEARTID), 643 FLAG_GENERIC(CLONE_DETACHED), 644 FLAG_GENERIC(CLONE_UNTRACED), 645 FLAG_GENERIC(CLONE_CHILD_SETTID), 646 #if defined(CLONE_NEWUTS) 647 FLAG_GENERIC(CLONE_NEWUTS), 648 #endif 649 #if defined(CLONE_NEWIPC) 650 FLAG_GENERIC(CLONE_NEWIPC), 651 #endif 652 #if defined(CLONE_NEWUSER) 653 FLAG_GENERIC(CLONE_NEWUSER), 654 #endif 655 #if defined(CLONE_NEWPID) 656 FLAG_GENERIC(CLONE_NEWPID), 657 #endif 658 #if defined(CLONE_NEWNET) 659 FLAG_GENERIC(CLONE_NEWNET), 660 #endif 661 #if defined(CLONE_IO) 662 FLAG_GENERIC(CLONE_IO), 663 #endif 664 FLAG_END, 665 }; 666 667 UNUSED static struct flags msg_flags[] = { 668 /* send */ 669 FLAG_GENERIC(MSG_CONFIRM), 670 FLAG_GENERIC(MSG_DONTROUTE), 671 FLAG_GENERIC(MSG_DONTWAIT), 672 FLAG_GENERIC(MSG_EOR), 673 FLAG_GENERIC(MSG_MORE), 674 FLAG_GENERIC(MSG_NOSIGNAL), 675 FLAG_GENERIC(MSG_OOB), 676 /* recv */ 677 FLAG_GENERIC(MSG_CMSG_CLOEXEC), 678 FLAG_GENERIC(MSG_ERRQUEUE), 679 FLAG_GENERIC(MSG_PEEK), 680 FLAG_GENERIC(MSG_TRUNC), 681 FLAG_GENERIC(MSG_WAITALL), 682 /* recvmsg */ 683 FLAG_GENERIC(MSG_CTRUNC), 684 FLAG_END, 685 }; 686 687 /* 688 * print_xxx utility functions. These are used to print syscall 689 * parameters in certain format. All of these have parameter 690 * named 'last'. This parameter is used to add comma to output 691 * when last == 0. 692 */ 693 694 static const char * 695 get_comma(int last) 696 { 697 return ((last) ? "" : ","); 698 } 699 700 static void 701 print_flags(const struct flags *f, abi_long flags, int last) 702 { 703 const char *sep = ""; 704 int n; 705 706 if ((flags == 0) && (f->f_value == 0)) { 707 gemu_log("%s%s", f->f_string, get_comma(last)); 708 return; 709 } 710 for (n = 0; f->f_string != NULL; f++) { 711 if ((f->f_value != 0) && ((flags & f->f_value) == f->f_value)) { 712 gemu_log("%s%s", sep, f->f_string); 713 flags &= ~f->f_value; 714 sep = "|"; 715 n++; 716 } 717 } 718 719 if (n > 0) { 720 /* print rest of the flags as numeric */ 721 if (flags != 0) { 722 gemu_log("%s%#x%s", sep, (unsigned int)flags, get_comma(last)); 723 } else { 724 gemu_log("%s", get_comma(last)); 725 } 726 } else { 727 /* 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 #ifdef AT_FDCWD 736 if (dirfd == AT_FDCWD) { 737 gemu_log("AT_FDCWD%s", get_comma(last)); 738 return; 739 } 740 #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 const char *sep = ""; 748 const struct flags *m; 749 750 for (m = &mode_flags[0]; m->f_string != NULL; m++) { 751 if ((m->f_value & mode) == m->f_value) { 752 gemu_log("%s%s", m->f_string, sep); 753 sep = "|"; 754 mode &= ~m->f_value; 755 break; 756 } 757 } 758 759 mode &= ~S_IFMT; 760 /* print rest of the mode as octal */ 761 if (mode != 0) 762 gemu_log("%s%#o", sep, (unsigned int)mode); 763 764 gemu_log("%s", get_comma(last)); 765 } 766 767 static void 768 print_open_flags(abi_long flags, int last) 769 { 770 print_flags(open_access_flags, flags & TARGET_O_ACCMODE, 1); 771 flags &= ~TARGET_O_ACCMODE; 772 if (flags == 0) { 773 gemu_log("%s", get_comma(last)); 774 return; 775 } 776 gemu_log("|"); 777 print_flags(open_flags, flags, last); 778 } 779 780 static void 781 print_syscall_prologue(const struct syscallname *sc) 782 { 783 gemu_log("%s(", sc->name); 784 } 785 786 /*ARGSUSED*/ 787 static void 788 print_syscall_epilogue(const struct syscallname *sc) 789 { 790 (void)sc; 791 gemu_log(")"); 792 } 793 794 static void 795 print_string(abi_long addr, int last) 796 { 797 char *s; 798 799 if ((s = lock_user_string(addr)) != NULL) { 800 gemu_log("\"%s\"%s", s, get_comma(last)); 801 unlock_user(s, addr, 0); 802 } else { 803 /* can't get string out of it, so print it as pointer */ 804 print_pointer(addr, last); 805 } 806 } 807 808 #define MAX_PRINT_BUF 40 809 static void 810 print_buf(abi_long addr, abi_long len, int last) 811 { 812 uint8_t *s; 813 int i; 814 815 s = lock_user(VERIFY_READ, addr, len, 1); 816 if (s) { 817 gemu_log("\""); 818 for (i = 0; i < MAX_PRINT_BUF && i < len; i++) { 819 if (isprint(s[i])) { 820 gemu_log("%c", s[i]); 821 } else { 822 gemu_log("\\%o", s[i]); 823 } 824 } 825 gemu_log("\""); 826 if (i != len) { 827 gemu_log("..."); 828 } 829 if (!last) { 830 gemu_log(","); 831 } 832 unlock_user(s, addr, 0); 833 } else { 834 print_pointer(addr, last); 835 } 836 } 837 838 /* 839 * Prints out raw parameter using given format. Caller needs 840 * to do byte swapping if needed. 841 */ 842 static void 843 print_raw_param(const char *fmt, abi_long param, int last) 844 { 845 char format[64]; 846 847 (void) snprintf(format, sizeof (format), "%s%s", fmt, get_comma(last)); 848 gemu_log(format, param); 849 } 850 851 static void 852 print_pointer(abi_long p, int last) 853 { 854 if (p == 0) 855 gemu_log("NULL%s", get_comma(last)); 856 else 857 gemu_log("0x" TARGET_ABI_FMT_lx "%s", p, get_comma(last)); 858 } 859 860 /* 861 * Reads 32-bit (int) number from guest address space from 862 * address 'addr' and prints it. 863 */ 864 static void 865 print_number(abi_long addr, int last) 866 { 867 if (addr == 0) { 868 gemu_log("NULL%s", get_comma(last)); 869 } else { 870 int num; 871 872 get_user_s32(num, addr); 873 gemu_log("[%d]%s", num, get_comma(last)); 874 } 875 } 876 877 static void 878 print_timeval(abi_ulong tv_addr, int last) 879 { 880 if( tv_addr ) { 881 struct target_timeval *tv; 882 883 tv = lock_user(VERIFY_READ, tv_addr, sizeof(*tv), 1); 884 if (!tv) 885 return; 886 gemu_log("{" TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld "}%s", 887 tswapal(tv->tv_sec), tswapal(tv->tv_usec), get_comma(last)); 888 unlock_user(tv, tv_addr, 0); 889 } else 890 gemu_log("NULL%s", get_comma(last)); 891 } 892 893 #undef UNUSED 894 895 #ifdef TARGET_NR_accept 896 static void 897 print_accept(const struct syscallname *name, 898 abi_long arg0, abi_long arg1, abi_long arg2, 899 abi_long arg3, abi_long arg4, abi_long arg5) 900 { 901 print_syscall_prologue(name); 902 print_raw_param("%d", arg0, 0); 903 print_pointer(arg1, 0); 904 print_number(arg2, 1); 905 print_syscall_epilogue(name); 906 } 907 #endif 908 909 #ifdef TARGET_NR_access 910 static void 911 print_access(const struct syscallname *name, 912 abi_long arg0, abi_long arg1, abi_long arg2, 913 abi_long arg3, abi_long arg4, abi_long arg5) 914 { 915 print_syscall_prologue(name); 916 print_string(arg0, 0); 917 print_flags(access_flags, arg1, 1); 918 print_syscall_epilogue(name); 919 } 920 #endif 921 922 #ifdef TARGET_NR_brk 923 static void 924 print_brk(const struct syscallname *name, 925 abi_long arg0, abi_long arg1, abi_long arg2, 926 abi_long arg3, abi_long arg4, abi_long arg5) 927 { 928 print_syscall_prologue(name); 929 print_pointer(arg0, 1); 930 print_syscall_epilogue(name); 931 } 932 #endif 933 934 #ifdef TARGET_NR_chdir 935 static void 936 print_chdir(const struct syscallname *name, 937 abi_long arg0, abi_long arg1, abi_long arg2, 938 abi_long arg3, abi_long arg4, abi_long arg5) 939 { 940 print_syscall_prologue(name); 941 print_string(arg0, 1); 942 print_syscall_epilogue(name); 943 } 944 #endif 945 946 #ifdef TARGET_NR_chmod 947 static void 948 print_chmod(const struct syscallname *name, 949 abi_long arg0, abi_long arg1, abi_long arg2, 950 abi_long arg3, abi_long arg4, abi_long arg5) 951 { 952 print_syscall_prologue(name); 953 print_string(arg0, 0); 954 print_file_mode(arg1, 1); 955 print_syscall_epilogue(name); 956 } 957 #endif 958 959 #ifdef TARGET_NR_clone 960 static void do_print_clone(unsigned int flags, abi_ulong newsp, 961 abi_ulong parent_tidptr, target_ulong newtls, 962 abi_ulong child_tidptr) 963 { 964 print_flags(clone_flags, flags, 0); 965 print_raw_param("child_stack=0x" TARGET_ABI_FMT_lx, newsp, 0); 966 print_raw_param("parent_tidptr=0x" TARGET_ABI_FMT_lx, parent_tidptr, 0); 967 print_raw_param("tls=0x" TARGET_ABI_FMT_lx, newtls, 0); 968 print_raw_param("child_tidptr=0x" TARGET_ABI_FMT_lx, child_tidptr, 1); 969 } 970 971 static void 972 print_clone(const struct syscallname *name, 973 abi_long arg1, abi_long arg2, abi_long arg3, 974 abi_long arg4, abi_long arg5, abi_long arg6) 975 { 976 print_syscall_prologue(name); 977 #if defined(TARGET_MICROBLAZE) 978 do_print_clone(arg1, arg2, arg4, arg6, arg5); 979 #elif defined(TARGET_CLONE_BACKWARDS) 980 do_print_clone(arg1, arg2, arg3, arg4, arg5); 981 #elif defined(TARGET_CLONE_BACKWARDS2) 982 do_print_clone(arg2, arg1, arg3, arg5, arg4); 983 #else 984 do_print_clone(arg1, arg2, arg3, arg5, arg4); 985 #endif 986 print_syscall_epilogue(name); 987 } 988 #endif 989 990 #ifdef TARGET_NR_creat 991 static void 992 print_creat(const struct syscallname *name, 993 abi_long arg0, abi_long arg1, abi_long arg2, 994 abi_long arg3, abi_long arg4, abi_long arg5) 995 { 996 print_syscall_prologue(name); 997 print_string(arg0, 0); 998 print_file_mode(arg1, 1); 999 print_syscall_epilogue(name); 1000 } 1001 #endif 1002 1003 #ifdef TARGET_NR_execv 1004 static void 1005 print_execv(const struct syscallname *name, 1006 abi_long arg0, abi_long arg1, abi_long arg2, 1007 abi_long arg3, abi_long arg4, abi_long arg5) 1008 { 1009 print_syscall_prologue(name); 1010 print_string(arg0, 0); 1011 print_raw_param("0x" TARGET_ABI_FMT_lx, arg1, 1); 1012 print_syscall_epilogue(name); 1013 } 1014 #endif 1015 1016 #ifdef TARGET_NR_faccessat 1017 static void 1018 print_faccessat(const struct syscallname *name, 1019 abi_long arg0, abi_long arg1, abi_long arg2, 1020 abi_long arg3, abi_long arg4, abi_long arg5) 1021 { 1022 print_syscall_prologue(name); 1023 print_at_dirfd(arg0, 0); 1024 print_string(arg1, 0); 1025 print_flags(access_flags, arg2, 0); 1026 print_flags(at_file_flags, arg3, 1); 1027 print_syscall_epilogue(name); 1028 } 1029 #endif 1030 1031 #ifdef TARGET_NR_fchmodat 1032 static void 1033 print_fchmodat(const struct syscallname *name, 1034 abi_long arg0, abi_long arg1, abi_long arg2, 1035 abi_long arg3, abi_long arg4, abi_long arg5) 1036 { 1037 print_syscall_prologue(name); 1038 print_at_dirfd(arg0, 0); 1039 print_string(arg1, 0); 1040 print_file_mode(arg2, 0); 1041 print_flags(at_file_flags, arg3, 1); 1042 print_syscall_epilogue(name); 1043 } 1044 #endif 1045 1046 #ifdef TARGET_NR_fchownat 1047 static void 1048 print_fchownat(const struct syscallname *name, 1049 abi_long arg0, abi_long arg1, abi_long arg2, 1050 abi_long arg3, abi_long arg4, abi_long arg5) 1051 { 1052 print_syscall_prologue(name); 1053 print_at_dirfd(arg0, 0); 1054 print_string(arg1, 0); 1055 print_raw_param("%d", arg2, 0); 1056 print_raw_param("%d", arg3, 0); 1057 print_flags(at_file_flags, arg4, 1); 1058 print_syscall_epilogue(name); 1059 } 1060 #endif 1061 1062 #if defined(TARGET_NR_fcntl) || defined(TARGET_NR_fcntl64) 1063 static void 1064 print_fcntl(const struct syscallname *name, 1065 abi_long arg0, abi_long arg1, abi_long arg2, 1066 abi_long arg3, abi_long arg4, abi_long arg5) 1067 { 1068 print_syscall_prologue(name); 1069 print_raw_param("%d", arg0, 0); 1070 switch(arg1) { 1071 case TARGET_F_DUPFD: 1072 gemu_log("F_DUPFD,"); 1073 print_raw_param(TARGET_ABI_FMT_ld, arg2, 1); 1074 break; 1075 case TARGET_F_GETFD: 1076 gemu_log("F_GETFD"); 1077 break; 1078 case TARGET_F_SETFD: 1079 gemu_log("F_SETFD,"); 1080 print_raw_param(TARGET_ABI_FMT_ld, arg2, 1); 1081 break; 1082 case TARGET_F_GETFL: 1083 gemu_log("F_GETFL"); 1084 break; 1085 case TARGET_F_SETFL: 1086 gemu_log("F_SETFL,"); 1087 print_open_flags(arg2, 1); 1088 break; 1089 case TARGET_F_GETLK: 1090 gemu_log("F_GETLK,"); 1091 print_pointer(arg2, 1); 1092 break; 1093 case TARGET_F_SETLK: 1094 gemu_log("F_SETLK,"); 1095 print_pointer(arg2, 1); 1096 break; 1097 case TARGET_F_SETLKW: 1098 gemu_log("F_SETLKW,"); 1099 print_pointer(arg2, 1); 1100 break; 1101 case TARGET_F_GETOWN: 1102 gemu_log("F_GETOWN"); 1103 break; 1104 case TARGET_F_SETOWN: 1105 gemu_log("F_SETOWN,"); 1106 print_raw_param(TARGET_ABI_FMT_ld, arg2, 0); 1107 break; 1108 case TARGET_F_GETSIG: 1109 gemu_log("F_GETSIG"); 1110 break; 1111 case TARGET_F_SETSIG: 1112 gemu_log("F_SETSIG,"); 1113 print_raw_param(TARGET_ABI_FMT_ld, arg2, 0); 1114 break; 1115 #if TARGET_ABI_BITS == 32 1116 case TARGET_F_GETLK64: 1117 gemu_log("F_GETLK64,"); 1118 print_pointer(arg2, 1); 1119 break; 1120 case TARGET_F_SETLK64: 1121 gemu_log("F_SETLK64,"); 1122 print_pointer(arg2, 1); 1123 break; 1124 case TARGET_F_SETLKW64: 1125 gemu_log("F_SETLKW64,"); 1126 print_pointer(arg2, 1); 1127 break; 1128 #endif 1129 case TARGET_F_SETLEASE: 1130 gemu_log("F_SETLEASE,"); 1131 print_raw_param(TARGET_ABI_FMT_ld, arg2, 0); 1132 break; 1133 case TARGET_F_GETLEASE: 1134 gemu_log("F_GETLEASE"); 1135 break; 1136 case TARGET_F_SETPIPE_SZ: 1137 gemu_log("F_SETPIPE_SZ,"); 1138 print_raw_param(TARGET_ABI_FMT_ld, arg2, 1); 1139 break; 1140 case TARGET_F_GETPIPE_SZ: 1141 gemu_log("F_GETPIPE_SZ"); 1142 break; 1143 case TARGET_F_DUPFD_CLOEXEC: 1144 gemu_log("F_DUPFD_CLOEXEC,"); 1145 print_raw_param(TARGET_ABI_FMT_ld, arg2, 1); 1146 break; 1147 case TARGET_F_NOTIFY: 1148 gemu_log("F_NOTIFY,"); 1149 print_raw_param(TARGET_ABI_FMT_ld, arg2, 0); 1150 break; 1151 default: 1152 print_raw_param(TARGET_ABI_FMT_ld, arg1, 0); 1153 print_pointer(arg2, 1); 1154 break; 1155 } 1156 print_syscall_epilogue(name); 1157 } 1158 #define print_fcntl64 print_fcntl 1159 #endif 1160 1161 1162 #ifdef TARGET_NR_futimesat 1163 static void 1164 print_futimesat(const struct syscallname *name, 1165 abi_long arg0, abi_long arg1, abi_long arg2, 1166 abi_long arg3, abi_long arg4, abi_long arg5) 1167 { 1168 print_syscall_prologue(name); 1169 print_at_dirfd(arg0, 0); 1170 print_string(arg1, 0); 1171 print_timeval(arg2, 0); 1172 print_timeval(arg2 + sizeof (struct target_timeval), 1); 1173 print_syscall_epilogue(name); 1174 } 1175 #endif 1176 1177 #ifdef TARGET_NR_link 1178 static void 1179 print_link(const struct syscallname *name, 1180 abi_long arg0, abi_long arg1, abi_long arg2, 1181 abi_long arg3, abi_long arg4, abi_long arg5) 1182 { 1183 print_syscall_prologue(name); 1184 print_string(arg0, 0); 1185 print_string(arg1, 1); 1186 print_syscall_epilogue(name); 1187 } 1188 #endif 1189 1190 #ifdef TARGET_NR_linkat 1191 static void 1192 print_linkat(const struct syscallname *name, 1193 abi_long arg0, abi_long arg1, abi_long arg2, 1194 abi_long arg3, abi_long arg4, abi_long arg5) 1195 { 1196 print_syscall_prologue(name); 1197 print_at_dirfd(arg0, 0); 1198 print_string(arg1, 0); 1199 print_at_dirfd(arg2, 0); 1200 print_string(arg3, 0); 1201 print_flags(at_file_flags, arg4, 1); 1202 print_syscall_epilogue(name); 1203 } 1204 #endif 1205 1206 #ifdef TARGET_NR__llseek 1207 static void 1208 print__llseek(const struct syscallname *name, 1209 abi_long arg0, abi_long arg1, abi_long arg2, 1210 abi_long arg3, abi_long arg4, abi_long arg5) 1211 { 1212 const char *whence = "UNKNOWN"; 1213 print_syscall_prologue(name); 1214 print_raw_param("%d", arg0, 0); 1215 print_raw_param("%ld", arg1, 0); 1216 print_raw_param("%ld", arg2, 0); 1217 print_pointer(arg3, 0); 1218 switch(arg4) { 1219 case SEEK_SET: whence = "SEEK_SET"; break; 1220 case SEEK_CUR: whence = "SEEK_CUR"; break; 1221 case SEEK_END: whence = "SEEK_END"; break; 1222 } 1223 gemu_log("%s",whence); 1224 print_syscall_epilogue(name); 1225 } 1226 #endif 1227 1228 #if defined(TARGET_NR_socket) 1229 static void 1230 print_socket(const struct syscallname *name, 1231 abi_long arg0, abi_long arg1, abi_long arg2, 1232 abi_long arg3, abi_long arg4, abi_long arg5) 1233 { 1234 abi_ulong domain = arg0, type = arg1, protocol = arg2; 1235 1236 print_syscall_prologue(name); 1237 print_socket_domain(domain); 1238 gemu_log(","); 1239 print_socket_type(type); 1240 gemu_log(","); 1241 if (domain == AF_PACKET || 1242 (domain == AF_INET && type == TARGET_SOCK_PACKET)) { 1243 protocol = tswap16(protocol); 1244 } 1245 print_socket_protocol(domain, type, protocol); 1246 print_syscall_epilogue(name); 1247 } 1248 1249 #endif 1250 1251 #if defined(TARGET_NR_socketcall) 1252 1253 #define get_user_ualx(x, gaddr, idx) \ 1254 get_user_ual(x, (gaddr) + (idx) * sizeof(abi_long)) 1255 1256 static void do_print_socket(const char *name, abi_long arg1) 1257 { 1258 abi_ulong domain, type, protocol; 1259 1260 get_user_ualx(domain, arg1, 0); 1261 get_user_ualx(type, arg1, 1); 1262 get_user_ualx(protocol, arg1, 2); 1263 gemu_log("%s(", name); 1264 print_socket_domain(domain); 1265 gemu_log(","); 1266 print_socket_type(type); 1267 gemu_log(","); 1268 if (domain == AF_PACKET || 1269 (domain == AF_INET && type == TARGET_SOCK_PACKET)) { 1270 protocol = tswap16(protocol); 1271 } 1272 print_socket_protocol(domain, type, protocol); 1273 gemu_log(")"); 1274 } 1275 1276 static void do_print_sockaddr(const char *name, abi_long arg1) 1277 { 1278 abi_ulong sockfd, addr, addrlen; 1279 1280 get_user_ualx(sockfd, arg1, 0); 1281 get_user_ualx(addr, arg1, 1); 1282 get_user_ualx(addrlen, arg1, 2); 1283 1284 gemu_log("%s(", name); 1285 print_raw_param(TARGET_ABI_FMT_ld, sockfd, 0); 1286 print_sockaddr(addr, addrlen); 1287 gemu_log(")"); 1288 } 1289 1290 static void do_print_listen(const char *name, abi_long arg1) 1291 { 1292 abi_ulong sockfd, backlog; 1293 1294 get_user_ualx(sockfd, arg1, 0); 1295 get_user_ualx(backlog, arg1, 1); 1296 1297 gemu_log("%s(", name); 1298 print_raw_param(TARGET_ABI_FMT_ld, sockfd, 0); 1299 print_raw_param(TARGET_ABI_FMT_ld, backlog, 1); 1300 gemu_log(")"); 1301 } 1302 1303 static void do_print_socketpair(const char *name, abi_long arg1) 1304 { 1305 abi_ulong domain, type, protocol, tab; 1306 1307 get_user_ualx(domain, arg1, 0); 1308 get_user_ualx(type, arg1, 1); 1309 get_user_ualx(protocol, arg1, 2); 1310 get_user_ualx(tab, arg1, 3); 1311 1312 gemu_log("%s(", name); 1313 print_socket_domain(domain); 1314 gemu_log(","); 1315 print_socket_type(type); 1316 gemu_log(","); 1317 print_socket_protocol(domain, type, protocol); 1318 gemu_log(","); 1319 print_raw_param(TARGET_ABI_FMT_lx, tab, 1); 1320 gemu_log(")"); 1321 } 1322 1323 static void do_print_sendrecv(const char *name, abi_long arg1) 1324 { 1325 abi_ulong sockfd, msg, len, flags; 1326 1327 get_user_ualx(sockfd, arg1, 0); 1328 get_user_ualx(msg, arg1, 1); 1329 get_user_ualx(len, arg1, 2); 1330 get_user_ualx(flags, arg1, 3); 1331 1332 gemu_log("%s(", name); 1333 print_raw_param(TARGET_ABI_FMT_ld, sockfd, 0); 1334 print_buf(msg, len, 0); 1335 print_raw_param(TARGET_ABI_FMT_ld, len, 0); 1336 print_flags(msg_flags, flags, 1); 1337 gemu_log(")"); 1338 } 1339 1340 static void do_print_msgaddr(const char *name, abi_long arg1) 1341 { 1342 abi_ulong sockfd, msg, len, flags, addr, addrlen; 1343 1344 get_user_ualx(sockfd, arg1, 0); 1345 get_user_ualx(msg, arg1, 1); 1346 get_user_ualx(len, arg1, 2); 1347 get_user_ualx(flags, arg1, 3); 1348 get_user_ualx(addr, arg1, 4); 1349 get_user_ualx(addrlen, arg1, 5); 1350 1351 gemu_log("%s(", name); 1352 print_raw_param(TARGET_ABI_FMT_ld, sockfd, 0); 1353 print_buf(msg, len, 0); 1354 print_raw_param(TARGET_ABI_FMT_ld, len, 0); 1355 print_flags(msg_flags, flags, 0); 1356 print_sockaddr(addr, addrlen); 1357 gemu_log(")"); 1358 } 1359 1360 static void do_print_shutdown(const char *name, abi_long arg1) 1361 { 1362 abi_ulong sockfd, how; 1363 1364 get_user_ualx(sockfd, arg1, 0); 1365 get_user_ualx(how, arg1, 1); 1366 1367 gemu_log("shutdown("); 1368 print_raw_param(TARGET_ABI_FMT_ld, sockfd, 0); 1369 switch (how) { 1370 case SHUT_RD: 1371 gemu_log("SHUT_RD"); 1372 break; 1373 case SHUT_WR: 1374 gemu_log("SHUT_WR"); 1375 break; 1376 case SHUT_RDWR: 1377 gemu_log("SHUT_RDWR"); 1378 break; 1379 default: 1380 print_raw_param(TARGET_ABI_FMT_ld, how, 1); 1381 break; 1382 } 1383 gemu_log(")"); 1384 } 1385 1386 static void do_print_msg(const char *name, abi_long arg1) 1387 { 1388 abi_ulong sockfd, msg, flags; 1389 1390 get_user_ualx(sockfd, arg1, 0); 1391 get_user_ualx(msg, arg1, 1); 1392 get_user_ualx(flags, arg1, 2); 1393 1394 gemu_log("%s(", name); 1395 print_raw_param(TARGET_ABI_FMT_ld, sockfd, 0); 1396 print_pointer(msg, 0); 1397 print_flags(msg_flags, flags, 1); 1398 gemu_log(")"); 1399 } 1400 1401 static void do_print_sockopt(const char *name, abi_long arg1) 1402 { 1403 abi_ulong sockfd, level, optname, optval, optlen; 1404 1405 get_user_ualx(sockfd, arg1, 0); 1406 get_user_ualx(level, arg1, 1); 1407 get_user_ualx(optname, arg1, 2); 1408 get_user_ualx(optval, arg1, 3); 1409 get_user_ualx(optlen, arg1, 4); 1410 1411 gemu_log("%s(", name); 1412 print_raw_param(TARGET_ABI_FMT_ld, sockfd, 0); 1413 switch (level) { 1414 case SOL_TCP: 1415 gemu_log("SOL_TCP,"); 1416 print_raw_param(TARGET_ABI_FMT_ld, optname, 0); 1417 print_pointer(optval, 0); 1418 break; 1419 case SOL_IP: 1420 gemu_log("SOL_IP,"); 1421 print_raw_param(TARGET_ABI_FMT_ld, optname, 0); 1422 print_pointer(optval, 0); 1423 break; 1424 case SOL_RAW: 1425 gemu_log("SOL_RAW,"); 1426 print_raw_param(TARGET_ABI_FMT_ld, optname, 0); 1427 print_pointer(optval, 0); 1428 break; 1429 case TARGET_SOL_SOCKET: 1430 gemu_log("SOL_SOCKET,"); 1431 switch (optname) { 1432 case TARGET_SO_DEBUG: 1433 gemu_log("SO_DEBUG,"); 1434 print_optint: 1435 print_number(optval, 0); 1436 break; 1437 case TARGET_SO_REUSEADDR: 1438 gemu_log("SO_REUSEADDR,"); 1439 goto print_optint; 1440 case TARGET_SO_TYPE: 1441 gemu_log("SO_TYPE,"); 1442 goto print_optint; 1443 case TARGET_SO_ERROR: 1444 gemu_log("SO_ERROR,"); 1445 goto print_optint; 1446 case TARGET_SO_DONTROUTE: 1447 gemu_log("SO_DONTROUTE,"); 1448 goto print_optint; 1449 case TARGET_SO_BROADCAST: 1450 gemu_log("SO_BROADCAST,"); 1451 goto print_optint; 1452 case TARGET_SO_SNDBUF: 1453 gemu_log("SO_SNDBUF,"); 1454 goto print_optint; 1455 case TARGET_SO_RCVBUF: 1456 gemu_log("SO_RCVBUF,"); 1457 goto print_optint; 1458 case TARGET_SO_KEEPALIVE: 1459 gemu_log("SO_KEEPALIVE,"); 1460 goto print_optint; 1461 case TARGET_SO_OOBINLINE: 1462 gemu_log("SO_OOBINLINE,"); 1463 goto print_optint; 1464 case TARGET_SO_NO_CHECK: 1465 gemu_log("SO_NO_CHECK,"); 1466 goto print_optint; 1467 case TARGET_SO_PRIORITY: 1468 gemu_log("SO_PRIORITY,"); 1469 goto print_optint; 1470 case TARGET_SO_BSDCOMPAT: 1471 gemu_log("SO_BSDCOMPAT,"); 1472 goto print_optint; 1473 case TARGET_SO_PASSCRED: 1474 gemu_log("SO_PASSCRED,"); 1475 goto print_optint; 1476 case TARGET_SO_TIMESTAMP: 1477 gemu_log("SO_TIMESTAMP,"); 1478 goto print_optint; 1479 case TARGET_SO_RCVLOWAT: 1480 gemu_log("SO_RCVLOWAT,"); 1481 goto print_optint; 1482 case TARGET_SO_RCVTIMEO: 1483 gemu_log("SO_RCVTIMEO,"); 1484 print_timeval(optval, 0); 1485 break; 1486 case TARGET_SO_SNDTIMEO: 1487 gemu_log("SO_SNDTIMEO,"); 1488 print_timeval(optval, 0); 1489 break; 1490 case TARGET_SO_ATTACH_FILTER: { 1491 struct target_sock_fprog *fprog; 1492 1493 gemu_log("SO_ATTACH_FILTER,"); 1494 1495 if (lock_user_struct(VERIFY_READ, fprog, optval, 0)) { 1496 struct target_sock_filter *filter; 1497 gemu_log("{"); 1498 if (lock_user_struct(VERIFY_READ, filter, 1499 tswapal(fprog->filter), 0)) { 1500 int i; 1501 for (i = 0; i < tswap16(fprog->len) - 1; i++) { 1502 gemu_log("[%d]{0x%x,%d,%d,0x%x},", 1503 i, tswap16(filter[i].code), 1504 filter[i].jt, filter[i].jf, 1505 tswap32(filter[i].k)); 1506 } 1507 gemu_log("[%d]{0x%x,%d,%d,0x%x}", 1508 i, tswap16(filter[i].code), 1509 filter[i].jt, filter[i].jf, 1510 tswap32(filter[i].k)); 1511 } else { 1512 gemu_log(TARGET_ABI_FMT_lx, tswapal(fprog->filter)); 1513 } 1514 gemu_log(",%d},", tswap16(fprog->len)); 1515 unlock_user(fprog, optval, 0); 1516 } else { 1517 print_pointer(optval, 0); 1518 } 1519 break; 1520 } 1521 default: 1522 print_raw_param(TARGET_ABI_FMT_ld, optname, 0); 1523 print_pointer(optval, 0); 1524 break; 1525 } 1526 break; 1527 default: 1528 print_raw_param(TARGET_ABI_FMT_ld, level, 0); 1529 print_raw_param(TARGET_ABI_FMT_ld, optname, 0); 1530 print_pointer(optval, 0); 1531 break; 1532 } 1533 print_raw_param(TARGET_ABI_FMT_ld, optlen, 1); 1534 gemu_log(")"); 1535 } 1536 1537 #define PRINT_SOCKOP(name, func) \ 1538 [SOCKOP_##name] = { #name, func } 1539 1540 static struct { 1541 const char *name; 1542 void (*print)(const char *, abi_long); 1543 } scall[] = { 1544 PRINT_SOCKOP(socket, do_print_socket), 1545 PRINT_SOCKOP(bind, do_print_sockaddr), 1546 PRINT_SOCKOP(connect, do_print_sockaddr), 1547 PRINT_SOCKOP(listen, do_print_listen), 1548 PRINT_SOCKOP(accept, do_print_sockaddr), 1549 PRINT_SOCKOP(getsockname, do_print_sockaddr), 1550 PRINT_SOCKOP(getpeername, do_print_sockaddr), 1551 PRINT_SOCKOP(socketpair, do_print_socketpair), 1552 PRINT_SOCKOP(send, do_print_sendrecv), 1553 PRINT_SOCKOP(recv, do_print_sendrecv), 1554 PRINT_SOCKOP(sendto, do_print_msgaddr), 1555 PRINT_SOCKOP(recvfrom, do_print_msgaddr), 1556 PRINT_SOCKOP(shutdown, do_print_shutdown), 1557 PRINT_SOCKOP(sendmsg, do_print_msg), 1558 PRINT_SOCKOP(recvmsg, do_print_msg), 1559 PRINT_SOCKOP(setsockopt, do_print_sockopt), 1560 PRINT_SOCKOP(getsockopt, do_print_sockopt), 1561 }; 1562 1563 static void 1564 print_socketcall(const struct syscallname *name, 1565 abi_long arg0, abi_long arg1, abi_long arg2, 1566 abi_long arg3, abi_long arg4, abi_long arg5) 1567 { 1568 if (arg0 >= 0 && arg0 < ARRAY_SIZE(scall) && scall[arg0].print) { 1569 scall[arg0].print(scall[arg0].name, arg1); 1570 return; 1571 } 1572 print_syscall_prologue(name); 1573 print_raw_param(TARGET_ABI_FMT_ld, arg0, 0); 1574 print_raw_param(TARGET_ABI_FMT_ld, arg1, 0); 1575 print_raw_param(TARGET_ABI_FMT_ld, arg2, 0); 1576 print_raw_param(TARGET_ABI_FMT_ld, arg3, 0); 1577 print_raw_param(TARGET_ABI_FMT_ld, arg4, 0); 1578 print_raw_param(TARGET_ABI_FMT_ld, arg5, 0); 1579 print_syscall_epilogue(name); 1580 } 1581 #endif 1582 1583 #if defined(TARGET_NR_stat) || defined(TARGET_NR_stat64) || \ 1584 defined(TARGET_NR_lstat) || defined(TARGET_NR_lstat64) 1585 static void 1586 print_stat(const struct syscallname *name, 1587 abi_long arg0, abi_long arg1, abi_long arg2, 1588 abi_long arg3, abi_long arg4, abi_long arg5) 1589 { 1590 print_syscall_prologue(name); 1591 print_string(arg0, 0); 1592 print_pointer(arg1, 1); 1593 print_syscall_epilogue(name); 1594 } 1595 #define print_lstat print_stat 1596 #define print_stat64 print_stat 1597 #define print_lstat64 print_stat 1598 #endif 1599 1600 #if defined(TARGET_NR_fstat) || defined(TARGET_NR_fstat64) 1601 static void 1602 print_fstat(const struct syscallname *name, 1603 abi_long arg0, abi_long arg1, abi_long arg2, 1604 abi_long arg3, abi_long arg4, abi_long arg5) 1605 { 1606 print_syscall_prologue(name); 1607 print_raw_param("%d", arg0, 0); 1608 print_pointer(arg1, 1); 1609 print_syscall_epilogue(name); 1610 } 1611 #define print_fstat64 print_fstat 1612 #endif 1613 1614 #ifdef TARGET_NR_mkdir 1615 static void 1616 print_mkdir(const struct syscallname *name, 1617 abi_long arg0, abi_long arg1, abi_long arg2, 1618 abi_long arg3, abi_long arg4, abi_long arg5) 1619 { 1620 print_syscall_prologue(name); 1621 print_string(arg0, 0); 1622 print_file_mode(arg1, 1); 1623 print_syscall_epilogue(name); 1624 } 1625 #endif 1626 1627 #ifdef TARGET_NR_mkdirat 1628 static void 1629 print_mkdirat(const struct syscallname *name, 1630 abi_long arg0, abi_long arg1, abi_long arg2, 1631 abi_long arg3, abi_long arg4, abi_long arg5) 1632 { 1633 print_syscall_prologue(name); 1634 print_at_dirfd(arg0, 0); 1635 print_string(arg1, 0); 1636 print_file_mode(arg2, 1); 1637 print_syscall_epilogue(name); 1638 } 1639 #endif 1640 1641 #ifdef TARGET_NR_rmdir 1642 static void 1643 print_rmdir(const struct syscallname *name, 1644 abi_long arg0, abi_long arg1, abi_long arg2, 1645 abi_long arg3, abi_long arg4, abi_long arg5) 1646 { 1647 print_syscall_prologue(name); 1648 print_string(arg0, 0); 1649 print_syscall_epilogue(name); 1650 } 1651 #endif 1652 1653 #ifdef TARGET_NR_rt_sigaction 1654 static void 1655 print_rt_sigaction(const struct syscallname *name, 1656 abi_long arg0, abi_long arg1, abi_long arg2, 1657 abi_long arg3, abi_long arg4, abi_long arg5) 1658 { 1659 print_syscall_prologue(name); 1660 print_signal(arg0, 0); 1661 print_pointer(arg1, 0); 1662 print_pointer(arg2, 1); 1663 print_syscall_epilogue(name); 1664 } 1665 #endif 1666 1667 #ifdef TARGET_NR_rt_sigprocmask 1668 static void 1669 print_rt_sigprocmask(const struct syscallname *name, 1670 abi_long arg0, abi_long arg1, abi_long arg2, 1671 abi_long arg3, abi_long arg4, abi_long arg5) 1672 { 1673 const char *how = "UNKNOWN"; 1674 print_syscall_prologue(name); 1675 switch(arg0) { 1676 case TARGET_SIG_BLOCK: how = "SIG_BLOCK"; break; 1677 case TARGET_SIG_UNBLOCK: how = "SIG_UNBLOCK"; break; 1678 case TARGET_SIG_SETMASK: how = "SIG_SETMASK"; break; 1679 } 1680 gemu_log("%s,",how); 1681 print_pointer(arg1, 0); 1682 print_pointer(arg2, 1); 1683 print_syscall_epilogue(name); 1684 } 1685 #endif 1686 1687 #ifdef TARGET_NR_mknod 1688 static void 1689 print_mknod(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 int hasdev = (arg1 & (S_IFCHR|S_IFBLK)); 1694 1695 print_syscall_prologue(name); 1696 print_string(arg0, 0); 1697 print_file_mode(arg1, (hasdev == 0)); 1698 if (hasdev) { 1699 print_raw_param("makedev(%d", major(arg2), 0); 1700 print_raw_param("%d)", minor(arg2), 1); 1701 } 1702 print_syscall_epilogue(name); 1703 } 1704 #endif 1705 1706 #ifdef TARGET_NR_mknodat 1707 static void 1708 print_mknodat(const struct syscallname *name, 1709 abi_long arg0, abi_long arg1, abi_long arg2, 1710 abi_long arg3, abi_long arg4, abi_long arg5) 1711 { 1712 int hasdev = (arg2 & (S_IFCHR|S_IFBLK)); 1713 1714 print_syscall_prologue(name); 1715 print_at_dirfd(arg0, 0); 1716 print_string(arg1, 0); 1717 print_file_mode(arg2, (hasdev == 0)); 1718 if (hasdev) { 1719 print_raw_param("makedev(%d", major(arg3), 0); 1720 print_raw_param("%d)", minor(arg3), 1); 1721 } 1722 print_syscall_epilogue(name); 1723 } 1724 #endif 1725 1726 #ifdef TARGET_NR_mq_open 1727 static void 1728 print_mq_open(const struct syscallname *name, 1729 abi_long arg0, abi_long arg1, abi_long arg2, 1730 abi_long arg3, abi_long arg4, abi_long arg5) 1731 { 1732 int is_creat = (arg1 & TARGET_O_CREAT); 1733 1734 print_syscall_prologue(name); 1735 print_string(arg0, 0); 1736 print_open_flags(arg1, (is_creat == 0)); 1737 if (is_creat) { 1738 print_file_mode(arg2, 0); 1739 print_pointer(arg3, 1); 1740 } 1741 print_syscall_epilogue(name); 1742 } 1743 #endif 1744 1745 #ifdef TARGET_NR_open 1746 static void 1747 print_open(const struct syscallname *name, 1748 abi_long arg0, abi_long arg1, abi_long arg2, 1749 abi_long arg3, abi_long arg4, abi_long arg5) 1750 { 1751 int is_creat = (arg1 & TARGET_O_CREAT); 1752 1753 print_syscall_prologue(name); 1754 print_string(arg0, 0); 1755 print_open_flags(arg1, (is_creat == 0)); 1756 if (is_creat) 1757 print_file_mode(arg2, 1); 1758 print_syscall_epilogue(name); 1759 } 1760 #endif 1761 1762 #ifdef TARGET_NR_openat 1763 static void 1764 print_openat(const struct syscallname *name, 1765 abi_long arg0, abi_long arg1, abi_long arg2, 1766 abi_long arg3, abi_long arg4, abi_long arg5) 1767 { 1768 int is_creat = (arg2 & TARGET_O_CREAT); 1769 1770 print_syscall_prologue(name); 1771 print_at_dirfd(arg0, 0); 1772 print_string(arg1, 0); 1773 print_open_flags(arg2, (is_creat == 0)); 1774 if (is_creat) 1775 print_file_mode(arg3, 1); 1776 print_syscall_epilogue(name); 1777 } 1778 #endif 1779 1780 #ifdef TARGET_NR_mq_unlink 1781 static void 1782 print_mq_unlink(const struct syscallname *name, 1783 abi_long arg0, abi_long arg1, abi_long arg2, 1784 abi_long arg3, abi_long arg4, abi_long arg5) 1785 { 1786 print_syscall_prologue(name); 1787 print_string(arg0, 1); 1788 print_syscall_epilogue(name); 1789 } 1790 #endif 1791 1792 #if defined(TARGET_NR_fstatat64) || defined(TARGET_NR_newfstatat) 1793 static void 1794 print_fstatat64(const struct syscallname *name, 1795 abi_long arg0, abi_long arg1, abi_long arg2, 1796 abi_long arg3, abi_long arg4, abi_long arg5) 1797 { 1798 print_syscall_prologue(name); 1799 print_at_dirfd(arg0, 0); 1800 print_string(arg1, 0); 1801 print_pointer(arg2, 0); 1802 print_flags(at_file_flags, arg3, 1); 1803 print_syscall_epilogue(name); 1804 } 1805 #define print_newfstatat print_fstatat64 1806 #endif 1807 1808 #ifdef TARGET_NR_readlink 1809 static void 1810 print_readlink(const struct syscallname *name, 1811 abi_long arg0, abi_long arg1, abi_long arg2, 1812 abi_long arg3, abi_long arg4, abi_long arg5) 1813 { 1814 print_syscall_prologue(name); 1815 print_string(arg0, 0); 1816 print_pointer(arg1, 0); 1817 print_raw_param("%u", arg2, 1); 1818 print_syscall_epilogue(name); 1819 } 1820 #endif 1821 1822 #ifdef TARGET_NR_readlinkat 1823 static void 1824 print_readlinkat(const struct syscallname *name, 1825 abi_long arg0, abi_long arg1, abi_long arg2, 1826 abi_long arg3, abi_long arg4, abi_long arg5) 1827 { 1828 print_syscall_prologue(name); 1829 print_at_dirfd(arg0, 0); 1830 print_string(arg1, 0); 1831 print_pointer(arg2, 0); 1832 print_raw_param("%u", arg3, 1); 1833 print_syscall_epilogue(name); 1834 } 1835 #endif 1836 1837 #ifdef TARGET_NR_rename 1838 static void 1839 print_rename(const struct syscallname *name, 1840 abi_long arg0, abi_long arg1, abi_long arg2, 1841 abi_long arg3, abi_long arg4, abi_long arg5) 1842 { 1843 print_syscall_prologue(name); 1844 print_string(arg0, 0); 1845 print_string(arg1, 1); 1846 print_syscall_epilogue(name); 1847 } 1848 #endif 1849 1850 #ifdef TARGET_NR_renameat 1851 static void 1852 print_renameat(const struct syscallname *name, 1853 abi_long arg0, abi_long arg1, abi_long arg2, 1854 abi_long arg3, abi_long arg4, abi_long arg5) 1855 { 1856 print_syscall_prologue(name); 1857 print_at_dirfd(arg0, 0); 1858 print_string(arg1, 0); 1859 print_at_dirfd(arg2, 0); 1860 print_string(arg3, 1); 1861 print_syscall_epilogue(name); 1862 } 1863 #endif 1864 1865 #ifdef TARGET_NR_statfs 1866 static void 1867 print_statfs(const struct syscallname *name, 1868 abi_long arg0, abi_long arg1, abi_long arg2, 1869 abi_long arg3, abi_long arg4, abi_long arg5) 1870 { 1871 print_syscall_prologue(name); 1872 print_string(arg0, 0); 1873 print_pointer(arg1, 1); 1874 print_syscall_epilogue(name); 1875 } 1876 #define print_statfs64 print_statfs 1877 #endif 1878 1879 #ifdef TARGET_NR_symlink 1880 static void 1881 print_symlink(const struct syscallname *name, 1882 abi_long arg0, abi_long arg1, abi_long arg2, 1883 abi_long arg3, abi_long arg4, abi_long arg5) 1884 { 1885 print_syscall_prologue(name); 1886 print_string(arg0, 0); 1887 print_string(arg1, 1); 1888 print_syscall_epilogue(name); 1889 } 1890 #endif 1891 1892 #ifdef TARGET_NR_symlinkat 1893 static void 1894 print_symlinkat(const struct syscallname *name, 1895 abi_long arg0, abi_long arg1, abi_long arg2, 1896 abi_long arg3, abi_long arg4, abi_long arg5) 1897 { 1898 print_syscall_prologue(name); 1899 print_string(arg0, 0); 1900 print_at_dirfd(arg1, 0); 1901 print_string(arg2, 1); 1902 print_syscall_epilogue(name); 1903 } 1904 #endif 1905 1906 #ifdef TARGET_NR_mount 1907 static void 1908 print_mount(const struct syscallname *name, 1909 abi_long arg0, abi_long arg1, abi_long arg2, 1910 abi_long arg3, abi_long arg4, abi_long arg5) 1911 { 1912 print_syscall_prologue(name); 1913 print_string(arg0, 0); 1914 print_string(arg1, 0); 1915 print_string(arg2, 0); 1916 print_flags(mount_flags, arg3, 0); 1917 print_pointer(arg4, 1); 1918 print_syscall_epilogue(name); 1919 } 1920 #endif 1921 1922 #ifdef TARGET_NR_umount 1923 static void 1924 print_umount(const struct syscallname *name, 1925 abi_long arg0, abi_long arg1, abi_long arg2, 1926 abi_long arg3, abi_long arg4, abi_long arg5) 1927 { 1928 print_syscall_prologue(name); 1929 print_string(arg0, 1); 1930 print_syscall_epilogue(name); 1931 } 1932 #endif 1933 1934 #ifdef TARGET_NR_umount2 1935 static void 1936 print_umount2(const struct syscallname *name, 1937 abi_long arg0, abi_long arg1, abi_long arg2, 1938 abi_long arg3, abi_long arg4, abi_long arg5) 1939 { 1940 print_syscall_prologue(name); 1941 print_string(arg0, 0); 1942 print_flags(umount2_flags, arg1, 1); 1943 print_syscall_epilogue(name); 1944 } 1945 #endif 1946 1947 #ifdef TARGET_NR_unlink 1948 static void 1949 print_unlink(const struct syscallname *name, 1950 abi_long arg0, abi_long arg1, abi_long arg2, 1951 abi_long arg3, abi_long arg4, abi_long arg5) 1952 { 1953 print_syscall_prologue(name); 1954 print_string(arg0, 1); 1955 print_syscall_epilogue(name); 1956 } 1957 #endif 1958 1959 #ifdef TARGET_NR_unlinkat 1960 static void 1961 print_unlinkat(const struct syscallname *name, 1962 abi_long arg0, abi_long arg1, abi_long arg2, 1963 abi_long arg3, abi_long arg4, abi_long arg5) 1964 { 1965 print_syscall_prologue(name); 1966 print_at_dirfd(arg0, 0); 1967 print_string(arg1, 0); 1968 print_flags(unlinkat_flags, arg2, 1); 1969 print_syscall_epilogue(name); 1970 } 1971 #endif 1972 1973 #ifdef TARGET_NR_utime 1974 static void 1975 print_utime(const struct syscallname *name, 1976 abi_long arg0, abi_long arg1, abi_long arg2, 1977 abi_long arg3, abi_long arg4, abi_long arg5) 1978 { 1979 print_syscall_prologue(name); 1980 print_string(arg0, 0); 1981 print_pointer(arg1, 1); 1982 print_syscall_epilogue(name); 1983 } 1984 #endif 1985 1986 #ifdef TARGET_NR_utimes 1987 static void 1988 print_utimes(const struct syscallname *name, 1989 abi_long arg0, abi_long arg1, abi_long arg2, 1990 abi_long arg3, abi_long arg4, abi_long arg5) 1991 { 1992 print_syscall_prologue(name); 1993 print_string(arg0, 0); 1994 print_pointer(arg1, 1); 1995 print_syscall_epilogue(name); 1996 } 1997 #endif 1998 1999 #ifdef TARGET_NR_utimensat 2000 static void 2001 print_utimensat(const struct syscallname *name, 2002 abi_long arg0, abi_long arg1, abi_long arg2, 2003 abi_long arg3, abi_long arg4, abi_long arg5) 2004 { 2005 print_syscall_prologue(name); 2006 print_at_dirfd(arg0, 0); 2007 print_string(arg1, 0); 2008 print_pointer(arg2, 0); 2009 print_flags(at_file_flags, arg3, 1); 2010 print_syscall_epilogue(name); 2011 } 2012 #endif 2013 2014 #if defined(TARGET_NR_mmap) || defined(TARGET_NR_mmap2) 2015 static void 2016 print_mmap(const struct syscallname *name, 2017 abi_long arg0, abi_long arg1, abi_long arg2, 2018 abi_long arg3, abi_long arg4, abi_long arg5) 2019 { 2020 print_syscall_prologue(name); 2021 print_pointer(arg0, 0); 2022 print_raw_param("%d", arg1, 0); 2023 print_flags(mmap_prot_flags, arg2, 0); 2024 print_flags(mmap_flags, arg3, 0); 2025 print_raw_param("%d", arg4, 0); 2026 print_raw_param("%#x", arg5, 1); 2027 print_syscall_epilogue(name); 2028 } 2029 #define print_mmap2 print_mmap 2030 #endif 2031 2032 #ifdef TARGET_NR_mprotect 2033 static void 2034 print_mprotect(const struct syscallname *name, 2035 abi_long arg0, abi_long arg1, abi_long arg2, 2036 abi_long arg3, abi_long arg4, abi_long arg5) 2037 { 2038 print_syscall_prologue(name); 2039 print_pointer(arg0, 0); 2040 print_raw_param("%d", arg1, 0); 2041 print_flags(mmap_prot_flags, arg2, 1); 2042 print_syscall_epilogue(name); 2043 } 2044 #endif 2045 2046 #ifdef TARGET_NR_munmap 2047 static void 2048 print_munmap(const struct syscallname *name, 2049 abi_long arg0, abi_long arg1, abi_long arg2, 2050 abi_long arg3, abi_long arg4, abi_long arg5) 2051 { 2052 print_syscall_prologue(name); 2053 print_pointer(arg0, 0); 2054 print_raw_param("%d", arg1, 1); 2055 print_syscall_epilogue(name); 2056 } 2057 #endif 2058 2059 #ifdef TARGET_NR_futex 2060 static void print_futex_op(abi_long tflag, int last) 2061 { 2062 #define print_op(val) \ 2063 if( cmd == val ) { \ 2064 gemu_log(#val); \ 2065 return; \ 2066 } 2067 2068 int cmd = (int)tflag; 2069 #ifdef FUTEX_PRIVATE_FLAG 2070 if (cmd & FUTEX_PRIVATE_FLAG) { 2071 gemu_log("FUTEX_PRIVATE_FLAG|"); 2072 cmd &= ~FUTEX_PRIVATE_FLAG; 2073 } 2074 #endif 2075 #ifdef FUTEX_CLOCK_REALTIME 2076 if (cmd & FUTEX_CLOCK_REALTIME) { 2077 gemu_log("FUTEX_CLOCK_REALTIME|"); 2078 cmd &= ~FUTEX_CLOCK_REALTIME; 2079 } 2080 #endif 2081 print_op(FUTEX_WAIT) 2082 print_op(FUTEX_WAKE) 2083 print_op(FUTEX_FD) 2084 print_op(FUTEX_REQUEUE) 2085 print_op(FUTEX_CMP_REQUEUE) 2086 print_op(FUTEX_WAKE_OP) 2087 print_op(FUTEX_LOCK_PI) 2088 print_op(FUTEX_UNLOCK_PI) 2089 print_op(FUTEX_TRYLOCK_PI) 2090 #ifdef FUTEX_WAIT_BITSET 2091 print_op(FUTEX_WAIT_BITSET) 2092 #endif 2093 #ifdef FUTEX_WAKE_BITSET 2094 print_op(FUTEX_WAKE_BITSET) 2095 #endif 2096 /* unknown values */ 2097 gemu_log("%d",cmd); 2098 } 2099 2100 static void 2101 print_futex(const struct syscallname *name, 2102 abi_long arg0, abi_long arg1, abi_long arg2, 2103 abi_long arg3, abi_long arg4, abi_long arg5) 2104 { 2105 print_syscall_prologue(name); 2106 print_pointer(arg0, 0); 2107 print_futex_op(arg1, 0); 2108 print_raw_param(",%d", arg2, 0); 2109 print_pointer(arg3, 0); /* struct timespec */ 2110 print_pointer(arg4, 0); 2111 print_raw_param("%d", arg4, 1); 2112 print_syscall_epilogue(name); 2113 } 2114 #endif 2115 2116 #ifdef TARGET_NR_kill 2117 static void 2118 print_kill(const struct syscallname *name, 2119 abi_long arg0, abi_long arg1, abi_long arg2, 2120 abi_long arg3, abi_long arg4, abi_long arg5) 2121 { 2122 print_syscall_prologue(name); 2123 print_raw_param("%d", arg0, 0); 2124 print_signal(arg1, 1); 2125 print_syscall_epilogue(name); 2126 } 2127 #endif 2128 2129 /* 2130 * An array of all of the syscalls we know about 2131 */ 2132 2133 static const struct syscallname scnames[] = { 2134 #include "strace.list" 2135 }; 2136 2137 static int nsyscalls = ARRAY_SIZE(scnames); 2138 2139 /* 2140 * The public interface to this module. 2141 */ 2142 void 2143 print_syscall(int num, 2144 abi_long arg1, abi_long arg2, abi_long arg3, 2145 abi_long arg4, abi_long arg5, abi_long arg6) 2146 { 2147 int i; 2148 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 ")"; 2149 2150 gemu_log("%d ", getpid() ); 2151 2152 for(i=0;i<nsyscalls;i++) 2153 if( scnames[i].nr == num ) { 2154 if( scnames[i].call != NULL ) { 2155 scnames[i].call(&scnames[i],arg1,arg2,arg3,arg4,arg5,arg6); 2156 } else { 2157 /* XXX: this format system is broken because it uses 2158 host types and host pointers for strings */ 2159 if( scnames[i].format != NULL ) 2160 format = scnames[i].format; 2161 gemu_log(format,scnames[i].name, arg1,arg2,arg3,arg4,arg5,arg6); 2162 } 2163 return; 2164 } 2165 gemu_log("Unknown syscall %d\n", num); 2166 } 2167 2168 2169 void 2170 print_syscall_ret(int num, abi_long ret) 2171 { 2172 int i; 2173 const char *errstr = NULL; 2174 2175 for(i=0;i<nsyscalls;i++) 2176 if( scnames[i].nr == num ) { 2177 if( scnames[i].result != NULL ) { 2178 scnames[i].result(&scnames[i],ret); 2179 } else { 2180 if (ret < 0) { 2181 errstr = target_strerror(-ret); 2182 } 2183 if (errstr) { 2184 gemu_log(" = -1 errno=" TARGET_ABI_FMT_ld " (%s)\n", 2185 -ret, errstr); 2186 } else { 2187 gemu_log(" = " TARGET_ABI_FMT_ld "\n", ret); 2188 } 2189 } 2190 break; 2191 } 2192 } 2193