blob: 4f7130b2ff630c82751393673583982ed21883b2 [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{
447 switch (type) {
448 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 }
467}
468
469static void
470print_socket_protocol(int domain, int type, int protocol)
471{
472 if (domain == AF_PACKET ||
473 (domain == AF_INET && type == TARGET_SOCK_PACKET)) {
474 switch (protocol) {
475 case 0x0003:
Josh Kunz4b25a502020-02-03 18:54:14 -0800476 qemu_log("ETH_P_ALL");
Laurent Vivierfb3aabf2016-06-11 02:19:45 +0200477 break;
478 default:
Josh Kunz4b25a502020-02-03 18:54:14 -0800479 qemu_log("%d", protocol);
Laurent Vivierfb3aabf2016-06-11 02:19:45 +0200480 }
481 return;
482 }
483
Philippe Mathieu-Daudé814ae702019-10-21 13:48:53 +0200484 if (domain == PF_NETLINK) {
485 switch (protocol) {
486 case NETLINK_ROUTE:
Josh Kunz4b25a502020-02-03 18:54:14 -0800487 qemu_log("NETLINK_ROUTE");
Philippe Mathieu-Daudé814ae702019-10-21 13:48:53 +0200488 break;
489 case NETLINK_AUDIT:
Josh Kunz4b25a502020-02-03 18:54:14 -0800490 qemu_log("NETLINK_AUDIT");
Philippe Mathieu-Daudé814ae702019-10-21 13:48:53 +0200491 break;
492 case NETLINK_NETFILTER:
Josh Kunz4b25a502020-02-03 18:54:14 -0800493 qemu_log("NETLINK_NETFILTER");
Philippe Mathieu-Daudé814ae702019-10-21 13:48:53 +0200494 break;
495 case NETLINK_KOBJECT_UEVENT:
Josh Kunz4b25a502020-02-03 18:54:14 -0800496 qemu_log("NETLINK_KOBJECT_UEVENT");
Philippe Mathieu-Daudé814ae702019-10-21 13:48:53 +0200497 break;
498 case NETLINK_RDMA:
Josh Kunz4b25a502020-02-03 18:54:14 -0800499 qemu_log("NETLINK_RDMA");
Philippe Mathieu-Daudé814ae702019-10-21 13:48:53 +0200500 break;
501 case NETLINK_CRYPTO:
Josh Kunz4b25a502020-02-03 18:54:14 -0800502 qemu_log("NETLINK_CRYPTO");
Philippe Mathieu-Daudé814ae702019-10-21 13:48:53 +0200503 break;
504 default:
Josh Kunz4b25a502020-02-03 18:54:14 -0800505 qemu_log("%d", protocol);
Philippe Mathieu-Daudé814ae702019-10-21 13:48:53 +0200506 break;
507 }
508 return;
509 }
510
Laurent Vivierfb3aabf2016-06-11 02:19:45 +0200511 switch (protocol) {
512 case IPPROTO_IP:
Josh Kunz4b25a502020-02-03 18:54:14 -0800513 qemu_log("IPPROTO_IP");
Laurent Vivierfb3aabf2016-06-11 02:19:45 +0200514 break;
515 case IPPROTO_TCP:
Josh Kunz4b25a502020-02-03 18:54:14 -0800516 qemu_log("IPPROTO_TCP");
Laurent Vivierfb3aabf2016-06-11 02:19:45 +0200517 break;
518 case IPPROTO_UDP:
Josh Kunz4b25a502020-02-03 18:54:14 -0800519 qemu_log("IPPROTO_UDP");
Laurent Vivierfb3aabf2016-06-11 02:19:45 +0200520 break;
521 case IPPROTO_RAW:
Josh Kunz4b25a502020-02-03 18:54:14 -0800522 qemu_log("IPPROTO_RAW");
Laurent Vivierfb3aabf2016-06-11 02:19:45 +0200523 break;
524 default:
Josh Kunz4b25a502020-02-03 18:54:14 -0800525 qemu_log("%d", protocol);
Laurent Vivierfb3aabf2016-06-11 02:19:45 +0200526 break;
527 }
528}
529
530
bellardc16f9ed2007-11-11 17:23:29 +0000531#ifdef TARGET_NR__newselect
ths33189d32007-11-01 00:13:36 +0000532static void
bellardc16f9ed2007-11-11 17:23:29 +0000533print_fdset(int n, abi_ulong target_fds_addr)
ths33189d32007-11-01 00:13:36 +0000534{
535 int i;
536
Josh Kunz4b25a502020-02-03 18:54:14 -0800537 qemu_log("[");
ths33189d32007-11-01 00:13:36 +0000538 if( target_fds_addr ) {
bellard579a97f2007-11-11 14:26:47 +0000539 abi_long *target_fds;
ths33189d32007-11-01 00:13:36 +0000540
bellard579a97f2007-11-11 14:26:47 +0000541 target_fds = lock_user(VERIFY_READ,
542 target_fds_addr,
543 sizeof(*target_fds)*(n / TARGET_ABI_BITS + 1),
544 1);
545
546 if (!target_fds)
ths33189d32007-11-01 00:13:36 +0000547 return;
548
ths33189d32007-11-01 00:13:36 +0000549 for (i=n; i>=0; i--) {
Matthias Brauncbb21ee2011-08-12 19:57:41 +0200550 if ((tswapal(target_fds[i / TARGET_ABI_BITS]) >> (i & (TARGET_ABI_BITS - 1))) & 1)
Josh Kunz4b25a502020-02-03 18:54:14 -0800551 qemu_log("%d,", i);
ths33189d32007-11-01 00:13:36 +0000552 }
553 unlock_user(target_fds, target_fds_addr, 0);
554 }
Josh Kunz4b25a502020-02-03 18:54:14 -0800555 qemu_log("]");
ths33189d32007-11-01 00:13:36 +0000556}
bellardc16f9ed2007-11-11 17:23:29 +0000557#endif
ths33189d32007-11-01 00:13:36 +0000558
Aleksandar Markovic38860a02016-10-10 13:23:29 +0200559#ifdef TARGET_NR_clock_adjtime
560/* IDs of the various system clocks */
561#define TARGET_CLOCK_REALTIME 0
562#define TARGET_CLOCK_MONOTONIC 1
563#define TARGET_CLOCK_PROCESS_CPUTIME_ID 2
564#define TARGET_CLOCK_THREAD_CPUTIME_ID 3
565#define TARGET_CLOCK_MONOTONIC_RAW 4
566#define TARGET_CLOCK_REALTIME_COARSE 5
567#define TARGET_CLOCK_MONOTONIC_COARSE 6
568#define TARGET_CLOCK_BOOTTIME 7
569#define TARGET_CLOCK_REALTIME_ALARM 8
570#define TARGET_CLOCK_BOOTTIME_ALARM 9
571#define TARGET_CLOCK_SGI_CYCLE 10
572#define TARGET_CLOCK_TAI 11
573
574static void
575print_clockid(int clockid, int last)
576{
577 switch (clockid) {
578 case TARGET_CLOCK_REALTIME:
Josh Kunz4b25a502020-02-03 18:54:14 -0800579 qemu_log("CLOCK_REALTIME");
Aleksandar Markovic38860a02016-10-10 13:23:29 +0200580 break;
581 case TARGET_CLOCK_MONOTONIC:
Josh Kunz4b25a502020-02-03 18:54:14 -0800582 qemu_log("CLOCK_MONOTONIC");
Aleksandar Markovic38860a02016-10-10 13:23:29 +0200583 break;
584 case TARGET_CLOCK_PROCESS_CPUTIME_ID:
Josh Kunz4b25a502020-02-03 18:54:14 -0800585 qemu_log("CLOCK_PROCESS_CPUTIME_ID");
Aleksandar Markovic38860a02016-10-10 13:23:29 +0200586 break;
587 case TARGET_CLOCK_THREAD_CPUTIME_ID:
Josh Kunz4b25a502020-02-03 18:54:14 -0800588 qemu_log("CLOCK_THREAD_CPUTIME_ID");
Aleksandar Markovic38860a02016-10-10 13:23:29 +0200589 break;
590 case TARGET_CLOCK_MONOTONIC_RAW:
Josh Kunz4b25a502020-02-03 18:54:14 -0800591 qemu_log("CLOCK_MONOTONIC_RAW");
Aleksandar Markovic38860a02016-10-10 13:23:29 +0200592 break;
593 case TARGET_CLOCK_REALTIME_COARSE:
Josh Kunz4b25a502020-02-03 18:54:14 -0800594 qemu_log("CLOCK_REALTIME_COARSE");
Aleksandar Markovic38860a02016-10-10 13:23:29 +0200595 break;
596 case TARGET_CLOCK_MONOTONIC_COARSE:
Josh Kunz4b25a502020-02-03 18:54:14 -0800597 qemu_log("CLOCK_MONOTONIC_COARSE");
Aleksandar Markovic38860a02016-10-10 13:23:29 +0200598 break;
599 case TARGET_CLOCK_BOOTTIME:
Josh Kunz4b25a502020-02-03 18:54:14 -0800600 qemu_log("CLOCK_BOOTTIME");
Aleksandar Markovic38860a02016-10-10 13:23:29 +0200601 break;
602 case TARGET_CLOCK_REALTIME_ALARM:
Josh Kunz4b25a502020-02-03 18:54:14 -0800603 qemu_log("CLOCK_REALTIME_ALARM");
Aleksandar Markovic38860a02016-10-10 13:23:29 +0200604 break;
605 case TARGET_CLOCK_BOOTTIME_ALARM:
Josh Kunz4b25a502020-02-03 18:54:14 -0800606 qemu_log("CLOCK_BOOTTIME_ALARM");
Aleksandar Markovic38860a02016-10-10 13:23:29 +0200607 break;
608 case TARGET_CLOCK_SGI_CYCLE:
Josh Kunz4b25a502020-02-03 18:54:14 -0800609 qemu_log("CLOCK_SGI_CYCLE");
Aleksandar Markovic38860a02016-10-10 13:23:29 +0200610 break;
611 case TARGET_CLOCK_TAI:
Josh Kunz4b25a502020-02-03 18:54:14 -0800612 qemu_log("CLOCK_TAI");
Aleksandar Markovic38860a02016-10-10 13:23:29 +0200613 break;
614 default:
Josh Kunz4b25a502020-02-03 18:54:14 -0800615 qemu_log("%d", clockid);
Aleksandar Markovic38860a02016-10-10 13:23:29 +0200616 break;
617 }
Josh Kunz4b25a502020-02-03 18:54:14 -0800618 qemu_log("%s", get_comma(last));
Aleksandar Markovic38860a02016-10-10 13:23:29 +0200619}
620#endif
621
ths33189d32007-11-01 00:13:36 +0000622/*
623 * Sysycall specific output functions
624 */
625
626/* select */
bellardc16f9ed2007-11-11 17:23:29 +0000627#ifdef TARGET_NR__newselect
ths33189d32007-11-01 00:13:36 +0000628static long newselect_arg1 = 0;
629static long newselect_arg2 = 0;
630static long newselect_arg3 = 0;
631static long newselect_arg4 = 0;
632static long newselect_arg5 = 0;
633
634static void
blueswir17ccfb2e2008-09-14 06:45:34 +0000635print_newselect(const struct syscallname *name,
bellardc16f9ed2007-11-11 17:23:29 +0000636 abi_long arg1, abi_long arg2, abi_long arg3,
637 abi_long arg4, abi_long arg5, abi_long arg6)
ths33189d32007-11-01 00:13:36 +0000638{
Josh Kunz4b25a502020-02-03 18:54:14 -0800639 qemu_log("%s(" TARGET_ABI_FMT_ld ",", name->name, arg1);
ths33189d32007-11-01 00:13:36 +0000640 print_fdset(arg1, arg2);
Josh Kunz4b25a502020-02-03 18:54:14 -0800641 qemu_log(",");
ths33189d32007-11-01 00:13:36 +0000642 print_fdset(arg1, arg3);
Josh Kunz4b25a502020-02-03 18:54:14 -0800643 qemu_log(",");
ths33189d32007-11-01 00:13:36 +0000644 print_fdset(arg1, arg4);
Josh Kunz4b25a502020-02-03 18:54:14 -0800645 qemu_log(",");
Mika Westerberg74d753a2009-04-07 16:57:29 +0300646 print_timeval(arg5, 1);
Josh Kunz4b25a502020-02-03 18:54:14 -0800647 qemu_log(")");
ths33189d32007-11-01 00:13:36 +0000648
649 /* save for use in the return output function below */
650 newselect_arg1=arg1;
651 newselect_arg2=arg2;
652 newselect_arg3=arg3;
653 newselect_arg4=arg4;
654 newselect_arg5=arg5;
655}
bellardc16f9ed2007-11-11 17:23:29 +0000656#endif
ths33189d32007-11-01 00:13:36 +0000657
blueswir13e46b2e2008-10-03 19:01:41 +0000658#ifdef TARGET_NR_semctl
ths33189d32007-11-01 00:13:36 +0000659static void
blueswir17ccfb2e2008-09-14 06:45:34 +0000660print_semctl(const struct syscallname *name,
bellardc16f9ed2007-11-11 17:23:29 +0000661 abi_long arg1, abi_long arg2, abi_long arg3,
662 abi_long arg4, abi_long arg5, abi_long arg6)
ths33189d32007-11-01 00:13:36 +0000663{
Josh Kunz4b25a502020-02-03 18:54:14 -0800664 qemu_log("%s(" TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld ",",
665 name->name, arg1, arg2);
ths33189d32007-11-01 00:13:36 +0000666 print_ipc_cmd(arg3);
Josh Kunz4b25a502020-02-03 18:54:14 -0800667 qemu_log(",0x" TARGET_ABI_FMT_lx ")", arg4);
ths33189d32007-11-01 00:13:36 +0000668}
blueswir13e46b2e2008-10-03 19:01:41 +0000669#endif
ths33189d32007-11-01 00:13:36 +0000670
671static void
blueswir17ccfb2e2008-09-14 06:45:34 +0000672print_execve(const struct syscallname *name,
bellardc16f9ed2007-11-11 17:23:29 +0000673 abi_long arg1, abi_long arg2, abi_long arg3,
674 abi_long arg4, abi_long arg5, abi_long arg6)
ths33189d32007-11-01 00:13:36 +0000675{
bellardc16f9ed2007-11-11 17:23:29 +0000676 abi_ulong arg_ptr_addr;
ths33189d32007-11-01 00:13:36 +0000677 char *s;
678
bellard579a97f2007-11-11 14:26:47 +0000679 if (!(s = lock_user_string(arg1)))
ths33189d32007-11-01 00:13:36 +0000680 return;
Josh Kunz4b25a502020-02-03 18:54:14 -0800681 qemu_log("%s(\"%s\",{", name->name, s);
ths33189d32007-11-01 00:13:36 +0000682 unlock_user(s, arg1, 0);
683
bellardc16f9ed2007-11-11 17:23:29 +0000684 for (arg_ptr_addr = arg2; ; arg_ptr_addr += sizeof(abi_ulong)) {
blueswir198448f52008-09-30 18:16:09 +0000685 abi_ulong *arg_ptr, arg_addr;
ths33189d32007-11-01 00:13:36 +0000686
Paolo Bonzini7d374352018-12-13 23:37:37 +0100687 arg_ptr = lock_user(VERIFY_READ, arg_ptr_addr, sizeof(abi_ulong), 1);
bellard579a97f2007-11-11 14:26:47 +0000688 if (!arg_ptr)
ths33189d32007-11-01 00:13:36 +0000689 return;
Matthias Brauncbb21ee2011-08-12 19:57:41 +0200690 arg_addr = tswapal(*arg_ptr);
Paolo Bonzini7d374352018-12-13 23:37:37 +0100691 unlock_user(arg_ptr, arg_ptr_addr, 0);
ths33189d32007-11-01 00:13:36 +0000692 if (!arg_addr)
693 break;
bellard579a97f2007-11-11 14:26:47 +0000694 if ((s = lock_user_string(arg_addr))) {
Josh Kunz4b25a502020-02-03 18:54:14 -0800695 qemu_log("\"%s\",", s);
blueswir198448f52008-09-30 18:16:09 +0000696 unlock_user(s, arg_addr, 0);
bellard579a97f2007-11-11 14:26:47 +0000697 }
ths33189d32007-11-01 00:13:36 +0000698 }
699
Josh Kunz4b25a502020-02-03 18:54:14 -0800700 qemu_log("NULL})");
ths33189d32007-11-01 00:13:36 +0000701}
702
bellardc16f9ed2007-11-11 17:23:29 +0000703#ifdef TARGET_NR_ipc
ths33189d32007-11-01 00:13:36 +0000704static void
blueswir17ccfb2e2008-09-14 06:45:34 +0000705print_ipc(const struct syscallname *name,
bellardc16f9ed2007-11-11 17:23:29 +0000706 abi_long arg1, abi_long arg2, abi_long arg3,
707 abi_long arg4, abi_long arg5, abi_long arg6)
ths33189d32007-11-01 00:13:36 +0000708{
709 switch(arg1) {
710 case IPCOP_semctl:
Josh Kunz4b25a502020-02-03 18:54:14 -0800711 qemu_log("semctl(" TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld ",",
712 arg1, arg2);
blueswir17ccfb2e2008-09-14 06:45:34 +0000713 print_ipc_cmd(arg3);
Josh Kunz4b25a502020-02-03 18:54:14 -0800714 qemu_log(",0x" TARGET_ABI_FMT_lx ")", arg4);
ths33189d32007-11-01 00:13:36 +0000715 break;
716 default:
Josh Kunz4b25a502020-02-03 18:54:14 -0800717 qemu_log(("%s("
718 TARGET_ABI_FMT_ld ","
719 TARGET_ABI_FMT_ld ","
720 TARGET_ABI_FMT_ld ","
721 TARGET_ABI_FMT_ld
722 ")"),
ths33189d32007-11-01 00:13:36 +0000723 name->name, arg1, arg2, arg3, arg4);
724 }
725}
bellardc16f9ed2007-11-11 17:23:29 +0000726#endif
ths33189d32007-11-01 00:13:36 +0000727
728/*
729 * Variants for the return value output function
730 */
731
732static void
blueswir17ccfb2e2008-09-14 06:45:34 +0000733print_syscall_ret_addr(const struct syscallname *name, abi_long ret)
ths33189d32007-11-01 00:13:36 +0000734{
Peter Maydell7dcdaea2016-06-06 19:58:18 +0100735 const char *errstr = NULL;
Alexander Graf962b2892011-11-21 12:04:07 +0100736
Peter Maydell2a7e1242011-11-21 12:21:19 +0000737 if (ret < 0) {
738 errstr = target_strerror(-ret);
Alexander Graf962b2892011-11-21 12:04:07 +0100739 }
Peter Maydell2a7e1242011-11-21 12:21:19 +0000740 if (errstr) {
Josh Kunz4b25a502020-02-03 18:54:14 -0800741 qemu_log(" = -1 errno=%d (%s)\n", (int)-ret, errstr);
ths33189d32007-11-01 00:13:36 +0000742 } else {
Josh Kunz4b25a502020-02-03 18:54:14 -0800743 qemu_log(" = 0x" TARGET_ABI_FMT_lx "\n", ret);
ths33189d32007-11-01 00:13:36 +0000744 }
745}
746
thsf3e32852007-11-03 15:12:16 +0000747#if 0 /* currently unused */
ths33189d32007-11-01 00:13:36 +0000748static void
bellardc16f9ed2007-11-11 17:23:29 +0000749print_syscall_ret_raw(struct syscallname *name, abi_long ret)
ths33189d32007-11-01 00:13:36 +0000750{
Josh Kunz4b25a502020-02-03 18:54:14 -0800751 qemu_log(" = 0x" TARGET_ABI_FMT_lx "\n", ret);
ths33189d32007-11-01 00:13:36 +0000752}
thsf3e32852007-11-03 15:12:16 +0000753#endif
ths33189d32007-11-01 00:13:36 +0000754
thsf3e32852007-11-03 15:12:16 +0000755#ifdef TARGET_NR__newselect
ths33189d32007-11-01 00:13:36 +0000756static void
blueswir17ccfb2e2008-09-14 06:45:34 +0000757print_syscall_ret_newselect(const struct syscallname *name, abi_long ret)
ths33189d32007-11-01 00:13:36 +0000758{
Josh Kunz4b25a502020-02-03 18:54:14 -0800759 qemu_log(" = 0x" TARGET_ABI_FMT_lx " (", ret);
ths33189d32007-11-01 00:13:36 +0000760 print_fdset(newselect_arg1,newselect_arg2);
Josh Kunz4b25a502020-02-03 18:54:14 -0800761 qemu_log(",");
ths33189d32007-11-01 00:13:36 +0000762 print_fdset(newselect_arg1,newselect_arg3);
Josh Kunz4b25a502020-02-03 18:54:14 -0800763 qemu_log(",");
ths33189d32007-11-01 00:13:36 +0000764 print_fdset(newselect_arg1,newselect_arg4);
Josh Kunz4b25a502020-02-03 18:54:14 -0800765 qemu_log(",");
Mika Westerberg74d753a2009-04-07 16:57:29 +0300766 print_timeval(newselect_arg5, 1);
Josh Kunz4b25a502020-02-03 18:54:14 -0800767 qemu_log(")\n");
ths33189d32007-11-01 00:13:36 +0000768}
thsf3e32852007-11-03 15:12:16 +0000769#endif
ths33189d32007-11-01 00:13:36 +0000770
Aleksandar Markovic19f59bc2016-09-22 18:56:50 +0200771/* special meanings of adjtimex()' non-negative return values */
772#define TARGET_TIME_OK 0 /* clock synchronized, no leap second */
773#define TARGET_TIME_INS 1 /* insert leap second */
774#define TARGET_TIME_DEL 2 /* delete leap second */
775#define TARGET_TIME_OOP 3 /* leap second in progress */
776#define TARGET_TIME_WAIT 4 /* leap second has occurred */
777#define TARGET_TIME_ERROR 5 /* clock not synchronized */
778static void
779print_syscall_ret_adjtimex(const struct syscallname *name, abi_long ret)
780{
781 const char *errstr = NULL;
782
Josh Kunz4b25a502020-02-03 18:54:14 -0800783 qemu_log(" = ");
Aleksandar Markovic19f59bc2016-09-22 18:56:50 +0200784 if (ret < 0) {
Josh Kunz4b25a502020-02-03 18:54:14 -0800785 qemu_log("-1 errno=%d", errno);
Aleksandar Markovic19f59bc2016-09-22 18:56:50 +0200786 errstr = target_strerror(-ret);
787 if (errstr) {
Josh Kunz4b25a502020-02-03 18:54:14 -0800788 qemu_log(" (%s)", errstr);
Aleksandar Markovic19f59bc2016-09-22 18:56:50 +0200789 }
790 } else {
Josh Kunz4b25a502020-02-03 18:54:14 -0800791 qemu_log(TARGET_ABI_FMT_ld, ret);
Aleksandar Markovic19f59bc2016-09-22 18:56:50 +0200792 switch (ret) {
793 case TARGET_TIME_OK:
Josh Kunz4b25a502020-02-03 18:54:14 -0800794 qemu_log(" TIME_OK (clock synchronized, no leap second)");
Aleksandar Markovic19f59bc2016-09-22 18:56:50 +0200795 break;
796 case TARGET_TIME_INS:
Josh Kunz4b25a502020-02-03 18:54:14 -0800797 qemu_log(" TIME_INS (insert leap second)");
Aleksandar Markovic19f59bc2016-09-22 18:56:50 +0200798 break;
799 case TARGET_TIME_DEL:
Josh Kunz4b25a502020-02-03 18:54:14 -0800800 qemu_log(" TIME_DEL (delete leap second)");
Aleksandar Markovic19f59bc2016-09-22 18:56:50 +0200801 break;
802 case TARGET_TIME_OOP:
Josh Kunz4b25a502020-02-03 18:54:14 -0800803 qemu_log(" TIME_OOP (leap second in progress)");
Aleksandar Markovic19f59bc2016-09-22 18:56:50 +0200804 break;
805 case TARGET_TIME_WAIT:
Josh Kunz4b25a502020-02-03 18:54:14 -0800806 qemu_log(" TIME_WAIT (leap second has occurred)");
Aleksandar Markovic19f59bc2016-09-22 18:56:50 +0200807 break;
808 case TARGET_TIME_ERROR:
Josh Kunz4b25a502020-02-03 18:54:14 -0800809 qemu_log(" TIME_ERROR (clock not synchronized)");
Aleksandar Markovic19f59bc2016-09-22 18:56:50 +0200810 break;
811 }
812 }
813
Josh Kunz4b25a502020-02-03 18:54:14 -0800814 qemu_log("\n");
Aleksandar Markovic19f59bc2016-09-22 18:56:50 +0200815}
816
Mika Westerberg74d753a2009-04-07 16:57:29 +0300817UNUSED static struct flags access_flags[] = {
818 FLAG_GENERIC(F_OK),
819 FLAG_GENERIC(R_OK),
820 FLAG_GENERIC(W_OK),
821 FLAG_GENERIC(X_OK),
822 FLAG_END,
823};
824
825UNUSED static struct flags at_file_flags[] = {
826#ifdef AT_EACCESS
827 FLAG_GENERIC(AT_EACCESS),
828#endif
829#ifdef AT_SYMLINK_NOFOLLOW
830 FLAG_GENERIC(AT_SYMLINK_NOFOLLOW),
831#endif
832 FLAG_END,
833};
834
835UNUSED static struct flags unlinkat_flags[] = {
836#ifdef AT_REMOVEDIR
837 FLAG_GENERIC(AT_REMOVEDIR),
838#endif
839 FLAG_END,
840};
841
842UNUSED static struct flags mode_flags[] = {
843 FLAG_GENERIC(S_IFSOCK),
844 FLAG_GENERIC(S_IFLNK),
845 FLAG_GENERIC(S_IFREG),
846 FLAG_GENERIC(S_IFBLK),
847 FLAG_GENERIC(S_IFDIR),
848 FLAG_GENERIC(S_IFCHR),
849 FLAG_GENERIC(S_IFIFO),
850 FLAG_END,
851};
852
853UNUSED static struct flags open_access_flags[] = {
854 FLAG_TARGET(O_RDONLY),
855 FLAG_TARGET(O_WRONLY),
856 FLAG_TARGET(O_RDWR),
857 FLAG_END,
858};
859
860UNUSED static struct flags open_flags[] = {
861 FLAG_TARGET(O_APPEND),
862 FLAG_TARGET(O_CREAT),
863 FLAG_TARGET(O_DIRECTORY),
864 FLAG_TARGET(O_EXCL),
865 FLAG_TARGET(O_LARGEFILE),
866 FLAG_TARGET(O_NOCTTY),
867 FLAG_TARGET(O_NOFOLLOW),
868 FLAG_TARGET(O_NONBLOCK), /* also O_NDELAY */
Richard Hendersonafc87632012-07-25 14:30:34 -0700869 FLAG_TARGET(O_DSYNC),
870 FLAG_TARGET(__O_SYNC),
Mika Westerberg74d753a2009-04-07 16:57:29 +0300871 FLAG_TARGET(O_TRUNC),
872#ifdef O_DIRECT
873 FLAG_TARGET(O_DIRECT),
874#endif
Richard Hendersonafc87632012-07-25 14:30:34 -0700875#ifdef O_NOATIME
876 FLAG_TARGET(O_NOATIME),
877#endif
878#ifdef O_CLOEXEC
879 FLAG_TARGET(O_CLOEXEC),
880#endif
881#ifdef O_PATH
882 FLAG_TARGET(O_PATH),
883#endif
Riku Voipio5f9cee42017-08-08 16:01:19 +0300884#ifdef O_TMPFILE
885 FLAG_TARGET(O_TMPFILE),
886 FLAG_TARGET(__O_TMPFILE),
887#endif
Mika Westerberg74d753a2009-04-07 16:57:29 +0300888 FLAG_END,
889};
890
891UNUSED static struct flags mount_flags[] = {
892#ifdef MS_BIND
893 FLAG_GENERIC(MS_BIND),
894#endif
895#ifdef MS_DIRSYNC
896 FLAG_GENERIC(MS_DIRSYNC),
897#endif
898 FLAG_GENERIC(MS_MANDLOCK),
899#ifdef MS_MOVE
900 FLAG_GENERIC(MS_MOVE),
901#endif
902 FLAG_GENERIC(MS_NOATIME),
903 FLAG_GENERIC(MS_NODEV),
904 FLAG_GENERIC(MS_NODIRATIME),
905 FLAG_GENERIC(MS_NOEXEC),
906 FLAG_GENERIC(MS_NOSUID),
907 FLAG_GENERIC(MS_RDONLY),
908#ifdef MS_RELATIME
909 FLAG_GENERIC(MS_RELATIME),
910#endif
911 FLAG_GENERIC(MS_REMOUNT),
912 FLAG_GENERIC(MS_SYNCHRONOUS),
913 FLAG_END,
914};
915
916UNUSED static struct flags umount2_flags[] = {
917#ifdef MNT_FORCE
918 FLAG_GENERIC(MNT_FORCE),
919#endif
920#ifdef MNT_DETACH
921 FLAG_GENERIC(MNT_DETACH),
922#endif
923#ifdef MNT_EXPIRE
924 FLAG_GENERIC(MNT_EXPIRE),
925#endif
926 FLAG_END,
927};
928
929UNUSED static struct flags mmap_prot_flags[] = {
930 FLAG_GENERIC(PROT_NONE),
931 FLAG_GENERIC(PROT_EXEC),
932 FLAG_GENERIC(PROT_READ),
933 FLAG_GENERIC(PROT_WRITE),
Paul Brook9e0b74a2010-06-16 13:03:51 +0100934 FLAG_TARGET(PROT_SEM),
935 FLAG_GENERIC(PROT_GROWSDOWN),
936 FLAG_GENERIC(PROT_GROWSUP),
Mika Westerberg74d753a2009-04-07 16:57:29 +0300937 FLAG_END,
938};
939
940UNUSED static struct flags mmap_flags[] = {
941 FLAG_TARGET(MAP_SHARED),
942 FLAG_TARGET(MAP_PRIVATE),
943 FLAG_TARGET(MAP_ANONYMOUS),
944 FLAG_TARGET(MAP_DENYWRITE),
945 FLAG_TARGET(MAP_FIXED),
946 FLAG_TARGET(MAP_GROWSDOWN),
Mike Frysinger906c1b82011-02-07 01:05:52 -0500947 FLAG_TARGET(MAP_EXECUTABLE),
Mika Westerberg74d753a2009-04-07 16:57:29 +0300948#ifdef MAP_LOCKED
949 FLAG_TARGET(MAP_LOCKED),
950#endif
951#ifdef MAP_NONBLOCK
952 FLAG_TARGET(MAP_NONBLOCK),
953#endif
954 FLAG_TARGET(MAP_NORESERVE),
955#ifdef MAP_POPULATE
956 FLAG_TARGET(MAP_POPULATE),
957#endif
Mike Frysinger906c1b82011-02-07 01:05:52 -0500958#ifdef TARGET_MAP_UNINITIALIZED
959 FLAG_TARGET(MAP_UNINITIALIZED),
960#endif
Mika Westerberg74d753a2009-04-07 16:57:29 +0300961 FLAG_END,
962};
963
Laurent Vivier608e5592011-04-07 00:25:32 +0200964UNUSED static struct flags clone_flags[] = {
965 FLAG_GENERIC(CLONE_VM),
966 FLAG_GENERIC(CLONE_FS),
967 FLAG_GENERIC(CLONE_FILES),
968 FLAG_GENERIC(CLONE_SIGHAND),
969 FLAG_GENERIC(CLONE_PTRACE),
970 FLAG_GENERIC(CLONE_VFORK),
971 FLAG_GENERIC(CLONE_PARENT),
972 FLAG_GENERIC(CLONE_THREAD),
973 FLAG_GENERIC(CLONE_NEWNS),
974 FLAG_GENERIC(CLONE_SYSVSEM),
975 FLAG_GENERIC(CLONE_SETTLS),
976 FLAG_GENERIC(CLONE_PARENT_SETTID),
977 FLAG_GENERIC(CLONE_CHILD_CLEARTID),
978 FLAG_GENERIC(CLONE_DETACHED),
979 FLAG_GENERIC(CLONE_UNTRACED),
980 FLAG_GENERIC(CLONE_CHILD_SETTID),
Stefan Weil6f11f012011-04-27 10:44:38 +0200981#if defined(CLONE_NEWUTS)
Laurent Vivier608e5592011-04-07 00:25:32 +0200982 FLAG_GENERIC(CLONE_NEWUTS),
Stefan Weil6f11f012011-04-27 10:44:38 +0200983#endif
984#if defined(CLONE_NEWIPC)
Laurent Vivier608e5592011-04-07 00:25:32 +0200985 FLAG_GENERIC(CLONE_NEWIPC),
Stefan Weil6f11f012011-04-27 10:44:38 +0200986#endif
987#if defined(CLONE_NEWUSER)
Laurent Vivier608e5592011-04-07 00:25:32 +0200988 FLAG_GENERIC(CLONE_NEWUSER),
Stefan Weil6f11f012011-04-27 10:44:38 +0200989#endif
990#if defined(CLONE_NEWPID)
Laurent Vivier608e5592011-04-07 00:25:32 +0200991 FLAG_GENERIC(CLONE_NEWPID),
Stefan Weil6f11f012011-04-27 10:44:38 +0200992#endif
993#if defined(CLONE_NEWNET)
Laurent Vivier608e5592011-04-07 00:25:32 +0200994 FLAG_GENERIC(CLONE_NEWNET),
Stefan Weil6f11f012011-04-27 10:44:38 +0200995#endif
996#if defined(CLONE_IO)
Laurent Vivier608e5592011-04-07 00:25:32 +0200997 FLAG_GENERIC(CLONE_IO),
Stefan Weil6f11f012011-04-27 10:44:38 +0200998#endif
Laurent Vivier608e5592011-04-07 00:25:32 +0200999 FLAG_END,
1000};
1001
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02001002UNUSED static struct flags msg_flags[] = {
1003 /* send */
1004 FLAG_GENERIC(MSG_CONFIRM),
1005 FLAG_GENERIC(MSG_DONTROUTE),
1006 FLAG_GENERIC(MSG_DONTWAIT),
1007 FLAG_GENERIC(MSG_EOR),
1008 FLAG_GENERIC(MSG_MORE),
1009 FLAG_GENERIC(MSG_NOSIGNAL),
1010 FLAG_GENERIC(MSG_OOB),
1011 /* recv */
1012 FLAG_GENERIC(MSG_CMSG_CLOEXEC),
1013 FLAG_GENERIC(MSG_ERRQUEUE),
1014 FLAG_GENERIC(MSG_PEEK),
1015 FLAG_GENERIC(MSG_TRUNC),
1016 FLAG_GENERIC(MSG_WAITALL),
1017 /* recvmsg */
1018 FLAG_GENERIC(MSG_CTRUNC),
1019 FLAG_END,
1020};
1021
Jim Wilsond42744f2019-06-28 12:43:35 +02001022UNUSED static struct flags statx_flags[] = {
1023#ifdef AT_EMPTY_PATH
1024 FLAG_GENERIC(AT_EMPTY_PATH),
1025#endif
1026#ifdef AT_NO_AUTOMOUNT
1027 FLAG_GENERIC(AT_NO_AUTOMOUNT),
1028#endif
1029#ifdef AT_SYMLINK_NOFOLLOW
1030 FLAG_GENERIC(AT_SYMLINK_NOFOLLOW),
1031#endif
1032#ifdef AT_STATX_SYNC_AS_STAT
1033 FLAG_GENERIC(AT_STATX_SYNC_AS_STAT),
1034#endif
1035#ifdef AT_STATX_FORCE_SYNC
1036 FLAG_GENERIC(AT_STATX_FORCE_SYNC),
1037#endif
1038#ifdef AT_STATX_DONT_SYNC
1039 FLAG_GENERIC(AT_STATX_DONT_SYNC),
1040#endif
1041 FLAG_END,
1042};
1043
1044UNUSED static struct flags statx_mask[] = {
1045/* This must come first, because it includes everything. */
1046#ifdef STATX_ALL
1047 FLAG_GENERIC(STATX_ALL),
1048#endif
1049/* This must come second; it includes everything except STATX_BTIME. */
1050#ifdef STATX_BASIC_STATS
1051 FLAG_GENERIC(STATX_BASIC_STATS),
1052#endif
1053#ifdef STATX_TYPE
1054 FLAG_GENERIC(STATX_TYPE),
1055#endif
1056#ifdef STATX_MODE
1057 FLAG_GENERIC(STATX_MODE),
1058#endif
1059#ifdef STATX_NLINK
1060 FLAG_GENERIC(STATX_NLINK),
1061#endif
1062#ifdef STATX_UID
1063 FLAG_GENERIC(STATX_UID),
1064#endif
1065#ifdef STATX_GID
1066 FLAG_GENERIC(STATX_GID),
1067#endif
1068#ifdef STATX_ATIME
1069 FLAG_GENERIC(STATX_ATIME),
1070#endif
1071#ifdef STATX_MTIME
1072 FLAG_GENERIC(STATX_MTIME),
1073#endif
1074#ifdef STATX_CTIME
1075 FLAG_GENERIC(STATX_CTIME),
1076#endif
1077#ifdef STATX_INO
1078 FLAG_GENERIC(STATX_INO),
1079#endif
1080#ifdef STATX_SIZE
1081 FLAG_GENERIC(STATX_SIZE),
1082#endif
1083#ifdef STATX_BLOCKS
1084 FLAG_GENERIC(STATX_BLOCKS),
1085#endif
1086#ifdef STATX_BTIME
1087 FLAG_GENERIC(STATX_BTIME),
1088#endif
1089 FLAG_END,
1090};
1091
Mika Westerberg74d753a2009-04-07 16:57:29 +03001092/*
1093 * print_xxx utility functions. These are used to print syscall
1094 * parameters in certain format. All of these have parameter
1095 * named 'last'. This parameter is used to add comma to output
1096 * when last == 0.
1097 */
1098
1099static const char *
1100get_comma(int last)
1101{
1102 return ((last) ? "" : ",");
1103}
1104
1105static void
Laurent Vivierd2ee72a2011-02-15 21:10:44 +01001106print_flags(const struct flags *f, abi_long flags, int last)
Mika Westerberg74d753a2009-04-07 16:57:29 +03001107{
1108 const char *sep = "";
Mika Westerberg74d753a2009-04-07 16:57:29 +03001109 int n;
1110
Mika Westerberg74d753a2009-04-07 16:57:29 +03001111 if ((flags == 0) && (f->f_value == 0)) {
Josh Kunz4b25a502020-02-03 18:54:14 -08001112 qemu_log("%s%s", f->f_string, get_comma(last));
Mika Westerberg74d753a2009-04-07 16:57:29 +03001113 return;
1114 }
1115 for (n = 0; f->f_string != NULL; f++) {
1116 if ((f->f_value != 0) && ((flags & f->f_value) == f->f_value)) {
Josh Kunz4b25a502020-02-03 18:54:14 -08001117 qemu_log("%s%s", sep, f->f_string);
Mika Westerberg74d753a2009-04-07 16:57:29 +03001118 flags &= ~f->f_value;
1119 sep = "|";
1120 n++;
1121 }
1122 }
1123
1124 if (n > 0) {
1125 /* print rest of the flags as numeric */
1126 if (flags != 0) {
Josh Kunz4b25a502020-02-03 18:54:14 -08001127 qemu_log("%s%#x%s", sep, (unsigned int)flags, get_comma(last));
Mika Westerberg74d753a2009-04-07 16:57:29 +03001128 } else {
Josh Kunz4b25a502020-02-03 18:54:14 -08001129 qemu_log("%s", get_comma(last));
Mika Westerberg74d753a2009-04-07 16:57:29 +03001130 }
1131 } else {
1132 /* no string version of flags found, print them in hex then */
Josh Kunz4b25a502020-02-03 18:54:14 -08001133 qemu_log("%#x%s", (unsigned int)flags, get_comma(last));
Mika Westerberg74d753a2009-04-07 16:57:29 +03001134 }
1135}
1136
1137static void
Laurent Vivierd2ee72a2011-02-15 21:10:44 +01001138print_at_dirfd(abi_long dirfd, int last)
Mika Westerberg74d753a2009-04-07 16:57:29 +03001139{
Mika Westerberg74d753a2009-04-07 16:57:29 +03001140#ifdef AT_FDCWD
1141 if (dirfd == AT_FDCWD) {
Josh Kunz4b25a502020-02-03 18:54:14 -08001142 qemu_log("AT_FDCWD%s", get_comma(last));
Mika Westerberg74d753a2009-04-07 16:57:29 +03001143 return;
1144 }
1145#endif
Josh Kunz4b25a502020-02-03 18:54:14 -08001146 qemu_log("%d%s", (int)dirfd, get_comma(last));
Mika Westerberg74d753a2009-04-07 16:57:29 +03001147}
1148
1149static void
Laurent Vivierd2ee72a2011-02-15 21:10:44 +01001150print_file_mode(abi_long mode, int last)
Mika Westerberg74d753a2009-04-07 16:57:29 +03001151{
1152 const char *sep = "";
1153 const struct flags *m;
Mika Westerberg74d753a2009-04-07 16:57:29 +03001154
1155 for (m = &mode_flags[0]; m->f_string != NULL; m++) {
1156 if ((m->f_value & mode) == m->f_value) {
Josh Kunz4b25a502020-02-03 18:54:14 -08001157 qemu_log("%s%s", m->f_string, sep);
Mika Westerberg74d753a2009-04-07 16:57:29 +03001158 sep = "|";
1159 mode &= ~m->f_value;
1160 break;
1161 }
1162 }
1163
1164 mode &= ~S_IFMT;
1165 /* print rest of the mode as octal */
1166 if (mode != 0)
Josh Kunz4b25a502020-02-03 18:54:14 -08001167 qemu_log("%s%#o", sep, (unsigned int)mode);
Mika Westerberg74d753a2009-04-07 16:57:29 +03001168
Josh Kunz4b25a502020-02-03 18:54:14 -08001169 qemu_log("%s", get_comma(last));
Mika Westerberg74d753a2009-04-07 16:57:29 +03001170}
1171
1172static void
Laurent Vivierd2ee72a2011-02-15 21:10:44 +01001173print_open_flags(abi_long flags, int last)
Mika Westerberg74d753a2009-04-07 16:57:29 +03001174{
Mika Westerberg74d753a2009-04-07 16:57:29 +03001175 print_flags(open_access_flags, flags & TARGET_O_ACCMODE, 1);
1176 flags &= ~TARGET_O_ACCMODE;
1177 if (flags == 0) {
Josh Kunz4b25a502020-02-03 18:54:14 -08001178 qemu_log("%s", get_comma(last));
Mika Westerberg74d753a2009-04-07 16:57:29 +03001179 return;
1180 }
Josh Kunz4b25a502020-02-03 18:54:14 -08001181 qemu_log("|");
Mika Westerberg74d753a2009-04-07 16:57:29 +03001182 print_flags(open_flags, flags, last);
1183}
1184
1185static void
1186print_syscall_prologue(const struct syscallname *sc)
1187{
Josh Kunz4b25a502020-02-03 18:54:14 -08001188 qemu_log("%s(", sc->name);
Mika Westerberg74d753a2009-04-07 16:57:29 +03001189}
1190
1191/*ARGSUSED*/
1192static void
1193print_syscall_epilogue(const struct syscallname *sc)
1194{
1195 (void)sc;
Josh Kunz4b25a502020-02-03 18:54:14 -08001196 qemu_log(")");
Mika Westerberg74d753a2009-04-07 16:57:29 +03001197}
1198
1199static void
1200print_string(abi_long addr, int last)
1201{
1202 char *s;
1203
1204 if ((s = lock_user_string(addr)) != NULL) {
Josh Kunz4b25a502020-02-03 18:54:14 -08001205 qemu_log("\"%s\"%s", s, get_comma(last));
Mika Westerberg74d753a2009-04-07 16:57:29 +03001206 unlock_user(s, addr, 0);
1207 } else {
1208 /* can't get string out of it, so print it as pointer */
1209 print_pointer(addr, last);
1210 }
1211}
1212
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02001213#define MAX_PRINT_BUF 40
1214static void
1215print_buf(abi_long addr, abi_long len, int last)
1216{
1217 uint8_t *s;
1218 int i;
1219
1220 s = lock_user(VERIFY_READ, addr, len, 1);
1221 if (s) {
Josh Kunz4b25a502020-02-03 18:54:14 -08001222 qemu_log("\"");
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02001223 for (i = 0; i < MAX_PRINT_BUF && i < len; i++) {
1224 if (isprint(s[i])) {
Josh Kunz4b25a502020-02-03 18:54:14 -08001225 qemu_log("%c", s[i]);
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02001226 } else {
Josh Kunz4b25a502020-02-03 18:54:14 -08001227 qemu_log("\\%o", s[i]);
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02001228 }
1229 }
Josh Kunz4b25a502020-02-03 18:54:14 -08001230 qemu_log("\"");
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02001231 if (i != len) {
Josh Kunz4b25a502020-02-03 18:54:14 -08001232 qemu_log("...");
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02001233 }
1234 if (!last) {
Josh Kunz4b25a502020-02-03 18:54:14 -08001235 qemu_log(",");
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02001236 }
1237 unlock_user(s, addr, 0);
1238 } else {
1239 print_pointer(addr, last);
1240 }
1241}
1242
Mika Westerberg74d753a2009-04-07 16:57:29 +03001243/*
1244 * Prints out raw parameter using given format. Caller needs
1245 * to do byte swapping if needed.
1246 */
1247static void
1248print_raw_param(const char *fmt, abi_long param, int last)
1249{
1250 char format[64];
1251
1252 (void) snprintf(format, sizeof (format), "%s%s", fmt, get_comma(last));
Josh Kunz4b25a502020-02-03 18:54:14 -08001253 qemu_log(format, param);
Mika Westerberg74d753a2009-04-07 16:57:29 +03001254}
1255
1256static void
1257print_pointer(abi_long p, int last)
1258{
1259 if (p == 0)
Josh Kunz4b25a502020-02-03 18:54:14 -08001260 qemu_log("NULL%s", get_comma(last));
Mika Westerberg74d753a2009-04-07 16:57:29 +03001261 else
Josh Kunz4b25a502020-02-03 18:54:14 -08001262 qemu_log("0x" TARGET_ABI_FMT_lx "%s", p, get_comma(last));
Mika Westerberg74d753a2009-04-07 16:57:29 +03001263}
1264
1265/*
1266 * Reads 32-bit (int) number from guest address space from
1267 * address 'addr' and prints it.
1268 */
1269static void
1270print_number(abi_long addr, int last)
1271{
1272 if (addr == 0) {
Josh Kunz4b25a502020-02-03 18:54:14 -08001273 qemu_log("NULL%s", get_comma(last));
Mika Westerberg74d753a2009-04-07 16:57:29 +03001274 } else {
1275 int num;
1276
1277 get_user_s32(num, addr);
Josh Kunz4b25a502020-02-03 18:54:14 -08001278 qemu_log("[%d]%s", num, get_comma(last));
Mika Westerberg74d753a2009-04-07 16:57:29 +03001279 }
1280}
1281
1282static void
1283print_timeval(abi_ulong tv_addr, int last)
1284{
1285 if( tv_addr ) {
1286 struct target_timeval *tv;
1287
1288 tv = lock_user(VERIFY_READ, tv_addr, sizeof(*tv), 1);
Philippe Mathieu-Daudé8f930892019-10-21 13:48:49 +02001289 if (!tv) {
1290 print_pointer(tv_addr, last);
Mika Westerberg74d753a2009-04-07 16:57:29 +03001291 return;
Philippe Mathieu-Daudé8f930892019-10-21 13:48:49 +02001292 }
Josh Kunz4b25a502020-02-03 18:54:14 -08001293 qemu_log("{" TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld "}%s",
Laurent Vivier910ee4e2012-12-31 09:45:06 +00001294 tswapal(tv->tv_sec), tswapal(tv->tv_usec), get_comma(last));
Mika Westerberg74d753a2009-04-07 16:57:29 +03001295 unlock_user(tv, tv_addr, 0);
1296 } else
Josh Kunz4b25a502020-02-03 18:54:14 -08001297 qemu_log("NULL%s", get_comma(last));
Mika Westerberg74d753a2009-04-07 16:57:29 +03001298}
1299
Philippe Mathieu-Daudé6d33e032019-10-21 13:48:50 +02001300static void
1301print_timezone(abi_ulong tz_addr, int last)
1302{
1303 if (tz_addr) {
1304 struct target_timezone *tz;
1305
1306 tz = lock_user(VERIFY_READ, tz_addr, sizeof(*tz), 1);
1307 if (!tz) {
1308 print_pointer(tz_addr, last);
1309 return;
1310 }
Josh Kunz4b25a502020-02-03 18:54:14 -08001311 qemu_log("{%d,%d}%s", tswap32(tz->tz_minuteswest),
Philippe Mathieu-Daudé6d33e032019-10-21 13:48:50 +02001312 tswap32(tz->tz_dsttime), get_comma(last));
1313 unlock_user(tz, tz_addr, 0);
1314 } else {
Josh Kunz4b25a502020-02-03 18:54:14 -08001315 qemu_log("NULL%s", get_comma(last));
Philippe Mathieu-Daudé6d33e032019-10-21 13:48:50 +02001316 }
1317}
1318
Mika Westerberg74d753a2009-04-07 16:57:29 +03001319#undef UNUSED
1320
1321#ifdef TARGET_NR_accept
1322static void
1323print_accept(const struct syscallname *name,
1324 abi_long arg0, abi_long arg1, abi_long arg2,
1325 abi_long arg3, abi_long arg4, abi_long arg5)
1326{
1327 print_syscall_prologue(name);
Laurent Vivierd2ee72a2011-02-15 21:10:44 +01001328 print_raw_param("%d", arg0, 0);
Mika Westerberg74d753a2009-04-07 16:57:29 +03001329 print_pointer(arg1, 0);
1330 print_number(arg2, 1);
1331 print_syscall_epilogue(name);
1332}
1333#endif
1334
1335#ifdef TARGET_NR_access
1336static void
1337print_access(const struct syscallname *name,
1338 abi_long arg0, abi_long arg1, abi_long arg2,
1339 abi_long arg3, abi_long arg4, abi_long arg5)
1340{
1341 print_syscall_prologue(name);
1342 print_string(arg0, 0);
1343 print_flags(access_flags, arg1, 1);
1344 print_syscall_epilogue(name);
1345}
1346#endif
1347
1348#ifdef TARGET_NR_brk
1349static void
1350print_brk(const struct syscallname *name,
1351 abi_long arg0, abi_long arg1, abi_long arg2,
1352 abi_long arg3, abi_long arg4, abi_long arg5)
1353{
1354 print_syscall_prologue(name);
1355 print_pointer(arg0, 1);
1356 print_syscall_epilogue(name);
1357}
1358#endif
1359
1360#ifdef TARGET_NR_chdir
1361static void
1362print_chdir(const struct syscallname *name,
1363 abi_long arg0, abi_long arg1, abi_long arg2,
1364 abi_long arg3, abi_long arg4, abi_long arg5)
1365{
1366 print_syscall_prologue(name);
1367 print_string(arg0, 1);
1368 print_syscall_epilogue(name);
1369}
1370#endif
1371
Helge Deller1b7695f2019-02-27 20:11:15 +01001372#ifdef TARGET_NR_chroot
1373static void
1374print_chroot(const struct syscallname *name,
1375 abi_long arg0, abi_long arg1, abi_long arg2,
1376 abi_long arg3, abi_long arg4, abi_long arg5)
1377{
1378 print_syscall_prologue(name);
1379 print_string(arg0, 1);
1380 print_syscall_epilogue(name);
1381}
1382#endif
1383
Mika Westerberg74d753a2009-04-07 16:57:29 +03001384#ifdef TARGET_NR_chmod
1385static void
1386print_chmod(const struct syscallname *name,
1387 abi_long arg0, abi_long arg1, abi_long arg2,
1388 abi_long arg3, abi_long arg4, abi_long arg5)
1389{
1390 print_syscall_prologue(name);
1391 print_string(arg0, 0);
1392 print_file_mode(arg1, 1);
1393 print_syscall_epilogue(name);
1394}
1395#endif
1396
Aleksandar Markovic38860a02016-10-10 13:23:29 +02001397#ifdef TARGET_NR_clock_adjtime
1398static void
1399print_clock_adjtime(const struct syscallname *name,
1400 abi_long arg0, abi_long arg1, abi_long arg2,
1401 abi_long arg3, abi_long arg4, abi_long arg5)
1402{
1403 print_syscall_prologue(name);
1404 print_clockid(arg0, 0);
1405 print_pointer(arg1, 1);
1406 print_syscall_epilogue(name);
1407}
1408#endif
1409
Laurent Vivier608e5592011-04-07 00:25:32 +02001410#ifdef TARGET_NR_clone
Laurent Vivier84bd8282016-06-11 02:19:47 +02001411static void do_print_clone(unsigned int flags, abi_ulong newsp,
1412 abi_ulong parent_tidptr, target_ulong newtls,
1413 abi_ulong child_tidptr)
1414{
1415 print_flags(clone_flags, flags, 0);
1416 print_raw_param("child_stack=0x" TARGET_ABI_FMT_lx, newsp, 0);
1417 print_raw_param("parent_tidptr=0x" TARGET_ABI_FMT_lx, parent_tidptr, 0);
1418 print_raw_param("tls=0x" TARGET_ABI_FMT_lx, newtls, 0);
1419 print_raw_param("child_tidptr=0x" TARGET_ABI_FMT_lx, child_tidptr, 1);
1420}
1421
Laurent Vivier608e5592011-04-07 00:25:32 +02001422static void
1423print_clone(const struct syscallname *name,
Laurent Vivier84bd8282016-06-11 02:19:47 +02001424 abi_long arg1, abi_long arg2, abi_long arg3,
1425 abi_long arg4, abi_long arg5, abi_long arg6)
Laurent Vivier608e5592011-04-07 00:25:32 +02001426{
1427 print_syscall_prologue(name);
Laurent Vivier84bd8282016-06-11 02:19:47 +02001428#if defined(TARGET_MICROBLAZE)
1429 do_print_clone(arg1, arg2, arg4, arg6, arg5);
1430#elif defined(TARGET_CLONE_BACKWARDS)
1431 do_print_clone(arg1, arg2, arg3, arg4, arg5);
1432#elif defined(TARGET_CLONE_BACKWARDS2)
1433 do_print_clone(arg2, arg1, arg3, arg5, arg4);
Laurent Vivier608e5592011-04-07 00:25:32 +02001434#else
Laurent Vivier84bd8282016-06-11 02:19:47 +02001435 do_print_clone(arg1, arg2, arg3, arg5, arg4);
Laurent Vivier608e5592011-04-07 00:25:32 +02001436#endif
1437 print_syscall_epilogue(name);
1438}
1439#endif
1440
Mika Westerberg74d753a2009-04-07 16:57:29 +03001441#ifdef TARGET_NR_creat
1442static void
1443print_creat(const struct syscallname *name,
1444 abi_long arg0, abi_long arg1, abi_long arg2,
1445 abi_long arg3, abi_long arg4, abi_long arg5)
1446{
1447 print_syscall_prologue(name);
1448 print_string(arg0, 0);
1449 print_file_mode(arg1, 1);
1450 print_syscall_epilogue(name);
1451}
1452#endif
1453
1454#ifdef TARGET_NR_execv
1455static void
1456print_execv(const struct syscallname *name,
1457 abi_long arg0, abi_long arg1, abi_long arg2,
1458 abi_long arg3, abi_long arg4, abi_long arg5)
1459{
1460 print_syscall_prologue(name);
1461 print_string(arg0, 0);
Laurent Vivierd2ee72a2011-02-15 21:10:44 +01001462 print_raw_param("0x" TARGET_ABI_FMT_lx, arg1, 1);
Mika Westerberg74d753a2009-04-07 16:57:29 +03001463 print_syscall_epilogue(name);
1464}
1465#endif
1466
1467#ifdef TARGET_NR_faccessat
1468static void
1469print_faccessat(const struct syscallname *name,
1470 abi_long arg0, abi_long arg1, abi_long arg2,
1471 abi_long arg3, abi_long arg4, abi_long arg5)
1472{
1473 print_syscall_prologue(name);
1474 print_at_dirfd(arg0, 0);
1475 print_string(arg1, 0);
1476 print_flags(access_flags, arg2, 0);
1477 print_flags(at_file_flags, arg3, 1);
1478 print_syscall_epilogue(name);
1479}
1480#endif
1481
1482#ifdef TARGET_NR_fchmodat
1483static void
1484print_fchmodat(const struct syscallname *name,
1485 abi_long arg0, abi_long arg1, abi_long arg2,
1486 abi_long arg3, abi_long arg4, abi_long arg5)
1487{
1488 print_syscall_prologue(name);
1489 print_at_dirfd(arg0, 0);
1490 print_string(arg1, 0);
1491 print_file_mode(arg2, 0);
1492 print_flags(at_file_flags, arg3, 1);
1493 print_syscall_epilogue(name);
1494}
1495#endif
1496
1497#ifdef TARGET_NR_fchownat
1498static void
1499print_fchownat(const struct syscallname *name,
1500 abi_long arg0, abi_long arg1, abi_long arg2,
1501 abi_long arg3, abi_long arg4, abi_long arg5)
1502{
1503 print_syscall_prologue(name);
1504 print_at_dirfd(arg0, 0);
1505 print_string(arg1, 0);
Laurent Vivierd2ee72a2011-02-15 21:10:44 +01001506 print_raw_param("%d", arg2, 0);
1507 print_raw_param("%d", arg3, 0);
Mika Westerberg74d753a2009-04-07 16:57:29 +03001508 print_flags(at_file_flags, arg4, 1);
1509 print_syscall_epilogue(name);
1510}
1511#endif
1512
1513#if defined(TARGET_NR_fcntl) || defined(TARGET_NR_fcntl64)
1514static void
1515print_fcntl(const struct syscallname *name,
1516 abi_long arg0, abi_long arg1, abi_long arg2,
1517 abi_long arg3, abi_long arg4, abi_long arg5)
1518{
1519 print_syscall_prologue(name);
Laurent Vivierd2ee72a2011-02-15 21:10:44 +01001520 print_raw_param("%d", arg0, 0);
Laurent Vivierd95ec142012-12-31 21:00:11 +01001521 switch(arg1) {
1522 case TARGET_F_DUPFD:
Josh Kunz4b25a502020-02-03 18:54:14 -08001523 qemu_log("F_DUPFD,");
Laurent Vivierd95ec142012-12-31 21:00:11 +01001524 print_raw_param(TARGET_ABI_FMT_ld, arg2, 1);
1525 break;
1526 case TARGET_F_GETFD:
Josh Kunz4b25a502020-02-03 18:54:14 -08001527 qemu_log("F_GETFD");
Laurent Vivierd95ec142012-12-31 21:00:11 +01001528 break;
1529 case TARGET_F_SETFD:
Josh Kunz4b25a502020-02-03 18:54:14 -08001530 qemu_log("F_SETFD,");
Laurent Vivierd95ec142012-12-31 21:00:11 +01001531 print_raw_param(TARGET_ABI_FMT_ld, arg2, 1);
1532 break;
1533 case TARGET_F_GETFL:
Josh Kunz4b25a502020-02-03 18:54:14 -08001534 qemu_log("F_GETFL");
Laurent Vivierd95ec142012-12-31 21:00:11 +01001535 break;
1536 case TARGET_F_SETFL:
Josh Kunz4b25a502020-02-03 18:54:14 -08001537 qemu_log("F_SETFL,");
Laurent Vivierd95ec142012-12-31 21:00:11 +01001538 print_open_flags(arg2, 1);
1539 break;
1540 case TARGET_F_GETLK:
Josh Kunz4b25a502020-02-03 18:54:14 -08001541 qemu_log("F_GETLK,");
Laurent Vivierd95ec142012-12-31 21:00:11 +01001542 print_pointer(arg2, 1);
1543 break;
1544 case TARGET_F_SETLK:
Josh Kunz4b25a502020-02-03 18:54:14 -08001545 qemu_log("F_SETLK,");
Laurent Vivierd95ec142012-12-31 21:00:11 +01001546 print_pointer(arg2, 1);
1547 break;
1548 case TARGET_F_SETLKW:
Josh Kunz4b25a502020-02-03 18:54:14 -08001549 qemu_log("F_SETLKW,");
Laurent Vivierd95ec142012-12-31 21:00:11 +01001550 print_pointer(arg2, 1);
1551 break;
1552 case TARGET_F_GETOWN:
Josh Kunz4b25a502020-02-03 18:54:14 -08001553 qemu_log("F_GETOWN");
Laurent Vivierd95ec142012-12-31 21:00:11 +01001554 break;
1555 case TARGET_F_SETOWN:
Josh Kunz4b25a502020-02-03 18:54:14 -08001556 qemu_log("F_SETOWN,");
Laurent Vivierd95ec142012-12-31 21:00:11 +01001557 print_raw_param(TARGET_ABI_FMT_ld, arg2, 0);
1558 break;
1559 case TARGET_F_GETSIG:
Josh Kunz4b25a502020-02-03 18:54:14 -08001560 qemu_log("F_GETSIG");
Laurent Vivierd95ec142012-12-31 21:00:11 +01001561 break;
1562 case TARGET_F_SETSIG:
Josh Kunz4b25a502020-02-03 18:54:14 -08001563 qemu_log("F_SETSIG,");
Laurent Vivierd95ec142012-12-31 21:00:11 +01001564 print_raw_param(TARGET_ABI_FMT_ld, arg2, 0);
1565 break;
1566#if TARGET_ABI_BITS == 32
1567 case TARGET_F_GETLK64:
Josh Kunz4b25a502020-02-03 18:54:14 -08001568 qemu_log("F_GETLK64,");
Laurent Vivierd95ec142012-12-31 21:00:11 +01001569 print_pointer(arg2, 1);
1570 break;
1571 case TARGET_F_SETLK64:
Josh Kunz4b25a502020-02-03 18:54:14 -08001572 qemu_log("F_SETLK64,");
Laurent Vivierd95ec142012-12-31 21:00:11 +01001573 print_pointer(arg2, 1);
1574 break;
1575 case TARGET_F_SETLKW64:
Josh Kunz4b25a502020-02-03 18:54:14 -08001576 qemu_log("F_SETLKW64,");
Laurent Vivierd95ec142012-12-31 21:00:11 +01001577 print_pointer(arg2, 1);
1578 break;
1579#endif
1580 case TARGET_F_SETLEASE:
Josh Kunz4b25a502020-02-03 18:54:14 -08001581 qemu_log("F_SETLEASE,");
Laurent Vivierd95ec142012-12-31 21:00:11 +01001582 print_raw_param(TARGET_ABI_FMT_ld, arg2, 0);
1583 break;
1584 case TARGET_F_GETLEASE:
Josh Kunz4b25a502020-02-03 18:54:14 -08001585 qemu_log("F_GETLEASE");
Laurent Vivierd95ec142012-12-31 21:00:11 +01001586 break;
Peter Maydell7e3b92e2016-06-20 15:50:37 +01001587 case TARGET_F_SETPIPE_SZ:
Josh Kunz4b25a502020-02-03 18:54:14 -08001588 qemu_log("F_SETPIPE_SZ,");
Peter Maydell7e3b92e2016-06-20 15:50:37 +01001589 print_raw_param(TARGET_ABI_FMT_ld, arg2, 1);
1590 break;
1591 case TARGET_F_GETPIPE_SZ:
Josh Kunz4b25a502020-02-03 18:54:14 -08001592 qemu_log("F_GETPIPE_SZ");
Peter Maydell7e3b92e2016-06-20 15:50:37 +01001593 break;
Laurent Vivierd95ec142012-12-31 21:00:11 +01001594 case TARGET_F_DUPFD_CLOEXEC:
Josh Kunz4b25a502020-02-03 18:54:14 -08001595 qemu_log("F_DUPFD_CLOEXEC,");
Laurent Vivierd95ec142012-12-31 21:00:11 +01001596 print_raw_param(TARGET_ABI_FMT_ld, arg2, 1);
1597 break;
1598 case TARGET_F_NOTIFY:
Josh Kunz4b25a502020-02-03 18:54:14 -08001599 qemu_log("F_NOTIFY,");
Laurent Vivierd95ec142012-12-31 21:00:11 +01001600 print_raw_param(TARGET_ABI_FMT_ld, arg2, 0);
1601 break;
1602 default:
1603 print_raw_param(TARGET_ABI_FMT_ld, arg1, 0);
1604 print_pointer(arg2, 1);
1605 break;
1606 }
Mika Westerberg74d753a2009-04-07 16:57:29 +03001607 print_syscall_epilogue(name);
1608}
1609#define print_fcntl64 print_fcntl
1610#endif
1611
1612
1613#ifdef TARGET_NR_futimesat
1614static void
1615print_futimesat(const struct syscallname *name,
1616 abi_long arg0, abi_long arg1, abi_long arg2,
1617 abi_long arg3, abi_long arg4, abi_long arg5)
1618{
1619 print_syscall_prologue(name);
1620 print_at_dirfd(arg0, 0);
1621 print_string(arg1, 0);
1622 print_timeval(arg2, 0);
1623 print_timeval(arg2 + sizeof (struct target_timeval), 1);
1624 print_syscall_epilogue(name);
1625}
1626#endif
1627
Philippe Mathieu-Daudé0d2187c2019-10-21 13:48:51 +02001628#ifdef TARGET_NR_settimeofday
1629static void
1630print_settimeofday(const struct syscallname *name,
1631 abi_long arg0, abi_long arg1, abi_long arg2,
1632 abi_long arg3, abi_long arg4, abi_long arg5)
1633{
1634 print_syscall_prologue(name);
1635 print_timeval(arg0, 0);
1636 print_timezone(arg1, 1);
1637 print_syscall_epilogue(name);
1638}
1639#endif
1640
Mika Westerberg74d753a2009-04-07 16:57:29 +03001641#ifdef TARGET_NR_link
1642static void
1643print_link(const struct syscallname *name,
1644 abi_long arg0, abi_long arg1, abi_long arg2,
1645 abi_long arg3, abi_long arg4, abi_long arg5)
1646{
1647 print_syscall_prologue(name);
1648 print_string(arg0, 0);
1649 print_string(arg1, 1);
1650 print_syscall_epilogue(name);
1651}
1652#endif
1653
1654#ifdef TARGET_NR_linkat
1655static void
1656print_linkat(const struct syscallname *name,
1657 abi_long arg0, abi_long arg1, abi_long arg2,
1658 abi_long arg3, abi_long arg4, abi_long arg5)
1659{
1660 print_syscall_prologue(name);
1661 print_at_dirfd(arg0, 0);
1662 print_string(arg1, 0);
1663 print_at_dirfd(arg2, 0);
1664 print_string(arg3, 0);
1665 print_flags(at_file_flags, arg4, 1);
1666 print_syscall_epilogue(name);
1667}
1668#endif
1669
Laurent Vivier608e5592011-04-07 00:25:32 +02001670#ifdef TARGET_NR__llseek
1671static void
1672print__llseek(const struct syscallname *name,
1673 abi_long arg0, abi_long arg1, abi_long arg2,
1674 abi_long arg3, abi_long arg4, abi_long arg5)
1675{
1676 const char *whence = "UNKNOWN";
1677 print_syscall_prologue(name);
1678 print_raw_param("%d", arg0, 0);
1679 print_raw_param("%ld", arg1, 0);
1680 print_raw_param("%ld", arg2, 0);
1681 print_pointer(arg3, 0);
1682 switch(arg4) {
1683 case SEEK_SET: whence = "SEEK_SET"; break;
1684 case SEEK_CUR: whence = "SEEK_CUR"; break;
1685 case SEEK_END: whence = "SEEK_END"; break;
1686 }
Josh Kunz4b25a502020-02-03 18:54:14 -08001687 qemu_log("%s", whence);
Laurent Vivier608e5592011-04-07 00:25:32 +02001688 print_syscall_epilogue(name);
1689}
1690#endif
1691
Laurent Vivier8997d1b2016-06-11 02:19:46 +02001692#if defined(TARGET_NR_socket)
1693static void
1694print_socket(const struct syscallname *name,
1695 abi_long arg0, abi_long arg1, abi_long arg2,
1696 abi_long arg3, abi_long arg4, abi_long arg5)
1697{
1698 abi_ulong domain = arg0, type = arg1, protocol = arg2;
1699
1700 print_syscall_prologue(name);
1701 print_socket_domain(domain);
Josh Kunz4b25a502020-02-03 18:54:14 -08001702 qemu_log(",");
Laurent Vivier8997d1b2016-06-11 02:19:46 +02001703 print_socket_type(type);
Josh Kunz4b25a502020-02-03 18:54:14 -08001704 qemu_log(",");
Laurent Vivier8997d1b2016-06-11 02:19:46 +02001705 if (domain == AF_PACKET ||
1706 (domain == AF_INET && type == TARGET_SOCK_PACKET)) {
1707 protocol = tswap16(protocol);
1708 }
1709 print_socket_protocol(domain, type, protocol);
1710 print_syscall_epilogue(name);
1711}
1712
1713#endif
1714
Philippe Mathieu-Daudébb105402019-10-21 13:48:55 +02001715#if defined(TARGET_NR_socketcall) || defined(TARGET_NR_bind)
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02001716
Philippe Mathieu-Daudéd84fe1e2019-10-21 13:48:54 +02001717static void print_sockfd(abi_long sockfd, int last)
1718{
1719 print_raw_param(TARGET_ABI_FMT_ld, sockfd, last);
1720}
1721
1722#endif
1723
1724#if defined(TARGET_NR_socketcall)
1725
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02001726#define get_user_ualx(x, gaddr, idx) \
1727 get_user_ual(x, (gaddr) + (idx) * sizeof(abi_long))
1728
1729static void do_print_socket(const char *name, abi_long arg1)
1730{
1731 abi_ulong domain, type, protocol;
1732
1733 get_user_ualx(domain, arg1, 0);
1734 get_user_ualx(type, arg1, 1);
1735 get_user_ualx(protocol, arg1, 2);
Josh Kunz4b25a502020-02-03 18:54:14 -08001736 qemu_log("%s(", name);
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02001737 print_socket_domain(domain);
Josh Kunz4b25a502020-02-03 18:54:14 -08001738 qemu_log(",");
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02001739 print_socket_type(type);
Josh Kunz4b25a502020-02-03 18:54:14 -08001740 qemu_log(",");
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02001741 if (domain == AF_PACKET ||
1742 (domain == AF_INET && type == TARGET_SOCK_PACKET)) {
1743 protocol = tswap16(protocol);
1744 }
1745 print_socket_protocol(domain, type, protocol);
Josh Kunz4b25a502020-02-03 18:54:14 -08001746 qemu_log(")");
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02001747}
1748
1749static void do_print_sockaddr(const char *name, abi_long arg1)
1750{
1751 abi_ulong sockfd, addr, addrlen;
1752
1753 get_user_ualx(sockfd, arg1, 0);
1754 get_user_ualx(addr, arg1, 1);
1755 get_user_ualx(addrlen, arg1, 2);
1756
Josh Kunz4b25a502020-02-03 18:54:14 -08001757 qemu_log("%s(", name);
Philippe Mathieu-Daudéd84fe1e2019-10-21 13:48:54 +02001758 print_sockfd(sockfd, 0);
Philippe Mathieu-Daudé42b15d72019-10-21 13:48:56 +02001759 print_sockaddr(addr, addrlen, 0);
Josh Kunz4b25a502020-02-03 18:54:14 -08001760 qemu_log(")");
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02001761}
1762
1763static void do_print_listen(const char *name, abi_long arg1)
1764{
1765 abi_ulong sockfd, backlog;
1766
1767 get_user_ualx(sockfd, arg1, 0);
1768 get_user_ualx(backlog, arg1, 1);
1769
Josh Kunz4b25a502020-02-03 18:54:14 -08001770 qemu_log("%s(", name);
Philippe Mathieu-Daudéd84fe1e2019-10-21 13:48:54 +02001771 print_sockfd(sockfd, 0);
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02001772 print_raw_param(TARGET_ABI_FMT_ld, backlog, 1);
Josh Kunz4b25a502020-02-03 18:54:14 -08001773 qemu_log(")");
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02001774}
1775
1776static void do_print_socketpair(const char *name, abi_long arg1)
1777{
1778 abi_ulong domain, type, protocol, tab;
1779
1780 get_user_ualx(domain, arg1, 0);
1781 get_user_ualx(type, arg1, 1);
1782 get_user_ualx(protocol, arg1, 2);
1783 get_user_ualx(tab, arg1, 3);
1784
Josh Kunz4b25a502020-02-03 18:54:14 -08001785 qemu_log("%s(", name);
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02001786 print_socket_domain(domain);
Josh Kunz4b25a502020-02-03 18:54:14 -08001787 qemu_log(",");
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02001788 print_socket_type(type);
Josh Kunz4b25a502020-02-03 18:54:14 -08001789 qemu_log(",");
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02001790 print_socket_protocol(domain, type, protocol);
Josh Kunz4b25a502020-02-03 18:54:14 -08001791 qemu_log(",");
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02001792 print_raw_param(TARGET_ABI_FMT_lx, tab, 1);
Josh Kunz4b25a502020-02-03 18:54:14 -08001793 qemu_log(")");
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02001794}
1795
1796static void do_print_sendrecv(const char *name, abi_long arg1)
1797{
1798 abi_ulong sockfd, msg, len, flags;
1799
1800 get_user_ualx(sockfd, arg1, 0);
1801 get_user_ualx(msg, arg1, 1);
1802 get_user_ualx(len, arg1, 2);
1803 get_user_ualx(flags, arg1, 3);
1804
Josh Kunz4b25a502020-02-03 18:54:14 -08001805 qemu_log("%s(", name);
Philippe Mathieu-Daudéd84fe1e2019-10-21 13:48:54 +02001806 print_sockfd(sockfd, 0);
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02001807 print_buf(msg, len, 0);
1808 print_raw_param(TARGET_ABI_FMT_ld, len, 0);
1809 print_flags(msg_flags, flags, 1);
Josh Kunz4b25a502020-02-03 18:54:14 -08001810 qemu_log(")");
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02001811}
1812
1813static void do_print_msgaddr(const char *name, abi_long arg1)
1814{
1815 abi_ulong sockfd, msg, len, flags, addr, addrlen;
1816
1817 get_user_ualx(sockfd, arg1, 0);
1818 get_user_ualx(msg, arg1, 1);
1819 get_user_ualx(len, arg1, 2);
1820 get_user_ualx(flags, arg1, 3);
1821 get_user_ualx(addr, arg1, 4);
1822 get_user_ualx(addrlen, arg1, 5);
1823
Josh Kunz4b25a502020-02-03 18:54:14 -08001824 qemu_log("%s(", name);
Philippe Mathieu-Daudéd84fe1e2019-10-21 13:48:54 +02001825 print_sockfd(sockfd, 0);
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02001826 print_buf(msg, len, 0);
1827 print_raw_param(TARGET_ABI_FMT_ld, len, 0);
1828 print_flags(msg_flags, flags, 0);
Philippe Mathieu-Daudé42b15d72019-10-21 13:48:56 +02001829 print_sockaddr(addr, addrlen, 0);
Josh Kunz4b25a502020-02-03 18:54:14 -08001830 qemu_log(")");
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02001831}
1832
1833static void do_print_shutdown(const char *name, abi_long arg1)
1834{
1835 abi_ulong sockfd, how;
1836
1837 get_user_ualx(sockfd, arg1, 0);
1838 get_user_ualx(how, arg1, 1);
1839
Josh Kunz4b25a502020-02-03 18:54:14 -08001840 qemu_log("shutdown(");
Philippe Mathieu-Daudéd84fe1e2019-10-21 13:48:54 +02001841 print_sockfd(sockfd, 0);
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02001842 switch (how) {
1843 case SHUT_RD:
Josh Kunz4b25a502020-02-03 18:54:14 -08001844 qemu_log("SHUT_RD");
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02001845 break;
1846 case SHUT_WR:
Josh Kunz4b25a502020-02-03 18:54:14 -08001847 qemu_log("SHUT_WR");
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02001848 break;
1849 case SHUT_RDWR:
Josh Kunz4b25a502020-02-03 18:54:14 -08001850 qemu_log("SHUT_RDWR");
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02001851 break;
1852 default:
1853 print_raw_param(TARGET_ABI_FMT_ld, how, 1);
1854 break;
1855 }
Josh Kunz4b25a502020-02-03 18:54:14 -08001856 qemu_log(")");
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02001857}
1858
1859static void do_print_msg(const char *name, abi_long arg1)
1860{
1861 abi_ulong sockfd, msg, flags;
1862
1863 get_user_ualx(sockfd, arg1, 0);
1864 get_user_ualx(msg, arg1, 1);
1865 get_user_ualx(flags, arg1, 2);
1866
Josh Kunz4b25a502020-02-03 18:54:14 -08001867 qemu_log("%s(", name);
Philippe Mathieu-Daudéd84fe1e2019-10-21 13:48:54 +02001868 print_sockfd(sockfd, 0);
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02001869 print_pointer(msg, 0);
1870 print_flags(msg_flags, flags, 1);
Josh Kunz4b25a502020-02-03 18:54:14 -08001871 qemu_log(")");
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02001872}
1873
1874static void do_print_sockopt(const char *name, abi_long arg1)
1875{
1876 abi_ulong sockfd, level, optname, optval, optlen;
1877
1878 get_user_ualx(sockfd, arg1, 0);
1879 get_user_ualx(level, arg1, 1);
1880 get_user_ualx(optname, arg1, 2);
1881 get_user_ualx(optval, arg1, 3);
1882 get_user_ualx(optlen, arg1, 4);
1883
Josh Kunz4b25a502020-02-03 18:54:14 -08001884 qemu_log("%s(", name);
Philippe Mathieu-Daudéd84fe1e2019-10-21 13:48:54 +02001885 print_sockfd(sockfd, 0);
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02001886 switch (level) {
1887 case SOL_TCP:
Josh Kunz4b25a502020-02-03 18:54:14 -08001888 qemu_log("SOL_TCP,");
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02001889 print_raw_param(TARGET_ABI_FMT_ld, optname, 0);
1890 print_pointer(optval, 0);
1891 break;
1892 case SOL_IP:
Josh Kunz4b25a502020-02-03 18:54:14 -08001893 qemu_log("SOL_IP,");
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02001894 print_raw_param(TARGET_ABI_FMT_ld, optname, 0);
1895 print_pointer(optval, 0);
1896 break;
1897 case SOL_RAW:
Josh Kunz4b25a502020-02-03 18:54:14 -08001898 qemu_log("SOL_RAW,");
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02001899 print_raw_param(TARGET_ABI_FMT_ld, optname, 0);
1900 print_pointer(optval, 0);
1901 break;
1902 case TARGET_SOL_SOCKET:
Josh Kunz4b25a502020-02-03 18:54:14 -08001903 qemu_log("SOL_SOCKET,");
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02001904 switch (optname) {
1905 case TARGET_SO_DEBUG:
Josh Kunz4b25a502020-02-03 18:54:14 -08001906 qemu_log("SO_DEBUG,");
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02001907print_optint:
1908 print_number(optval, 0);
1909 break;
1910 case TARGET_SO_REUSEADDR:
Josh Kunz4b25a502020-02-03 18:54:14 -08001911 qemu_log("SO_REUSEADDR,");
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02001912 goto print_optint;
Yunqiang Su113a9dd2018-10-30 13:55:08 +01001913 case TARGET_SO_REUSEPORT:
Josh Kunz4b25a502020-02-03 18:54:14 -08001914 qemu_log("SO_REUSEPORT,");
Yunqiang Su113a9dd2018-10-30 13:55:08 +01001915 goto print_optint;
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02001916 case TARGET_SO_TYPE:
Josh Kunz4b25a502020-02-03 18:54:14 -08001917 qemu_log("SO_TYPE,");
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02001918 goto print_optint;
1919 case TARGET_SO_ERROR:
Josh Kunz4b25a502020-02-03 18:54:14 -08001920 qemu_log("SO_ERROR,");
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02001921 goto print_optint;
1922 case TARGET_SO_DONTROUTE:
Josh Kunz4b25a502020-02-03 18:54:14 -08001923 qemu_log("SO_DONTROUTE,");
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02001924 goto print_optint;
1925 case TARGET_SO_BROADCAST:
Josh Kunz4b25a502020-02-03 18:54:14 -08001926 qemu_log("SO_BROADCAST,");
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02001927 goto print_optint;
1928 case TARGET_SO_SNDBUF:
Josh Kunz4b25a502020-02-03 18:54:14 -08001929 qemu_log("SO_SNDBUF,");
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02001930 goto print_optint;
1931 case TARGET_SO_RCVBUF:
Josh Kunz4b25a502020-02-03 18:54:14 -08001932 qemu_log("SO_RCVBUF,");
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02001933 goto print_optint;
1934 case TARGET_SO_KEEPALIVE:
Josh Kunz4b25a502020-02-03 18:54:14 -08001935 qemu_log("SO_KEEPALIVE,");
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02001936 goto print_optint;
1937 case TARGET_SO_OOBINLINE:
Josh Kunz4b25a502020-02-03 18:54:14 -08001938 qemu_log("SO_OOBINLINE,");
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02001939 goto print_optint;
1940 case TARGET_SO_NO_CHECK:
Josh Kunz4b25a502020-02-03 18:54:14 -08001941 qemu_log("SO_NO_CHECK,");
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02001942 goto print_optint;
1943 case TARGET_SO_PRIORITY:
Josh Kunz4b25a502020-02-03 18:54:14 -08001944 qemu_log("SO_PRIORITY,");
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02001945 goto print_optint;
1946 case TARGET_SO_BSDCOMPAT:
Josh Kunz4b25a502020-02-03 18:54:14 -08001947 qemu_log("SO_BSDCOMPAT,");
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02001948 goto print_optint;
1949 case TARGET_SO_PASSCRED:
Josh Kunz4b25a502020-02-03 18:54:14 -08001950 qemu_log("SO_PASSCRED,");
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02001951 goto print_optint;
1952 case TARGET_SO_TIMESTAMP:
Josh Kunz4b25a502020-02-03 18:54:14 -08001953 qemu_log("SO_TIMESTAMP,");
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02001954 goto print_optint;
1955 case TARGET_SO_RCVLOWAT:
Josh Kunz4b25a502020-02-03 18:54:14 -08001956 qemu_log("SO_RCVLOWAT,");
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02001957 goto print_optint;
1958 case TARGET_SO_RCVTIMEO:
Josh Kunz4b25a502020-02-03 18:54:14 -08001959 qemu_log("SO_RCVTIMEO,");
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02001960 print_timeval(optval, 0);
1961 break;
1962 case TARGET_SO_SNDTIMEO:
Josh Kunz4b25a502020-02-03 18:54:14 -08001963 qemu_log("SO_SNDTIMEO,");
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02001964 print_timeval(optval, 0);
1965 break;
1966 case TARGET_SO_ATTACH_FILTER: {
1967 struct target_sock_fprog *fprog;
1968
Josh Kunz4b25a502020-02-03 18:54:14 -08001969 qemu_log("SO_ATTACH_FILTER,");
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02001970
1971 if (lock_user_struct(VERIFY_READ, fprog, optval, 0)) {
1972 struct target_sock_filter *filter;
Josh Kunz4b25a502020-02-03 18:54:14 -08001973 qemu_log("{");
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02001974 if (lock_user_struct(VERIFY_READ, filter,
1975 tswapal(fprog->filter), 0)) {
1976 int i;
1977 for (i = 0; i < tswap16(fprog->len) - 1; i++) {
Josh Kunz4b25a502020-02-03 18:54:14 -08001978 qemu_log("[%d]{0x%x,%d,%d,0x%x},",
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02001979 i, tswap16(filter[i].code),
1980 filter[i].jt, filter[i].jf,
1981 tswap32(filter[i].k));
1982 }
Josh Kunz4b25a502020-02-03 18:54:14 -08001983 qemu_log("[%d]{0x%x,%d,%d,0x%x}",
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02001984 i, tswap16(filter[i].code),
1985 filter[i].jt, filter[i].jf,
1986 tswap32(filter[i].k));
1987 } else {
Josh Kunz4b25a502020-02-03 18:54:14 -08001988 qemu_log(TARGET_ABI_FMT_lx, tswapal(fprog->filter));
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02001989 }
Josh Kunz4b25a502020-02-03 18:54:14 -08001990 qemu_log(",%d},", tswap16(fprog->len));
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02001991 unlock_user(fprog, optval, 0);
1992 } else {
1993 print_pointer(optval, 0);
1994 }
1995 break;
1996 }
1997 default:
1998 print_raw_param(TARGET_ABI_FMT_ld, optname, 0);
1999 print_pointer(optval, 0);
2000 break;
2001 }
2002 break;
2003 default:
2004 print_raw_param(TARGET_ABI_FMT_ld, level, 0);
2005 print_raw_param(TARGET_ABI_FMT_ld, optname, 0);
2006 print_pointer(optval, 0);
2007 break;
2008 }
2009 print_raw_param(TARGET_ABI_FMT_ld, optlen, 1);
Josh Kunz4b25a502020-02-03 18:54:14 -08002010 qemu_log(")");
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02002011}
2012
2013#define PRINT_SOCKOP(name, func) \
Aleksandar Markovicff71a452016-09-22 18:56:57 +02002014 [TARGET_SYS_##name] = { #name, func }
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02002015
2016static struct {
2017 const char *name;
2018 void (*print)(const char *, abi_long);
2019} scall[] = {
Aleksandar Markovicff71a452016-09-22 18:56:57 +02002020 PRINT_SOCKOP(SOCKET, do_print_socket),
2021 PRINT_SOCKOP(BIND, do_print_sockaddr),
2022 PRINT_SOCKOP(CONNECT, do_print_sockaddr),
2023 PRINT_SOCKOP(LISTEN, do_print_listen),
2024 PRINT_SOCKOP(ACCEPT, do_print_sockaddr),
2025 PRINT_SOCKOP(GETSOCKNAME, do_print_sockaddr),
2026 PRINT_SOCKOP(GETPEERNAME, do_print_sockaddr),
2027 PRINT_SOCKOP(SOCKETPAIR, do_print_socketpair),
2028 PRINT_SOCKOP(SEND, do_print_sendrecv),
2029 PRINT_SOCKOP(RECV, do_print_sendrecv),
2030 PRINT_SOCKOP(SENDTO, do_print_msgaddr),
2031 PRINT_SOCKOP(RECVFROM, do_print_msgaddr),
2032 PRINT_SOCKOP(SHUTDOWN, do_print_shutdown),
2033 PRINT_SOCKOP(SETSOCKOPT, do_print_sockopt),
2034 PRINT_SOCKOP(GETSOCKOPT, do_print_sockopt),
2035 PRINT_SOCKOP(SENDMSG, do_print_msg),
2036 PRINT_SOCKOP(RECVMSG, do_print_msg),
2037 PRINT_SOCKOP(ACCEPT4, NULL),
2038 PRINT_SOCKOP(RECVMMSG, NULL),
2039 PRINT_SOCKOP(SENDMMSG, NULL),
Laurent Vivierfb3aabf2016-06-11 02:19:45 +02002040};
2041
2042static void
2043print_socketcall(const struct syscallname *name,
2044 abi_long arg0, abi_long arg1, abi_long arg2,
2045 abi_long arg3, abi_long arg4, abi_long arg5)
2046{
2047 if (arg0 >= 0 && arg0 < ARRAY_SIZE(scall) && scall[arg0].print) {
2048 scall[arg0].print(scall[arg0].name, arg1);
2049 return;
2050 }
2051 print_syscall_prologue(name);
2052 print_raw_param(TARGET_ABI_FMT_ld, arg0, 0);
2053 print_raw_param(TARGET_ABI_FMT_ld, arg1, 0);
2054 print_raw_param(TARGET_ABI_FMT_ld, arg2, 0);
2055 print_raw_param(TARGET_ABI_FMT_ld, arg3, 0);
2056 print_raw_param(TARGET_ABI_FMT_ld, arg4, 0);
2057 print_raw_param(TARGET_ABI_FMT_ld, arg5, 0);
2058 print_syscall_epilogue(name);
2059}
2060#endif
2061
Philippe Mathieu-Daudébb105402019-10-21 13:48:55 +02002062#if defined(TARGET_NR_bind)
2063static void
2064print_bind(const struct syscallname *name,
2065 abi_long arg0, abi_long arg1, abi_long arg2,
2066 abi_long arg3, abi_long arg4, abi_long arg5)
2067{
2068 print_syscall_prologue(name);
2069 print_sockfd(arg0, 0);
2070 print_sockaddr(arg1, arg2, 1);
2071 print_syscall_epilogue(name);
2072}
2073#endif
2074
Mika Westerberg74d753a2009-04-07 16:57:29 +03002075#if defined(TARGET_NR_stat) || defined(TARGET_NR_stat64) || \
2076 defined(TARGET_NR_lstat) || defined(TARGET_NR_lstat64)
2077static void
2078print_stat(const struct syscallname *name,
2079 abi_long arg0, abi_long arg1, abi_long arg2,
2080 abi_long arg3, abi_long arg4, abi_long arg5)
2081{
2082 print_syscall_prologue(name);
2083 print_string(arg0, 0);
2084 print_pointer(arg1, 1);
2085 print_syscall_epilogue(name);
2086}
2087#define print_lstat print_stat
2088#define print_stat64 print_stat
2089#define print_lstat64 print_stat
2090#endif
2091
2092#if defined(TARGET_NR_fstat) || defined(TARGET_NR_fstat64)
2093static void
2094print_fstat(const struct syscallname *name,
2095 abi_long arg0, abi_long arg1, abi_long arg2,
2096 abi_long arg3, abi_long arg4, abi_long arg5)
2097{
2098 print_syscall_prologue(name);
Laurent Vivierd2ee72a2011-02-15 21:10:44 +01002099 print_raw_param("%d", arg0, 0);
Mika Westerberg74d753a2009-04-07 16:57:29 +03002100 print_pointer(arg1, 1);
2101 print_syscall_epilogue(name);
2102}
2103#define print_fstat64 print_fstat
2104#endif
2105
2106#ifdef TARGET_NR_mkdir
2107static void
2108print_mkdir(const struct syscallname *name,
2109 abi_long arg0, abi_long arg1, abi_long arg2,
2110 abi_long arg3, abi_long arg4, abi_long arg5)
2111{
2112 print_syscall_prologue(name);
2113 print_string(arg0, 0);
2114 print_file_mode(arg1, 1);
2115 print_syscall_epilogue(name);
2116}
2117#endif
2118
2119#ifdef TARGET_NR_mkdirat
2120static void
2121print_mkdirat(const struct syscallname *name,
2122 abi_long arg0, abi_long arg1, abi_long arg2,
2123 abi_long arg3, abi_long arg4, abi_long arg5)
2124{
2125 print_syscall_prologue(name);
2126 print_at_dirfd(arg0, 0);
2127 print_string(arg1, 0);
2128 print_file_mode(arg2, 1);
2129 print_syscall_epilogue(name);
2130}
2131#endif
2132
Laurent Vivier4de596c2011-02-15 21:10:43 +01002133#ifdef TARGET_NR_rmdir
2134static void
2135print_rmdir(const struct syscallname *name,
2136 abi_long arg0, abi_long arg1, abi_long arg2,
2137 abi_long arg3, abi_long arg4, abi_long arg5)
2138{
2139 print_syscall_prologue(name);
2140 print_string(arg0, 0);
2141 print_syscall_epilogue(name);
2142}
2143#endif
2144
Laurent Vivier608e5592011-04-07 00:25:32 +02002145#ifdef TARGET_NR_rt_sigaction
2146static void
2147print_rt_sigaction(const struct syscallname *name,
2148 abi_long arg0, abi_long arg1, abi_long arg2,
2149 abi_long arg3, abi_long arg4, abi_long arg5)
2150{
2151 print_syscall_prologue(name);
2152 print_signal(arg0, 0);
2153 print_pointer(arg1, 0);
2154 print_pointer(arg2, 1);
2155 print_syscall_epilogue(name);
2156}
2157#endif
2158
2159#ifdef TARGET_NR_rt_sigprocmask
2160static void
2161print_rt_sigprocmask(const struct syscallname *name,
2162 abi_long arg0, abi_long arg1, abi_long arg2,
2163 abi_long arg3, abi_long arg4, abi_long arg5)
2164{
2165 const char *how = "UNKNOWN";
2166 print_syscall_prologue(name);
2167 switch(arg0) {
2168 case TARGET_SIG_BLOCK: how = "SIG_BLOCK"; break;
2169 case TARGET_SIG_UNBLOCK: how = "SIG_UNBLOCK"; break;
2170 case TARGET_SIG_SETMASK: how = "SIG_SETMASK"; break;
2171 }
Josh Kunz4b25a502020-02-03 18:54:14 -08002172 qemu_log("%s,", how);
Laurent Vivier608e5592011-04-07 00:25:32 +02002173 print_pointer(arg1, 0);
2174 print_pointer(arg2, 1);
2175 print_syscall_epilogue(name);
2176}
2177#endif
2178
Miloš Stojanović51622642017-05-15 16:59:42 +02002179#ifdef TARGET_NR_rt_sigqueueinfo
2180static void
2181print_rt_sigqueueinfo(const struct syscallname *name,
2182 abi_long arg0, abi_long arg1, abi_long arg2,
2183 abi_long arg3, abi_long arg4, abi_long arg5)
2184{
Miloš Stojanovićba9fcea2017-05-15 16:59:49 +02002185 void *p;
2186 target_siginfo_t uinfo;
2187
Miloš Stojanović51622642017-05-15 16:59:42 +02002188 print_syscall_prologue(name);
2189 print_raw_param("%d", arg0, 0);
2190 print_signal(arg1, 0);
Miloš Stojanovićba9fcea2017-05-15 16:59:49 +02002191 p = lock_user(VERIFY_READ, arg2, sizeof(target_siginfo_t), 1);
2192 if (p) {
2193 get_target_siginfo(&uinfo, p);
2194 print_siginfo(&uinfo);
2195
2196 unlock_user(p, arg2, 0);
2197 } else {
2198 print_pointer(arg2, 1);
2199 }
Miloš Stojanović51622642017-05-15 16:59:42 +02002200 print_syscall_epilogue(name);
2201}
2202#endif
2203
Miloš Stojanović243e0fe2017-05-15 16:59:47 +02002204#ifdef TARGET_NR_rt_tgsigqueueinfo
2205static void
2206print_rt_tgsigqueueinfo(const struct syscallname *name,
2207 abi_long arg0, abi_long arg1, abi_long arg2,
2208 abi_long arg3, abi_long arg4, abi_long arg5)
2209{
Miloš Stojanovićba9fcea2017-05-15 16:59:49 +02002210 void *p;
2211 target_siginfo_t uinfo;
2212
Miloš Stojanović243e0fe2017-05-15 16:59:47 +02002213 print_syscall_prologue(name);
2214 print_raw_param("%d", arg0, 0);
2215 print_raw_param("%d", arg1, 0);
2216 print_signal(arg2, 0);
Miloš Stojanovićba9fcea2017-05-15 16:59:49 +02002217 p = lock_user(VERIFY_READ, arg3, sizeof(target_siginfo_t), 1);
2218 if (p) {
2219 get_target_siginfo(&uinfo, p);
2220 print_siginfo(&uinfo);
2221
2222 unlock_user(p, arg3, 0);
2223 } else {
2224 print_pointer(arg3, 1);
2225 }
Miloš Stojanović243e0fe2017-05-15 16:59:47 +02002226 print_syscall_epilogue(name);
2227}
2228#endif
2229
Aleksandar Markovicda2c8ad2016-09-22 18:56:58 +02002230#ifdef TARGET_NR_syslog
2231static void
2232print_syslog_action(abi_ulong arg, int last)
2233{
2234 const char *type;
2235
2236 switch (arg) {
2237 case TARGET_SYSLOG_ACTION_CLOSE: {
2238 type = "SYSLOG_ACTION_CLOSE";
2239 break;
2240 }
2241 case TARGET_SYSLOG_ACTION_OPEN: {
2242 type = "SYSLOG_ACTION_OPEN";
2243 break;
2244 }
2245 case TARGET_SYSLOG_ACTION_READ: {
2246 type = "SYSLOG_ACTION_READ";
2247 break;
2248 }
2249 case TARGET_SYSLOG_ACTION_READ_ALL: {
2250 type = "SYSLOG_ACTION_READ_ALL";
2251 break;
2252 }
2253 case TARGET_SYSLOG_ACTION_READ_CLEAR: {
2254 type = "SYSLOG_ACTION_READ_CLEAR";
2255 break;
2256 }
2257 case TARGET_SYSLOG_ACTION_CLEAR: {
2258 type = "SYSLOG_ACTION_CLEAR";
2259 break;
2260 }
2261 case TARGET_SYSLOG_ACTION_CONSOLE_OFF: {
2262 type = "SYSLOG_ACTION_CONSOLE_OFF";
2263 break;
2264 }
2265 case TARGET_SYSLOG_ACTION_CONSOLE_ON: {
2266 type = "SYSLOG_ACTION_CONSOLE_ON";
2267 break;
2268 }
2269 case TARGET_SYSLOG_ACTION_CONSOLE_LEVEL: {
2270 type = "SYSLOG_ACTION_CONSOLE_LEVEL";
2271 break;
2272 }
2273 case TARGET_SYSLOG_ACTION_SIZE_UNREAD: {
2274 type = "SYSLOG_ACTION_SIZE_UNREAD";
2275 break;
2276 }
2277 case TARGET_SYSLOG_ACTION_SIZE_BUFFER: {
2278 type = "SYSLOG_ACTION_SIZE_BUFFER";
2279 break;
2280 }
2281 default: {
2282 print_raw_param("%ld", arg, last);
2283 return;
2284 }
2285 }
Josh Kunz4b25a502020-02-03 18:54:14 -08002286 qemu_log("%s%s", type, get_comma(last));
Aleksandar Markovicda2c8ad2016-09-22 18:56:58 +02002287}
2288
2289static void
2290print_syslog(const struct syscallname *name,
2291 abi_long arg0, abi_long arg1, abi_long arg2,
2292 abi_long arg3, abi_long arg4, abi_long arg5)
2293{
2294 print_syscall_prologue(name);
2295 print_syslog_action(arg0, 0);
2296 print_pointer(arg1, 0);
2297 print_raw_param("%d", arg2, 1);
2298 print_syscall_epilogue(name);
2299}
2300#endif
2301
Mika Westerberg74d753a2009-04-07 16:57:29 +03002302#ifdef TARGET_NR_mknod
2303static void
2304print_mknod(const struct syscallname *name,
2305 abi_long arg0, abi_long arg1, abi_long arg2,
2306 abi_long arg3, abi_long arg4, abi_long arg5)
2307{
Laurent Vivierd2ee72a2011-02-15 21:10:44 +01002308 int hasdev = (arg1 & (S_IFCHR|S_IFBLK));
Mika Westerberg74d753a2009-04-07 16:57:29 +03002309
2310 print_syscall_prologue(name);
2311 print_string(arg0, 0);
2312 print_file_mode(arg1, (hasdev == 0));
2313 if (hasdev) {
Laurent Vivierd2ee72a2011-02-15 21:10:44 +01002314 print_raw_param("makedev(%d", major(arg2), 0);
2315 print_raw_param("%d)", minor(arg2), 1);
Mika Westerberg74d753a2009-04-07 16:57:29 +03002316 }
2317 print_syscall_epilogue(name);
2318}
2319#endif
2320
2321#ifdef TARGET_NR_mknodat
2322static void
2323print_mknodat(const struct syscallname *name,
2324 abi_long arg0, abi_long arg1, abi_long arg2,
2325 abi_long arg3, abi_long arg4, abi_long arg5)
2326{
Laurent Vivierd2ee72a2011-02-15 21:10:44 +01002327 int hasdev = (arg2 & (S_IFCHR|S_IFBLK));
Mika Westerberg74d753a2009-04-07 16:57:29 +03002328
2329 print_syscall_prologue(name);
2330 print_at_dirfd(arg0, 0);
2331 print_string(arg1, 0);
2332 print_file_mode(arg2, (hasdev == 0));
2333 if (hasdev) {
Laurent Vivierd2ee72a2011-02-15 21:10:44 +01002334 print_raw_param("makedev(%d", major(arg3), 0);
2335 print_raw_param("%d)", minor(arg3), 1);
Mika Westerberg74d753a2009-04-07 16:57:29 +03002336 }
2337 print_syscall_epilogue(name);
2338}
2339#endif
2340
2341#ifdef TARGET_NR_mq_open
2342static void
2343print_mq_open(const struct syscallname *name,
2344 abi_long arg0, abi_long arg1, abi_long arg2,
2345 abi_long arg3, abi_long arg4, abi_long arg5)
2346{
Laurent Vivierd2ee72a2011-02-15 21:10:44 +01002347 int is_creat = (arg1 & TARGET_O_CREAT);
Mika Westerberg74d753a2009-04-07 16:57:29 +03002348
2349 print_syscall_prologue(name);
2350 print_string(arg0, 0);
2351 print_open_flags(arg1, (is_creat == 0));
2352 if (is_creat) {
2353 print_file_mode(arg2, 0);
2354 print_pointer(arg3, 1);
2355 }
2356 print_syscall_epilogue(name);
2357}
2358#endif
2359
2360#ifdef TARGET_NR_open
2361static void
2362print_open(const struct syscallname *name,
2363 abi_long arg0, abi_long arg1, abi_long arg2,
2364 abi_long arg3, abi_long arg4, abi_long arg5)
2365{
Laurent Vivierd2ee72a2011-02-15 21:10:44 +01002366 int is_creat = (arg1 & TARGET_O_CREAT);
Mika Westerberg74d753a2009-04-07 16:57:29 +03002367
2368 print_syscall_prologue(name);
2369 print_string(arg0, 0);
2370 print_open_flags(arg1, (is_creat == 0));
2371 if (is_creat)
2372 print_file_mode(arg2, 1);
2373 print_syscall_epilogue(name);
2374}
2375#endif
2376
2377#ifdef TARGET_NR_openat
2378static void
2379print_openat(const struct syscallname *name,
2380 abi_long arg0, abi_long arg1, abi_long arg2,
2381 abi_long arg3, abi_long arg4, abi_long arg5)
2382{
Laurent Vivierd2ee72a2011-02-15 21:10:44 +01002383 int is_creat = (arg2 & TARGET_O_CREAT);
Mika Westerberg74d753a2009-04-07 16:57:29 +03002384
2385 print_syscall_prologue(name);
2386 print_at_dirfd(arg0, 0);
2387 print_string(arg1, 0);
2388 print_open_flags(arg2, (is_creat == 0));
2389 if (is_creat)
2390 print_file_mode(arg3, 1);
2391 print_syscall_epilogue(name);
2392}
2393#endif
2394
2395#ifdef TARGET_NR_mq_unlink
2396static void
2397print_mq_unlink(const struct syscallname *name,
2398 abi_long arg0, abi_long arg1, abi_long arg2,
2399 abi_long arg3, abi_long arg4, abi_long arg5)
2400{
2401 print_syscall_prologue(name);
2402 print_string(arg0, 1);
2403 print_syscall_epilogue(name);
2404}
2405#endif
2406
2407#if defined(TARGET_NR_fstatat64) || defined(TARGET_NR_newfstatat)
2408static void
2409print_fstatat64(const struct syscallname *name,
2410 abi_long arg0, abi_long arg1, abi_long arg2,
2411 abi_long arg3, abi_long arg4, abi_long arg5)
2412{
2413 print_syscall_prologue(name);
2414 print_at_dirfd(arg0, 0);
2415 print_string(arg1, 0);
2416 print_pointer(arg2, 0);
2417 print_flags(at_file_flags, arg3, 1);
2418 print_syscall_epilogue(name);
2419}
2420#define print_newfstatat print_fstatat64
2421#endif
2422
2423#ifdef TARGET_NR_readlink
2424static void
2425print_readlink(const struct syscallname *name,
2426 abi_long arg0, abi_long arg1, abi_long arg2,
2427 abi_long arg3, abi_long arg4, abi_long arg5)
2428{
2429 print_syscall_prologue(name);
2430 print_string(arg0, 0);
2431 print_pointer(arg1, 0);
Laurent Vivierd2ee72a2011-02-15 21:10:44 +01002432 print_raw_param("%u", arg2, 1);
Mika Westerberg74d753a2009-04-07 16:57:29 +03002433 print_syscall_epilogue(name);
2434}
2435#endif
2436
2437#ifdef TARGET_NR_readlinkat
2438static void
2439print_readlinkat(const struct syscallname *name,
2440 abi_long arg0, abi_long arg1, abi_long arg2,
2441 abi_long arg3, abi_long arg4, abi_long arg5)
2442{
2443 print_syscall_prologue(name);
2444 print_at_dirfd(arg0, 0);
2445 print_string(arg1, 0);
2446 print_pointer(arg2, 0);
Laurent Vivierd2ee72a2011-02-15 21:10:44 +01002447 print_raw_param("%u", arg3, 1);
Mika Westerberg74d753a2009-04-07 16:57:29 +03002448 print_syscall_epilogue(name);
2449}
2450#endif
2451
2452#ifdef TARGET_NR_rename
2453static void
2454print_rename(const struct syscallname *name,
2455 abi_long arg0, abi_long arg1, abi_long arg2,
2456 abi_long arg3, abi_long arg4, abi_long arg5)
2457{
2458 print_syscall_prologue(name);
2459 print_string(arg0, 0);
2460 print_string(arg1, 1);
2461 print_syscall_epilogue(name);
2462}
2463#endif
2464
2465#ifdef TARGET_NR_renameat
2466static void
2467print_renameat(const struct syscallname *name,
2468 abi_long arg0, abi_long arg1, abi_long arg2,
2469 abi_long arg3, abi_long arg4, abi_long arg5)
2470{
2471 print_syscall_prologue(name);
2472 print_at_dirfd(arg0, 0);
2473 print_string(arg1, 0);
2474 print_at_dirfd(arg2, 0);
2475 print_string(arg3, 1);
2476 print_syscall_epilogue(name);
2477}
2478#endif
2479
2480#ifdef TARGET_NR_statfs
2481static void
2482print_statfs(const struct syscallname *name,
2483 abi_long arg0, abi_long arg1, abi_long arg2,
2484 abi_long arg3, abi_long arg4, abi_long arg5)
2485{
2486 print_syscall_prologue(name);
2487 print_string(arg0, 0);
2488 print_pointer(arg1, 1);
2489 print_syscall_epilogue(name);
2490}
Aleksandar Rikalo4f7f8922018-08-02 16:16:00 +02002491#endif
2492
2493#ifdef TARGET_NR_statfs64
2494static void
2495print_statfs64(const struct syscallname *name,
2496 abi_long arg0, abi_long arg1, abi_long arg2,
2497 abi_long arg3, abi_long arg4, abi_long arg5)
2498{
2499 print_syscall_prologue(name);
2500 print_string(arg0, 0);
2501 print_pointer(arg1, 1);
2502 print_syscall_epilogue(name);
2503}
Mika Westerberg74d753a2009-04-07 16:57:29 +03002504#endif
2505
2506#ifdef TARGET_NR_symlink
2507static void
2508print_symlink(const struct syscallname *name,
2509 abi_long arg0, abi_long arg1, abi_long arg2,
2510 abi_long arg3, abi_long arg4, abi_long arg5)
2511{
2512 print_syscall_prologue(name);
2513 print_string(arg0, 0);
2514 print_string(arg1, 1);
2515 print_syscall_epilogue(name);
2516}
2517#endif
2518
2519#ifdef TARGET_NR_symlinkat
2520static void
2521print_symlinkat(const struct syscallname *name,
2522 abi_long arg0, abi_long arg1, abi_long arg2,
2523 abi_long arg3, abi_long arg4, abi_long arg5)
2524{
2525 print_syscall_prologue(name);
2526 print_string(arg0, 0);
2527 print_at_dirfd(arg1, 0);
2528 print_string(arg2, 1);
2529 print_syscall_epilogue(name);
2530}
2531#endif
2532
2533#ifdef TARGET_NR_mount
2534static void
2535print_mount(const struct syscallname *name,
2536 abi_long arg0, abi_long arg1, abi_long arg2,
2537 abi_long arg3, abi_long arg4, abi_long arg5)
2538{
2539 print_syscall_prologue(name);
2540 print_string(arg0, 0);
2541 print_string(arg1, 0);
2542 print_string(arg2, 0);
2543 print_flags(mount_flags, arg3, 0);
2544 print_pointer(arg4, 1);
2545 print_syscall_epilogue(name);
2546}
2547#endif
2548
2549#ifdef TARGET_NR_umount
2550static void
2551print_umount(const struct syscallname *name,
2552 abi_long arg0, abi_long arg1, abi_long arg2,
2553 abi_long arg3, abi_long arg4, abi_long arg5)
2554{
2555 print_syscall_prologue(name);
2556 print_string(arg0, 1);
2557 print_syscall_epilogue(name);
2558}
2559#endif
2560
2561#ifdef TARGET_NR_umount2
2562static void
2563print_umount2(const struct syscallname *name,
2564 abi_long arg0, abi_long arg1, abi_long arg2,
2565 abi_long arg3, abi_long arg4, abi_long arg5)
2566{
2567 print_syscall_prologue(name);
2568 print_string(arg0, 0);
2569 print_flags(umount2_flags, arg1, 1);
2570 print_syscall_epilogue(name);
2571}
2572#endif
2573
2574#ifdef TARGET_NR_unlink
2575static void
2576print_unlink(const struct syscallname *name,
2577 abi_long arg0, abi_long arg1, abi_long arg2,
2578 abi_long arg3, abi_long arg4, abi_long arg5)
2579{
2580 print_syscall_prologue(name);
2581 print_string(arg0, 1);
2582 print_syscall_epilogue(name);
2583}
2584#endif
2585
2586#ifdef TARGET_NR_unlinkat
2587static void
2588print_unlinkat(const struct syscallname *name,
2589 abi_long arg0, abi_long arg1, abi_long arg2,
2590 abi_long arg3, abi_long arg4, abi_long arg5)
2591{
2592 print_syscall_prologue(name);
2593 print_at_dirfd(arg0, 0);
2594 print_string(arg1, 0);
2595 print_flags(unlinkat_flags, arg2, 1);
2596 print_syscall_epilogue(name);
2597}
2598#endif
2599
2600#ifdef TARGET_NR_utime
2601static void
2602print_utime(const struct syscallname *name,
2603 abi_long arg0, abi_long arg1, abi_long arg2,
2604 abi_long arg3, abi_long arg4, abi_long arg5)
2605{
2606 print_syscall_prologue(name);
2607 print_string(arg0, 0);
2608 print_pointer(arg1, 1);
2609 print_syscall_epilogue(name);
2610}
2611#endif
2612
2613#ifdef TARGET_NR_utimes
2614static void
2615print_utimes(const struct syscallname *name,
2616 abi_long arg0, abi_long arg1, abi_long arg2,
2617 abi_long arg3, abi_long arg4, abi_long arg5)
2618{
2619 print_syscall_prologue(name);
2620 print_string(arg0, 0);
2621 print_pointer(arg1, 1);
2622 print_syscall_epilogue(name);
2623}
2624#endif
2625
2626#ifdef TARGET_NR_utimensat
2627static void
2628print_utimensat(const struct syscallname *name,
2629 abi_long arg0, abi_long arg1, abi_long arg2,
2630 abi_long arg3, abi_long arg4, abi_long arg5)
2631{
2632 print_syscall_prologue(name);
2633 print_at_dirfd(arg0, 0);
2634 print_string(arg1, 0);
2635 print_pointer(arg2, 0);
2636 print_flags(at_file_flags, arg3, 1);
2637 print_syscall_epilogue(name);
2638}
2639#endif
2640
Mike Frysinger8d9016c2011-02-07 01:05:57 -05002641#if defined(TARGET_NR_mmap) || defined(TARGET_NR_mmap2)
Mika Westerberg74d753a2009-04-07 16:57:29 +03002642static void
2643print_mmap(const struct syscallname *name,
2644 abi_long arg0, abi_long arg1, abi_long arg2,
2645 abi_long arg3, abi_long arg4, abi_long arg5)
2646{
2647 print_syscall_prologue(name);
2648 print_pointer(arg0, 0);
Laurent Vivierd2ee72a2011-02-15 21:10:44 +01002649 print_raw_param("%d", arg1, 0);
Mika Westerberg74d753a2009-04-07 16:57:29 +03002650 print_flags(mmap_prot_flags, arg2, 0);
2651 print_flags(mmap_flags, arg3, 0);
Laurent Vivierd2ee72a2011-02-15 21:10:44 +01002652 print_raw_param("%d", arg4, 0);
2653 print_raw_param("%#x", arg5, 1);
Mika Westerberg74d753a2009-04-07 16:57:29 +03002654 print_syscall_epilogue(name);
2655}
2656#define print_mmap2 print_mmap
2657#endif
2658
2659#ifdef TARGET_NR_mprotect
2660static void
2661print_mprotect(const struct syscallname *name,
2662 abi_long arg0, abi_long arg1, abi_long arg2,
2663 abi_long arg3, abi_long arg4, abi_long arg5)
2664{
2665 print_syscall_prologue(name);
2666 print_pointer(arg0, 0);
Laurent Vivierd2ee72a2011-02-15 21:10:44 +01002667 print_raw_param("%d", arg1, 0);
Mika Westerberg74d753a2009-04-07 16:57:29 +03002668 print_flags(mmap_prot_flags, arg2, 1);
2669 print_syscall_epilogue(name);
2670}
2671#endif
2672
2673#ifdef TARGET_NR_munmap
2674static void
2675print_munmap(const struct syscallname *name,
2676 abi_long arg0, abi_long arg1, abi_long arg2,
2677 abi_long arg3, abi_long arg4, abi_long arg5)
2678{
2679 print_syscall_prologue(name);
2680 print_pointer(arg0, 0);
Laurent Vivierd2ee72a2011-02-15 21:10:44 +01002681 print_raw_param("%d", arg1, 1);
Mika Westerberg74d753a2009-04-07 16:57:29 +03002682 print_syscall_epilogue(name);
2683}
2684#endif
2685
2686#ifdef TARGET_NR_futex
2687static void print_futex_op(abi_long tflag, int last)
2688{
2689#define print_op(val) \
2690if( cmd == val ) { \
Josh Kunz4b25a502020-02-03 18:54:14 -08002691 qemu_log(#val); \
Mika Westerberg74d753a2009-04-07 16:57:29 +03002692 return; \
2693}
2694
Laurent Vivierd2ee72a2011-02-15 21:10:44 +01002695 int cmd = (int)tflag;
Mika Westerberg74d753a2009-04-07 16:57:29 +03002696#ifdef FUTEX_PRIVATE_FLAG
Paul Brook5f2243f2010-02-19 16:04:51 +00002697 if (cmd & FUTEX_PRIVATE_FLAG) {
Josh Kunz4b25a502020-02-03 18:54:14 -08002698 qemu_log("FUTEX_PRIVATE_FLAG|");
Paul Brook5f2243f2010-02-19 16:04:51 +00002699 cmd &= ~FUTEX_PRIVATE_FLAG;
2700 }
Mika Westerberg74d753a2009-04-07 16:57:29 +03002701#endif
John Rigbybfb669f2013-02-23 16:14:08 -07002702#ifdef FUTEX_CLOCK_REALTIME
2703 if (cmd & FUTEX_CLOCK_REALTIME) {
Josh Kunz4b25a502020-02-03 18:54:14 -08002704 qemu_log("FUTEX_CLOCK_REALTIME|");
John Rigbybfb669f2013-02-23 16:14:08 -07002705 cmd &= ~FUTEX_CLOCK_REALTIME;
2706 }
2707#endif
Mika Westerberg74d753a2009-04-07 16:57:29 +03002708 print_op(FUTEX_WAIT)
2709 print_op(FUTEX_WAKE)
2710 print_op(FUTEX_FD)
2711 print_op(FUTEX_REQUEUE)
2712 print_op(FUTEX_CMP_REQUEUE)
2713 print_op(FUTEX_WAKE_OP)
2714 print_op(FUTEX_LOCK_PI)
2715 print_op(FUTEX_UNLOCK_PI)
2716 print_op(FUTEX_TRYLOCK_PI)
2717#ifdef FUTEX_WAIT_BITSET
2718 print_op(FUTEX_WAIT_BITSET)
2719#endif
2720#ifdef FUTEX_WAKE_BITSET
2721 print_op(FUTEX_WAKE_BITSET)
2722#endif
2723 /* unknown values */
Josh Kunz4b25a502020-02-03 18:54:14 -08002724 qemu_log("%d", cmd);
Mika Westerberg74d753a2009-04-07 16:57:29 +03002725}
2726
2727static void
2728print_futex(const struct syscallname *name,
2729 abi_long arg0, abi_long arg1, abi_long arg2,
2730 abi_long arg3, abi_long arg4, abi_long arg5)
2731{
2732 print_syscall_prologue(name);
2733 print_pointer(arg0, 0);
2734 print_futex_op(arg1, 0);
Laurent Vivierd2ee72a2011-02-15 21:10:44 +01002735 print_raw_param(",%d", arg2, 0);
Mika Westerberg74d753a2009-04-07 16:57:29 +03002736 print_pointer(arg3, 0); /* struct timespec */
2737 print_pointer(arg4, 0);
Laurent Vivierd2ee72a2011-02-15 21:10:44 +01002738 print_raw_param("%d", arg4, 1);
Mika Westerberg74d753a2009-04-07 16:57:29 +03002739 print_syscall_epilogue(name);
2740}
2741#endif
2742
Laurent Vivier608e5592011-04-07 00:25:32 +02002743#ifdef TARGET_NR_kill
2744static void
2745print_kill(const struct syscallname *name,
2746 abi_long arg0, abi_long arg1, abi_long arg2,
2747 abi_long arg3, abi_long arg4, abi_long arg5)
2748{
2749 print_syscall_prologue(name);
2750 print_raw_param("%d", arg0, 0);
2751 print_signal(arg1, 1);
2752 print_syscall_epilogue(name);
2753}
2754#endif
2755
Miloš Stojanović51622642017-05-15 16:59:42 +02002756#ifdef TARGET_NR_tkill
2757static void
2758print_tkill(const struct syscallname *name,
2759 abi_long arg0, abi_long arg1, abi_long arg2,
2760 abi_long arg3, abi_long arg4, abi_long arg5)
2761{
2762 print_syscall_prologue(name);
2763 print_raw_param("%d", arg0, 0);
2764 print_signal(arg1, 1);
2765 print_syscall_epilogue(name);
2766}
2767#endif
2768
2769#ifdef TARGET_NR_tgkill
2770static void
2771print_tgkill(const struct syscallname *name,
2772 abi_long arg0, abi_long arg1, abi_long arg2,
2773 abi_long arg3, abi_long arg4, abi_long arg5)
2774{
2775 print_syscall_prologue(name);
2776 print_raw_param("%d", arg0, 0);
2777 print_raw_param("%d", arg1, 0);
2778 print_signal(arg2, 1);
2779 print_syscall_epilogue(name);
2780}
2781#endif
2782
Jim Wilsond42744f2019-06-28 12:43:35 +02002783#ifdef TARGET_NR_statx
2784static void
2785print_statx(const struct syscallname *name,
2786 abi_long arg0, abi_long arg1, abi_long arg2,
2787 abi_long arg3, abi_long arg4, abi_long arg5)
2788{
2789 print_syscall_prologue(name);
2790 print_at_dirfd(arg0, 0);
2791 print_string(arg1, 0);
2792 print_flags(statx_flags, arg2, 0);
2793 print_flags(statx_mask, arg3, 0);
2794 print_pointer(arg4, 1);
2795 print_syscall_epilogue(name);
2796}
2797#endif
2798
ths33189d32007-11-01 00:13:36 +00002799/*
2800 * An array of all of the syscalls we know about
2801 */
2802
blueswir17ccfb2e2008-09-14 06:45:34 +00002803static const struct syscallname scnames[] = {
ths33189d32007-11-01 00:13:36 +00002804#include "strace.list"
2805};
2806
malcb1503cd2008-12-22 20:33:55 +00002807static int nsyscalls = ARRAY_SIZE(scnames);
ths33189d32007-11-01 00:13:36 +00002808
2809/*
2810 * The public interface to this module.
2811 */
2812void
2813print_syscall(int num,
bellardc16f9ed2007-11-11 17:23:29 +00002814 abi_long arg1, abi_long arg2, abi_long arg3,
2815 abi_long arg4, abi_long arg5, abi_long arg6)
ths33189d32007-11-01 00:13:36 +00002816{
2817 int i;
blueswir17ccfb2e2008-09-14 06:45:34 +00002818 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 +00002819
Josh Kunz4b25a502020-02-03 18:54:14 -08002820 qemu_log("%d ", getpid());
ths33189d32007-11-01 00:13:36 +00002821
2822 for(i=0;i<nsyscalls;i++)
2823 if( scnames[i].nr == num ) {
2824 if( scnames[i].call != NULL ) {
Josh Kunz4b25a502020-02-03 18:54:14 -08002825 scnames[i].call(
2826 &scnames[i], arg1, arg2, arg3, arg4, arg5, arg6);
ths33189d32007-11-01 00:13:36 +00002827 } else {
bellard6b23f772007-11-14 18:04:05 +00002828 /* XXX: this format system is broken because it uses
2829 host types and host pointers for strings */
ths33189d32007-11-01 00:13:36 +00002830 if( scnames[i].format != NULL )
2831 format = scnames[i].format;
Josh Kunz4b25a502020-02-03 18:54:14 -08002832 qemu_log(format,
2833 scnames[i].name, arg1, arg2, arg3, arg4, arg5, arg6);
ths33189d32007-11-01 00:13:36 +00002834 }
pbrook74c11e52008-05-29 13:49:09 +00002835 return;
ths33189d32007-11-01 00:13:36 +00002836 }
Josh Kunz4b25a502020-02-03 18:54:14 -08002837 qemu_log("Unknown syscall %d\n", num);
ths33189d32007-11-01 00:13:36 +00002838}
2839
2840
2841void
bellardc16f9ed2007-11-11 17:23:29 +00002842print_syscall_ret(int num, abi_long ret)
ths33189d32007-11-01 00:13:36 +00002843{
2844 int i;
Peter Maydell7dcdaea2016-06-06 19:58:18 +01002845 const char *errstr = NULL;
ths33189d32007-11-01 00:13:36 +00002846
2847 for(i=0;i<nsyscalls;i++)
2848 if( scnames[i].nr == num ) {
2849 if( scnames[i].result != NULL ) {
Josh Kunz4b25a502020-02-03 18:54:14 -08002850 scnames[i].result(&scnames[i], ret);
ths33189d32007-11-01 00:13:36 +00002851 } else {
Alexander Graf962b2892011-11-21 12:04:07 +01002852 if (ret < 0) {
2853 errstr = target_strerror(-ret);
2854 }
2855 if (errstr) {
Josh Kunz4b25a502020-02-03 18:54:14 -08002856 qemu_log(" = -1 errno=" TARGET_ABI_FMT_ld " (%s)\n",
Alexander Graf962b2892011-11-21 12:04:07 +01002857 -ret, errstr);
ths33189d32007-11-01 00:13:36 +00002858 } else {
Josh Kunz4b25a502020-02-03 18:54:14 -08002859 qemu_log(" = " TARGET_ABI_FMT_ld "\n", ret);
ths33189d32007-11-01 00:13:36 +00002860 }
2861 }
2862 break;
2863 }
2864}
Peter Maydell0cb581d2016-07-18 18:12:24 +01002865
2866void print_taken_signal(int target_signum, const target_siginfo_t *tinfo)
2867{
2868 /* Print the strace output for a signal being taken:
2869 * --- SIGSEGV {si_signo=SIGSEGV, si_code=SI_KERNEL, si_addr=0} ---
2870 */
Josh Kunz4b25a502020-02-03 18:54:14 -08002871 qemu_log("--- ");
Peter Maydell0cb581d2016-07-18 18:12:24 +01002872 print_signal(target_signum, 1);
Josh Kunz4b25a502020-02-03 18:54:14 -08002873 qemu_log(" ");
Peter Maydell0cb581d2016-07-18 18:12:24 +01002874 print_siginfo(tinfo);
Josh Kunz4b25a502020-02-03 18:54:14 -08002875 qemu_log(" ---\n");
Peter Maydell0cb581d2016-07-18 18:12:24 +01002876}