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