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