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