forked from MoatLab/FEMU
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstrace.c
4273 lines (3938 loc) · 118 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 "qemu/osdep.h"
#include <sys/ipc.h>
#include <sys/msg.h>
#include <sys/sem.h>
#include <sys/shm.h>
#include <sys/select.h>
#include <sys/mount.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <netinet/udp.h>
#include <linux/if_packet.h>
#include <linux/in6.h>
#include <linux/netlink.h>
#include <sched.h>
#include "qemu.h"
#include "user-internals.h"
#include "strace.h"
#include "signal-common.h"
#include "target_mman.h"
struct syscallname {
int nr;
const char *name;
const char *format;
void (*call)(CPUArchState *, const struct syscallname *,
abi_long, abi_long, abi_long,
abi_long, abi_long, abi_long);
void (*result)(CPUArchState *, const struct syscallname *, abi_long,
abi_long, abi_long, abi_long,
abi_long, abi_long, abi_long);
};
/*
* 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))
/*
* 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 */
abi_long f_mask; /* mask */
const char *f_string; /* stringified flag */
};
/* No 'struct flags' element should have a zero mask. */
#define FLAG_BASIC(V, M, N) { V, M | QEMU_BUILD_BUG_ON_ZERO(!(M)), N }
/* common flags for all architectures */
#define FLAG_GENERIC_MASK(V, M) FLAG_BASIC(V, M, #V)
#define FLAG_GENERIC(V) FLAG_BASIC(V, V, #V)
/* target specific flags (syscall_defs.h has TARGET_<flag>) */
#define FLAG_TARGET_MASK(V, M) FLAG_BASIC(TARGET_##V, TARGET_##M, #V)
#define FLAG_TARGET(V) FLAG_BASIC(TARGET_##V, TARGET_##V, #V)
/* end of flags array */
#define FLAG_END { 0, 0, NULL }
/* Structure used to translate enumerated values into strings */
struct enums {
abi_long e_value; /* enum value */
const char *e_string; /* stringified enum */
};
/* common enums for all architectures */
#define ENUM_GENERIC(name) { name, #name }
/* target specific enums */
#define ENUM_TARGET(name) { TARGET_ ## name, #name }
/* end of enums array */
#define ENUM_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_enums(const struct enums *, 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_buf(abi_long addr, abi_long len, int last);
UNUSED static void print_raw_param(const char *, abi_long, int);
UNUSED static void print_raw_param64(const char *, long long, int last);
UNUSED static void print_timeval(abi_ulong, int);
UNUSED static void print_timespec(abi_ulong, int);
UNUSED static void print_timespec64(abi_ulong, int);
UNUSED static void print_timezone(abi_ulong, int);
UNUSED static void print_itimerval(abi_ulong, int);
UNUSED static void print_number(abi_long, int);
UNUSED static void print_signal(abi_ulong, int);
UNUSED static void print_sockaddr(abi_ulong, abi_long, int);
UNUSED static void print_socket_domain(int domain);
UNUSED static void print_socket_type(int type);
UNUSED static void print_socket_protocol(int domain, int type, int protocol);
/*
* Utility functions
*/
static void
print_ipc_cmd(int cmd)
{
#define output_cmd(val) \
if( cmd == val ) { \
qemu_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 */
output_cmd( MSG_STAT );
output_cmd( MSG_INFO );
/* 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 */
qemu_log("%d", cmd);
}
static const char * const target_signal_name[] = {
#define MAKE_SIG_ENTRY(sig) [TARGET_##sig] = #sig,
MAKE_SIGNAL_LIST
#undef MAKE_SIG_ENTRY
};
static void
print_signal(abi_ulong arg, int last)
{
const char *signal_name = NULL;
if (arg < ARRAY_SIZE(target_signal_name)) {
signal_name = target_signal_name[arg];
}
if (signal_name == NULL) {
print_raw_param("%ld", arg, last);
return;
}
qemu_log("%s%s", signal_name, get_comma(last));
}
static void print_si_code(int arg)
{
const char *codename = NULL;
switch (arg) {
case SI_USER:
codename = "SI_USER";
break;
case SI_KERNEL:
codename = "SI_KERNEL";
break;
case SI_QUEUE:
codename = "SI_QUEUE";
break;
case SI_TIMER:
codename = "SI_TIMER";
break;
case SI_MESGQ:
codename = "SI_MESGQ";
break;
case SI_ASYNCIO:
codename = "SI_ASYNCIO";
break;
case SI_SIGIO:
codename = "SI_SIGIO";
break;
case SI_TKILL:
codename = "SI_TKILL";
break;
default:
qemu_log("%d", arg);
return;
}
qemu_log("%s", codename);
}
static void get_target_siginfo(target_siginfo_t *tinfo,
const target_siginfo_t *info)
{
abi_ulong sival_ptr;
int sig;
int si_errno;
int si_code;
int si_type;
__get_user(sig, &info->si_signo);
__get_user(si_errno, &tinfo->si_errno);
__get_user(si_code, &info->si_code);
tinfo->si_signo = sig;
tinfo->si_errno = si_errno;
tinfo->si_code = si_code;
/* Ensure we don't leak random junk to the guest later */
memset(tinfo->_sifields._pad, 0, sizeof(tinfo->_sifields._pad));
/* This is awkward, because we have to use a combination of
* the si_code and si_signo to figure out which of the union's
* members are valid. (Within the host kernel it is always possible
* to tell, but the kernel carefully avoids giving userspace the
* high 16 bits of si_code, so we don't have the information to
* do this the easy way...) We therefore make our best guess,
* bearing in mind that a guest can spoof most of the si_codes
* via rt_sigqueueinfo() if it likes.
*
* Once we have made our guess, we record it in the top 16 bits of
* the si_code, so that print_siginfo() later can use it.
* print_siginfo() will strip these top bits out before printing
* the si_code.
*/
switch (si_code) {
case SI_USER:
case SI_TKILL:
case SI_KERNEL:
/* Sent via kill(), tkill() or tgkill(), or direct from the kernel.
* These are the only unspoofable si_code values.
*/
__get_user(tinfo->_sifields._kill._pid, &info->_sifields._kill._pid);
__get_user(tinfo->_sifields._kill._uid, &info->_sifields._kill._uid);
si_type = QEMU_SI_KILL;
break;
default:
/* Everything else is spoofable. Make best guess based on signal */
switch (sig) {
case TARGET_SIGCHLD:
__get_user(tinfo->_sifields._sigchld._pid,
&info->_sifields._sigchld._pid);
__get_user(tinfo->_sifields._sigchld._uid,
&info->_sifields._sigchld._uid);
__get_user(tinfo->_sifields._sigchld._status,
&info->_sifields._sigchld._status);
__get_user(tinfo->_sifields._sigchld._utime,
&info->_sifields._sigchld._utime);
__get_user(tinfo->_sifields._sigchld._stime,
&info->_sifields._sigchld._stime);
si_type = QEMU_SI_CHLD;
break;
case TARGET_SIGIO:
__get_user(tinfo->_sifields._sigpoll._band,
&info->_sifields._sigpoll._band);
__get_user(tinfo->_sifields._sigpoll._fd,
&info->_sifields._sigpoll._fd);
si_type = QEMU_SI_POLL;
break;
default:
/* Assume a sigqueue()/mq_notify()/rt_sigqueueinfo() source. */
__get_user(tinfo->_sifields._rt._pid, &info->_sifields._rt._pid);
__get_user(tinfo->_sifields._rt._uid, &info->_sifields._rt._uid);
/* XXX: potential problem if 64 bit */
__get_user(sival_ptr, &info->_sifields._rt._sigval.sival_ptr);
tinfo->_sifields._rt._sigval.sival_ptr = sival_ptr;
si_type = QEMU_SI_RT;
break;
}
break;
}
tinfo->si_code = deposit32(si_code, 16, 16, si_type);
}
static void print_siginfo(const target_siginfo_t *tinfo)
{
/* Print a target_siginfo_t in the format desired for printing
* signals being taken. We assume the target_siginfo_t is in the
* internal form where the top 16 bits of si_code indicate which
* part of the union is valid, rather than in the guest-visible
* form where the bottom 16 bits are sign-extended into the top 16.
*/
int si_type = extract32(tinfo->si_code, 16, 16);
int si_code = sextract32(tinfo->si_code, 0, 16);
qemu_log("{si_signo=");
print_signal(tinfo->si_signo, 1);
qemu_log(", si_code=");
print_si_code(si_code);
switch (si_type) {
case QEMU_SI_KILL:
qemu_log(", si_pid=%u, si_uid=%u",
(unsigned int)tinfo->_sifields._kill._pid,
(unsigned int)tinfo->_sifields._kill._uid);
break;
case QEMU_SI_TIMER:
qemu_log(", si_timer1=%u, si_timer2=%u",
tinfo->_sifields._timer._timer1,
tinfo->_sifields._timer._timer2);
break;
case QEMU_SI_POLL:
qemu_log(", si_band=%d, si_fd=%d",
tinfo->_sifields._sigpoll._band,
tinfo->_sifields._sigpoll._fd);
break;
case QEMU_SI_FAULT:
qemu_log(", si_addr=");
print_pointer(tinfo->_sifields._sigfault._addr, 1);
break;
case QEMU_SI_CHLD:
qemu_log(", si_pid=%u, si_uid=%u, si_status=%d"
", si_utime=" TARGET_ABI_FMT_ld
", si_stime=" TARGET_ABI_FMT_ld,
(unsigned int)(tinfo->_sifields._sigchld._pid),
(unsigned int)(tinfo->_sifields._sigchld._uid),
tinfo->_sifields._sigchld._status,
tinfo->_sifields._sigchld._utime,
tinfo->_sifields._sigchld._stime);
break;
case QEMU_SI_RT:
qemu_log(", si_pid=%u, si_uid=%u, si_sigval=" TARGET_ABI_FMT_ld,
(unsigned int)tinfo->_sifields._rt._pid,
(unsigned int)tinfo->_sifields._rt._uid,
tinfo->_sifields._rt._sigval.sival_ptr);
break;
default:
g_assert_not_reached();
}
qemu_log("}");
}
static void
print_sockaddr(abi_ulong addr, abi_long addrlen, int last)
{
struct target_sockaddr *sa;
int i;
int sa_family;
sa = lock_user(VERIFY_READ, addr, addrlen, 1);
if (sa) {
sa_family = tswap16(sa->sa_family);
switch (sa_family) {
case AF_UNIX: {
struct target_sockaddr_un *un = (struct target_sockaddr_un *)sa;
qemu_log("{sun_family=AF_UNIX,sun_path=\"");
for (i = 0; i < addrlen -
offsetof(struct target_sockaddr_un, sun_path) &&
un->sun_path[i]; i++) {
qemu_log("%c", un->sun_path[i]);
}
qemu_log("\"}");
break;
}
case AF_INET: {
struct target_sockaddr_in *in = (struct target_sockaddr_in *)sa;
uint8_t *c = (uint8_t *)&in->sin_addr.s_addr;
qemu_log("{sin_family=AF_INET,sin_port=htons(%d),",
ntohs(in->sin_port));
qemu_log("sin_addr=inet_addr(\"%d.%d.%d.%d\")",
c[0], c[1], c[2], c[3]);
qemu_log("}");
break;
}
case AF_PACKET: {
struct target_sockaddr_ll *ll = (struct target_sockaddr_ll *)sa;
uint8_t *c = (uint8_t *)&ll->sll_addr;
qemu_log("{sll_family=AF_PACKET,"
"sll_protocol=htons(0x%04x),if%d,pkttype=",
ntohs(ll->sll_protocol), ll->sll_ifindex);
switch (ll->sll_pkttype) {
case PACKET_HOST:
qemu_log("PACKET_HOST");
break;
case PACKET_BROADCAST:
qemu_log("PACKET_BROADCAST");
break;
case PACKET_MULTICAST:
qemu_log("PACKET_MULTICAST");
break;
case PACKET_OTHERHOST:
qemu_log("PACKET_OTHERHOST");
break;
case PACKET_OUTGOING:
qemu_log("PACKET_OUTGOING");
break;
default:
qemu_log("%d", ll->sll_pkttype);
break;
}
qemu_log(",sll_addr=%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x",
c[0], c[1], c[2], c[3], c[4], c[5], c[6], c[7]);
qemu_log("}");
break;
}
case AF_NETLINK: {
struct target_sockaddr_nl *nl = (struct target_sockaddr_nl *)sa;
qemu_log("{nl_family=AF_NETLINK,nl_pid=%u,nl_groups=%u}",
tswap32(nl->nl_pid), tswap32(nl->nl_groups));
break;
}
default:
qemu_log("{sa_family=%d, sa_data={", sa->sa_family);
for (i = 0; i < 13; i++) {
qemu_log("%02x, ", sa->sa_data[i]);
}
qemu_log("%02x}", sa->sa_data[i]);
qemu_log("}");
break;
}
unlock_user(sa, addr, 0);
} else {
print_raw_param("0x"TARGET_ABI_FMT_lx, addr, 0);
}
qemu_log(", "TARGET_ABI_FMT_ld"%s", addrlen, get_comma(last));
}
static void
print_socket_domain(int domain)
{
switch (domain) {
case PF_UNIX:
qemu_log("PF_UNIX");
break;
case PF_INET:
qemu_log("PF_INET");
break;
case PF_NETLINK:
qemu_log("PF_NETLINK");
break;
case PF_PACKET:
qemu_log("PF_PACKET");
break;
default:
qemu_log("%d", domain);
break;
}
}
static void
print_socket_type(int type)
{
switch (type & TARGET_SOCK_TYPE_MASK) {
case TARGET_SOCK_DGRAM:
qemu_log("SOCK_DGRAM");
break;
case TARGET_SOCK_STREAM:
qemu_log("SOCK_STREAM");
break;
case TARGET_SOCK_RAW:
qemu_log("SOCK_RAW");
break;
case TARGET_SOCK_RDM:
qemu_log("SOCK_RDM");
break;
case TARGET_SOCK_SEQPACKET:
qemu_log("SOCK_SEQPACKET");
break;
case TARGET_SOCK_PACKET:
qemu_log("SOCK_PACKET");
break;
}
if (type & TARGET_SOCK_CLOEXEC) {
qemu_log("|SOCK_CLOEXEC");
}
if (type & TARGET_SOCK_NONBLOCK) {
qemu_log("|SOCK_NONBLOCK");
}
}
static void
print_socket_protocol(int domain, int type, int protocol)
{
if (domain == AF_PACKET ||
(domain == AF_INET && type == TARGET_SOCK_PACKET)) {
switch (protocol) {
case 0x0003:
qemu_log("ETH_P_ALL");
break;
default:
qemu_log("%d", protocol);
}
return;
}
if (domain == PF_NETLINK) {
switch (protocol) {
case NETLINK_ROUTE:
qemu_log("NETLINK_ROUTE");
break;
case NETLINK_UNUSED:
qemu_log("NETLINK_UNUSED");
break;
case NETLINK_USERSOCK:
qemu_log("NETLINK_USERSOCK");
break;
case NETLINK_FIREWALL:
qemu_log("NETLINK_FIREWALL");
break;
case NETLINK_SOCK_DIAG:
qemu_log("NETLINK_SOCK_DIAG");
break;
case NETLINK_NFLOG:
qemu_log("NETLINK_NFLOG");
break;
case NETLINK_XFRM:
qemu_log("NETLINK_XFRM");
break;
case NETLINK_SELINUX:
qemu_log("NETLINK_SELINUX");
break;
case NETLINK_ISCSI:
qemu_log("NETLINK_ISCSI");
break;
case NETLINK_AUDIT:
qemu_log("NETLINK_AUDIT");
break;
case NETLINK_FIB_LOOKUP:
qemu_log("NETLINK_FIB_LOOKUP");
break;
case NETLINK_CONNECTOR:
qemu_log("NETLINK_CONNECTOR");
break;
case NETLINK_NETFILTER:
qemu_log("NETLINK_NETFILTER");
break;
case NETLINK_IP6_FW:
qemu_log("NETLINK_IP6_FW");
break;
case NETLINK_DNRTMSG:
qemu_log("NETLINK_DNRTMSG");
break;
case NETLINK_KOBJECT_UEVENT:
qemu_log("NETLINK_KOBJECT_UEVENT");
break;
case NETLINK_GENERIC:
qemu_log("NETLINK_GENERIC");
break;
case NETLINK_SCSITRANSPORT:
qemu_log("NETLINK_SCSITRANSPORT");
break;
case NETLINK_ECRYPTFS:
qemu_log("NETLINK_ECRYPTFS");
break;
case NETLINK_RDMA:
qemu_log("NETLINK_RDMA");
break;
case NETLINK_CRYPTO:
qemu_log("NETLINK_CRYPTO");
break;
case NETLINK_SMC:
qemu_log("NETLINK_SMC");
break;
default:
qemu_log("%d", protocol);
break;
}
return;
}
switch (protocol) {
case IPPROTO_IP:
qemu_log("IPPROTO_IP");
break;
case IPPROTO_TCP:
qemu_log("IPPROTO_TCP");
break;
case IPPROTO_UDP:
qemu_log("IPPROTO_UDP");
break;
case IPPROTO_RAW:
qemu_log("IPPROTO_RAW");
break;
default:
qemu_log("%d", protocol);
break;
}
}
#ifdef TARGET_NR__newselect
static void
print_fdset(int n, abi_ulong target_fds_addr)
{
int i;
int first = 1;
qemu_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) {
qemu_log("%s%d", get_comma(first), i);
first = 0;
}
}
unlock_user(target_fds, target_fds_addr, 0);
}
qemu_log("]");
}
#endif
/*
* Sysycall specific output functions
*/
/* select */
#ifdef TARGET_NR__newselect
static void
print_newselect(CPUArchState *cpu_env, const struct syscallname *name,
abi_long arg1, abi_long arg2, abi_long arg3,
abi_long arg4, abi_long arg5, abi_long arg6)
{
print_syscall_prologue(name);
print_fdset(arg1, arg2);
qemu_log(",");
print_fdset(arg1, arg3);
qemu_log(",");
print_fdset(arg1, arg4);
qemu_log(",");
print_timeval(arg5, 1);
print_syscall_epilogue(name);
}
#endif
static void
print_semctl(CPUArchState *cpu_env, const struct syscallname *name,
abi_long arg1, abi_long arg2, abi_long arg3,
abi_long arg4, abi_long arg5, abi_long arg6)
{
qemu_log("%s(" TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld ",",
name->name, arg1, arg2);
print_ipc_cmd(arg3);
qemu_log(",0x" TARGET_ABI_FMT_lx ")", arg4);
}
static void
print_shmat(CPUArchState *cpu_env, const struct syscallname *name,
abi_long arg0, abi_long arg1, abi_long arg2,
abi_long arg3, abi_long arg4, abi_long arg5)
{
static const struct flags shmat_flags[] = {
FLAG_GENERIC(SHM_RND),
FLAG_GENERIC(SHM_REMAP),
FLAG_GENERIC(SHM_RDONLY),
FLAG_GENERIC(SHM_EXEC),
FLAG_END
};
print_syscall_prologue(name);
print_raw_param(TARGET_ABI_FMT_ld, arg0, 0);
print_pointer(arg1, 0);
print_flags(shmat_flags, arg2, 1);
print_syscall_epilogue(name);
}
#ifdef TARGET_NR_ipc
static void
print_ipc(CPUArchState *cpu_env, 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:
print_semctl(cpu_env, &(const struct syscallname){ .name = "semctl" },
arg2, arg3, arg4, arg5, 0, 0);
break;
case IPCOP_shmat:
print_shmat(cpu_env, &(const struct syscallname){ .name = "shmat" },
arg2, arg5, arg3, 0, 0, 0);
break;
default:
qemu_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 bool
print_syscall_err(abi_long ret)
{
const char *errstr;
qemu_log(" = ");
if (is_error(ret)) {
errstr = target_strerror(-ret);
if (errstr) {
qemu_log("-1 errno=%d (%s)", (int)-ret, errstr);
return true;
}
}
return false;
}
static void
print_syscall_ret_addr(CPUArchState *cpu_env, const struct syscallname *name,
abi_long ret, abi_long arg0, abi_long arg1,
abi_long arg2, abi_long arg3, abi_long arg4,
abi_long arg5)
{
if (!print_syscall_err(ret)) {
qemu_log("0x" TARGET_ABI_FMT_lx, ret);
}
qemu_log("\n");
}
#if 0 /* currently unused */
static void
print_syscall_ret_raw(struct syscallname *name, abi_long ret)
{
qemu_log(" = 0x" TARGET_ABI_FMT_lx "\n", ret);
}
#endif
#ifdef TARGET_NR__newselect
static void
print_syscall_ret_newselect(CPUArchState *cpu_env, const struct syscallname *name,
abi_long ret, abi_long arg0, abi_long arg1,
abi_long arg2, abi_long arg3, abi_long arg4,
abi_long arg5)
{
if (!print_syscall_err(ret)) {
qemu_log(" = 0x" TARGET_ABI_FMT_lx " (", ret);
print_fdset(arg0, arg1);
qemu_log(",");
print_fdset(arg0, arg2);
qemu_log(",");
print_fdset(arg0, arg3);
qemu_log(",");
print_timeval(arg4, 1);
qemu_log(")");
}
qemu_log("\n");
}
#endif
/* special meanings of adjtimex()' non-negative return values */
#define TARGET_TIME_OK 0 /* clock synchronized, no leap second */
#define TARGET_TIME_INS 1 /* insert leap second */
#define TARGET_TIME_DEL 2 /* delete leap second */
#define TARGET_TIME_OOP 3 /* leap second in progress */
#define TARGET_TIME_WAIT 4 /* leap second has occurred */
#define TARGET_TIME_ERROR 5 /* clock not synchronized */
#ifdef TARGET_NR_adjtimex
static void
print_syscall_ret_adjtimex(CPUArchState *cpu_env, const struct syscallname *name,
abi_long ret, abi_long arg0, abi_long arg1,
abi_long arg2, abi_long arg3, abi_long arg4,
abi_long arg5)
{
if (!print_syscall_err(ret)) {
qemu_log(TARGET_ABI_FMT_ld, ret);
switch (ret) {
case TARGET_TIME_OK:
qemu_log(" TIME_OK (clock synchronized, no leap second)");
break;
case TARGET_TIME_INS:
qemu_log(" TIME_INS (insert leap second)");
break;
case TARGET_TIME_DEL:
qemu_log(" TIME_DEL (delete leap second)");
break;
case TARGET_TIME_OOP:
qemu_log(" TIME_OOP (leap second in progress)");
break;
case TARGET_TIME_WAIT:
qemu_log(" TIME_WAIT (leap second has occurred)");
break;
case TARGET_TIME_ERROR:
qemu_log(" TIME_ERROR (clock not synchronized)");
break;
}
}
qemu_log("\n");
}
#endif
#if defined(TARGET_NR_clock_gettime) || defined(TARGET_NR_clock_getres)
static void
print_syscall_ret_clock_gettime(CPUArchState *cpu_env, const struct syscallname *name,
abi_long ret, abi_long arg0, abi_long arg1,
abi_long arg2, abi_long arg3, abi_long arg4,
abi_long arg5)
{
if (!print_syscall_err(ret)) {
qemu_log(TARGET_ABI_FMT_ld, ret);
qemu_log(" (");
print_timespec(arg1, 1);
qemu_log(")");
}
qemu_log("\n");
}
#define print_syscall_ret_clock_getres print_syscall_ret_clock_gettime
#endif
#if defined(TARGET_NR_clock_gettime64)
static void
print_syscall_ret_clock_gettime64(CPUArchState *cpu_env, const struct syscallname *name,
abi_long ret, abi_long arg0, abi_long arg1,
abi_long arg2, abi_long arg3, abi_long arg4,
abi_long arg5)
{
if (!print_syscall_err(ret)) {
qemu_log(TARGET_ABI_FMT_ld, ret);
qemu_log(" (");
print_timespec64(arg1, 1);
qemu_log(")");
}
qemu_log("\n");
}
#endif
#ifdef TARGET_NR_gettimeofday
static void
print_syscall_ret_gettimeofday(CPUArchState *cpu_env, const struct syscallname *name,
abi_long ret, abi_long arg0, abi_long arg1,
abi_long arg2, abi_long arg3, abi_long arg4,
abi_long arg5)
{
if (!print_syscall_err(ret)) {
qemu_log(TARGET_ABI_FMT_ld, ret);
qemu_log(" (");
print_timeval(arg0, 0);
print_timezone(arg1, 1);
qemu_log(")");
}
qemu_log("\n");
}
#endif
#ifdef TARGET_NR_getitimer
static void
print_syscall_ret_getitimer(CPUArchState *cpu_env, const struct syscallname *name,
abi_long ret, abi_long arg0, abi_long arg1,
abi_long arg2, abi_long arg3, abi_long arg4,
abi_long arg5)
{
if (!print_syscall_err(ret)) {
qemu_log(TARGET_ABI_FMT_ld, ret);
qemu_log(" (");
print_itimerval(arg1, 1);
qemu_log(")");
}
qemu_log("\n");
}
#endif
#ifdef TARGET_NR_getitimer
static void
print_syscall_ret_setitimer(CPUArchState *cpu_env, const struct syscallname *name,
abi_long ret, abi_long arg0, abi_long arg1,
abi_long arg2, abi_long arg3, abi_long arg4,
abi_long arg5)
{
if (!print_syscall_err(ret)) {
qemu_log(TARGET_ABI_FMT_ld, ret);
qemu_log(" (old_value = ");
print_itimerval(arg2, 1);
qemu_log(")");
}
qemu_log("\n");
}
#endif
#if defined(TARGET_NR_listxattr) || defined(TARGET_NR_llistxattr) \
|| defined(TARGGET_NR_flistxattr)
static void
print_syscall_ret_listxattr(CPUArchState *cpu_env, const struct syscallname *name,
abi_long ret, abi_long arg0, abi_long arg1,
abi_long arg2, abi_long arg3, abi_long arg4,
abi_long arg5)
{
if (!print_syscall_err(ret)) {
qemu_log(TARGET_ABI_FMT_ld, ret);
qemu_log(" (list = ");
if (arg1 != 0) {
abi_long attr = arg1;
while (ret) {
if (attr != arg1) {
qemu_log(",");
}
print_string(attr, 1);
ret -= target_strlen(attr) + 1;
attr += target_strlen(attr) + 1;
}
} else {
qemu_log("NULL");
}
qemu_log(")");
}
qemu_log("\n");
}
#define print_syscall_ret_llistxattr print_syscall_ret_listxattr
#define print_syscall_ret_flistxattr print_syscall_ret_listxattr
#endif
#ifdef TARGET_NR_ioctl
static void
print_syscall_ret_ioctl(CPUArchState *cpu_env, const struct syscallname *name,
abi_long ret, abi_long arg0, abi_long arg1,
abi_long arg2, abi_long arg3, abi_long arg4,
abi_long arg5)
{
if (!print_syscall_err(ret)) {
qemu_log(TARGET_ABI_FMT_ld, ret);
const IOCTLEntry *ie;
const argtype *arg_type;
void *argptr;
int target_size;
for (ie = ioctl_entries; ie->target_cmd != 0; ie++) {
if (ie->target_cmd == arg1) {
break;
}
}
if (ie->target_cmd == arg1 &&
(ie->access == IOC_R || ie->access == IOC_RW)) {
arg_type = ie->arg_type;
qemu_log(" (");
arg_type++;
target_size = thunk_type_size(arg_type, 0);
argptr = lock_user(VERIFY_READ, arg2, target_size, 1);
if (argptr) {
thunk_print(argptr, arg_type);
unlock_user(argptr, arg2, target_size);
} else {
print_pointer(arg2, 1);
}
qemu_log(")");
}
}
qemu_log("\n");
}
#endif
UNUSED static const struct flags access_flags[] = {
FLAG_GENERIC_MASK(F_OK, R_OK | W_OK | X_OK),
FLAG_GENERIC(R_OK),
FLAG_GENERIC(W_OK),
FLAG_GENERIC(X_OK),
FLAG_END,
};
UNUSED static const struct flags at_file_flags[] = {
#ifdef AT_EACCESS
FLAG_GENERIC(AT_EACCESS),