]> Git Repo - qemu.git/blob - linux-user/strace.c
linux-user/strace: Improve settimeofday()
[qemu.git] / linux-user / strace.c
1 #include "qemu/osdep.h"
2 #include <sys/ipc.h>
3 #include <sys/msg.h>
4 #include <sys/sem.h>
5 #include <sys/shm.h>
6 #include <sys/select.h>
7 #include <sys/mount.h>
8 #include <arpa/inet.h>
9 #include <netinet/tcp.h>
10 #include <linux/if_packet.h>
11 #include <sched.h>
12 #include "qemu.h"
13
14 int do_strace=0;
15
16 struct syscallname {
17     int nr;
18     const char *name;
19     const char *format;
20     void (*call)(const struct syscallname *,
21                  abi_long, abi_long, abi_long,
22                  abi_long, abi_long, abi_long);
23     void (*result)(const struct syscallname *, abi_long);
24 };
25
26 #ifdef __GNUC__
27 /*
28  * It is possible that target doesn't have syscall that uses
29  * following flags but we don't want the compiler to warn
30  * us about them being unused.  Same applies to utility print
31  * functions.  It is ok to keep them while not used.
32  */
33 #define UNUSED __attribute__ ((unused))
34 #else
35 #define UNUSED
36 #endif
37
38 /*
39  * Structure used to translate flag values into strings.  This is
40  * similar that is in the actual strace tool.
41  */
42 struct flags {
43     abi_long    f_value;  /* flag */
44     const char  *f_string; /* stringified flag */
45 };
46
47 /* common flags for all architectures */
48 #define FLAG_GENERIC(name) { name, #name }
49 /* target specific flags (syscall_defs.h has TARGET_<flag>) */
50 #define FLAG_TARGET(name)  { TARGET_ ## name, #name }
51 /* end of flags array */
52 #define FLAG_END           { 0, NULL }
53
54 UNUSED static const char *get_comma(int);
55 UNUSED static void print_pointer(abi_long, int);
56 UNUSED static void print_flags(const struct flags *, abi_long, int);
57 UNUSED static void print_at_dirfd(abi_long, int);
58 UNUSED static void print_file_mode(abi_long, int);
59 UNUSED static void print_open_flags(abi_long, int);
60 UNUSED static void print_syscall_prologue(const struct syscallname *);
61 UNUSED static void print_syscall_epilogue(const struct syscallname *);
62 UNUSED static void print_string(abi_long, int);
63 UNUSED static void print_buf(abi_long addr, abi_long len, int last);
64 UNUSED static void print_raw_param(const char *, abi_long, int);
65 UNUSED static void print_timeval(abi_ulong, int);
66 UNUSED static void print_timezone(abi_ulong, int);
67 UNUSED static void print_number(abi_long, int);
68 UNUSED static void print_signal(abi_ulong, int);
69 UNUSED static void print_sockaddr(abi_ulong addr, abi_long addrlen);
70 UNUSED static void print_socket_domain(int domain);
71 UNUSED static void print_socket_type(int type);
72 UNUSED static void print_socket_protocol(int domain, int type, int protocol);
73
74 /*
75  * Utility functions
76  */
77 static void
78 print_ipc_cmd(int cmd)
79 {
80 #define output_cmd(val) \
81 if( cmd == val ) { \
82     gemu_log(#val); \
83     return; \
84 }
85
86     cmd &= 0xff;
87
88     /* General IPC commands */
89     output_cmd( IPC_RMID );
90     output_cmd( IPC_SET );
91     output_cmd( IPC_STAT );
92     output_cmd( IPC_INFO );
93     /* msgctl() commands */
94     output_cmd( MSG_STAT );
95     output_cmd( MSG_INFO );
96     /* shmctl() commands */
97     output_cmd( SHM_LOCK );
98     output_cmd( SHM_UNLOCK );
99     output_cmd( SHM_STAT );
100     output_cmd( SHM_INFO );
101     /* semctl() commands */
102     output_cmd( GETPID );
103     output_cmd( GETVAL );
104     output_cmd( GETALL );
105     output_cmd( GETNCNT );
106     output_cmd( GETZCNT );
107     output_cmd( SETVAL );
108     output_cmd( SETALL );
109     output_cmd( SEM_STAT );
110     output_cmd( SEM_INFO );
111     output_cmd( IPC_RMID );
112     output_cmd( IPC_RMID );
113     output_cmd( IPC_RMID );
114     output_cmd( IPC_RMID );
115     output_cmd( IPC_RMID );
116     output_cmd( IPC_RMID );
117     output_cmd( IPC_RMID );
118     output_cmd( IPC_RMID );
119     output_cmd( IPC_RMID );
120
121     /* Some value we don't recognize */
122     gemu_log("%d",cmd);
123 }
124
125 static void
126 print_signal(abi_ulong arg, int last)
127 {
128     const char *signal_name = NULL;
129     switch(arg) {
130     case TARGET_SIGHUP: signal_name = "SIGHUP"; break;
131     case TARGET_SIGINT: signal_name = "SIGINT"; break;
132     case TARGET_SIGQUIT: signal_name = "SIGQUIT"; break;
133     case TARGET_SIGILL: signal_name = "SIGILL"; break;
134     case TARGET_SIGABRT: signal_name = "SIGABRT"; break;
135     case TARGET_SIGFPE: signal_name = "SIGFPE"; break;
136     case TARGET_SIGKILL: signal_name = "SIGKILL"; break;
137     case TARGET_SIGSEGV: signal_name = "SIGSEGV"; break;
138     case TARGET_SIGPIPE: signal_name = "SIGPIPE"; break;
139     case TARGET_SIGALRM: signal_name = "SIGALRM"; break;
140     case TARGET_SIGTERM: signal_name = "SIGTERM"; break;
141     case TARGET_SIGUSR1: signal_name = "SIGUSR1"; break;
142     case TARGET_SIGUSR2: signal_name = "SIGUSR2"; break;
143     case TARGET_SIGCHLD: signal_name = "SIGCHLD"; break;
144     case TARGET_SIGCONT: signal_name = "SIGCONT"; break;
145     case TARGET_SIGSTOP: signal_name = "SIGSTOP"; break;
146     case TARGET_SIGTTIN: signal_name = "SIGTTIN"; break;
147     case TARGET_SIGTTOU: signal_name = "SIGTTOU"; break;
148     }
149     if (signal_name == NULL) {
150         print_raw_param("%ld", arg, last);
151         return;
152     }
153     gemu_log("%s%s", signal_name, get_comma(last));
154 }
155
156 static void print_si_code(int arg)
157 {
158     const char *codename = NULL;
159
160     switch (arg) {
161     case SI_USER:
162         codename = "SI_USER";
163         break;
164     case SI_KERNEL:
165         codename = "SI_KERNEL";
166         break;
167     case SI_QUEUE:
168         codename = "SI_QUEUE";
169         break;
170     case SI_TIMER:
171         codename = "SI_TIMER";
172         break;
173     case SI_MESGQ:
174         codename = "SI_MESGQ";
175         break;
176     case SI_ASYNCIO:
177         codename = "SI_ASYNCIO";
178         break;
179     case SI_SIGIO:
180         codename = "SI_SIGIO";
181         break;
182     case SI_TKILL:
183         codename = "SI_TKILL";
184         break;
185     default:
186         gemu_log("%d", arg);
187         return;
188     }
189     gemu_log("%s", codename);
190 }
191
192 static void get_target_siginfo(target_siginfo_t *tinfo,
193                                 const target_siginfo_t *info)
194 {
195     abi_ulong sival_ptr;
196
197     int sig;
198     int si_errno;
199     int si_code;
200     int si_type;
201
202     __get_user(sig, &info->si_signo);
203     __get_user(si_errno, &tinfo->si_errno);
204     __get_user(si_code, &info->si_code);
205
206     tinfo->si_signo = sig;
207     tinfo->si_errno = si_errno;
208     tinfo->si_code = si_code;
209
210     /* Ensure we don't leak random junk to the guest later */
211     memset(tinfo->_sifields._pad, 0, sizeof(tinfo->_sifields._pad));
212
213     /* This is awkward, because we have to use a combination of
214      * the si_code and si_signo to figure out which of the union's
215      * members are valid. (Within the host kernel it is always possible
216      * to tell, but the kernel carefully avoids giving userspace the
217      * high 16 bits of si_code, so we don't have the information to
218      * do this the easy way...) We therefore make our best guess,
219      * bearing in mind that a guest can spoof most of the si_codes
220      * via rt_sigqueueinfo() if it likes.
221      *
222      * Once we have made our guess, we record it in the top 16 bits of
223      * the si_code, so that print_siginfo() later can use it.
224      * print_siginfo() will strip these top bits out before printing
225      * the si_code.
226      */
227
228     switch (si_code) {
229     case SI_USER:
230     case SI_TKILL:
231     case SI_KERNEL:
232         /* Sent via kill(), tkill() or tgkill(), or direct from the kernel.
233          * These are the only unspoofable si_code values.
234          */
235         __get_user(tinfo->_sifields._kill._pid, &info->_sifields._kill._pid);
236         __get_user(tinfo->_sifields._kill._uid, &info->_sifields._kill._uid);
237         si_type = QEMU_SI_KILL;
238         break;
239     default:
240         /* Everything else is spoofable. Make best guess based on signal */
241         switch (sig) {
242         case TARGET_SIGCHLD:
243             __get_user(tinfo->_sifields._sigchld._pid,
244                        &info->_sifields._sigchld._pid);
245             __get_user(tinfo->_sifields._sigchld._uid,
246                        &info->_sifields._sigchld._uid);
247             __get_user(tinfo->_sifields._sigchld._status,
248                        &info->_sifields._sigchld._status);
249             __get_user(tinfo->_sifields._sigchld._utime,
250                        &info->_sifields._sigchld._utime);
251             __get_user(tinfo->_sifields._sigchld._stime,
252                        &info->_sifields._sigchld._stime);
253             si_type = QEMU_SI_CHLD;
254             break;
255         case TARGET_SIGIO:
256             __get_user(tinfo->_sifields._sigpoll._band,
257                        &info->_sifields._sigpoll._band);
258             __get_user(tinfo->_sifields._sigpoll._fd,
259                        &info->_sifields._sigpoll._fd);
260             si_type = QEMU_SI_POLL;
261             break;
262         default:
263             /* Assume a sigqueue()/mq_notify()/rt_sigqueueinfo() source. */
264             __get_user(tinfo->_sifields._rt._pid, &info->_sifields._rt._pid);
265             __get_user(tinfo->_sifields._rt._uid, &info->_sifields._rt._uid);
266             /* XXX: potential problem if 64 bit */
267             __get_user(sival_ptr, &info->_sifields._rt._sigval.sival_ptr);
268             tinfo->_sifields._rt._sigval.sival_ptr = sival_ptr;
269
270             si_type = QEMU_SI_RT;
271             break;
272         }
273         break;
274     }
275
276     tinfo->si_code = deposit32(si_code, 16, 16, si_type);
277 }
278
279 static void print_siginfo(const target_siginfo_t *tinfo)
280 {
281     /* Print a target_siginfo_t in the format desired for printing
282      * signals being taken. We assume the target_siginfo_t is in the
283      * internal form where the top 16 bits of si_code indicate which
284      * part of the union is valid, rather than in the guest-visible
285      * form where the bottom 16 bits are sign-extended into the top 16.
286      */
287     int si_type = extract32(tinfo->si_code, 16, 16);
288     int si_code = sextract32(tinfo->si_code, 0, 16);
289
290     gemu_log("{si_signo=");
291     print_signal(tinfo->si_signo, 1);
292     gemu_log(", si_code=");
293     print_si_code(si_code);
294
295     switch (si_type) {
296     case QEMU_SI_KILL:
297         gemu_log(", si_pid=%u, si_uid=%u",
298                  (unsigned int)tinfo->_sifields._kill._pid,
299                  (unsigned int)tinfo->_sifields._kill._uid);
300         break;
301     case QEMU_SI_TIMER:
302         gemu_log(", si_timer1=%u, si_timer2=%u",
303                  tinfo->_sifields._timer._timer1,
304                  tinfo->_sifields._timer._timer2);
305         break;
306     case QEMU_SI_POLL:
307         gemu_log(", si_band=%d, si_fd=%d",
308                  tinfo->_sifields._sigpoll._band,
309                  tinfo->_sifields._sigpoll._fd);
310         break;
311     case QEMU_SI_FAULT:
312         gemu_log(", si_addr=");
313         print_pointer(tinfo->_sifields._sigfault._addr, 1);
314         break;
315     case QEMU_SI_CHLD:
316         gemu_log(", si_pid=%u, si_uid=%u, si_status=%d"
317                  ", si_utime=" TARGET_ABI_FMT_ld
318                  ", si_stime=" TARGET_ABI_FMT_ld,
319                  (unsigned int)(tinfo->_sifields._sigchld._pid),
320                  (unsigned int)(tinfo->_sifields._sigchld._uid),
321                  tinfo->_sifields._sigchld._status,
322                  tinfo->_sifields._sigchld._utime,
323                  tinfo->_sifields._sigchld._stime);
324         break;
325     case QEMU_SI_RT:
326         gemu_log(", si_pid=%u, si_uid=%u, si_sigval=" TARGET_ABI_FMT_ld,
327                  (unsigned int)tinfo->_sifields._rt._pid,
328                  (unsigned int)tinfo->_sifields._rt._uid,
329                  tinfo->_sifields._rt._sigval.sival_ptr);
330         break;
331     default:
332         g_assert_not_reached();
333     }
334     gemu_log("}");
335 }
336
337 static void
338 print_sockaddr(abi_ulong addr, abi_long addrlen)
339 {
340     struct target_sockaddr *sa;
341     int i;
342     int sa_family;
343
344     sa = lock_user(VERIFY_READ, addr, addrlen, 1);
345     if (sa) {
346         sa_family = tswap16(sa->sa_family);
347         switch (sa_family) {
348         case AF_UNIX: {
349             struct target_sockaddr_un *un = (struct target_sockaddr_un *)sa;
350             int i;
351             gemu_log("{sun_family=AF_UNIX,sun_path=\"");
352             for (i = 0; i < addrlen -
353                             offsetof(struct target_sockaddr_un, sun_path) &&
354                  un->sun_path[i]; i++) {
355                 gemu_log("%c", un->sun_path[i]);
356             }
357             gemu_log("\"}");
358             break;
359         }
360         case AF_INET: {
361             struct target_sockaddr_in *in = (struct target_sockaddr_in *)sa;
362             uint8_t *c = (uint8_t *)&in->sin_addr.s_addr;
363             gemu_log("{sin_family=AF_INET,sin_port=htons(%d),",
364                      ntohs(in->sin_port));
365             gemu_log("sin_addr=inet_addr(\"%d.%d.%d.%d\")",
366                      c[0], c[1], c[2], c[3]);
367             gemu_log("}");
368             break;
369         }
370         case AF_PACKET: {
371             struct target_sockaddr_ll *ll = (struct target_sockaddr_ll *)sa;
372             uint8_t *c = (uint8_t *)&ll->sll_addr;
373             gemu_log("{sll_family=AF_PACKET,"
374                      "sll_protocol=htons(0x%04x),if%d,pkttype=",
375                      ntohs(ll->sll_protocol), ll->sll_ifindex);
376             switch (ll->sll_pkttype) {
377             case PACKET_HOST:
378                 gemu_log("PACKET_HOST");
379                 break;
380             case PACKET_BROADCAST:
381                 gemu_log("PACKET_BROADCAST");
382                 break;
383             case PACKET_MULTICAST:
384                 gemu_log("PACKET_MULTICAST");
385                 break;
386             case PACKET_OTHERHOST:
387                 gemu_log("PACKET_OTHERHOST");
388                 break;
389             case PACKET_OUTGOING:
390                 gemu_log("PACKET_OUTGOING");
391                 break;
392             default:
393                 gemu_log("%d", ll->sll_pkttype);
394                 break;
395             }
396             gemu_log(",sll_addr=%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x",
397                      c[0], c[1], c[2], c[3], c[4], c[5], c[6], c[7]);
398             gemu_log("}");
399             break;
400         }
401         default:
402             gemu_log("{sa_family=%d, sa_data={", sa->sa_family);
403             for (i = 0; i < 13; i++) {
404                 gemu_log("%02x, ", sa->sa_data[i]);
405             }
406             gemu_log("%02x}", sa->sa_data[i]);
407             gemu_log("}");
408             break;
409         }
410         unlock_user(sa, addr, 0);
411     } else {
412         print_raw_param("0x"TARGET_ABI_FMT_lx, addr, 0);
413     }
414     gemu_log(", "TARGET_ABI_FMT_ld, addrlen);
415 }
416
417 static void
418 print_socket_domain(int domain)
419 {
420     switch (domain) {
421     case PF_UNIX:
422         gemu_log("PF_UNIX");
423         break;
424     case PF_INET:
425         gemu_log("PF_INET");
426         break;
427     case PF_PACKET:
428         gemu_log("PF_PACKET");
429         break;
430     default:
431         gemu_log("%d", domain);
432         break;
433     }
434 }
435
436 static void
437 print_socket_type(int type)
438 {
439     switch (type) {
440     case TARGET_SOCK_DGRAM:
441         gemu_log("SOCK_DGRAM");
442         break;
443     case TARGET_SOCK_STREAM:
444         gemu_log("SOCK_STREAM");
445         break;
446     case TARGET_SOCK_RAW:
447         gemu_log("SOCK_RAW");
448         break;
449     case TARGET_SOCK_RDM:
450         gemu_log("SOCK_RDM");
451         break;
452     case TARGET_SOCK_SEQPACKET:
453         gemu_log("SOCK_SEQPACKET");
454         break;
455     case TARGET_SOCK_PACKET:
456         gemu_log("SOCK_PACKET");
457         break;
458     }
459 }
460
461 static void
462 print_socket_protocol(int domain, int type, int protocol)
463 {
464     if (domain == AF_PACKET ||
465         (domain == AF_INET && type == TARGET_SOCK_PACKET)) {
466         switch (protocol) {
467         case 0x0003:
468             gemu_log("ETH_P_ALL");
469             break;
470         default:
471             gemu_log("%d", protocol);
472         }
473         return;
474     }
475
476     switch (protocol) {
477     case IPPROTO_IP:
478         gemu_log("IPPROTO_IP");
479         break;
480     case IPPROTO_TCP:
481         gemu_log("IPPROTO_TCP");
482         break;
483     case IPPROTO_UDP:
484         gemu_log("IPPROTO_UDP");
485         break;
486     case IPPROTO_RAW:
487         gemu_log("IPPROTO_RAW");
488         break;
489     default:
490         gemu_log("%d", protocol);
491         break;
492     }
493 }
494
495
496 #ifdef TARGET_NR__newselect
497 static void
498 print_fdset(int n, abi_ulong target_fds_addr)
499 {
500     int i;
501
502     gemu_log("[");
503     if( target_fds_addr ) {
504         abi_long *target_fds;
505
506         target_fds = lock_user(VERIFY_READ,
507                                target_fds_addr,
508                                sizeof(*target_fds)*(n / TARGET_ABI_BITS + 1),
509                                1);
510
511         if (!target_fds)
512             return;
513
514         for (i=n; i>=0; i--) {
515             if ((tswapal(target_fds[i / TARGET_ABI_BITS]) >> (i & (TARGET_ABI_BITS - 1))) & 1)
516                 gemu_log("%d,", i );
517             }
518         unlock_user(target_fds, target_fds_addr, 0);
519     }
520     gemu_log("]");
521 }
522 #endif
523
524 #ifdef TARGET_NR_clock_adjtime
525 /* IDs of the various system clocks */
526 #define TARGET_CLOCK_REALTIME              0
527 #define TARGET_CLOCK_MONOTONIC             1
528 #define TARGET_CLOCK_PROCESS_CPUTIME_ID    2
529 #define TARGET_CLOCK_THREAD_CPUTIME_ID     3
530 #define TARGET_CLOCK_MONOTONIC_RAW         4
531 #define TARGET_CLOCK_REALTIME_COARSE       5
532 #define TARGET_CLOCK_MONOTONIC_COARSE      6
533 #define TARGET_CLOCK_BOOTTIME              7
534 #define TARGET_CLOCK_REALTIME_ALARM        8
535 #define TARGET_CLOCK_BOOTTIME_ALARM        9
536 #define TARGET_CLOCK_SGI_CYCLE             10
537 #define TARGET_CLOCK_TAI                   11
538
539 static void
540 print_clockid(int clockid, int last)
541 {
542     switch (clockid) {
543     case TARGET_CLOCK_REALTIME:
544         gemu_log("CLOCK_REALTIME");
545         break;
546     case TARGET_CLOCK_MONOTONIC:
547         gemu_log("CLOCK_MONOTONIC");
548         break;
549     case TARGET_CLOCK_PROCESS_CPUTIME_ID:
550         gemu_log("CLOCK_PROCESS_CPUTIME_ID");
551         break;
552     case TARGET_CLOCK_THREAD_CPUTIME_ID:
553         gemu_log("CLOCK_THREAD_CPUTIME_ID");
554         break;
555     case TARGET_CLOCK_MONOTONIC_RAW:
556         gemu_log("CLOCK_MONOTONIC_RAW");
557         break;
558     case TARGET_CLOCK_REALTIME_COARSE:
559         gemu_log("CLOCK_REALTIME_COARSE");
560         break;
561     case TARGET_CLOCK_MONOTONIC_COARSE:
562         gemu_log("CLOCK_MONOTONIC_COARSE");
563         break;
564     case TARGET_CLOCK_BOOTTIME:
565         gemu_log("CLOCK_BOOTTIME");
566         break;
567     case TARGET_CLOCK_REALTIME_ALARM:
568         gemu_log("CLOCK_REALTIME_ALARM");
569         break;
570     case TARGET_CLOCK_BOOTTIME_ALARM:
571         gemu_log("CLOCK_BOOTTIME_ALARM");
572         break;
573     case TARGET_CLOCK_SGI_CYCLE:
574         gemu_log("CLOCK_SGI_CYCLE");
575         break;
576     case TARGET_CLOCK_TAI:
577         gemu_log("CLOCK_TAI");
578         break;
579     default:
580         gemu_log("%d", clockid);
581         break;
582     }
583     gemu_log("%s", get_comma(last));
584 }
585 #endif
586
587 /*
588  * Sysycall specific output functions
589  */
590
591 /* select */
592 #ifdef TARGET_NR__newselect
593 static long newselect_arg1 = 0;
594 static long newselect_arg2 = 0;
595 static long newselect_arg3 = 0;
596 static long newselect_arg4 = 0;
597 static long newselect_arg5 = 0;
598
599 static void
600 print_newselect(const struct syscallname *name,
601                 abi_long arg1, abi_long arg2, abi_long arg3,
602                 abi_long arg4, abi_long arg5, abi_long arg6)
603 {
604     gemu_log("%s(" TARGET_ABI_FMT_ld ",", name->name, arg1);
605     print_fdset(arg1, arg2);
606     gemu_log(",");
607     print_fdset(arg1, arg3);
608     gemu_log(",");
609     print_fdset(arg1, arg4);
610     gemu_log(",");
611     print_timeval(arg5, 1);
612     gemu_log(")");
613
614     /* save for use in the return output function below */
615     newselect_arg1=arg1;
616     newselect_arg2=arg2;
617     newselect_arg3=arg3;
618     newselect_arg4=arg4;
619     newselect_arg5=arg5;
620 }
621 #endif
622
623 #ifdef TARGET_NR_semctl
624 static void
625 print_semctl(const struct syscallname *name,
626              abi_long arg1, abi_long arg2, abi_long arg3,
627              abi_long arg4, abi_long arg5, abi_long arg6)
628 {
629     gemu_log("%s(" TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld ",", name->name, arg1, arg2);
630     print_ipc_cmd(arg3);
631     gemu_log(",0x" TARGET_ABI_FMT_lx ")", arg4);
632 }
633 #endif
634
635 static void
636 print_execve(const struct syscallname *name,
637              abi_long arg1, abi_long arg2, abi_long arg3,
638              abi_long arg4, abi_long arg5, abi_long arg6)
639 {
640     abi_ulong arg_ptr_addr;
641     char *s;
642
643     if (!(s = lock_user_string(arg1)))
644         return;
645     gemu_log("%s(\"%s\",{", name->name, s);
646     unlock_user(s, arg1, 0);
647
648     for (arg_ptr_addr = arg2; ; arg_ptr_addr += sizeof(abi_ulong)) {
649         abi_ulong *arg_ptr, arg_addr;
650
651         arg_ptr = lock_user(VERIFY_READ, arg_ptr_addr, sizeof(abi_ulong), 1);
652         if (!arg_ptr)
653             return;
654     arg_addr = tswapal(*arg_ptr);
655         unlock_user(arg_ptr, arg_ptr_addr, 0);
656         if (!arg_addr)
657             break;
658         if ((s = lock_user_string(arg_addr))) {
659             gemu_log("\"%s\",", s);
660             unlock_user(s, arg_addr, 0);
661         }
662     }
663
664     gemu_log("NULL})");
665 }
666
667 #ifdef TARGET_NR_ipc
668 static void
669 print_ipc(const struct syscallname *name,
670           abi_long arg1, abi_long arg2, abi_long arg3,
671           abi_long arg4, abi_long arg5, abi_long arg6)
672 {
673     switch(arg1) {
674     case IPCOP_semctl:
675         gemu_log("semctl(" TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld ",", arg1, arg2);
676         print_ipc_cmd(arg3);
677         gemu_log(",0x" TARGET_ABI_FMT_lx ")", arg4);
678         break;
679     default:
680         gemu_log("%s(" TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld ")",
681                  name->name, arg1, arg2, arg3, arg4);
682     }
683 }
684 #endif
685
686 /*
687  * Variants for the return value output function
688  */
689
690 static void
691 print_syscall_ret_addr(const struct syscallname *name, abi_long ret)
692 {
693     const char *errstr = NULL;
694
695     if (ret < 0) {
696         errstr = target_strerror(-ret);
697     }
698     if (errstr) {
699         gemu_log(" = -1 errno=%d (%s)\n", (int)-ret, errstr);
700     } else {
701         gemu_log(" = 0x" TARGET_ABI_FMT_lx "\n", ret);
702     }
703 }
704
705 #if 0 /* currently unused */
706 static void
707 print_syscall_ret_raw(struct syscallname *name, abi_long ret)
708 {
709         gemu_log(" = 0x" TARGET_ABI_FMT_lx "\n", ret);
710 }
711 #endif
712
713 #ifdef TARGET_NR__newselect
714 static void
715 print_syscall_ret_newselect(const struct syscallname *name, abi_long ret)
716 {
717     gemu_log(" = 0x" TARGET_ABI_FMT_lx " (", ret);
718     print_fdset(newselect_arg1,newselect_arg2);
719     gemu_log(",");
720     print_fdset(newselect_arg1,newselect_arg3);
721     gemu_log(",");
722     print_fdset(newselect_arg1,newselect_arg4);
723     gemu_log(",");
724     print_timeval(newselect_arg5, 1);
725     gemu_log(")\n");
726 }
727 #endif
728
729 /* special meanings of adjtimex()' non-negative return values */
730 #define TARGET_TIME_OK       0   /* clock synchronized, no leap second */
731 #define TARGET_TIME_INS      1   /* insert leap second */
732 #define TARGET_TIME_DEL      2   /* delete leap second */
733 #define TARGET_TIME_OOP      3   /* leap second in progress */
734 #define TARGET_TIME_WAIT     4   /* leap second has occurred */
735 #define TARGET_TIME_ERROR    5   /* clock not synchronized */
736 static void
737 print_syscall_ret_adjtimex(const struct syscallname *name, abi_long ret)
738 {
739     const char *errstr = NULL;
740
741     gemu_log(" = ");
742     if (ret < 0) {
743         gemu_log("-1 errno=%d", errno);
744         errstr = target_strerror(-ret);
745         if (errstr) {
746             gemu_log(" (%s)", errstr);
747         }
748     } else {
749         gemu_log(TARGET_ABI_FMT_ld, ret);
750         switch (ret) {
751         case TARGET_TIME_OK:
752             gemu_log(" TIME_OK (clock synchronized, no leap second)");
753             break;
754         case TARGET_TIME_INS:
755             gemu_log(" TIME_INS (insert leap second)");
756             break;
757         case TARGET_TIME_DEL:
758             gemu_log(" TIME_DEL (delete leap second)");
759             break;
760         case TARGET_TIME_OOP:
761             gemu_log(" TIME_OOP (leap second in progress)");
762             break;
763         case TARGET_TIME_WAIT:
764             gemu_log(" TIME_WAIT (leap second has occurred)");
765             break;
766         case TARGET_TIME_ERROR:
767             gemu_log(" TIME_ERROR (clock not synchronized)");
768             break;
769         }
770     }
771
772     gemu_log("\n");
773 }
774
775 UNUSED static struct flags access_flags[] = {
776     FLAG_GENERIC(F_OK),
777     FLAG_GENERIC(R_OK),
778     FLAG_GENERIC(W_OK),
779     FLAG_GENERIC(X_OK),
780     FLAG_END,
781 };
782
783 UNUSED static struct flags at_file_flags[] = {
784 #ifdef AT_EACCESS
785     FLAG_GENERIC(AT_EACCESS),
786 #endif
787 #ifdef AT_SYMLINK_NOFOLLOW
788     FLAG_GENERIC(AT_SYMLINK_NOFOLLOW),
789 #endif
790     FLAG_END,
791 };
792
793 UNUSED static struct flags unlinkat_flags[] = {
794 #ifdef AT_REMOVEDIR
795     FLAG_GENERIC(AT_REMOVEDIR),
796 #endif
797     FLAG_END,
798 };
799
800 UNUSED static struct flags mode_flags[] = {
801     FLAG_GENERIC(S_IFSOCK),
802     FLAG_GENERIC(S_IFLNK),
803     FLAG_GENERIC(S_IFREG),
804     FLAG_GENERIC(S_IFBLK),
805     FLAG_GENERIC(S_IFDIR),
806     FLAG_GENERIC(S_IFCHR),
807     FLAG_GENERIC(S_IFIFO),
808     FLAG_END,
809 };
810
811 UNUSED static struct flags open_access_flags[] = {
812     FLAG_TARGET(O_RDONLY),
813     FLAG_TARGET(O_WRONLY),
814     FLAG_TARGET(O_RDWR),
815     FLAG_END,
816 };
817
818 UNUSED static struct flags open_flags[] = {
819     FLAG_TARGET(O_APPEND),
820     FLAG_TARGET(O_CREAT),
821     FLAG_TARGET(O_DIRECTORY),
822     FLAG_TARGET(O_EXCL),
823     FLAG_TARGET(O_LARGEFILE),
824     FLAG_TARGET(O_NOCTTY),
825     FLAG_TARGET(O_NOFOLLOW),
826     FLAG_TARGET(O_NONBLOCK),      /* also O_NDELAY */
827     FLAG_TARGET(O_DSYNC),
828     FLAG_TARGET(__O_SYNC),
829     FLAG_TARGET(O_TRUNC),
830 #ifdef O_DIRECT
831     FLAG_TARGET(O_DIRECT),
832 #endif
833 #ifdef O_NOATIME
834     FLAG_TARGET(O_NOATIME),
835 #endif
836 #ifdef O_CLOEXEC
837     FLAG_TARGET(O_CLOEXEC),
838 #endif
839 #ifdef O_PATH
840     FLAG_TARGET(O_PATH),
841 #endif
842 #ifdef O_TMPFILE
843     FLAG_TARGET(O_TMPFILE),
844     FLAG_TARGET(__O_TMPFILE),
845 #endif
846     FLAG_END,
847 };
848
849 UNUSED static struct flags mount_flags[] = {
850 #ifdef MS_BIND
851     FLAG_GENERIC(MS_BIND),
852 #endif
853 #ifdef MS_DIRSYNC
854     FLAG_GENERIC(MS_DIRSYNC),
855 #endif
856     FLAG_GENERIC(MS_MANDLOCK),
857 #ifdef MS_MOVE
858     FLAG_GENERIC(MS_MOVE),
859 #endif
860     FLAG_GENERIC(MS_NOATIME),
861     FLAG_GENERIC(MS_NODEV),
862     FLAG_GENERIC(MS_NODIRATIME),
863     FLAG_GENERIC(MS_NOEXEC),
864     FLAG_GENERIC(MS_NOSUID),
865     FLAG_GENERIC(MS_RDONLY),
866 #ifdef MS_RELATIME
867     FLAG_GENERIC(MS_RELATIME),
868 #endif
869     FLAG_GENERIC(MS_REMOUNT),
870     FLAG_GENERIC(MS_SYNCHRONOUS),
871     FLAG_END,
872 };
873
874 UNUSED static struct flags umount2_flags[] = {
875 #ifdef MNT_FORCE
876     FLAG_GENERIC(MNT_FORCE),
877 #endif
878 #ifdef MNT_DETACH
879     FLAG_GENERIC(MNT_DETACH),
880 #endif
881 #ifdef MNT_EXPIRE
882     FLAG_GENERIC(MNT_EXPIRE),
883 #endif
884     FLAG_END,
885 };
886
887 UNUSED static struct flags mmap_prot_flags[] = {
888     FLAG_GENERIC(PROT_NONE),
889     FLAG_GENERIC(PROT_EXEC),
890     FLAG_GENERIC(PROT_READ),
891     FLAG_GENERIC(PROT_WRITE),
892     FLAG_TARGET(PROT_SEM),
893     FLAG_GENERIC(PROT_GROWSDOWN),
894     FLAG_GENERIC(PROT_GROWSUP),
895     FLAG_END,
896 };
897
898 UNUSED static struct flags mmap_flags[] = {
899     FLAG_TARGET(MAP_SHARED),
900     FLAG_TARGET(MAP_PRIVATE),
901     FLAG_TARGET(MAP_ANONYMOUS),
902     FLAG_TARGET(MAP_DENYWRITE),
903     FLAG_TARGET(MAP_FIXED),
904     FLAG_TARGET(MAP_GROWSDOWN),
905     FLAG_TARGET(MAP_EXECUTABLE),
906 #ifdef MAP_LOCKED
907     FLAG_TARGET(MAP_LOCKED),
908 #endif
909 #ifdef MAP_NONBLOCK
910     FLAG_TARGET(MAP_NONBLOCK),
911 #endif
912     FLAG_TARGET(MAP_NORESERVE),
913 #ifdef MAP_POPULATE
914     FLAG_TARGET(MAP_POPULATE),
915 #endif
916 #ifdef TARGET_MAP_UNINITIALIZED
917     FLAG_TARGET(MAP_UNINITIALIZED),
918 #endif
919     FLAG_END,
920 };
921
922 UNUSED static struct flags clone_flags[] = {
923     FLAG_GENERIC(CLONE_VM),
924     FLAG_GENERIC(CLONE_FS),
925     FLAG_GENERIC(CLONE_FILES),
926     FLAG_GENERIC(CLONE_SIGHAND),
927     FLAG_GENERIC(CLONE_PTRACE),
928     FLAG_GENERIC(CLONE_VFORK),
929     FLAG_GENERIC(CLONE_PARENT),
930     FLAG_GENERIC(CLONE_THREAD),
931     FLAG_GENERIC(CLONE_NEWNS),
932     FLAG_GENERIC(CLONE_SYSVSEM),
933     FLAG_GENERIC(CLONE_SETTLS),
934     FLAG_GENERIC(CLONE_PARENT_SETTID),
935     FLAG_GENERIC(CLONE_CHILD_CLEARTID),
936     FLAG_GENERIC(CLONE_DETACHED),
937     FLAG_GENERIC(CLONE_UNTRACED),
938     FLAG_GENERIC(CLONE_CHILD_SETTID),
939 #if defined(CLONE_NEWUTS)
940     FLAG_GENERIC(CLONE_NEWUTS),
941 #endif
942 #if defined(CLONE_NEWIPC)
943     FLAG_GENERIC(CLONE_NEWIPC),
944 #endif
945 #if defined(CLONE_NEWUSER)
946     FLAG_GENERIC(CLONE_NEWUSER),
947 #endif
948 #if defined(CLONE_NEWPID)
949     FLAG_GENERIC(CLONE_NEWPID),
950 #endif
951 #if defined(CLONE_NEWNET)
952     FLAG_GENERIC(CLONE_NEWNET),
953 #endif
954 #if defined(CLONE_IO)
955     FLAG_GENERIC(CLONE_IO),
956 #endif
957     FLAG_END,
958 };
959
960 UNUSED static struct flags msg_flags[] = {
961     /* send */
962     FLAG_GENERIC(MSG_CONFIRM),
963     FLAG_GENERIC(MSG_DONTROUTE),
964     FLAG_GENERIC(MSG_DONTWAIT),
965     FLAG_GENERIC(MSG_EOR),
966     FLAG_GENERIC(MSG_MORE),
967     FLAG_GENERIC(MSG_NOSIGNAL),
968     FLAG_GENERIC(MSG_OOB),
969     /* recv */
970     FLAG_GENERIC(MSG_CMSG_CLOEXEC),
971     FLAG_GENERIC(MSG_ERRQUEUE),
972     FLAG_GENERIC(MSG_PEEK),
973     FLAG_GENERIC(MSG_TRUNC),
974     FLAG_GENERIC(MSG_WAITALL),
975     /* recvmsg */
976     FLAG_GENERIC(MSG_CTRUNC),
977     FLAG_END,
978 };
979
980 UNUSED static struct flags statx_flags[] = {
981 #ifdef AT_EMPTY_PATH
982     FLAG_GENERIC(AT_EMPTY_PATH),
983 #endif
984 #ifdef AT_NO_AUTOMOUNT
985     FLAG_GENERIC(AT_NO_AUTOMOUNT),
986 #endif
987 #ifdef AT_SYMLINK_NOFOLLOW
988     FLAG_GENERIC(AT_SYMLINK_NOFOLLOW),
989 #endif
990 #ifdef AT_STATX_SYNC_AS_STAT
991     FLAG_GENERIC(AT_STATX_SYNC_AS_STAT),
992 #endif
993 #ifdef AT_STATX_FORCE_SYNC
994     FLAG_GENERIC(AT_STATX_FORCE_SYNC),
995 #endif
996 #ifdef AT_STATX_DONT_SYNC
997     FLAG_GENERIC(AT_STATX_DONT_SYNC),
998 #endif
999     FLAG_END,
1000 };
1001
1002 UNUSED static struct flags statx_mask[] = {
1003 /* This must come first, because it includes everything.  */
1004 #ifdef STATX_ALL
1005     FLAG_GENERIC(STATX_ALL),
1006 #endif
1007 /* This must come second; it includes everything except STATX_BTIME.  */
1008 #ifdef STATX_BASIC_STATS
1009     FLAG_GENERIC(STATX_BASIC_STATS),
1010 #endif
1011 #ifdef STATX_TYPE
1012     FLAG_GENERIC(STATX_TYPE),
1013 #endif
1014 #ifdef STATX_MODE
1015     FLAG_GENERIC(STATX_MODE),
1016 #endif
1017 #ifdef STATX_NLINK
1018     FLAG_GENERIC(STATX_NLINK),
1019 #endif
1020 #ifdef STATX_UID
1021     FLAG_GENERIC(STATX_UID),
1022 #endif
1023 #ifdef STATX_GID
1024     FLAG_GENERIC(STATX_GID),
1025 #endif
1026 #ifdef STATX_ATIME
1027     FLAG_GENERIC(STATX_ATIME),
1028 #endif
1029 #ifdef STATX_MTIME
1030     FLAG_GENERIC(STATX_MTIME),
1031 #endif
1032 #ifdef STATX_CTIME
1033     FLAG_GENERIC(STATX_CTIME),
1034 #endif
1035 #ifdef STATX_INO
1036     FLAG_GENERIC(STATX_INO),
1037 #endif
1038 #ifdef STATX_SIZE
1039     FLAG_GENERIC(STATX_SIZE),
1040 #endif
1041 #ifdef STATX_BLOCKS
1042     FLAG_GENERIC(STATX_BLOCKS),
1043 #endif
1044 #ifdef STATX_BTIME
1045     FLAG_GENERIC(STATX_BTIME),
1046 #endif
1047     FLAG_END,
1048 };
1049
1050 /*
1051  * print_xxx utility functions.  These are used to print syscall
1052  * parameters in certain format.  All of these have parameter
1053  * named 'last'.  This parameter is used to add comma to output
1054  * when last == 0.
1055  */
1056
1057 static const char *
1058 get_comma(int last)
1059 {
1060     return ((last) ? "" : ",");
1061 }
1062
1063 static void
1064 print_flags(const struct flags *f, abi_long flags, int last)
1065 {
1066     const char *sep = "";
1067     int n;
1068
1069     if ((flags == 0) && (f->f_value == 0)) {
1070         gemu_log("%s%s", f->f_string, get_comma(last));
1071         return;
1072     }
1073     for (n = 0; f->f_string != NULL; f++) {
1074         if ((f->f_value != 0) && ((flags & f->f_value) == f->f_value)) {
1075             gemu_log("%s%s", sep, f->f_string);
1076             flags &= ~f->f_value;
1077             sep = "|";
1078             n++;
1079         }
1080     }
1081
1082     if (n > 0) {
1083         /* print rest of the flags as numeric */
1084         if (flags != 0) {
1085             gemu_log("%s%#x%s", sep, (unsigned int)flags, get_comma(last));
1086         } else {
1087             gemu_log("%s", get_comma(last));
1088         }
1089     } else {
1090         /* no string version of flags found, print them in hex then */
1091         gemu_log("%#x%s", (unsigned int)flags, get_comma(last));
1092     }
1093 }
1094
1095 static void
1096 print_at_dirfd(abi_long dirfd, int last)
1097 {
1098 #ifdef AT_FDCWD
1099     if (dirfd == AT_FDCWD) {
1100         gemu_log("AT_FDCWD%s", get_comma(last));
1101         return;
1102     }
1103 #endif
1104     gemu_log("%d%s", (int)dirfd, get_comma(last));
1105 }
1106
1107 static void
1108 print_file_mode(abi_long mode, int last)
1109 {
1110     const char *sep = "";
1111     const struct flags *m;
1112
1113     for (m = &mode_flags[0]; m->f_string != NULL; m++) {
1114         if ((m->f_value & mode) == m->f_value) {
1115             gemu_log("%s%s", m->f_string, sep);
1116             sep = "|";
1117             mode &= ~m->f_value;
1118             break;
1119         }
1120     }
1121
1122     mode &= ~S_IFMT;
1123     /* print rest of the mode as octal */
1124     if (mode != 0)
1125         gemu_log("%s%#o", sep, (unsigned int)mode);
1126
1127     gemu_log("%s", get_comma(last));
1128 }
1129
1130 static void
1131 print_open_flags(abi_long flags, int last)
1132 {
1133     print_flags(open_access_flags, flags & TARGET_O_ACCMODE, 1);
1134     flags &= ~TARGET_O_ACCMODE;
1135     if (flags == 0) {
1136         gemu_log("%s", get_comma(last));
1137         return;
1138     }
1139     gemu_log("|");
1140     print_flags(open_flags, flags, last);
1141 }
1142
1143 static void
1144 print_syscall_prologue(const struct syscallname *sc)
1145 {
1146     gemu_log("%s(", sc->name);
1147 }
1148
1149 /*ARGSUSED*/
1150 static void
1151 print_syscall_epilogue(const struct syscallname *sc)
1152 {
1153     (void)sc;
1154     gemu_log(")");
1155 }
1156
1157 static void
1158 print_string(abi_long addr, int last)
1159 {
1160     char *s;
1161
1162     if ((s = lock_user_string(addr)) != NULL) {
1163         gemu_log("\"%s\"%s", s, get_comma(last));
1164         unlock_user(s, addr, 0);
1165     } else {
1166         /* can't get string out of it, so print it as pointer */
1167         print_pointer(addr, last);
1168     }
1169 }
1170
1171 #define MAX_PRINT_BUF 40
1172 static void
1173 print_buf(abi_long addr, abi_long len, int last)
1174 {
1175     uint8_t *s;
1176     int i;
1177
1178     s = lock_user(VERIFY_READ, addr, len, 1);
1179     if (s) {
1180         gemu_log("\"");
1181         for (i = 0; i < MAX_PRINT_BUF && i < len; i++) {
1182             if (isprint(s[i])) {
1183                 gemu_log("%c", s[i]);
1184             } else {
1185                 gemu_log("\\%o", s[i]);
1186             }
1187         }
1188         gemu_log("\"");
1189         if (i != len) {
1190             gemu_log("...");
1191         }
1192         if (!last) {
1193             gemu_log(",");
1194         }
1195         unlock_user(s, addr, 0);
1196     } else {
1197         print_pointer(addr, last);
1198     }
1199 }
1200
1201 /*
1202  * Prints out raw parameter using given format.  Caller needs
1203  * to do byte swapping if needed.
1204  */
1205 static void
1206 print_raw_param(const char *fmt, abi_long param, int last)
1207 {
1208     char format[64];
1209
1210     (void) snprintf(format, sizeof (format), "%s%s", fmt, get_comma(last));
1211     gemu_log(format, param);
1212 }
1213
1214 static void
1215 print_pointer(abi_long p, int last)
1216 {
1217     if (p == 0)
1218         gemu_log("NULL%s", get_comma(last));
1219     else
1220         gemu_log("0x" TARGET_ABI_FMT_lx "%s", p, get_comma(last));
1221 }
1222
1223 /*
1224  * Reads 32-bit (int) number from guest address space from
1225  * address 'addr' and prints it.
1226  */
1227 static void
1228 print_number(abi_long addr, int last)
1229 {
1230     if (addr == 0) {
1231         gemu_log("NULL%s", get_comma(last));
1232     } else {
1233         int num;
1234
1235         get_user_s32(num, addr);
1236         gemu_log("[%d]%s", num, get_comma(last));
1237     }
1238 }
1239
1240 static void
1241 print_timeval(abi_ulong tv_addr, int last)
1242 {
1243     if( tv_addr ) {
1244         struct target_timeval *tv;
1245
1246         tv = lock_user(VERIFY_READ, tv_addr, sizeof(*tv), 1);
1247         if (!tv) {
1248             print_pointer(tv_addr, last);
1249             return;
1250         }
1251         gemu_log("{" TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld "}%s",
1252             tswapal(tv->tv_sec), tswapal(tv->tv_usec), get_comma(last));
1253         unlock_user(tv, tv_addr, 0);
1254     } else
1255         gemu_log("NULL%s", get_comma(last));
1256 }
1257
1258 static void
1259 print_timezone(abi_ulong tz_addr, int last)
1260 {
1261     if (tz_addr) {
1262         struct target_timezone *tz;
1263
1264         tz = lock_user(VERIFY_READ, tz_addr, sizeof(*tz), 1);
1265         if (!tz) {
1266             print_pointer(tz_addr, last);
1267             return;
1268         }
1269         gemu_log("{%d,%d}%s", tswap32(tz->tz_minuteswest),
1270                  tswap32(tz->tz_dsttime), get_comma(last));
1271         unlock_user(tz, tz_addr, 0);
1272     } else {
1273         gemu_log("NULL%s", get_comma(last));
1274     }
1275 }
1276
1277 #undef UNUSED
1278
1279 #ifdef TARGET_NR_accept
1280 static void
1281 print_accept(const struct syscallname *name,
1282     abi_long arg0, abi_long arg1, abi_long arg2,
1283     abi_long arg3, abi_long arg4, abi_long arg5)
1284 {
1285     print_syscall_prologue(name);
1286     print_raw_param("%d", arg0, 0);
1287     print_pointer(arg1, 0);
1288     print_number(arg2, 1);
1289     print_syscall_epilogue(name);
1290 }
1291 #endif
1292
1293 #ifdef TARGET_NR_access
1294 static void
1295 print_access(const struct syscallname *name,
1296     abi_long arg0, abi_long arg1, abi_long arg2,
1297     abi_long arg3, abi_long arg4, abi_long arg5)
1298 {
1299     print_syscall_prologue(name);
1300     print_string(arg0, 0);
1301     print_flags(access_flags, arg1, 1);
1302     print_syscall_epilogue(name);
1303 }
1304 #endif
1305
1306 #ifdef TARGET_NR_brk
1307 static void
1308 print_brk(const struct syscallname *name,
1309     abi_long arg0, abi_long arg1, abi_long arg2,
1310     abi_long arg3, abi_long arg4, abi_long arg5)
1311 {
1312     print_syscall_prologue(name);
1313     print_pointer(arg0, 1);
1314     print_syscall_epilogue(name);
1315 }
1316 #endif
1317
1318 #ifdef TARGET_NR_chdir
1319 static void
1320 print_chdir(const struct syscallname *name,
1321     abi_long arg0, abi_long arg1, abi_long arg2,
1322     abi_long arg3, abi_long arg4, abi_long arg5)
1323 {
1324     print_syscall_prologue(name);
1325     print_string(arg0, 1);
1326     print_syscall_epilogue(name);
1327 }
1328 #endif
1329
1330 #ifdef TARGET_NR_chroot
1331 static void
1332 print_chroot(const struct syscallname *name,
1333     abi_long arg0, abi_long arg1, abi_long arg2,
1334     abi_long arg3, abi_long arg4, abi_long arg5)
1335 {
1336     print_syscall_prologue(name);
1337     print_string(arg0, 1);
1338     print_syscall_epilogue(name);
1339 }
1340 #endif
1341
1342 #ifdef TARGET_NR_chmod
1343 static void
1344 print_chmod(const struct syscallname *name,
1345     abi_long arg0, abi_long arg1, abi_long arg2,
1346     abi_long arg3, abi_long arg4, abi_long arg5)
1347 {
1348     print_syscall_prologue(name);
1349     print_string(arg0, 0);
1350     print_file_mode(arg1, 1);
1351     print_syscall_epilogue(name);
1352 }
1353 #endif
1354
1355 #ifdef TARGET_NR_clock_adjtime
1356 static void
1357 print_clock_adjtime(const struct syscallname *name,
1358     abi_long arg0, abi_long arg1, abi_long arg2,
1359     abi_long arg3, abi_long arg4, abi_long arg5)
1360 {
1361     print_syscall_prologue(name);
1362     print_clockid(arg0, 0);
1363     print_pointer(arg1, 1);
1364     print_syscall_epilogue(name);
1365 }
1366 #endif
1367
1368 #ifdef TARGET_NR_clone
1369 static void do_print_clone(unsigned int flags, abi_ulong newsp,
1370                            abi_ulong parent_tidptr, target_ulong newtls,
1371                            abi_ulong child_tidptr)
1372 {
1373     print_flags(clone_flags, flags, 0);
1374     print_raw_param("child_stack=0x" TARGET_ABI_FMT_lx, newsp, 0);
1375     print_raw_param("parent_tidptr=0x" TARGET_ABI_FMT_lx, parent_tidptr, 0);
1376     print_raw_param("tls=0x" TARGET_ABI_FMT_lx, newtls, 0);
1377     print_raw_param("child_tidptr=0x" TARGET_ABI_FMT_lx, child_tidptr, 1);
1378 }
1379
1380 static void
1381 print_clone(const struct syscallname *name,
1382     abi_long arg1, abi_long arg2, abi_long arg3,
1383     abi_long arg4, abi_long arg5, abi_long arg6)
1384 {
1385     print_syscall_prologue(name);
1386 #if defined(TARGET_MICROBLAZE)
1387     do_print_clone(arg1, arg2, arg4, arg6, arg5);
1388 #elif defined(TARGET_CLONE_BACKWARDS)
1389     do_print_clone(arg1, arg2, arg3, arg4, arg5);
1390 #elif defined(TARGET_CLONE_BACKWARDS2)
1391     do_print_clone(arg2, arg1, arg3, arg5, arg4);
1392 #else
1393     do_print_clone(arg1, arg2, arg3, arg5, arg4);
1394 #endif
1395     print_syscall_epilogue(name);
1396 }
1397 #endif
1398
1399 #ifdef TARGET_NR_creat
1400 static void
1401 print_creat(const struct syscallname *name,
1402     abi_long arg0, abi_long arg1, abi_long arg2,
1403     abi_long arg3, abi_long arg4, abi_long arg5)
1404 {
1405     print_syscall_prologue(name);
1406     print_string(arg0, 0);
1407     print_file_mode(arg1, 1);
1408     print_syscall_epilogue(name);
1409 }
1410 #endif
1411
1412 #ifdef TARGET_NR_execv
1413 static void
1414 print_execv(const struct syscallname *name,
1415     abi_long arg0, abi_long arg1, abi_long arg2,
1416     abi_long arg3, abi_long arg4, abi_long arg5)
1417 {
1418     print_syscall_prologue(name);
1419     print_string(arg0, 0);
1420     print_raw_param("0x" TARGET_ABI_FMT_lx, arg1, 1);
1421     print_syscall_epilogue(name);
1422 }
1423 #endif
1424
1425 #ifdef TARGET_NR_faccessat
1426 static void
1427 print_faccessat(const struct syscallname *name,
1428     abi_long arg0, abi_long arg1, abi_long arg2,
1429     abi_long arg3, abi_long arg4, abi_long arg5)
1430 {
1431     print_syscall_prologue(name);
1432     print_at_dirfd(arg0, 0);
1433     print_string(arg1, 0);
1434     print_flags(access_flags, arg2, 0);
1435     print_flags(at_file_flags, arg3, 1);
1436     print_syscall_epilogue(name);
1437 }
1438 #endif
1439
1440 #ifdef TARGET_NR_fchmodat
1441 static void
1442 print_fchmodat(const struct syscallname *name,
1443     abi_long arg0, abi_long arg1, abi_long arg2,
1444     abi_long arg3, abi_long arg4, abi_long arg5)
1445 {
1446     print_syscall_prologue(name);
1447     print_at_dirfd(arg0, 0);
1448     print_string(arg1, 0);
1449     print_file_mode(arg2, 0);
1450     print_flags(at_file_flags, arg3, 1);
1451     print_syscall_epilogue(name);
1452 }
1453 #endif
1454
1455 #ifdef TARGET_NR_fchownat
1456 static void
1457 print_fchownat(const struct syscallname *name,
1458     abi_long arg0, abi_long arg1, abi_long arg2,
1459     abi_long arg3, abi_long arg4, abi_long arg5)
1460 {
1461     print_syscall_prologue(name);
1462     print_at_dirfd(arg0, 0);
1463     print_string(arg1, 0);
1464     print_raw_param("%d", arg2, 0);
1465     print_raw_param("%d", arg3, 0);
1466     print_flags(at_file_flags, arg4, 1);
1467     print_syscall_epilogue(name);
1468 }
1469 #endif
1470
1471 #if defined(TARGET_NR_fcntl) || defined(TARGET_NR_fcntl64)
1472 static void
1473 print_fcntl(const struct syscallname *name,
1474     abi_long arg0, abi_long arg1, abi_long arg2,
1475     abi_long arg3, abi_long arg4, abi_long arg5)
1476 {
1477     print_syscall_prologue(name);
1478     print_raw_param("%d", arg0, 0);
1479     switch(arg1) {
1480     case TARGET_F_DUPFD:
1481         gemu_log("F_DUPFD,");
1482         print_raw_param(TARGET_ABI_FMT_ld, arg2, 1);
1483         break;
1484     case TARGET_F_GETFD:
1485         gemu_log("F_GETFD");
1486         break;
1487     case TARGET_F_SETFD:
1488         gemu_log("F_SETFD,");
1489         print_raw_param(TARGET_ABI_FMT_ld, arg2, 1);
1490         break;
1491     case TARGET_F_GETFL:
1492         gemu_log("F_GETFL");
1493         break;
1494     case TARGET_F_SETFL:
1495         gemu_log("F_SETFL,");
1496         print_open_flags(arg2, 1);
1497         break;
1498     case TARGET_F_GETLK:
1499         gemu_log("F_GETLK,");
1500         print_pointer(arg2, 1);
1501         break;
1502     case TARGET_F_SETLK:
1503         gemu_log("F_SETLK,");
1504         print_pointer(arg2, 1);
1505         break;
1506     case TARGET_F_SETLKW:
1507         gemu_log("F_SETLKW,");
1508         print_pointer(arg2, 1);
1509         break;
1510     case TARGET_F_GETOWN:
1511         gemu_log("F_GETOWN");
1512         break;
1513     case TARGET_F_SETOWN:
1514         gemu_log("F_SETOWN,");
1515         print_raw_param(TARGET_ABI_FMT_ld, arg2, 0);
1516         break;
1517     case TARGET_F_GETSIG:
1518         gemu_log("F_GETSIG");
1519         break;
1520     case TARGET_F_SETSIG:
1521         gemu_log("F_SETSIG,");
1522         print_raw_param(TARGET_ABI_FMT_ld, arg2, 0);
1523         break;
1524 #if TARGET_ABI_BITS == 32
1525     case TARGET_F_GETLK64:
1526         gemu_log("F_GETLK64,");
1527         print_pointer(arg2, 1);
1528         break;
1529     case TARGET_F_SETLK64:
1530         gemu_log("F_SETLK64,");
1531         print_pointer(arg2, 1);
1532         break;
1533     case TARGET_F_SETLKW64:
1534         gemu_log("F_SETLKW64,");
1535         print_pointer(arg2, 1);
1536         break;
1537 #endif
1538     case TARGET_F_SETLEASE:
1539         gemu_log("F_SETLEASE,");
1540         print_raw_param(TARGET_ABI_FMT_ld, arg2, 0);
1541         break;
1542     case TARGET_F_GETLEASE:
1543         gemu_log("F_GETLEASE");
1544         break;
1545     case TARGET_F_SETPIPE_SZ:
1546         gemu_log("F_SETPIPE_SZ,");
1547         print_raw_param(TARGET_ABI_FMT_ld, arg2, 1);
1548         break;
1549     case TARGET_F_GETPIPE_SZ:
1550         gemu_log("F_GETPIPE_SZ");
1551         break;
1552     case TARGET_F_DUPFD_CLOEXEC:
1553         gemu_log("F_DUPFD_CLOEXEC,");
1554         print_raw_param(TARGET_ABI_FMT_ld, arg2, 1);
1555         break;
1556     case TARGET_F_NOTIFY:
1557         gemu_log("F_NOTIFY,");
1558         print_raw_param(TARGET_ABI_FMT_ld, arg2, 0);
1559         break;
1560     default:
1561         print_raw_param(TARGET_ABI_FMT_ld, arg1, 0);
1562         print_pointer(arg2, 1);
1563         break;
1564     }
1565     print_syscall_epilogue(name);
1566 }
1567 #define print_fcntl64   print_fcntl
1568 #endif
1569
1570
1571 #ifdef TARGET_NR_futimesat
1572 static void
1573 print_futimesat(const struct syscallname *name,
1574     abi_long arg0, abi_long arg1, abi_long arg2,
1575     abi_long arg3, abi_long arg4, abi_long arg5)
1576 {
1577     print_syscall_prologue(name);
1578     print_at_dirfd(arg0, 0);
1579     print_string(arg1, 0);
1580     print_timeval(arg2, 0);
1581     print_timeval(arg2 + sizeof (struct target_timeval), 1);
1582     print_syscall_epilogue(name);
1583 }
1584 #endif
1585
1586 #ifdef TARGET_NR_settimeofday
1587 static void
1588 print_settimeofday(const struct syscallname *name,
1589                 abi_long arg0, abi_long arg1, abi_long arg2,
1590                 abi_long arg3, abi_long arg4, abi_long arg5)
1591 {
1592     print_syscall_prologue(name);
1593     print_timeval(arg0, 0);
1594     print_timezone(arg1, 1);
1595     print_syscall_epilogue(name);
1596 }
1597 #endif
1598
1599 #ifdef TARGET_NR_link
1600 static void
1601 print_link(const struct syscallname *name,
1602     abi_long arg0, abi_long arg1, abi_long arg2,
1603     abi_long arg3, abi_long arg4, abi_long arg5)
1604 {
1605     print_syscall_prologue(name);
1606     print_string(arg0, 0);
1607     print_string(arg1, 1);
1608     print_syscall_epilogue(name);
1609 }
1610 #endif
1611
1612 #ifdef TARGET_NR_linkat
1613 static void
1614 print_linkat(const struct syscallname *name,
1615     abi_long arg0, abi_long arg1, abi_long arg2,
1616     abi_long arg3, abi_long arg4, abi_long arg5)
1617 {
1618     print_syscall_prologue(name);
1619     print_at_dirfd(arg0, 0);
1620     print_string(arg1, 0);
1621     print_at_dirfd(arg2, 0);
1622     print_string(arg3, 0);
1623     print_flags(at_file_flags, arg4, 1);
1624     print_syscall_epilogue(name);
1625 }
1626 #endif
1627
1628 #ifdef TARGET_NR__llseek
1629 static void
1630 print__llseek(const struct syscallname *name,
1631     abi_long arg0, abi_long arg1, abi_long arg2,
1632     abi_long arg3, abi_long arg4, abi_long arg5)
1633 {
1634     const char *whence = "UNKNOWN";
1635     print_syscall_prologue(name);
1636     print_raw_param("%d", arg0, 0);
1637     print_raw_param("%ld", arg1, 0);
1638     print_raw_param("%ld", arg2, 0);
1639     print_pointer(arg3, 0);
1640     switch(arg4) {
1641     case SEEK_SET: whence = "SEEK_SET"; break;
1642     case SEEK_CUR: whence = "SEEK_CUR"; break;
1643     case SEEK_END: whence = "SEEK_END"; break;
1644     }
1645     gemu_log("%s",whence);
1646     print_syscall_epilogue(name);
1647 }
1648 #endif
1649
1650 #if defined(TARGET_NR_socket)
1651 static void
1652 print_socket(const struct syscallname *name,
1653              abi_long arg0, abi_long arg1, abi_long arg2,
1654              abi_long arg3, abi_long arg4, abi_long arg5)
1655 {
1656     abi_ulong domain = arg0, type = arg1, protocol = arg2;
1657
1658     print_syscall_prologue(name);
1659     print_socket_domain(domain);
1660     gemu_log(",");
1661     print_socket_type(type);
1662     gemu_log(",");
1663     if (domain == AF_PACKET ||
1664         (domain == AF_INET && type == TARGET_SOCK_PACKET)) {
1665         protocol = tswap16(protocol);
1666     }
1667     print_socket_protocol(domain, type, protocol);
1668     print_syscall_epilogue(name);
1669 }
1670
1671 #endif
1672
1673 #if defined(TARGET_NR_socketcall)
1674
1675 #define get_user_ualx(x, gaddr, idx) \
1676         get_user_ual(x, (gaddr) + (idx) * sizeof(abi_long))
1677
1678 static void do_print_socket(const char *name, abi_long arg1)
1679 {
1680     abi_ulong domain, type, protocol;
1681
1682     get_user_ualx(domain, arg1, 0);
1683     get_user_ualx(type, arg1, 1);
1684     get_user_ualx(protocol, arg1, 2);
1685     gemu_log("%s(", name);
1686     print_socket_domain(domain);
1687     gemu_log(",");
1688     print_socket_type(type);
1689     gemu_log(",");
1690     if (domain == AF_PACKET ||
1691         (domain == AF_INET && type == TARGET_SOCK_PACKET)) {
1692         protocol = tswap16(protocol);
1693     }
1694     print_socket_protocol(domain, type, protocol);
1695     gemu_log(")");
1696 }
1697
1698 static void do_print_sockaddr(const char *name, abi_long arg1)
1699 {
1700     abi_ulong sockfd, addr, addrlen;
1701
1702     get_user_ualx(sockfd, arg1, 0);
1703     get_user_ualx(addr, arg1, 1);
1704     get_user_ualx(addrlen, arg1, 2);
1705
1706     gemu_log("%s(", name);
1707     print_raw_param(TARGET_ABI_FMT_ld, sockfd, 0);
1708     print_sockaddr(addr, addrlen);
1709     gemu_log(")");
1710 }
1711
1712 static void do_print_listen(const char *name, abi_long arg1)
1713 {
1714     abi_ulong sockfd, backlog;
1715
1716     get_user_ualx(sockfd, arg1, 0);
1717     get_user_ualx(backlog, arg1, 1);
1718
1719     gemu_log("%s(", name);
1720     print_raw_param(TARGET_ABI_FMT_ld, sockfd, 0);
1721     print_raw_param(TARGET_ABI_FMT_ld, backlog, 1);
1722     gemu_log(")");
1723 }
1724
1725 static void do_print_socketpair(const char *name, abi_long arg1)
1726 {
1727     abi_ulong domain, type, protocol, tab;
1728
1729     get_user_ualx(domain, arg1, 0);
1730     get_user_ualx(type, arg1, 1);
1731     get_user_ualx(protocol, arg1, 2);
1732     get_user_ualx(tab, arg1, 3);
1733
1734     gemu_log("%s(", name);
1735     print_socket_domain(domain);
1736     gemu_log(",");
1737     print_socket_type(type);
1738     gemu_log(",");
1739     print_socket_protocol(domain, type, protocol);
1740     gemu_log(",");
1741     print_raw_param(TARGET_ABI_FMT_lx, tab, 1);
1742     gemu_log(")");
1743 }
1744
1745 static void do_print_sendrecv(const char *name, abi_long arg1)
1746 {
1747     abi_ulong sockfd, msg, len, flags;
1748
1749     get_user_ualx(sockfd, arg1, 0);
1750     get_user_ualx(msg, arg1, 1);
1751     get_user_ualx(len, arg1, 2);
1752     get_user_ualx(flags, arg1, 3);
1753
1754     gemu_log("%s(", name);
1755     print_raw_param(TARGET_ABI_FMT_ld, sockfd, 0);
1756     print_buf(msg, len, 0);
1757     print_raw_param(TARGET_ABI_FMT_ld, len, 0);
1758     print_flags(msg_flags, flags, 1);
1759     gemu_log(")");
1760 }
1761
1762 static void do_print_msgaddr(const char *name, abi_long arg1)
1763 {
1764     abi_ulong sockfd, msg, len, flags, addr, addrlen;
1765
1766     get_user_ualx(sockfd, arg1, 0);
1767     get_user_ualx(msg, arg1, 1);
1768     get_user_ualx(len, arg1, 2);
1769     get_user_ualx(flags, arg1, 3);
1770     get_user_ualx(addr, arg1, 4);
1771     get_user_ualx(addrlen, arg1, 5);
1772
1773     gemu_log("%s(", name);
1774     print_raw_param(TARGET_ABI_FMT_ld, sockfd, 0);
1775     print_buf(msg, len, 0);
1776     print_raw_param(TARGET_ABI_FMT_ld, len, 0);
1777     print_flags(msg_flags, flags, 0);
1778     print_sockaddr(addr, addrlen);
1779     gemu_log(")");
1780 }
1781
1782 static void do_print_shutdown(const char *name, abi_long arg1)
1783 {
1784     abi_ulong sockfd, how;
1785
1786     get_user_ualx(sockfd, arg1, 0);
1787     get_user_ualx(how, arg1, 1);
1788
1789     gemu_log("shutdown(");
1790     print_raw_param(TARGET_ABI_FMT_ld, sockfd, 0);
1791     switch (how) {
1792     case SHUT_RD:
1793         gemu_log("SHUT_RD");
1794         break;
1795     case SHUT_WR:
1796         gemu_log("SHUT_WR");
1797         break;
1798     case SHUT_RDWR:
1799         gemu_log("SHUT_RDWR");
1800         break;
1801     default:
1802         print_raw_param(TARGET_ABI_FMT_ld, how, 1);
1803         break;
1804     }
1805     gemu_log(")");
1806 }
1807
1808 static void do_print_msg(const char *name, abi_long arg1)
1809 {
1810     abi_ulong sockfd, msg, flags;
1811
1812     get_user_ualx(sockfd, arg1, 0);
1813     get_user_ualx(msg, arg1, 1);
1814     get_user_ualx(flags, arg1, 2);
1815
1816     gemu_log("%s(", name);
1817     print_raw_param(TARGET_ABI_FMT_ld, sockfd, 0);
1818     print_pointer(msg, 0);
1819     print_flags(msg_flags, flags, 1);
1820     gemu_log(")");
1821 }
1822
1823 static void do_print_sockopt(const char *name, abi_long arg1)
1824 {
1825     abi_ulong sockfd, level, optname, optval, optlen;
1826
1827     get_user_ualx(sockfd, arg1, 0);
1828     get_user_ualx(level, arg1, 1);
1829     get_user_ualx(optname, arg1, 2);
1830     get_user_ualx(optval, arg1, 3);
1831     get_user_ualx(optlen, arg1, 4);
1832
1833     gemu_log("%s(", name);
1834     print_raw_param(TARGET_ABI_FMT_ld, sockfd, 0);
1835     switch (level) {
1836     case SOL_TCP:
1837         gemu_log("SOL_TCP,");
1838         print_raw_param(TARGET_ABI_FMT_ld, optname, 0);
1839         print_pointer(optval, 0);
1840         break;
1841     case SOL_IP:
1842         gemu_log("SOL_IP,");
1843         print_raw_param(TARGET_ABI_FMT_ld, optname, 0);
1844         print_pointer(optval, 0);
1845         break;
1846     case SOL_RAW:
1847         gemu_log("SOL_RAW,");
1848         print_raw_param(TARGET_ABI_FMT_ld, optname, 0);
1849         print_pointer(optval, 0);
1850         break;
1851     case TARGET_SOL_SOCKET:
1852         gemu_log("SOL_SOCKET,");
1853         switch (optname) {
1854         case TARGET_SO_DEBUG:
1855             gemu_log("SO_DEBUG,");
1856 print_optint:
1857             print_number(optval, 0);
1858             break;
1859         case TARGET_SO_REUSEADDR:
1860             gemu_log("SO_REUSEADDR,");
1861             goto print_optint;
1862         case TARGET_SO_REUSEPORT:
1863             gemu_log("SO_REUSEPORT,");
1864             goto print_optint;
1865         case TARGET_SO_TYPE:
1866             gemu_log("SO_TYPE,");
1867             goto print_optint;
1868         case TARGET_SO_ERROR:
1869             gemu_log("SO_ERROR,");
1870             goto print_optint;
1871         case TARGET_SO_DONTROUTE:
1872             gemu_log("SO_DONTROUTE,");
1873             goto print_optint;
1874         case TARGET_SO_BROADCAST:
1875             gemu_log("SO_BROADCAST,");
1876             goto print_optint;
1877         case TARGET_SO_SNDBUF:
1878             gemu_log("SO_SNDBUF,");
1879             goto print_optint;
1880         case TARGET_SO_RCVBUF:
1881             gemu_log("SO_RCVBUF,");
1882             goto print_optint;
1883         case TARGET_SO_KEEPALIVE:
1884             gemu_log("SO_KEEPALIVE,");
1885             goto print_optint;
1886         case TARGET_SO_OOBINLINE:
1887             gemu_log("SO_OOBINLINE,");
1888             goto print_optint;
1889         case TARGET_SO_NO_CHECK:
1890             gemu_log("SO_NO_CHECK,");
1891             goto print_optint;
1892         case TARGET_SO_PRIORITY:
1893             gemu_log("SO_PRIORITY,");
1894             goto print_optint;
1895         case TARGET_SO_BSDCOMPAT:
1896             gemu_log("SO_BSDCOMPAT,");
1897             goto print_optint;
1898         case TARGET_SO_PASSCRED:
1899             gemu_log("SO_PASSCRED,");
1900             goto print_optint;
1901         case TARGET_SO_TIMESTAMP:
1902             gemu_log("SO_TIMESTAMP,");
1903             goto print_optint;
1904         case TARGET_SO_RCVLOWAT:
1905             gemu_log("SO_RCVLOWAT,");
1906             goto print_optint;
1907         case TARGET_SO_RCVTIMEO:
1908             gemu_log("SO_RCVTIMEO,");
1909             print_timeval(optval, 0);
1910             break;
1911         case TARGET_SO_SNDTIMEO:
1912             gemu_log("SO_SNDTIMEO,");
1913             print_timeval(optval, 0);
1914             break;
1915         case TARGET_SO_ATTACH_FILTER: {
1916             struct target_sock_fprog *fprog;
1917
1918             gemu_log("SO_ATTACH_FILTER,");
1919
1920             if (lock_user_struct(VERIFY_READ, fprog, optval,  0)) {
1921                 struct target_sock_filter *filter;
1922                 gemu_log("{");
1923                 if (lock_user_struct(VERIFY_READ, filter,
1924                                      tswapal(fprog->filter),  0)) {
1925                     int i;
1926                     for (i = 0; i < tswap16(fprog->len) - 1; i++) {
1927                         gemu_log("[%d]{0x%x,%d,%d,0x%x},",
1928                                  i, tswap16(filter[i].code),
1929                                  filter[i].jt, filter[i].jf,
1930                                  tswap32(filter[i].k));
1931                     }
1932                     gemu_log("[%d]{0x%x,%d,%d,0x%x}",
1933                              i, tswap16(filter[i].code),
1934                              filter[i].jt, filter[i].jf,
1935                              tswap32(filter[i].k));
1936                 } else {
1937                     gemu_log(TARGET_ABI_FMT_lx, tswapal(fprog->filter));
1938                 }
1939                 gemu_log(",%d},", tswap16(fprog->len));
1940                 unlock_user(fprog, optval, 0);
1941             } else {
1942                 print_pointer(optval, 0);
1943             }
1944             break;
1945         }
1946         default:
1947             print_raw_param(TARGET_ABI_FMT_ld, optname, 0);
1948             print_pointer(optval, 0);
1949             break;
1950         }
1951         break;
1952     default:
1953         print_raw_param(TARGET_ABI_FMT_ld, level, 0);
1954         print_raw_param(TARGET_ABI_FMT_ld, optname, 0);
1955         print_pointer(optval, 0);
1956         break;
1957     }
1958     print_raw_param(TARGET_ABI_FMT_ld, optlen, 1);
1959     gemu_log(")");
1960 }
1961
1962 #define PRINT_SOCKOP(name, func) \
1963     [TARGET_SYS_##name] = { #name, func }
1964
1965 static struct {
1966     const char *name;
1967     void (*print)(const char *, abi_long);
1968 } scall[] = {
1969     PRINT_SOCKOP(SOCKET, do_print_socket),
1970     PRINT_SOCKOP(BIND, do_print_sockaddr),
1971     PRINT_SOCKOP(CONNECT, do_print_sockaddr),
1972     PRINT_SOCKOP(LISTEN, do_print_listen),
1973     PRINT_SOCKOP(ACCEPT, do_print_sockaddr),
1974     PRINT_SOCKOP(GETSOCKNAME, do_print_sockaddr),
1975     PRINT_SOCKOP(GETPEERNAME, do_print_sockaddr),
1976     PRINT_SOCKOP(SOCKETPAIR, do_print_socketpair),
1977     PRINT_SOCKOP(SEND, do_print_sendrecv),
1978     PRINT_SOCKOP(RECV, do_print_sendrecv),
1979     PRINT_SOCKOP(SENDTO, do_print_msgaddr),
1980     PRINT_SOCKOP(RECVFROM, do_print_msgaddr),
1981     PRINT_SOCKOP(SHUTDOWN, do_print_shutdown),
1982     PRINT_SOCKOP(SETSOCKOPT, do_print_sockopt),
1983     PRINT_SOCKOP(GETSOCKOPT, do_print_sockopt),
1984     PRINT_SOCKOP(SENDMSG, do_print_msg),
1985     PRINT_SOCKOP(RECVMSG, do_print_msg),
1986     PRINT_SOCKOP(ACCEPT4, NULL),
1987     PRINT_SOCKOP(RECVMMSG, NULL),
1988     PRINT_SOCKOP(SENDMMSG, NULL),
1989 };
1990
1991 static void
1992 print_socketcall(const struct syscallname *name,
1993                  abi_long arg0, abi_long arg1, abi_long arg2,
1994                  abi_long arg3, abi_long arg4, abi_long arg5)
1995 {
1996     if (arg0 >= 0 && arg0 < ARRAY_SIZE(scall) && scall[arg0].print) {
1997         scall[arg0].print(scall[arg0].name, arg1);
1998         return;
1999     }
2000     print_syscall_prologue(name);
2001     print_raw_param(TARGET_ABI_FMT_ld, arg0, 0);
2002     print_raw_param(TARGET_ABI_FMT_ld, arg1, 0);
2003     print_raw_param(TARGET_ABI_FMT_ld, arg2, 0);
2004     print_raw_param(TARGET_ABI_FMT_ld, arg3, 0);
2005     print_raw_param(TARGET_ABI_FMT_ld, arg4, 0);
2006     print_raw_param(TARGET_ABI_FMT_ld, arg5, 0);
2007     print_syscall_epilogue(name);
2008 }
2009 #endif
2010
2011 #if defined(TARGET_NR_stat) || defined(TARGET_NR_stat64) || \
2012     defined(TARGET_NR_lstat) || defined(TARGET_NR_lstat64)
2013 static void
2014 print_stat(const struct syscallname *name,
2015     abi_long arg0, abi_long arg1, abi_long arg2,
2016     abi_long arg3, abi_long arg4, abi_long arg5)
2017 {
2018     print_syscall_prologue(name);
2019     print_string(arg0, 0);
2020     print_pointer(arg1, 1);
2021     print_syscall_epilogue(name);
2022 }
2023 #define print_lstat     print_stat
2024 #define print_stat64    print_stat
2025 #define print_lstat64   print_stat
2026 #endif
2027
2028 #if defined(TARGET_NR_fstat) || defined(TARGET_NR_fstat64)
2029 static void
2030 print_fstat(const struct syscallname *name,
2031     abi_long arg0, abi_long arg1, abi_long arg2,
2032     abi_long arg3, abi_long arg4, abi_long arg5)
2033 {
2034     print_syscall_prologue(name);
2035     print_raw_param("%d", arg0, 0);
2036     print_pointer(arg1, 1);
2037     print_syscall_epilogue(name);
2038 }
2039 #define print_fstat64     print_fstat
2040 #endif
2041
2042 #ifdef TARGET_NR_mkdir
2043 static void
2044 print_mkdir(const struct syscallname *name,
2045     abi_long arg0, abi_long arg1, abi_long arg2,
2046     abi_long arg3, abi_long arg4, abi_long arg5)
2047 {
2048     print_syscall_prologue(name);
2049     print_string(arg0, 0);
2050     print_file_mode(arg1, 1);
2051     print_syscall_epilogue(name);
2052 }
2053 #endif
2054
2055 #ifdef TARGET_NR_mkdirat
2056 static void
2057 print_mkdirat(const struct syscallname *name,
2058     abi_long arg0, abi_long arg1, abi_long arg2,
2059     abi_long arg3, abi_long arg4, abi_long arg5)
2060 {
2061     print_syscall_prologue(name);
2062     print_at_dirfd(arg0, 0);
2063     print_string(arg1, 0);
2064     print_file_mode(arg2, 1);
2065     print_syscall_epilogue(name);
2066 }
2067 #endif
2068
2069 #ifdef TARGET_NR_rmdir
2070 static void
2071 print_rmdir(const struct syscallname *name,
2072     abi_long arg0, abi_long arg1, abi_long arg2,
2073     abi_long arg3, abi_long arg4, abi_long arg5)
2074 {
2075     print_syscall_prologue(name);
2076     print_string(arg0, 0);
2077     print_syscall_epilogue(name);
2078 }
2079 #endif
2080
2081 #ifdef TARGET_NR_rt_sigaction
2082 static void
2083 print_rt_sigaction(const struct syscallname *name,
2084     abi_long arg0, abi_long arg1, abi_long arg2,
2085     abi_long arg3, abi_long arg4, abi_long arg5)
2086 {
2087     print_syscall_prologue(name);
2088     print_signal(arg0, 0);
2089     print_pointer(arg1, 0);
2090     print_pointer(arg2, 1);
2091     print_syscall_epilogue(name);
2092 }
2093 #endif
2094
2095 #ifdef TARGET_NR_rt_sigprocmask
2096 static void
2097 print_rt_sigprocmask(const struct syscallname *name,
2098     abi_long arg0, abi_long arg1, abi_long arg2,
2099     abi_long arg3, abi_long arg4, abi_long arg5)
2100 {
2101     const char *how = "UNKNOWN";
2102     print_syscall_prologue(name);
2103     switch(arg0) {
2104     case TARGET_SIG_BLOCK: how = "SIG_BLOCK"; break;
2105     case TARGET_SIG_UNBLOCK: how = "SIG_UNBLOCK"; break;
2106     case TARGET_SIG_SETMASK: how = "SIG_SETMASK"; break;
2107     }
2108     gemu_log("%s,",how);
2109     print_pointer(arg1, 0);
2110     print_pointer(arg2, 1);
2111     print_syscall_epilogue(name);
2112 }
2113 #endif
2114
2115 #ifdef TARGET_NR_rt_sigqueueinfo
2116 static void
2117 print_rt_sigqueueinfo(const struct syscallname *name,
2118     abi_long arg0, abi_long arg1, abi_long arg2,
2119     abi_long arg3, abi_long arg4, abi_long arg5)
2120 {
2121     void *p;
2122     target_siginfo_t uinfo;
2123
2124     print_syscall_prologue(name);
2125     print_raw_param("%d", arg0, 0);
2126     print_signal(arg1, 0);
2127     p = lock_user(VERIFY_READ, arg2, sizeof(target_siginfo_t), 1);
2128     if (p) {
2129         get_target_siginfo(&uinfo, p);
2130         print_siginfo(&uinfo);
2131
2132         unlock_user(p, arg2, 0);
2133     } else {
2134         print_pointer(arg2, 1);
2135     }
2136     print_syscall_epilogue(name);
2137 }
2138 #endif
2139
2140 #ifdef TARGET_NR_rt_tgsigqueueinfo
2141 static void
2142 print_rt_tgsigqueueinfo(const struct syscallname *name,
2143     abi_long arg0, abi_long arg1, abi_long arg2,
2144     abi_long arg3, abi_long arg4, abi_long arg5)
2145 {
2146     void *p;
2147     target_siginfo_t uinfo;
2148
2149     print_syscall_prologue(name);
2150     print_raw_param("%d", arg0, 0);
2151     print_raw_param("%d", arg1, 0);
2152     print_signal(arg2, 0);
2153     p = lock_user(VERIFY_READ, arg3, sizeof(target_siginfo_t), 1);
2154     if (p) {
2155         get_target_siginfo(&uinfo, p);
2156         print_siginfo(&uinfo);
2157
2158         unlock_user(p, arg3, 0);
2159     } else {
2160         print_pointer(arg3, 1);
2161     }
2162     print_syscall_epilogue(name);
2163 }
2164 #endif
2165
2166 #ifdef TARGET_NR_syslog
2167 static void
2168 print_syslog_action(abi_ulong arg, int last)
2169 {
2170     const char *type;
2171
2172     switch (arg) {
2173         case TARGET_SYSLOG_ACTION_CLOSE: {
2174             type = "SYSLOG_ACTION_CLOSE";
2175             break;
2176         }
2177         case TARGET_SYSLOG_ACTION_OPEN: {
2178             type = "SYSLOG_ACTION_OPEN";
2179             break;
2180         }
2181         case TARGET_SYSLOG_ACTION_READ: {
2182             type = "SYSLOG_ACTION_READ";
2183             break;
2184         }
2185         case TARGET_SYSLOG_ACTION_READ_ALL: {
2186             type = "SYSLOG_ACTION_READ_ALL";
2187             break;
2188         }
2189         case TARGET_SYSLOG_ACTION_READ_CLEAR: {
2190             type = "SYSLOG_ACTION_READ_CLEAR";
2191             break;
2192         }
2193         case TARGET_SYSLOG_ACTION_CLEAR: {
2194             type = "SYSLOG_ACTION_CLEAR";
2195             break;
2196         }
2197         case TARGET_SYSLOG_ACTION_CONSOLE_OFF: {
2198             type = "SYSLOG_ACTION_CONSOLE_OFF";
2199             break;
2200         }
2201         case TARGET_SYSLOG_ACTION_CONSOLE_ON: {
2202             type = "SYSLOG_ACTION_CONSOLE_ON";
2203             break;
2204         }
2205         case TARGET_SYSLOG_ACTION_CONSOLE_LEVEL: {
2206             type = "SYSLOG_ACTION_CONSOLE_LEVEL";
2207             break;
2208         }
2209         case TARGET_SYSLOG_ACTION_SIZE_UNREAD: {
2210             type = "SYSLOG_ACTION_SIZE_UNREAD";
2211             break;
2212         }
2213         case TARGET_SYSLOG_ACTION_SIZE_BUFFER: {
2214             type = "SYSLOG_ACTION_SIZE_BUFFER";
2215             break;
2216         }
2217         default: {
2218             print_raw_param("%ld", arg, last);
2219             return;
2220         }
2221     }
2222     gemu_log("%s%s", type, get_comma(last));
2223 }
2224
2225 static void
2226 print_syslog(const struct syscallname *name,
2227     abi_long arg0, abi_long arg1, abi_long arg2,
2228     abi_long arg3, abi_long arg4, abi_long arg5)
2229 {
2230     print_syscall_prologue(name);
2231     print_syslog_action(arg0, 0);
2232     print_pointer(arg1, 0);
2233     print_raw_param("%d", arg2, 1);
2234     print_syscall_epilogue(name);
2235 }
2236 #endif
2237
2238 #ifdef TARGET_NR_mknod
2239 static void
2240 print_mknod(const struct syscallname *name,
2241     abi_long arg0, abi_long arg1, abi_long arg2,
2242     abi_long arg3, abi_long arg4, abi_long arg5)
2243 {
2244     int hasdev = (arg1 & (S_IFCHR|S_IFBLK));
2245
2246     print_syscall_prologue(name);
2247     print_string(arg0, 0);
2248     print_file_mode(arg1, (hasdev == 0));
2249     if (hasdev) {
2250         print_raw_param("makedev(%d", major(arg2), 0);
2251         print_raw_param("%d)", minor(arg2), 1);
2252     }
2253     print_syscall_epilogue(name);
2254 }
2255 #endif
2256
2257 #ifdef TARGET_NR_mknodat
2258 static void
2259 print_mknodat(const struct syscallname *name,
2260     abi_long arg0, abi_long arg1, abi_long arg2,
2261     abi_long arg3, abi_long arg4, abi_long arg5)
2262 {
2263     int hasdev = (arg2 & (S_IFCHR|S_IFBLK));
2264
2265     print_syscall_prologue(name);
2266     print_at_dirfd(arg0, 0);
2267     print_string(arg1, 0);
2268     print_file_mode(arg2, (hasdev == 0));
2269     if (hasdev) {
2270         print_raw_param("makedev(%d", major(arg3), 0);
2271         print_raw_param("%d)", minor(arg3), 1);
2272     }
2273     print_syscall_epilogue(name);
2274 }
2275 #endif
2276
2277 #ifdef TARGET_NR_mq_open
2278 static void
2279 print_mq_open(const struct syscallname *name,
2280     abi_long arg0, abi_long arg1, abi_long arg2,
2281     abi_long arg3, abi_long arg4, abi_long arg5)
2282 {
2283     int is_creat = (arg1 & TARGET_O_CREAT);
2284
2285     print_syscall_prologue(name);
2286     print_string(arg0, 0);
2287     print_open_flags(arg1, (is_creat == 0));
2288     if (is_creat) {
2289         print_file_mode(arg2, 0);
2290         print_pointer(arg3, 1);
2291     }
2292     print_syscall_epilogue(name);
2293 }
2294 #endif
2295
2296 #ifdef TARGET_NR_open
2297 static void
2298 print_open(const struct syscallname *name,
2299     abi_long arg0, abi_long arg1, abi_long arg2,
2300     abi_long arg3, abi_long arg4, abi_long arg5)
2301 {
2302     int is_creat = (arg1 & TARGET_O_CREAT);
2303
2304     print_syscall_prologue(name);
2305     print_string(arg0, 0);
2306     print_open_flags(arg1, (is_creat == 0));
2307     if (is_creat)
2308         print_file_mode(arg2, 1);
2309     print_syscall_epilogue(name);
2310 }
2311 #endif
2312
2313 #ifdef TARGET_NR_openat
2314 static void
2315 print_openat(const struct syscallname *name,
2316     abi_long arg0, abi_long arg1, abi_long arg2,
2317     abi_long arg3, abi_long arg4, abi_long arg5)
2318 {
2319     int is_creat = (arg2 & TARGET_O_CREAT);
2320
2321     print_syscall_prologue(name);
2322     print_at_dirfd(arg0, 0);
2323     print_string(arg1, 0);
2324     print_open_flags(arg2, (is_creat == 0));
2325     if (is_creat)
2326         print_file_mode(arg3, 1);
2327     print_syscall_epilogue(name);
2328 }
2329 #endif
2330
2331 #ifdef TARGET_NR_mq_unlink
2332 static void
2333 print_mq_unlink(const struct syscallname *name,
2334     abi_long arg0, abi_long arg1, abi_long arg2,
2335     abi_long arg3, abi_long arg4, abi_long arg5)
2336 {
2337     print_syscall_prologue(name);
2338     print_string(arg0, 1);
2339     print_syscall_epilogue(name);
2340 }
2341 #endif
2342
2343 #if defined(TARGET_NR_fstatat64) || defined(TARGET_NR_newfstatat)
2344 static void
2345 print_fstatat64(const struct syscallname *name,
2346     abi_long arg0, abi_long arg1, abi_long arg2,
2347     abi_long arg3, abi_long arg4, abi_long arg5)
2348 {
2349     print_syscall_prologue(name);
2350     print_at_dirfd(arg0, 0);
2351     print_string(arg1, 0);
2352     print_pointer(arg2, 0);
2353     print_flags(at_file_flags, arg3, 1);
2354     print_syscall_epilogue(name);
2355 }
2356 #define print_newfstatat    print_fstatat64
2357 #endif
2358
2359 #ifdef TARGET_NR_readlink
2360 static void
2361 print_readlink(const struct syscallname *name,
2362     abi_long arg0, abi_long arg1, abi_long arg2,
2363     abi_long arg3, abi_long arg4, abi_long arg5)
2364 {
2365     print_syscall_prologue(name);
2366     print_string(arg0, 0);
2367     print_pointer(arg1, 0);
2368     print_raw_param("%u", arg2, 1);
2369     print_syscall_epilogue(name);
2370 }
2371 #endif
2372
2373 #ifdef TARGET_NR_readlinkat
2374 static void
2375 print_readlinkat(const struct syscallname *name,
2376     abi_long arg0, abi_long arg1, abi_long arg2,
2377     abi_long arg3, abi_long arg4, abi_long arg5)
2378 {
2379     print_syscall_prologue(name);
2380     print_at_dirfd(arg0, 0);
2381     print_string(arg1, 0);
2382     print_pointer(arg2, 0);
2383     print_raw_param("%u", arg3, 1);
2384     print_syscall_epilogue(name);
2385 }
2386 #endif
2387
2388 #ifdef TARGET_NR_rename
2389 static void
2390 print_rename(const struct syscallname *name,
2391     abi_long arg0, abi_long arg1, abi_long arg2,
2392     abi_long arg3, abi_long arg4, abi_long arg5)
2393 {
2394     print_syscall_prologue(name);
2395     print_string(arg0, 0);
2396     print_string(arg1, 1);
2397     print_syscall_epilogue(name);
2398 }
2399 #endif
2400
2401 #ifdef TARGET_NR_renameat
2402 static void
2403 print_renameat(const struct syscallname *name,
2404     abi_long arg0, abi_long arg1, abi_long arg2,
2405     abi_long arg3, abi_long arg4, abi_long arg5)
2406 {
2407     print_syscall_prologue(name);
2408     print_at_dirfd(arg0, 0);
2409     print_string(arg1, 0);
2410     print_at_dirfd(arg2, 0);
2411     print_string(arg3, 1);
2412     print_syscall_epilogue(name);
2413 }
2414 #endif
2415
2416 #ifdef TARGET_NR_statfs
2417 static void
2418 print_statfs(const struct syscallname *name,
2419     abi_long arg0, abi_long arg1, abi_long arg2,
2420     abi_long arg3, abi_long arg4, abi_long arg5)
2421 {
2422     print_syscall_prologue(name);
2423     print_string(arg0, 0);
2424     print_pointer(arg1, 1);
2425     print_syscall_epilogue(name);
2426 }
2427 #endif
2428
2429 #ifdef TARGET_NR_statfs64
2430 static void
2431 print_statfs64(const struct syscallname *name,
2432     abi_long arg0, abi_long arg1, abi_long arg2,
2433     abi_long arg3, abi_long arg4, abi_long arg5)
2434 {
2435     print_syscall_prologue(name);
2436     print_string(arg0, 0);
2437     print_pointer(arg1, 1);
2438     print_syscall_epilogue(name);
2439 }
2440 #endif
2441
2442 #ifdef TARGET_NR_symlink
2443 static void
2444 print_symlink(const struct syscallname *name,
2445     abi_long arg0, abi_long arg1, abi_long arg2,
2446     abi_long arg3, abi_long arg4, abi_long arg5)
2447 {
2448     print_syscall_prologue(name);
2449     print_string(arg0, 0);
2450     print_string(arg1, 1);
2451     print_syscall_epilogue(name);
2452 }
2453 #endif
2454
2455 #ifdef TARGET_NR_symlinkat
2456 static void
2457 print_symlinkat(const struct syscallname *name,
2458     abi_long arg0, abi_long arg1, abi_long arg2,
2459     abi_long arg3, abi_long arg4, abi_long arg5)
2460 {
2461     print_syscall_prologue(name);
2462     print_string(arg0, 0);
2463     print_at_dirfd(arg1, 0);
2464     print_string(arg2, 1);
2465     print_syscall_epilogue(name);
2466 }
2467 #endif
2468
2469 #ifdef TARGET_NR_mount
2470 static void
2471 print_mount(const struct syscallname *name,
2472     abi_long arg0, abi_long arg1, abi_long arg2,
2473     abi_long arg3, abi_long arg4, abi_long arg5)
2474 {
2475     print_syscall_prologue(name);
2476     print_string(arg0, 0);
2477     print_string(arg1, 0);
2478     print_string(arg2, 0);
2479     print_flags(mount_flags, arg3, 0);
2480     print_pointer(arg4, 1);
2481     print_syscall_epilogue(name);
2482 }
2483 #endif
2484
2485 #ifdef TARGET_NR_umount
2486 static void
2487 print_umount(const struct syscallname *name,
2488     abi_long arg0, abi_long arg1, abi_long arg2,
2489     abi_long arg3, abi_long arg4, abi_long arg5)
2490 {
2491     print_syscall_prologue(name);
2492     print_string(arg0, 1);
2493     print_syscall_epilogue(name);
2494 }
2495 #endif
2496
2497 #ifdef TARGET_NR_umount2
2498 static void
2499 print_umount2(const struct syscallname *name,
2500     abi_long arg0, abi_long arg1, abi_long arg2,
2501     abi_long arg3, abi_long arg4, abi_long arg5)
2502 {
2503     print_syscall_prologue(name);
2504     print_string(arg0, 0);
2505     print_flags(umount2_flags, arg1, 1);
2506     print_syscall_epilogue(name);
2507 }
2508 #endif
2509
2510 #ifdef TARGET_NR_unlink
2511 static void
2512 print_unlink(const struct syscallname *name,
2513     abi_long arg0, abi_long arg1, abi_long arg2,
2514     abi_long arg3, abi_long arg4, abi_long arg5)
2515 {
2516     print_syscall_prologue(name);
2517     print_string(arg0, 1);
2518     print_syscall_epilogue(name);
2519 }
2520 #endif
2521
2522 #ifdef TARGET_NR_unlinkat
2523 static void
2524 print_unlinkat(const struct syscallname *name,
2525     abi_long arg0, abi_long arg1, abi_long arg2,
2526     abi_long arg3, abi_long arg4, abi_long arg5)
2527 {
2528     print_syscall_prologue(name);
2529     print_at_dirfd(arg0, 0);
2530     print_string(arg1, 0);
2531     print_flags(unlinkat_flags, arg2, 1);
2532     print_syscall_epilogue(name);
2533 }
2534 #endif
2535
2536 #ifdef TARGET_NR_utime
2537 static void
2538 print_utime(const struct syscallname *name,
2539     abi_long arg0, abi_long arg1, abi_long arg2,
2540     abi_long arg3, abi_long arg4, abi_long arg5)
2541 {
2542     print_syscall_prologue(name);
2543     print_string(arg0, 0);
2544     print_pointer(arg1, 1);
2545     print_syscall_epilogue(name);
2546 }
2547 #endif
2548
2549 #ifdef TARGET_NR_utimes
2550 static void
2551 print_utimes(const struct syscallname *name,
2552     abi_long arg0, abi_long arg1, abi_long arg2,
2553     abi_long arg3, abi_long arg4, abi_long arg5)
2554 {
2555     print_syscall_prologue(name);
2556     print_string(arg0, 0);
2557     print_pointer(arg1, 1);
2558     print_syscall_epilogue(name);
2559 }
2560 #endif
2561
2562 #ifdef TARGET_NR_utimensat
2563 static void
2564 print_utimensat(const struct syscallname *name,
2565     abi_long arg0, abi_long arg1, abi_long arg2,
2566     abi_long arg3, abi_long arg4, abi_long arg5)
2567 {
2568     print_syscall_prologue(name);
2569     print_at_dirfd(arg0, 0);
2570     print_string(arg1, 0);
2571     print_pointer(arg2, 0);
2572     print_flags(at_file_flags, arg3, 1);
2573     print_syscall_epilogue(name);
2574 }
2575 #endif
2576
2577 #if defined(TARGET_NR_mmap) || defined(TARGET_NR_mmap2)
2578 static void
2579 print_mmap(const struct syscallname *name,
2580     abi_long arg0, abi_long arg1, abi_long arg2,
2581     abi_long arg3, abi_long arg4, abi_long arg5)
2582 {
2583     print_syscall_prologue(name);
2584     print_pointer(arg0, 0);
2585     print_raw_param("%d", arg1, 0);
2586     print_flags(mmap_prot_flags, arg2, 0);
2587     print_flags(mmap_flags, arg3, 0);
2588     print_raw_param("%d", arg4, 0);
2589     print_raw_param("%#x", arg5, 1);
2590     print_syscall_epilogue(name);
2591 }
2592 #define print_mmap2     print_mmap
2593 #endif
2594
2595 #ifdef TARGET_NR_mprotect
2596 static void
2597 print_mprotect(const struct syscallname *name,
2598     abi_long arg0, abi_long arg1, abi_long arg2,
2599     abi_long arg3, abi_long arg4, abi_long arg5)
2600 {
2601     print_syscall_prologue(name);
2602     print_pointer(arg0, 0);
2603     print_raw_param("%d", arg1, 0);
2604     print_flags(mmap_prot_flags, arg2, 1);
2605     print_syscall_epilogue(name);
2606 }
2607 #endif
2608
2609 #ifdef TARGET_NR_munmap
2610 static void
2611 print_munmap(const struct syscallname *name,
2612     abi_long arg0, abi_long arg1, abi_long arg2,
2613     abi_long arg3, abi_long arg4, abi_long arg5)
2614 {
2615     print_syscall_prologue(name);
2616     print_pointer(arg0, 0);
2617     print_raw_param("%d", arg1, 1);
2618     print_syscall_epilogue(name);
2619 }
2620 #endif
2621
2622 #ifdef TARGET_NR_futex
2623 static void print_futex_op(abi_long tflag, int last)
2624 {
2625 #define print_op(val) \
2626 if( cmd == val ) { \
2627     gemu_log(#val); \
2628     return; \
2629 }
2630
2631     int cmd = (int)tflag;
2632 #ifdef FUTEX_PRIVATE_FLAG
2633     if (cmd & FUTEX_PRIVATE_FLAG) {
2634         gemu_log("FUTEX_PRIVATE_FLAG|");
2635         cmd &= ~FUTEX_PRIVATE_FLAG;
2636     }
2637 #endif
2638 #ifdef FUTEX_CLOCK_REALTIME
2639     if (cmd & FUTEX_CLOCK_REALTIME) {
2640         gemu_log("FUTEX_CLOCK_REALTIME|");
2641         cmd &= ~FUTEX_CLOCK_REALTIME;
2642     }
2643 #endif
2644     print_op(FUTEX_WAIT)
2645     print_op(FUTEX_WAKE)
2646     print_op(FUTEX_FD)
2647     print_op(FUTEX_REQUEUE)
2648     print_op(FUTEX_CMP_REQUEUE)
2649     print_op(FUTEX_WAKE_OP)
2650     print_op(FUTEX_LOCK_PI)
2651     print_op(FUTEX_UNLOCK_PI)
2652     print_op(FUTEX_TRYLOCK_PI)
2653 #ifdef FUTEX_WAIT_BITSET
2654     print_op(FUTEX_WAIT_BITSET)
2655 #endif
2656 #ifdef FUTEX_WAKE_BITSET
2657     print_op(FUTEX_WAKE_BITSET)
2658 #endif
2659     /* unknown values */
2660     gemu_log("%d",cmd);
2661 }
2662
2663 static void
2664 print_futex(const struct syscallname *name,
2665     abi_long arg0, abi_long arg1, abi_long arg2,
2666     abi_long arg3, abi_long arg4, abi_long arg5)
2667 {
2668     print_syscall_prologue(name);
2669     print_pointer(arg0, 0);
2670     print_futex_op(arg1, 0);
2671     print_raw_param(",%d", arg2, 0);
2672     print_pointer(arg3, 0); /* struct timespec */
2673     print_pointer(arg4, 0);
2674     print_raw_param("%d", arg4, 1);
2675     print_syscall_epilogue(name);
2676 }
2677 #endif
2678
2679 #ifdef TARGET_NR_kill
2680 static void
2681 print_kill(const struct syscallname *name,
2682     abi_long arg0, abi_long arg1, abi_long arg2,
2683     abi_long arg3, abi_long arg4, abi_long arg5)
2684 {
2685     print_syscall_prologue(name);
2686     print_raw_param("%d", arg0, 0);
2687     print_signal(arg1, 1);
2688     print_syscall_epilogue(name);
2689 }
2690 #endif
2691
2692 #ifdef TARGET_NR_tkill
2693 static void
2694 print_tkill(const struct syscallname *name,
2695     abi_long arg0, abi_long arg1, abi_long arg2,
2696     abi_long arg3, abi_long arg4, abi_long arg5)
2697 {
2698     print_syscall_prologue(name);
2699     print_raw_param("%d", arg0, 0);
2700     print_signal(arg1, 1);
2701     print_syscall_epilogue(name);
2702 }
2703 #endif
2704
2705 #ifdef TARGET_NR_tgkill
2706 static void
2707 print_tgkill(const struct syscallname *name,
2708     abi_long arg0, abi_long arg1, abi_long arg2,
2709     abi_long arg3, abi_long arg4, abi_long arg5)
2710 {
2711     print_syscall_prologue(name);
2712     print_raw_param("%d", arg0, 0);
2713     print_raw_param("%d", arg1, 0);
2714     print_signal(arg2, 1);
2715     print_syscall_epilogue(name);
2716 }
2717 #endif
2718
2719 #ifdef TARGET_NR_statx
2720 static void
2721 print_statx(const struct syscallname *name,
2722             abi_long arg0, abi_long arg1, abi_long arg2,
2723             abi_long arg3, abi_long arg4, abi_long arg5)
2724 {
2725     print_syscall_prologue(name);
2726     print_at_dirfd(arg0, 0);
2727     print_string(arg1, 0);
2728     print_flags(statx_flags, arg2, 0);
2729     print_flags(statx_mask, arg3, 0);
2730     print_pointer(arg4, 1);
2731     print_syscall_epilogue(name);
2732 }
2733 #endif
2734
2735 /*
2736  * An array of all of the syscalls we know about
2737  */
2738
2739 static const struct syscallname scnames[] = {
2740 #include "strace.list"
2741 };
2742
2743 static int nsyscalls = ARRAY_SIZE(scnames);
2744
2745 /*
2746  * The public interface to this module.
2747  */
2748 void
2749 print_syscall(int num,
2750               abi_long arg1, abi_long arg2, abi_long arg3,
2751               abi_long arg4, abi_long arg5, abi_long arg6)
2752 {
2753     int i;
2754     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 ")";
2755
2756     gemu_log("%d ", getpid() );
2757
2758     for(i=0;i<nsyscalls;i++)
2759         if( scnames[i].nr == num ) {
2760             if( scnames[i].call != NULL ) {
2761                 scnames[i].call(&scnames[i],arg1,arg2,arg3,arg4,arg5,arg6);
2762             } else {
2763                 /* XXX: this format system is broken because it uses
2764                    host types and host pointers for strings */
2765                 if( scnames[i].format != NULL )
2766                     format = scnames[i].format;
2767                 gemu_log(format,scnames[i].name, arg1,arg2,arg3,arg4,arg5,arg6);
2768             }
2769             return;
2770         }
2771     gemu_log("Unknown syscall %d\n", num);
2772 }
2773
2774
2775 void
2776 print_syscall_ret(int num, abi_long ret)
2777 {
2778     int i;
2779     const char *errstr = NULL;
2780
2781     for(i=0;i<nsyscalls;i++)
2782         if( scnames[i].nr == num ) {
2783             if( scnames[i].result != NULL ) {
2784                 scnames[i].result(&scnames[i],ret);
2785             } else {
2786                 if (ret < 0) {
2787                     errstr = target_strerror(-ret);
2788                 }
2789                 if (errstr) {
2790                     gemu_log(" = -1 errno=" TARGET_ABI_FMT_ld " (%s)\n",
2791                              -ret, errstr);
2792                 } else {
2793                     gemu_log(" = " TARGET_ABI_FMT_ld "\n", ret);
2794                 }
2795             }
2796             break;
2797         }
2798 }
2799
2800 void print_taken_signal(int target_signum, const target_siginfo_t *tinfo)
2801 {
2802     /* Print the strace output for a signal being taken:
2803      * --- SIGSEGV {si_signo=SIGSEGV, si_code=SI_KERNEL, si_addr=0} ---
2804      */
2805     gemu_log("--- ");
2806     print_signal(target_signum, 1);
2807     gemu_log(" ");
2808     print_siginfo(tinfo);
2809     gemu_log(" ---\n");
2810 }
This page took 0.183582 seconds and 4 git commands to generate.