blob: 0d9095c674f4dc8ca10f7a64d8fac6e942be94ae [file] [log] [blame]
Peter Maydelld39594e2016-01-26 18:17:02 +00001#include "qemu/osdep.h"
ths33189d32007-11-01 00:13:36 +00002#include <sys/ipc.h>
3#include <sys/msg.h>
4#include <sys/sem.h>
5#include <sys/shm.h>
6#include <sys/select.h>
Mika Westerberg74d753a2009-04-07 16:57:29 +03007#include <sys/mount.h>
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02008#include <arpa/inet.h>
9#include <netinet/tcp.h>
10#include <linux/if_packet.h>
Philippe Mathieu-Daudé814ae702019-10-21 13:48:53 +020011#include <linux/netlink.h>
Laurent Vivier608e5592011-04-07 00:25:32 +020012#include <sched.h>
ths33189d32007-11-01 00:13:36 +000013#include "qemu.h"
14
ths33189d32007-11-01 00:13:36 +000015struct syscallname {
16 int nr;
blueswir17ccfb2e2008-09-14 06:45:34 +000017 const char *name;
18 const char *format;
19 void (*call)(const struct syscallname *,
bellardc16f9ed2007-11-11 17:23:29 +000020 abi_long, abi_long, abi_long,
21 abi_long, abi_long, abi_long);
blueswir17ccfb2e2008-09-14 06:45:34 +000022 void (*result)(const struct syscallname *, abi_long);
ths33189d32007-11-01 00:13:36 +000023};
24
Mika Westerberg74d753a2009-04-07 16:57:29 +030025#ifdef __GNUC__
26/*
27 * It is possible that target doesn't have syscall that uses
28 * following flags but we don't want the compiler to warn
29 * us about them being unused. Same applies to utility print
30 * functions. It is ok to keep them while not used.
31 */
32#define UNUSED __attribute__ ((unused))
33#else
34#define UNUSED
35#endif
36
37/*
38 * Structure used to translate flag values into strings. This is
39 * similar that is in the actual strace tool.
40 */
41struct flags {
42 abi_long f_value; /* flag */
43 const char *f_string; /* stringified flag */
44};
45
46/* common flags for all architectures */
47#define FLAG_GENERIC(name) { name, #name }
48/* target specific flags (syscall_defs.h has TARGET_<flag>) */
49#define FLAG_TARGET(name) { TARGET_ ## name, #name }
50/* end of flags array */
51#define FLAG_END { 0, NULL }
52
53UNUSED static const char *get_comma(int);
54UNUSED static void print_pointer(abi_long, int);
55UNUSED static void print_flags(const struct flags *, abi_long, int);
56UNUSED static void print_at_dirfd(abi_long, int);
57UNUSED static void print_file_mode(abi_long, int);
58UNUSED static void print_open_flags(abi_long, int);
59UNUSED static void print_syscall_prologue(const struct syscallname *);
60UNUSED static void print_syscall_epilogue(const struct syscallname *);
61UNUSED static void print_string(abi_long, int);
Laurent Vivierfb3aabf2016-06-11 02:19:45 +020062UNUSED static void print_buf(abi_long addr, abi_long len, int last);
Mika Westerberg74d753a2009-04-07 16:57:29 +030063UNUSED static void print_raw_param(const char *, abi_long, int);
64UNUSED static void print_timeval(abi_ulong, int);
Philippe Mathieu-Daudé6d33e032019-10-21 13:48:50 +020065UNUSED static void print_timezone(abi_ulong, int);
Mika Westerberg74d753a2009-04-07 16:57:29 +030066UNUSED static void print_number(abi_long, int);
Laurent Vivier608e5592011-04-07 00:25:32 +020067UNUSED static void print_signal(abi_ulong, int);
Philippe Mathieu-Daudé42b15d72019-10-21 13:48:56 +020068UNUSED static void print_sockaddr(abi_ulong, abi_long, int);
Laurent Vivierfb3aabf2016-06-11 02:19:45 +020069UNUSED static void print_socket_domain(int domain);
70UNUSED static void print_socket_type(int type);
71UNUSED static void print_socket_protocol(int domain, int type, int protocol);
Mika Westerberg74d753a2009-04-07 16:57:29 +030072
ths33189d32007-11-01 00:13:36 +000073/*
74 * Utility functions
75 */
76static void
77print_ipc_cmd(int cmd)
78{
79#define output_cmd(val) \
80if( cmd == val ) { \
Josh Kunz4b25a502020-02-03 18:54:14 -080081 qemu_log(#val); \
ths33189d32007-11-01 00:13:36 +000082 return; \
83}
84
85 cmd &= 0xff;
86
87 /* General IPC commands */
88 output_cmd( IPC_RMID );
89 output_cmd( IPC_SET );
90 output_cmd( IPC_STAT );
91 output_cmd( IPC_INFO );
92 /* msgctl() commands */
ths33189d32007-11-01 00:13:36 +000093 output_cmd( MSG_STAT );
94 output_cmd( MSG_INFO );
ths33189d32007-11-01 00:13:36 +000095 /* shmctl() commands */
96 output_cmd( SHM_LOCK );
97 output_cmd( SHM_UNLOCK );
98 output_cmd( SHM_STAT );
99 output_cmd( SHM_INFO );
100 /* semctl() commands */
101 output_cmd( GETPID );
102 output_cmd( GETVAL );
103 output_cmd( GETALL );
104 output_cmd( GETNCNT );
105 output_cmd( GETZCNT );
106 output_cmd( SETVAL );
107 output_cmd( SETALL );
108 output_cmd( SEM_STAT );
109 output_cmd( SEM_INFO );
110 output_cmd( IPC_RMID );
111 output_cmd( IPC_RMID );
112 output_cmd( IPC_RMID );
113 output_cmd( IPC_RMID );
114 output_cmd( IPC_RMID );
115 output_cmd( IPC_RMID );
116 output_cmd( IPC_RMID );
117 output_cmd( IPC_RMID );
118 output_cmd( IPC_RMID );
119
120 /* Some value we don't recognize */
Josh Kunz4b25a502020-02-03 18:54:14 -0800121 qemu_log("%d", cmd);
ths33189d32007-11-01 00:13:36 +0000122}
123
Laurent Vivier608e5592011-04-07 00:25:32 +0200124static void
125print_signal(abi_ulong arg, int last)
126{
127 const char *signal_name = NULL;
128 switch(arg) {
129 case TARGET_SIGHUP: signal_name = "SIGHUP"; break;
130 case TARGET_SIGINT: signal_name = "SIGINT"; break;
131 case TARGET_SIGQUIT: signal_name = "SIGQUIT"; break;
132 case TARGET_SIGILL: signal_name = "SIGILL"; break;
133 case TARGET_SIGABRT: signal_name = "SIGABRT"; break;
134 case TARGET_SIGFPE: signal_name = "SIGFPE"; break;
135 case TARGET_SIGKILL: signal_name = "SIGKILL"; break;
136 case TARGET_SIGSEGV: signal_name = "SIGSEGV"; break;
137 case TARGET_SIGPIPE: signal_name = "SIGPIPE"; break;
138 case TARGET_SIGALRM: signal_name = "SIGALRM"; break;
139 case TARGET_SIGTERM: signal_name = "SIGTERM"; break;
140 case TARGET_SIGUSR1: signal_name = "SIGUSR1"; break;
141 case TARGET_SIGUSR2: signal_name = "SIGUSR2"; break;
142 case TARGET_SIGCHLD: signal_name = "SIGCHLD"; break;
143 case TARGET_SIGCONT: signal_name = "SIGCONT"; break;
144 case TARGET_SIGSTOP: signal_name = "SIGSTOP"; break;
145 case TARGET_SIGTTIN: signal_name = "SIGTTIN"; break;
146 case TARGET_SIGTTOU: signal_name = "SIGTTOU"; break;
147 }
148 if (signal_name == NULL) {
Peter Maydellabe20842013-03-28 14:33:24 +0000149 print_raw_param("%ld", arg, last);
Laurent Vivier608e5592011-04-07 00:25:32 +0200150 return;
151 }
Josh Kunz4b25a502020-02-03 18:54:14 -0800152 qemu_log("%s%s", signal_name, get_comma(last));
Laurent Vivier608e5592011-04-07 00:25:32 +0200153}
154
Peter Maydell0cb581d2016-07-18 18:12:24 +0100155static void print_si_code(int arg)
156{
157 const char *codename = NULL;
158
159 switch (arg) {
160 case SI_USER:
161 codename = "SI_USER";
162 break;
163 case SI_KERNEL:
164 codename = "SI_KERNEL";
165 break;
166 case SI_QUEUE:
167 codename = "SI_QUEUE";
168 break;
169 case SI_TIMER:
170 codename = "SI_TIMER";
171 break;
172 case SI_MESGQ:
173 codename = "SI_MESGQ";
174 break;
175 case SI_ASYNCIO:
176 codename = "SI_ASYNCIO";
177 break;
178 case SI_SIGIO:
179 codename = "SI_SIGIO";
180 break;
181 case SI_TKILL:
182 codename = "SI_TKILL";
183 break;
184 default:
Josh Kunz4b25a502020-02-03 18:54:14 -0800185 qemu_log("%d", arg);
Peter Maydell0cb581d2016-07-18 18:12:24 +0100186 return;
187 }
Josh Kunz4b25a502020-02-03 18:54:14 -0800188 qemu_log("%s", codename);
Peter Maydell0cb581d2016-07-18 18:12:24 +0100189}
190
Miloš Stojanovićba9fcea2017-05-15 16:59:49 +0200191static void get_target_siginfo(target_siginfo_t *tinfo,
192 const target_siginfo_t *info)
193{
194 abi_ulong sival_ptr;
195
196 int sig;
197 int si_errno;
198 int si_code;
199 int si_type;
200
201 __get_user(sig, &info->si_signo);
202 __get_user(si_errno, &tinfo->si_errno);
203 __get_user(si_code, &info->si_code);
204
205 tinfo->si_signo = sig;
206 tinfo->si_errno = si_errno;
207 tinfo->si_code = si_code;
208
209 /* Ensure we don't leak random junk to the guest later */
210 memset(tinfo->_sifields._pad, 0, sizeof(tinfo->_sifields._pad));
211
212 /* This is awkward, because we have to use a combination of
213 * the si_code and si_signo to figure out which of the union's
214 * members are valid. (Within the host kernel it is always possible
215 * to tell, but the kernel carefully avoids giving userspace the
216 * high 16 bits of si_code, so we don't have the information to
217 * do this the easy way...) We therefore make our best guess,
218 * bearing in mind that a guest can spoof most of the si_codes
219 * via rt_sigqueueinfo() if it likes.
220 *
221 * Once we have made our guess, we record it in the top 16 bits of
222 * the si_code, so that print_siginfo() later can use it.
223 * print_siginfo() will strip these top bits out before printing
224 * the si_code.
225 */
226
227 switch (si_code) {
228 case SI_USER:
229 case SI_TKILL:
230 case SI_KERNEL:
231 /* Sent via kill(), tkill() or tgkill(), or direct from the kernel.
232 * These are the only unspoofable si_code values.
233 */
234 __get_user(tinfo->_sifields._kill._pid, &info->_sifields._kill._pid);
235 __get_user(tinfo->_sifields._kill._uid, &info->_sifields._kill._uid);
236 si_type = QEMU_SI_KILL;
237 break;
238 default:
239 /* Everything else is spoofable. Make best guess based on signal */
240 switch (sig) {
241 case TARGET_SIGCHLD:
242 __get_user(tinfo->_sifields._sigchld._pid,
243 &info->_sifields._sigchld._pid);
244 __get_user(tinfo->_sifields._sigchld._uid,
245 &info->_sifields._sigchld._uid);
246 __get_user(tinfo->_sifields._sigchld._status,
247 &info->_sifields._sigchld._status);
248 __get_user(tinfo->_sifields._sigchld._utime,
249 &info->_sifields._sigchld._utime);
250 __get_user(tinfo->_sifields._sigchld._stime,
251 &info->_sifields._sigchld._stime);
252 si_type = QEMU_SI_CHLD;
253 break;
254 case TARGET_SIGIO:
255 __get_user(tinfo->_sifields._sigpoll._band,
256 &info->_sifields._sigpoll._band);
257 __get_user(tinfo->_sifields._sigpoll._fd,
258 &info->_sifields._sigpoll._fd);
259 si_type = QEMU_SI_POLL;
260 break;
261 default:
262 /* Assume a sigqueue()/mq_notify()/rt_sigqueueinfo() source. */
263 __get_user(tinfo->_sifields._rt._pid, &info->_sifields._rt._pid);
264 __get_user(tinfo->_sifields._rt._uid, &info->_sifields._rt._uid);
265 /* XXX: potential problem if 64 bit */
266 __get_user(sival_ptr, &info->_sifields._rt._sigval.sival_ptr);
267 tinfo->_sifields._rt._sigval.sival_ptr = sival_ptr;
268
269 si_type = QEMU_SI_RT;
270 break;
271 }
272 break;
273 }
274
275 tinfo->si_code = deposit32(si_code, 16, 16, si_type);
276}
277
Peter Maydell0cb581d2016-07-18 18:12:24 +0100278static void print_siginfo(const target_siginfo_t *tinfo)
279{
280 /* Print a target_siginfo_t in the format desired for printing
281 * signals being taken. We assume the target_siginfo_t is in the
282 * internal form where the top 16 bits of si_code indicate which
283 * part of the union is valid, rather than in the guest-visible
284 * form where the bottom 16 bits are sign-extended into the top 16.
285 */
286 int si_type = extract32(tinfo->si_code, 16, 16);
287 int si_code = sextract32(tinfo->si_code, 0, 16);
288
Josh Kunz4b25a502020-02-03 18:54:14 -0800289 qemu_log("{si_signo=");
Peter Maydell0cb581d2016-07-18 18:12:24 +0100290 print_signal(tinfo->si_signo, 1);
Josh Kunz4b25a502020-02-03 18:54:14 -0800291 qemu_log(", si_code=");
Peter Maydell0cb581d2016-07-18 18:12:24 +0100292 print_si_code(si_code);
293
294 switch (si_type) {
295 case QEMU_SI_KILL:
Josh Kunz4b25a502020-02-03 18:54:14 -0800296 qemu_log(", si_pid=%u, si_uid=%u",
Peter Maydell0cb581d2016-07-18 18:12:24 +0100297 (unsigned int)tinfo->_sifields._kill._pid,
298 (unsigned int)tinfo->_sifields._kill._uid);
299 break;
300 case QEMU_SI_TIMER:
Josh Kunz4b25a502020-02-03 18:54:14 -0800301 qemu_log(", si_timer1=%u, si_timer2=%u",
Peter Maydell0cb581d2016-07-18 18:12:24 +0100302 tinfo->_sifields._timer._timer1,
303 tinfo->_sifields._timer._timer2);
304 break;
305 case QEMU_SI_POLL:
Josh Kunz4b25a502020-02-03 18:54:14 -0800306 qemu_log(", si_band=%d, si_fd=%d",
Peter Maydell0cb581d2016-07-18 18:12:24 +0100307 tinfo->_sifields._sigpoll._band,
308 tinfo->_sifields._sigpoll._fd);
309 break;
310 case QEMU_SI_FAULT:
Josh Kunz4b25a502020-02-03 18:54:14 -0800311 qemu_log(", si_addr=");
Peter Maydell0cb581d2016-07-18 18:12:24 +0100312 print_pointer(tinfo->_sifields._sigfault._addr, 1);
313 break;
314 case QEMU_SI_CHLD:
Josh Kunz4b25a502020-02-03 18:54:14 -0800315 qemu_log(", si_pid=%u, si_uid=%u, si_status=%d"
Peter Maydell0cb581d2016-07-18 18:12:24 +0100316 ", si_utime=" TARGET_ABI_FMT_ld
317 ", si_stime=" TARGET_ABI_FMT_ld,
318 (unsigned int)(tinfo->_sifields._sigchld._pid),
319 (unsigned int)(tinfo->_sifields._sigchld._uid),
320 tinfo->_sifields._sigchld._status,
321 tinfo->_sifields._sigchld._utime,
322 tinfo->_sifields._sigchld._stime);
323 break;
324 case QEMU_SI_RT:
Josh Kunz4b25a502020-02-03 18:54:14 -0800325 qemu_log(", si_pid=%u, si_uid=%u, si_sigval=" TARGET_ABI_FMT_ld,
Peter Maydell0cb581d2016-07-18 18:12:24 +0100326 (unsigned int)tinfo->_sifields._rt._pid,
327 (unsigned int)tinfo->_sifields._rt._uid,
328 tinfo->_sifields._rt._sigval.sival_ptr);
329 break;
330 default:
331 g_assert_not_reached();
332 }
Josh Kunz4b25a502020-02-03 18:54:14 -0800333 qemu_log("}");
Peter Maydell0cb581d2016-07-18 18:12:24 +0100334}
335
Laurent Vivierfb3aabf2016-06-11 02:19:45 +0200336static void
Philippe Mathieu-Daudé42b15d72019-10-21 13:48:56 +0200337print_sockaddr(abi_ulong addr, abi_long addrlen, int last)
Laurent Vivierfb3aabf2016-06-11 02:19:45 +0200338{
339 struct target_sockaddr *sa;
340 int i;
341 int sa_family;
342
343 sa = lock_user(VERIFY_READ, addr, addrlen, 1);
344 if (sa) {
345 sa_family = tswap16(sa->sa_family);
346 switch (sa_family) {
347 case AF_UNIX: {
348 struct target_sockaddr_un *un = (struct target_sockaddr_un *)sa;
349 int i;
Josh Kunz4b25a502020-02-03 18:54:14 -0800350 qemu_log("{sun_family=AF_UNIX,sun_path=\"");
Laurent Vivierfb3aabf2016-06-11 02:19:45 +0200351 for (i = 0; i < addrlen -
352 offsetof(struct target_sockaddr_un, sun_path) &&
353 un->sun_path[i]; i++) {
Josh Kunz4b25a502020-02-03 18:54:14 -0800354 qemu_log("%c", un->sun_path[i]);
Laurent Vivierfb3aabf2016-06-11 02:19:45 +0200355 }
Josh Kunz4b25a502020-02-03 18:54:14 -0800356 qemu_log("\"}");
Laurent Vivierfb3aabf2016-06-11 02:19:45 +0200357 break;
358 }
359 case AF_INET: {
360 struct target_sockaddr_in *in = (struct target_sockaddr_in *)sa;
361 uint8_t *c = (uint8_t *)&in->sin_addr.s_addr;
Josh Kunz4b25a502020-02-03 18:54:14 -0800362 qemu_log("{sin_family=AF_INET,sin_port=htons(%d),",
Laurent Vivierfb3aabf2016-06-11 02:19:45 +0200363 ntohs(in->sin_port));
Josh Kunz4b25a502020-02-03 18:54:14 -0800364 qemu_log("sin_addr=inet_addr(\"%d.%d.%d.%d\")",
Laurent Vivierfb3aabf2016-06-11 02:19:45 +0200365 c[0], c[1], c[2], c[3]);
Josh Kunz4b25a502020-02-03 18:54:14 -0800366 qemu_log("}");
Laurent Vivierfb3aabf2016-06-11 02:19:45 +0200367 break;
368 }
369 case AF_PACKET: {
370 struct target_sockaddr_ll *ll = (struct target_sockaddr_ll *)sa;
371 uint8_t *c = (uint8_t *)&ll->sll_addr;
Josh Kunz4b25a502020-02-03 18:54:14 -0800372 qemu_log("{sll_family=AF_PACKET,"
Laurent Vivierfb3aabf2016-06-11 02:19:45 +0200373 "sll_protocol=htons(0x%04x),if%d,pkttype=",
374 ntohs(ll->sll_protocol), ll->sll_ifindex);
375 switch (ll->sll_pkttype) {
376 case PACKET_HOST:
Josh Kunz4b25a502020-02-03 18:54:14 -0800377 qemu_log("PACKET_HOST");
Laurent Vivierfb3aabf2016-06-11 02:19:45 +0200378 break;
379 case PACKET_BROADCAST:
Josh Kunz4b25a502020-02-03 18:54:14 -0800380 qemu_log("PACKET_BROADCAST");
Laurent Vivierfb3aabf2016-06-11 02:19:45 +0200381 break;
382 case PACKET_MULTICAST:
Josh Kunz4b25a502020-02-03 18:54:14 -0800383 qemu_log("PACKET_MULTICAST");
Laurent Vivierfb3aabf2016-06-11 02:19:45 +0200384 break;
385 case PACKET_OTHERHOST:
Josh Kunz4b25a502020-02-03 18:54:14 -0800386 qemu_log("PACKET_OTHERHOST");
Laurent Vivierfb3aabf2016-06-11 02:19:45 +0200387 break;
388 case PACKET_OUTGOING:
Josh Kunz4b25a502020-02-03 18:54:14 -0800389 qemu_log("PACKET_OUTGOING");
Laurent Vivierfb3aabf2016-06-11 02:19:45 +0200390 break;
391 default:
Josh Kunz4b25a502020-02-03 18:54:14 -0800392 qemu_log("%d", ll->sll_pkttype);
Laurent Vivierfb3aabf2016-06-11 02:19:45 +0200393 break;
394 }
Josh Kunz4b25a502020-02-03 18:54:14 -0800395 qemu_log(",sll_addr=%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x",
Laurent Vivierfb3aabf2016-06-11 02:19:45 +0200396 c[0], c[1], c[2], c[3], c[4], c[5], c[6], c[7]);
Josh Kunz4b25a502020-02-03 18:54:14 -0800397 qemu_log("}");
Laurent Vivierfb3aabf2016-06-11 02:19:45 +0200398 break;
399 }
Philippe Mathieu-Daudé814ae702019-10-21 13:48:53 +0200400 case AF_NETLINK: {
401 struct target_sockaddr_nl *nl = (struct target_sockaddr_nl *)sa;
Josh Kunz4b25a502020-02-03 18:54:14 -0800402 qemu_log("{nl_family=AF_NETLINK,nl_pid=%u,nl_groups=%u}",
Philippe Mathieu-Daudé814ae702019-10-21 13:48:53 +0200403 tswap32(nl->nl_pid), tswap32(nl->nl_groups));
404 break;
405 }
Laurent Vivierfb3aabf2016-06-11 02:19:45 +0200406 default:
Josh Kunz4b25a502020-02-03 18:54:14 -0800407 qemu_log("{sa_family=%d, sa_data={", sa->sa_family);
Laurent Vivierfb3aabf2016-06-11 02:19:45 +0200408 for (i = 0; i < 13; i++) {
Josh Kunz4b25a502020-02-03 18:54:14 -0800409 qemu_log("%02x, ", sa->sa_data[i]);
Laurent Vivierfb3aabf2016-06-11 02:19:45 +0200410 }
Josh Kunz4b25a502020-02-03 18:54:14 -0800411 qemu_log("%02x}", sa->sa_data[i]);
412 qemu_log("}");
Laurent Vivierfb3aabf2016-06-11 02:19:45 +0200413 break;
414 }
415 unlock_user(sa, addr, 0);
416 } else {
417 print_raw_param("0x"TARGET_ABI_FMT_lx, addr, 0);
418 }
Josh Kunz4b25a502020-02-03 18:54:14 -0800419 qemu_log(", "TARGET_ABI_FMT_ld"%s", addrlen, get_comma(last));
Laurent Vivierfb3aabf2016-06-11 02:19:45 +0200420}
421
422static void
423print_socket_domain(int domain)
424{
425 switch (domain) {
426 case PF_UNIX:
Josh Kunz4b25a502020-02-03 18:54:14 -0800427 qemu_log("PF_UNIX");
Laurent Vivierfb3aabf2016-06-11 02:19:45 +0200428 break;
429 case PF_INET:
Josh Kunz4b25a502020-02-03 18:54:14 -0800430 qemu_log("PF_INET");
Laurent Vivierfb3aabf2016-06-11 02:19:45 +0200431 break;
Philippe Mathieu-Daudé814ae702019-10-21 13:48:53 +0200432 case PF_NETLINK:
Josh Kunz4b25a502020-02-03 18:54:14 -0800433 qemu_log("PF_NETLINK");
Philippe Mathieu-Daudé814ae702019-10-21 13:48:53 +0200434 break;
Laurent Vivierfb3aabf2016-06-11 02:19:45 +0200435 case PF_PACKET:
Josh Kunz4b25a502020-02-03 18:54:14 -0800436 qemu_log("PF_PACKET");
Laurent Vivierfb3aabf2016-06-11 02:19:45 +0200437 break;
438 default:
Josh Kunz4b25a502020-02-03 18:54:14 -0800439 qemu_log("%d", domain);
Laurent Vivierfb3aabf2016-06-11 02:19:45 +0200440 break;
441 }
442}
443
444static void
445print_socket_type(int type)
446{
Laurent Vivier2039b1b2020-03-12 17:55:30 +0100447 switch (type & TARGET_SOCK_TYPE_MASK) {
Laurent Vivierfb3aabf2016-06-11 02:19:45 +0200448 case TARGET_SOCK_DGRAM:
Josh Kunz4b25a502020-02-03 18:54:14 -0800449 qemu_log("SOCK_DGRAM");
Laurent Vivierfb3aabf2016-06-11 02:19:45 +0200450 break;
451 case TARGET_SOCK_STREAM:
Josh Kunz4b25a502020-02-03 18:54:14 -0800452 qemu_log("SOCK_STREAM");
Laurent Vivierfb3aabf2016-06-11 02:19:45 +0200453 break;
454 case TARGET_SOCK_RAW:
Josh Kunz4b25a502020-02-03 18:54:14 -0800455 qemu_log("SOCK_RAW");
Laurent Vivierfb3aabf2016-06-11 02:19:45 +0200456 break;
457 case TARGET_SOCK_RDM:
Josh Kunz4b25a502020-02-03 18:54:14 -0800458 qemu_log("SOCK_RDM");
Laurent Vivierfb3aabf2016-06-11 02:19:45 +0200459 break;
460 case TARGET_SOCK_SEQPACKET:
Josh Kunz4b25a502020-02-03 18:54:14 -0800461 qemu_log("SOCK_SEQPACKET");
Laurent Vivierfb3aabf2016-06-11 02:19:45 +0200462 break;
463 case TARGET_SOCK_PACKET:
Josh Kunz4b25a502020-02-03 18:54:14 -0800464 qemu_log("SOCK_PACKET");
Laurent Vivierfb3aabf2016-06-11 02:19:45 +0200465 break;
466 }
Laurent Vivier2039b1b2020-03-12 17:55:30 +0100467 if (type & TARGET_SOCK_CLOEXEC) {
468 qemu_log("|SOCK_CLOEXEC");
469 }
470 if (type & TARGET_SOCK_NONBLOCK) {
471 qemu_log("|SOCK_NONBLOCK");
472 }
Laurent Vivierfb3aabf2016-06-11 02:19:45 +0200473}
474
475static void
476print_socket_protocol(int domain, int type, int protocol)
477{
478 if (domain == AF_PACKET ||
479 (domain == AF_INET && type == TARGET_SOCK_PACKET)) {
480 switch (protocol) {
481 case 0x0003:
Josh Kunz4b25a502020-02-03 18:54:14 -0800482 qemu_log("ETH_P_ALL");
Laurent Vivierfb3aabf2016-06-11 02:19:45 +0200483 break;
484 default:
Josh Kunz4b25a502020-02-03 18:54:14 -0800485 qemu_log("%d", protocol);
Laurent Vivierfb3aabf2016-06-11 02:19:45 +0200486 }
487 return;
488 }
489
Philippe Mathieu-Daudé814ae702019-10-21 13:48:53 +0200490 if (domain == PF_NETLINK) {
491 switch (protocol) {
492 case NETLINK_ROUTE:
Josh Kunz4b25a502020-02-03 18:54:14 -0800493 qemu_log("NETLINK_ROUTE");
Philippe Mathieu-Daudé814ae702019-10-21 13:48:53 +0200494 break;
495 case NETLINK_AUDIT:
Josh Kunz4b25a502020-02-03 18:54:14 -0800496 qemu_log("NETLINK_AUDIT");
Philippe Mathieu-Daudé814ae702019-10-21 13:48:53 +0200497 break;
498 case NETLINK_NETFILTER:
Josh Kunz4b25a502020-02-03 18:54:14 -0800499 qemu_log("NETLINK_NETFILTER");
Philippe Mathieu-Daudé814ae702019-10-21 13:48:53 +0200500 break;
501 case NETLINK_KOBJECT_UEVENT:
Josh Kunz4b25a502020-02-03 18:54:14 -0800502 qemu_log("NETLINK_KOBJECT_UEVENT");
Philippe Mathieu-Daudé814ae702019-10-21 13:48:53 +0200503 break;
504 case NETLINK_RDMA:
Josh Kunz4b25a502020-02-03 18:54:14 -0800505 qemu_log("NETLINK_RDMA");
Philippe Mathieu-Daudé814ae702019-10-21 13:48:53 +0200506 break;
507 case NETLINK_CRYPTO:
Josh Kunz4b25a502020-02-03 18:54:14 -0800508 qemu_log("NETLINK_CRYPTO");
Philippe Mathieu-Daudé814ae702019-10-21 13:48:53 +0200509 break;
510 default:
Josh Kunz4b25a502020-02-03 18:54:14 -0800511 qemu_log("%d", protocol);
Philippe Mathieu-Daudé814ae702019-10-21 13:48:53 +0200512 break;
513 }
514 return;
515 }
516
Laurent Vivierfb3aabf2016-06-11 02:19:45 +0200517 switch (protocol) {
518 case IPPROTO_IP:
Josh Kunz4b25a502020-02-03 18:54:14 -0800519 qemu_log("IPPROTO_IP");
Laurent Vivierfb3aabf2016-06-11 02:19:45 +0200520 break;
521 case IPPROTO_TCP:
Josh Kunz4b25a502020-02-03 18:54:14 -0800522 qemu_log("IPPROTO_TCP");
Laurent Vivierfb3aabf2016-06-11 02:19:45 +0200523 break;
524 case IPPROTO_UDP:
Josh Kunz4b25a502020-02-03 18:54:14 -0800525 qemu_log("IPPROTO_UDP");
Laurent Vivierfb3aabf2016-06-11 02:19:45 +0200526 break;
527 case IPPROTO_RAW:
Josh Kunz4b25a502020-02-03 18:54:14 -0800528 qemu_log("IPPROTO_RAW");
Laurent Vivierfb3aabf2016-06-11 02:19:45 +0200529 break;
530 default:
Josh Kunz4b25a502020-02-03 18:54:14 -0800531 qemu_log("%d", protocol);
Laurent Vivierfb3aabf2016-06-11 02:19:45 +0200532 break;
533 }
534}
535
536
bellardc16f9ed2007-11-11 17:23:29 +0000537#ifdef TARGET_NR__newselect
ths33189d32007-11-01 00:13:36 +0000538static void
bellardc16f9ed2007-11-11 17:23:29 +0000539print_fdset(int n, abi_ulong target_fds_addr)
ths33189d32007-11-01 00:13:36 +0000540{
541 int i;
542
Josh Kunz4b25a502020-02-03 18:54:14 -0800543 qemu_log("[");
ths33189d32007-11-01 00:13:36 +0000544 if( target_fds_addr ) {
bellard579a97f2007-11-11 14:26:47 +0000545 abi_long *target_fds;
ths33189d32007-11-01 00:13:36 +0000546
bellard579a97f2007-11-11 14:26:47 +0000547 target_fds = lock_user(VERIFY_READ,
548 target_fds_addr,
549 sizeof(*target_fds)*(n / TARGET_ABI_BITS + 1),
550 1);
551
552 if (!target_fds)
ths33189d32007-11-01 00:13:36 +0000553 return;
554
ths33189d32007-11-01 00:13:36 +0000555 for (i=n; i>=0; i--) {
Matthias Brauncbb21ee2011-08-12 19:57:41 +0200556 if ((tswapal(target_fds[i / TARGET_ABI_BITS]) >> (i & (TARGET_ABI_BITS - 1))) & 1)
Josh Kunz4b25a502020-02-03 18:54:14 -0800557 qemu_log("%d,", i);
ths33189d32007-11-01 00:13:36 +0000558 }
559 unlock_user(target_fds, target_fds_addr, 0);
560 }
Josh Kunz4b25a502020-02-03 18:54:14 -0800561 qemu_log("]");
ths33189d32007-11-01 00:13:36 +0000562}
bellardc16f9ed2007-11-11 17:23:29 +0000563#endif
ths33189d32007-11-01 00:13:36 +0000564
Aleksandar Markovic38860a02016-10-10 13:23:29 +0200565#ifdef TARGET_NR_clock_adjtime
566/* IDs of the various system clocks */
567#define TARGET_CLOCK_REALTIME 0
568#define TARGET_CLOCK_MONOTONIC 1
569#define TARGET_CLOCK_PROCESS_CPUTIME_ID 2
570#define TARGET_CLOCK_THREAD_CPUTIME_ID 3
571#define TARGET_CLOCK_MONOTONIC_RAW 4
572#define TARGET_CLOCK_REALTIME_COARSE 5
573#define TARGET_CLOCK_MONOTONIC_COARSE 6
574#define TARGET_CLOCK_BOOTTIME 7
575#define TARGET_CLOCK_REALTIME_ALARM 8
576#define TARGET_CLOCK_BOOTTIME_ALARM 9
577#define TARGET_CLOCK_SGI_CYCLE 10
578#define TARGET_CLOCK_TAI 11
579
580static void
581print_clockid(int clockid, int last)
582{
583 switch (clockid) {
584 case TARGET_CLOCK_REALTIME:
Josh Kunz4b25a502020-02-03 18:54:14 -0800585 qemu_log("CLOCK_REALTIME");
Aleksandar Markovic38860a02016-10-10 13:23:29 +0200586 break;
587 case TARGET_CLOCK_MONOTONIC:
Josh Kunz4b25a502020-02-03 18:54:14 -0800588 qemu_log("CLOCK_MONOTONIC");
Aleksandar Markovic38860a02016-10-10 13:23:29 +0200589 break;
590 case TARGET_CLOCK_PROCESS_CPUTIME_ID:
Josh Kunz4b25a502020-02-03 18:54:14 -0800591 qemu_log("CLOCK_PROCESS_CPUTIME_ID");
Aleksandar Markovic38860a02016-10-10 13:23:29 +0200592 break;
593 case TARGET_CLOCK_THREAD_CPUTIME_ID:
Josh Kunz4b25a502020-02-03 18:54:14 -0800594 qemu_log("CLOCK_THREAD_CPUTIME_ID");
Aleksandar Markovic38860a02016-10-10 13:23:29 +0200595 break;
596 case TARGET_CLOCK_MONOTONIC_RAW:
Josh Kunz4b25a502020-02-03 18:54:14 -0800597 qemu_log("CLOCK_MONOTONIC_RAW");
Aleksandar Markovic38860a02016-10-10 13:23:29 +0200598 break;
599 case TARGET_CLOCK_REALTIME_COARSE:
Josh Kunz4b25a502020-02-03 18:54:14 -0800600 qemu_log("CLOCK_REALTIME_COARSE");
Aleksandar Markovic38860a02016-10-10 13:23:29 +0200601 break;
602 case TARGET_CLOCK_MONOTONIC_COARSE:
Josh Kunz4b25a502020-02-03 18:54:14 -0800603 qemu_log("CLOCK_MONOTONIC_COARSE");
Aleksandar Markovic38860a02016-10-10 13:23:29 +0200604 break;
605 case TARGET_CLOCK_BOOTTIME:
Josh Kunz4b25a502020-02-03 18:54:14 -0800606 qemu_log("CLOCK_BOOTTIME");
Aleksandar Markovic38860a02016-10-10 13:23:29 +0200607 break;
608 case TARGET_CLOCK_REALTIME_ALARM:
Josh Kunz4b25a502020-02-03 18:54:14 -0800609 qemu_log("CLOCK_REALTIME_ALARM");
Aleksandar Markovic38860a02016-10-10 13:23:29 +0200610 break;
611 case TARGET_CLOCK_BOOTTIME_ALARM:
Josh Kunz4b25a502020-02-03 18:54:14 -0800612 qemu_log("CLOCK_BOOTTIME_ALARM");
Aleksandar Markovic38860a02016-10-10 13:23:29 +0200613 break;
614 case TARGET_CLOCK_SGI_CYCLE:
Josh Kunz4b25a502020-02-03 18:54:14 -0800615 qemu_log("CLOCK_SGI_CYCLE");
Aleksandar Markovic38860a02016-10-10 13:23:29 +0200616 break;
617 case TARGET_CLOCK_TAI:
Josh Kunz4b25a502020-02-03 18:54:14 -0800618 qemu_log("CLOCK_TAI");
Aleksandar Markovic38860a02016-10-10 13:23:29 +0200619 break;
620 default:
Josh Kunz4b25a502020-02-03 18:54:14 -0800621 qemu_log("%d", clockid);
Aleksandar Markovic38860a02016-10-10 13:23:29 +0200622 break;
623 }
Josh Kunz4b25a502020-02-03 18:54:14 -0800624 qemu_log("%s", get_comma(last));
Aleksandar Markovic38860a02016-10-10 13:23:29 +0200625}
626#endif
627
ths33189d32007-11-01 00:13:36 +0000628/*
629 * Sysycall specific output functions
630 */
631
632/* select */
bellardc16f9ed2007-11-11 17:23:29 +0000633#ifdef TARGET_NR__newselect
ths33189d32007-11-01 00:13:36 +0000634static long newselect_arg1 = 0;
635static long newselect_arg2 = 0;
636static long newselect_arg3 = 0;
637static long newselect_arg4 = 0;
638static long newselect_arg5 = 0;
639
640static void
blueswir17ccfb2e2008-09-14 06:45:34 +0000641print_newselect(const struct syscallname *name,
bellardc16f9ed2007-11-11 17:23:29 +0000642 abi_long arg1, abi_long arg2, abi_long arg3,
643 abi_long arg4, abi_long arg5, abi_long arg6)
ths33189d32007-11-01 00:13:36 +0000644{
Josh Kunz4b25a502020-02-03 18:54:14 -0800645 qemu_log("%s(" TARGET_ABI_FMT_ld ",", name->name, arg1);
ths33189d32007-11-01 00:13:36 +0000646 print_fdset(arg1, arg2);
Josh Kunz4b25a502020-02-03 18:54:14 -0800647 qemu_log(",");
ths33189d32007-11-01 00:13:36 +0000648 print_fdset(arg1, arg3);
Josh Kunz4b25a502020-02-03 18:54:14 -0800649 qemu_log(",");
ths33189d32007-11-01 00:13:36 +0000650 print_fdset(arg1, arg4);
Josh Kunz4b25a502020-02-03 18:54:14 -0800651 qemu_log(",");
Mika Westerberg74d753a2009-04-07 16:57:29 +0300652 print_timeval(arg5, 1);
Josh Kunz4b25a502020-02-03 18:54:14 -0800653 qemu_log(")");
ths33189d32007-11-01 00:13:36 +0000654
655 /* save for use in the return output function below */
656 newselect_arg1=arg1;
657 newselect_arg2=arg2;
658 newselect_arg3=arg3;
659 newselect_arg4=arg4;
660 newselect_arg5=arg5;
661}
bellardc16f9ed2007-11-11 17:23:29 +0000662#endif
ths33189d32007-11-01 00:13:36 +0000663
blueswir13e46b2e2008-10-03 19:01:41 +0000664#ifdef TARGET_NR_semctl
ths33189d32007-11-01 00:13:36 +0000665static void
blueswir17ccfb2e2008-09-14 06:45:34 +0000666print_semctl(const struct syscallname *name,
bellardc16f9ed2007-11-11 17:23:29 +0000667 abi_long arg1, abi_long arg2, abi_long arg3,
668 abi_long arg4, abi_long arg5, abi_long arg6)
ths33189d32007-11-01 00:13:36 +0000669{
Josh Kunz4b25a502020-02-03 18:54:14 -0800670 qemu_log("%s(" TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld ",",
671 name->name, arg1, arg2);
ths33189d32007-11-01 00:13:36 +0000672 print_ipc_cmd(arg3);
Josh Kunz4b25a502020-02-03 18:54:14 -0800673 qemu_log(",0x" TARGET_ABI_FMT_lx ")", arg4);
ths33189d32007-11-01 00:13:36 +0000674}
blueswir13e46b2e2008-10-03 19:01:41 +0000675#endif
ths33189d32007-11-01 00:13:36 +0000676
677static void
blueswir17ccfb2e2008-09-14 06:45:34 +0000678print_execve(const struct syscallname *name,
bellardc16f9ed2007-11-11 17:23:29 +0000679 abi_long arg1, abi_long arg2, abi_long arg3,
680 abi_long arg4, abi_long arg5, abi_long arg6)
ths33189d32007-11-01 00:13:36 +0000681{
bellardc16f9ed2007-11-11 17:23:29 +0000682 abi_ulong arg_ptr_addr;
ths33189d32007-11-01 00:13:36 +0000683 char *s;
684
bellard579a97f2007-11-11 14:26:47 +0000685 if (!(s = lock_user_string(arg1)))
ths33189d32007-11-01 00:13:36 +0000686 return;
Josh Kunz4b25a502020-02-03 18:54:14 -0800687 qemu_log("%s(\"%s\",{", name->name, s);
ths33189d32007-11-01 00:13:36 +0000688 unlock_user(s, arg1, 0);
689
bellardc16f9ed2007-11-11 17:23:29 +0000690 for (arg_ptr_addr = arg2; ; arg_ptr_addr += sizeof(abi_ulong)) {
blueswir198448f52008-09-30 18:16:09 +0000691 abi_ulong *arg_ptr, arg_addr;
ths33189d32007-11-01 00:13:36 +0000692
Paolo Bonzini7d374352018-12-13 23:37:37 +0100693 arg_ptr = lock_user(VERIFY_READ, arg_ptr_addr, sizeof(abi_ulong), 1);
bellard579a97f2007-11-11 14:26:47 +0000694 if (!arg_ptr)
ths33189d32007-11-01 00:13:36 +0000695 return;
Matthias Brauncbb21ee2011-08-12 19:57:41 +0200696 arg_addr = tswapal(*arg_ptr);
Paolo Bonzini7d374352018-12-13 23:37:37 +0100697 unlock_user(arg_ptr, arg_ptr_addr, 0);
ths33189d32007-11-01 00:13:36 +0000698 if (!arg_addr)
699 break;
bellard579a97f2007-11-11 14:26:47 +0000700 if ((s = lock_user_string(arg_addr))) {
Josh Kunz4b25a502020-02-03 18:54:14 -0800701 qemu_log("\"%s\",", s);
blueswir198448f52008-09-30 18:16:09 +0000702 unlock_user(s, arg_addr, 0);
bellard579a97f2007-11-11 14:26:47 +0000703 }
ths33189d32007-11-01 00:13:36 +0000704 }
705
Josh Kunz4b25a502020-02-03 18:54:14 -0800706 qemu_log("NULL})");
ths33189d32007-11-01 00:13:36 +0000707}
708
bellardc16f9ed2007-11-11 17:23:29 +0000709#ifdef TARGET_NR_ipc
ths33189d32007-11-01 00:13:36 +0000710static void
blueswir17ccfb2e2008-09-14 06:45:34 +0000711print_ipc(const struct syscallname *name,
bellardc16f9ed2007-11-11 17:23:29 +0000712 abi_long arg1, abi_long arg2, abi_long arg3,
713 abi_long arg4, abi_long arg5, abi_long arg6)
ths33189d32007-11-01 00:13:36 +0000714{
715 switch(arg1) {
716 case IPCOP_semctl:
Josh Kunz4b25a502020-02-03 18:54:14 -0800717 qemu_log("semctl(" TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld ",",
718 arg1, arg2);
blueswir17ccfb2e2008-09-14 06:45:34 +0000719 print_ipc_cmd(arg3);
Josh Kunz4b25a502020-02-03 18:54:14 -0800720 qemu_log(",0x" TARGET_ABI_FMT_lx ")", arg4);
ths33189d32007-11-01 00:13:36 +0000721 break;
722 default:
Josh Kunz4b25a502020-02-03 18:54:14 -0800723 qemu_log(("%s("
724 TARGET_ABI_FMT_ld ","
725 TARGET_ABI_FMT_ld ","
726 TARGET_ABI_FMT_ld ","
727 TARGET_ABI_FMT_ld
728 ")"),
ths33189d32007-11-01 00:13:36 +0000729 name->name, arg1, arg2, arg3, arg4);
730 }
731}
bellardc16f9ed2007-11-11 17:23:29 +0000732#endif
ths33189d32007-11-01 00:13:36 +0000733
734/*
735 * Variants for the return value output function
736 */
737
738static void
blueswir17ccfb2e2008-09-14 06:45:34 +0000739print_syscall_ret_addr(const struct syscallname *name, abi_long ret)
ths33189d32007-11-01 00:13:36 +0000740{
Peter Maydell7dcdaea2016-06-06 19:58:18 +0100741 const char *errstr = NULL;
Alexander Graf962b2892011-11-21 12:04:07 +0100742
Peter Maydell2a7e1242011-11-21 12:21:19 +0000743 if (ret < 0) {
744 errstr = target_strerror(-ret);
Alexander Graf962b2892011-11-21 12:04:07 +0100745 }
Peter Maydell2a7e1242011-11-21 12:21:19 +0000746 if (errstr) {
Josh Kunz4b25a502020-02-03 18:54:14 -0800747 qemu_log(" = -1 errno=%d (%s)\n", (int)-ret, errstr);
ths33189d32007-11-01 00:13:36 +0000748 } else {
Josh Kunz4b25a502020-02-03 18:54:14 -0800749 qemu_log(" = 0x" TARGET_ABI_FMT_lx "\n", ret);
ths33189d32007-11-01 00:13:36 +0000750 }
751}
752
thsf3e32852007-11-03 15:12:16 +0000753#if 0 /* currently unused */
ths33189d32007-11-01 00:13:36 +0000754static void
bellardc16f9ed2007-11-11 17:23:29 +0000755print_syscall_ret_raw(struct syscallname *name, abi_long ret)
ths33189d32007-11-01 00:13:36 +0000756{
Josh Kunz4b25a502020-02-03 18:54:14 -0800757 qemu_log(" = 0x" TARGET_ABI_FMT_lx "\n", ret);
ths33189d32007-11-01 00:13:36 +0000758}
thsf3e32852007-11-03 15:12:16 +0000759#endif
ths33189d32007-11-01 00:13:36 +0000760
thsf3e32852007-11-03 15:12:16 +0000761#ifdef TARGET_NR__newselect
ths33189d32007-11-01 00:13:36 +0000762static void
blueswir17ccfb2e2008-09-14 06:45:34 +0000763print_syscall_ret_newselect(const struct syscallname *name, abi_long ret)
ths33189d32007-11-01 00:13:36 +0000764{
Josh Kunz4b25a502020-02-03 18:54:14 -0800765 qemu_log(" = 0x" TARGET_ABI_FMT_lx " (", ret);
ths33189d32007-11-01 00:13:36 +0000766 print_fdset(newselect_arg1,newselect_arg2);
Josh Kunz4b25a502020-02-03 18:54:14 -0800767 qemu_log(",");
ths33189d32007-11-01 00:13:36 +0000768 print_fdset(newselect_arg1,newselect_arg3);
Josh Kunz4b25a502020-02-03 18:54:14 -0800769 qemu_log(",");
ths33189d32007-11-01 00:13:36 +0000770 print_fdset(newselect_arg1,newselect_arg4);
Josh Kunz4b25a502020-02-03 18:54:14 -0800771 qemu_log(",");
Mika Westerberg74d753a2009-04-07 16:57:29 +0300772 print_timeval(newselect_arg5, 1);
Josh Kunz4b25a502020-02-03 18:54:14 -0800773 qemu_log(")\n");
ths33189d32007-11-01 00:13:36 +0000774}
thsf3e32852007-11-03 15:12:16 +0000775#endif
ths33189d32007-11-01 00:13:36 +0000776
Aleksandar Markovic19f59bc2016-09-22 18:56:50 +0200777/* special meanings of adjtimex()' non-negative return values */
778#define TARGET_TIME_OK 0 /* clock synchronized, no leap second */
779#define TARGET_TIME_INS 1 /* insert leap second */
780#define TARGET_TIME_DEL 2 /* delete leap second */
781#define TARGET_TIME_OOP 3 /* leap second in progress */
782#define TARGET_TIME_WAIT 4 /* leap second has occurred */
783#define TARGET_TIME_ERROR 5 /* clock not synchronized */
Alistair Francis859e8a82020-03-12 15:13:49 -0700784#ifdef TARGET_NR_adjtimex
Aleksandar Markovic19f59bc2016-09-22 18:56:50 +0200785static void
786print_syscall_ret_adjtimex(const struct syscallname *name, abi_long ret)
787{
788 const char *errstr = NULL;
789
Josh Kunz4b25a502020-02-03 18:54:14 -0800790 qemu_log(" = ");
Aleksandar Markovic19f59bc2016-09-22 18:56:50 +0200791 if (ret < 0) {
Josh Kunz4b25a502020-02-03 18:54:14 -0800792 qemu_log("-1 errno=%d", errno);
Aleksandar Markovic19f59bc2016-09-22 18:56:50 +0200793 errstr = target_strerror(-ret);
794 if (errstr) {
Josh Kunz4b25a502020-02-03 18:54:14 -0800795 qemu_log(" (%s)", errstr);
Aleksandar Markovic19f59bc2016-09-22 18:56:50 +0200796 }
797 } else {
Josh Kunz4b25a502020-02-03 18:54:14 -0800798 qemu_log(TARGET_ABI_FMT_ld, ret);
Aleksandar Markovic19f59bc2016-09-22 18:56:50 +0200799 switch (ret) {
800 case TARGET_TIME_OK:
Josh Kunz4b25a502020-02-03 18:54:14 -0800801 qemu_log(" TIME_OK (clock synchronized, no leap second)");
Aleksandar Markovic19f59bc2016-09-22 18:56:50 +0200802 break;
803 case TARGET_TIME_INS:
Josh Kunz4b25a502020-02-03 18:54:14 -0800804 qemu_log(" TIME_INS (insert leap second)");
Aleksandar Markovic19f59bc2016-09-22 18:56:50 +0200805 break;
806 case TARGET_TIME_DEL:
Josh Kunz4b25a502020-02-03 18:54:14 -0800807 qemu_log(" TIME_DEL (delete leap second)");
Aleksandar Markovic19f59bc2016-09-22 18:56:50 +0200808 break;
809 case TARGET_TIME_OOP:
Josh Kunz4b25a502020-02-03 18:54:14 -0800810 qemu_log(" TIME_OOP (leap second in progress)");
Aleksandar Markovic19f59bc2016-09-22 18:56:50 +0200811 break;
812 case TARGET_TIME_WAIT:
Josh Kunz4b25a502020-02-03 18:54:14 -0800813 qemu_log(" TIME_WAIT (leap second has occurred)");
Aleksandar Markovic19f59bc2016-09-22 18:56:50 +0200814 break;
815 case TARGET_TIME_ERROR:
Josh Kunz4b25a502020-02-03 18:54:14 -0800816 qemu_log(" TIME_ERROR (clock not synchronized)");
Aleksandar Markovic19f59bc2016-09-22 18:56:50 +0200817 break;
818 }
819 }
820
Josh Kunz4b25a502020-02-03 18:54:14 -0800821 qemu_log("\n");
Aleksandar Markovic19f59bc2016-09-22 18:56:50 +0200822}
Alistair Francis859e8a82020-03-12 15:13:49 -0700823#endif
Aleksandar Markovic19f59bc2016-09-22 18:56:50 +0200824
Mika Westerberg74d753a2009-04-07 16:57:29 +0300825UNUSED static struct flags access_flags[] = {
826 FLAG_GENERIC(F_OK),
827 FLAG_GENERIC(R_OK),
828 FLAG_GENERIC(W_OK),
829 FLAG_GENERIC(X_OK),
830 FLAG_END,
831};
832
833UNUSED static struct flags at_file_flags[] = {
834#ifdef AT_EACCESS
835 FLAG_GENERIC(AT_EACCESS),
836#endif
837#ifdef AT_SYMLINK_NOFOLLOW
838 FLAG_GENERIC(AT_SYMLINK_NOFOLLOW),
839#endif
840 FLAG_END,
841};
842
843UNUSED static struct flags unlinkat_flags[] = {
844#ifdef AT_REMOVEDIR
845 FLAG_GENERIC(AT_REMOVEDIR),
846#endif
847 FLAG_END,
848};
849
850UNUSED static struct flags mode_flags[] = {
851 FLAG_GENERIC(S_IFSOCK),
852 FLAG_GENERIC(S_IFLNK),
853 FLAG_GENERIC(S_IFREG),
854 FLAG_GENERIC(S_IFBLK),
855 FLAG_GENERIC(S_IFDIR),
856 FLAG_GENERIC(S_IFCHR),
857 FLAG_GENERIC(S_IFIFO),
858 FLAG_END,
859};
860
861UNUSED static struct flags open_access_flags[] = {
862 FLAG_TARGET(O_RDONLY),
863 FLAG_TARGET(O_WRONLY),
864 FLAG_TARGET(O_RDWR),
865 FLAG_END,
866};
867
868UNUSED static struct flags open_flags[] = {
869 FLAG_TARGET(O_APPEND),
870 FLAG_TARGET(O_CREAT),
871 FLAG_TARGET(O_DIRECTORY),
872 FLAG_TARGET(O_EXCL),
873 FLAG_TARGET(O_LARGEFILE),
874 FLAG_TARGET(O_NOCTTY),
875 FLAG_TARGET(O_NOFOLLOW),
876 FLAG_TARGET(O_NONBLOCK), /* also O_NDELAY */
Richard Hendersonafc87632012-07-25 14:30:34 -0700877 FLAG_TARGET(O_DSYNC),
878 FLAG_TARGET(__O_SYNC),
Mika Westerberg74d753a2009-04-07 16:57:29 +0300879 FLAG_TARGET(O_TRUNC),
880#ifdef O_DIRECT
881 FLAG_TARGET(O_DIRECT),
882#endif
Richard Hendersonafc87632012-07-25 14:30:34 -0700883#ifdef O_NOATIME
884 FLAG_TARGET(O_NOATIME),
885#endif
886#ifdef O_CLOEXEC
887 FLAG_TARGET(O_CLOEXEC),
888#endif
889#ifdef O_PATH
890 FLAG_TARGET(O_PATH),
891#endif
Riku Voipio5f9cee42017-08-08 16:01:19 +0300892#ifdef O_TMPFILE
893 FLAG_TARGET(O_TMPFILE),
894 FLAG_TARGET(__O_TMPFILE),
895#endif
Mika Westerberg74d753a2009-04-07 16:57:29 +0300896 FLAG_END,
897};
898
899UNUSED static struct flags mount_flags[] = {
900#ifdef MS_BIND
901 FLAG_GENERIC(MS_BIND),
902#endif
903#ifdef MS_DIRSYNC
904 FLAG_GENERIC(MS_DIRSYNC),
905#endif
906 FLAG_GENERIC(MS_MANDLOCK),
907#ifdef MS_MOVE
908 FLAG_GENERIC(MS_MOVE),
909#endif
910 FLAG_GENERIC(MS_NOATIME),
911 FLAG_GENERIC(MS_NODEV),
912 FLAG_GENERIC(MS_NODIRATIME),
913 FLAG_GENERIC(MS_NOEXEC),
914 FLAG_GENERIC(MS_NOSUID),
915 FLAG_GENERIC(MS_RDONLY),
916#ifdef MS_RELATIME
917 FLAG_GENERIC(MS_RELATIME),
918#endif
919 FLAG_GENERIC(MS_REMOUNT),
920 FLAG_GENERIC(MS_SYNCHRONOUS),
921 FLAG_END,
922};
923
924UNUSED static struct flags umount2_flags[] = {
925#ifdef MNT_FORCE
926 FLAG_GENERIC(MNT_FORCE),
927#endif
928#ifdef MNT_DETACH
929 FLAG_GENERIC(MNT_DETACH),
930#endif
931#ifdef MNT_EXPIRE
932 FLAG_GENERIC(MNT_EXPIRE),
933#endif
934 FLAG_END,
935};
936
937UNUSED static struct flags mmap_prot_flags[] = {
938 FLAG_GENERIC(PROT_NONE),
939 FLAG_GENERIC(PROT_EXEC),
940 FLAG_GENERIC(PROT_READ),
941 FLAG_GENERIC(PROT_WRITE),
Paul Brook9e0b74a2010-06-16 13:03:51 +0100942 FLAG_TARGET(PROT_SEM),
943 FLAG_GENERIC(PROT_GROWSDOWN),
944 FLAG_GENERIC(PROT_GROWSUP),
Mika Westerberg74d753a2009-04-07 16:57:29 +0300945 FLAG_END,
946};
947
948UNUSED static struct flags mmap_flags[] = {
949 FLAG_TARGET(MAP_SHARED),
950 FLAG_TARGET(MAP_PRIVATE),
951 FLAG_TARGET(MAP_ANONYMOUS),
952 FLAG_TARGET(MAP_DENYWRITE),
953 FLAG_TARGET(MAP_FIXED),
954 FLAG_TARGET(MAP_GROWSDOWN),
Mike Frysinger906c1b82011-02-07 01:05:52 -0500955 FLAG_TARGET(MAP_EXECUTABLE),
Mika Westerberg74d753a2009-04-07 16:57:29 +0300956#ifdef MAP_LOCKED
957 FLAG_TARGET(MAP_LOCKED),
958#endif
959#ifdef MAP_NONBLOCK
960 FLAG_TARGET(MAP_NONBLOCK),
961#endif
962 FLAG_TARGET(MAP_NORESERVE),
963#ifdef MAP_POPULATE
964 FLAG_TARGET(MAP_POPULATE),
965#endif
Mike Frysinger906c1b82011-02-07 01:05:52 -0500966#ifdef TARGET_MAP_UNINITIALIZED
967 FLAG_TARGET(MAP_UNINITIALIZED),
968#endif
Mika Westerberg74d753a2009-04-07 16:57:29 +0300969 FLAG_END,
970};
971
Laurent Vivier608e5592011-04-07 00:25:32 +0200972UNUSED static struct flags clone_flags[] = {
973 FLAG_GENERIC(CLONE_VM),
974 FLAG_GENERIC(CLONE_FS),
975 FLAG_GENERIC(CLONE_FILES),
976 FLAG_GENERIC(CLONE_SIGHAND),
977 FLAG_GENERIC(CLONE_PTRACE),
978 FLAG_GENERIC(CLONE_VFORK),
979 FLAG_GENERIC(CLONE_PARENT),
980 FLAG_GENERIC(CLONE_THREAD),
981 FLAG_GENERIC(CLONE_NEWNS),
982 FLAG_GENERIC(CLONE_SYSVSEM),
983 FLAG_GENERIC(CLONE_SETTLS),
984 FLAG_GENERIC(CLONE_PARENT_SETTID),
985 FLAG_GENERIC(CLONE_CHILD_CLEARTID),
986 FLAG_GENERIC(CLONE_DETACHED),
987 FLAG_GENERIC(CLONE_UNTRACED),
988 FLAG_GENERIC(CLONE_CHILD_SETTID),
Stefan Weil6f11f012011-04-27 10:44:38 +0200989#if defined(CLONE_NEWUTS)
Laurent Vivier608e5592011-04-07 00:25:32 +0200990 FLAG_GENERIC(CLONE_NEWUTS),
Stefan Weil6f11f012011-04-27 10:44:38 +0200991#endif
992#if defined(CLONE_NEWIPC)
Laurent Vivier608e5592011-04-07 00:25:32 +0200993 FLAG_GENERIC(CLONE_NEWIPC),
Stefan Weil6f11f012011-04-27 10:44:38 +0200994#endif
995#if defined(CLONE_NEWUSER)
Laurent Vivier608e5592011-04-07 00:25:32 +0200996 FLAG_GENERIC(CLONE_NEWUSER),
Stefan Weil6f11f012011-04-27 10:44:38 +0200997#endif
998#if defined(CLONE_NEWPID)
Laurent Vivier608e5592011-04-07 00:25:32 +0200999 FLAG_GENERIC(CLONE_NEWPID),
Stefan Weil6f11f012011-04-27 10:44:38 +02001000#endif
1001#if defined(CLONE_NEWNET)
Laurent Vivier608e5592011-04-07 00:25:32 +02001002 FLAG_GENERIC(CLONE_NEWNET),
Stefan Weil6f11f012011-04-27 10:44:38 +02001003#endif
1004#if defined(CLONE_IO)
Laurent Vivier608e5592011-04-07 00:25:32 +02001005 FLAG_GENERIC(CLONE_IO),
Stefan Weil6f11f012011-04-27 10:44:38 +02001006#endif
Laurent Vivier608e5592011-04-07 00:25:32 +02001007 FLAG_END,
1008};
1009
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02001010UNUSED static struct flags msg_flags[] = {
1011 /* send */
1012 FLAG_GENERIC(MSG_CONFIRM),
1013 FLAG_GENERIC(MSG_DONTROUTE),
1014 FLAG_GENERIC(MSG_DONTWAIT),
1015 FLAG_GENERIC(MSG_EOR),
1016 FLAG_GENERIC(MSG_MORE),
1017 FLAG_GENERIC(MSG_NOSIGNAL),
1018 FLAG_GENERIC(MSG_OOB),
1019 /* recv */
1020 FLAG_GENERIC(MSG_CMSG_CLOEXEC),
1021 FLAG_GENERIC(MSG_ERRQUEUE),
1022 FLAG_GENERIC(MSG_PEEK),
1023 FLAG_GENERIC(MSG_TRUNC),
1024 FLAG_GENERIC(MSG_WAITALL),
1025 /* recvmsg */
1026 FLAG_GENERIC(MSG_CTRUNC),
1027 FLAG_END,
1028};
1029
Jim Wilsond42744f2019-06-28 12:43:35 +02001030UNUSED static struct flags statx_flags[] = {
1031#ifdef AT_EMPTY_PATH
1032 FLAG_GENERIC(AT_EMPTY_PATH),
1033#endif
1034#ifdef AT_NO_AUTOMOUNT
1035 FLAG_GENERIC(AT_NO_AUTOMOUNT),
1036#endif
1037#ifdef AT_SYMLINK_NOFOLLOW
1038 FLAG_GENERIC(AT_SYMLINK_NOFOLLOW),
1039#endif
1040#ifdef AT_STATX_SYNC_AS_STAT
1041 FLAG_GENERIC(AT_STATX_SYNC_AS_STAT),
1042#endif
1043#ifdef AT_STATX_FORCE_SYNC
1044 FLAG_GENERIC(AT_STATX_FORCE_SYNC),
1045#endif
1046#ifdef AT_STATX_DONT_SYNC
1047 FLAG_GENERIC(AT_STATX_DONT_SYNC),
1048#endif
1049 FLAG_END,
1050};
1051
1052UNUSED static struct flags statx_mask[] = {
1053/* This must come first, because it includes everything. */
1054#ifdef STATX_ALL
1055 FLAG_GENERIC(STATX_ALL),
1056#endif
1057/* This must come second; it includes everything except STATX_BTIME. */
1058#ifdef STATX_BASIC_STATS
1059 FLAG_GENERIC(STATX_BASIC_STATS),
1060#endif
1061#ifdef STATX_TYPE
1062 FLAG_GENERIC(STATX_TYPE),
1063#endif
1064#ifdef STATX_MODE
1065 FLAG_GENERIC(STATX_MODE),
1066#endif
1067#ifdef STATX_NLINK
1068 FLAG_GENERIC(STATX_NLINK),
1069#endif
1070#ifdef STATX_UID
1071 FLAG_GENERIC(STATX_UID),
1072#endif
1073#ifdef STATX_GID
1074 FLAG_GENERIC(STATX_GID),
1075#endif
1076#ifdef STATX_ATIME
1077 FLAG_GENERIC(STATX_ATIME),
1078#endif
1079#ifdef STATX_MTIME
1080 FLAG_GENERIC(STATX_MTIME),
1081#endif
1082#ifdef STATX_CTIME
1083 FLAG_GENERIC(STATX_CTIME),
1084#endif
1085#ifdef STATX_INO
1086 FLAG_GENERIC(STATX_INO),
1087#endif
1088#ifdef STATX_SIZE
1089 FLAG_GENERIC(STATX_SIZE),
1090#endif
1091#ifdef STATX_BLOCKS
1092 FLAG_GENERIC(STATX_BLOCKS),
1093#endif
1094#ifdef STATX_BTIME
1095 FLAG_GENERIC(STATX_BTIME),
1096#endif
1097 FLAG_END,
1098};
1099
Mika Westerberg74d753a2009-04-07 16:57:29 +03001100/*
1101 * print_xxx utility functions. These are used to print syscall
1102 * parameters in certain format. All of these have parameter
1103 * named 'last'. This parameter is used to add comma to output
1104 * when last == 0.
1105 */
1106
1107static const char *
1108get_comma(int last)
1109{
1110 return ((last) ? "" : ",");
1111}
1112
1113static void
Laurent Vivierd2ee72a2011-02-15 21:10:44 +01001114print_flags(const struct flags *f, abi_long flags, int last)
Mika Westerberg74d753a2009-04-07 16:57:29 +03001115{
1116 const char *sep = "";
Mika Westerberg74d753a2009-04-07 16:57:29 +03001117 int n;
1118
Mika Westerberg74d753a2009-04-07 16:57:29 +03001119 if ((flags == 0) && (f->f_value == 0)) {
Josh Kunz4b25a502020-02-03 18:54:14 -08001120 qemu_log("%s%s", f->f_string, get_comma(last));
Mika Westerberg74d753a2009-04-07 16:57:29 +03001121 return;
1122 }
1123 for (n = 0; f->f_string != NULL; f++) {
1124 if ((f->f_value != 0) && ((flags & f->f_value) == f->f_value)) {
Josh Kunz4b25a502020-02-03 18:54:14 -08001125 qemu_log("%s%s", sep, f->f_string);
Mika Westerberg74d753a2009-04-07 16:57:29 +03001126 flags &= ~f->f_value;
1127 sep = "|";
1128 n++;
1129 }
1130 }
1131
1132 if (n > 0) {
1133 /* print rest of the flags as numeric */
1134 if (flags != 0) {
Josh Kunz4b25a502020-02-03 18:54:14 -08001135 qemu_log("%s%#x%s", sep, (unsigned int)flags, get_comma(last));
Mika Westerberg74d753a2009-04-07 16:57:29 +03001136 } else {
Josh Kunz4b25a502020-02-03 18:54:14 -08001137 qemu_log("%s", get_comma(last));
Mika Westerberg74d753a2009-04-07 16:57:29 +03001138 }
1139 } else {
1140 /* no string version of flags found, print them in hex then */
Josh Kunz4b25a502020-02-03 18:54:14 -08001141 qemu_log("%#x%s", (unsigned int)flags, get_comma(last));
Mika Westerberg74d753a2009-04-07 16:57:29 +03001142 }
1143}
1144
1145static void
Laurent Vivierd2ee72a2011-02-15 21:10:44 +01001146print_at_dirfd(abi_long dirfd, int last)
Mika Westerberg74d753a2009-04-07 16:57:29 +03001147{
Mika Westerberg74d753a2009-04-07 16:57:29 +03001148#ifdef AT_FDCWD
1149 if (dirfd == AT_FDCWD) {
Josh Kunz4b25a502020-02-03 18:54:14 -08001150 qemu_log("AT_FDCWD%s", get_comma(last));
Mika Westerberg74d753a2009-04-07 16:57:29 +03001151 return;
1152 }
1153#endif
Josh Kunz4b25a502020-02-03 18:54:14 -08001154 qemu_log("%d%s", (int)dirfd, get_comma(last));
Mika Westerberg74d753a2009-04-07 16:57:29 +03001155}
1156
1157static void
Laurent Vivierd2ee72a2011-02-15 21:10:44 +01001158print_file_mode(abi_long mode, int last)
Mika Westerberg74d753a2009-04-07 16:57:29 +03001159{
1160 const char *sep = "";
1161 const struct flags *m;
Mika Westerberg74d753a2009-04-07 16:57:29 +03001162
1163 for (m = &mode_flags[0]; m->f_string != NULL; m++) {
1164 if ((m->f_value & mode) == m->f_value) {
Josh Kunz4b25a502020-02-03 18:54:14 -08001165 qemu_log("%s%s", m->f_string, sep);
Mika Westerberg74d753a2009-04-07 16:57:29 +03001166 sep = "|";
1167 mode &= ~m->f_value;
1168 break;
1169 }
1170 }
1171
1172 mode &= ~S_IFMT;
1173 /* print rest of the mode as octal */
1174 if (mode != 0)
Josh Kunz4b25a502020-02-03 18:54:14 -08001175 qemu_log("%s%#o", sep, (unsigned int)mode);
Mika Westerberg74d753a2009-04-07 16:57:29 +03001176
Josh Kunz4b25a502020-02-03 18:54:14 -08001177 qemu_log("%s", get_comma(last));
Mika Westerberg74d753a2009-04-07 16:57:29 +03001178}
1179
1180static void
Laurent Vivierd2ee72a2011-02-15 21:10:44 +01001181print_open_flags(abi_long flags, int last)
Mika Westerberg74d753a2009-04-07 16:57:29 +03001182{
Mika Westerberg74d753a2009-04-07 16:57:29 +03001183 print_flags(open_access_flags, flags & TARGET_O_ACCMODE, 1);
1184 flags &= ~TARGET_O_ACCMODE;
1185 if (flags == 0) {
Josh Kunz4b25a502020-02-03 18:54:14 -08001186 qemu_log("%s", get_comma(last));
Mika Westerberg74d753a2009-04-07 16:57:29 +03001187 return;
1188 }
Josh Kunz4b25a502020-02-03 18:54:14 -08001189 qemu_log("|");
Mika Westerberg74d753a2009-04-07 16:57:29 +03001190 print_flags(open_flags, flags, last);
1191}
1192
1193static void
1194print_syscall_prologue(const struct syscallname *sc)
1195{
Josh Kunz4b25a502020-02-03 18:54:14 -08001196 qemu_log("%s(", sc->name);
Mika Westerberg74d753a2009-04-07 16:57:29 +03001197}
1198
1199/*ARGSUSED*/
1200static void
1201print_syscall_epilogue(const struct syscallname *sc)
1202{
1203 (void)sc;
Josh Kunz4b25a502020-02-03 18:54:14 -08001204 qemu_log(")");
Mika Westerberg74d753a2009-04-07 16:57:29 +03001205}
1206
1207static void
1208print_string(abi_long addr, int last)
1209{
1210 char *s;
1211
1212 if ((s = lock_user_string(addr)) != NULL) {
Josh Kunz4b25a502020-02-03 18:54:14 -08001213 qemu_log("\"%s\"%s", s, get_comma(last));
Mika Westerberg74d753a2009-04-07 16:57:29 +03001214 unlock_user(s, addr, 0);
1215 } else {
1216 /* can't get string out of it, so print it as pointer */
1217 print_pointer(addr, last);
1218 }
1219}
1220
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02001221#define MAX_PRINT_BUF 40
1222static void
1223print_buf(abi_long addr, abi_long len, int last)
1224{
1225 uint8_t *s;
1226 int i;
1227
1228 s = lock_user(VERIFY_READ, addr, len, 1);
1229 if (s) {
Josh Kunz4b25a502020-02-03 18:54:14 -08001230 qemu_log("\"");
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02001231 for (i = 0; i < MAX_PRINT_BUF && i < len; i++) {
1232 if (isprint(s[i])) {
Josh Kunz4b25a502020-02-03 18:54:14 -08001233 qemu_log("%c", s[i]);
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02001234 } else {
Josh Kunz4b25a502020-02-03 18:54:14 -08001235 qemu_log("\\%o", s[i]);
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02001236 }
1237 }
Josh Kunz4b25a502020-02-03 18:54:14 -08001238 qemu_log("\"");
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02001239 if (i != len) {
Josh Kunz4b25a502020-02-03 18:54:14 -08001240 qemu_log("...");
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02001241 }
1242 if (!last) {
Josh Kunz4b25a502020-02-03 18:54:14 -08001243 qemu_log(",");
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02001244 }
1245 unlock_user(s, addr, 0);
1246 } else {
1247 print_pointer(addr, last);
1248 }
1249}
1250
Mika Westerberg74d753a2009-04-07 16:57:29 +03001251/*
1252 * Prints out raw parameter using given format. Caller needs
1253 * to do byte swapping if needed.
1254 */
1255static void
1256print_raw_param(const char *fmt, abi_long param, int last)
1257{
1258 char format[64];
1259
1260 (void) snprintf(format, sizeof (format), "%s%s", fmt, get_comma(last));
Josh Kunz4b25a502020-02-03 18:54:14 -08001261 qemu_log(format, param);
Mika Westerberg74d753a2009-04-07 16:57:29 +03001262}
1263
1264static void
1265print_pointer(abi_long p, int last)
1266{
1267 if (p == 0)
Josh Kunz4b25a502020-02-03 18:54:14 -08001268 qemu_log("NULL%s", get_comma(last));
Mika Westerberg74d753a2009-04-07 16:57:29 +03001269 else
Josh Kunz4b25a502020-02-03 18:54:14 -08001270 qemu_log("0x" TARGET_ABI_FMT_lx "%s", p, get_comma(last));
Mika Westerberg74d753a2009-04-07 16:57:29 +03001271}
1272
1273/*
1274 * Reads 32-bit (int) number from guest address space from
1275 * address 'addr' and prints it.
1276 */
1277static void
1278print_number(abi_long addr, int last)
1279{
1280 if (addr == 0) {
Josh Kunz4b25a502020-02-03 18:54:14 -08001281 qemu_log("NULL%s", get_comma(last));
Mika Westerberg74d753a2009-04-07 16:57:29 +03001282 } else {
1283 int num;
1284
1285 get_user_s32(num, addr);
Josh Kunz4b25a502020-02-03 18:54:14 -08001286 qemu_log("[%d]%s", num, get_comma(last));
Mika Westerberg74d753a2009-04-07 16:57:29 +03001287 }
1288}
1289
1290static void
1291print_timeval(abi_ulong tv_addr, int last)
1292{
1293 if( tv_addr ) {
1294 struct target_timeval *tv;
1295
1296 tv = lock_user(VERIFY_READ, tv_addr, sizeof(*tv), 1);
Philippe Mathieu-Daudé8f930892019-10-21 13:48:49 +02001297 if (!tv) {
1298 print_pointer(tv_addr, last);
Mika Westerberg74d753a2009-04-07 16:57:29 +03001299 return;
Philippe Mathieu-Daudé8f930892019-10-21 13:48:49 +02001300 }
Josh Kunz4b25a502020-02-03 18:54:14 -08001301 qemu_log("{" TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld "}%s",
Laurent Vivier910ee4e2012-12-31 09:45:06 +00001302 tswapal(tv->tv_sec), tswapal(tv->tv_usec), get_comma(last));
Mika Westerberg74d753a2009-04-07 16:57:29 +03001303 unlock_user(tv, tv_addr, 0);
1304 } else
Josh Kunz4b25a502020-02-03 18:54:14 -08001305 qemu_log("NULL%s", get_comma(last));
Mika Westerberg74d753a2009-04-07 16:57:29 +03001306}
1307
Philippe Mathieu-Daudé6d33e032019-10-21 13:48:50 +02001308static void
1309print_timezone(abi_ulong tz_addr, int last)
1310{
1311 if (tz_addr) {
1312 struct target_timezone *tz;
1313
1314 tz = lock_user(VERIFY_READ, tz_addr, sizeof(*tz), 1);
1315 if (!tz) {
1316 print_pointer(tz_addr, last);
1317 return;
1318 }
Josh Kunz4b25a502020-02-03 18:54:14 -08001319 qemu_log("{%d,%d}%s", tswap32(tz->tz_minuteswest),
Philippe Mathieu-Daudé6d33e032019-10-21 13:48:50 +02001320 tswap32(tz->tz_dsttime), get_comma(last));
1321 unlock_user(tz, tz_addr, 0);
1322 } else {
Josh Kunz4b25a502020-02-03 18:54:14 -08001323 qemu_log("NULL%s", get_comma(last));
Philippe Mathieu-Daudé6d33e032019-10-21 13:48:50 +02001324 }
1325}
1326
Mika Westerberg74d753a2009-04-07 16:57:29 +03001327#undef UNUSED
1328
1329#ifdef TARGET_NR_accept
1330static void
1331print_accept(const struct syscallname *name,
1332 abi_long arg0, abi_long arg1, abi_long arg2,
1333 abi_long arg3, abi_long arg4, abi_long arg5)
1334{
1335 print_syscall_prologue(name);
Laurent Vivierd2ee72a2011-02-15 21:10:44 +01001336 print_raw_param("%d", arg0, 0);
Mika Westerberg74d753a2009-04-07 16:57:29 +03001337 print_pointer(arg1, 0);
1338 print_number(arg2, 1);
1339 print_syscall_epilogue(name);
1340}
1341#endif
1342
1343#ifdef TARGET_NR_access
1344static void
1345print_access(const struct syscallname *name,
1346 abi_long arg0, abi_long arg1, abi_long arg2,
1347 abi_long arg3, abi_long arg4, abi_long arg5)
1348{
1349 print_syscall_prologue(name);
1350 print_string(arg0, 0);
1351 print_flags(access_flags, arg1, 1);
1352 print_syscall_epilogue(name);
1353}
1354#endif
1355
1356#ifdef TARGET_NR_brk
1357static void
1358print_brk(const struct syscallname *name,
1359 abi_long arg0, abi_long arg1, abi_long arg2,
1360 abi_long arg3, abi_long arg4, abi_long arg5)
1361{
1362 print_syscall_prologue(name);
1363 print_pointer(arg0, 1);
1364 print_syscall_epilogue(name);
1365}
1366#endif
1367
1368#ifdef TARGET_NR_chdir
1369static void
1370print_chdir(const struct syscallname *name,
1371 abi_long arg0, abi_long arg1, abi_long arg2,
1372 abi_long arg3, abi_long arg4, abi_long arg5)
1373{
1374 print_syscall_prologue(name);
1375 print_string(arg0, 1);
1376 print_syscall_epilogue(name);
1377}
1378#endif
1379
Helge Deller1b7695f2019-02-27 20:11:15 +01001380#ifdef TARGET_NR_chroot
1381static void
1382print_chroot(const struct syscallname *name,
1383 abi_long arg0, abi_long arg1, abi_long arg2,
1384 abi_long arg3, abi_long arg4, abi_long arg5)
1385{
1386 print_syscall_prologue(name);
1387 print_string(arg0, 1);
1388 print_syscall_epilogue(name);
1389}
1390#endif
1391
Mika Westerberg74d753a2009-04-07 16:57:29 +03001392#ifdef TARGET_NR_chmod
1393static void
1394print_chmod(const struct syscallname *name,
1395 abi_long arg0, abi_long arg1, abi_long arg2,
1396 abi_long arg3, abi_long arg4, abi_long arg5)
1397{
1398 print_syscall_prologue(name);
1399 print_string(arg0, 0);
1400 print_file_mode(arg1, 1);
1401 print_syscall_epilogue(name);
1402}
1403#endif
1404
Aleksandar Markovic38860a02016-10-10 13:23:29 +02001405#ifdef TARGET_NR_clock_adjtime
1406static void
1407print_clock_adjtime(const struct syscallname *name,
1408 abi_long arg0, abi_long arg1, abi_long arg2,
1409 abi_long arg3, abi_long arg4, abi_long arg5)
1410{
1411 print_syscall_prologue(name);
1412 print_clockid(arg0, 0);
1413 print_pointer(arg1, 1);
1414 print_syscall_epilogue(name);
1415}
1416#endif
1417
Laurent Vivier608e5592011-04-07 00:25:32 +02001418#ifdef TARGET_NR_clone
Laurent Vivier84bd8282016-06-11 02:19:47 +02001419static void do_print_clone(unsigned int flags, abi_ulong newsp,
1420 abi_ulong parent_tidptr, target_ulong newtls,
1421 abi_ulong child_tidptr)
1422{
1423 print_flags(clone_flags, flags, 0);
1424 print_raw_param("child_stack=0x" TARGET_ABI_FMT_lx, newsp, 0);
1425 print_raw_param("parent_tidptr=0x" TARGET_ABI_FMT_lx, parent_tidptr, 0);
1426 print_raw_param("tls=0x" TARGET_ABI_FMT_lx, newtls, 0);
1427 print_raw_param("child_tidptr=0x" TARGET_ABI_FMT_lx, child_tidptr, 1);
1428}
1429
Laurent Vivier608e5592011-04-07 00:25:32 +02001430static void
1431print_clone(const struct syscallname *name,
Laurent Vivier84bd8282016-06-11 02:19:47 +02001432 abi_long arg1, abi_long arg2, abi_long arg3,
1433 abi_long arg4, abi_long arg5, abi_long arg6)
Laurent Vivier608e5592011-04-07 00:25:32 +02001434{
1435 print_syscall_prologue(name);
Laurent Vivier84bd8282016-06-11 02:19:47 +02001436#if defined(TARGET_MICROBLAZE)
1437 do_print_clone(arg1, arg2, arg4, arg6, arg5);
1438#elif defined(TARGET_CLONE_BACKWARDS)
1439 do_print_clone(arg1, arg2, arg3, arg4, arg5);
1440#elif defined(TARGET_CLONE_BACKWARDS2)
1441 do_print_clone(arg2, arg1, arg3, arg5, arg4);
Laurent Vivier608e5592011-04-07 00:25:32 +02001442#else
Laurent Vivier84bd8282016-06-11 02:19:47 +02001443 do_print_clone(arg1, arg2, arg3, arg5, arg4);
Laurent Vivier608e5592011-04-07 00:25:32 +02001444#endif
1445 print_syscall_epilogue(name);
1446}
1447#endif
1448
Mika Westerberg74d753a2009-04-07 16:57:29 +03001449#ifdef TARGET_NR_creat
1450static void
1451print_creat(const struct syscallname *name,
1452 abi_long arg0, abi_long arg1, abi_long arg2,
1453 abi_long arg3, abi_long arg4, abi_long arg5)
1454{
1455 print_syscall_prologue(name);
1456 print_string(arg0, 0);
1457 print_file_mode(arg1, 1);
1458 print_syscall_epilogue(name);
1459}
1460#endif
1461
1462#ifdef TARGET_NR_execv
1463static void
1464print_execv(const struct syscallname *name,
1465 abi_long arg0, abi_long arg1, abi_long arg2,
1466 abi_long arg3, abi_long arg4, abi_long arg5)
1467{
1468 print_syscall_prologue(name);
1469 print_string(arg0, 0);
Laurent Vivierd2ee72a2011-02-15 21:10:44 +01001470 print_raw_param("0x" TARGET_ABI_FMT_lx, arg1, 1);
Mika Westerberg74d753a2009-04-07 16:57:29 +03001471 print_syscall_epilogue(name);
1472}
1473#endif
1474
1475#ifdef TARGET_NR_faccessat
1476static void
1477print_faccessat(const struct syscallname *name,
1478 abi_long arg0, abi_long arg1, abi_long arg2,
1479 abi_long arg3, abi_long arg4, abi_long arg5)
1480{
1481 print_syscall_prologue(name);
1482 print_at_dirfd(arg0, 0);
1483 print_string(arg1, 0);
1484 print_flags(access_flags, arg2, 0);
1485 print_flags(at_file_flags, arg3, 1);
1486 print_syscall_epilogue(name);
1487}
1488#endif
1489
1490#ifdef TARGET_NR_fchmodat
1491static void
1492print_fchmodat(const struct syscallname *name,
1493 abi_long arg0, abi_long arg1, abi_long arg2,
1494 abi_long arg3, abi_long arg4, abi_long arg5)
1495{
1496 print_syscall_prologue(name);
1497 print_at_dirfd(arg0, 0);
1498 print_string(arg1, 0);
1499 print_file_mode(arg2, 0);
1500 print_flags(at_file_flags, arg3, 1);
1501 print_syscall_epilogue(name);
1502}
1503#endif
1504
1505#ifdef TARGET_NR_fchownat
1506static void
1507print_fchownat(const struct syscallname *name,
1508 abi_long arg0, abi_long arg1, abi_long arg2,
1509 abi_long arg3, abi_long arg4, abi_long arg5)
1510{
1511 print_syscall_prologue(name);
1512 print_at_dirfd(arg0, 0);
1513 print_string(arg1, 0);
Laurent Vivierd2ee72a2011-02-15 21:10:44 +01001514 print_raw_param("%d", arg2, 0);
1515 print_raw_param("%d", arg3, 0);
Mika Westerberg74d753a2009-04-07 16:57:29 +03001516 print_flags(at_file_flags, arg4, 1);
1517 print_syscall_epilogue(name);
1518}
1519#endif
1520
1521#if defined(TARGET_NR_fcntl) || defined(TARGET_NR_fcntl64)
1522static void
1523print_fcntl(const struct syscallname *name,
1524 abi_long arg0, abi_long arg1, abi_long arg2,
1525 abi_long arg3, abi_long arg4, abi_long arg5)
1526{
1527 print_syscall_prologue(name);
Laurent Vivierd2ee72a2011-02-15 21:10:44 +01001528 print_raw_param("%d", arg0, 0);
Laurent Vivierd95ec142012-12-31 21:00:11 +01001529 switch(arg1) {
1530 case TARGET_F_DUPFD:
Josh Kunz4b25a502020-02-03 18:54:14 -08001531 qemu_log("F_DUPFD,");
Laurent Vivierd95ec142012-12-31 21:00:11 +01001532 print_raw_param(TARGET_ABI_FMT_ld, arg2, 1);
1533 break;
1534 case TARGET_F_GETFD:
Josh Kunz4b25a502020-02-03 18:54:14 -08001535 qemu_log("F_GETFD");
Laurent Vivierd95ec142012-12-31 21:00:11 +01001536 break;
1537 case TARGET_F_SETFD:
Josh Kunz4b25a502020-02-03 18:54:14 -08001538 qemu_log("F_SETFD,");
Laurent Vivierd95ec142012-12-31 21:00:11 +01001539 print_raw_param(TARGET_ABI_FMT_ld, arg2, 1);
1540 break;
1541 case TARGET_F_GETFL:
Josh Kunz4b25a502020-02-03 18:54:14 -08001542 qemu_log("F_GETFL");
Laurent Vivierd95ec142012-12-31 21:00:11 +01001543 break;
1544 case TARGET_F_SETFL:
Josh Kunz4b25a502020-02-03 18:54:14 -08001545 qemu_log("F_SETFL,");
Laurent Vivierd95ec142012-12-31 21:00:11 +01001546 print_open_flags(arg2, 1);
1547 break;
1548 case TARGET_F_GETLK:
Josh Kunz4b25a502020-02-03 18:54:14 -08001549 qemu_log("F_GETLK,");
Laurent Vivierd95ec142012-12-31 21:00:11 +01001550 print_pointer(arg2, 1);
1551 break;
1552 case TARGET_F_SETLK:
Josh Kunz4b25a502020-02-03 18:54:14 -08001553 qemu_log("F_SETLK,");
Laurent Vivierd95ec142012-12-31 21:00:11 +01001554 print_pointer(arg2, 1);
1555 break;
1556 case TARGET_F_SETLKW:
Josh Kunz4b25a502020-02-03 18:54:14 -08001557 qemu_log("F_SETLKW,");
Laurent Vivierd95ec142012-12-31 21:00:11 +01001558 print_pointer(arg2, 1);
1559 break;
1560 case TARGET_F_GETOWN:
Josh Kunz4b25a502020-02-03 18:54:14 -08001561 qemu_log("F_GETOWN");
Laurent Vivierd95ec142012-12-31 21:00:11 +01001562 break;
1563 case TARGET_F_SETOWN:
Josh Kunz4b25a502020-02-03 18:54:14 -08001564 qemu_log("F_SETOWN,");
Laurent Vivierd95ec142012-12-31 21:00:11 +01001565 print_raw_param(TARGET_ABI_FMT_ld, arg2, 0);
1566 break;
1567 case TARGET_F_GETSIG:
Josh Kunz4b25a502020-02-03 18:54:14 -08001568 qemu_log("F_GETSIG");
Laurent Vivierd95ec142012-12-31 21:00:11 +01001569 break;
1570 case TARGET_F_SETSIG:
Josh Kunz4b25a502020-02-03 18:54:14 -08001571 qemu_log("F_SETSIG,");
Laurent Vivierd95ec142012-12-31 21:00:11 +01001572 print_raw_param(TARGET_ABI_FMT_ld, arg2, 0);
1573 break;
1574#if TARGET_ABI_BITS == 32
1575 case TARGET_F_GETLK64:
Josh Kunz4b25a502020-02-03 18:54:14 -08001576 qemu_log("F_GETLK64,");
Laurent Vivierd95ec142012-12-31 21:00:11 +01001577 print_pointer(arg2, 1);
1578 break;
1579 case TARGET_F_SETLK64:
Josh Kunz4b25a502020-02-03 18:54:14 -08001580 qemu_log("F_SETLK64,");
Laurent Vivierd95ec142012-12-31 21:00:11 +01001581 print_pointer(arg2, 1);
1582 break;
1583 case TARGET_F_SETLKW64:
Josh Kunz4b25a502020-02-03 18:54:14 -08001584 qemu_log("F_SETLKW64,");
Laurent Vivierd95ec142012-12-31 21:00:11 +01001585 print_pointer(arg2, 1);
1586 break;
1587#endif
1588 case TARGET_F_SETLEASE:
Josh Kunz4b25a502020-02-03 18:54:14 -08001589 qemu_log("F_SETLEASE,");
Laurent Vivierd95ec142012-12-31 21:00:11 +01001590 print_raw_param(TARGET_ABI_FMT_ld, arg2, 0);
1591 break;
1592 case TARGET_F_GETLEASE:
Josh Kunz4b25a502020-02-03 18:54:14 -08001593 qemu_log("F_GETLEASE");
Laurent Vivierd95ec142012-12-31 21:00:11 +01001594 break;
Peter Maydell7e3b92e2016-06-20 15:50:37 +01001595 case TARGET_F_SETPIPE_SZ:
Josh Kunz4b25a502020-02-03 18:54:14 -08001596 qemu_log("F_SETPIPE_SZ,");
Peter Maydell7e3b92e2016-06-20 15:50:37 +01001597 print_raw_param(TARGET_ABI_FMT_ld, arg2, 1);
1598 break;
1599 case TARGET_F_GETPIPE_SZ:
Josh Kunz4b25a502020-02-03 18:54:14 -08001600 qemu_log("F_GETPIPE_SZ");
Peter Maydell7e3b92e2016-06-20 15:50:37 +01001601 break;
Laurent Vivierd95ec142012-12-31 21:00:11 +01001602 case TARGET_F_DUPFD_CLOEXEC:
Josh Kunz4b25a502020-02-03 18:54:14 -08001603 qemu_log("F_DUPFD_CLOEXEC,");
Laurent Vivierd95ec142012-12-31 21:00:11 +01001604 print_raw_param(TARGET_ABI_FMT_ld, arg2, 1);
1605 break;
1606 case TARGET_F_NOTIFY:
Josh Kunz4b25a502020-02-03 18:54:14 -08001607 qemu_log("F_NOTIFY,");
Laurent Vivierd95ec142012-12-31 21:00:11 +01001608 print_raw_param(TARGET_ABI_FMT_ld, arg2, 0);
1609 break;
1610 default:
1611 print_raw_param(TARGET_ABI_FMT_ld, arg1, 0);
1612 print_pointer(arg2, 1);
1613 break;
1614 }
Mika Westerberg74d753a2009-04-07 16:57:29 +03001615 print_syscall_epilogue(name);
1616}
1617#define print_fcntl64 print_fcntl
1618#endif
1619
1620
1621#ifdef TARGET_NR_futimesat
1622static void
1623print_futimesat(const struct syscallname *name,
1624 abi_long arg0, abi_long arg1, abi_long arg2,
1625 abi_long arg3, abi_long arg4, abi_long arg5)
1626{
1627 print_syscall_prologue(name);
1628 print_at_dirfd(arg0, 0);
1629 print_string(arg1, 0);
1630 print_timeval(arg2, 0);
1631 print_timeval(arg2 + sizeof (struct target_timeval), 1);
1632 print_syscall_epilogue(name);
1633}
1634#endif
1635
Philippe Mathieu-Daudé0d2187c2019-10-21 13:48:51 +02001636#ifdef TARGET_NR_settimeofday
1637static void
1638print_settimeofday(const struct syscallname *name,
1639 abi_long arg0, abi_long arg1, abi_long arg2,
1640 abi_long arg3, abi_long arg4, abi_long arg5)
1641{
1642 print_syscall_prologue(name);
1643 print_timeval(arg0, 0);
1644 print_timezone(arg1, 1);
1645 print_syscall_epilogue(name);
1646}
1647#endif
1648
Mika Westerberg74d753a2009-04-07 16:57:29 +03001649#ifdef TARGET_NR_link
1650static void
1651print_link(const struct syscallname *name,
1652 abi_long arg0, abi_long arg1, abi_long arg2,
1653 abi_long arg3, abi_long arg4, abi_long arg5)
1654{
1655 print_syscall_prologue(name);
1656 print_string(arg0, 0);
1657 print_string(arg1, 1);
1658 print_syscall_epilogue(name);
1659}
1660#endif
1661
1662#ifdef TARGET_NR_linkat
1663static void
1664print_linkat(const struct syscallname *name,
1665 abi_long arg0, abi_long arg1, abi_long arg2,
1666 abi_long arg3, abi_long arg4, abi_long arg5)
1667{
1668 print_syscall_prologue(name);
1669 print_at_dirfd(arg0, 0);
1670 print_string(arg1, 0);
1671 print_at_dirfd(arg2, 0);
1672 print_string(arg3, 0);
1673 print_flags(at_file_flags, arg4, 1);
1674 print_syscall_epilogue(name);
1675}
1676#endif
1677
Laurent Vivier608e5592011-04-07 00:25:32 +02001678#ifdef TARGET_NR__llseek
1679static void
1680print__llseek(const struct syscallname *name,
1681 abi_long arg0, abi_long arg1, abi_long arg2,
1682 abi_long arg3, abi_long arg4, abi_long arg5)
1683{
1684 const char *whence = "UNKNOWN";
1685 print_syscall_prologue(name);
1686 print_raw_param("%d", arg0, 0);
1687 print_raw_param("%ld", arg1, 0);
1688 print_raw_param("%ld", arg2, 0);
1689 print_pointer(arg3, 0);
1690 switch(arg4) {
1691 case SEEK_SET: whence = "SEEK_SET"; break;
1692 case SEEK_CUR: whence = "SEEK_CUR"; break;
1693 case SEEK_END: whence = "SEEK_END"; break;
1694 }
Josh Kunz4b25a502020-02-03 18:54:14 -08001695 qemu_log("%s", whence);
Laurent Vivier608e5592011-04-07 00:25:32 +02001696 print_syscall_epilogue(name);
1697}
1698#endif
1699
Laurent Vivier8997d1b2016-06-11 02:19:46 +02001700#if defined(TARGET_NR_socket)
1701static void
1702print_socket(const struct syscallname *name,
1703 abi_long arg0, abi_long arg1, abi_long arg2,
1704 abi_long arg3, abi_long arg4, abi_long arg5)
1705{
1706 abi_ulong domain = arg0, type = arg1, protocol = arg2;
1707
1708 print_syscall_prologue(name);
1709 print_socket_domain(domain);
Josh Kunz4b25a502020-02-03 18:54:14 -08001710 qemu_log(",");
Laurent Vivier8997d1b2016-06-11 02:19:46 +02001711 print_socket_type(type);
Josh Kunz4b25a502020-02-03 18:54:14 -08001712 qemu_log(",");
Laurent Vivier8997d1b2016-06-11 02:19:46 +02001713 if (domain == AF_PACKET ||
1714 (domain == AF_INET && type == TARGET_SOCK_PACKET)) {
1715 protocol = tswap16(protocol);
1716 }
1717 print_socket_protocol(domain, type, protocol);
1718 print_syscall_epilogue(name);
1719}
1720
1721#endif
1722
Philippe Mathieu-Daudébb105402019-10-21 13:48:55 +02001723#if defined(TARGET_NR_socketcall) || defined(TARGET_NR_bind)
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02001724
Philippe Mathieu-Daudéd84fe1e2019-10-21 13:48:54 +02001725static void print_sockfd(abi_long sockfd, int last)
1726{
1727 print_raw_param(TARGET_ABI_FMT_ld, sockfd, last);
1728}
1729
1730#endif
1731
1732#if defined(TARGET_NR_socketcall)
1733
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02001734#define get_user_ualx(x, gaddr, idx) \
1735 get_user_ual(x, (gaddr) + (idx) * sizeof(abi_long))
1736
1737static void do_print_socket(const char *name, abi_long arg1)
1738{
1739 abi_ulong domain, type, protocol;
1740
1741 get_user_ualx(domain, arg1, 0);
1742 get_user_ualx(type, arg1, 1);
1743 get_user_ualx(protocol, arg1, 2);
Josh Kunz4b25a502020-02-03 18:54:14 -08001744 qemu_log("%s(", name);
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02001745 print_socket_domain(domain);
Josh Kunz4b25a502020-02-03 18:54:14 -08001746 qemu_log(",");
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02001747 print_socket_type(type);
Josh Kunz4b25a502020-02-03 18:54:14 -08001748 qemu_log(",");
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02001749 if (domain == AF_PACKET ||
1750 (domain == AF_INET && type == TARGET_SOCK_PACKET)) {
1751 protocol = tswap16(protocol);
1752 }
1753 print_socket_protocol(domain, type, protocol);
Josh Kunz4b25a502020-02-03 18:54:14 -08001754 qemu_log(")");
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02001755}
1756
1757static void do_print_sockaddr(const char *name, abi_long arg1)
1758{
1759 abi_ulong sockfd, addr, addrlen;
1760
1761 get_user_ualx(sockfd, arg1, 0);
1762 get_user_ualx(addr, arg1, 1);
1763 get_user_ualx(addrlen, arg1, 2);
1764
Josh Kunz4b25a502020-02-03 18:54:14 -08001765 qemu_log("%s(", name);
Philippe Mathieu-Daudéd84fe1e2019-10-21 13:48:54 +02001766 print_sockfd(sockfd, 0);
Philippe Mathieu-Daudé42b15d72019-10-21 13:48:56 +02001767 print_sockaddr(addr, addrlen, 0);
Josh Kunz4b25a502020-02-03 18:54:14 -08001768 qemu_log(")");
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02001769}
1770
1771static void do_print_listen(const char *name, abi_long arg1)
1772{
1773 abi_ulong sockfd, backlog;
1774
1775 get_user_ualx(sockfd, arg1, 0);
1776 get_user_ualx(backlog, arg1, 1);
1777
Josh Kunz4b25a502020-02-03 18:54:14 -08001778 qemu_log("%s(", name);
Philippe Mathieu-Daudéd84fe1e2019-10-21 13:48:54 +02001779 print_sockfd(sockfd, 0);
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02001780 print_raw_param(TARGET_ABI_FMT_ld, backlog, 1);
Josh Kunz4b25a502020-02-03 18:54:14 -08001781 qemu_log(")");
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02001782}
1783
1784static void do_print_socketpair(const char *name, abi_long arg1)
1785{
1786 abi_ulong domain, type, protocol, tab;
1787
1788 get_user_ualx(domain, arg1, 0);
1789 get_user_ualx(type, arg1, 1);
1790 get_user_ualx(protocol, arg1, 2);
1791 get_user_ualx(tab, arg1, 3);
1792
Josh Kunz4b25a502020-02-03 18:54:14 -08001793 qemu_log("%s(", name);
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02001794 print_socket_domain(domain);
Josh Kunz4b25a502020-02-03 18:54:14 -08001795 qemu_log(",");
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02001796 print_socket_type(type);
Josh Kunz4b25a502020-02-03 18:54:14 -08001797 qemu_log(",");
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02001798 print_socket_protocol(domain, type, protocol);
Josh Kunz4b25a502020-02-03 18:54:14 -08001799 qemu_log(",");
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02001800 print_raw_param(TARGET_ABI_FMT_lx, tab, 1);
Josh Kunz4b25a502020-02-03 18:54:14 -08001801 qemu_log(")");
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02001802}
1803
1804static void do_print_sendrecv(const char *name, abi_long arg1)
1805{
1806 abi_ulong sockfd, msg, len, flags;
1807
1808 get_user_ualx(sockfd, arg1, 0);
1809 get_user_ualx(msg, arg1, 1);
1810 get_user_ualx(len, arg1, 2);
1811 get_user_ualx(flags, arg1, 3);
1812
Josh Kunz4b25a502020-02-03 18:54:14 -08001813 qemu_log("%s(", name);
Philippe Mathieu-Daudéd84fe1e2019-10-21 13:48:54 +02001814 print_sockfd(sockfd, 0);
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02001815 print_buf(msg, len, 0);
1816 print_raw_param(TARGET_ABI_FMT_ld, len, 0);
1817 print_flags(msg_flags, flags, 1);
Josh Kunz4b25a502020-02-03 18:54:14 -08001818 qemu_log(")");
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02001819}
1820
1821static void do_print_msgaddr(const char *name, abi_long arg1)
1822{
1823 abi_ulong sockfd, msg, len, flags, addr, addrlen;
1824
1825 get_user_ualx(sockfd, arg1, 0);
1826 get_user_ualx(msg, arg1, 1);
1827 get_user_ualx(len, arg1, 2);
1828 get_user_ualx(flags, arg1, 3);
1829 get_user_ualx(addr, arg1, 4);
1830 get_user_ualx(addrlen, arg1, 5);
1831
Josh Kunz4b25a502020-02-03 18:54:14 -08001832 qemu_log("%s(", name);
Philippe Mathieu-Daudéd84fe1e2019-10-21 13:48:54 +02001833 print_sockfd(sockfd, 0);
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02001834 print_buf(msg, len, 0);
1835 print_raw_param(TARGET_ABI_FMT_ld, len, 0);
1836 print_flags(msg_flags, flags, 0);
Philippe Mathieu-Daudé42b15d72019-10-21 13:48:56 +02001837 print_sockaddr(addr, addrlen, 0);
Josh Kunz4b25a502020-02-03 18:54:14 -08001838 qemu_log(")");
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02001839}
1840
1841static void do_print_shutdown(const char *name, abi_long arg1)
1842{
1843 abi_ulong sockfd, how;
1844
1845 get_user_ualx(sockfd, arg1, 0);
1846 get_user_ualx(how, arg1, 1);
1847
Josh Kunz4b25a502020-02-03 18:54:14 -08001848 qemu_log("shutdown(");
Philippe Mathieu-Daudéd84fe1e2019-10-21 13:48:54 +02001849 print_sockfd(sockfd, 0);
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02001850 switch (how) {
1851 case SHUT_RD:
Josh Kunz4b25a502020-02-03 18:54:14 -08001852 qemu_log("SHUT_RD");
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02001853 break;
1854 case SHUT_WR:
Josh Kunz4b25a502020-02-03 18:54:14 -08001855 qemu_log("SHUT_WR");
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02001856 break;
1857 case SHUT_RDWR:
Josh Kunz4b25a502020-02-03 18:54:14 -08001858 qemu_log("SHUT_RDWR");
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02001859 break;
1860 default:
1861 print_raw_param(TARGET_ABI_FMT_ld, how, 1);
1862 break;
1863 }
Josh Kunz4b25a502020-02-03 18:54:14 -08001864 qemu_log(")");
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02001865}
1866
1867static void do_print_msg(const char *name, abi_long arg1)
1868{
1869 abi_ulong sockfd, msg, flags;
1870
1871 get_user_ualx(sockfd, arg1, 0);
1872 get_user_ualx(msg, arg1, 1);
1873 get_user_ualx(flags, arg1, 2);
1874
Josh Kunz4b25a502020-02-03 18:54:14 -08001875 qemu_log("%s(", name);
Philippe Mathieu-Daudéd84fe1e2019-10-21 13:48:54 +02001876 print_sockfd(sockfd, 0);
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02001877 print_pointer(msg, 0);
1878 print_flags(msg_flags, flags, 1);
Josh Kunz4b25a502020-02-03 18:54:14 -08001879 qemu_log(")");
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02001880}
1881
1882static void do_print_sockopt(const char *name, abi_long arg1)
1883{
1884 abi_ulong sockfd, level, optname, optval, optlen;
1885
1886 get_user_ualx(sockfd, arg1, 0);
1887 get_user_ualx(level, arg1, 1);
1888 get_user_ualx(optname, arg1, 2);
1889 get_user_ualx(optval, arg1, 3);
1890 get_user_ualx(optlen, arg1, 4);
1891
Josh Kunz4b25a502020-02-03 18:54:14 -08001892 qemu_log("%s(", name);
Philippe Mathieu-Daudéd84fe1e2019-10-21 13:48:54 +02001893 print_sockfd(sockfd, 0);
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02001894 switch (level) {
1895 case SOL_TCP:
Josh Kunz4b25a502020-02-03 18:54:14 -08001896 qemu_log("SOL_TCP,");
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02001897 print_raw_param(TARGET_ABI_FMT_ld, optname, 0);
1898 print_pointer(optval, 0);
1899 break;
1900 case SOL_IP:
Josh Kunz4b25a502020-02-03 18:54:14 -08001901 qemu_log("SOL_IP,");
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02001902 print_raw_param(TARGET_ABI_FMT_ld, optname, 0);
1903 print_pointer(optval, 0);
1904 break;
1905 case SOL_RAW:
Josh Kunz4b25a502020-02-03 18:54:14 -08001906 qemu_log("SOL_RAW,");
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02001907 print_raw_param(TARGET_ABI_FMT_ld, optname, 0);
1908 print_pointer(optval, 0);
1909 break;
1910 case TARGET_SOL_SOCKET:
Josh Kunz4b25a502020-02-03 18:54:14 -08001911 qemu_log("SOL_SOCKET,");
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02001912 switch (optname) {
1913 case TARGET_SO_DEBUG:
Josh Kunz4b25a502020-02-03 18:54:14 -08001914 qemu_log("SO_DEBUG,");
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02001915print_optint:
1916 print_number(optval, 0);
1917 break;
1918 case TARGET_SO_REUSEADDR:
Josh Kunz4b25a502020-02-03 18:54:14 -08001919 qemu_log("SO_REUSEADDR,");
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02001920 goto print_optint;
Yunqiang Su113a9dd2018-10-30 13:55:08 +01001921 case TARGET_SO_REUSEPORT:
Josh Kunz4b25a502020-02-03 18:54:14 -08001922 qemu_log("SO_REUSEPORT,");
Yunqiang Su113a9dd2018-10-30 13:55:08 +01001923 goto print_optint;
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02001924 case TARGET_SO_TYPE:
Josh Kunz4b25a502020-02-03 18:54:14 -08001925 qemu_log("SO_TYPE,");
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02001926 goto print_optint;
1927 case TARGET_SO_ERROR:
Josh Kunz4b25a502020-02-03 18:54:14 -08001928 qemu_log("SO_ERROR,");
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02001929 goto print_optint;
1930 case TARGET_SO_DONTROUTE:
Josh Kunz4b25a502020-02-03 18:54:14 -08001931 qemu_log("SO_DONTROUTE,");
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02001932 goto print_optint;
1933 case TARGET_SO_BROADCAST:
Josh Kunz4b25a502020-02-03 18:54:14 -08001934 qemu_log("SO_BROADCAST,");
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02001935 goto print_optint;
1936 case TARGET_SO_SNDBUF:
Josh Kunz4b25a502020-02-03 18:54:14 -08001937 qemu_log("SO_SNDBUF,");
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02001938 goto print_optint;
1939 case TARGET_SO_RCVBUF:
Josh Kunz4b25a502020-02-03 18:54:14 -08001940 qemu_log("SO_RCVBUF,");
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02001941 goto print_optint;
1942 case TARGET_SO_KEEPALIVE:
Josh Kunz4b25a502020-02-03 18:54:14 -08001943 qemu_log("SO_KEEPALIVE,");
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02001944 goto print_optint;
1945 case TARGET_SO_OOBINLINE:
Josh Kunz4b25a502020-02-03 18:54:14 -08001946 qemu_log("SO_OOBINLINE,");
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02001947 goto print_optint;
1948 case TARGET_SO_NO_CHECK:
Josh Kunz4b25a502020-02-03 18:54:14 -08001949 qemu_log("SO_NO_CHECK,");
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02001950 goto print_optint;
1951 case TARGET_SO_PRIORITY:
Josh Kunz4b25a502020-02-03 18:54:14 -08001952 qemu_log("SO_PRIORITY,");
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02001953 goto print_optint;
1954 case TARGET_SO_BSDCOMPAT:
Josh Kunz4b25a502020-02-03 18:54:14 -08001955 qemu_log("SO_BSDCOMPAT,");
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02001956 goto print_optint;
1957 case TARGET_SO_PASSCRED:
Josh Kunz4b25a502020-02-03 18:54:14 -08001958 qemu_log("SO_PASSCRED,");
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02001959 goto print_optint;
1960 case TARGET_SO_TIMESTAMP:
Josh Kunz4b25a502020-02-03 18:54:14 -08001961 qemu_log("SO_TIMESTAMP,");
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02001962 goto print_optint;
1963 case TARGET_SO_RCVLOWAT:
Josh Kunz4b25a502020-02-03 18:54:14 -08001964 qemu_log("SO_RCVLOWAT,");
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02001965 goto print_optint;
1966 case TARGET_SO_RCVTIMEO:
Josh Kunz4b25a502020-02-03 18:54:14 -08001967 qemu_log("SO_RCVTIMEO,");
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02001968 print_timeval(optval, 0);
1969 break;
1970 case TARGET_SO_SNDTIMEO:
Josh Kunz4b25a502020-02-03 18:54:14 -08001971 qemu_log("SO_SNDTIMEO,");
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02001972 print_timeval(optval, 0);
1973 break;
1974 case TARGET_SO_ATTACH_FILTER: {
1975 struct target_sock_fprog *fprog;
1976
Josh Kunz4b25a502020-02-03 18:54:14 -08001977 qemu_log("SO_ATTACH_FILTER,");
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02001978
1979 if (lock_user_struct(VERIFY_READ, fprog, optval, 0)) {
1980 struct target_sock_filter *filter;
Josh Kunz4b25a502020-02-03 18:54:14 -08001981 qemu_log("{");
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02001982 if (lock_user_struct(VERIFY_READ, filter,
1983 tswapal(fprog->filter), 0)) {
1984 int i;
1985 for (i = 0; i < tswap16(fprog->len) - 1; i++) {
Josh Kunz4b25a502020-02-03 18:54:14 -08001986 qemu_log("[%d]{0x%x,%d,%d,0x%x},",
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02001987 i, tswap16(filter[i].code),
1988 filter[i].jt, filter[i].jf,
1989 tswap32(filter[i].k));
1990 }
Josh Kunz4b25a502020-02-03 18:54:14 -08001991 qemu_log("[%d]{0x%x,%d,%d,0x%x}",
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02001992 i, tswap16(filter[i].code),
1993 filter[i].jt, filter[i].jf,
1994 tswap32(filter[i].k));
1995 } else {
Josh Kunz4b25a502020-02-03 18:54:14 -08001996 qemu_log(TARGET_ABI_FMT_lx, tswapal(fprog->filter));
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02001997 }
Josh Kunz4b25a502020-02-03 18:54:14 -08001998 qemu_log(",%d},", tswap16(fprog->len));
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02001999 unlock_user(fprog, optval, 0);
2000 } else {
2001 print_pointer(optval, 0);
2002 }
2003 break;
2004 }
2005 default:
2006 print_raw_param(TARGET_ABI_FMT_ld, optname, 0);
2007 print_pointer(optval, 0);
2008 break;
2009 }
2010 break;
2011 default:
2012 print_raw_param(TARGET_ABI_FMT_ld, level, 0);
2013 print_raw_param(TARGET_ABI_FMT_ld, optname, 0);
2014 print_pointer(optval, 0);
2015 break;
2016 }
2017 print_raw_param(TARGET_ABI_FMT_ld, optlen, 1);
Josh Kunz4b25a502020-02-03 18:54:14 -08002018 qemu_log(")");
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02002019}
2020
2021#define PRINT_SOCKOP(name, func) \
Aleksandar Markovicff71a452016-09-22 18:56:57 +02002022 [TARGET_SYS_##name] = { #name, func }
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02002023
2024static struct {
2025 const char *name;
2026 void (*print)(const char *, abi_long);
2027} scall[] = {
Aleksandar Markovicff71a452016-09-22 18:56:57 +02002028 PRINT_SOCKOP(SOCKET, do_print_socket),
2029 PRINT_SOCKOP(BIND, do_print_sockaddr),
2030 PRINT_SOCKOP(CONNECT, do_print_sockaddr),
2031 PRINT_SOCKOP(LISTEN, do_print_listen),
2032 PRINT_SOCKOP(ACCEPT, do_print_sockaddr),
2033 PRINT_SOCKOP(GETSOCKNAME, do_print_sockaddr),
2034 PRINT_SOCKOP(GETPEERNAME, do_print_sockaddr),
2035 PRINT_SOCKOP(SOCKETPAIR, do_print_socketpair),
2036 PRINT_SOCKOP(SEND, do_print_sendrecv),
2037 PRINT_SOCKOP(RECV, do_print_sendrecv),
2038 PRINT_SOCKOP(SENDTO, do_print_msgaddr),
2039 PRINT_SOCKOP(RECVFROM, do_print_msgaddr),
2040 PRINT_SOCKOP(SHUTDOWN, do_print_shutdown),
2041 PRINT_SOCKOP(SETSOCKOPT, do_print_sockopt),
2042 PRINT_SOCKOP(GETSOCKOPT, do_print_sockopt),
2043 PRINT_SOCKOP(SENDMSG, do_print_msg),
2044 PRINT_SOCKOP(RECVMSG, do_print_msg),
2045 PRINT_SOCKOP(ACCEPT4, NULL),
2046 PRINT_SOCKOP(RECVMMSG, NULL),
2047 PRINT_SOCKOP(SENDMMSG, NULL),
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02002048};
2049
2050static void
2051print_socketcall(const struct syscallname *name,
2052 abi_long arg0, abi_long arg1, abi_long arg2,
2053 abi_long arg3, abi_long arg4, abi_long arg5)
2054{
2055 if (arg0 >= 0 && arg0 < ARRAY_SIZE(scall) && scall[arg0].print) {
2056 scall[arg0].print(scall[arg0].name, arg1);
2057 return;
2058 }
2059 print_syscall_prologue(name);
2060 print_raw_param(TARGET_ABI_FMT_ld, arg0, 0);
2061 print_raw_param(TARGET_ABI_FMT_ld, arg1, 0);
2062 print_raw_param(TARGET_ABI_FMT_ld, arg2, 0);
2063 print_raw_param(TARGET_ABI_FMT_ld, arg3, 0);
2064 print_raw_param(TARGET_ABI_FMT_ld, arg4, 0);
2065 print_raw_param(TARGET_ABI_FMT_ld, arg5, 0);
2066 print_syscall_epilogue(name);
2067}
2068#endif
2069
Philippe Mathieu-Daudébb105402019-10-21 13:48:55 +02002070#if defined(TARGET_NR_bind)
2071static void
2072print_bind(const struct syscallname *name,
2073 abi_long arg0, abi_long arg1, abi_long arg2,
2074 abi_long arg3, abi_long arg4, abi_long arg5)
2075{
2076 print_syscall_prologue(name);
2077 print_sockfd(arg0, 0);
2078 print_sockaddr(arg1, arg2, 1);
2079 print_syscall_epilogue(name);
2080}
2081#endif
2082
Mika Westerberg74d753a2009-04-07 16:57:29 +03002083#if defined(TARGET_NR_stat) || defined(TARGET_NR_stat64) || \
2084 defined(TARGET_NR_lstat) || defined(TARGET_NR_lstat64)
2085static void
2086print_stat(const struct syscallname *name,
2087 abi_long arg0, abi_long arg1, abi_long arg2,
2088 abi_long arg3, abi_long arg4, abi_long arg5)
2089{
2090 print_syscall_prologue(name);
2091 print_string(arg0, 0);
2092 print_pointer(arg1, 1);
2093 print_syscall_epilogue(name);
2094}
2095#define print_lstat print_stat
2096#define print_stat64 print_stat
2097#define print_lstat64 print_stat
2098#endif
2099
2100#if defined(TARGET_NR_fstat) || defined(TARGET_NR_fstat64)
2101static void
2102print_fstat(const struct syscallname *name,
2103 abi_long arg0, abi_long arg1, abi_long arg2,
2104 abi_long arg3, abi_long arg4, abi_long arg5)
2105{
2106 print_syscall_prologue(name);
Laurent Vivierd2ee72a2011-02-15 21:10:44 +01002107 print_raw_param("%d", arg0, 0);
Mika Westerberg74d753a2009-04-07 16:57:29 +03002108 print_pointer(arg1, 1);
2109 print_syscall_epilogue(name);
2110}
2111#define print_fstat64 print_fstat
2112#endif
2113
2114#ifdef TARGET_NR_mkdir
2115static void
2116print_mkdir(const struct syscallname *name,
2117 abi_long arg0, abi_long arg1, abi_long arg2,
2118 abi_long arg3, abi_long arg4, abi_long arg5)
2119{
2120 print_syscall_prologue(name);
2121 print_string(arg0, 0);
2122 print_file_mode(arg1, 1);
2123 print_syscall_epilogue(name);
2124}
2125#endif
2126
2127#ifdef TARGET_NR_mkdirat
2128static void
2129print_mkdirat(const struct syscallname *name,
2130 abi_long arg0, abi_long arg1, abi_long arg2,
2131 abi_long arg3, abi_long arg4, abi_long arg5)
2132{
2133 print_syscall_prologue(name);
2134 print_at_dirfd(arg0, 0);
2135 print_string(arg1, 0);
2136 print_file_mode(arg2, 1);
2137 print_syscall_epilogue(name);
2138}
2139#endif
2140
Laurent Vivier4de596c2011-02-15 21:10:43 +01002141#ifdef TARGET_NR_rmdir
2142static void
2143print_rmdir(const struct syscallname *name,
2144 abi_long arg0, abi_long arg1, abi_long arg2,
2145 abi_long arg3, abi_long arg4, abi_long arg5)
2146{
2147 print_syscall_prologue(name);
2148 print_string(arg0, 0);
2149 print_syscall_epilogue(name);
2150}
2151#endif
2152
Laurent Vivier608e5592011-04-07 00:25:32 +02002153#ifdef TARGET_NR_rt_sigaction
2154static void
2155print_rt_sigaction(const struct syscallname *name,
2156 abi_long arg0, abi_long arg1, abi_long arg2,
2157 abi_long arg3, abi_long arg4, abi_long arg5)
2158{
2159 print_syscall_prologue(name);
2160 print_signal(arg0, 0);
2161 print_pointer(arg1, 0);
2162 print_pointer(arg2, 1);
2163 print_syscall_epilogue(name);
2164}
2165#endif
2166
2167#ifdef TARGET_NR_rt_sigprocmask
2168static void
2169print_rt_sigprocmask(const struct syscallname *name,
2170 abi_long arg0, abi_long arg1, abi_long arg2,
2171 abi_long arg3, abi_long arg4, abi_long arg5)
2172{
2173 const char *how = "UNKNOWN";
2174 print_syscall_prologue(name);
2175 switch(arg0) {
2176 case TARGET_SIG_BLOCK: how = "SIG_BLOCK"; break;
2177 case TARGET_SIG_UNBLOCK: how = "SIG_UNBLOCK"; break;
2178 case TARGET_SIG_SETMASK: how = "SIG_SETMASK"; break;
2179 }
Josh Kunz4b25a502020-02-03 18:54:14 -08002180 qemu_log("%s,", how);
Laurent Vivier608e5592011-04-07 00:25:32 +02002181 print_pointer(arg1, 0);
2182 print_pointer(arg2, 1);
2183 print_syscall_epilogue(name);
2184}
2185#endif
2186
Miloš Stojanović51622642017-05-15 16:59:42 +02002187#ifdef TARGET_NR_rt_sigqueueinfo
2188static void
2189print_rt_sigqueueinfo(const struct syscallname *name,
2190 abi_long arg0, abi_long arg1, abi_long arg2,
2191 abi_long arg3, abi_long arg4, abi_long arg5)
2192{
Miloš Stojanovićba9fcea2017-05-15 16:59:49 +02002193 void *p;
2194 target_siginfo_t uinfo;
2195
Miloš Stojanović51622642017-05-15 16:59:42 +02002196 print_syscall_prologue(name);
2197 print_raw_param("%d", arg0, 0);
2198 print_signal(arg1, 0);
Miloš Stojanovićba9fcea2017-05-15 16:59:49 +02002199 p = lock_user(VERIFY_READ, arg2, sizeof(target_siginfo_t), 1);
2200 if (p) {
2201 get_target_siginfo(&uinfo, p);
2202 print_siginfo(&uinfo);
2203
2204 unlock_user(p, arg2, 0);
2205 } else {
2206 print_pointer(arg2, 1);
2207 }
Miloš Stojanović51622642017-05-15 16:59:42 +02002208 print_syscall_epilogue(name);
2209}
2210#endif
2211
Miloš Stojanović243e0fe2017-05-15 16:59:47 +02002212#ifdef TARGET_NR_rt_tgsigqueueinfo
2213static void
2214print_rt_tgsigqueueinfo(const struct syscallname *name,
2215 abi_long arg0, abi_long arg1, abi_long arg2,
2216 abi_long arg3, abi_long arg4, abi_long arg5)
2217{
Miloš Stojanovićba9fcea2017-05-15 16:59:49 +02002218 void *p;
2219 target_siginfo_t uinfo;
2220
Miloš Stojanović243e0fe2017-05-15 16:59:47 +02002221 print_syscall_prologue(name);
2222 print_raw_param("%d", arg0, 0);
2223 print_raw_param("%d", arg1, 0);
2224 print_signal(arg2, 0);
Miloš Stojanovićba9fcea2017-05-15 16:59:49 +02002225 p = lock_user(VERIFY_READ, arg3, sizeof(target_siginfo_t), 1);
2226 if (p) {
2227 get_target_siginfo(&uinfo, p);
2228 print_siginfo(&uinfo);
2229
2230 unlock_user(p, arg3, 0);
2231 } else {
2232 print_pointer(arg3, 1);
2233 }
Miloš Stojanović243e0fe2017-05-15 16:59:47 +02002234 print_syscall_epilogue(name);
2235}
2236#endif
2237
Aleksandar Markovicda2c8ad2016-09-22 18:56:58 +02002238#ifdef TARGET_NR_syslog
2239static void
2240print_syslog_action(abi_ulong arg, int last)
2241{
2242 const char *type;
2243
2244 switch (arg) {
2245 case TARGET_SYSLOG_ACTION_CLOSE: {
2246 type = "SYSLOG_ACTION_CLOSE";
2247 break;
2248 }
2249 case TARGET_SYSLOG_ACTION_OPEN: {
2250 type = "SYSLOG_ACTION_OPEN";
2251 break;
2252 }
2253 case TARGET_SYSLOG_ACTION_READ: {
2254 type = "SYSLOG_ACTION_READ";
2255 break;
2256 }
2257 case TARGET_SYSLOG_ACTION_READ_ALL: {
2258 type = "SYSLOG_ACTION_READ_ALL";
2259 break;
2260 }
2261 case TARGET_SYSLOG_ACTION_READ_CLEAR: {
2262 type = "SYSLOG_ACTION_READ_CLEAR";
2263 break;
2264 }
2265 case TARGET_SYSLOG_ACTION_CLEAR: {
2266 type = "SYSLOG_ACTION_CLEAR";
2267 break;
2268 }
2269 case TARGET_SYSLOG_ACTION_CONSOLE_OFF: {
2270 type = "SYSLOG_ACTION_CONSOLE_OFF";
2271 break;
2272 }
2273 case TARGET_SYSLOG_ACTION_CONSOLE_ON: {
2274 type = "SYSLOG_ACTION_CONSOLE_ON";
2275 break;
2276 }
2277 case TARGET_SYSLOG_ACTION_CONSOLE_LEVEL: {
2278 type = "SYSLOG_ACTION_CONSOLE_LEVEL";
2279 break;
2280 }
2281 case TARGET_SYSLOG_ACTION_SIZE_UNREAD: {
2282 type = "SYSLOG_ACTION_SIZE_UNREAD";
2283 break;
2284 }
2285 case TARGET_SYSLOG_ACTION_SIZE_BUFFER: {
2286 type = "SYSLOG_ACTION_SIZE_BUFFER";
2287 break;
2288 }
2289 default: {
2290 print_raw_param("%ld", arg, last);
2291 return;
2292 }
2293 }
Josh Kunz4b25a502020-02-03 18:54:14 -08002294 qemu_log("%s%s", type, get_comma(last));
Aleksandar Markovicda2c8ad2016-09-22 18:56:58 +02002295}
2296
2297static void
2298print_syslog(const struct syscallname *name,
2299 abi_long arg0, abi_long arg1, abi_long arg2,
2300 abi_long arg3, abi_long arg4, abi_long arg5)
2301{
2302 print_syscall_prologue(name);
2303 print_syslog_action(arg0, 0);
2304 print_pointer(arg1, 0);
2305 print_raw_param("%d", arg2, 1);
2306 print_syscall_epilogue(name);
2307}
2308#endif
2309
Mika Westerberg74d753a2009-04-07 16:57:29 +03002310#ifdef TARGET_NR_mknod
2311static void
2312print_mknod(const struct syscallname *name,
2313 abi_long arg0, abi_long arg1, abi_long arg2,
2314 abi_long arg3, abi_long arg4, abi_long arg5)
2315{
Laurent Vivierd2ee72a2011-02-15 21:10:44 +01002316 int hasdev = (arg1 & (S_IFCHR|S_IFBLK));
Mika Westerberg74d753a2009-04-07 16:57:29 +03002317
2318 print_syscall_prologue(name);
2319 print_string(arg0, 0);
2320 print_file_mode(arg1, (hasdev == 0));
2321 if (hasdev) {
Laurent Vivierd2ee72a2011-02-15 21:10:44 +01002322 print_raw_param("makedev(%d", major(arg2), 0);
2323 print_raw_param("%d)", minor(arg2), 1);
Mika Westerberg74d753a2009-04-07 16:57:29 +03002324 }
2325 print_syscall_epilogue(name);
2326}
2327#endif
2328
2329#ifdef TARGET_NR_mknodat
2330static void
2331print_mknodat(const struct syscallname *name,
2332 abi_long arg0, abi_long arg1, abi_long arg2,
2333 abi_long arg3, abi_long arg4, abi_long arg5)
2334{
Laurent Vivierd2ee72a2011-02-15 21:10:44 +01002335 int hasdev = (arg2 & (S_IFCHR|S_IFBLK));
Mika Westerberg74d753a2009-04-07 16:57:29 +03002336
2337 print_syscall_prologue(name);
2338 print_at_dirfd(arg0, 0);
2339 print_string(arg1, 0);
2340 print_file_mode(arg2, (hasdev == 0));
2341 if (hasdev) {
Laurent Vivierd2ee72a2011-02-15 21:10:44 +01002342 print_raw_param("makedev(%d", major(arg3), 0);
2343 print_raw_param("%d)", minor(arg3), 1);
Mika Westerberg74d753a2009-04-07 16:57:29 +03002344 }
2345 print_syscall_epilogue(name);
2346}
2347#endif
2348
2349#ifdef TARGET_NR_mq_open
2350static void
2351print_mq_open(const struct syscallname *name,
2352 abi_long arg0, abi_long arg1, abi_long arg2,
2353 abi_long arg3, abi_long arg4, abi_long arg5)
2354{
Laurent Vivierd2ee72a2011-02-15 21:10:44 +01002355 int is_creat = (arg1 & TARGET_O_CREAT);
Mika Westerberg74d753a2009-04-07 16:57:29 +03002356
2357 print_syscall_prologue(name);
2358 print_string(arg0, 0);
2359 print_open_flags(arg1, (is_creat == 0));
2360 if (is_creat) {
2361 print_file_mode(arg2, 0);
2362 print_pointer(arg3, 1);
2363 }
2364 print_syscall_epilogue(name);
2365}
2366#endif
2367
2368#ifdef TARGET_NR_open
2369static void
2370print_open(const struct syscallname *name,
2371 abi_long arg0, abi_long arg1, abi_long arg2,
2372 abi_long arg3, abi_long arg4, abi_long arg5)
2373{
Laurent Vivierd2ee72a2011-02-15 21:10:44 +01002374 int is_creat = (arg1 & TARGET_O_CREAT);
Mika Westerberg74d753a2009-04-07 16:57:29 +03002375
2376 print_syscall_prologue(name);
2377 print_string(arg0, 0);
2378 print_open_flags(arg1, (is_creat == 0));
2379 if (is_creat)
2380 print_file_mode(arg2, 1);
2381 print_syscall_epilogue(name);
2382}
2383#endif
2384
2385#ifdef TARGET_NR_openat
2386static void
2387print_openat(const struct syscallname *name,
2388 abi_long arg0, abi_long arg1, abi_long arg2,
2389 abi_long arg3, abi_long arg4, abi_long arg5)
2390{
Laurent Vivierd2ee72a2011-02-15 21:10:44 +01002391 int is_creat = (arg2 & TARGET_O_CREAT);
Mika Westerberg74d753a2009-04-07 16:57:29 +03002392
2393 print_syscall_prologue(name);
2394 print_at_dirfd(arg0, 0);
2395 print_string(arg1, 0);
2396 print_open_flags(arg2, (is_creat == 0));
2397 if (is_creat)
2398 print_file_mode(arg3, 1);
2399 print_syscall_epilogue(name);
2400}
2401#endif
2402
2403#ifdef TARGET_NR_mq_unlink
2404static void
2405print_mq_unlink(const struct syscallname *name,
2406 abi_long arg0, abi_long arg1, abi_long arg2,
2407 abi_long arg3, abi_long arg4, abi_long arg5)
2408{
2409 print_syscall_prologue(name);
2410 print_string(arg0, 1);
2411 print_syscall_epilogue(name);
2412}
2413#endif
2414
2415#if defined(TARGET_NR_fstatat64) || defined(TARGET_NR_newfstatat)
2416static void
2417print_fstatat64(const struct syscallname *name,
2418 abi_long arg0, abi_long arg1, abi_long arg2,
2419 abi_long arg3, abi_long arg4, abi_long arg5)
2420{
2421 print_syscall_prologue(name);
2422 print_at_dirfd(arg0, 0);
2423 print_string(arg1, 0);
2424 print_pointer(arg2, 0);
2425 print_flags(at_file_flags, arg3, 1);
2426 print_syscall_epilogue(name);
2427}
2428#define print_newfstatat print_fstatat64
2429#endif
2430
2431#ifdef TARGET_NR_readlink
2432static void
2433print_readlink(const struct syscallname *name,
2434 abi_long arg0, abi_long arg1, abi_long arg2,
2435 abi_long arg3, abi_long arg4, abi_long arg5)
2436{
2437 print_syscall_prologue(name);
2438 print_string(arg0, 0);
2439 print_pointer(arg1, 0);
Laurent Vivierd2ee72a2011-02-15 21:10:44 +01002440 print_raw_param("%u", arg2, 1);
Mika Westerberg74d753a2009-04-07 16:57:29 +03002441 print_syscall_epilogue(name);
2442}
2443#endif
2444
2445#ifdef TARGET_NR_readlinkat
2446static void
2447print_readlinkat(const struct syscallname *name,
2448 abi_long arg0, abi_long arg1, abi_long arg2,
2449 abi_long arg3, abi_long arg4, abi_long arg5)
2450{
2451 print_syscall_prologue(name);
2452 print_at_dirfd(arg0, 0);
2453 print_string(arg1, 0);
2454 print_pointer(arg2, 0);
Laurent Vivierd2ee72a2011-02-15 21:10:44 +01002455 print_raw_param("%u", arg3, 1);
Mika Westerberg74d753a2009-04-07 16:57:29 +03002456 print_syscall_epilogue(name);
2457}
2458#endif
2459
2460#ifdef TARGET_NR_rename
2461static void
2462print_rename(const struct syscallname *name,
2463 abi_long arg0, abi_long arg1, abi_long arg2,
2464 abi_long arg3, abi_long arg4, abi_long arg5)
2465{
2466 print_syscall_prologue(name);
2467 print_string(arg0, 0);
2468 print_string(arg1, 1);
2469 print_syscall_epilogue(name);
2470}
2471#endif
2472
2473#ifdef TARGET_NR_renameat
2474static void
2475print_renameat(const struct syscallname *name,
2476 abi_long arg0, abi_long arg1, abi_long arg2,
2477 abi_long arg3, abi_long arg4, abi_long arg5)
2478{
2479 print_syscall_prologue(name);
2480 print_at_dirfd(arg0, 0);
2481 print_string(arg1, 0);
2482 print_at_dirfd(arg2, 0);
2483 print_string(arg3, 1);
2484 print_syscall_epilogue(name);
2485}
2486#endif
2487
2488#ifdef TARGET_NR_statfs
2489static void
2490print_statfs(const struct syscallname *name,
2491 abi_long arg0, abi_long arg1, abi_long arg2,
2492 abi_long arg3, abi_long arg4, abi_long arg5)
2493{
2494 print_syscall_prologue(name);
2495 print_string(arg0, 0);
2496 print_pointer(arg1, 1);
2497 print_syscall_epilogue(name);
2498}
Aleksandar Rikalo4f7f8922018-08-02 16:16:00 +02002499#endif
2500
2501#ifdef TARGET_NR_statfs64
2502static void
2503print_statfs64(const struct syscallname *name,
2504 abi_long arg0, abi_long arg1, abi_long arg2,
2505 abi_long arg3, abi_long arg4, abi_long arg5)
2506{
2507 print_syscall_prologue(name);
2508 print_string(arg0, 0);
2509 print_pointer(arg1, 1);
2510 print_syscall_epilogue(name);
2511}
Mika Westerberg74d753a2009-04-07 16:57:29 +03002512#endif
2513
2514#ifdef TARGET_NR_symlink
2515static void
2516print_symlink(const struct syscallname *name,
2517 abi_long arg0, abi_long arg1, abi_long arg2,
2518 abi_long arg3, abi_long arg4, abi_long arg5)
2519{
2520 print_syscall_prologue(name);
2521 print_string(arg0, 0);
2522 print_string(arg1, 1);
2523 print_syscall_epilogue(name);
2524}
2525#endif
2526
2527#ifdef TARGET_NR_symlinkat
2528static void
2529print_symlinkat(const struct syscallname *name,
2530 abi_long arg0, abi_long arg1, abi_long arg2,
2531 abi_long arg3, abi_long arg4, abi_long arg5)
2532{
2533 print_syscall_prologue(name);
2534 print_string(arg0, 0);
2535 print_at_dirfd(arg1, 0);
2536 print_string(arg2, 1);
2537 print_syscall_epilogue(name);
2538}
2539#endif
2540
2541#ifdef TARGET_NR_mount
2542static void
2543print_mount(const struct syscallname *name,
2544 abi_long arg0, abi_long arg1, abi_long arg2,
2545 abi_long arg3, abi_long arg4, abi_long arg5)
2546{
2547 print_syscall_prologue(name);
2548 print_string(arg0, 0);
2549 print_string(arg1, 0);
2550 print_string(arg2, 0);
2551 print_flags(mount_flags, arg3, 0);
2552 print_pointer(arg4, 1);
2553 print_syscall_epilogue(name);
2554}
2555#endif
2556
2557#ifdef TARGET_NR_umount
2558static void
2559print_umount(const struct syscallname *name,
2560 abi_long arg0, abi_long arg1, abi_long arg2,
2561 abi_long arg3, abi_long arg4, abi_long arg5)
2562{
2563 print_syscall_prologue(name);
2564 print_string(arg0, 1);
2565 print_syscall_epilogue(name);
2566}
2567#endif
2568
2569#ifdef TARGET_NR_umount2
2570static void
2571print_umount2(const struct syscallname *name,
2572 abi_long arg0, abi_long arg1, abi_long arg2,
2573 abi_long arg3, abi_long arg4, abi_long arg5)
2574{
2575 print_syscall_prologue(name);
2576 print_string(arg0, 0);
2577 print_flags(umount2_flags, arg1, 1);
2578 print_syscall_epilogue(name);
2579}
2580#endif
2581
2582#ifdef TARGET_NR_unlink
2583static void
2584print_unlink(const struct syscallname *name,
2585 abi_long arg0, abi_long arg1, abi_long arg2,
2586 abi_long arg3, abi_long arg4, abi_long arg5)
2587{
2588 print_syscall_prologue(name);
2589 print_string(arg0, 1);
2590 print_syscall_epilogue(name);
2591}
2592#endif
2593
2594#ifdef TARGET_NR_unlinkat
2595static void
2596print_unlinkat(const struct syscallname *name,
2597 abi_long arg0, abi_long arg1, abi_long arg2,
2598 abi_long arg3, abi_long arg4, abi_long arg5)
2599{
2600 print_syscall_prologue(name);
2601 print_at_dirfd(arg0, 0);
2602 print_string(arg1, 0);
2603 print_flags(unlinkat_flags, arg2, 1);
2604 print_syscall_epilogue(name);
2605}
2606#endif
2607
2608#ifdef TARGET_NR_utime
2609static void
2610print_utime(const struct syscallname *name,
2611 abi_long arg0, abi_long arg1, abi_long arg2,
2612 abi_long arg3, abi_long arg4, abi_long arg5)
2613{
2614 print_syscall_prologue(name);
2615 print_string(arg0, 0);
2616 print_pointer(arg1, 1);
2617 print_syscall_epilogue(name);
2618}
2619#endif
2620
2621#ifdef TARGET_NR_utimes
2622static void
2623print_utimes(const struct syscallname *name,
2624 abi_long arg0, abi_long arg1, abi_long arg2,
2625 abi_long arg3, abi_long arg4, abi_long arg5)
2626{
2627 print_syscall_prologue(name);
2628 print_string(arg0, 0);
2629 print_pointer(arg1, 1);
2630 print_syscall_epilogue(name);
2631}
2632#endif
2633
2634#ifdef TARGET_NR_utimensat
2635static void
2636print_utimensat(const struct syscallname *name,
2637 abi_long arg0, abi_long arg1, abi_long arg2,
2638 abi_long arg3, abi_long arg4, abi_long arg5)
2639{
2640 print_syscall_prologue(name);
2641 print_at_dirfd(arg0, 0);
2642 print_string(arg1, 0);
2643 print_pointer(arg2, 0);
2644 print_flags(at_file_flags, arg3, 1);
2645 print_syscall_epilogue(name);
2646}
2647#endif
2648
Mike Frysinger8d9016c2011-02-07 01:05:57 -05002649#if defined(TARGET_NR_mmap) || defined(TARGET_NR_mmap2)
Mika Westerberg74d753a2009-04-07 16:57:29 +03002650static void
2651print_mmap(const struct syscallname *name,
2652 abi_long arg0, abi_long arg1, abi_long arg2,
2653 abi_long arg3, abi_long arg4, abi_long arg5)
2654{
2655 print_syscall_prologue(name);
2656 print_pointer(arg0, 0);
Laurent Vivierd2ee72a2011-02-15 21:10:44 +01002657 print_raw_param("%d", arg1, 0);
Mika Westerberg74d753a2009-04-07 16:57:29 +03002658 print_flags(mmap_prot_flags, arg2, 0);
2659 print_flags(mmap_flags, arg3, 0);
Laurent Vivierd2ee72a2011-02-15 21:10:44 +01002660 print_raw_param("%d", arg4, 0);
2661 print_raw_param("%#x", arg5, 1);
Mika Westerberg74d753a2009-04-07 16:57:29 +03002662 print_syscall_epilogue(name);
2663}
2664#define print_mmap2 print_mmap
2665#endif
2666
2667#ifdef TARGET_NR_mprotect
2668static void
2669print_mprotect(const struct syscallname *name,
2670 abi_long arg0, abi_long arg1, abi_long arg2,
2671 abi_long arg3, abi_long arg4, abi_long arg5)
2672{
2673 print_syscall_prologue(name);
2674 print_pointer(arg0, 0);
Laurent Vivierd2ee72a2011-02-15 21:10:44 +01002675 print_raw_param("%d", arg1, 0);
Mika Westerberg74d753a2009-04-07 16:57:29 +03002676 print_flags(mmap_prot_flags, arg2, 1);
2677 print_syscall_epilogue(name);
2678}
2679#endif
2680
2681#ifdef TARGET_NR_munmap
2682static void
2683print_munmap(const struct syscallname *name,
2684 abi_long arg0, abi_long arg1, abi_long arg2,
2685 abi_long arg3, abi_long arg4, abi_long arg5)
2686{
2687 print_syscall_prologue(name);
2688 print_pointer(arg0, 0);
Laurent Vivierd2ee72a2011-02-15 21:10:44 +01002689 print_raw_param("%d", arg1, 1);
Mika Westerberg74d753a2009-04-07 16:57:29 +03002690 print_syscall_epilogue(name);
2691}
2692#endif
2693
2694#ifdef TARGET_NR_futex
2695static void print_futex_op(abi_long tflag, int last)
2696{
2697#define print_op(val) \
2698if( cmd == val ) { \
Josh Kunz4b25a502020-02-03 18:54:14 -08002699 qemu_log(#val); \
Mika Westerberg74d753a2009-04-07 16:57:29 +03002700 return; \
2701}
2702
Laurent Vivierd2ee72a2011-02-15 21:10:44 +01002703 int cmd = (int)tflag;
Mika Westerberg74d753a2009-04-07 16:57:29 +03002704#ifdef FUTEX_PRIVATE_FLAG
Paul Brook5f2243f2010-02-19 16:04:51 +00002705 if (cmd & FUTEX_PRIVATE_FLAG) {
Josh Kunz4b25a502020-02-03 18:54:14 -08002706 qemu_log("FUTEX_PRIVATE_FLAG|");
Paul Brook5f2243f2010-02-19 16:04:51 +00002707 cmd &= ~FUTEX_PRIVATE_FLAG;
2708 }
Mika Westerberg74d753a2009-04-07 16:57:29 +03002709#endif
John Rigbybfb669f2013-02-23 16:14:08 -07002710#ifdef FUTEX_CLOCK_REALTIME
2711 if (cmd & FUTEX_CLOCK_REALTIME) {
Josh Kunz4b25a502020-02-03 18:54:14 -08002712 qemu_log("FUTEX_CLOCK_REALTIME|");
John Rigbybfb669f2013-02-23 16:14:08 -07002713 cmd &= ~FUTEX_CLOCK_REALTIME;
2714 }
2715#endif
Mika Westerberg74d753a2009-04-07 16:57:29 +03002716 print_op(FUTEX_WAIT)
2717 print_op(FUTEX_WAKE)
2718 print_op(FUTEX_FD)
2719 print_op(FUTEX_REQUEUE)
2720 print_op(FUTEX_CMP_REQUEUE)
2721 print_op(FUTEX_WAKE_OP)
2722 print_op(FUTEX_LOCK_PI)
2723 print_op(FUTEX_UNLOCK_PI)
2724 print_op(FUTEX_TRYLOCK_PI)
2725#ifdef FUTEX_WAIT_BITSET
2726 print_op(FUTEX_WAIT_BITSET)
2727#endif
2728#ifdef FUTEX_WAKE_BITSET
2729 print_op(FUTEX_WAKE_BITSET)
2730#endif
2731 /* unknown values */
Josh Kunz4b25a502020-02-03 18:54:14 -08002732 qemu_log("%d", cmd);
Mika Westerberg74d753a2009-04-07 16:57:29 +03002733}
2734
2735static void
2736print_futex(const struct syscallname *name,
2737 abi_long arg0, abi_long arg1, abi_long arg2,
2738 abi_long arg3, abi_long arg4, abi_long arg5)
2739{
2740 print_syscall_prologue(name);
2741 print_pointer(arg0, 0);
2742 print_futex_op(arg1, 0);
Laurent Vivierd2ee72a2011-02-15 21:10:44 +01002743 print_raw_param(",%d", arg2, 0);
Mika Westerberg74d753a2009-04-07 16:57:29 +03002744 print_pointer(arg3, 0); /* struct timespec */
2745 print_pointer(arg4, 0);
Laurent Vivierd2ee72a2011-02-15 21:10:44 +01002746 print_raw_param("%d", arg4, 1);
Mika Westerberg74d753a2009-04-07 16:57:29 +03002747 print_syscall_epilogue(name);
2748}
2749#endif
2750
Laurent Vivier608e5592011-04-07 00:25:32 +02002751#ifdef TARGET_NR_kill
2752static void
2753print_kill(const struct syscallname *name,
2754 abi_long arg0, abi_long arg1, abi_long arg2,
2755 abi_long arg3, abi_long arg4, abi_long arg5)
2756{
2757 print_syscall_prologue(name);
2758 print_raw_param("%d", arg0, 0);
2759 print_signal(arg1, 1);
2760 print_syscall_epilogue(name);
2761}
2762#endif
2763
Miloš Stojanović51622642017-05-15 16:59:42 +02002764#ifdef TARGET_NR_tkill
2765static void
2766print_tkill(const struct syscallname *name,
2767 abi_long arg0, abi_long arg1, abi_long arg2,
2768 abi_long arg3, abi_long arg4, abi_long arg5)
2769{
2770 print_syscall_prologue(name);
2771 print_raw_param("%d", arg0, 0);
2772 print_signal(arg1, 1);
2773 print_syscall_epilogue(name);
2774}
2775#endif
2776
2777#ifdef TARGET_NR_tgkill
2778static void
2779print_tgkill(const struct syscallname *name,
2780 abi_long arg0, abi_long arg1, abi_long arg2,
2781 abi_long arg3, abi_long arg4, abi_long arg5)
2782{
2783 print_syscall_prologue(name);
2784 print_raw_param("%d", arg0, 0);
2785 print_raw_param("%d", arg1, 0);
2786 print_signal(arg2, 1);
2787 print_syscall_epilogue(name);
2788}
2789#endif
2790
Jim Wilsond42744f2019-06-28 12:43:35 +02002791#ifdef TARGET_NR_statx
2792static void
2793print_statx(const struct syscallname *name,
2794 abi_long arg0, abi_long arg1, abi_long arg2,
2795 abi_long arg3, abi_long arg4, abi_long arg5)
2796{
2797 print_syscall_prologue(name);
2798 print_at_dirfd(arg0, 0);
2799 print_string(arg1, 0);
2800 print_flags(statx_flags, arg2, 0);
2801 print_flags(statx_mask, arg3, 0);
2802 print_pointer(arg4, 1);
2803 print_syscall_epilogue(name);
2804}
2805#endif
2806
ths33189d32007-11-01 00:13:36 +00002807/*
2808 * An array of all of the syscalls we know about
2809 */
2810
blueswir17ccfb2e2008-09-14 06:45:34 +00002811static const struct syscallname scnames[] = {
ths33189d32007-11-01 00:13:36 +00002812#include "strace.list"
2813};
2814
malcb1503cd2008-12-22 20:33:55 +00002815static int nsyscalls = ARRAY_SIZE(scnames);
ths33189d32007-11-01 00:13:36 +00002816
2817/*
2818 * The public interface to this module.
2819 */
2820void
2821print_syscall(int num,
bellardc16f9ed2007-11-11 17:23:29 +00002822 abi_long arg1, abi_long arg2, abi_long arg3,
2823 abi_long arg4, abi_long arg5, abi_long arg6)
ths33189d32007-11-01 00:13:36 +00002824{
2825 int i;
blueswir17ccfb2e2008-09-14 06:45:34 +00002826 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 ")";
ths33189d32007-11-01 00:13:36 +00002827
Josh Kunz4b25a502020-02-03 18:54:14 -08002828 qemu_log("%d ", getpid());
ths33189d32007-11-01 00:13:36 +00002829
2830 for(i=0;i<nsyscalls;i++)
2831 if( scnames[i].nr == num ) {
2832 if( scnames[i].call != NULL ) {
Josh Kunz4b25a502020-02-03 18:54:14 -08002833 scnames[i].call(
2834 &scnames[i], arg1, arg2, arg3, arg4, arg5, arg6);
ths33189d32007-11-01 00:13:36 +00002835 } else {
bellard6b23f772007-11-14 18:04:05 +00002836 /* XXX: this format system is broken because it uses
2837 host types and host pointers for strings */
ths33189d32007-11-01 00:13:36 +00002838 if( scnames[i].format != NULL )
2839 format = scnames[i].format;
Josh Kunz4b25a502020-02-03 18:54:14 -08002840 qemu_log(format,
2841 scnames[i].name, arg1, arg2, arg3, arg4, arg5, arg6);
ths33189d32007-11-01 00:13:36 +00002842 }
pbrook74c11e52008-05-29 13:49:09 +00002843 return;
ths33189d32007-11-01 00:13:36 +00002844 }
Josh Kunz4b25a502020-02-03 18:54:14 -08002845 qemu_log("Unknown syscall %d\n", num);
ths33189d32007-11-01 00:13:36 +00002846}
2847
2848
2849void
bellardc16f9ed2007-11-11 17:23:29 +00002850print_syscall_ret(int num, abi_long ret)
ths33189d32007-11-01 00:13:36 +00002851{
2852 int i;
Peter Maydell7dcdaea2016-06-06 19:58:18 +01002853 const char *errstr = NULL;
ths33189d32007-11-01 00:13:36 +00002854
2855 for(i=0;i<nsyscalls;i++)
2856 if( scnames[i].nr == num ) {
2857 if( scnames[i].result != NULL ) {
Josh Kunz4b25a502020-02-03 18:54:14 -08002858 scnames[i].result(&scnames[i], ret);
ths33189d32007-11-01 00:13:36 +00002859 } else {
Alexander Graf962b2892011-11-21 12:04:07 +01002860 if (ret < 0) {
2861 errstr = target_strerror(-ret);
2862 }
2863 if (errstr) {
Josh Kunz4b25a502020-02-03 18:54:14 -08002864 qemu_log(" = -1 errno=" TARGET_ABI_FMT_ld " (%s)\n",
Alexander Graf962b2892011-11-21 12:04:07 +01002865 -ret, errstr);
ths33189d32007-11-01 00:13:36 +00002866 } else {
Josh Kunz4b25a502020-02-03 18:54:14 -08002867 qemu_log(" = " TARGET_ABI_FMT_ld "\n", ret);
ths33189d32007-11-01 00:13:36 +00002868 }
2869 }
2870 break;
2871 }
2872}
Peter Maydell0cb581d2016-07-18 18:12:24 +01002873
2874void print_taken_signal(int target_signum, const target_siginfo_t *tinfo)
2875{
2876 /* Print the strace output for a signal being taken:
2877 * --- SIGSEGV {si_signo=SIGSEGV, si_code=SI_KERNEL, si_addr=0} ---
2878 */
Josh Kunz4b25a502020-02-03 18:54:14 -08002879 qemu_log("--- ");
Peter Maydell0cb581d2016-07-18 18:12:24 +01002880 print_signal(target_signum, 1);
Josh Kunz4b25a502020-02-03 18:54:14 -08002881 qemu_log(" ");
Peter Maydell0cb581d2016-07-18 18:12:24 +01002882 print_siginfo(tinfo);
Josh Kunz4b25a502020-02-03 18:54:14 -08002883 qemu_log(" ---\n");
Peter Maydell0cb581d2016-07-18 18:12:24 +01002884}