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