OSDN Git Service

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