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