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