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