]> git.proxmox.com Git - mirror_qemu.git/blob - linux-user/strace.c
linux-user: Add strace support for printing argument of syscalls used for extended...
[mirror_qemu.git] / linux-user / strace.c
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"
14
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);
25 };
26
27 #ifdef __GNUC__
28 /*
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.
33 */
34 #define UNUSED __attribute__ ((unused))
35 #else
36 #define UNUSED
37 #endif
38
39 /*
40 * Structure used to translate flag values into strings. This is
41 * similar that is in the actual strace tool.
42 */
43 struct flags {
44 abi_long f_value; /* flag */
45 const char *f_string; /* stringified flag */
46 };
47
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 }
54
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);
74
75 /*
76 * Utility functions
77 */
78 static void
79 print_ipc_cmd(int cmd)
80 {
81 #define output_cmd(val) \
82 if( cmd == val ) { \
83 qemu_log(#val); \
84 return; \
85 }
86
87 cmd &= 0xff;
88
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 );
121
122 /* Some value we don't recognize */
123 qemu_log("%d", cmd);
124 }
125
126 static void
127 print_signal(abi_ulong arg, int last)
128 {
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;
149 }
150 if (signal_name == NULL) {
151 print_raw_param("%ld", arg, last);
152 return;
153 }
154 qemu_log("%s%s", signal_name, get_comma(last));
155 }
156
157 static void print_si_code(int arg)
158 {
159 const char *codename = NULL;
160
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;
189 }
190 qemu_log("%s", codename);
191 }
192
193 static void get_target_siginfo(target_siginfo_t *tinfo,
194 const target_siginfo_t *info)
195 {
196 abi_ulong sival_ptr;
197
198 int sig;
199 int si_errno;
200 int si_code;
201 int si_type;
202
203 __get_user(sig, &info->si_signo);
204 __get_user(si_errno, &tinfo->si_errno);
205 __get_user(si_code, &info->si_code);
206
207 tinfo->si_signo = sig;
208 tinfo->si_errno = si_errno;
209 tinfo->si_code = si_code;
210
211 /* Ensure we don't leak random junk to the guest later */
212 memset(tinfo->_sifields._pad, 0, sizeof(tinfo->_sifields._pad));
213
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.
222 *
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.
227 */
228
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.
235 */
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;
270
271 si_type = QEMU_SI_RT;
272 break;
273 }
274 break;
275 }
276
277 tinfo->si_code = deposit32(si_code, 16, 16, si_type);
278 }
279
280 static void print_siginfo(const target_siginfo_t *tinfo)
281 {
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.
287 */
288 int si_type = extract32(tinfo->si_code, 16, 16);
289 int si_code = sextract32(tinfo->si_code, 0, 16);
290
291 qemu_log("{si_signo=");
292 print_signal(tinfo->si_signo, 1);
293 qemu_log(", si_code=");
294 print_si_code(si_code);
295
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();
334 }
335 qemu_log("}");
336 }
337
338 static void
339 print_sockaddr(abi_ulong addr, abi_long addrlen, int last)
340 {
341 struct target_sockaddr *sa;
342 int i;
343 int sa_family;
344
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]);
357 }
358 qemu_log("\"}");
359 break;
360 }
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;
370 }
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;
396 }
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;
401 }
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;
407 }
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]);
412 }
413 qemu_log("%02x}", sa->sa_data[i]);
414 qemu_log("}");
415 break;
416 }
417 unlock_user(sa, addr, 0);
418 } else {
419 print_raw_param("0x"TARGET_ABI_FMT_lx, addr, 0);
420 }
421 qemu_log(", "TARGET_ABI_FMT_ld"%s", addrlen, get_comma(last));
422 }
423
424 static void
425 print_socket_domain(int domain)
426 {
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;
443 }
444 }
445
446 static void
447 print_socket_type(int type)
448 {
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;
468 }
469 if (type & TARGET_SOCK_CLOEXEC) {
470 qemu_log("|SOCK_CLOEXEC");
471 }
472 if (type & TARGET_SOCK_NONBLOCK) {
473 qemu_log("|SOCK_NONBLOCK");
474 }
475 }
476
477 static void
478 print_socket_protocol(int domain, int type, int protocol)
479 {
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);
488 }
489 return;
490 }
491
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;
515 }
516 return;
517 }
518
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;
535 }
536 }
537
538
539 #ifdef TARGET_NR__newselect
540 static void
541 print_fdset(int n, abi_ulong target_fds_addr)
542 {
543 int i;
544
545 qemu_log("[");
546 if( target_fds_addr ) {
547 abi_long *target_fds;
548
549 target_fds = lock_user(VERIFY_READ,
550 target_fds_addr,
551 sizeof(*target_fds)*(n / TARGET_ABI_BITS + 1),
552 1);
553
554 if (!target_fds)
555 return;
556
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);
560 }
561 unlock_user(target_fds, target_fds_addr, 0);
562 }
563 qemu_log("]");
564 }
565 #endif
566
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
581
582 static void
583 print_clockid(int clockid, int last)
584 {
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;
625 }
626 qemu_log("%s", get_comma(last));
627 }
628 #endif
629
630 /*
631 * Sysycall specific output functions
632 */
633
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)
640 {
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);
650 }
651 #endif
652
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)
658 {
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);
663 }
664 #endif
665
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)
670 {
671 abi_ulong arg_ptr_addr;
672 char *s;
673
674 if (!(s = lock_user_string(arg1)))
675 return;
676 qemu_log("%s(\"%s\",{", name->name, s);
677 unlock_user(s, arg1, 0);
678
679 for (arg_ptr_addr = arg2; ; arg_ptr_addr += sizeof(abi_ulong)) {
680 abi_ulong *arg_ptr, arg_addr;
681
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);
692 }
693 }
694
695 qemu_log("NULL})");
696 }
697
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)
703 {
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);
719 }
720 }
721 #endif
722
723 /*
724 * Variants for the return value output function
725 */
726
727 static void
728 print_syscall_err(abi_long ret)
729 {
730 const char *errstr = NULL;
731
732 qemu_log(" = ");
733 if (ret < 0) {
734 qemu_log("-1 errno=%d", errno);
735 errstr = target_strerror(-ret);
736 if (errstr) {
737 qemu_log(" (%s)", errstr);
738 }
739 }
740 }
741
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)
746 {
747 print_syscall_err(ret);
748
749 if (ret >= 0) {
750 qemu_log("0x" TARGET_ABI_FMT_lx "\n", ret);
751 }
752 }
753
754 #if 0 /* currently unused */
755 static void
756 print_syscall_ret_raw(struct syscallname *name, abi_long ret)
757 {
758 qemu_log(" = 0x" TARGET_ABI_FMT_lx "\n", ret);
759 }
760 #endif
761
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)
767 {
768 print_syscall_err(ret);
769
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(")");
780 }
781
782 qemu_log("\n");
783 }
784 #endif
785
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)
798 {
799 print_syscall_err(ret);
800
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;
822 }
823 }
824
825 qemu_log("\n");
826 }
827 #endif
828
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)
835 {
836 print_syscall_err(ret);
837
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(",");
846 }
847 print_string(attr, 1);
848 ret -= target_strlen(attr) + 1;
849 attr += target_strlen(attr) + 1;
850 }
851 } else {
852 qemu_log("NULL");
853 }
854 qemu_log(")");
855 }
856
857 qemu_log("\n");
858 }
859 #define print_syscall_ret_llistxattr print_syscall_ret_listxattr
860 #define print_syscall_ret_flistxattr print_syscall_ret_listxattr
861 #endif
862
863 UNUSED static struct flags access_flags[] = {
864 FLAG_GENERIC(F_OK),
865 FLAG_GENERIC(R_OK),
866 FLAG_GENERIC(W_OK),
867 FLAG_GENERIC(X_OK),
868 FLAG_END,
869 };
870
871 UNUSED static struct flags at_file_flags[] = {
872 #ifdef AT_EACCESS
873 FLAG_GENERIC(AT_EACCESS),
874 #endif
875 #ifdef AT_SYMLINK_NOFOLLOW
876 FLAG_GENERIC(AT_SYMLINK_NOFOLLOW),
877 #endif
878 FLAG_END,
879 };
880
881 UNUSED static struct flags unlinkat_flags[] = {
882 #ifdef AT_REMOVEDIR
883 FLAG_GENERIC(AT_REMOVEDIR),
884 #endif
885 FLAG_END,
886 };
887
888 UNUSED static struct flags mode_flags[] = {
889 FLAG_GENERIC(S_IFSOCK),
890 FLAG_GENERIC(S_IFLNK),
891 FLAG_GENERIC(S_IFREG),
892 FLAG_GENERIC(S_IFBLK),
893 FLAG_GENERIC(S_IFDIR),
894 FLAG_GENERIC(S_IFCHR),
895 FLAG_GENERIC(S_IFIFO),
896 FLAG_END,
897 };
898
899 UNUSED static struct flags open_access_flags[] = {
900 FLAG_TARGET(O_RDONLY),
901 FLAG_TARGET(O_WRONLY),
902 FLAG_TARGET(O_RDWR),
903 FLAG_END,
904 };
905
906 UNUSED static struct flags open_flags[] = {
907 FLAG_TARGET(O_APPEND),
908 FLAG_TARGET(O_CREAT),
909 FLAG_TARGET(O_DIRECTORY),
910 FLAG_TARGET(O_EXCL),
911 FLAG_TARGET(O_LARGEFILE),
912 FLAG_TARGET(O_NOCTTY),
913 FLAG_TARGET(O_NOFOLLOW),
914 FLAG_TARGET(O_NONBLOCK), /* also O_NDELAY */
915 FLAG_TARGET(O_DSYNC),
916 FLAG_TARGET(__O_SYNC),
917 FLAG_TARGET(O_TRUNC),
918 #ifdef O_DIRECT
919 FLAG_TARGET(O_DIRECT),
920 #endif
921 #ifdef O_NOATIME
922 FLAG_TARGET(O_NOATIME),
923 #endif
924 #ifdef O_CLOEXEC
925 FLAG_TARGET(O_CLOEXEC),
926 #endif
927 #ifdef O_PATH
928 FLAG_TARGET(O_PATH),
929 #endif
930 #ifdef O_TMPFILE
931 FLAG_TARGET(O_TMPFILE),
932 FLAG_TARGET(__O_TMPFILE),
933 #endif
934 FLAG_END,
935 };
936
937 UNUSED static struct flags mount_flags[] = {
938 #ifdef MS_BIND
939 FLAG_GENERIC(MS_BIND),
940 #endif
941 #ifdef MS_DIRSYNC
942 FLAG_GENERIC(MS_DIRSYNC),
943 #endif
944 FLAG_GENERIC(MS_MANDLOCK),
945 #ifdef MS_MOVE
946 FLAG_GENERIC(MS_MOVE),
947 #endif
948 FLAG_GENERIC(MS_NOATIME),
949 FLAG_GENERIC(MS_NODEV),
950 FLAG_GENERIC(MS_NODIRATIME),
951 FLAG_GENERIC(MS_NOEXEC),
952 FLAG_GENERIC(MS_NOSUID),
953 FLAG_GENERIC(MS_RDONLY),
954 #ifdef MS_RELATIME
955 FLAG_GENERIC(MS_RELATIME),
956 #endif
957 FLAG_GENERIC(MS_REMOUNT),
958 FLAG_GENERIC(MS_SYNCHRONOUS),
959 FLAG_END,
960 };
961
962 UNUSED static struct flags umount2_flags[] = {
963 #ifdef MNT_FORCE
964 FLAG_GENERIC(MNT_FORCE),
965 #endif
966 #ifdef MNT_DETACH
967 FLAG_GENERIC(MNT_DETACH),
968 #endif
969 #ifdef MNT_EXPIRE
970 FLAG_GENERIC(MNT_EXPIRE),
971 #endif
972 FLAG_END,
973 };
974
975 UNUSED static struct flags mmap_prot_flags[] = {
976 FLAG_GENERIC(PROT_NONE),
977 FLAG_GENERIC(PROT_EXEC),
978 FLAG_GENERIC(PROT_READ),
979 FLAG_GENERIC(PROT_WRITE),
980 FLAG_TARGET(PROT_SEM),
981 FLAG_GENERIC(PROT_GROWSDOWN),
982 FLAG_GENERIC(PROT_GROWSUP),
983 FLAG_END,
984 };
985
986 UNUSED static struct flags mmap_flags[] = {
987 FLAG_TARGET(MAP_SHARED),
988 FLAG_TARGET(MAP_PRIVATE),
989 FLAG_TARGET(MAP_ANONYMOUS),
990 FLAG_TARGET(MAP_DENYWRITE),
991 FLAG_TARGET(MAP_FIXED),
992 FLAG_TARGET(MAP_GROWSDOWN),
993 FLAG_TARGET(MAP_EXECUTABLE),
994 #ifdef MAP_LOCKED
995 FLAG_TARGET(MAP_LOCKED),
996 #endif
997 #ifdef MAP_NONBLOCK
998 FLAG_TARGET(MAP_NONBLOCK),
999 #endif
1000 FLAG_TARGET(MAP_NORESERVE),
1001 #ifdef MAP_POPULATE
1002 FLAG_TARGET(MAP_POPULATE),
1003 #endif
1004 #ifdef TARGET_MAP_UNINITIALIZED
1005 FLAG_TARGET(MAP_UNINITIALIZED),
1006 #endif
1007 FLAG_END,
1008 };
1009
1010 UNUSED static struct flags clone_flags[] = {
1011 FLAG_GENERIC(CLONE_VM),
1012 FLAG_GENERIC(CLONE_FS),
1013 FLAG_GENERIC(CLONE_FILES),
1014 FLAG_GENERIC(CLONE_SIGHAND),
1015 FLAG_GENERIC(CLONE_PTRACE),
1016 FLAG_GENERIC(CLONE_VFORK),
1017 FLAG_GENERIC(CLONE_PARENT),
1018 FLAG_GENERIC(CLONE_THREAD),
1019 FLAG_GENERIC(CLONE_NEWNS),
1020 FLAG_GENERIC(CLONE_SYSVSEM),
1021 FLAG_GENERIC(CLONE_SETTLS),
1022 FLAG_GENERIC(CLONE_PARENT_SETTID),
1023 FLAG_GENERIC(CLONE_CHILD_CLEARTID),
1024 FLAG_GENERIC(CLONE_DETACHED),
1025 FLAG_GENERIC(CLONE_UNTRACED),
1026 FLAG_GENERIC(CLONE_CHILD_SETTID),
1027 #if defined(CLONE_NEWUTS)
1028 FLAG_GENERIC(CLONE_NEWUTS),
1029 #endif
1030 #if defined(CLONE_NEWIPC)
1031 FLAG_GENERIC(CLONE_NEWIPC),
1032 #endif
1033 #if defined(CLONE_NEWUSER)
1034 FLAG_GENERIC(CLONE_NEWUSER),
1035 #endif
1036 #if defined(CLONE_NEWPID)
1037 FLAG_GENERIC(CLONE_NEWPID),
1038 #endif
1039 #if defined(CLONE_NEWNET)
1040 FLAG_GENERIC(CLONE_NEWNET),
1041 #endif
1042 #if defined(CLONE_IO)
1043 FLAG_GENERIC(CLONE_IO),
1044 #endif
1045 FLAG_END,
1046 };
1047
1048 UNUSED static struct flags msg_flags[] = {
1049 /* send */
1050 FLAG_GENERIC(MSG_CONFIRM),
1051 FLAG_GENERIC(MSG_DONTROUTE),
1052 FLAG_GENERIC(MSG_DONTWAIT),
1053 FLAG_GENERIC(MSG_EOR),
1054 FLAG_GENERIC(MSG_MORE),
1055 FLAG_GENERIC(MSG_NOSIGNAL),
1056 FLAG_GENERIC(MSG_OOB),
1057 /* recv */
1058 FLAG_GENERIC(MSG_CMSG_CLOEXEC),
1059 FLAG_GENERIC(MSG_ERRQUEUE),
1060 FLAG_GENERIC(MSG_PEEK),
1061 FLAG_GENERIC(MSG_TRUNC),
1062 FLAG_GENERIC(MSG_WAITALL),
1063 /* recvmsg */
1064 FLAG_GENERIC(MSG_CTRUNC),
1065 FLAG_END,
1066 };
1067
1068 UNUSED static struct flags statx_flags[] = {
1069 #ifdef AT_EMPTY_PATH
1070 FLAG_GENERIC(AT_EMPTY_PATH),
1071 #endif
1072 #ifdef AT_NO_AUTOMOUNT
1073 FLAG_GENERIC(AT_NO_AUTOMOUNT),
1074 #endif
1075 #ifdef AT_SYMLINK_NOFOLLOW
1076 FLAG_GENERIC(AT_SYMLINK_NOFOLLOW),
1077 #endif
1078 #ifdef AT_STATX_SYNC_AS_STAT
1079 FLAG_GENERIC(AT_STATX_SYNC_AS_STAT),
1080 #endif
1081 #ifdef AT_STATX_FORCE_SYNC
1082 FLAG_GENERIC(AT_STATX_FORCE_SYNC),
1083 #endif
1084 #ifdef AT_STATX_DONT_SYNC
1085 FLAG_GENERIC(AT_STATX_DONT_SYNC),
1086 #endif
1087 FLAG_END,
1088 };
1089
1090 UNUSED static struct flags statx_mask[] = {
1091 /* This must come first, because it includes everything. */
1092 #ifdef STATX_ALL
1093 FLAG_GENERIC(STATX_ALL),
1094 #endif
1095 /* This must come second; it includes everything except STATX_BTIME. */
1096 #ifdef STATX_BASIC_STATS
1097 FLAG_GENERIC(STATX_BASIC_STATS),
1098 #endif
1099 #ifdef STATX_TYPE
1100 FLAG_GENERIC(STATX_TYPE),
1101 #endif
1102 #ifdef STATX_MODE
1103 FLAG_GENERIC(STATX_MODE),
1104 #endif
1105 #ifdef STATX_NLINK
1106 FLAG_GENERIC(STATX_NLINK),
1107 #endif
1108 #ifdef STATX_UID
1109 FLAG_GENERIC(STATX_UID),
1110 #endif
1111 #ifdef STATX_GID
1112 FLAG_GENERIC(STATX_GID),
1113 #endif
1114 #ifdef STATX_ATIME
1115 FLAG_GENERIC(STATX_ATIME),
1116 #endif
1117 #ifdef STATX_MTIME
1118 FLAG_GENERIC(STATX_MTIME),
1119 #endif
1120 #ifdef STATX_CTIME
1121 FLAG_GENERIC(STATX_CTIME),
1122 #endif
1123 #ifdef STATX_INO
1124 FLAG_GENERIC(STATX_INO),
1125 #endif
1126 #ifdef STATX_SIZE
1127 FLAG_GENERIC(STATX_SIZE),
1128 #endif
1129 #ifdef STATX_BLOCKS
1130 FLAG_GENERIC(STATX_BLOCKS),
1131 #endif
1132 #ifdef STATX_BTIME
1133 FLAG_GENERIC(STATX_BTIME),
1134 #endif
1135 FLAG_END,
1136 };
1137
1138 /*
1139 * print_xxx utility functions. These are used to print syscall
1140 * parameters in certain format. All of these have parameter
1141 * named 'last'. This parameter is used to add comma to output
1142 * when last == 0.
1143 */
1144
1145 static const char *
1146 get_comma(int last)
1147 {
1148 return ((last) ? "" : ",");
1149 }
1150
1151 static void
1152 print_flags(const struct flags *f, abi_long flags, int last)
1153 {
1154 const char *sep = "";
1155 int n;
1156
1157 if ((flags == 0) && (f->f_value == 0)) {
1158 qemu_log("%s%s", f->f_string, get_comma(last));
1159 return;
1160 }
1161 for (n = 0; f->f_string != NULL; f++) {
1162 if ((f->f_value != 0) && ((flags & f->f_value) == f->f_value)) {
1163 qemu_log("%s%s", sep, f->f_string);
1164 flags &= ~f->f_value;
1165 sep = "|";
1166 n++;
1167 }
1168 }
1169
1170 if (n > 0) {
1171 /* print rest of the flags as numeric */
1172 if (flags != 0) {
1173 qemu_log("%s%#x%s", sep, (unsigned int)flags, get_comma(last));
1174 } else {
1175 qemu_log("%s", get_comma(last));
1176 }
1177 } else {
1178 /* no string version of flags found, print them in hex then */
1179 qemu_log("%#x%s", (unsigned int)flags, get_comma(last));
1180 }
1181 }
1182
1183 static void
1184 print_at_dirfd(abi_long dirfd, int last)
1185 {
1186 #ifdef AT_FDCWD
1187 if (dirfd == AT_FDCWD) {
1188 qemu_log("AT_FDCWD%s", get_comma(last));
1189 return;
1190 }
1191 #endif
1192 qemu_log("%d%s", (int)dirfd, get_comma(last));
1193 }
1194
1195 static void
1196 print_file_mode(abi_long mode, int last)
1197 {
1198 const char *sep = "";
1199 const struct flags *m;
1200
1201 for (m = &mode_flags[0]; m->f_string != NULL; m++) {
1202 if ((m->f_value & mode) == m->f_value) {
1203 qemu_log("%s%s", m->f_string, sep);
1204 sep = "|";
1205 mode &= ~m->f_value;
1206 break;
1207 }
1208 }
1209
1210 mode &= ~S_IFMT;
1211 /* print rest of the mode as octal */
1212 if (mode != 0)
1213 qemu_log("%s%#o", sep, (unsigned int)mode);
1214
1215 qemu_log("%s", get_comma(last));
1216 }
1217
1218 static void
1219 print_open_flags(abi_long flags, int last)
1220 {
1221 print_flags(open_access_flags, flags & TARGET_O_ACCMODE, 1);
1222 flags &= ~TARGET_O_ACCMODE;
1223 if (flags == 0) {
1224 qemu_log("%s", get_comma(last));
1225 return;
1226 }
1227 qemu_log("|");
1228 print_flags(open_flags, flags, last);
1229 }
1230
1231 static void
1232 print_syscall_prologue(const struct syscallname *sc)
1233 {
1234 qemu_log("%s(", sc->name);
1235 }
1236
1237 /*ARGSUSED*/
1238 static void
1239 print_syscall_epilogue(const struct syscallname *sc)
1240 {
1241 (void)sc;
1242 qemu_log(")");
1243 }
1244
1245 static void
1246 print_string(abi_long addr, int last)
1247 {
1248 char *s;
1249
1250 if ((s = lock_user_string(addr)) != NULL) {
1251 qemu_log("\"%s\"%s", s, get_comma(last));
1252 unlock_user(s, addr, 0);
1253 } else {
1254 /* can't get string out of it, so print it as pointer */
1255 print_pointer(addr, last);
1256 }
1257 }
1258
1259 #define MAX_PRINT_BUF 40
1260 static void
1261 print_buf(abi_long addr, abi_long len, int last)
1262 {
1263 uint8_t *s;
1264 int i;
1265
1266 s = lock_user(VERIFY_READ, addr, len, 1);
1267 if (s) {
1268 qemu_log("\"");
1269 for (i = 0; i < MAX_PRINT_BUF && i < len; i++) {
1270 if (isprint(s[i])) {
1271 qemu_log("%c", s[i]);
1272 } else {
1273 qemu_log("\\%o", s[i]);
1274 }
1275 }
1276 qemu_log("\"");
1277 if (i != len) {
1278 qemu_log("...");
1279 }
1280 if (!last) {
1281 qemu_log(",");
1282 }
1283 unlock_user(s, addr, 0);
1284 } else {
1285 print_pointer(addr, last);
1286 }
1287 }
1288
1289 /*
1290 * Prints out raw parameter using given format. Caller needs
1291 * to do byte swapping if needed.
1292 */
1293 static void
1294 print_raw_param(const char *fmt, abi_long param, int last)
1295 {
1296 char format[64];
1297
1298 (void) snprintf(format, sizeof (format), "%s%s", fmt, get_comma(last));
1299 qemu_log(format, param);
1300 }
1301
1302 static void
1303 print_pointer(abi_long p, int last)
1304 {
1305 if (p == 0)
1306 qemu_log("NULL%s", get_comma(last));
1307 else
1308 qemu_log("0x" TARGET_ABI_FMT_lx "%s", p, get_comma(last));
1309 }
1310
1311 /*
1312 * Reads 32-bit (int) number from guest address space from
1313 * address 'addr' and prints it.
1314 */
1315 static void
1316 print_number(abi_long addr, int last)
1317 {
1318 if (addr == 0) {
1319 qemu_log("NULL%s", get_comma(last));
1320 } else {
1321 int num;
1322
1323 get_user_s32(num, addr);
1324 qemu_log("[%d]%s", num, get_comma(last));
1325 }
1326 }
1327
1328 static void
1329 print_timeval(abi_ulong tv_addr, int last)
1330 {
1331 if( tv_addr ) {
1332 struct target_timeval *tv;
1333
1334 tv = lock_user(VERIFY_READ, tv_addr, sizeof(*tv), 1);
1335 if (!tv) {
1336 print_pointer(tv_addr, last);
1337 return;
1338 }
1339 qemu_log("{" TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld "}%s",
1340 tswapal(tv->tv_sec), tswapal(tv->tv_usec), get_comma(last));
1341 unlock_user(tv, tv_addr, 0);
1342 } else
1343 qemu_log("NULL%s", get_comma(last));
1344 }
1345
1346 static void
1347 print_timezone(abi_ulong tz_addr, int last)
1348 {
1349 if (tz_addr) {
1350 struct target_timezone *tz;
1351
1352 tz = lock_user(VERIFY_READ, tz_addr, sizeof(*tz), 1);
1353 if (!tz) {
1354 print_pointer(tz_addr, last);
1355 return;
1356 }
1357 qemu_log("{%d,%d}%s", tswap32(tz->tz_minuteswest),
1358 tswap32(tz->tz_dsttime), get_comma(last));
1359 unlock_user(tz, tz_addr, 0);
1360 } else {
1361 qemu_log("NULL%s", get_comma(last));
1362 }
1363 }
1364
1365 #undef UNUSED
1366
1367 #ifdef TARGET_NR_accept
1368 static void
1369 print_accept(const struct syscallname *name,
1370 abi_long arg0, abi_long arg1, abi_long arg2,
1371 abi_long arg3, abi_long arg4, abi_long arg5)
1372 {
1373 print_syscall_prologue(name);
1374 print_raw_param("%d", arg0, 0);
1375 print_pointer(arg1, 0);
1376 print_number(arg2, 1);
1377 print_syscall_epilogue(name);
1378 }
1379 #endif
1380
1381 #ifdef TARGET_NR_access
1382 static void
1383 print_access(const struct syscallname *name,
1384 abi_long arg0, abi_long arg1, abi_long arg2,
1385 abi_long arg3, abi_long arg4, abi_long arg5)
1386 {
1387 print_syscall_prologue(name);
1388 print_string(arg0, 0);
1389 print_flags(access_flags, arg1, 1);
1390 print_syscall_epilogue(name);
1391 }
1392 #endif
1393
1394 #ifdef TARGET_NR_acct
1395 static void
1396 print_acct(const struct syscallname *name,
1397 abi_long arg0, abi_long arg1, abi_long arg2,
1398 abi_long arg3, abi_long arg4, abi_long arg5)
1399 {
1400 print_syscall_prologue(name);
1401 print_string(arg0, 1);
1402 print_syscall_epilogue(name);
1403 }
1404 #endif
1405
1406 #ifdef TARGET_NR_brk
1407 static void
1408 print_brk(const struct syscallname *name,
1409 abi_long arg0, abi_long arg1, abi_long arg2,
1410 abi_long arg3, abi_long arg4, abi_long arg5)
1411 {
1412 print_syscall_prologue(name);
1413 print_pointer(arg0, 1);
1414 print_syscall_epilogue(name);
1415 }
1416 #endif
1417
1418 #ifdef TARGET_NR_chdir
1419 static void
1420 print_chdir(const struct syscallname *name,
1421 abi_long arg0, abi_long arg1, abi_long arg2,
1422 abi_long arg3, abi_long arg4, abi_long arg5)
1423 {
1424 print_syscall_prologue(name);
1425 print_string(arg0, 1);
1426 print_syscall_epilogue(name);
1427 }
1428 #endif
1429
1430 #ifdef TARGET_NR_chroot
1431 static void
1432 print_chroot(const struct syscallname *name,
1433 abi_long arg0, abi_long arg1, abi_long arg2,
1434 abi_long arg3, abi_long arg4, abi_long arg5)
1435 {
1436 print_syscall_prologue(name);
1437 print_string(arg0, 1);
1438 print_syscall_epilogue(name);
1439 }
1440 #endif
1441
1442 #ifdef TARGET_NR_chmod
1443 static void
1444 print_chmod(const struct syscallname *name,
1445 abi_long arg0, abi_long arg1, abi_long arg2,
1446 abi_long arg3, abi_long arg4, abi_long arg5)
1447 {
1448 print_syscall_prologue(name);
1449 print_string(arg0, 0);
1450 print_file_mode(arg1, 1);
1451 print_syscall_epilogue(name);
1452 }
1453 #endif
1454
1455 #ifdef TARGET_NR_clock_adjtime
1456 static void
1457 print_clock_adjtime(const struct syscallname *name,
1458 abi_long arg0, abi_long arg1, abi_long arg2,
1459 abi_long arg3, abi_long arg4, abi_long arg5)
1460 {
1461 print_syscall_prologue(name);
1462 print_clockid(arg0, 0);
1463 print_pointer(arg1, 1);
1464 print_syscall_epilogue(name);
1465 }
1466 #endif
1467
1468 #ifdef TARGET_NR_clone
1469 static void do_print_clone(unsigned int flags, abi_ulong newsp,
1470 abi_ulong parent_tidptr, target_ulong newtls,
1471 abi_ulong child_tidptr)
1472 {
1473 print_flags(clone_flags, flags, 0);
1474 print_raw_param("child_stack=0x" TARGET_ABI_FMT_lx, newsp, 0);
1475 print_raw_param("parent_tidptr=0x" TARGET_ABI_FMT_lx, parent_tidptr, 0);
1476 print_raw_param("tls=0x" TARGET_ABI_FMT_lx, newtls, 0);
1477 print_raw_param("child_tidptr=0x" TARGET_ABI_FMT_lx, child_tidptr, 1);
1478 }
1479
1480 static void
1481 print_clone(const struct syscallname *name,
1482 abi_long arg1, abi_long arg2, abi_long arg3,
1483 abi_long arg4, abi_long arg5, abi_long arg6)
1484 {
1485 print_syscall_prologue(name);
1486 #if defined(TARGET_MICROBLAZE)
1487 do_print_clone(arg1, arg2, arg4, arg6, arg5);
1488 #elif defined(TARGET_CLONE_BACKWARDS)
1489 do_print_clone(arg1, arg2, arg3, arg4, arg5);
1490 #elif defined(TARGET_CLONE_BACKWARDS2)
1491 do_print_clone(arg2, arg1, arg3, arg5, arg4);
1492 #else
1493 do_print_clone(arg1, arg2, arg3, arg5, arg4);
1494 #endif
1495 print_syscall_epilogue(name);
1496 }
1497 #endif
1498
1499 #ifdef TARGET_NR_creat
1500 static void
1501 print_creat(const struct syscallname *name,
1502 abi_long arg0, abi_long arg1, abi_long arg2,
1503 abi_long arg3, abi_long arg4, abi_long arg5)
1504 {
1505 print_syscall_prologue(name);
1506 print_string(arg0, 0);
1507 print_file_mode(arg1, 1);
1508 print_syscall_epilogue(name);
1509 }
1510 #endif
1511
1512 #ifdef TARGET_NR_execv
1513 static void
1514 print_execv(const struct syscallname *name,
1515 abi_long arg0, abi_long arg1, abi_long arg2,
1516 abi_long arg3, abi_long arg4, abi_long arg5)
1517 {
1518 print_syscall_prologue(name);
1519 print_string(arg0, 0);
1520 print_raw_param("0x" TARGET_ABI_FMT_lx, arg1, 1);
1521 print_syscall_epilogue(name);
1522 }
1523 #endif
1524
1525 #ifdef TARGET_NR_faccessat
1526 static void
1527 print_faccessat(const struct syscallname *name,
1528 abi_long arg0, abi_long arg1, abi_long arg2,
1529 abi_long arg3, abi_long arg4, abi_long arg5)
1530 {
1531 print_syscall_prologue(name);
1532 print_at_dirfd(arg0, 0);
1533 print_string(arg1, 0);
1534 print_flags(access_flags, arg2, 0);
1535 print_flags(at_file_flags, arg3, 1);
1536 print_syscall_epilogue(name);
1537 }
1538 #endif
1539
1540 #ifdef TARGET_NR_fchmodat
1541 static void
1542 print_fchmodat(const struct syscallname *name,
1543 abi_long arg0, abi_long arg1, abi_long arg2,
1544 abi_long arg3, abi_long arg4, abi_long arg5)
1545 {
1546 print_syscall_prologue(name);
1547 print_at_dirfd(arg0, 0);
1548 print_string(arg1, 0);
1549 print_file_mode(arg2, 0);
1550 print_flags(at_file_flags, arg3, 1);
1551 print_syscall_epilogue(name);
1552 }
1553 #endif
1554
1555 #ifdef TARGET_NR_fchownat
1556 static void
1557 print_fchownat(const struct syscallname *name,
1558 abi_long arg0, abi_long arg1, abi_long arg2,
1559 abi_long arg3, abi_long arg4, abi_long arg5)
1560 {
1561 print_syscall_prologue(name);
1562 print_at_dirfd(arg0, 0);
1563 print_string(arg1, 0);
1564 print_raw_param("%d", arg2, 0);
1565 print_raw_param("%d", arg3, 0);
1566 print_flags(at_file_flags, arg4, 1);
1567 print_syscall_epilogue(name);
1568 }
1569 #endif
1570
1571 #if defined(TARGET_NR_fcntl) || defined(TARGET_NR_fcntl64)
1572 static void
1573 print_fcntl(const struct syscallname *name,
1574 abi_long arg0, abi_long arg1, abi_long arg2,
1575 abi_long arg3, abi_long arg4, abi_long arg5)
1576 {
1577 print_syscall_prologue(name);
1578 print_raw_param("%d", arg0, 0);
1579 switch(arg1) {
1580 case TARGET_F_DUPFD:
1581 qemu_log("F_DUPFD,");
1582 print_raw_param(TARGET_ABI_FMT_ld, arg2, 1);
1583 break;
1584 case TARGET_F_GETFD:
1585 qemu_log("F_GETFD");
1586 break;
1587 case TARGET_F_SETFD:
1588 qemu_log("F_SETFD,");
1589 print_raw_param(TARGET_ABI_FMT_ld, arg2, 1);
1590 break;
1591 case TARGET_F_GETFL:
1592 qemu_log("F_GETFL");
1593 break;
1594 case TARGET_F_SETFL:
1595 qemu_log("F_SETFL,");
1596 print_open_flags(arg2, 1);
1597 break;
1598 case TARGET_F_GETLK:
1599 qemu_log("F_GETLK,");
1600 print_pointer(arg2, 1);
1601 break;
1602 case TARGET_F_SETLK:
1603 qemu_log("F_SETLK,");
1604 print_pointer(arg2, 1);
1605 break;
1606 case TARGET_F_SETLKW:
1607 qemu_log("F_SETLKW,");
1608 print_pointer(arg2, 1);
1609 break;
1610 case TARGET_F_GETOWN:
1611 qemu_log("F_GETOWN");
1612 break;
1613 case TARGET_F_SETOWN:
1614 qemu_log("F_SETOWN,");
1615 print_raw_param(TARGET_ABI_FMT_ld, arg2, 0);
1616 break;
1617 case TARGET_F_GETSIG:
1618 qemu_log("F_GETSIG");
1619 break;
1620 case TARGET_F_SETSIG:
1621 qemu_log("F_SETSIG,");
1622 print_raw_param(TARGET_ABI_FMT_ld, arg2, 0);
1623 break;
1624 #if TARGET_ABI_BITS == 32
1625 case TARGET_F_GETLK64:
1626 qemu_log("F_GETLK64,");
1627 print_pointer(arg2, 1);
1628 break;
1629 case TARGET_F_SETLK64:
1630 qemu_log("F_SETLK64,");
1631 print_pointer(arg2, 1);
1632 break;
1633 case TARGET_F_SETLKW64:
1634 qemu_log("F_SETLKW64,");
1635 print_pointer(arg2, 1);
1636 break;
1637 #endif
1638 case TARGET_F_SETLEASE:
1639 qemu_log("F_SETLEASE,");
1640 print_raw_param(TARGET_ABI_FMT_ld, arg2, 0);
1641 break;
1642 case TARGET_F_GETLEASE:
1643 qemu_log("F_GETLEASE");
1644 break;
1645 case TARGET_F_SETPIPE_SZ:
1646 qemu_log("F_SETPIPE_SZ,");
1647 print_raw_param(TARGET_ABI_FMT_ld, arg2, 1);
1648 break;
1649 case TARGET_F_GETPIPE_SZ:
1650 qemu_log("F_GETPIPE_SZ");
1651 break;
1652 case TARGET_F_DUPFD_CLOEXEC:
1653 qemu_log("F_DUPFD_CLOEXEC,");
1654 print_raw_param(TARGET_ABI_FMT_ld, arg2, 1);
1655 break;
1656 case TARGET_F_NOTIFY:
1657 qemu_log("F_NOTIFY,");
1658 print_raw_param(TARGET_ABI_FMT_ld, arg2, 0);
1659 break;
1660 default:
1661 print_raw_param(TARGET_ABI_FMT_ld, arg1, 0);
1662 print_pointer(arg2, 1);
1663 break;
1664 }
1665 print_syscall_epilogue(name);
1666 }
1667 #define print_fcntl64 print_fcntl
1668 #endif
1669
1670 #ifdef TARGET_NR_fgetxattr
1671 static void
1672 print_fgetxattr(const struct syscallname *name,
1673 abi_long arg0, abi_long arg1, abi_long arg2,
1674 abi_long arg3, abi_long arg4, abi_long arg5)
1675 {
1676 print_syscall_prologue(name);
1677 print_raw_param("%d", arg0, 0);
1678 print_string(arg1, 0);
1679 print_pointer(arg2, 0);
1680 print_raw_param(TARGET_FMT_lu, arg3, 1);
1681 print_syscall_epilogue(name);
1682 }
1683 #endif
1684
1685 #ifdef TARGET_NR_flistxattr
1686 static void
1687 print_flistxattr(const struct syscallname *name,
1688 abi_long arg0, abi_long arg1, abi_long arg2,
1689 abi_long arg3, abi_long arg4, abi_long arg5)
1690 {
1691 print_syscall_prologue(name);
1692 print_raw_param("%d", arg0, 0);
1693 print_pointer(arg1, 0);
1694 print_raw_param(TARGET_FMT_lu, arg2, 1);
1695 print_syscall_epilogue(name);
1696 }
1697 #endif
1698
1699 #if defined(TARGET_NR_getxattr) || defined(TARGET_NR_lgetxattr)
1700 static void
1701 print_getxattr(const struct syscallname *name,
1702 abi_long arg0, abi_long arg1, abi_long arg2,
1703 abi_long arg3, abi_long arg4, abi_long arg5)
1704 {
1705 print_syscall_prologue(name);
1706 print_string(arg0, 0);
1707 print_string(arg1, 0);
1708 print_pointer(arg2, 0);
1709 print_raw_param(TARGET_FMT_lu, arg3, 1);
1710 print_syscall_epilogue(name);
1711 }
1712 #define print_lgetxattr print_getxattr
1713 #endif
1714
1715 #if defined(TARGET_NR_listxattr) || defined(TARGET_NR_llistxattr)
1716 static void
1717 print_listxattr(const struct syscallname *name,
1718 abi_long arg0, abi_long arg1, abi_long arg2,
1719 abi_long arg3, abi_long arg4, abi_long arg5)
1720 {
1721 print_syscall_prologue(name);
1722 print_string(arg0, 0);
1723 print_pointer(arg1, 0);
1724 print_raw_param(TARGET_FMT_lu, arg2, 1);
1725 print_syscall_epilogue(name);
1726 }
1727 #define print_llistxattr print_listxattr
1728 #endif
1729
1730 #if defined(TARGET_NR_fremovexattr)
1731 static void
1732 print_fremovexattr(const struct syscallname *name,
1733 abi_long arg0, abi_long arg1, abi_long arg2,
1734 abi_long arg3, abi_long arg4, abi_long arg5)
1735 {
1736 print_syscall_prologue(name);
1737 print_raw_param("%d", arg0, 0);
1738 print_string(arg1, 1);
1739 print_syscall_epilogue(name);
1740 }
1741 #endif
1742
1743 #if defined(TARGET_NR_removexattr) || defined(TARGET_NR_lremovexattr)
1744 static void
1745 print_removexattr(const struct syscallname *name,
1746 abi_long arg0, abi_long arg1, abi_long arg2,
1747 abi_long arg3, abi_long arg4, abi_long arg5)
1748 {
1749 print_syscall_prologue(name);
1750 print_string(arg0, 0);
1751 print_string(arg1, 1);
1752 print_syscall_epilogue(name);
1753 }
1754 #define print_lremovexattr print_removexattr
1755 #endif
1756
1757 #ifdef TARGET_NR_futimesat
1758 static void
1759 print_futimesat(const struct syscallname *name,
1760 abi_long arg0, abi_long arg1, abi_long arg2,
1761 abi_long arg3, abi_long arg4, abi_long arg5)
1762 {
1763 print_syscall_prologue(name);
1764 print_at_dirfd(arg0, 0);
1765 print_string(arg1, 0);
1766 print_timeval(arg2, 0);
1767 print_timeval(arg2 + sizeof (struct target_timeval), 1);
1768 print_syscall_epilogue(name);
1769 }
1770 #endif
1771
1772 #ifdef TARGET_NR_settimeofday
1773 static void
1774 print_settimeofday(const struct syscallname *name,
1775 abi_long arg0, abi_long arg1, abi_long arg2,
1776 abi_long arg3, abi_long arg4, abi_long arg5)
1777 {
1778 print_syscall_prologue(name);
1779 print_timeval(arg0, 0);
1780 print_timezone(arg1, 1);
1781 print_syscall_epilogue(name);
1782 }
1783 #endif
1784
1785 #ifdef TARGET_NR_link
1786 static void
1787 print_link(const struct syscallname *name,
1788 abi_long arg0, abi_long arg1, abi_long arg2,
1789 abi_long arg3, abi_long arg4, abi_long arg5)
1790 {
1791 print_syscall_prologue(name);
1792 print_string(arg0, 0);
1793 print_string(arg1, 1);
1794 print_syscall_epilogue(name);
1795 }
1796 #endif
1797
1798 #ifdef TARGET_NR_linkat
1799 static void
1800 print_linkat(const struct syscallname *name,
1801 abi_long arg0, abi_long arg1, abi_long arg2,
1802 abi_long arg3, abi_long arg4, abi_long arg5)
1803 {
1804 print_syscall_prologue(name);
1805 print_at_dirfd(arg0, 0);
1806 print_string(arg1, 0);
1807 print_at_dirfd(arg2, 0);
1808 print_string(arg3, 0);
1809 print_flags(at_file_flags, arg4, 1);
1810 print_syscall_epilogue(name);
1811 }
1812 #endif
1813
1814 #ifdef TARGET_NR__llseek
1815 static void
1816 print__llseek(const struct syscallname *name,
1817 abi_long arg0, abi_long arg1, abi_long arg2,
1818 abi_long arg3, abi_long arg4, abi_long arg5)
1819 {
1820 const char *whence = "UNKNOWN";
1821 print_syscall_prologue(name);
1822 print_raw_param("%d", arg0, 0);
1823 print_raw_param("%ld", arg1, 0);
1824 print_raw_param("%ld", arg2, 0);
1825 print_pointer(arg3, 0);
1826 switch(arg4) {
1827 case SEEK_SET: whence = "SEEK_SET"; break;
1828 case SEEK_CUR: whence = "SEEK_CUR"; break;
1829 case SEEK_END: whence = "SEEK_END"; break;
1830 }
1831 qemu_log("%s", whence);
1832 print_syscall_epilogue(name);
1833 }
1834 #endif
1835
1836 #if defined(TARGET_NR_socket)
1837 static void
1838 print_socket(const struct syscallname *name,
1839 abi_long arg0, abi_long arg1, abi_long arg2,
1840 abi_long arg3, abi_long arg4, abi_long arg5)
1841 {
1842 abi_ulong domain = arg0, type = arg1, protocol = arg2;
1843
1844 print_syscall_prologue(name);
1845 print_socket_domain(domain);
1846 qemu_log(",");
1847 print_socket_type(type);
1848 qemu_log(",");
1849 if (domain == AF_PACKET ||
1850 (domain == AF_INET && type == TARGET_SOCK_PACKET)) {
1851 protocol = tswap16(protocol);
1852 }
1853 print_socket_protocol(domain, type, protocol);
1854 print_syscall_epilogue(name);
1855 }
1856
1857 #endif
1858
1859 #if defined(TARGET_NR_socketcall) || defined(TARGET_NR_bind)
1860
1861 static void print_sockfd(abi_long sockfd, int last)
1862 {
1863 print_raw_param(TARGET_ABI_FMT_ld, sockfd, last);
1864 }
1865
1866 #endif
1867
1868 #if defined(TARGET_NR_socketcall)
1869
1870 #define get_user_ualx(x, gaddr, idx) \
1871 get_user_ual(x, (gaddr) + (idx) * sizeof(abi_long))
1872
1873 static void do_print_socket(const char *name, abi_long arg1)
1874 {
1875 abi_ulong domain, type, protocol;
1876
1877 get_user_ualx(domain, arg1, 0);
1878 get_user_ualx(type, arg1, 1);
1879 get_user_ualx(protocol, arg1, 2);
1880 qemu_log("%s(", name);
1881 print_socket_domain(domain);
1882 qemu_log(",");
1883 print_socket_type(type);
1884 qemu_log(",");
1885 if (domain == AF_PACKET ||
1886 (domain == AF_INET && type == TARGET_SOCK_PACKET)) {
1887 protocol = tswap16(protocol);
1888 }
1889 print_socket_protocol(domain, type, protocol);
1890 qemu_log(")");
1891 }
1892
1893 static void do_print_sockaddr(const char *name, abi_long arg1)
1894 {
1895 abi_ulong sockfd, addr, addrlen;
1896
1897 get_user_ualx(sockfd, arg1, 0);
1898 get_user_ualx(addr, arg1, 1);
1899 get_user_ualx(addrlen, arg1, 2);
1900
1901 qemu_log("%s(", name);
1902 print_sockfd(sockfd, 0);
1903 print_sockaddr(addr, addrlen, 0);
1904 qemu_log(")");
1905 }
1906
1907 static void do_print_listen(const char *name, abi_long arg1)
1908 {
1909 abi_ulong sockfd, backlog;
1910
1911 get_user_ualx(sockfd, arg1, 0);
1912 get_user_ualx(backlog, arg1, 1);
1913
1914 qemu_log("%s(", name);
1915 print_sockfd(sockfd, 0);
1916 print_raw_param(TARGET_ABI_FMT_ld, backlog, 1);
1917 qemu_log(")");
1918 }
1919
1920 static void do_print_socketpair(const char *name, abi_long arg1)
1921 {
1922 abi_ulong domain, type, protocol, tab;
1923
1924 get_user_ualx(domain, arg1, 0);
1925 get_user_ualx(type, arg1, 1);
1926 get_user_ualx(protocol, arg1, 2);
1927 get_user_ualx(tab, arg1, 3);
1928
1929 qemu_log("%s(", name);
1930 print_socket_domain(domain);
1931 qemu_log(",");
1932 print_socket_type(type);
1933 qemu_log(",");
1934 print_socket_protocol(domain, type, protocol);
1935 qemu_log(",");
1936 print_raw_param(TARGET_ABI_FMT_lx, tab, 1);
1937 qemu_log(")");
1938 }
1939
1940 static void do_print_sendrecv(const char *name, abi_long arg1)
1941 {
1942 abi_ulong sockfd, msg, len, flags;
1943
1944 get_user_ualx(sockfd, arg1, 0);
1945 get_user_ualx(msg, arg1, 1);
1946 get_user_ualx(len, arg1, 2);
1947 get_user_ualx(flags, arg1, 3);
1948
1949 qemu_log("%s(", name);
1950 print_sockfd(sockfd, 0);
1951 print_buf(msg, len, 0);
1952 print_raw_param(TARGET_ABI_FMT_ld, len, 0);
1953 print_flags(msg_flags, flags, 1);
1954 qemu_log(")");
1955 }
1956
1957 static void do_print_msgaddr(const char *name, abi_long arg1)
1958 {
1959 abi_ulong sockfd, msg, len, flags, addr, addrlen;
1960
1961 get_user_ualx(sockfd, arg1, 0);
1962 get_user_ualx(msg, arg1, 1);
1963 get_user_ualx(len, arg1, 2);
1964 get_user_ualx(flags, arg1, 3);
1965 get_user_ualx(addr, arg1, 4);
1966 get_user_ualx(addrlen, arg1, 5);
1967
1968 qemu_log("%s(", name);
1969 print_sockfd(sockfd, 0);
1970 print_buf(msg, len, 0);
1971 print_raw_param(TARGET_ABI_FMT_ld, len, 0);
1972 print_flags(msg_flags, flags, 0);
1973 print_sockaddr(addr, addrlen, 0);
1974 qemu_log(")");
1975 }
1976
1977 static void do_print_shutdown(const char *name, abi_long arg1)
1978 {
1979 abi_ulong sockfd, how;
1980
1981 get_user_ualx(sockfd, arg1, 0);
1982 get_user_ualx(how, arg1, 1);
1983
1984 qemu_log("shutdown(");
1985 print_sockfd(sockfd, 0);
1986 switch (how) {
1987 case SHUT_RD:
1988 qemu_log("SHUT_RD");
1989 break;
1990 case SHUT_WR:
1991 qemu_log("SHUT_WR");
1992 break;
1993 case SHUT_RDWR:
1994 qemu_log("SHUT_RDWR");
1995 break;
1996 default:
1997 print_raw_param(TARGET_ABI_FMT_ld, how, 1);
1998 break;
1999 }
2000 qemu_log(")");
2001 }
2002
2003 static void do_print_msg(const char *name, abi_long arg1)
2004 {
2005 abi_ulong sockfd, msg, flags;
2006
2007 get_user_ualx(sockfd, arg1, 0);
2008 get_user_ualx(msg, arg1, 1);
2009 get_user_ualx(flags, arg1, 2);
2010
2011 qemu_log("%s(", name);
2012 print_sockfd(sockfd, 0);
2013 print_pointer(msg, 0);
2014 print_flags(msg_flags, flags, 1);
2015 qemu_log(")");
2016 }
2017
2018 static void do_print_sockopt(const char *name, abi_long arg1)
2019 {
2020 abi_ulong sockfd, level, optname, optval, optlen;
2021
2022 get_user_ualx(sockfd, arg1, 0);
2023 get_user_ualx(level, arg1, 1);
2024 get_user_ualx(optname, arg1, 2);
2025 get_user_ualx(optval, arg1, 3);
2026 get_user_ualx(optlen, arg1, 4);
2027
2028 qemu_log("%s(", name);
2029 print_sockfd(sockfd, 0);
2030 switch (level) {
2031 case SOL_TCP:
2032 qemu_log("SOL_TCP,");
2033 print_raw_param(TARGET_ABI_FMT_ld, optname, 0);
2034 print_pointer(optval, 0);
2035 break;
2036 case SOL_IP:
2037 qemu_log("SOL_IP,");
2038 print_raw_param(TARGET_ABI_FMT_ld, optname, 0);
2039 print_pointer(optval, 0);
2040 break;
2041 case SOL_RAW:
2042 qemu_log("SOL_RAW,");
2043 print_raw_param(TARGET_ABI_FMT_ld, optname, 0);
2044 print_pointer(optval, 0);
2045 break;
2046 case TARGET_SOL_SOCKET:
2047 qemu_log("SOL_SOCKET,");
2048 switch (optname) {
2049 case TARGET_SO_DEBUG:
2050 qemu_log("SO_DEBUG,");
2051 print_optint:
2052 print_number(optval, 0);
2053 break;
2054 case TARGET_SO_REUSEADDR:
2055 qemu_log("SO_REUSEADDR,");
2056 goto print_optint;
2057 case TARGET_SO_REUSEPORT:
2058 qemu_log("SO_REUSEPORT,");
2059 goto print_optint;
2060 case TARGET_SO_TYPE:
2061 qemu_log("SO_TYPE,");
2062 goto print_optint;
2063 case TARGET_SO_ERROR:
2064 qemu_log("SO_ERROR,");
2065 goto print_optint;
2066 case TARGET_SO_DONTROUTE:
2067 qemu_log("SO_DONTROUTE,");
2068 goto print_optint;
2069 case TARGET_SO_BROADCAST:
2070 qemu_log("SO_BROADCAST,");
2071 goto print_optint;
2072 case TARGET_SO_SNDBUF:
2073 qemu_log("SO_SNDBUF,");
2074 goto print_optint;
2075 case TARGET_SO_RCVBUF:
2076 qemu_log("SO_RCVBUF,");
2077 goto print_optint;
2078 case TARGET_SO_KEEPALIVE:
2079 qemu_log("SO_KEEPALIVE,");
2080 goto print_optint;
2081 case TARGET_SO_OOBINLINE:
2082 qemu_log("SO_OOBINLINE,");
2083 goto print_optint;
2084 case TARGET_SO_NO_CHECK:
2085 qemu_log("SO_NO_CHECK,");
2086 goto print_optint;
2087 case TARGET_SO_PRIORITY:
2088 qemu_log("SO_PRIORITY,");
2089 goto print_optint;
2090 case TARGET_SO_BSDCOMPAT:
2091 qemu_log("SO_BSDCOMPAT,");
2092 goto print_optint;
2093 case TARGET_SO_PASSCRED:
2094 qemu_log("SO_PASSCRED,");
2095 goto print_optint;
2096 case TARGET_SO_TIMESTAMP:
2097 qemu_log("SO_TIMESTAMP,");
2098 goto print_optint;
2099 case TARGET_SO_RCVLOWAT:
2100 qemu_log("SO_RCVLOWAT,");
2101 goto print_optint;
2102 case TARGET_SO_RCVTIMEO:
2103 qemu_log("SO_RCVTIMEO,");
2104 print_timeval(optval, 0);
2105 break;
2106 case TARGET_SO_SNDTIMEO:
2107 qemu_log("SO_SNDTIMEO,");
2108 print_timeval(optval, 0);
2109 break;
2110 case TARGET_SO_ATTACH_FILTER: {
2111 struct target_sock_fprog *fprog;
2112
2113 qemu_log("SO_ATTACH_FILTER,");
2114
2115 if (lock_user_struct(VERIFY_READ, fprog, optval, 0)) {
2116 struct target_sock_filter *filter;
2117 qemu_log("{");
2118 if (lock_user_struct(VERIFY_READ, filter,
2119 tswapal(fprog->filter), 0)) {
2120 int i;
2121 for (i = 0; i < tswap16(fprog->len) - 1; i++) {
2122 qemu_log("[%d]{0x%x,%d,%d,0x%x},",
2123 i, tswap16(filter[i].code),
2124 filter[i].jt, filter[i].jf,
2125 tswap32(filter[i].k));
2126 }
2127 qemu_log("[%d]{0x%x,%d,%d,0x%x}",
2128 i, tswap16(filter[i].code),
2129 filter[i].jt, filter[i].jf,
2130 tswap32(filter[i].k));
2131 } else {
2132 qemu_log(TARGET_ABI_FMT_lx, tswapal(fprog->filter));
2133 }
2134 qemu_log(",%d},", tswap16(fprog->len));
2135 unlock_user(fprog, optval, 0);
2136 } else {
2137 print_pointer(optval, 0);
2138 }
2139 break;
2140 }
2141 default:
2142 print_raw_param(TARGET_ABI_FMT_ld, optname, 0);
2143 print_pointer(optval, 0);
2144 break;
2145 }
2146 break;
2147 default:
2148 print_raw_param(TARGET_ABI_FMT_ld, level, 0);
2149 print_raw_param(TARGET_ABI_FMT_ld, optname, 0);
2150 print_pointer(optval, 0);
2151 break;
2152 }
2153 print_raw_param(TARGET_ABI_FMT_ld, optlen, 1);
2154 qemu_log(")");
2155 }
2156
2157 #define PRINT_SOCKOP(name, func) \
2158 [TARGET_SYS_##name] = { #name, func }
2159
2160 static struct {
2161 const char *name;
2162 void (*print)(const char *, abi_long);
2163 } scall[] = {
2164 PRINT_SOCKOP(SOCKET, do_print_socket),
2165 PRINT_SOCKOP(BIND, do_print_sockaddr),
2166 PRINT_SOCKOP(CONNECT, do_print_sockaddr),
2167 PRINT_SOCKOP(LISTEN, do_print_listen),
2168 PRINT_SOCKOP(ACCEPT, do_print_sockaddr),
2169 PRINT_SOCKOP(GETSOCKNAME, do_print_sockaddr),
2170 PRINT_SOCKOP(GETPEERNAME, do_print_sockaddr),
2171 PRINT_SOCKOP(SOCKETPAIR, do_print_socketpair),
2172 PRINT_SOCKOP(SEND, do_print_sendrecv),
2173 PRINT_SOCKOP(RECV, do_print_sendrecv),
2174 PRINT_SOCKOP(SENDTO, do_print_msgaddr),
2175 PRINT_SOCKOP(RECVFROM, do_print_msgaddr),
2176 PRINT_SOCKOP(SHUTDOWN, do_print_shutdown),
2177 PRINT_SOCKOP(SETSOCKOPT, do_print_sockopt),
2178 PRINT_SOCKOP(GETSOCKOPT, do_print_sockopt),
2179 PRINT_SOCKOP(SENDMSG, do_print_msg),
2180 PRINT_SOCKOP(RECVMSG, do_print_msg),
2181 PRINT_SOCKOP(ACCEPT4, NULL),
2182 PRINT_SOCKOP(RECVMMSG, NULL),
2183 PRINT_SOCKOP(SENDMMSG, NULL),
2184 };
2185
2186 static void
2187 print_socketcall(const struct syscallname *name,
2188 abi_long arg0, abi_long arg1, abi_long arg2,
2189 abi_long arg3, abi_long arg4, abi_long arg5)
2190 {
2191 if (arg0 >= 0 && arg0 < ARRAY_SIZE(scall) && scall[arg0].print) {
2192 scall[arg0].print(scall[arg0].name, arg1);
2193 return;
2194 }
2195 print_syscall_prologue(name);
2196 print_raw_param(TARGET_ABI_FMT_ld, arg0, 0);
2197 print_raw_param(TARGET_ABI_FMT_ld, arg1, 0);
2198 print_raw_param(TARGET_ABI_FMT_ld, arg2, 0);
2199 print_raw_param(TARGET_ABI_FMT_ld, arg3, 0);
2200 print_raw_param(TARGET_ABI_FMT_ld, arg4, 0);
2201 print_raw_param(TARGET_ABI_FMT_ld, arg5, 0);
2202 print_syscall_epilogue(name);
2203 }
2204 #endif
2205
2206 #if defined(TARGET_NR_bind)
2207 static void
2208 print_bind(const struct syscallname *name,
2209 abi_long arg0, abi_long arg1, abi_long arg2,
2210 abi_long arg3, abi_long arg4, abi_long arg5)
2211 {
2212 print_syscall_prologue(name);
2213 print_sockfd(arg0, 0);
2214 print_sockaddr(arg1, arg2, 1);
2215 print_syscall_epilogue(name);
2216 }
2217 #endif
2218
2219 #if defined(TARGET_NR_stat) || defined(TARGET_NR_stat64) || \
2220 defined(TARGET_NR_lstat) || defined(TARGET_NR_lstat64)
2221 static void
2222 print_stat(const struct syscallname *name,
2223 abi_long arg0, abi_long arg1, abi_long arg2,
2224 abi_long arg3, abi_long arg4, abi_long arg5)
2225 {
2226 print_syscall_prologue(name);
2227 print_string(arg0, 0);
2228 print_pointer(arg1, 1);
2229 print_syscall_epilogue(name);
2230 }
2231 #define print_lstat print_stat
2232 #define print_stat64 print_stat
2233 #define print_lstat64 print_stat
2234 #endif
2235
2236 #if defined(TARGET_NR_fstat) || defined(TARGET_NR_fstat64)
2237 static void
2238 print_fstat(const struct syscallname *name,
2239 abi_long arg0, abi_long arg1, abi_long arg2,
2240 abi_long arg3, abi_long arg4, abi_long arg5)
2241 {
2242 print_syscall_prologue(name);
2243 print_raw_param("%d", arg0, 0);
2244 print_pointer(arg1, 1);
2245 print_syscall_epilogue(name);
2246 }
2247 #define print_fstat64 print_fstat
2248 #endif
2249
2250 #ifdef TARGET_NR_mkdir
2251 static void
2252 print_mkdir(const struct syscallname *name,
2253 abi_long arg0, abi_long arg1, abi_long arg2,
2254 abi_long arg3, abi_long arg4, abi_long arg5)
2255 {
2256 print_syscall_prologue(name);
2257 print_string(arg0, 0);
2258 print_file_mode(arg1, 1);
2259 print_syscall_epilogue(name);
2260 }
2261 #endif
2262
2263 #ifdef TARGET_NR_mkdirat
2264 static void
2265 print_mkdirat(const struct syscallname *name,
2266 abi_long arg0, abi_long arg1, abi_long arg2,
2267 abi_long arg3, abi_long arg4, abi_long arg5)
2268 {
2269 print_syscall_prologue(name);
2270 print_at_dirfd(arg0, 0);
2271 print_string(arg1, 0);
2272 print_file_mode(arg2, 1);
2273 print_syscall_epilogue(name);
2274 }
2275 #endif
2276
2277 #ifdef TARGET_NR_rmdir
2278 static void
2279 print_rmdir(const struct syscallname *name,
2280 abi_long arg0, abi_long arg1, abi_long arg2,
2281 abi_long arg3, abi_long arg4, abi_long arg5)
2282 {
2283 print_syscall_prologue(name);
2284 print_string(arg0, 0);
2285 print_syscall_epilogue(name);
2286 }
2287 #endif
2288
2289 #ifdef TARGET_NR_rt_sigaction
2290 static void
2291 print_rt_sigaction(const struct syscallname *name,
2292 abi_long arg0, abi_long arg1, abi_long arg2,
2293 abi_long arg3, abi_long arg4, abi_long arg5)
2294 {
2295 print_syscall_prologue(name);
2296 print_signal(arg0, 0);
2297 print_pointer(arg1, 0);
2298 print_pointer(arg2, 1);
2299 print_syscall_epilogue(name);
2300 }
2301 #endif
2302
2303 #ifdef TARGET_NR_rt_sigprocmask
2304 static void
2305 print_rt_sigprocmask(const struct syscallname *name,
2306 abi_long arg0, abi_long arg1, abi_long arg2,
2307 abi_long arg3, abi_long arg4, abi_long arg5)
2308 {
2309 const char *how = "UNKNOWN";
2310 print_syscall_prologue(name);
2311 switch(arg0) {
2312 case TARGET_SIG_BLOCK: how = "SIG_BLOCK"; break;
2313 case TARGET_SIG_UNBLOCK: how = "SIG_UNBLOCK"; break;
2314 case TARGET_SIG_SETMASK: how = "SIG_SETMASK"; break;
2315 }
2316 qemu_log("%s,", how);
2317 print_pointer(arg1, 0);
2318 print_pointer(arg2, 1);
2319 print_syscall_epilogue(name);
2320 }
2321 #endif
2322
2323 #ifdef TARGET_NR_rt_sigqueueinfo
2324 static void
2325 print_rt_sigqueueinfo(const struct syscallname *name,
2326 abi_long arg0, abi_long arg1, abi_long arg2,
2327 abi_long arg3, abi_long arg4, abi_long arg5)
2328 {
2329 void *p;
2330 target_siginfo_t uinfo;
2331
2332 print_syscall_prologue(name);
2333 print_raw_param("%d", arg0, 0);
2334 print_signal(arg1, 0);
2335 p = lock_user(VERIFY_READ, arg2, sizeof(target_siginfo_t), 1);
2336 if (p) {
2337 get_target_siginfo(&uinfo, p);
2338 print_siginfo(&uinfo);
2339
2340 unlock_user(p, arg2, 0);
2341 } else {
2342 print_pointer(arg2, 1);
2343 }
2344 print_syscall_epilogue(name);
2345 }
2346 #endif
2347
2348 #ifdef TARGET_NR_rt_tgsigqueueinfo
2349 static void
2350 print_rt_tgsigqueueinfo(const struct syscallname *name,
2351 abi_long arg0, abi_long arg1, abi_long arg2,
2352 abi_long arg3, abi_long arg4, abi_long arg5)
2353 {
2354 void *p;
2355 target_siginfo_t uinfo;
2356
2357 print_syscall_prologue(name);
2358 print_raw_param("%d", arg0, 0);
2359 print_raw_param("%d", arg1, 0);
2360 print_signal(arg2, 0);
2361 p = lock_user(VERIFY_READ, arg3, sizeof(target_siginfo_t), 1);
2362 if (p) {
2363 get_target_siginfo(&uinfo, p);
2364 print_siginfo(&uinfo);
2365
2366 unlock_user(p, arg3, 0);
2367 } else {
2368 print_pointer(arg3, 1);
2369 }
2370 print_syscall_epilogue(name);
2371 }
2372 #endif
2373
2374 #ifdef TARGET_NR_syslog
2375 static void
2376 print_syslog_action(abi_ulong arg, int last)
2377 {
2378 const char *type;
2379
2380 switch (arg) {
2381 case TARGET_SYSLOG_ACTION_CLOSE: {
2382 type = "SYSLOG_ACTION_CLOSE";
2383 break;
2384 }
2385 case TARGET_SYSLOG_ACTION_OPEN: {
2386 type = "SYSLOG_ACTION_OPEN";
2387 break;
2388 }
2389 case TARGET_SYSLOG_ACTION_READ: {
2390 type = "SYSLOG_ACTION_READ";
2391 break;
2392 }
2393 case TARGET_SYSLOG_ACTION_READ_ALL: {
2394 type = "SYSLOG_ACTION_READ_ALL";
2395 break;
2396 }
2397 case TARGET_SYSLOG_ACTION_READ_CLEAR: {
2398 type = "SYSLOG_ACTION_READ_CLEAR";
2399 break;
2400 }
2401 case TARGET_SYSLOG_ACTION_CLEAR: {
2402 type = "SYSLOG_ACTION_CLEAR";
2403 break;
2404 }
2405 case TARGET_SYSLOG_ACTION_CONSOLE_OFF: {
2406 type = "SYSLOG_ACTION_CONSOLE_OFF";
2407 break;
2408 }
2409 case TARGET_SYSLOG_ACTION_CONSOLE_ON: {
2410 type = "SYSLOG_ACTION_CONSOLE_ON";
2411 break;
2412 }
2413 case TARGET_SYSLOG_ACTION_CONSOLE_LEVEL: {
2414 type = "SYSLOG_ACTION_CONSOLE_LEVEL";
2415 break;
2416 }
2417 case TARGET_SYSLOG_ACTION_SIZE_UNREAD: {
2418 type = "SYSLOG_ACTION_SIZE_UNREAD";
2419 break;
2420 }
2421 case TARGET_SYSLOG_ACTION_SIZE_BUFFER: {
2422 type = "SYSLOG_ACTION_SIZE_BUFFER";
2423 break;
2424 }
2425 default: {
2426 print_raw_param("%ld", arg, last);
2427 return;
2428 }
2429 }
2430 qemu_log("%s%s", type, get_comma(last));
2431 }
2432
2433 static void
2434 print_syslog(const struct syscallname *name,
2435 abi_long arg0, abi_long arg1, abi_long arg2,
2436 abi_long arg3, abi_long arg4, abi_long arg5)
2437 {
2438 print_syscall_prologue(name);
2439 print_syslog_action(arg0, 0);
2440 print_pointer(arg1, 0);
2441 print_raw_param("%d", arg2, 1);
2442 print_syscall_epilogue(name);
2443 }
2444 #endif
2445
2446 #ifdef TARGET_NR_mknod
2447 static void
2448 print_mknod(const struct syscallname *name,
2449 abi_long arg0, abi_long arg1, abi_long arg2,
2450 abi_long arg3, abi_long arg4, abi_long arg5)
2451 {
2452 int hasdev = (arg1 & (S_IFCHR|S_IFBLK));
2453
2454 print_syscall_prologue(name);
2455 print_string(arg0, 0);
2456 print_file_mode(arg1, (hasdev == 0));
2457 if (hasdev) {
2458 print_raw_param("makedev(%d", major(arg2), 0);
2459 print_raw_param("%d)", minor(arg2), 1);
2460 }
2461 print_syscall_epilogue(name);
2462 }
2463 #endif
2464
2465 #ifdef TARGET_NR_mknodat
2466 static void
2467 print_mknodat(const struct syscallname *name,
2468 abi_long arg0, abi_long arg1, abi_long arg2,
2469 abi_long arg3, abi_long arg4, abi_long arg5)
2470 {
2471 int hasdev = (arg2 & (S_IFCHR|S_IFBLK));
2472
2473 print_syscall_prologue(name);
2474 print_at_dirfd(arg0, 0);
2475 print_string(arg1, 0);
2476 print_file_mode(arg2, (hasdev == 0));
2477 if (hasdev) {
2478 print_raw_param("makedev(%d", major(arg3), 0);
2479 print_raw_param("%d)", minor(arg3), 1);
2480 }
2481 print_syscall_epilogue(name);
2482 }
2483 #endif
2484
2485 #ifdef TARGET_NR_mq_open
2486 static void
2487 print_mq_open(const struct syscallname *name,
2488 abi_long arg0, abi_long arg1, abi_long arg2,
2489 abi_long arg3, abi_long arg4, abi_long arg5)
2490 {
2491 int is_creat = (arg1 & TARGET_O_CREAT);
2492
2493 print_syscall_prologue(name);
2494 print_string(arg0, 0);
2495 print_open_flags(arg1, (is_creat == 0));
2496 if (is_creat) {
2497 print_file_mode(arg2, 0);
2498 print_pointer(arg3, 1);
2499 }
2500 print_syscall_epilogue(name);
2501 }
2502 #endif
2503
2504 #ifdef TARGET_NR_open
2505 static void
2506 print_open(const struct syscallname *name,
2507 abi_long arg0, abi_long arg1, abi_long arg2,
2508 abi_long arg3, abi_long arg4, abi_long arg5)
2509 {
2510 int is_creat = (arg1 & TARGET_O_CREAT);
2511
2512 print_syscall_prologue(name);
2513 print_string(arg0, 0);
2514 print_open_flags(arg1, (is_creat == 0));
2515 if (is_creat)
2516 print_file_mode(arg2, 1);
2517 print_syscall_epilogue(name);
2518 }
2519 #endif
2520
2521 #ifdef TARGET_NR_openat
2522 static void
2523 print_openat(const struct syscallname *name,
2524 abi_long arg0, abi_long arg1, abi_long arg2,
2525 abi_long arg3, abi_long arg4, abi_long arg5)
2526 {
2527 int is_creat = (arg2 & TARGET_O_CREAT);
2528
2529 print_syscall_prologue(name);
2530 print_at_dirfd(arg0, 0);
2531 print_string(arg1, 0);
2532 print_open_flags(arg2, (is_creat == 0));
2533 if (is_creat)
2534 print_file_mode(arg3, 1);
2535 print_syscall_epilogue(name);
2536 }
2537 #endif
2538
2539 #ifdef TARGET_NR_mq_unlink
2540 static void
2541 print_mq_unlink(const struct syscallname *name,
2542 abi_long arg0, abi_long arg1, abi_long arg2,
2543 abi_long arg3, abi_long arg4, abi_long arg5)
2544 {
2545 print_syscall_prologue(name);
2546 print_string(arg0, 1);
2547 print_syscall_epilogue(name);
2548 }
2549 #endif
2550
2551 #if defined(TARGET_NR_fstatat64) || defined(TARGET_NR_newfstatat)
2552 static void
2553 print_fstatat64(const struct syscallname *name,
2554 abi_long arg0, abi_long arg1, abi_long arg2,
2555 abi_long arg3, abi_long arg4, abi_long arg5)
2556 {
2557 print_syscall_prologue(name);
2558 print_at_dirfd(arg0, 0);
2559 print_string(arg1, 0);
2560 print_pointer(arg2, 0);
2561 print_flags(at_file_flags, arg3, 1);
2562 print_syscall_epilogue(name);
2563 }
2564 #define print_newfstatat print_fstatat64
2565 #endif
2566
2567 #ifdef TARGET_NR_readlink
2568 static void
2569 print_readlink(const struct syscallname *name,
2570 abi_long arg0, abi_long arg1, abi_long arg2,
2571 abi_long arg3, abi_long arg4, abi_long arg5)
2572 {
2573 print_syscall_prologue(name);
2574 print_string(arg0, 0);
2575 print_pointer(arg1, 0);
2576 print_raw_param("%u", arg2, 1);
2577 print_syscall_epilogue(name);
2578 }
2579 #endif
2580
2581 #ifdef TARGET_NR_readlinkat
2582 static void
2583 print_readlinkat(const struct syscallname *name,
2584 abi_long arg0, abi_long arg1, abi_long arg2,
2585 abi_long arg3, abi_long arg4, abi_long arg5)
2586 {
2587 print_syscall_prologue(name);
2588 print_at_dirfd(arg0, 0);
2589 print_string(arg1, 0);
2590 print_pointer(arg2, 0);
2591 print_raw_param("%u", arg3, 1);
2592 print_syscall_epilogue(name);
2593 }
2594 #endif
2595
2596 #ifdef TARGET_NR_rename
2597 static void
2598 print_rename(const struct syscallname *name,
2599 abi_long arg0, abi_long arg1, abi_long arg2,
2600 abi_long arg3, abi_long arg4, abi_long arg5)
2601 {
2602 print_syscall_prologue(name);
2603 print_string(arg0, 0);
2604 print_string(arg1, 1);
2605 print_syscall_epilogue(name);
2606 }
2607 #endif
2608
2609 #ifdef TARGET_NR_renameat
2610 static void
2611 print_renameat(const struct syscallname *name,
2612 abi_long arg0, abi_long arg1, abi_long arg2,
2613 abi_long arg3, abi_long arg4, abi_long arg5)
2614 {
2615 print_syscall_prologue(name);
2616 print_at_dirfd(arg0, 0);
2617 print_string(arg1, 0);
2618 print_at_dirfd(arg2, 0);
2619 print_string(arg3, 1);
2620 print_syscall_epilogue(name);
2621 }
2622 #endif
2623
2624 #ifdef TARGET_NR_statfs
2625 static void
2626 print_statfs(const struct syscallname *name,
2627 abi_long arg0, abi_long arg1, abi_long arg2,
2628 abi_long arg3, abi_long arg4, abi_long arg5)
2629 {
2630 print_syscall_prologue(name);
2631 print_string(arg0, 0);
2632 print_pointer(arg1, 1);
2633 print_syscall_epilogue(name);
2634 }
2635 #endif
2636
2637 #ifdef TARGET_NR_statfs64
2638 static void
2639 print_statfs64(const struct syscallname *name,
2640 abi_long arg0, abi_long arg1, abi_long arg2,
2641 abi_long arg3, abi_long arg4, abi_long arg5)
2642 {
2643 print_syscall_prologue(name);
2644 print_string(arg0, 0);
2645 print_pointer(arg1, 1);
2646 print_syscall_epilogue(name);
2647 }
2648 #endif
2649
2650 #ifdef TARGET_NR_symlink
2651 static void
2652 print_symlink(const struct syscallname *name,
2653 abi_long arg0, abi_long arg1, abi_long arg2,
2654 abi_long arg3, abi_long arg4, abi_long arg5)
2655 {
2656 print_syscall_prologue(name);
2657 print_string(arg0, 0);
2658 print_string(arg1, 1);
2659 print_syscall_epilogue(name);
2660 }
2661 #endif
2662
2663 #ifdef TARGET_NR_symlinkat
2664 static void
2665 print_symlinkat(const struct syscallname *name,
2666 abi_long arg0, abi_long arg1, abi_long arg2,
2667 abi_long arg3, abi_long arg4, abi_long arg5)
2668 {
2669 print_syscall_prologue(name);
2670 print_string(arg0, 0);
2671 print_at_dirfd(arg1, 0);
2672 print_string(arg2, 1);
2673 print_syscall_epilogue(name);
2674 }
2675 #endif
2676
2677 #ifdef TARGET_NR_mount
2678 static void
2679 print_mount(const struct syscallname *name,
2680 abi_long arg0, abi_long arg1, abi_long arg2,
2681 abi_long arg3, abi_long arg4, abi_long arg5)
2682 {
2683 print_syscall_prologue(name);
2684 print_string(arg0, 0);
2685 print_string(arg1, 0);
2686 print_string(arg2, 0);
2687 print_flags(mount_flags, arg3, 0);
2688 print_pointer(arg4, 1);
2689 print_syscall_epilogue(name);
2690 }
2691 #endif
2692
2693 #ifdef TARGET_NR_umount
2694 static void
2695 print_umount(const struct syscallname *name,
2696 abi_long arg0, abi_long arg1, abi_long arg2,
2697 abi_long arg3, abi_long arg4, abi_long arg5)
2698 {
2699 print_syscall_prologue(name);
2700 print_string(arg0, 1);
2701 print_syscall_epilogue(name);
2702 }
2703 #endif
2704
2705 #ifdef TARGET_NR_umount2
2706 static void
2707 print_umount2(const struct syscallname *name,
2708 abi_long arg0, abi_long arg1, abi_long arg2,
2709 abi_long arg3, abi_long arg4, abi_long arg5)
2710 {
2711 print_syscall_prologue(name);
2712 print_string(arg0, 0);
2713 print_flags(umount2_flags, arg1, 1);
2714 print_syscall_epilogue(name);
2715 }
2716 #endif
2717
2718 #ifdef TARGET_NR_unlink
2719 static void
2720 print_unlink(const struct syscallname *name,
2721 abi_long arg0, abi_long arg1, abi_long arg2,
2722 abi_long arg3, abi_long arg4, abi_long arg5)
2723 {
2724 print_syscall_prologue(name);
2725 print_string(arg0, 1);
2726 print_syscall_epilogue(name);
2727 }
2728 #endif
2729
2730 #ifdef TARGET_NR_unlinkat
2731 static void
2732 print_unlinkat(const struct syscallname *name,
2733 abi_long arg0, abi_long arg1, abi_long arg2,
2734 abi_long arg3, abi_long arg4, abi_long arg5)
2735 {
2736 print_syscall_prologue(name);
2737 print_at_dirfd(arg0, 0);
2738 print_string(arg1, 0);
2739 print_flags(unlinkat_flags, arg2, 1);
2740 print_syscall_epilogue(name);
2741 }
2742 #endif
2743
2744 #ifdef TARGET_NR_utime
2745 static void
2746 print_utime(const struct syscallname *name,
2747 abi_long arg0, abi_long arg1, abi_long arg2,
2748 abi_long arg3, abi_long arg4, abi_long arg5)
2749 {
2750 print_syscall_prologue(name);
2751 print_string(arg0, 0);
2752 print_pointer(arg1, 1);
2753 print_syscall_epilogue(name);
2754 }
2755 #endif
2756
2757 #ifdef TARGET_NR_utimes
2758 static void
2759 print_utimes(const struct syscallname *name,
2760 abi_long arg0, abi_long arg1, abi_long arg2,
2761 abi_long arg3, abi_long arg4, abi_long arg5)
2762 {
2763 print_syscall_prologue(name);
2764 print_string(arg0, 0);
2765 print_pointer(arg1, 1);
2766 print_syscall_epilogue(name);
2767 }
2768 #endif
2769
2770 #ifdef TARGET_NR_utimensat
2771 static void
2772 print_utimensat(const struct syscallname *name,
2773 abi_long arg0, abi_long arg1, abi_long arg2,
2774 abi_long arg3, abi_long arg4, abi_long arg5)
2775 {
2776 print_syscall_prologue(name);
2777 print_at_dirfd(arg0, 0);
2778 print_string(arg1, 0);
2779 print_pointer(arg2, 0);
2780 print_flags(at_file_flags, arg3, 1);
2781 print_syscall_epilogue(name);
2782 }
2783 #endif
2784
2785 #if defined(TARGET_NR_mmap) || defined(TARGET_NR_mmap2)
2786 static void
2787 print_mmap(const struct syscallname *name,
2788 abi_long arg0, abi_long arg1, abi_long arg2,
2789 abi_long arg3, abi_long arg4, abi_long arg5)
2790 {
2791 print_syscall_prologue(name);
2792 print_pointer(arg0, 0);
2793 print_raw_param("%d", arg1, 0);
2794 print_flags(mmap_prot_flags, arg2, 0);
2795 print_flags(mmap_flags, arg3, 0);
2796 print_raw_param("%d", arg4, 0);
2797 print_raw_param("%#x", arg5, 1);
2798 print_syscall_epilogue(name);
2799 }
2800 #define print_mmap2 print_mmap
2801 #endif
2802
2803 #ifdef TARGET_NR_mprotect
2804 static void
2805 print_mprotect(const struct syscallname *name,
2806 abi_long arg0, abi_long arg1, abi_long arg2,
2807 abi_long arg3, abi_long arg4, abi_long arg5)
2808 {
2809 print_syscall_prologue(name);
2810 print_pointer(arg0, 0);
2811 print_raw_param("%d", arg1, 0);
2812 print_flags(mmap_prot_flags, arg2, 1);
2813 print_syscall_epilogue(name);
2814 }
2815 #endif
2816
2817 #ifdef TARGET_NR_munmap
2818 static void
2819 print_munmap(const struct syscallname *name,
2820 abi_long arg0, abi_long arg1, abi_long arg2,
2821 abi_long arg3, abi_long arg4, abi_long arg5)
2822 {
2823 print_syscall_prologue(name);
2824 print_pointer(arg0, 0);
2825 print_raw_param("%d", arg1, 1);
2826 print_syscall_epilogue(name);
2827 }
2828 #endif
2829
2830 #ifdef TARGET_NR_futex
2831 static void print_futex_op(abi_long tflag, int last)
2832 {
2833 #define print_op(val) \
2834 if( cmd == val ) { \
2835 qemu_log(#val); \
2836 return; \
2837 }
2838
2839 int cmd = (int)tflag;
2840 #ifdef FUTEX_PRIVATE_FLAG
2841 if (cmd & FUTEX_PRIVATE_FLAG) {
2842 qemu_log("FUTEX_PRIVATE_FLAG|");
2843 cmd &= ~FUTEX_PRIVATE_FLAG;
2844 }
2845 #endif
2846 #ifdef FUTEX_CLOCK_REALTIME
2847 if (cmd & FUTEX_CLOCK_REALTIME) {
2848 qemu_log("FUTEX_CLOCK_REALTIME|");
2849 cmd &= ~FUTEX_CLOCK_REALTIME;
2850 }
2851 #endif
2852 print_op(FUTEX_WAIT)
2853 print_op(FUTEX_WAKE)
2854 print_op(FUTEX_FD)
2855 print_op(FUTEX_REQUEUE)
2856 print_op(FUTEX_CMP_REQUEUE)
2857 print_op(FUTEX_WAKE_OP)
2858 print_op(FUTEX_LOCK_PI)
2859 print_op(FUTEX_UNLOCK_PI)
2860 print_op(FUTEX_TRYLOCK_PI)
2861 #ifdef FUTEX_WAIT_BITSET
2862 print_op(FUTEX_WAIT_BITSET)
2863 #endif
2864 #ifdef FUTEX_WAKE_BITSET
2865 print_op(FUTEX_WAKE_BITSET)
2866 #endif
2867 /* unknown values */
2868 qemu_log("%d", cmd);
2869 }
2870
2871 static void
2872 print_futex(const struct syscallname *name,
2873 abi_long arg0, abi_long arg1, abi_long arg2,
2874 abi_long arg3, abi_long arg4, abi_long arg5)
2875 {
2876 print_syscall_prologue(name);
2877 print_pointer(arg0, 0);
2878 print_futex_op(arg1, 0);
2879 print_raw_param(",%d", arg2, 0);
2880 print_pointer(arg3, 0); /* struct timespec */
2881 print_pointer(arg4, 0);
2882 print_raw_param("%d", arg4, 1);
2883 print_syscall_epilogue(name);
2884 }
2885 #endif
2886
2887 #ifdef TARGET_NR_kill
2888 static void
2889 print_kill(const struct syscallname *name,
2890 abi_long arg0, abi_long arg1, abi_long arg2,
2891 abi_long arg3, abi_long arg4, abi_long arg5)
2892 {
2893 print_syscall_prologue(name);
2894 print_raw_param("%d", arg0, 0);
2895 print_signal(arg1, 1);
2896 print_syscall_epilogue(name);
2897 }
2898 #endif
2899
2900 #ifdef TARGET_NR_tkill
2901 static void
2902 print_tkill(const struct syscallname *name,
2903 abi_long arg0, abi_long arg1, abi_long arg2,
2904 abi_long arg3, abi_long arg4, abi_long arg5)
2905 {
2906 print_syscall_prologue(name);
2907 print_raw_param("%d", arg0, 0);
2908 print_signal(arg1, 1);
2909 print_syscall_epilogue(name);
2910 }
2911 #endif
2912
2913 #ifdef TARGET_NR_tgkill
2914 static void
2915 print_tgkill(const struct syscallname *name,
2916 abi_long arg0, abi_long arg1, abi_long arg2,
2917 abi_long arg3, abi_long arg4, abi_long arg5)
2918 {
2919 print_syscall_prologue(name);
2920 print_raw_param("%d", arg0, 0);
2921 print_raw_param("%d", arg1, 0);
2922 print_signal(arg2, 1);
2923 print_syscall_epilogue(name);
2924 }
2925 #endif
2926
2927 #ifdef TARGET_NR_statx
2928 static void
2929 print_statx(const struct syscallname *name,
2930 abi_long arg0, abi_long arg1, abi_long arg2,
2931 abi_long arg3, abi_long arg4, abi_long arg5)
2932 {
2933 print_syscall_prologue(name);
2934 print_at_dirfd(arg0, 0);
2935 print_string(arg1, 0);
2936 print_flags(statx_flags, arg2, 0);
2937 print_flags(statx_mask, arg3, 0);
2938 print_pointer(arg4, 1);
2939 print_syscall_epilogue(name);
2940 }
2941 #endif
2942
2943 /*
2944 * An array of all of the syscalls we know about
2945 */
2946
2947 static const struct syscallname scnames[] = {
2948 #include "strace.list"
2949 };
2950
2951 static int nsyscalls = ARRAY_SIZE(scnames);
2952
2953 /*
2954 * The public interface to this module.
2955 */
2956 void
2957 print_syscall(int num,
2958 abi_long arg1, abi_long arg2, abi_long arg3,
2959 abi_long arg4, abi_long arg5, abi_long arg6)
2960 {
2961 int i;
2962 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 ")";
2963
2964 qemu_log("%d ", getpid());
2965
2966 for(i=0;i<nsyscalls;i++)
2967 if( scnames[i].nr == num ) {
2968 if( scnames[i].call != NULL ) {
2969 scnames[i].call(
2970 &scnames[i], arg1, arg2, arg3, arg4, arg5, arg6);
2971 } else {
2972 /* XXX: this format system is broken because it uses
2973 host types and host pointers for strings */
2974 if( scnames[i].format != NULL )
2975 format = scnames[i].format;
2976 qemu_log(format,
2977 scnames[i].name, arg1, arg2, arg3, arg4, arg5, arg6);
2978 }
2979 return;
2980 }
2981 qemu_log("Unknown syscall %d\n", num);
2982 }
2983
2984
2985 void
2986 print_syscall_ret(int num, abi_long ret,
2987 abi_long arg1, abi_long arg2, abi_long arg3,
2988 abi_long arg4, abi_long arg5, abi_long arg6)
2989 {
2990 int i;
2991
2992 for(i=0;i<nsyscalls;i++)
2993 if( scnames[i].nr == num ) {
2994 if( scnames[i].result != NULL ) {
2995 scnames[i].result(&scnames[i], ret,
2996 arg1, arg2, arg3,
2997 arg4, arg5, arg6);
2998 } else {
2999 print_syscall_err(ret);
3000
3001 if (ret >= 0) {
3002 qemu_log(TARGET_ABI_FMT_ld, ret);
3003 }
3004 qemu_log("\n");
3005 }
3006 break;
3007 }
3008 }
3009
3010 void print_taken_signal(int target_signum, const target_siginfo_t *tinfo)
3011 {
3012 /* Print the strace output for a signal being taken:
3013 * --- SIGSEGV {si_signo=SIGSEGV, si_code=SI_KERNEL, si_addr=0} ---
3014 */
3015 qemu_log("--- ");
3016 print_signal(target_signum, 1);
3017 qemu_log(" ");
3018 print_siginfo(tinfo);
3019 qemu_log(" ---\n");
3020 }