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