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