scsi: esp: check buffer length before reading scsi command
[qemu.git] / linux-user / strace.c
1 #include "qemu/osdep.h"
2 #include <sys/ipc.h>
3 #include <sys/msg.h>
4 #include <sys/sem.h>
5 #include <sys/shm.h>
6 #include <sys/select.h>
7 #include <sys/mount.h>
8 #include <sched.h>
9 #include "qemu.h"
10
11 int do_strace=0;
12
13 struct syscallname {
14 int nr;
15 const char *name;
16 const char *format;
17 void (*call)(const struct syscallname *,
18 abi_long, abi_long, abi_long,
19 abi_long, abi_long, abi_long);
20 void (*result)(const struct syscallname *, abi_long);
21 };
22
23 #ifdef __GNUC__
24 /*
25 * It is possible that target doesn't have syscall that uses
26 * following flags but we don't want the compiler to warn
27 * us about them being unused. Same applies to utility print
28 * functions. It is ok to keep them while not used.
29 */
30 #define UNUSED __attribute__ ((unused))
31 #else
32 #define UNUSED
33 #endif
34
35 /*
36 * Structure used to translate flag values into strings. This is
37 * similar that is in the actual strace tool.
38 */
39 struct flags {
40 abi_long f_value; /* flag */
41 const char *f_string; /* stringified flag */
42 };
43
44 /* common flags for all architectures */
45 #define FLAG_GENERIC(name) { name, #name }
46 /* target specific flags (syscall_defs.h has TARGET_<flag>) */
47 #define FLAG_TARGET(name) { TARGET_ ## name, #name }
48 /* end of flags array */
49 #define FLAG_END { 0, NULL }
50
51 UNUSED static const char *get_comma(int);
52 UNUSED static void print_pointer(abi_long, int);
53 UNUSED static void print_flags(const struct flags *, abi_long, int);
54 UNUSED static void print_at_dirfd(abi_long, int);
55 UNUSED static void print_file_mode(abi_long, int);
56 UNUSED static void print_open_flags(abi_long, int);
57 UNUSED static void print_syscall_prologue(const struct syscallname *);
58 UNUSED static void print_syscall_epilogue(const struct syscallname *);
59 UNUSED static void print_string(abi_long, int);
60 UNUSED static void print_raw_param(const char *, abi_long, int);
61 UNUSED static void print_timeval(abi_ulong, int);
62 UNUSED static void print_number(abi_long, int);
63 UNUSED static void print_signal(abi_ulong, int);
64
65 /*
66 * Utility functions
67 */
68 static void
69 print_ipc_cmd(int cmd)
70 {
71 #define output_cmd(val) \
72 if( cmd == val ) { \
73 gemu_log(#val); \
74 return; \
75 }
76
77 cmd &= 0xff;
78
79 /* General IPC commands */
80 output_cmd( IPC_RMID );
81 output_cmd( IPC_SET );
82 output_cmd( IPC_STAT );
83 output_cmd( IPC_INFO );
84 /* msgctl() commands */
85 #ifdef __USER_MISC
86 output_cmd( MSG_STAT );
87 output_cmd( MSG_INFO );
88 #endif
89 /* shmctl() commands */
90 output_cmd( SHM_LOCK );
91 output_cmd( SHM_UNLOCK );
92 output_cmd( SHM_STAT );
93 output_cmd( SHM_INFO );
94 /* semctl() commands */
95 output_cmd( GETPID );
96 output_cmd( GETVAL );
97 output_cmd( GETALL );
98 output_cmd( GETNCNT );
99 output_cmd( GETZCNT );
100 output_cmd( SETVAL );
101 output_cmd( SETALL );
102 output_cmd( SEM_STAT );
103 output_cmd( SEM_INFO );
104 output_cmd( IPC_RMID );
105 output_cmd( IPC_RMID );
106 output_cmd( IPC_RMID );
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
114 /* Some value we don't recognize */
115 gemu_log("%d",cmd);
116 }
117
118 static void
119 print_signal(abi_ulong arg, int last)
120 {
121 const char *signal_name = NULL;
122 switch(arg) {
123 case TARGET_SIGHUP: signal_name = "SIGHUP"; break;
124 case TARGET_SIGINT: signal_name = "SIGINT"; break;
125 case TARGET_SIGQUIT: signal_name = "SIGQUIT"; break;
126 case TARGET_SIGILL: signal_name = "SIGILL"; break;
127 case TARGET_SIGABRT: signal_name = "SIGABRT"; break;
128 case TARGET_SIGFPE: signal_name = "SIGFPE"; break;
129 case TARGET_SIGKILL: signal_name = "SIGKILL"; break;
130 case TARGET_SIGSEGV: signal_name = "SIGSEGV"; break;
131 case TARGET_SIGPIPE: signal_name = "SIGPIPE"; break;
132 case TARGET_SIGALRM: signal_name = "SIGALRM"; break;
133 case TARGET_SIGTERM: signal_name = "SIGTERM"; break;
134 case TARGET_SIGUSR1: signal_name = "SIGUSR1"; break;
135 case TARGET_SIGUSR2: signal_name = "SIGUSR2"; break;
136 case TARGET_SIGCHLD: signal_name = "SIGCHLD"; break;
137 case TARGET_SIGCONT: signal_name = "SIGCONT"; break;
138 case TARGET_SIGSTOP: signal_name = "SIGSTOP"; break;
139 case TARGET_SIGTTIN: signal_name = "SIGTTIN"; break;
140 case TARGET_SIGTTOU: signal_name = "SIGTTOU"; break;
141 }
142 if (signal_name == NULL) {
143 print_raw_param("%ld", arg, last);
144 return;
145 }
146 gemu_log("%s%s", signal_name, get_comma(last));
147 }
148
149 #ifdef TARGET_NR__newselect
150 static void
151 print_fdset(int n, abi_ulong target_fds_addr)
152 {
153 int i;
154
155 gemu_log("[");
156 if( target_fds_addr ) {
157 abi_long *target_fds;
158
159 target_fds = lock_user(VERIFY_READ,
160 target_fds_addr,
161 sizeof(*target_fds)*(n / TARGET_ABI_BITS + 1),
162 1);
163
164 if (!target_fds)
165 return;
166
167 for (i=n; i>=0; i--) {
168 if ((tswapal(target_fds[i / TARGET_ABI_BITS]) >> (i & (TARGET_ABI_BITS - 1))) & 1)
169 gemu_log("%d,", i );
170 }
171 unlock_user(target_fds, target_fds_addr, 0);
172 }
173 gemu_log("]");
174 }
175 #endif
176
177 /*
178 * Sysycall specific output functions
179 */
180
181 /* select */
182 #ifdef TARGET_NR__newselect
183 static long newselect_arg1 = 0;
184 static long newselect_arg2 = 0;
185 static long newselect_arg3 = 0;
186 static long newselect_arg4 = 0;
187 static long newselect_arg5 = 0;
188
189 static void
190 print_newselect(const struct syscallname *name,
191 abi_long arg1, abi_long arg2, abi_long arg3,
192 abi_long arg4, abi_long arg5, abi_long arg6)
193 {
194 gemu_log("%s(" TARGET_ABI_FMT_ld ",", name->name, arg1);
195 print_fdset(arg1, arg2);
196 gemu_log(",");
197 print_fdset(arg1, arg3);
198 gemu_log(",");
199 print_fdset(arg1, arg4);
200 gemu_log(",");
201 print_timeval(arg5, 1);
202 gemu_log(")");
203
204 /* save for use in the return output function below */
205 newselect_arg1=arg1;
206 newselect_arg2=arg2;
207 newselect_arg3=arg3;
208 newselect_arg4=arg4;
209 newselect_arg5=arg5;
210 }
211 #endif
212
213 #ifdef TARGET_NR_semctl
214 static void
215 print_semctl(const struct syscallname *name,
216 abi_long arg1, abi_long arg2, abi_long arg3,
217 abi_long arg4, abi_long arg5, abi_long arg6)
218 {
219 gemu_log("%s(" TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld ",", name->name, arg1, arg2);
220 print_ipc_cmd(arg3);
221 gemu_log(",0x" TARGET_ABI_FMT_lx ")", arg4);
222 }
223 #endif
224
225 static void
226 print_execve(const struct syscallname *name,
227 abi_long arg1, abi_long arg2, abi_long arg3,
228 abi_long arg4, abi_long arg5, abi_long arg6)
229 {
230 abi_ulong arg_ptr_addr;
231 char *s;
232
233 if (!(s = lock_user_string(arg1)))
234 return;
235 gemu_log("%s(\"%s\",{", name->name, s);
236 unlock_user(s, arg1, 0);
237
238 for (arg_ptr_addr = arg2; ; arg_ptr_addr += sizeof(abi_ulong)) {
239 abi_ulong *arg_ptr, arg_addr;
240
241 arg_ptr = lock_user(VERIFY_READ, arg_ptr_addr, sizeof(abi_ulong), 1);
242 if (!arg_ptr)
243 return;
244 arg_addr = tswapal(*arg_ptr);
245 unlock_user(arg_ptr, arg_ptr_addr, 0);
246 if (!arg_addr)
247 break;
248 if ((s = lock_user_string(arg_addr))) {
249 gemu_log("\"%s\",", s);
250 unlock_user(s, arg_addr, 0);
251 }
252 }
253
254 gemu_log("NULL})");
255 }
256
257 #ifdef TARGET_NR_ipc
258 static void
259 print_ipc(const struct syscallname *name,
260 abi_long arg1, abi_long arg2, abi_long arg3,
261 abi_long arg4, abi_long arg5, abi_long arg6)
262 {
263 switch(arg1) {
264 case IPCOP_semctl:
265 gemu_log("semctl(" TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld ",", arg1, arg2);
266 print_ipc_cmd(arg3);
267 gemu_log(",0x" TARGET_ABI_FMT_lx ")", arg4);
268 break;
269 default:
270 gemu_log("%s(" TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld ")",
271 name->name, arg1, arg2, arg3, arg4);
272 }
273 }
274 #endif
275
276 /*
277 * Variants for the return value output function
278 */
279
280 static void
281 print_syscall_ret_addr(const struct syscallname *name, abi_long ret)
282 {
283 const char *errstr = NULL;
284
285 if (ret < 0) {
286 errstr = target_strerror(-ret);
287 }
288 if (errstr) {
289 gemu_log(" = -1 errno=%d (%s)\n", (int)-ret, errstr);
290 } else {
291 gemu_log(" = 0x" TARGET_ABI_FMT_lx "\n", ret);
292 }
293 }
294
295 #if 0 /* currently unused */
296 static void
297 print_syscall_ret_raw(struct syscallname *name, abi_long ret)
298 {
299 gemu_log(" = 0x" TARGET_ABI_FMT_lx "\n", ret);
300 }
301 #endif
302
303 #ifdef TARGET_NR__newselect
304 static void
305 print_syscall_ret_newselect(const struct syscallname *name, abi_long ret)
306 {
307 gemu_log(" = 0x" TARGET_ABI_FMT_lx " (", ret);
308 print_fdset(newselect_arg1,newselect_arg2);
309 gemu_log(",");
310 print_fdset(newselect_arg1,newselect_arg3);
311 gemu_log(",");
312 print_fdset(newselect_arg1,newselect_arg4);
313 gemu_log(",");
314 print_timeval(newselect_arg5, 1);
315 gemu_log(")\n");
316 }
317 #endif
318
319 UNUSED static struct flags access_flags[] = {
320 FLAG_GENERIC(F_OK),
321 FLAG_GENERIC(R_OK),
322 FLAG_GENERIC(W_OK),
323 FLAG_GENERIC(X_OK),
324 FLAG_END,
325 };
326
327 UNUSED static struct flags at_file_flags[] = {
328 #ifdef AT_EACCESS
329 FLAG_GENERIC(AT_EACCESS),
330 #endif
331 #ifdef AT_SYMLINK_NOFOLLOW
332 FLAG_GENERIC(AT_SYMLINK_NOFOLLOW),
333 #endif
334 FLAG_END,
335 };
336
337 UNUSED static struct flags unlinkat_flags[] = {
338 #ifdef AT_REMOVEDIR
339 FLAG_GENERIC(AT_REMOVEDIR),
340 #endif
341 FLAG_END,
342 };
343
344 UNUSED static struct flags mode_flags[] = {
345 FLAG_GENERIC(S_IFSOCK),
346 FLAG_GENERIC(S_IFLNK),
347 FLAG_GENERIC(S_IFREG),
348 FLAG_GENERIC(S_IFBLK),
349 FLAG_GENERIC(S_IFDIR),
350 FLAG_GENERIC(S_IFCHR),
351 FLAG_GENERIC(S_IFIFO),
352 FLAG_END,
353 };
354
355 UNUSED static struct flags open_access_flags[] = {
356 FLAG_TARGET(O_RDONLY),
357 FLAG_TARGET(O_WRONLY),
358 FLAG_TARGET(O_RDWR),
359 FLAG_END,
360 };
361
362 UNUSED static struct flags open_flags[] = {
363 FLAG_TARGET(O_APPEND),
364 FLAG_TARGET(O_CREAT),
365 FLAG_TARGET(O_DIRECTORY),
366 FLAG_TARGET(O_EXCL),
367 FLAG_TARGET(O_LARGEFILE),
368 FLAG_TARGET(O_NOCTTY),
369 FLAG_TARGET(O_NOFOLLOW),
370 FLAG_TARGET(O_NONBLOCK), /* also O_NDELAY */
371 FLAG_TARGET(O_DSYNC),
372 FLAG_TARGET(__O_SYNC),
373 FLAG_TARGET(O_TRUNC),
374 #ifdef O_DIRECT
375 FLAG_TARGET(O_DIRECT),
376 #endif
377 #ifdef O_NOATIME
378 FLAG_TARGET(O_NOATIME),
379 #endif
380 #ifdef O_CLOEXEC
381 FLAG_TARGET(O_CLOEXEC),
382 #endif
383 #ifdef O_PATH
384 FLAG_TARGET(O_PATH),
385 #endif
386 FLAG_END,
387 };
388
389 UNUSED static struct flags mount_flags[] = {
390 #ifdef MS_BIND
391 FLAG_GENERIC(MS_BIND),
392 #endif
393 #ifdef MS_DIRSYNC
394 FLAG_GENERIC(MS_DIRSYNC),
395 #endif
396 FLAG_GENERIC(MS_MANDLOCK),
397 #ifdef MS_MOVE
398 FLAG_GENERIC(MS_MOVE),
399 #endif
400 FLAG_GENERIC(MS_NOATIME),
401 FLAG_GENERIC(MS_NODEV),
402 FLAG_GENERIC(MS_NODIRATIME),
403 FLAG_GENERIC(MS_NOEXEC),
404 FLAG_GENERIC(MS_NOSUID),
405 FLAG_GENERIC(MS_RDONLY),
406 #ifdef MS_RELATIME
407 FLAG_GENERIC(MS_RELATIME),
408 #endif
409 FLAG_GENERIC(MS_REMOUNT),
410 FLAG_GENERIC(MS_SYNCHRONOUS),
411 FLAG_END,
412 };
413
414 UNUSED static struct flags umount2_flags[] = {
415 #ifdef MNT_FORCE
416 FLAG_GENERIC(MNT_FORCE),
417 #endif
418 #ifdef MNT_DETACH
419 FLAG_GENERIC(MNT_DETACH),
420 #endif
421 #ifdef MNT_EXPIRE
422 FLAG_GENERIC(MNT_EXPIRE),
423 #endif
424 FLAG_END,
425 };
426
427 UNUSED static struct flags mmap_prot_flags[] = {
428 FLAG_GENERIC(PROT_NONE),
429 FLAG_GENERIC(PROT_EXEC),
430 FLAG_GENERIC(PROT_READ),
431 FLAG_GENERIC(PROT_WRITE),
432 FLAG_TARGET(PROT_SEM),
433 FLAG_GENERIC(PROT_GROWSDOWN),
434 FLAG_GENERIC(PROT_GROWSUP),
435 FLAG_END,
436 };
437
438 UNUSED static struct flags mmap_flags[] = {
439 FLAG_TARGET(MAP_SHARED),
440 FLAG_TARGET(MAP_PRIVATE),
441 FLAG_TARGET(MAP_ANONYMOUS),
442 FLAG_TARGET(MAP_DENYWRITE),
443 FLAG_TARGET(MAP_FIXED),
444 FLAG_TARGET(MAP_GROWSDOWN),
445 FLAG_TARGET(MAP_EXECUTABLE),
446 #ifdef MAP_LOCKED
447 FLAG_TARGET(MAP_LOCKED),
448 #endif
449 #ifdef MAP_NONBLOCK
450 FLAG_TARGET(MAP_NONBLOCK),
451 #endif
452 FLAG_TARGET(MAP_NORESERVE),
453 #ifdef MAP_POPULATE
454 FLAG_TARGET(MAP_POPULATE),
455 #endif
456 #ifdef TARGET_MAP_UNINITIALIZED
457 FLAG_TARGET(MAP_UNINITIALIZED),
458 #endif
459 FLAG_END,
460 };
461
462 UNUSED static struct flags clone_flags[] = {
463 FLAG_GENERIC(CLONE_VM),
464 FLAG_GENERIC(CLONE_FS),
465 FLAG_GENERIC(CLONE_FILES),
466 FLAG_GENERIC(CLONE_SIGHAND),
467 FLAG_GENERIC(CLONE_PTRACE),
468 FLAG_GENERIC(CLONE_VFORK),
469 FLAG_GENERIC(CLONE_PARENT),
470 FLAG_GENERIC(CLONE_THREAD),
471 FLAG_GENERIC(CLONE_NEWNS),
472 FLAG_GENERIC(CLONE_SYSVSEM),
473 FLAG_GENERIC(CLONE_SETTLS),
474 FLAG_GENERIC(CLONE_PARENT_SETTID),
475 FLAG_GENERIC(CLONE_CHILD_CLEARTID),
476 FLAG_GENERIC(CLONE_DETACHED),
477 FLAG_GENERIC(CLONE_UNTRACED),
478 FLAG_GENERIC(CLONE_CHILD_SETTID),
479 #if defined(CLONE_NEWUTS)
480 FLAG_GENERIC(CLONE_NEWUTS),
481 #endif
482 #if defined(CLONE_NEWIPC)
483 FLAG_GENERIC(CLONE_NEWIPC),
484 #endif
485 #if defined(CLONE_NEWUSER)
486 FLAG_GENERIC(CLONE_NEWUSER),
487 #endif
488 #if defined(CLONE_NEWPID)
489 FLAG_GENERIC(CLONE_NEWPID),
490 #endif
491 #if defined(CLONE_NEWNET)
492 FLAG_GENERIC(CLONE_NEWNET),
493 #endif
494 #if defined(CLONE_IO)
495 FLAG_GENERIC(CLONE_IO),
496 #endif
497 FLAG_END,
498 };
499
500 /*
501 * print_xxx utility functions. These are used to print syscall
502 * parameters in certain format. All of these have parameter
503 * named 'last'. This parameter is used to add comma to output
504 * when last == 0.
505 */
506
507 static const char *
508 get_comma(int last)
509 {
510 return ((last) ? "" : ",");
511 }
512
513 static void
514 print_flags(const struct flags *f, abi_long flags, int last)
515 {
516 const char *sep = "";
517 int n;
518
519 if ((flags == 0) && (f->f_value == 0)) {
520 gemu_log("%s%s", f->f_string, get_comma(last));
521 return;
522 }
523 for (n = 0; f->f_string != NULL; f++) {
524 if ((f->f_value != 0) && ((flags & f->f_value) == f->f_value)) {
525 gemu_log("%s%s", sep, f->f_string);
526 flags &= ~f->f_value;
527 sep = "|";
528 n++;
529 }
530 }
531
532 if (n > 0) {
533 /* print rest of the flags as numeric */
534 if (flags != 0) {
535 gemu_log("%s%#x%s", sep, (unsigned int)flags, get_comma(last));
536 } else {
537 gemu_log("%s", get_comma(last));
538 }
539 } else {
540 /* no string version of flags found, print them in hex then */
541 gemu_log("%#x%s", (unsigned int)flags, get_comma(last));
542 }
543 }
544
545 static void
546 print_at_dirfd(abi_long dirfd, int last)
547 {
548 #ifdef AT_FDCWD
549 if (dirfd == AT_FDCWD) {
550 gemu_log("AT_FDCWD%s", get_comma(last));
551 return;
552 }
553 #endif
554 gemu_log("%d%s", (int)dirfd, get_comma(last));
555 }
556
557 static void
558 print_file_mode(abi_long mode, int last)
559 {
560 const char *sep = "";
561 const struct flags *m;
562
563 for (m = &mode_flags[0]; m->f_string != NULL; m++) {
564 if ((m->f_value & mode) == m->f_value) {
565 gemu_log("%s%s", m->f_string, sep);
566 sep = "|";
567 mode &= ~m->f_value;
568 break;
569 }
570 }
571
572 mode &= ~S_IFMT;
573 /* print rest of the mode as octal */
574 if (mode != 0)
575 gemu_log("%s%#o", sep, (unsigned int)mode);
576
577 gemu_log("%s", get_comma(last));
578 }
579
580 static void
581 print_open_flags(abi_long flags, int last)
582 {
583 print_flags(open_access_flags, flags & TARGET_O_ACCMODE, 1);
584 flags &= ~TARGET_O_ACCMODE;
585 if (flags == 0) {
586 gemu_log("%s", get_comma(last));
587 return;
588 }
589 gemu_log("|");
590 print_flags(open_flags, flags, last);
591 }
592
593 static void
594 print_syscall_prologue(const struct syscallname *sc)
595 {
596 gemu_log("%s(", sc->name);
597 }
598
599 /*ARGSUSED*/
600 static void
601 print_syscall_epilogue(const struct syscallname *sc)
602 {
603 (void)sc;
604 gemu_log(")");
605 }
606
607 static void
608 print_string(abi_long addr, int last)
609 {
610 char *s;
611
612 if ((s = lock_user_string(addr)) != NULL) {
613 gemu_log("\"%s\"%s", s, get_comma(last));
614 unlock_user(s, addr, 0);
615 } else {
616 /* can't get string out of it, so print it as pointer */
617 print_pointer(addr, last);
618 }
619 }
620
621 /*
622 * Prints out raw parameter using given format. Caller needs
623 * to do byte swapping if needed.
624 */
625 static void
626 print_raw_param(const char *fmt, abi_long param, int last)
627 {
628 char format[64];
629
630 (void) snprintf(format, sizeof (format), "%s%s", fmt, get_comma(last));
631 gemu_log(format, param);
632 }
633
634 static void
635 print_pointer(abi_long p, int last)
636 {
637 if (p == 0)
638 gemu_log("NULL%s", get_comma(last));
639 else
640 gemu_log("0x" TARGET_ABI_FMT_lx "%s", p, get_comma(last));
641 }
642
643 /*
644 * Reads 32-bit (int) number from guest address space from
645 * address 'addr' and prints it.
646 */
647 static void
648 print_number(abi_long addr, int last)
649 {
650 if (addr == 0) {
651 gemu_log("NULL%s", get_comma(last));
652 } else {
653 int num;
654
655 get_user_s32(num, addr);
656 gemu_log("[%d]%s", num, get_comma(last));
657 }
658 }
659
660 static void
661 print_timeval(abi_ulong tv_addr, int last)
662 {
663 if( tv_addr ) {
664 struct target_timeval *tv;
665
666 tv = lock_user(VERIFY_READ, tv_addr, sizeof(*tv), 1);
667 if (!tv)
668 return;
669 gemu_log("{" TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld "}%s",
670 tswapal(tv->tv_sec), tswapal(tv->tv_usec), get_comma(last));
671 unlock_user(tv, tv_addr, 0);
672 } else
673 gemu_log("NULL%s", get_comma(last));
674 }
675
676 #undef UNUSED
677
678 #ifdef TARGET_NR_accept
679 static void
680 print_accept(const struct syscallname *name,
681 abi_long arg0, abi_long arg1, abi_long arg2,
682 abi_long arg3, abi_long arg4, abi_long arg5)
683 {
684 print_syscall_prologue(name);
685 print_raw_param("%d", arg0, 0);
686 print_pointer(arg1, 0);
687 print_number(arg2, 1);
688 print_syscall_epilogue(name);
689 }
690 #endif
691
692 #ifdef TARGET_NR_access
693 static void
694 print_access(const struct syscallname *name,
695 abi_long arg0, abi_long arg1, abi_long arg2,
696 abi_long arg3, abi_long arg4, abi_long arg5)
697 {
698 print_syscall_prologue(name);
699 print_string(arg0, 0);
700 print_flags(access_flags, arg1, 1);
701 print_syscall_epilogue(name);
702 }
703 #endif
704
705 #ifdef TARGET_NR_brk
706 static void
707 print_brk(const struct syscallname *name,
708 abi_long arg0, abi_long arg1, abi_long arg2,
709 abi_long arg3, abi_long arg4, abi_long arg5)
710 {
711 print_syscall_prologue(name);
712 print_pointer(arg0, 1);
713 print_syscall_epilogue(name);
714 }
715 #endif
716
717 #ifdef TARGET_NR_chdir
718 static void
719 print_chdir(const struct syscallname *name,
720 abi_long arg0, abi_long arg1, abi_long arg2,
721 abi_long arg3, abi_long arg4, abi_long arg5)
722 {
723 print_syscall_prologue(name);
724 print_string(arg0, 1);
725 print_syscall_epilogue(name);
726 }
727 #endif
728
729 #ifdef TARGET_NR_chmod
730 static void
731 print_chmod(const struct syscallname *name,
732 abi_long arg0, abi_long arg1, abi_long arg2,
733 abi_long arg3, abi_long arg4, abi_long arg5)
734 {
735 print_syscall_prologue(name);
736 print_string(arg0, 0);
737 print_file_mode(arg1, 1);
738 print_syscall_epilogue(name);
739 }
740 #endif
741
742 #ifdef TARGET_NR_clone
743 static void
744 print_clone(const struct syscallname *name,
745 abi_long arg0, abi_long arg1, abi_long arg2,
746 abi_long arg3, abi_long arg4, abi_long arg5)
747 {
748 print_syscall_prologue(name);
749 #if defined(TARGET_M68K)
750 print_flags(clone_flags, arg0, 0);
751 print_raw_param("newsp=0x" TARGET_ABI_FMT_lx, arg1, 1);
752 #elif defined(TARGET_SH4) || defined(TARGET_ALPHA)
753 print_flags(clone_flags, arg0, 0);
754 print_raw_param("child_stack=0x" TARGET_ABI_FMT_lx, arg1, 0);
755 print_raw_param("parent_tidptr=0x" TARGET_ABI_FMT_lx, arg2, 0);
756 print_raw_param("child_tidptr=0x" TARGET_ABI_FMT_lx, arg3, 0);
757 print_raw_param("tls=0x" TARGET_ABI_FMT_lx, arg4, 1);
758 #elif defined(TARGET_CRIS)
759 print_raw_param("child_stack=0x" TARGET_ABI_FMT_lx, arg0, 0);
760 print_flags(clone_flags, arg1, 0);
761 print_raw_param("parent_tidptr=0x" TARGET_ABI_FMT_lx, arg2, 0);
762 print_raw_param("tls=0x" TARGET_ABI_FMT_lx, arg3, 0);
763 print_raw_param("child_tidptr=0x" TARGET_ABI_FMT_lx, arg4, 1);
764 #else
765 print_flags(clone_flags, arg0, 0);
766 print_raw_param("child_stack=0x" TARGET_ABI_FMT_lx, arg1, 0);
767 print_raw_param("parent_tidptr=0x" TARGET_ABI_FMT_lx, arg2, 0);
768 print_raw_param("tls=0x" TARGET_ABI_FMT_lx, arg3, 0);
769 print_raw_param("child_tidptr=0x" TARGET_ABI_FMT_lx, arg4, 1);
770 #endif
771 print_syscall_epilogue(name);
772 }
773 #endif
774
775 #ifdef TARGET_NR_creat
776 static void
777 print_creat(const struct syscallname *name,
778 abi_long arg0, abi_long arg1, abi_long arg2,
779 abi_long arg3, abi_long arg4, abi_long arg5)
780 {
781 print_syscall_prologue(name);
782 print_string(arg0, 0);
783 print_file_mode(arg1, 1);
784 print_syscall_epilogue(name);
785 }
786 #endif
787
788 #ifdef TARGET_NR_execv
789 static void
790 print_execv(const struct syscallname *name,
791 abi_long arg0, abi_long arg1, abi_long arg2,
792 abi_long arg3, abi_long arg4, abi_long arg5)
793 {
794 print_syscall_prologue(name);
795 print_string(arg0, 0);
796 print_raw_param("0x" TARGET_ABI_FMT_lx, arg1, 1);
797 print_syscall_epilogue(name);
798 }
799 #endif
800
801 #ifdef TARGET_NR_faccessat
802 static void
803 print_faccessat(const struct syscallname *name,
804 abi_long arg0, abi_long arg1, abi_long arg2,
805 abi_long arg3, abi_long arg4, abi_long arg5)
806 {
807 print_syscall_prologue(name);
808 print_at_dirfd(arg0, 0);
809 print_string(arg1, 0);
810 print_flags(access_flags, arg2, 0);
811 print_flags(at_file_flags, arg3, 1);
812 print_syscall_epilogue(name);
813 }
814 #endif
815
816 #ifdef TARGET_NR_fchmodat
817 static void
818 print_fchmodat(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_at_dirfd(arg0, 0);
824 print_string(arg1, 0);
825 print_file_mode(arg2, 0);
826 print_flags(at_file_flags, arg3, 1);
827 print_syscall_epilogue(name);
828 }
829 #endif
830
831 #ifdef TARGET_NR_fchownat
832 static void
833 print_fchownat(const struct syscallname *name,
834 abi_long arg0, abi_long arg1, abi_long arg2,
835 abi_long arg3, abi_long arg4, abi_long arg5)
836 {
837 print_syscall_prologue(name);
838 print_at_dirfd(arg0, 0);
839 print_string(arg1, 0);
840 print_raw_param("%d", arg2, 0);
841 print_raw_param("%d", arg3, 0);
842 print_flags(at_file_flags, arg4, 1);
843 print_syscall_epilogue(name);
844 }
845 #endif
846
847 #if defined(TARGET_NR_fcntl) || defined(TARGET_NR_fcntl64)
848 static void
849 print_fcntl(const struct syscallname *name,
850 abi_long arg0, abi_long arg1, abi_long arg2,
851 abi_long arg3, abi_long arg4, abi_long arg5)
852 {
853 print_syscall_prologue(name);
854 print_raw_param("%d", arg0, 0);
855 switch(arg1) {
856 case TARGET_F_DUPFD:
857 gemu_log("F_DUPFD,");
858 print_raw_param(TARGET_ABI_FMT_ld, arg2, 1);
859 break;
860 case TARGET_F_GETFD:
861 gemu_log("F_GETFD");
862 break;
863 case TARGET_F_SETFD:
864 gemu_log("F_SETFD,");
865 print_raw_param(TARGET_ABI_FMT_ld, arg2, 1);
866 break;
867 case TARGET_F_GETFL:
868 gemu_log("F_GETFL");
869 break;
870 case TARGET_F_SETFL:
871 gemu_log("F_SETFL,");
872 print_open_flags(arg2, 1);
873 break;
874 case TARGET_F_GETLK:
875 gemu_log("F_GETLK,");
876 print_pointer(arg2, 1);
877 break;
878 case TARGET_F_SETLK:
879 gemu_log("F_SETLK,");
880 print_pointer(arg2, 1);
881 break;
882 case TARGET_F_SETLKW:
883 gemu_log("F_SETLKW,");
884 print_pointer(arg2, 1);
885 break;
886 case TARGET_F_GETOWN:
887 gemu_log("F_GETOWN");
888 break;
889 case TARGET_F_SETOWN:
890 gemu_log("F_SETOWN,");
891 print_raw_param(TARGET_ABI_FMT_ld, arg2, 0);
892 break;
893 case TARGET_F_GETSIG:
894 gemu_log("F_GETSIG");
895 break;
896 case TARGET_F_SETSIG:
897 gemu_log("F_SETSIG,");
898 print_raw_param(TARGET_ABI_FMT_ld, arg2, 0);
899 break;
900 #if TARGET_ABI_BITS == 32
901 case TARGET_F_GETLK64:
902 gemu_log("F_GETLK64,");
903 print_pointer(arg2, 1);
904 break;
905 case TARGET_F_SETLK64:
906 gemu_log("F_SETLK64,");
907 print_pointer(arg2, 1);
908 break;
909 case TARGET_F_SETLKW64:
910 gemu_log("F_SETLKW64,");
911 print_pointer(arg2, 1);
912 break;
913 #endif
914 case TARGET_F_SETLEASE:
915 gemu_log("F_SETLEASE,");
916 print_raw_param(TARGET_ABI_FMT_ld, arg2, 0);
917 break;
918 case TARGET_F_GETLEASE:
919 gemu_log("F_GETLEASE");
920 break;
921 case TARGET_F_DUPFD_CLOEXEC:
922 gemu_log("F_DUPFD_CLOEXEC,");
923 print_raw_param(TARGET_ABI_FMT_ld, arg2, 1);
924 break;
925 case TARGET_F_NOTIFY:
926 gemu_log("F_NOTIFY,");
927 print_raw_param(TARGET_ABI_FMT_ld, arg2, 0);
928 break;
929 default:
930 print_raw_param(TARGET_ABI_FMT_ld, arg1, 0);
931 print_pointer(arg2, 1);
932 break;
933 }
934 print_syscall_epilogue(name);
935 }
936 #define print_fcntl64 print_fcntl
937 #endif
938
939
940 #ifdef TARGET_NR_futimesat
941 static void
942 print_futimesat(const struct syscallname *name,
943 abi_long arg0, abi_long arg1, abi_long arg2,
944 abi_long arg3, abi_long arg4, abi_long arg5)
945 {
946 print_syscall_prologue(name);
947 print_at_dirfd(arg0, 0);
948 print_string(arg1, 0);
949 print_timeval(arg2, 0);
950 print_timeval(arg2 + sizeof (struct target_timeval), 1);
951 print_syscall_epilogue(name);
952 }
953 #endif
954
955 #ifdef TARGET_NR_link
956 static void
957 print_link(const struct syscallname *name,
958 abi_long arg0, abi_long arg1, abi_long arg2,
959 abi_long arg3, abi_long arg4, abi_long arg5)
960 {
961 print_syscall_prologue(name);
962 print_string(arg0, 0);
963 print_string(arg1, 1);
964 print_syscall_epilogue(name);
965 }
966 #endif
967
968 #ifdef TARGET_NR_linkat
969 static void
970 print_linkat(const struct syscallname *name,
971 abi_long arg0, abi_long arg1, abi_long arg2,
972 abi_long arg3, abi_long arg4, abi_long arg5)
973 {
974 print_syscall_prologue(name);
975 print_at_dirfd(arg0, 0);
976 print_string(arg1, 0);
977 print_at_dirfd(arg2, 0);
978 print_string(arg3, 0);
979 print_flags(at_file_flags, arg4, 1);
980 print_syscall_epilogue(name);
981 }
982 #endif
983
984 #ifdef TARGET_NR__llseek
985 static void
986 print__llseek(const struct syscallname *name,
987 abi_long arg0, abi_long arg1, abi_long arg2,
988 abi_long arg3, abi_long arg4, abi_long arg5)
989 {
990 const char *whence = "UNKNOWN";
991 print_syscall_prologue(name);
992 print_raw_param("%d", arg0, 0);
993 print_raw_param("%ld", arg1, 0);
994 print_raw_param("%ld", arg2, 0);
995 print_pointer(arg3, 0);
996 switch(arg4) {
997 case SEEK_SET: whence = "SEEK_SET"; break;
998 case SEEK_CUR: whence = "SEEK_CUR"; break;
999 case SEEK_END: whence = "SEEK_END"; break;
1000 }
1001 gemu_log("%s",whence);
1002 print_syscall_epilogue(name);
1003 }
1004 #endif
1005
1006 #if defined(TARGET_NR_stat) || defined(TARGET_NR_stat64) || \
1007 defined(TARGET_NR_lstat) || defined(TARGET_NR_lstat64)
1008 static void
1009 print_stat(const struct syscallname *name,
1010 abi_long arg0, abi_long arg1, abi_long arg2,
1011 abi_long arg3, abi_long arg4, abi_long arg5)
1012 {
1013 print_syscall_prologue(name);
1014 print_string(arg0, 0);
1015 print_pointer(arg1, 1);
1016 print_syscall_epilogue(name);
1017 }
1018 #define print_lstat print_stat
1019 #define print_stat64 print_stat
1020 #define print_lstat64 print_stat
1021 #endif
1022
1023 #if defined(TARGET_NR_fstat) || defined(TARGET_NR_fstat64)
1024 static void
1025 print_fstat(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_raw_param("%d", arg0, 0);
1031 print_pointer(arg1, 1);
1032 print_syscall_epilogue(name);
1033 }
1034 #define print_fstat64 print_fstat
1035 #endif
1036
1037 #ifdef TARGET_NR_mkdir
1038 static void
1039 print_mkdir(const struct syscallname *name,
1040 abi_long arg0, abi_long arg1, abi_long arg2,
1041 abi_long arg3, abi_long arg4, abi_long arg5)
1042 {
1043 print_syscall_prologue(name);
1044 print_string(arg0, 0);
1045 print_file_mode(arg1, 1);
1046 print_syscall_epilogue(name);
1047 }
1048 #endif
1049
1050 #ifdef TARGET_NR_mkdirat
1051 static void
1052 print_mkdirat(const struct syscallname *name,
1053 abi_long arg0, abi_long arg1, abi_long arg2,
1054 abi_long arg3, abi_long arg4, abi_long arg5)
1055 {
1056 print_syscall_prologue(name);
1057 print_at_dirfd(arg0, 0);
1058 print_string(arg1, 0);
1059 print_file_mode(arg2, 1);
1060 print_syscall_epilogue(name);
1061 }
1062 #endif
1063
1064 #ifdef TARGET_NR_rmdir
1065 static void
1066 print_rmdir(const struct syscallname *name,
1067 abi_long arg0, abi_long arg1, abi_long arg2,
1068 abi_long arg3, abi_long arg4, abi_long arg5)
1069 {
1070 print_syscall_prologue(name);
1071 print_string(arg0, 0);
1072 print_syscall_epilogue(name);
1073 }
1074 #endif
1075
1076 #ifdef TARGET_NR_rt_sigaction
1077 static void
1078 print_rt_sigaction(const struct syscallname *name,
1079 abi_long arg0, abi_long arg1, abi_long arg2,
1080 abi_long arg3, abi_long arg4, abi_long arg5)
1081 {
1082 print_syscall_prologue(name);
1083 print_signal(arg0, 0);
1084 print_pointer(arg1, 0);
1085 print_pointer(arg2, 1);
1086 print_syscall_epilogue(name);
1087 }
1088 #endif
1089
1090 #ifdef TARGET_NR_rt_sigprocmask
1091 static void
1092 print_rt_sigprocmask(const struct syscallname *name,
1093 abi_long arg0, abi_long arg1, abi_long arg2,
1094 abi_long arg3, abi_long arg4, abi_long arg5)
1095 {
1096 const char *how = "UNKNOWN";
1097 print_syscall_prologue(name);
1098 switch(arg0) {
1099 case TARGET_SIG_BLOCK: how = "SIG_BLOCK"; break;
1100 case TARGET_SIG_UNBLOCK: how = "SIG_UNBLOCK"; break;
1101 case TARGET_SIG_SETMASK: how = "SIG_SETMASK"; break;
1102 }
1103 gemu_log("%s,",how);
1104 print_pointer(arg1, 0);
1105 print_pointer(arg2, 1);
1106 print_syscall_epilogue(name);
1107 }
1108 #endif
1109
1110 #ifdef TARGET_NR_mknod
1111 static void
1112 print_mknod(const struct syscallname *name,
1113 abi_long arg0, abi_long arg1, abi_long arg2,
1114 abi_long arg3, abi_long arg4, abi_long arg5)
1115 {
1116 int hasdev = (arg1 & (S_IFCHR|S_IFBLK));
1117
1118 print_syscall_prologue(name);
1119 print_string(arg0, 0);
1120 print_file_mode(arg1, (hasdev == 0));
1121 if (hasdev) {
1122 print_raw_param("makedev(%d", major(arg2), 0);
1123 print_raw_param("%d)", minor(arg2), 1);
1124 }
1125 print_syscall_epilogue(name);
1126 }
1127 #endif
1128
1129 #ifdef TARGET_NR_mknodat
1130 static void
1131 print_mknodat(const struct syscallname *name,
1132 abi_long arg0, abi_long arg1, abi_long arg2,
1133 abi_long arg3, abi_long arg4, abi_long arg5)
1134 {
1135 int hasdev = (arg2 & (S_IFCHR|S_IFBLK));
1136
1137 print_syscall_prologue(name);
1138 print_at_dirfd(arg0, 0);
1139 print_string(arg1, 0);
1140 print_file_mode(arg2, (hasdev == 0));
1141 if (hasdev) {
1142 print_raw_param("makedev(%d", major(arg3), 0);
1143 print_raw_param("%d)", minor(arg3), 1);
1144 }
1145 print_syscall_epilogue(name);
1146 }
1147 #endif
1148
1149 #ifdef TARGET_NR_mq_open
1150 static void
1151 print_mq_open(const struct syscallname *name,
1152 abi_long arg0, abi_long arg1, abi_long arg2,
1153 abi_long arg3, abi_long arg4, abi_long arg5)
1154 {
1155 int is_creat = (arg1 & TARGET_O_CREAT);
1156
1157 print_syscall_prologue(name);
1158 print_string(arg0, 0);
1159 print_open_flags(arg1, (is_creat == 0));
1160 if (is_creat) {
1161 print_file_mode(arg2, 0);
1162 print_pointer(arg3, 1);
1163 }
1164 print_syscall_epilogue(name);
1165 }
1166 #endif
1167
1168 #ifdef TARGET_NR_open
1169 static void
1170 print_open(const struct syscallname *name,
1171 abi_long arg0, abi_long arg1, abi_long arg2,
1172 abi_long arg3, abi_long arg4, abi_long arg5)
1173 {
1174 int is_creat = (arg1 & TARGET_O_CREAT);
1175
1176 print_syscall_prologue(name);
1177 print_string(arg0, 0);
1178 print_open_flags(arg1, (is_creat == 0));
1179 if (is_creat)
1180 print_file_mode(arg2, 1);
1181 print_syscall_epilogue(name);
1182 }
1183 #endif
1184
1185 #ifdef TARGET_NR_openat
1186 static void
1187 print_openat(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 int is_creat = (arg2 & TARGET_O_CREAT);
1192
1193 print_syscall_prologue(name);
1194 print_at_dirfd(arg0, 0);
1195 print_string(arg1, 0);
1196 print_open_flags(arg2, (is_creat == 0));
1197 if (is_creat)
1198 print_file_mode(arg3, 1);
1199 print_syscall_epilogue(name);
1200 }
1201 #endif
1202
1203 #ifdef TARGET_NR_mq_unlink
1204 static void
1205 print_mq_unlink(const struct syscallname *name,
1206 abi_long arg0, abi_long arg1, abi_long arg2,
1207 abi_long arg3, abi_long arg4, abi_long arg5)
1208 {
1209 print_syscall_prologue(name);
1210 print_string(arg0, 1);
1211 print_syscall_epilogue(name);
1212 }
1213 #endif
1214
1215 #if defined(TARGET_NR_fstatat64) || defined(TARGET_NR_newfstatat)
1216 static void
1217 print_fstatat64(const struct syscallname *name,
1218 abi_long arg0, abi_long arg1, abi_long arg2,
1219 abi_long arg3, abi_long arg4, abi_long arg5)
1220 {
1221 print_syscall_prologue(name);
1222 print_at_dirfd(arg0, 0);
1223 print_string(arg1, 0);
1224 print_pointer(arg2, 0);
1225 print_flags(at_file_flags, arg3, 1);
1226 print_syscall_epilogue(name);
1227 }
1228 #define print_newfstatat print_fstatat64
1229 #endif
1230
1231 #ifdef TARGET_NR_readlink
1232 static void
1233 print_readlink(const struct syscallname *name,
1234 abi_long arg0, abi_long arg1, abi_long arg2,
1235 abi_long arg3, abi_long arg4, abi_long arg5)
1236 {
1237 print_syscall_prologue(name);
1238 print_string(arg0, 0);
1239 print_pointer(arg1, 0);
1240 print_raw_param("%u", arg2, 1);
1241 print_syscall_epilogue(name);
1242 }
1243 #endif
1244
1245 #ifdef TARGET_NR_readlinkat
1246 static void
1247 print_readlinkat(const struct syscallname *name,
1248 abi_long arg0, abi_long arg1, abi_long arg2,
1249 abi_long arg3, abi_long arg4, abi_long arg5)
1250 {
1251 print_syscall_prologue(name);
1252 print_at_dirfd(arg0, 0);
1253 print_string(arg1, 0);
1254 print_pointer(arg2, 0);
1255 print_raw_param("%u", arg3, 1);
1256 print_syscall_epilogue(name);
1257 }
1258 #endif
1259
1260 #ifdef TARGET_NR_rename
1261 static void
1262 print_rename(const struct syscallname *name,
1263 abi_long arg0, abi_long arg1, abi_long arg2,
1264 abi_long arg3, abi_long arg4, abi_long arg5)
1265 {
1266 print_syscall_prologue(name);
1267 print_string(arg0, 0);
1268 print_string(arg1, 1);
1269 print_syscall_epilogue(name);
1270 }
1271 #endif
1272
1273 #ifdef TARGET_NR_renameat
1274 static void
1275 print_renameat(const struct syscallname *name,
1276 abi_long arg0, abi_long arg1, abi_long arg2,
1277 abi_long arg3, abi_long arg4, abi_long arg5)
1278 {
1279 print_syscall_prologue(name);
1280 print_at_dirfd(arg0, 0);
1281 print_string(arg1, 0);
1282 print_at_dirfd(arg2, 0);
1283 print_string(arg3, 1);
1284 print_syscall_epilogue(name);
1285 }
1286 #endif
1287
1288 #ifdef TARGET_NR_statfs
1289 static void
1290 print_statfs(const struct syscallname *name,
1291 abi_long arg0, abi_long arg1, abi_long arg2,
1292 abi_long arg3, abi_long arg4, abi_long arg5)
1293 {
1294 print_syscall_prologue(name);
1295 print_string(arg0, 0);
1296 print_pointer(arg1, 1);
1297 print_syscall_epilogue(name);
1298 }
1299 #define print_statfs64 print_statfs
1300 #endif
1301
1302 #ifdef TARGET_NR_symlink
1303 static void
1304 print_symlink(const struct syscallname *name,
1305 abi_long arg0, abi_long arg1, abi_long arg2,
1306 abi_long arg3, abi_long arg4, abi_long arg5)
1307 {
1308 print_syscall_prologue(name);
1309 print_string(arg0, 0);
1310 print_string(arg1, 1);
1311 print_syscall_epilogue(name);
1312 }
1313 #endif
1314
1315 #ifdef TARGET_NR_symlinkat
1316 static void
1317 print_symlinkat(const struct syscallname *name,
1318 abi_long arg0, abi_long arg1, abi_long arg2,
1319 abi_long arg3, abi_long arg4, abi_long arg5)
1320 {
1321 print_syscall_prologue(name);
1322 print_string(arg0, 0);
1323 print_at_dirfd(arg1, 0);
1324 print_string(arg2, 1);
1325 print_syscall_epilogue(name);
1326 }
1327 #endif
1328
1329 #ifdef TARGET_NR_mount
1330 static void
1331 print_mount(const struct syscallname *name,
1332 abi_long arg0, abi_long arg1, abi_long arg2,
1333 abi_long arg3, abi_long arg4, abi_long arg5)
1334 {
1335 print_syscall_prologue(name);
1336 print_string(arg0, 0);
1337 print_string(arg1, 0);
1338 print_string(arg2, 0);
1339 print_flags(mount_flags, arg3, 0);
1340 print_pointer(arg4, 1);
1341 print_syscall_epilogue(name);
1342 }
1343 #endif
1344
1345 #ifdef TARGET_NR_umount
1346 static void
1347 print_umount(const struct syscallname *name,
1348 abi_long arg0, abi_long arg1, abi_long arg2,
1349 abi_long arg3, abi_long arg4, abi_long arg5)
1350 {
1351 print_syscall_prologue(name);
1352 print_string(arg0, 1);
1353 print_syscall_epilogue(name);
1354 }
1355 #endif
1356
1357 #ifdef TARGET_NR_umount2
1358 static void
1359 print_umount2(const struct syscallname *name,
1360 abi_long arg0, abi_long arg1, abi_long arg2,
1361 abi_long arg3, abi_long arg4, abi_long arg5)
1362 {
1363 print_syscall_prologue(name);
1364 print_string(arg0, 0);
1365 print_flags(umount2_flags, arg1, 1);
1366 print_syscall_epilogue(name);
1367 }
1368 #endif
1369
1370 #ifdef TARGET_NR_unlink
1371 static void
1372 print_unlink(const struct syscallname *name,
1373 abi_long arg0, abi_long arg1, abi_long arg2,
1374 abi_long arg3, abi_long arg4, abi_long arg5)
1375 {
1376 print_syscall_prologue(name);
1377 print_string(arg0, 1);
1378 print_syscall_epilogue(name);
1379 }
1380 #endif
1381
1382 #ifdef TARGET_NR_unlinkat
1383 static void
1384 print_unlinkat(const struct syscallname *name,
1385 abi_long arg0, abi_long arg1, abi_long arg2,
1386 abi_long arg3, abi_long arg4, abi_long arg5)
1387 {
1388 print_syscall_prologue(name);
1389 print_at_dirfd(arg0, 0);
1390 print_string(arg1, 0);
1391 print_flags(unlinkat_flags, arg2, 1);
1392 print_syscall_epilogue(name);
1393 }
1394 #endif
1395
1396 #ifdef TARGET_NR_utime
1397 static void
1398 print_utime(const struct syscallname *name,
1399 abi_long arg0, abi_long arg1, abi_long arg2,
1400 abi_long arg3, abi_long arg4, abi_long arg5)
1401 {
1402 print_syscall_prologue(name);
1403 print_string(arg0, 0);
1404 print_pointer(arg1, 1);
1405 print_syscall_epilogue(name);
1406 }
1407 #endif
1408
1409 #ifdef TARGET_NR_utimes
1410 static void
1411 print_utimes(const struct syscallname *name,
1412 abi_long arg0, abi_long arg1, abi_long arg2,
1413 abi_long arg3, abi_long arg4, abi_long arg5)
1414 {
1415 print_syscall_prologue(name);
1416 print_string(arg0, 0);
1417 print_pointer(arg1, 1);
1418 print_syscall_epilogue(name);
1419 }
1420 #endif
1421
1422 #ifdef TARGET_NR_utimensat
1423 static void
1424 print_utimensat(const struct syscallname *name,
1425 abi_long arg0, abi_long arg1, abi_long arg2,
1426 abi_long arg3, abi_long arg4, abi_long arg5)
1427 {
1428 print_syscall_prologue(name);
1429 print_at_dirfd(arg0, 0);
1430 print_string(arg1, 0);
1431 print_pointer(arg2, 0);
1432 print_flags(at_file_flags, arg3, 1);
1433 print_syscall_epilogue(name);
1434 }
1435 #endif
1436
1437 #if defined(TARGET_NR_mmap) || defined(TARGET_NR_mmap2)
1438 static void
1439 print_mmap(const struct syscallname *name,
1440 abi_long arg0, abi_long arg1, abi_long arg2,
1441 abi_long arg3, abi_long arg4, abi_long arg5)
1442 {
1443 print_syscall_prologue(name);
1444 print_pointer(arg0, 0);
1445 print_raw_param("%d", arg1, 0);
1446 print_flags(mmap_prot_flags, arg2, 0);
1447 print_flags(mmap_flags, arg3, 0);
1448 print_raw_param("%d", arg4, 0);
1449 print_raw_param("%#x", arg5, 1);
1450 print_syscall_epilogue(name);
1451 }
1452 #define print_mmap2 print_mmap
1453 #endif
1454
1455 #ifdef TARGET_NR_mprotect
1456 static void
1457 print_mprotect(const struct syscallname *name,
1458 abi_long arg0, abi_long arg1, abi_long arg2,
1459 abi_long arg3, abi_long arg4, abi_long arg5)
1460 {
1461 print_syscall_prologue(name);
1462 print_pointer(arg0, 0);
1463 print_raw_param("%d", arg1, 0);
1464 print_flags(mmap_prot_flags, arg2, 1);
1465 print_syscall_epilogue(name);
1466 }
1467 #endif
1468
1469 #ifdef TARGET_NR_munmap
1470 static void
1471 print_munmap(const struct syscallname *name,
1472 abi_long arg0, abi_long arg1, abi_long arg2,
1473 abi_long arg3, abi_long arg4, abi_long arg5)
1474 {
1475 print_syscall_prologue(name);
1476 print_pointer(arg0, 0);
1477 print_raw_param("%d", arg1, 1);
1478 print_syscall_epilogue(name);
1479 }
1480 #endif
1481
1482 #ifdef TARGET_NR_futex
1483 static void print_futex_op(abi_long tflag, int last)
1484 {
1485 #define print_op(val) \
1486 if( cmd == val ) { \
1487 gemu_log(#val); \
1488 return; \
1489 }
1490
1491 int cmd = (int)tflag;
1492 #ifdef FUTEX_PRIVATE_FLAG
1493 if (cmd & FUTEX_PRIVATE_FLAG) {
1494 gemu_log("FUTEX_PRIVATE_FLAG|");
1495 cmd &= ~FUTEX_PRIVATE_FLAG;
1496 }
1497 #endif
1498 #ifdef FUTEX_CLOCK_REALTIME
1499 if (cmd & FUTEX_CLOCK_REALTIME) {
1500 gemu_log("FUTEX_CLOCK_REALTIME|");
1501 cmd &= ~FUTEX_CLOCK_REALTIME;
1502 }
1503 #endif
1504 print_op(FUTEX_WAIT)
1505 print_op(FUTEX_WAKE)
1506 print_op(FUTEX_FD)
1507 print_op(FUTEX_REQUEUE)
1508 print_op(FUTEX_CMP_REQUEUE)
1509 print_op(FUTEX_WAKE_OP)
1510 print_op(FUTEX_LOCK_PI)
1511 print_op(FUTEX_UNLOCK_PI)
1512 print_op(FUTEX_TRYLOCK_PI)
1513 #ifdef FUTEX_WAIT_BITSET
1514 print_op(FUTEX_WAIT_BITSET)
1515 #endif
1516 #ifdef FUTEX_WAKE_BITSET
1517 print_op(FUTEX_WAKE_BITSET)
1518 #endif
1519 /* unknown values */
1520 gemu_log("%d",cmd);
1521 }
1522
1523 static void
1524 print_futex(const struct syscallname *name,
1525 abi_long arg0, abi_long arg1, abi_long arg2,
1526 abi_long arg3, abi_long arg4, abi_long arg5)
1527 {
1528 print_syscall_prologue(name);
1529 print_pointer(arg0, 0);
1530 print_futex_op(arg1, 0);
1531 print_raw_param(",%d", arg2, 0);
1532 print_pointer(arg3, 0); /* struct timespec */
1533 print_pointer(arg4, 0);
1534 print_raw_param("%d", arg4, 1);
1535 print_syscall_epilogue(name);
1536 }
1537 #endif
1538
1539 #ifdef TARGET_NR_kill
1540 static void
1541 print_kill(const struct syscallname *name,
1542 abi_long arg0, abi_long arg1, abi_long arg2,
1543 abi_long arg3, abi_long arg4, abi_long arg5)
1544 {
1545 print_syscall_prologue(name);
1546 print_raw_param("%d", arg0, 0);
1547 print_signal(arg1, 1);
1548 print_syscall_epilogue(name);
1549 }
1550 #endif
1551
1552 /*
1553 * An array of all of the syscalls we know about
1554 */
1555
1556 static const struct syscallname scnames[] = {
1557 #include "strace.list"
1558 };
1559
1560 static int nsyscalls = ARRAY_SIZE(scnames);
1561
1562 /*
1563 * The public interface to this module.
1564 */
1565 void
1566 print_syscall(int num,
1567 abi_long arg1, abi_long arg2, abi_long arg3,
1568 abi_long arg4, abi_long arg5, abi_long arg6)
1569 {
1570 int i;
1571 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 ")";
1572
1573 gemu_log("%d ", getpid() );
1574
1575 for(i=0;i<nsyscalls;i++)
1576 if( scnames[i].nr == num ) {
1577 if( scnames[i].call != NULL ) {
1578 scnames[i].call(&scnames[i],arg1,arg2,arg3,arg4,arg5,arg6);
1579 } else {
1580 /* XXX: this format system is broken because it uses
1581 host types and host pointers for strings */
1582 if( scnames[i].format != NULL )
1583 format = scnames[i].format;
1584 gemu_log(format,scnames[i].name, arg1,arg2,arg3,arg4,arg5,arg6);
1585 }
1586 return;
1587 }
1588 gemu_log("Unknown syscall %d\n", num);
1589 }
1590
1591
1592 void
1593 print_syscall_ret(int num, abi_long ret)
1594 {
1595 int i;
1596 const char *errstr = NULL;
1597
1598 for(i=0;i<nsyscalls;i++)
1599 if( scnames[i].nr == num ) {
1600 if( scnames[i].result != NULL ) {
1601 scnames[i].result(&scnames[i],ret);
1602 } else {
1603 if (ret < 0) {
1604 errstr = target_strerror(-ret);
1605 }
1606 if (errstr) {
1607 gemu_log(" = -1 errno=" TARGET_ABI_FMT_ld " (%s)\n",
1608 -ret, errstr);
1609 } else {
1610 gemu_log(" = " TARGET_ABI_FMT_ld "\n", ret);
1611 }
1612 }
1613 break;
1614 }
1615 }