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