linux-user: fix the errno value in print_syscall_err()
[qemu/kevin.git] / linux-user / strace.c
blob7769f53bd5ed33332bc117b8db6acd52db3b5a8c
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)(const struct syscallname *,
20 abi_long, abi_long, abi_long,
21 abi_long, abi_long, abi_long);
22 void (*result)(const struct syscallname *, abi_long,
23 abi_long, abi_long, abi_long,
24 abi_long, abi_long, abi_long);
27 #ifdef __GNUC__
29 * It is possible that target doesn't have syscall that uses
30 * following flags but we don't want the compiler to warn
31 * us about them being unused. Same applies to utility print
32 * functions. It is ok to keep them while not used.
34 #define UNUSED __attribute__ ((unused))
35 #else
36 #define UNUSED
37 #endif
40 * Structure used to translate flag values into strings. This is
41 * similar that is in the actual strace tool.
43 struct flags {
44 abi_long f_value; /* flag */
45 const char *f_string; /* stringified flag */
48 /* common flags for all architectures */
49 #define FLAG_GENERIC(name) { name, #name }
50 /* target specific flags (syscall_defs.h has TARGET_<flag>) */
51 #define FLAG_TARGET(name) { TARGET_ ## name, #name }
52 /* end of flags array */
53 #define FLAG_END { 0, NULL }
55 UNUSED static const char *get_comma(int);
56 UNUSED static void print_pointer(abi_long, int);
57 UNUSED static void print_flags(const struct flags *, abi_long, int);
58 UNUSED static void print_at_dirfd(abi_long, int);
59 UNUSED static void print_file_mode(abi_long, int);
60 UNUSED static void print_open_flags(abi_long, int);
61 UNUSED static void print_syscall_prologue(const struct syscallname *);
62 UNUSED static void print_syscall_epilogue(const struct syscallname *);
63 UNUSED static void print_string(abi_long, int);
64 UNUSED static void print_buf(abi_long addr, abi_long len, int last);
65 UNUSED static void print_raw_param(const char *, abi_long, int);
66 UNUSED static void print_timeval(abi_ulong, int);
67 UNUSED static void print_timezone(abi_ulong, int);
68 UNUSED static void print_number(abi_long, int);
69 UNUSED static void print_signal(abi_ulong, int);
70 UNUSED static void print_sockaddr(abi_ulong, abi_long, int);
71 UNUSED static void print_socket_domain(int domain);
72 UNUSED static void print_socket_type(int type);
73 UNUSED static void print_socket_protocol(int domain, int type, int protocol);
76 * Utility functions
78 static void
79 print_ipc_cmd(int cmd)
81 #define output_cmd(val) \
82 if( cmd == val ) { \
83 qemu_log(#val); \
84 return; \
87 cmd &= 0xff;
89 /* General IPC commands */
90 output_cmd( IPC_RMID );
91 output_cmd( IPC_SET );
92 output_cmd( IPC_STAT );
93 output_cmd( IPC_INFO );
94 /* msgctl() commands */
95 output_cmd( MSG_STAT );
96 output_cmd( MSG_INFO );
97 /* shmctl() commands */
98 output_cmd( SHM_LOCK );
99 output_cmd( SHM_UNLOCK );
100 output_cmd( SHM_STAT );
101 output_cmd( SHM_INFO );
102 /* semctl() commands */
103 output_cmd( GETPID );
104 output_cmd( GETVAL );
105 output_cmd( GETALL );
106 output_cmd( GETNCNT );
107 output_cmd( GETZCNT );
108 output_cmd( SETVAL );
109 output_cmd( SETALL );
110 output_cmd( SEM_STAT );
111 output_cmd( SEM_INFO );
112 output_cmd( IPC_RMID );
113 output_cmd( IPC_RMID );
114 output_cmd( IPC_RMID );
115 output_cmd( IPC_RMID );
116 output_cmd( IPC_RMID );
117 output_cmd( IPC_RMID );
118 output_cmd( IPC_RMID );
119 output_cmd( IPC_RMID );
120 output_cmd( IPC_RMID );
122 /* Some value we don't recognize */
123 qemu_log("%d", cmd);
126 static void
127 print_signal(abi_ulong arg, int last)
129 const char *signal_name = NULL;
130 switch(arg) {
131 case TARGET_SIGHUP: signal_name = "SIGHUP"; break;
132 case TARGET_SIGINT: signal_name = "SIGINT"; break;
133 case TARGET_SIGQUIT: signal_name = "SIGQUIT"; break;
134 case TARGET_SIGILL: signal_name = "SIGILL"; break;
135 case TARGET_SIGABRT: signal_name = "SIGABRT"; break;
136 case TARGET_SIGFPE: signal_name = "SIGFPE"; break;
137 case TARGET_SIGKILL: signal_name = "SIGKILL"; break;
138 case TARGET_SIGSEGV: signal_name = "SIGSEGV"; break;
139 case TARGET_SIGPIPE: signal_name = "SIGPIPE"; break;
140 case TARGET_SIGALRM: signal_name = "SIGALRM"; break;
141 case TARGET_SIGTERM: signal_name = "SIGTERM"; break;
142 case TARGET_SIGUSR1: signal_name = "SIGUSR1"; break;
143 case TARGET_SIGUSR2: signal_name = "SIGUSR2"; break;
144 case TARGET_SIGCHLD: signal_name = "SIGCHLD"; break;
145 case TARGET_SIGCONT: signal_name = "SIGCONT"; break;
146 case TARGET_SIGSTOP: signal_name = "SIGSTOP"; break;
147 case TARGET_SIGTTIN: signal_name = "SIGTTIN"; break;
148 case TARGET_SIGTTOU: signal_name = "SIGTTOU"; break;
150 if (signal_name == NULL) {
151 print_raw_param("%ld", arg, last);
152 return;
154 qemu_log("%s%s", signal_name, get_comma(last));
157 static void print_si_code(int arg)
159 const char *codename = NULL;
161 switch (arg) {
162 case SI_USER:
163 codename = "SI_USER";
164 break;
165 case SI_KERNEL:
166 codename = "SI_KERNEL";
167 break;
168 case SI_QUEUE:
169 codename = "SI_QUEUE";
170 break;
171 case SI_TIMER:
172 codename = "SI_TIMER";
173 break;
174 case SI_MESGQ:
175 codename = "SI_MESGQ";
176 break;
177 case SI_ASYNCIO:
178 codename = "SI_ASYNCIO";
179 break;
180 case SI_SIGIO:
181 codename = "SI_SIGIO";
182 break;
183 case SI_TKILL:
184 codename = "SI_TKILL";
185 break;
186 default:
187 qemu_log("%d", arg);
188 return;
190 qemu_log("%s", codename);
193 static void get_target_siginfo(target_siginfo_t *tinfo,
194 const target_siginfo_t *info)
196 abi_ulong sival_ptr;
198 int sig;
199 int si_errno;
200 int si_code;
201 int si_type;
203 __get_user(sig, &info->si_signo);
204 __get_user(si_errno, &tinfo->si_errno);
205 __get_user(si_code, &info->si_code);
207 tinfo->si_signo = sig;
208 tinfo->si_errno = si_errno;
209 tinfo->si_code = si_code;
211 /* Ensure we don't leak random junk to the guest later */
212 memset(tinfo->_sifields._pad, 0, sizeof(tinfo->_sifields._pad));
214 /* This is awkward, because we have to use a combination of
215 * the si_code and si_signo to figure out which of the union's
216 * members are valid. (Within the host kernel it is always possible
217 * to tell, but the kernel carefully avoids giving userspace the
218 * high 16 bits of si_code, so we don't have the information to
219 * do this the easy way...) We therefore make our best guess,
220 * bearing in mind that a guest can spoof most of the si_codes
221 * via rt_sigqueueinfo() if it likes.
223 * Once we have made our guess, we record it in the top 16 bits of
224 * the si_code, so that print_siginfo() later can use it.
225 * print_siginfo() will strip these top bits out before printing
226 * the si_code.
229 switch (si_code) {
230 case SI_USER:
231 case SI_TKILL:
232 case SI_KERNEL:
233 /* Sent via kill(), tkill() or tgkill(), or direct from the kernel.
234 * These are the only unspoofable si_code values.
236 __get_user(tinfo->_sifields._kill._pid, &info->_sifields._kill._pid);
237 __get_user(tinfo->_sifields._kill._uid, &info->_sifields._kill._uid);
238 si_type = QEMU_SI_KILL;
239 break;
240 default:
241 /* Everything else is spoofable. Make best guess based on signal */
242 switch (sig) {
243 case TARGET_SIGCHLD:
244 __get_user(tinfo->_sifields._sigchld._pid,
245 &info->_sifields._sigchld._pid);
246 __get_user(tinfo->_sifields._sigchld._uid,
247 &info->_sifields._sigchld._uid);
248 __get_user(tinfo->_sifields._sigchld._status,
249 &info->_sifields._sigchld._status);
250 __get_user(tinfo->_sifields._sigchld._utime,
251 &info->_sifields._sigchld._utime);
252 __get_user(tinfo->_sifields._sigchld._stime,
253 &info->_sifields._sigchld._stime);
254 si_type = QEMU_SI_CHLD;
255 break;
256 case TARGET_SIGIO:
257 __get_user(tinfo->_sifields._sigpoll._band,
258 &info->_sifields._sigpoll._band);
259 __get_user(tinfo->_sifields._sigpoll._fd,
260 &info->_sifields._sigpoll._fd);
261 si_type = QEMU_SI_POLL;
262 break;
263 default:
264 /* Assume a sigqueue()/mq_notify()/rt_sigqueueinfo() source. */
265 __get_user(tinfo->_sifields._rt._pid, &info->_sifields._rt._pid);
266 __get_user(tinfo->_sifields._rt._uid, &info->_sifields._rt._uid);
267 /* XXX: potential problem if 64 bit */
268 __get_user(sival_ptr, &info->_sifields._rt._sigval.sival_ptr);
269 tinfo->_sifields._rt._sigval.sival_ptr = sival_ptr;
271 si_type = QEMU_SI_RT;
272 break;
274 break;
277 tinfo->si_code = deposit32(si_code, 16, 16, si_type);
280 static void print_siginfo(const target_siginfo_t *tinfo)
282 /* Print a target_siginfo_t in the format desired for printing
283 * signals being taken. We assume the target_siginfo_t is in the
284 * internal form where the top 16 bits of si_code indicate which
285 * part of the union is valid, rather than in the guest-visible
286 * form where the bottom 16 bits are sign-extended into the top 16.
288 int si_type = extract32(tinfo->si_code, 16, 16);
289 int si_code = sextract32(tinfo->si_code, 0, 16);
291 qemu_log("{si_signo=");
292 print_signal(tinfo->si_signo, 1);
293 qemu_log(", si_code=");
294 print_si_code(si_code);
296 switch (si_type) {
297 case QEMU_SI_KILL:
298 qemu_log(", si_pid=%u, si_uid=%u",
299 (unsigned int)tinfo->_sifields._kill._pid,
300 (unsigned int)tinfo->_sifields._kill._uid);
301 break;
302 case QEMU_SI_TIMER:
303 qemu_log(", si_timer1=%u, si_timer2=%u",
304 tinfo->_sifields._timer._timer1,
305 tinfo->_sifields._timer._timer2);
306 break;
307 case QEMU_SI_POLL:
308 qemu_log(", si_band=%d, si_fd=%d",
309 tinfo->_sifields._sigpoll._band,
310 tinfo->_sifields._sigpoll._fd);
311 break;
312 case QEMU_SI_FAULT:
313 qemu_log(", si_addr=");
314 print_pointer(tinfo->_sifields._sigfault._addr, 1);
315 break;
316 case QEMU_SI_CHLD:
317 qemu_log(", si_pid=%u, si_uid=%u, si_status=%d"
318 ", si_utime=" TARGET_ABI_FMT_ld
319 ", si_stime=" TARGET_ABI_FMT_ld,
320 (unsigned int)(tinfo->_sifields._sigchld._pid),
321 (unsigned int)(tinfo->_sifields._sigchld._uid),
322 tinfo->_sifields._sigchld._status,
323 tinfo->_sifields._sigchld._utime,
324 tinfo->_sifields._sigchld._stime);
325 break;
326 case QEMU_SI_RT:
327 qemu_log(", si_pid=%u, si_uid=%u, si_sigval=" TARGET_ABI_FMT_ld,
328 (unsigned int)tinfo->_sifields._rt._pid,
329 (unsigned int)tinfo->_sifields._rt._uid,
330 tinfo->_sifields._rt._sigval.sival_ptr);
331 break;
332 default:
333 g_assert_not_reached();
335 qemu_log("}");
338 static void
339 print_sockaddr(abi_ulong addr, abi_long addrlen, int last)
341 struct target_sockaddr *sa;
342 int i;
343 int sa_family;
345 sa = lock_user(VERIFY_READ, addr, addrlen, 1);
346 if (sa) {
347 sa_family = tswap16(sa->sa_family);
348 switch (sa_family) {
349 case AF_UNIX: {
350 struct target_sockaddr_un *un = (struct target_sockaddr_un *)sa;
351 int i;
352 qemu_log("{sun_family=AF_UNIX,sun_path=\"");
353 for (i = 0; i < addrlen -
354 offsetof(struct target_sockaddr_un, sun_path) &&
355 un->sun_path[i]; i++) {
356 qemu_log("%c", un->sun_path[i]);
358 qemu_log("\"}");
359 break;
361 case AF_INET: {
362 struct target_sockaddr_in *in = (struct target_sockaddr_in *)sa;
363 uint8_t *c = (uint8_t *)&in->sin_addr.s_addr;
364 qemu_log("{sin_family=AF_INET,sin_port=htons(%d),",
365 ntohs(in->sin_port));
366 qemu_log("sin_addr=inet_addr(\"%d.%d.%d.%d\")",
367 c[0], c[1], c[2], c[3]);
368 qemu_log("}");
369 break;
371 case AF_PACKET: {
372 struct target_sockaddr_ll *ll = (struct target_sockaddr_ll *)sa;
373 uint8_t *c = (uint8_t *)&ll->sll_addr;
374 qemu_log("{sll_family=AF_PACKET,"
375 "sll_protocol=htons(0x%04x),if%d,pkttype=",
376 ntohs(ll->sll_protocol), ll->sll_ifindex);
377 switch (ll->sll_pkttype) {
378 case PACKET_HOST:
379 qemu_log("PACKET_HOST");
380 break;
381 case PACKET_BROADCAST:
382 qemu_log("PACKET_BROADCAST");
383 break;
384 case PACKET_MULTICAST:
385 qemu_log("PACKET_MULTICAST");
386 break;
387 case PACKET_OTHERHOST:
388 qemu_log("PACKET_OTHERHOST");
389 break;
390 case PACKET_OUTGOING:
391 qemu_log("PACKET_OUTGOING");
392 break;
393 default:
394 qemu_log("%d", ll->sll_pkttype);
395 break;
397 qemu_log(",sll_addr=%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x",
398 c[0], c[1], c[2], c[3], c[4], c[5], c[6], c[7]);
399 qemu_log("}");
400 break;
402 case AF_NETLINK: {
403 struct target_sockaddr_nl *nl = (struct target_sockaddr_nl *)sa;
404 qemu_log("{nl_family=AF_NETLINK,nl_pid=%u,nl_groups=%u}",
405 tswap32(nl->nl_pid), tswap32(nl->nl_groups));
406 break;
408 default:
409 qemu_log("{sa_family=%d, sa_data={", sa->sa_family);
410 for (i = 0; i < 13; i++) {
411 qemu_log("%02x, ", sa->sa_data[i]);
413 qemu_log("%02x}", sa->sa_data[i]);
414 qemu_log("}");
415 break;
417 unlock_user(sa, addr, 0);
418 } else {
419 print_raw_param("0x"TARGET_ABI_FMT_lx, addr, 0);
421 qemu_log(", "TARGET_ABI_FMT_ld"%s", addrlen, get_comma(last));
424 static void
425 print_socket_domain(int domain)
427 switch (domain) {
428 case PF_UNIX:
429 qemu_log("PF_UNIX");
430 break;
431 case PF_INET:
432 qemu_log("PF_INET");
433 break;
434 case PF_NETLINK:
435 qemu_log("PF_NETLINK");
436 break;
437 case PF_PACKET:
438 qemu_log("PF_PACKET");
439 break;
440 default:
441 qemu_log("%d", domain);
442 break;
446 static void
447 print_socket_type(int type)
449 switch (type & TARGET_SOCK_TYPE_MASK) {
450 case TARGET_SOCK_DGRAM:
451 qemu_log("SOCK_DGRAM");
452 break;
453 case TARGET_SOCK_STREAM:
454 qemu_log("SOCK_STREAM");
455 break;
456 case TARGET_SOCK_RAW:
457 qemu_log("SOCK_RAW");
458 break;
459 case TARGET_SOCK_RDM:
460 qemu_log("SOCK_RDM");
461 break;
462 case TARGET_SOCK_SEQPACKET:
463 qemu_log("SOCK_SEQPACKET");
464 break;
465 case TARGET_SOCK_PACKET:
466 qemu_log("SOCK_PACKET");
467 break;
469 if (type & TARGET_SOCK_CLOEXEC) {
470 qemu_log("|SOCK_CLOEXEC");
472 if (type & TARGET_SOCK_NONBLOCK) {
473 qemu_log("|SOCK_NONBLOCK");
477 static void
478 print_socket_protocol(int domain, int type, int protocol)
480 if (domain == AF_PACKET ||
481 (domain == AF_INET && type == TARGET_SOCK_PACKET)) {
482 switch (protocol) {
483 case 0x0003:
484 qemu_log("ETH_P_ALL");
485 break;
486 default:
487 qemu_log("%d", protocol);
489 return;
492 if (domain == PF_NETLINK) {
493 switch (protocol) {
494 case NETLINK_ROUTE:
495 qemu_log("NETLINK_ROUTE");
496 break;
497 case NETLINK_AUDIT:
498 qemu_log("NETLINK_AUDIT");
499 break;
500 case NETLINK_NETFILTER:
501 qemu_log("NETLINK_NETFILTER");
502 break;
503 case NETLINK_KOBJECT_UEVENT:
504 qemu_log("NETLINK_KOBJECT_UEVENT");
505 break;
506 case NETLINK_RDMA:
507 qemu_log("NETLINK_RDMA");
508 break;
509 case NETLINK_CRYPTO:
510 qemu_log("NETLINK_CRYPTO");
511 break;
512 default:
513 qemu_log("%d", protocol);
514 break;
516 return;
519 switch (protocol) {
520 case IPPROTO_IP:
521 qemu_log("IPPROTO_IP");
522 break;
523 case IPPROTO_TCP:
524 qemu_log("IPPROTO_TCP");
525 break;
526 case IPPROTO_UDP:
527 qemu_log("IPPROTO_UDP");
528 break;
529 case IPPROTO_RAW:
530 qemu_log("IPPROTO_RAW");
531 break;
532 default:
533 qemu_log("%d", protocol);
534 break;
539 #ifdef TARGET_NR__newselect
540 static void
541 print_fdset(int n, abi_ulong target_fds_addr)
543 int i;
545 qemu_log("[");
546 if( target_fds_addr ) {
547 abi_long *target_fds;
549 target_fds = lock_user(VERIFY_READ,
550 target_fds_addr,
551 sizeof(*target_fds)*(n / TARGET_ABI_BITS + 1),
554 if (!target_fds)
555 return;
557 for (i=n; i>=0; i--) {
558 if ((tswapal(target_fds[i / TARGET_ABI_BITS]) >> (i & (TARGET_ABI_BITS - 1))) & 1)
559 qemu_log("%d,", i);
561 unlock_user(target_fds, target_fds_addr, 0);
563 qemu_log("]");
565 #endif
567 #ifdef TARGET_NR_clock_adjtime
568 /* IDs of the various system clocks */
569 #define TARGET_CLOCK_REALTIME 0
570 #define TARGET_CLOCK_MONOTONIC 1
571 #define TARGET_CLOCK_PROCESS_CPUTIME_ID 2
572 #define TARGET_CLOCK_THREAD_CPUTIME_ID 3
573 #define TARGET_CLOCK_MONOTONIC_RAW 4
574 #define TARGET_CLOCK_REALTIME_COARSE 5
575 #define TARGET_CLOCK_MONOTONIC_COARSE 6
576 #define TARGET_CLOCK_BOOTTIME 7
577 #define TARGET_CLOCK_REALTIME_ALARM 8
578 #define TARGET_CLOCK_BOOTTIME_ALARM 9
579 #define TARGET_CLOCK_SGI_CYCLE 10
580 #define TARGET_CLOCK_TAI 11
582 static void
583 print_clockid(int clockid, int last)
585 switch (clockid) {
586 case TARGET_CLOCK_REALTIME:
587 qemu_log("CLOCK_REALTIME");
588 break;
589 case TARGET_CLOCK_MONOTONIC:
590 qemu_log("CLOCK_MONOTONIC");
591 break;
592 case TARGET_CLOCK_PROCESS_CPUTIME_ID:
593 qemu_log("CLOCK_PROCESS_CPUTIME_ID");
594 break;
595 case TARGET_CLOCK_THREAD_CPUTIME_ID:
596 qemu_log("CLOCK_THREAD_CPUTIME_ID");
597 break;
598 case TARGET_CLOCK_MONOTONIC_RAW:
599 qemu_log("CLOCK_MONOTONIC_RAW");
600 break;
601 case TARGET_CLOCK_REALTIME_COARSE:
602 qemu_log("CLOCK_REALTIME_COARSE");
603 break;
604 case TARGET_CLOCK_MONOTONIC_COARSE:
605 qemu_log("CLOCK_MONOTONIC_COARSE");
606 break;
607 case TARGET_CLOCK_BOOTTIME:
608 qemu_log("CLOCK_BOOTTIME");
609 break;
610 case TARGET_CLOCK_REALTIME_ALARM:
611 qemu_log("CLOCK_REALTIME_ALARM");
612 break;
613 case TARGET_CLOCK_BOOTTIME_ALARM:
614 qemu_log("CLOCK_BOOTTIME_ALARM");
615 break;
616 case TARGET_CLOCK_SGI_CYCLE:
617 qemu_log("CLOCK_SGI_CYCLE");
618 break;
619 case TARGET_CLOCK_TAI:
620 qemu_log("CLOCK_TAI");
621 break;
622 default:
623 qemu_log("%d", clockid);
624 break;
626 qemu_log("%s", get_comma(last));
628 #endif
631 * Sysycall specific output functions
634 /* select */
635 #ifdef TARGET_NR__newselect
636 static void
637 print_newselect(const struct syscallname *name,
638 abi_long arg1, abi_long arg2, abi_long arg3,
639 abi_long arg4, abi_long arg5, abi_long arg6)
641 print_syscall_prologue(name);
642 print_fdset(arg1, arg2);
643 qemu_log(",");
644 print_fdset(arg1, arg3);
645 qemu_log(",");
646 print_fdset(arg1, arg4);
647 qemu_log(",");
648 print_timeval(arg5, 1);
649 print_syscall_epilogue(name);
651 #endif
653 #ifdef TARGET_NR_semctl
654 static void
655 print_semctl(const struct syscallname *name,
656 abi_long arg1, abi_long arg2, abi_long arg3,
657 abi_long arg4, abi_long arg5, abi_long arg6)
659 qemu_log("%s(" TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld ",",
660 name->name, arg1, arg2);
661 print_ipc_cmd(arg3);
662 qemu_log(",0x" TARGET_ABI_FMT_lx ")", arg4);
664 #endif
666 static void
667 print_execve(const struct syscallname *name,
668 abi_long arg1, abi_long arg2, abi_long arg3,
669 abi_long arg4, abi_long arg5, abi_long arg6)
671 abi_ulong arg_ptr_addr;
672 char *s;
674 if (!(s = lock_user_string(arg1)))
675 return;
676 qemu_log("%s(\"%s\",{", name->name, s);
677 unlock_user(s, arg1, 0);
679 for (arg_ptr_addr = arg2; ; arg_ptr_addr += sizeof(abi_ulong)) {
680 abi_ulong *arg_ptr, arg_addr;
682 arg_ptr = lock_user(VERIFY_READ, arg_ptr_addr, sizeof(abi_ulong), 1);
683 if (!arg_ptr)
684 return;
685 arg_addr = tswapal(*arg_ptr);
686 unlock_user(arg_ptr, arg_ptr_addr, 0);
687 if (!arg_addr)
688 break;
689 if ((s = lock_user_string(arg_addr))) {
690 qemu_log("\"%s\",", s);
691 unlock_user(s, arg_addr, 0);
695 qemu_log("NULL})");
698 #ifdef TARGET_NR_ipc
699 static void
700 print_ipc(const struct syscallname *name,
701 abi_long arg1, abi_long arg2, abi_long arg3,
702 abi_long arg4, abi_long arg5, abi_long arg6)
704 switch(arg1) {
705 case IPCOP_semctl:
706 qemu_log("semctl(" TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld ",",
707 arg1, arg2);
708 print_ipc_cmd(arg3);
709 qemu_log(",0x" TARGET_ABI_FMT_lx ")", arg4);
710 break;
711 default:
712 qemu_log(("%s("
713 TARGET_ABI_FMT_ld ","
714 TARGET_ABI_FMT_ld ","
715 TARGET_ABI_FMT_ld ","
716 TARGET_ABI_FMT_ld
717 ")"),
718 name->name, arg1, arg2, arg3, arg4);
721 #endif
724 * Variants for the return value output function
727 static void
728 print_syscall_err(abi_long ret)
730 const char *errstr = NULL;
732 qemu_log(" = ");
733 if (ret < 0) {
734 qemu_log("-1 errno=%d", (int)-ret);
735 errstr = target_strerror(-ret);
736 if (errstr) {
737 qemu_log(" (%s)", errstr);
742 static void
743 print_syscall_ret_addr(const struct syscallname *name, abi_long ret,
744 abi_long arg0, abi_long arg1, abi_long arg2,
745 abi_long arg3, abi_long arg4, abi_long arg5)
747 print_syscall_err(ret);
749 if (ret >= 0) {
750 qemu_log("0x" TARGET_ABI_FMT_lx "\n", ret);
754 #if 0 /* currently unused */
755 static void
756 print_syscall_ret_raw(struct syscallname *name, abi_long ret)
758 qemu_log(" = 0x" TARGET_ABI_FMT_lx "\n", ret);
760 #endif
762 #ifdef TARGET_NR__newselect
763 static void
764 print_syscall_ret_newselect(const struct syscallname *name, abi_long ret,
765 abi_long arg0, abi_long arg1, abi_long arg2,
766 abi_long arg3, abi_long arg4, abi_long arg5)
768 print_syscall_err(ret);
770 if (ret >= 0) {
771 qemu_log(" = 0x" TARGET_ABI_FMT_lx " (", ret);
772 print_fdset(arg0, arg1);
773 qemu_log(",");
774 print_fdset(arg0, arg2);
775 qemu_log(",");
776 print_fdset(arg0, arg3);
777 qemu_log(",");
778 print_timeval(arg4, 1);
779 qemu_log(")");
782 qemu_log("\n");
784 #endif
786 /* special meanings of adjtimex()' non-negative return values */
787 #define TARGET_TIME_OK 0 /* clock synchronized, no leap second */
788 #define TARGET_TIME_INS 1 /* insert leap second */
789 #define TARGET_TIME_DEL 2 /* delete leap second */
790 #define TARGET_TIME_OOP 3 /* leap second in progress */
791 #define TARGET_TIME_WAIT 4 /* leap second has occurred */
792 #define TARGET_TIME_ERROR 5 /* clock not synchronized */
793 #ifdef TARGET_NR_adjtimex
794 static void
795 print_syscall_ret_adjtimex(const struct syscallname *name, abi_long ret,
796 abi_long arg0, abi_long arg1, abi_long arg2,
797 abi_long arg3, abi_long arg4, abi_long arg5)
799 print_syscall_err(ret);
801 if (ret >= 0) {
802 qemu_log(TARGET_ABI_FMT_ld, ret);
803 switch (ret) {
804 case TARGET_TIME_OK:
805 qemu_log(" TIME_OK (clock synchronized, no leap second)");
806 break;
807 case TARGET_TIME_INS:
808 qemu_log(" TIME_INS (insert leap second)");
809 break;
810 case TARGET_TIME_DEL:
811 qemu_log(" TIME_DEL (delete leap second)");
812 break;
813 case TARGET_TIME_OOP:
814 qemu_log(" TIME_OOP (leap second in progress)");
815 break;
816 case TARGET_TIME_WAIT:
817 qemu_log(" TIME_WAIT (leap second has occurred)");
818 break;
819 case TARGET_TIME_ERROR:
820 qemu_log(" TIME_ERROR (clock not synchronized)");
821 break;
825 qemu_log("\n");
827 #endif
829 #if defined(TARGET_NR_listxattr) || defined(TARGET_NR_llistxattr) \
830 || defined(TARGGET_NR_flistxattr)
831 static void
832 print_syscall_ret_listxattr(const struct syscallname *name, abi_long ret,
833 abi_long arg0, abi_long arg1, abi_long arg2,
834 abi_long arg3, abi_long arg4, abi_long arg5)
836 print_syscall_err(ret);
838 if (ret >= 0) {
839 qemu_log(TARGET_ABI_FMT_ld, ret);
840 qemu_log(" (list = ");
841 if (arg1 != 0) {
842 abi_long attr = arg1;
843 while (ret) {
844 if (attr != arg1) {
845 qemu_log(",");
847 print_string(attr, 1);
848 ret -= target_strlen(attr) + 1;
849 attr += target_strlen(attr) + 1;
851 } else {
852 qemu_log("NULL");
854 qemu_log(")");
857 qemu_log("\n");
859 #define print_syscall_ret_llistxattr print_syscall_ret_listxattr
860 #define print_syscall_ret_flistxattr print_syscall_ret_listxattr
861 #endif
863 #ifdef TARGET_NR_ioctl
864 static void
865 print_syscall_ret_ioctl(const struct syscallname *name, abi_long ret,
866 abi_long arg0, abi_long arg1, abi_long arg2,
867 abi_long arg3, abi_long arg4, abi_long arg5)
869 print_syscall_err(ret);
871 if (ret >= 0) {
872 qemu_log(TARGET_ABI_FMT_ld, ret);
874 const IOCTLEntry *ie;
875 const argtype *arg_type;
876 void *argptr;
877 int target_size;
879 for (ie = ioctl_entries; ie->target_cmd != 0; ie++) {
880 if (ie->target_cmd == arg1) {
881 break;
885 if (ie->target_cmd == arg1 &&
886 (ie->access == IOC_R || ie->access == IOC_RW)) {
887 arg_type = ie->arg_type;
888 qemu_log(" (");
889 arg_type++;
890 target_size = thunk_type_size(arg_type, 0);
891 argptr = lock_user(VERIFY_READ, arg2, target_size, 1);
892 if (argptr) {
893 thunk_print(argptr, arg_type);
894 unlock_user(argptr, arg2, target_size);
895 } else {
896 print_pointer(arg2, 1);
898 qemu_log(")");
901 qemu_log("\n");
903 #endif
905 UNUSED static struct flags access_flags[] = {
906 FLAG_GENERIC(F_OK),
907 FLAG_GENERIC(R_OK),
908 FLAG_GENERIC(W_OK),
909 FLAG_GENERIC(X_OK),
910 FLAG_END,
913 UNUSED static struct flags at_file_flags[] = {
914 #ifdef AT_EACCESS
915 FLAG_GENERIC(AT_EACCESS),
916 #endif
917 #ifdef AT_SYMLINK_NOFOLLOW
918 FLAG_GENERIC(AT_SYMLINK_NOFOLLOW),
919 #endif
920 FLAG_END,
923 UNUSED static struct flags unlinkat_flags[] = {
924 #ifdef AT_REMOVEDIR
925 FLAG_GENERIC(AT_REMOVEDIR),
926 #endif
927 FLAG_END,
930 UNUSED static struct flags mode_flags[] = {
931 FLAG_GENERIC(S_IFSOCK),
932 FLAG_GENERIC(S_IFLNK),
933 FLAG_GENERIC(S_IFREG),
934 FLAG_GENERIC(S_IFBLK),
935 FLAG_GENERIC(S_IFDIR),
936 FLAG_GENERIC(S_IFCHR),
937 FLAG_GENERIC(S_IFIFO),
938 FLAG_END,
941 UNUSED static struct flags open_access_flags[] = {
942 FLAG_TARGET(O_RDONLY),
943 FLAG_TARGET(O_WRONLY),
944 FLAG_TARGET(O_RDWR),
945 FLAG_END,
948 UNUSED static struct flags open_flags[] = {
949 FLAG_TARGET(O_APPEND),
950 FLAG_TARGET(O_CREAT),
951 FLAG_TARGET(O_DIRECTORY),
952 FLAG_TARGET(O_EXCL),
953 FLAG_TARGET(O_LARGEFILE),
954 FLAG_TARGET(O_NOCTTY),
955 FLAG_TARGET(O_NOFOLLOW),
956 FLAG_TARGET(O_NONBLOCK), /* also O_NDELAY */
957 FLAG_TARGET(O_DSYNC),
958 FLAG_TARGET(__O_SYNC),
959 FLAG_TARGET(O_TRUNC),
960 #ifdef O_DIRECT
961 FLAG_TARGET(O_DIRECT),
962 #endif
963 #ifdef O_NOATIME
964 FLAG_TARGET(O_NOATIME),
965 #endif
966 #ifdef O_CLOEXEC
967 FLAG_TARGET(O_CLOEXEC),
968 #endif
969 #ifdef O_PATH
970 FLAG_TARGET(O_PATH),
971 #endif
972 #ifdef O_TMPFILE
973 FLAG_TARGET(O_TMPFILE),
974 FLAG_TARGET(__O_TMPFILE),
975 #endif
976 FLAG_END,
979 UNUSED static struct flags mount_flags[] = {
980 #ifdef MS_BIND
981 FLAG_GENERIC(MS_BIND),
982 #endif
983 #ifdef MS_DIRSYNC
984 FLAG_GENERIC(MS_DIRSYNC),
985 #endif
986 FLAG_GENERIC(MS_MANDLOCK),
987 #ifdef MS_MOVE
988 FLAG_GENERIC(MS_MOVE),
989 #endif
990 FLAG_GENERIC(MS_NOATIME),
991 FLAG_GENERIC(MS_NODEV),
992 FLAG_GENERIC(MS_NODIRATIME),
993 FLAG_GENERIC(MS_NOEXEC),
994 FLAG_GENERIC(MS_NOSUID),
995 FLAG_GENERIC(MS_RDONLY),
996 #ifdef MS_RELATIME
997 FLAG_GENERIC(MS_RELATIME),
998 #endif
999 FLAG_GENERIC(MS_REMOUNT),
1000 FLAG_GENERIC(MS_SYNCHRONOUS),
1001 FLAG_END,
1004 UNUSED static struct flags umount2_flags[] = {
1005 #ifdef MNT_FORCE
1006 FLAG_GENERIC(MNT_FORCE),
1007 #endif
1008 #ifdef MNT_DETACH
1009 FLAG_GENERIC(MNT_DETACH),
1010 #endif
1011 #ifdef MNT_EXPIRE
1012 FLAG_GENERIC(MNT_EXPIRE),
1013 #endif
1014 FLAG_END,
1017 UNUSED static struct flags mmap_prot_flags[] = {
1018 FLAG_GENERIC(PROT_NONE),
1019 FLAG_GENERIC(PROT_EXEC),
1020 FLAG_GENERIC(PROT_READ),
1021 FLAG_GENERIC(PROT_WRITE),
1022 FLAG_TARGET(PROT_SEM),
1023 FLAG_GENERIC(PROT_GROWSDOWN),
1024 FLAG_GENERIC(PROT_GROWSUP),
1025 FLAG_END,
1028 UNUSED static struct flags mmap_flags[] = {
1029 FLAG_TARGET(MAP_SHARED),
1030 FLAG_TARGET(MAP_PRIVATE),
1031 FLAG_TARGET(MAP_ANONYMOUS),
1032 FLAG_TARGET(MAP_DENYWRITE),
1033 FLAG_TARGET(MAP_FIXED),
1034 FLAG_TARGET(MAP_GROWSDOWN),
1035 FLAG_TARGET(MAP_EXECUTABLE),
1036 #ifdef MAP_LOCKED
1037 FLAG_TARGET(MAP_LOCKED),
1038 #endif
1039 #ifdef MAP_NONBLOCK
1040 FLAG_TARGET(MAP_NONBLOCK),
1041 #endif
1042 FLAG_TARGET(MAP_NORESERVE),
1043 #ifdef MAP_POPULATE
1044 FLAG_TARGET(MAP_POPULATE),
1045 #endif
1046 #ifdef TARGET_MAP_UNINITIALIZED
1047 FLAG_TARGET(MAP_UNINITIALIZED),
1048 #endif
1049 FLAG_END,
1052 UNUSED static struct flags clone_flags[] = {
1053 FLAG_GENERIC(CLONE_VM),
1054 FLAG_GENERIC(CLONE_FS),
1055 FLAG_GENERIC(CLONE_FILES),
1056 FLAG_GENERIC(CLONE_SIGHAND),
1057 FLAG_GENERIC(CLONE_PTRACE),
1058 FLAG_GENERIC(CLONE_VFORK),
1059 FLAG_GENERIC(CLONE_PARENT),
1060 FLAG_GENERIC(CLONE_THREAD),
1061 FLAG_GENERIC(CLONE_NEWNS),
1062 FLAG_GENERIC(CLONE_SYSVSEM),
1063 FLAG_GENERIC(CLONE_SETTLS),
1064 FLAG_GENERIC(CLONE_PARENT_SETTID),
1065 FLAG_GENERIC(CLONE_CHILD_CLEARTID),
1066 FLAG_GENERIC(CLONE_DETACHED),
1067 FLAG_GENERIC(CLONE_UNTRACED),
1068 FLAG_GENERIC(CLONE_CHILD_SETTID),
1069 #if defined(CLONE_NEWUTS)
1070 FLAG_GENERIC(CLONE_NEWUTS),
1071 #endif
1072 #if defined(CLONE_NEWIPC)
1073 FLAG_GENERIC(CLONE_NEWIPC),
1074 #endif
1075 #if defined(CLONE_NEWUSER)
1076 FLAG_GENERIC(CLONE_NEWUSER),
1077 #endif
1078 #if defined(CLONE_NEWPID)
1079 FLAG_GENERIC(CLONE_NEWPID),
1080 #endif
1081 #if defined(CLONE_NEWNET)
1082 FLAG_GENERIC(CLONE_NEWNET),
1083 #endif
1084 #if defined(CLONE_IO)
1085 FLAG_GENERIC(CLONE_IO),
1086 #endif
1087 FLAG_END,
1090 UNUSED static struct flags msg_flags[] = {
1091 /* send */
1092 FLAG_GENERIC(MSG_CONFIRM),
1093 FLAG_GENERIC(MSG_DONTROUTE),
1094 FLAG_GENERIC(MSG_DONTWAIT),
1095 FLAG_GENERIC(MSG_EOR),
1096 FLAG_GENERIC(MSG_MORE),
1097 FLAG_GENERIC(MSG_NOSIGNAL),
1098 FLAG_GENERIC(MSG_OOB),
1099 /* recv */
1100 FLAG_GENERIC(MSG_CMSG_CLOEXEC),
1101 FLAG_GENERIC(MSG_ERRQUEUE),
1102 FLAG_GENERIC(MSG_PEEK),
1103 FLAG_GENERIC(MSG_TRUNC),
1104 FLAG_GENERIC(MSG_WAITALL),
1105 /* recvmsg */
1106 FLAG_GENERIC(MSG_CTRUNC),
1107 FLAG_END,
1110 UNUSED static struct flags statx_flags[] = {
1111 #ifdef AT_EMPTY_PATH
1112 FLAG_GENERIC(AT_EMPTY_PATH),
1113 #endif
1114 #ifdef AT_NO_AUTOMOUNT
1115 FLAG_GENERIC(AT_NO_AUTOMOUNT),
1116 #endif
1117 #ifdef AT_SYMLINK_NOFOLLOW
1118 FLAG_GENERIC(AT_SYMLINK_NOFOLLOW),
1119 #endif
1120 #ifdef AT_STATX_SYNC_AS_STAT
1121 FLAG_GENERIC(AT_STATX_SYNC_AS_STAT),
1122 #endif
1123 #ifdef AT_STATX_FORCE_SYNC
1124 FLAG_GENERIC(AT_STATX_FORCE_SYNC),
1125 #endif
1126 #ifdef AT_STATX_DONT_SYNC
1127 FLAG_GENERIC(AT_STATX_DONT_SYNC),
1128 #endif
1129 FLAG_END,
1132 UNUSED static struct flags statx_mask[] = {
1133 /* This must come first, because it includes everything. */
1134 #ifdef STATX_ALL
1135 FLAG_GENERIC(STATX_ALL),
1136 #endif
1137 /* This must come second; it includes everything except STATX_BTIME. */
1138 #ifdef STATX_BASIC_STATS
1139 FLAG_GENERIC(STATX_BASIC_STATS),
1140 #endif
1141 #ifdef STATX_TYPE
1142 FLAG_GENERIC(STATX_TYPE),
1143 #endif
1144 #ifdef STATX_MODE
1145 FLAG_GENERIC(STATX_MODE),
1146 #endif
1147 #ifdef STATX_NLINK
1148 FLAG_GENERIC(STATX_NLINK),
1149 #endif
1150 #ifdef STATX_UID
1151 FLAG_GENERIC(STATX_UID),
1152 #endif
1153 #ifdef STATX_GID
1154 FLAG_GENERIC(STATX_GID),
1155 #endif
1156 #ifdef STATX_ATIME
1157 FLAG_GENERIC(STATX_ATIME),
1158 #endif
1159 #ifdef STATX_MTIME
1160 FLAG_GENERIC(STATX_MTIME),
1161 #endif
1162 #ifdef STATX_CTIME
1163 FLAG_GENERIC(STATX_CTIME),
1164 #endif
1165 #ifdef STATX_INO
1166 FLAG_GENERIC(STATX_INO),
1167 #endif
1168 #ifdef STATX_SIZE
1169 FLAG_GENERIC(STATX_SIZE),
1170 #endif
1171 #ifdef STATX_BLOCKS
1172 FLAG_GENERIC(STATX_BLOCKS),
1173 #endif
1174 #ifdef STATX_BTIME
1175 FLAG_GENERIC(STATX_BTIME),
1176 #endif
1177 FLAG_END,
1180 UNUSED static struct flags falloc_flags[] = {
1181 FLAG_GENERIC(FALLOC_FL_KEEP_SIZE),
1182 FLAG_GENERIC(FALLOC_FL_PUNCH_HOLE),
1183 #ifdef FALLOC_FL_NO_HIDE_STALE
1184 FLAG_GENERIC(FALLOC_FL_NO_HIDE_STALE),
1185 #endif
1186 #ifdef FALLOC_FL_COLLAPSE_RANGE
1187 FLAG_GENERIC(FALLOC_FL_COLLAPSE_RANGE),
1188 #endif
1189 #ifdef FALLOC_FL_ZERO_RANGE
1190 FLAG_GENERIC(FALLOC_FL_ZERO_RANGE),
1191 #endif
1192 #ifdef FALLOC_FL_INSERT_RANGE
1193 FLAG_GENERIC(FALLOC_FL_INSERT_RANGE),
1194 #endif
1195 #ifdef FALLOC_FL_UNSHARE_RANGE
1196 FLAG_GENERIC(FALLOC_FL_UNSHARE_RANGE),
1197 #endif
1201 * print_xxx utility functions. These are used to print syscall
1202 * parameters in certain format. All of these have parameter
1203 * named 'last'. This parameter is used to add comma to output
1204 * when last == 0.
1207 static const char *
1208 get_comma(int last)
1210 return ((last) ? "" : ",");
1213 static void
1214 print_flags(const struct flags *f, abi_long flags, int last)
1216 const char *sep = "";
1217 int n;
1219 if ((flags == 0) && (f->f_value == 0)) {
1220 qemu_log("%s%s", f->f_string, get_comma(last));
1221 return;
1223 for (n = 0; f->f_string != NULL; f++) {
1224 if ((f->f_value != 0) && ((flags & f->f_value) == f->f_value)) {
1225 qemu_log("%s%s", sep, f->f_string);
1226 flags &= ~f->f_value;
1227 sep = "|";
1228 n++;
1232 if (n > 0) {
1233 /* print rest of the flags as numeric */
1234 if (flags != 0) {
1235 qemu_log("%s%#x%s", sep, (unsigned int)flags, get_comma(last));
1236 } else {
1237 qemu_log("%s", get_comma(last));
1239 } else {
1240 /* no string version of flags found, print them in hex then */
1241 qemu_log("%#x%s", (unsigned int)flags, get_comma(last));
1245 static void
1246 print_at_dirfd(abi_long dirfd, int last)
1248 #ifdef AT_FDCWD
1249 if (dirfd == AT_FDCWD) {
1250 qemu_log("AT_FDCWD%s", get_comma(last));
1251 return;
1253 #endif
1254 qemu_log("%d%s", (int)dirfd, get_comma(last));
1257 static void
1258 print_file_mode(abi_long mode, int last)
1260 const char *sep = "";
1261 const struct flags *m;
1263 for (m = &mode_flags[0]; m->f_string != NULL; m++) {
1264 if ((m->f_value & mode) == m->f_value) {
1265 qemu_log("%s%s", m->f_string, sep);
1266 sep = "|";
1267 mode &= ~m->f_value;
1268 break;
1272 mode &= ~S_IFMT;
1273 /* print rest of the mode as octal */
1274 if (mode != 0)
1275 qemu_log("%s%#o", sep, (unsigned int)mode);
1277 qemu_log("%s", get_comma(last));
1280 static void
1281 print_open_flags(abi_long flags, int last)
1283 print_flags(open_access_flags, flags & TARGET_O_ACCMODE, 1);
1284 flags &= ~TARGET_O_ACCMODE;
1285 if (flags == 0) {
1286 qemu_log("%s", get_comma(last));
1287 return;
1289 qemu_log("|");
1290 print_flags(open_flags, flags, last);
1293 static void
1294 print_syscall_prologue(const struct syscallname *sc)
1296 qemu_log("%s(", sc->name);
1299 /*ARGSUSED*/
1300 static void
1301 print_syscall_epilogue(const struct syscallname *sc)
1303 (void)sc;
1304 qemu_log(")");
1307 static void
1308 print_string(abi_long addr, int last)
1310 char *s;
1312 if ((s = lock_user_string(addr)) != NULL) {
1313 qemu_log("\"%s\"%s", s, get_comma(last));
1314 unlock_user(s, addr, 0);
1315 } else {
1316 /* can't get string out of it, so print it as pointer */
1317 print_pointer(addr, last);
1321 #define MAX_PRINT_BUF 40
1322 static void
1323 print_buf(abi_long addr, abi_long len, int last)
1325 uint8_t *s;
1326 int i;
1328 s = lock_user(VERIFY_READ, addr, len, 1);
1329 if (s) {
1330 qemu_log("\"");
1331 for (i = 0; i < MAX_PRINT_BUF && i < len; i++) {
1332 if (isprint(s[i])) {
1333 qemu_log("%c", s[i]);
1334 } else {
1335 qemu_log("\\%o", s[i]);
1338 qemu_log("\"");
1339 if (i != len) {
1340 qemu_log("...");
1342 if (!last) {
1343 qemu_log(",");
1345 unlock_user(s, addr, 0);
1346 } else {
1347 print_pointer(addr, last);
1352 * Prints out raw parameter using given format. Caller needs
1353 * to do byte swapping if needed.
1355 static void
1356 print_raw_param(const char *fmt, abi_long param, int last)
1358 char format[64];
1360 (void) snprintf(format, sizeof (format), "%s%s", fmt, get_comma(last));
1361 qemu_log(format, param);
1364 static void
1365 print_pointer(abi_long p, int last)
1367 if (p == 0)
1368 qemu_log("NULL%s", get_comma(last));
1369 else
1370 qemu_log("0x" TARGET_ABI_FMT_lx "%s", p, get_comma(last));
1374 * Reads 32-bit (int) number from guest address space from
1375 * address 'addr' and prints it.
1377 static void
1378 print_number(abi_long addr, int last)
1380 if (addr == 0) {
1381 qemu_log("NULL%s", get_comma(last));
1382 } else {
1383 int num;
1385 get_user_s32(num, addr);
1386 qemu_log("[%d]%s", num, get_comma(last));
1390 static void
1391 print_timeval(abi_ulong tv_addr, int last)
1393 if( tv_addr ) {
1394 struct target_timeval *tv;
1396 tv = lock_user(VERIFY_READ, tv_addr, sizeof(*tv), 1);
1397 if (!tv) {
1398 print_pointer(tv_addr, last);
1399 return;
1401 qemu_log("{" TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld "}%s",
1402 tswapal(tv->tv_sec), tswapal(tv->tv_usec), get_comma(last));
1403 unlock_user(tv, tv_addr, 0);
1404 } else
1405 qemu_log("NULL%s", get_comma(last));
1408 static void
1409 print_timezone(abi_ulong tz_addr, int last)
1411 if (tz_addr) {
1412 struct target_timezone *tz;
1414 tz = lock_user(VERIFY_READ, tz_addr, sizeof(*tz), 1);
1415 if (!tz) {
1416 print_pointer(tz_addr, last);
1417 return;
1419 qemu_log("{%d,%d}%s", tswap32(tz->tz_minuteswest),
1420 tswap32(tz->tz_dsttime), get_comma(last));
1421 unlock_user(tz, tz_addr, 0);
1422 } else {
1423 qemu_log("NULL%s", get_comma(last));
1427 #undef UNUSED
1429 #ifdef TARGET_NR_accept
1430 static void
1431 print_accept(const struct syscallname *name,
1432 abi_long arg0, abi_long arg1, abi_long arg2,
1433 abi_long arg3, abi_long arg4, abi_long arg5)
1435 print_syscall_prologue(name);
1436 print_raw_param("%d", arg0, 0);
1437 print_pointer(arg1, 0);
1438 print_number(arg2, 1);
1439 print_syscall_epilogue(name);
1441 #endif
1443 #ifdef TARGET_NR_access
1444 static void
1445 print_access(const struct syscallname *name,
1446 abi_long arg0, abi_long arg1, abi_long arg2,
1447 abi_long arg3, abi_long arg4, abi_long arg5)
1449 print_syscall_prologue(name);
1450 print_string(arg0, 0);
1451 print_flags(access_flags, arg1, 1);
1452 print_syscall_epilogue(name);
1454 #endif
1456 #ifdef TARGET_NR_acct
1457 static void
1458 print_acct(const struct syscallname *name,
1459 abi_long arg0, abi_long arg1, abi_long arg2,
1460 abi_long arg3, abi_long arg4, abi_long arg5)
1462 print_syscall_prologue(name);
1463 print_string(arg0, 1);
1464 print_syscall_epilogue(name);
1466 #endif
1468 #ifdef TARGET_NR_brk
1469 static void
1470 print_brk(const struct syscallname *name,
1471 abi_long arg0, abi_long arg1, abi_long arg2,
1472 abi_long arg3, abi_long arg4, abi_long arg5)
1474 print_syscall_prologue(name);
1475 print_pointer(arg0, 1);
1476 print_syscall_epilogue(name);
1478 #endif
1480 #ifdef TARGET_NR_chdir
1481 static void
1482 print_chdir(const struct syscallname *name,
1483 abi_long arg0, abi_long arg1, abi_long arg2,
1484 abi_long arg3, abi_long arg4, abi_long arg5)
1486 print_syscall_prologue(name);
1487 print_string(arg0, 1);
1488 print_syscall_epilogue(name);
1490 #endif
1492 #ifdef TARGET_NR_chroot
1493 static void
1494 print_chroot(const struct syscallname *name,
1495 abi_long arg0, abi_long arg1, abi_long arg2,
1496 abi_long arg3, abi_long arg4, abi_long arg5)
1498 print_syscall_prologue(name);
1499 print_string(arg0, 1);
1500 print_syscall_epilogue(name);
1502 #endif
1504 #ifdef TARGET_NR_chmod
1505 static void
1506 print_chmod(const struct syscallname *name,
1507 abi_long arg0, abi_long arg1, abi_long arg2,
1508 abi_long arg3, abi_long arg4, abi_long arg5)
1510 print_syscall_prologue(name);
1511 print_string(arg0, 0);
1512 print_file_mode(arg1, 1);
1513 print_syscall_epilogue(name);
1515 #endif
1517 #if defined(TARGET_NR_chown) || defined(TARGET_NR_lchown)
1518 static void
1519 print_chown(const struct syscallname *name,
1520 abi_long arg0, abi_long arg1, abi_long arg2,
1521 abi_long arg3, abi_long arg4, abi_long arg5)
1523 print_syscall_prologue(name);
1524 print_string(arg0, 0);
1525 print_raw_param("%d", arg1, 0);
1526 print_raw_param("%d", arg2, 1);
1527 print_syscall_epilogue(name);
1529 #define print_lchown print_chown
1530 #endif
1532 #ifdef TARGET_NR_clock_adjtime
1533 static void
1534 print_clock_adjtime(const struct syscallname *name,
1535 abi_long arg0, abi_long arg1, abi_long arg2,
1536 abi_long arg3, abi_long arg4, abi_long arg5)
1538 print_syscall_prologue(name);
1539 print_clockid(arg0, 0);
1540 print_pointer(arg1, 1);
1541 print_syscall_epilogue(name);
1543 #endif
1545 #ifdef TARGET_NR_clone
1546 static void do_print_clone(unsigned int flags, abi_ulong newsp,
1547 abi_ulong parent_tidptr, target_ulong newtls,
1548 abi_ulong child_tidptr)
1550 print_flags(clone_flags, flags, 0);
1551 print_raw_param("child_stack=0x" TARGET_ABI_FMT_lx, newsp, 0);
1552 print_raw_param("parent_tidptr=0x" TARGET_ABI_FMT_lx, parent_tidptr, 0);
1553 print_raw_param("tls=0x" TARGET_ABI_FMT_lx, newtls, 0);
1554 print_raw_param("child_tidptr=0x" TARGET_ABI_FMT_lx, child_tidptr, 1);
1557 static void
1558 print_clone(const struct syscallname *name,
1559 abi_long arg1, abi_long arg2, abi_long arg3,
1560 abi_long arg4, abi_long arg5, abi_long arg6)
1562 print_syscall_prologue(name);
1563 #if defined(TARGET_MICROBLAZE)
1564 do_print_clone(arg1, arg2, arg4, arg6, arg5);
1565 #elif defined(TARGET_CLONE_BACKWARDS)
1566 do_print_clone(arg1, arg2, arg3, arg4, arg5);
1567 #elif defined(TARGET_CLONE_BACKWARDS2)
1568 do_print_clone(arg2, arg1, arg3, arg5, arg4);
1569 #else
1570 do_print_clone(arg1, arg2, arg3, arg5, arg4);
1571 #endif
1572 print_syscall_epilogue(name);
1574 #endif
1576 #ifdef TARGET_NR_creat
1577 static void
1578 print_creat(const struct syscallname *name,
1579 abi_long arg0, abi_long arg1, abi_long arg2,
1580 abi_long arg3, abi_long arg4, abi_long arg5)
1582 print_syscall_prologue(name);
1583 print_string(arg0, 0);
1584 print_file_mode(arg1, 1);
1585 print_syscall_epilogue(name);
1587 #endif
1589 #ifdef TARGET_NR_execv
1590 static void
1591 print_execv(const struct syscallname *name,
1592 abi_long arg0, abi_long arg1, abi_long arg2,
1593 abi_long arg3, abi_long arg4, abi_long arg5)
1595 print_syscall_prologue(name);
1596 print_string(arg0, 0);
1597 print_raw_param("0x" TARGET_ABI_FMT_lx, arg1, 1);
1598 print_syscall_epilogue(name);
1600 #endif
1602 #ifdef TARGET_NR_faccessat
1603 static void
1604 print_faccessat(const struct syscallname *name,
1605 abi_long arg0, abi_long arg1, abi_long arg2,
1606 abi_long arg3, abi_long arg4, abi_long arg5)
1608 print_syscall_prologue(name);
1609 print_at_dirfd(arg0, 0);
1610 print_string(arg1, 0);
1611 print_flags(access_flags, arg2, 0);
1612 print_flags(at_file_flags, arg3, 1);
1613 print_syscall_epilogue(name);
1615 #endif
1617 #ifdef TARGET_NR_fallocate
1618 static void
1619 print_fallocate(const struct syscallname *name,
1620 abi_long arg0, abi_long arg1, abi_long arg2,
1621 abi_long arg3, abi_long arg4, abi_long arg5)
1623 print_syscall_prologue(name);
1624 print_raw_param("%d", arg0, 0);
1625 print_flags(falloc_flags, arg1, 0);
1626 #if TARGET_ABI_BITS == 32
1627 print_raw_param("%" PRIu64, target_offset64(arg2, arg3), 0);
1628 print_raw_param("%" PRIu64, target_offset64(arg4, arg5), 1);
1629 #else
1630 print_raw_param(TARGET_ABI_FMT_ld, arg2, 0);
1631 print_raw_param(TARGET_ABI_FMT_ld, arg3, 1);
1632 #endif
1633 print_syscall_epilogue(name);
1635 #endif
1637 #ifdef TARGET_NR_fchmodat
1638 static void
1639 print_fchmodat(const struct syscallname *name,
1640 abi_long arg0, abi_long arg1, abi_long arg2,
1641 abi_long arg3, abi_long arg4, abi_long arg5)
1643 print_syscall_prologue(name);
1644 print_at_dirfd(arg0, 0);
1645 print_string(arg1, 0);
1646 print_file_mode(arg2, 0);
1647 print_flags(at_file_flags, arg3, 1);
1648 print_syscall_epilogue(name);
1650 #endif
1652 #ifdef TARGET_NR_fchownat
1653 static void
1654 print_fchownat(const struct syscallname *name,
1655 abi_long arg0, abi_long arg1, abi_long arg2,
1656 abi_long arg3, abi_long arg4, abi_long arg5)
1658 print_syscall_prologue(name);
1659 print_at_dirfd(arg0, 0);
1660 print_string(arg1, 0);
1661 print_raw_param("%d", arg2, 0);
1662 print_raw_param("%d", arg3, 0);
1663 print_flags(at_file_flags, arg4, 1);
1664 print_syscall_epilogue(name);
1666 #endif
1668 #if defined(TARGET_NR_fcntl) || defined(TARGET_NR_fcntl64)
1669 static void
1670 print_fcntl(const struct syscallname *name,
1671 abi_long arg0, abi_long arg1, abi_long arg2,
1672 abi_long arg3, abi_long arg4, abi_long arg5)
1674 print_syscall_prologue(name);
1675 print_raw_param("%d", arg0, 0);
1676 switch(arg1) {
1677 case TARGET_F_DUPFD:
1678 qemu_log("F_DUPFD,");
1679 print_raw_param(TARGET_ABI_FMT_ld, arg2, 1);
1680 break;
1681 case TARGET_F_GETFD:
1682 qemu_log("F_GETFD");
1683 break;
1684 case TARGET_F_SETFD:
1685 qemu_log("F_SETFD,");
1686 print_raw_param(TARGET_ABI_FMT_ld, arg2, 1);
1687 break;
1688 case TARGET_F_GETFL:
1689 qemu_log("F_GETFL");
1690 break;
1691 case TARGET_F_SETFL:
1692 qemu_log("F_SETFL,");
1693 print_open_flags(arg2, 1);
1694 break;
1695 case TARGET_F_GETLK:
1696 qemu_log("F_GETLK,");
1697 print_pointer(arg2, 1);
1698 break;
1699 case TARGET_F_SETLK:
1700 qemu_log("F_SETLK,");
1701 print_pointer(arg2, 1);
1702 break;
1703 case TARGET_F_SETLKW:
1704 qemu_log("F_SETLKW,");
1705 print_pointer(arg2, 1);
1706 break;
1707 case TARGET_F_GETOWN:
1708 qemu_log("F_GETOWN");
1709 break;
1710 case TARGET_F_SETOWN:
1711 qemu_log("F_SETOWN,");
1712 print_raw_param(TARGET_ABI_FMT_ld, arg2, 0);
1713 break;
1714 case TARGET_F_GETSIG:
1715 qemu_log("F_GETSIG");
1716 break;
1717 case TARGET_F_SETSIG:
1718 qemu_log("F_SETSIG,");
1719 print_raw_param(TARGET_ABI_FMT_ld, arg2, 0);
1720 break;
1721 #if TARGET_ABI_BITS == 32
1722 case TARGET_F_GETLK64:
1723 qemu_log("F_GETLK64,");
1724 print_pointer(arg2, 1);
1725 break;
1726 case TARGET_F_SETLK64:
1727 qemu_log("F_SETLK64,");
1728 print_pointer(arg2, 1);
1729 break;
1730 case TARGET_F_SETLKW64:
1731 qemu_log("F_SETLKW64,");
1732 print_pointer(arg2, 1);
1733 break;
1734 #endif
1735 case TARGET_F_SETLEASE:
1736 qemu_log("F_SETLEASE,");
1737 print_raw_param(TARGET_ABI_FMT_ld, arg2, 0);
1738 break;
1739 case TARGET_F_GETLEASE:
1740 qemu_log("F_GETLEASE");
1741 break;
1742 case TARGET_F_SETPIPE_SZ:
1743 qemu_log("F_SETPIPE_SZ,");
1744 print_raw_param(TARGET_ABI_FMT_ld, arg2, 1);
1745 break;
1746 case TARGET_F_GETPIPE_SZ:
1747 qemu_log("F_GETPIPE_SZ");
1748 break;
1749 case TARGET_F_DUPFD_CLOEXEC:
1750 qemu_log("F_DUPFD_CLOEXEC,");
1751 print_raw_param(TARGET_ABI_FMT_ld, arg2, 1);
1752 break;
1753 case TARGET_F_NOTIFY:
1754 qemu_log("F_NOTIFY,");
1755 print_raw_param(TARGET_ABI_FMT_ld, arg2, 0);
1756 break;
1757 default:
1758 print_raw_param(TARGET_ABI_FMT_ld, arg1, 0);
1759 print_pointer(arg2, 1);
1760 break;
1762 print_syscall_epilogue(name);
1764 #define print_fcntl64 print_fcntl
1765 #endif
1767 #ifdef TARGET_NR_fgetxattr
1768 static void
1769 print_fgetxattr(const struct syscallname *name,
1770 abi_long arg0, abi_long arg1, abi_long arg2,
1771 abi_long arg3, abi_long arg4, abi_long arg5)
1773 print_syscall_prologue(name);
1774 print_raw_param("%d", arg0, 0);
1775 print_string(arg1, 0);
1776 print_pointer(arg2, 0);
1777 print_raw_param(TARGET_FMT_lu, arg3, 1);
1778 print_syscall_epilogue(name);
1780 #endif
1782 #ifdef TARGET_NR_flistxattr
1783 static void
1784 print_flistxattr(const struct syscallname *name,
1785 abi_long arg0, abi_long arg1, abi_long arg2,
1786 abi_long arg3, abi_long arg4, abi_long arg5)
1788 print_syscall_prologue(name);
1789 print_raw_param("%d", arg0, 0);
1790 print_pointer(arg1, 0);
1791 print_raw_param(TARGET_FMT_lu, arg2, 1);
1792 print_syscall_epilogue(name);
1794 #endif
1796 #if defined(TARGET_NR_getxattr) || defined(TARGET_NR_lgetxattr)
1797 static void
1798 print_getxattr(const struct syscallname *name,
1799 abi_long arg0, abi_long arg1, abi_long arg2,
1800 abi_long arg3, abi_long arg4, abi_long arg5)
1802 print_syscall_prologue(name);
1803 print_string(arg0, 0);
1804 print_string(arg1, 0);
1805 print_pointer(arg2, 0);
1806 print_raw_param(TARGET_FMT_lu, arg3, 1);
1807 print_syscall_epilogue(name);
1809 #define print_lgetxattr print_getxattr
1810 #endif
1812 #if defined(TARGET_NR_listxattr) || defined(TARGET_NR_llistxattr)
1813 static void
1814 print_listxattr(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, 0);
1820 print_pointer(arg1, 0);
1821 print_raw_param(TARGET_FMT_lu, arg2, 1);
1822 print_syscall_epilogue(name);
1824 #define print_llistxattr print_listxattr
1825 #endif
1827 #if defined(TARGET_NR_fremovexattr)
1828 static void
1829 print_fremovexattr(const struct syscallname *name,
1830 abi_long arg0, abi_long arg1, abi_long arg2,
1831 abi_long arg3, abi_long arg4, abi_long arg5)
1833 print_syscall_prologue(name);
1834 print_raw_param("%d", arg0, 0);
1835 print_string(arg1, 1);
1836 print_syscall_epilogue(name);
1838 #endif
1840 #if defined(TARGET_NR_removexattr) || defined(TARGET_NR_lremovexattr)
1841 static void
1842 print_removexattr(const struct syscallname *name,
1843 abi_long arg0, abi_long arg1, abi_long arg2,
1844 abi_long arg3, abi_long arg4, abi_long arg5)
1846 print_syscall_prologue(name);
1847 print_string(arg0, 0);
1848 print_string(arg1, 1);
1849 print_syscall_epilogue(name);
1851 #define print_lremovexattr print_removexattr
1852 #endif
1854 #ifdef TARGET_NR_futimesat
1855 static void
1856 print_futimesat(const struct syscallname *name,
1857 abi_long arg0, abi_long arg1, abi_long arg2,
1858 abi_long arg3, abi_long arg4, abi_long arg5)
1860 print_syscall_prologue(name);
1861 print_at_dirfd(arg0, 0);
1862 print_string(arg1, 0);
1863 print_timeval(arg2, 0);
1864 print_timeval(arg2 + sizeof (struct target_timeval), 1);
1865 print_syscall_epilogue(name);
1867 #endif
1869 #ifdef TARGET_NR_settimeofday
1870 static void
1871 print_settimeofday(const struct syscallname *name,
1872 abi_long arg0, abi_long arg1, abi_long arg2,
1873 abi_long arg3, abi_long arg4, abi_long arg5)
1875 print_syscall_prologue(name);
1876 print_timeval(arg0, 0);
1877 print_timezone(arg1, 1);
1878 print_syscall_epilogue(name);
1880 #endif
1882 #ifdef TARGET_NR_link
1883 static void
1884 print_link(const struct syscallname *name,
1885 abi_long arg0, abi_long arg1, abi_long arg2,
1886 abi_long arg3, abi_long arg4, abi_long arg5)
1888 print_syscall_prologue(name);
1889 print_string(arg0, 0);
1890 print_string(arg1, 1);
1891 print_syscall_epilogue(name);
1893 #endif
1895 #ifdef TARGET_NR_linkat
1896 static void
1897 print_linkat(const struct syscallname *name,
1898 abi_long arg0, abi_long arg1, abi_long arg2,
1899 abi_long arg3, abi_long arg4, abi_long arg5)
1901 print_syscall_prologue(name);
1902 print_at_dirfd(arg0, 0);
1903 print_string(arg1, 0);
1904 print_at_dirfd(arg2, 0);
1905 print_string(arg3, 0);
1906 print_flags(at_file_flags, arg4, 1);
1907 print_syscall_epilogue(name);
1909 #endif
1911 #ifdef TARGET_NR__llseek
1912 static void
1913 print__llseek(const struct syscallname *name,
1914 abi_long arg0, abi_long arg1, abi_long arg2,
1915 abi_long arg3, abi_long arg4, abi_long arg5)
1917 const char *whence = "UNKNOWN";
1918 print_syscall_prologue(name);
1919 print_raw_param("%d", arg0, 0);
1920 print_raw_param("%ld", arg1, 0);
1921 print_raw_param("%ld", arg2, 0);
1922 print_pointer(arg3, 0);
1923 switch(arg4) {
1924 case SEEK_SET: whence = "SEEK_SET"; break;
1925 case SEEK_CUR: whence = "SEEK_CUR"; break;
1926 case SEEK_END: whence = "SEEK_END"; break;
1928 qemu_log("%s", whence);
1929 print_syscall_epilogue(name);
1931 #endif
1933 #ifdef TARGET_NR_lseek
1934 static void
1935 print_lseek(const struct syscallname *name,
1936 abi_long arg0, abi_long arg1, abi_long arg2,
1937 abi_long arg3, abi_long arg4, abi_long arg5)
1939 print_syscall_prologue(name);
1940 print_raw_param("%d", arg0, 0);
1941 print_raw_param(TARGET_ABI_FMT_ld, arg1, 0);
1942 switch (arg2) {
1943 case SEEK_SET:
1944 qemu_log("SEEK_SET"); break;
1945 case SEEK_CUR:
1946 qemu_log("SEEK_CUR"); break;
1947 case SEEK_END:
1948 qemu_log("SEEK_END"); break;
1949 #ifdef SEEK_DATA
1950 case SEEK_DATA:
1951 qemu_log("SEEK_DATA"); break;
1952 #endif
1953 #ifdef SEEK_HOLE
1954 case SEEK_HOLE:
1955 qemu_log("SEEK_HOLE"); break;
1956 #endif
1957 default:
1958 print_raw_param("%#x", arg2, 1);
1960 print_syscall_epilogue(name);
1962 #endif
1964 #if defined(TARGET_NR_socket)
1965 static void
1966 print_socket(const struct syscallname *name,
1967 abi_long arg0, abi_long arg1, abi_long arg2,
1968 abi_long arg3, abi_long arg4, abi_long arg5)
1970 abi_ulong domain = arg0, type = arg1, protocol = arg2;
1972 print_syscall_prologue(name);
1973 print_socket_domain(domain);
1974 qemu_log(",");
1975 print_socket_type(type);
1976 qemu_log(",");
1977 if (domain == AF_PACKET ||
1978 (domain == AF_INET && type == TARGET_SOCK_PACKET)) {
1979 protocol = tswap16(protocol);
1981 print_socket_protocol(domain, type, protocol);
1982 print_syscall_epilogue(name);
1985 #endif
1987 #if defined(TARGET_NR_socketcall) || defined(TARGET_NR_bind)
1989 static void print_sockfd(abi_long sockfd, int last)
1991 print_raw_param(TARGET_ABI_FMT_ld, sockfd, last);
1994 #endif
1996 #if defined(TARGET_NR_socketcall)
1998 #define get_user_ualx(x, gaddr, idx) \
1999 get_user_ual(x, (gaddr) + (idx) * sizeof(abi_long))
2001 static void do_print_socket(const char *name, abi_long arg1)
2003 abi_ulong domain, type, protocol;
2005 get_user_ualx(domain, arg1, 0);
2006 get_user_ualx(type, arg1, 1);
2007 get_user_ualx(protocol, arg1, 2);
2008 qemu_log("%s(", name);
2009 print_socket_domain(domain);
2010 qemu_log(",");
2011 print_socket_type(type);
2012 qemu_log(",");
2013 if (domain == AF_PACKET ||
2014 (domain == AF_INET && type == TARGET_SOCK_PACKET)) {
2015 protocol = tswap16(protocol);
2017 print_socket_protocol(domain, type, protocol);
2018 qemu_log(")");
2021 static void do_print_sockaddr(const char *name, abi_long arg1)
2023 abi_ulong sockfd, addr, addrlen;
2025 get_user_ualx(sockfd, arg1, 0);
2026 get_user_ualx(addr, arg1, 1);
2027 get_user_ualx(addrlen, arg1, 2);
2029 qemu_log("%s(", name);
2030 print_sockfd(sockfd, 0);
2031 print_sockaddr(addr, addrlen, 0);
2032 qemu_log(")");
2035 static void do_print_listen(const char *name, abi_long arg1)
2037 abi_ulong sockfd, backlog;
2039 get_user_ualx(sockfd, arg1, 0);
2040 get_user_ualx(backlog, arg1, 1);
2042 qemu_log("%s(", name);
2043 print_sockfd(sockfd, 0);
2044 print_raw_param(TARGET_ABI_FMT_ld, backlog, 1);
2045 qemu_log(")");
2048 static void do_print_socketpair(const char *name, abi_long arg1)
2050 abi_ulong domain, type, protocol, tab;
2052 get_user_ualx(domain, arg1, 0);
2053 get_user_ualx(type, arg1, 1);
2054 get_user_ualx(protocol, arg1, 2);
2055 get_user_ualx(tab, arg1, 3);
2057 qemu_log("%s(", name);
2058 print_socket_domain(domain);
2059 qemu_log(",");
2060 print_socket_type(type);
2061 qemu_log(",");
2062 print_socket_protocol(domain, type, protocol);
2063 qemu_log(",");
2064 print_raw_param(TARGET_ABI_FMT_lx, tab, 1);
2065 qemu_log(")");
2068 static void do_print_sendrecv(const char *name, abi_long arg1)
2070 abi_ulong sockfd, msg, len, flags;
2072 get_user_ualx(sockfd, arg1, 0);
2073 get_user_ualx(msg, arg1, 1);
2074 get_user_ualx(len, arg1, 2);
2075 get_user_ualx(flags, arg1, 3);
2077 qemu_log("%s(", name);
2078 print_sockfd(sockfd, 0);
2079 print_buf(msg, len, 0);
2080 print_raw_param(TARGET_ABI_FMT_ld, len, 0);
2081 print_flags(msg_flags, flags, 1);
2082 qemu_log(")");
2085 static void do_print_msgaddr(const char *name, abi_long arg1)
2087 abi_ulong sockfd, msg, len, flags, addr, addrlen;
2089 get_user_ualx(sockfd, arg1, 0);
2090 get_user_ualx(msg, arg1, 1);
2091 get_user_ualx(len, arg1, 2);
2092 get_user_ualx(flags, arg1, 3);
2093 get_user_ualx(addr, arg1, 4);
2094 get_user_ualx(addrlen, arg1, 5);
2096 qemu_log("%s(", name);
2097 print_sockfd(sockfd, 0);
2098 print_buf(msg, len, 0);
2099 print_raw_param(TARGET_ABI_FMT_ld, len, 0);
2100 print_flags(msg_flags, flags, 0);
2101 print_sockaddr(addr, addrlen, 0);
2102 qemu_log(")");
2105 static void do_print_shutdown(const char *name, abi_long arg1)
2107 abi_ulong sockfd, how;
2109 get_user_ualx(sockfd, arg1, 0);
2110 get_user_ualx(how, arg1, 1);
2112 qemu_log("shutdown(");
2113 print_sockfd(sockfd, 0);
2114 switch (how) {
2115 case SHUT_RD:
2116 qemu_log("SHUT_RD");
2117 break;
2118 case SHUT_WR:
2119 qemu_log("SHUT_WR");
2120 break;
2121 case SHUT_RDWR:
2122 qemu_log("SHUT_RDWR");
2123 break;
2124 default:
2125 print_raw_param(TARGET_ABI_FMT_ld, how, 1);
2126 break;
2128 qemu_log(")");
2131 static void do_print_msg(const char *name, abi_long arg1)
2133 abi_ulong sockfd, msg, flags;
2135 get_user_ualx(sockfd, arg1, 0);
2136 get_user_ualx(msg, arg1, 1);
2137 get_user_ualx(flags, arg1, 2);
2139 qemu_log("%s(", name);
2140 print_sockfd(sockfd, 0);
2141 print_pointer(msg, 0);
2142 print_flags(msg_flags, flags, 1);
2143 qemu_log(")");
2146 static void do_print_sockopt(const char *name, abi_long arg1)
2148 abi_ulong sockfd, level, optname, optval, optlen;
2150 get_user_ualx(sockfd, arg1, 0);
2151 get_user_ualx(level, arg1, 1);
2152 get_user_ualx(optname, arg1, 2);
2153 get_user_ualx(optval, arg1, 3);
2154 get_user_ualx(optlen, arg1, 4);
2156 qemu_log("%s(", name);
2157 print_sockfd(sockfd, 0);
2158 switch (level) {
2159 case SOL_TCP:
2160 qemu_log("SOL_TCP,");
2161 print_raw_param(TARGET_ABI_FMT_ld, optname, 0);
2162 print_pointer(optval, 0);
2163 break;
2164 case SOL_IP:
2165 qemu_log("SOL_IP,");
2166 print_raw_param(TARGET_ABI_FMT_ld, optname, 0);
2167 print_pointer(optval, 0);
2168 break;
2169 case SOL_RAW:
2170 qemu_log("SOL_RAW,");
2171 print_raw_param(TARGET_ABI_FMT_ld, optname, 0);
2172 print_pointer(optval, 0);
2173 break;
2174 case TARGET_SOL_SOCKET:
2175 qemu_log("SOL_SOCKET,");
2176 switch (optname) {
2177 case TARGET_SO_DEBUG:
2178 qemu_log("SO_DEBUG,");
2179 print_optint:
2180 print_number(optval, 0);
2181 break;
2182 case TARGET_SO_REUSEADDR:
2183 qemu_log("SO_REUSEADDR,");
2184 goto print_optint;
2185 case TARGET_SO_REUSEPORT:
2186 qemu_log("SO_REUSEPORT,");
2187 goto print_optint;
2188 case TARGET_SO_TYPE:
2189 qemu_log("SO_TYPE,");
2190 goto print_optint;
2191 case TARGET_SO_ERROR:
2192 qemu_log("SO_ERROR,");
2193 goto print_optint;
2194 case TARGET_SO_DONTROUTE:
2195 qemu_log("SO_DONTROUTE,");
2196 goto print_optint;
2197 case TARGET_SO_BROADCAST:
2198 qemu_log("SO_BROADCAST,");
2199 goto print_optint;
2200 case TARGET_SO_SNDBUF:
2201 qemu_log("SO_SNDBUF,");
2202 goto print_optint;
2203 case TARGET_SO_RCVBUF:
2204 qemu_log("SO_RCVBUF,");
2205 goto print_optint;
2206 case TARGET_SO_KEEPALIVE:
2207 qemu_log("SO_KEEPALIVE,");
2208 goto print_optint;
2209 case TARGET_SO_OOBINLINE:
2210 qemu_log("SO_OOBINLINE,");
2211 goto print_optint;
2212 case TARGET_SO_NO_CHECK:
2213 qemu_log("SO_NO_CHECK,");
2214 goto print_optint;
2215 case TARGET_SO_PRIORITY:
2216 qemu_log("SO_PRIORITY,");
2217 goto print_optint;
2218 case TARGET_SO_BSDCOMPAT:
2219 qemu_log("SO_BSDCOMPAT,");
2220 goto print_optint;
2221 case TARGET_SO_PASSCRED:
2222 qemu_log("SO_PASSCRED,");
2223 goto print_optint;
2224 case TARGET_SO_TIMESTAMP:
2225 qemu_log("SO_TIMESTAMP,");
2226 goto print_optint;
2227 case TARGET_SO_RCVLOWAT:
2228 qemu_log("SO_RCVLOWAT,");
2229 goto print_optint;
2230 case TARGET_SO_RCVTIMEO:
2231 qemu_log("SO_RCVTIMEO,");
2232 print_timeval(optval, 0);
2233 break;
2234 case TARGET_SO_SNDTIMEO:
2235 qemu_log("SO_SNDTIMEO,");
2236 print_timeval(optval, 0);
2237 break;
2238 case TARGET_SO_ATTACH_FILTER: {
2239 struct target_sock_fprog *fprog;
2241 qemu_log("SO_ATTACH_FILTER,");
2243 if (lock_user_struct(VERIFY_READ, fprog, optval, 0)) {
2244 struct target_sock_filter *filter;
2245 qemu_log("{");
2246 if (lock_user_struct(VERIFY_READ, filter,
2247 tswapal(fprog->filter), 0)) {
2248 int i;
2249 for (i = 0; i < tswap16(fprog->len) - 1; i++) {
2250 qemu_log("[%d]{0x%x,%d,%d,0x%x},",
2251 i, tswap16(filter[i].code),
2252 filter[i].jt, filter[i].jf,
2253 tswap32(filter[i].k));
2255 qemu_log("[%d]{0x%x,%d,%d,0x%x}",
2256 i, tswap16(filter[i].code),
2257 filter[i].jt, filter[i].jf,
2258 tswap32(filter[i].k));
2259 } else {
2260 qemu_log(TARGET_ABI_FMT_lx, tswapal(fprog->filter));
2262 qemu_log(",%d},", tswap16(fprog->len));
2263 unlock_user(fprog, optval, 0);
2264 } else {
2265 print_pointer(optval, 0);
2267 break;
2269 default:
2270 print_raw_param(TARGET_ABI_FMT_ld, optname, 0);
2271 print_pointer(optval, 0);
2272 break;
2274 break;
2275 default:
2276 print_raw_param(TARGET_ABI_FMT_ld, level, 0);
2277 print_raw_param(TARGET_ABI_FMT_ld, optname, 0);
2278 print_pointer(optval, 0);
2279 break;
2281 print_raw_param(TARGET_ABI_FMT_ld, optlen, 1);
2282 qemu_log(")");
2285 #define PRINT_SOCKOP(name, func) \
2286 [TARGET_SYS_##name] = { #name, func }
2288 static struct {
2289 const char *name;
2290 void (*print)(const char *, abi_long);
2291 } scall[] = {
2292 PRINT_SOCKOP(SOCKET, do_print_socket),
2293 PRINT_SOCKOP(BIND, do_print_sockaddr),
2294 PRINT_SOCKOP(CONNECT, do_print_sockaddr),
2295 PRINT_SOCKOP(LISTEN, do_print_listen),
2296 PRINT_SOCKOP(ACCEPT, do_print_sockaddr),
2297 PRINT_SOCKOP(GETSOCKNAME, do_print_sockaddr),
2298 PRINT_SOCKOP(GETPEERNAME, do_print_sockaddr),
2299 PRINT_SOCKOP(SOCKETPAIR, do_print_socketpair),
2300 PRINT_SOCKOP(SEND, do_print_sendrecv),
2301 PRINT_SOCKOP(RECV, do_print_sendrecv),
2302 PRINT_SOCKOP(SENDTO, do_print_msgaddr),
2303 PRINT_SOCKOP(RECVFROM, do_print_msgaddr),
2304 PRINT_SOCKOP(SHUTDOWN, do_print_shutdown),
2305 PRINT_SOCKOP(SETSOCKOPT, do_print_sockopt),
2306 PRINT_SOCKOP(GETSOCKOPT, do_print_sockopt),
2307 PRINT_SOCKOP(SENDMSG, do_print_msg),
2308 PRINT_SOCKOP(RECVMSG, do_print_msg),
2309 PRINT_SOCKOP(ACCEPT4, NULL),
2310 PRINT_SOCKOP(RECVMMSG, NULL),
2311 PRINT_SOCKOP(SENDMMSG, NULL),
2314 static void
2315 print_socketcall(const struct syscallname *name,
2316 abi_long arg0, abi_long arg1, abi_long arg2,
2317 abi_long arg3, abi_long arg4, abi_long arg5)
2319 if (arg0 >= 0 && arg0 < ARRAY_SIZE(scall) && scall[arg0].print) {
2320 scall[arg0].print(scall[arg0].name, arg1);
2321 return;
2323 print_syscall_prologue(name);
2324 print_raw_param(TARGET_ABI_FMT_ld, arg0, 0);
2325 print_raw_param(TARGET_ABI_FMT_ld, arg1, 0);
2326 print_raw_param(TARGET_ABI_FMT_ld, arg2, 0);
2327 print_raw_param(TARGET_ABI_FMT_ld, arg3, 0);
2328 print_raw_param(TARGET_ABI_FMT_ld, arg4, 0);
2329 print_raw_param(TARGET_ABI_FMT_ld, arg5, 0);
2330 print_syscall_epilogue(name);
2332 #endif
2334 #if defined(TARGET_NR_bind)
2335 static void
2336 print_bind(const struct syscallname *name,
2337 abi_long arg0, abi_long arg1, abi_long arg2,
2338 abi_long arg3, abi_long arg4, abi_long arg5)
2340 print_syscall_prologue(name);
2341 print_sockfd(arg0, 0);
2342 print_sockaddr(arg1, arg2, 1);
2343 print_syscall_epilogue(name);
2345 #endif
2347 #if defined(TARGET_NR_stat) || defined(TARGET_NR_stat64) || \
2348 defined(TARGET_NR_lstat) || defined(TARGET_NR_lstat64)
2349 static void
2350 print_stat(const struct syscallname *name,
2351 abi_long arg0, abi_long arg1, abi_long arg2,
2352 abi_long arg3, abi_long arg4, abi_long arg5)
2354 print_syscall_prologue(name);
2355 print_string(arg0, 0);
2356 print_pointer(arg1, 1);
2357 print_syscall_epilogue(name);
2359 #define print_lstat print_stat
2360 #define print_stat64 print_stat
2361 #define print_lstat64 print_stat
2362 #endif
2364 #if defined(TARGET_NR_fstat) || defined(TARGET_NR_fstat64)
2365 static void
2366 print_fstat(const struct syscallname *name,
2367 abi_long arg0, abi_long arg1, abi_long arg2,
2368 abi_long arg3, abi_long arg4, abi_long arg5)
2370 print_syscall_prologue(name);
2371 print_raw_param("%d", arg0, 0);
2372 print_pointer(arg1, 1);
2373 print_syscall_epilogue(name);
2375 #define print_fstat64 print_fstat
2376 #endif
2378 #ifdef TARGET_NR_mkdir
2379 static void
2380 print_mkdir(const struct syscallname *name,
2381 abi_long arg0, abi_long arg1, abi_long arg2,
2382 abi_long arg3, abi_long arg4, abi_long arg5)
2384 print_syscall_prologue(name);
2385 print_string(arg0, 0);
2386 print_file_mode(arg1, 1);
2387 print_syscall_epilogue(name);
2389 #endif
2391 #ifdef TARGET_NR_mkdirat
2392 static void
2393 print_mkdirat(const struct syscallname *name,
2394 abi_long arg0, abi_long arg1, abi_long arg2,
2395 abi_long arg3, abi_long arg4, abi_long arg5)
2397 print_syscall_prologue(name);
2398 print_at_dirfd(arg0, 0);
2399 print_string(arg1, 0);
2400 print_file_mode(arg2, 1);
2401 print_syscall_epilogue(name);
2403 #endif
2405 #ifdef TARGET_NR_rmdir
2406 static void
2407 print_rmdir(const struct syscallname *name,
2408 abi_long arg0, abi_long arg1, abi_long arg2,
2409 abi_long arg3, abi_long arg4, abi_long arg5)
2411 print_syscall_prologue(name);
2412 print_string(arg0, 0);
2413 print_syscall_epilogue(name);
2415 #endif
2417 #ifdef TARGET_NR_rt_sigaction
2418 static void
2419 print_rt_sigaction(const struct syscallname *name,
2420 abi_long arg0, abi_long arg1, abi_long arg2,
2421 abi_long arg3, abi_long arg4, abi_long arg5)
2423 print_syscall_prologue(name);
2424 print_signal(arg0, 0);
2425 print_pointer(arg1, 0);
2426 print_pointer(arg2, 1);
2427 print_syscall_epilogue(name);
2429 #endif
2431 #ifdef TARGET_NR_rt_sigprocmask
2432 static void
2433 print_rt_sigprocmask(const struct syscallname *name,
2434 abi_long arg0, abi_long arg1, abi_long arg2,
2435 abi_long arg3, abi_long arg4, abi_long arg5)
2437 const char *how = "UNKNOWN";
2438 print_syscall_prologue(name);
2439 switch(arg0) {
2440 case TARGET_SIG_BLOCK: how = "SIG_BLOCK"; break;
2441 case TARGET_SIG_UNBLOCK: how = "SIG_UNBLOCK"; break;
2442 case TARGET_SIG_SETMASK: how = "SIG_SETMASK"; break;
2444 qemu_log("%s,", how);
2445 print_pointer(arg1, 0);
2446 print_pointer(arg2, 1);
2447 print_syscall_epilogue(name);
2449 #endif
2451 #ifdef TARGET_NR_rt_sigqueueinfo
2452 static void
2453 print_rt_sigqueueinfo(const struct syscallname *name,
2454 abi_long arg0, abi_long arg1, abi_long arg2,
2455 abi_long arg3, abi_long arg4, abi_long arg5)
2457 void *p;
2458 target_siginfo_t uinfo;
2460 print_syscall_prologue(name);
2461 print_raw_param("%d", arg0, 0);
2462 print_signal(arg1, 0);
2463 p = lock_user(VERIFY_READ, arg2, sizeof(target_siginfo_t), 1);
2464 if (p) {
2465 get_target_siginfo(&uinfo, p);
2466 print_siginfo(&uinfo);
2468 unlock_user(p, arg2, 0);
2469 } else {
2470 print_pointer(arg2, 1);
2472 print_syscall_epilogue(name);
2474 #endif
2476 #ifdef TARGET_NR_rt_tgsigqueueinfo
2477 static void
2478 print_rt_tgsigqueueinfo(const struct syscallname *name,
2479 abi_long arg0, abi_long arg1, abi_long arg2,
2480 abi_long arg3, abi_long arg4, abi_long arg5)
2482 void *p;
2483 target_siginfo_t uinfo;
2485 print_syscall_prologue(name);
2486 print_raw_param("%d", arg0, 0);
2487 print_raw_param("%d", arg1, 0);
2488 print_signal(arg2, 0);
2489 p = lock_user(VERIFY_READ, arg3, sizeof(target_siginfo_t), 1);
2490 if (p) {
2491 get_target_siginfo(&uinfo, p);
2492 print_siginfo(&uinfo);
2494 unlock_user(p, arg3, 0);
2495 } else {
2496 print_pointer(arg3, 1);
2498 print_syscall_epilogue(name);
2500 #endif
2502 #ifdef TARGET_NR_syslog
2503 static void
2504 print_syslog_action(abi_ulong arg, int last)
2506 const char *type;
2508 switch (arg) {
2509 case TARGET_SYSLOG_ACTION_CLOSE: {
2510 type = "SYSLOG_ACTION_CLOSE";
2511 break;
2513 case TARGET_SYSLOG_ACTION_OPEN: {
2514 type = "SYSLOG_ACTION_OPEN";
2515 break;
2517 case TARGET_SYSLOG_ACTION_READ: {
2518 type = "SYSLOG_ACTION_READ";
2519 break;
2521 case TARGET_SYSLOG_ACTION_READ_ALL: {
2522 type = "SYSLOG_ACTION_READ_ALL";
2523 break;
2525 case TARGET_SYSLOG_ACTION_READ_CLEAR: {
2526 type = "SYSLOG_ACTION_READ_CLEAR";
2527 break;
2529 case TARGET_SYSLOG_ACTION_CLEAR: {
2530 type = "SYSLOG_ACTION_CLEAR";
2531 break;
2533 case TARGET_SYSLOG_ACTION_CONSOLE_OFF: {
2534 type = "SYSLOG_ACTION_CONSOLE_OFF";
2535 break;
2537 case TARGET_SYSLOG_ACTION_CONSOLE_ON: {
2538 type = "SYSLOG_ACTION_CONSOLE_ON";
2539 break;
2541 case TARGET_SYSLOG_ACTION_CONSOLE_LEVEL: {
2542 type = "SYSLOG_ACTION_CONSOLE_LEVEL";
2543 break;
2545 case TARGET_SYSLOG_ACTION_SIZE_UNREAD: {
2546 type = "SYSLOG_ACTION_SIZE_UNREAD";
2547 break;
2549 case TARGET_SYSLOG_ACTION_SIZE_BUFFER: {
2550 type = "SYSLOG_ACTION_SIZE_BUFFER";
2551 break;
2553 default: {
2554 print_raw_param("%ld", arg, last);
2555 return;
2558 qemu_log("%s%s", type, get_comma(last));
2561 static void
2562 print_syslog(const struct syscallname *name,
2563 abi_long arg0, abi_long arg1, abi_long arg2,
2564 abi_long arg3, abi_long arg4, abi_long arg5)
2566 print_syscall_prologue(name);
2567 print_syslog_action(arg0, 0);
2568 print_pointer(arg1, 0);
2569 print_raw_param("%d", arg2, 1);
2570 print_syscall_epilogue(name);
2572 #endif
2574 #ifdef TARGET_NR_mknod
2575 static void
2576 print_mknod(const struct syscallname *name,
2577 abi_long arg0, abi_long arg1, abi_long arg2,
2578 abi_long arg3, abi_long arg4, abi_long arg5)
2580 int hasdev = (arg1 & (S_IFCHR|S_IFBLK));
2582 print_syscall_prologue(name);
2583 print_string(arg0, 0);
2584 print_file_mode(arg1, (hasdev == 0));
2585 if (hasdev) {
2586 print_raw_param("makedev(%d", major(arg2), 0);
2587 print_raw_param("%d)", minor(arg2), 1);
2589 print_syscall_epilogue(name);
2591 #endif
2593 #ifdef TARGET_NR_mknodat
2594 static void
2595 print_mknodat(const struct syscallname *name,
2596 abi_long arg0, abi_long arg1, abi_long arg2,
2597 abi_long arg3, abi_long arg4, abi_long arg5)
2599 int hasdev = (arg2 & (S_IFCHR|S_IFBLK));
2601 print_syscall_prologue(name);
2602 print_at_dirfd(arg0, 0);
2603 print_string(arg1, 0);
2604 print_file_mode(arg2, (hasdev == 0));
2605 if (hasdev) {
2606 print_raw_param("makedev(%d", major(arg3), 0);
2607 print_raw_param("%d)", minor(arg3), 1);
2609 print_syscall_epilogue(name);
2611 #endif
2613 #ifdef TARGET_NR_mq_open
2614 static void
2615 print_mq_open(const struct syscallname *name,
2616 abi_long arg0, abi_long arg1, abi_long arg2,
2617 abi_long arg3, abi_long arg4, abi_long arg5)
2619 int is_creat = (arg1 & TARGET_O_CREAT);
2621 print_syscall_prologue(name);
2622 print_string(arg0, 0);
2623 print_open_flags(arg1, (is_creat == 0));
2624 if (is_creat) {
2625 print_file_mode(arg2, 0);
2626 print_pointer(arg3, 1);
2628 print_syscall_epilogue(name);
2630 #endif
2632 #ifdef TARGET_NR_open
2633 static void
2634 print_open(const struct syscallname *name,
2635 abi_long arg0, abi_long arg1, abi_long arg2,
2636 abi_long arg3, abi_long arg4, abi_long arg5)
2638 int is_creat = (arg1 & TARGET_O_CREAT);
2640 print_syscall_prologue(name);
2641 print_string(arg0, 0);
2642 print_open_flags(arg1, (is_creat == 0));
2643 if (is_creat)
2644 print_file_mode(arg2, 1);
2645 print_syscall_epilogue(name);
2647 #endif
2649 #ifdef TARGET_NR_openat
2650 static void
2651 print_openat(const struct syscallname *name,
2652 abi_long arg0, abi_long arg1, abi_long arg2,
2653 abi_long arg3, abi_long arg4, abi_long arg5)
2655 int is_creat = (arg2 & TARGET_O_CREAT);
2657 print_syscall_prologue(name);
2658 print_at_dirfd(arg0, 0);
2659 print_string(arg1, 0);
2660 print_open_flags(arg2, (is_creat == 0));
2661 if (is_creat)
2662 print_file_mode(arg3, 1);
2663 print_syscall_epilogue(name);
2665 #endif
2667 #ifdef TARGET_NR_mq_unlink
2668 static void
2669 print_mq_unlink(const struct syscallname *name,
2670 abi_long arg0, abi_long arg1, abi_long arg2,
2671 abi_long arg3, abi_long arg4, abi_long arg5)
2673 print_syscall_prologue(name);
2674 print_string(arg0, 1);
2675 print_syscall_epilogue(name);
2677 #endif
2679 #if defined(TARGET_NR_fstatat64) || defined(TARGET_NR_newfstatat)
2680 static void
2681 print_fstatat64(const struct syscallname *name,
2682 abi_long arg0, abi_long arg1, abi_long arg2,
2683 abi_long arg3, abi_long arg4, abi_long arg5)
2685 print_syscall_prologue(name);
2686 print_at_dirfd(arg0, 0);
2687 print_string(arg1, 0);
2688 print_pointer(arg2, 0);
2689 print_flags(at_file_flags, arg3, 1);
2690 print_syscall_epilogue(name);
2692 #define print_newfstatat print_fstatat64
2693 #endif
2695 #ifdef TARGET_NR_readlink
2696 static void
2697 print_readlink(const struct syscallname *name,
2698 abi_long arg0, abi_long arg1, abi_long arg2,
2699 abi_long arg3, abi_long arg4, abi_long arg5)
2701 print_syscall_prologue(name);
2702 print_string(arg0, 0);
2703 print_pointer(arg1, 0);
2704 print_raw_param("%u", arg2, 1);
2705 print_syscall_epilogue(name);
2707 #endif
2709 #ifdef TARGET_NR_readlinkat
2710 static void
2711 print_readlinkat(const struct syscallname *name,
2712 abi_long arg0, abi_long arg1, abi_long arg2,
2713 abi_long arg3, abi_long arg4, abi_long arg5)
2715 print_syscall_prologue(name);
2716 print_at_dirfd(arg0, 0);
2717 print_string(arg1, 0);
2718 print_pointer(arg2, 0);
2719 print_raw_param("%u", arg3, 1);
2720 print_syscall_epilogue(name);
2722 #endif
2724 #ifdef TARGET_NR_rename
2725 static void
2726 print_rename(const struct syscallname *name,
2727 abi_long arg0, abi_long arg1, abi_long arg2,
2728 abi_long arg3, abi_long arg4, abi_long arg5)
2730 print_syscall_prologue(name);
2731 print_string(arg0, 0);
2732 print_string(arg1, 1);
2733 print_syscall_epilogue(name);
2735 #endif
2737 #ifdef TARGET_NR_renameat
2738 static void
2739 print_renameat(const struct syscallname *name,
2740 abi_long arg0, abi_long arg1, abi_long arg2,
2741 abi_long arg3, abi_long arg4, abi_long arg5)
2743 print_syscall_prologue(name);
2744 print_at_dirfd(arg0, 0);
2745 print_string(arg1, 0);
2746 print_at_dirfd(arg2, 0);
2747 print_string(arg3, 1);
2748 print_syscall_epilogue(name);
2750 #endif
2752 #ifdef TARGET_NR_statfs
2753 static void
2754 print_statfs(const struct syscallname *name,
2755 abi_long arg0, abi_long arg1, abi_long arg2,
2756 abi_long arg3, abi_long arg4, abi_long arg5)
2758 print_syscall_prologue(name);
2759 print_string(arg0, 0);
2760 print_pointer(arg1, 1);
2761 print_syscall_epilogue(name);
2763 #endif
2765 #ifdef TARGET_NR_statfs64
2766 static void
2767 print_statfs64(const struct syscallname *name,
2768 abi_long arg0, abi_long arg1, abi_long arg2,
2769 abi_long arg3, abi_long arg4, abi_long arg5)
2771 print_syscall_prologue(name);
2772 print_string(arg0, 0);
2773 print_pointer(arg1, 1);
2774 print_syscall_epilogue(name);
2776 #endif
2778 #ifdef TARGET_NR_symlink
2779 static void
2780 print_symlink(const struct syscallname *name,
2781 abi_long arg0, abi_long arg1, abi_long arg2,
2782 abi_long arg3, abi_long arg4, abi_long arg5)
2784 print_syscall_prologue(name);
2785 print_string(arg0, 0);
2786 print_string(arg1, 1);
2787 print_syscall_epilogue(name);
2789 #endif
2791 #ifdef TARGET_NR_symlinkat
2792 static void
2793 print_symlinkat(const struct syscallname *name,
2794 abi_long arg0, abi_long arg1, abi_long arg2,
2795 abi_long arg3, abi_long arg4, abi_long arg5)
2797 print_syscall_prologue(name);
2798 print_string(arg0, 0);
2799 print_at_dirfd(arg1, 0);
2800 print_string(arg2, 1);
2801 print_syscall_epilogue(name);
2803 #endif
2805 #ifdef TARGET_NR_mount
2806 static void
2807 print_mount(const struct syscallname *name,
2808 abi_long arg0, abi_long arg1, abi_long arg2,
2809 abi_long arg3, abi_long arg4, abi_long arg5)
2811 print_syscall_prologue(name);
2812 print_string(arg0, 0);
2813 print_string(arg1, 0);
2814 print_string(arg2, 0);
2815 print_flags(mount_flags, arg3, 0);
2816 print_pointer(arg4, 1);
2817 print_syscall_epilogue(name);
2819 #endif
2821 #ifdef TARGET_NR_umount
2822 static void
2823 print_umount(const struct syscallname *name,
2824 abi_long arg0, abi_long arg1, abi_long arg2,
2825 abi_long arg3, abi_long arg4, abi_long arg5)
2827 print_syscall_prologue(name);
2828 print_string(arg0, 1);
2829 print_syscall_epilogue(name);
2831 #endif
2833 #ifdef TARGET_NR_umount2
2834 static void
2835 print_umount2(const struct syscallname *name,
2836 abi_long arg0, abi_long arg1, abi_long arg2,
2837 abi_long arg3, abi_long arg4, abi_long arg5)
2839 print_syscall_prologue(name);
2840 print_string(arg0, 0);
2841 print_flags(umount2_flags, arg1, 1);
2842 print_syscall_epilogue(name);
2844 #endif
2846 #ifdef TARGET_NR_unlink
2847 static void
2848 print_unlink(const struct syscallname *name,
2849 abi_long arg0, abi_long arg1, abi_long arg2,
2850 abi_long arg3, abi_long arg4, abi_long arg5)
2852 print_syscall_prologue(name);
2853 print_string(arg0, 1);
2854 print_syscall_epilogue(name);
2856 #endif
2858 #ifdef TARGET_NR_unlinkat
2859 static void
2860 print_unlinkat(const struct syscallname *name,
2861 abi_long arg0, abi_long arg1, abi_long arg2,
2862 abi_long arg3, abi_long arg4, abi_long arg5)
2864 print_syscall_prologue(name);
2865 print_at_dirfd(arg0, 0);
2866 print_string(arg1, 0);
2867 print_flags(unlinkat_flags, arg2, 1);
2868 print_syscall_epilogue(name);
2870 #endif
2872 #ifdef TARGET_NR_utime
2873 static void
2874 print_utime(const struct syscallname *name,
2875 abi_long arg0, abi_long arg1, abi_long arg2,
2876 abi_long arg3, abi_long arg4, abi_long arg5)
2878 print_syscall_prologue(name);
2879 print_string(arg0, 0);
2880 print_pointer(arg1, 1);
2881 print_syscall_epilogue(name);
2883 #endif
2885 #ifdef TARGET_NR_utimes
2886 static void
2887 print_utimes(const struct syscallname *name,
2888 abi_long arg0, abi_long arg1, abi_long arg2,
2889 abi_long arg3, abi_long arg4, abi_long arg5)
2891 print_syscall_prologue(name);
2892 print_string(arg0, 0);
2893 print_pointer(arg1, 1);
2894 print_syscall_epilogue(name);
2896 #endif
2898 #ifdef TARGET_NR_utimensat
2899 static void
2900 print_utimensat(const struct syscallname *name,
2901 abi_long arg0, abi_long arg1, abi_long arg2,
2902 abi_long arg3, abi_long arg4, abi_long arg5)
2904 print_syscall_prologue(name);
2905 print_at_dirfd(arg0, 0);
2906 print_string(arg1, 0);
2907 print_pointer(arg2, 0);
2908 print_flags(at_file_flags, arg3, 1);
2909 print_syscall_epilogue(name);
2911 #endif
2913 #if defined(TARGET_NR_mmap) || defined(TARGET_NR_mmap2)
2914 static void
2915 print_mmap(const struct syscallname *name,
2916 abi_long arg0, abi_long arg1, abi_long arg2,
2917 abi_long arg3, abi_long arg4, abi_long arg5)
2919 print_syscall_prologue(name);
2920 print_pointer(arg0, 0);
2921 print_raw_param("%d", arg1, 0);
2922 print_flags(mmap_prot_flags, arg2, 0);
2923 print_flags(mmap_flags, arg3, 0);
2924 print_raw_param("%d", arg4, 0);
2925 print_raw_param("%#x", arg5, 1);
2926 print_syscall_epilogue(name);
2928 #define print_mmap2 print_mmap
2929 #endif
2931 #ifdef TARGET_NR_mprotect
2932 static void
2933 print_mprotect(const struct syscallname *name,
2934 abi_long arg0, abi_long arg1, abi_long arg2,
2935 abi_long arg3, abi_long arg4, abi_long arg5)
2937 print_syscall_prologue(name);
2938 print_pointer(arg0, 0);
2939 print_raw_param("%d", arg1, 0);
2940 print_flags(mmap_prot_flags, arg2, 1);
2941 print_syscall_epilogue(name);
2943 #endif
2945 #ifdef TARGET_NR_munmap
2946 static void
2947 print_munmap(const struct syscallname *name,
2948 abi_long arg0, abi_long arg1, abi_long arg2,
2949 abi_long arg3, abi_long arg4, abi_long arg5)
2951 print_syscall_prologue(name);
2952 print_pointer(arg0, 0);
2953 print_raw_param("%d", arg1, 1);
2954 print_syscall_epilogue(name);
2956 #endif
2958 #ifdef TARGET_NR_futex
2959 static void print_futex_op(abi_long tflag, int last)
2961 #define print_op(val) \
2962 if( cmd == val ) { \
2963 qemu_log(#val); \
2964 return; \
2967 int cmd = (int)tflag;
2968 #ifdef FUTEX_PRIVATE_FLAG
2969 if (cmd & FUTEX_PRIVATE_FLAG) {
2970 qemu_log("FUTEX_PRIVATE_FLAG|");
2971 cmd &= ~FUTEX_PRIVATE_FLAG;
2973 #endif
2974 #ifdef FUTEX_CLOCK_REALTIME
2975 if (cmd & FUTEX_CLOCK_REALTIME) {
2976 qemu_log("FUTEX_CLOCK_REALTIME|");
2977 cmd &= ~FUTEX_CLOCK_REALTIME;
2979 #endif
2980 print_op(FUTEX_WAIT)
2981 print_op(FUTEX_WAKE)
2982 print_op(FUTEX_FD)
2983 print_op(FUTEX_REQUEUE)
2984 print_op(FUTEX_CMP_REQUEUE)
2985 print_op(FUTEX_WAKE_OP)
2986 print_op(FUTEX_LOCK_PI)
2987 print_op(FUTEX_UNLOCK_PI)
2988 print_op(FUTEX_TRYLOCK_PI)
2989 #ifdef FUTEX_WAIT_BITSET
2990 print_op(FUTEX_WAIT_BITSET)
2991 #endif
2992 #ifdef FUTEX_WAKE_BITSET
2993 print_op(FUTEX_WAKE_BITSET)
2994 #endif
2995 /* unknown values */
2996 qemu_log("%d", cmd);
2999 static void
3000 print_futex(const struct syscallname *name,
3001 abi_long arg0, abi_long arg1, abi_long arg2,
3002 abi_long arg3, abi_long arg4, abi_long arg5)
3004 print_syscall_prologue(name);
3005 print_pointer(arg0, 0);
3006 print_futex_op(arg1, 0);
3007 print_raw_param(",%d", arg2, 0);
3008 print_pointer(arg3, 0); /* struct timespec */
3009 print_pointer(arg4, 0);
3010 print_raw_param("%d", arg4, 1);
3011 print_syscall_epilogue(name);
3013 #endif
3015 #ifdef TARGET_NR_kill
3016 static void
3017 print_kill(const struct syscallname *name,
3018 abi_long arg0, abi_long arg1, abi_long arg2,
3019 abi_long arg3, abi_long arg4, abi_long arg5)
3021 print_syscall_prologue(name);
3022 print_raw_param("%d", arg0, 0);
3023 print_signal(arg1, 1);
3024 print_syscall_epilogue(name);
3026 #endif
3028 #ifdef TARGET_NR_tkill
3029 static void
3030 print_tkill(const struct syscallname *name,
3031 abi_long arg0, abi_long arg1, abi_long arg2,
3032 abi_long arg3, abi_long arg4, abi_long arg5)
3034 print_syscall_prologue(name);
3035 print_raw_param("%d", arg0, 0);
3036 print_signal(arg1, 1);
3037 print_syscall_epilogue(name);
3039 #endif
3041 #ifdef TARGET_NR_tgkill
3042 static void
3043 print_tgkill(const struct syscallname *name,
3044 abi_long arg0, abi_long arg1, abi_long arg2,
3045 abi_long arg3, abi_long arg4, abi_long arg5)
3047 print_syscall_prologue(name);
3048 print_raw_param("%d", arg0, 0);
3049 print_raw_param("%d", arg1, 0);
3050 print_signal(arg2, 1);
3051 print_syscall_epilogue(name);
3053 #endif
3055 #ifdef TARGET_NR_statx
3056 static void
3057 print_statx(const struct syscallname *name,
3058 abi_long arg0, abi_long arg1, abi_long arg2,
3059 abi_long arg3, abi_long arg4, abi_long arg5)
3061 print_syscall_prologue(name);
3062 print_at_dirfd(arg0, 0);
3063 print_string(arg1, 0);
3064 print_flags(statx_flags, arg2, 0);
3065 print_flags(statx_mask, arg3, 0);
3066 print_pointer(arg4, 1);
3067 print_syscall_epilogue(name);
3069 #endif
3071 #ifdef TARGET_NR_ioctl
3072 static void
3073 print_ioctl(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 print_syscall_prologue(name);
3078 print_raw_param("%d", arg0, 0);
3080 const IOCTLEntry *ie;
3081 const argtype *arg_type;
3082 void *argptr;
3083 int target_size;
3085 for (ie = ioctl_entries; ie->target_cmd != 0; ie++) {
3086 if (ie->target_cmd == arg1) {
3087 break;
3091 if (ie->target_cmd == 0) {
3092 print_raw_param("%#x", arg1, 0);
3093 print_raw_param("%#x", arg2, 1);
3094 } else {
3095 qemu_log("%s", ie->name);
3096 arg_type = ie->arg_type;
3098 if (arg_type[0] != TYPE_NULL) {
3099 qemu_log(",");
3101 switch (arg_type[0]) {
3102 case TYPE_PTRVOID:
3103 print_pointer(arg2, 1);
3104 break;
3105 case TYPE_CHAR:
3106 case TYPE_SHORT:
3107 case TYPE_INT:
3108 print_raw_param("%d", arg2, 1);
3109 break;
3110 case TYPE_LONG:
3111 print_raw_param(TARGET_ABI_FMT_ld, arg2, 1);
3112 break;
3113 case TYPE_ULONG:
3114 print_raw_param(TARGET_ABI_FMT_lu, arg2, 1);
3115 break;
3116 case TYPE_PTR:
3117 switch (ie->access) {
3118 case IOC_R:
3119 print_pointer(arg2, 1);
3120 break;
3121 case IOC_W:
3122 case IOC_RW:
3123 arg_type++;
3124 target_size = thunk_type_size(arg_type, 0);
3125 argptr = lock_user(VERIFY_READ, arg2, target_size, 1);
3126 if (argptr) {
3127 thunk_print(argptr, arg_type);
3128 unlock_user(argptr, arg2, target_size);
3129 } else {
3130 print_pointer(arg2, 1);
3132 break;
3134 break;
3135 default:
3136 g_assert_not_reached();
3140 print_syscall_epilogue(name);
3142 #endif
3145 * An array of all of the syscalls we know about
3148 static const struct syscallname scnames[] = {
3149 #include "strace.list"
3152 static int nsyscalls = ARRAY_SIZE(scnames);
3155 * The public interface to this module.
3157 void
3158 print_syscall(int num,
3159 abi_long arg1, abi_long arg2, abi_long arg3,
3160 abi_long arg4, abi_long arg5, abi_long arg6)
3162 int i;
3163 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 ")";
3165 qemu_log("%d ", getpid());
3167 for(i=0;i<nsyscalls;i++)
3168 if( scnames[i].nr == num ) {
3169 if( scnames[i].call != NULL ) {
3170 scnames[i].call(
3171 &scnames[i], arg1, arg2, arg3, arg4, arg5, arg6);
3172 } else {
3173 /* XXX: this format system is broken because it uses
3174 host types and host pointers for strings */
3175 if( scnames[i].format != NULL )
3176 format = scnames[i].format;
3177 qemu_log(format,
3178 scnames[i].name, arg1, arg2, arg3, arg4, arg5, arg6);
3180 return;
3182 qemu_log("Unknown syscall %d\n", num);
3186 void
3187 print_syscall_ret(int num, abi_long ret,
3188 abi_long arg1, abi_long arg2, abi_long arg3,
3189 abi_long arg4, abi_long arg5, abi_long arg6)
3191 int i;
3193 for(i=0;i<nsyscalls;i++)
3194 if( scnames[i].nr == num ) {
3195 if( scnames[i].result != NULL ) {
3196 scnames[i].result(&scnames[i], ret,
3197 arg1, arg2, arg3,
3198 arg4, arg5, arg6);
3199 } else {
3200 print_syscall_err(ret);
3202 if (ret >= 0) {
3203 qemu_log(TARGET_ABI_FMT_ld, ret);
3205 qemu_log("\n");
3207 break;
3211 void print_taken_signal(int target_signum, const target_siginfo_t *tinfo)
3213 /* Print the strace output for a signal being taken:
3214 * --- SIGSEGV {si_signo=SIGSEGV, si_code=SI_KERNEL, si_addr=0} ---
3216 qemu_log("--- ");
3217 print_signal(target_signum, 1);
3218 qemu_log(" ");
3219 print_siginfo(tinfo);
3220 qemu_log(" ---\n");