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