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