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