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