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