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