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