]> git.proxmox.com Git - mirror_qemu.git/blame - linux-user/strace.c
minikconf: do not include variables from MINIKCONF_ARGS in config-all-devices.mak
[mirror_qemu.git] / linux-user / strace.c
CommitLineData
d39594e9 1#include "qemu/osdep.h"
33189d31
TS
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>
74d753ac 7#include <sys/mount.h>
fb3aabf3
LV
8#include <arpa/inet.h>
9#include <netinet/tcp.h>
10#include <linux/if_packet.h>
608e5592 11#include <sched.h>
33189d31
TS
12#include "qemu.h"
13
14int do_strace=0;
15
16struct syscallname {
17 int nr;
7ccfb2eb
BS
18 const char *name;
19 const char *format;
20 void (*call)(const struct syscallname *,
c16f9ed3
FB
21 abi_long, abi_long, abi_long,
22 abi_long, abi_long, abi_long);
7ccfb2eb 23 void (*result)(const struct syscallname *, abi_long);
33189d31
TS
24};
25
74d753ac
MW
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 */
42struct 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
54UNUSED static const char *get_comma(int);
55UNUSED static void print_pointer(abi_long, int);
56UNUSED static void print_flags(const struct flags *, abi_long, int);
57UNUSED static void print_at_dirfd(abi_long, int);
58UNUSED static void print_file_mode(abi_long, int);
59UNUSED static void print_open_flags(abi_long, int);
60UNUSED static void print_syscall_prologue(const struct syscallname *);
61UNUSED static void print_syscall_epilogue(const struct syscallname *);
62UNUSED static void print_string(abi_long, int);
fb3aabf3 63UNUSED static void print_buf(abi_long addr, abi_long len, int last);
74d753ac
MW
64UNUSED static void print_raw_param(const char *, abi_long, int);
65UNUSED static void print_timeval(abi_ulong, int);
66UNUSED static void print_number(abi_long, int);
608e5592 67UNUSED static void print_signal(abi_ulong, int);
fb3aabf3
LV
68UNUSED static void print_sockaddr(abi_ulong addr, abi_long addrlen);
69UNUSED static void print_socket_domain(int domain);
70UNUSED static void print_socket_type(int type);
71UNUSED static void print_socket_protocol(int domain, int type, int protocol);
74d753ac 72
33189d31
TS
73/*
74 * Utility functions
75 */
76static void
77print_ipc_cmd(int cmd)
78{
79#define output_cmd(val) \
80if( cmd == val ) { \
81 gemu_log(#val); \
82 return; \
83}
84
85 cmd &= 0xff;
86
87 /* General IPC commands */
88 output_cmd( IPC_RMID );
89 output_cmd( IPC_SET );
90 output_cmd( IPC_STAT );
91 output_cmd( IPC_INFO );
92 /* msgctl() commands */
33189d31
TS
93 output_cmd( MSG_STAT );
94 output_cmd( MSG_INFO );
33189d31
TS
95 /* shmctl() commands */
96 output_cmd( SHM_LOCK );
97 output_cmd( SHM_UNLOCK );
98 output_cmd( SHM_STAT );
99 output_cmd( SHM_INFO );
100 /* semctl() commands */
101 output_cmd( GETPID );
102 output_cmd( GETVAL );
103 output_cmd( GETALL );
104 output_cmd( GETNCNT );
105 output_cmd( GETZCNT );
106 output_cmd( SETVAL );
107 output_cmd( SETALL );
108 output_cmd( SEM_STAT );
109 output_cmd( SEM_INFO );
110 output_cmd( IPC_RMID );
111 output_cmd( IPC_RMID );
112 output_cmd( IPC_RMID );
113 output_cmd( IPC_RMID );
114 output_cmd( IPC_RMID );
115 output_cmd( IPC_RMID );
116 output_cmd( IPC_RMID );
117 output_cmd( IPC_RMID );
118 output_cmd( IPC_RMID );
119
120 /* Some value we don't recognize */
121 gemu_log("%d",cmd);
122}
123
608e5592
LV
124static void
125print_signal(abi_ulong arg, int last)
126{
127 const char *signal_name = NULL;
128 switch(arg) {
129 case TARGET_SIGHUP: signal_name = "SIGHUP"; break;
130 case TARGET_SIGINT: signal_name = "SIGINT"; break;
131 case TARGET_SIGQUIT: signal_name = "SIGQUIT"; break;
132 case TARGET_SIGILL: signal_name = "SIGILL"; break;
133 case TARGET_SIGABRT: signal_name = "SIGABRT"; break;
134 case TARGET_SIGFPE: signal_name = "SIGFPE"; break;
135 case TARGET_SIGKILL: signal_name = "SIGKILL"; break;
136 case TARGET_SIGSEGV: signal_name = "SIGSEGV"; break;
137 case TARGET_SIGPIPE: signal_name = "SIGPIPE"; break;
138 case TARGET_SIGALRM: signal_name = "SIGALRM"; break;
139 case TARGET_SIGTERM: signal_name = "SIGTERM"; break;
140 case TARGET_SIGUSR1: signal_name = "SIGUSR1"; break;
141 case TARGET_SIGUSR2: signal_name = "SIGUSR2"; break;
142 case TARGET_SIGCHLD: signal_name = "SIGCHLD"; break;
143 case TARGET_SIGCONT: signal_name = "SIGCONT"; break;
144 case TARGET_SIGSTOP: signal_name = "SIGSTOP"; break;
145 case TARGET_SIGTTIN: signal_name = "SIGTTIN"; break;
146 case TARGET_SIGTTOU: signal_name = "SIGTTOU"; break;
147 }
148 if (signal_name == NULL) {
abe20840 149 print_raw_param("%ld", arg, last);
608e5592
LV
150 return;
151 }
152 gemu_log("%s%s", signal_name, get_comma(last));
153}
154
0cb581d6
PM
155static void print_si_code(int arg)
156{
157 const char *codename = NULL;
158
159 switch (arg) {
160 case SI_USER:
161 codename = "SI_USER";
162 break;
163 case SI_KERNEL:
164 codename = "SI_KERNEL";
165 break;
166 case SI_QUEUE:
167 codename = "SI_QUEUE";
168 break;
169 case SI_TIMER:
170 codename = "SI_TIMER";
171 break;
172 case SI_MESGQ:
173 codename = "SI_MESGQ";
174 break;
175 case SI_ASYNCIO:
176 codename = "SI_ASYNCIO";
177 break;
178 case SI_SIGIO:
179 codename = "SI_SIGIO";
180 break;
181 case SI_TKILL:
182 codename = "SI_TKILL";
183 break;
184 default:
185 gemu_log("%d", arg);
186 return;
187 }
188 gemu_log("%s", codename);
189}
190
ba9fcea1
MS
191static void get_target_siginfo(target_siginfo_t *tinfo,
192 const target_siginfo_t *info)
193{
194 abi_ulong sival_ptr;
195
196 int sig;
197 int si_errno;
198 int si_code;
199 int si_type;
200
201 __get_user(sig, &info->si_signo);
202 __get_user(si_errno, &tinfo->si_errno);
203 __get_user(si_code, &info->si_code);
204
205 tinfo->si_signo = sig;
206 tinfo->si_errno = si_errno;
207 tinfo->si_code = si_code;
208
209 /* Ensure we don't leak random junk to the guest later */
210 memset(tinfo->_sifields._pad, 0, sizeof(tinfo->_sifields._pad));
211
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.
220 *
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.
225 */
226
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.
233 */
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;
268
269 si_type = QEMU_SI_RT;
270 break;
271 }
272 break;
273 }
274
275 tinfo->si_code = deposit32(si_code, 16, 16, si_type);
276}
277
0cb581d6
PM
278static void print_siginfo(const target_siginfo_t *tinfo)
279{
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.
285 */
286 int si_type = extract32(tinfo->si_code, 16, 16);
287 int si_code = sextract32(tinfo->si_code, 0, 16);
288
289 gemu_log("{si_signo=");
290 print_signal(tinfo->si_signo, 1);
291 gemu_log(", si_code=");
292 print_si_code(si_code);
293
294 switch (si_type) {
295 case QEMU_SI_KILL:
f196c370 296 gemu_log(", si_pid=%u, si_uid=%u",
0cb581d6
PM
297 (unsigned int)tinfo->_sifields._kill._pid,
298 (unsigned int)tinfo->_sifields._kill._uid);
299 break;
300 case QEMU_SI_TIMER:
f196c370 301 gemu_log(", si_timer1=%u, si_timer2=%u",
0cb581d6
PM
302 tinfo->_sifields._timer._timer1,
303 tinfo->_sifields._timer._timer2);
304 break;
305 case QEMU_SI_POLL:
f196c370 306 gemu_log(", si_band=%d, si_fd=%d",
0cb581d6
PM
307 tinfo->_sifields._sigpoll._band,
308 tinfo->_sifields._sigpoll._fd);
309 break;
310 case QEMU_SI_FAULT:
f196c370 311 gemu_log(", si_addr=");
0cb581d6
PM
312 print_pointer(tinfo->_sifields._sigfault._addr, 1);
313 break;
314 case QEMU_SI_CHLD:
f196c370 315 gemu_log(", si_pid=%u, si_uid=%u, si_status=%d"
0cb581d6
PM
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:
f196c370 325 gemu_log(", si_pid=%u, si_uid=%u, si_sigval=" TARGET_ABI_FMT_ld,
0cb581d6
PM
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();
332 }
333 gemu_log("}");
334}
335
fb3aabf3
LV
336static void
337print_sockaddr(abi_ulong addr, abi_long addrlen)
338{
339 struct target_sockaddr *sa;
340 int i;
341 int sa_family;
342
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]);
355 }
356 gemu_log("\"}");
357 break;
358 }
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;
368 }
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;
394 }
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;
399 }
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]);
404 }
405 gemu_log("%02x}", sa->sa_data[i]);
406 gemu_log("}");
407 break;
408 }
409 unlock_user(sa, addr, 0);
410 } else {
411 print_raw_param("0x"TARGET_ABI_FMT_lx, addr, 0);
412 }
413 gemu_log(", "TARGET_ABI_FMT_ld, addrlen);
414}
415
416static void
417print_socket_domain(int domain)
418{
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;
432 }
433}
434
435static void
436print_socket_type(int type)
437{
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;
457 }
458}
459
460static void
461print_socket_protocol(int domain, int type, int protocol)
462{
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);
471 }
472 return;
473 }
474
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;
491 }
492}
493
494
c16f9ed3 495#ifdef TARGET_NR__newselect
33189d31 496static void
c16f9ed3 497print_fdset(int n, abi_ulong target_fds_addr)
33189d31
TS
498{
499 int i;
500
501 gemu_log("[");
502 if( target_fds_addr ) {
579a97f7 503 abi_long *target_fds;
33189d31 504
579a97f7
FB
505 target_fds = lock_user(VERIFY_READ,
506 target_fds_addr,
507 sizeof(*target_fds)*(n / TARGET_ABI_BITS + 1),
508 1);
509
510 if (!target_fds)
33189d31
TS
511 return;
512
33189d31 513 for (i=n; i>=0; i--) {
cbb21eed 514 if ((tswapal(target_fds[i / TARGET_ABI_BITS]) >> (i & (TARGET_ABI_BITS - 1))) & 1)
33189d31
TS
515 gemu_log("%d,", i );
516 }
517 unlock_user(target_fds, target_fds_addr, 0);
518 }
519 gemu_log("]");
520}
c16f9ed3 521#endif
33189d31 522
38860a03
AM
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
537
538static void
539print_clockid(int clockid, int last)
540{
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;
581 }
582 gemu_log("%s", get_comma(last));
583}
584#endif
585
33189d31
TS
586/*
587 * Sysycall specific output functions
588 */
589
590/* select */
c16f9ed3 591#ifdef TARGET_NR__newselect
33189d31
TS
592static long newselect_arg1 = 0;
593static long newselect_arg2 = 0;
594static long newselect_arg3 = 0;
595static long newselect_arg4 = 0;
596static long newselect_arg5 = 0;
597
598static void
7ccfb2eb 599print_newselect(const struct syscallname *name,
c16f9ed3
FB
600 abi_long arg1, abi_long arg2, abi_long arg3,
601 abi_long arg4, abi_long arg5, abi_long arg6)
33189d31 602{
c16f9ed3 603 gemu_log("%s(" TARGET_ABI_FMT_ld ",", name->name, arg1);
33189d31
TS
604 print_fdset(arg1, arg2);
605 gemu_log(",");
606 print_fdset(arg1, arg3);
607 gemu_log(",");
608 print_fdset(arg1, arg4);
609 gemu_log(",");
74d753ac 610 print_timeval(arg5, 1);
33189d31
TS
611 gemu_log(")");
612
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;
619}
c16f9ed3 620#endif
33189d31 621
3e46b2ef 622#ifdef TARGET_NR_semctl
33189d31 623static void
7ccfb2eb 624print_semctl(const struct syscallname *name,
c16f9ed3
FB
625 abi_long arg1, abi_long arg2, abi_long arg3,
626 abi_long arg4, abi_long arg5, abi_long arg6)
33189d31 627{
c16f9ed3 628 gemu_log("%s(" TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld ",", name->name, arg1, arg2);
33189d31 629 print_ipc_cmd(arg3);
c16f9ed3 630 gemu_log(",0x" TARGET_ABI_FMT_lx ")", arg4);
33189d31 631}
3e46b2ef 632#endif
33189d31
TS
633
634static void
7ccfb2eb 635print_execve(const struct syscallname *name,
c16f9ed3
FB
636 abi_long arg1, abi_long arg2, abi_long arg3,
637 abi_long arg4, abi_long arg5, abi_long arg6)
33189d31 638{
c16f9ed3 639 abi_ulong arg_ptr_addr;
33189d31
TS
640 char *s;
641
579a97f7 642 if (!(s = lock_user_string(arg1)))
33189d31 643 return;
33189d31
TS
644 gemu_log("%s(\"%s\",{", name->name, s);
645 unlock_user(s, arg1, 0);
646
c16f9ed3 647 for (arg_ptr_addr = arg2; ; arg_ptr_addr += sizeof(abi_ulong)) {
98448f58 648 abi_ulong *arg_ptr, arg_addr;
33189d31 649
7d37435b 650 arg_ptr = lock_user(VERIFY_READ, arg_ptr_addr, sizeof(abi_ulong), 1);
579a97f7 651 if (!arg_ptr)
33189d31 652 return;
cbb21eed 653 arg_addr = tswapal(*arg_ptr);
7d37435b 654 unlock_user(arg_ptr, arg_ptr_addr, 0);
33189d31
TS
655 if (!arg_addr)
656 break;
579a97f7
FB
657 if ((s = lock_user_string(arg_addr))) {
658 gemu_log("\"%s\",", s);
98448f58 659 unlock_user(s, arg_addr, 0);
579a97f7 660 }
33189d31
TS
661 }
662
663 gemu_log("NULL})");
664}
665
c16f9ed3 666#ifdef TARGET_NR_ipc
33189d31 667static void
7ccfb2eb 668print_ipc(const struct syscallname *name,
c16f9ed3
FB
669 abi_long arg1, abi_long arg2, abi_long arg3,
670 abi_long arg4, abi_long arg5, abi_long arg6)
33189d31
TS
671{
672 switch(arg1) {
673 case IPCOP_semctl:
7ccfb2eb
BS
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);
33189d31
TS
677 break;
678 default:
c16f9ed3 679 gemu_log("%s(" TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld ")",
33189d31
TS
680 name->name, arg1, arg2, arg3, arg4);
681 }
682}
c16f9ed3 683#endif
33189d31
TS
684
685/*
686 * Variants for the return value output function
687 */
688
689static void
7ccfb2eb 690print_syscall_ret_addr(const struct syscallname *name, abi_long ret)
33189d31 691{
7dcdaeaf 692 const char *errstr = NULL;
962b289e 693
2a7e1245
PM
694 if (ret < 0) {
695 errstr = target_strerror(-ret);
962b289e 696 }
2a7e1245
PM
697 if (errstr) {
698 gemu_log(" = -1 errno=%d (%s)\n", (int)-ret, errstr);
33189d31 699 } else {
29fa23e7 700 gemu_log(" = 0x" TARGET_ABI_FMT_lx "\n", ret);
33189d31
TS
701 }
702}
703
f3e3285d 704#if 0 /* currently unused */
33189d31 705static void
c16f9ed3 706print_syscall_ret_raw(struct syscallname *name, abi_long ret)
33189d31 707{
29fa23e7 708 gemu_log(" = 0x" TARGET_ABI_FMT_lx "\n", ret);
33189d31 709}
f3e3285d 710#endif
33189d31 711
f3e3285d 712#ifdef TARGET_NR__newselect
33189d31 713static void
7ccfb2eb 714print_syscall_ret_newselect(const struct syscallname *name, abi_long ret)
33189d31 715{
29fa23e7 716 gemu_log(" = 0x" TARGET_ABI_FMT_lx " (", ret);
33189d31
TS
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(",");
74d753ac 723 print_timeval(newselect_arg5, 1);
33189d31
TS
724 gemu_log(")\n");
725}
f3e3285d 726#endif
33189d31 727
19f59bce
AM
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 */
735static void
736print_syscall_ret_adjtimex(const struct syscallname *name, abi_long ret)
737{
738 const char *errstr = NULL;
739
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);
746 }
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;
768 }
769 }
770
771 gemu_log("\n");
772}
773
74d753ac
MW
774UNUSED 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,
780};
781
782UNUSED 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,
790};
791
792UNUSED static struct flags unlinkat_flags[] = {
793#ifdef AT_REMOVEDIR
794 FLAG_GENERIC(AT_REMOVEDIR),
795#endif
796 FLAG_END,
797};
798
799UNUSED 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,
808};
809
810UNUSED static struct flags open_access_flags[] = {
811 FLAG_TARGET(O_RDONLY),
812 FLAG_TARGET(O_WRONLY),
813 FLAG_TARGET(O_RDWR),
814 FLAG_END,
815};
816
817UNUSED 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 */
afc8763f
RH
826 FLAG_TARGET(O_DSYNC),
827 FLAG_TARGET(__O_SYNC),
74d753ac
MW
828 FLAG_TARGET(O_TRUNC),
829#ifdef O_DIRECT
830 FLAG_TARGET(O_DIRECT),
afc8763f
RH
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),
5f9cee46
RV
840#endif
841#ifdef O_TMPFILE
842 FLAG_TARGET(O_TMPFILE),
843 FLAG_TARGET(__O_TMPFILE),
74d753ac
MW
844#endif
845 FLAG_END,
846};
847
848UNUSED static struct flags mount_flags[] = {
849#ifdef MS_BIND
850 FLAG_GENERIC(MS_BIND),
851#endif
852#ifdef MS_DIRSYNC
853 FLAG_GENERIC(MS_DIRSYNC),
854#endif
855 FLAG_GENERIC(MS_MANDLOCK),
856#ifdef MS_MOVE
857 FLAG_GENERIC(MS_MOVE),
858#endif
859 FLAG_GENERIC(MS_NOATIME),
860 FLAG_GENERIC(MS_NODEV),
861 FLAG_GENERIC(MS_NODIRATIME),
862 FLAG_GENERIC(MS_NOEXEC),
863 FLAG_GENERIC(MS_NOSUID),
864 FLAG_GENERIC(MS_RDONLY),
865#ifdef MS_RELATIME
866 FLAG_GENERIC(MS_RELATIME),
867#endif
868 FLAG_GENERIC(MS_REMOUNT),
869 FLAG_GENERIC(MS_SYNCHRONOUS),
870 FLAG_END,
871};
872
873UNUSED static struct flags umount2_flags[] = {
874#ifdef MNT_FORCE
875 FLAG_GENERIC(MNT_FORCE),
876#endif
877#ifdef MNT_DETACH
878 FLAG_GENERIC(MNT_DETACH),
879#endif
880#ifdef MNT_EXPIRE
881 FLAG_GENERIC(MNT_EXPIRE),
882#endif
883 FLAG_END,
884};
885
886UNUSED static struct flags mmap_prot_flags[] = {
887 FLAG_GENERIC(PROT_NONE),
888 FLAG_GENERIC(PROT_EXEC),
889 FLAG_GENERIC(PROT_READ),
890 FLAG_GENERIC(PROT_WRITE),
9e0b74a4
PB
891 FLAG_TARGET(PROT_SEM),
892 FLAG_GENERIC(PROT_GROWSDOWN),
893 FLAG_GENERIC(PROT_GROWSUP),
74d753ac
MW
894 FLAG_END,
895};
896
897UNUSED static struct flags mmap_flags[] = {
898 FLAG_TARGET(MAP_SHARED),
899 FLAG_TARGET(MAP_PRIVATE),
900 FLAG_TARGET(MAP_ANONYMOUS),
901 FLAG_TARGET(MAP_DENYWRITE),
902 FLAG_TARGET(MAP_FIXED),
903 FLAG_TARGET(MAP_GROWSDOWN),
906c1b8e 904 FLAG_TARGET(MAP_EXECUTABLE),
74d753ac
MW
905#ifdef MAP_LOCKED
906 FLAG_TARGET(MAP_LOCKED),
907#endif
908#ifdef MAP_NONBLOCK
909 FLAG_TARGET(MAP_NONBLOCK),
910#endif
911 FLAG_TARGET(MAP_NORESERVE),
912#ifdef MAP_POPULATE
913 FLAG_TARGET(MAP_POPULATE),
906c1b8e
MF
914#endif
915#ifdef TARGET_MAP_UNINITIALIZED
916 FLAG_TARGET(MAP_UNINITIALIZED),
74d753ac
MW
917#endif
918 FLAG_END,
919};
920
608e5592
LV
921UNUSED static struct flags clone_flags[] = {
922 FLAG_GENERIC(CLONE_VM),
923 FLAG_GENERIC(CLONE_FS),
924 FLAG_GENERIC(CLONE_FILES),
925 FLAG_GENERIC(CLONE_SIGHAND),
926 FLAG_GENERIC(CLONE_PTRACE),
927 FLAG_GENERIC(CLONE_VFORK),
928 FLAG_GENERIC(CLONE_PARENT),
929 FLAG_GENERIC(CLONE_THREAD),
930 FLAG_GENERIC(CLONE_NEWNS),
931 FLAG_GENERIC(CLONE_SYSVSEM),
932 FLAG_GENERIC(CLONE_SETTLS),
933 FLAG_GENERIC(CLONE_PARENT_SETTID),
934 FLAG_GENERIC(CLONE_CHILD_CLEARTID),
935 FLAG_GENERIC(CLONE_DETACHED),
936 FLAG_GENERIC(CLONE_UNTRACED),
937 FLAG_GENERIC(CLONE_CHILD_SETTID),
6f11f013 938#if defined(CLONE_NEWUTS)
608e5592 939 FLAG_GENERIC(CLONE_NEWUTS),
6f11f013
SW
940#endif
941#if defined(CLONE_NEWIPC)
608e5592 942 FLAG_GENERIC(CLONE_NEWIPC),
6f11f013
SW
943#endif
944#if defined(CLONE_NEWUSER)
608e5592 945 FLAG_GENERIC(CLONE_NEWUSER),
6f11f013
SW
946#endif
947#if defined(CLONE_NEWPID)
608e5592 948 FLAG_GENERIC(CLONE_NEWPID),
6f11f013
SW
949#endif
950#if defined(CLONE_NEWNET)
608e5592 951 FLAG_GENERIC(CLONE_NEWNET),
6f11f013
SW
952#endif
953#if defined(CLONE_IO)
608e5592 954 FLAG_GENERIC(CLONE_IO),
6f11f013 955#endif
608e5592
LV
956 FLAG_END,
957};
958
fb3aabf3
LV
959UNUSED static struct flags msg_flags[] = {
960 /* send */
961 FLAG_GENERIC(MSG_CONFIRM),
962 FLAG_GENERIC(MSG_DONTROUTE),
963 FLAG_GENERIC(MSG_DONTWAIT),
964 FLAG_GENERIC(MSG_EOR),
965 FLAG_GENERIC(MSG_MORE),
966 FLAG_GENERIC(MSG_NOSIGNAL),
967 FLAG_GENERIC(MSG_OOB),
968 /* recv */
969 FLAG_GENERIC(MSG_CMSG_CLOEXEC),
970 FLAG_GENERIC(MSG_ERRQUEUE),
971 FLAG_GENERIC(MSG_PEEK),
972 FLAG_GENERIC(MSG_TRUNC),
973 FLAG_GENERIC(MSG_WAITALL),
974 /* recvmsg */
975 FLAG_GENERIC(MSG_CTRUNC),
976 FLAG_END,
977};
978
74d753ac
MW
979/*
980 * print_xxx utility functions. These are used to print syscall
981 * parameters in certain format. All of these have parameter
982 * named 'last'. This parameter is used to add comma to output
983 * when last == 0.
984 */
985
986static const char *
987get_comma(int last)
988{
989 return ((last) ? "" : ",");
990}
991
992static void
d2ee72a5 993print_flags(const struct flags *f, abi_long flags, int last)
74d753ac
MW
994{
995 const char *sep = "";
74d753ac
MW
996 int n;
997
74d753ac
MW
998 if ((flags == 0) && (f->f_value == 0)) {
999 gemu_log("%s%s", f->f_string, get_comma(last));
1000 return;
1001 }
1002 for (n = 0; f->f_string != NULL; f++) {
1003 if ((f->f_value != 0) && ((flags & f->f_value) == f->f_value)) {
1004 gemu_log("%s%s", sep, f->f_string);
1005 flags &= ~f->f_value;
1006 sep = "|";
1007 n++;
1008 }
1009 }
1010
1011 if (n > 0) {
1012 /* print rest of the flags as numeric */
1013 if (flags != 0) {
d2ee72a5 1014 gemu_log("%s%#x%s", sep, (unsigned int)flags, get_comma(last));
74d753ac
MW
1015 } else {
1016 gemu_log("%s", get_comma(last));
1017 }
1018 } else {
1019 /* no string version of flags found, print them in hex then */
d2ee72a5 1020 gemu_log("%#x%s", (unsigned int)flags, get_comma(last));
74d753ac
MW
1021 }
1022}
1023
1024static void
d2ee72a5 1025print_at_dirfd(abi_long dirfd, int last)
74d753ac 1026{
74d753ac
MW
1027#ifdef AT_FDCWD
1028 if (dirfd == AT_FDCWD) {
1029 gemu_log("AT_FDCWD%s", get_comma(last));
1030 return;
1031 }
1032#endif
d2ee72a5 1033 gemu_log("%d%s", (int)dirfd, get_comma(last));
74d753ac
MW
1034}
1035
1036static void
d2ee72a5 1037print_file_mode(abi_long mode, int last)
74d753ac
MW
1038{
1039 const char *sep = "";
1040 const struct flags *m;
74d753ac
MW
1041
1042 for (m = &mode_flags[0]; m->f_string != NULL; m++) {
1043 if ((m->f_value & mode) == m->f_value) {
1044 gemu_log("%s%s", m->f_string, sep);
1045 sep = "|";
1046 mode &= ~m->f_value;
1047 break;
1048 }
1049 }
1050
1051 mode &= ~S_IFMT;
1052 /* print rest of the mode as octal */
1053 if (mode != 0)
d2ee72a5 1054 gemu_log("%s%#o", sep, (unsigned int)mode);
74d753ac
MW
1055
1056 gemu_log("%s", get_comma(last));
1057}
1058
1059static void
d2ee72a5 1060print_open_flags(abi_long flags, int last)
74d753ac 1061{
74d753ac
MW
1062 print_flags(open_access_flags, flags & TARGET_O_ACCMODE, 1);
1063 flags &= ~TARGET_O_ACCMODE;
1064 if (flags == 0) {
1065 gemu_log("%s", get_comma(last));
1066 return;
1067 }
1068 gemu_log("|");
1069 print_flags(open_flags, flags, last);
1070}
1071
1072static void
1073print_syscall_prologue(const struct syscallname *sc)
1074{
1075 gemu_log("%s(", sc->name);
1076}
1077
1078/*ARGSUSED*/
1079static void
1080print_syscall_epilogue(const struct syscallname *sc)
1081{
1082 (void)sc;
1083 gemu_log(")");
1084}
1085
1086static void
1087print_string(abi_long addr, int last)
1088{
1089 char *s;
1090
1091 if ((s = lock_user_string(addr)) != NULL) {
1092 gemu_log("\"%s\"%s", s, get_comma(last));
1093 unlock_user(s, addr, 0);
1094 } else {
1095 /* can't get string out of it, so print it as pointer */
1096 print_pointer(addr, last);
1097 }
1098}
1099
fb3aabf3
LV
1100#define MAX_PRINT_BUF 40
1101static void
1102print_buf(abi_long addr, abi_long len, int last)
1103{
1104 uint8_t *s;
1105 int i;
1106
1107 s = lock_user(VERIFY_READ, addr, len, 1);
1108 if (s) {
1109 gemu_log("\"");
1110 for (i = 0; i < MAX_PRINT_BUF && i < len; i++) {
1111 if (isprint(s[i])) {
1112 gemu_log("%c", s[i]);
1113 } else {
1114 gemu_log("\\%o", s[i]);
1115 }
1116 }
1117 gemu_log("\"");
1118 if (i != len) {
1119 gemu_log("...");
1120 }
1121 if (!last) {
1122 gemu_log(",");
1123 }
1124 unlock_user(s, addr, 0);
1125 } else {
1126 print_pointer(addr, last);
1127 }
1128}
1129
74d753ac
MW
1130/*
1131 * Prints out raw parameter using given format. Caller needs
1132 * to do byte swapping if needed.
1133 */
1134static void
1135print_raw_param(const char *fmt, abi_long param, int last)
1136{
1137 char format[64];
1138
1139 (void) snprintf(format, sizeof (format), "%s%s", fmt, get_comma(last));
1140 gemu_log(format, param);
1141}
1142
1143static void
1144print_pointer(abi_long p, int last)
1145{
1146 if (p == 0)
1147 gemu_log("NULL%s", get_comma(last));
1148 else
1149 gemu_log("0x" TARGET_ABI_FMT_lx "%s", p, get_comma(last));
1150}
1151
1152/*
1153 * Reads 32-bit (int) number from guest address space from
1154 * address 'addr' and prints it.
1155 */
1156static void
1157print_number(abi_long addr, int last)
1158{
1159 if (addr == 0) {
1160 gemu_log("NULL%s", get_comma(last));
1161 } else {
1162 int num;
1163
1164 get_user_s32(num, addr);
1165 gemu_log("[%d]%s", num, get_comma(last));
1166 }
1167}
1168
1169static void
1170print_timeval(abi_ulong tv_addr, int last)
1171{
1172 if( tv_addr ) {
1173 struct target_timeval *tv;
1174
1175 tv = lock_user(VERIFY_READ, tv_addr, sizeof(*tv), 1);
1176 if (!tv)
1177 return;
1178 gemu_log("{" TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld "}%s",
910ee4e5 1179 tswapal(tv->tv_sec), tswapal(tv->tv_usec), get_comma(last));
74d753ac
MW
1180 unlock_user(tv, tv_addr, 0);
1181 } else
1182 gemu_log("NULL%s", get_comma(last));
1183}
1184
1185#undef UNUSED
1186
1187#ifdef TARGET_NR_accept
1188static void
1189print_accept(const struct syscallname *name,
1190 abi_long arg0, abi_long arg1, abi_long arg2,
1191 abi_long arg3, abi_long arg4, abi_long arg5)
1192{
1193 print_syscall_prologue(name);
d2ee72a5 1194 print_raw_param("%d", arg0, 0);
74d753ac
MW
1195 print_pointer(arg1, 0);
1196 print_number(arg2, 1);
1197 print_syscall_epilogue(name);
1198}
1199#endif
1200
1201#ifdef TARGET_NR_access
1202static void
1203print_access(const struct syscallname *name,
1204 abi_long arg0, abi_long arg1, abi_long arg2,
1205 abi_long arg3, abi_long arg4, abi_long arg5)
1206{
1207 print_syscall_prologue(name);
1208 print_string(arg0, 0);
1209 print_flags(access_flags, arg1, 1);
1210 print_syscall_epilogue(name);
1211}
1212#endif
1213
1214#ifdef TARGET_NR_brk
1215static void
1216print_brk(const struct syscallname *name,
1217 abi_long arg0, abi_long arg1, abi_long arg2,
1218 abi_long arg3, abi_long arg4, abi_long arg5)
1219{
1220 print_syscall_prologue(name);
1221 print_pointer(arg0, 1);
1222 print_syscall_epilogue(name);
1223}
1224#endif
1225
1226#ifdef TARGET_NR_chdir
1227static void
1228print_chdir(const struct syscallname *name,
1229 abi_long arg0, abi_long arg1, abi_long arg2,
1230 abi_long arg3, abi_long arg4, abi_long arg5)
1231{
1232 print_syscall_prologue(name);
1233 print_string(arg0, 1);
1234 print_syscall_epilogue(name);
1235}
1236#endif
1237
1b7695fe
HD
1238#ifdef TARGET_NR_chroot
1239static void
1240print_chroot(const struct syscallname *name,
1241 abi_long arg0, abi_long arg1, abi_long arg2,
1242 abi_long arg3, abi_long arg4, abi_long arg5)
1243{
1244 print_syscall_prologue(name);
1245 print_string(arg0, 1);
1246 print_syscall_epilogue(name);
1247}
1248#endif
1249
74d753ac
MW
1250#ifdef TARGET_NR_chmod
1251static void
1252print_chmod(const struct syscallname *name,
1253 abi_long arg0, abi_long arg1, abi_long arg2,
1254 abi_long arg3, abi_long arg4, abi_long arg5)
1255{
1256 print_syscall_prologue(name);
1257 print_string(arg0, 0);
1258 print_file_mode(arg1, 1);
1259 print_syscall_epilogue(name);
1260}
1261#endif
1262
38860a03
AM
1263#ifdef TARGET_NR_clock_adjtime
1264static void
1265print_clock_adjtime(const struct syscallname *name,
1266 abi_long arg0, abi_long arg1, abi_long arg2,
1267 abi_long arg3, abi_long arg4, abi_long arg5)
1268{
1269 print_syscall_prologue(name);
1270 print_clockid(arg0, 0);
1271 print_pointer(arg1, 1);
1272 print_syscall_epilogue(name);
1273}
1274#endif
1275
608e5592 1276#ifdef TARGET_NR_clone
84bd8284
LV
1277static void do_print_clone(unsigned int flags, abi_ulong newsp,
1278 abi_ulong parent_tidptr, target_ulong newtls,
1279 abi_ulong child_tidptr)
1280{
1281 print_flags(clone_flags, flags, 0);
1282 print_raw_param("child_stack=0x" TARGET_ABI_FMT_lx, newsp, 0);
1283 print_raw_param("parent_tidptr=0x" TARGET_ABI_FMT_lx, parent_tidptr, 0);
1284 print_raw_param("tls=0x" TARGET_ABI_FMT_lx, newtls, 0);
1285 print_raw_param("child_tidptr=0x" TARGET_ABI_FMT_lx, child_tidptr, 1);
1286}
1287
608e5592
LV
1288static void
1289print_clone(const struct syscallname *name,
84bd8284
LV
1290 abi_long arg1, abi_long arg2, abi_long arg3,
1291 abi_long arg4, abi_long arg5, abi_long arg6)
608e5592
LV
1292{
1293 print_syscall_prologue(name);
84bd8284
LV
1294#if defined(TARGET_MICROBLAZE)
1295 do_print_clone(arg1, arg2, arg4, arg6, arg5);
1296#elif defined(TARGET_CLONE_BACKWARDS)
1297 do_print_clone(arg1, arg2, arg3, arg4, arg5);
1298#elif defined(TARGET_CLONE_BACKWARDS2)
1299 do_print_clone(arg2, arg1, arg3, arg5, arg4);
608e5592 1300#else
84bd8284 1301 do_print_clone(arg1, arg2, arg3, arg5, arg4);
608e5592
LV
1302#endif
1303 print_syscall_epilogue(name);
1304}
1305#endif
1306
74d753ac
MW
1307#ifdef TARGET_NR_creat
1308static void
1309print_creat(const struct syscallname *name,
1310 abi_long arg0, abi_long arg1, abi_long arg2,
1311 abi_long arg3, abi_long arg4, abi_long arg5)
1312{
1313 print_syscall_prologue(name);
1314 print_string(arg0, 0);
1315 print_file_mode(arg1, 1);
1316 print_syscall_epilogue(name);
1317}
1318#endif
1319
1320#ifdef TARGET_NR_execv
1321static void
1322print_execv(const struct syscallname *name,
1323 abi_long arg0, abi_long arg1, abi_long arg2,
1324 abi_long arg3, abi_long arg4, abi_long arg5)
1325{
1326 print_syscall_prologue(name);
1327 print_string(arg0, 0);
d2ee72a5 1328 print_raw_param("0x" TARGET_ABI_FMT_lx, arg1, 1);
74d753ac
MW
1329 print_syscall_epilogue(name);
1330}
1331#endif
1332
1333#ifdef TARGET_NR_faccessat
1334static void
1335print_faccessat(const struct syscallname *name,
1336 abi_long arg0, abi_long arg1, abi_long arg2,
1337 abi_long arg3, abi_long arg4, abi_long arg5)
1338{
1339 print_syscall_prologue(name);
1340 print_at_dirfd(arg0, 0);
1341 print_string(arg1, 0);
1342 print_flags(access_flags, arg2, 0);
1343 print_flags(at_file_flags, arg3, 1);
1344 print_syscall_epilogue(name);
1345}
1346#endif
1347
1348#ifdef TARGET_NR_fchmodat
1349static void
1350print_fchmodat(const struct syscallname *name,
1351 abi_long arg0, abi_long arg1, abi_long arg2,
1352 abi_long arg3, abi_long arg4, abi_long arg5)
1353{
1354 print_syscall_prologue(name);
1355 print_at_dirfd(arg0, 0);
1356 print_string(arg1, 0);
1357 print_file_mode(arg2, 0);
1358 print_flags(at_file_flags, arg3, 1);
1359 print_syscall_epilogue(name);
1360}
1361#endif
1362
1363#ifdef TARGET_NR_fchownat
1364static void
1365print_fchownat(const struct syscallname *name,
1366 abi_long arg0, abi_long arg1, abi_long arg2,
1367 abi_long arg3, abi_long arg4, abi_long arg5)
1368{
1369 print_syscall_prologue(name);
1370 print_at_dirfd(arg0, 0);
1371 print_string(arg1, 0);
d2ee72a5
LV
1372 print_raw_param("%d", arg2, 0);
1373 print_raw_param("%d", arg3, 0);
74d753ac
MW
1374 print_flags(at_file_flags, arg4, 1);
1375 print_syscall_epilogue(name);
1376}
1377#endif
1378
1379#if defined(TARGET_NR_fcntl) || defined(TARGET_NR_fcntl64)
1380static void
1381print_fcntl(const struct syscallname *name,
1382 abi_long arg0, abi_long arg1, abi_long arg2,
1383 abi_long arg3, abi_long arg4, abi_long arg5)
1384{
1385 print_syscall_prologue(name);
d2ee72a5 1386 print_raw_param("%d", arg0, 0);
d95ec14f
LV
1387 switch(arg1) {
1388 case TARGET_F_DUPFD:
1389 gemu_log("F_DUPFD,");
1390 print_raw_param(TARGET_ABI_FMT_ld, arg2, 1);
1391 break;
1392 case TARGET_F_GETFD:
1393 gemu_log("F_GETFD");
1394 break;
1395 case TARGET_F_SETFD:
1396 gemu_log("F_SETFD,");
1397 print_raw_param(TARGET_ABI_FMT_ld, arg2, 1);
1398 break;
1399 case TARGET_F_GETFL:
1400 gemu_log("F_GETFL");
1401 break;
1402 case TARGET_F_SETFL:
1403 gemu_log("F_SETFL,");
1404 print_open_flags(arg2, 1);
1405 break;
1406 case TARGET_F_GETLK:
1407 gemu_log("F_GETLK,");
1408 print_pointer(arg2, 1);
1409 break;
1410 case TARGET_F_SETLK:
1411 gemu_log("F_SETLK,");
1412 print_pointer(arg2, 1);
1413 break;
1414 case TARGET_F_SETLKW:
1415 gemu_log("F_SETLKW,");
1416 print_pointer(arg2, 1);
1417 break;
1418 case TARGET_F_GETOWN:
1419 gemu_log("F_GETOWN");
1420 break;
1421 case TARGET_F_SETOWN:
1422 gemu_log("F_SETOWN,");
1423 print_raw_param(TARGET_ABI_FMT_ld, arg2, 0);
1424 break;
1425 case TARGET_F_GETSIG:
1426 gemu_log("F_GETSIG");
1427 break;
1428 case TARGET_F_SETSIG:
1429 gemu_log("F_SETSIG,");
1430 print_raw_param(TARGET_ABI_FMT_ld, arg2, 0);
1431 break;
1432#if TARGET_ABI_BITS == 32
1433 case TARGET_F_GETLK64:
1434 gemu_log("F_GETLK64,");
1435 print_pointer(arg2, 1);
1436 break;
1437 case TARGET_F_SETLK64:
1438 gemu_log("F_SETLK64,");
1439 print_pointer(arg2, 1);
1440 break;
1441 case TARGET_F_SETLKW64:
1442 gemu_log("F_SETLKW64,");
1443 print_pointer(arg2, 1);
1444 break;
1445#endif
1446 case TARGET_F_SETLEASE:
1447 gemu_log("F_SETLEASE,");
1448 print_raw_param(TARGET_ABI_FMT_ld, arg2, 0);
1449 break;
1450 case TARGET_F_GETLEASE:
1451 gemu_log("F_GETLEASE");
1452 break;
7e3b92ec
PM
1453 case TARGET_F_SETPIPE_SZ:
1454 gemu_log("F_SETPIPE_SZ,");
1455 print_raw_param(TARGET_ABI_FMT_ld, arg2, 1);
1456 break;
1457 case TARGET_F_GETPIPE_SZ:
1458 gemu_log("F_GETPIPE_SZ");
1459 break;
d95ec14f
LV
1460 case TARGET_F_DUPFD_CLOEXEC:
1461 gemu_log("F_DUPFD_CLOEXEC,");
1462 print_raw_param(TARGET_ABI_FMT_ld, arg2, 1);
1463 break;
1464 case TARGET_F_NOTIFY:
1465 gemu_log("F_NOTIFY,");
1466 print_raw_param(TARGET_ABI_FMT_ld, arg2, 0);
1467 break;
1468 default:
1469 print_raw_param(TARGET_ABI_FMT_ld, arg1, 0);
1470 print_pointer(arg2, 1);
1471 break;
1472 }
74d753ac
MW
1473 print_syscall_epilogue(name);
1474}
1475#define print_fcntl64 print_fcntl
1476#endif
1477
1478
1479#ifdef TARGET_NR_futimesat
1480static void
1481print_futimesat(const struct syscallname *name,
1482 abi_long arg0, abi_long arg1, abi_long arg2,
1483 abi_long arg3, abi_long arg4, abi_long arg5)
1484{
1485 print_syscall_prologue(name);
1486 print_at_dirfd(arg0, 0);
1487 print_string(arg1, 0);
1488 print_timeval(arg2, 0);
1489 print_timeval(arg2 + sizeof (struct target_timeval), 1);
1490 print_syscall_epilogue(name);
1491}
1492#endif
1493
1494#ifdef TARGET_NR_link
1495static void
1496print_link(const struct syscallname *name,
1497 abi_long arg0, abi_long arg1, abi_long arg2,
1498 abi_long arg3, abi_long arg4, abi_long arg5)
1499{
1500 print_syscall_prologue(name);
1501 print_string(arg0, 0);
1502 print_string(arg1, 1);
1503 print_syscall_epilogue(name);
1504}
1505#endif
1506
1507#ifdef TARGET_NR_linkat
1508static void
1509print_linkat(const struct syscallname *name,
1510 abi_long arg0, abi_long arg1, abi_long arg2,
1511 abi_long arg3, abi_long arg4, abi_long arg5)
1512{
1513 print_syscall_prologue(name);
1514 print_at_dirfd(arg0, 0);
1515 print_string(arg1, 0);
1516 print_at_dirfd(arg2, 0);
1517 print_string(arg3, 0);
1518 print_flags(at_file_flags, arg4, 1);
1519 print_syscall_epilogue(name);
1520}
1521#endif
1522
608e5592
LV
1523#ifdef TARGET_NR__llseek
1524static void
1525print__llseek(const struct syscallname *name,
1526 abi_long arg0, abi_long arg1, abi_long arg2,
1527 abi_long arg3, abi_long arg4, abi_long arg5)
1528{
1529 const char *whence = "UNKNOWN";
1530 print_syscall_prologue(name);
1531 print_raw_param("%d", arg0, 0);
1532 print_raw_param("%ld", arg1, 0);
1533 print_raw_param("%ld", arg2, 0);
1534 print_pointer(arg3, 0);
1535 switch(arg4) {
1536 case SEEK_SET: whence = "SEEK_SET"; break;
1537 case SEEK_CUR: whence = "SEEK_CUR"; break;
1538 case SEEK_END: whence = "SEEK_END"; break;
1539 }
1540 gemu_log("%s",whence);
1541 print_syscall_epilogue(name);
1542}
1543#endif
1544
8997d1bd
LV
1545#if defined(TARGET_NR_socket)
1546static void
1547print_socket(const struct syscallname *name,
1548 abi_long arg0, abi_long arg1, abi_long arg2,
1549 abi_long arg3, abi_long arg4, abi_long arg5)
1550{
1551 abi_ulong domain = arg0, type = arg1, protocol = arg2;
1552
1553 print_syscall_prologue(name);
1554 print_socket_domain(domain);
1555 gemu_log(",");
1556 print_socket_type(type);
1557 gemu_log(",");
1558 if (domain == AF_PACKET ||
1559 (domain == AF_INET && type == TARGET_SOCK_PACKET)) {
1560 protocol = tswap16(protocol);
1561 }
1562 print_socket_protocol(domain, type, protocol);
1563 print_syscall_epilogue(name);
1564}
1565
1566#endif
1567
fb3aabf3
LV
1568#if defined(TARGET_NR_socketcall)
1569
1570#define get_user_ualx(x, gaddr, idx) \
1571 get_user_ual(x, (gaddr) + (idx) * sizeof(abi_long))
1572
1573static void do_print_socket(const char *name, abi_long arg1)
1574{
1575 abi_ulong domain, type, protocol;
1576
1577 get_user_ualx(domain, arg1, 0);
1578 get_user_ualx(type, arg1, 1);
1579 get_user_ualx(protocol, arg1, 2);
1580 gemu_log("%s(", name);
1581 print_socket_domain(domain);
1582 gemu_log(",");
1583 print_socket_type(type);
1584 gemu_log(",");
1585 if (domain == AF_PACKET ||
1586 (domain == AF_INET && type == TARGET_SOCK_PACKET)) {
1587 protocol = tswap16(protocol);
1588 }
1589 print_socket_protocol(domain, type, protocol);
1590 gemu_log(")");
1591}
1592
1593static void do_print_sockaddr(const char *name, abi_long arg1)
1594{
1595 abi_ulong sockfd, addr, addrlen;
1596
1597 get_user_ualx(sockfd, arg1, 0);
1598 get_user_ualx(addr, arg1, 1);
1599 get_user_ualx(addrlen, arg1, 2);
1600
1601 gemu_log("%s(", name);
1602 print_raw_param(TARGET_ABI_FMT_ld, sockfd, 0);
1603 print_sockaddr(addr, addrlen);
1604 gemu_log(")");
1605}
1606
1607static void do_print_listen(const char *name, abi_long arg1)
1608{
1609 abi_ulong sockfd, backlog;
1610
1611 get_user_ualx(sockfd, arg1, 0);
1612 get_user_ualx(backlog, arg1, 1);
1613
1614 gemu_log("%s(", name);
1615 print_raw_param(TARGET_ABI_FMT_ld, sockfd, 0);
1616 print_raw_param(TARGET_ABI_FMT_ld, backlog, 1);
1617 gemu_log(")");
1618}
1619
1620static void do_print_socketpair(const char *name, abi_long arg1)
1621{
1622 abi_ulong domain, type, protocol, tab;
1623
1624 get_user_ualx(domain, arg1, 0);
1625 get_user_ualx(type, arg1, 1);
1626 get_user_ualx(protocol, arg1, 2);
1627 get_user_ualx(tab, arg1, 3);
1628
1629 gemu_log("%s(", name);
1630 print_socket_domain(domain);
1631 gemu_log(",");
1632 print_socket_type(type);
1633 gemu_log(",");
1634 print_socket_protocol(domain, type, protocol);
1635 gemu_log(",");
1636 print_raw_param(TARGET_ABI_FMT_lx, tab, 1);
1637 gemu_log(")");
1638}
1639
1640static void do_print_sendrecv(const char *name, abi_long arg1)
1641{
1642 abi_ulong sockfd, msg, len, flags;
1643
1644 get_user_ualx(sockfd, arg1, 0);
1645 get_user_ualx(msg, arg1, 1);
1646 get_user_ualx(len, arg1, 2);
1647 get_user_ualx(flags, arg1, 3);
1648
1649 gemu_log("%s(", name);
1650 print_raw_param(TARGET_ABI_FMT_ld, sockfd, 0);
1651 print_buf(msg, len, 0);
1652 print_raw_param(TARGET_ABI_FMT_ld, len, 0);
1653 print_flags(msg_flags, flags, 1);
1654 gemu_log(")");
1655}
1656
1657static void do_print_msgaddr(const char *name, abi_long arg1)
1658{
1659 abi_ulong sockfd, msg, len, flags, addr, addrlen;
1660
1661 get_user_ualx(sockfd, arg1, 0);
1662 get_user_ualx(msg, arg1, 1);
1663 get_user_ualx(len, arg1, 2);
1664 get_user_ualx(flags, arg1, 3);
1665 get_user_ualx(addr, arg1, 4);
1666 get_user_ualx(addrlen, arg1, 5);
1667
1668 gemu_log("%s(", name);
1669 print_raw_param(TARGET_ABI_FMT_ld, sockfd, 0);
1670 print_buf(msg, len, 0);
1671 print_raw_param(TARGET_ABI_FMT_ld, len, 0);
1672 print_flags(msg_flags, flags, 0);
1673 print_sockaddr(addr, addrlen);
1674 gemu_log(")");
1675}
1676
1677static void do_print_shutdown(const char *name, abi_long arg1)
1678{
1679 abi_ulong sockfd, how;
1680
1681 get_user_ualx(sockfd, arg1, 0);
1682 get_user_ualx(how, arg1, 1);
1683
1684 gemu_log("shutdown(");
1685 print_raw_param(TARGET_ABI_FMT_ld, sockfd, 0);
1686 switch (how) {
1687 case SHUT_RD:
1688 gemu_log("SHUT_RD");
1689 break;
1690 case SHUT_WR:
1691 gemu_log("SHUT_WR");
1692 break;
1693 case SHUT_RDWR:
1694 gemu_log("SHUT_RDWR");
1695 break;
1696 default:
1697 print_raw_param(TARGET_ABI_FMT_ld, how, 1);
1698 break;
1699 }
1700 gemu_log(")");
1701}
1702
1703static void do_print_msg(const char *name, abi_long arg1)
1704{
1705 abi_ulong sockfd, msg, flags;
1706
1707 get_user_ualx(sockfd, arg1, 0);
1708 get_user_ualx(msg, arg1, 1);
1709 get_user_ualx(flags, arg1, 2);
1710
1711 gemu_log("%s(", name);
1712 print_raw_param(TARGET_ABI_FMT_ld, sockfd, 0);
1713 print_pointer(msg, 0);
1714 print_flags(msg_flags, flags, 1);
1715 gemu_log(")");
1716}
1717
1718static void do_print_sockopt(const char *name, abi_long arg1)
1719{
1720 abi_ulong sockfd, level, optname, optval, optlen;
1721
1722 get_user_ualx(sockfd, arg1, 0);
1723 get_user_ualx(level, arg1, 1);
1724 get_user_ualx(optname, arg1, 2);
1725 get_user_ualx(optval, arg1, 3);
1726 get_user_ualx(optlen, arg1, 4);
1727
1728 gemu_log("%s(", name);
1729 print_raw_param(TARGET_ABI_FMT_ld, sockfd, 0);
1730 switch (level) {
1731 case SOL_TCP:
1732 gemu_log("SOL_TCP,");
1733 print_raw_param(TARGET_ABI_FMT_ld, optname, 0);
1734 print_pointer(optval, 0);
1735 break;
1736 case SOL_IP:
1737 gemu_log("SOL_IP,");
1738 print_raw_param(TARGET_ABI_FMT_ld, optname, 0);
1739 print_pointer(optval, 0);
1740 break;
1741 case SOL_RAW:
1742 gemu_log("SOL_RAW,");
1743 print_raw_param(TARGET_ABI_FMT_ld, optname, 0);
1744 print_pointer(optval, 0);
1745 break;
1746 case TARGET_SOL_SOCKET:
1747 gemu_log("SOL_SOCKET,");
1748 switch (optname) {
1749 case TARGET_SO_DEBUG:
1750 gemu_log("SO_DEBUG,");
1751print_optint:
1752 print_number(optval, 0);
1753 break;
1754 case TARGET_SO_REUSEADDR:
1755 gemu_log("SO_REUSEADDR,");
1756 goto print_optint;
113a9dd7
YS
1757 case TARGET_SO_REUSEPORT:
1758 gemu_log("SO_REUSEPORT,");
1759 goto print_optint;
fb3aabf3
LV
1760 case TARGET_SO_TYPE:
1761 gemu_log("SO_TYPE,");
1762 goto print_optint;
1763 case TARGET_SO_ERROR:
1764 gemu_log("SO_ERROR,");
1765 goto print_optint;
1766 case TARGET_SO_DONTROUTE:
1767 gemu_log("SO_DONTROUTE,");
1768 goto print_optint;
1769 case TARGET_SO_BROADCAST:
1770 gemu_log("SO_BROADCAST,");
1771 goto print_optint;
1772 case TARGET_SO_SNDBUF:
1773 gemu_log("SO_SNDBUF,");
1774 goto print_optint;
1775 case TARGET_SO_RCVBUF:
1776 gemu_log("SO_RCVBUF,");
1777 goto print_optint;
1778 case TARGET_SO_KEEPALIVE:
1779 gemu_log("SO_KEEPALIVE,");
1780 goto print_optint;
1781 case TARGET_SO_OOBINLINE:
1782 gemu_log("SO_OOBINLINE,");
1783 goto print_optint;
1784 case TARGET_SO_NO_CHECK:
1785 gemu_log("SO_NO_CHECK,");
1786 goto print_optint;
1787 case TARGET_SO_PRIORITY:
1788 gemu_log("SO_PRIORITY,");
1789 goto print_optint;
1790 case TARGET_SO_BSDCOMPAT:
1791 gemu_log("SO_BSDCOMPAT,");
1792 goto print_optint;
1793 case TARGET_SO_PASSCRED:
1794 gemu_log("SO_PASSCRED,");
1795 goto print_optint;
1796 case TARGET_SO_TIMESTAMP:
1797 gemu_log("SO_TIMESTAMP,");
1798 goto print_optint;
1799 case TARGET_SO_RCVLOWAT:
1800 gemu_log("SO_RCVLOWAT,");
1801 goto print_optint;
1802 case TARGET_SO_RCVTIMEO:
1803 gemu_log("SO_RCVTIMEO,");
1804 print_timeval(optval, 0);
1805 break;
1806 case TARGET_SO_SNDTIMEO:
1807 gemu_log("SO_SNDTIMEO,");
1808 print_timeval(optval, 0);
1809 break;
1810 case TARGET_SO_ATTACH_FILTER: {
1811 struct target_sock_fprog *fprog;
1812
1813 gemu_log("SO_ATTACH_FILTER,");
1814
1815 if (lock_user_struct(VERIFY_READ, fprog, optval, 0)) {
1816 struct target_sock_filter *filter;
1817 gemu_log("{");
1818 if (lock_user_struct(VERIFY_READ, filter,
1819 tswapal(fprog->filter), 0)) {
1820 int i;
1821 for (i = 0; i < tswap16(fprog->len) - 1; i++) {
1822 gemu_log("[%d]{0x%x,%d,%d,0x%x},",
1823 i, tswap16(filter[i].code),
1824 filter[i].jt, filter[i].jf,
1825 tswap32(filter[i].k));
1826 }
1827 gemu_log("[%d]{0x%x,%d,%d,0x%x}",
1828 i, tswap16(filter[i].code),
1829 filter[i].jt, filter[i].jf,
1830 tswap32(filter[i].k));
1831 } else {
1832 gemu_log(TARGET_ABI_FMT_lx, tswapal(fprog->filter));
1833 }
1834 gemu_log(",%d},", tswap16(fprog->len));
1835 unlock_user(fprog, optval, 0);
1836 } else {
1837 print_pointer(optval, 0);
1838 }
1839 break;
1840 }
1841 default:
1842 print_raw_param(TARGET_ABI_FMT_ld, optname, 0);
1843 print_pointer(optval, 0);
1844 break;
1845 }
1846 break;
1847 default:
1848 print_raw_param(TARGET_ABI_FMT_ld, level, 0);
1849 print_raw_param(TARGET_ABI_FMT_ld, optname, 0);
1850 print_pointer(optval, 0);
1851 break;
1852 }
1853 print_raw_param(TARGET_ABI_FMT_ld, optlen, 1);
1854 gemu_log(")");
1855}
1856
1857#define PRINT_SOCKOP(name, func) \
ff71a454 1858 [TARGET_SYS_##name] = { #name, func }
fb3aabf3
LV
1859
1860static struct {
1861 const char *name;
1862 void (*print)(const char *, abi_long);
1863} scall[] = {
ff71a454
AM
1864 PRINT_SOCKOP(SOCKET, do_print_socket),
1865 PRINT_SOCKOP(BIND, do_print_sockaddr),
1866 PRINT_SOCKOP(CONNECT, do_print_sockaddr),
1867 PRINT_SOCKOP(LISTEN, do_print_listen),
1868 PRINT_SOCKOP(ACCEPT, do_print_sockaddr),
1869 PRINT_SOCKOP(GETSOCKNAME, do_print_sockaddr),
1870 PRINT_SOCKOP(GETPEERNAME, do_print_sockaddr),
1871 PRINT_SOCKOP(SOCKETPAIR, do_print_socketpair),
1872 PRINT_SOCKOP(SEND, do_print_sendrecv),
1873 PRINT_SOCKOP(RECV, do_print_sendrecv),
1874 PRINT_SOCKOP(SENDTO, do_print_msgaddr),
1875 PRINT_SOCKOP(RECVFROM, do_print_msgaddr),
1876 PRINT_SOCKOP(SHUTDOWN, do_print_shutdown),
1877 PRINT_SOCKOP(SETSOCKOPT, do_print_sockopt),
1878 PRINT_SOCKOP(GETSOCKOPT, do_print_sockopt),
1879 PRINT_SOCKOP(SENDMSG, do_print_msg),
1880 PRINT_SOCKOP(RECVMSG, do_print_msg),
1881 PRINT_SOCKOP(ACCEPT4, NULL),
1882 PRINT_SOCKOP(RECVMMSG, NULL),
1883 PRINT_SOCKOP(SENDMMSG, NULL),
fb3aabf3
LV
1884};
1885
1886static void
1887print_socketcall(const struct syscallname *name,
1888 abi_long arg0, abi_long arg1, abi_long arg2,
1889 abi_long arg3, abi_long arg4, abi_long arg5)
1890{
1891 if (arg0 >= 0 && arg0 < ARRAY_SIZE(scall) && scall[arg0].print) {
1892 scall[arg0].print(scall[arg0].name, arg1);
1893 return;
1894 }
1895 print_syscall_prologue(name);
1896 print_raw_param(TARGET_ABI_FMT_ld, arg0, 0);
1897 print_raw_param(TARGET_ABI_FMT_ld, arg1, 0);
1898 print_raw_param(TARGET_ABI_FMT_ld, arg2, 0);
1899 print_raw_param(TARGET_ABI_FMT_ld, arg3, 0);
1900 print_raw_param(TARGET_ABI_FMT_ld, arg4, 0);
1901 print_raw_param(TARGET_ABI_FMT_ld, arg5, 0);
1902 print_syscall_epilogue(name);
1903}
1904#endif
1905
74d753ac
MW
1906#if defined(TARGET_NR_stat) || defined(TARGET_NR_stat64) || \
1907 defined(TARGET_NR_lstat) || defined(TARGET_NR_lstat64)
1908static void
1909print_stat(const struct syscallname *name,
1910 abi_long arg0, abi_long arg1, abi_long arg2,
1911 abi_long arg3, abi_long arg4, abi_long arg5)
1912{
1913 print_syscall_prologue(name);
1914 print_string(arg0, 0);
1915 print_pointer(arg1, 1);
1916 print_syscall_epilogue(name);
1917}
1918#define print_lstat print_stat
1919#define print_stat64 print_stat
1920#define print_lstat64 print_stat
1921#endif
1922
1923#if defined(TARGET_NR_fstat) || defined(TARGET_NR_fstat64)
1924static void
1925print_fstat(const struct syscallname *name,
1926 abi_long arg0, abi_long arg1, abi_long arg2,
1927 abi_long arg3, abi_long arg4, abi_long arg5)
1928{
1929 print_syscall_prologue(name);
d2ee72a5 1930 print_raw_param("%d", arg0, 0);
74d753ac
MW
1931 print_pointer(arg1, 1);
1932 print_syscall_epilogue(name);
1933}
1934#define print_fstat64 print_fstat
1935#endif
1936
1937#ifdef TARGET_NR_mkdir
1938static void
1939print_mkdir(const struct syscallname *name,
1940 abi_long arg0, abi_long arg1, abi_long arg2,
1941 abi_long arg3, abi_long arg4, abi_long arg5)
1942{
1943 print_syscall_prologue(name);
1944 print_string(arg0, 0);
1945 print_file_mode(arg1, 1);
1946 print_syscall_epilogue(name);
1947}
1948#endif
1949
1950#ifdef TARGET_NR_mkdirat
1951static void
1952print_mkdirat(const struct syscallname *name,
1953 abi_long arg0, abi_long arg1, abi_long arg2,
1954 abi_long arg3, abi_long arg4, abi_long arg5)
1955{
1956 print_syscall_prologue(name);
1957 print_at_dirfd(arg0, 0);
1958 print_string(arg1, 0);
1959 print_file_mode(arg2, 1);
1960 print_syscall_epilogue(name);
1961}
1962#endif
1963
4de596cb
LV
1964#ifdef TARGET_NR_rmdir
1965static void
1966print_rmdir(const struct syscallname *name,
1967 abi_long arg0, abi_long arg1, abi_long arg2,
1968 abi_long arg3, abi_long arg4, abi_long arg5)
1969{
1970 print_syscall_prologue(name);
1971 print_string(arg0, 0);
1972 print_syscall_epilogue(name);
1973}
1974#endif
1975
608e5592
LV
1976#ifdef TARGET_NR_rt_sigaction
1977static void
1978print_rt_sigaction(const struct syscallname *name,
1979 abi_long arg0, abi_long arg1, abi_long arg2,
1980 abi_long arg3, abi_long arg4, abi_long arg5)
1981{
1982 print_syscall_prologue(name);
1983 print_signal(arg0, 0);
1984 print_pointer(arg1, 0);
1985 print_pointer(arg2, 1);
1986 print_syscall_epilogue(name);
1987}
1988#endif
1989
1990#ifdef TARGET_NR_rt_sigprocmask
1991static void
1992print_rt_sigprocmask(const struct syscallname *name,
1993 abi_long arg0, abi_long arg1, abi_long arg2,
1994 abi_long arg3, abi_long arg4, abi_long arg5)
1995{
1996 const char *how = "UNKNOWN";
1997 print_syscall_prologue(name);
1998 switch(arg0) {
1999 case TARGET_SIG_BLOCK: how = "SIG_BLOCK"; break;
2000 case TARGET_SIG_UNBLOCK: how = "SIG_UNBLOCK"; break;
2001 case TARGET_SIG_SETMASK: how = "SIG_SETMASK"; break;
2002 }
2003 gemu_log("%s,",how);
2004 print_pointer(arg1, 0);
2005 print_pointer(arg2, 1);
2006 print_syscall_epilogue(name);
2007}
2008#endif
2009
5162264e
MS
2010#ifdef TARGET_NR_rt_sigqueueinfo
2011static void
2012print_rt_sigqueueinfo(const struct syscallname *name,
2013 abi_long arg0, abi_long arg1, abi_long arg2,
2014 abi_long arg3, abi_long arg4, abi_long arg5)
2015{
ba9fcea1
MS
2016 void *p;
2017 target_siginfo_t uinfo;
2018
5162264e
MS
2019 print_syscall_prologue(name);
2020 print_raw_param("%d", arg0, 0);
2021 print_signal(arg1, 0);
ba9fcea1
MS
2022 p = lock_user(VERIFY_READ, arg2, sizeof(target_siginfo_t), 1);
2023 if (p) {
2024 get_target_siginfo(&uinfo, p);
2025 print_siginfo(&uinfo);
2026
2027 unlock_user(p, arg2, 0);
2028 } else {
2029 print_pointer(arg2, 1);
2030 }
5162264e
MS
2031 print_syscall_epilogue(name);
2032}
2033#endif
2034
243e0fe5
MS
2035#ifdef TARGET_NR_rt_tgsigqueueinfo
2036static void
2037print_rt_tgsigqueueinfo(const struct syscallname *name,
2038 abi_long arg0, abi_long arg1, abi_long arg2,
2039 abi_long arg3, abi_long arg4, abi_long arg5)
2040{
ba9fcea1
MS
2041 void *p;
2042 target_siginfo_t uinfo;
2043
243e0fe5
MS
2044 print_syscall_prologue(name);
2045 print_raw_param("%d", arg0, 0);
2046 print_raw_param("%d", arg1, 0);
2047 print_signal(arg2, 0);
ba9fcea1
MS
2048 p = lock_user(VERIFY_READ, arg3, sizeof(target_siginfo_t), 1);
2049 if (p) {
2050 get_target_siginfo(&uinfo, p);
2051 print_siginfo(&uinfo);
2052
2053 unlock_user(p, arg3, 0);
2054 } else {
2055 print_pointer(arg3, 1);
2056 }
243e0fe5
MS
2057 print_syscall_epilogue(name);
2058}
2059#endif
2060
da2c8ad7
AM
2061#ifdef TARGET_NR_syslog
2062static void
2063print_syslog_action(abi_ulong arg, int last)
2064{
2065 const char *type;
2066
2067 switch (arg) {
2068 case TARGET_SYSLOG_ACTION_CLOSE: {
2069 type = "SYSLOG_ACTION_CLOSE";
2070 break;
2071 }
2072 case TARGET_SYSLOG_ACTION_OPEN: {
2073 type = "SYSLOG_ACTION_OPEN";
2074 break;
2075 }
2076 case TARGET_SYSLOG_ACTION_READ: {
2077 type = "SYSLOG_ACTION_READ";
2078 break;
2079 }
2080 case TARGET_SYSLOG_ACTION_READ_ALL: {
2081 type = "SYSLOG_ACTION_READ_ALL";
2082 break;
2083 }
2084 case TARGET_SYSLOG_ACTION_READ_CLEAR: {
2085 type = "SYSLOG_ACTION_READ_CLEAR";
2086 break;
2087 }
2088 case TARGET_SYSLOG_ACTION_CLEAR: {
2089 type = "SYSLOG_ACTION_CLEAR";
2090 break;
2091 }
2092 case TARGET_SYSLOG_ACTION_CONSOLE_OFF: {
2093 type = "SYSLOG_ACTION_CONSOLE_OFF";
2094 break;
2095 }
2096 case TARGET_SYSLOG_ACTION_CONSOLE_ON: {
2097 type = "SYSLOG_ACTION_CONSOLE_ON";
2098 break;
2099 }
2100 case TARGET_SYSLOG_ACTION_CONSOLE_LEVEL: {
2101 type = "SYSLOG_ACTION_CONSOLE_LEVEL";
2102 break;
2103 }
2104 case TARGET_SYSLOG_ACTION_SIZE_UNREAD: {
2105 type = "SYSLOG_ACTION_SIZE_UNREAD";
2106 break;
2107 }
2108 case TARGET_SYSLOG_ACTION_SIZE_BUFFER: {
2109 type = "SYSLOG_ACTION_SIZE_BUFFER";
2110 break;
2111 }
2112 default: {
2113 print_raw_param("%ld", arg, last);
2114 return;
2115 }
2116 }
2117 gemu_log("%s%s", type, get_comma(last));
2118}
2119
2120static void
2121print_syslog(const struct syscallname *name,
2122 abi_long arg0, abi_long arg1, abi_long arg2,
2123 abi_long arg3, abi_long arg4, abi_long arg5)
2124{
2125 print_syscall_prologue(name);
2126 print_syslog_action(arg0, 0);
2127 print_pointer(arg1, 0);
2128 print_raw_param("%d", arg2, 1);
2129 print_syscall_epilogue(name);
2130}
2131#endif
2132
74d753ac
MW
2133#ifdef TARGET_NR_mknod
2134static void
2135print_mknod(const struct syscallname *name,
2136 abi_long arg0, abi_long arg1, abi_long arg2,
2137 abi_long arg3, abi_long arg4, abi_long arg5)
2138{
d2ee72a5 2139 int hasdev = (arg1 & (S_IFCHR|S_IFBLK));
74d753ac
MW
2140
2141 print_syscall_prologue(name);
2142 print_string(arg0, 0);
2143 print_file_mode(arg1, (hasdev == 0));
2144 if (hasdev) {
d2ee72a5
LV
2145 print_raw_param("makedev(%d", major(arg2), 0);
2146 print_raw_param("%d)", minor(arg2), 1);
74d753ac
MW
2147 }
2148 print_syscall_epilogue(name);
2149}
2150#endif
2151
2152#ifdef TARGET_NR_mknodat
2153static void
2154print_mknodat(const struct syscallname *name,
2155 abi_long arg0, abi_long arg1, abi_long arg2,
2156 abi_long arg3, abi_long arg4, abi_long arg5)
2157{
d2ee72a5 2158 int hasdev = (arg2 & (S_IFCHR|S_IFBLK));
74d753ac
MW
2159
2160 print_syscall_prologue(name);
2161 print_at_dirfd(arg0, 0);
2162 print_string(arg1, 0);
2163 print_file_mode(arg2, (hasdev == 0));
2164 if (hasdev) {
d2ee72a5
LV
2165 print_raw_param("makedev(%d", major(arg3), 0);
2166 print_raw_param("%d)", minor(arg3), 1);
74d753ac
MW
2167 }
2168 print_syscall_epilogue(name);
2169}
2170#endif
2171
2172#ifdef TARGET_NR_mq_open
2173static void
2174print_mq_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)
2177{
d2ee72a5 2178 int is_creat = (arg1 & TARGET_O_CREAT);
74d753ac
MW
2179
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, 0);
2185 print_pointer(arg3, 1);
2186 }
2187 print_syscall_epilogue(name);
2188}
2189#endif
2190
2191#ifdef TARGET_NR_open
2192static void
2193print_open(const struct syscallname *name,
2194 abi_long arg0, abi_long arg1, abi_long arg2,
2195 abi_long arg3, abi_long arg4, abi_long arg5)
2196{
d2ee72a5 2197 int is_creat = (arg1 & TARGET_O_CREAT);
74d753ac
MW
2198
2199 print_syscall_prologue(name);
2200 print_string(arg0, 0);
2201 print_open_flags(arg1, (is_creat == 0));
2202 if (is_creat)
2203 print_file_mode(arg2, 1);
2204 print_syscall_epilogue(name);
2205}
2206#endif
2207
2208#ifdef TARGET_NR_openat
2209static void
2210print_openat(const struct syscallname *name,
2211 abi_long arg0, abi_long arg1, abi_long arg2,
2212 abi_long arg3, abi_long arg4, abi_long arg5)
2213{
d2ee72a5 2214 int is_creat = (arg2 & TARGET_O_CREAT);
74d753ac
MW
2215
2216 print_syscall_prologue(name);
2217 print_at_dirfd(arg0, 0);
2218 print_string(arg1, 0);
2219 print_open_flags(arg2, (is_creat == 0));
2220 if (is_creat)
2221 print_file_mode(arg3, 1);
2222 print_syscall_epilogue(name);
2223}
2224#endif
2225
2226#ifdef TARGET_NR_mq_unlink
2227static void
2228print_mq_unlink(const struct syscallname *name,
2229 abi_long arg0, abi_long arg1, abi_long arg2,
2230 abi_long arg3, abi_long arg4, abi_long arg5)
2231{
2232 print_syscall_prologue(name);
2233 print_string(arg0, 1);
2234 print_syscall_epilogue(name);
2235}
2236#endif
2237
2238#if defined(TARGET_NR_fstatat64) || defined(TARGET_NR_newfstatat)
2239static void
2240print_fstatat64(const struct syscallname *name,
2241 abi_long arg0, abi_long arg1, abi_long arg2,
2242 abi_long arg3, abi_long arg4, abi_long arg5)
2243{
2244 print_syscall_prologue(name);
2245 print_at_dirfd(arg0, 0);
2246 print_string(arg1, 0);
2247 print_pointer(arg2, 0);
2248 print_flags(at_file_flags, arg3, 1);
2249 print_syscall_epilogue(name);
2250}
2251#define print_newfstatat print_fstatat64
2252#endif
2253
2254#ifdef TARGET_NR_readlink
2255static void
2256print_readlink(const struct syscallname *name,
2257 abi_long arg0, abi_long arg1, abi_long arg2,
2258 abi_long arg3, abi_long arg4, abi_long arg5)
2259{
2260 print_syscall_prologue(name);
2261 print_string(arg0, 0);
2262 print_pointer(arg1, 0);
d2ee72a5 2263 print_raw_param("%u", arg2, 1);
74d753ac
MW
2264 print_syscall_epilogue(name);
2265}
2266#endif
2267
2268#ifdef TARGET_NR_readlinkat
2269static void
2270print_readlinkat(const struct syscallname *name,
2271 abi_long arg0, abi_long arg1, abi_long arg2,
2272 abi_long arg3, abi_long arg4, abi_long arg5)
2273{
2274 print_syscall_prologue(name);
2275 print_at_dirfd(arg0, 0);
2276 print_string(arg1, 0);
2277 print_pointer(arg2, 0);
d2ee72a5 2278 print_raw_param("%u", arg3, 1);
74d753ac
MW
2279 print_syscall_epilogue(name);
2280}
2281#endif
2282
2283#ifdef TARGET_NR_rename
2284static void
2285print_rename(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 print_syscall_prologue(name);
2290 print_string(arg0, 0);
2291 print_string(arg1, 1);
2292 print_syscall_epilogue(name);
2293}
2294#endif
2295
2296#ifdef TARGET_NR_renameat
2297static void
2298print_renameat(const struct syscallname *name,
2299 abi_long arg0, abi_long arg1, abi_long arg2,
2300 abi_long arg3, abi_long arg4, abi_long arg5)
2301{
2302 print_syscall_prologue(name);
2303 print_at_dirfd(arg0, 0);
2304 print_string(arg1, 0);
2305 print_at_dirfd(arg2, 0);
2306 print_string(arg3, 1);
2307 print_syscall_epilogue(name);
2308}
2309#endif
2310
2311#ifdef TARGET_NR_statfs
2312static void
2313print_statfs(const struct syscallname *name,
2314 abi_long arg0, abi_long arg1, abi_long arg2,
2315 abi_long arg3, abi_long arg4, abi_long arg5)
2316{
2317 print_syscall_prologue(name);
2318 print_string(arg0, 0);
2319 print_pointer(arg1, 1);
2320 print_syscall_epilogue(name);
2321}
4f7f8924
AR
2322#endif
2323
2324#ifdef TARGET_NR_statfs64
2325static void
2326print_statfs64(const struct syscallname *name,
2327 abi_long arg0, abi_long arg1, abi_long arg2,
2328 abi_long arg3, abi_long arg4, abi_long arg5)
2329{
2330 print_syscall_prologue(name);
2331 print_string(arg0, 0);
2332 print_pointer(arg1, 1);
2333 print_syscall_epilogue(name);
2334}
74d753ac
MW
2335#endif
2336
2337#ifdef TARGET_NR_symlink
2338static void
2339print_symlink(const struct syscallname *name,
2340 abi_long arg0, abi_long arg1, abi_long arg2,
2341 abi_long arg3, abi_long arg4, abi_long arg5)
2342{
2343 print_syscall_prologue(name);
2344 print_string(arg0, 0);
2345 print_string(arg1, 1);
2346 print_syscall_epilogue(name);
2347}
2348#endif
2349
2350#ifdef TARGET_NR_symlinkat
2351static void
2352print_symlinkat(const struct syscallname *name,
2353 abi_long arg0, abi_long arg1, abi_long arg2,
2354 abi_long arg3, abi_long arg4, abi_long arg5)
2355{
2356 print_syscall_prologue(name);
2357 print_string(arg0, 0);
2358 print_at_dirfd(arg1, 0);
2359 print_string(arg2, 1);
2360 print_syscall_epilogue(name);
2361}
2362#endif
2363
2364#ifdef TARGET_NR_mount
2365static void
2366print_mount(const struct syscallname *name,
2367 abi_long arg0, abi_long arg1, abi_long arg2,
2368 abi_long arg3, abi_long arg4, abi_long arg5)
2369{
2370 print_syscall_prologue(name);
2371 print_string(arg0, 0);
2372 print_string(arg1, 0);
2373 print_string(arg2, 0);
2374 print_flags(mount_flags, arg3, 0);
2375 print_pointer(arg4, 1);
2376 print_syscall_epilogue(name);
2377}
2378#endif
2379
2380#ifdef TARGET_NR_umount
2381static void
2382print_umount(const struct syscallname *name,
2383 abi_long arg0, abi_long arg1, abi_long arg2,
2384 abi_long arg3, abi_long arg4, abi_long arg5)
2385{
2386 print_syscall_prologue(name);
2387 print_string(arg0, 1);
2388 print_syscall_epilogue(name);
2389}
2390#endif
2391
2392#ifdef TARGET_NR_umount2
2393static void
2394print_umount2(const struct syscallname *name,
2395 abi_long arg0, abi_long arg1, abi_long arg2,
2396 abi_long arg3, abi_long arg4, abi_long arg5)
2397{
2398 print_syscall_prologue(name);
2399 print_string(arg0, 0);
2400 print_flags(umount2_flags, arg1, 1);
2401 print_syscall_epilogue(name);
2402}
2403#endif
2404
2405#ifdef TARGET_NR_unlink
2406static void
2407print_unlink(const struct syscallname *name,
2408 abi_long arg0, abi_long arg1, abi_long arg2,
2409 abi_long arg3, abi_long arg4, abi_long arg5)
2410{
2411 print_syscall_prologue(name);
2412 print_string(arg0, 1);
2413 print_syscall_epilogue(name);
2414}
2415#endif
2416
2417#ifdef TARGET_NR_unlinkat
2418static void
2419print_unlinkat(const struct syscallname *name,
2420 abi_long arg0, abi_long arg1, abi_long arg2,
2421 abi_long arg3, abi_long arg4, abi_long arg5)
2422{
2423 print_syscall_prologue(name);
2424 print_at_dirfd(arg0, 0);
2425 print_string(arg1, 0);
2426 print_flags(unlinkat_flags, arg2, 1);
2427 print_syscall_epilogue(name);
2428}
2429#endif
2430
2431#ifdef TARGET_NR_utime
2432static void
2433print_utime(const struct syscallname *name,
2434 abi_long arg0, abi_long arg1, abi_long arg2,
2435 abi_long arg3, abi_long arg4, abi_long arg5)
2436{
2437 print_syscall_prologue(name);
2438 print_string(arg0, 0);
2439 print_pointer(arg1, 1);
2440 print_syscall_epilogue(name);
2441}
2442#endif
2443
2444#ifdef TARGET_NR_utimes
2445static void
2446print_utimes(const struct syscallname *name,
2447 abi_long arg0, abi_long arg1, abi_long arg2,
2448 abi_long arg3, abi_long arg4, abi_long arg5)
2449{
2450 print_syscall_prologue(name);
2451 print_string(arg0, 0);
2452 print_pointer(arg1, 1);
2453 print_syscall_epilogue(name);
2454}
2455#endif
2456
2457#ifdef TARGET_NR_utimensat
2458static void
2459print_utimensat(const struct syscallname *name,
2460 abi_long arg0, abi_long arg1, abi_long arg2,
2461 abi_long arg3, abi_long arg4, abi_long arg5)
2462{
2463 print_syscall_prologue(name);
2464 print_at_dirfd(arg0, 0);
2465 print_string(arg1, 0);
2466 print_pointer(arg2, 0);
2467 print_flags(at_file_flags, arg3, 1);
2468 print_syscall_epilogue(name);
2469}
2470#endif
2471
8d9016c0 2472#if defined(TARGET_NR_mmap) || defined(TARGET_NR_mmap2)
74d753ac
MW
2473static void
2474print_mmap(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_pointer(arg0, 0);
d2ee72a5 2480 print_raw_param("%d", arg1, 0);
74d753ac
MW
2481 print_flags(mmap_prot_flags, arg2, 0);
2482 print_flags(mmap_flags, arg3, 0);
d2ee72a5
LV
2483 print_raw_param("%d", arg4, 0);
2484 print_raw_param("%#x", arg5, 1);
74d753ac
MW
2485 print_syscall_epilogue(name);
2486}
2487#define print_mmap2 print_mmap
2488#endif
2489
2490#ifdef TARGET_NR_mprotect
2491static void
2492print_mprotect(const struct syscallname *name,
2493 abi_long arg0, abi_long arg1, abi_long arg2,
2494 abi_long arg3, abi_long arg4, abi_long arg5)
2495{
2496 print_syscall_prologue(name);
2497 print_pointer(arg0, 0);
d2ee72a5 2498 print_raw_param("%d", arg1, 0);
74d753ac
MW
2499 print_flags(mmap_prot_flags, arg2, 1);
2500 print_syscall_epilogue(name);
2501}
2502#endif
2503
2504#ifdef TARGET_NR_munmap
2505static void
2506print_munmap(const struct syscallname *name,
2507 abi_long arg0, abi_long arg1, abi_long arg2,
2508 abi_long arg3, abi_long arg4, abi_long arg5)
2509{
2510 print_syscall_prologue(name);
2511 print_pointer(arg0, 0);
d2ee72a5 2512 print_raw_param("%d", arg1, 1);
74d753ac
MW
2513 print_syscall_epilogue(name);
2514}
2515#endif
2516
2517#ifdef TARGET_NR_futex
2518static void print_futex_op(abi_long tflag, int last)
2519{
2520#define print_op(val) \
2521if( cmd == val ) { \
2522 gemu_log(#val); \
2523 return; \
2524}
2525
d2ee72a5 2526 int cmd = (int)tflag;
74d753ac 2527#ifdef FUTEX_PRIVATE_FLAG
5f2243f3 2528 if (cmd & FUTEX_PRIVATE_FLAG) {
74d753ac 2529 gemu_log("FUTEX_PRIVATE_FLAG|");
5f2243f3
PB
2530 cmd &= ~FUTEX_PRIVATE_FLAG;
2531 }
bfb669f3
JR
2532#endif
2533#ifdef FUTEX_CLOCK_REALTIME
2534 if (cmd & FUTEX_CLOCK_REALTIME) {
2535 gemu_log("FUTEX_CLOCK_REALTIME|");
2536 cmd &= ~FUTEX_CLOCK_REALTIME;
2537 }
74d753ac
MW
2538#endif
2539 print_op(FUTEX_WAIT)
2540 print_op(FUTEX_WAKE)
2541 print_op(FUTEX_FD)
2542 print_op(FUTEX_REQUEUE)
2543 print_op(FUTEX_CMP_REQUEUE)
2544 print_op(FUTEX_WAKE_OP)
2545 print_op(FUTEX_LOCK_PI)
2546 print_op(FUTEX_UNLOCK_PI)
2547 print_op(FUTEX_TRYLOCK_PI)
2548#ifdef FUTEX_WAIT_BITSET
2549 print_op(FUTEX_WAIT_BITSET)
2550#endif
2551#ifdef FUTEX_WAKE_BITSET
2552 print_op(FUTEX_WAKE_BITSET)
2553#endif
2554 /* unknown values */
2555 gemu_log("%d",cmd);
2556}
2557
2558static void
2559print_futex(const struct syscallname *name,
2560 abi_long arg0, abi_long arg1, abi_long arg2,
2561 abi_long arg3, abi_long arg4, abi_long arg5)
2562{
2563 print_syscall_prologue(name);
2564 print_pointer(arg0, 0);
2565 print_futex_op(arg1, 0);
d2ee72a5 2566 print_raw_param(",%d", arg2, 0);
74d753ac
MW
2567 print_pointer(arg3, 0); /* struct timespec */
2568 print_pointer(arg4, 0);
d2ee72a5 2569 print_raw_param("%d", arg4, 1);
74d753ac
MW
2570 print_syscall_epilogue(name);
2571}
2572#endif
2573
608e5592
LV
2574#ifdef TARGET_NR_kill
2575static void
2576print_kill(const struct syscallname *name,
2577 abi_long arg0, abi_long arg1, abi_long arg2,
2578 abi_long arg3, abi_long arg4, abi_long arg5)
2579{
2580 print_syscall_prologue(name);
2581 print_raw_param("%d", arg0, 0);
2582 print_signal(arg1, 1);
2583 print_syscall_epilogue(name);
2584}
2585#endif
2586
5162264e
MS
2587#ifdef TARGET_NR_tkill
2588static void
2589print_tkill(const struct syscallname *name,
2590 abi_long arg0, abi_long arg1, abi_long arg2,
2591 abi_long arg3, abi_long arg4, abi_long arg5)
2592{
2593 print_syscall_prologue(name);
2594 print_raw_param("%d", arg0, 0);
2595 print_signal(arg1, 1);
2596 print_syscall_epilogue(name);
2597}
2598#endif
2599
2600#ifdef TARGET_NR_tgkill
2601static void
2602print_tgkill(const struct syscallname *name,
2603 abi_long arg0, abi_long arg1, abi_long arg2,
2604 abi_long arg3, abi_long arg4, abi_long arg5)
2605{
2606 print_syscall_prologue(name);
2607 print_raw_param("%d", arg0, 0);
2608 print_raw_param("%d", arg1, 0);
2609 print_signal(arg2, 1);
2610 print_syscall_epilogue(name);
2611}
2612#endif
2613
33189d31
TS
2614/*
2615 * An array of all of the syscalls we know about
2616 */
2617
7ccfb2eb 2618static const struct syscallname scnames[] = {
33189d31
TS
2619#include "strace.list"
2620};
2621
b1503cda 2622static int nsyscalls = ARRAY_SIZE(scnames);
33189d31
TS
2623
2624/*
2625 * The public interface to this module.
2626 */
2627void
2628print_syscall(int num,
c16f9ed3
FB
2629 abi_long arg1, abi_long arg2, abi_long arg3,
2630 abi_long arg4, abi_long arg5, abi_long arg6)
33189d31
TS
2631{
2632 int i;
7ccfb2eb 2633 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 ")";
33189d31
TS
2634
2635 gemu_log("%d ", getpid() );
2636
2637 for(i=0;i<nsyscalls;i++)
2638 if( scnames[i].nr == num ) {
2639 if( scnames[i].call != NULL ) {
2640 scnames[i].call(&scnames[i],arg1,arg2,arg3,arg4,arg5,arg6);
2641 } else {
6b23f777
FB
2642 /* XXX: this format system is broken because it uses
2643 host types and host pointers for strings */
33189d31
TS
2644 if( scnames[i].format != NULL )
2645 format = scnames[i].format;
2646 gemu_log(format,scnames[i].name, arg1,arg2,arg3,arg4,arg5,arg6);
2647 }
74c11e55 2648 return;
33189d31 2649 }
74c11e55 2650 gemu_log("Unknown syscall %d\n", num);
33189d31
TS
2651}
2652
2653
2654void
c16f9ed3 2655print_syscall_ret(int num, abi_long ret)
33189d31
TS
2656{
2657 int i;
7dcdaeaf 2658 const char *errstr = NULL;
33189d31
TS
2659
2660 for(i=0;i<nsyscalls;i++)
2661 if( scnames[i].nr == num ) {
2662 if( scnames[i].result != NULL ) {
2663 scnames[i].result(&scnames[i],ret);
2664 } else {
962b289e
AG
2665 if (ret < 0) {
2666 errstr = target_strerror(-ret);
2667 }
2668 if (errstr) {
2669 gemu_log(" = -1 errno=" TARGET_ABI_FMT_ld " (%s)\n",
2670 -ret, errstr);
33189d31 2671 } else {
c16f9ed3 2672 gemu_log(" = " TARGET_ABI_FMT_ld "\n", ret);
33189d31
TS
2673 }
2674 }
2675 break;
2676 }
2677}
0cb581d6
PM
2678
2679void print_taken_signal(int target_signum, const target_siginfo_t *tinfo)
2680{
2681 /* Print the strace output for a signal being taken:
2682 * --- SIGSEGV {si_signo=SIGSEGV, si_code=SI_KERNEL, si_addr=0} ---
2683 */
2684 gemu_log("--- ");
2685 print_signal(target_signum, 1);
2686 gemu_log(" ");
2687 print_siginfo(tinfo);
2688 gemu_log(" ---\n");
2689}