blob: a7b62f4fd0f7f58c1bc849f3f9d4cad55a64cd62 [file] [log] [blame]
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001/*
2 * Copyright (c) 1991, 1992 Paul Kranenburg <pk@cs.few.eur.nl>
3 * Copyright (c) 1993 Branko Lankester <branko@hacktic.nl>
4 * Copyright (c) 1993, 1994, 1995, 1996 Rick Sladkey <jrs@world.std.com>
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 *
29 * $Id$
30 */
31
32#include "defs.h"
33
34#include <fcntl.h>
35#include <sys/stat.h>
36#include <sys/time.h>
37#include <sys/wait.h>
38#include <sys/resource.h>
39#include <sys/utsname.h>
40#include <sys/user.h>
41#include <sys/syscall.h>
42#include <signal.h>
43#ifdef SUNOS4
44#include <machine/reg.h>
45#endif /* SUNOS4 */
46
47#if __GLIBC__ == 2 && __GLIBC_MINOR__ >= 1
48# include <sys/reg.h>
49# define PTRACE_PEEKUSR PTRACE_PEEKUSER
50# define PTRACE_POKEUSR PTRACE_POKEUSER
51#endif
52
53#ifdef LINUX
54#include <linux/ptrace.h>
55#endif /* LINUX */
56
57#ifdef HAVE_PRCTL
58#include <sys/prctl.h>
59#endif
60
61#ifndef WCOREDUMP
62#define WCOREDUMP(status) ((status) & 0200)
63#endif
64
Wichert Akkerman5daa0281999-03-15 19:49:42 +000065/* WTA: this has `&& !defined(LINUXSPARC)', this seems unneeded though? */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000066#if defined(HAVE_PRCTL)
67static struct xlat prctl_options[] = {
68#ifdef PR_MAXPROCS
69 { PR_MAXPROCS, "PR_MAXPROCS" },
70#endif
71#ifdef PR_ISBLOCKED
72 { PR_ISBLOCKED, "PR_ISBLOCKED" },
73#endif
74#ifdef PR_SETSTACKSIZE
75 { PR_SETSTACKSIZE, "PR_SETSTACKSIZE" },
76#endif
77#ifdef PR_GETSTACKSIZE
78 { PR_GETSTACKSIZE, "PR_GETSTACKSIZE" },
79#endif
80#ifdef PR_MAXPPROCS
81 { PR_MAXPPROCS, "PR_MAXPPROCS" },
82#endif
83#ifdef PR_UNBLKONEXEC
84 { PR_UNBLKONEXEC, "PR_UNBLKONEXEC" },
85#endif
86#ifdef PR_ATOMICSIM
87 { PR_ATOMICSIM, "PR_ATOMICSIM" },
88#endif
89#ifdef PR_SETEXITSIG
90 { PR_SETEXITSIG, "PR_SETEXITSIG" },
91#endif
92#ifdef PR_RESIDENT
93 { PR_RESIDENT, "PR_RESIDENT" },
94#endif
95#ifdef PR_ATTACHADDR
96 { PR_ATTACHADDR, "PR_ATTACHADDR" },
97#endif
98#ifdef PR_DETACHADDR
99 { PR_DETACHADDR, "PR_DETACHADDR" },
100#endif
101#ifdef PR_TERMCHILD
102 { PR_TERMCHILD, "PR_TERMCHILD" },
103#endif
104#ifdef PR_GETSHMASK
105 { PR_GETSHMASK, "PR_GETSHMASK" },
106#endif
107#ifdef PR_GETNSHARE
108 { PR_GETNSHARE, "PR_GETNSHARE" },
109#endif
110#if defined(PR_SET_PDEATHSIG)
111 { PR_SET_PDEATHSIG, "PR_SET_PDEATHSIG" },
112#endif
113 { 0, NULL },
114};
115
116int
117sys_prctl(tcp)
118struct tcb *tcp;
119{
120 int i;
121
122 if (entering(tcp)) {
123 printxval(prctl_options, tcp->u_arg[0], "PR_???");
124 switch (tcp->u_arg[0]) {
125#ifdef PR_GETNSHARE
126 case PR_GETNSHARE:
127 break;
128#endif
129 default:
130 for (i = 1; i < tcp->u_nargs; i++)
131 tprintf(", %#lx", tcp->u_arg[i]);
132 break;
133 }
134 }
135 return 0;
136}
137
138#endif /* HAVE_PRCTL */
139
140int
141sys_gethostid(tcp)
142struct tcb *tcp;
143{
144 if (exiting(tcp))
145 return RVAL_HEX;
146 return 0;
147}
148
149int
150sys_sethostname(tcp)
151struct tcb *tcp;
152{
153 if (entering(tcp)) {
154 printpathn(tcp, tcp->u_arg[0], tcp->u_arg[1]);
155 tprintf(", %lu", tcp->u_arg[1]);
156 }
157 return 0;
158}
159
160int
161sys_gethostname(tcp)
162struct tcb *tcp;
163{
164 if (exiting(tcp)) {
165 if (syserror(tcp))
166 tprintf("%#lx", tcp->u_arg[0]);
167 else
168 printpath(tcp, tcp->u_arg[0]);
169 tprintf(", %lu", tcp->u_arg[1]);
170 }
171 return 0;
172}
173
174int
175sys_setdomainname(tcp)
176struct tcb *tcp;
177{
178 if (entering(tcp)) {
179 printpathn(tcp, tcp->u_arg[0], tcp->u_arg[1]);
180 tprintf(", %lu", tcp->u_arg[1]);
181 }
182 return 0;
183}
184
Wichert Akkerman5daa0281999-03-15 19:49:42 +0000185#if !defined(LINUX)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000186
187int
188sys_getdomainname(tcp)
189struct tcb *tcp;
190{
191 if (exiting(tcp)) {
192 if (syserror(tcp))
193 tprintf("%#lx", tcp->u_arg[0]);
194 else
195 printpath(tcp, tcp->u_arg[0]);
196 tprintf(", %lu", tcp->u_arg[1]);
197 }
198 return 0;
199}
200#endif /* !LINUX */
201
202int
203sys_exit(tcp)
204struct tcb *tcp;
205{
206 if (exiting(tcp)) {
207 fprintf(stderr, "_exit returned!\n");
208 return -1;
209 }
210 /* special case: we stop tracing this process, finish line now */
211 tprintf("%ld) ", tcp->u_arg[0]);
212 tabto(acolumn);
213 tprintf("= ?");
214 printtrailer(tcp);
215 return 0;
216}
217
218int
219internal_exit(tcp)
220struct tcb *tcp;
221{
222 if (entering(tcp))
223 tcp->flags |= TCB_EXITING;
224 return 0;
225}
226
227#ifdef SVR4
228
229int
230sys_fork(tcp)
231struct tcb *tcp;
232{
233 if (exiting(tcp)) {
234 if (getrval2(tcp)) {
235 tcp->auxstr = "child process";
236 return RVAL_UDECIMAL | RVAL_STR;
237 }
238 }
239 return 0;
240}
241
242int
243internal_fork(tcp)
244struct tcb *tcp;
245{
246 struct tcb *tcpchild;
247
248 if (exiting(tcp)) {
249 if (getrval2(tcp))
250 return 0;
251 if (!followfork)
252 return 0;
253 if (nprocs == MAX_PROCS) {
254 tcp->flags &= ~TCB_FOLLOWFORK;
255 fprintf(stderr, "sys_fork: tcb table full\n");
256 return 0;
257 }
258 else
259 tcp->flags |= TCB_FOLLOWFORK;
260 if (syserror(tcp))
261 return 0;
262 if ((tcpchild = alloctcb(tcp->u_rval)) == NULL) {
263 fprintf(stderr, "sys_fork: tcb table full\n");
264 return 0;
265 }
266 proc_open(tcpchild, 1);
267 }
268 return 0;
269}
270
271#else /* !SVR4 */
272
273int
274sys_fork(tcp)
275struct tcb *tcp;
276{
277 if (exiting(tcp))
278 return RVAL_UDECIMAL;
279 return 0;
280}
281
282int
283internal_fork(tcp)
284struct tcb *tcp;
285{
286 struct tcb *tcpchild;
287 int pid;
288 int vforking = 0;
289
290#ifdef SYS_vfork
291 vforking = (tcp->scno == EXEC_vfork);
292#endif
293 if (entering(tcp)) {
294 if (!followfork || vforking)
295 return 0;
296 if (nprocs == MAX_PROCS) {
297 tcp->flags &= ~TCB_FOLLOWFORK;
298 fprintf(stderr, "sys_fork: tcb table full\n");
299 return 0;
300 }
301 tcp->flags |= TCB_FOLLOWFORK;
302 if (setbpt(tcp) < 0)
303 return 0;
304 }
305 else {
306 int bpt = tcp->flags & TCB_BPTSET;
307
308 if (!(tcp->flags & TCB_FOLLOWFORK))
309 return 0;
310 if (bpt)
311 clearbpt(tcp);
312
313 if (syserror(tcp))
314 return 0;
315
316 pid = tcp->u_rval;
317 if ((tcpchild = alloctcb(pid)) == NULL) {
318 fprintf(stderr, " [tcb table full]\n");
319 kill(pid, SIGKILL); /* XXX */
320 return 0;
321 }
322#ifdef LINUX
323 if (ptrace(PTRACE_ATTACH, pid, (char *) 1, 0) < 0) {
324 perror("PTRACE_ATTACH");
325 fprintf(stderr, "Too late?\n");
326 droptcb(tcpchild);
327 return 0;
328 }
329#endif /* LINUX */
330#ifdef SUNOS4
331#ifdef oldway
332 /* The child must have run before it can be attached. */
333 {
334 struct timeval tv;
335 tv.tv_sec = 0;
336 tv.tv_usec = 10000;
337 select(0, NULL, NULL, NULL, &tv);
338 }
339 if (ptrace(PTRACE_ATTACH, pid, (char *)1, 0) < 0) {
340 perror("PTRACE_ATTACH");
341 fprintf(stderr, "Too late?\n");
342 droptcb(tcpchild);
343 return 0;
344 }
345#else /* !oldway */
346 /* Try to catch the new process as soon as possible. */
347 {
348 int i;
349 for (i = 0; i < 1024; i++)
350 if (ptrace(PTRACE_ATTACH, pid, (char *) 1, 0) >= 0)
351 break;
352 if (i == 1024) {
353 perror("PTRACE_ATTACH");
354 fprintf(stderr, "Too late?\n");
355 droptcb(tcpchild);
356 return 0;
357 }
358 }
359#endif /* !oldway */
360#endif /* SUNOS4 */
361 tcpchild->flags |= TCB_ATTACHED;
362 /* Child has BPT too, must be removed on first occasion */
363 if (bpt) {
364 tcpchild->flags |= TCB_BPTSET;
365 tcpchild->baddr = tcp->baddr;
366 memcpy(tcpchild->inst, tcp->inst,
367 sizeof tcpchild->inst);
368 }
369 newoutf(tcpchild);
370 tcpchild->parent = tcp;
371 tcp->nchildren++;
372 if (!qflag)
373 fprintf(stderr, "Process %d attached\n", pid);
374 }
375 return 0;
376}
377
378#endif /* !SVR4 */
379
380#if defined(SUNOS4) || defined(LINUX)
381
382int
383sys_vfork(tcp)
384struct tcb *tcp;
385{
386 if (exiting(tcp))
387 return RVAL_UDECIMAL;
388 return 0;
389}
390
391#endif /* SUNOS4 || LINUX */
392
393#ifndef LINUX
394
395static char idstr[16];
396
397int
398sys_getpid(tcp)
399struct tcb *tcp;
400{
401 if (exiting(tcp)) {
402 sprintf(idstr, "ppid %lu", getrval2(tcp));
403 tcp->auxstr = idstr;
404 return RVAL_STR;
405 }
406 return 0;
407}
408
409int
410sys_getuid(tcp)
411struct tcb *tcp;
412{
413 if (exiting(tcp)) {
414 sprintf(idstr, "euid %lu", getrval2(tcp));
415 tcp->auxstr = idstr;
416 return RVAL_STR;
417 }
418 return 0;
419}
420
421int
422sys_getgid(tcp)
423struct tcb *tcp;
424{
425 if (exiting(tcp)) {
426 sprintf(idstr, "egid %lu", getrval2(tcp));
427 tcp->auxstr = idstr;
428 return RVAL_STR;
429 }
430 return 0;
431}
432
433#endif /* !LINUX */
434
435#ifdef LINUX
436
437int
438sys_setuid(tcp)
439struct tcb *tcp;
440{
441 if (entering(tcp)) {
442 tprintf("%u", (uid_t) tcp->u_arg[0]);
443 }
444 return 0;
445}
446
447int
448sys_setgid(tcp)
449struct tcb *tcp;
450{
451 if (entering(tcp)) {
452 tprintf("%u", (gid_t) tcp->u_arg[0]);
453 }
454 return 0;
455}
456
457int
458sys_getresuid(tcp)
459 struct tcb *tcp;
460{
461 if (exiting(tcp)) {
462 uid_t res[3];
463 if (umoven(tcp, tcp->u_arg[0], sizeof(pid_t),
464 (char *) &res[0]) < 0
465 || umoven(tcp, tcp->u_arg[2], sizeof(pid_t),
466 (char *) &res[1]) < 0
467 || umoven(tcp, tcp->u_arg[2], sizeof(pid_t),
468 (char *) &res[2]) < 0)
469 return -1;
470 tprintf("ruid %lu, euid %lu, suid %lu",
471 (unsigned long) res[0],
472 (unsigned long) res[1],
473 (unsigned long) res[2]);
474 }
475 return 0;
476}
477
478int
479sys_getresgid(tcp)
480struct tcb *tcp;
481{
482 if (exiting(tcp)) {
483 uid_t res[3];
484 if (umoven(tcp, tcp->u_arg[0], sizeof(pid_t),
485 (char *) &res[0]) < 0
486 || umoven(tcp, tcp->u_arg[2], sizeof(pid_t),
487 (char *) &res[1]) < 0
488 || umoven(tcp, tcp->u_arg[2], sizeof(pid_t),
489 (char *) &res[2]) < 0)
490 return -1;
491 tprintf("rgid %lu, egid %lu, sgid %lu",
492 (unsigned long) res[0],
493 (unsigned long) res[1],
494 (unsigned long) res[2]);
495 }
496 return 0;
497}
498
499#endif /* LINUX */
500
501int
502sys_setreuid(tcp)
503struct tcb *tcp;
504{
505 if (entering(tcp)) {
506 tprintf("%lu, %lu",
507 (unsigned long) (uid_t) tcp->u_arg[0],
508 (unsigned long) (uid_t) tcp->u_arg[1]);
509 }
510 return 0;
511}
512
513int
514sys_setregid(tcp)
515struct tcb *tcp;
516{
517 if (entering(tcp)) {
518 tprintf("%lu, %lu",
519 (unsigned long) (gid_t) tcp->u_arg[0],
520 (unsigned long) (gid_t) tcp->u_arg[1]);
521 }
522 return 0;
523}
524
525#ifdef LINUX
526int
527sys_setresuid(tcp)
528 struct tcb *tcp;
529{
530 if (entering(tcp)) {
531 tprintf("ruid %u, euid %u, suid %u",
532 (uid_t) tcp->u_arg[0],
533 (uid_t) tcp->u_arg[1],
534 (uid_t) tcp->u_arg[2]);
535 }
536 return 0;
537}
538int
539sys_setresgid(tcp)
540 struct tcb *tcp;
541{
542 if (entering(tcp)) {
543 tprintf("rgid %u, egid %u, sgid %u",
544 (uid_t) tcp->u_arg[0],
545 (uid_t) tcp->u_arg[1],
546 (uid_t) tcp->u_arg[2]);
547 }
548 return 0;
549}
550
551#endif /* LINUX */
552
553int
554sys_setgroups(tcp)
555struct tcb *tcp;
556{
557 int i, len;
558 GETGROUPS_T *gidset;
559
560 if (entering(tcp)) {
561 len = tcp->u_arg[0];
562 tprintf("%u, ", len);
563 if (len <= 0) {
564 tprintf("[]");
565 return 0;
566 }
567 gidset = (GETGROUPS_T *) malloc(len * sizeof(GETGROUPS_T));
568 if (gidset == NULL) {
569 fprintf(stderr, "sys_setgroups: out of memory\n");
570 return -1;
571 }
572 if (!verbose(tcp))
573 tprintf("%#lx", tcp->u_arg[1]);
574 else if (umoven(tcp, tcp->u_arg[1],
575 len * sizeof(GETGROUPS_T), (char *) gidset) < 0)
576 tprintf("[?]");
577 else {
578 tprintf("[");
579 for (i = 0; i < len; i++)
580 tprintf("%s%lu", i ? ", " : "",
581 (unsigned long) gidset[i]);
582 tprintf("]");
583 }
584 free((char *) gidset);
585 }
586 return 0;
587}
588
589int
590sys_getgroups(tcp)
591struct tcb *tcp;
592{
593 int i, len;
594 GETGROUPS_T *gidset;
595
596 if (entering(tcp)) {
597 len = tcp->u_arg[0];
598 tprintf("%u, ", len);
599 } else {
600 len = tcp->u_rval;
601 if (len <= 0) {
602 tprintf("[]");
603 return 0;
604 }
605 gidset = (GETGROUPS_T *) malloc(len * sizeof(GETGROUPS_T));
606 if (gidset == NULL) {
607 fprintf(stderr, "sys_getgroups: out of memory\n");
608 return -1;
609 }
610 if (!tcp->u_arg[1])
611 tprintf("NULL");
612 else if (!verbose(tcp) || tcp->u_arg[0] == 0)
613 tprintf("%#lx", tcp->u_arg[1]);
614 else if (umoven(tcp, tcp->u_arg[1],
615 len * sizeof(GETGROUPS_T), (char *) gidset) < 0)
616 tprintf("[?]");
617 else {
618 tprintf("[");
619 for (i = 0; i < len; i++)
620 tprintf("%s%lu", i ? ", " : "",
621 (unsigned long) gidset[i]);
622 tprintf("]");
623 }
624 free((char *)gidset);
625 }
626 return 0;
627}
628
629int
630sys_setpgrp(tcp)
631struct tcb *tcp;
632{
633 if (entering(tcp)) {
634#ifndef SVR4
635 tprintf("%lu, %lu", tcp->u_arg[0], tcp->u_arg[1]);
636#endif /* !SVR4 */
637 }
638 return 0;
639}
640
641int
642sys_getpgrp(tcp)
643struct tcb *tcp;
644{
645 if (entering(tcp)) {
646#ifndef SVR4
647 tprintf("%lu", tcp->u_arg[0]);
648#endif /* !SVR4 */
649 }
650 return 0;
651}
652
653int
654sys_getsid(tcp)
655struct tcb *tcp;
656{
657 if (entering(tcp)) {
658 tprintf("%lu", tcp->u_arg[0]);
659 }
660 return 0;
661}
662
663int
664sys_setsid(tcp)
665struct tcb *tcp;
666{
667 return 0;
668}
669
670int
671sys_getpgid(tcp)
672struct tcb *tcp;
673{
674 if (entering(tcp)) {
675 tprintf("%lu", tcp->u_arg[0]);
676 }
677 return 0;
678}
679
680int
681sys_setpgid(tcp)
682struct tcb *tcp;
683{
684 if (entering(tcp)) {
685 tprintf("%lu, %lu", tcp->u_arg[0], tcp->u_arg[1]);
686 }
687 return 0;
688}
689
690void
691fake_execve(tcp, program, argv, envp)
692struct tcb *tcp;
693char *program;
694char *argv[];
695char *envp[];
696{
697 int i;
698
699#ifdef ARM
700 if (!(qual_flags[SYS_execve - __NR_SYSCALL_BASE] & QUAL_TRACE))
701 return;
702#else
703 if (!(qual_flags[SYS_execve] & QUAL_TRACE))
704 return;
705#endif /* !ARM */
706 printleader(tcp);
707 tprintf("execve(");
708 string_quote(program);
709 tprintf(", [");
710 for (i = 0; argv[i] != NULL; i++) {
711 if (i != 0)
712 tprintf(", ");
713 string_quote(argv[i]);
714 }
715 for (i = 0; envp[i] != NULL; i++)
716 ;
717 tprintf("], [/* %d var%s */]) ", i, (i != 1) ? "s" : "");
718 tabto(acolumn);
719 tprintf("= 0");
720 printtrailer(tcp);
721}
722
723static void
724printargv(tcp, addr)
725struct tcb *tcp;
726long addr;
727{
728 char *cp;
729 char *sep;
730 int max = max_strlen / 2;
731
732 for (sep = ""; --max >= 0; sep = ", ") {
733 if (!abbrev(tcp))
734 max++;
735 if (umove(tcp, addr, &cp) < 0) {
736 tprintf("%#lx", addr);
737 return;
738 }
739 if (cp == 0)
740 break;
741 tprintf(sep);
742 printstr(tcp, (long) cp, -1);
743 addr += sizeof(char *);
744 }
745 if (cp)
746 tprintf(", ...");
747}
748
749static void
750printargc(fmt, tcp, addr)
751char *fmt;
752struct tcb *tcp;
753long addr;
754{
755 int count;
756 char *cp;
757
758 for (count = 0; umove(tcp, addr, &cp) >= 0 && cp != NULL; count++) {
759 addr += sizeof(char *);
760 }
761 tprintf(fmt, count, count == 1 ? "" : "s");
762}
763
764int
765sys_execv(tcp)
766struct tcb *tcp;
767{
768 if (entering(tcp)) {
769 printpath(tcp, tcp->u_arg[0]);
770 if (!verbose(tcp))
771 tprintf(", %#lx", tcp->u_arg[1]);
772#if 0
773 else if (abbrev(tcp))
774 printargc(", [/* %d arg%s */]", tcp, tcp->u_arg[1]);
775#endif
776 else {
777 tprintf(", [");
778 printargv(tcp, tcp->u_arg[1]);
779 tprintf("]");
780 }
781 }
782 return 0;
783}
784
785int
786sys_execve(tcp)
787struct tcb *tcp;
788{
789 if (entering(tcp)) {
790 printpath(tcp, tcp->u_arg[0]);
791 if (!verbose(tcp))
792 tprintf(", %#lx", tcp->u_arg[1]);
793#if 0
794 else if (abbrev(tcp))
795 printargc(", [/* %d arg%s */]", tcp, tcp->u_arg[1]);
796#endif
797 else {
798 tprintf(", [");
799 printargv(tcp, tcp->u_arg[1]);
800 tprintf("]");
801 }
802 if (!verbose(tcp))
803 tprintf(", %#lx", tcp->u_arg[2]);
804 else if (abbrev(tcp))
805 printargc(", [/* %d var%s */]", tcp, tcp->u_arg[2]);
806 else {
807 tprintf(", [");
808 printargv(tcp, tcp->u_arg[2]);
809 tprintf("]");
810 }
811 }
812#ifdef LINUX
813#if defined(ALPHA) || defined(SPARC) || defined(POWERPC)
814 tcp->flags |= TCB_WAITEXECVE;
815#endif /* ALPHA || SPARC || POWERPC */
816#endif /* LINUX */
817 return 0;
818}
819
820int
821internal_exec(tcp)
822struct tcb *tcp;
823{
824#ifdef SUNOS4
825 if (exiting(tcp) && !syserror(tcp) && followfork)
826 fixvfork(tcp);
827#endif /* SUNOS4 */
828 return 0;
829}
830
831#ifdef LINUX
832#ifndef __WCLONE
833#define __WCLONE 0x8000000
834#endif
835#endif /* LINUX */
836
837static struct xlat wait4_options[] = {
838 { WNOHANG, "WNOHANG" },
839#ifndef WSTOPPED
840 { WUNTRACED, "WUNTRACED" },
841#endif
842#ifdef WEXITED
843 { WEXITED, "WEXITED" },
844#endif
845#ifdef WTRAPPED
846 { WTRAPPED, "WTRAPPED" },
847#endif
848#ifdef WSTOPPED
849 { WSTOPPED, "WSTOPPED" },
850#endif
851#ifdef WCONTINUED
852 { WCONTINUED, "WCONTINUED" },
853#endif
854#ifdef WNOWAIT
855 { WNOWAIT, "WNOWAIT" },
856#endif
857#ifdef __WCLONE
858 { __WCLONE, "__WCLONE" },
859#endif
860 { 0, NULL },
861};
862
863static int
864printstatus(status)
865int status;
866{
867 int exited = 0;
868
869 /*
870 * Here is a tricky presentation problem. This solution
871 * is still not entirely satisfactory but since there
872 * are no wait status constructors it will have to do.
873 */
874 if (WIFSTOPPED(status))
875 tprintf("[WIFSTOPPED(s) && WSTOPSIG(s) == %s]",
876 signalent[WSTOPSIG(status)]);
877 else if WIFSIGNALED(status)
878 tprintf("[WIFSIGNALED(s) && WTERMSIG(s) == %s%s]",
879 signalent[WTERMSIG(status)],
880 WCOREDUMP(status) ? " && WCOREDUMP(s)" : "");
881 else if WIFEXITED(status) {
882 tprintf("[WIFEXITED(s) && WEXITSTATUS(s) == %d]",
883 WEXITSTATUS(status));
884 exited = 1;
885 }
886 else
887 tprintf("[%#x]", status);
888 return exited;
889}
890
891static int
892printwaitn(tcp, n)
893struct tcb *tcp;
894int n;
895{
896 int status;
897 int exited = 0;
898
899 if (entering(tcp)) {
900 tprintf("%ld, ", tcp->u_arg[0]);
901 } else {
902 /* status */
903 if (!tcp->u_arg[1])
904 tprintf("NULL");
905 else if (syserror(tcp) || tcp->u_rval == 0)
906 tprintf("%#lx", tcp->u_arg[1]);
907 else if (umove(tcp, tcp->u_arg[1], &status) < 0)
908 tprintf("[?]");
909 else
910 exited = printstatus(status);
911 /* options */
912 tprintf(", ");
913 if (!printflags(wait4_options, tcp->u_arg[2]))
914 tprintf("0");
915 if (n == 4) {
916 tprintf(", ");
917 /* usage */
918 if (!tcp->u_arg[3])
919 tprintf("NULL");
920#ifdef LINUX
921 else if (tcp->u_rval > 0)
922 printrusage(tcp, tcp->u_arg[3]);
923#endif /* LINUX */
924#ifdef SUNOS4
925 else if (tcp->u_rval > 0 && exited)
926 printrusage(tcp, tcp->u_arg[3]);
927#endif /* SUNOS4 */
928 else
929 tprintf("%#lx", tcp->u_arg[3]);
930 }
931 }
932 return 0;
933}
934
935int
936internal_wait(tcp)
937struct tcb *tcp;
938{
939 if (entering(tcp)) {
Wichert Akkerman5daa0281999-03-15 19:49:42 +0000940 /* WTA: fix bug with hanging children */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000941 if (!(tcp->u_arg[2] & WNOHANG) && tcp->nchildren > 0) {
942 /* There are traced children */
943 tcp->flags |= TCB_SUSPENDED;
944 tcp->waitpid = tcp->u_arg[0];
945 }
946 }
947 return 0;
948}
949
950#ifdef SVR4
951
952int
953sys_wait(tcp)
954struct tcb *tcp;
955{
956 if (exiting(tcp)) {
957 /* The library wrapper stuffs this into the user variable. */
958 if (!syserror(tcp))
959 printstatus(getrval2(tcp));
960 }
961 return 0;
962}
963
964#endif /* SVR4 */
965
966int
967sys_waitpid(tcp)
968struct tcb *tcp;
969{
970 return printwaitn(tcp, 3);
971}
972
973int
974sys_wait4(tcp)
975struct tcb *tcp;
976{
977 return printwaitn(tcp, 4);
978}
979
980#ifdef SVR4
981
982static struct xlat waitid_types[] = {
983 { P_PID, "P_PID" },
984 { P_PPID, "P_PPID" },
985 { P_PGID, "P_PGID" },
986 { P_SID, "P_SID" },
987 { P_CID, "P_CID" },
988 { P_UID, "P_UID" },
989 { P_GID, "P_GID" },
990 { P_ALL, "P_ALL" },
991#ifdef P_LWPID
992 { P_LWPID, "P_LWPID" },
993#endif
994 { 0, NULL },
995};
996
997static struct xlat siginfo_codes[] = {
998#ifdef SI_NOINFO
999 { SI_NOINFO, "SI_NOINFO" },
1000#endif
1001#ifdef SI_USER
1002 { SI_USER, "SI_USER" },
1003#endif
1004#ifdef SI_LWP
1005 { SI_LWP, "SI_LWP" },
1006#endif
1007#ifdef SI_QUEUE
1008 { SI_QUEUE, "SI_QUEUE" },
1009#endif
1010#ifdef SI_TIMER
1011 { SI_TIMER, "SI_TIMER" },
1012#endif
1013#ifdef SI_ASYNCIO
1014 { SI_ASYNCIO, "SI_ASYNCIO" },
1015#endif
1016#ifdef SI_MESGQ
1017 { SI_MESGQ, "SI_MESGQ" },
1018#endif
1019 { 0, NULL },
1020};
1021
1022static struct xlat sigtrap_codes[] = {
1023 { TRAP_BRKPT, "TRAP_BRKPT" },
1024 { TRAP_TRACE, "TRAP_TRACE" },
1025 { 0, NULL },
1026};
1027
1028static struct xlat sigcld_codes[] = {
1029 { CLD_EXITED, "CLD_EXITED" },
1030 { CLD_KILLED, "CLD_KILLED" },
1031 { CLD_DUMPED, "CLD_DUMPED" },
1032 { CLD_TRAPPED, "CLD_TRAPPED" },
1033 { CLD_STOPPED, "CLD_STOPPED" },
1034 { CLD_CONTINUED,"CLD_CONTINUED" },
1035 { 0, NULL },
1036};
1037
1038static struct xlat sigpoll_codes[] = {
1039 { POLL_IN, "POLL_IN" },
1040 { POLL_OUT, "POLL_OUT" },
1041 { POLL_MSG, "POLL_MSG" },
1042 { POLL_ERR, "POLL_ERR" },
1043 { POLL_PRI, "POLL_PRI" },
1044 { POLL_HUP, "POLL_HUP" },
1045 { 0, NULL },
1046};
1047
1048static struct xlat sigprof_codes[] = {
1049#ifdef PROF_SIG
1050 { PROF_SIG, "PROF_SIG" },
1051#endif
1052 { 0, NULL },
1053};
1054
1055static struct xlat sigill_codes[] = {
1056 { ILL_ILLOPC, "ILL_ILLOPC" },
1057 { ILL_ILLOPN, "ILL_ILLOPN" },
1058 { ILL_ILLADR, "ILL_ILLADR" },
1059 { ILL_ILLTRP, "ILL_ILLTRP" },
1060 { ILL_PRVOPC, "ILL_PRVOPC" },
1061 { ILL_PRVREG, "ILL_PRVREG" },
1062 { ILL_COPROC, "ILL_COPROC" },
1063 { ILL_BADSTK, "ILL_BADSTK" },
1064 { 0, NULL },
1065};
1066
1067static struct xlat sigemt_codes[] = {
1068#ifdef EMT_TAGOVF
1069 { EMT_TAGOVF, "EMT_TAGOVF" },
1070#endif
1071 { 0, NULL },
1072};
1073
1074static struct xlat sigfpe_codes[] = {
1075 { FPE_INTDIV, "FPE_INTDIV" },
1076 { FPE_INTOVF, "FPE_INTOVF" },
1077 { FPE_FLTDIV, "FPE_FLTDIV" },
1078 { FPE_FLTOVF, "FPE_FLTOVF" },
1079 { FPE_FLTUND, "FPE_FLTUND" },
1080 { FPE_FLTRES, "FPE_FLTRES" },
1081 { FPE_FLTINV, "FPE_FLTINV" },
1082 { FPE_FLTSUB, "FPE_FLTSUB" },
1083 { 0, NULL },
1084};
1085
1086static struct xlat sigsegv_codes[] = {
1087 { SEGV_MAPERR, "SEGV_MAPERR" },
1088 { SEGV_ACCERR, "SEGV_ACCERR" },
1089 { 0, NULL },
1090};
1091
1092static struct xlat sigbus_codes[] = {
1093 { BUS_ADRALN, "BUS_ADRALN" },
1094 { BUS_ADRERR, "BUS_ADRERR" },
1095 { BUS_OBJERR, "BUS_OBJERR" },
1096 { 0, NULL },
1097};
1098
1099void
1100printsiginfo(sip)
1101siginfo_t *sip;
1102{
1103 char *code;
1104
1105 tprintf("{si_signo=");
1106 printsignal(sip->si_signo);
1107 code = xlookup(siginfo_codes, sip->si_code);
1108 if (!code) {
1109 switch (sip->si_signo) {
1110 case SIGTRAP:
1111 code = xlookup(sigtrap_codes, sip->si_code);
1112 break;
1113 case SIGCHLD:
1114 code = xlookup(sigcld_codes, sip->si_code);
1115 break;
1116 case SIGPOLL:
1117 code = xlookup(sigpoll_codes, sip->si_code);
1118 break;
1119 case SIGPROF:
1120 code = xlookup(sigprof_codes, sip->si_code);
1121 break;
1122 case SIGILL:
1123 code = xlookup(sigill_codes, sip->si_code);
1124 break;
1125 case SIGEMT:
1126 code = xlookup(sigemt_codes, sip->si_code);
1127 break;
1128 case SIGFPE:
1129 code = xlookup(sigfpe_codes, sip->si_code);
1130 break;
1131 case SIGSEGV:
1132 code = xlookup(sigsegv_codes, sip->si_code);
1133 break;
1134 case SIGBUS:
1135 code = xlookup(sigbus_codes, sip->si_code);
1136 break;
1137 }
1138 }
1139 if (code)
1140 tprintf(", si_code=%s", code);
1141 else
1142 tprintf(", si_code=%#x", sip->si_code);
1143#ifdef SI_NOINFO
1144 if (sip->si_code != SI_NOINFO) {
1145#endif
1146 if (sip->si_errno) {
1147 if (sip->si_errno < 0 || sip->si_errno >= nerrnos)
1148 tprintf(", si_errno=%d", sip->si_errno);
1149 else
1150 tprintf(", si_errno=%s",
1151 errnoent[sip->si_errno]);
1152 }
1153 if (SI_FROMUSER(sip)) {
1154#ifdef SI_QUEUE
1155 tprintf(", si_pid=%ld, si_uid=%ld",
1156 sip->si_pid, sip->si_uid);
1157 switch (sip->si_code) {
1158 case SI_QUEUE:
1159#ifdef SI_TIMER
1160 case SI_TIMER:
1161#endif /* SI_QUEUE */
1162 case SI_ASYNCIO:
1163#ifdef SI_MESGQ
1164 case SI_MESGQ:
1165#endif /* SI_MESGQ */
1166 tprintf(", si_value=%d",
1167 sip->si_value.sival_int);
1168 break;
1169 }
1170#endif /* SI_QUEUE */
1171 }
1172 else {
1173 switch (sip->si_signo) {
1174 case SIGCHLD:
1175 tprintf(", si_pid=%ld, si_status=",
1176 sip->si_pid);
1177 if (sip->si_code == CLD_EXITED)
1178 tprintf("%d", sip->si_status);
1179 else
1180 printsignal(sip->si_status);
1181 break;
1182 case SIGILL: case SIGFPE:
1183 case SIGSEGV: case SIGBUS:
1184 tprintf(", si_addr=%#lx",
1185 (unsigned long) sip->si_addr);
1186 break;
1187 case SIGPOLL:
1188 switch (sip->si_code) {
1189 case POLL_IN: case POLL_OUT: case POLL_MSG:
1190 tprintf(", si_band=%ld",
1191 (long) sip->si_band);
1192 break;
1193 }
1194 break;
1195 }
1196 }
1197 tprintf(", ...");
1198#ifdef SI_NOINFO
1199 }
1200#endif
1201 tprintf("}");
1202}
1203
1204int
1205sys_waitid(tcp)
1206struct tcb *tcp;
1207{
1208 siginfo_t si;
1209 int exited;
1210
1211 if (entering(tcp)) {
1212 printxval(waitid_types, tcp->u_arg[0], "P_???");
1213 tprintf(", %ld, ", tcp->u_arg[1]);
1214 if (tcp->nchildren > 0) {
1215 /* There are traced children */
1216 tcp->flags |= TCB_SUSPENDED;
1217 tcp->waitpid = tcp->u_arg[0];
1218 }
1219 }
1220 else {
1221 /* siginfo */
1222 exited = 0;
1223 if (!tcp->u_arg[2])
1224 tprintf("NULL");
1225 else if (syserror(tcp))
1226 tprintf("%#lx", tcp->u_arg[2]);
1227 else if (umove(tcp, tcp->u_arg[2], &si) < 0)
1228 tprintf("{???}");
1229 else
1230 printsiginfo(&si);
1231 /* options */
1232 tprintf(", ");
1233 if (!printflags(wait4_options, tcp->u_arg[3]))
1234 tprintf("0");
1235 }
1236 return 0;
1237}
1238
1239#endif /* SVR4 */
1240
1241int
1242sys_alarm(tcp)
1243struct tcb *tcp;
1244{
1245 if (entering(tcp))
1246 tprintf("%lu", tcp->u_arg[0]);
1247 return 0;
1248}
1249
1250int
1251sys_uname(tcp)
1252struct tcb *tcp;
1253{
1254 struct utsname uname;
1255
1256 if (exiting(tcp)) {
1257 if (syserror(tcp) || !verbose(tcp))
1258 tprintf("%#lx", tcp->u_arg[0]);
1259 else if (umove(tcp, tcp->u_arg[0], &uname) < 0)
1260 tprintf("{...}");
1261 else if (!abbrev(tcp)) {
1262
1263 tprintf("{sysname=\"%s\", nodename=\"%s\", ",
1264 uname.sysname, uname.nodename);
1265 tprintf("release=\"%s\", version=\"%s\", ",
1266 uname.release, uname.version);
1267 tprintf("machine=\"%s\"", uname.machine);
1268#ifdef LINUX
1269#ifndef __GLIBC__
1270 tprintf(", domainname=\"%s\"", uname.domainname);
1271#endif /* __GLIBC__ */
1272#endif /* LINUX */
1273 tprintf("}");
1274 }
1275 else
1276 tprintf("{sys=\"%s\", node=\"%s\", ...}",
1277 uname.sysname, uname.nodename);
1278 }
1279 return 0;
1280}
1281
1282#ifndef SVR4
1283
1284static struct xlat ptrace_cmds[] = {
1285 { PTRACE_TRACEME, "PTRACE_TRACEME" },
1286 { PTRACE_PEEKTEXT, "PTRACE_PEEKTEXT", },
1287 { PTRACE_PEEKDATA, "PTRACE_PEEKDATA", },
1288 { PTRACE_PEEKUSER, "PTRACE_PEEKUSER", },
1289 { PTRACE_POKETEXT, "PTRACE_POKETEXT", },
1290 { PTRACE_POKEDATA, "PTRACE_POKEDATA", },
1291 { PTRACE_POKEUSER, "PTRACE_POKEUSER", },
1292 { PTRACE_CONT, "PTRACE_CONT" },
1293 { PTRACE_KILL, "PTRACE_KILL" },
1294 { PTRACE_SINGLESTEP, "PTRACE_SINGLESTEP" },
1295 { PTRACE_ATTACH, "PTRACE_ATTACH" },
1296 { PTRACE_DETACH, "PTRACE_DETACH" },
1297#ifdef SUNOS4
1298 { PTRACE_GETREGS, "PTRACE_GETREGS" },
1299 { PTRACE_SETREGS, "PTRACE_SETREGS" },
1300 { PTRACE_GETFPREGS, "PTRACE_GETFPREGS", },
1301 { PTRACE_SETFPREGS, "PTRACE_SETFPREGS", },
1302 { PTRACE_READDATA, "PTRACE_READDATA" },
1303 { PTRACE_WRITEDATA, "PTRACE_WRITEDATA" },
1304 { PTRACE_READTEXT, "PTRACE_READTEXT" },
1305 { PTRACE_WRITETEXT, "PTRACE_WRITETEXT" },
1306 { PTRACE_GETFPAREGS, "PTRACE_GETFPAREGS" },
1307 { PTRACE_SETFPAREGS, "PTRACE_SETFPAREGS" },
1308#ifdef SPARC
1309 { PTRACE_GETWINDOW, "PTRACE_GETWINDOW" },
1310 { PTRACE_SETWINDOW, "PTRACE_SETWINDOW" },
1311#else /* !SPARC */
1312 { PTRACE_22, "PTRACE_PTRACE_22" },
1313 { PTRACE_23, "PTRACE_PTRACE_23" },
1314#endif /* !SPARC */
1315#endif /* SUNOS4 */
1316 { PTRACE_SYSCALL, "PTRACE_SYSCALL" },
1317#ifdef SUNOS4
1318 { PTRACE_DUMPCORE, "PTRACE_DUMPCORE" },
1319#ifdef I386
1320 { PTRACE_SETWRBKPT, "PTRACE_SETWRBKPT" },
1321 { PTRACE_SETACBKPT, "PTRACE_SETACBKPT" },
1322 { PTRACE_CLRDR7, "PTRACE_CLRDR7" },
1323#else /* !I386 */
1324 { PTRACE_26, "PTRACE_26" },
1325 { PTRACE_27, "PTRACE_27" },
1326 { PTRACE_28, "PTRACE_28" },
1327#endif /* !I386 */
1328 { PTRACE_GETUCODE, "PTRACE_GETUCODE" },
1329#endif /* SUNOS4 */
1330 { 0, NULL },
1331};
1332
1333#ifndef SUNOS4_KERNEL_ARCH_KLUDGE
1334static
1335#endif /* !SUNOS4_KERNEL_ARCH_KLUDGE */
1336struct xlat struct_user_offsets[] = {
1337#ifdef LINUX
1338#ifdef SPARC
1339 /* XXX No support for these offsets yet. */
1340#elif defined(POWERPC)
1341 { 4*PT_R0, "4*PT_R0" },
1342 { 4*PT_R1, "4*PT_R1" },
1343 { 4*PT_R2, "4*PT_R2" },
1344 { 4*PT_R3, "4*PT_R3" },
1345 { 4*PT_R4, "4*PT_R4" },
1346 { 4*PT_R5, "4*PT_R5" },
1347 { 4*PT_R6, "4*PT_R6" },
1348 { 4*PT_R7, "4*PT_R7" },
1349 { 4*PT_R8, "4*PT_R8" },
1350 { 4*PT_R9, "4*PT_R9" },
1351 { 4*PT_R10, "4*PT_R10" },
1352 { 4*PT_R11, "4*PT_R11" },
1353 { 4*PT_R12, "4*PT_R12" },
1354 { 4*PT_R13, "4*PT_R13" },
1355 { 4*PT_R14, "4*PT_R14" },
1356 { 4*PT_R15, "4*PT_R15" },
1357 { 4*PT_R16, "4*PT_R16" },
1358 { 4*PT_R17, "4*PT_R17" },
1359 { 4*PT_R18, "4*PT_R18" },
1360 { 4*PT_R19, "4*PT_R19" },
1361 { 4*PT_R20, "4*PT_R20" },
1362 { 4*PT_R21, "4*PT_R21" },
1363 { 4*PT_R22, "4*PT_R22" },
1364 { 4*PT_R23, "4*PT_R23" },
1365 { 4*PT_R24, "4*PT_R24" },
1366 { 4*PT_R25, "4*PT_R25" },
1367 { 4*PT_R26, "4*PT_R26" },
1368 { 4*PT_R27, "4*PT_R27" },
1369 { 4*PT_R28, "4*PT_R28" },
1370 { 4*PT_R29, "4*PT_R29" },
1371 { 4*PT_R30, "4*PT_R30" },
1372 { 4*PT_R31, "4*PT_R31" },
1373 { 4*PT_NIP, "4*PT_NIP" },
1374 { 4*PT_MSR, "4*PT_MSR" },
1375 { 4*PT_ORIG_R3, "4*PT_ORIG_R3" },
1376 { 4*PT_CTR, "4*PT_CTR" },
1377 { 4*PT_LNK, "4*PT_LNK" },
1378 { 4*PT_XER, "4*PT_XER" },
1379 { 4*PT_CCR, "4*PT_CCR" },
1380 { 4*PT_FPR0, "4*PT_FPR0" },
1381#else
1382#ifdef ALPHA
1383 { 0, "r0" },
1384 { 1, "r1" },
1385 { 2, "r2" },
1386 { 3, "r3" },
1387 { 4, "r4" },
1388 { 5, "r5" },
1389 { 6, "r6" },
1390 { 7, "r7" },
1391 { 8, "r8" },
1392 { 9, "r9" },
1393 { 10, "r10" },
1394 { 11, "r11" },
1395 { 12, "r12" },
1396 { 13, "r13" },
1397 { 14, "r14" },
1398 { 15, "r15" },
1399 { 16, "r16" },
1400 { 17, "r17" },
1401 { 18, "r18" },
1402 { 19, "r19" },
1403 { 20, "r20" },
1404 { 21, "r21" },
1405 { 22, "r22" },
1406 { 23, "r23" },
1407 { 24, "r24" },
1408 { 25, "r25" },
1409 { 26, "r26" },
1410 { 27, "r27" },
1411 { 28, "r28" },
1412 { 29, "gp" },
1413 { 30, "fp" },
1414 { 31, "zero" },
1415 { 32, "fp0" },
1416 { 33, "fp" },
1417 { 34, "fp2" },
1418 { 35, "fp3" },
1419 { 36, "fp4" },
1420 { 37, "fp5" },
1421 { 38, "fp6" },
1422 { 39, "fp7" },
1423 { 40, "fp8" },
1424 { 41, "fp9" },
1425 { 42, "fp10" },
1426 { 43, "fp11" },
1427 { 44, "fp12" },
1428 { 45, "fp13" },
1429 { 46, "fp14" },
1430 { 47, "fp15" },
1431 { 48, "fp16" },
1432 { 49, "fp17" },
1433 { 50, "fp18" },
1434 { 51, "fp19" },
1435 { 52, "fp20" },
1436 { 53, "fp21" },
1437 { 54, "fp22" },
1438 { 55, "fp23" },
1439 { 56, "fp24" },
1440 { 57, "fp25" },
1441 { 58, "fp26" },
1442 { 59, "fp27" },
1443 { 60, "fp28" },
1444 { 61, "fp29" },
1445 { 62, "fp30" },
1446 { 63, "fp31" },
1447 { 64, "pc" },
1448#else /* !ALPHA */
1449#ifdef I386
1450 { 4*EBX, "4*EBX" },
1451 { 4*ECX, "4*ECX" },
1452 { 4*EDX, "4*EDX" },
1453 { 4*ESI, "4*ESI" },
1454 { 4*EDI, "4*EDI" },
1455 { 4*EBP, "4*EBP" },
1456 { 4*EAX, "4*EAX" },
1457 { 4*DS, "4*DS" },
1458 { 4*ES, "4*ES" },
1459 { 4*FS, "4*FS" },
1460 { 4*GS, "4*GS" },
1461 { 4*ORIG_EAX, "4*ORIG_EAX" },
1462 { 4*EIP, "4*EIP" },
1463 { 4*CS, "4*CS" },
1464 { 4*EFL, "4*EFL" },
1465 { 4*UESP, "4*UESP" },
1466 { 4*SS, "4*SS" },
1467#else /* !I386 */
1468#ifdef M68K
1469 { 4*PT_D1, "4*PT_D1" },
1470 { 4*PT_D2, "4*PT_D2" },
1471 { 4*PT_D3, "4*PT_D3" },
1472 { 4*PT_D4, "4*PT_D4" },
1473 { 4*PT_D5, "4*PT_D5" },
1474 { 4*PT_D6, "4*PT_D6" },
1475 { 4*PT_D7, "4*PT_D7" },
1476 { 4*PT_A0, "4*PT_A0" },
1477 { 4*PT_A1, "4*PT_A1" },
1478 { 4*PT_A2, "4*PT_A2" },
1479 { 4*PT_A3, "4*PT_A3" },
1480 { 4*PT_A4, "4*PT_A4" },
1481 { 4*PT_A5, "4*PT_A5" },
1482 { 4*PT_A6, "4*PT_A6" },
1483 { 4*PT_D0, "4*PT_D0" },
1484 { 4*PT_USP, "4*PT_USP" },
1485 { 4*PT_ORIG_D0, "4*PT_ORIG_D0" },
1486 { 4*PT_SR, "4*PT_SR" },
1487 { 4*PT_PC, "4*PT_PC" },
1488#endif /* M68K */
1489#endif /* !I386 */
1490 { uoff(u_fpvalid), "offsetof(struct user, u_fpvalid)" },
1491#ifdef I386
1492 { uoff(i387), "offsetof(struct user, i387)" },
1493#else /* !I386 */
1494#ifdef M68K
1495 { uoff(m68kfp), "offsetof(struct user, m68kfp)" },
1496#endif /* M68K */
1497#endif /* !I386 */
1498 { uoff(u_tsize), "offsetof(struct user, u_tsize)" },
1499 { uoff(u_dsize), "offsetof(struct user, u_dsize)" },
1500 { uoff(u_ssize), "offsetof(struct user, u_ssize)" },
1501 { uoff(start_code), "offsetof(struct user, start_code)" },
1502 { uoff(start_stack), "offsetof(struct user, start_stack)" },
1503 { uoff(signal), "offsetof(struct user, signal)" },
1504 { uoff(reserved), "offsetof(struct user, reserved)" },
1505 { uoff(u_ar0), "offsetof(struct user, u_ar0)" },
1506#ifndef ARM
1507 { uoff(u_fpstate), "offsetof(struct user, u_fpstate)" },
1508#endif
1509 { uoff(magic), "offsetof(struct user, magic)" },
1510 { uoff(u_comm), "offsetof(struct user, u_comm)" },
1511#ifdef I386
1512 { uoff(u_debugreg), "offsetof(struct user, u_debugreg)" },
1513#endif /* I386 */
1514#endif /* !ALPHA */
1515#endif /* !POWERPC/!SPARC */
1516#endif /* LINUX */
1517#ifdef SUNOS4
1518 { uoff(u_pcb), "offsetof(struct user, u_pcb)" },
1519 { uoff(u_procp), "offsetof(struct user, u_procp)" },
1520 { uoff(u_ar0), "offsetof(struct user, u_ar0)" },
1521 { uoff(u_comm[0]), "offsetof(struct user, u_comm[0])" },
1522 { uoff(u_arg[0]), "offsetof(struct user, u_arg[0])" },
1523 { uoff(u_ap), "offsetof(struct user, u_ap)" },
1524 { uoff(u_qsave), "offsetof(struct user, u_qsave)" },
1525 { uoff(u_rval1), "offsetof(struct user, u_rval1)" },
1526 { uoff(u_rval2), "offsetof(struct user, u_rval2)" },
1527 { uoff(u_error), "offsetof(struct user, u_error)" },
1528 { uoff(u_eosys), "offsetof(struct user, u_eosys)" },
1529 { uoff(u_ssave), "offsetof(struct user, u_ssave)" },
1530 { uoff(u_signal[0]), "offsetof(struct user, u_signal)" },
1531 { uoff(u_sigmask[0]), "offsetof(struct user, u_sigmask)" },
1532 { uoff(u_sigonstack), "offsetof(struct user, u_sigonstack)" },
1533 { uoff(u_sigintr), "offsetof(struct user, u_sigintr)" },
1534 { uoff(u_sigreset), "offsetof(struct user, u_sigreset)" },
1535 { uoff(u_oldmask), "offsetof(struct user, u_oldmask)" },
1536 { uoff(u_code), "offsetof(struct user, u_code)" },
1537 { uoff(u_addr), "offsetof(struct user, u_addr)" },
1538 { uoff(u_sigstack), "offsetof(struct user, u_sigstack)" },
1539 { uoff(u_ofile), "offsetof(struct user, u_ofile)" },
1540 { uoff(u_pofile), "offsetof(struct user, u_pofile)" },
1541 { uoff(u_ofile_arr[0]), "offsetof(struct user, u_ofile_arr[0])" },
1542 { uoff(u_pofile_arr[0]),"offsetof(struct user, u_pofile_arr[0])"},
1543 { uoff(u_lastfile), "offsetof(struct user, u_lastfile)" },
1544 { uoff(u_cwd), "offsetof(struct user, u_cwd)" },
1545 { uoff(u_cdir), "offsetof(struct user, u_cdir)" },
1546 { uoff(u_rdir), "offsetof(struct user, u_rdir)" },
1547 { uoff(u_cmask), "offsetof(struct user, u_cmask)" },
1548 { uoff(u_ru), "offsetof(struct user, u_ru)" },
1549 { uoff(u_cru), "offsetof(struct user, u_cru)" },
1550 { uoff(u_timer[0]), "offsetof(struct user, u_timer[0])" },
1551 { uoff(u_XXX[0]), "offsetof(struct user, u_XXX[0])" },
1552 { uoff(u_ioch), "offsetof(struct user, u_ioch)" },
1553 { uoff(u_start), "offsetof(struct user, u_start)" },
1554 { uoff(u_acflag), "offsetof(struct user, u_acflag)" },
1555 { uoff(u_prof.pr_base), "offsetof(struct user, u_prof.pr_base)" },
1556 { uoff(u_prof.pr_size), "offsetof(struct user, u_prof.pr_size)" },
1557 { uoff(u_prof.pr_off), "offsetof(struct user, u_prof.pr_off)" },
1558 { uoff(u_prof.pr_scale),"offsetof(struct user, u_prof.pr_scale)"},
1559 { uoff(u_rlimit[0]), "offsetof(struct user, u_rlimit)" },
1560 { uoff(u_exdata.Ux_A), "offsetof(struct user, u_exdata.Ux_A)" },
1561 { uoff(u_exdata.ux_shell[0]),"offsetof(struct user, u_exdata.ux_shell[0])"},
1562 { uoff(u_lofault), "offsetof(struct user, u_lofault)" },
1563#endif /* SUNOS4 */
1564 { sizeof(struct user), "sizeof(struct user)" },
1565 { 0, NULL },
1566};
1567
1568int
1569sys_ptrace(tcp)
1570struct tcb *tcp;
1571{
1572 char *cmd;
1573 struct xlat *x;
1574 long addr;
1575
1576 cmd = xlookup(ptrace_cmds, tcp->u_arg[0]);
1577 if (!cmd)
1578 cmd = "PTRACE_???";
1579 if (entering(tcp)) {
1580 tprintf("%s, %lu, ", cmd, tcp->u_arg[1]);
1581 addr = tcp->u_arg[2];
1582 if (tcp->u_arg[0] == PTRACE_PEEKUSER
1583 || tcp->u_arg[0] == PTRACE_POKEUSER) {
1584 for (x = struct_user_offsets; x->str; x++) {
1585 if (x->val >= addr)
1586 break;
1587 }
1588 if (!x->str)
1589 tprintf("%#lx, ", addr);
1590 else if (x->val > addr && x != struct_user_offsets) {
1591 x--;
1592 tprintf("%s + %ld, ", x->str, addr - x->val);
1593 }
1594 else
1595 tprintf("%s, ", x->str);
1596 }
1597 else
1598 tprintf("%#lx, ", tcp->u_arg[2]);
1599#ifdef LINUX
1600 switch (tcp->u_arg[0]) {
1601 case PTRACE_PEEKDATA:
1602 case PTRACE_PEEKTEXT:
1603 case PTRACE_PEEKUSER:
1604 break;
1605 case PTRACE_CONT:
1606 case PTRACE_SINGLESTEP:
1607 case PTRACE_SYSCALL:
1608 case PTRACE_DETACH:
1609 printsignal(tcp->u_arg[3]);
1610 break;
1611 default:
1612 tprintf("%#lx", tcp->u_arg[3]);
1613 break;
1614 }
1615 } else {
1616 switch (tcp->u_arg[0]) {
1617 case PTRACE_PEEKDATA:
1618 case PTRACE_PEEKTEXT:
1619 case PTRACE_PEEKUSER:
1620 printnum(tcp, tcp->u_arg[3], "%#x");
1621 break;
1622 }
1623 }
1624#endif /* LINUX */
1625#ifdef SUNOS4
1626 if (tcp->u_arg[0] == PTRACE_WRITEDATA ||
1627 tcp->u_arg[0] == PTRACE_WRITETEXT) {
1628 tprintf("%lu, ", tcp->u_arg[3]);
1629 printstr(tcp, tcp->u_arg[4], tcp->u_arg[3]);
1630 } else if (tcp->u_arg[0] != PTRACE_READDATA &&
1631 tcp->u_arg[0] != PTRACE_READTEXT) {
1632 tprintf("%#lx", tcp->u_arg[3]);
1633 }
1634 } else {
1635 if (tcp->u_arg[0] == PTRACE_READDATA ||
1636 tcp->u_arg[0] == PTRACE_READTEXT) {
1637 tprintf("%lu, ", tcp->u_arg[3]);
1638 printstr(tcp, tcp->u_arg[4], tcp->u_arg[3]);
1639 }
1640 }
1641#endif /* SUNOS4 */
1642 return 0;
1643}
1644
1645#endif /* !SVR4 */