blob: de0c25af0eca418f7f6e4208a808cba76feaaf8b [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 Akkerman7a0b6491999-12-23 15:08:17 +000081/* WTA: this was `&& !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
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000319#ifdef LINUX
320
321/* defines copied from linux/sched.h since we can't include that
322 * ourselves (it conflicts with *lots* of libc includes)
323 */
324#define CSIGNAL 0x000000ff /* signal mask to be sent at exit */
325#define CLONE_VM 0x00000100 /* set if VM shared between processes */
326#define CLONE_FS 0x00000200 /* set if fs info shared between processes */
327#define CLONE_FILES 0x00000400 /* set if open files shared between processes */
328#define CLONE_SIGHAND 0x00000800 /* set if signal handlers shared */
329#define CLONE_PID 0x00001000 /* set if pid shared */
330#define CLONE_PTRACE 0x00002000 /* set if we want to let tracing continue on the child too */
331#define CLONE_VFORK 0x00004000 /* set if the parent wants the child to wake it up on mm_release */
332#define CLONE_PARENT 0x00008000 /* set if we want to have the same parent as the cloner */
333
334static struct xlat clone_flags[] = {
335 { CLONE_VM, "CLONE_VM" },
336 { CLONE_FS, "CLONE_FS" },
337 { CLONE_FILES, "CLONE_FILES" },
338 { CLONE_SIGHAND, "CLONE_SIGHAND" },
339 { CLONE_PID, "CLONE_PID" },
340 { CLONE_PTRACE, "CLONE_PTRACE" },
341 { CLONE_VFORK, "CLONE_VFORK" },
342 { CLONE_PARENT, "CLONE_PARENT" },
343 { 0, NULL },
344};
345
346#endif
347
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000348int
349sys_fork(tcp)
350struct tcb *tcp;
351{
352 if (exiting(tcp))
353 return RVAL_UDECIMAL;
354 return 0;
355}
356
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000357#ifdef SYS_clone
358int
359internal_clone(tcp)
360struct tcb *tcp;
361{
Ulrich Drepper90512f01999-12-24 07:22:25 +0000362 struct tcb *tcpchild;
363 int pid;
364 int dont_follow = 0;
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000365 if (entering(tcp)) {
366 tprintf("fn=%#lx, child_stack=%#lx, flags=",
367 tcp->u_arg[0], tcp->u_arg[1]);
368 if (printflags(clone_flags, tcp->u_arg[2]) == 0)
369 tprintf("0");
370 tprintf(", args=%#lx", tcp->u_arg[3]);
371
372 /* For now we don't follow clone yet.. we're just preparing the code */
373 dont_follow = 1;
374
375 if (!followfork || dont_follow)
376 return 0;
377 if (nprocs == MAX_PROCS) {
378 tcp->flags &= ~TCB_FOLLOWFORK;
379 fprintf(stderr, "sys_fork: tcb table full\n");
380 return 0;
381 }
382 tcp->flags |= TCB_FOLLOWFORK;
383
384 /* XXX
Ulrich Drepper90512f01999-12-24 07:22:25 +0000385 * We will take the simple approach and add CLONE_PTRACE to the clone
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000386 * options. This only works on Linux 2.2.x and later. This means that
387 * we break all programs using clone on older kernels..
388 * We should try to fallback to the bpt-trick if this fails, but right
389 * now we don't.
390 */
391
392 /* TODO: actually change the flags */
393 } else {
394 if (!(tcp->flags & TCB_FOLLOWFORK))
395 return 0;
396
397 if (syserror(tcp))
398 return 0;
399
400 pid = tcp->u_rval;
401 if ((tcpchild = alloctcb(pid)) == NULL) {
402 fprintf(stderr, " [tcb table full]\n");
403 kill(pid, SIGKILL); /* XXX */
404 return 0;
405 }
406
407 /* For fork we need to re-attach, but thanks to CLONE_PTRACE we're
408 * already attached.
409 */
Ulrich Drepper90512f01999-12-24 07:22:25 +0000410 tcpchild->flags |= TCB_ATTACHED;
411 newoutf(tcpchild);
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000412 tcp->nchildren++;
413 if (!qflag)
414 fprintf(stderr, "Process %d attached\n", pid);
415 }
416 return 0;
417}
418#endif
419
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000420int
421internal_fork(tcp)
422struct tcb *tcp;
423{
424 struct tcb *tcpchild;
425 int pid;
Nate Sammonsccd8f211999-03-29 22:57:54 +0000426 int dont_follow = 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000427
428#ifdef SYS_vfork
Nate Sammonsccd8f211999-03-29 22:57:54 +0000429 if (tcp->scno == SYS_vfork) {
430#if defined(I386) && defined(LINUX)
431 /* Attempt to make vfork into fork, which we can follow. */
432 if (!followvfork ||
433 ptrace(PTRACE_POKEUSR, tcp->pid,
434 (void *)(ORIG_EAX * 4), SYS_fork) < 0)
435 dont_follow = 1;
436
437#else
438 dont_follow = 1;
439#endif
440 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000441#endif
Nate Sammons38508fd1999-03-29 23:02:29 +0000442#ifdef SYS_clone
443 /* clone can do many things, not all of which we know how to handle.
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000444 Don't do much for now. */
445 if (tcp->scno == SYS_clone) {
446 if (entering(tcp)) {
447 tprintf("fn=%#lx, child_stack=%#lx, flags=",
448 tcp->u_arg[0], tcp->u_arg[1]);
449 if (printflags(clone_flags, tcp->u_arg[2]) == 0)
450 tprintf("0");
451 tprintf(", args=%#lx", tcp->u_arg[3]);
452 }
Nate Sammons38508fd1999-03-29 23:02:29 +0000453 dont_follow = 1;
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000454 }
Nate Sammons38508fd1999-03-29 23:02:29 +0000455#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000456 if (entering(tcp)) {
Nate Sammonsccd8f211999-03-29 22:57:54 +0000457 if (!followfork || dont_follow)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000458 return 0;
459 if (nprocs == MAX_PROCS) {
460 tcp->flags &= ~TCB_FOLLOWFORK;
461 fprintf(stderr, "sys_fork: tcb table full\n");
462 return 0;
463 }
464 tcp->flags |= TCB_FOLLOWFORK;
465 if (setbpt(tcp) < 0)
466 return 0;
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000467 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000468 else {
469 int bpt = tcp->flags & TCB_BPTSET;
470
471 if (!(tcp->flags & TCB_FOLLOWFORK))
472 return 0;
473 if (bpt)
474 clearbpt(tcp);
475
476 if (syserror(tcp))
477 return 0;
478
479 pid = tcp->u_rval;
480 if ((tcpchild = alloctcb(pid)) == NULL) {
481 fprintf(stderr, " [tcb table full]\n");
482 kill(pid, SIGKILL); /* XXX */
483 return 0;
484 }
485#ifdef LINUX
486 if (ptrace(PTRACE_ATTACH, pid, (char *) 1, 0) < 0) {
487 perror("PTRACE_ATTACH");
488 fprintf(stderr, "Too late?\n");
489 droptcb(tcpchild);
490 return 0;
491 }
492#endif /* LINUX */
493#ifdef SUNOS4
494#ifdef oldway
495 /* The child must have run before it can be attached. */
496 {
497 struct timeval tv;
498 tv.tv_sec = 0;
499 tv.tv_usec = 10000;
500 select(0, NULL, NULL, NULL, &tv);
501 }
502 if (ptrace(PTRACE_ATTACH, pid, (char *)1, 0) < 0) {
503 perror("PTRACE_ATTACH");
504 fprintf(stderr, "Too late?\n");
505 droptcb(tcpchild);
506 return 0;
507 }
508#else /* !oldway */
509 /* Try to catch the new process as soon as possible. */
510 {
511 int i;
512 for (i = 0; i < 1024; i++)
513 if (ptrace(PTRACE_ATTACH, pid, (char *) 1, 0) >= 0)
514 break;
515 if (i == 1024) {
516 perror("PTRACE_ATTACH");
517 fprintf(stderr, "Too late?\n");
518 droptcb(tcpchild);
519 return 0;
520 }
521 }
522#endif /* !oldway */
523#endif /* SUNOS4 */
524 tcpchild->flags |= TCB_ATTACHED;
525 /* Child has BPT too, must be removed on first occasion */
526 if (bpt) {
527 tcpchild->flags |= TCB_BPTSET;
528 tcpchild->baddr = tcp->baddr;
529 memcpy(tcpchild->inst, tcp->inst,
530 sizeof tcpchild->inst);
531 }
532 newoutf(tcpchild);
533 tcpchild->parent = tcp;
534 tcp->nchildren++;
535 if (!qflag)
536 fprintf(stderr, "Process %d attached\n", pid);
537 }
538 return 0;
539}
540
541#endif /* !SVR4 */
542
543#if defined(SUNOS4) || defined(LINUX)
544
545int
546sys_vfork(tcp)
547struct tcb *tcp;
548{
549 if (exiting(tcp))
550 return RVAL_UDECIMAL;
551 return 0;
552}
553
554#endif /* SUNOS4 || LINUX */
555
556#ifndef LINUX
557
558static char idstr[16];
559
560int
561sys_getpid(tcp)
562struct tcb *tcp;
563{
564 if (exiting(tcp)) {
565 sprintf(idstr, "ppid %lu", getrval2(tcp));
566 tcp->auxstr = idstr;
567 return RVAL_STR;
568 }
569 return 0;
570}
571
572int
573sys_getuid(tcp)
574struct tcb *tcp;
575{
576 if (exiting(tcp)) {
577 sprintf(idstr, "euid %lu", getrval2(tcp));
578 tcp->auxstr = idstr;
579 return RVAL_STR;
580 }
581 return 0;
582}
583
584int
585sys_getgid(tcp)
586struct tcb *tcp;
587{
588 if (exiting(tcp)) {
589 sprintf(idstr, "egid %lu", getrval2(tcp));
590 tcp->auxstr = idstr;
591 return RVAL_STR;
592 }
593 return 0;
594}
595
596#endif /* !LINUX */
597
598#ifdef LINUX
599
600int
601sys_setuid(tcp)
602struct tcb *tcp;
603{
604 if (entering(tcp)) {
605 tprintf("%u", (uid_t) tcp->u_arg[0]);
606 }
607 return 0;
608}
609
610int
611sys_setgid(tcp)
612struct tcb *tcp;
613{
614 if (entering(tcp)) {
615 tprintf("%u", (gid_t) tcp->u_arg[0]);
616 }
617 return 0;
618}
619
620int
621sys_getresuid(tcp)
622 struct tcb *tcp;
623{
624 if (exiting(tcp)) {
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000625 __kernel_uid_t uid;
626 if (syserror(tcp))
627 tprintf("%#lx, %#lx, %#lx", tcp->u_arg[0],
628 tcp->u_arg[1], tcp->u_arg[2]);
629 else {
630 if (umove(tcp, tcp->u_arg[0], &uid) < 0)
631 tprintf("%#lx, ", tcp->u_arg[0]);
632 else
633 tprintf("ruid %lu, ", (unsigned long) uid);
634 if (umove(tcp, tcp->u_arg[0], &uid) < 0)
635 tprintf("%#lx, ", tcp->u_arg[0]);
636 else
637 tprintf("euid %lu, ", (unsigned long) uid);
638 if (umove(tcp, tcp->u_arg[0], &uid) < 0)
639 tprintf("%#lx", tcp->u_arg[0]);
640 else
641 tprintf("suid %lu", (unsigned long) uid);
642 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000643 }
644 return 0;
645}
646
647int
648sys_getresgid(tcp)
649struct tcb *tcp;
650{
651 if (exiting(tcp)) {
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000652 __kernel_gid_t gid;
653 if (syserror(tcp))
654 tprintf("%#lx, %#lx, %#lx", tcp->u_arg[0],
655 tcp->u_arg[1], tcp->u_arg[2]);
656 else {
657 if (umove(tcp, tcp->u_arg[0], &gid) < 0)
658 tprintf("%#lx, ", tcp->u_arg[0]);
659 else
660 tprintf("rgid %lu, ", (unsigned long) gid);
661 if (umove(tcp, tcp->u_arg[0], &gid) < 0)
662 tprintf("%#lx, ", tcp->u_arg[0]);
663 else
664 tprintf("egid %lu, ", (unsigned long) gid);
665 if (umove(tcp, tcp->u_arg[0], &gid) < 0)
666 tprintf("%#lx", tcp->u_arg[0]);
667 else
668 tprintf("sgid %lu", (unsigned long) gid);
669 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000670 }
671 return 0;
672}
673
674#endif /* LINUX */
675
676int
677sys_setreuid(tcp)
678struct tcb *tcp;
679{
680 if (entering(tcp)) {
681 tprintf("%lu, %lu",
682 (unsigned long) (uid_t) tcp->u_arg[0],
683 (unsigned long) (uid_t) tcp->u_arg[1]);
684 }
685 return 0;
686}
687
688int
689sys_setregid(tcp)
690struct tcb *tcp;
691{
692 if (entering(tcp)) {
693 tprintf("%lu, %lu",
694 (unsigned long) (gid_t) tcp->u_arg[0],
695 (unsigned long) (gid_t) tcp->u_arg[1]);
696 }
697 return 0;
698}
699
700#ifdef LINUX
701int
702sys_setresuid(tcp)
703 struct tcb *tcp;
704{
705 if (entering(tcp)) {
706 tprintf("ruid %u, euid %u, suid %u",
707 (uid_t) tcp->u_arg[0],
708 (uid_t) tcp->u_arg[1],
709 (uid_t) tcp->u_arg[2]);
710 }
711 return 0;
712}
713int
714sys_setresgid(tcp)
715 struct tcb *tcp;
716{
717 if (entering(tcp)) {
718 tprintf("rgid %u, egid %u, sgid %u",
719 (uid_t) tcp->u_arg[0],
720 (uid_t) tcp->u_arg[1],
721 (uid_t) tcp->u_arg[2]);
722 }
723 return 0;
724}
725
726#endif /* LINUX */
727
728int
729sys_setgroups(tcp)
730struct tcb *tcp;
731{
732 int i, len;
733 GETGROUPS_T *gidset;
734
735 if (entering(tcp)) {
736 len = tcp->u_arg[0];
737 tprintf("%u, ", len);
738 if (len <= 0) {
739 tprintf("[]");
740 return 0;
741 }
742 gidset = (GETGROUPS_T *) malloc(len * sizeof(GETGROUPS_T));
743 if (gidset == NULL) {
744 fprintf(stderr, "sys_setgroups: out of memory\n");
745 return -1;
746 }
747 if (!verbose(tcp))
748 tprintf("%#lx", tcp->u_arg[1]);
749 else if (umoven(tcp, tcp->u_arg[1],
750 len * sizeof(GETGROUPS_T), (char *) gidset) < 0)
751 tprintf("[?]");
752 else {
753 tprintf("[");
754 for (i = 0; i < len; i++)
755 tprintf("%s%lu", i ? ", " : "",
756 (unsigned long) gidset[i]);
757 tprintf("]");
758 }
759 free((char *) gidset);
760 }
761 return 0;
762}
763
764int
765sys_getgroups(tcp)
766struct tcb *tcp;
767{
768 int i, len;
769 GETGROUPS_T *gidset;
770
771 if (entering(tcp)) {
772 len = tcp->u_arg[0];
773 tprintf("%u, ", len);
774 } else {
775 len = tcp->u_rval;
776 if (len <= 0) {
777 tprintf("[]");
778 return 0;
779 }
780 gidset = (GETGROUPS_T *) malloc(len * sizeof(GETGROUPS_T));
781 if (gidset == NULL) {
782 fprintf(stderr, "sys_getgroups: out of memory\n");
783 return -1;
784 }
785 if (!tcp->u_arg[1])
786 tprintf("NULL");
787 else if (!verbose(tcp) || tcp->u_arg[0] == 0)
788 tprintf("%#lx", tcp->u_arg[1]);
789 else if (umoven(tcp, tcp->u_arg[1],
790 len * sizeof(GETGROUPS_T), (char *) gidset) < 0)
791 tprintf("[?]");
792 else {
793 tprintf("[");
794 for (i = 0; i < len; i++)
795 tprintf("%s%lu", i ? ", " : "",
796 (unsigned long) gidset[i]);
797 tprintf("]");
798 }
799 free((char *)gidset);
800 }
801 return 0;
802}
803
804int
805sys_setpgrp(tcp)
806struct tcb *tcp;
807{
808 if (entering(tcp)) {
809#ifndef SVR4
810 tprintf("%lu, %lu", tcp->u_arg[0], tcp->u_arg[1]);
811#endif /* !SVR4 */
812 }
813 return 0;
814}
815
816int
817sys_getpgrp(tcp)
818struct tcb *tcp;
819{
820 if (entering(tcp)) {
821#ifndef SVR4
822 tprintf("%lu", tcp->u_arg[0]);
823#endif /* !SVR4 */
824 }
825 return 0;
826}
827
828int
829sys_getsid(tcp)
830struct tcb *tcp;
831{
832 if (entering(tcp)) {
833 tprintf("%lu", tcp->u_arg[0]);
834 }
835 return 0;
836}
837
838int
839sys_setsid(tcp)
840struct tcb *tcp;
841{
842 return 0;
843}
844
845int
846sys_getpgid(tcp)
847struct tcb *tcp;
848{
849 if (entering(tcp)) {
850 tprintf("%lu", tcp->u_arg[0]);
851 }
852 return 0;
853}
854
855int
856sys_setpgid(tcp)
857struct tcb *tcp;
858{
859 if (entering(tcp)) {
860 tprintf("%lu, %lu", tcp->u_arg[0], tcp->u_arg[1]);
861 }
862 return 0;
863}
864
865void
866fake_execve(tcp, program, argv, envp)
867struct tcb *tcp;
868char *program;
869char *argv[];
870char *envp[];
871{
872 int i;
873
874#ifdef ARM
875 if (!(qual_flags[SYS_execve - __NR_SYSCALL_BASE] & QUAL_TRACE))
876 return;
877#else
878 if (!(qual_flags[SYS_execve] & QUAL_TRACE))
879 return;
880#endif /* !ARM */
881 printleader(tcp);
882 tprintf("execve(");
883 string_quote(program);
884 tprintf(", [");
885 for (i = 0; argv[i] != NULL; i++) {
886 if (i != 0)
887 tprintf(", ");
888 string_quote(argv[i]);
889 }
890 for (i = 0; envp[i] != NULL; i++)
891 ;
892 tprintf("], [/* %d var%s */]) ", i, (i != 1) ? "s" : "");
893 tabto(acolumn);
894 tprintf("= 0");
895 printtrailer(tcp);
896}
897
898static void
899printargv(tcp, addr)
900struct tcb *tcp;
901long addr;
902{
903 char *cp;
904 char *sep;
905 int max = max_strlen / 2;
906
907 for (sep = ""; --max >= 0; sep = ", ") {
908 if (!abbrev(tcp))
909 max++;
910 if (umove(tcp, addr, &cp) < 0) {
911 tprintf("%#lx", addr);
912 return;
913 }
914 if (cp == 0)
915 break;
916 tprintf(sep);
917 printstr(tcp, (long) cp, -1);
918 addr += sizeof(char *);
919 }
920 if (cp)
921 tprintf(", ...");
922}
923
924static void
925printargc(fmt, tcp, addr)
926char *fmt;
927struct tcb *tcp;
928long addr;
929{
930 int count;
931 char *cp;
932
933 for (count = 0; umove(tcp, addr, &cp) >= 0 && cp != NULL; count++) {
934 addr += sizeof(char *);
935 }
936 tprintf(fmt, count, count == 1 ? "" : "s");
937}
938
939int
940sys_execv(tcp)
941struct tcb *tcp;
942{
943 if (entering(tcp)) {
944 printpath(tcp, tcp->u_arg[0]);
945 if (!verbose(tcp))
946 tprintf(", %#lx", tcp->u_arg[1]);
947#if 0
948 else if (abbrev(tcp))
949 printargc(", [/* %d arg%s */]", tcp, tcp->u_arg[1]);
950#endif
951 else {
952 tprintf(", [");
953 printargv(tcp, tcp->u_arg[1]);
954 tprintf("]");
955 }
956 }
957 return 0;
958}
959
960int
961sys_execve(tcp)
962struct tcb *tcp;
963{
964 if (entering(tcp)) {
965 printpath(tcp, tcp->u_arg[0]);
966 if (!verbose(tcp))
967 tprintf(", %#lx", tcp->u_arg[1]);
968#if 0
969 else if (abbrev(tcp))
970 printargc(", [/* %d arg%s */]", tcp, tcp->u_arg[1]);
971#endif
972 else {
973 tprintf(", [");
974 printargv(tcp, tcp->u_arg[1]);
975 tprintf("]");
976 }
977 if (!verbose(tcp))
978 tprintf(", %#lx", tcp->u_arg[2]);
979 else if (abbrev(tcp))
980 printargc(", [/* %d var%s */]", tcp, tcp->u_arg[2]);
981 else {
982 tprintf(", [");
983 printargv(tcp, tcp->u_arg[2]);
984 tprintf("]");
985 }
986 }
987#ifdef LINUX
988#if defined(ALPHA) || defined(SPARC) || defined(POWERPC)
989 tcp->flags |= TCB_WAITEXECVE;
990#endif /* ALPHA || SPARC || POWERPC */
991#endif /* LINUX */
992 return 0;
993}
994
995int
996internal_exec(tcp)
997struct tcb *tcp;
998{
999#ifdef SUNOS4
1000 if (exiting(tcp) && !syserror(tcp) && followfork)
1001 fixvfork(tcp);
1002#endif /* SUNOS4 */
1003 return 0;
1004}
1005
1006#ifdef LINUX
1007#ifndef __WCLONE
1008#define __WCLONE 0x8000000
1009#endif
1010#endif /* LINUX */
1011
1012static struct xlat wait4_options[] = {
1013 { WNOHANG, "WNOHANG" },
1014#ifndef WSTOPPED
1015 { WUNTRACED, "WUNTRACED" },
1016#endif
1017#ifdef WEXITED
1018 { WEXITED, "WEXITED" },
1019#endif
1020#ifdef WTRAPPED
1021 { WTRAPPED, "WTRAPPED" },
1022#endif
1023#ifdef WSTOPPED
1024 { WSTOPPED, "WSTOPPED" },
1025#endif
1026#ifdef WCONTINUED
1027 { WCONTINUED, "WCONTINUED" },
1028#endif
1029#ifdef WNOWAIT
1030 { WNOWAIT, "WNOWAIT" },
1031#endif
1032#ifdef __WCLONE
1033 { __WCLONE, "__WCLONE" },
1034#endif
1035 { 0, NULL },
1036};
1037
1038static int
1039printstatus(status)
1040int status;
1041{
1042 int exited = 0;
1043
1044 /*
1045 * Here is a tricky presentation problem. This solution
1046 * is still not entirely satisfactory but since there
1047 * are no wait status constructors it will have to do.
1048 */
1049 if (WIFSTOPPED(status))
1050 tprintf("[WIFSTOPPED(s) && WSTOPSIG(s) == %s]",
Nate Sammonsce780fc1999-03-29 23:23:13 +00001051 signame(WSTOPSIG(status)));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001052 else if WIFSIGNALED(status)
1053 tprintf("[WIFSIGNALED(s) && WTERMSIG(s) == %s%s]",
Nate Sammonsce780fc1999-03-29 23:23:13 +00001054 signame(WTERMSIG(status)),
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001055 WCOREDUMP(status) ? " && WCOREDUMP(s)" : "");
1056 else if WIFEXITED(status) {
1057 tprintf("[WIFEXITED(s) && WEXITSTATUS(s) == %d]",
1058 WEXITSTATUS(status));
1059 exited = 1;
1060 }
1061 else
1062 tprintf("[%#x]", status);
1063 return exited;
1064}
1065
1066static int
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001067printwaitn(tcp, n, bitness)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001068struct tcb *tcp;
1069int n;
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001070int bitness;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001071{
1072 int status;
1073 int exited = 0;
1074
1075 if (entering(tcp)) {
1076 tprintf("%ld, ", tcp->u_arg[0]);
1077 } else {
1078 /* status */
1079 if (!tcp->u_arg[1])
1080 tprintf("NULL");
1081 else if (syserror(tcp) || tcp->u_rval == 0)
1082 tprintf("%#lx", tcp->u_arg[1]);
1083 else if (umove(tcp, tcp->u_arg[1], &status) < 0)
1084 tprintf("[?]");
1085 else
1086 exited = printstatus(status);
1087 /* options */
1088 tprintf(", ");
1089 if (!printflags(wait4_options, tcp->u_arg[2]))
1090 tprintf("0");
1091 if (n == 4) {
1092 tprintf(", ");
1093 /* usage */
1094 if (!tcp->u_arg[3])
1095 tprintf("NULL");
1096#ifdef LINUX
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001097 else if (tcp->u_rval > 0) {
1098#ifdef LINUX_64BIT
1099 if (bitness)
1100 printrusage32(tcp, tcp->u_arg[3]);
1101 else
1102#endif
1103 printrusage(tcp, tcp->u_arg[3]);
1104 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001105#endif /* LINUX */
1106#ifdef SUNOS4
1107 else if (tcp->u_rval > 0 && exited)
1108 printrusage(tcp, tcp->u_arg[3]);
1109#endif /* SUNOS4 */
1110 else
1111 tprintf("%#lx", tcp->u_arg[3]);
1112 }
1113 }
1114 return 0;
1115}
1116
1117int
1118internal_wait(tcp)
1119struct tcb *tcp;
1120{
1121 if (entering(tcp)) {
Wichert Akkerman5daa0281999-03-15 19:49:42 +00001122 /* WTA: fix bug with hanging children */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001123 if (!(tcp->u_arg[2] & WNOHANG) && tcp->nchildren > 0) {
1124 /* There are traced children */
1125 tcp->flags |= TCB_SUSPENDED;
1126 tcp->waitpid = tcp->u_arg[0];
1127 }
1128 }
1129 return 0;
1130}
1131
1132#ifdef SVR4
1133
1134int
1135sys_wait(tcp)
1136struct tcb *tcp;
1137{
1138 if (exiting(tcp)) {
1139 /* The library wrapper stuffs this into the user variable. */
1140 if (!syserror(tcp))
1141 printstatus(getrval2(tcp));
1142 }
1143 return 0;
1144}
1145
1146#endif /* SVR4 */
1147
1148int
1149sys_waitpid(tcp)
1150struct tcb *tcp;
1151{
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001152 return printwaitn(tcp, 3, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001153}
1154
1155int
1156sys_wait4(tcp)
1157struct tcb *tcp;
1158{
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001159 return printwaitn(tcp, 4, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001160}
1161
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001162#ifdef ALPHA
1163int
1164sys_osf_wait4(tcp)
1165struct tcb *tcp;
1166{
1167 return printwaitn(tcp, 4, 1);
1168}
1169#endif
1170
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001171#ifdef SVR4
1172
1173static struct xlat waitid_types[] = {
1174 { P_PID, "P_PID" },
1175 { P_PPID, "P_PPID" },
1176 { P_PGID, "P_PGID" },
1177 { P_SID, "P_SID" },
1178 { P_CID, "P_CID" },
1179 { P_UID, "P_UID" },
1180 { P_GID, "P_GID" },
1181 { P_ALL, "P_ALL" },
1182#ifdef P_LWPID
1183 { P_LWPID, "P_LWPID" },
1184#endif
1185 { 0, NULL },
1186};
1187
1188static struct xlat siginfo_codes[] = {
1189#ifdef SI_NOINFO
1190 { SI_NOINFO, "SI_NOINFO" },
1191#endif
1192#ifdef SI_USER
1193 { SI_USER, "SI_USER" },
1194#endif
1195#ifdef SI_LWP
1196 { SI_LWP, "SI_LWP" },
1197#endif
1198#ifdef SI_QUEUE
1199 { SI_QUEUE, "SI_QUEUE" },
1200#endif
1201#ifdef SI_TIMER
1202 { SI_TIMER, "SI_TIMER" },
1203#endif
1204#ifdef SI_ASYNCIO
1205 { SI_ASYNCIO, "SI_ASYNCIO" },
1206#endif
1207#ifdef SI_MESGQ
1208 { SI_MESGQ, "SI_MESGQ" },
1209#endif
1210 { 0, NULL },
1211};
1212
1213static struct xlat sigtrap_codes[] = {
1214 { TRAP_BRKPT, "TRAP_BRKPT" },
1215 { TRAP_TRACE, "TRAP_TRACE" },
1216 { 0, NULL },
1217};
1218
1219static struct xlat sigcld_codes[] = {
1220 { CLD_EXITED, "CLD_EXITED" },
1221 { CLD_KILLED, "CLD_KILLED" },
1222 { CLD_DUMPED, "CLD_DUMPED" },
1223 { CLD_TRAPPED, "CLD_TRAPPED" },
1224 { CLD_STOPPED, "CLD_STOPPED" },
1225 { CLD_CONTINUED,"CLD_CONTINUED" },
1226 { 0, NULL },
1227};
1228
1229static struct xlat sigpoll_codes[] = {
1230 { POLL_IN, "POLL_IN" },
1231 { POLL_OUT, "POLL_OUT" },
1232 { POLL_MSG, "POLL_MSG" },
1233 { POLL_ERR, "POLL_ERR" },
1234 { POLL_PRI, "POLL_PRI" },
1235 { POLL_HUP, "POLL_HUP" },
1236 { 0, NULL },
1237};
1238
1239static struct xlat sigprof_codes[] = {
1240#ifdef PROF_SIG
1241 { PROF_SIG, "PROF_SIG" },
1242#endif
1243 { 0, NULL },
1244};
1245
1246static struct xlat sigill_codes[] = {
1247 { ILL_ILLOPC, "ILL_ILLOPC" },
1248 { ILL_ILLOPN, "ILL_ILLOPN" },
1249 { ILL_ILLADR, "ILL_ILLADR" },
1250 { ILL_ILLTRP, "ILL_ILLTRP" },
1251 { ILL_PRVOPC, "ILL_PRVOPC" },
1252 { ILL_PRVREG, "ILL_PRVREG" },
1253 { ILL_COPROC, "ILL_COPROC" },
1254 { ILL_BADSTK, "ILL_BADSTK" },
1255 { 0, NULL },
1256};
1257
1258static struct xlat sigemt_codes[] = {
1259#ifdef EMT_TAGOVF
1260 { EMT_TAGOVF, "EMT_TAGOVF" },
1261#endif
1262 { 0, NULL },
1263};
1264
1265static struct xlat sigfpe_codes[] = {
1266 { FPE_INTDIV, "FPE_INTDIV" },
1267 { FPE_INTOVF, "FPE_INTOVF" },
1268 { FPE_FLTDIV, "FPE_FLTDIV" },
1269 { FPE_FLTOVF, "FPE_FLTOVF" },
1270 { FPE_FLTUND, "FPE_FLTUND" },
1271 { FPE_FLTRES, "FPE_FLTRES" },
1272 { FPE_FLTINV, "FPE_FLTINV" },
1273 { FPE_FLTSUB, "FPE_FLTSUB" },
1274 { 0, NULL },
1275};
1276
1277static struct xlat sigsegv_codes[] = {
1278 { SEGV_MAPERR, "SEGV_MAPERR" },
1279 { SEGV_ACCERR, "SEGV_ACCERR" },
1280 { 0, NULL },
1281};
1282
1283static struct xlat sigbus_codes[] = {
1284 { BUS_ADRALN, "BUS_ADRALN" },
1285 { BUS_ADRERR, "BUS_ADRERR" },
1286 { BUS_OBJERR, "BUS_OBJERR" },
1287 { 0, NULL },
1288};
1289
1290void
1291printsiginfo(sip)
1292siginfo_t *sip;
1293{
1294 char *code;
1295
1296 tprintf("{si_signo=");
1297 printsignal(sip->si_signo);
1298 code = xlookup(siginfo_codes, sip->si_code);
1299 if (!code) {
1300 switch (sip->si_signo) {
1301 case SIGTRAP:
1302 code = xlookup(sigtrap_codes, sip->si_code);
1303 break;
1304 case SIGCHLD:
1305 code = xlookup(sigcld_codes, sip->si_code);
1306 break;
1307 case SIGPOLL:
1308 code = xlookup(sigpoll_codes, sip->si_code);
1309 break;
1310 case SIGPROF:
1311 code = xlookup(sigprof_codes, sip->si_code);
1312 break;
1313 case SIGILL:
1314 code = xlookup(sigill_codes, sip->si_code);
1315 break;
1316 case SIGEMT:
1317 code = xlookup(sigemt_codes, sip->si_code);
1318 break;
1319 case SIGFPE:
1320 code = xlookup(sigfpe_codes, sip->si_code);
1321 break;
1322 case SIGSEGV:
1323 code = xlookup(sigsegv_codes, sip->si_code);
1324 break;
1325 case SIGBUS:
1326 code = xlookup(sigbus_codes, sip->si_code);
1327 break;
1328 }
1329 }
1330 if (code)
1331 tprintf(", si_code=%s", code);
1332 else
1333 tprintf(", si_code=%#x", sip->si_code);
1334#ifdef SI_NOINFO
1335 if (sip->si_code != SI_NOINFO) {
1336#endif
1337 if (sip->si_errno) {
1338 if (sip->si_errno < 0 || sip->si_errno >= nerrnos)
1339 tprintf(", si_errno=%d", sip->si_errno);
1340 else
1341 tprintf(", si_errno=%s",
1342 errnoent[sip->si_errno]);
1343 }
1344 if (SI_FROMUSER(sip)) {
1345#ifdef SI_QUEUE
1346 tprintf(", si_pid=%ld, si_uid=%ld",
1347 sip->si_pid, sip->si_uid);
1348 switch (sip->si_code) {
1349 case SI_QUEUE:
1350#ifdef SI_TIMER
1351 case SI_TIMER:
1352#endif /* SI_QUEUE */
1353 case SI_ASYNCIO:
1354#ifdef SI_MESGQ
1355 case SI_MESGQ:
1356#endif /* SI_MESGQ */
1357 tprintf(", si_value=%d",
1358 sip->si_value.sival_int);
1359 break;
1360 }
1361#endif /* SI_QUEUE */
1362 }
1363 else {
1364 switch (sip->si_signo) {
1365 case SIGCHLD:
1366 tprintf(", si_pid=%ld, si_status=",
1367 sip->si_pid);
1368 if (sip->si_code == CLD_EXITED)
1369 tprintf("%d", sip->si_status);
1370 else
1371 printsignal(sip->si_status);
1372 break;
1373 case SIGILL: case SIGFPE:
1374 case SIGSEGV: case SIGBUS:
1375 tprintf(", si_addr=%#lx",
1376 (unsigned long) sip->si_addr);
1377 break;
1378 case SIGPOLL:
1379 switch (sip->si_code) {
1380 case POLL_IN: case POLL_OUT: case POLL_MSG:
1381 tprintf(", si_band=%ld",
1382 (long) sip->si_band);
1383 break;
1384 }
1385 break;
1386 }
1387 }
1388 tprintf(", ...");
1389#ifdef SI_NOINFO
1390 }
1391#endif
1392 tprintf("}");
1393}
1394
1395int
1396sys_waitid(tcp)
1397struct tcb *tcp;
1398{
1399 siginfo_t si;
1400 int exited;
1401
1402 if (entering(tcp)) {
1403 printxval(waitid_types, tcp->u_arg[0], "P_???");
1404 tprintf(", %ld, ", tcp->u_arg[1]);
1405 if (tcp->nchildren > 0) {
1406 /* There are traced children */
1407 tcp->flags |= TCB_SUSPENDED;
1408 tcp->waitpid = tcp->u_arg[0];
1409 }
1410 }
1411 else {
1412 /* siginfo */
1413 exited = 0;
1414 if (!tcp->u_arg[2])
1415 tprintf("NULL");
1416 else if (syserror(tcp))
1417 tprintf("%#lx", tcp->u_arg[2]);
1418 else if (umove(tcp, tcp->u_arg[2], &si) < 0)
1419 tprintf("{???}");
1420 else
1421 printsiginfo(&si);
1422 /* options */
1423 tprintf(", ");
1424 if (!printflags(wait4_options, tcp->u_arg[3]))
1425 tprintf("0");
1426 }
1427 return 0;
1428}
1429
1430#endif /* SVR4 */
1431
1432int
1433sys_alarm(tcp)
1434struct tcb *tcp;
1435{
1436 if (entering(tcp))
1437 tprintf("%lu", tcp->u_arg[0]);
1438 return 0;
1439}
1440
1441int
1442sys_uname(tcp)
1443struct tcb *tcp;
1444{
1445 struct utsname uname;
1446
1447 if (exiting(tcp)) {
1448 if (syserror(tcp) || !verbose(tcp))
1449 tprintf("%#lx", tcp->u_arg[0]);
1450 else if (umove(tcp, tcp->u_arg[0], &uname) < 0)
1451 tprintf("{...}");
1452 else if (!abbrev(tcp)) {
1453
1454 tprintf("{sysname=\"%s\", nodename=\"%s\", ",
1455 uname.sysname, uname.nodename);
1456 tprintf("release=\"%s\", version=\"%s\", ",
1457 uname.release, uname.version);
1458 tprintf("machine=\"%s\"", uname.machine);
1459#ifdef LINUX
1460#ifndef __GLIBC__
1461 tprintf(", domainname=\"%s\"", uname.domainname);
1462#endif /* __GLIBC__ */
1463#endif /* LINUX */
1464 tprintf("}");
1465 }
1466 else
1467 tprintf("{sys=\"%s\", node=\"%s\", ...}",
1468 uname.sysname, uname.nodename);
1469 }
1470 return 0;
1471}
1472
1473#ifndef SVR4
1474
1475static struct xlat ptrace_cmds[] = {
1476 { PTRACE_TRACEME, "PTRACE_TRACEME" },
1477 { PTRACE_PEEKTEXT, "PTRACE_PEEKTEXT", },
1478 { PTRACE_PEEKDATA, "PTRACE_PEEKDATA", },
1479 { PTRACE_PEEKUSER, "PTRACE_PEEKUSER", },
1480 { PTRACE_POKETEXT, "PTRACE_POKETEXT", },
1481 { PTRACE_POKEDATA, "PTRACE_POKEDATA", },
1482 { PTRACE_POKEUSER, "PTRACE_POKEUSER", },
1483 { PTRACE_CONT, "PTRACE_CONT" },
1484 { PTRACE_KILL, "PTRACE_KILL" },
1485 { PTRACE_SINGLESTEP, "PTRACE_SINGLESTEP" },
1486 { PTRACE_ATTACH, "PTRACE_ATTACH" },
1487 { PTRACE_DETACH, "PTRACE_DETACH" },
1488#ifdef SUNOS4
1489 { PTRACE_GETREGS, "PTRACE_GETREGS" },
1490 { PTRACE_SETREGS, "PTRACE_SETREGS" },
1491 { PTRACE_GETFPREGS, "PTRACE_GETFPREGS", },
1492 { PTRACE_SETFPREGS, "PTRACE_SETFPREGS", },
1493 { PTRACE_READDATA, "PTRACE_READDATA" },
1494 { PTRACE_WRITEDATA, "PTRACE_WRITEDATA" },
1495 { PTRACE_READTEXT, "PTRACE_READTEXT" },
1496 { PTRACE_WRITETEXT, "PTRACE_WRITETEXT" },
1497 { PTRACE_GETFPAREGS, "PTRACE_GETFPAREGS" },
1498 { PTRACE_SETFPAREGS, "PTRACE_SETFPAREGS" },
1499#ifdef SPARC
1500 { PTRACE_GETWINDOW, "PTRACE_GETWINDOW" },
1501 { PTRACE_SETWINDOW, "PTRACE_SETWINDOW" },
1502#else /* !SPARC */
1503 { PTRACE_22, "PTRACE_PTRACE_22" },
1504 { PTRACE_23, "PTRACE_PTRACE_23" },
1505#endif /* !SPARC */
1506#endif /* SUNOS4 */
1507 { PTRACE_SYSCALL, "PTRACE_SYSCALL" },
1508#ifdef SUNOS4
1509 { PTRACE_DUMPCORE, "PTRACE_DUMPCORE" },
1510#ifdef I386
1511 { PTRACE_SETWRBKPT, "PTRACE_SETWRBKPT" },
1512 { PTRACE_SETACBKPT, "PTRACE_SETACBKPT" },
1513 { PTRACE_CLRDR7, "PTRACE_CLRDR7" },
1514#else /* !I386 */
1515 { PTRACE_26, "PTRACE_26" },
1516 { PTRACE_27, "PTRACE_27" },
1517 { PTRACE_28, "PTRACE_28" },
1518#endif /* !I386 */
1519 { PTRACE_GETUCODE, "PTRACE_GETUCODE" },
1520#endif /* SUNOS4 */
1521 { 0, NULL },
1522};
1523
1524#ifndef SUNOS4_KERNEL_ARCH_KLUDGE
1525static
1526#endif /* !SUNOS4_KERNEL_ARCH_KLUDGE */
1527struct xlat struct_user_offsets[] = {
1528#ifdef LINUX
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00001529#ifdef S390
1530 { PT_PSWMASK, "psw_mask" },
1531 { PT_PSWADDR, "psw_addr" },
1532 { PT_GPR0, "gpr0" },
1533 { PT_GPR1, "gpr1" },
1534 { PT_GPR2, "gpr2" },
1535 { PT_GPR3, "gpr3" },
1536 { PT_GPR4, "gpr4" },
1537 { PT_GPR5, "gpr5" },
1538 { PT_GPR6, "gpr6" },
1539 { PT_GPR7, "gpr7" },
1540 { PT_GPR8, "gpr8" },
1541 { PT_GPR9, "gpr9" },
1542 { PT_GPR10, "gpr10" },
1543 { PT_GPR11, "gpr11" },
1544 { PT_GPR12, "gpr12" },
1545 { PT_GPR13, "gpr13" },
1546 { PT_GPR14, "gpr14" },
1547 { PT_GPR15, "gpr15" },
1548 { PT_ACR0, "acr0" },
1549 { PT_ACR1, "acr1" },
1550 { PT_ACR2, "acr2" },
1551 { PT_ACR3, "acr3" },
1552 { PT_ACR4, "acr4" },
1553 { PT_ACR5, "acr5" },
1554 { PT_ACR6, "acr6" },
1555 { PT_ACR7, "acr7" },
1556 { PT_ACR8, "acr8" },
1557 { PT_ACR9, "acr9" },
1558 { PT_ACR10, "acr10" },
1559 { PT_ACR11, "acr11" },
1560 { PT_ACR12, "acr12" },
1561 { PT_ACR13, "acr13" },
1562 { PT_ACR14, "acr14" },
1563 { PT_ACR15, "acr15" },
1564 { PT_ORIGGPR2, "orig_gpr2" },
1565 { PT_FPC, "fpc" },
1566 { PT_FPR0_HI, "fpr0.hi" },
1567 { PT_FPR0_LO, "fpr0.lo" },
1568 { PT_FPR1_HI, "fpr1.hi" },
1569 { PT_FPR1_LO, "fpr1.lo" },
1570 { PT_FPR2_HI, "fpr2.hi" },
1571 { PT_FPR2_LO, "fpr2.lo" },
1572 { PT_FPR3_HI, "fpr3.hi" },
1573 { PT_FPR3_LO, "fpr3.lo" },
1574 { PT_FPR4_HI, "fpr4.hi" },
1575 { PT_FPR4_LO, "fpr4.lo" },
1576 { PT_FPR5_HI, "fpr5.hi" },
1577 { PT_FPR5_LO, "fpr5.lo" },
1578 { PT_FPR6_HI, "fpr6.hi" },
1579 { PT_FPR6_LO, "fpr6.lo" },
1580 { PT_FPR7_HI, "fpr7.hi" },
1581 { PT_FPR7_LO, "fpr7.lo" },
1582 { PT_FPR8_HI, "fpr8.hi" },
1583 { PT_FPR8_LO, "fpr8.lo" },
1584 { PT_FPR9_HI, "fpr9.hi" },
1585 { PT_FPR9_LO, "fpr9.lo" },
1586 { PT_FPR10_HI, "fpr10.hi" },
1587 { PT_FPR10_LO, "fpr10.lo" },
1588 { PT_FPR11_HI, "fpr11.hi" },
1589 { PT_FPR11_LO, "fpr11.lo" },
1590 { PT_FPR12_HI, "fpr12.hi" },
1591 { PT_FPR12_LO, "fpr12.lo" },
1592 { PT_FPR13_HI, "fpr13.hi" },
1593 { PT_FPR13_LO, "fpr13.lo" },
1594 { PT_FPR14_HI, "fpr14.hi" },
1595 { PT_FPR14_LO, "fpr14.lo" },
1596 { PT_FPR15_HI, "fpr15.hi" },
1597 { PT_FPR15_LO, "fpr15.lo" },
1598 { PT_CR_9, "cr9" },
1599 { PT_CR_10, "cr10" },
1600 { PT_CR_11, "cr11" },
1601#endif
1602#if defined(SPARC)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001603 /* XXX No support for these offsets yet. */
1604#elif defined(POWERPC)
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00001605 { 4*PT_R0, "4*PT_R0" },
1606 { 4*PT_R1, "4*PT_R1" },
1607 { 4*PT_R2, "4*PT_R2" },
1608 { 4*PT_R3, "4*PT_R3" },
1609 { 4*PT_R4, "4*PT_R4" },
1610 { 4*PT_R5, "4*PT_R5" },
1611 { 4*PT_R6, "4*PT_R6" },
1612 { 4*PT_R7, "4*PT_R7" },
1613 { 4*PT_R8, "4*PT_R8" },
1614 { 4*PT_R9, "4*PT_R9" },
1615 { 4*PT_R10, "4*PT_R10" },
1616 { 4*PT_R11, "4*PT_R11" },
1617 { 4*PT_R12, "4*PT_R12" },
1618 { 4*PT_R13, "4*PT_R13" },
1619 { 4*PT_R14, "4*PT_R14" },
1620 { 4*PT_R15, "4*PT_R15" },
1621 { 4*PT_R16, "4*PT_R16" },
1622 { 4*PT_R17, "4*PT_R17" },
1623 { 4*PT_R18, "4*PT_R18" },
1624 { 4*PT_R19, "4*PT_R19" },
1625 { 4*PT_R20, "4*PT_R20" },
1626 { 4*PT_R21, "4*PT_R21" },
1627 { 4*PT_R22, "4*PT_R22" },
1628 { 4*PT_R23, "4*PT_R23" },
1629 { 4*PT_R24, "4*PT_R24" },
1630 { 4*PT_R25, "4*PT_R25" },
1631 { 4*PT_R26, "4*PT_R26" },
1632 { 4*PT_R27, "4*PT_R27" },
1633 { 4*PT_R28, "4*PT_R28" },
1634 { 4*PT_R29, "4*PT_R29" },
1635 { 4*PT_R30, "4*PT_R30" },
1636 { 4*PT_R31, "4*PT_R31" },
1637 { 4*PT_NIP, "4*PT_NIP" },
1638 { 4*PT_MSR, "4*PT_MSR" },
1639 { 4*PT_ORIG_R3, "4*PT_ORIG_R3" },
1640 { 4*PT_CTR, "4*PT_CTR" },
1641 { 4*PT_LNK, "4*PT_LNK" },
1642 { 4*PT_XER, "4*PT_XER" },
1643 { 4*PT_CCR, "4*PT_CCR" },
1644 { 4*PT_FPR0, "4*PT_FPR0" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001645#else
1646#ifdef ALPHA
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00001647 { 0, "r0" },
1648 { 1, "r1" },
1649 { 2, "r2" },
1650 { 3, "r3" },
1651 { 4, "r4" },
1652 { 5, "r5" },
1653 { 6, "r6" },
1654 { 7, "r7" },
1655 { 8, "r8" },
1656 { 9, "r9" },
1657 { 10, "r10" },
1658 { 11, "r11" },
1659 { 12, "r12" },
1660 { 13, "r13" },
1661 { 14, "r14" },
1662 { 15, "r15" },
1663 { 16, "r16" },
1664 { 17, "r17" },
1665 { 18, "r18" },
1666 { 19, "r19" },
1667 { 20, "r20" },
1668 { 21, "r21" },
1669 { 22, "r22" },
1670 { 23, "r23" },
1671 { 24, "r24" },
1672 { 25, "r25" },
1673 { 26, "r26" },
1674 { 27, "r27" },
1675 { 28, "r28" },
1676 { 29, "gp" },
1677 { 30, "fp" },
1678 { 31, "zero" },
1679 { 32, "fp0" },
1680 { 33, "fp" },
1681 { 34, "fp2" },
1682 { 35, "fp3" },
1683 { 36, "fp4" },
1684 { 37, "fp5" },
1685 { 38, "fp6" },
1686 { 39, "fp7" },
1687 { 40, "fp8" },
1688 { 41, "fp9" },
1689 { 42, "fp10" },
1690 { 43, "fp11" },
1691 { 44, "fp12" },
1692 { 45, "fp13" },
1693 { 46, "fp14" },
1694 { 47, "fp15" },
1695 { 48, "fp16" },
1696 { 49, "fp17" },
1697 { 50, "fp18" },
1698 { 51, "fp19" },
1699 { 52, "fp20" },
1700 { 53, "fp21" },
1701 { 54, "fp22" },
1702 { 55, "fp23" },
1703 { 56, "fp24" },
1704 { 57, "fp25" },
1705 { 58, "fp26" },
1706 { 59, "fp27" },
1707 { 60, "fp28" },
1708 { 61, "fp29" },
1709 { 62, "fp30" },
1710 { 63, "fp31" },
1711 { 64, "pc" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001712#else /* !ALPHA */
1713#ifdef I386
1714 { 4*EBX, "4*EBX" },
1715 { 4*ECX, "4*ECX" },
1716 { 4*EDX, "4*EDX" },
1717 { 4*ESI, "4*ESI" },
1718 { 4*EDI, "4*EDI" },
1719 { 4*EBP, "4*EBP" },
1720 { 4*EAX, "4*EAX" },
1721 { 4*DS, "4*DS" },
1722 { 4*ES, "4*ES" },
1723 { 4*FS, "4*FS" },
1724 { 4*GS, "4*GS" },
1725 { 4*ORIG_EAX, "4*ORIG_EAX" },
1726 { 4*EIP, "4*EIP" },
1727 { 4*CS, "4*CS" },
1728 { 4*EFL, "4*EFL" },
1729 { 4*UESP, "4*UESP" },
1730 { 4*SS, "4*SS" },
1731#else /* !I386 */
1732#ifdef M68K
1733 { 4*PT_D1, "4*PT_D1" },
1734 { 4*PT_D2, "4*PT_D2" },
1735 { 4*PT_D3, "4*PT_D3" },
1736 { 4*PT_D4, "4*PT_D4" },
1737 { 4*PT_D5, "4*PT_D5" },
1738 { 4*PT_D6, "4*PT_D6" },
1739 { 4*PT_D7, "4*PT_D7" },
1740 { 4*PT_A0, "4*PT_A0" },
1741 { 4*PT_A1, "4*PT_A1" },
1742 { 4*PT_A2, "4*PT_A2" },
1743 { 4*PT_A3, "4*PT_A3" },
1744 { 4*PT_A4, "4*PT_A4" },
1745 { 4*PT_A5, "4*PT_A5" },
1746 { 4*PT_A6, "4*PT_A6" },
1747 { 4*PT_D0, "4*PT_D0" },
1748 { 4*PT_USP, "4*PT_USP" },
1749 { 4*PT_ORIG_D0, "4*PT_ORIG_D0" },
1750 { 4*PT_SR, "4*PT_SR" },
1751 { 4*PT_PC, "4*PT_PC" },
1752#endif /* M68K */
1753#endif /* !I386 */
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00001754#ifdef S390
1755 { uoff(u_fpvalid), "offsetof(struct user, u_fpvalid)" },
1756#endif
Wichert Akkermanf90da011999-10-31 21:15:38 +00001757#ifndef MIPS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001758 { uoff(u_fpvalid), "offsetof(struct user, u_fpvalid)" },
Wichert Akkermanf90da011999-10-31 21:15:38 +00001759#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001760#ifdef I386
1761 { uoff(i387), "offsetof(struct user, i387)" },
1762#else /* !I386 */
1763#ifdef M68K
1764 { uoff(m68kfp), "offsetof(struct user, m68kfp)" },
1765#endif /* M68K */
1766#endif /* !I386 */
1767 { uoff(u_tsize), "offsetof(struct user, u_tsize)" },
1768 { uoff(u_dsize), "offsetof(struct user, u_dsize)" },
1769 { uoff(u_ssize), "offsetof(struct user, u_ssize)" },
1770 { uoff(start_code), "offsetof(struct user, start_code)" },
1771 { uoff(start_stack), "offsetof(struct user, start_stack)" },
1772 { uoff(signal), "offsetof(struct user, signal)" },
Wichert Akkermanf90da011999-10-31 21:15:38 +00001773#ifndef MIPS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001774 { uoff(reserved), "offsetof(struct user, reserved)" },
Wichert Akkermanf90da011999-10-31 21:15:38 +00001775#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001776 { uoff(u_ar0), "offsetof(struct user, u_ar0)" },
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00001777#if !defined(ARM) && !defined(MIPS) && !defined(S390)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001778 { uoff(u_fpstate), "offsetof(struct user, u_fpstate)" },
1779#endif
1780 { uoff(magic), "offsetof(struct user, magic)" },
1781 { uoff(u_comm), "offsetof(struct user, u_comm)" },
1782#ifdef I386
1783 { uoff(u_debugreg), "offsetof(struct user, u_debugreg)" },
1784#endif /* I386 */
1785#endif /* !ALPHA */
1786#endif /* !POWERPC/!SPARC */
1787#endif /* LINUX */
1788#ifdef SUNOS4
1789 { uoff(u_pcb), "offsetof(struct user, u_pcb)" },
1790 { uoff(u_procp), "offsetof(struct user, u_procp)" },
1791 { uoff(u_ar0), "offsetof(struct user, u_ar0)" },
1792 { uoff(u_comm[0]), "offsetof(struct user, u_comm[0])" },
1793 { uoff(u_arg[0]), "offsetof(struct user, u_arg[0])" },
1794 { uoff(u_ap), "offsetof(struct user, u_ap)" },
1795 { uoff(u_qsave), "offsetof(struct user, u_qsave)" },
1796 { uoff(u_rval1), "offsetof(struct user, u_rval1)" },
1797 { uoff(u_rval2), "offsetof(struct user, u_rval2)" },
1798 { uoff(u_error), "offsetof(struct user, u_error)" },
1799 { uoff(u_eosys), "offsetof(struct user, u_eosys)" },
1800 { uoff(u_ssave), "offsetof(struct user, u_ssave)" },
1801 { uoff(u_signal[0]), "offsetof(struct user, u_signal)" },
1802 { uoff(u_sigmask[0]), "offsetof(struct user, u_sigmask)" },
1803 { uoff(u_sigonstack), "offsetof(struct user, u_sigonstack)" },
1804 { uoff(u_sigintr), "offsetof(struct user, u_sigintr)" },
1805 { uoff(u_sigreset), "offsetof(struct user, u_sigreset)" },
1806 { uoff(u_oldmask), "offsetof(struct user, u_oldmask)" },
1807 { uoff(u_code), "offsetof(struct user, u_code)" },
1808 { uoff(u_addr), "offsetof(struct user, u_addr)" },
1809 { uoff(u_sigstack), "offsetof(struct user, u_sigstack)" },
1810 { uoff(u_ofile), "offsetof(struct user, u_ofile)" },
1811 { uoff(u_pofile), "offsetof(struct user, u_pofile)" },
1812 { uoff(u_ofile_arr[0]), "offsetof(struct user, u_ofile_arr[0])" },
1813 { uoff(u_pofile_arr[0]),"offsetof(struct user, u_pofile_arr[0])"},
1814 { uoff(u_lastfile), "offsetof(struct user, u_lastfile)" },
1815 { uoff(u_cwd), "offsetof(struct user, u_cwd)" },
1816 { uoff(u_cdir), "offsetof(struct user, u_cdir)" },
1817 { uoff(u_rdir), "offsetof(struct user, u_rdir)" },
1818 { uoff(u_cmask), "offsetof(struct user, u_cmask)" },
1819 { uoff(u_ru), "offsetof(struct user, u_ru)" },
1820 { uoff(u_cru), "offsetof(struct user, u_cru)" },
1821 { uoff(u_timer[0]), "offsetof(struct user, u_timer[0])" },
1822 { uoff(u_XXX[0]), "offsetof(struct user, u_XXX[0])" },
1823 { uoff(u_ioch), "offsetof(struct user, u_ioch)" },
1824 { uoff(u_start), "offsetof(struct user, u_start)" },
1825 { uoff(u_acflag), "offsetof(struct user, u_acflag)" },
1826 { uoff(u_prof.pr_base), "offsetof(struct user, u_prof.pr_base)" },
1827 { uoff(u_prof.pr_size), "offsetof(struct user, u_prof.pr_size)" },
1828 { uoff(u_prof.pr_off), "offsetof(struct user, u_prof.pr_off)" },
1829 { uoff(u_prof.pr_scale),"offsetof(struct user, u_prof.pr_scale)"},
1830 { uoff(u_rlimit[0]), "offsetof(struct user, u_rlimit)" },
1831 { uoff(u_exdata.Ux_A), "offsetof(struct user, u_exdata.Ux_A)" },
1832 { uoff(u_exdata.ux_shell[0]),"offsetof(struct user, u_exdata.ux_shell[0])"},
1833 { uoff(u_lofault), "offsetof(struct user, u_lofault)" },
1834#endif /* SUNOS4 */
1835 { sizeof(struct user), "sizeof(struct user)" },
1836 { 0, NULL },
1837};
1838
1839int
1840sys_ptrace(tcp)
1841struct tcb *tcp;
1842{
1843 char *cmd;
1844 struct xlat *x;
1845 long addr;
1846
1847 cmd = xlookup(ptrace_cmds, tcp->u_arg[0]);
1848 if (!cmd)
1849 cmd = "PTRACE_???";
1850 if (entering(tcp)) {
1851 tprintf("%s, %lu, ", cmd, tcp->u_arg[1]);
1852 addr = tcp->u_arg[2];
1853 if (tcp->u_arg[0] == PTRACE_PEEKUSER
1854 || tcp->u_arg[0] == PTRACE_POKEUSER) {
1855 for (x = struct_user_offsets; x->str; x++) {
1856 if (x->val >= addr)
1857 break;
1858 }
1859 if (!x->str)
1860 tprintf("%#lx, ", addr);
1861 else if (x->val > addr && x != struct_user_offsets) {
1862 x--;
1863 tprintf("%s + %ld, ", x->str, addr - x->val);
1864 }
1865 else
1866 tprintf("%s, ", x->str);
1867 }
1868 else
1869 tprintf("%#lx, ", tcp->u_arg[2]);
1870#ifdef LINUX
1871 switch (tcp->u_arg[0]) {
1872 case PTRACE_PEEKDATA:
1873 case PTRACE_PEEKTEXT:
1874 case PTRACE_PEEKUSER:
1875 break;
1876 case PTRACE_CONT:
1877 case PTRACE_SINGLESTEP:
1878 case PTRACE_SYSCALL:
1879 case PTRACE_DETACH:
1880 printsignal(tcp->u_arg[3]);
1881 break;
1882 default:
1883 tprintf("%#lx", tcp->u_arg[3]);
1884 break;
1885 }
1886 } else {
1887 switch (tcp->u_arg[0]) {
1888 case PTRACE_PEEKDATA:
1889 case PTRACE_PEEKTEXT:
1890 case PTRACE_PEEKUSER:
1891 printnum(tcp, tcp->u_arg[3], "%#x");
1892 break;
1893 }
1894 }
1895#endif /* LINUX */
1896#ifdef SUNOS4
1897 if (tcp->u_arg[0] == PTRACE_WRITEDATA ||
1898 tcp->u_arg[0] == PTRACE_WRITETEXT) {
1899 tprintf("%lu, ", tcp->u_arg[3]);
1900 printstr(tcp, tcp->u_arg[4], tcp->u_arg[3]);
1901 } else if (tcp->u_arg[0] != PTRACE_READDATA &&
1902 tcp->u_arg[0] != PTRACE_READTEXT) {
1903 tprintf("%#lx", tcp->u_arg[3]);
1904 }
1905 } else {
1906 if (tcp->u_arg[0] == PTRACE_READDATA ||
1907 tcp->u_arg[0] == PTRACE_READTEXT) {
1908 tprintf("%lu, ", tcp->u_arg[3]);
1909 printstr(tcp, tcp->u_arg[4], tcp->u_arg[3]);
1910 }
1911 }
1912#endif /* SUNOS4 */
1913 return 0;
1914}
1915
1916#endif /* !SVR4 */