-
Notifications
You must be signed in to change notification settings - Fork 0
/
strace.c
1618 lines (1485 loc) · 41 KB
/
strace.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include <stdio.h>
#include <sys/ipc.h>
#include <sys/msg.h>
#include <sys/sem.h>
#include <sys/shm.h>
#include <sys/select.h>
#include <sys/types.h>
#include <sys/mount.h>
#include <sys/mman.h>
#include <unistd.h>
#include <sched.h>
#include "qemu.h"
int do_strace=0;
struct syscallname {
int nr;
const char *name;
const char *format;
void (*call)(const struct syscallname *,
abi_long, abi_long, abi_long,
abi_long, abi_long, abi_long);
void (*result)(const struct syscallname *, abi_long);
};
#ifdef __GNUC__
/*
* It is possible that target doesn't have syscall that uses
* following flags but we don't want the compiler to warn
* us about them being unused. Same applies to utility print
* functions. It is ok to keep them while not used.
*/
#define UNUSED __attribute__ ((unused))
#else
#define UNUSED
#endif
/*
* Structure used to translate flag values into strings. This is
* similar that is in the actual strace tool.
*/
struct flags {
abi_long f_value; /* flag */
const char *f_string; /* stringified flag */
};
/* common flags for all architectures */
#define FLAG_GENERIC(name) { name, #name }
/* target specific flags (syscall_defs.h has TARGET_<flag>) */
#define FLAG_TARGET(name) { TARGET_ ## name, #name }
/* end of flags array */
#define FLAG_END { 0, NULL }
UNUSED static const char *get_comma(int);
UNUSED static void print_pointer(abi_long, int);
UNUSED static void print_flags(const struct flags *, abi_long, int);
UNUSED static void print_at_dirfd(abi_long, int);
UNUSED static void print_file_mode(abi_long, int);
UNUSED static void print_open_flags(abi_long, int);
UNUSED static void print_syscall_prologue(const struct syscallname *);
UNUSED static void print_syscall_epilogue(const struct syscallname *);
UNUSED static void print_string(abi_long, int);
UNUSED static void print_raw_param(const char *, abi_long, int);
UNUSED static void print_timeval(abi_ulong, int);
UNUSED static void print_number(abi_long, int);
UNUSED static void print_signal(abi_ulong, int);
/*
* Utility functions
*/
static void
print_ipc_cmd(int cmd)
{
#define output_cmd(val) \
if( cmd == val ) { \
gemu_log(#val); \
return; \
}
cmd &= 0xff;
/* General IPC commands */
output_cmd( IPC_RMID );
output_cmd( IPC_SET );
output_cmd( IPC_STAT );
output_cmd( IPC_INFO );
/* msgctl() commands */
#ifdef __USER_MISC
output_cmd( MSG_STAT );
output_cmd( MSG_INFO );
#endif
/* shmctl() commands */
output_cmd( SHM_LOCK );
output_cmd( SHM_UNLOCK );
output_cmd( SHM_STAT );
output_cmd( SHM_INFO );
/* semctl() commands */
output_cmd( GETPID );
output_cmd( GETVAL );
output_cmd( GETALL );
output_cmd( GETNCNT );
output_cmd( GETZCNT );
output_cmd( SETVAL );
output_cmd( SETALL );
output_cmd( SEM_STAT );
output_cmd( SEM_INFO );
output_cmd( IPC_RMID );
output_cmd( IPC_RMID );
output_cmd( IPC_RMID );
output_cmd( IPC_RMID );
output_cmd( IPC_RMID );
output_cmd( IPC_RMID );
output_cmd( IPC_RMID );
output_cmd( IPC_RMID );
output_cmd( IPC_RMID );
/* Some value we don't recognize */
gemu_log("%d",cmd);
}
static void
print_signal(abi_ulong arg, int last)
{
const char *signal_name = NULL;
switch(arg) {
case TARGET_SIGHUP: signal_name = "SIGHUP"; break;
case TARGET_SIGINT: signal_name = "SIGINT"; break;
case TARGET_SIGQUIT: signal_name = "SIGQUIT"; break;
case TARGET_SIGILL: signal_name = "SIGILL"; break;
case TARGET_SIGABRT: signal_name = "SIGABRT"; break;
case TARGET_SIGFPE: signal_name = "SIGFPE"; break;
case TARGET_SIGKILL: signal_name = "SIGKILL"; break;
case TARGET_SIGSEGV: signal_name = "SIGSEGV"; break;
case TARGET_SIGPIPE: signal_name = "SIGPIPE"; break;
case TARGET_SIGALRM: signal_name = "SIGALRM"; break;
case TARGET_SIGTERM: signal_name = "SIGTERM"; break;
case TARGET_SIGUSR1: signal_name = "SIGUSR1"; break;
case TARGET_SIGUSR2: signal_name = "SIGUSR2"; break;
case TARGET_SIGCHLD: signal_name = "SIGCHLD"; break;
case TARGET_SIGCONT: signal_name = "SIGCONT"; break;
case TARGET_SIGSTOP: signal_name = "SIGSTOP"; break;
case TARGET_SIGTTIN: signal_name = "SIGTTIN"; break;
case TARGET_SIGTTOU: signal_name = "SIGTTOU"; break;
}
if (signal_name == NULL) {
print_raw_param("%ld", arg, last);
return;
}
gemu_log("%s%s", signal_name, get_comma(last));
}
#ifdef TARGET_NR__newselect
static void
print_fdset(int n, abi_ulong target_fds_addr)
{
int i;
gemu_log("[");
if( target_fds_addr ) {
abi_long *target_fds;
target_fds = lock_user(VERIFY_READ,
target_fds_addr,
sizeof(*target_fds)*(n / TARGET_ABI_BITS + 1),
1);
if (!target_fds)
return;
for (i=n; i>=0; i--) {
if ((tswapal(target_fds[i / TARGET_ABI_BITS]) >> (i & (TARGET_ABI_BITS - 1))) & 1)
gemu_log("%d,", i );
}
unlock_user(target_fds, target_fds_addr, 0);
}
gemu_log("]");
}
#endif
/*
* Sysycall specific output functions
*/
/* select */
#ifdef TARGET_NR__newselect
static long newselect_arg1 = 0;
static long newselect_arg2 = 0;
static long newselect_arg3 = 0;
static long newselect_arg4 = 0;
static long newselect_arg5 = 0;
static void
print_newselect(const struct syscallname *name,
abi_long arg1, abi_long arg2, abi_long arg3,
abi_long arg4, abi_long arg5, abi_long arg6)
{
gemu_log("%s(" TARGET_ABI_FMT_ld ",", name->name, arg1);
print_fdset(arg1, arg2);
gemu_log(",");
print_fdset(arg1, arg3);
gemu_log(",");
print_fdset(arg1, arg4);
gemu_log(",");
print_timeval(arg5, 1);
gemu_log(")");
/* save for use in the return output function below */
newselect_arg1=arg1;
newselect_arg2=arg2;
newselect_arg3=arg3;
newselect_arg4=arg4;
newselect_arg5=arg5;
}
#endif
#ifdef TARGET_NR_semctl
static void
print_semctl(const struct syscallname *name,
abi_long arg1, abi_long arg2, abi_long arg3,
abi_long arg4, abi_long arg5, abi_long arg6)
{
gemu_log("%s(" TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld ",", name->name, arg1, arg2);
print_ipc_cmd(arg3);
gemu_log(",0x" TARGET_ABI_FMT_lx ")", arg4);
}
#endif
static void
print_execve(const struct syscallname *name,
abi_long arg1, abi_long arg2, abi_long arg3,
abi_long arg4, abi_long arg5, abi_long arg6)
{
abi_ulong arg_ptr_addr;
char *s;
if (!(s = lock_user_string(arg1)))
return;
gemu_log("%s(\"%s\",{", name->name, s);
unlock_user(s, arg1, 0);
for (arg_ptr_addr = arg2; ; arg_ptr_addr += sizeof(abi_ulong)) {
abi_ulong *arg_ptr, arg_addr;
arg_ptr = lock_user(VERIFY_READ, arg_ptr_addr, sizeof(abi_ulong), 1);
if (!arg_ptr)
return;
arg_addr = tswapal(*arg_ptr);
unlock_user(arg_ptr, arg_ptr_addr, 0);
if (!arg_addr)
break;
if ((s = lock_user_string(arg_addr))) {
gemu_log("\"%s\",", s);
unlock_user(s, arg_addr, 0);
}
}
gemu_log("NULL})");
}
#ifdef TARGET_NR_ipc
static void
print_ipc(const struct syscallname *name,
abi_long arg1, abi_long arg2, abi_long arg3,
abi_long arg4, abi_long arg5, abi_long arg6)
{
switch(arg1) {
case IPCOP_semctl:
gemu_log("semctl(" TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld ",", arg1, arg2);
print_ipc_cmd(arg3);
gemu_log(",0x" TARGET_ABI_FMT_lx ")", arg4);
break;
default:
gemu_log("%s(" TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld ")",
name->name, arg1, arg2, arg3, arg4);
}
}
#endif
/*
* Variants for the return value output function
*/
static void
print_syscall_ret_addr(const struct syscallname *name, abi_long ret)
{
char *errstr = NULL;
if (ret < 0) {
errstr = target_strerror(-ret);
}
if (errstr) {
gemu_log(" = -1 errno=%d (%s)\n", (int)-ret, errstr);
} else {
gemu_log(" = 0x" TARGET_ABI_FMT_lx "\n", ret);
}
}
#if 0 /* currently unused */
static void
print_syscall_ret_raw(struct syscallname *name, abi_long ret)
{
gemu_log(" = 0x" TARGET_ABI_FMT_lx "\n", ret);
}
#endif
#ifdef TARGET_NR__newselect
static void
print_syscall_ret_newselect(const struct syscallname *name, abi_long ret)
{
gemu_log(" = 0x" TARGET_ABI_FMT_lx " (", ret);
print_fdset(newselect_arg1,newselect_arg2);
gemu_log(",");
print_fdset(newselect_arg1,newselect_arg3);
gemu_log(",");
print_fdset(newselect_arg1,newselect_arg4);
gemu_log(",");
print_timeval(newselect_arg5, 1);
gemu_log(")\n");
}
#endif
UNUSED static struct flags access_flags[] = {
FLAG_GENERIC(F_OK),
FLAG_GENERIC(R_OK),
FLAG_GENERIC(W_OK),
FLAG_GENERIC(X_OK),
FLAG_END,
};
UNUSED static struct flags at_file_flags[] = {
#ifdef AT_EACCESS
FLAG_GENERIC(AT_EACCESS),
#endif
#ifdef AT_SYMLINK_NOFOLLOW
FLAG_GENERIC(AT_SYMLINK_NOFOLLOW),
#endif
FLAG_END,
};
UNUSED static struct flags unlinkat_flags[] = {
#ifdef AT_REMOVEDIR
FLAG_GENERIC(AT_REMOVEDIR),
#endif
FLAG_END,
};
UNUSED static struct flags mode_flags[] = {
FLAG_GENERIC(S_IFSOCK),
FLAG_GENERIC(S_IFLNK),
FLAG_GENERIC(S_IFREG),
FLAG_GENERIC(S_IFBLK),
FLAG_GENERIC(S_IFDIR),
FLAG_GENERIC(S_IFCHR),
FLAG_GENERIC(S_IFIFO),
FLAG_END,
};
UNUSED static struct flags open_access_flags[] = {
FLAG_TARGET(O_RDONLY),
FLAG_TARGET(O_WRONLY),
FLAG_TARGET(O_RDWR),
FLAG_END,
};
UNUSED static struct flags open_flags[] = {
FLAG_TARGET(O_APPEND),
FLAG_TARGET(O_CREAT),
FLAG_TARGET(O_DIRECTORY),
FLAG_TARGET(O_EXCL),
FLAG_TARGET(O_LARGEFILE),
FLAG_TARGET(O_NOCTTY),
FLAG_TARGET(O_NOFOLLOW),
FLAG_TARGET(O_NONBLOCK), /* also O_NDELAY */
FLAG_TARGET(O_DSYNC),
FLAG_TARGET(__O_SYNC),
FLAG_TARGET(O_TRUNC),
#ifdef O_DIRECT
FLAG_TARGET(O_DIRECT),
#endif
#ifdef O_NOATIME
FLAG_TARGET(O_NOATIME),
#endif
#ifdef O_CLOEXEC
FLAG_TARGET(O_CLOEXEC),
#endif
#ifdef O_PATH
FLAG_TARGET(O_PATH),
#endif
FLAG_END,
};
UNUSED static struct flags mount_flags[] = {
#ifdef MS_BIND
FLAG_GENERIC(MS_BIND),
#endif
#ifdef MS_DIRSYNC
FLAG_GENERIC(MS_DIRSYNC),
#endif
FLAG_GENERIC(MS_MANDLOCK),
#ifdef MS_MOVE
FLAG_GENERIC(MS_MOVE),
#endif
FLAG_GENERIC(MS_NOATIME),
FLAG_GENERIC(MS_NODEV),
FLAG_GENERIC(MS_NODIRATIME),
FLAG_GENERIC(MS_NOEXEC),
FLAG_GENERIC(MS_NOSUID),
FLAG_GENERIC(MS_RDONLY),
#ifdef MS_RELATIME
FLAG_GENERIC(MS_RELATIME),
#endif
FLAG_GENERIC(MS_REMOUNT),
FLAG_GENERIC(MS_SYNCHRONOUS),
FLAG_END,
};
UNUSED static struct flags umount2_flags[] = {
#ifdef MNT_FORCE
FLAG_GENERIC(MNT_FORCE),
#endif
#ifdef MNT_DETACH
FLAG_GENERIC(MNT_DETACH),
#endif
#ifdef MNT_EXPIRE
FLAG_GENERIC(MNT_EXPIRE),
#endif
FLAG_END,
};
UNUSED static struct flags mmap_prot_flags[] = {
FLAG_GENERIC(PROT_NONE),
FLAG_GENERIC(PROT_EXEC),
FLAG_GENERIC(PROT_READ),
FLAG_GENERIC(PROT_WRITE),
FLAG_TARGET(PROT_SEM),
FLAG_GENERIC(PROT_GROWSDOWN),
FLAG_GENERIC(PROT_GROWSUP),
FLAG_END,
};
UNUSED static struct flags mmap_flags[] = {
FLAG_TARGET(MAP_SHARED),
FLAG_TARGET(MAP_PRIVATE),
FLAG_TARGET(MAP_ANONYMOUS),
FLAG_TARGET(MAP_DENYWRITE),
FLAG_TARGET(MAP_FIXED),
FLAG_TARGET(MAP_GROWSDOWN),
FLAG_TARGET(MAP_EXECUTABLE),
#ifdef MAP_LOCKED
FLAG_TARGET(MAP_LOCKED),
#endif
#ifdef MAP_NONBLOCK
FLAG_TARGET(MAP_NONBLOCK),
#endif
FLAG_TARGET(MAP_NORESERVE),
#ifdef MAP_POPULATE
FLAG_TARGET(MAP_POPULATE),
#endif
#ifdef TARGET_MAP_UNINITIALIZED
FLAG_TARGET(MAP_UNINITIALIZED),
#endif
FLAG_END,
};
UNUSED static struct flags clone_flags[] = {
FLAG_GENERIC(CLONE_VM),
FLAG_GENERIC(CLONE_FS),
FLAG_GENERIC(CLONE_FILES),
FLAG_GENERIC(CLONE_SIGHAND),
FLAG_GENERIC(CLONE_PTRACE),
FLAG_GENERIC(CLONE_VFORK),
FLAG_GENERIC(CLONE_PARENT),
FLAG_GENERIC(CLONE_THREAD),
FLAG_GENERIC(CLONE_NEWNS),
FLAG_GENERIC(CLONE_SYSVSEM),
FLAG_GENERIC(CLONE_SETTLS),
FLAG_GENERIC(CLONE_PARENT_SETTID),
FLAG_GENERIC(CLONE_CHILD_CLEARTID),
FLAG_GENERIC(CLONE_DETACHED),
FLAG_GENERIC(CLONE_UNTRACED),
FLAG_GENERIC(CLONE_CHILD_SETTID),
#if defined(CLONE_NEWUTS)
FLAG_GENERIC(CLONE_NEWUTS),
#endif
#if defined(CLONE_NEWIPC)
FLAG_GENERIC(CLONE_NEWIPC),
#endif
#if defined(CLONE_NEWUSER)
FLAG_GENERIC(CLONE_NEWUSER),
#endif
#if defined(CLONE_NEWPID)
FLAG_GENERIC(CLONE_NEWPID),
#endif
#if defined(CLONE_NEWNET)
FLAG_GENERIC(CLONE_NEWNET),
#endif
#if defined(CLONE_IO)
FLAG_GENERIC(CLONE_IO),
#endif
FLAG_END,
};
/*
* print_xxx utility functions. These are used to print syscall
* parameters in certain format. All of these have parameter
* named 'last'. This parameter is used to add comma to output
* when last == 0.
*/
static const char *
get_comma(int last)
{
return ((last) ? "" : ",");
}
static void
print_flags(const struct flags *f, abi_long flags, int last)
{
const char *sep = "";
int n;
if ((flags == 0) && (f->f_value == 0)) {
gemu_log("%s%s", f->f_string, get_comma(last));
return;
}
for (n = 0; f->f_string != NULL; f++) {
if ((f->f_value != 0) && ((flags & f->f_value) == f->f_value)) {
gemu_log("%s%s", sep, f->f_string);
flags &= ~f->f_value;
sep = "|";
n++;
}
}
if (n > 0) {
/* print rest of the flags as numeric */
if (flags != 0) {
gemu_log("%s%#x%s", sep, (unsigned int)flags, get_comma(last));
} else {
gemu_log("%s", get_comma(last));
}
} else {
/* no string version of flags found, print them in hex then */
gemu_log("%#x%s", (unsigned int)flags, get_comma(last));
}
}
static void
print_at_dirfd(abi_long dirfd, int last)
{
#ifdef AT_FDCWD
if (dirfd == AT_FDCWD) {
gemu_log("AT_FDCWD%s", get_comma(last));
return;
}
#endif
gemu_log("%d%s", (int)dirfd, get_comma(last));
}
static void
print_file_mode(abi_long mode, int last)
{
const char *sep = "";
const struct flags *m;
for (m = &mode_flags[0]; m->f_string != NULL; m++) {
if ((m->f_value & mode) == m->f_value) {
gemu_log("%s%s", m->f_string, sep);
sep = "|";
mode &= ~m->f_value;
break;
}
}
mode &= ~S_IFMT;
/* print rest of the mode as octal */
if (mode != 0)
gemu_log("%s%#o", sep, (unsigned int)mode);
gemu_log("%s", get_comma(last));
}
static void
print_open_flags(abi_long flags, int last)
{
print_flags(open_access_flags, flags & TARGET_O_ACCMODE, 1);
flags &= ~TARGET_O_ACCMODE;
if (flags == 0) {
gemu_log("%s", get_comma(last));
return;
}
gemu_log("|");
print_flags(open_flags, flags, last);
}
static void
print_syscall_prologue(const struct syscallname *sc)
{
gemu_log("%s(", sc->name);
}
/*ARGSUSED*/
static void
print_syscall_epilogue(const struct syscallname *sc)
{
(void)sc;
gemu_log(")");
}
static void
print_string(abi_long addr, int last)
{
char *s;
if ((s = lock_user_string(addr)) != NULL) {
gemu_log("\"%s\"%s", s, get_comma(last));
unlock_user(s, addr, 0);
} else {
/* can't get string out of it, so print it as pointer */
print_pointer(addr, last);
}
}
/*
* Prints out raw parameter using given format. Caller needs
* to do byte swapping if needed.
*/
static void
print_raw_param(const char *fmt, abi_long param, int last)
{
char format[64];
(void) snprintf(format, sizeof (format), "%s%s", fmt, get_comma(last));
gemu_log(format, param);
}
static void
print_pointer(abi_long p, int last)
{
if (p == 0)
gemu_log("NULL%s", get_comma(last));
else
gemu_log("0x" TARGET_ABI_FMT_lx "%s", p, get_comma(last));
}
/*
* Reads 32-bit (int) number from guest address space from
* address 'addr' and prints it.
*/
static void
print_number(abi_long addr, int last)
{
if (addr == 0) {
gemu_log("NULL%s", get_comma(last));
} else {
int num;
get_user_s32(num, addr);
gemu_log("[%d]%s", num, get_comma(last));
}
}
static void
print_timeval(abi_ulong tv_addr, int last)
{
if( tv_addr ) {
struct target_timeval *tv;
tv = lock_user(VERIFY_READ, tv_addr, sizeof(*tv), 1);
if (!tv)
return;
gemu_log("{" TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld "}%s",
tswapal(tv->tv_sec), tswapal(tv->tv_usec), get_comma(last));
unlock_user(tv, tv_addr, 0);
} else
gemu_log("NULL%s", get_comma(last));
}
#undef UNUSED
#ifdef TARGET_NR_accept
static void
print_accept(const struct syscallname *name,
abi_long arg0, abi_long arg1, abi_long arg2,
abi_long arg3, abi_long arg4, abi_long arg5)
{
print_syscall_prologue(name);
print_raw_param("%d", arg0, 0);
print_pointer(arg1, 0);
print_number(arg2, 1);
print_syscall_epilogue(name);
}
#endif
#ifdef TARGET_NR_access
static void
print_access(const struct syscallname *name,
abi_long arg0, abi_long arg1, abi_long arg2,
abi_long arg3, abi_long arg4, abi_long arg5)
{
print_syscall_prologue(name);
print_string(arg0, 0);
print_flags(access_flags, arg1, 1);
print_syscall_epilogue(name);
}
#endif
#ifdef TARGET_NR_brk
static void
print_brk(const struct syscallname *name,
abi_long arg0, abi_long arg1, abi_long arg2,
abi_long arg3, abi_long arg4, abi_long arg5)
{
print_syscall_prologue(name);
print_pointer(arg0, 1);
print_syscall_epilogue(name);
}
#endif
#ifdef TARGET_NR_chdir
static void
print_chdir(const struct syscallname *name,
abi_long arg0, abi_long arg1, abi_long arg2,
abi_long arg3, abi_long arg4, abi_long arg5)
{
print_syscall_prologue(name);
print_string(arg0, 1);
print_syscall_epilogue(name);
}
#endif
#ifdef TARGET_NR_chmod
static void
print_chmod(const struct syscallname *name,
abi_long arg0, abi_long arg1, abi_long arg2,
abi_long arg3, abi_long arg4, abi_long arg5)
{
print_syscall_prologue(name);
print_string(arg0, 0);
print_file_mode(arg1, 1);
print_syscall_epilogue(name);
}
#endif
#ifdef TARGET_NR_clone
static void
print_clone(const struct syscallname *name,
abi_long arg0, abi_long arg1, abi_long arg2,
abi_long arg3, abi_long arg4, abi_long arg5)
{
print_syscall_prologue(name);
#if defined(TARGET_M68K)
print_flags(clone_flags, arg0, 0);
print_raw_param("newsp=0x" TARGET_ABI_FMT_lx, arg1, 1);
#elif defined(TARGET_SH4) || defined(TARGET_ALPHA)
print_flags(clone_flags, arg0, 0);
print_raw_param("child_stack=0x" TARGET_ABI_FMT_lx, arg1, 0);
print_raw_param("parent_tidptr=0x" TARGET_ABI_FMT_lx, arg2, 0);
print_raw_param("child_tidptr=0x" TARGET_ABI_FMT_lx, arg3, 0);
print_raw_param("tls=0x" TARGET_ABI_FMT_lx, arg4, 1);
#elif defined(TARGET_CRIS)
print_raw_param("child_stack=0x" TARGET_ABI_FMT_lx, arg0, 0);
print_flags(clone_flags, arg1, 0);
print_raw_param("parent_tidptr=0x" TARGET_ABI_FMT_lx, arg2, 0);
print_raw_param("tls=0x" TARGET_ABI_FMT_lx, arg3, 0);
print_raw_param("child_tidptr=0x" TARGET_ABI_FMT_lx, arg4, 1);
#else
print_flags(clone_flags, arg0, 0);
print_raw_param("child_stack=0x" TARGET_ABI_FMT_lx, arg1, 0);
print_raw_param("parent_tidptr=0x" TARGET_ABI_FMT_lx, arg2, 0);
print_raw_param("tls=0x" TARGET_ABI_FMT_lx, arg3, 0);
print_raw_param("child_tidptr=0x" TARGET_ABI_FMT_lx, arg4, 1);
#endif
print_syscall_epilogue(name);
}
#endif
#ifdef TARGET_NR_creat
static void
print_creat(const struct syscallname *name,
abi_long arg0, abi_long arg1, abi_long arg2,
abi_long arg3, abi_long arg4, abi_long arg5)
{
print_syscall_prologue(name);
print_string(arg0, 0);
print_file_mode(arg1, 1);
print_syscall_epilogue(name);
}
#endif
#ifdef TARGET_NR_execv
static void
print_execv(const struct syscallname *name,
abi_long arg0, abi_long arg1, abi_long arg2,
abi_long arg3, abi_long arg4, abi_long arg5)
{
print_syscall_prologue(name);
print_string(arg0, 0);
print_raw_param("0x" TARGET_ABI_FMT_lx, arg1, 1);
print_syscall_epilogue(name);
}
#endif
#ifdef TARGET_NR_faccessat
static void
print_faccessat(const struct syscallname *name,
abi_long arg0, abi_long arg1, abi_long arg2,
abi_long arg3, abi_long arg4, abi_long arg5)
{
print_syscall_prologue(name);
print_at_dirfd(arg0, 0);
print_string(arg1, 0);
print_flags(access_flags, arg2, 0);
print_flags(at_file_flags, arg3, 1);
print_syscall_epilogue(name);
}
#endif
#ifdef TARGET_NR_fchmodat
static void
print_fchmodat(const struct syscallname *name,
abi_long arg0, abi_long arg1, abi_long arg2,
abi_long arg3, abi_long arg4, abi_long arg5)
{
print_syscall_prologue(name);
print_at_dirfd(arg0, 0);
print_string(arg1, 0);
print_file_mode(arg2, 0);
print_flags(at_file_flags, arg3, 1);
print_syscall_epilogue(name);
}
#endif
#ifdef TARGET_NR_fchownat
static void
print_fchownat(const struct syscallname *name,
abi_long arg0, abi_long arg1, abi_long arg2,
abi_long arg3, abi_long arg4, abi_long arg5)
{
print_syscall_prologue(name);
print_at_dirfd(arg0, 0);
print_string(arg1, 0);
print_raw_param("%d", arg2, 0);
print_raw_param("%d", arg3, 0);
print_flags(at_file_flags, arg4, 1);
print_syscall_epilogue(name);
}
#endif
#if defined(TARGET_NR_fcntl) || defined(TARGET_NR_fcntl64)
static void
print_fcntl(const struct syscallname *name,
abi_long arg0, abi_long arg1, abi_long arg2,
abi_long arg3, abi_long arg4, abi_long arg5)
{
print_syscall_prologue(name);
print_raw_param("%d", arg0, 0);
switch(arg1) {
case TARGET_F_DUPFD:
gemu_log("F_DUPFD,");
print_raw_param(TARGET_ABI_FMT_ld, arg2, 1);
break;
case TARGET_F_GETFD:
gemu_log("F_GETFD");
break;
case TARGET_F_SETFD:
gemu_log("F_SETFD,");
print_raw_param(TARGET_ABI_FMT_ld, arg2, 1);
break;
case TARGET_F_GETFL:
gemu_log("F_GETFL");
break;
case TARGET_F_SETFL:
gemu_log("F_SETFL,");
print_open_flags(arg2, 1);
break;
case TARGET_F_GETLK:
gemu_log("F_GETLK,");
print_pointer(arg2, 1);
break;
case TARGET_F_SETLK:
gemu_log("F_SETLK,");
print_pointer(arg2, 1);
break;
case TARGET_F_SETLKW:
gemu_log("F_SETLKW,");
print_pointer(arg2, 1);
break;
case TARGET_F_GETOWN:
gemu_log("F_GETOWN");
break;
case TARGET_F_SETOWN:
gemu_log("F_SETOWN,");
print_raw_param(TARGET_ABI_FMT_ld, arg2, 0);
break;
case TARGET_F_GETSIG:
gemu_log("F_GETSIG");
break;
case TARGET_F_SETSIG:
gemu_log("F_SETSIG,");
print_raw_param(TARGET_ABI_FMT_ld, arg2, 0);
break;
#if TARGET_ABI_BITS == 32
case TARGET_F_GETLK64:
gemu_log("F_GETLK64,");
print_pointer(arg2, 1);
break;
case TARGET_F_SETLK64:
gemu_log("F_SETLK64,");
print_pointer(arg2, 1);
break;
case TARGET_F_SETLKW64:
gemu_log("F_SETLKW64,");
print_pointer(arg2, 1);
break;
#endif
case TARGET_F_SETLEASE:
gemu_log("F_SETLEASE,");
print_raw_param(TARGET_ABI_FMT_ld, arg2, 0);
break;
case TARGET_F_GETLEASE:
gemu_log("F_GETLEASE");
break;
case TARGET_F_DUPFD_CLOEXEC:
gemu_log("F_DUPFD_CLOEXEC,");
print_raw_param(TARGET_ABI_FMT_ld, arg2, 1);
break;
case TARGET_F_NOTIFY:
gemu_log("F_NOTIFY,");
print_raw_param(TARGET_ABI_FMT_ld, arg2, 0);
break;
default:
print_raw_param(TARGET_ABI_FMT_ld, arg1, 0);
print_pointer(arg2, 1);
break;
}
print_syscall_epilogue(name);
}
#define print_fcntl64 print_fcntl
#endif
#ifdef TARGET_NR_futimesat
static void
print_futimesat(const struct syscallname *name,
abi_long arg0, abi_long arg1, abi_long arg2,
abi_long arg3, abi_long arg4, abi_long arg5)
{
print_syscall_prologue(name);
print_at_dirfd(arg0, 0);
print_string(arg1, 0);
print_timeval(arg2, 0);
print_timeval(arg2 + sizeof (struct target_timeval), 1);
print_syscall_epilogue(name);
}
#endif
#ifdef TARGET_NR_link
static void
print_link(const struct syscallname *name,
abi_long arg0, abi_long arg1, abi_long arg2,
abi_long arg3, abi_long arg4, abi_long arg5)
{
print_syscall_prologue(name);
print_string(arg0, 0);
print_string(arg1, 1);
print_syscall_epilogue(name);
}
#endif
#ifdef TARGET_NR_linkat
static void
print_linkat(const struct syscallname *name,
abi_long arg0, abi_long arg1, abi_long arg2,
abi_long arg3, abi_long arg4, abi_long arg5)
{
print_syscall_prologue(name);
print_at_dirfd(arg0, 0);
print_string(arg1, 0);
print_at_dirfd(arg2, 0);
print_string(arg3, 0);
print_flags(at_file_flags, arg4, 1);
print_syscall_epilogue(name);
}
#endif
#ifdef TARGET_NR__llseek
static void
print__llseek(const struct syscallname *name,
abi_long arg0, abi_long arg1, abi_long arg2,
abi_long arg3, abi_long arg4, abi_long arg5)
{
const char *whence = "UNKNOWN";
print_syscall_prologue(name);
print_raw_param("%d", arg0, 0);
print_raw_param("%ld", arg1, 0);
print_raw_param("%ld", arg2, 0);
print_pointer(arg3, 0);
switch(arg4) {
case SEEK_SET: whence = "SEEK_SET"; break;