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