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