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