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