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