-
Notifications
You must be signed in to change notification settings - Fork 9
/
process.c
2677 lines (2582 loc) · 67.1 KB
/
process.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
/*
* Copyright (c) 1991, 1992 Paul Kranenburg <[email protected]>
* Copyright (c) 1993 Branko Lankester <[email protected]>
* Copyright (c) 1993, 1994, 1995, 1996 Rick Sladkey <[email protected]>
* Copyright (c) 1996-1999 Wichert Akkerman <[email protected]>
* Copyright (c) 1999 IBM Deutschland Entwicklung GmbH, IBM Corporation
* Linux for s390 port by D.J. Barrow
* Copyright (c) 2000 PocketPenguins Inc. Linux for Hitachi SuperH
* port by Greg Banks <[email protected]>
*
* 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. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
*/
#include "defs.h"
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <sys/resource.h>
#include <sys/utsname.h>
#include <sys/user.h>
#ifdef HAVE_SYS_REG_H
# include <sys/reg.h>
# ifndef PTRACE_PEEKUSR
# define PTRACE_PEEKUSR PTRACE_PEEKUSER
# endif
# ifndef PTRACE_POKEUSR
# define PTRACE_POKEUSR PTRACE_POKEUSER
# endif
#endif
#ifdef HAVE_LINUX_PTRACE_H
# undef PTRACE_SYSCALL
# ifdef HAVE_STRUCT_IA64_FPREG
# define ia64_fpreg XXX_ia64_fpreg
# endif
# ifdef HAVE_STRUCT_PT_ALL_USER_REGS
# define pt_all_user_regs XXX_pt_all_user_regs
# endif
# include <linux/ptrace.h>
# undef ia64_fpreg
# undef pt_all_user_regs
#endif
#if defined(SPARC64)
# define r_pc r_tpc
# undef PTRACE_GETREGS
# define PTRACE_GETREGS PTRACE_GETREGS64
# undef PTRACE_SETREGS
# define PTRACE_SETREGS PTRACE_SETREGS64
#endif
#ifdef HAVE_LINUX_FUTEX_H
# include <linux/futex.h>
#endif
#ifndef FUTEX_WAIT
# define FUTEX_WAIT 0
#endif
#ifndef FUTEX_WAKE
# define FUTEX_WAKE 1
#endif
#ifndef FUTEX_FD
# define FUTEX_FD 2
#endif
#ifndef FUTEX_REQUEUE
# define FUTEX_REQUEUE 3
#endif
#include <sched.h>
#include <asm/posix_types.h>
#undef GETGROUPS_T
#define GETGROUPS_T __kernel_gid_t
#undef GETGROUPS32_T
#define GETGROUPS32_T __kernel_gid32_t
#if defined(IA64)
# include <asm/ptrace_offsets.h>
# include <asm/rse.h>
#endif
#ifdef HAVE_PRCTL
# include <sys/prctl.h>
static const struct xlat prctl_options[] = {
#ifdef PR_MAXPROCS
{ PR_MAXPROCS, "PR_MAXPROCS" },
#endif
#ifdef PR_ISBLOCKED
{ PR_ISBLOCKED, "PR_ISBLOCKED" },
#endif
#ifdef PR_SETSTACKSIZE
{ PR_SETSTACKSIZE, "PR_SETSTACKSIZE" },
#endif
#ifdef PR_GETSTACKSIZE
{ PR_GETSTACKSIZE, "PR_GETSTACKSIZE" },
#endif
#ifdef PR_MAXPPROCS
{ PR_MAXPPROCS, "PR_MAXPPROCS" },
#endif
#ifdef PR_UNBLKONEXEC
{ PR_UNBLKONEXEC, "PR_UNBLKONEXEC" },
#endif
#ifdef PR_ATOMICSIM
{ PR_ATOMICSIM, "PR_ATOMICSIM" },
#endif
#ifdef PR_SETEXITSIG
{ PR_SETEXITSIG, "PR_SETEXITSIG" },
#endif
#ifdef PR_RESIDENT
{ PR_RESIDENT, "PR_RESIDENT" },
#endif
#ifdef PR_ATTACHADDR
{ PR_ATTACHADDR, "PR_ATTACHADDR" },
#endif
#ifdef PR_DETACHADDR
{ PR_DETACHADDR, "PR_DETACHADDR" },
#endif
#ifdef PR_TERMCHILD
{ PR_TERMCHILD, "PR_TERMCHILD" },
#endif
#ifdef PR_GETSHMASK
{ PR_GETSHMASK, "PR_GETSHMASK" },
#endif
#ifdef PR_GETNSHARE
{ PR_GETNSHARE, "PR_GETNSHARE" },
#endif
#ifdef PR_COREPID
{ PR_COREPID, "PR_COREPID" },
#endif
#ifdef PR_ATTACHADDRPERM
{ PR_ATTACHADDRPERM, "PR_ATTACHADDRPERM" },
#endif
#ifdef PR_PTHREADEXIT
{ PR_PTHREADEXIT, "PR_PTHREADEXIT" },
#endif
#ifdef PR_SET_PDEATHSIG
{ PR_SET_PDEATHSIG, "PR_SET_PDEATHSIG" },
#endif
#ifdef PR_GET_PDEATHSIG
{ PR_GET_PDEATHSIG, "PR_GET_PDEATHSIG" },
#endif
#ifdef PR_GET_DUMPABLE
{ PR_GET_DUMPABLE, "PR_GET_DUMPABLE" },
#endif
#ifdef PR_SET_DUMPABLE
{ PR_SET_DUMPABLE, "PR_SET_DUMPABLE" },
#endif
#ifdef PR_GET_UNALIGN
{ PR_GET_UNALIGN, "PR_GET_UNALIGN" },
#endif
#ifdef PR_SET_UNALIGN
{ PR_SET_UNALIGN, "PR_SET_UNALIGN" },
#endif
#ifdef PR_GET_KEEPCAPS
{ PR_GET_KEEPCAPS, "PR_GET_KEEPCAPS" },
#endif
#ifdef PR_SET_KEEPCAPS
{ PR_SET_KEEPCAPS, "PR_SET_KEEPCAPS" },
#endif
#ifdef PR_GET_FPEMU
{ PR_GET_FPEMU, "PR_GET_FPEMU" },
#endif
#ifdef PR_SET_FPEMU
{ PR_SET_FPEMU, "PR_SET_FPEMU" },
#endif
#ifdef PR_GET_FPEXC
{ PR_GET_FPEXC, "PR_GET_FPEXC" },
#endif
#ifdef PR_SET_FPEXC
{ PR_SET_FPEXC, "PR_SET_FPEXC" },
#endif
#ifdef PR_GET_TIMING
{ PR_GET_TIMING, "PR_GET_TIMING" },
#endif
#ifdef PR_SET_TIMING
{ PR_SET_TIMING, "PR_SET_TIMING" },
#endif
#ifdef PR_SET_NAME
{ PR_SET_NAME, "PR_SET_NAME" },
#endif
#ifdef PR_GET_NAME
{ PR_GET_NAME, "PR_GET_NAME" },
#endif
#ifdef PR_GET_ENDIAN
{ PR_GET_ENDIAN, "PR_GET_ENDIAN" },
#endif
#ifdef PR_SET_ENDIAN
{ PR_SET_ENDIAN, "PR_SET_ENDIAN" },
#endif
#ifdef PR_GET_SECCOMP
{ PR_GET_SECCOMP, "PR_GET_SECCOMP" },
#endif
#ifdef PR_SET_SECCOMP
{ PR_SET_SECCOMP, "PR_SET_SECCOMP" },
#endif
#ifdef PR_GET_TSC
{ PR_GET_TSC, "PR_GET_TSC" },
#endif
#ifdef PR_SET_TSC
{ PR_SET_TSC, "PR_SET_TSC" },
#endif
#ifdef PR_GET_SECUREBITS
{ PR_GET_SECUREBITS, "PR_GET_SECUREBITS" },
#endif
#ifdef PR_SET_SECUREBITS
{ PR_SET_SECUREBITS, "PR_SET_SECUREBITS" },
#endif
{ 0, NULL },
};
static const char *
unalignctl_string(unsigned int ctl)
{
static char buf[sizeof(int)*2 + 2];
switch (ctl) {
#ifdef PR_UNALIGN_NOPRINT
case PR_UNALIGN_NOPRINT:
return "NOPRINT";
#endif
#ifdef PR_UNALIGN_SIGBUS
case PR_UNALIGN_SIGBUS:
return "SIGBUS";
#endif
default:
break;
}
sprintf(buf, "%x", ctl);
return buf;
}
int
sys_prctl(struct tcb *tcp)
{
int i;
if (entering(tcp)) {
printxval(prctl_options, tcp->u_arg[0], "PR_???");
switch (tcp->u_arg[0]) {
#ifdef PR_GETNSHARE
case PR_GETNSHARE:
break;
#endif
#ifdef PR_SET_PDEATHSIG
case PR_SET_PDEATHSIG:
tprintf(", %lu", tcp->u_arg[1]);
break;
#endif
#ifdef PR_GET_PDEATHSIG
case PR_GET_PDEATHSIG:
break;
#endif
#ifdef PR_SET_DUMPABLE
case PR_SET_DUMPABLE:
tprintf(", %lu", tcp->u_arg[1]);
break;
#endif
#ifdef PR_GET_DUMPABLE
case PR_GET_DUMPABLE:
break;
#endif
#ifdef PR_SET_UNALIGN
case PR_SET_UNALIGN:
tprintf(", %s", unalignctl_string(tcp->u_arg[1]));
break;
#endif
#ifdef PR_GET_UNALIGN
case PR_GET_UNALIGN:
tprintf(", %#lx", tcp->u_arg[1]);
break;
#endif
#ifdef PR_SET_KEEPCAPS
case PR_SET_KEEPCAPS:
tprintf(", %lu", tcp->u_arg[1]);
break;
#endif
#ifdef PR_GET_KEEPCAPS
case PR_GET_KEEPCAPS:
break;
#endif
default:
for (i = 1; i < tcp->u_nargs; i++)
tprintf(", %#lx", tcp->u_arg[i]);
break;
}
} else {
switch (tcp->u_arg[0]) {
#ifdef PR_GET_PDEATHSIG
case PR_GET_PDEATHSIG:
if (umove(tcp, tcp->u_arg[1], &i) < 0)
tprintf(", %#lx", tcp->u_arg[1]);
else
tprintf(", {%u}", i);
break;
#endif
#ifdef PR_GET_DUMPABLE
case PR_GET_DUMPABLE:
return RVAL_UDECIMAL;
#endif
#ifdef PR_GET_UNALIGN
case PR_GET_UNALIGN:
if (syserror(tcp) || umove(tcp, tcp->u_arg[1], &i) < 0)
break;
tcp->auxstr = unalignctl_string(i);
return RVAL_STR;
#endif
#ifdef PR_GET_KEEPCAPS
case PR_GET_KEEPCAPS:
return RVAL_UDECIMAL;
#endif
default:
break;
}
}
return 0;
}
#endif /* HAVE_PRCTL */
int
sys_sethostname(struct tcb *tcp)
{
if (entering(tcp)) {
printpathn(tcp, tcp->u_arg[0], tcp->u_arg[1]);
tprintf(", %lu", tcp->u_arg[1]);
}
return 0;
}
#if defined(ALPHA)
int
sys_gethostname(struct tcb *tcp)
{
if (exiting(tcp)) {
if (syserror(tcp))
tprintf("%#lx", tcp->u_arg[0]);
else
printpath(tcp, tcp->u_arg[0]);
tprintf(", %lu", tcp->u_arg[1]);
}
return 0;
}
#endif
int
sys_setdomainname(struct tcb *tcp)
{
if (entering(tcp)) {
printpathn(tcp, tcp->u_arg[0], tcp->u_arg[1]);
tprintf(", %lu", tcp->u_arg[1]);
}
return 0;
}
int
sys_exit(struct tcb *tcp)
{
if (exiting(tcp)) {
fprintf(stderr, "_exit returned!\n");
return -1;
}
/* special case: we stop tracing this process, finish line now */
tprintf("%ld) ", tcp->u_arg[0]);
tabto();
tprints("= ?\n");
line_ended();
return 0;
}
/* defines copied from linux/sched.h since we can't include that
* ourselves (it conflicts with *lots* of libc includes)
*/
#define CSIGNAL 0x000000ff /* signal mask to be sent at exit */
#define CLONE_VM 0x00000100 /* set if VM shared between processes */
#define CLONE_FS 0x00000200 /* set if fs info shared between processes */
#define CLONE_FILES 0x00000400 /* set if open files shared between processes */
#define CLONE_SIGHAND 0x00000800 /* set if signal handlers shared */
#define CLONE_IDLETASK 0x00001000 /* kernel-only flag */
#define CLONE_PTRACE 0x00002000 /* set if we want to let tracing continue on the child too */
#define CLONE_VFORK 0x00004000 /* set if the parent wants the child to wake it up on mm_release */
#define CLONE_PARENT 0x00008000 /* set if we want to have the same parent as the cloner */
#define CLONE_THREAD 0x00010000 /* Same thread group? */
#define CLONE_NEWNS 0x00020000 /* New namespace group? */
#define CLONE_SYSVSEM 0x00040000 /* share system V SEM_UNDO semantics */
#define CLONE_SETTLS 0x00080000 /* create a new TLS for the child */
#define CLONE_PARENT_SETTID 0x00100000 /* set the TID in the parent */
#define CLONE_CHILD_CLEARTID 0x00200000 /* clear the TID in the child */
#define CLONE_UNTRACED 0x00800000 /* set if the tracing process can't force CLONE_PTRACE on this clone */
#define CLONE_CHILD_SETTID 0x01000000 /* set the TID in the child */
#define CLONE_STOPPED 0x02000000 /* Start in stopped state */
#define CLONE_NEWUTS 0x04000000 /* New utsname group? */
#define CLONE_NEWIPC 0x08000000 /* New ipcs */
#define CLONE_NEWUSER 0x10000000 /* New user namespace */
#define CLONE_NEWPID 0x20000000 /* New pid namespace */
#define CLONE_NEWNET 0x40000000 /* New network namespace */
#define CLONE_IO 0x80000000 /* Clone io context */
static const struct xlat clone_flags[] = {
{ CLONE_VM, "CLONE_VM" },
{ CLONE_FS, "CLONE_FS" },
{ CLONE_FILES, "CLONE_FILES" },
{ CLONE_SIGHAND, "CLONE_SIGHAND" },
{ CLONE_IDLETASK, "CLONE_IDLETASK" },
{ CLONE_PTRACE, "CLONE_PTRACE" },
{ CLONE_VFORK, "CLONE_VFORK" },
{ CLONE_PARENT, "CLONE_PARENT" },
{ CLONE_THREAD, "CLONE_THREAD" },
{ CLONE_NEWNS, "CLONE_NEWNS" },
{ CLONE_SYSVSEM, "CLONE_SYSVSEM" },
{ CLONE_SETTLS, "CLONE_SETTLS" },
{ CLONE_PARENT_SETTID, "CLONE_PARENT_SETTID" },
{ CLONE_CHILD_CLEARTID, "CLONE_CHILD_CLEARTID" },
{ CLONE_UNTRACED, "CLONE_UNTRACED" },
{ CLONE_CHILD_SETTID, "CLONE_CHILD_SETTID" },
{ CLONE_STOPPED, "CLONE_STOPPED" },
{ CLONE_NEWUTS, "CLONE_NEWUTS" },
{ CLONE_NEWIPC, "CLONE_NEWIPC" },
{ CLONE_NEWUSER, "CLONE_NEWUSER" },
{ CLONE_NEWPID, "CLONE_NEWPID" },
{ CLONE_NEWNET, "CLONE_NEWNET" },
{ CLONE_IO, "CLONE_IO" },
{ 0, NULL },
};
#ifdef I386
# include <asm/ldt.h>
# ifdef HAVE_STRUCT_USER_DESC
# define modify_ldt_ldt_s user_desc
# endif
extern void print_ldt_entry();
#endif
#if defined IA64
# define ARG_FLAGS 0
# define ARG_STACK 1
# define ARG_STACKSIZE (tcp->scno == SYS_clone2 ? 2 : -1)
# define ARG_PTID (tcp->scno == SYS_clone2 ? 3 : 2)
# define ARG_CTID (tcp->scno == SYS_clone2 ? 4 : 3)
# define ARG_TLS (tcp->scno == SYS_clone2 ? 5 : 4)
#elif defined S390 || defined S390X || defined CRISV10 || defined CRISV32
# define ARG_STACK 0
# define ARG_FLAGS 1
# define ARG_PTID 2
# define ARG_CTID 3
# define ARG_TLS 4
#elif defined X86_64 || defined X32 || defined ALPHA
# define ARG_FLAGS 0
# define ARG_STACK 1
# define ARG_PTID 2
# define ARG_CTID 3
# define ARG_TLS 4
#else
# define ARG_FLAGS 0
# define ARG_STACK 1
# define ARG_PTID 2
# define ARG_TLS 3
# define ARG_CTID 4
#endif
int
sys_clone(struct tcb *tcp)
{
if (exiting(tcp)) {
const char *sep = "|";
unsigned long flags = tcp->u_arg[ARG_FLAGS];
tprintf("child_stack=%#lx, ", tcp->u_arg[ARG_STACK]);
#ifdef ARG_STACKSIZE
if (ARG_STACKSIZE != -1)
tprintf("stack_size=%#lx, ",
tcp->u_arg[ARG_STACKSIZE]);
#endif
tprints("flags=");
if (!printflags(clone_flags, flags &~ CSIGNAL, NULL))
sep = "";
if ((flags & CSIGNAL) != 0)
tprintf("%s%s", sep, signame(flags & CSIGNAL));
if ((flags & (CLONE_PARENT_SETTID|CLONE_CHILD_SETTID
|CLONE_CHILD_CLEARTID|CLONE_SETTLS)) == 0)
return 0;
if (flags & CLONE_PARENT_SETTID)
tprintf(", parent_tidptr=%#lx", tcp->u_arg[ARG_PTID]);
if (flags & CLONE_SETTLS) {
#ifdef I386
struct modify_ldt_ldt_s copy;
if (umove(tcp, tcp->u_arg[ARG_TLS], ©) != -1) {
tprintf(", {entry_number:%d, ",
copy.entry_number);
if (!verbose(tcp))
tprints("...}");
else
print_ldt_entry(©);
}
else
#endif
tprintf(", tls=%#lx", tcp->u_arg[ARG_TLS]);
}
if (flags & (CLONE_CHILD_SETTID|CLONE_CHILD_CLEARTID))
tprintf(", child_tidptr=%#lx", tcp->u_arg[ARG_CTID]);
}
return 0;
}
int
sys_unshare(struct tcb *tcp)
{
if (entering(tcp))
printflags(clone_flags, tcp->u_arg[0], "CLONE_???");
return 0;
}
int
sys_fork(struct tcb *tcp)
{
if (exiting(tcp))
return RVAL_UDECIMAL;
return 0;
}
int
sys_vfork(struct tcb *tcp)
{
if (exiting(tcp))
return RVAL_UDECIMAL;
return 0;
}
int sys_getuid(struct tcb *tcp)
{
if (exiting(tcp))
tcp->u_rval = (uid_t) tcp->u_rval;
return RVAL_UDECIMAL;
}
int sys_setfsuid(struct tcb *tcp)
{
if (entering(tcp))
tprintf("%u", (uid_t) tcp->u_arg[0]);
else
tcp->u_rval = (uid_t) tcp->u_rval;
return RVAL_UDECIMAL;
}
int
sys_setuid(struct tcb *tcp)
{
if (entering(tcp)) {
tprintf("%u", (uid_t) tcp->u_arg[0]);
}
return 0;
}
int
sys_getresuid(struct tcb *tcp)
{
if (exiting(tcp)) {
__kernel_uid_t uid;
if (syserror(tcp))
tprintf("%#lx, %#lx, %#lx", tcp->u_arg[0],
tcp->u_arg[1], tcp->u_arg[2]);
else {
if (umove(tcp, tcp->u_arg[0], &uid) < 0)
tprintf("%#lx, ", tcp->u_arg[0]);
else
tprintf("[%lu], ", (unsigned long) uid);
if (umove(tcp, tcp->u_arg[1], &uid) < 0)
tprintf("%#lx, ", tcp->u_arg[1]);
else
tprintf("[%lu], ", (unsigned long) uid);
if (umove(tcp, tcp->u_arg[2], &uid) < 0)
tprintf("%#lx", tcp->u_arg[2]);
else
tprintf("[%lu]", (unsigned long) uid);
}
}
return 0;
}
int
sys_setreuid(struct tcb *tcp)
{
if (entering(tcp)) {
printuid("", tcp->u_arg[0]);
printuid(", ", tcp->u_arg[1]);
}
return 0;
}
int
sys_setresuid(struct tcb *tcp)
{
if (entering(tcp)) {
printuid("", tcp->u_arg[0]);
printuid(", ", tcp->u_arg[1]);
printuid(", ", tcp->u_arg[2]);
}
return 0;
}
int
sys_setgroups(struct tcb *tcp)
{
if (entering(tcp)) {
unsigned long len, size, start, cur, end, abbrev_end;
GETGROUPS_T gid;
int failed = 0;
len = tcp->u_arg[0];
tprintf("%lu, ", len);
if (len == 0) {
tprints("[]");
return 0;
}
start = tcp->u_arg[1];
if (start == 0) {
tprints("NULL");
return 0;
}
size = len * sizeof(gid);
end = start + size;
if (!verbose(tcp) || size / sizeof(gid) != len || end < start) {
tprintf("%#lx", start);
return 0;
}
if (abbrev(tcp)) {
abbrev_end = start + max_strlen * sizeof(gid);
if (abbrev_end < start)
abbrev_end = end;
} else {
abbrev_end = end;
}
tprints("[");
for (cur = start; cur < end; cur += sizeof(gid)) {
if (cur > start)
tprints(", ");
if (cur >= abbrev_end) {
tprints("...");
break;
}
if (umoven(tcp, cur, sizeof(gid), (char *) &gid) < 0) {
tprints("?");
failed = 1;
break;
}
tprintf("%lu", (unsigned long) gid);
}
tprints("]");
if (failed)
tprintf(" %#lx", tcp->u_arg[1]);
}
return 0;
}
int
sys_getgroups(struct tcb *tcp)
{
unsigned long len;
if (entering(tcp)) {
len = tcp->u_arg[0];
tprintf("%lu, ", len);
} else {
unsigned long size, start, cur, end, abbrev_end;
GETGROUPS_T gid;
int failed = 0;
len = tcp->u_rval;
if (len == 0) {
tprints("[]");
return 0;
}
start = tcp->u_arg[1];
if (start == 0) {
tprints("NULL");
return 0;
}
if (tcp->u_arg[0] == 0) {
tprintf("%#lx", start);
return 0;
}
size = len * sizeof(gid);
end = start + size;
if (!verbose(tcp) || tcp->u_arg[0] == 0 ||
size / sizeof(gid) != len || end < start) {
tprintf("%#lx", start);
return 0;
}
if (abbrev(tcp)) {
abbrev_end = start + max_strlen * sizeof(gid);
if (abbrev_end < start)
abbrev_end = end;
} else {
abbrev_end = end;
}
tprints("[");
for (cur = start; cur < end; cur += sizeof(gid)) {
if (cur > start)
tprints(", ");
if (cur >= abbrev_end) {
tprints("...");
break;
}
if (umoven(tcp, cur, sizeof(gid), (char *) &gid) < 0) {
tprints("?");
failed = 1;
break;
}
tprintf("%lu", (unsigned long) gid);
}
tprints("]");
if (failed)
tprintf(" %#lx", tcp->u_arg[1]);
}
return 0;
}
int
sys_setgroups32(struct tcb *tcp)
{
if (entering(tcp)) {
unsigned long len, size, start, cur, end, abbrev_end;
GETGROUPS32_T gid;
int failed = 0;
len = tcp->u_arg[0];
tprintf("%lu, ", len);
if (len == 0) {
tprints("[]");
return 0;
}
start = tcp->u_arg[1];
if (start == 0) {
tprints("NULL");
return 0;
}
size = len * sizeof(gid);
end = start + size;
if (!verbose(tcp) || size / sizeof(gid) != len || end < start) {
tprintf("%#lx", start);
return 0;
}
if (abbrev(tcp)) {
abbrev_end = start + max_strlen * sizeof(gid);
if (abbrev_end < start)
abbrev_end = end;
} else {
abbrev_end = end;
}
tprints("[");
for (cur = start; cur < end; cur += sizeof(gid)) {
if (cur > start)
tprints(", ");
if (cur >= abbrev_end) {
tprints("...");
break;
}
if (umoven(tcp, cur, sizeof(gid), (char *) &gid) < 0) {
tprints("?");
failed = 1;
break;
}
tprintf("%lu", (unsigned long) gid);
}
tprints("]");
if (failed)
tprintf(" %#lx", tcp->u_arg[1]);
}
return 0;
}
int
sys_getgroups32(struct tcb *tcp)
{
unsigned long len;
if (entering(tcp)) {
len = tcp->u_arg[0];
tprintf("%lu, ", len);
} else {
unsigned long size, start, cur, end, abbrev_end;
GETGROUPS32_T gid;
int failed = 0;
len = tcp->u_rval;
if (len == 0) {
tprints("[]");
return 0;
}
start = tcp->u_arg[1];
if (start == 0) {
tprints("NULL");
return 0;
}
size = len * sizeof(gid);
end = start + size;
if (!verbose(tcp) || tcp->u_arg[0] == 0 ||
size / sizeof(gid) != len || end < start) {
tprintf("%#lx", start);
return 0;
}
if (abbrev(tcp)) {
abbrev_end = start + max_strlen * sizeof(gid);
if (abbrev_end < start)
abbrev_end = end;
} else {
abbrev_end = end;
}
tprints("[");
for (cur = start; cur < end; cur += sizeof(gid)) {
if (cur > start)
tprints(", ");
if (cur >= abbrev_end) {
tprints("...");
break;
}
if (umoven(tcp, cur, sizeof(gid), (char *) &gid) < 0) {
tprints("?");
failed = 1;
break;
}
tprintf("%lu", (unsigned long) gid);
}
tprints("]");
if (failed)
tprintf(" %#lx", tcp->u_arg[1]);
}
return 0;
}
static void
printargv(struct tcb *tcp, long addr)
{
union {
unsigned int p32;
unsigned long p64;
char data[sizeof(long)];
} cp;
const char *sep;
int n = 0;
unsigned wordsize = current_wordsize;
cp.p64 = 1;
for (sep = ""; !abbrev(tcp) || n < max_strlen / 2; sep = ", ", ++n) {
if (umoven(tcp, addr, wordsize, cp.data) < 0) {
tprintf("%#lx", addr);
return;
}
if (wordsize == 4)
cp.p64 = cp.p32;
if (cp.p64 == 0)
break;
tprints(sep);
printstr(tcp, cp.p64, -1);
addr += wordsize;
}
if (cp.p64)
tprintf("%s...", sep);
}
static void
printargc(const char *fmt, struct tcb *tcp, long addr)
{
int count;
char *cp;
for (count = 0; umove(tcp, addr, &cp) >= 0 && cp != NULL; count++) {
addr += sizeof(char *);
}
tprintf(fmt, count, count == 1 ? "" : "s");
}
#if defined(SPARC) || defined(SPARC64)
int
sys_execv(struct tcb *tcp)
{
if (entering(tcp)) {
printpath(tcp, tcp->u_arg[0]);
if (!verbose(tcp))
tprintf(", %#lx", tcp->u_arg[1]);
else {
tprints(", [");
printargv(tcp, tcp->u_arg[1]);
tprints("]");
}
}
return 0;
}
#endif
int
sys_execve(struct tcb *tcp)
{
if (entering(tcp)) {
printpath(tcp, tcp->u_arg[0]);
if (!verbose(tcp))
tprintf(", %#lx", tcp->u_arg[1]);
else {
tprints(", [");
printargv(tcp, tcp->u_arg[1]);
tprints("]");
}
if (!verbose(tcp))
tprintf(", %#lx", tcp->u_arg[2]);
else if (abbrev(tcp))
printargc(", [/* %d var%s */]", tcp, tcp->u_arg[2]);
else {
tprints(", [");
printargv(tcp, tcp->u_arg[2]);
tprints("]");
}
}
return 0;
}
#ifndef __WNOTHREAD
#define __WNOTHREAD 0x20000000
#endif
#ifndef __WALL
#define __WALL 0x40000000
#endif
#ifndef __WCLONE
#define __WCLONE 0x80000000
#endif
static const struct xlat wait4_options[] = {
{ WNOHANG, "WNOHANG" },
#ifndef WSTOPPED
{ WUNTRACED, "WUNTRACED" },
#endif
#ifdef WEXITED
{ WEXITED, "WEXITED" },
#endif
#ifdef WTRAPPED
{ WTRAPPED, "WTRAPPED" },
#endif
#ifdef WSTOPPED
{ WSTOPPED, "WSTOPPED" },
#endif
#ifdef WCONTINUED
{ WCONTINUED, "WCONTINUED" },
#endif
#ifdef WNOWAIT
{ WNOWAIT, "WNOWAIT" },
#endif
#ifdef __WCLONE
{ __WCLONE, "__WCLONE" },
#endif
#ifdef __WALL
{ __WALL, "__WALL" },
#endif
#ifdef __WNOTHREAD
{ __WNOTHREAD, "__WNOTHREAD" },
#endif
{ 0, NULL },
};
#if !defined WCOREFLAG && defined WCOREFLG
# define WCOREFLAG WCOREFLG
#endif
#ifndef WCOREFLAG
# define WCOREFLAG 0x80
#endif
#ifndef WCOREDUMP
# define WCOREDUMP(status) ((status) & 0200)
#endif
#ifndef W_STOPCODE
# define W_STOPCODE(sig) ((sig) << 8 | 0x7f)
#endif
#ifndef W_EXITCODE
# define W_EXITCODE(ret, sig) ((ret) << 8 | (sig))
#endif
static int
printstatus(int status)
{
int exited = 0;
/*
* Here is a tricky presentation problem. This solution