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