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