]> git.proxmox.com Git - mirror_qemu.git/blame - linux-user/strace.c
tests: acpi: aarch64: Add *.topology tables
[mirror_qemu.git] / linux-user / strace.c
CommitLineData
d39594e9 1#include "qemu/osdep.h"
a44d57a3 2
33189d31
TS
3#include <sys/ipc.h>
4#include <sys/msg.h>
5#include <sys/sem.h>
6#include <sys/shm.h>
7#include <sys/select.h>
74d753ac 8#include <sys/mount.h>
fb3aabf3 9#include <arpa/inet.h>
38987eab 10#include <netinet/in.h>
fb3aabf3 11#include <netinet/tcp.h>
fe51b0a5 12#include <netinet/udp.h>
fb3aabf3 13#include <linux/if_packet.h>
38987eab 14#include <linux/in6.h>
814ae70f 15#include <linux/netlink.h>
608e5592 16#include <sched.h>
33189d31 17#include "qemu.h"
3b249d26 18#include "user-internals.h"
a44d57a3 19#include "strace.h"
7b72aa1d 20#include "signal-common.h"
375ce49b 21#include "target_mman.h"
33189d31 22
33189d31
TS
23struct syscallname {
24 int nr;
7ccfb2eb
BS
25 const char *name;
26 const char *format;
a0939b89 27 void (*call)(CPUArchState *, const struct syscallname *,
c16f9ed3
FB
28 abi_long, abi_long, abi_long,
29 abi_long, abi_long, abi_long);
a0939b89 30 void (*result)(CPUArchState *, const struct syscallname *, abi_long,
c84be71f
FB
31 abi_long, abi_long, abi_long,
32 abi_long, abi_long, abi_long);
33189d31
TS
33};
34
74d753ac
MW
35/*
36 * It is possible that target doesn't have syscall that uses
37 * following flags but we don't want the compiler to warn
38 * us about them being unused. Same applies to utility print
39 * functions. It is ok to keep them while not used.
40 */
41#define UNUSED __attribute__ ((unused))
74d753ac
MW
42
43/*
44 * Structure used to translate flag values into strings. This is
45 * similar that is in the actual strace tool.
46 */
47struct flags {
48 abi_long f_value; /* flag */
49 const char *f_string; /* stringified flag */
50};
51
52/* common flags for all architectures */
53#define FLAG_GENERIC(name) { name, #name }
54/* target specific flags (syscall_defs.h has TARGET_<flag>) */
55#define FLAG_TARGET(name) { TARGET_ ## name, #name }
56/* end of flags array */
57#define FLAG_END { 0, NULL }
58
45f56799
FB
59/* Structure used to translate enumerated values into strings */
60struct enums {
61 abi_long e_value; /* enum value */
62 const char *e_string; /* stringified enum */
63};
64
65/* common enums for all architectures */
66#define ENUM_GENERIC(name) { name, #name }
67/* target specific enums */
68#define ENUM_TARGET(name) { TARGET_ ## name, #name }
69/* end of enums array */
70#define ENUM_END { 0, NULL }
71
74d753ac
MW
72UNUSED static const char *get_comma(int);
73UNUSED static void print_pointer(abi_long, int);
74UNUSED static void print_flags(const struct flags *, abi_long, int);
45f56799 75UNUSED static void print_enums(const struct enums *, abi_long, int);
74d753ac
MW
76UNUSED static void print_at_dirfd(abi_long, int);
77UNUSED static void print_file_mode(abi_long, int);
78UNUSED static void print_open_flags(abi_long, int);
79UNUSED static void print_syscall_prologue(const struct syscallname *);
80UNUSED static void print_syscall_epilogue(const struct syscallname *);
81UNUSED static void print_string(abi_long, int);
fb3aabf3 82UNUSED static void print_buf(abi_long addr, abi_long len, int last);
74d753ac
MW
83UNUSED static void print_raw_param(const char *, abi_long, int);
84UNUSED static void print_timeval(abi_ulong, int);
1a674adf 85UNUSED static void print_timespec(abi_ulong, int);
aad43d15 86UNUSED static void print_timespec64(abi_ulong, int);
6d33e036 87UNUSED static void print_timezone(abi_ulong, int);
1a674adf 88UNUSED static void print_itimerval(abi_ulong, int);
74d753ac 89UNUSED static void print_number(abi_long, int);
608e5592 90UNUSED static void print_signal(abi_ulong, int);
42b15d70 91UNUSED static void print_sockaddr(abi_ulong, abi_long, int);
fb3aabf3
LV
92UNUSED static void print_socket_domain(int domain);
93UNUSED static void print_socket_type(int type);
94UNUSED static void print_socket_protocol(int domain, int type, int protocol);
74d753ac 95
33189d31
TS
96/*
97 * Utility functions
98 */
99static void
100print_ipc_cmd(int cmd)
101{
102#define output_cmd(val) \
103if( cmd == val ) { \
4b25a506 104 qemu_log(#val); \
33189d31
TS
105 return; \
106}
107
108 cmd &= 0xff;
109
110 /* General IPC commands */
111 output_cmd( IPC_RMID );
112 output_cmd( IPC_SET );
113 output_cmd( IPC_STAT );
114 output_cmd( IPC_INFO );
115 /* msgctl() commands */
33189d31
TS
116 output_cmd( MSG_STAT );
117 output_cmd( MSG_INFO );
33189d31
TS
118 /* shmctl() commands */
119 output_cmd( SHM_LOCK );
120 output_cmd( SHM_UNLOCK );
121 output_cmd( SHM_STAT );
122 output_cmd( SHM_INFO );
123 /* semctl() commands */
124 output_cmd( GETPID );
125 output_cmd( GETVAL );
126 output_cmd( GETALL );
127 output_cmd( GETNCNT );
128 output_cmd( GETZCNT );
129 output_cmd( SETVAL );
130 output_cmd( SETALL );
131 output_cmd( SEM_STAT );
132 output_cmd( SEM_INFO );
133 output_cmd( IPC_RMID );
134 output_cmd( IPC_RMID );
135 output_cmd( IPC_RMID );
136 output_cmd( IPC_RMID );
137 output_cmd( IPC_RMID );
138 output_cmd( IPC_RMID );
139 output_cmd( IPC_RMID );
140 output_cmd( IPC_RMID );
141 output_cmd( IPC_RMID );
142
143 /* Some value we don't recognize */
4b25a506 144 qemu_log("%d", cmd);
33189d31
TS
145}
146
7b72aa1d
HD
147static const char * const target_signal_name[] = {
148#define MAKE_SIG_ENTRY(sig) [TARGET_##sig] = #sig,
149 MAKE_SIGNAL_LIST
150#undef MAKE_SIG_ENTRY
151};
152
608e5592
LV
153static void
154print_signal(abi_ulong arg, int last)
155{
156 const char *signal_name = NULL;
7b72aa1d
HD
157
158 if (arg < ARRAY_SIZE(target_signal_name)) {
159 signal_name = target_signal_name[arg];
608e5592 160 }
7b72aa1d 161
608e5592 162 if (signal_name == NULL) {
abe20840 163 print_raw_param("%ld", arg, last);
608e5592
LV
164 return;
165 }
4b25a506 166 qemu_log("%s%s", signal_name, get_comma(last));
608e5592
LV
167}
168
0cb581d6
PM
169static void print_si_code(int arg)
170{
171 const char *codename = NULL;
172
173 switch (arg) {
174 case SI_USER:
175 codename = "SI_USER";
176 break;
177 case SI_KERNEL:
178 codename = "SI_KERNEL";
179 break;
180 case SI_QUEUE:
181 codename = "SI_QUEUE";
182 break;
183 case SI_TIMER:
184 codename = "SI_TIMER";
185 break;
186 case SI_MESGQ:
187 codename = "SI_MESGQ";
188 break;
189 case SI_ASYNCIO:
190 codename = "SI_ASYNCIO";
191 break;
192 case SI_SIGIO:
193 codename = "SI_SIGIO";
194 break;
195 case SI_TKILL:
196 codename = "SI_TKILL";
197 break;
198 default:
4b25a506 199 qemu_log("%d", arg);
0cb581d6
PM
200 return;
201 }
4b25a506 202 qemu_log("%s", codename);
0cb581d6
PM
203}
204
ba9fcea1
MS
205static void get_target_siginfo(target_siginfo_t *tinfo,
206 const target_siginfo_t *info)
207{
208 abi_ulong sival_ptr;
209
210 int sig;
211 int si_errno;
212 int si_code;
213 int si_type;
214
215 __get_user(sig, &info->si_signo);
216 __get_user(si_errno, &tinfo->si_errno);
217 __get_user(si_code, &info->si_code);
218
219 tinfo->si_signo = sig;
220 tinfo->si_errno = si_errno;
221 tinfo->si_code = si_code;
222
223 /* Ensure we don't leak random junk to the guest later */
224 memset(tinfo->_sifields._pad, 0, sizeof(tinfo->_sifields._pad));
225
226 /* This is awkward, because we have to use a combination of
227 * the si_code and si_signo to figure out which of the union's
228 * members are valid. (Within the host kernel it is always possible
229 * to tell, but the kernel carefully avoids giving userspace the
230 * high 16 bits of si_code, so we don't have the information to
231 * do this the easy way...) We therefore make our best guess,
232 * bearing in mind that a guest can spoof most of the si_codes
233 * via rt_sigqueueinfo() if it likes.
234 *
235 * Once we have made our guess, we record it in the top 16 bits of
236 * the si_code, so that print_siginfo() later can use it.
237 * print_siginfo() will strip these top bits out before printing
238 * the si_code.
239 */
240
241 switch (si_code) {
242 case SI_USER:
243 case SI_TKILL:
244 case SI_KERNEL:
245 /* Sent via kill(), tkill() or tgkill(), or direct from the kernel.
246 * These are the only unspoofable si_code values.
247 */
248 __get_user(tinfo->_sifields._kill._pid, &info->_sifields._kill._pid);
249 __get_user(tinfo->_sifields._kill._uid, &info->_sifields._kill._uid);
250 si_type = QEMU_SI_KILL;
251 break;
252 default:
253 /* Everything else is spoofable. Make best guess based on signal */
254 switch (sig) {
255 case TARGET_SIGCHLD:
256 __get_user(tinfo->_sifields._sigchld._pid,
257 &info->_sifields._sigchld._pid);
258 __get_user(tinfo->_sifields._sigchld._uid,
259 &info->_sifields._sigchld._uid);
260 __get_user(tinfo->_sifields._sigchld._status,
261 &info->_sifields._sigchld._status);
262 __get_user(tinfo->_sifields._sigchld._utime,
263 &info->_sifields._sigchld._utime);
264 __get_user(tinfo->_sifields._sigchld._stime,
265 &info->_sifields._sigchld._stime);
266 si_type = QEMU_SI_CHLD;
267 break;
268 case TARGET_SIGIO:
269 __get_user(tinfo->_sifields._sigpoll._band,
270 &info->_sifields._sigpoll._band);
271 __get_user(tinfo->_sifields._sigpoll._fd,
272 &info->_sifields._sigpoll._fd);
273 si_type = QEMU_SI_POLL;
274 break;
275 default:
276 /* Assume a sigqueue()/mq_notify()/rt_sigqueueinfo() source. */
277 __get_user(tinfo->_sifields._rt._pid, &info->_sifields._rt._pid);
278 __get_user(tinfo->_sifields._rt._uid, &info->_sifields._rt._uid);
279 /* XXX: potential problem if 64 bit */
280 __get_user(sival_ptr, &info->_sifields._rt._sigval.sival_ptr);
281 tinfo->_sifields._rt._sigval.sival_ptr = sival_ptr;
282
283 si_type = QEMU_SI_RT;
284 break;
285 }
286 break;
287 }
288
289 tinfo->si_code = deposit32(si_code, 16, 16, si_type);
290}
291
0cb581d6
PM
292static void print_siginfo(const target_siginfo_t *tinfo)
293{
294 /* Print a target_siginfo_t in the format desired for printing
295 * signals being taken. We assume the target_siginfo_t is in the
296 * internal form where the top 16 bits of si_code indicate which
297 * part of the union is valid, rather than in the guest-visible
298 * form where the bottom 16 bits are sign-extended into the top 16.
299 */
300 int si_type = extract32(tinfo->si_code, 16, 16);
301 int si_code = sextract32(tinfo->si_code, 0, 16);
302
4b25a506 303 qemu_log("{si_signo=");
0cb581d6 304 print_signal(tinfo->si_signo, 1);
4b25a506 305 qemu_log(", si_code=");
0cb581d6
PM
306 print_si_code(si_code);
307
308 switch (si_type) {
309 case QEMU_SI_KILL:
4b25a506 310 qemu_log(", si_pid=%u, si_uid=%u",
0cb581d6
PM
311 (unsigned int)tinfo->_sifields._kill._pid,
312 (unsigned int)tinfo->_sifields._kill._uid);
313 break;
314 case QEMU_SI_TIMER:
4b25a506 315 qemu_log(", si_timer1=%u, si_timer2=%u",
0cb581d6
PM
316 tinfo->_sifields._timer._timer1,
317 tinfo->_sifields._timer._timer2);
318 break;
319 case QEMU_SI_POLL:
4b25a506 320 qemu_log(", si_band=%d, si_fd=%d",
0cb581d6
PM
321 tinfo->_sifields._sigpoll._band,
322 tinfo->_sifields._sigpoll._fd);
323 break;
324 case QEMU_SI_FAULT:
4b25a506 325 qemu_log(", si_addr=");
0cb581d6
PM
326 print_pointer(tinfo->_sifields._sigfault._addr, 1);
327 break;
328 case QEMU_SI_CHLD:
4b25a506 329 qemu_log(", si_pid=%u, si_uid=%u, si_status=%d"
0cb581d6
PM
330 ", si_utime=" TARGET_ABI_FMT_ld
331 ", si_stime=" TARGET_ABI_FMT_ld,
332 (unsigned int)(tinfo->_sifields._sigchld._pid),
333 (unsigned int)(tinfo->_sifields._sigchld._uid),
334 tinfo->_sifields._sigchld._status,
335 tinfo->_sifields._sigchld._utime,
336 tinfo->_sifields._sigchld._stime);
337 break;
338 case QEMU_SI_RT:
4b25a506 339 qemu_log(", si_pid=%u, si_uid=%u, si_sigval=" TARGET_ABI_FMT_ld,
0cb581d6
PM
340 (unsigned int)tinfo->_sifields._rt._pid,
341 (unsigned int)tinfo->_sifields._rt._uid,
342 tinfo->_sifields._rt._sigval.sival_ptr);
343 break;
344 default:
345 g_assert_not_reached();
346 }
4b25a506 347 qemu_log("}");
0cb581d6
PM
348}
349
fb3aabf3 350static void
42b15d70 351print_sockaddr(abi_ulong addr, abi_long addrlen, int last)
fb3aabf3
LV
352{
353 struct target_sockaddr *sa;
354 int i;
355 int sa_family;
356
357 sa = lock_user(VERIFY_READ, addr, addrlen, 1);
358 if (sa) {
359 sa_family = tswap16(sa->sa_family);
360 switch (sa_family) {
361 case AF_UNIX: {
362 struct target_sockaddr_un *un = (struct target_sockaddr_un *)sa;
363 int i;
4b25a506 364 qemu_log("{sun_family=AF_UNIX,sun_path=\"");
fb3aabf3
LV
365 for (i = 0; i < addrlen -
366 offsetof(struct target_sockaddr_un, sun_path) &&
367 un->sun_path[i]; i++) {
4b25a506 368 qemu_log("%c", un->sun_path[i]);
fb3aabf3 369 }
4b25a506 370 qemu_log("\"}");
fb3aabf3
LV
371 break;
372 }
373 case AF_INET: {
374 struct target_sockaddr_in *in = (struct target_sockaddr_in *)sa;
375 uint8_t *c = (uint8_t *)&in->sin_addr.s_addr;
4b25a506 376 qemu_log("{sin_family=AF_INET,sin_port=htons(%d),",
fb3aabf3 377 ntohs(in->sin_port));
4b25a506 378 qemu_log("sin_addr=inet_addr(\"%d.%d.%d.%d\")",
fb3aabf3 379 c[0], c[1], c[2], c[3]);
4b25a506 380 qemu_log("}");
fb3aabf3
LV
381 break;
382 }
383 case AF_PACKET: {
384 struct target_sockaddr_ll *ll = (struct target_sockaddr_ll *)sa;
385 uint8_t *c = (uint8_t *)&ll->sll_addr;
4b25a506 386 qemu_log("{sll_family=AF_PACKET,"
fb3aabf3
LV
387 "sll_protocol=htons(0x%04x),if%d,pkttype=",
388 ntohs(ll->sll_protocol), ll->sll_ifindex);
389 switch (ll->sll_pkttype) {
390 case PACKET_HOST:
4b25a506 391 qemu_log("PACKET_HOST");
fb3aabf3
LV
392 break;
393 case PACKET_BROADCAST:
4b25a506 394 qemu_log("PACKET_BROADCAST");
fb3aabf3
LV
395 break;
396 case PACKET_MULTICAST:
4b25a506 397 qemu_log("PACKET_MULTICAST");
fb3aabf3
LV
398 break;
399 case PACKET_OTHERHOST:
4b25a506 400 qemu_log("PACKET_OTHERHOST");
fb3aabf3
LV
401 break;
402 case PACKET_OUTGOING:
4b25a506 403 qemu_log("PACKET_OUTGOING");
fb3aabf3
LV
404 break;
405 default:
4b25a506 406 qemu_log("%d", ll->sll_pkttype);
fb3aabf3
LV
407 break;
408 }
4b25a506 409 qemu_log(",sll_addr=%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x",
fb3aabf3 410 c[0], c[1], c[2], c[3], c[4], c[5], c[6], c[7]);
4b25a506 411 qemu_log("}");
fb3aabf3
LV
412 break;
413 }
814ae70f
PMD
414 case AF_NETLINK: {
415 struct target_sockaddr_nl *nl = (struct target_sockaddr_nl *)sa;
4b25a506 416 qemu_log("{nl_family=AF_NETLINK,nl_pid=%u,nl_groups=%u}",
814ae70f
PMD
417 tswap32(nl->nl_pid), tswap32(nl->nl_groups));
418 break;
419 }
fb3aabf3 420 default:
4b25a506 421 qemu_log("{sa_family=%d, sa_data={", sa->sa_family);
fb3aabf3 422 for (i = 0; i < 13; i++) {
4b25a506 423 qemu_log("%02x, ", sa->sa_data[i]);
fb3aabf3 424 }
4b25a506
JK
425 qemu_log("%02x}", sa->sa_data[i]);
426 qemu_log("}");
fb3aabf3
LV
427 break;
428 }
429 unlock_user(sa, addr, 0);
430 } else {
431 print_raw_param("0x"TARGET_ABI_FMT_lx, addr, 0);
432 }
4b25a506 433 qemu_log(", "TARGET_ABI_FMT_ld"%s", addrlen, get_comma(last));
fb3aabf3
LV
434}
435
436static void
437print_socket_domain(int domain)
438{
439 switch (domain) {
440 case PF_UNIX:
4b25a506 441 qemu_log("PF_UNIX");
fb3aabf3
LV
442 break;
443 case PF_INET:
4b25a506 444 qemu_log("PF_INET");
fb3aabf3 445 break;
814ae70f 446 case PF_NETLINK:
4b25a506 447 qemu_log("PF_NETLINK");
814ae70f 448 break;
fb3aabf3 449 case PF_PACKET:
4b25a506 450 qemu_log("PF_PACKET");
fb3aabf3
LV
451 break;
452 default:
4b25a506 453 qemu_log("%d", domain);
fb3aabf3
LV
454 break;
455 }
456}
457
458static void
459print_socket_type(int type)
460{
2039b1b0 461 switch (type & TARGET_SOCK_TYPE_MASK) {
fb3aabf3 462 case TARGET_SOCK_DGRAM:
4b25a506 463 qemu_log("SOCK_DGRAM");
fb3aabf3
LV
464 break;
465 case TARGET_SOCK_STREAM:
4b25a506 466 qemu_log("SOCK_STREAM");
fb3aabf3
LV
467 break;
468 case TARGET_SOCK_RAW:
4b25a506 469 qemu_log("SOCK_RAW");
fb3aabf3
LV
470 break;
471 case TARGET_SOCK_RDM:
4b25a506 472 qemu_log("SOCK_RDM");
fb3aabf3
LV
473 break;
474 case TARGET_SOCK_SEQPACKET:
4b25a506 475 qemu_log("SOCK_SEQPACKET");
fb3aabf3
LV
476 break;
477 case TARGET_SOCK_PACKET:
4b25a506 478 qemu_log("SOCK_PACKET");
fb3aabf3
LV
479 break;
480 }
2039b1b0
LV
481 if (type & TARGET_SOCK_CLOEXEC) {
482 qemu_log("|SOCK_CLOEXEC");
483 }
484 if (type & TARGET_SOCK_NONBLOCK) {
485 qemu_log("|SOCK_NONBLOCK");
486 }
fb3aabf3
LV
487}
488
489static void
490print_socket_protocol(int domain, int type, int protocol)
491{
492 if (domain == AF_PACKET ||
493 (domain == AF_INET && type == TARGET_SOCK_PACKET)) {
494 switch (protocol) {
495 case 0x0003:
4b25a506 496 qemu_log("ETH_P_ALL");
fb3aabf3
LV
497 break;
498 default:
4b25a506 499 qemu_log("%d", protocol);
fb3aabf3
LV
500 }
501 return;
502 }
503
814ae70f
PMD
504 if (domain == PF_NETLINK) {
505 switch (protocol) {
506 case NETLINK_ROUTE:
4b25a506 507 qemu_log("NETLINK_ROUTE");
814ae70f
PMD
508 break;
509 case NETLINK_AUDIT:
4b25a506 510 qemu_log("NETLINK_AUDIT");
814ae70f
PMD
511 break;
512 case NETLINK_NETFILTER:
4b25a506 513 qemu_log("NETLINK_NETFILTER");
814ae70f
PMD
514 break;
515 case NETLINK_KOBJECT_UEVENT:
4b25a506 516 qemu_log("NETLINK_KOBJECT_UEVENT");
814ae70f
PMD
517 break;
518 case NETLINK_RDMA:
4b25a506 519 qemu_log("NETLINK_RDMA");
814ae70f
PMD
520 break;
521 case NETLINK_CRYPTO:
4b25a506 522 qemu_log("NETLINK_CRYPTO");
814ae70f
PMD
523 break;
524 default:
4b25a506 525 qemu_log("%d", protocol);
814ae70f
PMD
526 break;
527 }
528 return;
529 }
530
fb3aabf3
LV
531 switch (protocol) {
532 case IPPROTO_IP:
4b25a506 533 qemu_log("IPPROTO_IP");
fb3aabf3
LV
534 break;
535 case IPPROTO_TCP:
4b25a506 536 qemu_log("IPPROTO_TCP");
fb3aabf3
LV
537 break;
538 case IPPROTO_UDP:
4b25a506 539 qemu_log("IPPROTO_UDP");
fb3aabf3
LV
540 break;
541 case IPPROTO_RAW:
4b25a506 542 qemu_log("IPPROTO_RAW");
fb3aabf3
LV
543 break;
544 default:
4b25a506 545 qemu_log("%d", protocol);
fb3aabf3
LV
546 break;
547 }
548}
549
550
c16f9ed3 551#ifdef TARGET_NR__newselect
33189d31 552static void
c16f9ed3 553print_fdset(int n, abi_ulong target_fds_addr)
33189d31
TS
554{
555 int i;
664441ea 556 int first = 1;
33189d31 557
4b25a506 558 qemu_log("[");
33189d31 559 if( target_fds_addr ) {
579a97f7 560 abi_long *target_fds;
33189d31 561
579a97f7
FB
562 target_fds = lock_user(VERIFY_READ,
563 target_fds_addr,
564 sizeof(*target_fds)*(n / TARGET_ABI_BITS + 1),
565 1);
566
567 if (!target_fds)
33189d31
TS
568 return;
569
33189d31 570 for (i=n; i>=0; i--) {
664441ea
FB
571 if ((tswapal(target_fds[i / TARGET_ABI_BITS]) >>
572 (i & (TARGET_ABI_BITS - 1))) & 1) {
573 qemu_log("%s%d", get_comma(first), i);
574 first = 0;
33189d31 575 }
664441ea 576 }
33189d31
TS
577 unlock_user(target_fds, target_fds_addr, 0);
578 }
4b25a506 579 qemu_log("]");
33189d31 580}
c16f9ed3 581#endif
33189d31
TS
582
583/*
584 * Sysycall specific output functions
585 */
586
587/* select */
c16f9ed3 588#ifdef TARGET_NR__newselect
33189d31 589static void
a0939b89 590print_newselect(CPUArchState *cpu_env, const struct syscallname *name,
c16f9ed3
FB
591 abi_long arg1, abi_long arg2, abi_long arg3,
592 abi_long arg4, abi_long arg5, abi_long arg6)
33189d31 593{
c84be71f 594 print_syscall_prologue(name);
33189d31 595 print_fdset(arg1, arg2);
4b25a506 596 qemu_log(",");
33189d31 597 print_fdset(arg1, arg3);
4b25a506 598 qemu_log(",");
33189d31 599 print_fdset(arg1, arg4);
4b25a506 600 qemu_log(",");
74d753ac 601 print_timeval(arg5, 1);
c84be71f 602 print_syscall_epilogue(name);
33189d31 603}
c16f9ed3 604#endif
33189d31 605
3e46b2ef 606#ifdef TARGET_NR_semctl
33189d31 607static void
a0939b89 608print_semctl(CPUArchState *cpu_env, const struct syscallname *name,
c16f9ed3
FB
609 abi_long arg1, abi_long arg2, abi_long arg3,
610 abi_long arg4, abi_long arg5, abi_long arg6)
33189d31 611{
4b25a506
JK
612 qemu_log("%s(" TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld ",",
613 name->name, arg1, arg2);
33189d31 614 print_ipc_cmd(arg3);
4b25a506 615 qemu_log(",0x" TARGET_ABI_FMT_lx ")", arg4);
33189d31 616}
3e46b2ef 617#endif
33189d31
TS
618
619static void
a0939b89 620print_execve(CPUArchState *cpu_env, const struct syscallname *name,
c16f9ed3
FB
621 abi_long arg1, abi_long arg2, abi_long arg3,
622 abi_long arg4, abi_long arg5, abi_long arg6)
33189d31 623{
c16f9ed3 624 abi_ulong arg_ptr_addr;
33189d31
TS
625 char *s;
626
579a97f7 627 if (!(s = lock_user_string(arg1)))
33189d31 628 return;
4b25a506 629 qemu_log("%s(\"%s\",{", name->name, s);
33189d31
TS
630 unlock_user(s, arg1, 0);
631
c16f9ed3 632 for (arg_ptr_addr = arg2; ; arg_ptr_addr += sizeof(abi_ulong)) {
98448f58 633 abi_ulong *arg_ptr, arg_addr;
33189d31 634
7d37435b 635 arg_ptr = lock_user(VERIFY_READ, arg_ptr_addr, sizeof(abi_ulong), 1);
579a97f7 636 if (!arg_ptr)
33189d31 637 return;
cbb21eed 638 arg_addr = tswapal(*arg_ptr);
7d37435b 639 unlock_user(arg_ptr, arg_ptr_addr, 0);
33189d31
TS
640 if (!arg_addr)
641 break;
579a97f7 642 if ((s = lock_user_string(arg_addr))) {
4b25a506 643 qemu_log("\"%s\",", s);
98448f58 644 unlock_user(s, arg_addr, 0);
579a97f7 645 }
33189d31
TS
646 }
647
4b25a506 648 qemu_log("NULL})");
33189d31
TS
649}
650
c16f9ed3 651#ifdef TARGET_NR_ipc
33189d31 652static void
a0939b89 653print_ipc(CPUArchState *cpu_env, const struct syscallname *name,
c16f9ed3
FB
654 abi_long arg1, abi_long arg2, abi_long arg3,
655 abi_long arg4, abi_long arg5, abi_long arg6)
33189d31
TS
656{
657 switch(arg1) {
658 case IPCOP_semctl:
4b25a506
JK
659 qemu_log("semctl(" TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld ",",
660 arg1, arg2);
7ccfb2eb 661 print_ipc_cmd(arg3);
4b25a506 662 qemu_log(",0x" TARGET_ABI_FMT_lx ")", arg4);
33189d31
TS
663 break;
664 default:
4b25a506
JK
665 qemu_log(("%s("
666 TARGET_ABI_FMT_ld ","
667 TARGET_ABI_FMT_ld ","
668 TARGET_ABI_FMT_ld ","
669 TARGET_ABI_FMT_ld
670 ")"),
33189d31
TS
671 name->name, arg1, arg2, arg3, arg4);
672 }
673}
c16f9ed3 674#endif
33189d31
TS
675
676/*
677 * Variants for the return value output function
678 */
679
42b16184 680static bool
c84be71f 681print_syscall_err(abi_long ret)
33189d31 682{
42b16184 683 const char *errstr;
962b289e 684
c84be71f 685 qemu_log(" = ");
7c75571c 686 if (is_error(ret)) {
2a7e1245 687 errstr = target_strerror(-ret);
c84be71f 688 if (errstr) {
42b16184
LV
689 qemu_log("-1 errno=%d (%s)", (int)-ret, errstr);
690 return true;
c84be71f 691 }
962b289e 692 }
42b16184 693 return false;
c84be71f
FB
694}
695
696static void
a0939b89 697print_syscall_ret_addr(CPUArchState *cpu_env, const struct syscallname *name,
e400e119
FB
698 abi_long ret, abi_long arg0, abi_long arg1,
699 abi_long arg2, abi_long arg3, abi_long arg4,
700 abi_long arg5)
c84be71f 701{
42b16184
LV
702 if (!print_syscall_err(ret)) {
703 qemu_log("0x" TARGET_ABI_FMT_lx, ret);
33189d31 704 }
42b16184 705 qemu_log("\n");
33189d31
TS
706}
707
f3e3285d 708#if 0 /* currently unused */
33189d31 709static void
c16f9ed3 710print_syscall_ret_raw(struct syscallname *name, abi_long ret)
33189d31 711{
4b25a506 712 qemu_log(" = 0x" TARGET_ABI_FMT_lx "\n", ret);
33189d31 713}
f3e3285d 714#endif
33189d31 715
f3e3285d 716#ifdef TARGET_NR__newselect
33189d31 717static void
a0939b89 718print_syscall_ret_newselect(CPUArchState *cpu_env, const struct syscallname *name,
e400e119
FB
719 abi_long ret, abi_long arg0, abi_long arg1,
720 abi_long arg2, abi_long arg3, abi_long arg4,
721 abi_long arg5)
c84be71f 722{
42b16184 723 if (!print_syscall_err(ret)) {
c84be71f
FB
724 qemu_log(" = 0x" TARGET_ABI_FMT_lx " (", ret);
725 print_fdset(arg0, arg1);
726 qemu_log(",");
727 print_fdset(arg0, arg2);
728 qemu_log(",");
729 print_fdset(arg0, arg3);
730 qemu_log(",");
731 print_timeval(arg4, 1);
732 qemu_log(")");
733 }
734
735 qemu_log("\n");
33189d31 736}
f3e3285d 737#endif
33189d31 738
19f59bce
AM
739/* special meanings of adjtimex()' non-negative return values */
740#define TARGET_TIME_OK 0 /* clock synchronized, no leap second */
741#define TARGET_TIME_INS 1 /* insert leap second */
742#define TARGET_TIME_DEL 2 /* delete leap second */
743#define TARGET_TIME_OOP 3 /* leap second in progress */
744#define TARGET_TIME_WAIT 4 /* leap second has occurred */
745#define TARGET_TIME_ERROR 5 /* clock not synchronized */
859e8a89 746#ifdef TARGET_NR_adjtimex
19f59bce 747static void
a0939b89 748print_syscall_ret_adjtimex(CPUArchState *cpu_env, const struct syscallname *name,
e400e119
FB
749 abi_long ret, abi_long arg0, abi_long arg1,
750 abi_long arg2, abi_long arg3, abi_long arg4,
751 abi_long arg5)
19f59bce 752{
42b16184 753 if (!print_syscall_err(ret)) {
4b25a506 754 qemu_log(TARGET_ABI_FMT_ld, ret);
19f59bce
AM
755 switch (ret) {
756 case TARGET_TIME_OK:
4b25a506 757 qemu_log(" TIME_OK (clock synchronized, no leap second)");
19f59bce
AM
758 break;
759 case TARGET_TIME_INS:
4b25a506 760 qemu_log(" TIME_INS (insert leap second)");
19f59bce
AM
761 break;
762 case TARGET_TIME_DEL:
4b25a506 763 qemu_log(" TIME_DEL (delete leap second)");
19f59bce
AM
764 break;
765 case TARGET_TIME_OOP:
4b25a506 766 qemu_log(" TIME_OOP (leap second in progress)");
19f59bce
AM
767 break;
768 case TARGET_TIME_WAIT:
4b25a506 769 qemu_log(" TIME_WAIT (leap second has occurred)");
19f59bce
AM
770 break;
771 case TARGET_TIME_ERROR:
4b25a506 772 qemu_log(" TIME_ERROR (clock not synchronized)");
19f59bce
AM
773 break;
774 }
775 }
776
4b25a506 777 qemu_log("\n");
19f59bce 778}
859e8a89 779#endif
19f59bce 780
1a674adf
FB
781#if defined(TARGET_NR_clock_gettime) || defined(TARGET_NR_clock_getres)
782static void
a0939b89 783print_syscall_ret_clock_gettime(CPUArchState *cpu_env, const struct syscallname *name,
1a674adf
FB
784 abi_long ret, abi_long arg0, abi_long arg1,
785 abi_long arg2, abi_long arg3, abi_long arg4,
786 abi_long arg5)
787{
788 if (!print_syscall_err(ret)) {
789 qemu_log(TARGET_ABI_FMT_ld, ret);
790 qemu_log(" (");
791 print_timespec(arg1, 1);
792 qemu_log(")");
793 }
794
795 qemu_log("\n");
796}
797#define print_syscall_ret_clock_getres print_syscall_ret_clock_gettime
798#endif
799
aad43d15
HD
800#if defined(TARGET_NR_clock_gettime64)
801static void
802print_syscall_ret_clock_gettime64(CPUArchState *cpu_env, const struct syscallname *name,
803 abi_long ret, abi_long arg0, abi_long arg1,
804 abi_long arg2, abi_long arg3, abi_long arg4,
805 abi_long arg5)
806{
807 if (!print_syscall_err(ret)) {
808 qemu_log(TARGET_ABI_FMT_ld, ret);
809 qemu_log(" (");
810 print_timespec64(arg1, 1);
811 qemu_log(")");
812 }
813
814 qemu_log("\n");
815}
816#endif
817
1a674adf
FB
818#ifdef TARGET_NR_gettimeofday
819static void
a0939b89 820print_syscall_ret_gettimeofday(CPUArchState *cpu_env, const struct syscallname *name,
1a674adf
FB
821 abi_long ret, abi_long arg0, abi_long arg1,
822 abi_long arg2, abi_long arg3, abi_long arg4,
823 abi_long arg5)
824{
825 if (!print_syscall_err(ret)) {
826 qemu_log(TARGET_ABI_FMT_ld, ret);
827 qemu_log(" (");
828 print_timeval(arg0, 0);
829 print_timezone(arg1, 1);
830 qemu_log(")");
831 }
832
833 qemu_log("\n");
834}
835#endif
836
837#ifdef TARGET_NR_getitimer
838static void
a0939b89 839print_syscall_ret_getitimer(CPUArchState *cpu_env, const struct syscallname *name,
1a674adf
FB
840 abi_long ret, abi_long arg0, abi_long arg1,
841 abi_long arg2, abi_long arg3, abi_long arg4,
842 abi_long arg5)
843{
844 if (!print_syscall_err(ret)) {
845 qemu_log(TARGET_ABI_FMT_ld, ret);
846 qemu_log(" (");
847 print_itimerval(arg1, 1);
848 qemu_log(")");
849 }
850
851 qemu_log("\n");
852}
853#endif
854
855
856#ifdef TARGET_NR_getitimer
857static void
a0939b89 858print_syscall_ret_setitimer(CPUArchState *cpu_env, const struct syscallname *name,
1a674adf
FB
859 abi_long ret, abi_long arg0, abi_long arg1,
860 abi_long arg2, abi_long arg3, abi_long arg4,
861 abi_long arg5)
862{
863 if (!print_syscall_err(ret)) {
864 qemu_log(TARGET_ABI_FMT_ld, ret);
865 qemu_log(" (old_value = ");
866 print_itimerval(arg2, 1);
867 qemu_log(")");
868 }
869
870 qemu_log("\n");
871}
872#endif
873
4fc3cdde
FB
874#if defined(TARGET_NR_listxattr) || defined(TARGET_NR_llistxattr) \
875 || defined(TARGGET_NR_flistxattr)
876static void
a0939b89 877print_syscall_ret_listxattr(CPUArchState *cpu_env, const struct syscallname *name,
e400e119
FB
878 abi_long ret, abi_long arg0, abi_long arg1,
879 abi_long arg2, abi_long arg3, abi_long arg4,
880 abi_long arg5)
4fc3cdde 881{
42b16184 882 if (!print_syscall_err(ret)) {
4fc3cdde
FB
883 qemu_log(TARGET_ABI_FMT_ld, ret);
884 qemu_log(" (list = ");
885 if (arg1 != 0) {
886 abi_long attr = arg1;
887 while (ret) {
888 if (attr != arg1) {
889 qemu_log(",");
890 }
891 print_string(attr, 1);
892 ret -= target_strlen(attr) + 1;
893 attr += target_strlen(attr) + 1;
894 }
895 } else {
896 qemu_log("NULL");
897 }
898 qemu_log(")");
899 }
900
901 qemu_log("\n");
902}
903#define print_syscall_ret_llistxattr print_syscall_ret_listxattr
904#define print_syscall_ret_flistxattr print_syscall_ret_listxattr
905#endif
906
79482e59
FB
907#ifdef TARGET_NR_ioctl
908static void
a0939b89 909print_syscall_ret_ioctl(CPUArchState *cpu_env, const struct syscallname *name,
e400e119
FB
910 abi_long ret, abi_long arg0, abi_long arg1,
911 abi_long arg2, abi_long arg3, abi_long arg4,
912 abi_long arg5)
79482e59 913{
42b16184 914 if (!print_syscall_err(ret)) {
79482e59
FB
915 qemu_log(TARGET_ABI_FMT_ld, ret);
916
917 const IOCTLEntry *ie;
918 const argtype *arg_type;
919 void *argptr;
920 int target_size;
921
922 for (ie = ioctl_entries; ie->target_cmd != 0; ie++) {
923 if (ie->target_cmd == arg1) {
924 break;
925 }
926 }
927
928 if (ie->target_cmd == arg1 &&
929 (ie->access == IOC_R || ie->access == IOC_RW)) {
930 arg_type = ie->arg_type;
931 qemu_log(" (");
932 arg_type++;
933 target_size = thunk_type_size(arg_type, 0);
934 argptr = lock_user(VERIFY_READ, arg2, target_size, 1);
4c1850c1
LV
935 if (argptr) {
936 thunk_print(argptr, arg_type);
937 unlock_user(argptr, arg2, target_size);
938 } else {
939 print_pointer(arg2, 1);
940 }
79482e59
FB
941 qemu_log(")");
942 }
943 }
944 qemu_log("\n");
945}
946#endif
947
74d753ac
MW
948UNUSED static struct flags access_flags[] = {
949 FLAG_GENERIC(F_OK),
950 FLAG_GENERIC(R_OK),
951 FLAG_GENERIC(W_OK),
952 FLAG_GENERIC(X_OK),
953 FLAG_END,
954};
955
956UNUSED static struct flags at_file_flags[] = {
957#ifdef AT_EACCESS
958 FLAG_GENERIC(AT_EACCESS),
959#endif
960#ifdef AT_SYMLINK_NOFOLLOW
961 FLAG_GENERIC(AT_SYMLINK_NOFOLLOW),
962#endif
963 FLAG_END,
964};
965
966UNUSED static struct flags unlinkat_flags[] = {
967#ifdef AT_REMOVEDIR
968 FLAG_GENERIC(AT_REMOVEDIR),
969#endif
970 FLAG_END,
971};
972
973UNUSED static struct flags mode_flags[] = {
974 FLAG_GENERIC(S_IFSOCK),
975 FLAG_GENERIC(S_IFLNK),
976 FLAG_GENERIC(S_IFREG),
977 FLAG_GENERIC(S_IFBLK),
978 FLAG_GENERIC(S_IFDIR),
979 FLAG_GENERIC(S_IFCHR),
980 FLAG_GENERIC(S_IFIFO),
981 FLAG_END,
982};
983
984UNUSED static struct flags open_access_flags[] = {
985 FLAG_TARGET(O_RDONLY),
986 FLAG_TARGET(O_WRONLY),
987 FLAG_TARGET(O_RDWR),
988 FLAG_END,
989};
990
991UNUSED static struct flags open_flags[] = {
992 FLAG_TARGET(O_APPEND),
993 FLAG_TARGET(O_CREAT),
994 FLAG_TARGET(O_DIRECTORY),
995 FLAG_TARGET(O_EXCL),
996 FLAG_TARGET(O_LARGEFILE),
997 FLAG_TARGET(O_NOCTTY),
998 FLAG_TARGET(O_NOFOLLOW),
999 FLAG_TARGET(O_NONBLOCK), /* also O_NDELAY */
afc8763f
RH
1000 FLAG_TARGET(O_DSYNC),
1001 FLAG_TARGET(__O_SYNC),
74d753ac
MW
1002 FLAG_TARGET(O_TRUNC),
1003#ifdef O_DIRECT
1004 FLAG_TARGET(O_DIRECT),
afc8763f
RH
1005#endif
1006#ifdef O_NOATIME
1007 FLAG_TARGET(O_NOATIME),
1008#endif
1009#ifdef O_CLOEXEC
1010 FLAG_TARGET(O_CLOEXEC),
1011#endif
1012#ifdef O_PATH
1013 FLAG_TARGET(O_PATH),
5f9cee46
RV
1014#endif
1015#ifdef O_TMPFILE
1016 FLAG_TARGET(O_TMPFILE),
1017 FLAG_TARGET(__O_TMPFILE),
74d753ac
MW
1018#endif
1019 FLAG_END,
1020};
1021
1022UNUSED static struct flags mount_flags[] = {
1023#ifdef MS_BIND
1024 FLAG_GENERIC(MS_BIND),
1025#endif
1026#ifdef MS_DIRSYNC
1027 FLAG_GENERIC(MS_DIRSYNC),
1028#endif
1029 FLAG_GENERIC(MS_MANDLOCK),
1030#ifdef MS_MOVE
1031 FLAG_GENERIC(MS_MOVE),
1032#endif
1033 FLAG_GENERIC(MS_NOATIME),
1034 FLAG_GENERIC(MS_NODEV),
1035 FLAG_GENERIC(MS_NODIRATIME),
1036 FLAG_GENERIC(MS_NOEXEC),
1037 FLAG_GENERIC(MS_NOSUID),
1038 FLAG_GENERIC(MS_RDONLY),
1039#ifdef MS_RELATIME
1040 FLAG_GENERIC(MS_RELATIME),
1041#endif
1042 FLAG_GENERIC(MS_REMOUNT),
1043 FLAG_GENERIC(MS_SYNCHRONOUS),
1044 FLAG_END,
1045};
1046
1047UNUSED static struct flags umount2_flags[] = {
1048#ifdef MNT_FORCE
1049 FLAG_GENERIC(MNT_FORCE),
1050#endif
1051#ifdef MNT_DETACH
1052 FLAG_GENERIC(MNT_DETACH),
1053#endif
1054#ifdef MNT_EXPIRE
1055 FLAG_GENERIC(MNT_EXPIRE),
1056#endif
1057 FLAG_END,
1058};
1059
1060UNUSED static struct flags mmap_prot_flags[] = {
1061 FLAG_GENERIC(PROT_NONE),
1062 FLAG_GENERIC(PROT_EXEC),
1063 FLAG_GENERIC(PROT_READ),
1064 FLAG_GENERIC(PROT_WRITE),
9e0b74a4
PB
1065 FLAG_TARGET(PROT_SEM),
1066 FLAG_GENERIC(PROT_GROWSDOWN),
1067 FLAG_GENERIC(PROT_GROWSUP),
74d753ac
MW
1068 FLAG_END,
1069};
1070
1071UNUSED static struct flags mmap_flags[] = {
1072 FLAG_TARGET(MAP_SHARED),
1073 FLAG_TARGET(MAP_PRIVATE),
1074 FLAG_TARGET(MAP_ANONYMOUS),
1075 FLAG_TARGET(MAP_DENYWRITE),
1076 FLAG_TARGET(MAP_FIXED),
1077 FLAG_TARGET(MAP_GROWSDOWN),
906c1b8e 1078 FLAG_TARGET(MAP_EXECUTABLE),
74d753ac
MW
1079#ifdef MAP_LOCKED
1080 FLAG_TARGET(MAP_LOCKED),
1081#endif
1082#ifdef MAP_NONBLOCK
1083 FLAG_TARGET(MAP_NONBLOCK),
1084#endif
1085 FLAG_TARGET(MAP_NORESERVE),
1086#ifdef MAP_POPULATE
1087 FLAG_TARGET(MAP_POPULATE),
906c1b8e
MF
1088#endif
1089#ifdef TARGET_MAP_UNINITIALIZED
1090 FLAG_TARGET(MAP_UNINITIALIZED),
74d753ac
MW
1091#endif
1092 FLAG_END,
1093};
1094
608e5592
LV
1095UNUSED static struct flags clone_flags[] = {
1096 FLAG_GENERIC(CLONE_VM),
1097 FLAG_GENERIC(CLONE_FS),
1098 FLAG_GENERIC(CLONE_FILES),
1099 FLAG_GENERIC(CLONE_SIGHAND),
1100 FLAG_GENERIC(CLONE_PTRACE),
1101 FLAG_GENERIC(CLONE_VFORK),
1102 FLAG_GENERIC(CLONE_PARENT),
1103 FLAG_GENERIC(CLONE_THREAD),
1104 FLAG_GENERIC(CLONE_NEWNS),
1105 FLAG_GENERIC(CLONE_SYSVSEM),
1106 FLAG_GENERIC(CLONE_SETTLS),
1107 FLAG_GENERIC(CLONE_PARENT_SETTID),
1108 FLAG_GENERIC(CLONE_CHILD_CLEARTID),
1109 FLAG_GENERIC(CLONE_DETACHED),
1110 FLAG_GENERIC(CLONE_UNTRACED),
1111 FLAG_GENERIC(CLONE_CHILD_SETTID),
6f11f013 1112#if defined(CLONE_NEWUTS)
608e5592 1113 FLAG_GENERIC(CLONE_NEWUTS),
6f11f013
SW
1114#endif
1115#if defined(CLONE_NEWIPC)
608e5592 1116 FLAG_GENERIC(CLONE_NEWIPC),
6f11f013
SW
1117#endif
1118#if defined(CLONE_NEWUSER)
608e5592 1119 FLAG_GENERIC(CLONE_NEWUSER),
6f11f013
SW
1120#endif
1121#if defined(CLONE_NEWPID)
608e5592 1122 FLAG_GENERIC(CLONE_NEWPID),
6f11f013
SW
1123#endif
1124#if defined(CLONE_NEWNET)
608e5592 1125 FLAG_GENERIC(CLONE_NEWNET),
6f11f013 1126#endif
5847d309
MK
1127#if defined(CLONE_NEWCGROUP)
1128 FLAG_GENERIC(CLONE_NEWCGROUP),
1129#endif
1130#if defined(CLONE_NEWTIME)
1131 FLAG_GENERIC(CLONE_NEWTIME),
1132#endif
6f11f013 1133#if defined(CLONE_IO)
608e5592 1134 FLAG_GENERIC(CLONE_IO),
6f11f013 1135#endif
608e5592
LV
1136 FLAG_END,
1137};
1138
fb3aabf3
LV
1139UNUSED static struct flags msg_flags[] = {
1140 /* send */
1141 FLAG_GENERIC(MSG_CONFIRM),
1142 FLAG_GENERIC(MSG_DONTROUTE),
1143 FLAG_GENERIC(MSG_DONTWAIT),
1144 FLAG_GENERIC(MSG_EOR),
1145 FLAG_GENERIC(MSG_MORE),
1146 FLAG_GENERIC(MSG_NOSIGNAL),
1147 FLAG_GENERIC(MSG_OOB),
1148 /* recv */
1149 FLAG_GENERIC(MSG_CMSG_CLOEXEC),
1150 FLAG_GENERIC(MSG_ERRQUEUE),
1151 FLAG_GENERIC(MSG_PEEK),
1152 FLAG_GENERIC(MSG_TRUNC),
1153 FLAG_GENERIC(MSG_WAITALL),
1154 /* recvmsg */
1155 FLAG_GENERIC(MSG_CTRUNC),
1156 FLAG_END,
1157};
1158
d42744fe
JW
1159UNUSED static struct flags statx_flags[] = {
1160#ifdef AT_EMPTY_PATH
1161 FLAG_GENERIC(AT_EMPTY_PATH),
1162#endif
1163#ifdef AT_NO_AUTOMOUNT
1164 FLAG_GENERIC(AT_NO_AUTOMOUNT),
1165#endif
1166#ifdef AT_SYMLINK_NOFOLLOW
1167 FLAG_GENERIC(AT_SYMLINK_NOFOLLOW),
1168#endif
1169#ifdef AT_STATX_SYNC_AS_STAT
1170 FLAG_GENERIC(AT_STATX_SYNC_AS_STAT),
1171#endif
1172#ifdef AT_STATX_FORCE_SYNC
1173 FLAG_GENERIC(AT_STATX_FORCE_SYNC),
1174#endif
1175#ifdef AT_STATX_DONT_SYNC
1176 FLAG_GENERIC(AT_STATX_DONT_SYNC),
1177#endif
1178 FLAG_END,
1179};
1180
1181UNUSED static struct flags statx_mask[] = {
1182/* This must come first, because it includes everything. */
1183#ifdef STATX_ALL
1184 FLAG_GENERIC(STATX_ALL),
1185#endif
1186/* This must come second; it includes everything except STATX_BTIME. */
1187#ifdef STATX_BASIC_STATS
1188 FLAG_GENERIC(STATX_BASIC_STATS),
1189#endif
1190#ifdef STATX_TYPE
1191 FLAG_GENERIC(STATX_TYPE),
1192#endif
1193#ifdef STATX_MODE
1194 FLAG_GENERIC(STATX_MODE),
1195#endif
1196#ifdef STATX_NLINK
1197 FLAG_GENERIC(STATX_NLINK),
1198#endif
1199#ifdef STATX_UID
1200 FLAG_GENERIC(STATX_UID),
1201#endif
1202#ifdef STATX_GID
1203 FLAG_GENERIC(STATX_GID),
1204#endif
1205#ifdef STATX_ATIME
1206 FLAG_GENERIC(STATX_ATIME),
1207#endif
1208#ifdef STATX_MTIME
1209 FLAG_GENERIC(STATX_MTIME),
1210#endif
1211#ifdef STATX_CTIME
1212 FLAG_GENERIC(STATX_CTIME),
1213#endif
1214#ifdef STATX_INO
1215 FLAG_GENERIC(STATX_INO),
1216#endif
1217#ifdef STATX_SIZE
1218 FLAG_GENERIC(STATX_SIZE),
1219#endif
1220#ifdef STATX_BLOCKS
1221 FLAG_GENERIC(STATX_BLOCKS),
1222#endif
1223#ifdef STATX_BTIME
1224 FLAG_GENERIC(STATX_BTIME),
1225#endif
1226 FLAG_END,
1227};
1228
f4d92c5e
FB
1229UNUSED static struct flags falloc_flags[] = {
1230 FLAG_GENERIC(FALLOC_FL_KEEP_SIZE),
1231 FLAG_GENERIC(FALLOC_FL_PUNCH_HOLE),
1232#ifdef FALLOC_FL_NO_HIDE_STALE
1233 FLAG_GENERIC(FALLOC_FL_NO_HIDE_STALE),
1234#endif
1235#ifdef FALLOC_FL_COLLAPSE_RANGE
1236 FLAG_GENERIC(FALLOC_FL_COLLAPSE_RANGE),
1237#endif
1238#ifdef FALLOC_FL_ZERO_RANGE
1239 FLAG_GENERIC(FALLOC_FL_ZERO_RANGE),
1240#endif
1241#ifdef FALLOC_FL_INSERT_RANGE
1242 FLAG_GENERIC(FALLOC_FL_INSERT_RANGE),
1243#endif
1244#ifdef FALLOC_FL_UNSHARE_RANGE
1245 FLAG_GENERIC(FALLOC_FL_UNSHARE_RANGE),
1246#endif
1247};
1248
888468db
FB
1249UNUSED static struct flags termios_iflags[] = {
1250 FLAG_TARGET(IGNBRK),
1251 FLAG_TARGET(BRKINT),
1252 FLAG_TARGET(IGNPAR),
1253 FLAG_TARGET(PARMRK),
1254 FLAG_TARGET(INPCK),
1255 FLAG_TARGET(ISTRIP),
1256 FLAG_TARGET(INLCR),
1257 FLAG_TARGET(IGNCR),
1258 FLAG_TARGET(ICRNL),
1259 FLAG_TARGET(IUCLC),
1260 FLAG_TARGET(IXON),
1261 FLAG_TARGET(IXANY),
1262 FLAG_TARGET(IXOFF),
1263 FLAG_TARGET(IMAXBEL),
1264 FLAG_TARGET(IUTF8),
1265 FLAG_END,
1266};
1267
1268UNUSED static struct flags termios_oflags[] = {
1269 FLAG_TARGET(OPOST),
1270 FLAG_TARGET(OLCUC),
1271 FLAG_TARGET(ONLCR),
1272 FLAG_TARGET(OCRNL),
1273 FLAG_TARGET(ONOCR),
1274 FLAG_TARGET(ONLRET),
1275 FLAG_TARGET(OFILL),
1276 FLAG_TARGET(OFDEL),
1277 FLAG_END,
1278};
1279
1280UNUSED static struct enums termios_oflags_NLDLY[] = {
1281 ENUM_TARGET(NL0),
1282 ENUM_TARGET(NL1),
1283 ENUM_END,
1284};
1285
1286UNUSED static struct enums termios_oflags_CRDLY[] = {
1287 ENUM_TARGET(CR0),
1288 ENUM_TARGET(CR1),
1289 ENUM_TARGET(CR2),
1290 ENUM_TARGET(CR3),
1291 ENUM_END,
1292};
1293
1294UNUSED static struct enums termios_oflags_TABDLY[] = {
1295 ENUM_TARGET(TAB0),
1296 ENUM_TARGET(TAB1),
1297 ENUM_TARGET(TAB2),
1298 ENUM_TARGET(TAB3),
1299 ENUM_END,
1300};
1301
1302UNUSED static struct enums termios_oflags_VTDLY[] = {
1303 ENUM_TARGET(VT0),
1304 ENUM_TARGET(VT1),
1305 ENUM_END,
1306};
1307
1308UNUSED static struct enums termios_oflags_FFDLY[] = {
1309 ENUM_TARGET(FF0),
1310 ENUM_TARGET(FF1),
1311 ENUM_END,
1312};
1313
1314UNUSED static struct enums termios_oflags_BSDLY[] = {
1315 ENUM_TARGET(BS0),
1316 ENUM_TARGET(BS1),
1317 ENUM_END,
1318};
1319
1320UNUSED static struct enums termios_cflags_CBAUD[] = {
1321 ENUM_TARGET(B0),
1322 ENUM_TARGET(B50),
1323 ENUM_TARGET(B75),
1324 ENUM_TARGET(B110),
1325 ENUM_TARGET(B134),
1326 ENUM_TARGET(B150),
1327 ENUM_TARGET(B200),
1328 ENUM_TARGET(B300),
1329 ENUM_TARGET(B600),
1330 ENUM_TARGET(B1200),
1331 ENUM_TARGET(B1800),
1332 ENUM_TARGET(B2400),
1333 ENUM_TARGET(B4800),
1334 ENUM_TARGET(B9600),
1335 ENUM_TARGET(B19200),
1336 ENUM_TARGET(B38400),
1337 ENUM_TARGET(B57600),
1338 ENUM_TARGET(B115200),
1339 ENUM_TARGET(B230400),
1340 ENUM_TARGET(B460800),
1341 ENUM_END,
1342};
1343
1344UNUSED static struct enums termios_cflags_CSIZE[] = {
1345 ENUM_TARGET(CS5),
1346 ENUM_TARGET(CS6),
1347 ENUM_TARGET(CS7),
1348 ENUM_TARGET(CS8),
1349 ENUM_END,
1350};
1351
1352UNUSED static struct flags termios_cflags[] = {
1353 FLAG_TARGET(CSTOPB),
1354 FLAG_TARGET(CREAD),
1355 FLAG_TARGET(PARENB),
1356 FLAG_TARGET(PARODD),
1357 FLAG_TARGET(HUPCL),
1358 FLAG_TARGET(CLOCAL),
1359 FLAG_TARGET(CRTSCTS),
1360 FLAG_END,
1361};
1362
1363UNUSED static struct flags termios_lflags[] = {
1364 FLAG_TARGET(ISIG),
1365 FLAG_TARGET(ICANON),
1366 FLAG_TARGET(XCASE),
1367 FLAG_TARGET(ECHO),
1368 FLAG_TARGET(ECHOE),
1369 FLAG_TARGET(ECHOK),
1370 FLAG_TARGET(ECHONL),
1371 FLAG_TARGET(NOFLSH),
1372 FLAG_TARGET(TOSTOP),
1373 FLAG_TARGET(ECHOCTL),
1374 FLAG_TARGET(ECHOPRT),
1375 FLAG_TARGET(ECHOKE),
1376 FLAG_TARGET(FLUSHO),
1377 FLAG_TARGET(PENDIN),
1378 FLAG_TARGET(IEXTEN),
1379 FLAG_TARGET(EXTPROC),
1380 FLAG_END,
1381};
1382
02e5d7d7
FB
1383UNUSED static struct flags mlockall_flags[] = {
1384 FLAG_TARGET(MCL_CURRENT),
1385 FLAG_TARGET(MCL_FUTURE),
1386#ifdef MCL_ONFAULT
1387 FLAG_TARGET(MCL_ONFAULT),
1388#endif
1389 FLAG_END,
1390};
1391
1a674adf
FB
1392/* IDs of the various system clocks */
1393#define TARGET_CLOCK_REALTIME 0
1394#define TARGET_CLOCK_MONOTONIC 1
1395#define TARGET_CLOCK_PROCESS_CPUTIME_ID 2
1396#define TARGET_CLOCK_THREAD_CPUTIME_ID 3
1397#define TARGET_CLOCK_MONOTONIC_RAW 4
1398#define TARGET_CLOCK_REALTIME_COARSE 5
1399#define TARGET_CLOCK_MONOTONIC_COARSE 6
1400#define TARGET_CLOCK_BOOTTIME 7
1401#define TARGET_CLOCK_REALTIME_ALARM 8
1402#define TARGET_CLOCK_BOOTTIME_ALARM 9
1403#define TARGET_CLOCK_SGI_CYCLE 10
1404#define TARGET_CLOCK_TAI 11
1405
1406UNUSED static struct enums clockids[] = {
1407 ENUM_TARGET(CLOCK_REALTIME),
1408 ENUM_TARGET(CLOCK_MONOTONIC),
1409 ENUM_TARGET(CLOCK_PROCESS_CPUTIME_ID),
1410 ENUM_TARGET(CLOCK_THREAD_CPUTIME_ID),
1411 ENUM_TARGET(CLOCK_MONOTONIC_RAW),
1412 ENUM_TARGET(CLOCK_REALTIME_COARSE),
1413 ENUM_TARGET(CLOCK_MONOTONIC_COARSE),
1414 ENUM_TARGET(CLOCK_BOOTTIME),
1415 ENUM_TARGET(CLOCK_REALTIME_ALARM),
1416 ENUM_TARGET(CLOCK_BOOTTIME_ALARM),
1417 ENUM_TARGET(CLOCK_SGI_CYCLE),
1418 ENUM_TARGET(CLOCK_TAI),
1419 ENUM_END,
1420};
1421
1422UNUSED static struct enums itimer_types[] = {
1423 ENUM_GENERIC(ITIMER_REAL),
1424 ENUM_GENERIC(ITIMER_VIRTUAL),
1425 ENUM_GENERIC(ITIMER_PROF),
1426 ENUM_END,
1427};
1428
74d753ac
MW
1429/*
1430 * print_xxx utility functions. These are used to print syscall
1431 * parameters in certain format. All of these have parameter
1432 * named 'last'. This parameter is used to add comma to output
1433 * when last == 0.
1434 */
1435
1436static const char *
1437get_comma(int last)
1438{
1439 return ((last) ? "" : ",");
1440}
1441
1442static void
d2ee72a5 1443print_flags(const struct flags *f, abi_long flags, int last)
74d753ac
MW
1444{
1445 const char *sep = "";
74d753ac
MW
1446 int n;
1447
74d753ac 1448 if ((flags == 0) && (f->f_value == 0)) {
4b25a506 1449 qemu_log("%s%s", f->f_string, get_comma(last));
74d753ac
MW
1450 return;
1451 }
1452 for (n = 0; f->f_string != NULL; f++) {
1453 if ((f->f_value != 0) && ((flags & f->f_value) == f->f_value)) {
4b25a506 1454 qemu_log("%s%s", sep, f->f_string);
74d753ac
MW
1455 flags &= ~f->f_value;
1456 sep = "|";
1457 n++;
1458 }
1459 }
1460
1461 if (n > 0) {
1462 /* print rest of the flags as numeric */
1463 if (flags != 0) {
4b25a506 1464 qemu_log("%s%#x%s", sep, (unsigned int)flags, get_comma(last));
74d753ac 1465 } else {
4b25a506 1466 qemu_log("%s", get_comma(last));
74d753ac
MW
1467 }
1468 } else {
1469 /* no string version of flags found, print them in hex then */
4b25a506 1470 qemu_log("%#x%s", (unsigned int)flags, get_comma(last));
74d753ac
MW
1471 }
1472}
1473
45f56799
FB
1474static void
1475print_enums(const struct enums *e, abi_long enum_arg, int last)
1476{
1477 for (; e->e_string != NULL; e++) {
1478 if (e->e_value == enum_arg) {
1479 qemu_log("%s", e->e_string);
1480 break;
1481 }
1482 }
1483
1484 if (e->e_string == NULL) {
1485 qemu_log("%#x", (unsigned int)enum_arg);
1486 }
1487
1488 qemu_log("%s", get_comma(last));
1489}
1490
74d753ac 1491static void
d2ee72a5 1492print_at_dirfd(abi_long dirfd, int last)
74d753ac 1493{
74d753ac
MW
1494#ifdef AT_FDCWD
1495 if (dirfd == AT_FDCWD) {
4b25a506 1496 qemu_log("AT_FDCWD%s", get_comma(last));
74d753ac
MW
1497 return;
1498 }
1499#endif
4b25a506 1500 qemu_log("%d%s", (int)dirfd, get_comma(last));
74d753ac
MW
1501}
1502
1503static void
d2ee72a5 1504print_file_mode(abi_long mode, int last)
74d753ac
MW
1505{
1506 const char *sep = "";
1507 const struct flags *m;
74d753ac 1508
105d599a
HD
1509 if (mode == 0) {
1510 qemu_log("000%s", get_comma(last));
1511 return;
1512 }
1513
74d753ac
MW
1514 for (m = &mode_flags[0]; m->f_string != NULL; m++) {
1515 if ((m->f_value & mode) == m->f_value) {
4b25a506 1516 qemu_log("%s%s", m->f_string, sep);
74d753ac
MW
1517 sep = "|";
1518 mode &= ~m->f_value;
1519 break;
1520 }
1521 }
1522
1523 mode &= ~S_IFMT;
1524 /* print rest of the mode as octal */
1525 if (mode != 0)
4b25a506 1526 qemu_log("%s%#o", sep, (unsigned int)mode);
74d753ac 1527
4b25a506 1528 qemu_log("%s", get_comma(last));
74d753ac
MW
1529}
1530
1531static void
d2ee72a5 1532print_open_flags(abi_long flags, int last)
74d753ac 1533{
74d753ac
MW
1534 print_flags(open_access_flags, flags & TARGET_O_ACCMODE, 1);
1535 flags &= ~TARGET_O_ACCMODE;
1536 if (flags == 0) {
4b25a506 1537 qemu_log("%s", get_comma(last));
74d753ac
MW
1538 return;
1539 }
4b25a506 1540 qemu_log("|");
74d753ac
MW
1541 print_flags(open_flags, flags, last);
1542}
1543
1544static void
1545print_syscall_prologue(const struct syscallname *sc)
1546{
4b25a506 1547 qemu_log("%s(", sc->name);
74d753ac
MW
1548}
1549
1550/*ARGSUSED*/
1551static void
1552print_syscall_epilogue(const struct syscallname *sc)
1553{
1554 (void)sc;
4b25a506 1555 qemu_log(")");
74d753ac
MW
1556}
1557
1558static void
1559print_string(abi_long addr, int last)
1560{
1561 char *s;
1562
1563 if ((s = lock_user_string(addr)) != NULL) {
4b25a506 1564 qemu_log("\"%s\"%s", s, get_comma(last));
74d753ac
MW
1565 unlock_user(s, addr, 0);
1566 } else {
1567 /* can't get string out of it, so print it as pointer */
1568 print_pointer(addr, last);
1569 }
1570}
1571
fb3aabf3
LV
1572#define MAX_PRINT_BUF 40
1573static void
1574print_buf(abi_long addr, abi_long len, int last)
1575{
1576 uint8_t *s;
1577 int i;
1578
1579 s = lock_user(VERIFY_READ, addr, len, 1);
1580 if (s) {
4b25a506 1581 qemu_log("\"");
fb3aabf3
LV
1582 for (i = 0; i < MAX_PRINT_BUF && i < len; i++) {
1583 if (isprint(s[i])) {
4b25a506 1584 qemu_log("%c", s[i]);
fb3aabf3 1585 } else {
4b25a506 1586 qemu_log("\\%o", s[i]);
fb3aabf3
LV
1587 }
1588 }
4b25a506 1589 qemu_log("\"");
fb3aabf3 1590 if (i != len) {
4b25a506 1591 qemu_log("...");
fb3aabf3
LV
1592 }
1593 if (!last) {
4b25a506 1594 qemu_log(",");
fb3aabf3
LV
1595 }
1596 unlock_user(s, addr, 0);
1597 } else {
1598 print_pointer(addr, last);
1599 }
1600}
1601
74d753ac
MW
1602/*
1603 * Prints out raw parameter using given format. Caller needs
1604 * to do byte swapping if needed.
1605 */
1606static void
1607print_raw_param(const char *fmt, abi_long param, int last)
1608{
1609 char format[64];
1610
1611 (void) snprintf(format, sizeof (format), "%s%s", fmt, get_comma(last));
4b25a506 1612 qemu_log(format, param);
74d753ac
MW
1613}
1614
1615static void
1616print_pointer(abi_long p, int last)
1617{
1618 if (p == 0)
4b25a506 1619 qemu_log("NULL%s", get_comma(last));
74d753ac 1620 else
4b25a506 1621 qemu_log("0x" TARGET_ABI_FMT_lx "%s", p, get_comma(last));
74d753ac
MW
1622}
1623
1624/*
1625 * Reads 32-bit (int) number from guest address space from
1626 * address 'addr' and prints it.
1627 */
1628static void
1629print_number(abi_long addr, int last)
1630{
1631 if (addr == 0) {
4b25a506 1632 qemu_log("NULL%s", get_comma(last));
74d753ac
MW
1633 } else {
1634 int num;
1635
1636 get_user_s32(num, addr);
4b25a506 1637 qemu_log("[%d]%s", num, get_comma(last));
74d753ac
MW
1638 }
1639}
1640
1641static void
1642print_timeval(abi_ulong tv_addr, int last)
1643{
1644 if( tv_addr ) {
1645 struct target_timeval *tv;
1646
1647 tv = lock_user(VERIFY_READ, tv_addr, sizeof(*tv), 1);
8f93089d
PMD
1648 if (!tv) {
1649 print_pointer(tv_addr, last);
74d753ac 1650 return;
8f93089d 1651 }
1a674adf
FB
1652 qemu_log("{tv_sec = " TARGET_ABI_FMT_ld
1653 ",tv_usec = " TARGET_ABI_FMT_ld "}%s",
1654 tswapal(tv->tv_sec), tswapal(tv->tv_usec), get_comma(last));
74d753ac
MW
1655 unlock_user(tv, tv_addr, 0);
1656 } else
4b25a506 1657 qemu_log("NULL%s", get_comma(last));
74d753ac
MW
1658}
1659
1a674adf
FB
1660static void
1661print_timespec(abi_ulong ts_addr, int last)
1662{
1663 if (ts_addr) {
1664 struct target_timespec *ts;
1665
1666 ts = lock_user(VERIFY_READ, ts_addr, sizeof(*ts), 1);
1667 if (!ts) {
1668 print_pointer(ts_addr, last);
1669 return;
1670 }
1671 qemu_log("{tv_sec = " TARGET_ABI_FMT_ld
1672 ",tv_nsec = " TARGET_ABI_FMT_ld "}%s",
1673 tswapal(ts->tv_sec), tswapal(ts->tv_nsec), get_comma(last));
1674 unlock_user(ts, ts_addr, 0);
1675 } else {
1676 qemu_log("NULL%s", get_comma(last));
1677 }
1678}
1679
aad43d15
HD
1680static void
1681print_timespec64(abi_ulong ts_addr, int last)
1682{
1683 if (ts_addr) {
1684 struct target__kernel_timespec *ts;
1685
1686 ts = lock_user(VERIFY_READ, ts_addr, sizeof(*ts), 1);
1687 if (!ts) {
1688 print_pointer(ts_addr, last);
1689 return;
1690 }
1691 qemu_log("{tv_sec = %lld"
1692 ",tv_nsec = %lld}%s",
1693 (long long)tswap64(ts->tv_sec), (long long)tswap64(ts->tv_nsec),
1694 get_comma(last));
1695 unlock_user(ts, ts_addr, 0);
1696 } else {
1697 qemu_log("NULL%s", get_comma(last));
1698 }
1699}
1700
6d33e036
PMD
1701static void
1702print_timezone(abi_ulong tz_addr, int last)
1703{
1704 if (tz_addr) {
1705 struct target_timezone *tz;
1706
1707 tz = lock_user(VERIFY_READ, tz_addr, sizeof(*tz), 1);
1708 if (!tz) {
1709 print_pointer(tz_addr, last);
1710 return;
1711 }
4b25a506 1712 qemu_log("{%d,%d}%s", tswap32(tz->tz_minuteswest),
6d33e036
PMD
1713 tswap32(tz->tz_dsttime), get_comma(last));
1714 unlock_user(tz, tz_addr, 0);
1715 } else {
4b25a506 1716 qemu_log("NULL%s", get_comma(last));
6d33e036
PMD
1717 }
1718}
1719
1a674adf
FB
1720static void
1721print_itimerval(abi_ulong it_addr, int last)
1722{
1723 if (it_addr) {
1724 qemu_log("{it_interval=");
1725 print_timeval(it_addr +
1726 offsetof(struct target_itimerval, it_interval), 0);
1727 qemu_log("it_value=");
1728 print_timeval(it_addr +
1729 offsetof(struct target_itimerval, it_value), 0);
1730 qemu_log("}%s", get_comma(last));
1731 } else {
1732 qemu_log("NULL%s", get_comma(last));
1733 }
1734}
1735
888468db
FB
1736void
1737print_termios(void *arg)
1738{
1739 const struct target_termios *target = arg;
1740
1741 target_tcflag_t iflags = tswap32(target->c_iflag);
1742 target_tcflag_t oflags = tswap32(target->c_oflag);
1743 target_tcflag_t cflags = tswap32(target->c_cflag);
1744 target_tcflag_t lflags = tswap32(target->c_lflag);
1745
1746 qemu_log("{");
1747
1748 qemu_log("c_iflag = ");
1749 print_flags(termios_iflags, iflags, 0);
1750
1751 qemu_log("c_oflag = ");
1752 target_tcflag_t oflags_clean = oflags & ~(TARGET_NLDLY | TARGET_CRDLY |
1753 TARGET_TABDLY | TARGET_BSDLY |
1754 TARGET_VTDLY | TARGET_FFDLY);
1755 print_flags(termios_oflags, oflags_clean, 0);
1756 if (oflags & TARGET_NLDLY) {
1757 print_enums(termios_oflags_NLDLY, oflags & TARGET_NLDLY, 0);
1758 }
1759 if (oflags & TARGET_CRDLY) {
1760 print_enums(termios_oflags_CRDLY, oflags & TARGET_CRDLY, 0);
1761 }
1762 if (oflags & TARGET_TABDLY) {
1763 print_enums(termios_oflags_TABDLY, oflags & TARGET_TABDLY, 0);
1764 }
1765 if (oflags & TARGET_BSDLY) {
1766 print_enums(termios_oflags_BSDLY, oflags & TARGET_BSDLY, 0);
1767 }
1768 if (oflags & TARGET_VTDLY) {
1769 print_enums(termios_oflags_VTDLY, oflags & TARGET_VTDLY, 0);
1770 }
1771 if (oflags & TARGET_FFDLY) {
1772 print_enums(termios_oflags_FFDLY, oflags & TARGET_FFDLY, 0);
1773 }
1774
1775 qemu_log("c_cflag = ");
1776 if (cflags & TARGET_CBAUD) {
1777 print_enums(termios_cflags_CBAUD, cflags & TARGET_CBAUD, 0);
1778 }
1779 if (cflags & TARGET_CSIZE) {
1780 print_enums(termios_cflags_CSIZE, cflags & TARGET_CSIZE, 0);
1781 }
1782 target_tcflag_t cflags_clean = cflags & ~(TARGET_CBAUD | TARGET_CSIZE);
1783 print_flags(termios_cflags, cflags_clean, 0);
1784
1785 qemu_log("c_lflag = ");
1786 print_flags(termios_lflags, lflags, 0);
1787
1788 qemu_log("c_cc = ");
1789 qemu_log("\"%s\",", target->c_cc);
1790
1791 qemu_log("c_line = ");
1792 print_raw_param("\'%c\'", target->c_line, 1);
1793
1794 qemu_log("}");
1795}
1796
74d753ac
MW
1797#undef UNUSED
1798
1799#ifdef TARGET_NR_accept
1800static void
a0939b89 1801print_accept(CPUArchState *cpu_env, const struct syscallname *name,
e400e119
FB
1802 abi_long arg0, abi_long arg1, abi_long arg2,
1803 abi_long arg3, abi_long arg4, abi_long arg5)
74d753ac
MW
1804{
1805 print_syscall_prologue(name);
d2ee72a5 1806 print_raw_param("%d", arg0, 0);
74d753ac
MW
1807 print_pointer(arg1, 0);
1808 print_number(arg2, 1);
1809 print_syscall_epilogue(name);
1810}
1811#endif
1812
1813#ifdef TARGET_NR_access
1814static void
a0939b89 1815print_access(CPUArchState *cpu_env, const struct syscallname *name,
e400e119
FB
1816 abi_long arg0, abi_long arg1, abi_long arg2,
1817 abi_long arg3, abi_long arg4, abi_long arg5)
74d753ac
MW
1818{
1819 print_syscall_prologue(name);
1820 print_string(arg0, 0);
1821 print_flags(access_flags, arg1, 1);
1822 print_syscall_epilogue(name);
1823}
1824#endif
1825
c42569f6
FB
1826#ifdef TARGET_NR_acct
1827static void
a0939b89 1828print_acct(CPUArchState *cpu_env, const struct syscallname *name,
e400e119
FB
1829 abi_long arg0, abi_long arg1, abi_long arg2,
1830 abi_long arg3, abi_long arg4, abi_long arg5)
c42569f6
FB
1831{
1832 print_syscall_prologue(name);
1833 print_string(arg0, 1);
1834 print_syscall_epilogue(name);
1835}
1836#endif
1837
74d753ac
MW
1838#ifdef TARGET_NR_brk
1839static void
a0939b89 1840print_brk(CPUArchState *cpu_env, const struct syscallname *name,
e400e119
FB
1841 abi_long arg0, abi_long arg1, abi_long arg2,
1842 abi_long arg3, abi_long arg4, abi_long arg5)
74d753ac
MW
1843{
1844 print_syscall_prologue(name);
1845 print_pointer(arg0, 1);
1846 print_syscall_epilogue(name);
1847}
1848#endif
1849
1850#ifdef TARGET_NR_chdir
1851static void
a0939b89 1852print_chdir(CPUArchState *cpu_env, const struct syscallname *name,
e400e119
FB
1853 abi_long arg0, abi_long arg1, abi_long arg2,
1854 abi_long arg3, abi_long arg4, abi_long arg5)
74d753ac
MW
1855{
1856 print_syscall_prologue(name);
1857 print_string(arg0, 1);
1858 print_syscall_epilogue(name);
1859}
1860#endif
1861
1b7695fe
HD
1862#ifdef TARGET_NR_chroot
1863static void
a0939b89 1864print_chroot(CPUArchState *cpu_env, const struct syscallname *name,
e400e119
FB
1865 abi_long arg0, abi_long arg1, abi_long arg2,
1866 abi_long arg3, abi_long arg4, abi_long arg5)
1b7695fe
HD
1867{
1868 print_syscall_prologue(name);
1869 print_string(arg0, 1);
1870 print_syscall_epilogue(name);
1871}
1872#endif
1873
74d753ac
MW
1874#ifdef TARGET_NR_chmod
1875static void
a0939b89 1876print_chmod(CPUArchState *cpu_env, const struct syscallname *name,
e400e119
FB
1877 abi_long arg0, abi_long arg1, abi_long arg2,
1878 abi_long arg3, abi_long arg4, abi_long arg5)
74d753ac
MW
1879{
1880 print_syscall_prologue(name);
1881 print_string(arg0, 0);
1882 print_file_mode(arg1, 1);
1883 print_syscall_epilogue(name);
1884}
1885#endif
1886
5844f4bc
FB
1887#if defined(TARGET_NR_chown) || defined(TARGET_NR_lchown)
1888static void
a0939b89 1889print_chown(CPUArchState *cpu_env, const struct syscallname *name,
e400e119
FB
1890 abi_long arg0, abi_long arg1, abi_long arg2,
1891 abi_long arg3, abi_long arg4, abi_long arg5)
5844f4bc
FB
1892{
1893 print_syscall_prologue(name);
1894 print_string(arg0, 0);
1895 print_raw_param("%d", arg1, 0);
1896 print_raw_param("%d", arg2, 1);
1897 print_syscall_epilogue(name);
1898}
1899#define print_lchown print_chown
1900#endif
1901
38860a03
AM
1902#ifdef TARGET_NR_clock_adjtime
1903static void
a0939b89 1904print_clock_adjtime(CPUArchState *cpu_env, const struct syscallname *name,
e400e119
FB
1905 abi_long arg0, abi_long arg1, abi_long arg2,
1906 abi_long arg3, abi_long arg4, abi_long arg5)
38860a03
AM
1907{
1908 print_syscall_prologue(name);
1a674adf 1909 print_enums(clockids, arg0, 0);
38860a03
AM
1910 print_pointer(arg1, 1);
1911 print_syscall_epilogue(name);
1912}
1913#endif
1914
608e5592 1915#ifdef TARGET_NR_clone
84bd8284
LV
1916static void do_print_clone(unsigned int flags, abi_ulong newsp,
1917 abi_ulong parent_tidptr, target_ulong newtls,
1918 abi_ulong child_tidptr)
1919{
1920 print_flags(clone_flags, flags, 0);
1921 print_raw_param("child_stack=0x" TARGET_ABI_FMT_lx, newsp, 0);
1922 print_raw_param("parent_tidptr=0x" TARGET_ABI_FMT_lx, parent_tidptr, 0);
1923 print_raw_param("tls=0x" TARGET_ABI_FMT_lx, newtls, 0);
1924 print_raw_param("child_tidptr=0x" TARGET_ABI_FMT_lx, child_tidptr, 1);
1925}
1926
608e5592 1927static void
a0939b89 1928print_clone(CPUArchState *cpu_env, const struct syscallname *name,
e400e119
FB
1929 abi_long arg1, abi_long arg2, abi_long arg3,
1930 abi_long arg4, abi_long arg5, abi_long arg6)
608e5592
LV
1931{
1932 print_syscall_prologue(name);
84bd8284
LV
1933#if defined(TARGET_MICROBLAZE)
1934 do_print_clone(arg1, arg2, arg4, arg6, arg5);
1935#elif defined(TARGET_CLONE_BACKWARDS)
1936 do_print_clone(arg1, arg2, arg3, arg4, arg5);
1937#elif defined(TARGET_CLONE_BACKWARDS2)
1938 do_print_clone(arg2, arg1, arg3, arg5, arg4);
608e5592 1939#else
84bd8284 1940 do_print_clone(arg1, arg2, arg3, arg5, arg4);
608e5592
LV
1941#endif
1942 print_syscall_epilogue(name);
1943}
1944#endif
1945
74d753ac
MW
1946#ifdef TARGET_NR_creat
1947static void
a0939b89 1948print_creat(CPUArchState *cpu_env, const struct syscallname *name,
e400e119
FB
1949 abi_long arg0, abi_long arg1, abi_long arg2,
1950 abi_long arg3, abi_long arg4, abi_long arg5)
74d753ac
MW
1951{
1952 print_syscall_prologue(name);
1953 print_string(arg0, 0);
1954 print_file_mode(arg1, 1);
1955 print_syscall_epilogue(name);
1956}
1957#endif
1958
1959#ifdef TARGET_NR_execv
1960static void
a0939b89 1961print_execv(CPUArchState *cpu_env, const struct syscallname *name,
e400e119
FB
1962 abi_long arg0, abi_long arg1, abi_long arg2,
1963 abi_long arg3, abi_long arg4, abi_long arg5)
74d753ac
MW
1964{
1965 print_syscall_prologue(name);
1966 print_string(arg0, 0);
d2ee72a5 1967 print_raw_param("0x" TARGET_ABI_FMT_lx, arg1, 1);
74d753ac
MW
1968 print_syscall_epilogue(name);
1969}
1970#endif
1971
35a2c85f 1972#if defined(TARGET_NR_faccessat) || defined(TARGET_NR_faccessat2)
74d753ac 1973static void
a0939b89 1974print_faccessat(CPUArchState *cpu_env, const struct syscallname *name,
e400e119
FB
1975 abi_long arg0, abi_long arg1, abi_long arg2,
1976 abi_long arg3, abi_long arg4, abi_long arg5)
74d753ac
MW
1977{
1978 print_syscall_prologue(name);
1979 print_at_dirfd(arg0, 0);
1980 print_string(arg1, 0);
1981 print_flags(access_flags, arg2, 0);
1982 print_flags(at_file_flags, arg3, 1);
1983 print_syscall_epilogue(name);
1984}
1985#endif
1986
f4d92c5e
FB
1987#ifdef TARGET_NR_fallocate
1988static void
a0939b89 1989print_fallocate(CPUArchState *cpu_env, const struct syscallname *name,
e400e119
FB
1990 abi_long arg0, abi_long arg1, abi_long arg2,
1991 abi_long arg3, abi_long arg4, abi_long arg5)
f4d92c5e
FB
1992{
1993 print_syscall_prologue(name);
1994 print_raw_param("%d", arg0, 0);
1995 print_flags(falloc_flags, arg1, 0);
1996#if TARGET_ABI_BITS == 32
1997 print_raw_param("%" PRIu64, target_offset64(arg2, arg3), 0);
1998 print_raw_param("%" PRIu64, target_offset64(arg4, arg5), 1);
1999#else
2000 print_raw_param(TARGET_ABI_FMT_ld, arg2, 0);
2001 print_raw_param(TARGET_ABI_FMT_ld, arg3, 1);
2002#endif
2003 print_syscall_epilogue(name);
2004}
2005#endif
2006
74d753ac
MW
2007#ifdef TARGET_NR_fchmodat
2008static void
a0939b89 2009print_fchmodat(CPUArchState *cpu_env, const struct syscallname *name,
e400e119
FB
2010 abi_long arg0, abi_long arg1, abi_long arg2,
2011 abi_long arg3, abi_long arg4, abi_long arg5)
74d753ac
MW
2012{
2013 print_syscall_prologue(name);
2014 print_at_dirfd(arg0, 0);
2015 print_string(arg1, 0);
2016 print_file_mode(arg2, 0);
2017 print_flags(at_file_flags, arg3, 1);
2018 print_syscall_epilogue(name);
2019}
2020#endif
2021
2022#ifdef TARGET_NR_fchownat
2023static void
a0939b89 2024print_fchownat(CPUArchState *cpu_env, const struct syscallname *name,
e400e119
FB
2025 abi_long arg0, abi_long arg1, abi_long arg2,
2026 abi_long arg3, abi_long arg4, abi_long arg5)
74d753ac
MW
2027{
2028 print_syscall_prologue(name);
2029 print_at_dirfd(arg0, 0);
2030 print_string(arg1, 0);
d2ee72a5
LV
2031 print_raw_param("%d", arg2, 0);
2032 print_raw_param("%d", arg3, 0);
74d753ac
MW
2033 print_flags(at_file_flags, arg4, 1);
2034 print_syscall_epilogue(name);
2035}
2036#endif
2037
2038#if defined(TARGET_NR_fcntl) || defined(TARGET_NR_fcntl64)
2039static void
a0939b89 2040print_fcntl(CPUArchState *cpu_env, const struct syscallname *name,
e400e119
FB
2041 abi_long arg0, abi_long arg1, abi_long arg2,
2042 abi_long arg3, abi_long arg4, abi_long arg5)
74d753ac
MW
2043{
2044 print_syscall_prologue(name);
d2ee72a5 2045 print_raw_param("%d", arg0, 0);
d95ec14f
LV
2046 switch(arg1) {
2047 case TARGET_F_DUPFD:
4b25a506 2048 qemu_log("F_DUPFD,");
d95ec14f
LV
2049 print_raw_param(TARGET_ABI_FMT_ld, arg2, 1);
2050 break;
2051 case TARGET_F_GETFD:
4b25a506 2052 qemu_log("F_GETFD");
d95ec14f
LV
2053 break;
2054 case TARGET_F_SETFD:
4b25a506 2055 qemu_log("F_SETFD,");
d95ec14f
LV
2056 print_raw_param(TARGET_ABI_FMT_ld, arg2, 1);
2057 break;
2058 case TARGET_F_GETFL:
4b25a506 2059 qemu_log("F_GETFL");
d95ec14f
LV
2060 break;
2061 case TARGET_F_SETFL:
4b25a506 2062 qemu_log("F_SETFL,");
d95ec14f
LV
2063 print_open_flags(arg2, 1);
2064 break;
2065 case TARGET_F_GETLK:
4b25a506 2066 qemu_log("F_GETLK,");
d95ec14f
LV
2067 print_pointer(arg2, 1);
2068 break;
2069 case TARGET_F_SETLK:
4b25a506 2070 qemu_log("F_SETLK,");
d95ec14f
LV
2071 print_pointer(arg2, 1);
2072 break;
2073 case TARGET_F_SETLKW:
4b25a506 2074 qemu_log("F_SETLKW,");
d95ec14f
LV
2075 print_pointer(arg2, 1);
2076 break;
2077 case TARGET_F_GETOWN:
4b25a506 2078 qemu_log("F_GETOWN");
d95ec14f
LV
2079 break;
2080 case TARGET_F_SETOWN:
4b25a506 2081 qemu_log("F_SETOWN,");
d95ec14f
LV
2082 print_raw_param(TARGET_ABI_FMT_ld, arg2, 0);
2083 break;
2084 case TARGET_F_GETSIG:
4b25a506 2085 qemu_log("F_GETSIG");
d95ec14f
LV
2086 break;
2087 case TARGET_F_SETSIG:
4b25a506 2088 qemu_log("F_SETSIG,");
d95ec14f
LV
2089 print_raw_param(TARGET_ABI_FMT_ld, arg2, 0);
2090 break;
2091#if TARGET_ABI_BITS == 32
2092 case TARGET_F_GETLK64:
4b25a506 2093 qemu_log("F_GETLK64,");
d95ec14f
LV
2094 print_pointer(arg2, 1);
2095 break;
2096 case TARGET_F_SETLK64:
4b25a506 2097 qemu_log("F_SETLK64,");
d95ec14f
LV
2098 print_pointer(arg2, 1);
2099 break;
2100 case TARGET_F_SETLKW64:
4b25a506 2101 qemu_log("F_SETLKW64,");
d95ec14f
LV
2102 print_pointer(arg2, 1);
2103 break;
2104#endif
38be863d
MG
2105 case TARGET_F_OFD_GETLK:
2106 qemu_log("F_OFD_GETLK,");
2107 print_pointer(arg2, 1);
2108 break;
2109 case TARGET_F_OFD_SETLK:
2110 qemu_log("F_OFD_SETLK,");
2111 print_pointer(arg2, 1);
2112 break;
2113 case TARGET_F_OFD_SETLKW:
2114 qemu_log("F_OFD_SETLKW,");
2115 print_pointer(arg2, 1);
2116 break;
d95ec14f 2117 case TARGET_F_SETLEASE:
4b25a506 2118 qemu_log("F_SETLEASE,");
2bb963ff 2119 print_raw_param(TARGET_ABI_FMT_ld, arg2, 1);
d95ec14f
LV
2120 break;
2121 case TARGET_F_GETLEASE:
4b25a506 2122 qemu_log("F_GETLEASE");
d95ec14f 2123 break;
2bb963ff
SCW
2124#ifdef F_DUPFD_CLOEXEC
2125 case TARGET_F_DUPFD_CLOEXEC:
2126 qemu_log("F_DUPFD_CLOEXEC,");
2127 print_raw_param(TARGET_ABI_FMT_ld, arg2, 1);
2128 break;
2129#endif
2130 case TARGET_F_NOTIFY:
2131 qemu_log("F_NOTIFY,");
2132 print_raw_param(TARGET_ABI_FMT_ld, arg2, 1);
2133 break;
2134#ifdef F_GETOWN_EX
2135 case TARGET_F_GETOWN_EX:
2136 qemu_log("F_GETOWN_EX,");
2137 print_pointer(arg2, 1);
2138 break;
2139#endif
2140#ifdef F_SETOWN_EX
2141 case TARGET_F_SETOWN_EX:
2142 qemu_log("F_SETOWN_EX,");
2143 print_pointer(arg2, 1);
2144 break;
2145#endif
2146#ifdef F_SETPIPE_SZ
7e3b92ec 2147 case TARGET_F_SETPIPE_SZ:
4b25a506 2148 qemu_log("F_SETPIPE_SZ,");
7e3b92ec
PM
2149 print_raw_param(TARGET_ABI_FMT_ld, arg2, 1);
2150 break;
2151 case TARGET_F_GETPIPE_SZ:
4b25a506 2152 qemu_log("F_GETPIPE_SZ");
7e3b92ec 2153 break;
2bb963ff
SCW
2154#endif
2155#ifdef F_ADD_SEALS
2156 case TARGET_F_ADD_SEALS:
2157 qemu_log("F_ADD_SEALS,");
2158 print_raw_param("0x"TARGET_ABI_FMT_lx, arg2, 1);
d95ec14f 2159 break;
2bb963ff
SCW
2160 case TARGET_F_GET_SEALS:
2161 qemu_log("F_GET_SEALS");
d95ec14f 2162 break;
2bb963ff 2163#endif
d95ec14f
LV
2164 default:
2165 print_raw_param(TARGET_ABI_FMT_ld, arg1, 0);
2166 print_pointer(arg2, 1);
2167 break;
2168 }
74d753ac
MW
2169 print_syscall_epilogue(name);
2170}
2171#define print_fcntl64 print_fcntl
2172#endif
2173
4fc3cdde
FB
2174#ifdef TARGET_NR_fgetxattr
2175static void
a0939b89 2176print_fgetxattr(CPUArchState *cpu_env, const struct syscallname *name,
e400e119
FB
2177 abi_long arg0, abi_long arg1, abi_long arg2,
2178 abi_long arg3, abi_long arg4, abi_long arg5)
4fc3cdde
FB
2179{
2180 print_syscall_prologue(name);
2181 print_raw_param("%d", arg0, 0);
2182 print_string(arg1, 0);
2183 print_pointer(arg2, 0);
2184 print_raw_param(TARGET_FMT_lu, arg3, 1);
2185 print_syscall_epilogue(name);
2186}
2187#endif
2188
2189#ifdef TARGET_NR_flistxattr
2190static void
a0939b89 2191print_flistxattr(CPUArchState *cpu_env, const struct syscallname *name,
e400e119
FB
2192 abi_long arg0, abi_long arg1, abi_long arg2,
2193 abi_long arg3, abi_long arg4, abi_long arg5)
4fc3cdde
FB
2194{
2195 print_syscall_prologue(name);
2196 print_raw_param("%d", arg0, 0);
2197 print_pointer(arg1, 0);
2198 print_raw_param(TARGET_FMT_lu, arg2, 1);
2199 print_syscall_epilogue(name);
2200}
2201#endif
2202
2203#if defined(TARGET_NR_getxattr) || defined(TARGET_NR_lgetxattr)
2204static void
a0939b89 2205print_getxattr(CPUArchState *cpu_env, const struct syscallname *name,
e400e119
FB
2206 abi_long arg0, abi_long arg1, abi_long arg2,
2207 abi_long arg3, abi_long arg4, abi_long arg5)
4fc3cdde
FB
2208{
2209 print_syscall_prologue(name);
2210 print_string(arg0, 0);
2211 print_string(arg1, 0);
2212 print_pointer(arg2, 0);
2213 print_raw_param(TARGET_FMT_lu, arg3, 1);
2214 print_syscall_epilogue(name);
2215}
2216#define print_lgetxattr print_getxattr
2217#endif
2218
2219#if defined(TARGET_NR_listxattr) || defined(TARGET_NR_llistxattr)
2220static void
a0939b89 2221print_listxattr(CPUArchState *cpu_env, const struct syscallname *name,
e400e119
FB
2222 abi_long arg0, abi_long arg1, abi_long arg2,
2223 abi_long arg3, abi_long arg4, abi_long arg5)
4fc3cdde
FB
2224{
2225 print_syscall_prologue(name);
2226 print_string(arg0, 0);
2227 print_pointer(arg1, 0);
2228 print_raw_param(TARGET_FMT_lu, arg2, 1);
2229 print_syscall_epilogue(name);
2230}
2231#define print_llistxattr print_listxattr
2232#endif
2233
2234#if defined(TARGET_NR_fremovexattr)
2235static void
a0939b89 2236print_fremovexattr(CPUArchState *cpu_env, const struct syscallname *name,
e400e119
FB
2237 abi_long arg0, abi_long arg1, abi_long arg2,
2238 abi_long arg3, abi_long arg4, abi_long arg5)
4fc3cdde
FB
2239{
2240 print_syscall_prologue(name);
2241 print_raw_param("%d", arg0, 0);
2242 print_string(arg1, 1);
2243 print_syscall_epilogue(name);
2244}
2245#endif
2246
2247#if defined(TARGET_NR_removexattr) || defined(TARGET_NR_lremovexattr)
2248static void
a0939b89 2249print_removexattr(CPUArchState *cpu_env, const struct syscallname *name,
e400e119
FB
2250 abi_long arg0, abi_long arg1, abi_long arg2,
2251 abi_long arg3, abi_long arg4, abi_long arg5)
4fc3cdde
FB
2252{
2253 print_syscall_prologue(name);
2254 print_string(arg0, 0);
2255 print_string(arg1, 1);
2256 print_syscall_epilogue(name);
2257}
2258#define print_lremovexattr print_removexattr
2259#endif
2260
74d753ac
MW
2261#ifdef TARGET_NR_futimesat
2262static void
a0939b89 2263print_futimesat(CPUArchState *cpu_env, const struct syscallname *name,
e400e119
FB
2264 abi_long arg0, abi_long arg1, abi_long arg2,
2265 abi_long arg3, abi_long arg4, abi_long arg5)
74d753ac
MW
2266{
2267 print_syscall_prologue(name);
2268 print_at_dirfd(arg0, 0);
2269 print_string(arg1, 0);
2270 print_timeval(arg2, 0);
2271 print_timeval(arg2 + sizeof (struct target_timeval), 1);
2272 print_syscall_epilogue(name);
2273}
2274#endif
2275
1a674adf
FB
2276#ifdef TARGET_NR_gettimeofday
2277static void
a0939b89 2278print_gettimeofday(CPUArchState *cpu_env, const struct syscallname *name,
1a674adf
FB
2279 abi_long arg0, abi_long arg1, abi_long arg2,
2280 abi_long arg3, abi_long arg4, abi_long arg5)
2281{
2282 print_syscall_prologue(name);
2283 print_pointer(arg0, 0);
2284 print_pointer(arg1, 1);
2285 print_syscall_epilogue(name);
2286}
2287#endif
2288
0d2187c4
PMD
2289#ifdef TARGET_NR_settimeofday
2290static void
a0939b89 2291print_settimeofday(CPUArchState *cpu_env, const struct syscallname *name,
e400e119
FB
2292 abi_long arg0, abi_long arg1, abi_long arg2,
2293 abi_long arg3, abi_long arg4, abi_long arg5)
0d2187c4
PMD
2294{
2295 print_syscall_prologue(name);
2296 print_timeval(arg0, 0);
2297 print_timezone(arg1, 1);
2298 print_syscall_epilogue(name);
2299}
2300#endif
2301
1a674adf
FB
2302#if defined(TARGET_NR_clock_gettime) || defined(TARGET_NR_clock_getres)
2303static void
a0939b89 2304print_clock_gettime(CPUArchState *cpu_env, const struct syscallname *name,
1a674adf
FB
2305 abi_long arg0, abi_long arg1, abi_long arg2,
2306 abi_long arg3, abi_long arg4, abi_long arg5)
2307{
2308 print_syscall_prologue(name);
2309 print_enums(clockids, arg0, 0);
2310 print_pointer(arg1, 1);
2311 print_syscall_epilogue(name);
2312}
2313#define print_clock_getres print_clock_gettime
2314#endif
2315
aad43d15
HD
2316#if defined(TARGET_NR_clock_gettime64)
2317static void
2318print_clock_gettime64(CPUArchState *cpu_env, const struct syscallname *name,
2319 abi_long arg0, abi_long arg1, abi_long arg2,
2320 abi_long arg3, abi_long arg4, abi_long arg5)
2321{
2322 print_syscall_prologue(name);
2323 print_enums(clockids, arg0, 0);
2324 print_pointer(arg1, 1);
2325 print_syscall_epilogue(name);
2326}
2327#endif
2328
1a674adf
FB
2329#ifdef TARGET_NR_clock_settime
2330static void
a0939b89 2331print_clock_settime(CPUArchState *cpu_env, const struct syscallname *name,
1a674adf
FB
2332 abi_long arg0, abi_long arg1, abi_long arg2,
2333 abi_long arg3, abi_long arg4, abi_long arg5)
2334{
2335 print_syscall_prologue(name);
2336 print_enums(clockids, arg0, 0);
2337 print_timespec(arg1, 1);
2338 print_syscall_epilogue(name);
2339}
2340#endif
2341
2342#ifdef TARGET_NR_getitimer
2343static void
a0939b89 2344print_getitimer(CPUArchState *cpu_env, const struct syscallname *name,
1a674adf
FB
2345 abi_long arg0, abi_long arg1, abi_long arg2,
2346 abi_long arg3, abi_long arg4, abi_long arg5)
2347{
2348 print_syscall_prologue(name);
2349 print_enums(itimer_types, arg0, 0);
2350 print_pointer(arg1, 1);
2351 print_syscall_epilogue(name);
2352}
2353#endif
2354
2355#ifdef TARGET_NR_setitimer
2356static void
a0939b89 2357print_setitimer(CPUArchState *cpu_env, const struct syscallname *name,
1a674adf
FB
2358 abi_long arg0, abi_long arg1, abi_long arg2,
2359 abi_long arg3, abi_long arg4, abi_long arg5)
2360{
2361 print_syscall_prologue(name);
2362 print_enums(itimer_types, arg0, 0);
2363 print_itimerval(arg1, 0);
2364 print_pointer(arg2, 1);
2365 print_syscall_epilogue(name);
2366}
2367#endif
2368
74d753ac
MW
2369#ifdef TARGET_NR_link
2370static void
a0939b89 2371print_link(CPUArchState *cpu_env, const struct syscallname *name,
e400e119
FB
2372 abi_long arg0, abi_long arg1, abi_long arg2,
2373 abi_long arg3, abi_long arg4, abi_long arg5)
74d753ac
MW
2374{
2375 print_syscall_prologue(name);
2376 print_string(arg0, 0);
2377 print_string(arg1, 1);
2378 print_syscall_epilogue(name);
2379}
2380#endif
2381
2382#ifdef TARGET_NR_linkat
2383static void
a0939b89 2384print_linkat(CPUArchState *cpu_env, const struct syscallname *name,
e400e119
FB
2385 abi_long arg0, abi_long arg1, abi_long arg2,
2386 abi_long arg3, abi_long arg4, abi_long arg5)
74d753ac
MW
2387{
2388 print_syscall_prologue(name);
2389 print_at_dirfd(arg0, 0);
2390 print_string(arg1, 0);
2391 print_at_dirfd(arg2, 0);
2392 print_string(arg3, 0);
2393 print_flags(at_file_flags, arg4, 1);
2394 print_syscall_epilogue(name);
2395}
2396#endif
2397
9f771ad8 2398#if defined(TARGET_NR__llseek) || defined(TARGET_NR_llseek)
608e5592 2399static void
a0939b89 2400print__llseek(CPUArchState *cpu_env, const struct syscallname *name,
e400e119
FB
2401 abi_long arg0, abi_long arg1, abi_long arg2,
2402 abi_long arg3, abi_long arg4, abi_long arg5)
608e5592
LV
2403{
2404 const char *whence = "UNKNOWN";
2405 print_syscall_prologue(name);
2406 print_raw_param("%d", arg0, 0);
2407 print_raw_param("%ld", arg1, 0);
2408 print_raw_param("%ld", arg2, 0);
2409 print_pointer(arg3, 0);
2410 switch(arg4) {
2411 case SEEK_SET: whence = "SEEK_SET"; break;
2412 case SEEK_CUR: whence = "SEEK_CUR"; break;
2413 case SEEK_END: whence = "SEEK_END"; break;
2414 }
4b25a506 2415 qemu_log("%s", whence);
608e5592
LV
2416 print_syscall_epilogue(name);
2417}
9f771ad8 2418#define print_llseek print__llseek
608e5592
LV
2419#endif
2420
af861dea
FB
2421#ifdef TARGET_NR_lseek
2422static void
a0939b89 2423print_lseek(CPUArchState *cpu_env, const struct syscallname *name,
e400e119
FB
2424 abi_long arg0, abi_long arg1, abi_long arg2,
2425 abi_long arg3, abi_long arg4, abi_long arg5)
af861dea
FB
2426{
2427 print_syscall_prologue(name);
2428 print_raw_param("%d", arg0, 0);
2429 print_raw_param(TARGET_ABI_FMT_ld, arg1, 0);
2430 switch (arg2) {
2431 case SEEK_SET:
2432 qemu_log("SEEK_SET"); break;
2433 case SEEK_CUR:
2434 qemu_log("SEEK_CUR"); break;
2435 case SEEK_END:
2436 qemu_log("SEEK_END"); break;
2437#ifdef SEEK_DATA
2438 case SEEK_DATA:
2439 qemu_log("SEEK_DATA"); break;
2440#endif
2441#ifdef SEEK_HOLE
2442 case SEEK_HOLE:
2443 qemu_log("SEEK_HOLE"); break;
2444#endif
2445 default:
2446 print_raw_param("%#x", arg2, 1);
2447 }
2448 print_syscall_epilogue(name);
2449}
2450#endif
2451
7c89f343
FB
2452#ifdef TARGET_NR_truncate
2453static void
a0939b89 2454print_truncate(CPUArchState *cpu_env, const struct syscallname *name,
7c89f343
FB
2455 abi_long arg0, abi_long arg1, abi_long arg2,
2456 abi_long arg3, abi_long arg4, abi_long arg5)
2457{
2458 print_syscall_prologue(name);
2459 print_string(arg0, 0);
2460 print_raw_param(TARGET_ABI_FMT_ld, arg1, 1);
2461 print_syscall_epilogue(name);
2462}
2463#endif
2464
2465#ifdef TARGET_NR_truncate64
2466static void
a0939b89 2467print_truncate64(CPUArchState *cpu_env, const struct syscallname *name,
7c89f343
FB
2468 abi_long arg0, abi_long arg1, abi_long arg2,
2469 abi_long arg3, abi_long arg4, abi_long arg5)
2470{
2471 print_syscall_prologue(name);
2472 print_string(arg0, 0);
2473 if (regpairs_aligned(cpu_env, TARGET_NR_truncate64)) {
2474 arg1 = arg2;
2475 arg2 = arg3;
2476 }
2477 print_raw_param("%" PRIu64, target_offset64(arg1, arg2), 1);
2478 print_syscall_epilogue(name);
2479}
2480#endif
2481
2482#ifdef TARGET_NR_ftruncate64
2483static void
a0939b89 2484print_ftruncate64(CPUArchState *cpu_env, const struct syscallname *name,
7c89f343
FB
2485 abi_long arg0, abi_long arg1, abi_long arg2,
2486 abi_long arg3, abi_long arg4, abi_long arg5)
2487{
2488 print_syscall_prologue(name);
2489 print_raw_param("%d", arg0, 0);
2490 if (regpairs_aligned(cpu_env, TARGET_NR_ftruncate64)) {
2491 arg1 = arg2;
2492 arg2 = arg3;
2493 }
2494 print_raw_param("%" PRIu64, target_offset64(arg1, arg2), 1);
2495 print_syscall_epilogue(name);
2496}
2497#endif
2498
02e5d7d7
FB
2499#ifdef TARGET_NR_mlockall
2500static void
a0939b89 2501print_mlockall(CPUArchState *cpu_env, const struct syscallname *name,
02e5d7d7
FB
2502 abi_long arg0, abi_long arg1, abi_long arg2,
2503 abi_long arg3, abi_long arg4, abi_long arg5)
2504{
2505 print_syscall_prologue(name);
2506 print_flags(mlockall_flags, arg0, 1);
2507 print_syscall_epilogue(name);
2508}
2509#endif
2510
8997d1bd
LV
2511#if defined(TARGET_NR_socket)
2512static void
a0939b89 2513print_socket(CPUArchState *cpu_env, const struct syscallname *name,
8997d1bd
LV
2514 abi_long arg0, abi_long arg1, abi_long arg2,
2515 abi_long arg3, abi_long arg4, abi_long arg5)
2516{
2517 abi_ulong domain = arg0, type = arg1, protocol = arg2;
2518
2519 print_syscall_prologue(name);
2520 print_socket_domain(domain);
4b25a506 2521 qemu_log(",");
8997d1bd 2522 print_socket_type(type);
4b25a506 2523 qemu_log(",");
8997d1bd
LV
2524 if (domain == AF_PACKET ||
2525 (domain == AF_INET && type == TARGET_SOCK_PACKET)) {
2526 protocol = tswap16(protocol);
2527 }
2528 print_socket_protocol(domain, type, protocol);
2529 print_syscall_epilogue(name);
2530}
2531
2532#endif
2533
bb10540e 2534#if defined(TARGET_NR_socketcall) || defined(TARGET_NR_bind)
fb3aabf3 2535
d84fe1ed
PMD
2536static void print_sockfd(abi_long sockfd, int last)
2537{
2538 print_raw_param(TARGET_ABI_FMT_ld, sockfd, last);
2539}
2540
2541#endif
2542
2543#if defined(TARGET_NR_socketcall)
2544
fb3aabf3
LV
2545#define get_user_ualx(x, gaddr, idx) \
2546 get_user_ual(x, (gaddr) + (idx) * sizeof(abi_long))
2547
2548static void do_print_socket(const char *name, abi_long arg1)
2549{
2550 abi_ulong domain, type, protocol;
2551
2552 get_user_ualx(domain, arg1, 0);
2553 get_user_ualx(type, arg1, 1);
2554 get_user_ualx(protocol, arg1, 2);
4b25a506 2555 qemu_log("%s(", name);
fb3aabf3 2556 print_socket_domain(domain);
4b25a506 2557 qemu_log(",");
fb3aabf3 2558 print_socket_type(type);
4b25a506 2559 qemu_log(",");
fb3aabf3
LV
2560 if (domain == AF_PACKET ||
2561 (domain == AF_INET && type == TARGET_SOCK_PACKET)) {
2562 protocol = tswap16(protocol);
2563 }
2564 print_socket_protocol(domain, type, protocol);
4b25a506 2565 qemu_log(")");
fb3aabf3
LV
2566}
2567
2568static void do_print_sockaddr(const char *name, abi_long arg1)
2569{
2570 abi_ulong sockfd, addr, addrlen;
2571
2572 get_user_ualx(sockfd, arg1, 0);
2573 get_user_ualx(addr, arg1, 1);
2574 get_user_ualx(addrlen, arg1, 2);
2575
4b25a506 2576 qemu_log("%s(", name);
d84fe1ed 2577 print_sockfd(sockfd, 0);
42b15d70 2578 print_sockaddr(addr, addrlen, 0);
4b25a506 2579 qemu_log(")");
fb3aabf3
LV
2580}
2581
2582static void do_print_listen(const char *name, abi_long arg1)
2583{
2584 abi_ulong sockfd, backlog;
2585
2586 get_user_ualx(sockfd, arg1, 0);
2587 get_user_ualx(backlog, arg1, 1);
2588
4b25a506 2589 qemu_log("%s(", name);
d84fe1ed 2590 print_sockfd(sockfd, 0);
fb3aabf3 2591 print_raw_param(TARGET_ABI_FMT_ld, backlog, 1);
4b25a506 2592 qemu_log(")");
fb3aabf3
LV
2593}
2594
2595static void do_print_socketpair(const char *name, abi_long arg1)
2596{
2597 abi_ulong domain, type, protocol, tab;
2598
2599 get_user_ualx(domain, arg1, 0);
2600 get_user_ualx(type, arg1, 1);
2601 get_user_ualx(protocol, arg1, 2);
2602 get_user_ualx(tab, arg1, 3);
2603
4b25a506 2604 qemu_log("%s(", name);
fb3aabf3 2605 print_socket_domain(domain);
4b25a506 2606 qemu_log(",");
fb3aabf3 2607 print_socket_type(type);
4b25a506 2608 qemu_log(",");
fb3aabf3 2609 print_socket_protocol(domain, type, protocol);
4b25a506 2610 qemu_log(",");
fb3aabf3 2611 print_raw_param(TARGET_ABI_FMT_lx, tab, 1);
4b25a506 2612 qemu_log(")");
fb3aabf3
LV
2613}
2614
2615static void do_print_sendrecv(const char *name, abi_long arg1)
2616{
2617 abi_ulong sockfd, msg, len, flags;
2618
2619 get_user_ualx(sockfd, arg1, 0);
2620 get_user_ualx(msg, arg1, 1);
2621 get_user_ualx(len, arg1, 2);
2622 get_user_ualx(flags, arg1, 3);
2623
4b25a506 2624 qemu_log("%s(", name);
d84fe1ed 2625 print_sockfd(sockfd, 0);
fb3aabf3
LV
2626 print_buf(msg, len, 0);
2627 print_raw_param(TARGET_ABI_FMT_ld, len, 0);
2628 print_flags(msg_flags, flags, 1);
4b25a506 2629 qemu_log(")");
fb3aabf3
LV
2630}
2631
2632static void do_print_msgaddr(const char *name, abi_long arg1)
2633{
2634 abi_ulong sockfd, msg, len, flags, addr, addrlen;
2635
2636 get_user_ualx(sockfd, arg1, 0);
2637 get_user_ualx(msg, arg1, 1);
2638 get_user_ualx(len, arg1, 2);
2639 get_user_ualx(flags, arg1, 3);
2640 get_user_ualx(addr, arg1, 4);
2641 get_user_ualx(addrlen, arg1, 5);
2642
4b25a506 2643 qemu_log("%s(", name);
d84fe1ed 2644 print_sockfd(sockfd, 0);
fb3aabf3
LV
2645 print_buf(msg, len, 0);
2646 print_raw_param(TARGET_ABI_FMT_ld, len, 0);
2647 print_flags(msg_flags, flags, 0);
42b15d70 2648 print_sockaddr(addr, addrlen, 0);
4b25a506 2649 qemu_log(")");
fb3aabf3
LV
2650}
2651
2652static void do_print_shutdown(const char *name, abi_long arg1)
2653{
2654 abi_ulong sockfd, how;
2655
2656 get_user_ualx(sockfd, arg1, 0);
2657 get_user_ualx(how, arg1, 1);
2658
4b25a506 2659 qemu_log("shutdown(");
d84fe1ed 2660 print_sockfd(sockfd, 0);
fb3aabf3
LV
2661 switch (how) {
2662 case SHUT_RD:
4b25a506 2663 qemu_log("SHUT_RD");
fb3aabf3
LV
2664 break;
2665 case SHUT_WR:
4b25a506 2666 qemu_log("SHUT_WR");
fb3aabf3
LV
2667 break;
2668 case SHUT_RDWR:
4b25a506 2669 qemu_log("SHUT_RDWR");
fb3aabf3
LV
2670 break;
2671 default:
2672 print_raw_param(TARGET_ABI_FMT_ld, how, 1);
2673 break;
2674 }
4b25a506 2675 qemu_log(")");
fb3aabf3
LV
2676}
2677
2678static void do_print_msg(const char *name, abi_long arg1)
2679{
2680 abi_ulong sockfd, msg, flags;
2681
2682 get_user_ualx(sockfd, arg1, 0);
2683 get_user_ualx(msg, arg1, 1);
2684 get_user_ualx(flags, arg1, 2);
2685
4b25a506 2686 qemu_log("%s(", name);
d84fe1ed 2687 print_sockfd(sockfd, 0);
fb3aabf3
LV
2688 print_pointer(msg, 0);
2689 print_flags(msg_flags, flags, 1);
4b25a506 2690 qemu_log(")");
fb3aabf3
LV
2691}
2692
2693static void do_print_sockopt(const char *name, abi_long arg1)
2694{
2695 abi_ulong sockfd, level, optname, optval, optlen;
2696
2697 get_user_ualx(sockfd, arg1, 0);
2698 get_user_ualx(level, arg1, 1);
2699 get_user_ualx(optname, arg1, 2);
2700 get_user_ualx(optval, arg1, 3);
2701 get_user_ualx(optlen, arg1, 4);
2702
4b25a506 2703 qemu_log("%s(", name);
d84fe1ed 2704 print_sockfd(sockfd, 0);
fb3aabf3
LV
2705 switch (level) {
2706 case SOL_TCP:
4b25a506 2707 qemu_log("SOL_TCP,");
fb3aabf3
LV
2708 print_raw_param(TARGET_ABI_FMT_ld, optname, 0);
2709 print_pointer(optval, 0);
fe51b0a5
SCW
2710 break;
2711 case SOL_UDP:
2712 qemu_log("SOL_UDP,");
2713 print_raw_param(TARGET_ABI_FMT_ld, optname, 0);
2714 print_pointer(optval, 0);
fb3aabf3
LV
2715 break;
2716 case SOL_IP:
4b25a506 2717 qemu_log("SOL_IP,");
fb3aabf3
LV
2718 print_raw_param(TARGET_ABI_FMT_ld, optname, 0);
2719 print_pointer(optval, 0);
2720 break;
2721 case SOL_RAW:
4b25a506 2722 qemu_log("SOL_RAW,");
fb3aabf3
LV
2723 print_raw_param(TARGET_ABI_FMT_ld, optname, 0);
2724 print_pointer(optval, 0);
2725 break;
2726 case TARGET_SOL_SOCKET:
4b25a506 2727 qemu_log("SOL_SOCKET,");
fb3aabf3
LV
2728 switch (optname) {
2729 case TARGET_SO_DEBUG:
4b25a506 2730 qemu_log("SO_DEBUG,");
fb3aabf3
LV
2731print_optint:
2732 print_number(optval, 0);
2733 break;
2734 case TARGET_SO_REUSEADDR:
4b25a506 2735 qemu_log("SO_REUSEADDR,");
fb3aabf3 2736 goto print_optint;
113a9dd7 2737 case TARGET_SO_REUSEPORT:
4b25a506 2738 qemu_log("SO_REUSEPORT,");
113a9dd7 2739 goto print_optint;
fb3aabf3 2740 case TARGET_SO_TYPE:
4b25a506 2741 qemu_log("SO_TYPE,");
fb3aabf3
LV
2742 goto print_optint;
2743 case TARGET_SO_ERROR:
4b25a506 2744 qemu_log("SO_ERROR,");
fb3aabf3
LV
2745 goto print_optint;
2746 case TARGET_SO_DONTROUTE:
4b25a506 2747 qemu_log("SO_DONTROUTE,");
fb3aabf3
LV
2748 goto print_optint;
2749 case TARGET_SO_BROADCAST:
4b25a506 2750 qemu_log("SO_BROADCAST,");
fb3aabf3
LV
2751 goto print_optint;
2752 case TARGET_SO_SNDBUF:
4b25a506 2753 qemu_log("SO_SNDBUF,");
fb3aabf3
LV
2754 goto print_optint;
2755 case TARGET_SO_RCVBUF:
4b25a506 2756 qemu_log("SO_RCVBUF,");
fb3aabf3
LV
2757 goto print_optint;
2758 case TARGET_SO_KEEPALIVE:
4b25a506 2759 qemu_log("SO_KEEPALIVE,");
fb3aabf3
LV
2760 goto print_optint;
2761 case TARGET_SO_OOBINLINE:
4b25a506 2762 qemu_log("SO_OOBINLINE,");
fb3aabf3
LV
2763 goto print_optint;
2764 case TARGET_SO_NO_CHECK:
4b25a506 2765 qemu_log("SO_NO_CHECK,");
fb3aabf3
LV
2766 goto print_optint;
2767 case TARGET_SO_PRIORITY:
4b25a506 2768 qemu_log("SO_PRIORITY,");
fb3aabf3
LV
2769 goto print_optint;
2770 case TARGET_SO_BSDCOMPAT:
4b25a506 2771 qemu_log("SO_BSDCOMPAT,");
fb3aabf3
LV
2772 goto print_optint;
2773 case TARGET_SO_PASSCRED:
4b25a506 2774 qemu_log("SO_PASSCRED,");
fb3aabf3
LV
2775 goto print_optint;
2776 case TARGET_SO_TIMESTAMP:
4b25a506 2777 qemu_log("SO_TIMESTAMP,");
fb3aabf3
LV
2778 goto print_optint;
2779 case TARGET_SO_RCVLOWAT:
4b25a506 2780 qemu_log("SO_RCVLOWAT,");
fb3aabf3
LV
2781 goto print_optint;
2782 case TARGET_SO_RCVTIMEO:
4b25a506 2783 qemu_log("SO_RCVTIMEO,");
fb3aabf3
LV
2784 print_timeval(optval, 0);
2785 break;
2786 case TARGET_SO_SNDTIMEO:
4b25a506 2787 qemu_log("SO_SNDTIMEO,");
fb3aabf3
LV
2788 print_timeval(optval, 0);
2789 break;
2790 case TARGET_SO_ATTACH_FILTER: {
2791 struct target_sock_fprog *fprog;
2792
4b25a506 2793 qemu_log("SO_ATTACH_FILTER,");
fb3aabf3
LV
2794
2795 if (lock_user_struct(VERIFY_READ, fprog, optval, 0)) {
2796 struct target_sock_filter *filter;
4b25a506 2797 qemu_log("{");
fb3aabf3
LV
2798 if (lock_user_struct(VERIFY_READ, filter,
2799 tswapal(fprog->filter), 0)) {
2800 int i;
2801 for (i = 0; i < tswap16(fprog->len) - 1; i++) {
4b25a506 2802 qemu_log("[%d]{0x%x,%d,%d,0x%x},",
fb3aabf3
LV
2803 i, tswap16(filter[i].code),
2804 filter[i].jt, filter[i].jf,
2805 tswap32(filter[i].k));
2806 }
4b25a506 2807 qemu_log("[%d]{0x%x,%d,%d,0x%x}",
fb3aabf3
LV
2808 i, tswap16(filter[i].code),
2809 filter[i].jt, filter[i].jf,
2810 tswap32(filter[i].k));
2811 } else {
4b25a506 2812 qemu_log(TARGET_ABI_FMT_lx, tswapal(fprog->filter));
fb3aabf3 2813 }
4b25a506 2814 qemu_log(",%d},", tswap16(fprog->len));
fb3aabf3
LV
2815 unlock_user(fprog, optval, 0);
2816 } else {
2817 print_pointer(optval, 0);
2818 }
2819 break;
2820 }
2821 default:
2822 print_raw_param(TARGET_ABI_FMT_ld, optname, 0);
2823 print_pointer(optval, 0);
2824 break;
2825 }
2826 break;
38987eab
SCW
2827 case SOL_IPV6:
2828 qemu_log("SOL_IPV6,");
2829 switch (optname) {
2830 case IPV6_MTU_DISCOVER:
2831 qemu_log("IPV6_MTU_DISCOVER,");
2832 goto print_optint;
2833 case IPV6_MTU:
2834 qemu_log("IPV6_MTU,");
2835 goto print_optint;
2836 case IPV6_V6ONLY:
2837 qemu_log("IPV6_V6ONLY,");
2838 goto print_optint;
2839 case IPV6_RECVPKTINFO:
2840 qemu_log("IPV6_RECVPKTINFO,");
2841 goto print_optint;
2842 case IPV6_UNICAST_HOPS:
2843 qemu_log("IPV6_UNICAST_HOPS,");
2844 goto print_optint;
2845 case IPV6_MULTICAST_HOPS:
2846 qemu_log("IPV6_MULTICAST_HOPS,");
2847 goto print_optint;
2848 case IPV6_MULTICAST_LOOP:
2849 qemu_log("IPV6_MULTICAST_LOOP,");
2850 goto print_optint;
2851 case IPV6_RECVERR:
2852 qemu_log("IPV6_RECVERR,");
2853 goto print_optint;
2854 case IPV6_RECVHOPLIMIT:
2855 qemu_log("IPV6_RECVHOPLIMIT,");
2856 goto print_optint;
2857 case IPV6_2292HOPLIMIT:
2858 qemu_log("IPV6_2292HOPLIMIT,");
2859 goto print_optint;
2860 case IPV6_CHECKSUM:
2861 qemu_log("IPV6_CHECKSUM,");
2862 goto print_optint;
2863 case IPV6_ADDRFORM:
2864 qemu_log("IPV6_ADDRFORM,");
2865 goto print_optint;
2866 case IPV6_2292PKTINFO:
2867 qemu_log("IPV6_2292PKTINFO,");
2868 goto print_optint;
2869 case IPV6_RECVTCLASS:
2870 qemu_log("IPV6_RECVTCLASS,");
2871 goto print_optint;
2872 case IPV6_RECVRTHDR:
2873 qemu_log("IPV6_RECVRTHDR,");
2874 goto print_optint;
2875 case IPV6_2292RTHDR:
2876 qemu_log("IPV6_2292RTHDR,");
2877 goto print_optint;
2878 case IPV6_RECVHOPOPTS:
2879 qemu_log("IPV6_RECVHOPOPTS,");
2880 goto print_optint;
2881 case IPV6_2292HOPOPTS:
2882 qemu_log("IPV6_2292HOPOPTS,");
2883 goto print_optint;
2884 case IPV6_RECVDSTOPTS:
2885 qemu_log("IPV6_RECVDSTOPTS,");
2886 goto print_optint;
2887 case IPV6_2292DSTOPTS:
2888 qemu_log("IPV6_2292DSTOPTS,");
2889 goto print_optint;
2890 case IPV6_TCLASS:
2891 qemu_log("IPV6_TCLASS,");
2892 goto print_optint;
2893 case IPV6_ADDR_PREFERENCES:
2894 qemu_log("IPV6_ADDR_PREFERENCES,");
2895 goto print_optint;
2896#ifdef IPV6_RECVPATHMTU
2897 case IPV6_RECVPATHMTU:
2898 qemu_log("IPV6_RECVPATHMTU,");
2899 goto print_optint;
2900#endif
2901#ifdef IPV6_TRANSPARENT
2902 case IPV6_TRANSPARENT:
2903 qemu_log("IPV6_TRANSPARENT,");
2904 goto print_optint;
2905#endif
2906#ifdef IPV6_FREEBIND
2907 case IPV6_FREEBIND:
2908 qemu_log("IPV6_FREEBIND,");
2909 goto print_optint;
2910#endif
2911#ifdef IPV6_RECVORIGDSTADDR
2912 case IPV6_RECVORIGDSTADDR:
2913 qemu_log("IPV6_RECVORIGDSTADDR,");
2914 goto print_optint;
2915#endif
2916 case IPV6_PKTINFO:
2917 qemu_log("IPV6_PKTINFO,");
2918 print_pointer(optval, 0);
2919 break;
2920 case IPV6_ADD_MEMBERSHIP:
2921 qemu_log("IPV6_ADD_MEMBERSHIP,");
2922 print_pointer(optval, 0);
2923 break;
2924 case IPV6_DROP_MEMBERSHIP:
2925 qemu_log("IPV6_DROP_MEMBERSHIP,");
2926 print_pointer(optval, 0);
2927 break;
2928 default:
2929 print_raw_param(TARGET_ABI_FMT_ld, optname, 0);
2930 print_pointer(optval, 0);
2931 break;
2932 }
2933 break;
fb3aabf3
LV
2934 default:
2935 print_raw_param(TARGET_ABI_FMT_ld, level, 0);
2936 print_raw_param(TARGET_ABI_FMT_ld, optname, 0);
2937 print_pointer(optval, 0);
2938 break;
2939 }
2940 print_raw_param(TARGET_ABI_FMT_ld, optlen, 1);
4b25a506 2941 qemu_log(")");
fb3aabf3
LV
2942}
2943
2944#define PRINT_SOCKOP(name, func) \
ff71a454 2945 [TARGET_SYS_##name] = { #name, func }
fb3aabf3
LV
2946
2947static struct {
2948 const char *name;
2949 void (*print)(const char *, abi_long);
2950} scall[] = {
ff71a454
AM
2951 PRINT_SOCKOP(SOCKET, do_print_socket),
2952 PRINT_SOCKOP(BIND, do_print_sockaddr),
2953 PRINT_SOCKOP(CONNECT, do_print_sockaddr),
2954 PRINT_SOCKOP(LISTEN, do_print_listen),
2955 PRINT_SOCKOP(ACCEPT, do_print_sockaddr),
2956 PRINT_SOCKOP(GETSOCKNAME, do_print_sockaddr),
2957 PRINT_SOCKOP(GETPEERNAME, do_print_sockaddr),
2958 PRINT_SOCKOP(SOCKETPAIR, do_print_socketpair),
2959 PRINT_SOCKOP(SEND, do_print_sendrecv),
2960 PRINT_SOCKOP(RECV, do_print_sendrecv),
2961 PRINT_SOCKOP(SENDTO, do_print_msgaddr),
2962 PRINT_SOCKOP(RECVFROM, do_print_msgaddr),
2963 PRINT_SOCKOP(SHUTDOWN, do_print_shutdown),
2964 PRINT_SOCKOP(SETSOCKOPT, do_print_sockopt),
2965 PRINT_SOCKOP(GETSOCKOPT, do_print_sockopt),
2966 PRINT_SOCKOP(SENDMSG, do_print_msg),
2967 PRINT_SOCKOP(RECVMSG, do_print_msg),
2968 PRINT_SOCKOP(ACCEPT4, NULL),
2969 PRINT_SOCKOP(RECVMMSG, NULL),
2970 PRINT_SOCKOP(SENDMMSG, NULL),
fb3aabf3
LV
2971};
2972
2973static void
a0939b89 2974print_socketcall(CPUArchState *cpu_env, const struct syscallname *name,
fb3aabf3
LV
2975 abi_long arg0, abi_long arg1, abi_long arg2,
2976 abi_long arg3, abi_long arg4, abi_long arg5)
2977{
2978 if (arg0 >= 0 && arg0 < ARRAY_SIZE(scall) && scall[arg0].print) {
2979 scall[arg0].print(scall[arg0].name, arg1);
2980 return;
2981 }
2982 print_syscall_prologue(name);
2983 print_raw_param(TARGET_ABI_FMT_ld, arg0, 0);
2984 print_raw_param(TARGET_ABI_FMT_ld, arg1, 0);
2985 print_raw_param(TARGET_ABI_FMT_ld, arg2, 0);
2986 print_raw_param(TARGET_ABI_FMT_ld, arg3, 0);
2987 print_raw_param(TARGET_ABI_FMT_ld, arg4, 0);
2988 print_raw_param(TARGET_ABI_FMT_ld, arg5, 0);
2989 print_syscall_epilogue(name);
2990}
2991#endif
2992
bb10540e
PMD
2993#if defined(TARGET_NR_bind)
2994static void
a0939b89 2995print_bind(CPUArchState *cpu_env, const struct syscallname *name,
bb10540e
PMD
2996 abi_long arg0, abi_long arg1, abi_long arg2,
2997 abi_long arg3, abi_long arg4, abi_long arg5)
2998{
2999 print_syscall_prologue(name);
3000 print_sockfd(arg0, 0);
3001 print_sockaddr(arg1, arg2, 1);
3002 print_syscall_epilogue(name);
3003}
3004#endif
3005
74d753ac
MW
3006#if defined(TARGET_NR_stat) || defined(TARGET_NR_stat64) || \
3007 defined(TARGET_NR_lstat) || defined(TARGET_NR_lstat64)
3008static void
a0939b89 3009print_stat(CPUArchState *cpu_env, const struct syscallname *name,
e400e119
FB
3010 abi_long arg0, abi_long arg1, abi_long arg2,
3011 abi_long arg3, abi_long arg4, abi_long arg5)
74d753ac
MW
3012{
3013 print_syscall_prologue(name);
3014 print_string(arg0, 0);
3015 print_pointer(arg1, 1);
3016 print_syscall_epilogue(name);
3017}
3018#define print_lstat print_stat
3019#define print_stat64 print_stat
3020#define print_lstat64 print_stat
3021#endif
3022
375ce49b
IL
3023#if defined(TARGET_NR_madvise)
3024static struct enums madvise_advice[] = {
3025 ENUM_TARGET(MADV_NORMAL),
3026 ENUM_TARGET(MADV_RANDOM),
3027 ENUM_TARGET(MADV_SEQUENTIAL),
3028 ENUM_TARGET(MADV_WILLNEED),
3029 ENUM_TARGET(MADV_DONTNEED),
3030 ENUM_TARGET(MADV_FREE),
3031 ENUM_TARGET(MADV_REMOVE),
3032 ENUM_TARGET(MADV_DONTFORK),
3033 ENUM_TARGET(MADV_DOFORK),
3034 ENUM_TARGET(MADV_MERGEABLE),
3035 ENUM_TARGET(MADV_UNMERGEABLE),
3036 ENUM_TARGET(MADV_HUGEPAGE),
3037 ENUM_TARGET(MADV_NOHUGEPAGE),
3038 ENUM_TARGET(MADV_DONTDUMP),
3039 ENUM_TARGET(MADV_DODUMP),
3040 ENUM_TARGET(MADV_WIPEONFORK),
3041 ENUM_TARGET(MADV_KEEPONFORK),
3042 ENUM_TARGET(MADV_COLD),
3043 ENUM_TARGET(MADV_PAGEOUT),
3044 ENUM_TARGET(MADV_POPULATE_READ),
3045 ENUM_TARGET(MADV_POPULATE_WRITE),
3046 ENUM_TARGET(MADV_DONTNEED_LOCKED),
3047 ENUM_END,
3048};
3049
3050static void
3051print_madvise(CPUArchState *cpu_env, const struct syscallname *name,
3052 abi_long arg0, abi_long arg1, abi_long arg2,
3053 abi_long arg3, abi_long arg4, abi_long arg5)
3054{
3055 print_syscall_prologue(name);
3056 print_pointer(arg0, 0);
3057 print_raw_param("%d", arg1, 0);
3058 print_enums(madvise_advice, arg2, 1);
3059 print_syscall_epilogue(name);
3060}
3061#endif
3062
74d753ac
MW
3063#if defined(TARGET_NR_fstat) || defined(TARGET_NR_fstat64)
3064static void
a0939b89 3065print_fstat(CPUArchState *cpu_env, const struct syscallname *name,
e400e119
FB
3066 abi_long arg0, abi_long arg1, abi_long arg2,
3067 abi_long arg3, abi_long arg4, abi_long arg5)
74d753ac
MW
3068{
3069 print_syscall_prologue(name);
d2ee72a5 3070 print_raw_param("%d", arg0, 0);
74d753ac
MW
3071 print_pointer(arg1, 1);
3072 print_syscall_epilogue(name);
3073}
3074#define print_fstat64 print_fstat
3075#endif
3076
3077#ifdef TARGET_NR_mkdir
3078static void
a0939b89 3079print_mkdir(CPUArchState *cpu_env, const struct syscallname *name,
e400e119
FB
3080 abi_long arg0, abi_long arg1, abi_long arg2,
3081 abi_long arg3, abi_long arg4, abi_long arg5)
74d753ac
MW
3082{
3083 print_syscall_prologue(name);
3084 print_string(arg0, 0);
3085 print_file_mode(arg1, 1);
3086 print_syscall_epilogue(name);
3087}
3088#endif
3089
3090#ifdef TARGET_NR_mkdirat
3091static void
a0939b89 3092print_mkdirat(CPUArchState *cpu_env, const struct syscallname *name,
e400e119
FB
3093 abi_long arg0, abi_long arg1, abi_long arg2,
3094 abi_long arg3, abi_long arg4, abi_long arg5)
74d753ac
MW
3095{
3096 print_syscall_prologue(name);
3097 print_at_dirfd(arg0, 0);
3098 print_string(arg1, 0);
3099 print_file_mode(arg2, 1);
3100 print_syscall_epilogue(name);
3101}
3102#endif
3103
4de596cb
LV
3104#ifdef TARGET_NR_rmdir
3105static void
a0939b89 3106print_rmdir(CPUArchState *cpu_env, const struct syscallname *name,
e400e119
FB
3107 abi_long arg0, abi_long arg1, abi_long arg2,
3108 abi_long arg3, abi_long arg4, abi_long arg5)
4de596cb
LV
3109{
3110 print_syscall_prologue(name);
3111 print_string(arg0, 0);
3112 print_syscall_epilogue(name);
3113}
3114#endif
3115
608e5592
LV
3116#ifdef TARGET_NR_rt_sigaction
3117static void
a0939b89 3118print_rt_sigaction(CPUArchState *cpu_env, const struct syscallname *name,
e400e119
FB
3119 abi_long arg0, abi_long arg1, abi_long arg2,
3120 abi_long arg3, abi_long arg4, abi_long arg5)
608e5592
LV
3121{
3122 print_syscall_prologue(name);
3123 print_signal(arg0, 0);
3124 print_pointer(arg1, 0);
3125 print_pointer(arg2, 1);
3126 print_syscall_epilogue(name);
3127}
3128#endif
3129
3130#ifdef TARGET_NR_rt_sigprocmask
3131static void
a0939b89 3132print_rt_sigprocmask(CPUArchState *cpu_env, const struct syscallname *name,
e400e119
FB
3133 abi_long arg0, abi_long arg1, abi_long arg2,
3134 abi_long arg3, abi_long arg4, abi_long arg5)
608e5592
LV
3135{
3136 const char *how = "UNKNOWN";
3137 print_syscall_prologue(name);
3138 switch(arg0) {
3139 case TARGET_SIG_BLOCK: how = "SIG_BLOCK"; break;
3140 case TARGET_SIG_UNBLOCK: how = "SIG_UNBLOCK"; break;
3141 case TARGET_SIG_SETMASK: how = "SIG_SETMASK"; break;
3142 }
4b25a506 3143 qemu_log("%s,", how);
608e5592
LV
3144 print_pointer(arg1, 0);
3145 print_pointer(arg2, 1);
3146 print_syscall_epilogue(name);
3147}
3148#endif
3149
5162264e
MS
3150#ifdef TARGET_NR_rt_sigqueueinfo
3151static void
a0939b89 3152print_rt_sigqueueinfo(CPUArchState *cpu_env, const struct syscallname *name,
e400e119
FB
3153 abi_long arg0, abi_long arg1, abi_long arg2,
3154 abi_long arg3, abi_long arg4, abi_long arg5)
5162264e 3155{
ba9fcea1
MS
3156 void *p;
3157 target_siginfo_t uinfo;
3158
5162264e
MS
3159 print_syscall_prologue(name);
3160 print_raw_param("%d", arg0, 0);
3161 print_signal(arg1, 0);
ba9fcea1
MS
3162 p = lock_user(VERIFY_READ, arg2, sizeof(target_siginfo_t), 1);
3163 if (p) {
3164 get_target_siginfo(&uinfo, p);
3165 print_siginfo(&uinfo);
3166
3167 unlock_user(p, arg2, 0);
3168 } else {
3169 print_pointer(arg2, 1);
3170 }
5162264e
MS
3171 print_syscall_epilogue(name);
3172}
3173#endif
3174
243e0fe5
MS
3175#ifdef TARGET_NR_rt_tgsigqueueinfo
3176static void
a0939b89 3177print_rt_tgsigqueueinfo(CPUArchState *cpu_env, const struct syscallname *name,
e400e119
FB
3178 abi_long arg0, abi_long arg1, abi_long arg2,
3179 abi_long arg3, abi_long arg4, abi_long arg5)
243e0fe5 3180{
ba9fcea1
MS
3181 void *p;
3182 target_siginfo_t uinfo;
3183
243e0fe5
MS
3184 print_syscall_prologue(name);
3185 print_raw_param("%d", arg0, 0);
3186 print_raw_param("%d", arg1, 0);
3187 print_signal(arg2, 0);
ba9fcea1
MS
3188 p = lock_user(VERIFY_READ, arg3, sizeof(target_siginfo_t), 1);
3189 if (p) {
3190 get_target_siginfo(&uinfo, p);
3191 print_siginfo(&uinfo);
3192
3193 unlock_user(p, arg3, 0);
3194 } else {
3195 print_pointer(arg3, 1);
3196 }
243e0fe5
MS
3197 print_syscall_epilogue(name);
3198}
3199#endif
3200
da2c8ad7
AM
3201#ifdef TARGET_NR_syslog
3202static void
3203print_syslog_action(abi_ulong arg, int last)
3204{
3205 const char *type;
3206
3207 switch (arg) {
3208 case TARGET_SYSLOG_ACTION_CLOSE: {
3209 type = "SYSLOG_ACTION_CLOSE";
3210 break;
3211 }
3212 case TARGET_SYSLOG_ACTION_OPEN: {
3213 type = "SYSLOG_ACTION_OPEN";
3214 break;
3215 }
3216 case TARGET_SYSLOG_ACTION_READ: {
3217 type = "SYSLOG_ACTION_READ";
3218 break;
3219 }
3220 case TARGET_SYSLOG_ACTION_READ_ALL: {
3221 type = "SYSLOG_ACTION_READ_ALL";
3222 break;
3223 }
3224 case TARGET_SYSLOG_ACTION_READ_CLEAR: {
3225 type = "SYSLOG_ACTION_READ_CLEAR";
3226 break;
3227 }
3228 case TARGET_SYSLOG_ACTION_CLEAR: {
3229 type = "SYSLOG_ACTION_CLEAR";
3230 break;
3231 }
3232 case TARGET_SYSLOG_ACTION_CONSOLE_OFF: {
3233 type = "SYSLOG_ACTION_CONSOLE_OFF";
3234 break;
3235 }
3236 case TARGET_SYSLOG_ACTION_CONSOLE_ON: {
3237 type = "SYSLOG_ACTION_CONSOLE_ON";
3238 break;
3239 }
3240 case TARGET_SYSLOG_ACTION_CONSOLE_LEVEL: {
3241 type = "SYSLOG_ACTION_CONSOLE_LEVEL";
3242 break;
3243 }
3244 case TARGET_SYSLOG_ACTION_SIZE_UNREAD: {
3245 type = "SYSLOG_ACTION_SIZE_UNREAD";
3246 break;
3247 }
3248 case TARGET_SYSLOG_ACTION_SIZE_BUFFER: {
3249 type = "SYSLOG_ACTION_SIZE_BUFFER";
3250 break;
3251 }
3252 default: {
3253 print_raw_param("%ld", arg, last);
3254 return;
3255 }
3256 }
4b25a506 3257 qemu_log("%s%s", type, get_comma(last));
da2c8ad7
AM
3258}
3259
3260static void
a0939b89 3261print_syslog(CPUArchState *cpu_env, const struct syscallname *name,
e400e119
FB
3262 abi_long arg0, abi_long arg1, abi_long arg2,
3263 abi_long arg3, abi_long arg4, abi_long arg5)
da2c8ad7
AM
3264{
3265 print_syscall_prologue(name);
3266 print_syslog_action(arg0, 0);
3267 print_pointer(arg1, 0);
3268 print_raw_param("%d", arg2, 1);
3269 print_syscall_epilogue(name);
3270}
3271#endif
3272
74d753ac
MW
3273#ifdef TARGET_NR_mknod
3274static void
a0939b89 3275print_mknod(CPUArchState *cpu_env, const struct syscallname *name,
e400e119
FB
3276 abi_long arg0, abi_long arg1, abi_long arg2,
3277 abi_long arg3, abi_long arg4, abi_long arg5)
74d753ac 3278{
d2ee72a5 3279 int hasdev = (arg1 & (S_IFCHR|S_IFBLK));
74d753ac
MW
3280
3281 print_syscall_prologue(name);
3282 print_string(arg0, 0);
3283 print_file_mode(arg1, (hasdev == 0));
3284 if (hasdev) {
d2ee72a5
LV
3285 print_raw_param("makedev(%d", major(arg2), 0);
3286 print_raw_param("%d)", minor(arg2), 1);
74d753ac
MW
3287 }
3288 print_syscall_epilogue(name);
3289}
3290#endif
3291
3292#ifdef TARGET_NR_mknodat
3293static void
a0939b89 3294print_mknodat(CPUArchState *cpu_env, const struct syscallname *name,
e400e119
FB
3295 abi_long arg0, abi_long arg1, abi_long arg2,
3296 abi_long arg3, abi_long arg4, abi_long arg5)
74d753ac 3297{
d2ee72a5 3298 int hasdev = (arg2 & (S_IFCHR|S_IFBLK));
74d753ac
MW
3299
3300 print_syscall_prologue(name);
3301 print_at_dirfd(arg0, 0);
3302 print_string(arg1, 0);
3303 print_file_mode(arg2, (hasdev == 0));
3304 if (hasdev) {
d2ee72a5
LV
3305 print_raw_param("makedev(%d", major(arg3), 0);
3306 print_raw_param("%d)", minor(arg3), 1);
74d753ac
MW
3307 }
3308 print_syscall_epilogue(name);
3309}
3310#endif
3311
3312#ifdef TARGET_NR_mq_open
3313static void
a0939b89 3314print_mq_open(CPUArchState *cpu_env, const struct syscallname *name,
e400e119
FB
3315 abi_long arg0, abi_long arg1, abi_long arg2,
3316 abi_long arg3, abi_long arg4, abi_long arg5)
74d753ac 3317{
d2ee72a5 3318 int is_creat = (arg1 & TARGET_O_CREAT);
74d753ac
MW
3319
3320 print_syscall_prologue(name);
3321 print_string(arg0, 0);
3322 print_open_flags(arg1, (is_creat == 0));
3323 if (is_creat) {
3324 print_file_mode(arg2, 0);
3325 print_pointer(arg3, 1);
3326 }
3327 print_syscall_epilogue(name);
3328}
3329#endif
3330
3331#ifdef TARGET_NR_open
3332static void
a0939b89 3333print_open(CPUArchState *cpu_env, const struct syscallname *name,
e400e119
FB
3334 abi_long arg0, abi_long arg1, abi_long arg2,
3335 abi_long arg3, abi_long arg4, abi_long arg5)
74d753ac 3336{
d2ee72a5 3337 int is_creat = (arg1 & TARGET_O_CREAT);
74d753ac
MW
3338
3339 print_syscall_prologue(name);
3340 print_string(arg0, 0);
3341 print_open_flags(arg1, (is_creat == 0));
3342 if (is_creat)
3343 print_file_mode(arg2, 1);
3344 print_syscall_epilogue(name);
3345}
3346#endif
3347
3348#ifdef TARGET_NR_openat
3349static void
a0939b89 3350print_openat(CPUArchState *cpu_env, const struct syscallname *name,
e400e119
FB
3351 abi_long arg0, abi_long arg1, abi_long arg2,
3352 abi_long arg3, abi_long arg4, abi_long arg5)
74d753ac 3353{
d2ee72a5 3354 int is_creat = (arg2 & TARGET_O_CREAT);
74d753ac
MW
3355
3356 print_syscall_prologue(name);
3357 print_at_dirfd(arg0, 0);
3358 print_string(arg1, 0);
3359 print_open_flags(arg2, (is_creat == 0));
3360 if (is_creat)
3361 print_file_mode(arg3, 1);
3362 print_syscall_epilogue(name);
3363}
3364#endif
3365
cc054c6f
HD
3366#ifdef TARGET_NR_pidfd_send_signal
3367static void
3368print_pidfd_send_signal(CPUArchState *cpu_env, const struct syscallname *name,
3369 abi_long arg0, abi_long arg1, abi_long arg2,
3370 abi_long arg3, abi_long arg4, abi_long arg5)
3371{
3372 void *p;
3373 target_siginfo_t uinfo;
3374
3375 print_syscall_prologue(name);
3376 print_raw_param("%d", arg0, 0);
3377 print_signal(arg1, 0);
3378
3379 p = lock_user(VERIFY_READ, arg2, sizeof(target_siginfo_t), 1);
3380 if (p) {
3381 get_target_siginfo(&uinfo, p);
3382 print_siginfo(&uinfo);
3383
3384 unlock_user(p, arg2, 0);
3385 } else {
46187d70 3386 print_pointer(arg2, 0);
cc054c6f
HD
3387 }
3388
46187d70 3389 print_raw_param("%u", arg3, 1);
cc054c6f
HD
3390 print_syscall_epilogue(name);
3391}
3392#endif
3393
74d753ac
MW
3394#ifdef TARGET_NR_mq_unlink
3395static void
a0939b89 3396print_mq_unlink(CPUArchState *cpu_env, const struct syscallname *name,
e400e119
FB
3397 abi_long arg0, abi_long arg1, abi_long arg2,
3398 abi_long arg3, abi_long arg4, abi_long arg5)
74d753ac
MW
3399{
3400 print_syscall_prologue(name);
3401 print_string(arg0, 1);
3402 print_syscall_epilogue(name);
3403}
3404#endif
3405
3406#if defined(TARGET_NR_fstatat64) || defined(TARGET_NR_newfstatat)
3407static void
a0939b89 3408print_fstatat64(CPUArchState *cpu_env, const struct syscallname *name,
e400e119
FB
3409 abi_long arg0, abi_long arg1, abi_long arg2,
3410 abi_long arg3, abi_long arg4, abi_long arg5)
74d753ac
MW
3411{
3412 print_syscall_prologue(name);
3413 print_at_dirfd(arg0, 0);
3414 print_string(arg1, 0);
3415 print_pointer(arg2, 0);
3416 print_flags(at_file_flags, arg3, 1);
3417 print_syscall_epilogue(name);
3418}
3419#define print_newfstatat print_fstatat64
3420#endif
3421
3422#ifdef TARGET_NR_readlink
3423static void
a0939b89 3424print_readlink(CPUArchState *cpu_env, const struct syscallname *name,
e400e119
FB
3425 abi_long arg0, abi_long arg1, abi_long arg2,
3426 abi_long arg3, abi_long arg4, abi_long arg5)
74d753ac
MW
3427{
3428 print_syscall_prologue(name);
3429 print_string(arg0, 0);
3430 print_pointer(arg1, 0);
d2ee72a5 3431 print_raw_param("%u", arg2, 1);
74d753ac
MW
3432 print_syscall_epilogue(name);
3433}
3434#endif
3435
3436#ifdef TARGET_NR_readlinkat
3437static void
a0939b89 3438print_readlinkat(CPUArchState *cpu_env, const struct syscallname *name,
e400e119
FB
3439 abi_long arg0, abi_long arg1, abi_long arg2,
3440 abi_long arg3, abi_long arg4, abi_long arg5)
74d753ac
MW
3441{
3442 print_syscall_prologue(name);
3443 print_at_dirfd(arg0, 0);
3444 print_string(arg1, 0);
3445 print_pointer(arg2, 0);
d2ee72a5 3446 print_raw_param("%u", arg3, 1);
74d753ac
MW
3447 print_syscall_epilogue(name);
3448}
3449#endif
3450
3451#ifdef TARGET_NR_rename
3452static void
a0939b89 3453print_rename(CPUArchState *cpu_env, const struct syscallname *name,
e400e119
FB
3454 abi_long arg0, abi_long arg1, abi_long arg2,
3455 abi_long arg3, abi_long arg4, abi_long arg5)
74d753ac
MW
3456{
3457 print_syscall_prologue(name);
3458 print_string(arg0, 0);
3459 print_string(arg1, 1);
3460 print_syscall_epilogue(name);
3461}
3462#endif
3463
3464#ifdef TARGET_NR_renameat
3465static void
a0939b89 3466print_renameat(CPUArchState *cpu_env, const struct syscallname *name,
e400e119
FB
3467 abi_long arg0, abi_long arg1, abi_long arg2,
3468 abi_long arg3, abi_long arg4, abi_long arg5)
74d753ac
MW
3469{
3470 print_syscall_prologue(name);
3471 print_at_dirfd(arg0, 0);
3472 print_string(arg1, 0);
3473 print_at_dirfd(arg2, 0);
3474 print_string(arg3, 1);
3475 print_syscall_epilogue(name);
3476}
3477#endif
3478
3479#ifdef TARGET_NR_statfs
3480static void
a0939b89 3481print_statfs(CPUArchState *cpu_env, const struct syscallname *name,
e400e119
FB
3482 abi_long arg0, abi_long arg1, abi_long arg2,
3483 abi_long arg3, abi_long arg4, abi_long arg5)
74d753ac
MW
3484{
3485 print_syscall_prologue(name);
3486 print_string(arg0, 0);
3487 print_pointer(arg1, 1);
3488 print_syscall_epilogue(name);
3489}
4f7f8924
AR
3490#endif
3491
3492#ifdef TARGET_NR_statfs64
3493static void
a0939b89 3494print_statfs64(CPUArchState *cpu_env, const struct syscallname *name,
e400e119
FB
3495 abi_long arg0, abi_long arg1, abi_long arg2,
3496 abi_long arg3, abi_long arg4, abi_long arg5)
4f7f8924
AR
3497{
3498 print_syscall_prologue(name);
3499 print_string(arg0, 0);
3500 print_pointer(arg1, 1);
3501 print_syscall_epilogue(name);
3502}
74d753ac
MW
3503#endif
3504
3505#ifdef TARGET_NR_symlink
3506static void
a0939b89 3507print_symlink(CPUArchState *cpu_env, const struct syscallname *name,
e400e119
FB
3508 abi_long arg0, abi_long arg1, abi_long arg2,
3509 abi_long arg3, abi_long arg4, abi_long arg5)
74d753ac
MW
3510{
3511 print_syscall_prologue(name);
3512 print_string(arg0, 0);
3513 print_string(arg1, 1);
3514 print_syscall_epilogue(name);
3515}
3516#endif
3517
3518#ifdef TARGET_NR_symlinkat
3519static void
a0939b89 3520print_symlinkat(CPUArchState *cpu_env, const struct syscallname *name,
e400e119
FB
3521 abi_long arg0, abi_long arg1, abi_long arg2,
3522 abi_long arg3, abi_long arg4, abi_long arg5)
74d753ac
MW
3523{
3524 print_syscall_prologue(name);
3525 print_string(arg0, 0);
3526 print_at_dirfd(arg1, 0);
3527 print_string(arg2, 1);
3528 print_syscall_epilogue(name);
3529}
3530#endif
3531
3532#ifdef TARGET_NR_mount
3533static void
a0939b89 3534print_mount(CPUArchState *cpu_env, const struct syscallname *name,
e400e119
FB
3535 abi_long arg0, abi_long arg1, abi_long arg2,
3536 abi_long arg3, abi_long arg4, abi_long arg5)
74d753ac
MW
3537{
3538 print_syscall_prologue(name);
3539 print_string(arg0, 0);
3540 print_string(arg1, 0);
3541 print_string(arg2, 0);
3542 print_flags(mount_flags, arg3, 0);
3543 print_pointer(arg4, 1);
3544 print_syscall_epilogue(name);
3545}
3546#endif
3547
3548#ifdef TARGET_NR_umount
3549static void
a0939b89 3550print_umount(CPUArchState *cpu_env, const struct syscallname *name,
e400e119
FB
3551 abi_long arg0, abi_long arg1, abi_long arg2,
3552 abi_long arg3, abi_long arg4, abi_long arg5)
74d753ac
MW
3553{
3554 print_syscall_prologue(name);
3555 print_string(arg0, 1);
3556 print_syscall_epilogue(name);
3557}
3558#endif
3559
3560#ifdef TARGET_NR_umount2
3561static void
a0939b89 3562print_umount2(CPUArchState *cpu_env, const struct syscallname *name,
e400e119
FB
3563 abi_long arg0, abi_long arg1, abi_long arg2,
3564 abi_long arg3, abi_long arg4, abi_long arg5)
74d753ac
MW
3565{
3566 print_syscall_prologue(name);
3567 print_string(arg0, 0);
3568 print_flags(umount2_flags, arg1, 1);
3569 print_syscall_epilogue(name);
3570}
3571#endif
3572
3573#ifdef TARGET_NR_unlink
3574static void
a0939b89 3575print_unlink(CPUArchState *cpu_env, const struct syscallname *name,
e400e119
FB
3576 abi_long arg0, abi_long arg1, abi_long arg2,
3577 abi_long arg3, abi_long arg4, abi_long arg5)
74d753ac
MW
3578{
3579 print_syscall_prologue(name);
3580 print_string(arg0, 1);
3581 print_syscall_epilogue(name);
3582}
3583#endif
3584
3585#ifdef TARGET_NR_unlinkat
3586static void
a0939b89 3587print_unlinkat(CPUArchState *cpu_env, const struct syscallname *name,
e400e119
FB
3588 abi_long arg0, abi_long arg1, abi_long arg2,
3589 abi_long arg3, abi_long arg4, abi_long arg5)
74d753ac
MW
3590{
3591 print_syscall_prologue(name);
3592 print_at_dirfd(arg0, 0);
3593 print_string(arg1, 0);
3594 print_flags(unlinkat_flags, arg2, 1);
3595 print_syscall_epilogue(name);
3596}
3597#endif
3598
5847d309
MK
3599#ifdef TARGET_NR_unshare
3600static void
a0939b89 3601print_unshare(CPUArchState *cpu_env, const struct syscallname *name,
5847d309
MK
3602 abi_long arg0, abi_long arg1, abi_long arg2,
3603 abi_long arg3, abi_long arg4, abi_long arg5)
3604{
3605 print_syscall_prologue(name);
3606 print_flags(clone_flags, arg0, 1);
3607 print_syscall_epilogue(name);
3608}
3609#endif
3610
05f3adc9
HD
3611#ifdef TARGET_NR_clock_nanosleep
3612static void
3613print_clock_nanosleep(CPUArchState *cpu_env, const struct syscallname *name,
3614 abi_long arg0, abi_long arg1, abi_long arg2,
3615 abi_long arg3, abi_long arg4, abi_long arg5)
3616{
3617 print_syscall_prologue(name);
3618 print_enums(clockids, arg0, 0);
3619 print_raw_param("%d", arg1, 0);
3620 print_timespec(arg2, 0);
3621 print_timespec(arg3, 1);
3622 print_syscall_epilogue(name);
3623}
3624#endif
3625
74d753ac
MW
3626#ifdef TARGET_NR_utime
3627static void
a0939b89 3628print_utime(CPUArchState *cpu_env, const struct syscallname *name,
e400e119
FB
3629 abi_long arg0, abi_long arg1, abi_long arg2,
3630 abi_long arg3, abi_long arg4, abi_long arg5)
74d753ac
MW
3631{
3632 print_syscall_prologue(name);
3633 print_string(arg0, 0);
3634 print_pointer(arg1, 1);
3635 print_syscall_epilogue(name);
3636}
3637#endif
3638
3639#ifdef TARGET_NR_utimes
3640static void
a0939b89 3641print_utimes(CPUArchState *cpu_env, const struct syscallname *name,
e400e119
FB
3642 abi_long arg0, abi_long arg1, abi_long arg2,
3643 abi_long arg3, abi_long arg4, abi_long arg5)
74d753ac
MW
3644{
3645 print_syscall_prologue(name);
3646 print_string(arg0, 0);
3647 print_pointer(arg1, 1);
3648 print_syscall_epilogue(name);
3649}
3650#endif
3651
3652#ifdef TARGET_NR_utimensat
3653static void
a0939b89 3654print_utimensat(CPUArchState *cpu_env, const struct syscallname *name,
e400e119
FB
3655 abi_long arg0, abi_long arg1, abi_long arg2,
3656 abi_long arg3, abi_long arg4, abi_long arg5)
74d753ac
MW
3657{
3658 print_syscall_prologue(name);
3659 print_at_dirfd(arg0, 0);
3660 print_string(arg1, 0);
3661 print_pointer(arg2, 0);
3662 print_flags(at_file_flags, arg3, 1);
3663 print_syscall_epilogue(name);
3664}
3665#endif
3666
8d9016c0 3667#if defined(TARGET_NR_mmap) || defined(TARGET_NR_mmap2)
74d753ac 3668static void
a0939b89 3669print_mmap(CPUArchState *cpu_env, const struct syscallname *name,
e400e119
FB
3670 abi_long arg0, abi_long arg1, abi_long arg2,
3671 abi_long arg3, abi_long arg4, abi_long arg5)
74d753ac
MW
3672{
3673 print_syscall_prologue(name);
3674 print_pointer(arg0, 0);
d2ee72a5 3675 print_raw_param("%d", arg1, 0);
74d753ac
MW
3676 print_flags(mmap_prot_flags, arg2, 0);
3677 print_flags(mmap_flags, arg3, 0);
d2ee72a5
LV
3678 print_raw_param("%d", arg4, 0);
3679 print_raw_param("%#x", arg5, 1);
74d753ac
MW
3680 print_syscall_epilogue(name);
3681}
3682#define print_mmap2 print_mmap
3683#endif
3684
3685#ifdef TARGET_NR_mprotect
3686static void
a0939b89 3687print_mprotect(CPUArchState *cpu_env, const struct syscallname *name,
e400e119
FB
3688 abi_long arg0, abi_long arg1, abi_long arg2,
3689 abi_long arg3, abi_long arg4, abi_long arg5)
74d753ac
MW
3690{
3691 print_syscall_prologue(name);
3692 print_pointer(arg0, 0);
d2ee72a5 3693 print_raw_param("%d", arg1, 0);
74d753ac
MW
3694 print_flags(mmap_prot_flags, arg2, 1);
3695 print_syscall_epilogue(name);
3696}
3697#endif
3698
3699#ifdef TARGET_NR_munmap
3700static void
a0939b89 3701print_munmap(CPUArchState *cpu_env, const struct syscallname *name,
e400e119
FB
3702 abi_long arg0, abi_long arg1, abi_long arg2,
3703 abi_long arg3, abi_long arg4, abi_long arg5)
74d753ac
MW
3704{
3705 print_syscall_prologue(name);
3706 print_pointer(arg0, 0);
d2ee72a5 3707 print_raw_param("%d", arg1, 1);
74d753ac
MW
3708 print_syscall_epilogue(name);
3709}
3710#endif
3711
3712#ifdef TARGET_NR_futex
53b578f3
RH
3713static void print_futex_op(int cmd, int last)
3714{
3715 static const char * const futex_names[] = {
3716#define NAME(X) [X] = #X
3717 NAME(FUTEX_WAIT),
3718 NAME(FUTEX_WAKE),
3719 NAME(FUTEX_FD),
3720 NAME(FUTEX_REQUEUE),
3721 NAME(FUTEX_CMP_REQUEUE),
3722 NAME(FUTEX_WAKE_OP),
3723 NAME(FUTEX_LOCK_PI),
3724 NAME(FUTEX_UNLOCK_PI),
3725 NAME(FUTEX_TRYLOCK_PI),
3726 NAME(FUTEX_WAIT_BITSET),
3727 NAME(FUTEX_WAKE_BITSET),
3728 NAME(FUTEX_WAIT_REQUEUE_PI),
3729 NAME(FUTEX_CMP_REQUEUE_PI),
3730 NAME(FUTEX_LOCK_PI2),
3731#undef NAME
3732 };
3733
3734 unsigned base_cmd = cmd & FUTEX_CMD_MASK;
3735
3736 if (base_cmd < ARRAY_SIZE(futex_names)) {
3737 qemu_log("%s%s%s",
3738 (cmd & FUTEX_PRIVATE_FLAG ? "FUTEX_PRIVATE_FLAG|" : ""),
3739 (cmd & FUTEX_CLOCK_REALTIME ? "FUTEX_CLOCK_REALTIME|" : ""),
3740 futex_names[base_cmd]);
3741 } else {
3742 qemu_log("0x%x", cmd);
bfb669f3 3743 }
74d753ac
MW
3744}
3745
3746static void
a0939b89 3747print_futex(CPUArchState *cpu_env, const struct syscallname *name,
e400e119
FB
3748 abi_long arg0, abi_long arg1, abi_long arg2,
3749 abi_long arg3, abi_long arg4, abi_long arg5)
74d753ac 3750{
811ee5cf 3751 abi_long op = arg1 & FUTEX_CMD_MASK;
74d753ac
MW
3752 print_syscall_prologue(name);
3753 print_pointer(arg0, 0);
3754 print_futex_op(arg1, 0);
d2ee72a5 3755 print_raw_param(",%d", arg2, 0);
811ee5cf
HD
3756 switch (op) {
3757 case FUTEX_WAIT:
3758 case FUTEX_WAIT_BITSET:
53b578f3
RH
3759 case FUTEX_LOCK_PI:
3760 case FUTEX_LOCK_PI2:
3761 case FUTEX_WAIT_REQUEUE_PI:
811ee5cf
HD
3762 print_timespec(arg3, 0);
3763 break;
3764 default:
3765 print_pointer(arg3, 0);
3766 break;
3767 }
74d753ac 3768 print_pointer(arg4, 0);
d2ee72a5 3769 print_raw_param("%d", arg4, 1);
74d753ac
MW
3770 print_syscall_epilogue(name);
3771}
3772#endif
3773
608e5592
LV
3774#ifdef TARGET_NR_kill
3775static void
a0939b89 3776print_kill(CPUArchState *cpu_env, const struct syscallname *name,
e400e119
FB
3777 abi_long arg0, abi_long arg1, abi_long arg2,
3778 abi_long arg3, abi_long arg4, abi_long arg5)
608e5592
LV
3779{
3780 print_syscall_prologue(name);
3781 print_raw_param("%d", arg0, 0);
3782 print_signal(arg1, 1);
3783 print_syscall_epilogue(name);
3784}
3785#endif
3786
5162264e
MS
3787#ifdef TARGET_NR_tkill
3788static void
a0939b89 3789print_tkill(CPUArchState *cpu_env, const struct syscallname *name,
e400e119
FB
3790 abi_long arg0, abi_long arg1, abi_long arg2,
3791 abi_long arg3, abi_long arg4, abi_long arg5)
5162264e
MS
3792{
3793 print_syscall_prologue(name);
3794 print_raw_param("%d", arg0, 0);
3795 print_signal(arg1, 1);
3796 print_syscall_epilogue(name);
3797}
3798#endif
3799
3800#ifdef TARGET_NR_tgkill
3801static void
a0939b89 3802print_tgkill(CPUArchState *cpu_env, const struct syscallname *name,
e400e119
FB
3803 abi_long arg0, abi_long arg1, abi_long arg2,
3804 abi_long arg3, abi_long arg4, abi_long arg5)
5162264e
MS
3805{
3806 print_syscall_prologue(name);
3807 print_raw_param("%d", arg0, 0);
3808 print_raw_param("%d", arg1, 0);
3809 print_signal(arg2, 1);
3810 print_syscall_epilogue(name);
3811}
3812#endif
3813
d42744fe
JW
3814#ifdef TARGET_NR_statx
3815static void
a0939b89 3816print_statx(CPUArchState *cpu_env, const struct syscallname *name,
d42744fe
JW
3817 abi_long arg0, abi_long arg1, abi_long arg2,
3818 abi_long arg3, abi_long arg4, abi_long arg5)
3819{
3820 print_syscall_prologue(name);
3821 print_at_dirfd(arg0, 0);
3822 print_string(arg1, 0);
3823 print_flags(statx_flags, arg2, 0);
3824 print_flags(statx_mask, arg3, 0);
3825 print_pointer(arg4, 1);
3826 print_syscall_epilogue(name);
3827}
3828#endif
3829
79482e59
FB
3830#ifdef TARGET_NR_ioctl
3831static void
a0939b89 3832print_ioctl(CPUArchState *cpu_env, const struct syscallname *name,
79482e59
FB
3833 abi_long arg0, abi_long arg1, abi_long arg2,
3834 abi_long arg3, abi_long arg4, abi_long arg5)
3835{
3836 print_syscall_prologue(name);
3837 print_raw_param("%d", arg0, 0);
3838
3839 const IOCTLEntry *ie;
3840 const argtype *arg_type;
3841 void *argptr;
3842 int target_size;
3843
3844 for (ie = ioctl_entries; ie->target_cmd != 0; ie++) {
3845 if (ie->target_cmd == arg1) {
3846 break;
3847 }
3848 }
3849
3850 if (ie->target_cmd == 0) {
3851 print_raw_param("%#x", arg1, 0);
3852 print_raw_param("%#x", arg2, 1);
3853 } else {
3854 qemu_log("%s", ie->name);
3855 arg_type = ie->arg_type;
3856
3857 if (arg_type[0] != TYPE_NULL) {
3858 qemu_log(",");
3859
3860 switch (arg_type[0]) {
3861 case TYPE_PTRVOID:
3862 print_pointer(arg2, 1);
3863 break;
3864 case TYPE_CHAR:
3865 case TYPE_SHORT:
3866 case TYPE_INT:
3867 print_raw_param("%d", arg2, 1);
3868 break;
3869 case TYPE_LONG:
3870 print_raw_param(TARGET_ABI_FMT_ld, arg2, 1);
3871 break;
3872 case TYPE_ULONG:
3873 print_raw_param(TARGET_ABI_FMT_lu, arg2, 1);
3874 break;
3875 case TYPE_PTR:
3876 switch (ie->access) {
3877 case IOC_R:
3878 print_pointer(arg2, 1);
3879 break;
3880 case IOC_W:
3881 case IOC_RW:
3882 arg_type++;
3883 target_size = thunk_type_size(arg_type, 0);
3884 argptr = lock_user(VERIFY_READ, arg2, target_size, 1);
4c1850c1
LV
3885 if (argptr) {
3886 thunk_print(argptr, arg_type);
3887 unlock_user(argptr, arg2, target_size);
3888 } else {
3889 print_pointer(arg2, 1);
3890 }
79482e59
FB
3891 break;
3892 }
3893 break;
3894 default:
3895 g_assert_not_reached();
3896 }
3897 }
3898 }
3899 print_syscall_epilogue(name);
3900}
3901#endif
3902
33189d31
TS
3903/*
3904 * An array of all of the syscalls we know about
3905 */
3906
7ccfb2eb 3907static const struct syscallname scnames[] = {
33189d31
TS
3908#include "strace.list"
3909};
3910
b1503cda 3911static int nsyscalls = ARRAY_SIZE(scnames);
33189d31
TS
3912
3913/*
3914 * The public interface to this module.
3915 */
3916void
a0939b89 3917print_syscall(CPUArchState *cpu_env, int num,
c16f9ed3
FB
3918 abi_long arg1, abi_long arg2, abi_long arg3,
3919 abi_long arg4, abi_long arg5, abi_long arg6)
33189d31
TS
3920{
3921 int i;
c5a1c6b8
RH
3922 FILE *f;
3923 const char *format = "%s(" TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld ","
3924 TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld ","
3925 TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld ")";
33189d31 3926
c5a1c6b8
RH
3927 f = qemu_log_trylock();
3928 if (!f) {
3929 return;
3930 }
3931 fprintf(f, "%d ", getpid());
33189d31 3932
c5a1c6b8
RH
3933 for (i = 0; i < nsyscalls; i++) {
3934 if (scnames[i].nr == num) {
3935 if (scnames[i].call != NULL) {
3936 scnames[i].call(cpu_env, &scnames[i], arg1, arg2, arg3,
3937 arg4, arg5, arg6);
33189d31 3938 } else {
6b23f777
FB
3939 /* XXX: this format system is broken because it uses
3940 host types and host pointers for strings */
c5a1c6b8 3941 if (scnames[i].format != NULL) {
33189d31 3942 format = scnames[i].format;
c5a1c6b8
RH
3943 }
3944 fprintf(f, format, scnames[i].name, arg1, arg2,
3945 arg3, arg4, arg5, arg6);
33189d31 3946 }
c5a1c6b8 3947 qemu_log_unlock(f);
74c11e55 3948 return;
33189d31 3949 }
c5a1c6b8
RH
3950 }
3951 fprintf(f, "Unknown syscall %d\n", num);
3952 qemu_log_unlock(f);
33189d31
TS
3953}
3954
3955
3956void
a0939b89 3957print_syscall_ret(CPUArchState *cpu_env, int num, abi_long ret,
c84be71f
FB
3958 abi_long arg1, abi_long arg2, abi_long arg3,
3959 abi_long arg4, abi_long arg5, abi_long arg6)
33189d31
TS
3960{
3961 int i;
c5a1c6b8
RH
3962 FILE *f;
3963
3964 f = qemu_log_trylock();
3965 if (!f) {
3966 return;
3967 }
33189d31 3968
c5a1c6b8
RH
3969 for (i = 0; i < nsyscalls; i++) {
3970 if (scnames[i].nr == num) {
3971 if (scnames[i].result != NULL) {
e400e119 3972 scnames[i].result(cpu_env, &scnames[i], ret,
c84be71f
FB
3973 arg1, arg2, arg3,
3974 arg4, arg5, arg6);
33189d31 3975 } else {
42b16184 3976 if (!print_syscall_err(ret)) {
c5a1c6b8 3977 fprintf(f, TARGET_ABI_FMT_ld, ret);
33189d31 3978 }
c5a1c6b8 3979 fprintf(f, "\n");
33189d31
TS
3980 }
3981 break;
3982 }
c5a1c6b8
RH
3983 }
3984 qemu_log_unlock(f);
33189d31 3985}
0cb581d6
PM
3986
3987void print_taken_signal(int target_signum, const target_siginfo_t *tinfo)
3988{
3989 /* Print the strace output for a signal being taken:
3990 * --- SIGSEGV {si_signo=SIGSEGV, si_code=SI_KERNEL, si_addr=0} ---
3991 */
c5a1c6b8
RH
3992 FILE *f;
3993
3994 f = qemu_log_trylock();
3995 if (!f) {
3996 return;
3997 }
3998
3999 fprintf(f, "--- ");
0cb581d6 4000 print_signal(target_signum, 1);
c5a1c6b8 4001 fprintf(f, " ");
0cb581d6 4002 print_siginfo(tinfo);
c5a1c6b8
RH
4003 fprintf(f, " ---\n");
4004 qemu_log_unlock(f);
0cb581d6 4005}