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