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