]> Git Repo - qemu.git/blob - linux-user/strace.c
linux-user: report signals being taken in strace output
[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_number(abi_long, int);
67 UNUSED static void print_signal(abi_ulong, int);
68 UNUSED static void print_sockaddr(abi_ulong addr, abi_long addrlen);
69 UNUSED static void print_socket_domain(int domain);
70 UNUSED static void print_socket_type(int type);
71 UNUSED static void print_socket_protocol(int domain, int type, int protocol);
72
73 /*
74  * Utility functions
75  */
76 static void
77 print_ipc_cmd(int cmd)
78 {
79 #define output_cmd(val) \
80 if( cmd == val ) { \
81     gemu_log(#val); \
82     return; \
83 }
84
85     cmd &= 0xff;
86
87     /* General IPC commands */
88     output_cmd( IPC_RMID );
89     output_cmd( IPC_SET );
90     output_cmd( IPC_STAT );
91     output_cmd( IPC_INFO );
92     /* msgctl() commands */
93     #ifdef __USER_MISC
94     output_cmd( MSG_STAT );
95     output_cmd( MSG_INFO );
96     #endif
97     /* shmctl() commands */
98     output_cmd( SHM_LOCK );
99     output_cmd( SHM_UNLOCK );
100     output_cmd( SHM_STAT );
101     output_cmd( SHM_INFO );
102     /* semctl() commands */
103     output_cmd( GETPID );
104     output_cmd( GETVAL );
105     output_cmd( GETALL );
106     output_cmd( GETNCNT );
107     output_cmd( GETZCNT );
108     output_cmd( SETVAL );
109     output_cmd( SETALL );
110     output_cmd( SEM_STAT );
111     output_cmd( SEM_INFO );
112     output_cmd( IPC_RMID );
113     output_cmd( IPC_RMID );
114     output_cmd( IPC_RMID );
115     output_cmd( IPC_RMID );
116     output_cmd( IPC_RMID );
117     output_cmd( IPC_RMID );
118     output_cmd( IPC_RMID );
119     output_cmd( IPC_RMID );
120     output_cmd( IPC_RMID );
121
122     /* Some value we don't recognize */
123     gemu_log("%d",cmd);
124 }
125
126 static void
127 print_signal(abi_ulong arg, int last)
128 {
129     const char *signal_name = NULL;
130     switch(arg) {
131     case TARGET_SIGHUP: signal_name = "SIGHUP"; break;
132     case TARGET_SIGINT: signal_name = "SIGINT"; break;
133     case TARGET_SIGQUIT: signal_name = "SIGQUIT"; break;
134     case TARGET_SIGILL: signal_name = "SIGILL"; break;
135     case TARGET_SIGABRT: signal_name = "SIGABRT"; break;
136     case TARGET_SIGFPE: signal_name = "SIGFPE"; break;
137     case TARGET_SIGKILL: signal_name = "SIGKILL"; break;
138     case TARGET_SIGSEGV: signal_name = "SIGSEGV"; break;
139     case TARGET_SIGPIPE: signal_name = "SIGPIPE"; break;
140     case TARGET_SIGALRM: signal_name = "SIGALRM"; break;
141     case TARGET_SIGTERM: signal_name = "SIGTERM"; break;
142     case TARGET_SIGUSR1: signal_name = "SIGUSR1"; break;
143     case TARGET_SIGUSR2: signal_name = "SIGUSR2"; break;
144     case TARGET_SIGCHLD: signal_name = "SIGCHLD"; break;
145     case TARGET_SIGCONT: signal_name = "SIGCONT"; break;
146     case TARGET_SIGSTOP: signal_name = "SIGSTOP"; break;
147     case TARGET_SIGTTIN: signal_name = "SIGTTIN"; break;
148     case TARGET_SIGTTOU: signal_name = "SIGTTOU"; break;
149     }
150     if (signal_name == NULL) {
151         print_raw_param("%ld", arg, last);
152         return;
153     }
154     gemu_log("%s%s", signal_name, get_comma(last));
155 }
156
157 static void print_si_code(int arg)
158 {
159     const char *codename = NULL;
160
161     switch (arg) {
162     case SI_USER:
163         codename = "SI_USER";
164         break;
165     case SI_KERNEL:
166         codename = "SI_KERNEL";
167         break;
168     case SI_QUEUE:
169         codename = "SI_QUEUE";
170         break;
171     case SI_TIMER:
172         codename = "SI_TIMER";
173         break;
174     case SI_MESGQ:
175         codename = "SI_MESGQ";
176         break;
177     case SI_ASYNCIO:
178         codename = "SI_ASYNCIO";
179         break;
180     case SI_SIGIO:
181         codename = "SI_SIGIO";
182         break;
183     case SI_TKILL:
184         codename = "SI_TKILL";
185         break;
186     default:
187         gemu_log("%d", arg);
188         return;
189     }
190     gemu_log("%s", codename);
191 }
192
193 static void print_siginfo(const target_siginfo_t *tinfo)
194 {
195     /* Print a target_siginfo_t in the format desired for printing
196      * signals being taken. We assume the target_siginfo_t is in the
197      * internal form where the top 16 bits of si_code indicate which
198      * part of the union is valid, rather than in the guest-visible
199      * form where the bottom 16 bits are sign-extended into the top 16.
200      */
201     int si_type = extract32(tinfo->si_code, 16, 16);
202     int si_code = sextract32(tinfo->si_code, 0, 16);
203
204     gemu_log("{si_signo=");
205     print_signal(tinfo->si_signo, 1);
206     gemu_log(", si_code=");
207     print_si_code(si_code);
208
209     switch (si_type) {
210     case QEMU_SI_KILL:
211         gemu_log(", si_pid = %u, si_uid = %u",
212                  (unsigned int)tinfo->_sifields._kill._pid,
213                  (unsigned int)tinfo->_sifields._kill._uid);
214         break;
215     case QEMU_SI_TIMER:
216         gemu_log(", si_timer1 = %u, si_timer2 = %u",
217                  tinfo->_sifields._timer._timer1,
218                  tinfo->_sifields._timer._timer2);
219         break;
220     case QEMU_SI_POLL:
221         gemu_log(", si_band = %d, si_fd = %d",
222                  tinfo->_sifields._sigpoll._band,
223                  tinfo->_sifields._sigpoll._fd);
224         break;
225     case QEMU_SI_FAULT:
226         gemu_log(", si_addr = ");
227         print_pointer(tinfo->_sifields._sigfault._addr, 1);
228         break;
229     case QEMU_SI_CHLD:
230         gemu_log(", si_pid = %u, si_uid = %u, si_status = %d"
231                  ", si_utime=" TARGET_ABI_FMT_ld
232                  ", si_stime=" TARGET_ABI_FMT_ld,
233                  (unsigned int)(tinfo->_sifields._sigchld._pid),
234                  (unsigned int)(tinfo->_sifields._sigchld._uid),
235                  tinfo->_sifields._sigchld._status,
236                  tinfo->_sifields._sigchld._utime,
237                  tinfo->_sifields._sigchld._stime);
238         break;
239     case QEMU_SI_RT:
240         gemu_log(", si_pid = %u, si_uid = %u, si_sigval = " TARGET_ABI_FMT_ld,
241                  (unsigned int)tinfo->_sifields._rt._pid,
242                  (unsigned int)tinfo->_sifields._rt._uid,
243                  tinfo->_sifields._rt._sigval.sival_ptr);
244         break;
245     default:
246         g_assert_not_reached();
247     }
248     gemu_log("}");
249 }
250
251 static void
252 print_sockaddr(abi_ulong addr, abi_long addrlen)
253 {
254     struct target_sockaddr *sa;
255     int i;
256     int sa_family;
257
258     sa = lock_user(VERIFY_READ, addr, addrlen, 1);
259     if (sa) {
260         sa_family = tswap16(sa->sa_family);
261         switch (sa_family) {
262         case AF_UNIX: {
263             struct target_sockaddr_un *un = (struct target_sockaddr_un *)sa;
264             int i;
265             gemu_log("{sun_family=AF_UNIX,sun_path=\"");
266             for (i = 0; i < addrlen -
267                             offsetof(struct target_sockaddr_un, sun_path) &&
268                  un->sun_path[i]; i++) {
269                 gemu_log("%c", un->sun_path[i]);
270             }
271             gemu_log("\"}");
272             break;
273         }
274         case AF_INET: {
275             struct target_sockaddr_in *in = (struct target_sockaddr_in *)sa;
276             uint8_t *c = (uint8_t *)&in->sin_addr.s_addr;
277             gemu_log("{sin_family=AF_INET,sin_port=htons(%d),",
278                      ntohs(in->sin_port));
279             gemu_log("sin_addr=inet_addr(\"%d.%d.%d.%d\")",
280                      c[0], c[1], c[2], c[3]);
281             gemu_log("}");
282             break;
283         }
284         case AF_PACKET: {
285             struct target_sockaddr_ll *ll = (struct target_sockaddr_ll *)sa;
286             uint8_t *c = (uint8_t *)&ll->sll_addr;
287             gemu_log("{sll_family=AF_PACKET,"
288                      "sll_protocol=htons(0x%04x),if%d,pkttype=",
289                      ntohs(ll->sll_protocol), ll->sll_ifindex);
290             switch (ll->sll_pkttype) {
291             case PACKET_HOST:
292                 gemu_log("PACKET_HOST");
293                 break;
294             case PACKET_BROADCAST:
295                 gemu_log("PACKET_BROADCAST");
296                 break;
297             case PACKET_MULTICAST:
298                 gemu_log("PACKET_MULTICAST");
299                 break;
300             case PACKET_OTHERHOST:
301                 gemu_log("PACKET_OTHERHOST");
302                 break;
303             case PACKET_OUTGOING:
304                 gemu_log("PACKET_OUTGOING");
305                 break;
306             default:
307                 gemu_log("%d", ll->sll_pkttype);
308                 break;
309             }
310             gemu_log(",sll_addr=%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x",
311                      c[0], c[1], c[2], c[3], c[4], c[5], c[6], c[7]);
312             gemu_log("}");
313             break;
314         }
315         default:
316             gemu_log("{sa_family=%d, sa_data={", sa->sa_family);
317             for (i = 0; i < 13; i++) {
318                 gemu_log("%02x, ", sa->sa_data[i]);
319             }
320             gemu_log("%02x}", sa->sa_data[i]);
321             gemu_log("}");
322             break;
323         }
324         unlock_user(sa, addr, 0);
325     } else {
326         print_raw_param("0x"TARGET_ABI_FMT_lx, addr, 0);
327     }
328     gemu_log(", "TARGET_ABI_FMT_ld, addrlen);
329 }
330
331 static void
332 print_socket_domain(int domain)
333 {
334     switch (domain) {
335     case PF_UNIX:
336         gemu_log("PF_UNIX");
337         break;
338     case PF_INET:
339         gemu_log("PF_INET");
340         break;
341     case PF_PACKET:
342         gemu_log("PF_PACKET");
343         break;
344     default:
345         gemu_log("%d", domain);
346         break;
347     }
348 }
349
350 static void
351 print_socket_type(int type)
352 {
353     switch (type) {
354     case TARGET_SOCK_DGRAM:
355         gemu_log("SOCK_DGRAM");
356         break;
357     case TARGET_SOCK_STREAM:
358         gemu_log("SOCK_STREAM");
359         break;
360     case TARGET_SOCK_RAW:
361         gemu_log("SOCK_RAW");
362         break;
363     case TARGET_SOCK_RDM:
364         gemu_log("SOCK_RDM");
365         break;
366     case TARGET_SOCK_SEQPACKET:
367         gemu_log("SOCK_SEQPACKET");
368         break;
369     case TARGET_SOCK_PACKET:
370         gemu_log("SOCK_PACKET");
371         break;
372     }
373 }
374
375 static void
376 print_socket_protocol(int domain, int type, int protocol)
377 {
378     if (domain == AF_PACKET ||
379         (domain == AF_INET && type == TARGET_SOCK_PACKET)) {
380         switch (protocol) {
381         case 0x0003:
382             gemu_log("ETH_P_ALL");
383             break;
384         default:
385             gemu_log("%d", protocol);
386         }
387         return;
388     }
389
390     switch (protocol) {
391     case IPPROTO_IP:
392         gemu_log("IPPROTO_IP");
393         break;
394     case IPPROTO_TCP:
395         gemu_log("IPPROTO_TCP");
396         break;
397     case IPPROTO_UDP:
398         gemu_log("IPPROTO_UDP");
399         break;
400     case IPPROTO_RAW:
401         gemu_log("IPPROTO_RAW");
402         break;
403     default:
404         gemu_log("%d", protocol);
405         break;
406     }
407 }
408
409
410 #ifdef TARGET_NR__newselect
411 static void
412 print_fdset(int n, abi_ulong target_fds_addr)
413 {
414     int i;
415
416     gemu_log("[");
417     if( target_fds_addr ) {
418         abi_long *target_fds;
419
420         target_fds = lock_user(VERIFY_READ,
421                                target_fds_addr,
422                                sizeof(*target_fds)*(n / TARGET_ABI_BITS + 1),
423                                1);
424
425         if (!target_fds)
426             return;
427
428         for (i=n; i>=0; i--) {
429             if ((tswapal(target_fds[i / TARGET_ABI_BITS]) >> (i & (TARGET_ABI_BITS - 1))) & 1)
430                 gemu_log("%d,", i );
431             }
432         unlock_user(target_fds, target_fds_addr, 0);
433     }
434     gemu_log("]");
435 }
436 #endif
437
438 /*
439  * Sysycall specific output functions
440  */
441
442 /* select */
443 #ifdef TARGET_NR__newselect
444 static long newselect_arg1 = 0;
445 static long newselect_arg2 = 0;
446 static long newselect_arg3 = 0;
447 static long newselect_arg4 = 0;
448 static long newselect_arg5 = 0;
449
450 static void
451 print_newselect(const struct syscallname *name,
452                 abi_long arg1, abi_long arg2, abi_long arg3,
453                 abi_long arg4, abi_long arg5, abi_long arg6)
454 {
455     gemu_log("%s(" TARGET_ABI_FMT_ld ",", name->name, arg1);
456     print_fdset(arg1, arg2);
457     gemu_log(",");
458     print_fdset(arg1, arg3);
459     gemu_log(",");
460     print_fdset(arg1, arg4);
461     gemu_log(",");
462     print_timeval(arg5, 1);
463     gemu_log(")");
464
465     /* save for use in the return output function below */
466     newselect_arg1=arg1;
467     newselect_arg2=arg2;
468     newselect_arg3=arg3;
469     newselect_arg4=arg4;
470     newselect_arg5=arg5;
471 }
472 #endif
473
474 #ifdef TARGET_NR_semctl
475 static void
476 print_semctl(const struct syscallname *name,
477              abi_long arg1, abi_long arg2, abi_long arg3,
478              abi_long arg4, abi_long arg5, abi_long arg6)
479 {
480     gemu_log("%s(" TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld ",", name->name, arg1, arg2);
481     print_ipc_cmd(arg3);
482     gemu_log(",0x" TARGET_ABI_FMT_lx ")", arg4);
483 }
484 #endif
485
486 static void
487 print_execve(const struct syscallname *name,
488              abi_long arg1, abi_long arg2, abi_long arg3,
489              abi_long arg4, abi_long arg5, abi_long arg6)
490 {
491     abi_ulong arg_ptr_addr;
492     char *s;
493
494     if (!(s = lock_user_string(arg1)))
495         return;
496     gemu_log("%s(\"%s\",{", name->name, s);
497     unlock_user(s, arg1, 0);
498
499     for (arg_ptr_addr = arg2; ; arg_ptr_addr += sizeof(abi_ulong)) {
500         abi_ulong *arg_ptr, arg_addr;
501
502         arg_ptr = lock_user(VERIFY_READ, arg_ptr_addr, sizeof(abi_ulong), 1);
503         if (!arg_ptr)
504             return;
505     arg_addr = tswapal(*arg_ptr);
506         unlock_user(arg_ptr, arg_ptr_addr, 0);
507         if (!arg_addr)
508             break;
509         if ((s = lock_user_string(arg_addr))) {
510             gemu_log("\"%s\",", s);
511             unlock_user(s, arg_addr, 0);
512         }
513     }
514
515     gemu_log("NULL})");
516 }
517
518 #ifdef TARGET_NR_ipc
519 static void
520 print_ipc(const struct syscallname *name,
521           abi_long arg1, abi_long arg2, abi_long arg3,
522           abi_long arg4, abi_long arg5, abi_long arg6)
523 {
524     switch(arg1) {
525     case IPCOP_semctl:
526         gemu_log("semctl(" TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld ",", arg1, arg2);
527         print_ipc_cmd(arg3);
528         gemu_log(",0x" TARGET_ABI_FMT_lx ")", arg4);
529         break;
530     default:
531         gemu_log("%s(" TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld ")",
532                  name->name, arg1, arg2, arg3, arg4);
533     }
534 }
535 #endif
536
537 /*
538  * Variants for the return value output function
539  */
540
541 static void
542 print_syscall_ret_addr(const struct syscallname *name, abi_long ret)
543 {
544     const char *errstr = NULL;
545
546     if (ret < 0) {
547         errstr = target_strerror(-ret);
548     }
549     if (errstr) {
550         gemu_log(" = -1 errno=%d (%s)\n", (int)-ret, errstr);
551     } else {
552         gemu_log(" = 0x" TARGET_ABI_FMT_lx "\n", ret);
553     }
554 }
555
556 #if 0 /* currently unused */
557 static void
558 print_syscall_ret_raw(struct syscallname *name, abi_long ret)
559 {
560         gemu_log(" = 0x" TARGET_ABI_FMT_lx "\n", ret);
561 }
562 #endif
563
564 #ifdef TARGET_NR__newselect
565 static void
566 print_syscall_ret_newselect(const struct syscallname *name, abi_long ret)
567 {
568     gemu_log(" = 0x" TARGET_ABI_FMT_lx " (", ret);
569     print_fdset(newselect_arg1,newselect_arg2);
570     gemu_log(",");
571     print_fdset(newselect_arg1,newselect_arg3);
572     gemu_log(",");
573     print_fdset(newselect_arg1,newselect_arg4);
574     gemu_log(",");
575     print_timeval(newselect_arg5, 1);
576     gemu_log(")\n");
577 }
578 #endif
579
580 UNUSED static struct flags access_flags[] = {
581     FLAG_GENERIC(F_OK),
582     FLAG_GENERIC(R_OK),
583     FLAG_GENERIC(W_OK),
584     FLAG_GENERIC(X_OK),
585     FLAG_END,
586 };
587
588 UNUSED static struct flags at_file_flags[] = {
589 #ifdef AT_EACCESS
590     FLAG_GENERIC(AT_EACCESS),
591 #endif
592 #ifdef AT_SYMLINK_NOFOLLOW
593     FLAG_GENERIC(AT_SYMLINK_NOFOLLOW),
594 #endif
595     FLAG_END,
596 };
597
598 UNUSED static struct flags unlinkat_flags[] = {
599 #ifdef AT_REMOVEDIR
600     FLAG_GENERIC(AT_REMOVEDIR),
601 #endif
602     FLAG_END,
603 };
604
605 UNUSED static struct flags mode_flags[] = {
606     FLAG_GENERIC(S_IFSOCK),
607     FLAG_GENERIC(S_IFLNK),
608     FLAG_GENERIC(S_IFREG),
609     FLAG_GENERIC(S_IFBLK),
610     FLAG_GENERIC(S_IFDIR),
611     FLAG_GENERIC(S_IFCHR),
612     FLAG_GENERIC(S_IFIFO),
613     FLAG_END,
614 };
615
616 UNUSED static struct flags open_access_flags[] = {
617     FLAG_TARGET(O_RDONLY),
618     FLAG_TARGET(O_WRONLY),
619     FLAG_TARGET(O_RDWR),
620     FLAG_END,
621 };
622
623 UNUSED static struct flags open_flags[] = {
624     FLAG_TARGET(O_APPEND),
625     FLAG_TARGET(O_CREAT),
626     FLAG_TARGET(O_DIRECTORY),
627     FLAG_TARGET(O_EXCL),
628     FLAG_TARGET(O_LARGEFILE),
629     FLAG_TARGET(O_NOCTTY),
630     FLAG_TARGET(O_NOFOLLOW),
631     FLAG_TARGET(O_NONBLOCK),      /* also O_NDELAY */
632     FLAG_TARGET(O_DSYNC),
633     FLAG_TARGET(__O_SYNC),
634     FLAG_TARGET(O_TRUNC),
635 #ifdef O_DIRECT
636     FLAG_TARGET(O_DIRECT),
637 #endif
638 #ifdef O_NOATIME
639     FLAG_TARGET(O_NOATIME),
640 #endif
641 #ifdef O_CLOEXEC
642     FLAG_TARGET(O_CLOEXEC),
643 #endif
644 #ifdef O_PATH
645     FLAG_TARGET(O_PATH),
646 #endif
647     FLAG_END,
648 };
649
650 UNUSED static struct flags mount_flags[] = {
651 #ifdef MS_BIND
652     FLAG_GENERIC(MS_BIND),
653 #endif
654 #ifdef MS_DIRSYNC
655     FLAG_GENERIC(MS_DIRSYNC),
656 #endif
657     FLAG_GENERIC(MS_MANDLOCK),
658 #ifdef MS_MOVE
659     FLAG_GENERIC(MS_MOVE),
660 #endif
661     FLAG_GENERIC(MS_NOATIME),
662     FLAG_GENERIC(MS_NODEV),
663     FLAG_GENERIC(MS_NODIRATIME),
664     FLAG_GENERIC(MS_NOEXEC),
665     FLAG_GENERIC(MS_NOSUID),
666     FLAG_GENERIC(MS_RDONLY),
667 #ifdef MS_RELATIME
668     FLAG_GENERIC(MS_RELATIME),
669 #endif
670     FLAG_GENERIC(MS_REMOUNT),
671     FLAG_GENERIC(MS_SYNCHRONOUS),
672     FLAG_END,
673 };
674
675 UNUSED static struct flags umount2_flags[] = {
676 #ifdef MNT_FORCE
677     FLAG_GENERIC(MNT_FORCE),
678 #endif
679 #ifdef MNT_DETACH
680     FLAG_GENERIC(MNT_DETACH),
681 #endif
682 #ifdef MNT_EXPIRE
683     FLAG_GENERIC(MNT_EXPIRE),
684 #endif
685     FLAG_END,
686 };
687
688 UNUSED static struct flags mmap_prot_flags[] = {
689     FLAG_GENERIC(PROT_NONE),
690     FLAG_GENERIC(PROT_EXEC),
691     FLAG_GENERIC(PROT_READ),
692     FLAG_GENERIC(PROT_WRITE),
693     FLAG_TARGET(PROT_SEM),
694     FLAG_GENERIC(PROT_GROWSDOWN),
695     FLAG_GENERIC(PROT_GROWSUP),
696     FLAG_END,
697 };
698
699 UNUSED static struct flags mmap_flags[] = {
700     FLAG_TARGET(MAP_SHARED),
701     FLAG_TARGET(MAP_PRIVATE),
702     FLAG_TARGET(MAP_ANONYMOUS),
703     FLAG_TARGET(MAP_DENYWRITE),
704     FLAG_TARGET(MAP_FIXED),
705     FLAG_TARGET(MAP_GROWSDOWN),
706     FLAG_TARGET(MAP_EXECUTABLE),
707 #ifdef MAP_LOCKED
708     FLAG_TARGET(MAP_LOCKED),
709 #endif
710 #ifdef MAP_NONBLOCK
711     FLAG_TARGET(MAP_NONBLOCK),
712 #endif
713     FLAG_TARGET(MAP_NORESERVE),
714 #ifdef MAP_POPULATE
715     FLAG_TARGET(MAP_POPULATE),
716 #endif
717 #ifdef TARGET_MAP_UNINITIALIZED
718     FLAG_TARGET(MAP_UNINITIALIZED),
719 #endif
720     FLAG_END,
721 };
722
723 UNUSED static struct flags clone_flags[] = {
724     FLAG_GENERIC(CLONE_VM),
725     FLAG_GENERIC(CLONE_FS),
726     FLAG_GENERIC(CLONE_FILES),
727     FLAG_GENERIC(CLONE_SIGHAND),
728     FLAG_GENERIC(CLONE_PTRACE),
729     FLAG_GENERIC(CLONE_VFORK),
730     FLAG_GENERIC(CLONE_PARENT),
731     FLAG_GENERIC(CLONE_THREAD),
732     FLAG_GENERIC(CLONE_NEWNS),
733     FLAG_GENERIC(CLONE_SYSVSEM),
734     FLAG_GENERIC(CLONE_SETTLS),
735     FLAG_GENERIC(CLONE_PARENT_SETTID),
736     FLAG_GENERIC(CLONE_CHILD_CLEARTID),
737     FLAG_GENERIC(CLONE_DETACHED),
738     FLAG_GENERIC(CLONE_UNTRACED),
739     FLAG_GENERIC(CLONE_CHILD_SETTID),
740 #if defined(CLONE_NEWUTS)
741     FLAG_GENERIC(CLONE_NEWUTS),
742 #endif
743 #if defined(CLONE_NEWIPC)
744     FLAG_GENERIC(CLONE_NEWIPC),
745 #endif
746 #if defined(CLONE_NEWUSER)
747     FLAG_GENERIC(CLONE_NEWUSER),
748 #endif
749 #if defined(CLONE_NEWPID)
750     FLAG_GENERIC(CLONE_NEWPID),
751 #endif
752 #if defined(CLONE_NEWNET)
753     FLAG_GENERIC(CLONE_NEWNET),
754 #endif
755 #if defined(CLONE_IO)
756     FLAG_GENERIC(CLONE_IO),
757 #endif
758     FLAG_END,
759 };
760
761 UNUSED static struct flags msg_flags[] = {
762     /* send */
763     FLAG_GENERIC(MSG_CONFIRM),
764     FLAG_GENERIC(MSG_DONTROUTE),
765     FLAG_GENERIC(MSG_DONTWAIT),
766     FLAG_GENERIC(MSG_EOR),
767     FLAG_GENERIC(MSG_MORE),
768     FLAG_GENERIC(MSG_NOSIGNAL),
769     FLAG_GENERIC(MSG_OOB),
770     /* recv */
771     FLAG_GENERIC(MSG_CMSG_CLOEXEC),
772     FLAG_GENERIC(MSG_ERRQUEUE),
773     FLAG_GENERIC(MSG_PEEK),
774     FLAG_GENERIC(MSG_TRUNC),
775     FLAG_GENERIC(MSG_WAITALL),
776     /* recvmsg */
777     FLAG_GENERIC(MSG_CTRUNC),
778     FLAG_END,
779 };
780
781 /*
782  * print_xxx utility functions.  These are used to print syscall
783  * parameters in certain format.  All of these have parameter
784  * named 'last'.  This parameter is used to add comma to output
785  * when last == 0.
786  */
787
788 static const char *
789 get_comma(int last)
790 {
791     return ((last) ? "" : ",");
792 }
793
794 static void
795 print_flags(const struct flags *f, abi_long flags, int last)
796 {
797     const char *sep = "";
798     int n;
799
800     if ((flags == 0) && (f->f_value == 0)) {
801         gemu_log("%s%s", f->f_string, get_comma(last));
802         return;
803     }
804     for (n = 0; f->f_string != NULL; f++) {
805         if ((f->f_value != 0) && ((flags & f->f_value) == f->f_value)) {
806             gemu_log("%s%s", sep, f->f_string);
807             flags &= ~f->f_value;
808             sep = "|";
809             n++;
810         }
811     }
812
813     if (n > 0) {
814         /* print rest of the flags as numeric */
815         if (flags != 0) {
816             gemu_log("%s%#x%s", sep, (unsigned int)flags, get_comma(last));
817         } else {
818             gemu_log("%s", get_comma(last));
819         }
820     } else {
821         /* no string version of flags found, print them in hex then */
822         gemu_log("%#x%s", (unsigned int)flags, get_comma(last));
823     }
824 }
825
826 static void
827 print_at_dirfd(abi_long dirfd, int last)
828 {
829 #ifdef AT_FDCWD
830     if (dirfd == AT_FDCWD) {
831         gemu_log("AT_FDCWD%s", get_comma(last));
832         return;
833     }
834 #endif
835     gemu_log("%d%s", (int)dirfd, get_comma(last));
836 }
837
838 static void
839 print_file_mode(abi_long mode, int last)
840 {
841     const char *sep = "";
842     const struct flags *m;
843
844     for (m = &mode_flags[0]; m->f_string != NULL; m++) {
845         if ((m->f_value & mode) == m->f_value) {
846             gemu_log("%s%s", m->f_string, sep);
847             sep = "|";
848             mode &= ~m->f_value;
849             break;
850         }
851     }
852
853     mode &= ~S_IFMT;
854     /* print rest of the mode as octal */
855     if (mode != 0)
856         gemu_log("%s%#o", sep, (unsigned int)mode);
857
858     gemu_log("%s", get_comma(last));
859 }
860
861 static void
862 print_open_flags(abi_long flags, int last)
863 {
864     print_flags(open_access_flags, flags & TARGET_O_ACCMODE, 1);
865     flags &= ~TARGET_O_ACCMODE;
866     if (flags == 0) {
867         gemu_log("%s", get_comma(last));
868         return;
869     }
870     gemu_log("|");
871     print_flags(open_flags, flags, last);
872 }
873
874 static void
875 print_syscall_prologue(const struct syscallname *sc)
876 {
877     gemu_log("%s(", sc->name);
878 }
879
880 /*ARGSUSED*/
881 static void
882 print_syscall_epilogue(const struct syscallname *sc)
883 {
884     (void)sc;
885     gemu_log(")");
886 }
887
888 static void
889 print_string(abi_long addr, int last)
890 {
891     char *s;
892
893     if ((s = lock_user_string(addr)) != NULL) {
894         gemu_log("\"%s\"%s", s, get_comma(last));
895         unlock_user(s, addr, 0);
896     } else {
897         /* can't get string out of it, so print it as pointer */
898         print_pointer(addr, last);
899     }
900 }
901
902 #define MAX_PRINT_BUF 40
903 static void
904 print_buf(abi_long addr, abi_long len, int last)
905 {
906     uint8_t *s;
907     int i;
908
909     s = lock_user(VERIFY_READ, addr, len, 1);
910     if (s) {
911         gemu_log("\"");
912         for (i = 0; i < MAX_PRINT_BUF && i < len; i++) {
913             if (isprint(s[i])) {
914                 gemu_log("%c", s[i]);
915             } else {
916                 gemu_log("\\%o", s[i]);
917             }
918         }
919         gemu_log("\"");
920         if (i != len) {
921             gemu_log("...");
922         }
923         if (!last) {
924             gemu_log(",");
925         }
926         unlock_user(s, addr, 0);
927     } else {
928         print_pointer(addr, last);
929     }
930 }
931
932 /*
933  * Prints out raw parameter using given format.  Caller needs
934  * to do byte swapping if needed.
935  */
936 static void
937 print_raw_param(const char *fmt, abi_long param, int last)
938 {
939     char format[64];
940
941     (void) snprintf(format, sizeof (format), "%s%s", fmt, get_comma(last));
942     gemu_log(format, param);
943 }
944
945 static void
946 print_pointer(abi_long p, int last)
947 {
948     if (p == 0)
949         gemu_log("NULL%s", get_comma(last));
950     else
951         gemu_log("0x" TARGET_ABI_FMT_lx "%s", p, get_comma(last));
952 }
953
954 /*
955  * Reads 32-bit (int) number from guest address space from
956  * address 'addr' and prints it.
957  */
958 static void
959 print_number(abi_long addr, int last)
960 {
961     if (addr == 0) {
962         gemu_log("NULL%s", get_comma(last));
963     } else {
964         int num;
965
966         get_user_s32(num, addr);
967         gemu_log("[%d]%s", num, get_comma(last));
968     }
969 }
970
971 static void
972 print_timeval(abi_ulong tv_addr, int last)
973 {
974     if( tv_addr ) {
975         struct target_timeval *tv;
976
977         tv = lock_user(VERIFY_READ, tv_addr, sizeof(*tv), 1);
978         if (!tv)
979             return;
980         gemu_log("{" TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld "}%s",
981             tswapal(tv->tv_sec), tswapal(tv->tv_usec), get_comma(last));
982         unlock_user(tv, tv_addr, 0);
983     } else
984         gemu_log("NULL%s", get_comma(last));
985 }
986
987 #undef UNUSED
988
989 #ifdef TARGET_NR_accept
990 static void
991 print_accept(const struct syscallname *name,
992     abi_long arg0, abi_long arg1, abi_long arg2,
993     abi_long arg3, abi_long arg4, abi_long arg5)
994 {
995     print_syscall_prologue(name);
996     print_raw_param("%d", arg0, 0);
997     print_pointer(arg1, 0);
998     print_number(arg2, 1);
999     print_syscall_epilogue(name);
1000 }
1001 #endif
1002
1003 #ifdef TARGET_NR_access
1004 static void
1005 print_access(const struct syscallname *name,
1006     abi_long arg0, abi_long arg1, abi_long arg2,
1007     abi_long arg3, abi_long arg4, abi_long arg5)
1008 {
1009     print_syscall_prologue(name);
1010     print_string(arg0, 0);
1011     print_flags(access_flags, arg1, 1);
1012     print_syscall_epilogue(name);
1013 }
1014 #endif
1015
1016 #ifdef TARGET_NR_brk
1017 static void
1018 print_brk(const struct syscallname *name,
1019     abi_long arg0, abi_long arg1, abi_long arg2,
1020     abi_long arg3, abi_long arg4, abi_long arg5)
1021 {
1022     print_syscall_prologue(name);
1023     print_pointer(arg0, 1);
1024     print_syscall_epilogue(name);
1025 }
1026 #endif
1027
1028 #ifdef TARGET_NR_chdir
1029 static void
1030 print_chdir(const struct syscallname *name,
1031     abi_long arg0, abi_long arg1, abi_long arg2,
1032     abi_long arg3, abi_long arg4, abi_long arg5)
1033 {
1034     print_syscall_prologue(name);
1035     print_string(arg0, 1);
1036     print_syscall_epilogue(name);
1037 }
1038 #endif
1039
1040 #ifdef TARGET_NR_chmod
1041 static void
1042 print_chmod(const struct syscallname *name,
1043     abi_long arg0, abi_long arg1, abi_long arg2,
1044     abi_long arg3, abi_long arg4, abi_long arg5)
1045 {
1046     print_syscall_prologue(name);
1047     print_string(arg0, 0);
1048     print_file_mode(arg1, 1);
1049     print_syscall_epilogue(name);
1050 }
1051 #endif
1052
1053 #ifdef TARGET_NR_clone
1054 static void do_print_clone(unsigned int flags, abi_ulong newsp,
1055                            abi_ulong parent_tidptr, target_ulong newtls,
1056                            abi_ulong child_tidptr)
1057 {
1058     print_flags(clone_flags, flags, 0);
1059     print_raw_param("child_stack=0x" TARGET_ABI_FMT_lx, newsp, 0);
1060     print_raw_param("parent_tidptr=0x" TARGET_ABI_FMT_lx, parent_tidptr, 0);
1061     print_raw_param("tls=0x" TARGET_ABI_FMT_lx, newtls, 0);
1062     print_raw_param("child_tidptr=0x" TARGET_ABI_FMT_lx, child_tidptr, 1);
1063 }
1064
1065 static void
1066 print_clone(const struct syscallname *name,
1067     abi_long arg1, abi_long arg2, abi_long arg3,
1068     abi_long arg4, abi_long arg5, abi_long arg6)
1069 {
1070     print_syscall_prologue(name);
1071 #if defined(TARGET_MICROBLAZE)
1072     do_print_clone(arg1, arg2, arg4, arg6, arg5);
1073 #elif defined(TARGET_CLONE_BACKWARDS)
1074     do_print_clone(arg1, arg2, arg3, arg4, arg5);
1075 #elif defined(TARGET_CLONE_BACKWARDS2)
1076     do_print_clone(arg2, arg1, arg3, arg5, arg4);
1077 #else
1078     do_print_clone(arg1, arg2, arg3, arg5, arg4);
1079 #endif
1080     print_syscall_epilogue(name);
1081 }
1082 #endif
1083
1084 #ifdef TARGET_NR_creat
1085 static void
1086 print_creat(const struct syscallname *name,
1087     abi_long arg0, abi_long arg1, abi_long arg2,
1088     abi_long arg3, abi_long arg4, abi_long arg5)
1089 {
1090     print_syscall_prologue(name);
1091     print_string(arg0, 0);
1092     print_file_mode(arg1, 1);
1093     print_syscall_epilogue(name);
1094 }
1095 #endif
1096
1097 #ifdef TARGET_NR_execv
1098 static void
1099 print_execv(const struct syscallname *name,
1100     abi_long arg0, abi_long arg1, abi_long arg2,
1101     abi_long arg3, abi_long arg4, abi_long arg5)
1102 {
1103     print_syscall_prologue(name);
1104     print_string(arg0, 0);
1105     print_raw_param("0x" TARGET_ABI_FMT_lx, arg1, 1);
1106     print_syscall_epilogue(name);
1107 }
1108 #endif
1109
1110 #ifdef TARGET_NR_faccessat
1111 static void
1112 print_faccessat(const struct syscallname *name,
1113     abi_long arg0, abi_long arg1, abi_long arg2,
1114     abi_long arg3, abi_long arg4, abi_long arg5)
1115 {
1116     print_syscall_prologue(name);
1117     print_at_dirfd(arg0, 0);
1118     print_string(arg1, 0);
1119     print_flags(access_flags, arg2, 0);
1120     print_flags(at_file_flags, arg3, 1);
1121     print_syscall_epilogue(name);
1122 }
1123 #endif
1124
1125 #ifdef TARGET_NR_fchmodat
1126 static void
1127 print_fchmodat(const struct syscallname *name,
1128     abi_long arg0, abi_long arg1, abi_long arg2,
1129     abi_long arg3, abi_long arg4, abi_long arg5)
1130 {
1131     print_syscall_prologue(name);
1132     print_at_dirfd(arg0, 0);
1133     print_string(arg1, 0);
1134     print_file_mode(arg2, 0);
1135     print_flags(at_file_flags, arg3, 1);
1136     print_syscall_epilogue(name);
1137 }
1138 #endif
1139
1140 #ifdef TARGET_NR_fchownat
1141 static void
1142 print_fchownat(const struct syscallname *name,
1143     abi_long arg0, abi_long arg1, abi_long arg2,
1144     abi_long arg3, abi_long arg4, abi_long arg5)
1145 {
1146     print_syscall_prologue(name);
1147     print_at_dirfd(arg0, 0);
1148     print_string(arg1, 0);
1149     print_raw_param("%d", arg2, 0);
1150     print_raw_param("%d", arg3, 0);
1151     print_flags(at_file_flags, arg4, 1);
1152     print_syscall_epilogue(name);
1153 }
1154 #endif
1155
1156 #if defined(TARGET_NR_fcntl) || defined(TARGET_NR_fcntl64)
1157 static void
1158 print_fcntl(const struct syscallname *name,
1159     abi_long arg0, abi_long arg1, abi_long arg2,
1160     abi_long arg3, abi_long arg4, abi_long arg5)
1161 {
1162     print_syscall_prologue(name);
1163     print_raw_param("%d", arg0, 0);
1164     switch(arg1) {
1165     case TARGET_F_DUPFD:
1166         gemu_log("F_DUPFD,");
1167         print_raw_param(TARGET_ABI_FMT_ld, arg2, 1);
1168         break;
1169     case TARGET_F_GETFD:
1170         gemu_log("F_GETFD");
1171         break;
1172     case TARGET_F_SETFD:
1173         gemu_log("F_SETFD,");
1174         print_raw_param(TARGET_ABI_FMT_ld, arg2, 1);
1175         break;
1176     case TARGET_F_GETFL:
1177         gemu_log("F_GETFL");
1178         break;
1179     case TARGET_F_SETFL:
1180         gemu_log("F_SETFL,");
1181         print_open_flags(arg2, 1);
1182         break;
1183     case TARGET_F_GETLK:
1184         gemu_log("F_GETLK,");
1185         print_pointer(arg2, 1);
1186         break;
1187     case TARGET_F_SETLK:
1188         gemu_log("F_SETLK,");
1189         print_pointer(arg2, 1);
1190         break;
1191     case TARGET_F_SETLKW:
1192         gemu_log("F_SETLKW,");
1193         print_pointer(arg2, 1);
1194         break;
1195     case TARGET_F_GETOWN:
1196         gemu_log("F_GETOWN");
1197         break;
1198     case TARGET_F_SETOWN:
1199         gemu_log("F_SETOWN,");
1200         print_raw_param(TARGET_ABI_FMT_ld, arg2, 0);
1201         break;
1202     case TARGET_F_GETSIG:
1203         gemu_log("F_GETSIG");
1204         break;
1205     case TARGET_F_SETSIG:
1206         gemu_log("F_SETSIG,");
1207         print_raw_param(TARGET_ABI_FMT_ld, arg2, 0);
1208         break;
1209 #if TARGET_ABI_BITS == 32
1210     case TARGET_F_GETLK64:
1211         gemu_log("F_GETLK64,");
1212         print_pointer(arg2, 1);
1213         break;
1214     case TARGET_F_SETLK64:
1215         gemu_log("F_SETLK64,");
1216         print_pointer(arg2, 1);
1217         break;
1218     case TARGET_F_SETLKW64:
1219         gemu_log("F_SETLKW64,");
1220         print_pointer(arg2, 1);
1221         break;
1222 #endif
1223     case TARGET_F_SETLEASE:
1224         gemu_log("F_SETLEASE,");
1225         print_raw_param(TARGET_ABI_FMT_ld, arg2, 0);
1226         break;
1227     case TARGET_F_GETLEASE:
1228         gemu_log("F_GETLEASE");
1229         break;
1230     case TARGET_F_SETPIPE_SZ:
1231         gemu_log("F_SETPIPE_SZ,");
1232         print_raw_param(TARGET_ABI_FMT_ld, arg2, 1);
1233         break;
1234     case TARGET_F_GETPIPE_SZ:
1235         gemu_log("F_GETPIPE_SZ");
1236         break;
1237     case TARGET_F_DUPFD_CLOEXEC:
1238         gemu_log("F_DUPFD_CLOEXEC,");
1239         print_raw_param(TARGET_ABI_FMT_ld, arg2, 1);
1240         break;
1241     case TARGET_F_NOTIFY:
1242         gemu_log("F_NOTIFY,");
1243         print_raw_param(TARGET_ABI_FMT_ld, arg2, 0);
1244         break;
1245     default:
1246         print_raw_param(TARGET_ABI_FMT_ld, arg1, 0);
1247         print_pointer(arg2, 1);
1248         break;
1249     }
1250     print_syscall_epilogue(name);
1251 }
1252 #define print_fcntl64   print_fcntl
1253 #endif
1254
1255
1256 #ifdef TARGET_NR_futimesat
1257 static void
1258 print_futimesat(const struct syscallname *name,
1259     abi_long arg0, abi_long arg1, abi_long arg2,
1260     abi_long arg3, abi_long arg4, abi_long arg5)
1261 {
1262     print_syscall_prologue(name);
1263     print_at_dirfd(arg0, 0);
1264     print_string(arg1, 0);
1265     print_timeval(arg2, 0);
1266     print_timeval(arg2 + sizeof (struct target_timeval), 1);
1267     print_syscall_epilogue(name);
1268 }
1269 #endif
1270
1271 #ifdef TARGET_NR_link
1272 static void
1273 print_link(const struct syscallname *name,
1274     abi_long arg0, abi_long arg1, abi_long arg2,
1275     abi_long arg3, abi_long arg4, abi_long arg5)
1276 {
1277     print_syscall_prologue(name);
1278     print_string(arg0, 0);
1279     print_string(arg1, 1);
1280     print_syscall_epilogue(name);
1281 }
1282 #endif
1283
1284 #ifdef TARGET_NR_linkat
1285 static void
1286 print_linkat(const struct syscallname *name,
1287     abi_long arg0, abi_long arg1, abi_long arg2,
1288     abi_long arg3, abi_long arg4, abi_long arg5)
1289 {
1290     print_syscall_prologue(name);
1291     print_at_dirfd(arg0, 0);
1292     print_string(arg1, 0);
1293     print_at_dirfd(arg2, 0);
1294     print_string(arg3, 0);
1295     print_flags(at_file_flags, arg4, 1);
1296     print_syscall_epilogue(name);
1297 }
1298 #endif
1299
1300 #ifdef TARGET_NR__llseek
1301 static void
1302 print__llseek(const struct syscallname *name,
1303     abi_long arg0, abi_long arg1, abi_long arg2,
1304     abi_long arg3, abi_long arg4, abi_long arg5)
1305 {
1306     const char *whence = "UNKNOWN";
1307     print_syscall_prologue(name);
1308     print_raw_param("%d", arg0, 0);
1309     print_raw_param("%ld", arg1, 0);
1310     print_raw_param("%ld", arg2, 0);
1311     print_pointer(arg3, 0);
1312     switch(arg4) {
1313     case SEEK_SET: whence = "SEEK_SET"; break;
1314     case SEEK_CUR: whence = "SEEK_CUR"; break;
1315     case SEEK_END: whence = "SEEK_END"; break;
1316     }
1317     gemu_log("%s",whence);
1318     print_syscall_epilogue(name);
1319 }
1320 #endif
1321
1322 #if defined(TARGET_NR_socket)
1323 static void
1324 print_socket(const struct syscallname *name,
1325              abi_long arg0, abi_long arg1, abi_long arg2,
1326              abi_long arg3, abi_long arg4, abi_long arg5)
1327 {
1328     abi_ulong domain = arg0, type = arg1, protocol = arg2;
1329
1330     print_syscall_prologue(name);
1331     print_socket_domain(domain);
1332     gemu_log(",");
1333     print_socket_type(type);
1334     gemu_log(",");
1335     if (domain == AF_PACKET ||
1336         (domain == AF_INET && type == TARGET_SOCK_PACKET)) {
1337         protocol = tswap16(protocol);
1338     }
1339     print_socket_protocol(domain, type, protocol);
1340     print_syscall_epilogue(name);
1341 }
1342
1343 #endif
1344
1345 #if defined(TARGET_NR_socketcall)
1346
1347 #define get_user_ualx(x, gaddr, idx) \
1348         get_user_ual(x, (gaddr) + (idx) * sizeof(abi_long))
1349
1350 static void do_print_socket(const char *name, abi_long arg1)
1351 {
1352     abi_ulong domain, type, protocol;
1353
1354     get_user_ualx(domain, arg1, 0);
1355     get_user_ualx(type, arg1, 1);
1356     get_user_ualx(protocol, arg1, 2);
1357     gemu_log("%s(", name);
1358     print_socket_domain(domain);
1359     gemu_log(",");
1360     print_socket_type(type);
1361     gemu_log(",");
1362     if (domain == AF_PACKET ||
1363         (domain == AF_INET && type == TARGET_SOCK_PACKET)) {
1364         protocol = tswap16(protocol);
1365     }
1366     print_socket_protocol(domain, type, protocol);
1367     gemu_log(")");
1368 }
1369
1370 static void do_print_sockaddr(const char *name, abi_long arg1)
1371 {
1372     abi_ulong sockfd, addr, addrlen;
1373
1374     get_user_ualx(sockfd, arg1, 0);
1375     get_user_ualx(addr, arg1, 1);
1376     get_user_ualx(addrlen, arg1, 2);
1377
1378     gemu_log("%s(", name);
1379     print_raw_param(TARGET_ABI_FMT_ld, sockfd, 0);
1380     print_sockaddr(addr, addrlen);
1381     gemu_log(")");
1382 }
1383
1384 static void do_print_listen(const char *name, abi_long arg1)
1385 {
1386     abi_ulong sockfd, backlog;
1387
1388     get_user_ualx(sockfd, arg1, 0);
1389     get_user_ualx(backlog, arg1, 1);
1390
1391     gemu_log("%s(", name);
1392     print_raw_param(TARGET_ABI_FMT_ld, sockfd, 0);
1393     print_raw_param(TARGET_ABI_FMT_ld, backlog, 1);
1394     gemu_log(")");
1395 }
1396
1397 static void do_print_socketpair(const char *name, abi_long arg1)
1398 {
1399     abi_ulong domain, type, protocol, tab;
1400
1401     get_user_ualx(domain, arg1, 0);
1402     get_user_ualx(type, arg1, 1);
1403     get_user_ualx(protocol, arg1, 2);
1404     get_user_ualx(tab, arg1, 3);
1405
1406     gemu_log("%s(", name);
1407     print_socket_domain(domain);
1408     gemu_log(",");
1409     print_socket_type(type);
1410     gemu_log(",");
1411     print_socket_protocol(domain, type, protocol);
1412     gemu_log(",");
1413     print_raw_param(TARGET_ABI_FMT_lx, tab, 1);
1414     gemu_log(")");
1415 }
1416
1417 static void do_print_sendrecv(const char *name, abi_long arg1)
1418 {
1419     abi_ulong sockfd, msg, len, flags;
1420
1421     get_user_ualx(sockfd, arg1, 0);
1422     get_user_ualx(msg, arg1, 1);
1423     get_user_ualx(len, arg1, 2);
1424     get_user_ualx(flags, arg1, 3);
1425
1426     gemu_log("%s(", name);
1427     print_raw_param(TARGET_ABI_FMT_ld, sockfd, 0);
1428     print_buf(msg, len, 0);
1429     print_raw_param(TARGET_ABI_FMT_ld, len, 0);
1430     print_flags(msg_flags, flags, 1);
1431     gemu_log(")");
1432 }
1433
1434 static void do_print_msgaddr(const char *name, abi_long arg1)
1435 {
1436     abi_ulong sockfd, msg, len, flags, addr, addrlen;
1437
1438     get_user_ualx(sockfd, arg1, 0);
1439     get_user_ualx(msg, arg1, 1);
1440     get_user_ualx(len, arg1, 2);
1441     get_user_ualx(flags, arg1, 3);
1442     get_user_ualx(addr, arg1, 4);
1443     get_user_ualx(addrlen, arg1, 5);
1444
1445     gemu_log("%s(", name);
1446     print_raw_param(TARGET_ABI_FMT_ld, sockfd, 0);
1447     print_buf(msg, len, 0);
1448     print_raw_param(TARGET_ABI_FMT_ld, len, 0);
1449     print_flags(msg_flags, flags, 0);
1450     print_sockaddr(addr, addrlen);
1451     gemu_log(")");
1452 }
1453
1454 static void do_print_shutdown(const char *name, abi_long arg1)
1455 {
1456     abi_ulong sockfd, how;
1457
1458     get_user_ualx(sockfd, arg1, 0);
1459     get_user_ualx(how, arg1, 1);
1460
1461     gemu_log("shutdown(");
1462     print_raw_param(TARGET_ABI_FMT_ld, sockfd, 0);
1463     switch (how) {
1464     case SHUT_RD:
1465         gemu_log("SHUT_RD");
1466         break;
1467     case SHUT_WR:
1468         gemu_log("SHUT_WR");
1469         break;
1470     case SHUT_RDWR:
1471         gemu_log("SHUT_RDWR");
1472         break;
1473     default:
1474         print_raw_param(TARGET_ABI_FMT_ld, how, 1);
1475         break;
1476     }
1477     gemu_log(")");
1478 }
1479
1480 static void do_print_msg(const char *name, abi_long arg1)
1481 {
1482     abi_ulong sockfd, msg, flags;
1483
1484     get_user_ualx(sockfd, arg1, 0);
1485     get_user_ualx(msg, arg1, 1);
1486     get_user_ualx(flags, arg1, 2);
1487
1488     gemu_log("%s(", name);
1489     print_raw_param(TARGET_ABI_FMT_ld, sockfd, 0);
1490     print_pointer(msg, 0);
1491     print_flags(msg_flags, flags, 1);
1492     gemu_log(")");
1493 }
1494
1495 static void do_print_sockopt(const char *name, abi_long arg1)
1496 {
1497     abi_ulong sockfd, level, optname, optval, optlen;
1498
1499     get_user_ualx(sockfd, arg1, 0);
1500     get_user_ualx(level, arg1, 1);
1501     get_user_ualx(optname, arg1, 2);
1502     get_user_ualx(optval, arg1, 3);
1503     get_user_ualx(optlen, arg1, 4);
1504
1505     gemu_log("%s(", name);
1506     print_raw_param(TARGET_ABI_FMT_ld, sockfd, 0);
1507     switch (level) {
1508     case SOL_TCP:
1509         gemu_log("SOL_TCP,");
1510         print_raw_param(TARGET_ABI_FMT_ld, optname, 0);
1511         print_pointer(optval, 0);
1512         break;
1513     case SOL_IP:
1514         gemu_log("SOL_IP,");
1515         print_raw_param(TARGET_ABI_FMT_ld, optname, 0);
1516         print_pointer(optval, 0);
1517         break;
1518     case SOL_RAW:
1519         gemu_log("SOL_RAW,");
1520         print_raw_param(TARGET_ABI_FMT_ld, optname, 0);
1521         print_pointer(optval, 0);
1522         break;
1523     case TARGET_SOL_SOCKET:
1524         gemu_log("SOL_SOCKET,");
1525         switch (optname) {
1526         case TARGET_SO_DEBUG:
1527             gemu_log("SO_DEBUG,");
1528 print_optint:
1529             print_number(optval, 0);
1530             break;
1531         case TARGET_SO_REUSEADDR:
1532             gemu_log("SO_REUSEADDR,");
1533             goto print_optint;
1534         case TARGET_SO_TYPE:
1535             gemu_log("SO_TYPE,");
1536             goto print_optint;
1537         case TARGET_SO_ERROR:
1538             gemu_log("SO_ERROR,");
1539             goto print_optint;
1540         case TARGET_SO_DONTROUTE:
1541             gemu_log("SO_DONTROUTE,");
1542             goto print_optint;
1543         case TARGET_SO_BROADCAST:
1544             gemu_log("SO_BROADCAST,");
1545             goto print_optint;
1546         case TARGET_SO_SNDBUF:
1547             gemu_log("SO_SNDBUF,");
1548             goto print_optint;
1549         case TARGET_SO_RCVBUF:
1550             gemu_log("SO_RCVBUF,");
1551             goto print_optint;
1552         case TARGET_SO_KEEPALIVE:
1553             gemu_log("SO_KEEPALIVE,");
1554             goto print_optint;
1555         case TARGET_SO_OOBINLINE:
1556             gemu_log("SO_OOBINLINE,");
1557             goto print_optint;
1558         case TARGET_SO_NO_CHECK:
1559             gemu_log("SO_NO_CHECK,");
1560             goto print_optint;
1561         case TARGET_SO_PRIORITY:
1562             gemu_log("SO_PRIORITY,");
1563             goto print_optint;
1564         case TARGET_SO_BSDCOMPAT:
1565             gemu_log("SO_BSDCOMPAT,");
1566             goto print_optint;
1567         case TARGET_SO_PASSCRED:
1568             gemu_log("SO_PASSCRED,");
1569             goto print_optint;
1570         case TARGET_SO_TIMESTAMP:
1571             gemu_log("SO_TIMESTAMP,");
1572             goto print_optint;
1573         case TARGET_SO_RCVLOWAT:
1574             gemu_log("SO_RCVLOWAT,");
1575             goto print_optint;
1576         case TARGET_SO_RCVTIMEO:
1577             gemu_log("SO_RCVTIMEO,");
1578             print_timeval(optval, 0);
1579             break;
1580         case TARGET_SO_SNDTIMEO:
1581             gemu_log("SO_SNDTIMEO,");
1582             print_timeval(optval, 0);
1583             break;
1584         case TARGET_SO_ATTACH_FILTER: {
1585             struct target_sock_fprog *fprog;
1586
1587             gemu_log("SO_ATTACH_FILTER,");
1588
1589             if (lock_user_struct(VERIFY_READ, fprog, optval,  0)) {
1590                 struct target_sock_filter *filter;
1591                 gemu_log("{");
1592                 if (lock_user_struct(VERIFY_READ, filter,
1593                                      tswapal(fprog->filter),  0)) {
1594                     int i;
1595                     for (i = 0; i < tswap16(fprog->len) - 1; i++) {
1596                         gemu_log("[%d]{0x%x,%d,%d,0x%x},",
1597                                  i, tswap16(filter[i].code),
1598                                  filter[i].jt, filter[i].jf,
1599                                  tswap32(filter[i].k));
1600                     }
1601                     gemu_log("[%d]{0x%x,%d,%d,0x%x}",
1602                              i, tswap16(filter[i].code),
1603                              filter[i].jt, filter[i].jf,
1604                              tswap32(filter[i].k));
1605                 } else {
1606                     gemu_log(TARGET_ABI_FMT_lx, tswapal(fprog->filter));
1607                 }
1608                 gemu_log(",%d},", tswap16(fprog->len));
1609                 unlock_user(fprog, optval, 0);
1610             } else {
1611                 print_pointer(optval, 0);
1612             }
1613             break;
1614         }
1615         default:
1616             print_raw_param(TARGET_ABI_FMT_ld, optname, 0);
1617             print_pointer(optval, 0);
1618             break;
1619         }
1620         break;
1621     default:
1622         print_raw_param(TARGET_ABI_FMT_ld, level, 0);
1623         print_raw_param(TARGET_ABI_FMT_ld, optname, 0);
1624         print_pointer(optval, 0);
1625         break;
1626     }
1627     print_raw_param(TARGET_ABI_FMT_ld, optlen, 1);
1628     gemu_log(")");
1629 }
1630
1631 #define PRINT_SOCKOP(name, func) \
1632     [SOCKOP_##name] = { #name, func }
1633
1634 static struct {
1635     const char *name;
1636     void (*print)(const char *, abi_long);
1637 } scall[] = {
1638     PRINT_SOCKOP(socket, do_print_socket),
1639     PRINT_SOCKOP(bind, do_print_sockaddr),
1640     PRINT_SOCKOP(connect, do_print_sockaddr),
1641     PRINT_SOCKOP(listen, do_print_listen),
1642     PRINT_SOCKOP(accept, do_print_sockaddr),
1643     PRINT_SOCKOP(getsockname, do_print_sockaddr),
1644     PRINT_SOCKOP(getpeername, do_print_sockaddr),
1645     PRINT_SOCKOP(socketpair, do_print_socketpair),
1646     PRINT_SOCKOP(send, do_print_sendrecv),
1647     PRINT_SOCKOP(recv, do_print_sendrecv),
1648     PRINT_SOCKOP(sendto, do_print_msgaddr),
1649     PRINT_SOCKOP(recvfrom, do_print_msgaddr),
1650     PRINT_SOCKOP(shutdown, do_print_shutdown),
1651     PRINT_SOCKOP(sendmsg, do_print_msg),
1652     PRINT_SOCKOP(recvmsg, do_print_msg),
1653     PRINT_SOCKOP(setsockopt, do_print_sockopt),
1654     PRINT_SOCKOP(getsockopt, do_print_sockopt),
1655 };
1656
1657 static void
1658 print_socketcall(const struct syscallname *name,
1659                  abi_long arg0, abi_long arg1, abi_long arg2,
1660                  abi_long arg3, abi_long arg4, abi_long arg5)
1661 {
1662     if (arg0 >= 0 && arg0 < ARRAY_SIZE(scall) && scall[arg0].print) {
1663         scall[arg0].print(scall[arg0].name, arg1);
1664         return;
1665     }
1666     print_syscall_prologue(name);
1667     print_raw_param(TARGET_ABI_FMT_ld, arg0, 0);
1668     print_raw_param(TARGET_ABI_FMT_ld, arg1, 0);
1669     print_raw_param(TARGET_ABI_FMT_ld, arg2, 0);
1670     print_raw_param(TARGET_ABI_FMT_ld, arg3, 0);
1671     print_raw_param(TARGET_ABI_FMT_ld, arg4, 0);
1672     print_raw_param(TARGET_ABI_FMT_ld, arg5, 0);
1673     print_syscall_epilogue(name);
1674 }
1675 #endif
1676
1677 #if defined(TARGET_NR_stat) || defined(TARGET_NR_stat64) || \
1678     defined(TARGET_NR_lstat) || defined(TARGET_NR_lstat64)
1679 static void
1680 print_stat(const struct syscallname *name,
1681     abi_long arg0, abi_long arg1, abi_long arg2,
1682     abi_long arg3, abi_long arg4, abi_long arg5)
1683 {
1684     print_syscall_prologue(name);
1685     print_string(arg0, 0);
1686     print_pointer(arg1, 1);
1687     print_syscall_epilogue(name);
1688 }
1689 #define print_lstat     print_stat
1690 #define print_stat64    print_stat
1691 #define print_lstat64   print_stat
1692 #endif
1693
1694 #if defined(TARGET_NR_fstat) || defined(TARGET_NR_fstat64)
1695 static void
1696 print_fstat(const struct syscallname *name,
1697     abi_long arg0, abi_long arg1, abi_long arg2,
1698     abi_long arg3, abi_long arg4, abi_long arg5)
1699 {
1700     print_syscall_prologue(name);
1701     print_raw_param("%d", arg0, 0);
1702     print_pointer(arg1, 1);
1703     print_syscall_epilogue(name);
1704 }
1705 #define print_fstat64     print_fstat
1706 #endif
1707
1708 #ifdef TARGET_NR_mkdir
1709 static void
1710 print_mkdir(const struct syscallname *name,
1711     abi_long arg0, abi_long arg1, abi_long arg2,
1712     abi_long arg3, abi_long arg4, abi_long arg5)
1713 {
1714     print_syscall_prologue(name);
1715     print_string(arg0, 0);
1716     print_file_mode(arg1, 1);
1717     print_syscall_epilogue(name);
1718 }
1719 #endif
1720
1721 #ifdef TARGET_NR_mkdirat
1722 static void
1723 print_mkdirat(const struct syscallname *name,
1724     abi_long arg0, abi_long arg1, abi_long arg2,
1725     abi_long arg3, abi_long arg4, abi_long arg5)
1726 {
1727     print_syscall_prologue(name);
1728     print_at_dirfd(arg0, 0);
1729     print_string(arg1, 0);
1730     print_file_mode(arg2, 1);
1731     print_syscall_epilogue(name);
1732 }
1733 #endif
1734
1735 #ifdef TARGET_NR_rmdir
1736 static void
1737 print_rmdir(const struct syscallname *name,
1738     abi_long arg0, abi_long arg1, abi_long arg2,
1739     abi_long arg3, abi_long arg4, abi_long arg5)
1740 {
1741     print_syscall_prologue(name);
1742     print_string(arg0, 0);
1743     print_syscall_epilogue(name);
1744 }
1745 #endif
1746
1747 #ifdef TARGET_NR_rt_sigaction
1748 static void
1749 print_rt_sigaction(const struct syscallname *name,
1750     abi_long arg0, abi_long arg1, abi_long arg2,
1751     abi_long arg3, abi_long arg4, abi_long arg5)
1752 {
1753     print_syscall_prologue(name);
1754     print_signal(arg0, 0);
1755     print_pointer(arg1, 0);
1756     print_pointer(arg2, 1);
1757     print_syscall_epilogue(name);
1758 }
1759 #endif
1760
1761 #ifdef TARGET_NR_rt_sigprocmask
1762 static void
1763 print_rt_sigprocmask(const struct syscallname *name,
1764     abi_long arg0, abi_long arg1, abi_long arg2,
1765     abi_long arg3, abi_long arg4, abi_long arg5)
1766 {
1767     const char *how = "UNKNOWN";
1768     print_syscall_prologue(name);
1769     switch(arg0) {
1770     case TARGET_SIG_BLOCK: how = "SIG_BLOCK"; break;
1771     case TARGET_SIG_UNBLOCK: how = "SIG_UNBLOCK"; break;
1772     case TARGET_SIG_SETMASK: how = "SIG_SETMASK"; break;
1773     }
1774     gemu_log("%s,",how);
1775     print_pointer(arg1, 0);
1776     print_pointer(arg2, 1);
1777     print_syscall_epilogue(name);
1778 }
1779 #endif
1780
1781 #ifdef TARGET_NR_mknod
1782 static void
1783 print_mknod(const struct syscallname *name,
1784     abi_long arg0, abi_long arg1, abi_long arg2,
1785     abi_long arg3, abi_long arg4, abi_long arg5)
1786 {
1787     int hasdev = (arg1 & (S_IFCHR|S_IFBLK));
1788
1789     print_syscall_prologue(name);
1790     print_string(arg0, 0);
1791     print_file_mode(arg1, (hasdev == 0));
1792     if (hasdev) {
1793         print_raw_param("makedev(%d", major(arg2), 0);
1794         print_raw_param("%d)", minor(arg2), 1);
1795     }
1796     print_syscall_epilogue(name);
1797 }
1798 #endif
1799
1800 #ifdef TARGET_NR_mknodat
1801 static void
1802 print_mknodat(const struct syscallname *name,
1803     abi_long arg0, abi_long arg1, abi_long arg2,
1804     abi_long arg3, abi_long arg4, abi_long arg5)
1805 {
1806     int hasdev = (arg2 & (S_IFCHR|S_IFBLK));
1807
1808     print_syscall_prologue(name);
1809     print_at_dirfd(arg0, 0);
1810     print_string(arg1, 0);
1811     print_file_mode(arg2, (hasdev == 0));
1812     if (hasdev) {
1813         print_raw_param("makedev(%d", major(arg3), 0);
1814         print_raw_param("%d)", minor(arg3), 1);
1815     }
1816     print_syscall_epilogue(name);
1817 }
1818 #endif
1819
1820 #ifdef TARGET_NR_mq_open
1821 static void
1822 print_mq_open(const struct syscallname *name,
1823     abi_long arg0, abi_long arg1, abi_long arg2,
1824     abi_long arg3, abi_long arg4, abi_long arg5)
1825 {
1826     int is_creat = (arg1 & TARGET_O_CREAT);
1827
1828     print_syscall_prologue(name);
1829     print_string(arg0, 0);
1830     print_open_flags(arg1, (is_creat == 0));
1831     if (is_creat) {
1832         print_file_mode(arg2, 0);
1833         print_pointer(arg3, 1);
1834     }
1835     print_syscall_epilogue(name);
1836 }
1837 #endif
1838
1839 #ifdef TARGET_NR_open
1840 static void
1841 print_open(const struct syscallname *name,
1842     abi_long arg0, abi_long arg1, abi_long arg2,
1843     abi_long arg3, abi_long arg4, abi_long arg5)
1844 {
1845     int is_creat = (arg1 & TARGET_O_CREAT);
1846
1847     print_syscall_prologue(name);
1848     print_string(arg0, 0);
1849     print_open_flags(arg1, (is_creat == 0));
1850     if (is_creat)
1851         print_file_mode(arg2, 1);
1852     print_syscall_epilogue(name);
1853 }
1854 #endif
1855
1856 #ifdef TARGET_NR_openat
1857 static void
1858 print_openat(const struct syscallname *name,
1859     abi_long arg0, abi_long arg1, abi_long arg2,
1860     abi_long arg3, abi_long arg4, abi_long arg5)
1861 {
1862     int is_creat = (arg2 & TARGET_O_CREAT);
1863
1864     print_syscall_prologue(name);
1865     print_at_dirfd(arg0, 0);
1866     print_string(arg1, 0);
1867     print_open_flags(arg2, (is_creat == 0));
1868     if (is_creat)
1869         print_file_mode(arg3, 1);
1870     print_syscall_epilogue(name);
1871 }
1872 #endif
1873
1874 #ifdef TARGET_NR_mq_unlink
1875 static void
1876 print_mq_unlink(const struct syscallname *name,
1877     abi_long arg0, abi_long arg1, abi_long arg2,
1878     abi_long arg3, abi_long arg4, abi_long arg5)
1879 {
1880     print_syscall_prologue(name);
1881     print_string(arg0, 1);
1882     print_syscall_epilogue(name);
1883 }
1884 #endif
1885
1886 #if defined(TARGET_NR_fstatat64) || defined(TARGET_NR_newfstatat)
1887 static void
1888 print_fstatat64(const struct syscallname *name,
1889     abi_long arg0, abi_long arg1, abi_long arg2,
1890     abi_long arg3, abi_long arg4, abi_long arg5)
1891 {
1892     print_syscall_prologue(name);
1893     print_at_dirfd(arg0, 0);
1894     print_string(arg1, 0);
1895     print_pointer(arg2, 0);
1896     print_flags(at_file_flags, arg3, 1);
1897     print_syscall_epilogue(name);
1898 }
1899 #define print_newfstatat    print_fstatat64
1900 #endif
1901
1902 #ifdef TARGET_NR_readlink
1903 static void
1904 print_readlink(const struct syscallname *name,
1905     abi_long arg0, abi_long arg1, abi_long arg2,
1906     abi_long arg3, abi_long arg4, abi_long arg5)
1907 {
1908     print_syscall_prologue(name);
1909     print_string(arg0, 0);
1910     print_pointer(arg1, 0);
1911     print_raw_param("%u", arg2, 1);
1912     print_syscall_epilogue(name);
1913 }
1914 #endif
1915
1916 #ifdef TARGET_NR_readlinkat
1917 static void
1918 print_readlinkat(const struct syscallname *name,
1919     abi_long arg0, abi_long arg1, abi_long arg2,
1920     abi_long arg3, abi_long arg4, abi_long arg5)
1921 {
1922     print_syscall_prologue(name);
1923     print_at_dirfd(arg0, 0);
1924     print_string(arg1, 0);
1925     print_pointer(arg2, 0);
1926     print_raw_param("%u", arg3, 1);
1927     print_syscall_epilogue(name);
1928 }
1929 #endif
1930
1931 #ifdef TARGET_NR_rename
1932 static void
1933 print_rename(const struct syscallname *name,
1934     abi_long arg0, abi_long arg1, abi_long arg2,
1935     abi_long arg3, abi_long arg4, abi_long arg5)
1936 {
1937     print_syscall_prologue(name);
1938     print_string(arg0, 0);
1939     print_string(arg1, 1);
1940     print_syscall_epilogue(name);
1941 }
1942 #endif
1943
1944 #ifdef TARGET_NR_renameat
1945 static void
1946 print_renameat(const struct syscallname *name,
1947     abi_long arg0, abi_long arg1, abi_long arg2,
1948     abi_long arg3, abi_long arg4, abi_long arg5)
1949 {
1950     print_syscall_prologue(name);
1951     print_at_dirfd(arg0, 0);
1952     print_string(arg1, 0);
1953     print_at_dirfd(arg2, 0);
1954     print_string(arg3, 1);
1955     print_syscall_epilogue(name);
1956 }
1957 #endif
1958
1959 #ifdef TARGET_NR_statfs
1960 static void
1961 print_statfs(const struct syscallname *name,
1962     abi_long arg0, abi_long arg1, abi_long arg2,
1963     abi_long arg3, abi_long arg4, abi_long arg5)
1964 {
1965     print_syscall_prologue(name);
1966     print_string(arg0, 0);
1967     print_pointer(arg1, 1);
1968     print_syscall_epilogue(name);
1969 }
1970 #define print_statfs64  print_statfs
1971 #endif
1972
1973 #ifdef TARGET_NR_symlink
1974 static void
1975 print_symlink(const struct syscallname *name,
1976     abi_long arg0, abi_long arg1, abi_long arg2,
1977     abi_long arg3, abi_long arg4, abi_long arg5)
1978 {
1979     print_syscall_prologue(name);
1980     print_string(arg0, 0);
1981     print_string(arg1, 1);
1982     print_syscall_epilogue(name);
1983 }
1984 #endif
1985
1986 #ifdef TARGET_NR_symlinkat
1987 static void
1988 print_symlinkat(const struct syscallname *name,
1989     abi_long arg0, abi_long arg1, abi_long arg2,
1990     abi_long arg3, abi_long arg4, abi_long arg5)
1991 {
1992     print_syscall_prologue(name);
1993     print_string(arg0, 0);
1994     print_at_dirfd(arg1, 0);
1995     print_string(arg2, 1);
1996     print_syscall_epilogue(name);
1997 }
1998 #endif
1999
2000 #ifdef TARGET_NR_mount
2001 static void
2002 print_mount(const struct syscallname *name,
2003     abi_long arg0, abi_long arg1, abi_long arg2,
2004     abi_long arg3, abi_long arg4, abi_long arg5)
2005 {
2006     print_syscall_prologue(name);
2007     print_string(arg0, 0);
2008     print_string(arg1, 0);
2009     print_string(arg2, 0);
2010     print_flags(mount_flags, arg3, 0);
2011     print_pointer(arg4, 1);
2012     print_syscall_epilogue(name);
2013 }
2014 #endif
2015
2016 #ifdef TARGET_NR_umount
2017 static void
2018 print_umount(const struct syscallname *name,
2019     abi_long arg0, abi_long arg1, abi_long arg2,
2020     abi_long arg3, abi_long arg4, abi_long arg5)
2021 {
2022     print_syscall_prologue(name);
2023     print_string(arg0, 1);
2024     print_syscall_epilogue(name);
2025 }
2026 #endif
2027
2028 #ifdef TARGET_NR_umount2
2029 static void
2030 print_umount2(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_string(arg0, 0);
2036     print_flags(umount2_flags, arg1, 1);
2037     print_syscall_epilogue(name);
2038 }
2039 #endif
2040
2041 #ifdef TARGET_NR_unlink
2042 static void
2043 print_unlink(const struct syscallname *name,
2044     abi_long arg0, abi_long arg1, abi_long arg2,
2045     abi_long arg3, abi_long arg4, abi_long arg5)
2046 {
2047     print_syscall_prologue(name);
2048     print_string(arg0, 1);
2049     print_syscall_epilogue(name);
2050 }
2051 #endif
2052
2053 #ifdef TARGET_NR_unlinkat
2054 static void
2055 print_unlinkat(const struct syscallname *name,
2056     abi_long arg0, abi_long arg1, abi_long arg2,
2057     abi_long arg3, abi_long arg4, abi_long arg5)
2058 {
2059     print_syscall_prologue(name);
2060     print_at_dirfd(arg0, 0);
2061     print_string(arg1, 0);
2062     print_flags(unlinkat_flags, arg2, 1);
2063     print_syscall_epilogue(name);
2064 }
2065 #endif
2066
2067 #ifdef TARGET_NR_utime
2068 static void
2069 print_utime(const struct syscallname *name,
2070     abi_long arg0, abi_long arg1, abi_long arg2,
2071     abi_long arg3, abi_long arg4, abi_long arg5)
2072 {
2073     print_syscall_prologue(name);
2074     print_string(arg0, 0);
2075     print_pointer(arg1, 1);
2076     print_syscall_epilogue(name);
2077 }
2078 #endif
2079
2080 #ifdef TARGET_NR_utimes
2081 static void
2082 print_utimes(const struct syscallname *name,
2083     abi_long arg0, abi_long arg1, abi_long arg2,
2084     abi_long arg3, abi_long arg4, abi_long arg5)
2085 {
2086     print_syscall_prologue(name);
2087     print_string(arg0, 0);
2088     print_pointer(arg1, 1);
2089     print_syscall_epilogue(name);
2090 }
2091 #endif
2092
2093 #ifdef TARGET_NR_utimensat
2094 static void
2095 print_utimensat(const struct syscallname *name,
2096     abi_long arg0, abi_long arg1, abi_long arg2,
2097     abi_long arg3, abi_long arg4, abi_long arg5)
2098 {
2099     print_syscall_prologue(name);
2100     print_at_dirfd(arg0, 0);
2101     print_string(arg1, 0);
2102     print_pointer(arg2, 0);
2103     print_flags(at_file_flags, arg3, 1);
2104     print_syscall_epilogue(name);
2105 }
2106 #endif
2107
2108 #if defined(TARGET_NR_mmap) || defined(TARGET_NR_mmap2)
2109 static void
2110 print_mmap(const struct syscallname *name,
2111     abi_long arg0, abi_long arg1, abi_long arg2,
2112     abi_long arg3, abi_long arg4, abi_long arg5)
2113 {
2114     print_syscall_prologue(name);
2115     print_pointer(arg0, 0);
2116     print_raw_param("%d", arg1, 0);
2117     print_flags(mmap_prot_flags, arg2, 0);
2118     print_flags(mmap_flags, arg3, 0);
2119     print_raw_param("%d", arg4, 0);
2120     print_raw_param("%#x", arg5, 1);
2121     print_syscall_epilogue(name);
2122 }
2123 #define print_mmap2     print_mmap
2124 #endif
2125
2126 #ifdef TARGET_NR_mprotect
2127 static void
2128 print_mprotect(const struct syscallname *name,
2129     abi_long arg0, abi_long arg1, abi_long arg2,
2130     abi_long arg3, abi_long arg4, abi_long arg5)
2131 {
2132     print_syscall_prologue(name);
2133     print_pointer(arg0, 0);
2134     print_raw_param("%d", arg1, 0);
2135     print_flags(mmap_prot_flags, arg2, 1);
2136     print_syscall_epilogue(name);
2137 }
2138 #endif
2139
2140 #ifdef TARGET_NR_munmap
2141 static void
2142 print_munmap(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     print_syscall_prologue(name);
2147     print_pointer(arg0, 0);
2148     print_raw_param("%d", arg1, 1);
2149     print_syscall_epilogue(name);
2150 }
2151 #endif
2152
2153 #ifdef TARGET_NR_futex
2154 static void print_futex_op(abi_long tflag, int last)
2155 {
2156 #define print_op(val) \
2157 if( cmd == val ) { \
2158     gemu_log(#val); \
2159     return; \
2160 }
2161
2162     int cmd = (int)tflag;
2163 #ifdef FUTEX_PRIVATE_FLAG
2164     if (cmd & FUTEX_PRIVATE_FLAG) {
2165         gemu_log("FUTEX_PRIVATE_FLAG|");
2166         cmd &= ~FUTEX_PRIVATE_FLAG;
2167     }
2168 #endif
2169 #ifdef FUTEX_CLOCK_REALTIME
2170     if (cmd & FUTEX_CLOCK_REALTIME) {
2171         gemu_log("FUTEX_CLOCK_REALTIME|");
2172         cmd &= ~FUTEX_CLOCK_REALTIME;
2173     }
2174 #endif
2175     print_op(FUTEX_WAIT)
2176     print_op(FUTEX_WAKE)
2177     print_op(FUTEX_FD)
2178     print_op(FUTEX_REQUEUE)
2179     print_op(FUTEX_CMP_REQUEUE)
2180     print_op(FUTEX_WAKE_OP)
2181     print_op(FUTEX_LOCK_PI)
2182     print_op(FUTEX_UNLOCK_PI)
2183     print_op(FUTEX_TRYLOCK_PI)
2184 #ifdef FUTEX_WAIT_BITSET
2185     print_op(FUTEX_WAIT_BITSET)
2186 #endif
2187 #ifdef FUTEX_WAKE_BITSET
2188     print_op(FUTEX_WAKE_BITSET)
2189 #endif
2190     /* unknown values */
2191     gemu_log("%d",cmd);
2192 }
2193
2194 static void
2195 print_futex(const struct syscallname *name,
2196     abi_long arg0, abi_long arg1, abi_long arg2,
2197     abi_long arg3, abi_long arg4, abi_long arg5)
2198 {
2199     print_syscall_prologue(name);
2200     print_pointer(arg0, 0);
2201     print_futex_op(arg1, 0);
2202     print_raw_param(",%d", arg2, 0);
2203     print_pointer(arg3, 0); /* struct timespec */
2204     print_pointer(arg4, 0);
2205     print_raw_param("%d", arg4, 1);
2206     print_syscall_epilogue(name);
2207 }
2208 #endif
2209
2210 #ifdef TARGET_NR_kill
2211 static void
2212 print_kill(const struct syscallname *name,
2213     abi_long arg0, abi_long arg1, abi_long arg2,
2214     abi_long arg3, abi_long arg4, abi_long arg5)
2215 {
2216     print_syscall_prologue(name);
2217     print_raw_param("%d", arg0, 0);
2218     print_signal(arg1, 1);
2219     print_syscall_epilogue(name);
2220 }
2221 #endif
2222
2223 /*
2224  * An array of all of the syscalls we know about
2225  */
2226
2227 static const struct syscallname scnames[] = {
2228 #include "strace.list"
2229 };
2230
2231 static int nsyscalls = ARRAY_SIZE(scnames);
2232
2233 /*
2234  * The public interface to this module.
2235  */
2236 void
2237 print_syscall(int num,
2238               abi_long arg1, abi_long arg2, abi_long arg3,
2239               abi_long arg4, abi_long arg5, abi_long arg6)
2240 {
2241     int i;
2242     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 ")";
2243
2244     gemu_log("%d ", getpid() );
2245
2246     for(i=0;i<nsyscalls;i++)
2247         if( scnames[i].nr == num ) {
2248             if( scnames[i].call != NULL ) {
2249                 scnames[i].call(&scnames[i],arg1,arg2,arg3,arg4,arg5,arg6);
2250             } else {
2251                 /* XXX: this format system is broken because it uses
2252                    host types and host pointers for strings */
2253                 if( scnames[i].format != NULL )
2254                     format = scnames[i].format;
2255                 gemu_log(format,scnames[i].name, arg1,arg2,arg3,arg4,arg5,arg6);
2256             }
2257             return;
2258         }
2259     gemu_log("Unknown syscall %d\n", num);
2260 }
2261
2262
2263 void
2264 print_syscall_ret(int num, abi_long ret)
2265 {
2266     int i;
2267     const char *errstr = NULL;
2268
2269     for(i=0;i<nsyscalls;i++)
2270         if( scnames[i].nr == num ) {
2271             if( scnames[i].result != NULL ) {
2272                 scnames[i].result(&scnames[i],ret);
2273             } else {
2274                 if (ret < 0) {
2275                     errstr = target_strerror(-ret);
2276                 }
2277                 if (errstr) {
2278                     gemu_log(" = -1 errno=" TARGET_ABI_FMT_ld " (%s)\n",
2279                              -ret, errstr);
2280                 } else {
2281                     gemu_log(" = " TARGET_ABI_FMT_ld "\n", ret);
2282                 }
2283             }
2284             break;
2285         }
2286 }
2287
2288 void print_taken_signal(int target_signum, const target_siginfo_t *tinfo)
2289 {
2290     /* Print the strace output for a signal being taken:
2291      * --- SIGSEGV {si_signo=SIGSEGV, si_code=SI_KERNEL, si_addr=0} ---
2292      */
2293     gemu_log("--- ");
2294     print_signal(target_signum, 1);
2295     gemu_log(" ");
2296     print_siginfo(tinfo);
2297     gemu_log(" ---\n");
2298 }
This page took 0.14587 seconds and 4 git commands to generate.