forked from freebsd/freebsd-src
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkdump.c
2219 lines (2099 loc) · 47.6 KB
/
kdump.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
/*-
* SPDX-License-Identifier: BSD-3-Clause
*
* Copyright (c) 1988, 1993
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef lint
static const char copyright[] =
"@(#) Copyright (c) 1988, 1993\n\
The Regents of the University of California. All rights reserved.\n";
#endif /* not lint */
#ifndef lint
#if 0
static char sccsid[] = "@(#)kdump.c 8.1 (Berkeley) 6/6/93";
#endif
#endif /* not lint */
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#define _WANT_KERNEL_ERRNO
#ifdef __LP64__
#define _WANT_KEVENT32
#endif
#define _WANT_FREEBSD11_KEVENT
#include <sys/param.h>
#include <sys/capsicum.h>
#include <sys/errno.h>
#include <sys/time.h>
#include <sys/uio.h>
#include <sys/event.h>
#include <sys/ktrace.h>
#include <sys/mman.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/sysent.h>
#include <sys/umtx.h>
#include <sys/un.h>
#include <sys/queue.h>
#include <sys/wait.h>
#ifdef WITH_CASPER
#include <sys/nv.h>
#endif
#include <arpa/inet.h>
#include <netinet/in.h>
#include <ctype.h>
#include <capsicum_helpers.h>
#include <err.h>
#include <grp.h>
#include <inttypes.h>
#include <locale.h>
#include <netdb.h>
#include <nl_types.h>
#include <pwd.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sysdecode.h>
#include <time.h>
#include <unistd.h>
#include <vis.h>
#include "ktrace.h"
#ifdef WITH_CASPER
#include <libcasper.h>
#include <casper/cap_grp.h>
#include <casper/cap_pwd.h>
#endif
int fetchprocinfo(struct ktr_header *, u_int *);
u_int findabi(struct ktr_header *);
int fread_tail(void *, int, int);
void dumpheader(struct ktr_header *, u_int);
void ktrsyscall(struct ktr_syscall *, u_int);
void ktrsysret(struct ktr_sysret *, u_int);
void ktrnamei(char *, int);
void hexdump(char *, int, int);
void visdump(char *, int, int);
void ktrgenio(struct ktr_genio *, int);
void ktrpsig(struct ktr_psig *);
void ktrcsw(struct ktr_csw *);
void ktrcsw_old(struct ktr_csw_old *);
void ktruser(int, void *);
void ktrcaprights(cap_rights_t *);
void ktritimerval(struct itimerval *it);
void ktrsockaddr(struct sockaddr *);
void ktrstat(struct stat *);
void ktrstruct(char *, size_t);
void ktrcapfail(struct ktr_cap_fail *);
void ktrfault(struct ktr_fault *);
void ktrfaultend(struct ktr_faultend *);
void ktrkevent(struct kevent *);
void ktrstructarray(struct ktr_struct_array *, size_t);
void usage(void);
#define TIMESTAMP_NONE 0x0
#define TIMESTAMP_ABSOLUTE 0x1
#define TIMESTAMP_ELAPSED 0x2
#define TIMESTAMP_RELATIVE 0x4
static bool abiflag, decimal, fancy = true, resolv, suppressdata, syscallno,
tail, threads;
static int timestamp, maxdata;
static const char *tracefile = DEF_TRACEFILE;
static struct ktr_header ktr_header;
#define TIME_FORMAT "%b %e %T %Y"
#define eqs(s1, s2) (strcmp((s1), (s2)) == 0)
#define print_number64(first,i,n,c) do { \
uint64_t __v; \
\
if (quad_align && (((ptrdiff_t)((i) - (first))) & 1) == 1) { \
(i)++; \
(n)--; \
} \
if (quad_slots == 2) \
__v = (uint64_t)(uint32_t)(i)[0] | \
((uint64_t)(uint32_t)(i)[1]) << 32; \
else \
__v = (uint64_t)*(i); \
if (decimal) \
printf("%c%jd", (c), (intmax_t)__v); \
else \
printf("%c%#jx", (c), (uintmax_t)__v); \
(i) += quad_slots; \
(n) -= quad_slots; \
(c) = ','; \
} while (0)
#define print_number(i,n,c) do { \
if (decimal) \
printf("%c%jd", c, (intmax_t)*i); \
else \
printf("%c%#jx", c, (uintmax_t)(u_register_t)*i); \
i++; \
n--; \
c = ','; \
} while (0)
struct proc_info
{
TAILQ_ENTRY(proc_info) info;
u_int sv_flags;
pid_t pid;
};
static TAILQ_HEAD(trace_procs, proc_info) trace_procs;
#ifdef WITH_CASPER
static cap_channel_t *cappwd, *capgrp;
static int
cappwdgrp_setup(cap_channel_t **cappwdp, cap_channel_t **capgrpp)
{
cap_channel_t *capcas, *cappwdloc, *capgrploc;
const char *cmds[1], *fields[1];
capcas = cap_init();
if (capcas == NULL) {
err(1, "unable to create casper process");
exit(1);
}
cappwdloc = cap_service_open(capcas, "system.pwd");
capgrploc = cap_service_open(capcas, "system.grp");
/* Casper capability no longer needed. */
cap_close(capcas);
if (cappwdloc == NULL || capgrploc == NULL) {
if (cappwdloc == NULL)
warn("unable to open system.pwd service");
if (capgrploc == NULL)
warn("unable to open system.grp service");
exit(1);
}
/* Limit system.pwd to only getpwuid() function and pw_name field. */
cmds[0] = "getpwuid";
if (cap_pwd_limit_cmds(cappwdloc, cmds, 1) < 0)
err(1, "unable to limit system.pwd service");
fields[0] = "pw_name";
if (cap_pwd_limit_fields(cappwdloc, fields, 1) < 0)
err(1, "unable to limit system.pwd service");
/* Limit system.grp to only getgrgid() function and gr_name field. */
cmds[0] = "getgrgid";
if (cap_grp_limit_cmds(capgrploc, cmds, 1) < 0)
err(1, "unable to limit system.grp service");
fields[0] = "gr_name";
if (cap_grp_limit_fields(capgrploc, fields, 1) < 0)
err(1, "unable to limit system.grp service");
*cappwdp = cappwdloc;
*capgrpp = capgrploc;
return (0);
}
#endif /* WITH_CASPER */
static void
print_integer_arg(const char *(*decoder)(int), int value)
{
const char *str;
str = decoder(value);
if (str != NULL)
printf("%s", str);
else {
if (decimal)
printf("<invalid=%d>", value);
else
printf("<invalid=%#x>", value);
}
}
/* Like print_integer_arg but unknown values are treated as valid. */
static void
print_integer_arg_valid(const char *(*decoder)(int), int value)
{
const char *str;
str = decoder(value);
if (str != NULL)
printf("%s", str);
else {
if (decimal)
printf("%d", value);
else
printf("%#x", value);
}
}
static bool
print_mask_arg_part(bool (*decoder)(FILE *, int, int *), int value, int *rem)
{
printf("%#x<", value);
return (decoder(stdout, value, rem));
}
static void
print_mask_arg(bool (*decoder)(FILE *, int, int *), int value)
{
bool invalid;
int rem;
invalid = !print_mask_arg_part(decoder, value, &rem);
printf(">");
if (invalid)
printf("<invalid>%u", rem);
}
static void
print_mask_arg0(bool (*decoder)(FILE *, int, int *), int value)
{
bool invalid;
int rem;
if (value == 0) {
printf("0");
return;
}
printf("%#x<", value);
invalid = !decoder(stdout, value, &rem);
printf(">");
if (invalid)
printf("<invalid>%u", rem);
}
static void
decode_fileflags(fflags_t value)
{
bool invalid;
fflags_t rem;
if (value == 0) {
printf("0");
return;
}
printf("%#x<", value);
invalid = !sysdecode_fileflags(stdout, value, &rem);
printf(">");
if (invalid)
printf("<invalid>%u", rem);
}
static void
decode_filemode(int value)
{
bool invalid;
int rem;
if (value == 0) {
printf("0");
return;
}
printf("%#o<", value);
invalid = !sysdecode_filemode(stdout, value, &rem);
printf(">");
if (invalid)
printf("<invalid>%u", rem);
}
static void
print_mask_arg32(bool (*decoder)(FILE *, uint32_t, uint32_t *), uint32_t value)
{
bool invalid;
uint32_t rem;
printf("%#x<", value);
invalid = !decoder(stdout, value, &rem);
printf(">");
if (invalid)
printf("<invalid>%u", rem);
}
static void
print_mask_argul(bool (*decoder)(FILE *, u_long, u_long *), u_long value)
{
bool invalid;
u_long rem;
if (value == 0) {
printf("0");
return;
}
printf("%#lx<", value);
invalid = !decoder(stdout, value, &rem);
printf(">");
if (invalid)
printf("<invalid>%lu", rem);
}
int
main(int argc, char *argv[])
{
int ch, ktrlen, size;
void *m;
int trpoints = ALL_POINTS;
int drop_logged;
pid_t pid = 0;
u_int sv_flags;
setlocale(LC_CTYPE, "");
timestamp = TIMESTAMP_NONE;
while ((ch = getopt(argc,argv,"f:dElm:np:AHRrSsTt:")) != -1)
switch (ch) {
case 'A':
abiflag = true;
break;
case 'f':
tracefile = optarg;
break;
case 'd':
decimal = true;
break;
case 'l':
tail = true;
break;
case 'm':
maxdata = atoi(optarg);
break;
case 'n':
fancy = false;
break;
case 'p':
pid = atoi(optarg);
break;
case 'r':
resolv = true;
break;
case 'S':
syscallno = true;
break;
case 's':
suppressdata = true;
break;
case 'E':
timestamp |= TIMESTAMP_ELAPSED;
break;
case 'H':
threads = true;
break;
case 'R':
timestamp |= TIMESTAMP_RELATIVE;
break;
case 'T':
timestamp |= TIMESTAMP_ABSOLUTE;
break;
case 't':
trpoints = getpoints(optarg);
if (trpoints < 0)
errx(1, "unknown trace point in %s", optarg);
break;
default:
usage();
}
if (argc > optind)
usage();
m = malloc(size = 1025);
if (m == NULL)
errx(1, "%s", strerror(ENOMEM));
if (strcmp(tracefile, "-") != 0)
if (!freopen(tracefile, "r", stdin))
err(1, "%s", tracefile);
caph_cache_catpages();
caph_cache_tzdata();
#ifdef WITH_CASPER
if (resolv) {
if (cappwdgrp_setup(&cappwd, &capgrp) < 0) {
cappwd = NULL;
capgrp = NULL;
}
}
if (!resolv || (cappwd != NULL && capgrp != NULL)) {
if (caph_enter() < 0)
err(1, "unable to enter capability mode");
}
#else
if (!resolv) {
if (caph_enter() < 0)
err(1, "unable to enter capability mode");
}
#endif
if (caph_limit_stdio() == -1)
err(1, "unable to limit stdio");
TAILQ_INIT(&trace_procs);
drop_logged = 0;
while (fread_tail(&ktr_header, sizeof(struct ktr_header), 1)) {
if (ktr_header.ktr_type & KTR_DROP) {
ktr_header.ktr_type &= ~KTR_DROP;
if (!drop_logged && threads) {
printf(
"%6jd %6jd %-8.*s Events dropped.\n",
(intmax_t)ktr_header.ktr_pid,
ktr_header.ktr_tid > 0 ?
(intmax_t)ktr_header.ktr_tid : 0,
MAXCOMLEN, ktr_header.ktr_comm);
drop_logged = 1;
} else if (!drop_logged) {
printf("%6jd %-8.*s Events dropped.\n",
(intmax_t)ktr_header.ktr_pid, MAXCOMLEN,
ktr_header.ktr_comm);
drop_logged = 1;
}
}
if ((ktrlen = ktr_header.ktr_len) < 0)
errx(1, "bogus length 0x%x", ktrlen);
if (ktrlen > size) {
m = realloc(m, ktrlen+1);
if (m == NULL)
errx(1, "%s", strerror(ENOMEM));
size = ktrlen;
}
if (ktrlen && fread_tail(m, ktrlen, 1) == 0)
errx(1, "data too short");
if (fetchprocinfo(&ktr_header, (u_int *)m) != 0)
continue;
if (pid && ktr_header.ktr_pid != pid &&
ktr_header.ktr_tid != pid)
continue;
if ((trpoints & (1<<ktr_header.ktr_type)) == 0)
continue;
sv_flags = findabi(&ktr_header);
dumpheader(&ktr_header, sv_flags);
drop_logged = 0;
switch (ktr_header.ktr_type) {
case KTR_SYSCALL:
ktrsyscall((struct ktr_syscall *)m, sv_flags);
break;
case KTR_SYSRET:
ktrsysret((struct ktr_sysret *)m, sv_flags);
break;
case KTR_NAMEI:
case KTR_SYSCTL:
ktrnamei(m, ktrlen);
break;
case KTR_GENIO:
ktrgenio((struct ktr_genio *)m, ktrlen);
break;
case KTR_PSIG:
ktrpsig((struct ktr_psig *)m);
break;
case KTR_CSW:
if (ktrlen == sizeof(struct ktr_csw_old))
ktrcsw_old((struct ktr_csw_old *)m);
else
ktrcsw((struct ktr_csw *)m);
break;
case KTR_USER:
ktruser(ktrlen, m);
break;
case KTR_STRUCT:
ktrstruct(m, ktrlen);
break;
case KTR_CAPFAIL:
ktrcapfail((struct ktr_cap_fail *)m);
break;
case KTR_FAULT:
ktrfault((struct ktr_fault *)m);
break;
case KTR_FAULTEND:
ktrfaultend((struct ktr_faultend *)m);
break;
case KTR_STRUCT_ARRAY:
ktrstructarray((struct ktr_struct_array *)m, ktrlen);
break;
default:
printf("\n");
break;
}
if (tail)
fflush(stdout);
}
return 0;
}
int
fread_tail(void *buf, int size, int num)
{
int i;
while ((i = fread(buf, size, num, stdin)) == 0 && tail) {
sleep(1);
clearerr(stdin);
}
return (i);
}
int
fetchprocinfo(struct ktr_header *kth, u_int *flags)
{
struct proc_info *pi;
switch (kth->ktr_type) {
case KTR_PROCCTOR:
TAILQ_FOREACH(pi, &trace_procs, info) {
if (pi->pid == kth->ktr_pid) {
TAILQ_REMOVE(&trace_procs, pi, info);
break;
}
}
pi = malloc(sizeof(struct proc_info));
if (pi == NULL)
errx(1, "%s", strerror(ENOMEM));
pi->sv_flags = *flags;
pi->pid = kth->ktr_pid;
TAILQ_INSERT_TAIL(&trace_procs, pi, info);
return (1);
case KTR_PROCDTOR:
TAILQ_FOREACH(pi, &trace_procs, info) {
if (pi->pid == kth->ktr_pid) {
TAILQ_REMOVE(&trace_procs, pi, info);
free(pi);
break;
}
}
return (1);
}
return (0);
}
u_int
findabi(struct ktr_header *kth)
{
struct proc_info *pi;
TAILQ_FOREACH(pi, &trace_procs, info) {
if (pi->pid == kth->ktr_pid) {
return (pi->sv_flags);
}
}
return (0);
}
void
dumpheader(struct ktr_header *kth, u_int sv_flags)
{
static char unknown[64];
static struct timeval prevtime, prevtime_e;
struct timeval temp;
const char *abi;
const char *arch;
const char *type;
const char *sign;
switch (kth->ktr_type) {
case KTR_SYSCALL:
type = "CALL";
break;
case KTR_SYSRET:
type = "RET ";
break;
case KTR_NAMEI:
type = "NAMI";
break;
case KTR_GENIO:
type = "GIO ";
break;
case KTR_PSIG:
type = "PSIG";
break;
case KTR_CSW:
type = "CSW ";
break;
case KTR_USER:
type = "USER";
break;
case KTR_STRUCT:
case KTR_STRUCT_ARRAY:
type = "STRU";
break;
case KTR_SYSCTL:
type = "SCTL";
break;
case KTR_CAPFAIL:
type = "CAP ";
break;
case KTR_FAULT:
type = "PFLT";
break;
case KTR_FAULTEND:
type = "PRET";
break;
default:
sprintf(unknown, "UNKNOWN(%d)", kth->ktr_type);
type = unknown;
}
/*
* The ktr_tid field was previously the ktr_buffer field, which held
* the kernel pointer value for the buffer associated with data
* following the record header. It now holds a threadid, but only
* for trace files after the change. Older trace files still contain
* kernel pointers. Detect this and suppress the results by printing
* negative tid's as 0.
*/
if (threads)
printf("%6jd %6jd %-8.*s ", (intmax_t)kth->ktr_pid,
kth->ktr_tid > 0 ? (intmax_t)kth->ktr_tid : 0,
MAXCOMLEN, kth->ktr_comm);
else
printf("%6jd %-8.*s ", (intmax_t)kth->ktr_pid, MAXCOMLEN,
kth->ktr_comm);
if (timestamp) {
if (timestamp & TIMESTAMP_ABSOLUTE) {
printf("%jd.%06ld ", (intmax_t)kth->ktr_time.tv_sec,
kth->ktr_time.tv_usec);
}
if (timestamp & TIMESTAMP_ELAPSED) {
if (prevtime_e.tv_sec == 0)
prevtime_e = kth->ktr_time;
timersub(&kth->ktr_time, &prevtime_e, &temp);
printf("%jd.%06ld ", (intmax_t)temp.tv_sec,
temp.tv_usec);
}
if (timestamp & TIMESTAMP_RELATIVE) {
if (prevtime.tv_sec == 0)
prevtime = kth->ktr_time;
if (timercmp(&kth->ktr_time, &prevtime, <)) {
timersub(&prevtime, &kth->ktr_time, &temp);
sign = "-";
} else {
timersub(&kth->ktr_time, &prevtime, &temp);
sign = "";
}
prevtime = kth->ktr_time;
printf("%s%jd.%06ld ", sign, (intmax_t)temp.tv_sec,
temp.tv_usec);
}
}
printf("%s ", type);
if (abiflag != 0) {
switch (sv_flags & SV_ABI_MASK) {
case SV_ABI_LINUX:
abi = "L";
break;
case SV_ABI_FREEBSD:
abi = "F";
break;
case SV_ABI_CLOUDABI:
abi = "C";
break;
default:
abi = "U";
break;
}
if ((sv_flags & SV_LP64) != 0)
arch = "64";
else if ((sv_flags & SV_ILP32) != 0)
arch = "32";
else
arch = "00";
printf("%s%s ", abi, arch);
}
}
#include <sys/syscall.h>
static void
ioctlname(unsigned long val)
{
const char *str;
str = sysdecode_ioctlname(val);
if (str != NULL)
printf("%s", str);
else if (decimal)
printf("%lu", val);
else
printf("%#lx", val);
}
static enum sysdecode_abi
syscallabi(u_int sv_flags)
{
if (sv_flags == 0)
return (SYSDECODE_ABI_FREEBSD);
switch (sv_flags & SV_ABI_MASK) {
case SV_ABI_FREEBSD:
return (SYSDECODE_ABI_FREEBSD);
case SV_ABI_LINUX:
#ifdef __LP64__
if (sv_flags & SV_ILP32)
return (SYSDECODE_ABI_LINUX32);
#endif
return (SYSDECODE_ABI_LINUX);
case SV_ABI_CLOUDABI:
return (SYSDECODE_ABI_CLOUDABI64);
default:
return (SYSDECODE_ABI_UNKNOWN);
}
}
static void
syscallname(u_int code, u_int sv_flags)
{
const char *name;
name = sysdecode_syscallname(syscallabi(sv_flags), code);
if (name == NULL)
printf("[%d]", code);
else {
printf("%s", name);
if (syscallno)
printf("[%d]", code);
}
}
static void
print_signal(int signo)
{
const char *signame;
signame = sysdecode_signal(signo);
if (signame != NULL)
printf("%s", signame);
else
printf("SIG %d", signo);
}
void
ktrsyscall(struct ktr_syscall *ktr, u_int sv_flags)
{
int narg = ktr->ktr_narg;
register_t *ip, *first;
intmax_t arg;
int quad_align, quad_slots;
syscallname(ktr->ktr_code, sv_flags);
ip = first = &ktr->ktr_args[0];
if (narg) {
char c = '(';
if (fancy &&
(sv_flags == 0 ||
(sv_flags & SV_ABI_MASK) == SV_ABI_FREEBSD)) {
quad_align = 0;
if (sv_flags & SV_ILP32) {
#ifdef __powerpc__
quad_align = 1;
#endif
quad_slots = 2;
} else
quad_slots = 1;
switch (ktr->ktr_code) {
case SYS_bindat:
case SYS_chflagsat:
case SYS_connectat:
case SYS_faccessat:
case SYS_fchmodat:
case SYS_fchownat:
case SYS_fstatat:
case SYS_futimesat:
case SYS_linkat:
case SYS_mkdirat:
case SYS_mkfifoat:
case SYS_mknodat:
case SYS_openat:
case SYS_readlinkat:
case SYS_renameat:
case SYS_unlinkat:
case SYS_utimensat:
putchar('(');
print_integer_arg_valid(sysdecode_atfd, *ip);
c = ',';
ip++;
narg--;
break;
}
switch (ktr->ktr_code) {
case SYS_ioctl: {
print_number(ip, narg, c);
putchar(c);
ioctlname(*ip);
c = ',';
ip++;
narg--;
break;
}
case SYS_ptrace:
putchar('(');
print_integer_arg(sysdecode_ptrace_request, *ip);
c = ',';
ip++;
narg--;
break;
case SYS_access:
case SYS_eaccess:
case SYS_faccessat:
print_number(ip, narg, c);
putchar(',');
print_mask_arg(sysdecode_access_mode, *ip);
ip++;
narg--;
break;
case SYS_open:
case SYS_openat:
print_number(ip, narg, c);
putchar(',');
print_mask_arg(sysdecode_open_flags, ip[0]);
if ((ip[0] & O_CREAT) == O_CREAT) {
putchar(',');
decode_filemode(ip[1]);
}
ip += 2;
narg -= 2;
break;
case SYS_wait4:
print_number(ip, narg, c);
print_number(ip, narg, c);
putchar(',');
print_mask_arg0(sysdecode_wait4_options, *ip);
ip++;
narg--;
break;
case SYS_wait6:
putchar('(');
print_integer_arg(sysdecode_idtype, *ip);
c = ',';
ip++;
narg--;
print_number64(first, ip, narg, c);
print_number(ip, narg, c);
putchar(',');
print_mask_arg(sysdecode_wait6_options, *ip);
ip++;
narg--;
break;
case SYS_chmod:
case SYS_fchmod:
case SYS_lchmod:
case SYS_fchmodat:
print_number(ip, narg, c);
putchar(',');
decode_filemode(*ip);
ip++;
narg--;
break;
case SYS_mknodat:
print_number(ip, narg, c);
putchar(',');
decode_filemode(*ip);
ip++;
narg--;
break;
case SYS_getfsstat:
print_number(ip, narg, c);
print_number(ip, narg, c);
putchar(',');
print_integer_arg(sysdecode_getfsstat_mode, *ip);
ip++;
narg--;
break;
case SYS_mount:
print_number(ip, narg, c);
print_number(ip, narg, c);
putchar(',');
print_mask_arg(sysdecode_mount_flags, *ip);
ip++;
narg--;
break;
case SYS_unmount:
print_number(ip, narg, c);
putchar(',');
print_mask_arg(sysdecode_mount_flags, *ip);
ip++;
narg--;
break;
case SYS_recvmsg:
case SYS_sendmsg:
print_number(ip, narg, c);
print_number(ip, narg, c);
putchar(',');
print_mask_arg0(sysdecode_msg_flags, *ip);
ip++;
narg--;
break;
case SYS_recvfrom:
case SYS_sendto:
print_number(ip, narg, c);
print_number(ip, narg, c);
print_number(ip, narg, c);
putchar(',');
print_mask_arg0(sysdecode_msg_flags, *ip);
ip++;
narg--;
break;
case SYS_chflags:
case SYS_chflagsat:
case SYS_fchflags:
case SYS_lchflags:
print_number(ip, narg, c);
putchar(',');
decode_fileflags(*ip);
ip++;
narg--;
break;
case SYS_kill:
print_number(ip, narg, c);
putchar(',');
print_signal(*ip);
ip++;
narg--;
break;
case SYS_reboot:
putchar('(');
print_mask_arg(sysdecode_reboot_howto, *ip);
ip++;
narg--;
break;
case SYS_umask:
putchar('(');
decode_filemode(*ip);
ip++;
narg--;
break;
case SYS_msync:
print_number(ip, narg, c);
print_number(ip, narg, c);
putchar(',');
print_mask_arg(sysdecode_msync_flags, *ip);
ip++;
narg--;
break;