]> Git Repo - qemu.git/blame - linux-user/strace.c
linux-user: implement pipe2 [v3]
[qemu.git] / linux-user / strace.c
CommitLineData
33189d31
TS
1#include <stdio.h>
2#include <errno.h>
3#include <sys/ipc.h>
4#include <sys/msg.h>
5#include <sys/sem.h>
6#include <sys/shm.h>
7#include <sys/select.h>
8#include <sys/types.h>
74d753ac
MW
9#include <sys/mount.h>
10#include <sys/mman.h>
11#include <linux/futex.h>
33189d31
TS
12#include <unistd.h>
13#include "qemu.h"
14
15int do_strace=0;
16
17struct syscallname {
18 int nr;
7ccfb2eb
BS
19 const char *name;
20 const char *format;
21 void (*call)(const struct syscallname *,
c16f9ed3
FB
22 abi_long, abi_long, abi_long,
23 abi_long, abi_long, abi_long);
7ccfb2eb 24 void (*result)(const struct syscallname *, abi_long);
33189d31
TS
25};
26
74d753ac
MW
27#ifdef __GNUC__
28/*
29 * It is possible that target doesn't have syscall that uses
30 * following flags but we don't want the compiler to warn
31 * us about them being unused. Same applies to utility print
32 * functions. It is ok to keep them while not used.
33 */
34#define UNUSED __attribute__ ((unused))
35#else
36#define UNUSED
37#endif
38
39/*
40 * Structure used to translate flag values into strings. This is
41 * similar that is in the actual strace tool.
42 */
43struct flags {
44 abi_long f_value; /* flag */
45 const char *f_string; /* stringified flag */
46};
47
48/* common flags for all architectures */
49#define FLAG_GENERIC(name) { name, #name }
50/* target specific flags (syscall_defs.h has TARGET_<flag>) */
51#define FLAG_TARGET(name) { TARGET_ ## name, #name }
52/* end of flags array */
53#define FLAG_END { 0, NULL }
54
55UNUSED static const char *get_comma(int);
56UNUSED static void print_pointer(abi_long, int);
57UNUSED static void print_flags(const struct flags *, abi_long, int);
58UNUSED static void print_at_dirfd(abi_long, int);
59UNUSED static void print_file_mode(abi_long, int);
60UNUSED static void print_open_flags(abi_long, int);
61UNUSED static void print_syscall_prologue(const struct syscallname *);
62UNUSED static void print_syscall_epilogue(const struct syscallname *);
63UNUSED static void print_string(abi_long, int);
64UNUSED static void print_raw_param(const char *, abi_long, int);
65UNUSED static void print_timeval(abi_ulong, int);
66UNUSED static void print_number(abi_long, int);
67
33189d31
TS
68/*
69 * Utility functions
70 */
71static void
72print_ipc_cmd(int cmd)
73{
74#define output_cmd(val) \
75if( cmd == val ) { \
76 gemu_log(#val); \
77 return; \
78}
79
80 cmd &= 0xff;
81
82 /* General IPC commands */
83 output_cmd( IPC_RMID );
84 output_cmd( IPC_SET );
85 output_cmd( IPC_STAT );
86 output_cmd( IPC_INFO );
87 /* msgctl() commands */
88 #ifdef __USER_MISC
89 output_cmd( MSG_STAT );
90 output_cmd( MSG_INFO );
91 #endif
92 /* shmctl() commands */
93 output_cmd( SHM_LOCK );
94 output_cmd( SHM_UNLOCK );
95 output_cmd( SHM_STAT );
96 output_cmd( SHM_INFO );
97 /* semctl() commands */
98 output_cmd( GETPID );
99 output_cmd( GETVAL );
100 output_cmd( GETALL );
101 output_cmd( GETNCNT );
102 output_cmd( GETZCNT );
103 output_cmd( SETVAL );
104 output_cmd( SETALL );
105 output_cmd( SEM_STAT );
106 output_cmd( SEM_INFO );
107 output_cmd( IPC_RMID );
108 output_cmd( IPC_RMID );
109 output_cmd( IPC_RMID );
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
117 /* Some value we don't recognize */
118 gemu_log("%d",cmd);
119}
120
c16f9ed3 121#ifdef TARGET_NR__newselect
33189d31 122static void
c16f9ed3 123print_fdset(int n, abi_ulong target_fds_addr)
33189d31
TS
124{
125 int i;
126
127 gemu_log("[");
128 if( target_fds_addr ) {
579a97f7 129 abi_long *target_fds;
33189d31 130
579a97f7
FB
131 target_fds = lock_user(VERIFY_READ,
132 target_fds_addr,
133 sizeof(*target_fds)*(n / TARGET_ABI_BITS + 1),
134 1);
135
136 if (!target_fds)
33189d31
TS
137 return;
138
33189d31 139 for (i=n; i>=0; i--) {
579a97f7 140 if ((tswapl(target_fds[i / TARGET_ABI_BITS]) >> (i & (TARGET_ABI_BITS - 1))) & 1)
33189d31
TS
141 gemu_log("%d,", i );
142 }
143 unlock_user(target_fds, target_fds_addr, 0);
144 }
145 gemu_log("]");
146}
c16f9ed3 147#endif
33189d31
TS
148
149/*
150 * Sysycall specific output functions
151 */
152
153/* select */
c16f9ed3 154#ifdef TARGET_NR__newselect
33189d31
TS
155static long newselect_arg1 = 0;
156static long newselect_arg2 = 0;
157static long newselect_arg3 = 0;
158static long newselect_arg4 = 0;
159static long newselect_arg5 = 0;
160
161static void
7ccfb2eb 162print_newselect(const struct syscallname *name,
c16f9ed3
FB
163 abi_long arg1, abi_long arg2, abi_long arg3,
164 abi_long arg4, abi_long arg5, abi_long arg6)
33189d31 165{
c16f9ed3 166 gemu_log("%s(" TARGET_ABI_FMT_ld ",", name->name, arg1);
33189d31
TS
167 print_fdset(arg1, arg2);
168 gemu_log(",");
169 print_fdset(arg1, arg3);
170 gemu_log(",");
171 print_fdset(arg1, arg4);
172 gemu_log(",");
74d753ac 173 print_timeval(arg5, 1);
33189d31
TS
174 gemu_log(")");
175
176 /* save for use in the return output function below */
177 newselect_arg1=arg1;
178 newselect_arg2=arg2;
179 newselect_arg3=arg3;
180 newselect_arg4=arg4;
181 newselect_arg5=arg5;
182}
c16f9ed3 183#endif
33189d31 184
3e46b2ef 185#ifdef TARGET_NR_semctl
33189d31 186static void
7ccfb2eb 187print_semctl(const struct syscallname *name,
c16f9ed3
FB
188 abi_long arg1, abi_long arg2, abi_long arg3,
189 abi_long arg4, abi_long arg5, abi_long arg6)
33189d31 190{
c16f9ed3 191 gemu_log("%s(" TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld ",", name->name, arg1, arg2);
33189d31 192 print_ipc_cmd(arg3);
c16f9ed3 193 gemu_log(",0x" TARGET_ABI_FMT_lx ")", arg4);
33189d31 194}
3e46b2ef 195#endif
33189d31
TS
196
197static void
7ccfb2eb 198print_execve(const struct syscallname *name,
c16f9ed3
FB
199 abi_long arg1, abi_long arg2, abi_long arg3,
200 abi_long arg4, abi_long arg5, abi_long arg6)
33189d31 201{
c16f9ed3 202 abi_ulong arg_ptr_addr;
33189d31
TS
203 char *s;
204
579a97f7 205 if (!(s = lock_user_string(arg1)))
33189d31 206 return;
33189d31
TS
207 gemu_log("%s(\"%s\",{", name->name, s);
208 unlock_user(s, arg1, 0);
209
c16f9ed3 210 for (arg_ptr_addr = arg2; ; arg_ptr_addr += sizeof(abi_ulong)) {
98448f58 211 abi_ulong *arg_ptr, arg_addr;
33189d31 212
c16f9ed3 213 arg_ptr = lock_user(VERIFY_READ, arg_ptr_addr, sizeof(abi_ulong), 1);
579a97f7 214 if (!arg_ptr)
33189d31 215 return;
33189d31
TS
216 arg_addr = tswapl(*arg_ptr);
217 unlock_user(arg_ptr, arg_ptr_addr, 0);
218 if (!arg_addr)
219 break;
579a97f7
FB
220 if ((s = lock_user_string(arg_addr))) {
221 gemu_log("\"%s\",", s);
98448f58 222 unlock_user(s, arg_addr, 0);
579a97f7 223 }
33189d31
TS
224 }
225
226 gemu_log("NULL})");
227}
228
c16f9ed3 229#ifdef TARGET_NR_ipc
33189d31 230static void
7ccfb2eb 231print_ipc(const struct syscallname *name,
c16f9ed3
FB
232 abi_long arg1, abi_long arg2, abi_long arg3,
233 abi_long arg4, abi_long arg5, abi_long arg6)
33189d31
TS
234{
235 switch(arg1) {
236 case IPCOP_semctl:
7ccfb2eb
BS
237 gemu_log("semctl(" TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld ",", arg1, arg2);
238 print_ipc_cmd(arg3);
239 gemu_log(",0x" TARGET_ABI_FMT_lx ")", arg4);
33189d31
TS
240 break;
241 default:
c16f9ed3 242 gemu_log("%s(" TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld ")",
33189d31
TS
243 name->name, arg1, arg2, arg3, arg4);
244 }
245}
c16f9ed3 246#endif
33189d31
TS
247
248/*
249 * Variants for the return value output function
250 */
251
252static void
7ccfb2eb 253print_syscall_ret_addr(const struct syscallname *name, abi_long ret)
33189d31
TS
254{
255if( ret == -1 ) {
256 gemu_log(" = -1 errno=%d (%s)\n", errno, target_strerror(errno));
257 } else {
29fa23e7 258 gemu_log(" = 0x" TARGET_ABI_FMT_lx "\n", ret);
33189d31
TS
259 }
260}
261
f3e3285d 262#if 0 /* currently unused */
33189d31 263static void
c16f9ed3 264print_syscall_ret_raw(struct syscallname *name, abi_long ret)
33189d31 265{
29fa23e7 266 gemu_log(" = 0x" TARGET_ABI_FMT_lx "\n", ret);
33189d31 267}
f3e3285d 268#endif
33189d31 269
f3e3285d 270#ifdef TARGET_NR__newselect
33189d31 271static void
7ccfb2eb 272print_syscall_ret_newselect(const struct syscallname *name, abi_long ret)
33189d31 273{
29fa23e7 274 gemu_log(" = 0x" TARGET_ABI_FMT_lx " (", ret);
33189d31
TS
275 print_fdset(newselect_arg1,newselect_arg2);
276 gemu_log(",");
277 print_fdset(newselect_arg1,newselect_arg3);
278 gemu_log(",");
279 print_fdset(newselect_arg1,newselect_arg4);
280 gemu_log(",");
74d753ac 281 print_timeval(newselect_arg5, 1);
33189d31
TS
282 gemu_log(")\n");
283}
f3e3285d 284#endif
33189d31 285
74d753ac
MW
286UNUSED static struct flags access_flags[] = {
287 FLAG_GENERIC(F_OK),
288 FLAG_GENERIC(R_OK),
289 FLAG_GENERIC(W_OK),
290 FLAG_GENERIC(X_OK),
291 FLAG_END,
292};
293
294UNUSED static struct flags at_file_flags[] = {
295#ifdef AT_EACCESS
296 FLAG_GENERIC(AT_EACCESS),
297#endif
298#ifdef AT_SYMLINK_NOFOLLOW
299 FLAG_GENERIC(AT_SYMLINK_NOFOLLOW),
300#endif
301 FLAG_END,
302};
303
304UNUSED static struct flags unlinkat_flags[] = {
305#ifdef AT_REMOVEDIR
306 FLAG_GENERIC(AT_REMOVEDIR),
307#endif
308 FLAG_END,
309};
310
311UNUSED static struct flags mode_flags[] = {
312 FLAG_GENERIC(S_IFSOCK),
313 FLAG_GENERIC(S_IFLNK),
314 FLAG_GENERIC(S_IFREG),
315 FLAG_GENERIC(S_IFBLK),
316 FLAG_GENERIC(S_IFDIR),
317 FLAG_GENERIC(S_IFCHR),
318 FLAG_GENERIC(S_IFIFO),
319 FLAG_END,
320};
321
322UNUSED static struct flags open_access_flags[] = {
323 FLAG_TARGET(O_RDONLY),
324 FLAG_TARGET(O_WRONLY),
325 FLAG_TARGET(O_RDWR),
326 FLAG_END,
327};
328
329UNUSED static struct flags open_flags[] = {
330 FLAG_TARGET(O_APPEND),
331 FLAG_TARGET(O_CREAT),
332 FLAG_TARGET(O_DIRECTORY),
333 FLAG_TARGET(O_EXCL),
334 FLAG_TARGET(O_LARGEFILE),
335 FLAG_TARGET(O_NOCTTY),
336 FLAG_TARGET(O_NOFOLLOW),
337 FLAG_TARGET(O_NONBLOCK), /* also O_NDELAY */
338 FLAG_TARGET(O_SYNC),
339 FLAG_TARGET(O_TRUNC),
340#ifdef O_DIRECT
341 FLAG_TARGET(O_DIRECT),
342#endif
343 FLAG_END,
344};
345
346UNUSED static struct flags mount_flags[] = {
347#ifdef MS_BIND
348 FLAG_GENERIC(MS_BIND),
349#endif
350#ifdef MS_DIRSYNC
351 FLAG_GENERIC(MS_DIRSYNC),
352#endif
353 FLAG_GENERIC(MS_MANDLOCK),
354#ifdef MS_MOVE
355 FLAG_GENERIC(MS_MOVE),
356#endif
357 FLAG_GENERIC(MS_NOATIME),
358 FLAG_GENERIC(MS_NODEV),
359 FLAG_GENERIC(MS_NODIRATIME),
360 FLAG_GENERIC(MS_NOEXEC),
361 FLAG_GENERIC(MS_NOSUID),
362 FLAG_GENERIC(MS_RDONLY),
363#ifdef MS_RELATIME
364 FLAG_GENERIC(MS_RELATIME),
365#endif
366 FLAG_GENERIC(MS_REMOUNT),
367 FLAG_GENERIC(MS_SYNCHRONOUS),
368 FLAG_END,
369};
370
371UNUSED static struct flags umount2_flags[] = {
372#ifdef MNT_FORCE
373 FLAG_GENERIC(MNT_FORCE),
374#endif
375#ifdef MNT_DETACH
376 FLAG_GENERIC(MNT_DETACH),
377#endif
378#ifdef MNT_EXPIRE
379 FLAG_GENERIC(MNT_EXPIRE),
380#endif
381 FLAG_END,
382};
383
384UNUSED static struct flags mmap_prot_flags[] = {
385 FLAG_GENERIC(PROT_NONE),
386 FLAG_GENERIC(PROT_EXEC),
387 FLAG_GENERIC(PROT_READ),
388 FLAG_GENERIC(PROT_WRITE),
389 FLAG_END,
390};
391
392UNUSED static struct flags mmap_flags[] = {
393 FLAG_TARGET(MAP_SHARED),
394 FLAG_TARGET(MAP_PRIVATE),
395 FLAG_TARGET(MAP_ANONYMOUS),
396 FLAG_TARGET(MAP_DENYWRITE),
397 FLAG_TARGET(MAP_FIXED),
398 FLAG_TARGET(MAP_GROWSDOWN),
399#ifdef MAP_LOCKED
400 FLAG_TARGET(MAP_LOCKED),
401#endif
402#ifdef MAP_NONBLOCK
403 FLAG_TARGET(MAP_NONBLOCK),
404#endif
405 FLAG_TARGET(MAP_NORESERVE),
406#ifdef MAP_POPULATE
407 FLAG_TARGET(MAP_POPULATE),
408#endif
409 FLAG_END,
410};
411
412UNUSED static struct flags fcntl_flags[] = {
413 FLAG_TARGET(F_DUPFD),
414 FLAG_TARGET(F_GETFD),
415 FLAG_TARGET(F_SETFD),
416 FLAG_TARGET(F_GETFL),
417 FLAG_TARGET(F_SETFL),
418 FLAG_TARGET(F_GETLK),
419 FLAG_TARGET(F_SETLK),
420 FLAG_TARGET(F_SETLKW),
421 FLAG_END,
422};
423
424/*
425 * print_xxx utility functions. These are used to print syscall
426 * parameters in certain format. All of these have parameter
427 * named 'last'. This parameter is used to add comma to output
428 * when last == 0.
429 */
430
431static const char *
432get_comma(int last)
433{
434 return ((last) ? "" : ",");
435}
436
437static void
438print_flags(const struct flags *f, abi_long tflags, int last)
439{
440 const char *sep = "";
441 int flags;
442 int n;
443
444 flags = (int)tswap32(tflags);
445
446 if ((flags == 0) && (f->f_value == 0)) {
447 gemu_log("%s%s", f->f_string, get_comma(last));
448 return;
449 }
450 for (n = 0; f->f_string != NULL; f++) {
451 if ((f->f_value != 0) && ((flags & f->f_value) == f->f_value)) {
452 gemu_log("%s%s", sep, f->f_string);
453 flags &= ~f->f_value;
454 sep = "|";
455 n++;
456 }
457 }
458
459 if (n > 0) {
460 /* print rest of the flags as numeric */
461 if (flags != 0) {
462 gemu_log("%s%#x%s", sep, flags, get_comma(last));
463 } else {
464 gemu_log("%s", get_comma(last));
465 }
466 } else {
467 /* no string version of flags found, print them in hex then */
468 gemu_log("%#x%s", flags, get_comma(last));
469 }
470}
471
472static void
473print_at_dirfd(abi_long tdirfd, int last)
474{
475 int dirfd = tswap32(tdirfd);
476
477#ifdef AT_FDCWD
478 if (dirfd == AT_FDCWD) {
479 gemu_log("AT_FDCWD%s", get_comma(last));
480 return;
481 }
482#endif
483 gemu_log("%d%s", dirfd, get_comma(last));
484}
485
486static void
487print_file_mode(abi_long tmode, int last)
488{
489 const char *sep = "";
490 const struct flags *m;
491 mode_t mode = (mode_t)tswap32(tmode);
492
493 for (m = &mode_flags[0]; m->f_string != NULL; m++) {
494 if ((m->f_value & mode) == m->f_value) {
495 gemu_log("%s%s", m->f_string, sep);
496 sep = "|";
497 mode &= ~m->f_value;
498 break;
499 }
500 }
501
502 mode &= ~S_IFMT;
503 /* print rest of the mode as octal */
504 if (mode != 0)
505 gemu_log("%s%#o", sep, mode);
506
507 gemu_log("%s", get_comma(last));
508}
509
510static void
511print_open_flags(abi_long tflags, int last)
512{
513 int flags = tswap32(tflags);
514
515 print_flags(open_access_flags, flags & TARGET_O_ACCMODE, 1);
516 flags &= ~TARGET_O_ACCMODE;
517 if (flags == 0) {
518 gemu_log("%s", get_comma(last));
519 return;
520 }
521 gemu_log("|");
522 print_flags(open_flags, flags, last);
523}
524
525static void
526print_syscall_prologue(const struct syscallname *sc)
527{
528 gemu_log("%s(", sc->name);
529}
530
531/*ARGSUSED*/
532static void
533print_syscall_epilogue(const struct syscallname *sc)
534{
535 (void)sc;
536 gemu_log(")");
537}
538
539static void
540print_string(abi_long addr, int last)
541{
542 char *s;
543
544 if ((s = lock_user_string(addr)) != NULL) {
545 gemu_log("\"%s\"%s", s, get_comma(last));
546 unlock_user(s, addr, 0);
547 } else {
548 /* can't get string out of it, so print it as pointer */
549 print_pointer(addr, last);
550 }
551}
552
553/*
554 * Prints out raw parameter using given format. Caller needs
555 * to do byte swapping if needed.
556 */
557static void
558print_raw_param(const char *fmt, abi_long param, int last)
559{
560 char format[64];
561
562 (void) snprintf(format, sizeof (format), "%s%s", fmt, get_comma(last));
563 gemu_log(format, param);
564}
565
566static void
567print_pointer(abi_long p, int last)
568{
569 if (p == 0)
570 gemu_log("NULL%s", get_comma(last));
571 else
572 gemu_log("0x" TARGET_ABI_FMT_lx "%s", p, get_comma(last));
573}
574
575/*
576 * Reads 32-bit (int) number from guest address space from
577 * address 'addr' and prints it.
578 */
579static void
580print_number(abi_long addr, int last)
581{
582 if (addr == 0) {
583 gemu_log("NULL%s", get_comma(last));
584 } else {
585 int num;
586
587 get_user_s32(num, addr);
588 gemu_log("[%d]%s", num, get_comma(last));
589 }
590}
591
592static void
593print_timeval(abi_ulong tv_addr, int last)
594{
595 if( tv_addr ) {
596 struct target_timeval *tv;
597
598 tv = lock_user(VERIFY_READ, tv_addr, sizeof(*tv), 1);
599 if (!tv)
600 return;
601 gemu_log("{" TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld "}%s",
602 tv->tv_sec, tv->tv_usec, get_comma(last));
603 unlock_user(tv, tv_addr, 0);
604 } else
605 gemu_log("NULL%s", get_comma(last));
606}
607
608#undef UNUSED
609
610#ifdef TARGET_NR_accept
611static void
612print_accept(const struct syscallname *name,
613 abi_long arg0, abi_long arg1, abi_long arg2,
614 abi_long arg3, abi_long arg4, abi_long arg5)
615{
616 print_syscall_prologue(name);
617 print_raw_param("%d", tswap32(arg0), 0);
618 print_pointer(arg1, 0);
619 print_number(arg2, 1);
620 print_syscall_epilogue(name);
621}
622#endif
623
624#ifdef TARGET_NR_access
625static void
626print_access(const struct syscallname *name,
627 abi_long arg0, abi_long arg1, abi_long arg2,
628 abi_long arg3, abi_long arg4, abi_long arg5)
629{
630 print_syscall_prologue(name);
631 print_string(arg0, 0);
632 print_flags(access_flags, arg1, 1);
633 print_syscall_epilogue(name);
634}
635#endif
636
637#ifdef TARGET_NR_brk
638static void
639print_brk(const struct syscallname *name,
640 abi_long arg0, abi_long arg1, abi_long arg2,
641 abi_long arg3, abi_long arg4, abi_long arg5)
642{
643 print_syscall_prologue(name);
644 print_pointer(arg0, 1);
645 print_syscall_epilogue(name);
646}
647#endif
648
649#ifdef TARGET_NR_chdir
650static void
651print_chdir(const struct syscallname *name,
652 abi_long arg0, abi_long arg1, abi_long arg2,
653 abi_long arg3, abi_long arg4, abi_long arg5)
654{
655 print_syscall_prologue(name);
656 print_string(arg0, 1);
657 print_syscall_epilogue(name);
658}
659#endif
660
661#ifdef TARGET_NR_chmod
662static void
663print_chmod(const struct syscallname *name,
664 abi_long arg0, abi_long arg1, abi_long arg2,
665 abi_long arg3, abi_long arg4, abi_long arg5)
666{
667 print_syscall_prologue(name);
668 print_string(arg0, 0);
669 print_file_mode(arg1, 1);
670 print_syscall_epilogue(name);
671}
672#endif
673
674#ifdef TARGET_NR_creat
675static void
676print_creat(const struct syscallname *name,
677 abi_long arg0, abi_long arg1, abi_long arg2,
678 abi_long arg3, abi_long arg4, abi_long arg5)
679{
680 print_syscall_prologue(name);
681 print_string(arg0, 0);
682 print_file_mode(arg1, 1);
683 print_syscall_epilogue(name);
684}
685#endif
686
687#ifdef TARGET_NR_execv
688static void
689print_execv(const struct syscallname *name,
690 abi_long arg0, abi_long arg1, abi_long arg2,
691 abi_long arg3, abi_long arg4, abi_long arg5)
692{
693 print_syscall_prologue(name);
694 print_string(arg0, 0);
695 print_raw_param("0x" TARGET_ABI_FMT_lx, tswapl(arg1), 1);
696 print_syscall_epilogue(name);
697}
698#endif
699
700#ifdef TARGET_NR_faccessat
701static void
702print_faccessat(const struct syscallname *name,
703 abi_long arg0, abi_long arg1, abi_long arg2,
704 abi_long arg3, abi_long arg4, abi_long arg5)
705{
706 print_syscall_prologue(name);
707 print_at_dirfd(arg0, 0);
708 print_string(arg1, 0);
709 print_flags(access_flags, arg2, 0);
710 print_flags(at_file_flags, arg3, 1);
711 print_syscall_epilogue(name);
712}
713#endif
714
715#ifdef TARGET_NR_fchmodat
716static void
717print_fchmodat(const struct syscallname *name,
718 abi_long arg0, abi_long arg1, abi_long arg2,
719 abi_long arg3, abi_long arg4, abi_long arg5)
720{
721 print_syscall_prologue(name);
722 print_at_dirfd(arg0, 0);
723 print_string(arg1, 0);
724 print_file_mode(arg2, 0);
725 print_flags(at_file_flags, arg3, 1);
726 print_syscall_epilogue(name);
727}
728#endif
729
730#ifdef TARGET_NR_fchownat
731static void
732print_fchownat(const struct syscallname *name,
733 abi_long arg0, abi_long arg1, abi_long arg2,
734 abi_long arg3, abi_long arg4, abi_long arg5)
735{
736 print_syscall_prologue(name);
737 print_at_dirfd(arg0, 0);
738 print_string(arg1, 0);
739#ifdef USE_UID16
740 print_raw_param("%d", tswap16(arg2), 0);
741 print_raw_param("%d", tswap16(arg3), 0);
742#else
743 print_raw_param("%d", tswap32(arg2), 0);
744 print_raw_param("%d", tswap32(arg3), 0);
745#endif
746 print_flags(at_file_flags, arg4, 1);
747 print_syscall_epilogue(name);
748}
749#endif
750
751#if defined(TARGET_NR_fcntl) || defined(TARGET_NR_fcntl64)
752static void
753print_fcntl(const struct syscallname *name,
754 abi_long arg0, abi_long arg1, abi_long arg2,
755 abi_long arg3, abi_long arg4, abi_long arg5)
756{
757 print_syscall_prologue(name);
758 print_raw_param("%d", tswap32(arg0), 0);
759 print_flags(fcntl_flags, arg1, 0);
760 /*
761 * TODO: check flags and print following argument only
762 * when needed.
763 */
764 print_pointer(arg2, 1);
765 print_syscall_epilogue(name);
766}
767#define print_fcntl64 print_fcntl
768#endif
769
770
771#ifdef TARGET_NR_futimesat
772static void
773print_futimesat(const struct syscallname *name,
774 abi_long arg0, abi_long arg1, abi_long arg2,
775 abi_long arg3, abi_long arg4, abi_long arg5)
776{
777 print_syscall_prologue(name);
778 print_at_dirfd(arg0, 0);
779 print_string(arg1, 0);
780 print_timeval(arg2, 0);
781 print_timeval(arg2 + sizeof (struct target_timeval), 1);
782 print_syscall_epilogue(name);
783}
784#endif
785
786#ifdef TARGET_NR_link
787static void
788print_link(const struct syscallname *name,
789 abi_long arg0, abi_long arg1, abi_long arg2,
790 abi_long arg3, abi_long arg4, abi_long arg5)
791{
792 print_syscall_prologue(name);
793 print_string(arg0, 0);
794 print_string(arg1, 1);
795 print_syscall_epilogue(name);
796}
797#endif
798
799#ifdef TARGET_NR_linkat
800static void
801print_linkat(const struct syscallname *name,
802 abi_long arg0, abi_long arg1, abi_long arg2,
803 abi_long arg3, abi_long arg4, abi_long arg5)
804{
805 print_syscall_prologue(name);
806 print_at_dirfd(arg0, 0);
807 print_string(arg1, 0);
808 print_at_dirfd(arg2, 0);
809 print_string(arg3, 0);
810 print_flags(at_file_flags, arg4, 1);
811 print_syscall_epilogue(name);
812}
813#endif
814
815#if defined(TARGET_NR_stat) || defined(TARGET_NR_stat64) || \
816 defined(TARGET_NR_lstat) || defined(TARGET_NR_lstat64)
817static void
818print_stat(const struct syscallname *name,
819 abi_long arg0, abi_long arg1, abi_long arg2,
820 abi_long arg3, abi_long arg4, abi_long arg5)
821{
822 print_syscall_prologue(name);
823 print_string(arg0, 0);
824 print_pointer(arg1, 1);
825 print_syscall_epilogue(name);
826}
827#define print_lstat print_stat
828#define print_stat64 print_stat
829#define print_lstat64 print_stat
830#endif
831
832#if defined(TARGET_NR_fstat) || defined(TARGET_NR_fstat64)
833static void
834print_fstat(const struct syscallname *name,
835 abi_long arg0, abi_long arg1, abi_long arg2,
836 abi_long arg3, abi_long arg4, abi_long arg5)
837{
838 print_syscall_prologue(name);
839 print_raw_param("%d", tswap32(arg0), 0);
840 print_pointer(arg1, 1);
841 print_syscall_epilogue(name);
842}
843#define print_fstat64 print_fstat
844#endif
845
846#ifdef TARGET_NR_mkdir
847static void
848print_mkdir(const struct syscallname *name,
849 abi_long arg0, abi_long arg1, abi_long arg2,
850 abi_long arg3, abi_long arg4, abi_long arg5)
851{
852 print_syscall_prologue(name);
853 print_string(arg0, 0);
854 print_file_mode(arg1, 1);
855 print_syscall_epilogue(name);
856}
857#endif
858
859#ifdef TARGET_NR_mkdirat
860static void
861print_mkdirat(const struct syscallname *name,
862 abi_long arg0, abi_long arg1, abi_long arg2,
863 abi_long arg3, abi_long arg4, abi_long arg5)
864{
865 print_syscall_prologue(name);
866 print_at_dirfd(arg0, 0);
867 print_string(arg1, 0);
868 print_file_mode(arg2, 1);
869 print_syscall_epilogue(name);
870}
871#endif
872
873#ifdef TARGET_NR_mknod
874static void
875print_mknod(const struct syscallname *name,
876 abi_long arg0, abi_long arg1, abi_long arg2,
877 abi_long arg3, abi_long arg4, abi_long arg5)
878{
879 int hasdev = (tswapl(arg1) & (S_IFCHR|S_IFBLK));
880
881 print_syscall_prologue(name);
882 print_string(arg0, 0);
883 print_file_mode(arg1, (hasdev == 0));
884 if (hasdev) {
885 print_raw_param("makedev(%d", major(tswapl(arg2)), 0);
886 print_raw_param("%d)", minor(tswapl(arg2)), 1);
887 }
888 print_syscall_epilogue(name);
889}
890#endif
891
892#ifdef TARGET_NR_mknodat
893static void
894print_mknodat(const struct syscallname *name,
895 abi_long arg0, abi_long arg1, abi_long arg2,
896 abi_long arg3, abi_long arg4, abi_long arg5)
897{
898 int hasdev = (tswapl(arg2) & (S_IFCHR|S_IFBLK));
899
900 print_syscall_prologue(name);
901 print_at_dirfd(arg0, 0);
902 print_string(arg1, 0);
903 print_file_mode(arg2, (hasdev == 0));
904 if (hasdev) {
905 print_raw_param("makedev(%d", major(tswapl(arg3)), 0);
906 print_raw_param("%d)", minor(tswapl(arg3)), 1);
907 }
908 print_syscall_epilogue(name);
909}
910#endif
911
912#ifdef TARGET_NR_mq_open
913static void
914print_mq_open(const struct syscallname *name,
915 abi_long arg0, abi_long arg1, abi_long arg2,
916 abi_long arg3, abi_long arg4, abi_long arg5)
917{
918 int is_creat = (tswapl(arg1) & TARGET_O_CREAT);
919
920 print_syscall_prologue(name);
921 print_string(arg0, 0);
922 print_open_flags(arg1, (is_creat == 0));
923 if (is_creat) {
924 print_file_mode(arg2, 0);
925 print_pointer(arg3, 1);
926 }
927 print_syscall_epilogue(name);
928}
929#endif
930
931#ifdef TARGET_NR_open
932static void
933print_open(const struct syscallname *name,
934 abi_long arg0, abi_long arg1, abi_long arg2,
935 abi_long arg3, abi_long arg4, abi_long arg5)
936{
937 int is_creat = (tswap32(arg1) & TARGET_O_CREAT);
938
939 print_syscall_prologue(name);
940 print_string(arg0, 0);
941 print_open_flags(arg1, (is_creat == 0));
942 if (is_creat)
943 print_file_mode(arg2, 1);
944 print_syscall_epilogue(name);
945}
946#endif
947
948#ifdef TARGET_NR_openat
949static void
950print_openat(const struct syscallname *name,
951 abi_long arg0, abi_long arg1, abi_long arg2,
952 abi_long arg3, abi_long arg4, abi_long arg5)
953{
954 int is_creat = (tswap32(arg2) & TARGET_O_CREAT);
955
956 print_syscall_prologue(name);
957 print_at_dirfd(arg0, 0);
958 print_string(arg1, 0);
959 print_open_flags(arg2, (is_creat == 0));
960 if (is_creat)
961 print_file_mode(arg3, 1);
962 print_syscall_epilogue(name);
963}
964#endif
965
966#ifdef TARGET_NR_mq_unlink
967static void
968print_mq_unlink(const struct syscallname *name,
969 abi_long arg0, abi_long arg1, abi_long arg2,
970 abi_long arg3, abi_long arg4, abi_long arg5)
971{
972 print_syscall_prologue(name);
973 print_string(arg0, 1);
974 print_syscall_epilogue(name);
975}
976#endif
977
978#if defined(TARGET_NR_fstatat64) || defined(TARGET_NR_newfstatat)
979static void
980print_fstatat64(const struct syscallname *name,
981 abi_long arg0, abi_long arg1, abi_long arg2,
982 abi_long arg3, abi_long arg4, abi_long arg5)
983{
984 print_syscall_prologue(name);
985 print_at_dirfd(arg0, 0);
986 print_string(arg1, 0);
987 print_pointer(arg2, 0);
988 print_flags(at_file_flags, arg3, 1);
989 print_syscall_epilogue(name);
990}
991#define print_newfstatat print_fstatat64
992#endif
993
994#ifdef TARGET_NR_readlink
995static void
996print_readlink(const struct syscallname *name,
997 abi_long arg0, abi_long arg1, abi_long arg2,
998 abi_long arg3, abi_long arg4, abi_long arg5)
999{
1000 print_syscall_prologue(name);
1001 print_string(arg0, 0);
1002 print_pointer(arg1, 0);
1003 print_raw_param("%u", tswapl(arg2), 1);
1004 print_syscall_epilogue(name);
1005}
1006#endif
1007
1008#ifdef TARGET_NR_readlinkat
1009static void
1010print_readlinkat(const struct syscallname *name,
1011 abi_long arg0, abi_long arg1, abi_long arg2,
1012 abi_long arg3, abi_long arg4, abi_long arg5)
1013{
1014 print_syscall_prologue(name);
1015 print_at_dirfd(arg0, 0);
1016 print_string(arg1, 0);
1017 print_pointer(arg2, 0);
1018 print_raw_param("%u", tswapl(arg3), 1);
1019 print_syscall_epilogue(name);
1020}
1021#endif
1022
1023#ifdef TARGET_NR_rename
1024static void
1025print_rename(const struct syscallname *name,
1026 abi_long arg0, abi_long arg1, abi_long arg2,
1027 abi_long arg3, abi_long arg4, abi_long arg5)
1028{
1029 print_syscall_prologue(name);
1030 print_string(arg0, 0);
1031 print_string(arg1, 1);
1032 print_syscall_epilogue(name);
1033}
1034#endif
1035
1036#ifdef TARGET_NR_renameat
1037static void
1038print_renameat(const struct syscallname *name,
1039 abi_long arg0, abi_long arg1, abi_long arg2,
1040 abi_long arg3, abi_long arg4, abi_long arg5)
1041{
1042 print_syscall_prologue(name);
1043 print_at_dirfd(arg0, 0);
1044 print_string(arg1, 0);
1045 print_at_dirfd(arg2, 0);
1046 print_string(arg3, 1);
1047 print_syscall_epilogue(name);
1048}
1049#endif
1050
1051#ifdef TARGET_NR_statfs
1052static void
1053print_statfs(const struct syscallname *name,
1054 abi_long arg0, abi_long arg1, abi_long arg2,
1055 abi_long arg3, abi_long arg4, abi_long arg5)
1056{
1057 print_syscall_prologue(name);
1058 print_string(arg0, 0);
1059 print_pointer(arg1, 1);
1060 print_syscall_epilogue(name);
1061}
1062#define print_statfs64 print_statfs
1063#endif
1064
1065#ifdef TARGET_NR_symlink
1066static void
1067print_symlink(const struct syscallname *name,
1068 abi_long arg0, abi_long arg1, abi_long arg2,
1069 abi_long arg3, abi_long arg4, abi_long arg5)
1070{
1071 print_syscall_prologue(name);
1072 print_string(arg0, 0);
1073 print_string(arg1, 1);
1074 print_syscall_epilogue(name);
1075}
1076#endif
1077
1078#ifdef TARGET_NR_symlinkat
1079static void
1080print_symlinkat(const struct syscallname *name,
1081 abi_long arg0, abi_long arg1, abi_long arg2,
1082 abi_long arg3, abi_long arg4, abi_long arg5)
1083{
1084 print_syscall_prologue(name);
1085 print_string(arg0, 0);
1086 print_at_dirfd(arg1, 0);
1087 print_string(arg2, 1);
1088 print_syscall_epilogue(name);
1089}
1090#endif
1091
1092#ifdef TARGET_NR_mount
1093static void
1094print_mount(const struct syscallname *name,
1095 abi_long arg0, abi_long arg1, abi_long arg2,
1096 abi_long arg3, abi_long arg4, abi_long arg5)
1097{
1098 print_syscall_prologue(name);
1099 print_string(arg0, 0);
1100 print_string(arg1, 0);
1101 print_string(arg2, 0);
1102 print_flags(mount_flags, arg3, 0);
1103 print_pointer(arg4, 1);
1104 print_syscall_epilogue(name);
1105}
1106#endif
1107
1108#ifdef TARGET_NR_umount
1109static void
1110print_umount(const struct syscallname *name,
1111 abi_long arg0, abi_long arg1, abi_long arg2,
1112 abi_long arg3, abi_long arg4, abi_long arg5)
1113{
1114 print_syscall_prologue(name);
1115 print_string(arg0, 1);
1116 print_syscall_epilogue(name);
1117}
1118#endif
1119
1120#ifdef TARGET_NR_umount2
1121static void
1122print_umount2(const struct syscallname *name,
1123 abi_long arg0, abi_long arg1, abi_long arg2,
1124 abi_long arg3, abi_long arg4, abi_long arg5)
1125{
1126 print_syscall_prologue(name);
1127 print_string(arg0, 0);
1128 print_flags(umount2_flags, arg1, 1);
1129 print_syscall_epilogue(name);
1130}
1131#endif
1132
1133#ifdef TARGET_NR_unlink
1134static void
1135print_unlink(const struct syscallname *name,
1136 abi_long arg0, abi_long arg1, abi_long arg2,
1137 abi_long arg3, abi_long arg4, abi_long arg5)
1138{
1139 print_syscall_prologue(name);
1140 print_string(arg0, 1);
1141 print_syscall_epilogue(name);
1142}
1143#endif
1144
1145#ifdef TARGET_NR_unlinkat
1146static void
1147print_unlinkat(const struct syscallname *name,
1148 abi_long arg0, abi_long arg1, abi_long arg2,
1149 abi_long arg3, abi_long arg4, abi_long arg5)
1150{
1151 print_syscall_prologue(name);
1152 print_at_dirfd(arg0, 0);
1153 print_string(arg1, 0);
1154 print_flags(unlinkat_flags, arg2, 1);
1155 print_syscall_epilogue(name);
1156}
1157#endif
1158
1159#ifdef TARGET_NR_utime
1160static void
1161print_utime(const struct syscallname *name,
1162 abi_long arg0, abi_long arg1, abi_long arg2,
1163 abi_long arg3, abi_long arg4, abi_long arg5)
1164{
1165 print_syscall_prologue(name);
1166 print_string(arg0, 0);
1167 print_pointer(arg1, 1);
1168 print_syscall_epilogue(name);
1169}
1170#endif
1171
1172#ifdef TARGET_NR_utimes
1173static void
1174print_utimes(const struct syscallname *name,
1175 abi_long arg0, abi_long arg1, abi_long arg2,
1176 abi_long arg3, abi_long arg4, abi_long arg5)
1177{
1178 print_syscall_prologue(name);
1179 print_string(arg0, 0);
1180 print_pointer(arg1, 1);
1181 print_syscall_epilogue(name);
1182}
1183#endif
1184
1185#ifdef TARGET_NR_utimensat
1186static void
1187print_utimensat(const struct syscallname *name,
1188 abi_long arg0, abi_long arg1, abi_long arg2,
1189 abi_long arg3, abi_long arg4, abi_long arg5)
1190{
1191 print_syscall_prologue(name);
1192 print_at_dirfd(arg0, 0);
1193 print_string(arg1, 0);
1194 print_pointer(arg2, 0);
1195 print_flags(at_file_flags, arg3, 1);
1196 print_syscall_epilogue(name);
1197}
1198#endif
1199
1200#ifdef TARGET_NR_mmap
1201static void
1202print_mmap(const struct syscallname *name,
1203 abi_long arg0, abi_long arg1, abi_long arg2,
1204 abi_long arg3, abi_long arg4, abi_long arg5)
1205{
1206 print_syscall_prologue(name);
1207 print_pointer(arg0, 0);
1208 print_raw_param("%d", tswapl(arg1), 0);
1209 print_flags(mmap_prot_flags, arg2, 0);
1210 print_flags(mmap_flags, arg3, 0);
1211 print_raw_param("%d", tswapl(arg4), 0);
1212 print_raw_param("%#x", tswapl(arg5), 1);
1213 print_syscall_epilogue(name);
1214}
1215#define print_mmap2 print_mmap
1216#endif
1217
1218#ifdef TARGET_NR_mprotect
1219static void
1220print_mprotect(const struct syscallname *name,
1221 abi_long arg0, abi_long arg1, abi_long arg2,
1222 abi_long arg3, abi_long arg4, abi_long arg5)
1223{
1224 print_syscall_prologue(name);
1225 print_pointer(arg0, 0);
1226 print_raw_param("%d", tswapl(arg1), 0);
1227 print_flags(mmap_prot_flags, arg2, 1);
1228 print_syscall_epilogue(name);
1229}
1230#endif
1231
1232#ifdef TARGET_NR_munmap
1233static void
1234print_munmap(const struct syscallname *name,
1235 abi_long arg0, abi_long arg1, abi_long arg2,
1236 abi_long arg3, abi_long arg4, abi_long arg5)
1237{
1238 print_syscall_prologue(name);
1239 print_pointer(arg0, 0);
1240 print_raw_param("%d", tswapl(arg1), 1);
1241 print_syscall_epilogue(name);
1242}
1243#endif
1244
1245#ifdef TARGET_NR_futex
1246static void print_futex_op(abi_long tflag, int last)
1247{
1248#define print_op(val) \
1249if( cmd == val ) { \
1250 gemu_log(#val); \
1251 return; \
1252}
1253
1254 int cmd = (int)tswap32(tflag);
1255#ifdef FUTEX_PRIVATE_FLAG
1256 if (cmd == FUTEX_PRIVATE_FLAG)
1257 gemu_log("FUTEX_PRIVATE_FLAG|");
1258#endif
1259 print_op(FUTEX_WAIT)
1260 print_op(FUTEX_WAKE)
1261 print_op(FUTEX_FD)
1262 print_op(FUTEX_REQUEUE)
1263 print_op(FUTEX_CMP_REQUEUE)
1264 print_op(FUTEX_WAKE_OP)
1265 print_op(FUTEX_LOCK_PI)
1266 print_op(FUTEX_UNLOCK_PI)
1267 print_op(FUTEX_TRYLOCK_PI)
1268#ifdef FUTEX_WAIT_BITSET
1269 print_op(FUTEX_WAIT_BITSET)
1270#endif
1271#ifdef FUTEX_WAKE_BITSET
1272 print_op(FUTEX_WAKE_BITSET)
1273#endif
1274 /* unknown values */
1275 gemu_log("%d",cmd);
1276}
1277
1278static void
1279print_futex(const struct syscallname *name,
1280 abi_long arg0, abi_long arg1, abi_long arg2,
1281 abi_long arg3, abi_long arg4, abi_long arg5)
1282{
1283 print_syscall_prologue(name);
1284 print_pointer(arg0, 0);
1285 print_futex_op(arg1, 0);
1286 print_raw_param(",%d", tswapl(arg2), 0);
1287 print_pointer(arg3, 0); /* struct timespec */
1288 print_pointer(arg4, 0);
1289 print_raw_param("%d", tswapl(arg4), 1);
1290 print_syscall_epilogue(name);
1291}
1292#endif
1293
33189d31
TS
1294/*
1295 * An array of all of the syscalls we know about
1296 */
1297
7ccfb2eb 1298static const struct syscallname scnames[] = {
33189d31
TS
1299#include "strace.list"
1300};
1301
b1503cda 1302static int nsyscalls = ARRAY_SIZE(scnames);
33189d31
TS
1303
1304/*
1305 * The public interface to this module.
1306 */
1307void
1308print_syscall(int num,
c16f9ed3
FB
1309 abi_long arg1, abi_long arg2, abi_long arg3,
1310 abi_long arg4, abi_long arg5, abi_long arg6)
33189d31
TS
1311{
1312 int i;
7ccfb2eb 1313 const char *format="%s(" TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld ")";
33189d31
TS
1314
1315 gemu_log("%d ", getpid() );
1316
1317 for(i=0;i<nsyscalls;i++)
1318 if( scnames[i].nr == num ) {
1319 if( scnames[i].call != NULL ) {
1320 scnames[i].call(&scnames[i],arg1,arg2,arg3,arg4,arg5,arg6);
1321 } else {
6b23f777
FB
1322 /* XXX: this format system is broken because it uses
1323 host types and host pointers for strings */
33189d31
TS
1324 if( scnames[i].format != NULL )
1325 format = scnames[i].format;
1326 gemu_log(format,scnames[i].name, arg1,arg2,arg3,arg4,arg5,arg6);
1327 }
74c11e55 1328 return;
33189d31 1329 }
74c11e55 1330 gemu_log("Unknown syscall %d\n", num);
33189d31
TS
1331}
1332
1333
1334void
c16f9ed3 1335print_syscall_ret(int num, abi_long ret)
33189d31
TS
1336{
1337 int i;
1338
1339 for(i=0;i<nsyscalls;i++)
1340 if( scnames[i].nr == num ) {
1341 if( scnames[i].result != NULL ) {
1342 scnames[i].result(&scnames[i],ret);
1343 } else {
1344 if( ret < 0 ) {
c16f9ed3 1345 gemu_log(" = -1 errno=" TARGET_ABI_FMT_ld " (%s)\n", -ret, target_strerror(-ret));
33189d31 1346 } else {
c16f9ed3 1347 gemu_log(" = " TARGET_ABI_FMT_ld "\n", ret);
33189d31
TS
1348 }
1349 }
1350 break;
1351 }
1352}
This page took 0.344255 seconds and 4 git commands to generate.