linux-user: Add strace support for printing arguments of truncate()/ftruncate() and...
[qemu/ar7.git] / linux-user / strace.c
blob31c7be24ebfd0bc0933b38426f0e111cb72c5b2f
1 #include "qemu/osdep.h"
2 #include <sys/ipc.h>
3 #include <sys/msg.h>
4 #include <sys/sem.h>
5 #include <sys/shm.h>
6 #include <sys/select.h>
7 #include <sys/mount.h>
8 #include <arpa/inet.h>
9 #include <netinet/tcp.h>
10 #include <linux/if_packet.h>
11 #include <linux/netlink.h>
12 #include <sched.h>
13 #include "qemu.h"
15 struct syscallname {
16 int nr;
17 const char *name;
18 const char *format;
19 void (*call)(void *, const struct syscallname *,
20 abi_long, abi_long, abi_long,
21 abi_long, abi_long, abi_long);
22 void (*result)(void *, const struct syscallname *, abi_long,
23 abi_long, abi_long, abi_long,
24 abi_long, abi_long, abi_long);
27 #ifdef __GNUC__
29 * It is possible that target doesn't have syscall that uses
30 * following flags but we don't want the compiler to warn
31 * us about them being unused. Same applies to utility print
32 * functions. It is ok to keep them while not used.
34 #define UNUSED __attribute__ ((unused))
35 #else
36 #define UNUSED
37 #endif
40 * Structure used to translate flag values into strings. This is
41 * similar that is in the actual strace tool.
43 struct flags {
44 abi_long f_value; /* flag */
45 const char *f_string; /* stringified flag */
48 /* common flags for all architectures */
49 #define FLAG_GENERIC(name) { name, #name }
50 /* target specific flags (syscall_defs.h has TARGET_<flag>) */
51 #define FLAG_TARGET(name) { TARGET_ ## name, #name }
52 /* end of flags array */
53 #define FLAG_END { 0, NULL }
55 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;
544 int first = 1;
546 qemu_log("[");
547 if( target_fds_addr ) {
548 abi_long *target_fds;
550 target_fds = lock_user(VERIFY_READ,
551 target_fds_addr,
552 sizeof(*target_fds)*(n / TARGET_ABI_BITS + 1),
555 if (!target_fds)
556 return;
558 for (i=n; i>=0; i--) {
559 if ((tswapal(target_fds[i / TARGET_ABI_BITS]) >>
560 (i & (TARGET_ABI_BITS - 1))) & 1) {
561 qemu_log("%s%d", get_comma(first), i);
562 first = 0;
565 unlock_user(target_fds, target_fds_addr, 0);
567 qemu_log("]");
569 #endif
571 #ifdef TARGET_NR_clock_adjtime
572 /* IDs of the various system clocks */
573 #define TARGET_CLOCK_REALTIME 0
574 #define TARGET_CLOCK_MONOTONIC 1
575 #define TARGET_CLOCK_PROCESS_CPUTIME_ID 2
576 #define TARGET_CLOCK_THREAD_CPUTIME_ID 3
577 #define TARGET_CLOCK_MONOTONIC_RAW 4
578 #define TARGET_CLOCK_REALTIME_COARSE 5
579 #define TARGET_CLOCK_MONOTONIC_COARSE 6
580 #define TARGET_CLOCK_BOOTTIME 7
581 #define TARGET_CLOCK_REALTIME_ALARM 8
582 #define TARGET_CLOCK_BOOTTIME_ALARM 9
583 #define TARGET_CLOCK_SGI_CYCLE 10
584 #define TARGET_CLOCK_TAI 11
586 static void
587 print_clockid(int clockid, int last)
589 switch (clockid) {
590 case TARGET_CLOCK_REALTIME:
591 qemu_log("CLOCK_REALTIME");
592 break;
593 case TARGET_CLOCK_MONOTONIC:
594 qemu_log("CLOCK_MONOTONIC");
595 break;
596 case TARGET_CLOCK_PROCESS_CPUTIME_ID:
597 qemu_log("CLOCK_PROCESS_CPUTIME_ID");
598 break;
599 case TARGET_CLOCK_THREAD_CPUTIME_ID:
600 qemu_log("CLOCK_THREAD_CPUTIME_ID");
601 break;
602 case TARGET_CLOCK_MONOTONIC_RAW:
603 qemu_log("CLOCK_MONOTONIC_RAW");
604 break;
605 case TARGET_CLOCK_REALTIME_COARSE:
606 qemu_log("CLOCK_REALTIME_COARSE");
607 break;
608 case TARGET_CLOCK_MONOTONIC_COARSE:
609 qemu_log("CLOCK_MONOTONIC_COARSE");
610 break;
611 case TARGET_CLOCK_BOOTTIME:
612 qemu_log("CLOCK_BOOTTIME");
613 break;
614 case TARGET_CLOCK_REALTIME_ALARM:
615 qemu_log("CLOCK_REALTIME_ALARM");
616 break;
617 case TARGET_CLOCK_BOOTTIME_ALARM:
618 qemu_log("CLOCK_BOOTTIME_ALARM");
619 break;
620 case TARGET_CLOCK_SGI_CYCLE:
621 qemu_log("CLOCK_SGI_CYCLE");
622 break;
623 case TARGET_CLOCK_TAI:
624 qemu_log("CLOCK_TAI");
625 break;
626 default:
627 qemu_log("%d", clockid);
628 break;
630 qemu_log("%s", get_comma(last));
632 #endif
635 * Sysycall specific output functions
638 /* select */
639 #ifdef TARGET_NR__newselect
640 static void
641 print_newselect(void *cpu_env, const struct syscallname *name,
642 abi_long arg1, abi_long arg2, abi_long arg3,
643 abi_long arg4, abi_long arg5, abi_long arg6)
645 print_syscall_prologue(name);
646 print_fdset(arg1, arg2);
647 qemu_log(",");
648 print_fdset(arg1, arg3);
649 qemu_log(",");
650 print_fdset(arg1, arg4);
651 qemu_log(",");
652 print_timeval(arg5, 1);
653 print_syscall_epilogue(name);
655 #endif
657 #ifdef TARGET_NR_semctl
658 static void
659 print_semctl(void *cpu_env, const struct syscallname *name,
660 abi_long arg1, abi_long arg2, abi_long arg3,
661 abi_long arg4, abi_long arg5, abi_long arg6)
663 qemu_log("%s(" TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld ",",
664 name->name, arg1, arg2);
665 print_ipc_cmd(arg3);
666 qemu_log(",0x" TARGET_ABI_FMT_lx ")", arg4);
668 #endif
670 static void
671 print_execve(void *cpu_env, const struct syscallname *name,
672 abi_long arg1, abi_long arg2, abi_long arg3,
673 abi_long arg4, abi_long arg5, abi_long arg6)
675 abi_ulong arg_ptr_addr;
676 char *s;
678 if (!(s = lock_user_string(arg1)))
679 return;
680 qemu_log("%s(\"%s\",{", name->name, s);
681 unlock_user(s, arg1, 0);
683 for (arg_ptr_addr = arg2; ; arg_ptr_addr += sizeof(abi_ulong)) {
684 abi_ulong *arg_ptr, arg_addr;
686 arg_ptr = lock_user(VERIFY_READ, arg_ptr_addr, sizeof(abi_ulong), 1);
687 if (!arg_ptr)
688 return;
689 arg_addr = tswapal(*arg_ptr);
690 unlock_user(arg_ptr, arg_ptr_addr, 0);
691 if (!arg_addr)
692 break;
693 if ((s = lock_user_string(arg_addr))) {
694 qemu_log("\"%s\",", s);
695 unlock_user(s, arg_addr, 0);
699 qemu_log("NULL})");
702 #ifdef TARGET_NR_ipc
703 static void
704 print_ipc(void *cpu_env, const struct syscallname *name,
705 abi_long arg1, abi_long arg2, abi_long arg3,
706 abi_long arg4, abi_long arg5, abi_long arg6)
708 switch(arg1) {
709 case IPCOP_semctl:
710 qemu_log("semctl(" TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld ",",
711 arg1, arg2);
712 print_ipc_cmd(arg3);
713 qemu_log(",0x" TARGET_ABI_FMT_lx ")", arg4);
714 break;
715 default:
716 qemu_log(("%s("
717 TARGET_ABI_FMT_ld ","
718 TARGET_ABI_FMT_ld ","
719 TARGET_ABI_FMT_ld ","
720 TARGET_ABI_FMT_ld
721 ")"),
722 name->name, arg1, arg2, arg3, arg4);
725 #endif
728 * Variants for the return value output function
731 static bool
732 print_syscall_err(abi_long ret)
734 const char *errstr;
736 qemu_log(" = ");
737 if (ret < 0) {
738 errstr = target_strerror(-ret);
739 if (errstr) {
740 qemu_log("-1 errno=%d (%s)", (int)-ret, errstr);
741 return true;
744 return false;
747 static void
748 print_syscall_ret_addr(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("0x" TARGET_ABI_FMT_lx, ret);
756 qemu_log("\n");
759 #if 0 /* currently unused */
760 static void
761 print_syscall_ret_raw(struct syscallname *name, abi_long ret)
763 qemu_log(" = 0x" TARGET_ABI_FMT_lx "\n", ret);
765 #endif
767 #ifdef TARGET_NR__newselect
768 static void
769 print_syscall_ret_newselect(void *cpu_env, const struct syscallname *name,
770 abi_long ret, abi_long arg0, abi_long arg1,
771 abi_long arg2, abi_long arg3, abi_long arg4,
772 abi_long arg5)
774 if (!print_syscall_err(ret)) {
775 qemu_log(" = 0x" TARGET_ABI_FMT_lx " (", ret);
776 print_fdset(arg0, arg1);
777 qemu_log(",");
778 print_fdset(arg0, arg2);
779 qemu_log(",");
780 print_fdset(arg0, arg3);
781 qemu_log(",");
782 print_timeval(arg4, 1);
783 qemu_log(")");
786 qemu_log("\n");
788 #endif
790 /* special meanings of adjtimex()' non-negative return values */
791 #define TARGET_TIME_OK 0 /* clock synchronized, no leap second */
792 #define TARGET_TIME_INS 1 /* insert leap second */
793 #define TARGET_TIME_DEL 2 /* delete leap second */
794 #define TARGET_TIME_OOP 3 /* leap second in progress */
795 #define TARGET_TIME_WAIT 4 /* leap second has occurred */
796 #define TARGET_TIME_ERROR 5 /* clock not synchronized */
797 #ifdef TARGET_NR_adjtimex
798 static void
799 print_syscall_ret_adjtimex(void *cpu_env, const struct syscallname *name,
800 abi_long ret, abi_long arg0, abi_long arg1,
801 abi_long arg2, abi_long arg3, abi_long arg4,
802 abi_long arg5)
804 if (!print_syscall_err(ret)) {
805 qemu_log(TARGET_ABI_FMT_ld, ret);
806 switch (ret) {
807 case TARGET_TIME_OK:
808 qemu_log(" TIME_OK (clock synchronized, no leap second)");
809 break;
810 case TARGET_TIME_INS:
811 qemu_log(" TIME_INS (insert leap second)");
812 break;
813 case TARGET_TIME_DEL:
814 qemu_log(" TIME_DEL (delete leap second)");
815 break;
816 case TARGET_TIME_OOP:
817 qemu_log(" TIME_OOP (leap second in progress)");
818 break;
819 case TARGET_TIME_WAIT:
820 qemu_log(" TIME_WAIT (leap second has occurred)");
821 break;
822 case TARGET_TIME_ERROR:
823 qemu_log(" TIME_ERROR (clock not synchronized)");
824 break;
828 qemu_log("\n");
830 #endif
832 #if defined(TARGET_NR_listxattr) || defined(TARGET_NR_llistxattr) \
833 || defined(TARGGET_NR_flistxattr)
834 static void
835 print_syscall_ret_listxattr(void *cpu_env, const struct syscallname *name,
836 abi_long ret, abi_long arg0, abi_long arg1,
837 abi_long arg2, abi_long arg3, abi_long arg4,
838 abi_long arg5)
840 if (!print_syscall_err(ret)) {
841 qemu_log(TARGET_ABI_FMT_ld, ret);
842 qemu_log(" (list = ");
843 if (arg1 != 0) {
844 abi_long attr = arg1;
845 while (ret) {
846 if (attr != arg1) {
847 qemu_log(",");
849 print_string(attr, 1);
850 ret -= target_strlen(attr) + 1;
851 attr += target_strlen(attr) + 1;
853 } else {
854 qemu_log("NULL");
856 qemu_log(")");
859 qemu_log("\n");
861 #define print_syscall_ret_llistxattr print_syscall_ret_listxattr
862 #define print_syscall_ret_flistxattr print_syscall_ret_listxattr
863 #endif
865 #ifdef TARGET_NR_ioctl
866 static void
867 print_syscall_ret_ioctl(void *cpu_env, const struct syscallname *name,
868 abi_long ret, abi_long arg0, abi_long arg1,
869 abi_long arg2, abi_long arg3, abi_long arg4,
870 abi_long arg5)
872 if (!print_syscall_err(ret)) {
873 qemu_log(TARGET_ABI_FMT_ld, ret);
875 const IOCTLEntry *ie;
876 const argtype *arg_type;
877 void *argptr;
878 int target_size;
880 for (ie = ioctl_entries; ie->target_cmd != 0; ie++) {
881 if (ie->target_cmd == arg1) {
882 break;
886 if (ie->target_cmd == arg1 &&
887 (ie->access == IOC_R || ie->access == IOC_RW)) {
888 arg_type = ie->arg_type;
889 qemu_log(" (");
890 arg_type++;
891 target_size = thunk_type_size(arg_type, 0);
892 argptr = lock_user(VERIFY_READ, arg2, target_size, 1);
893 if (argptr) {
894 thunk_print(argptr, arg_type);
895 unlock_user(argptr, arg2, target_size);
896 } else {
897 print_pointer(arg2, 1);
899 qemu_log(")");
902 qemu_log("\n");
904 #endif
906 UNUSED static struct flags access_flags[] = {
907 FLAG_GENERIC(F_OK),
908 FLAG_GENERIC(R_OK),
909 FLAG_GENERIC(W_OK),
910 FLAG_GENERIC(X_OK),
911 FLAG_END,
914 UNUSED static struct flags at_file_flags[] = {
915 #ifdef AT_EACCESS
916 FLAG_GENERIC(AT_EACCESS),
917 #endif
918 #ifdef AT_SYMLINK_NOFOLLOW
919 FLAG_GENERIC(AT_SYMLINK_NOFOLLOW),
920 #endif
921 FLAG_END,
924 UNUSED static struct flags unlinkat_flags[] = {
925 #ifdef AT_REMOVEDIR
926 FLAG_GENERIC(AT_REMOVEDIR),
927 #endif
928 FLAG_END,
931 UNUSED static struct flags mode_flags[] = {
932 FLAG_GENERIC(S_IFSOCK),
933 FLAG_GENERIC(S_IFLNK),
934 FLAG_GENERIC(S_IFREG),
935 FLAG_GENERIC(S_IFBLK),
936 FLAG_GENERIC(S_IFDIR),
937 FLAG_GENERIC(S_IFCHR),
938 FLAG_GENERIC(S_IFIFO),
939 FLAG_END,
942 UNUSED static struct flags open_access_flags[] = {
943 FLAG_TARGET(O_RDONLY),
944 FLAG_TARGET(O_WRONLY),
945 FLAG_TARGET(O_RDWR),
946 FLAG_END,
949 UNUSED static struct flags open_flags[] = {
950 FLAG_TARGET(O_APPEND),
951 FLAG_TARGET(O_CREAT),
952 FLAG_TARGET(O_DIRECTORY),
953 FLAG_TARGET(O_EXCL),
954 FLAG_TARGET(O_LARGEFILE),
955 FLAG_TARGET(O_NOCTTY),
956 FLAG_TARGET(O_NOFOLLOW),
957 FLAG_TARGET(O_NONBLOCK), /* also O_NDELAY */
958 FLAG_TARGET(O_DSYNC),
959 FLAG_TARGET(__O_SYNC),
960 FLAG_TARGET(O_TRUNC),
961 #ifdef O_DIRECT
962 FLAG_TARGET(O_DIRECT),
963 #endif
964 #ifdef O_NOATIME
965 FLAG_TARGET(O_NOATIME),
966 #endif
967 #ifdef O_CLOEXEC
968 FLAG_TARGET(O_CLOEXEC),
969 #endif
970 #ifdef O_PATH
971 FLAG_TARGET(O_PATH),
972 #endif
973 #ifdef O_TMPFILE
974 FLAG_TARGET(O_TMPFILE),
975 FLAG_TARGET(__O_TMPFILE),
976 #endif
977 FLAG_END,
980 UNUSED static struct flags mount_flags[] = {
981 #ifdef MS_BIND
982 FLAG_GENERIC(MS_BIND),
983 #endif
984 #ifdef MS_DIRSYNC
985 FLAG_GENERIC(MS_DIRSYNC),
986 #endif
987 FLAG_GENERIC(MS_MANDLOCK),
988 #ifdef MS_MOVE
989 FLAG_GENERIC(MS_MOVE),
990 #endif
991 FLAG_GENERIC(MS_NOATIME),
992 FLAG_GENERIC(MS_NODEV),
993 FLAG_GENERIC(MS_NODIRATIME),
994 FLAG_GENERIC(MS_NOEXEC),
995 FLAG_GENERIC(MS_NOSUID),
996 FLAG_GENERIC(MS_RDONLY),
997 #ifdef MS_RELATIME
998 FLAG_GENERIC(MS_RELATIME),
999 #endif
1000 FLAG_GENERIC(MS_REMOUNT),
1001 FLAG_GENERIC(MS_SYNCHRONOUS),
1002 FLAG_END,
1005 UNUSED static struct flags umount2_flags[] = {
1006 #ifdef MNT_FORCE
1007 FLAG_GENERIC(MNT_FORCE),
1008 #endif
1009 #ifdef MNT_DETACH
1010 FLAG_GENERIC(MNT_DETACH),
1011 #endif
1012 #ifdef MNT_EXPIRE
1013 FLAG_GENERIC(MNT_EXPIRE),
1014 #endif
1015 FLAG_END,
1018 UNUSED static struct flags mmap_prot_flags[] = {
1019 FLAG_GENERIC(PROT_NONE),
1020 FLAG_GENERIC(PROT_EXEC),
1021 FLAG_GENERIC(PROT_READ),
1022 FLAG_GENERIC(PROT_WRITE),
1023 FLAG_TARGET(PROT_SEM),
1024 FLAG_GENERIC(PROT_GROWSDOWN),
1025 FLAG_GENERIC(PROT_GROWSUP),
1026 FLAG_END,
1029 UNUSED static struct flags mmap_flags[] = {
1030 FLAG_TARGET(MAP_SHARED),
1031 FLAG_TARGET(MAP_PRIVATE),
1032 FLAG_TARGET(MAP_ANONYMOUS),
1033 FLAG_TARGET(MAP_DENYWRITE),
1034 FLAG_TARGET(MAP_FIXED),
1035 FLAG_TARGET(MAP_GROWSDOWN),
1036 FLAG_TARGET(MAP_EXECUTABLE),
1037 #ifdef MAP_LOCKED
1038 FLAG_TARGET(MAP_LOCKED),
1039 #endif
1040 #ifdef MAP_NONBLOCK
1041 FLAG_TARGET(MAP_NONBLOCK),
1042 #endif
1043 FLAG_TARGET(MAP_NORESERVE),
1044 #ifdef MAP_POPULATE
1045 FLAG_TARGET(MAP_POPULATE),
1046 #endif
1047 #ifdef TARGET_MAP_UNINITIALIZED
1048 FLAG_TARGET(MAP_UNINITIALIZED),
1049 #endif
1050 FLAG_END,
1053 UNUSED static struct flags clone_flags[] = {
1054 FLAG_GENERIC(CLONE_VM),
1055 FLAG_GENERIC(CLONE_FS),
1056 FLAG_GENERIC(CLONE_FILES),
1057 FLAG_GENERIC(CLONE_SIGHAND),
1058 FLAG_GENERIC(CLONE_PTRACE),
1059 FLAG_GENERIC(CLONE_VFORK),
1060 FLAG_GENERIC(CLONE_PARENT),
1061 FLAG_GENERIC(CLONE_THREAD),
1062 FLAG_GENERIC(CLONE_NEWNS),
1063 FLAG_GENERIC(CLONE_SYSVSEM),
1064 FLAG_GENERIC(CLONE_SETTLS),
1065 FLAG_GENERIC(CLONE_PARENT_SETTID),
1066 FLAG_GENERIC(CLONE_CHILD_CLEARTID),
1067 FLAG_GENERIC(CLONE_DETACHED),
1068 FLAG_GENERIC(CLONE_UNTRACED),
1069 FLAG_GENERIC(CLONE_CHILD_SETTID),
1070 #if defined(CLONE_NEWUTS)
1071 FLAG_GENERIC(CLONE_NEWUTS),
1072 #endif
1073 #if defined(CLONE_NEWIPC)
1074 FLAG_GENERIC(CLONE_NEWIPC),
1075 #endif
1076 #if defined(CLONE_NEWUSER)
1077 FLAG_GENERIC(CLONE_NEWUSER),
1078 #endif
1079 #if defined(CLONE_NEWPID)
1080 FLAG_GENERIC(CLONE_NEWPID),
1081 #endif
1082 #if defined(CLONE_NEWNET)
1083 FLAG_GENERIC(CLONE_NEWNET),
1084 #endif
1085 #if defined(CLONE_IO)
1086 FLAG_GENERIC(CLONE_IO),
1087 #endif
1088 FLAG_END,
1091 UNUSED static struct flags msg_flags[] = {
1092 /* send */
1093 FLAG_GENERIC(MSG_CONFIRM),
1094 FLAG_GENERIC(MSG_DONTROUTE),
1095 FLAG_GENERIC(MSG_DONTWAIT),
1096 FLAG_GENERIC(MSG_EOR),
1097 FLAG_GENERIC(MSG_MORE),
1098 FLAG_GENERIC(MSG_NOSIGNAL),
1099 FLAG_GENERIC(MSG_OOB),
1100 /* recv */
1101 FLAG_GENERIC(MSG_CMSG_CLOEXEC),
1102 FLAG_GENERIC(MSG_ERRQUEUE),
1103 FLAG_GENERIC(MSG_PEEK),
1104 FLAG_GENERIC(MSG_TRUNC),
1105 FLAG_GENERIC(MSG_WAITALL),
1106 /* recvmsg */
1107 FLAG_GENERIC(MSG_CTRUNC),
1108 FLAG_END,
1111 UNUSED static struct flags statx_flags[] = {
1112 #ifdef AT_EMPTY_PATH
1113 FLAG_GENERIC(AT_EMPTY_PATH),
1114 #endif
1115 #ifdef AT_NO_AUTOMOUNT
1116 FLAG_GENERIC(AT_NO_AUTOMOUNT),
1117 #endif
1118 #ifdef AT_SYMLINK_NOFOLLOW
1119 FLAG_GENERIC(AT_SYMLINK_NOFOLLOW),
1120 #endif
1121 #ifdef AT_STATX_SYNC_AS_STAT
1122 FLAG_GENERIC(AT_STATX_SYNC_AS_STAT),
1123 #endif
1124 #ifdef AT_STATX_FORCE_SYNC
1125 FLAG_GENERIC(AT_STATX_FORCE_SYNC),
1126 #endif
1127 #ifdef AT_STATX_DONT_SYNC
1128 FLAG_GENERIC(AT_STATX_DONT_SYNC),
1129 #endif
1130 FLAG_END,
1133 UNUSED static struct flags statx_mask[] = {
1134 /* This must come first, because it includes everything. */
1135 #ifdef STATX_ALL
1136 FLAG_GENERIC(STATX_ALL),
1137 #endif
1138 /* This must come second; it includes everything except STATX_BTIME. */
1139 #ifdef STATX_BASIC_STATS
1140 FLAG_GENERIC(STATX_BASIC_STATS),
1141 #endif
1142 #ifdef STATX_TYPE
1143 FLAG_GENERIC(STATX_TYPE),
1144 #endif
1145 #ifdef STATX_MODE
1146 FLAG_GENERIC(STATX_MODE),
1147 #endif
1148 #ifdef STATX_NLINK
1149 FLAG_GENERIC(STATX_NLINK),
1150 #endif
1151 #ifdef STATX_UID
1152 FLAG_GENERIC(STATX_UID),
1153 #endif
1154 #ifdef STATX_GID
1155 FLAG_GENERIC(STATX_GID),
1156 #endif
1157 #ifdef STATX_ATIME
1158 FLAG_GENERIC(STATX_ATIME),
1159 #endif
1160 #ifdef STATX_MTIME
1161 FLAG_GENERIC(STATX_MTIME),
1162 #endif
1163 #ifdef STATX_CTIME
1164 FLAG_GENERIC(STATX_CTIME),
1165 #endif
1166 #ifdef STATX_INO
1167 FLAG_GENERIC(STATX_INO),
1168 #endif
1169 #ifdef STATX_SIZE
1170 FLAG_GENERIC(STATX_SIZE),
1171 #endif
1172 #ifdef STATX_BLOCKS
1173 FLAG_GENERIC(STATX_BLOCKS),
1174 #endif
1175 #ifdef STATX_BTIME
1176 FLAG_GENERIC(STATX_BTIME),
1177 #endif
1178 FLAG_END,
1181 UNUSED static struct flags falloc_flags[] = {
1182 FLAG_GENERIC(FALLOC_FL_KEEP_SIZE),
1183 FLAG_GENERIC(FALLOC_FL_PUNCH_HOLE),
1184 #ifdef FALLOC_FL_NO_HIDE_STALE
1185 FLAG_GENERIC(FALLOC_FL_NO_HIDE_STALE),
1186 #endif
1187 #ifdef FALLOC_FL_COLLAPSE_RANGE
1188 FLAG_GENERIC(FALLOC_FL_COLLAPSE_RANGE),
1189 #endif
1190 #ifdef FALLOC_FL_ZERO_RANGE
1191 FLAG_GENERIC(FALLOC_FL_ZERO_RANGE),
1192 #endif
1193 #ifdef FALLOC_FL_INSERT_RANGE
1194 FLAG_GENERIC(FALLOC_FL_INSERT_RANGE),
1195 #endif
1196 #ifdef FALLOC_FL_UNSHARE_RANGE
1197 FLAG_GENERIC(FALLOC_FL_UNSHARE_RANGE),
1198 #endif
1202 * print_xxx utility functions. These are used to print syscall
1203 * parameters in certain format. All of these have parameter
1204 * named 'last'. This parameter is used to add comma to output
1205 * when last == 0.
1208 static const char *
1209 get_comma(int last)
1211 return ((last) ? "" : ",");
1214 static void
1215 print_flags(const struct flags *f, abi_long flags, int last)
1217 const char *sep = "";
1218 int n;
1220 if ((flags == 0) && (f->f_value == 0)) {
1221 qemu_log("%s%s", f->f_string, get_comma(last));
1222 return;
1224 for (n = 0; f->f_string != NULL; f++) {
1225 if ((f->f_value != 0) && ((flags & f->f_value) == f->f_value)) {
1226 qemu_log("%s%s", sep, f->f_string);
1227 flags &= ~f->f_value;
1228 sep = "|";
1229 n++;
1233 if (n > 0) {
1234 /* print rest of the flags as numeric */
1235 if (flags != 0) {
1236 qemu_log("%s%#x%s", sep, (unsigned int)flags, get_comma(last));
1237 } else {
1238 qemu_log("%s", get_comma(last));
1240 } else {
1241 /* no string version of flags found, print them in hex then */
1242 qemu_log("%#x%s", (unsigned int)flags, get_comma(last));
1246 static void
1247 print_at_dirfd(abi_long dirfd, int last)
1249 #ifdef AT_FDCWD
1250 if (dirfd == AT_FDCWD) {
1251 qemu_log("AT_FDCWD%s", get_comma(last));
1252 return;
1254 #endif
1255 qemu_log("%d%s", (int)dirfd, get_comma(last));
1258 static void
1259 print_file_mode(abi_long mode, int last)
1261 const char *sep = "";
1262 const struct flags *m;
1264 for (m = &mode_flags[0]; m->f_string != NULL; m++) {
1265 if ((m->f_value & mode) == m->f_value) {
1266 qemu_log("%s%s", m->f_string, sep);
1267 sep = "|";
1268 mode &= ~m->f_value;
1269 break;
1273 mode &= ~S_IFMT;
1274 /* print rest of the mode as octal */
1275 if (mode != 0)
1276 qemu_log("%s%#o", sep, (unsigned int)mode);
1278 qemu_log("%s", get_comma(last));
1281 static void
1282 print_open_flags(abi_long flags, int last)
1284 print_flags(open_access_flags, flags & TARGET_O_ACCMODE, 1);
1285 flags &= ~TARGET_O_ACCMODE;
1286 if (flags == 0) {
1287 qemu_log("%s", get_comma(last));
1288 return;
1290 qemu_log("|");
1291 print_flags(open_flags, flags, last);
1294 static void
1295 print_syscall_prologue(const struct syscallname *sc)
1297 qemu_log("%s(", sc->name);
1300 /*ARGSUSED*/
1301 static void
1302 print_syscall_epilogue(const struct syscallname *sc)
1304 (void)sc;
1305 qemu_log(")");
1308 static void
1309 print_string(abi_long addr, int last)
1311 char *s;
1313 if ((s = lock_user_string(addr)) != NULL) {
1314 qemu_log("\"%s\"%s", s, get_comma(last));
1315 unlock_user(s, addr, 0);
1316 } else {
1317 /* can't get string out of it, so print it as pointer */
1318 print_pointer(addr, last);
1322 #define MAX_PRINT_BUF 40
1323 static void
1324 print_buf(abi_long addr, abi_long len, int last)
1326 uint8_t *s;
1327 int i;
1329 s = lock_user(VERIFY_READ, addr, len, 1);
1330 if (s) {
1331 qemu_log("\"");
1332 for (i = 0; i < MAX_PRINT_BUF && i < len; i++) {
1333 if (isprint(s[i])) {
1334 qemu_log("%c", s[i]);
1335 } else {
1336 qemu_log("\\%o", s[i]);
1339 qemu_log("\"");
1340 if (i != len) {
1341 qemu_log("...");
1343 if (!last) {
1344 qemu_log(",");
1346 unlock_user(s, addr, 0);
1347 } else {
1348 print_pointer(addr, last);
1353 * Prints out raw parameter using given format. Caller needs
1354 * to do byte swapping if needed.
1356 static void
1357 print_raw_param(const char *fmt, abi_long param, int last)
1359 char format[64];
1361 (void) snprintf(format, sizeof (format), "%s%s", fmt, get_comma(last));
1362 qemu_log(format, param);
1365 static void
1366 print_pointer(abi_long p, int last)
1368 if (p == 0)
1369 qemu_log("NULL%s", get_comma(last));
1370 else
1371 qemu_log("0x" TARGET_ABI_FMT_lx "%s", p, get_comma(last));
1375 * Reads 32-bit (int) number from guest address space from
1376 * address 'addr' and prints it.
1378 static void
1379 print_number(abi_long addr, int last)
1381 if (addr == 0) {
1382 qemu_log("NULL%s", get_comma(last));
1383 } else {
1384 int num;
1386 get_user_s32(num, addr);
1387 qemu_log("[%d]%s", num, get_comma(last));
1391 static void
1392 print_timeval(abi_ulong tv_addr, int last)
1394 if( tv_addr ) {
1395 struct target_timeval *tv;
1397 tv = lock_user(VERIFY_READ, tv_addr, sizeof(*tv), 1);
1398 if (!tv) {
1399 print_pointer(tv_addr, last);
1400 return;
1402 qemu_log("{" TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld "}%s",
1403 tswapal(tv->tv_sec), tswapal(tv->tv_usec), get_comma(last));
1404 unlock_user(tv, tv_addr, 0);
1405 } else
1406 qemu_log("NULL%s", get_comma(last));
1409 static void
1410 print_timezone(abi_ulong tz_addr, int last)
1412 if (tz_addr) {
1413 struct target_timezone *tz;
1415 tz = lock_user(VERIFY_READ, tz_addr, sizeof(*tz), 1);
1416 if (!tz) {
1417 print_pointer(tz_addr, last);
1418 return;
1420 qemu_log("{%d,%d}%s", tswap32(tz->tz_minuteswest),
1421 tswap32(tz->tz_dsttime), get_comma(last));
1422 unlock_user(tz, tz_addr, 0);
1423 } else {
1424 qemu_log("NULL%s", get_comma(last));
1428 #undef UNUSED
1430 #ifdef TARGET_NR_accept
1431 static void
1432 print_accept(void *cpu_env, const struct syscallname *name,
1433 abi_long arg0, abi_long arg1, abi_long arg2,
1434 abi_long arg3, abi_long arg4, abi_long arg5)
1436 print_syscall_prologue(name);
1437 print_raw_param("%d", arg0, 0);
1438 print_pointer(arg1, 0);
1439 print_number(arg2, 1);
1440 print_syscall_epilogue(name);
1442 #endif
1444 #ifdef TARGET_NR_access
1445 static void
1446 print_access(void *cpu_env, const struct syscallname *name,
1447 abi_long arg0, abi_long arg1, abi_long arg2,
1448 abi_long arg3, abi_long arg4, abi_long arg5)
1450 print_syscall_prologue(name);
1451 print_string(arg0, 0);
1452 print_flags(access_flags, arg1, 1);
1453 print_syscall_epilogue(name);
1455 #endif
1457 #ifdef TARGET_NR_acct
1458 static void
1459 print_acct(void *cpu_env, const struct syscallname *name,
1460 abi_long arg0, abi_long arg1, abi_long arg2,
1461 abi_long arg3, abi_long arg4, abi_long arg5)
1463 print_syscall_prologue(name);
1464 print_string(arg0, 1);
1465 print_syscall_epilogue(name);
1467 #endif
1469 #ifdef TARGET_NR_brk
1470 static void
1471 print_brk(void *cpu_env, const struct syscallname *name,
1472 abi_long arg0, abi_long arg1, abi_long arg2,
1473 abi_long arg3, abi_long arg4, abi_long arg5)
1475 print_syscall_prologue(name);
1476 print_pointer(arg0, 1);
1477 print_syscall_epilogue(name);
1479 #endif
1481 #ifdef TARGET_NR_chdir
1482 static void
1483 print_chdir(void *cpu_env, const struct syscallname *name,
1484 abi_long arg0, abi_long arg1, abi_long arg2,
1485 abi_long arg3, abi_long arg4, abi_long arg5)
1487 print_syscall_prologue(name);
1488 print_string(arg0, 1);
1489 print_syscall_epilogue(name);
1491 #endif
1493 #ifdef TARGET_NR_chroot
1494 static void
1495 print_chroot(void *cpu_env, const struct syscallname *name,
1496 abi_long arg0, abi_long arg1, abi_long arg2,
1497 abi_long arg3, abi_long arg4, abi_long arg5)
1499 print_syscall_prologue(name);
1500 print_string(arg0, 1);
1501 print_syscall_epilogue(name);
1503 #endif
1505 #ifdef TARGET_NR_chmod
1506 static void
1507 print_chmod(void *cpu_env, const struct syscallname *name,
1508 abi_long arg0, abi_long arg1, abi_long arg2,
1509 abi_long arg3, abi_long arg4, abi_long arg5)
1511 print_syscall_prologue(name);
1512 print_string(arg0, 0);
1513 print_file_mode(arg1, 1);
1514 print_syscall_epilogue(name);
1516 #endif
1518 #if defined(TARGET_NR_chown) || defined(TARGET_NR_lchown)
1519 static void
1520 print_chown(void *cpu_env, const struct syscallname *name,
1521 abi_long arg0, abi_long arg1, abi_long arg2,
1522 abi_long arg3, abi_long arg4, abi_long arg5)
1524 print_syscall_prologue(name);
1525 print_string(arg0, 0);
1526 print_raw_param("%d", arg1, 0);
1527 print_raw_param("%d", arg2, 1);
1528 print_syscall_epilogue(name);
1530 #define print_lchown print_chown
1531 #endif
1533 #ifdef TARGET_NR_clock_adjtime
1534 static void
1535 print_clock_adjtime(void *cpu_env, const struct syscallname *name,
1536 abi_long arg0, abi_long arg1, abi_long arg2,
1537 abi_long arg3, abi_long arg4, abi_long arg5)
1539 print_syscall_prologue(name);
1540 print_clockid(arg0, 0);
1541 print_pointer(arg1, 1);
1542 print_syscall_epilogue(name);
1544 #endif
1546 #ifdef TARGET_NR_clone
1547 static void do_print_clone(unsigned int flags, abi_ulong newsp,
1548 abi_ulong parent_tidptr, target_ulong newtls,
1549 abi_ulong child_tidptr)
1551 print_flags(clone_flags, flags, 0);
1552 print_raw_param("child_stack=0x" TARGET_ABI_FMT_lx, newsp, 0);
1553 print_raw_param("parent_tidptr=0x" TARGET_ABI_FMT_lx, parent_tidptr, 0);
1554 print_raw_param("tls=0x" TARGET_ABI_FMT_lx, newtls, 0);
1555 print_raw_param("child_tidptr=0x" TARGET_ABI_FMT_lx, child_tidptr, 1);
1558 static void
1559 print_clone(void *cpu_env, const struct syscallname *name,
1560 abi_long arg1, abi_long arg2, abi_long arg3,
1561 abi_long arg4, abi_long arg5, abi_long arg6)
1563 print_syscall_prologue(name);
1564 #if defined(TARGET_MICROBLAZE)
1565 do_print_clone(arg1, arg2, arg4, arg6, arg5);
1566 #elif defined(TARGET_CLONE_BACKWARDS)
1567 do_print_clone(arg1, arg2, arg3, arg4, arg5);
1568 #elif defined(TARGET_CLONE_BACKWARDS2)
1569 do_print_clone(arg2, arg1, arg3, arg5, arg4);
1570 #else
1571 do_print_clone(arg1, arg2, arg3, arg5, arg4);
1572 #endif
1573 print_syscall_epilogue(name);
1575 #endif
1577 #ifdef TARGET_NR_creat
1578 static void
1579 print_creat(void *cpu_env, const struct syscallname *name,
1580 abi_long arg0, abi_long arg1, abi_long arg2,
1581 abi_long arg3, abi_long arg4, abi_long arg5)
1583 print_syscall_prologue(name);
1584 print_string(arg0, 0);
1585 print_file_mode(arg1, 1);
1586 print_syscall_epilogue(name);
1588 #endif
1590 #ifdef TARGET_NR_execv
1591 static void
1592 print_execv(void *cpu_env, const struct syscallname *name,
1593 abi_long arg0, abi_long arg1, abi_long arg2,
1594 abi_long arg3, abi_long arg4, abi_long arg5)
1596 print_syscall_prologue(name);
1597 print_string(arg0, 0);
1598 print_raw_param("0x" TARGET_ABI_FMT_lx, arg1, 1);
1599 print_syscall_epilogue(name);
1601 #endif
1603 #ifdef TARGET_NR_faccessat
1604 static void
1605 print_faccessat(void *cpu_env, const struct syscallname *name,
1606 abi_long arg0, abi_long arg1, abi_long arg2,
1607 abi_long arg3, abi_long arg4, abi_long arg5)
1609 print_syscall_prologue(name);
1610 print_at_dirfd(arg0, 0);
1611 print_string(arg1, 0);
1612 print_flags(access_flags, arg2, 0);
1613 print_flags(at_file_flags, arg3, 1);
1614 print_syscall_epilogue(name);
1616 #endif
1618 #ifdef TARGET_NR_fallocate
1619 static void
1620 print_fallocate(void *cpu_env, const struct syscallname *name,
1621 abi_long arg0, abi_long arg1, abi_long arg2,
1622 abi_long arg3, abi_long arg4, abi_long arg5)
1624 print_syscall_prologue(name);
1625 print_raw_param("%d", arg0, 0);
1626 print_flags(falloc_flags, arg1, 0);
1627 #if TARGET_ABI_BITS == 32
1628 print_raw_param("%" PRIu64, target_offset64(arg2, arg3), 0);
1629 print_raw_param("%" PRIu64, target_offset64(arg4, arg5), 1);
1630 #else
1631 print_raw_param(TARGET_ABI_FMT_ld, arg2, 0);
1632 print_raw_param(TARGET_ABI_FMT_ld, arg3, 1);
1633 #endif
1634 print_syscall_epilogue(name);
1636 #endif
1638 #ifdef TARGET_NR_fchmodat
1639 static void
1640 print_fchmodat(void *cpu_env, const struct syscallname *name,
1641 abi_long arg0, abi_long arg1, abi_long arg2,
1642 abi_long arg3, abi_long arg4, abi_long arg5)
1644 print_syscall_prologue(name);
1645 print_at_dirfd(arg0, 0);
1646 print_string(arg1, 0);
1647 print_file_mode(arg2, 0);
1648 print_flags(at_file_flags, arg3, 1);
1649 print_syscall_epilogue(name);
1651 #endif
1653 #ifdef TARGET_NR_fchownat
1654 static void
1655 print_fchownat(void *cpu_env, const struct syscallname *name,
1656 abi_long arg0, abi_long arg1, abi_long arg2,
1657 abi_long arg3, abi_long arg4, abi_long arg5)
1659 print_syscall_prologue(name);
1660 print_at_dirfd(arg0, 0);
1661 print_string(arg1, 0);
1662 print_raw_param("%d", arg2, 0);
1663 print_raw_param("%d", arg3, 0);
1664 print_flags(at_file_flags, arg4, 1);
1665 print_syscall_epilogue(name);
1667 #endif
1669 #if defined(TARGET_NR_fcntl) || defined(TARGET_NR_fcntl64)
1670 static void
1671 print_fcntl(void *cpu_env, const struct syscallname *name,
1672 abi_long arg0, abi_long arg1, abi_long arg2,
1673 abi_long arg3, abi_long arg4, abi_long arg5)
1675 print_syscall_prologue(name);
1676 print_raw_param("%d", arg0, 0);
1677 switch(arg1) {
1678 case TARGET_F_DUPFD:
1679 qemu_log("F_DUPFD,");
1680 print_raw_param(TARGET_ABI_FMT_ld, arg2, 1);
1681 break;
1682 case TARGET_F_GETFD:
1683 qemu_log("F_GETFD");
1684 break;
1685 case TARGET_F_SETFD:
1686 qemu_log("F_SETFD,");
1687 print_raw_param(TARGET_ABI_FMT_ld, arg2, 1);
1688 break;
1689 case TARGET_F_GETFL:
1690 qemu_log("F_GETFL");
1691 break;
1692 case TARGET_F_SETFL:
1693 qemu_log("F_SETFL,");
1694 print_open_flags(arg2, 1);
1695 break;
1696 case TARGET_F_GETLK:
1697 qemu_log("F_GETLK,");
1698 print_pointer(arg2, 1);
1699 break;
1700 case TARGET_F_SETLK:
1701 qemu_log("F_SETLK,");
1702 print_pointer(arg2, 1);
1703 break;
1704 case TARGET_F_SETLKW:
1705 qemu_log("F_SETLKW,");
1706 print_pointer(arg2, 1);
1707 break;
1708 case TARGET_F_GETOWN:
1709 qemu_log("F_GETOWN");
1710 break;
1711 case TARGET_F_SETOWN:
1712 qemu_log("F_SETOWN,");
1713 print_raw_param(TARGET_ABI_FMT_ld, arg2, 0);
1714 break;
1715 case TARGET_F_GETSIG:
1716 qemu_log("F_GETSIG");
1717 break;
1718 case TARGET_F_SETSIG:
1719 qemu_log("F_SETSIG,");
1720 print_raw_param(TARGET_ABI_FMT_ld, arg2, 0);
1721 break;
1722 #if TARGET_ABI_BITS == 32
1723 case TARGET_F_GETLK64:
1724 qemu_log("F_GETLK64,");
1725 print_pointer(arg2, 1);
1726 break;
1727 case TARGET_F_SETLK64:
1728 qemu_log("F_SETLK64,");
1729 print_pointer(arg2, 1);
1730 break;
1731 case TARGET_F_SETLKW64:
1732 qemu_log("F_SETLKW64,");
1733 print_pointer(arg2, 1);
1734 break;
1735 #endif
1736 case TARGET_F_SETLEASE:
1737 qemu_log("F_SETLEASE,");
1738 print_raw_param(TARGET_ABI_FMT_ld, arg2, 0);
1739 break;
1740 case TARGET_F_GETLEASE:
1741 qemu_log("F_GETLEASE");
1742 break;
1743 case TARGET_F_SETPIPE_SZ:
1744 qemu_log("F_SETPIPE_SZ,");
1745 print_raw_param(TARGET_ABI_FMT_ld, arg2, 1);
1746 break;
1747 case TARGET_F_GETPIPE_SZ:
1748 qemu_log("F_GETPIPE_SZ");
1749 break;
1750 case TARGET_F_DUPFD_CLOEXEC:
1751 qemu_log("F_DUPFD_CLOEXEC,");
1752 print_raw_param(TARGET_ABI_FMT_ld, arg2, 1);
1753 break;
1754 case TARGET_F_NOTIFY:
1755 qemu_log("F_NOTIFY,");
1756 print_raw_param(TARGET_ABI_FMT_ld, arg2, 0);
1757 break;
1758 default:
1759 print_raw_param(TARGET_ABI_FMT_ld, arg1, 0);
1760 print_pointer(arg2, 1);
1761 break;
1763 print_syscall_epilogue(name);
1765 #define print_fcntl64 print_fcntl
1766 #endif
1768 #ifdef TARGET_NR_fgetxattr
1769 static void
1770 print_fgetxattr(void *cpu_env, const struct syscallname *name,
1771 abi_long arg0, abi_long arg1, abi_long arg2,
1772 abi_long arg3, abi_long arg4, abi_long arg5)
1774 print_syscall_prologue(name);
1775 print_raw_param("%d", arg0, 0);
1776 print_string(arg1, 0);
1777 print_pointer(arg2, 0);
1778 print_raw_param(TARGET_FMT_lu, arg3, 1);
1779 print_syscall_epilogue(name);
1781 #endif
1783 #ifdef TARGET_NR_flistxattr
1784 static void
1785 print_flistxattr(void *cpu_env, const struct syscallname *name,
1786 abi_long arg0, abi_long arg1, abi_long arg2,
1787 abi_long arg3, abi_long arg4, abi_long arg5)
1789 print_syscall_prologue(name);
1790 print_raw_param("%d", arg0, 0);
1791 print_pointer(arg1, 0);
1792 print_raw_param(TARGET_FMT_lu, arg2, 1);
1793 print_syscall_epilogue(name);
1795 #endif
1797 #if defined(TARGET_NR_getxattr) || defined(TARGET_NR_lgetxattr)
1798 static void
1799 print_getxattr(void *cpu_env, const struct syscallname *name,
1800 abi_long arg0, abi_long arg1, abi_long arg2,
1801 abi_long arg3, abi_long arg4, abi_long arg5)
1803 print_syscall_prologue(name);
1804 print_string(arg0, 0);
1805 print_string(arg1, 0);
1806 print_pointer(arg2, 0);
1807 print_raw_param(TARGET_FMT_lu, arg3, 1);
1808 print_syscall_epilogue(name);
1810 #define print_lgetxattr print_getxattr
1811 #endif
1813 #if defined(TARGET_NR_listxattr) || defined(TARGET_NR_llistxattr)
1814 static void
1815 print_listxattr(void *cpu_env, const struct syscallname *name,
1816 abi_long arg0, abi_long arg1, abi_long arg2,
1817 abi_long arg3, abi_long arg4, abi_long arg5)
1819 print_syscall_prologue(name);
1820 print_string(arg0, 0);
1821 print_pointer(arg1, 0);
1822 print_raw_param(TARGET_FMT_lu, arg2, 1);
1823 print_syscall_epilogue(name);
1825 #define print_llistxattr print_listxattr
1826 #endif
1828 #if defined(TARGET_NR_fremovexattr)
1829 static void
1830 print_fremovexattr(void *cpu_env, const struct syscallname *name,
1831 abi_long arg0, abi_long arg1, abi_long arg2,
1832 abi_long arg3, abi_long arg4, abi_long arg5)
1834 print_syscall_prologue(name);
1835 print_raw_param("%d", arg0, 0);
1836 print_string(arg1, 1);
1837 print_syscall_epilogue(name);
1839 #endif
1841 #if defined(TARGET_NR_removexattr) || defined(TARGET_NR_lremovexattr)
1842 static void
1843 print_removexattr(void *cpu_env, const struct syscallname *name,
1844 abi_long arg0, abi_long arg1, abi_long arg2,
1845 abi_long arg3, abi_long arg4, abi_long arg5)
1847 print_syscall_prologue(name);
1848 print_string(arg0, 0);
1849 print_string(arg1, 1);
1850 print_syscall_epilogue(name);
1852 #define print_lremovexattr print_removexattr
1853 #endif
1855 #ifdef TARGET_NR_futimesat
1856 static void
1857 print_futimesat(void *cpu_env, const struct syscallname *name,
1858 abi_long arg0, abi_long arg1, abi_long arg2,
1859 abi_long arg3, abi_long arg4, abi_long arg5)
1861 print_syscall_prologue(name);
1862 print_at_dirfd(arg0, 0);
1863 print_string(arg1, 0);
1864 print_timeval(arg2, 0);
1865 print_timeval(arg2 + sizeof (struct target_timeval), 1);
1866 print_syscall_epilogue(name);
1868 #endif
1870 #ifdef TARGET_NR_settimeofday
1871 static void
1872 print_settimeofday(void *cpu_env, const struct syscallname *name,
1873 abi_long arg0, abi_long arg1, abi_long arg2,
1874 abi_long arg3, abi_long arg4, abi_long arg5)
1876 print_syscall_prologue(name);
1877 print_timeval(arg0, 0);
1878 print_timezone(arg1, 1);
1879 print_syscall_epilogue(name);
1881 #endif
1883 #ifdef TARGET_NR_link
1884 static void
1885 print_link(void *cpu_env, const struct syscallname *name,
1886 abi_long arg0, abi_long arg1, abi_long arg2,
1887 abi_long arg3, abi_long arg4, abi_long arg5)
1889 print_syscall_prologue(name);
1890 print_string(arg0, 0);
1891 print_string(arg1, 1);
1892 print_syscall_epilogue(name);
1894 #endif
1896 #ifdef TARGET_NR_linkat
1897 static void
1898 print_linkat(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_at_dirfd(arg0, 0);
1904 print_string(arg1, 0);
1905 print_at_dirfd(arg2, 0);
1906 print_string(arg3, 0);
1907 print_flags(at_file_flags, arg4, 1);
1908 print_syscall_epilogue(name);
1910 #endif
1912 #ifdef TARGET_NR__llseek
1913 static void
1914 print__llseek(void *cpu_env, const struct syscallname *name,
1915 abi_long arg0, abi_long arg1, abi_long arg2,
1916 abi_long arg3, abi_long arg4, abi_long arg5)
1918 const char *whence = "UNKNOWN";
1919 print_syscall_prologue(name);
1920 print_raw_param("%d", arg0, 0);
1921 print_raw_param("%ld", arg1, 0);
1922 print_raw_param("%ld", arg2, 0);
1923 print_pointer(arg3, 0);
1924 switch(arg4) {
1925 case SEEK_SET: whence = "SEEK_SET"; break;
1926 case SEEK_CUR: whence = "SEEK_CUR"; break;
1927 case SEEK_END: whence = "SEEK_END"; break;
1929 qemu_log("%s", whence);
1930 print_syscall_epilogue(name);
1932 #endif
1934 #ifdef TARGET_NR_lseek
1935 static void
1936 print_lseek(void *cpu_env, const struct syscallname *name,
1937 abi_long arg0, abi_long arg1, abi_long arg2,
1938 abi_long arg3, abi_long arg4, abi_long arg5)
1940 print_syscall_prologue(name);
1941 print_raw_param("%d", arg0, 0);
1942 print_raw_param(TARGET_ABI_FMT_ld, arg1, 0);
1943 switch (arg2) {
1944 case SEEK_SET:
1945 qemu_log("SEEK_SET"); break;
1946 case SEEK_CUR:
1947 qemu_log("SEEK_CUR"); break;
1948 case SEEK_END:
1949 qemu_log("SEEK_END"); break;
1950 #ifdef SEEK_DATA
1951 case SEEK_DATA:
1952 qemu_log("SEEK_DATA"); break;
1953 #endif
1954 #ifdef SEEK_HOLE
1955 case SEEK_HOLE:
1956 qemu_log("SEEK_HOLE"); break;
1957 #endif
1958 default:
1959 print_raw_param("%#x", arg2, 1);
1961 print_syscall_epilogue(name);
1963 #endif
1965 #ifdef TARGET_NR_truncate
1966 static void
1967 print_truncate(void *cpu_env, const struct syscallname *name,
1968 abi_long arg0, abi_long arg1, abi_long arg2,
1969 abi_long arg3, abi_long arg4, abi_long arg5)
1971 print_syscall_prologue(name);
1972 print_string(arg0, 0);
1973 print_raw_param(TARGET_ABI_FMT_ld, arg1, 1);
1974 print_syscall_epilogue(name);
1976 #endif
1978 #ifdef TARGET_NR_truncate64
1979 static void
1980 print_truncate64(void *cpu_env, const struct syscallname *name,
1981 abi_long arg0, abi_long arg1, abi_long arg2,
1982 abi_long arg3, abi_long arg4, abi_long arg5)
1984 print_syscall_prologue(name);
1985 print_string(arg0, 0);
1986 if (regpairs_aligned(cpu_env, TARGET_NR_truncate64)) {
1987 arg1 = arg2;
1988 arg2 = arg3;
1990 print_raw_param("%" PRIu64, target_offset64(arg1, arg2), 1);
1991 print_syscall_epilogue(name);
1993 #endif
1995 #ifdef TARGET_NR_ftruncate64
1996 static void
1997 print_ftruncate64(void *cpu_env, const struct syscallname *name,
1998 abi_long arg0, abi_long arg1, abi_long arg2,
1999 abi_long arg3, abi_long arg4, abi_long arg5)
2001 print_syscall_prologue(name);
2002 print_raw_param("%d", arg0, 0);
2003 if (regpairs_aligned(cpu_env, TARGET_NR_ftruncate64)) {
2004 arg1 = arg2;
2005 arg2 = arg3;
2007 print_raw_param("%" PRIu64, target_offset64(arg1, arg2), 1);
2008 print_syscall_epilogue(name);
2010 #endif
2012 #if defined(TARGET_NR_socket)
2013 static void
2014 print_socket(void *cpu_env, const struct syscallname *name,
2015 abi_long arg0, abi_long arg1, abi_long arg2,
2016 abi_long arg3, abi_long arg4, abi_long arg5)
2018 abi_ulong domain = arg0, type = arg1, protocol = arg2;
2020 print_syscall_prologue(name);
2021 print_socket_domain(domain);
2022 qemu_log(",");
2023 print_socket_type(type);
2024 qemu_log(",");
2025 if (domain == AF_PACKET ||
2026 (domain == AF_INET && type == TARGET_SOCK_PACKET)) {
2027 protocol = tswap16(protocol);
2029 print_socket_protocol(domain, type, protocol);
2030 print_syscall_epilogue(name);
2033 #endif
2035 #if defined(TARGET_NR_socketcall) || defined(TARGET_NR_bind)
2037 static void print_sockfd(abi_long sockfd, int last)
2039 print_raw_param(TARGET_ABI_FMT_ld, sockfd, last);
2042 #endif
2044 #if defined(TARGET_NR_socketcall)
2046 #define get_user_ualx(x, gaddr, idx) \
2047 get_user_ual(x, (gaddr) + (idx) * sizeof(abi_long))
2049 static void do_print_socket(const char *name, abi_long arg1)
2051 abi_ulong domain, type, protocol;
2053 get_user_ualx(domain, arg1, 0);
2054 get_user_ualx(type, arg1, 1);
2055 get_user_ualx(protocol, arg1, 2);
2056 qemu_log("%s(", name);
2057 print_socket_domain(domain);
2058 qemu_log(",");
2059 print_socket_type(type);
2060 qemu_log(",");
2061 if (domain == AF_PACKET ||
2062 (domain == AF_INET && type == TARGET_SOCK_PACKET)) {
2063 protocol = tswap16(protocol);
2065 print_socket_protocol(domain, type, protocol);
2066 qemu_log(")");
2069 static void do_print_sockaddr(const char *name, abi_long arg1)
2071 abi_ulong sockfd, addr, addrlen;
2073 get_user_ualx(sockfd, arg1, 0);
2074 get_user_ualx(addr, arg1, 1);
2075 get_user_ualx(addrlen, arg1, 2);
2077 qemu_log("%s(", name);
2078 print_sockfd(sockfd, 0);
2079 print_sockaddr(addr, addrlen, 0);
2080 qemu_log(")");
2083 static void do_print_listen(const char *name, abi_long arg1)
2085 abi_ulong sockfd, backlog;
2087 get_user_ualx(sockfd, arg1, 0);
2088 get_user_ualx(backlog, arg1, 1);
2090 qemu_log("%s(", name);
2091 print_sockfd(sockfd, 0);
2092 print_raw_param(TARGET_ABI_FMT_ld, backlog, 1);
2093 qemu_log(")");
2096 static void do_print_socketpair(const char *name, abi_long arg1)
2098 abi_ulong domain, type, protocol, tab;
2100 get_user_ualx(domain, arg1, 0);
2101 get_user_ualx(type, arg1, 1);
2102 get_user_ualx(protocol, arg1, 2);
2103 get_user_ualx(tab, arg1, 3);
2105 qemu_log("%s(", name);
2106 print_socket_domain(domain);
2107 qemu_log(",");
2108 print_socket_type(type);
2109 qemu_log(",");
2110 print_socket_protocol(domain, type, protocol);
2111 qemu_log(",");
2112 print_raw_param(TARGET_ABI_FMT_lx, tab, 1);
2113 qemu_log(")");
2116 static void do_print_sendrecv(const char *name, abi_long arg1)
2118 abi_ulong sockfd, msg, len, flags;
2120 get_user_ualx(sockfd, arg1, 0);
2121 get_user_ualx(msg, arg1, 1);
2122 get_user_ualx(len, arg1, 2);
2123 get_user_ualx(flags, arg1, 3);
2125 qemu_log("%s(", name);
2126 print_sockfd(sockfd, 0);
2127 print_buf(msg, len, 0);
2128 print_raw_param(TARGET_ABI_FMT_ld, len, 0);
2129 print_flags(msg_flags, flags, 1);
2130 qemu_log(")");
2133 static void do_print_msgaddr(const char *name, abi_long arg1)
2135 abi_ulong sockfd, msg, len, flags, addr, addrlen;
2137 get_user_ualx(sockfd, arg1, 0);
2138 get_user_ualx(msg, arg1, 1);
2139 get_user_ualx(len, arg1, 2);
2140 get_user_ualx(flags, arg1, 3);
2141 get_user_ualx(addr, arg1, 4);
2142 get_user_ualx(addrlen, arg1, 5);
2144 qemu_log("%s(", name);
2145 print_sockfd(sockfd, 0);
2146 print_buf(msg, len, 0);
2147 print_raw_param(TARGET_ABI_FMT_ld, len, 0);
2148 print_flags(msg_flags, flags, 0);
2149 print_sockaddr(addr, addrlen, 0);
2150 qemu_log(")");
2153 static void do_print_shutdown(const char *name, abi_long arg1)
2155 abi_ulong sockfd, how;
2157 get_user_ualx(sockfd, arg1, 0);
2158 get_user_ualx(how, arg1, 1);
2160 qemu_log("shutdown(");
2161 print_sockfd(sockfd, 0);
2162 switch (how) {
2163 case SHUT_RD:
2164 qemu_log("SHUT_RD");
2165 break;
2166 case SHUT_WR:
2167 qemu_log("SHUT_WR");
2168 break;
2169 case SHUT_RDWR:
2170 qemu_log("SHUT_RDWR");
2171 break;
2172 default:
2173 print_raw_param(TARGET_ABI_FMT_ld, how, 1);
2174 break;
2176 qemu_log(")");
2179 static void do_print_msg(const char *name, abi_long arg1)
2181 abi_ulong sockfd, msg, flags;
2183 get_user_ualx(sockfd, arg1, 0);
2184 get_user_ualx(msg, arg1, 1);
2185 get_user_ualx(flags, arg1, 2);
2187 qemu_log("%s(", name);
2188 print_sockfd(sockfd, 0);
2189 print_pointer(msg, 0);
2190 print_flags(msg_flags, flags, 1);
2191 qemu_log(")");
2194 static void do_print_sockopt(const char *name, abi_long arg1)
2196 abi_ulong sockfd, level, optname, optval, optlen;
2198 get_user_ualx(sockfd, arg1, 0);
2199 get_user_ualx(level, arg1, 1);
2200 get_user_ualx(optname, arg1, 2);
2201 get_user_ualx(optval, arg1, 3);
2202 get_user_ualx(optlen, arg1, 4);
2204 qemu_log("%s(", name);
2205 print_sockfd(sockfd, 0);
2206 switch (level) {
2207 case SOL_TCP:
2208 qemu_log("SOL_TCP,");
2209 print_raw_param(TARGET_ABI_FMT_ld, optname, 0);
2210 print_pointer(optval, 0);
2211 break;
2212 case SOL_IP:
2213 qemu_log("SOL_IP,");
2214 print_raw_param(TARGET_ABI_FMT_ld, optname, 0);
2215 print_pointer(optval, 0);
2216 break;
2217 case SOL_RAW:
2218 qemu_log("SOL_RAW,");
2219 print_raw_param(TARGET_ABI_FMT_ld, optname, 0);
2220 print_pointer(optval, 0);
2221 break;
2222 case TARGET_SOL_SOCKET:
2223 qemu_log("SOL_SOCKET,");
2224 switch (optname) {
2225 case TARGET_SO_DEBUG:
2226 qemu_log("SO_DEBUG,");
2227 print_optint:
2228 print_number(optval, 0);
2229 break;
2230 case TARGET_SO_REUSEADDR:
2231 qemu_log("SO_REUSEADDR,");
2232 goto print_optint;
2233 case TARGET_SO_REUSEPORT:
2234 qemu_log("SO_REUSEPORT,");
2235 goto print_optint;
2236 case TARGET_SO_TYPE:
2237 qemu_log("SO_TYPE,");
2238 goto print_optint;
2239 case TARGET_SO_ERROR:
2240 qemu_log("SO_ERROR,");
2241 goto print_optint;
2242 case TARGET_SO_DONTROUTE:
2243 qemu_log("SO_DONTROUTE,");
2244 goto print_optint;
2245 case TARGET_SO_BROADCAST:
2246 qemu_log("SO_BROADCAST,");
2247 goto print_optint;
2248 case TARGET_SO_SNDBUF:
2249 qemu_log("SO_SNDBUF,");
2250 goto print_optint;
2251 case TARGET_SO_RCVBUF:
2252 qemu_log("SO_RCVBUF,");
2253 goto print_optint;
2254 case TARGET_SO_KEEPALIVE:
2255 qemu_log("SO_KEEPALIVE,");
2256 goto print_optint;
2257 case TARGET_SO_OOBINLINE:
2258 qemu_log("SO_OOBINLINE,");
2259 goto print_optint;
2260 case TARGET_SO_NO_CHECK:
2261 qemu_log("SO_NO_CHECK,");
2262 goto print_optint;
2263 case TARGET_SO_PRIORITY:
2264 qemu_log("SO_PRIORITY,");
2265 goto print_optint;
2266 case TARGET_SO_BSDCOMPAT:
2267 qemu_log("SO_BSDCOMPAT,");
2268 goto print_optint;
2269 case TARGET_SO_PASSCRED:
2270 qemu_log("SO_PASSCRED,");
2271 goto print_optint;
2272 case TARGET_SO_TIMESTAMP:
2273 qemu_log("SO_TIMESTAMP,");
2274 goto print_optint;
2275 case TARGET_SO_RCVLOWAT:
2276 qemu_log("SO_RCVLOWAT,");
2277 goto print_optint;
2278 case TARGET_SO_RCVTIMEO:
2279 qemu_log("SO_RCVTIMEO,");
2280 print_timeval(optval, 0);
2281 break;
2282 case TARGET_SO_SNDTIMEO:
2283 qemu_log("SO_SNDTIMEO,");
2284 print_timeval(optval, 0);
2285 break;
2286 case TARGET_SO_ATTACH_FILTER: {
2287 struct target_sock_fprog *fprog;
2289 qemu_log("SO_ATTACH_FILTER,");
2291 if (lock_user_struct(VERIFY_READ, fprog, optval, 0)) {
2292 struct target_sock_filter *filter;
2293 qemu_log("{");
2294 if (lock_user_struct(VERIFY_READ, filter,
2295 tswapal(fprog->filter), 0)) {
2296 int i;
2297 for (i = 0; i < tswap16(fprog->len) - 1; i++) {
2298 qemu_log("[%d]{0x%x,%d,%d,0x%x},",
2299 i, tswap16(filter[i].code),
2300 filter[i].jt, filter[i].jf,
2301 tswap32(filter[i].k));
2303 qemu_log("[%d]{0x%x,%d,%d,0x%x}",
2304 i, tswap16(filter[i].code),
2305 filter[i].jt, filter[i].jf,
2306 tswap32(filter[i].k));
2307 } else {
2308 qemu_log(TARGET_ABI_FMT_lx, tswapal(fprog->filter));
2310 qemu_log(",%d},", tswap16(fprog->len));
2311 unlock_user(fprog, optval, 0);
2312 } else {
2313 print_pointer(optval, 0);
2315 break;
2317 default:
2318 print_raw_param(TARGET_ABI_FMT_ld, optname, 0);
2319 print_pointer(optval, 0);
2320 break;
2322 break;
2323 default:
2324 print_raw_param(TARGET_ABI_FMT_ld, level, 0);
2325 print_raw_param(TARGET_ABI_FMT_ld, optname, 0);
2326 print_pointer(optval, 0);
2327 break;
2329 print_raw_param(TARGET_ABI_FMT_ld, optlen, 1);
2330 qemu_log(")");
2333 #define PRINT_SOCKOP(name, func) \
2334 [TARGET_SYS_##name] = { #name, func }
2336 static struct {
2337 const char *name;
2338 void (*print)(const char *, abi_long);
2339 } scall[] = {
2340 PRINT_SOCKOP(SOCKET, do_print_socket),
2341 PRINT_SOCKOP(BIND, do_print_sockaddr),
2342 PRINT_SOCKOP(CONNECT, do_print_sockaddr),
2343 PRINT_SOCKOP(LISTEN, do_print_listen),
2344 PRINT_SOCKOP(ACCEPT, do_print_sockaddr),
2345 PRINT_SOCKOP(GETSOCKNAME, do_print_sockaddr),
2346 PRINT_SOCKOP(GETPEERNAME, do_print_sockaddr),
2347 PRINT_SOCKOP(SOCKETPAIR, do_print_socketpair),
2348 PRINT_SOCKOP(SEND, do_print_sendrecv),
2349 PRINT_SOCKOP(RECV, do_print_sendrecv),
2350 PRINT_SOCKOP(SENDTO, do_print_msgaddr),
2351 PRINT_SOCKOP(RECVFROM, do_print_msgaddr),
2352 PRINT_SOCKOP(SHUTDOWN, do_print_shutdown),
2353 PRINT_SOCKOP(SETSOCKOPT, do_print_sockopt),
2354 PRINT_SOCKOP(GETSOCKOPT, do_print_sockopt),
2355 PRINT_SOCKOP(SENDMSG, do_print_msg),
2356 PRINT_SOCKOP(RECVMSG, do_print_msg),
2357 PRINT_SOCKOP(ACCEPT4, NULL),
2358 PRINT_SOCKOP(RECVMMSG, NULL),
2359 PRINT_SOCKOP(SENDMMSG, NULL),
2362 static void
2363 print_socketcall(void *cpu_env, const struct syscallname *name,
2364 abi_long arg0, abi_long arg1, abi_long arg2,
2365 abi_long arg3, abi_long arg4, abi_long arg5)
2367 if (arg0 >= 0 && arg0 < ARRAY_SIZE(scall) && scall[arg0].print) {
2368 scall[arg0].print(scall[arg0].name, arg1);
2369 return;
2371 print_syscall_prologue(name);
2372 print_raw_param(TARGET_ABI_FMT_ld, arg0, 0);
2373 print_raw_param(TARGET_ABI_FMT_ld, arg1, 0);
2374 print_raw_param(TARGET_ABI_FMT_ld, arg2, 0);
2375 print_raw_param(TARGET_ABI_FMT_ld, arg3, 0);
2376 print_raw_param(TARGET_ABI_FMT_ld, arg4, 0);
2377 print_raw_param(TARGET_ABI_FMT_ld, arg5, 0);
2378 print_syscall_epilogue(name);
2380 #endif
2382 #if defined(TARGET_NR_bind)
2383 static void
2384 print_bind(void *cpu_env, const struct syscallname *name,
2385 abi_long arg0, abi_long arg1, abi_long arg2,
2386 abi_long arg3, abi_long arg4, abi_long arg5)
2388 print_syscall_prologue(name);
2389 print_sockfd(arg0, 0);
2390 print_sockaddr(arg1, arg2, 1);
2391 print_syscall_epilogue(name);
2393 #endif
2395 #if defined(TARGET_NR_stat) || defined(TARGET_NR_stat64) || \
2396 defined(TARGET_NR_lstat) || defined(TARGET_NR_lstat64)
2397 static void
2398 print_stat(void *cpu_env, const struct syscallname *name,
2399 abi_long arg0, abi_long arg1, abi_long arg2,
2400 abi_long arg3, abi_long arg4, abi_long arg5)
2402 print_syscall_prologue(name);
2403 print_string(arg0, 0);
2404 print_pointer(arg1, 1);
2405 print_syscall_epilogue(name);
2407 #define print_lstat print_stat
2408 #define print_stat64 print_stat
2409 #define print_lstat64 print_stat
2410 #endif
2412 #if defined(TARGET_NR_fstat) || defined(TARGET_NR_fstat64)
2413 static void
2414 print_fstat(void *cpu_env, const struct syscallname *name,
2415 abi_long arg0, abi_long arg1, abi_long arg2,
2416 abi_long arg3, abi_long arg4, abi_long arg5)
2418 print_syscall_prologue(name);
2419 print_raw_param("%d", arg0, 0);
2420 print_pointer(arg1, 1);
2421 print_syscall_epilogue(name);
2423 #define print_fstat64 print_fstat
2424 #endif
2426 #ifdef TARGET_NR_mkdir
2427 static void
2428 print_mkdir(void *cpu_env, const struct syscallname *name,
2429 abi_long arg0, abi_long arg1, abi_long arg2,
2430 abi_long arg3, abi_long arg4, abi_long arg5)
2432 print_syscall_prologue(name);
2433 print_string(arg0, 0);
2434 print_file_mode(arg1, 1);
2435 print_syscall_epilogue(name);
2437 #endif
2439 #ifdef TARGET_NR_mkdirat
2440 static void
2441 print_mkdirat(void *cpu_env, const struct syscallname *name,
2442 abi_long arg0, abi_long arg1, abi_long arg2,
2443 abi_long arg3, abi_long arg4, abi_long arg5)
2445 print_syscall_prologue(name);
2446 print_at_dirfd(arg0, 0);
2447 print_string(arg1, 0);
2448 print_file_mode(arg2, 1);
2449 print_syscall_epilogue(name);
2451 #endif
2453 #ifdef TARGET_NR_rmdir
2454 static void
2455 print_rmdir(void *cpu_env, const struct syscallname *name,
2456 abi_long arg0, abi_long arg1, abi_long arg2,
2457 abi_long arg3, abi_long arg4, abi_long arg5)
2459 print_syscall_prologue(name);
2460 print_string(arg0, 0);
2461 print_syscall_epilogue(name);
2463 #endif
2465 #ifdef TARGET_NR_rt_sigaction
2466 static void
2467 print_rt_sigaction(void *cpu_env, const struct syscallname *name,
2468 abi_long arg0, abi_long arg1, abi_long arg2,
2469 abi_long arg3, abi_long arg4, abi_long arg5)
2471 print_syscall_prologue(name);
2472 print_signal(arg0, 0);
2473 print_pointer(arg1, 0);
2474 print_pointer(arg2, 1);
2475 print_syscall_epilogue(name);
2477 #endif
2479 #ifdef TARGET_NR_rt_sigprocmask
2480 static void
2481 print_rt_sigprocmask(void *cpu_env, const struct syscallname *name,
2482 abi_long arg0, abi_long arg1, abi_long arg2,
2483 abi_long arg3, abi_long arg4, abi_long arg5)
2485 const char *how = "UNKNOWN";
2486 print_syscall_prologue(name);
2487 switch(arg0) {
2488 case TARGET_SIG_BLOCK: how = "SIG_BLOCK"; break;
2489 case TARGET_SIG_UNBLOCK: how = "SIG_UNBLOCK"; break;
2490 case TARGET_SIG_SETMASK: how = "SIG_SETMASK"; break;
2492 qemu_log("%s,", how);
2493 print_pointer(arg1, 0);
2494 print_pointer(arg2, 1);
2495 print_syscall_epilogue(name);
2497 #endif
2499 #ifdef TARGET_NR_rt_sigqueueinfo
2500 static void
2501 print_rt_sigqueueinfo(void *cpu_env, const struct syscallname *name,
2502 abi_long arg0, abi_long arg1, abi_long arg2,
2503 abi_long arg3, abi_long arg4, abi_long arg5)
2505 void *p;
2506 target_siginfo_t uinfo;
2508 print_syscall_prologue(name);
2509 print_raw_param("%d", arg0, 0);
2510 print_signal(arg1, 0);
2511 p = lock_user(VERIFY_READ, arg2, sizeof(target_siginfo_t), 1);
2512 if (p) {
2513 get_target_siginfo(&uinfo, p);
2514 print_siginfo(&uinfo);
2516 unlock_user(p, arg2, 0);
2517 } else {
2518 print_pointer(arg2, 1);
2520 print_syscall_epilogue(name);
2522 #endif
2524 #ifdef TARGET_NR_rt_tgsigqueueinfo
2525 static void
2526 print_rt_tgsigqueueinfo(void *cpu_env, const struct syscallname *name,
2527 abi_long arg0, abi_long arg1, abi_long arg2,
2528 abi_long arg3, abi_long arg4, abi_long arg5)
2530 void *p;
2531 target_siginfo_t uinfo;
2533 print_syscall_prologue(name);
2534 print_raw_param("%d", arg0, 0);
2535 print_raw_param("%d", arg1, 0);
2536 print_signal(arg2, 0);
2537 p = lock_user(VERIFY_READ, arg3, sizeof(target_siginfo_t), 1);
2538 if (p) {
2539 get_target_siginfo(&uinfo, p);
2540 print_siginfo(&uinfo);
2542 unlock_user(p, arg3, 0);
2543 } else {
2544 print_pointer(arg3, 1);
2546 print_syscall_epilogue(name);
2548 #endif
2550 #ifdef TARGET_NR_syslog
2551 static void
2552 print_syslog_action(abi_ulong arg, int last)
2554 const char *type;
2556 switch (arg) {
2557 case TARGET_SYSLOG_ACTION_CLOSE: {
2558 type = "SYSLOG_ACTION_CLOSE";
2559 break;
2561 case TARGET_SYSLOG_ACTION_OPEN: {
2562 type = "SYSLOG_ACTION_OPEN";
2563 break;
2565 case TARGET_SYSLOG_ACTION_READ: {
2566 type = "SYSLOG_ACTION_READ";
2567 break;
2569 case TARGET_SYSLOG_ACTION_READ_ALL: {
2570 type = "SYSLOG_ACTION_READ_ALL";
2571 break;
2573 case TARGET_SYSLOG_ACTION_READ_CLEAR: {
2574 type = "SYSLOG_ACTION_READ_CLEAR";
2575 break;
2577 case TARGET_SYSLOG_ACTION_CLEAR: {
2578 type = "SYSLOG_ACTION_CLEAR";
2579 break;
2581 case TARGET_SYSLOG_ACTION_CONSOLE_OFF: {
2582 type = "SYSLOG_ACTION_CONSOLE_OFF";
2583 break;
2585 case TARGET_SYSLOG_ACTION_CONSOLE_ON: {
2586 type = "SYSLOG_ACTION_CONSOLE_ON";
2587 break;
2589 case TARGET_SYSLOG_ACTION_CONSOLE_LEVEL: {
2590 type = "SYSLOG_ACTION_CONSOLE_LEVEL";
2591 break;
2593 case TARGET_SYSLOG_ACTION_SIZE_UNREAD: {
2594 type = "SYSLOG_ACTION_SIZE_UNREAD";
2595 break;
2597 case TARGET_SYSLOG_ACTION_SIZE_BUFFER: {
2598 type = "SYSLOG_ACTION_SIZE_BUFFER";
2599 break;
2601 default: {
2602 print_raw_param("%ld", arg, last);
2603 return;
2606 qemu_log("%s%s", type, get_comma(last));
2609 static void
2610 print_syslog(void *cpu_env, const struct syscallname *name,
2611 abi_long arg0, abi_long arg1, abi_long arg2,
2612 abi_long arg3, abi_long arg4, abi_long arg5)
2614 print_syscall_prologue(name);
2615 print_syslog_action(arg0, 0);
2616 print_pointer(arg1, 0);
2617 print_raw_param("%d", arg2, 1);
2618 print_syscall_epilogue(name);
2620 #endif
2622 #ifdef TARGET_NR_mknod
2623 static void
2624 print_mknod(void *cpu_env, const struct syscallname *name,
2625 abi_long arg0, abi_long arg1, abi_long arg2,
2626 abi_long arg3, abi_long arg4, abi_long arg5)
2628 int hasdev = (arg1 & (S_IFCHR|S_IFBLK));
2630 print_syscall_prologue(name);
2631 print_string(arg0, 0);
2632 print_file_mode(arg1, (hasdev == 0));
2633 if (hasdev) {
2634 print_raw_param("makedev(%d", major(arg2), 0);
2635 print_raw_param("%d)", minor(arg2), 1);
2637 print_syscall_epilogue(name);
2639 #endif
2641 #ifdef TARGET_NR_mknodat
2642 static void
2643 print_mknodat(void *cpu_env, const struct syscallname *name,
2644 abi_long arg0, abi_long arg1, abi_long arg2,
2645 abi_long arg3, abi_long arg4, abi_long arg5)
2647 int hasdev = (arg2 & (S_IFCHR|S_IFBLK));
2649 print_syscall_prologue(name);
2650 print_at_dirfd(arg0, 0);
2651 print_string(arg1, 0);
2652 print_file_mode(arg2, (hasdev == 0));
2653 if (hasdev) {
2654 print_raw_param("makedev(%d", major(arg3), 0);
2655 print_raw_param("%d)", minor(arg3), 1);
2657 print_syscall_epilogue(name);
2659 #endif
2661 #ifdef TARGET_NR_mq_open
2662 static void
2663 print_mq_open(void *cpu_env, const struct syscallname *name,
2664 abi_long arg0, abi_long arg1, abi_long arg2,
2665 abi_long arg3, abi_long arg4, abi_long arg5)
2667 int is_creat = (arg1 & TARGET_O_CREAT);
2669 print_syscall_prologue(name);
2670 print_string(arg0, 0);
2671 print_open_flags(arg1, (is_creat == 0));
2672 if (is_creat) {
2673 print_file_mode(arg2, 0);
2674 print_pointer(arg3, 1);
2676 print_syscall_epilogue(name);
2678 #endif
2680 #ifdef TARGET_NR_open
2681 static void
2682 print_open(void *cpu_env, const struct syscallname *name,
2683 abi_long arg0, abi_long arg1, abi_long arg2,
2684 abi_long arg3, abi_long arg4, abi_long arg5)
2686 int is_creat = (arg1 & TARGET_O_CREAT);
2688 print_syscall_prologue(name);
2689 print_string(arg0, 0);
2690 print_open_flags(arg1, (is_creat == 0));
2691 if (is_creat)
2692 print_file_mode(arg2, 1);
2693 print_syscall_epilogue(name);
2695 #endif
2697 #ifdef TARGET_NR_openat
2698 static void
2699 print_openat(void *cpu_env, const struct syscallname *name,
2700 abi_long arg0, abi_long arg1, abi_long arg2,
2701 abi_long arg3, abi_long arg4, abi_long arg5)
2703 int is_creat = (arg2 & TARGET_O_CREAT);
2705 print_syscall_prologue(name);
2706 print_at_dirfd(arg0, 0);
2707 print_string(arg1, 0);
2708 print_open_flags(arg2, (is_creat == 0));
2709 if (is_creat)
2710 print_file_mode(arg3, 1);
2711 print_syscall_epilogue(name);
2713 #endif
2715 #ifdef TARGET_NR_mq_unlink
2716 static void
2717 print_mq_unlink(void *cpu_env, const struct syscallname *name,
2718 abi_long arg0, abi_long arg1, abi_long arg2,
2719 abi_long arg3, abi_long arg4, abi_long arg5)
2721 print_syscall_prologue(name);
2722 print_string(arg0, 1);
2723 print_syscall_epilogue(name);
2725 #endif
2727 #if defined(TARGET_NR_fstatat64) || defined(TARGET_NR_newfstatat)
2728 static void
2729 print_fstatat64(void *cpu_env, const struct syscallname *name,
2730 abi_long arg0, abi_long arg1, abi_long arg2,
2731 abi_long arg3, abi_long arg4, abi_long arg5)
2733 print_syscall_prologue(name);
2734 print_at_dirfd(arg0, 0);
2735 print_string(arg1, 0);
2736 print_pointer(arg2, 0);
2737 print_flags(at_file_flags, arg3, 1);
2738 print_syscall_epilogue(name);
2740 #define print_newfstatat print_fstatat64
2741 #endif
2743 #ifdef TARGET_NR_readlink
2744 static void
2745 print_readlink(void *cpu_env, const struct syscallname *name,
2746 abi_long arg0, abi_long arg1, abi_long arg2,
2747 abi_long arg3, abi_long arg4, abi_long arg5)
2749 print_syscall_prologue(name);
2750 print_string(arg0, 0);
2751 print_pointer(arg1, 0);
2752 print_raw_param("%u", arg2, 1);
2753 print_syscall_epilogue(name);
2755 #endif
2757 #ifdef TARGET_NR_readlinkat
2758 static void
2759 print_readlinkat(void *cpu_env, const struct syscallname *name,
2760 abi_long arg0, abi_long arg1, abi_long arg2,
2761 abi_long arg3, abi_long arg4, abi_long arg5)
2763 print_syscall_prologue(name);
2764 print_at_dirfd(arg0, 0);
2765 print_string(arg1, 0);
2766 print_pointer(arg2, 0);
2767 print_raw_param("%u", arg3, 1);
2768 print_syscall_epilogue(name);
2770 #endif
2772 #ifdef TARGET_NR_rename
2773 static void
2774 print_rename(void *cpu_env, const struct syscallname *name,
2775 abi_long arg0, abi_long arg1, abi_long arg2,
2776 abi_long arg3, abi_long arg4, abi_long arg5)
2778 print_syscall_prologue(name);
2779 print_string(arg0, 0);
2780 print_string(arg1, 1);
2781 print_syscall_epilogue(name);
2783 #endif
2785 #ifdef TARGET_NR_renameat
2786 static void
2787 print_renameat(void *cpu_env, const struct syscallname *name,
2788 abi_long arg0, abi_long arg1, abi_long arg2,
2789 abi_long arg3, abi_long arg4, abi_long arg5)
2791 print_syscall_prologue(name);
2792 print_at_dirfd(arg0, 0);
2793 print_string(arg1, 0);
2794 print_at_dirfd(arg2, 0);
2795 print_string(arg3, 1);
2796 print_syscall_epilogue(name);
2798 #endif
2800 #ifdef TARGET_NR_statfs
2801 static void
2802 print_statfs(void *cpu_env, const struct syscallname *name,
2803 abi_long arg0, abi_long arg1, abi_long arg2,
2804 abi_long arg3, abi_long arg4, abi_long arg5)
2806 print_syscall_prologue(name);
2807 print_string(arg0, 0);
2808 print_pointer(arg1, 1);
2809 print_syscall_epilogue(name);
2811 #endif
2813 #ifdef TARGET_NR_statfs64
2814 static void
2815 print_statfs64(void *cpu_env, const struct syscallname *name,
2816 abi_long arg0, abi_long arg1, abi_long arg2,
2817 abi_long arg3, abi_long arg4, abi_long arg5)
2819 print_syscall_prologue(name);
2820 print_string(arg0, 0);
2821 print_pointer(arg1, 1);
2822 print_syscall_epilogue(name);
2824 #endif
2826 #ifdef TARGET_NR_symlink
2827 static void
2828 print_symlink(void *cpu_env, const struct syscallname *name,
2829 abi_long arg0, abi_long arg1, abi_long arg2,
2830 abi_long arg3, abi_long arg4, abi_long arg5)
2832 print_syscall_prologue(name);
2833 print_string(arg0, 0);
2834 print_string(arg1, 1);
2835 print_syscall_epilogue(name);
2837 #endif
2839 #ifdef TARGET_NR_symlinkat
2840 static void
2841 print_symlinkat(void *cpu_env, const struct syscallname *name,
2842 abi_long arg0, abi_long arg1, abi_long arg2,
2843 abi_long arg3, abi_long arg4, abi_long arg5)
2845 print_syscall_prologue(name);
2846 print_string(arg0, 0);
2847 print_at_dirfd(arg1, 0);
2848 print_string(arg2, 1);
2849 print_syscall_epilogue(name);
2851 #endif
2853 #ifdef TARGET_NR_mount
2854 static void
2855 print_mount(void *cpu_env, const struct syscallname *name,
2856 abi_long arg0, abi_long arg1, abi_long arg2,
2857 abi_long arg3, abi_long arg4, abi_long arg5)
2859 print_syscall_prologue(name);
2860 print_string(arg0, 0);
2861 print_string(arg1, 0);
2862 print_string(arg2, 0);
2863 print_flags(mount_flags, arg3, 0);
2864 print_pointer(arg4, 1);
2865 print_syscall_epilogue(name);
2867 #endif
2869 #ifdef TARGET_NR_umount
2870 static void
2871 print_umount(void *cpu_env, const struct syscallname *name,
2872 abi_long arg0, abi_long arg1, abi_long arg2,
2873 abi_long arg3, abi_long arg4, abi_long arg5)
2875 print_syscall_prologue(name);
2876 print_string(arg0, 1);
2877 print_syscall_epilogue(name);
2879 #endif
2881 #ifdef TARGET_NR_umount2
2882 static void
2883 print_umount2(void *cpu_env, const struct syscallname *name,
2884 abi_long arg0, abi_long arg1, abi_long arg2,
2885 abi_long arg3, abi_long arg4, abi_long arg5)
2887 print_syscall_prologue(name);
2888 print_string(arg0, 0);
2889 print_flags(umount2_flags, arg1, 1);
2890 print_syscall_epilogue(name);
2892 #endif
2894 #ifdef TARGET_NR_unlink
2895 static void
2896 print_unlink(void *cpu_env, const struct syscallname *name,
2897 abi_long arg0, abi_long arg1, abi_long arg2,
2898 abi_long arg3, abi_long arg4, abi_long arg5)
2900 print_syscall_prologue(name);
2901 print_string(arg0, 1);
2902 print_syscall_epilogue(name);
2904 #endif
2906 #ifdef TARGET_NR_unlinkat
2907 static void
2908 print_unlinkat(void *cpu_env, const struct syscallname *name,
2909 abi_long arg0, abi_long arg1, abi_long arg2,
2910 abi_long arg3, abi_long arg4, abi_long arg5)
2912 print_syscall_prologue(name);
2913 print_at_dirfd(arg0, 0);
2914 print_string(arg1, 0);
2915 print_flags(unlinkat_flags, arg2, 1);
2916 print_syscall_epilogue(name);
2918 #endif
2920 #ifdef TARGET_NR_utime
2921 static void
2922 print_utime(void *cpu_env, const struct syscallname *name,
2923 abi_long arg0, abi_long arg1, abi_long arg2,
2924 abi_long arg3, abi_long arg4, abi_long arg5)
2926 print_syscall_prologue(name);
2927 print_string(arg0, 0);
2928 print_pointer(arg1, 1);
2929 print_syscall_epilogue(name);
2931 #endif
2933 #ifdef TARGET_NR_utimes
2934 static void
2935 print_utimes(void *cpu_env, const struct syscallname *name,
2936 abi_long arg0, abi_long arg1, abi_long arg2,
2937 abi_long arg3, abi_long arg4, abi_long arg5)
2939 print_syscall_prologue(name);
2940 print_string(arg0, 0);
2941 print_pointer(arg1, 1);
2942 print_syscall_epilogue(name);
2944 #endif
2946 #ifdef TARGET_NR_utimensat
2947 static void
2948 print_utimensat(void *cpu_env, const struct syscallname *name,
2949 abi_long arg0, abi_long arg1, abi_long arg2,
2950 abi_long arg3, abi_long arg4, abi_long arg5)
2952 print_syscall_prologue(name);
2953 print_at_dirfd(arg0, 0);
2954 print_string(arg1, 0);
2955 print_pointer(arg2, 0);
2956 print_flags(at_file_flags, arg3, 1);
2957 print_syscall_epilogue(name);
2959 #endif
2961 #if defined(TARGET_NR_mmap) || defined(TARGET_NR_mmap2)
2962 static void
2963 print_mmap(void *cpu_env, const struct syscallname *name,
2964 abi_long arg0, abi_long arg1, abi_long arg2,
2965 abi_long arg3, abi_long arg4, abi_long arg5)
2967 print_syscall_prologue(name);
2968 print_pointer(arg0, 0);
2969 print_raw_param("%d", arg1, 0);
2970 print_flags(mmap_prot_flags, arg2, 0);
2971 print_flags(mmap_flags, arg3, 0);
2972 print_raw_param("%d", arg4, 0);
2973 print_raw_param("%#x", arg5, 1);
2974 print_syscall_epilogue(name);
2976 #define print_mmap2 print_mmap
2977 #endif
2979 #ifdef TARGET_NR_mprotect
2980 static void
2981 print_mprotect(void *cpu_env, const struct syscallname *name,
2982 abi_long arg0, abi_long arg1, abi_long arg2,
2983 abi_long arg3, abi_long arg4, abi_long arg5)
2985 print_syscall_prologue(name);
2986 print_pointer(arg0, 0);
2987 print_raw_param("%d", arg1, 0);
2988 print_flags(mmap_prot_flags, arg2, 1);
2989 print_syscall_epilogue(name);
2991 #endif
2993 #ifdef TARGET_NR_munmap
2994 static void
2995 print_munmap(void *cpu_env, const struct syscallname *name,
2996 abi_long arg0, abi_long arg1, abi_long arg2,
2997 abi_long arg3, abi_long arg4, abi_long arg5)
2999 print_syscall_prologue(name);
3000 print_pointer(arg0, 0);
3001 print_raw_param("%d", arg1, 1);
3002 print_syscall_epilogue(name);
3004 #endif
3006 #ifdef TARGET_NR_futex
3007 static void print_futex_op(abi_long tflag, int last)
3009 #define print_op(val) \
3010 if( cmd == val ) { \
3011 qemu_log(#val); \
3012 return; \
3015 int cmd = (int)tflag;
3016 #ifdef FUTEX_PRIVATE_FLAG
3017 if (cmd & FUTEX_PRIVATE_FLAG) {
3018 qemu_log("FUTEX_PRIVATE_FLAG|");
3019 cmd &= ~FUTEX_PRIVATE_FLAG;
3021 #endif
3022 #ifdef FUTEX_CLOCK_REALTIME
3023 if (cmd & FUTEX_CLOCK_REALTIME) {
3024 qemu_log("FUTEX_CLOCK_REALTIME|");
3025 cmd &= ~FUTEX_CLOCK_REALTIME;
3027 #endif
3028 print_op(FUTEX_WAIT)
3029 print_op(FUTEX_WAKE)
3030 print_op(FUTEX_FD)
3031 print_op(FUTEX_REQUEUE)
3032 print_op(FUTEX_CMP_REQUEUE)
3033 print_op(FUTEX_WAKE_OP)
3034 print_op(FUTEX_LOCK_PI)
3035 print_op(FUTEX_UNLOCK_PI)
3036 print_op(FUTEX_TRYLOCK_PI)
3037 #ifdef FUTEX_WAIT_BITSET
3038 print_op(FUTEX_WAIT_BITSET)
3039 #endif
3040 #ifdef FUTEX_WAKE_BITSET
3041 print_op(FUTEX_WAKE_BITSET)
3042 #endif
3043 /* unknown values */
3044 qemu_log("%d", cmd);
3047 static void
3048 print_futex(void *cpu_env, const struct syscallname *name,
3049 abi_long arg0, abi_long arg1, abi_long arg2,
3050 abi_long arg3, abi_long arg4, abi_long arg5)
3052 print_syscall_prologue(name);
3053 print_pointer(arg0, 0);
3054 print_futex_op(arg1, 0);
3055 print_raw_param(",%d", arg2, 0);
3056 print_pointer(arg3, 0); /* struct timespec */
3057 print_pointer(arg4, 0);
3058 print_raw_param("%d", arg4, 1);
3059 print_syscall_epilogue(name);
3061 #endif
3063 #ifdef TARGET_NR_kill
3064 static void
3065 print_kill(void *cpu_env, const struct syscallname *name,
3066 abi_long arg0, abi_long arg1, abi_long arg2,
3067 abi_long arg3, abi_long arg4, abi_long arg5)
3069 print_syscall_prologue(name);
3070 print_raw_param("%d", arg0, 0);
3071 print_signal(arg1, 1);
3072 print_syscall_epilogue(name);
3074 #endif
3076 #ifdef TARGET_NR_tkill
3077 static void
3078 print_tkill(void *cpu_env, const struct syscallname *name,
3079 abi_long arg0, abi_long arg1, abi_long arg2,
3080 abi_long arg3, abi_long arg4, abi_long arg5)
3082 print_syscall_prologue(name);
3083 print_raw_param("%d", arg0, 0);
3084 print_signal(arg1, 1);
3085 print_syscall_epilogue(name);
3087 #endif
3089 #ifdef TARGET_NR_tgkill
3090 static void
3091 print_tgkill(void *cpu_env, const struct syscallname *name,
3092 abi_long arg0, abi_long arg1, abi_long arg2,
3093 abi_long arg3, abi_long arg4, abi_long arg5)
3095 print_syscall_prologue(name);
3096 print_raw_param("%d", arg0, 0);
3097 print_raw_param("%d", arg1, 0);
3098 print_signal(arg2, 1);
3099 print_syscall_epilogue(name);
3101 #endif
3103 #ifdef TARGET_NR_statx
3104 static void
3105 print_statx(void *cpu_env, const struct syscallname *name,
3106 abi_long arg0, abi_long arg1, abi_long arg2,
3107 abi_long arg3, abi_long arg4, abi_long arg5)
3109 print_syscall_prologue(name);
3110 print_at_dirfd(arg0, 0);
3111 print_string(arg1, 0);
3112 print_flags(statx_flags, arg2, 0);
3113 print_flags(statx_mask, arg3, 0);
3114 print_pointer(arg4, 1);
3115 print_syscall_epilogue(name);
3117 #endif
3119 #ifdef TARGET_NR_ioctl
3120 static void
3121 print_ioctl(void *cpu_env, const struct syscallname *name,
3122 abi_long arg0, abi_long arg1, abi_long arg2,
3123 abi_long arg3, abi_long arg4, abi_long arg5)
3125 print_syscall_prologue(name);
3126 print_raw_param("%d", arg0, 0);
3128 const IOCTLEntry *ie;
3129 const argtype *arg_type;
3130 void *argptr;
3131 int target_size;
3133 for (ie = ioctl_entries; ie->target_cmd != 0; ie++) {
3134 if (ie->target_cmd == arg1) {
3135 break;
3139 if (ie->target_cmd == 0) {
3140 print_raw_param("%#x", arg1, 0);
3141 print_raw_param("%#x", arg2, 1);
3142 } else {
3143 qemu_log("%s", ie->name);
3144 arg_type = ie->arg_type;
3146 if (arg_type[0] != TYPE_NULL) {
3147 qemu_log(",");
3149 switch (arg_type[0]) {
3150 case TYPE_PTRVOID:
3151 print_pointer(arg2, 1);
3152 break;
3153 case TYPE_CHAR:
3154 case TYPE_SHORT:
3155 case TYPE_INT:
3156 print_raw_param("%d", arg2, 1);
3157 break;
3158 case TYPE_LONG:
3159 print_raw_param(TARGET_ABI_FMT_ld, arg2, 1);
3160 break;
3161 case TYPE_ULONG:
3162 print_raw_param(TARGET_ABI_FMT_lu, arg2, 1);
3163 break;
3164 case TYPE_PTR:
3165 switch (ie->access) {
3166 case IOC_R:
3167 print_pointer(arg2, 1);
3168 break;
3169 case IOC_W:
3170 case IOC_RW:
3171 arg_type++;
3172 target_size = thunk_type_size(arg_type, 0);
3173 argptr = lock_user(VERIFY_READ, arg2, target_size, 1);
3174 if (argptr) {
3175 thunk_print(argptr, arg_type);
3176 unlock_user(argptr, arg2, target_size);
3177 } else {
3178 print_pointer(arg2, 1);
3180 break;
3182 break;
3183 default:
3184 g_assert_not_reached();
3188 print_syscall_epilogue(name);
3190 #endif
3193 * An array of all of the syscalls we know about
3196 static const struct syscallname scnames[] = {
3197 #include "strace.list"
3200 static int nsyscalls = ARRAY_SIZE(scnames);
3203 * The public interface to this module.
3205 void
3206 print_syscall(void *cpu_env, int num,
3207 abi_long arg1, abi_long arg2, abi_long arg3,
3208 abi_long arg4, abi_long arg5, abi_long arg6)
3210 int i;
3211 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 ")";
3213 qemu_log("%d ", getpid());
3215 for(i=0;i<nsyscalls;i++)
3216 if( scnames[i].nr == num ) {
3217 if( scnames[i].call != NULL ) {
3218 scnames[i].call(
3219 cpu_env, &scnames[i], arg1, arg2, arg3, arg4, arg5, arg6);
3220 } else {
3221 /* XXX: this format system is broken because it uses
3222 host types and host pointers for strings */
3223 if( scnames[i].format != NULL )
3224 format = scnames[i].format;
3225 qemu_log(format,
3226 scnames[i].name, arg1, arg2, arg3, arg4, arg5, arg6);
3228 return;
3230 qemu_log("Unknown syscall %d\n", num);
3234 void
3235 print_syscall_ret(void *cpu_env, int num, abi_long ret,
3236 abi_long arg1, abi_long arg2, abi_long arg3,
3237 abi_long arg4, abi_long arg5, abi_long arg6)
3239 int i;
3241 for(i=0;i<nsyscalls;i++)
3242 if( scnames[i].nr == num ) {
3243 if( scnames[i].result != NULL ) {
3244 scnames[i].result(cpu_env, &scnames[i], ret,
3245 arg1, arg2, arg3,
3246 arg4, arg5, arg6);
3247 } else {
3248 if (!print_syscall_err(ret)) {
3249 qemu_log(TARGET_ABI_FMT_ld, ret);
3251 qemu_log("\n");
3253 break;
3257 void print_taken_signal(int target_signum, const target_siginfo_t *tinfo)
3259 /* Print the strace output for a signal being taken:
3260 * --- SIGSEGV {si_signo=SIGSEGV, si_code=SI_KERNEL, si_addr=0} ---
3262 qemu_log("--- ");
3263 print_signal(target_signum, 1);
3264 qemu_log(" ");
3265 print_siginfo(tinfo);
3266 qemu_log(" ---\n");