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