]> git.proxmox.com Git - mirror_qemu.git/blob - linux-user/strace.c
a0e45b55d1fd14a12f8c93480d1e23a455e5d08e
[mirror_qemu.git] / linux-user / strace.c
1 #include "qemu/osdep.h"
2 #include <sys/ipc.h>
3 #include <sys/msg.h>
4 #include <sys/sem.h>
5 #include <sys/shm.h>
6 #include <sys/select.h>
7 #include <sys/mount.h>
8 #include <arpa/inet.h>
9 #include <netinet/tcp.h>
10 #include <linux/if_packet.h>
11 #include <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 /* special meanings of adjtimex()' non-negative return values */
581 #define TARGET_TIME_OK 0 /* clock synchronized, no leap second */
582 #define TARGET_TIME_INS 1 /* insert leap second */
583 #define TARGET_TIME_DEL 2 /* delete leap second */
584 #define TARGET_TIME_OOP 3 /* leap second in progress */
585 #define TARGET_TIME_WAIT 4 /* leap second has occurred */
586 #define TARGET_TIME_ERROR 5 /* clock not synchronized */
587 static void
588 print_syscall_ret_adjtimex(const struct syscallname *name, abi_long ret)
589 {
590 const char *errstr = NULL;
591
592 gemu_log(" = ");
593 if (ret < 0) {
594 gemu_log("-1 errno=%d", errno);
595 errstr = target_strerror(-ret);
596 if (errstr) {
597 gemu_log(" (%s)", errstr);
598 }
599 } else {
600 gemu_log(TARGET_ABI_FMT_ld, ret);
601 switch (ret) {
602 case TARGET_TIME_OK:
603 gemu_log(" TIME_OK (clock synchronized, no leap second)");
604 break;
605 case TARGET_TIME_INS:
606 gemu_log(" TIME_INS (insert leap second)");
607 break;
608 case TARGET_TIME_DEL:
609 gemu_log(" TIME_DEL (delete leap second)");
610 break;
611 case TARGET_TIME_OOP:
612 gemu_log(" TIME_OOP (leap second in progress)");
613 break;
614 case TARGET_TIME_WAIT:
615 gemu_log(" TIME_WAIT (leap second has occurred)");
616 break;
617 case TARGET_TIME_ERROR:
618 gemu_log(" TIME_ERROR (clock not synchronized)");
619 break;
620 }
621 }
622
623 gemu_log("\n");
624 }
625
626 UNUSED static struct flags access_flags[] = {
627 FLAG_GENERIC(F_OK),
628 FLAG_GENERIC(R_OK),
629 FLAG_GENERIC(W_OK),
630 FLAG_GENERIC(X_OK),
631 FLAG_END,
632 };
633
634 UNUSED static struct flags at_file_flags[] = {
635 #ifdef AT_EACCESS
636 FLAG_GENERIC(AT_EACCESS),
637 #endif
638 #ifdef AT_SYMLINK_NOFOLLOW
639 FLAG_GENERIC(AT_SYMLINK_NOFOLLOW),
640 #endif
641 FLAG_END,
642 };
643
644 UNUSED static struct flags unlinkat_flags[] = {
645 #ifdef AT_REMOVEDIR
646 FLAG_GENERIC(AT_REMOVEDIR),
647 #endif
648 FLAG_END,
649 };
650
651 UNUSED static struct flags mode_flags[] = {
652 FLAG_GENERIC(S_IFSOCK),
653 FLAG_GENERIC(S_IFLNK),
654 FLAG_GENERIC(S_IFREG),
655 FLAG_GENERIC(S_IFBLK),
656 FLAG_GENERIC(S_IFDIR),
657 FLAG_GENERIC(S_IFCHR),
658 FLAG_GENERIC(S_IFIFO),
659 FLAG_END,
660 };
661
662 UNUSED static struct flags open_access_flags[] = {
663 FLAG_TARGET(O_RDONLY),
664 FLAG_TARGET(O_WRONLY),
665 FLAG_TARGET(O_RDWR),
666 FLAG_END,
667 };
668
669 UNUSED static struct flags open_flags[] = {
670 FLAG_TARGET(O_APPEND),
671 FLAG_TARGET(O_CREAT),
672 FLAG_TARGET(O_DIRECTORY),
673 FLAG_TARGET(O_EXCL),
674 FLAG_TARGET(O_LARGEFILE),
675 FLAG_TARGET(O_NOCTTY),
676 FLAG_TARGET(O_NOFOLLOW),
677 FLAG_TARGET(O_NONBLOCK), /* also O_NDELAY */
678 FLAG_TARGET(O_DSYNC),
679 FLAG_TARGET(__O_SYNC),
680 FLAG_TARGET(O_TRUNC),
681 #ifdef O_DIRECT
682 FLAG_TARGET(O_DIRECT),
683 #endif
684 #ifdef O_NOATIME
685 FLAG_TARGET(O_NOATIME),
686 #endif
687 #ifdef O_CLOEXEC
688 FLAG_TARGET(O_CLOEXEC),
689 #endif
690 #ifdef O_PATH
691 FLAG_TARGET(O_PATH),
692 #endif
693 FLAG_END,
694 };
695
696 UNUSED static struct flags mount_flags[] = {
697 #ifdef MS_BIND
698 FLAG_GENERIC(MS_BIND),
699 #endif
700 #ifdef MS_DIRSYNC
701 FLAG_GENERIC(MS_DIRSYNC),
702 #endif
703 FLAG_GENERIC(MS_MANDLOCK),
704 #ifdef MS_MOVE
705 FLAG_GENERIC(MS_MOVE),
706 #endif
707 FLAG_GENERIC(MS_NOATIME),
708 FLAG_GENERIC(MS_NODEV),
709 FLAG_GENERIC(MS_NODIRATIME),
710 FLAG_GENERIC(MS_NOEXEC),
711 FLAG_GENERIC(MS_NOSUID),
712 FLAG_GENERIC(MS_RDONLY),
713 #ifdef MS_RELATIME
714 FLAG_GENERIC(MS_RELATIME),
715 #endif
716 FLAG_GENERIC(MS_REMOUNT),
717 FLAG_GENERIC(MS_SYNCHRONOUS),
718 FLAG_END,
719 };
720
721 UNUSED static struct flags umount2_flags[] = {
722 #ifdef MNT_FORCE
723 FLAG_GENERIC(MNT_FORCE),
724 #endif
725 #ifdef MNT_DETACH
726 FLAG_GENERIC(MNT_DETACH),
727 #endif
728 #ifdef MNT_EXPIRE
729 FLAG_GENERIC(MNT_EXPIRE),
730 #endif
731 FLAG_END,
732 };
733
734 UNUSED static struct flags mmap_prot_flags[] = {
735 FLAG_GENERIC(PROT_NONE),
736 FLAG_GENERIC(PROT_EXEC),
737 FLAG_GENERIC(PROT_READ),
738 FLAG_GENERIC(PROT_WRITE),
739 FLAG_TARGET(PROT_SEM),
740 FLAG_GENERIC(PROT_GROWSDOWN),
741 FLAG_GENERIC(PROT_GROWSUP),
742 FLAG_END,
743 };
744
745 UNUSED static struct flags mmap_flags[] = {
746 FLAG_TARGET(MAP_SHARED),
747 FLAG_TARGET(MAP_PRIVATE),
748 FLAG_TARGET(MAP_ANONYMOUS),
749 FLAG_TARGET(MAP_DENYWRITE),
750 FLAG_TARGET(MAP_FIXED),
751 FLAG_TARGET(MAP_GROWSDOWN),
752 FLAG_TARGET(MAP_EXECUTABLE),
753 #ifdef MAP_LOCKED
754 FLAG_TARGET(MAP_LOCKED),
755 #endif
756 #ifdef MAP_NONBLOCK
757 FLAG_TARGET(MAP_NONBLOCK),
758 #endif
759 FLAG_TARGET(MAP_NORESERVE),
760 #ifdef MAP_POPULATE
761 FLAG_TARGET(MAP_POPULATE),
762 #endif
763 #ifdef TARGET_MAP_UNINITIALIZED
764 FLAG_TARGET(MAP_UNINITIALIZED),
765 #endif
766 FLAG_END,
767 };
768
769 UNUSED static struct flags clone_flags[] = {
770 FLAG_GENERIC(CLONE_VM),
771 FLAG_GENERIC(CLONE_FS),
772 FLAG_GENERIC(CLONE_FILES),
773 FLAG_GENERIC(CLONE_SIGHAND),
774 FLAG_GENERIC(CLONE_PTRACE),
775 FLAG_GENERIC(CLONE_VFORK),
776 FLAG_GENERIC(CLONE_PARENT),
777 FLAG_GENERIC(CLONE_THREAD),
778 FLAG_GENERIC(CLONE_NEWNS),
779 FLAG_GENERIC(CLONE_SYSVSEM),
780 FLAG_GENERIC(CLONE_SETTLS),
781 FLAG_GENERIC(CLONE_PARENT_SETTID),
782 FLAG_GENERIC(CLONE_CHILD_CLEARTID),
783 FLAG_GENERIC(CLONE_DETACHED),
784 FLAG_GENERIC(CLONE_UNTRACED),
785 FLAG_GENERIC(CLONE_CHILD_SETTID),
786 #if defined(CLONE_NEWUTS)
787 FLAG_GENERIC(CLONE_NEWUTS),
788 #endif
789 #if defined(CLONE_NEWIPC)
790 FLAG_GENERIC(CLONE_NEWIPC),
791 #endif
792 #if defined(CLONE_NEWUSER)
793 FLAG_GENERIC(CLONE_NEWUSER),
794 #endif
795 #if defined(CLONE_NEWPID)
796 FLAG_GENERIC(CLONE_NEWPID),
797 #endif
798 #if defined(CLONE_NEWNET)
799 FLAG_GENERIC(CLONE_NEWNET),
800 #endif
801 #if defined(CLONE_IO)
802 FLAG_GENERIC(CLONE_IO),
803 #endif
804 FLAG_END,
805 };
806
807 UNUSED static struct flags msg_flags[] = {
808 /* send */
809 FLAG_GENERIC(MSG_CONFIRM),
810 FLAG_GENERIC(MSG_DONTROUTE),
811 FLAG_GENERIC(MSG_DONTWAIT),
812 FLAG_GENERIC(MSG_EOR),
813 FLAG_GENERIC(MSG_MORE),
814 FLAG_GENERIC(MSG_NOSIGNAL),
815 FLAG_GENERIC(MSG_OOB),
816 /* recv */
817 FLAG_GENERIC(MSG_CMSG_CLOEXEC),
818 FLAG_GENERIC(MSG_ERRQUEUE),
819 FLAG_GENERIC(MSG_PEEK),
820 FLAG_GENERIC(MSG_TRUNC),
821 FLAG_GENERIC(MSG_WAITALL),
822 /* recvmsg */
823 FLAG_GENERIC(MSG_CTRUNC),
824 FLAG_END,
825 };
826
827 /*
828 * print_xxx utility functions. These are used to print syscall
829 * parameters in certain format. All of these have parameter
830 * named 'last'. This parameter is used to add comma to output
831 * when last == 0.
832 */
833
834 static const char *
835 get_comma(int last)
836 {
837 return ((last) ? "" : ",");
838 }
839
840 static void
841 print_flags(const struct flags *f, abi_long flags, int last)
842 {
843 const char *sep = "";
844 int n;
845
846 if ((flags == 0) && (f->f_value == 0)) {
847 gemu_log("%s%s", f->f_string, get_comma(last));
848 return;
849 }
850 for (n = 0; f->f_string != NULL; f++) {
851 if ((f->f_value != 0) && ((flags & f->f_value) == f->f_value)) {
852 gemu_log("%s%s", sep, f->f_string);
853 flags &= ~f->f_value;
854 sep = "|";
855 n++;
856 }
857 }
858
859 if (n > 0) {
860 /* print rest of the flags as numeric */
861 if (flags != 0) {
862 gemu_log("%s%#x%s", sep, (unsigned int)flags, get_comma(last));
863 } else {
864 gemu_log("%s", get_comma(last));
865 }
866 } else {
867 /* no string version of flags found, print them in hex then */
868 gemu_log("%#x%s", (unsigned int)flags, get_comma(last));
869 }
870 }
871
872 static void
873 print_at_dirfd(abi_long dirfd, int last)
874 {
875 #ifdef AT_FDCWD
876 if (dirfd == AT_FDCWD) {
877 gemu_log("AT_FDCWD%s", get_comma(last));
878 return;
879 }
880 #endif
881 gemu_log("%d%s", (int)dirfd, get_comma(last));
882 }
883
884 static void
885 print_file_mode(abi_long mode, int last)
886 {
887 const char *sep = "";
888 const struct flags *m;
889
890 for (m = &mode_flags[0]; m->f_string != NULL; m++) {
891 if ((m->f_value & mode) == m->f_value) {
892 gemu_log("%s%s", m->f_string, sep);
893 sep = "|";
894 mode &= ~m->f_value;
895 break;
896 }
897 }
898
899 mode &= ~S_IFMT;
900 /* print rest of the mode as octal */
901 if (mode != 0)
902 gemu_log("%s%#o", sep, (unsigned int)mode);
903
904 gemu_log("%s", get_comma(last));
905 }
906
907 static void
908 print_open_flags(abi_long flags, int last)
909 {
910 print_flags(open_access_flags, flags & TARGET_O_ACCMODE, 1);
911 flags &= ~TARGET_O_ACCMODE;
912 if (flags == 0) {
913 gemu_log("%s", get_comma(last));
914 return;
915 }
916 gemu_log("|");
917 print_flags(open_flags, flags, last);
918 }
919
920 static void
921 print_syscall_prologue(const struct syscallname *sc)
922 {
923 gemu_log("%s(", sc->name);
924 }
925
926 /*ARGSUSED*/
927 static void
928 print_syscall_epilogue(const struct syscallname *sc)
929 {
930 (void)sc;
931 gemu_log(")");
932 }
933
934 static void
935 print_string(abi_long addr, int last)
936 {
937 char *s;
938
939 if ((s = lock_user_string(addr)) != NULL) {
940 gemu_log("\"%s\"%s", s, get_comma(last));
941 unlock_user(s, addr, 0);
942 } else {
943 /* can't get string out of it, so print it as pointer */
944 print_pointer(addr, last);
945 }
946 }
947
948 #define MAX_PRINT_BUF 40
949 static void
950 print_buf(abi_long addr, abi_long len, int last)
951 {
952 uint8_t *s;
953 int i;
954
955 s = lock_user(VERIFY_READ, addr, len, 1);
956 if (s) {
957 gemu_log("\"");
958 for (i = 0; i < MAX_PRINT_BUF && i < len; i++) {
959 if (isprint(s[i])) {
960 gemu_log("%c", s[i]);
961 } else {
962 gemu_log("\\%o", s[i]);
963 }
964 }
965 gemu_log("\"");
966 if (i != len) {
967 gemu_log("...");
968 }
969 if (!last) {
970 gemu_log(",");
971 }
972 unlock_user(s, addr, 0);
973 } else {
974 print_pointer(addr, last);
975 }
976 }
977
978 /*
979 * Prints out raw parameter using given format. Caller needs
980 * to do byte swapping if needed.
981 */
982 static void
983 print_raw_param(const char *fmt, abi_long param, int last)
984 {
985 char format[64];
986
987 (void) snprintf(format, sizeof (format), "%s%s", fmt, get_comma(last));
988 gemu_log(format, param);
989 }
990
991 static void
992 print_pointer(abi_long p, int last)
993 {
994 if (p == 0)
995 gemu_log("NULL%s", get_comma(last));
996 else
997 gemu_log("0x" TARGET_ABI_FMT_lx "%s", p, get_comma(last));
998 }
999
1000 /*
1001 * Reads 32-bit (int) number from guest address space from
1002 * address 'addr' and prints it.
1003 */
1004 static void
1005 print_number(abi_long addr, int last)
1006 {
1007 if (addr == 0) {
1008 gemu_log("NULL%s", get_comma(last));
1009 } else {
1010 int num;
1011
1012 get_user_s32(num, addr);
1013 gemu_log("[%d]%s", num, get_comma(last));
1014 }
1015 }
1016
1017 static void
1018 print_timeval(abi_ulong tv_addr, int last)
1019 {
1020 if( tv_addr ) {
1021 struct target_timeval *tv;
1022
1023 tv = lock_user(VERIFY_READ, tv_addr, sizeof(*tv), 1);
1024 if (!tv)
1025 return;
1026 gemu_log("{" TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld "}%s",
1027 tswapal(tv->tv_sec), tswapal(tv->tv_usec), get_comma(last));
1028 unlock_user(tv, tv_addr, 0);
1029 } else
1030 gemu_log("NULL%s", get_comma(last));
1031 }
1032
1033 #undef UNUSED
1034
1035 #ifdef TARGET_NR_accept
1036 static void
1037 print_accept(const struct syscallname *name,
1038 abi_long arg0, abi_long arg1, abi_long arg2,
1039 abi_long arg3, abi_long arg4, abi_long arg5)
1040 {
1041 print_syscall_prologue(name);
1042 print_raw_param("%d", arg0, 0);
1043 print_pointer(arg1, 0);
1044 print_number(arg2, 1);
1045 print_syscall_epilogue(name);
1046 }
1047 #endif
1048
1049 #ifdef TARGET_NR_access
1050 static void
1051 print_access(const struct syscallname *name,
1052 abi_long arg0, abi_long arg1, abi_long arg2,
1053 abi_long arg3, abi_long arg4, abi_long arg5)
1054 {
1055 print_syscall_prologue(name);
1056 print_string(arg0, 0);
1057 print_flags(access_flags, arg1, 1);
1058 print_syscall_epilogue(name);
1059 }
1060 #endif
1061
1062 #ifdef TARGET_NR_brk
1063 static void
1064 print_brk(const struct syscallname *name,
1065 abi_long arg0, abi_long arg1, abi_long arg2,
1066 abi_long arg3, abi_long arg4, abi_long arg5)
1067 {
1068 print_syscall_prologue(name);
1069 print_pointer(arg0, 1);
1070 print_syscall_epilogue(name);
1071 }
1072 #endif
1073
1074 #ifdef TARGET_NR_chdir
1075 static void
1076 print_chdir(const struct syscallname *name,
1077 abi_long arg0, abi_long arg1, abi_long arg2,
1078 abi_long arg3, abi_long arg4, abi_long arg5)
1079 {
1080 print_syscall_prologue(name);
1081 print_string(arg0, 1);
1082 print_syscall_epilogue(name);
1083 }
1084 #endif
1085
1086 #ifdef TARGET_NR_chmod
1087 static void
1088 print_chmod(const struct syscallname *name,
1089 abi_long arg0, abi_long arg1, abi_long arg2,
1090 abi_long arg3, abi_long arg4, abi_long arg5)
1091 {
1092 print_syscall_prologue(name);
1093 print_string(arg0, 0);
1094 print_file_mode(arg1, 1);
1095 print_syscall_epilogue(name);
1096 }
1097 #endif
1098
1099 #ifdef TARGET_NR_clone
1100 static void do_print_clone(unsigned int flags, abi_ulong newsp,
1101 abi_ulong parent_tidptr, target_ulong newtls,
1102 abi_ulong child_tidptr)
1103 {
1104 print_flags(clone_flags, flags, 0);
1105 print_raw_param("child_stack=0x" TARGET_ABI_FMT_lx, newsp, 0);
1106 print_raw_param("parent_tidptr=0x" TARGET_ABI_FMT_lx, parent_tidptr, 0);
1107 print_raw_param("tls=0x" TARGET_ABI_FMT_lx, newtls, 0);
1108 print_raw_param("child_tidptr=0x" TARGET_ABI_FMT_lx, child_tidptr, 1);
1109 }
1110
1111 static void
1112 print_clone(const struct syscallname *name,
1113 abi_long arg1, abi_long arg2, abi_long arg3,
1114 abi_long arg4, abi_long arg5, abi_long arg6)
1115 {
1116 print_syscall_prologue(name);
1117 #if defined(TARGET_MICROBLAZE)
1118 do_print_clone(arg1, arg2, arg4, arg6, arg5);
1119 #elif defined(TARGET_CLONE_BACKWARDS)
1120 do_print_clone(arg1, arg2, arg3, arg4, arg5);
1121 #elif defined(TARGET_CLONE_BACKWARDS2)
1122 do_print_clone(arg2, arg1, arg3, arg5, arg4);
1123 #else
1124 do_print_clone(arg1, arg2, arg3, arg5, arg4);
1125 #endif
1126 print_syscall_epilogue(name);
1127 }
1128 #endif
1129
1130 #ifdef TARGET_NR_creat
1131 static void
1132 print_creat(const struct syscallname *name,
1133 abi_long arg0, abi_long arg1, abi_long arg2,
1134 abi_long arg3, abi_long arg4, abi_long arg5)
1135 {
1136 print_syscall_prologue(name);
1137 print_string(arg0, 0);
1138 print_file_mode(arg1, 1);
1139 print_syscall_epilogue(name);
1140 }
1141 #endif
1142
1143 #ifdef TARGET_NR_execv
1144 static void
1145 print_execv(const struct syscallname *name,
1146 abi_long arg0, abi_long arg1, abi_long arg2,
1147 abi_long arg3, abi_long arg4, abi_long arg5)
1148 {
1149 print_syscall_prologue(name);
1150 print_string(arg0, 0);
1151 print_raw_param("0x" TARGET_ABI_FMT_lx, arg1, 1);
1152 print_syscall_epilogue(name);
1153 }
1154 #endif
1155
1156 #ifdef TARGET_NR_faccessat
1157 static void
1158 print_faccessat(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_at_dirfd(arg0, 0);
1164 print_string(arg1, 0);
1165 print_flags(access_flags, arg2, 0);
1166 print_flags(at_file_flags, arg3, 1);
1167 print_syscall_epilogue(name);
1168 }
1169 #endif
1170
1171 #ifdef TARGET_NR_fchmodat
1172 static void
1173 print_fchmodat(const struct syscallname *name,
1174 abi_long arg0, abi_long arg1, abi_long arg2,
1175 abi_long arg3, abi_long arg4, abi_long arg5)
1176 {
1177 print_syscall_prologue(name);
1178 print_at_dirfd(arg0, 0);
1179 print_string(arg1, 0);
1180 print_file_mode(arg2, 0);
1181 print_flags(at_file_flags, arg3, 1);
1182 print_syscall_epilogue(name);
1183 }
1184 #endif
1185
1186 #ifdef TARGET_NR_fchownat
1187 static void
1188 print_fchownat(const struct syscallname *name,
1189 abi_long arg0, abi_long arg1, abi_long arg2,
1190 abi_long arg3, abi_long arg4, abi_long arg5)
1191 {
1192 print_syscall_prologue(name);
1193 print_at_dirfd(arg0, 0);
1194 print_string(arg1, 0);
1195 print_raw_param("%d", arg2, 0);
1196 print_raw_param("%d", arg3, 0);
1197 print_flags(at_file_flags, arg4, 1);
1198 print_syscall_epilogue(name);
1199 }
1200 #endif
1201
1202 #if defined(TARGET_NR_fcntl) || defined(TARGET_NR_fcntl64)
1203 static void
1204 print_fcntl(const struct syscallname *name,
1205 abi_long arg0, abi_long arg1, abi_long arg2,
1206 abi_long arg3, abi_long arg4, abi_long arg5)
1207 {
1208 print_syscall_prologue(name);
1209 print_raw_param("%d", arg0, 0);
1210 switch(arg1) {
1211 case TARGET_F_DUPFD:
1212 gemu_log("F_DUPFD,");
1213 print_raw_param(TARGET_ABI_FMT_ld, arg2, 1);
1214 break;
1215 case TARGET_F_GETFD:
1216 gemu_log("F_GETFD");
1217 break;
1218 case TARGET_F_SETFD:
1219 gemu_log("F_SETFD,");
1220 print_raw_param(TARGET_ABI_FMT_ld, arg2, 1);
1221 break;
1222 case TARGET_F_GETFL:
1223 gemu_log("F_GETFL");
1224 break;
1225 case TARGET_F_SETFL:
1226 gemu_log("F_SETFL,");
1227 print_open_flags(arg2, 1);
1228 break;
1229 case TARGET_F_GETLK:
1230 gemu_log("F_GETLK,");
1231 print_pointer(arg2, 1);
1232 break;
1233 case TARGET_F_SETLK:
1234 gemu_log("F_SETLK,");
1235 print_pointer(arg2, 1);
1236 break;
1237 case TARGET_F_SETLKW:
1238 gemu_log("F_SETLKW,");
1239 print_pointer(arg2, 1);
1240 break;
1241 case TARGET_F_GETOWN:
1242 gemu_log("F_GETOWN");
1243 break;
1244 case TARGET_F_SETOWN:
1245 gemu_log("F_SETOWN,");
1246 print_raw_param(TARGET_ABI_FMT_ld, arg2, 0);
1247 break;
1248 case TARGET_F_GETSIG:
1249 gemu_log("F_GETSIG");
1250 break;
1251 case TARGET_F_SETSIG:
1252 gemu_log("F_SETSIG,");
1253 print_raw_param(TARGET_ABI_FMT_ld, arg2, 0);
1254 break;
1255 #if TARGET_ABI_BITS == 32
1256 case TARGET_F_GETLK64:
1257 gemu_log("F_GETLK64,");
1258 print_pointer(arg2, 1);
1259 break;
1260 case TARGET_F_SETLK64:
1261 gemu_log("F_SETLK64,");
1262 print_pointer(arg2, 1);
1263 break;
1264 case TARGET_F_SETLKW64:
1265 gemu_log("F_SETLKW64,");
1266 print_pointer(arg2, 1);
1267 break;
1268 #endif
1269 case TARGET_F_SETLEASE:
1270 gemu_log("F_SETLEASE,");
1271 print_raw_param(TARGET_ABI_FMT_ld, arg2, 0);
1272 break;
1273 case TARGET_F_GETLEASE:
1274 gemu_log("F_GETLEASE");
1275 break;
1276 case TARGET_F_SETPIPE_SZ:
1277 gemu_log("F_SETPIPE_SZ,");
1278 print_raw_param(TARGET_ABI_FMT_ld, arg2, 1);
1279 break;
1280 case TARGET_F_GETPIPE_SZ:
1281 gemu_log("F_GETPIPE_SZ");
1282 break;
1283 case TARGET_F_DUPFD_CLOEXEC:
1284 gemu_log("F_DUPFD_CLOEXEC,");
1285 print_raw_param(TARGET_ABI_FMT_ld, arg2, 1);
1286 break;
1287 case TARGET_F_NOTIFY:
1288 gemu_log("F_NOTIFY,");
1289 print_raw_param(TARGET_ABI_FMT_ld, arg2, 0);
1290 break;
1291 default:
1292 print_raw_param(TARGET_ABI_FMT_ld, arg1, 0);
1293 print_pointer(arg2, 1);
1294 break;
1295 }
1296 print_syscall_epilogue(name);
1297 }
1298 #define print_fcntl64 print_fcntl
1299 #endif
1300
1301
1302 #ifdef TARGET_NR_futimesat
1303 static void
1304 print_futimesat(const struct syscallname *name,
1305 abi_long arg0, abi_long arg1, abi_long arg2,
1306 abi_long arg3, abi_long arg4, abi_long arg5)
1307 {
1308 print_syscall_prologue(name);
1309 print_at_dirfd(arg0, 0);
1310 print_string(arg1, 0);
1311 print_timeval(arg2, 0);
1312 print_timeval(arg2 + sizeof (struct target_timeval), 1);
1313 print_syscall_epilogue(name);
1314 }
1315 #endif
1316
1317 #ifdef TARGET_NR_link
1318 static void
1319 print_link(const struct syscallname *name,
1320 abi_long arg0, abi_long arg1, abi_long arg2,
1321 abi_long arg3, abi_long arg4, abi_long arg5)
1322 {
1323 print_syscall_prologue(name);
1324 print_string(arg0, 0);
1325 print_string(arg1, 1);
1326 print_syscall_epilogue(name);
1327 }
1328 #endif
1329
1330 #ifdef TARGET_NR_linkat
1331 static void
1332 print_linkat(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_at_dirfd(arg0, 0);
1338 print_string(arg1, 0);
1339 print_at_dirfd(arg2, 0);
1340 print_string(arg3, 0);
1341 print_flags(at_file_flags, arg4, 1);
1342 print_syscall_epilogue(name);
1343 }
1344 #endif
1345
1346 #ifdef TARGET_NR__llseek
1347 static void
1348 print__llseek(const struct syscallname *name,
1349 abi_long arg0, abi_long arg1, abi_long arg2,
1350 abi_long arg3, abi_long arg4, abi_long arg5)
1351 {
1352 const char *whence = "UNKNOWN";
1353 print_syscall_prologue(name);
1354 print_raw_param("%d", arg0, 0);
1355 print_raw_param("%ld", arg1, 0);
1356 print_raw_param("%ld", arg2, 0);
1357 print_pointer(arg3, 0);
1358 switch(arg4) {
1359 case SEEK_SET: whence = "SEEK_SET"; break;
1360 case SEEK_CUR: whence = "SEEK_CUR"; break;
1361 case SEEK_END: whence = "SEEK_END"; break;
1362 }
1363 gemu_log("%s",whence);
1364 print_syscall_epilogue(name);
1365 }
1366 #endif
1367
1368 #if defined(TARGET_NR_socket)
1369 static void
1370 print_socket(const struct syscallname *name,
1371 abi_long arg0, abi_long arg1, abi_long arg2,
1372 abi_long arg3, abi_long arg4, abi_long arg5)
1373 {
1374 abi_ulong domain = arg0, type = arg1, protocol = arg2;
1375
1376 print_syscall_prologue(name);
1377 print_socket_domain(domain);
1378 gemu_log(",");
1379 print_socket_type(type);
1380 gemu_log(",");
1381 if (domain == AF_PACKET ||
1382 (domain == AF_INET && type == TARGET_SOCK_PACKET)) {
1383 protocol = tswap16(protocol);
1384 }
1385 print_socket_protocol(domain, type, protocol);
1386 print_syscall_epilogue(name);
1387 }
1388
1389 #endif
1390
1391 #if defined(TARGET_NR_socketcall)
1392
1393 #define get_user_ualx(x, gaddr, idx) \
1394 get_user_ual(x, (gaddr) + (idx) * sizeof(abi_long))
1395
1396 static void do_print_socket(const char *name, abi_long arg1)
1397 {
1398 abi_ulong domain, type, protocol;
1399
1400 get_user_ualx(domain, arg1, 0);
1401 get_user_ualx(type, arg1, 1);
1402 get_user_ualx(protocol, arg1, 2);
1403 gemu_log("%s(", name);
1404 print_socket_domain(domain);
1405 gemu_log(",");
1406 print_socket_type(type);
1407 gemu_log(",");
1408 if (domain == AF_PACKET ||
1409 (domain == AF_INET && type == TARGET_SOCK_PACKET)) {
1410 protocol = tswap16(protocol);
1411 }
1412 print_socket_protocol(domain, type, protocol);
1413 gemu_log(")");
1414 }
1415
1416 static void do_print_sockaddr(const char *name, abi_long arg1)
1417 {
1418 abi_ulong sockfd, addr, addrlen;
1419
1420 get_user_ualx(sockfd, arg1, 0);
1421 get_user_ualx(addr, arg1, 1);
1422 get_user_ualx(addrlen, arg1, 2);
1423
1424 gemu_log("%s(", name);
1425 print_raw_param(TARGET_ABI_FMT_ld, sockfd, 0);
1426 print_sockaddr(addr, addrlen);
1427 gemu_log(")");
1428 }
1429
1430 static void do_print_listen(const char *name, abi_long arg1)
1431 {
1432 abi_ulong sockfd, backlog;
1433
1434 get_user_ualx(sockfd, arg1, 0);
1435 get_user_ualx(backlog, arg1, 1);
1436
1437 gemu_log("%s(", name);
1438 print_raw_param(TARGET_ABI_FMT_ld, sockfd, 0);
1439 print_raw_param(TARGET_ABI_FMT_ld, backlog, 1);
1440 gemu_log(")");
1441 }
1442
1443 static void do_print_socketpair(const char *name, abi_long arg1)
1444 {
1445 abi_ulong domain, type, protocol, tab;
1446
1447 get_user_ualx(domain, arg1, 0);
1448 get_user_ualx(type, arg1, 1);
1449 get_user_ualx(protocol, arg1, 2);
1450 get_user_ualx(tab, arg1, 3);
1451
1452 gemu_log("%s(", name);
1453 print_socket_domain(domain);
1454 gemu_log(",");
1455 print_socket_type(type);
1456 gemu_log(",");
1457 print_socket_protocol(domain, type, protocol);
1458 gemu_log(",");
1459 print_raw_param(TARGET_ABI_FMT_lx, tab, 1);
1460 gemu_log(")");
1461 }
1462
1463 static void do_print_sendrecv(const char *name, abi_long arg1)
1464 {
1465 abi_ulong sockfd, msg, len, flags;
1466
1467 get_user_ualx(sockfd, arg1, 0);
1468 get_user_ualx(msg, arg1, 1);
1469 get_user_ualx(len, arg1, 2);
1470 get_user_ualx(flags, arg1, 3);
1471
1472 gemu_log("%s(", name);
1473 print_raw_param(TARGET_ABI_FMT_ld, sockfd, 0);
1474 print_buf(msg, len, 0);
1475 print_raw_param(TARGET_ABI_FMT_ld, len, 0);
1476 print_flags(msg_flags, flags, 1);
1477 gemu_log(")");
1478 }
1479
1480 static void do_print_msgaddr(const char *name, abi_long arg1)
1481 {
1482 abi_ulong sockfd, msg, len, flags, addr, addrlen;
1483
1484 get_user_ualx(sockfd, arg1, 0);
1485 get_user_ualx(msg, arg1, 1);
1486 get_user_ualx(len, arg1, 2);
1487 get_user_ualx(flags, arg1, 3);
1488 get_user_ualx(addr, arg1, 4);
1489 get_user_ualx(addrlen, arg1, 5);
1490
1491 gemu_log("%s(", name);
1492 print_raw_param(TARGET_ABI_FMT_ld, sockfd, 0);
1493 print_buf(msg, len, 0);
1494 print_raw_param(TARGET_ABI_FMT_ld, len, 0);
1495 print_flags(msg_flags, flags, 0);
1496 print_sockaddr(addr, addrlen);
1497 gemu_log(")");
1498 }
1499
1500 static void do_print_shutdown(const char *name, abi_long arg1)
1501 {
1502 abi_ulong sockfd, how;
1503
1504 get_user_ualx(sockfd, arg1, 0);
1505 get_user_ualx(how, arg1, 1);
1506
1507 gemu_log("shutdown(");
1508 print_raw_param(TARGET_ABI_FMT_ld, sockfd, 0);
1509 switch (how) {
1510 case SHUT_RD:
1511 gemu_log("SHUT_RD");
1512 break;
1513 case SHUT_WR:
1514 gemu_log("SHUT_WR");
1515 break;
1516 case SHUT_RDWR:
1517 gemu_log("SHUT_RDWR");
1518 break;
1519 default:
1520 print_raw_param(TARGET_ABI_FMT_ld, how, 1);
1521 break;
1522 }
1523 gemu_log(")");
1524 }
1525
1526 static void do_print_msg(const char *name, abi_long arg1)
1527 {
1528 abi_ulong sockfd, msg, flags;
1529
1530 get_user_ualx(sockfd, arg1, 0);
1531 get_user_ualx(msg, arg1, 1);
1532 get_user_ualx(flags, arg1, 2);
1533
1534 gemu_log("%s(", name);
1535 print_raw_param(TARGET_ABI_FMT_ld, sockfd, 0);
1536 print_pointer(msg, 0);
1537 print_flags(msg_flags, flags, 1);
1538 gemu_log(")");
1539 }
1540
1541 static void do_print_sockopt(const char *name, abi_long arg1)
1542 {
1543 abi_ulong sockfd, level, optname, optval, optlen;
1544
1545 get_user_ualx(sockfd, arg1, 0);
1546 get_user_ualx(level, arg1, 1);
1547 get_user_ualx(optname, arg1, 2);
1548 get_user_ualx(optval, arg1, 3);
1549 get_user_ualx(optlen, arg1, 4);
1550
1551 gemu_log("%s(", name);
1552 print_raw_param(TARGET_ABI_FMT_ld, sockfd, 0);
1553 switch (level) {
1554 case SOL_TCP:
1555 gemu_log("SOL_TCP,");
1556 print_raw_param(TARGET_ABI_FMT_ld, optname, 0);
1557 print_pointer(optval, 0);
1558 break;
1559 case SOL_IP:
1560 gemu_log("SOL_IP,");
1561 print_raw_param(TARGET_ABI_FMT_ld, optname, 0);
1562 print_pointer(optval, 0);
1563 break;
1564 case SOL_RAW:
1565 gemu_log("SOL_RAW,");
1566 print_raw_param(TARGET_ABI_FMT_ld, optname, 0);
1567 print_pointer(optval, 0);
1568 break;
1569 case TARGET_SOL_SOCKET:
1570 gemu_log("SOL_SOCKET,");
1571 switch (optname) {
1572 case TARGET_SO_DEBUG:
1573 gemu_log("SO_DEBUG,");
1574 print_optint:
1575 print_number(optval, 0);
1576 break;
1577 case TARGET_SO_REUSEADDR:
1578 gemu_log("SO_REUSEADDR,");
1579 goto print_optint;
1580 case TARGET_SO_TYPE:
1581 gemu_log("SO_TYPE,");
1582 goto print_optint;
1583 case TARGET_SO_ERROR:
1584 gemu_log("SO_ERROR,");
1585 goto print_optint;
1586 case TARGET_SO_DONTROUTE:
1587 gemu_log("SO_DONTROUTE,");
1588 goto print_optint;
1589 case TARGET_SO_BROADCAST:
1590 gemu_log("SO_BROADCAST,");
1591 goto print_optint;
1592 case TARGET_SO_SNDBUF:
1593 gemu_log("SO_SNDBUF,");
1594 goto print_optint;
1595 case TARGET_SO_RCVBUF:
1596 gemu_log("SO_RCVBUF,");
1597 goto print_optint;
1598 case TARGET_SO_KEEPALIVE:
1599 gemu_log("SO_KEEPALIVE,");
1600 goto print_optint;
1601 case TARGET_SO_OOBINLINE:
1602 gemu_log("SO_OOBINLINE,");
1603 goto print_optint;
1604 case TARGET_SO_NO_CHECK:
1605 gemu_log("SO_NO_CHECK,");
1606 goto print_optint;
1607 case TARGET_SO_PRIORITY:
1608 gemu_log("SO_PRIORITY,");
1609 goto print_optint;
1610 case TARGET_SO_BSDCOMPAT:
1611 gemu_log("SO_BSDCOMPAT,");
1612 goto print_optint;
1613 case TARGET_SO_PASSCRED:
1614 gemu_log("SO_PASSCRED,");
1615 goto print_optint;
1616 case TARGET_SO_TIMESTAMP:
1617 gemu_log("SO_TIMESTAMP,");
1618 goto print_optint;
1619 case TARGET_SO_RCVLOWAT:
1620 gemu_log("SO_RCVLOWAT,");
1621 goto print_optint;
1622 case TARGET_SO_RCVTIMEO:
1623 gemu_log("SO_RCVTIMEO,");
1624 print_timeval(optval, 0);
1625 break;
1626 case TARGET_SO_SNDTIMEO:
1627 gemu_log("SO_SNDTIMEO,");
1628 print_timeval(optval, 0);
1629 break;
1630 case TARGET_SO_ATTACH_FILTER: {
1631 struct target_sock_fprog *fprog;
1632
1633 gemu_log("SO_ATTACH_FILTER,");
1634
1635 if (lock_user_struct(VERIFY_READ, fprog, optval, 0)) {
1636 struct target_sock_filter *filter;
1637 gemu_log("{");
1638 if (lock_user_struct(VERIFY_READ, filter,
1639 tswapal(fprog->filter), 0)) {
1640 int i;
1641 for (i = 0; i < tswap16(fprog->len) - 1; i++) {
1642 gemu_log("[%d]{0x%x,%d,%d,0x%x},",
1643 i, tswap16(filter[i].code),
1644 filter[i].jt, filter[i].jf,
1645 tswap32(filter[i].k));
1646 }
1647 gemu_log("[%d]{0x%x,%d,%d,0x%x}",
1648 i, tswap16(filter[i].code),
1649 filter[i].jt, filter[i].jf,
1650 tswap32(filter[i].k));
1651 } else {
1652 gemu_log(TARGET_ABI_FMT_lx, tswapal(fprog->filter));
1653 }
1654 gemu_log(",%d},", tswap16(fprog->len));
1655 unlock_user(fprog, optval, 0);
1656 } else {
1657 print_pointer(optval, 0);
1658 }
1659 break;
1660 }
1661 default:
1662 print_raw_param(TARGET_ABI_FMT_ld, optname, 0);
1663 print_pointer(optval, 0);
1664 break;
1665 }
1666 break;
1667 default:
1668 print_raw_param(TARGET_ABI_FMT_ld, level, 0);
1669 print_raw_param(TARGET_ABI_FMT_ld, optname, 0);
1670 print_pointer(optval, 0);
1671 break;
1672 }
1673 print_raw_param(TARGET_ABI_FMT_ld, optlen, 1);
1674 gemu_log(")");
1675 }
1676
1677 #define PRINT_SOCKOP(name, func) \
1678 [TARGET_SYS_##name] = { #name, func }
1679
1680 static struct {
1681 const char *name;
1682 void (*print)(const char *, abi_long);
1683 } scall[] = {
1684 PRINT_SOCKOP(SOCKET, do_print_socket),
1685 PRINT_SOCKOP(BIND, do_print_sockaddr),
1686 PRINT_SOCKOP(CONNECT, do_print_sockaddr),
1687 PRINT_SOCKOP(LISTEN, do_print_listen),
1688 PRINT_SOCKOP(ACCEPT, do_print_sockaddr),
1689 PRINT_SOCKOP(GETSOCKNAME, do_print_sockaddr),
1690 PRINT_SOCKOP(GETPEERNAME, do_print_sockaddr),
1691 PRINT_SOCKOP(SOCKETPAIR, do_print_socketpair),
1692 PRINT_SOCKOP(SEND, do_print_sendrecv),
1693 PRINT_SOCKOP(RECV, do_print_sendrecv),
1694 PRINT_SOCKOP(SENDTO, do_print_msgaddr),
1695 PRINT_SOCKOP(RECVFROM, do_print_msgaddr),
1696 PRINT_SOCKOP(SHUTDOWN, do_print_shutdown),
1697 PRINT_SOCKOP(SETSOCKOPT, do_print_sockopt),
1698 PRINT_SOCKOP(GETSOCKOPT, do_print_sockopt),
1699 PRINT_SOCKOP(SENDMSG, do_print_msg),
1700 PRINT_SOCKOP(RECVMSG, do_print_msg),
1701 PRINT_SOCKOP(ACCEPT4, NULL),
1702 PRINT_SOCKOP(RECVMMSG, NULL),
1703 PRINT_SOCKOP(SENDMMSG, NULL),
1704 };
1705
1706 static void
1707 print_socketcall(const struct syscallname *name,
1708 abi_long arg0, abi_long arg1, abi_long arg2,
1709 abi_long arg3, abi_long arg4, abi_long arg5)
1710 {
1711 if (arg0 >= 0 && arg0 < ARRAY_SIZE(scall) && scall[arg0].print) {
1712 scall[arg0].print(scall[arg0].name, arg1);
1713 return;
1714 }
1715 print_syscall_prologue(name);
1716 print_raw_param(TARGET_ABI_FMT_ld, arg0, 0);
1717 print_raw_param(TARGET_ABI_FMT_ld, arg1, 0);
1718 print_raw_param(TARGET_ABI_FMT_ld, arg2, 0);
1719 print_raw_param(TARGET_ABI_FMT_ld, arg3, 0);
1720 print_raw_param(TARGET_ABI_FMT_ld, arg4, 0);
1721 print_raw_param(TARGET_ABI_FMT_ld, arg5, 0);
1722 print_syscall_epilogue(name);
1723 }
1724 #endif
1725
1726 #if defined(TARGET_NR_stat) || defined(TARGET_NR_stat64) || \
1727 defined(TARGET_NR_lstat) || defined(TARGET_NR_lstat64)
1728 static void
1729 print_stat(const struct syscallname *name,
1730 abi_long arg0, abi_long arg1, abi_long arg2,
1731 abi_long arg3, abi_long arg4, abi_long arg5)
1732 {
1733 print_syscall_prologue(name);
1734 print_string(arg0, 0);
1735 print_pointer(arg1, 1);
1736 print_syscall_epilogue(name);
1737 }
1738 #define print_lstat print_stat
1739 #define print_stat64 print_stat
1740 #define print_lstat64 print_stat
1741 #endif
1742
1743 #if defined(TARGET_NR_fstat) || defined(TARGET_NR_fstat64)
1744 static void
1745 print_fstat(const struct syscallname *name,
1746 abi_long arg0, abi_long arg1, abi_long arg2,
1747 abi_long arg3, abi_long arg4, abi_long arg5)
1748 {
1749 print_syscall_prologue(name);
1750 print_raw_param("%d", arg0, 0);
1751 print_pointer(arg1, 1);
1752 print_syscall_epilogue(name);
1753 }
1754 #define print_fstat64 print_fstat
1755 #endif
1756
1757 #ifdef TARGET_NR_mkdir
1758 static void
1759 print_mkdir(const struct syscallname *name,
1760 abi_long arg0, abi_long arg1, abi_long arg2,
1761 abi_long arg3, abi_long arg4, abi_long arg5)
1762 {
1763 print_syscall_prologue(name);
1764 print_string(arg0, 0);
1765 print_file_mode(arg1, 1);
1766 print_syscall_epilogue(name);
1767 }
1768 #endif
1769
1770 #ifdef TARGET_NR_mkdirat
1771 static void
1772 print_mkdirat(const struct syscallname *name,
1773 abi_long arg0, abi_long arg1, abi_long arg2,
1774 abi_long arg3, abi_long arg4, abi_long arg5)
1775 {
1776 print_syscall_prologue(name);
1777 print_at_dirfd(arg0, 0);
1778 print_string(arg1, 0);
1779 print_file_mode(arg2, 1);
1780 print_syscall_epilogue(name);
1781 }
1782 #endif
1783
1784 #ifdef TARGET_NR_rmdir
1785 static void
1786 print_rmdir(const struct syscallname *name,
1787 abi_long arg0, abi_long arg1, abi_long arg2,
1788 abi_long arg3, abi_long arg4, abi_long arg5)
1789 {
1790 print_syscall_prologue(name);
1791 print_string(arg0, 0);
1792 print_syscall_epilogue(name);
1793 }
1794 #endif
1795
1796 #ifdef TARGET_NR_rt_sigaction
1797 static void
1798 print_rt_sigaction(const struct syscallname *name,
1799 abi_long arg0, abi_long arg1, abi_long arg2,
1800 abi_long arg3, abi_long arg4, abi_long arg5)
1801 {
1802 print_syscall_prologue(name);
1803 print_signal(arg0, 0);
1804 print_pointer(arg1, 0);
1805 print_pointer(arg2, 1);
1806 print_syscall_epilogue(name);
1807 }
1808 #endif
1809
1810 #ifdef TARGET_NR_rt_sigprocmask
1811 static void
1812 print_rt_sigprocmask(const struct syscallname *name,
1813 abi_long arg0, abi_long arg1, abi_long arg2,
1814 abi_long arg3, abi_long arg4, abi_long arg5)
1815 {
1816 const char *how = "UNKNOWN";
1817 print_syscall_prologue(name);
1818 switch(arg0) {
1819 case TARGET_SIG_BLOCK: how = "SIG_BLOCK"; break;
1820 case TARGET_SIG_UNBLOCK: how = "SIG_UNBLOCK"; break;
1821 case TARGET_SIG_SETMASK: how = "SIG_SETMASK"; break;
1822 }
1823 gemu_log("%s,",how);
1824 print_pointer(arg1, 0);
1825 print_pointer(arg2, 1);
1826 print_syscall_epilogue(name);
1827 }
1828 #endif
1829
1830 #ifdef TARGET_NR_mknod
1831 static void
1832 print_mknod(const struct syscallname *name,
1833 abi_long arg0, abi_long arg1, abi_long arg2,
1834 abi_long arg3, abi_long arg4, abi_long arg5)
1835 {
1836 int hasdev = (arg1 & (S_IFCHR|S_IFBLK));
1837
1838 print_syscall_prologue(name);
1839 print_string(arg0, 0);
1840 print_file_mode(arg1, (hasdev == 0));
1841 if (hasdev) {
1842 print_raw_param("makedev(%d", major(arg2), 0);
1843 print_raw_param("%d)", minor(arg2), 1);
1844 }
1845 print_syscall_epilogue(name);
1846 }
1847 #endif
1848
1849 #ifdef TARGET_NR_mknodat
1850 static void
1851 print_mknodat(const struct syscallname *name,
1852 abi_long arg0, abi_long arg1, abi_long arg2,
1853 abi_long arg3, abi_long arg4, abi_long arg5)
1854 {
1855 int hasdev = (arg2 & (S_IFCHR|S_IFBLK));
1856
1857 print_syscall_prologue(name);
1858 print_at_dirfd(arg0, 0);
1859 print_string(arg1, 0);
1860 print_file_mode(arg2, (hasdev == 0));
1861 if (hasdev) {
1862 print_raw_param("makedev(%d", major(arg3), 0);
1863 print_raw_param("%d)", minor(arg3), 1);
1864 }
1865 print_syscall_epilogue(name);
1866 }
1867 #endif
1868
1869 #ifdef TARGET_NR_mq_open
1870 static void
1871 print_mq_open(const struct syscallname *name,
1872 abi_long arg0, abi_long arg1, abi_long arg2,
1873 abi_long arg3, abi_long arg4, abi_long arg5)
1874 {
1875 int is_creat = (arg1 & TARGET_O_CREAT);
1876
1877 print_syscall_prologue(name);
1878 print_string(arg0, 0);
1879 print_open_flags(arg1, (is_creat == 0));
1880 if (is_creat) {
1881 print_file_mode(arg2, 0);
1882 print_pointer(arg3, 1);
1883 }
1884 print_syscall_epilogue(name);
1885 }
1886 #endif
1887
1888 #ifdef TARGET_NR_open
1889 static void
1890 print_open(const struct syscallname *name,
1891 abi_long arg0, abi_long arg1, abi_long arg2,
1892 abi_long arg3, abi_long arg4, abi_long arg5)
1893 {
1894 int is_creat = (arg1 & TARGET_O_CREAT);
1895
1896 print_syscall_prologue(name);
1897 print_string(arg0, 0);
1898 print_open_flags(arg1, (is_creat == 0));
1899 if (is_creat)
1900 print_file_mode(arg2, 1);
1901 print_syscall_epilogue(name);
1902 }
1903 #endif
1904
1905 #ifdef TARGET_NR_openat
1906 static void
1907 print_openat(const struct syscallname *name,
1908 abi_long arg0, abi_long arg1, abi_long arg2,
1909 abi_long arg3, abi_long arg4, abi_long arg5)
1910 {
1911 int is_creat = (arg2 & TARGET_O_CREAT);
1912
1913 print_syscall_prologue(name);
1914 print_at_dirfd(arg0, 0);
1915 print_string(arg1, 0);
1916 print_open_flags(arg2, (is_creat == 0));
1917 if (is_creat)
1918 print_file_mode(arg3, 1);
1919 print_syscall_epilogue(name);
1920 }
1921 #endif
1922
1923 #ifdef TARGET_NR_mq_unlink
1924 static void
1925 print_mq_unlink(const struct syscallname *name,
1926 abi_long arg0, abi_long arg1, abi_long arg2,
1927 abi_long arg3, abi_long arg4, abi_long arg5)
1928 {
1929 print_syscall_prologue(name);
1930 print_string(arg0, 1);
1931 print_syscall_epilogue(name);
1932 }
1933 #endif
1934
1935 #if defined(TARGET_NR_fstatat64) || defined(TARGET_NR_newfstatat)
1936 static void
1937 print_fstatat64(const struct syscallname *name,
1938 abi_long arg0, abi_long arg1, abi_long arg2,
1939 abi_long arg3, abi_long arg4, abi_long arg5)
1940 {
1941 print_syscall_prologue(name);
1942 print_at_dirfd(arg0, 0);
1943 print_string(arg1, 0);
1944 print_pointer(arg2, 0);
1945 print_flags(at_file_flags, arg3, 1);
1946 print_syscall_epilogue(name);
1947 }
1948 #define print_newfstatat print_fstatat64
1949 #endif
1950
1951 #ifdef TARGET_NR_readlink
1952 static void
1953 print_readlink(const struct syscallname *name,
1954 abi_long arg0, abi_long arg1, abi_long arg2,
1955 abi_long arg3, abi_long arg4, abi_long arg5)
1956 {
1957 print_syscall_prologue(name);
1958 print_string(arg0, 0);
1959 print_pointer(arg1, 0);
1960 print_raw_param("%u", arg2, 1);
1961 print_syscall_epilogue(name);
1962 }
1963 #endif
1964
1965 #ifdef TARGET_NR_readlinkat
1966 static void
1967 print_readlinkat(const struct syscallname *name,
1968 abi_long arg0, abi_long arg1, abi_long arg2,
1969 abi_long arg3, abi_long arg4, abi_long arg5)
1970 {
1971 print_syscall_prologue(name);
1972 print_at_dirfd(arg0, 0);
1973 print_string(arg1, 0);
1974 print_pointer(arg2, 0);
1975 print_raw_param("%u", arg3, 1);
1976 print_syscall_epilogue(name);
1977 }
1978 #endif
1979
1980 #ifdef TARGET_NR_rename
1981 static void
1982 print_rename(const struct syscallname *name,
1983 abi_long arg0, abi_long arg1, abi_long arg2,
1984 abi_long arg3, abi_long arg4, abi_long arg5)
1985 {
1986 print_syscall_prologue(name);
1987 print_string(arg0, 0);
1988 print_string(arg1, 1);
1989 print_syscall_epilogue(name);
1990 }
1991 #endif
1992
1993 #ifdef TARGET_NR_renameat
1994 static void
1995 print_renameat(const struct syscallname *name,
1996 abi_long arg0, abi_long arg1, abi_long arg2,
1997 abi_long arg3, abi_long arg4, abi_long arg5)
1998 {
1999 print_syscall_prologue(name);
2000 print_at_dirfd(arg0, 0);
2001 print_string(arg1, 0);
2002 print_at_dirfd(arg2, 0);
2003 print_string(arg3, 1);
2004 print_syscall_epilogue(name);
2005 }
2006 #endif
2007
2008 #ifdef TARGET_NR_statfs
2009 static void
2010 print_statfs(const struct syscallname *name,
2011 abi_long arg0, abi_long arg1, abi_long arg2,
2012 abi_long arg3, abi_long arg4, abi_long arg5)
2013 {
2014 print_syscall_prologue(name);
2015 print_string(arg0, 0);
2016 print_pointer(arg1, 1);
2017 print_syscall_epilogue(name);
2018 }
2019 #define print_statfs64 print_statfs
2020 #endif
2021
2022 #ifdef TARGET_NR_symlink
2023 static void
2024 print_symlink(const struct syscallname *name,
2025 abi_long arg0, abi_long arg1, abi_long arg2,
2026 abi_long arg3, abi_long arg4, abi_long arg5)
2027 {
2028 print_syscall_prologue(name);
2029 print_string(arg0, 0);
2030 print_string(arg1, 1);
2031 print_syscall_epilogue(name);
2032 }
2033 #endif
2034
2035 #ifdef TARGET_NR_symlinkat
2036 static void
2037 print_symlinkat(const struct syscallname *name,
2038 abi_long arg0, abi_long arg1, abi_long arg2,
2039 abi_long arg3, abi_long arg4, abi_long arg5)
2040 {
2041 print_syscall_prologue(name);
2042 print_string(arg0, 0);
2043 print_at_dirfd(arg1, 0);
2044 print_string(arg2, 1);
2045 print_syscall_epilogue(name);
2046 }
2047 #endif
2048
2049 #ifdef TARGET_NR_mount
2050 static void
2051 print_mount(const struct syscallname *name,
2052 abi_long arg0, abi_long arg1, abi_long arg2,
2053 abi_long arg3, abi_long arg4, abi_long arg5)
2054 {
2055 print_syscall_prologue(name);
2056 print_string(arg0, 0);
2057 print_string(arg1, 0);
2058 print_string(arg2, 0);
2059 print_flags(mount_flags, arg3, 0);
2060 print_pointer(arg4, 1);
2061 print_syscall_epilogue(name);
2062 }
2063 #endif
2064
2065 #ifdef TARGET_NR_umount
2066 static void
2067 print_umount(const struct syscallname *name,
2068 abi_long arg0, abi_long arg1, abi_long arg2,
2069 abi_long arg3, abi_long arg4, abi_long arg5)
2070 {
2071 print_syscall_prologue(name);
2072 print_string(arg0, 1);
2073 print_syscall_epilogue(name);
2074 }
2075 #endif
2076
2077 #ifdef TARGET_NR_umount2
2078 static void
2079 print_umount2(const struct syscallname *name,
2080 abi_long arg0, abi_long arg1, abi_long arg2,
2081 abi_long arg3, abi_long arg4, abi_long arg5)
2082 {
2083 print_syscall_prologue(name);
2084 print_string(arg0, 0);
2085 print_flags(umount2_flags, arg1, 1);
2086 print_syscall_epilogue(name);
2087 }
2088 #endif
2089
2090 #ifdef TARGET_NR_unlink
2091 static void
2092 print_unlink(const struct syscallname *name,
2093 abi_long arg0, abi_long arg1, abi_long arg2,
2094 abi_long arg3, abi_long arg4, abi_long arg5)
2095 {
2096 print_syscall_prologue(name);
2097 print_string(arg0, 1);
2098 print_syscall_epilogue(name);
2099 }
2100 #endif
2101
2102 #ifdef TARGET_NR_unlinkat
2103 static void
2104 print_unlinkat(const struct syscallname *name,
2105 abi_long arg0, abi_long arg1, abi_long arg2,
2106 abi_long arg3, abi_long arg4, abi_long arg5)
2107 {
2108 print_syscall_prologue(name);
2109 print_at_dirfd(arg0, 0);
2110 print_string(arg1, 0);
2111 print_flags(unlinkat_flags, arg2, 1);
2112 print_syscall_epilogue(name);
2113 }
2114 #endif
2115
2116 #ifdef TARGET_NR_utime
2117 static void
2118 print_utime(const struct syscallname *name,
2119 abi_long arg0, abi_long arg1, abi_long arg2,
2120 abi_long arg3, abi_long arg4, abi_long arg5)
2121 {
2122 print_syscall_prologue(name);
2123 print_string(arg0, 0);
2124 print_pointer(arg1, 1);
2125 print_syscall_epilogue(name);
2126 }
2127 #endif
2128
2129 #ifdef TARGET_NR_utimes
2130 static void
2131 print_utimes(const struct syscallname *name,
2132 abi_long arg0, abi_long arg1, abi_long arg2,
2133 abi_long arg3, abi_long arg4, abi_long arg5)
2134 {
2135 print_syscall_prologue(name);
2136 print_string(arg0, 0);
2137 print_pointer(arg1, 1);
2138 print_syscall_epilogue(name);
2139 }
2140 #endif
2141
2142 #ifdef TARGET_NR_utimensat
2143 static void
2144 print_utimensat(const struct syscallname *name,
2145 abi_long arg0, abi_long arg1, abi_long arg2,
2146 abi_long arg3, abi_long arg4, abi_long arg5)
2147 {
2148 print_syscall_prologue(name);
2149 print_at_dirfd(arg0, 0);
2150 print_string(arg1, 0);
2151 print_pointer(arg2, 0);
2152 print_flags(at_file_flags, arg3, 1);
2153 print_syscall_epilogue(name);
2154 }
2155 #endif
2156
2157 #if defined(TARGET_NR_mmap) || defined(TARGET_NR_mmap2)
2158 static void
2159 print_mmap(const struct syscallname *name,
2160 abi_long arg0, abi_long arg1, abi_long arg2,
2161 abi_long arg3, abi_long arg4, abi_long arg5)
2162 {
2163 print_syscall_prologue(name);
2164 print_pointer(arg0, 0);
2165 print_raw_param("%d", arg1, 0);
2166 print_flags(mmap_prot_flags, arg2, 0);
2167 print_flags(mmap_flags, arg3, 0);
2168 print_raw_param("%d", arg4, 0);
2169 print_raw_param("%#x", arg5, 1);
2170 print_syscall_epilogue(name);
2171 }
2172 #define print_mmap2 print_mmap
2173 #endif
2174
2175 #ifdef TARGET_NR_mprotect
2176 static void
2177 print_mprotect(const struct syscallname *name,
2178 abi_long arg0, abi_long arg1, abi_long arg2,
2179 abi_long arg3, abi_long arg4, abi_long arg5)
2180 {
2181 print_syscall_prologue(name);
2182 print_pointer(arg0, 0);
2183 print_raw_param("%d", arg1, 0);
2184 print_flags(mmap_prot_flags, arg2, 1);
2185 print_syscall_epilogue(name);
2186 }
2187 #endif
2188
2189 #ifdef TARGET_NR_munmap
2190 static void
2191 print_munmap(const struct syscallname *name,
2192 abi_long arg0, abi_long arg1, abi_long arg2,
2193 abi_long arg3, abi_long arg4, abi_long arg5)
2194 {
2195 print_syscall_prologue(name);
2196 print_pointer(arg0, 0);
2197 print_raw_param("%d", arg1, 1);
2198 print_syscall_epilogue(name);
2199 }
2200 #endif
2201
2202 #ifdef TARGET_NR_futex
2203 static void print_futex_op(abi_long tflag, int last)
2204 {
2205 #define print_op(val) \
2206 if( cmd == val ) { \
2207 gemu_log(#val); \
2208 return; \
2209 }
2210
2211 int cmd = (int)tflag;
2212 #ifdef FUTEX_PRIVATE_FLAG
2213 if (cmd & FUTEX_PRIVATE_FLAG) {
2214 gemu_log("FUTEX_PRIVATE_FLAG|");
2215 cmd &= ~FUTEX_PRIVATE_FLAG;
2216 }
2217 #endif
2218 #ifdef FUTEX_CLOCK_REALTIME
2219 if (cmd & FUTEX_CLOCK_REALTIME) {
2220 gemu_log("FUTEX_CLOCK_REALTIME|");
2221 cmd &= ~FUTEX_CLOCK_REALTIME;
2222 }
2223 #endif
2224 print_op(FUTEX_WAIT)
2225 print_op(FUTEX_WAKE)
2226 print_op(FUTEX_FD)
2227 print_op(FUTEX_REQUEUE)
2228 print_op(FUTEX_CMP_REQUEUE)
2229 print_op(FUTEX_WAKE_OP)
2230 print_op(FUTEX_LOCK_PI)
2231 print_op(FUTEX_UNLOCK_PI)
2232 print_op(FUTEX_TRYLOCK_PI)
2233 #ifdef FUTEX_WAIT_BITSET
2234 print_op(FUTEX_WAIT_BITSET)
2235 #endif
2236 #ifdef FUTEX_WAKE_BITSET
2237 print_op(FUTEX_WAKE_BITSET)
2238 #endif
2239 /* unknown values */
2240 gemu_log("%d",cmd);
2241 }
2242
2243 static void
2244 print_futex(const struct syscallname *name,
2245 abi_long arg0, abi_long arg1, abi_long arg2,
2246 abi_long arg3, abi_long arg4, abi_long arg5)
2247 {
2248 print_syscall_prologue(name);
2249 print_pointer(arg0, 0);
2250 print_futex_op(arg1, 0);
2251 print_raw_param(",%d", arg2, 0);
2252 print_pointer(arg3, 0); /* struct timespec */
2253 print_pointer(arg4, 0);
2254 print_raw_param("%d", arg4, 1);
2255 print_syscall_epilogue(name);
2256 }
2257 #endif
2258
2259 #ifdef TARGET_NR_kill
2260 static void
2261 print_kill(const struct syscallname *name,
2262 abi_long arg0, abi_long arg1, abi_long arg2,
2263 abi_long arg3, abi_long arg4, abi_long arg5)
2264 {
2265 print_syscall_prologue(name);
2266 print_raw_param("%d", arg0, 0);
2267 print_signal(arg1, 1);
2268 print_syscall_epilogue(name);
2269 }
2270 #endif
2271
2272 /*
2273 * An array of all of the syscalls we know about
2274 */
2275
2276 static const struct syscallname scnames[] = {
2277 #include "strace.list"
2278 };
2279
2280 static int nsyscalls = ARRAY_SIZE(scnames);
2281
2282 /*
2283 * The public interface to this module.
2284 */
2285 void
2286 print_syscall(int num,
2287 abi_long arg1, abi_long arg2, abi_long arg3,
2288 abi_long arg4, abi_long arg5, abi_long arg6)
2289 {
2290 int i;
2291 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 ")";
2292
2293 gemu_log("%d ", getpid() );
2294
2295 for(i=0;i<nsyscalls;i++)
2296 if( scnames[i].nr == num ) {
2297 if( scnames[i].call != NULL ) {
2298 scnames[i].call(&scnames[i],arg1,arg2,arg3,arg4,arg5,arg6);
2299 } else {
2300 /* XXX: this format system is broken because it uses
2301 host types and host pointers for strings */
2302 if( scnames[i].format != NULL )
2303 format = scnames[i].format;
2304 gemu_log(format,scnames[i].name, arg1,arg2,arg3,arg4,arg5,arg6);
2305 }
2306 return;
2307 }
2308 gemu_log("Unknown syscall %d\n", num);
2309 }
2310
2311
2312 void
2313 print_syscall_ret(int num, abi_long ret)
2314 {
2315 int i;
2316 const char *errstr = NULL;
2317
2318 for(i=0;i<nsyscalls;i++)
2319 if( scnames[i].nr == num ) {
2320 if( scnames[i].result != NULL ) {
2321 scnames[i].result(&scnames[i],ret);
2322 } else {
2323 if (ret < 0) {
2324 errstr = target_strerror(-ret);
2325 }
2326 if (errstr) {
2327 gemu_log(" = -1 errno=" TARGET_ABI_FMT_ld " (%s)\n",
2328 -ret, errstr);
2329 } else {
2330 gemu_log(" = " TARGET_ABI_FMT_ld "\n", ret);
2331 }
2332 }
2333 break;
2334 }
2335 }
2336
2337 void print_taken_signal(int target_signum, const target_siginfo_t *tinfo)
2338 {
2339 /* Print the strace output for a signal being taken:
2340 * --- SIGSEGV {si_signo=SIGSEGV, si_code=SI_KERNEL, si_addr=0} ---
2341 */
2342 gemu_log("--- ");
2343 print_signal(target_signum, 1);
2344 gemu_log(" ");
2345 print_siginfo(tinfo);
2346 gemu_log(" ---\n");
2347 }