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