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