blob: 0a0f0a34dffc473fa565c7282632897d2c92ee2b [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 Akkerman36915a11999-07-13 15:45:02 +000052#ifdef HAVE_SYS_REG_H
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000053# include <sys/reg.h>
Wichert Akkerman15dea971999-10-06 13:06:34 +000054#ifndef PTRACE_PEEKUSR
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000055# define PTRACE_PEEKUSR PTRACE_PEEKUSER
Wichert Akkerman15dea971999-10-06 13:06:34 +000056#endif
57#ifndef PTRACE_POKEUSR
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000058# define PTRACE_POKEUSR PTRACE_POKEUSER
59#endif
Wichert Akkermanfaf72222000-02-19 23:59:03 +000060#elif defined(HAVE_LINUX_PTRACE_H)
61#undef PTRACE_SYSCALL
62#include <linux/ptrace.h>
Wichert Akkerman15dea971999-10-06 13:06:34 +000063#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000064
Wichert Akkermanfaf72222000-02-19 23:59:03 +000065
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000066#ifdef LINUX
Wichert Akkerman2e2553a1999-05-09 00:29:58 +000067#include <asm/posix_types.h>
68#undef GETGROUPS_T
69#define GETGROUPS_T __kernel_gid_t
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000070#endif /* LINUX */
71
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +000072#if defined(LINUX) && defined(IA64)
73# include <asm/ptrace_offsets.h>
74# include <asm/rse.h>
75#endif
76
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000077#ifdef HAVE_PRCTL
78#include <sys/prctl.h>
79#endif
80
81#ifndef WCOREDUMP
82#define WCOREDUMP(status) ((status) & 0200)
83#endif
84
Wichert Akkerman7a0b6491999-12-23 15:08:17 +000085/* WTA: this was `&& !defined(LINUXSPARC)', this seems unneeded though? */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000086#if defined(HAVE_PRCTL)
87static struct xlat prctl_options[] = {
88#ifdef PR_MAXPROCS
89 { PR_MAXPROCS, "PR_MAXPROCS" },
90#endif
91#ifdef PR_ISBLOCKED
92 { PR_ISBLOCKED, "PR_ISBLOCKED" },
93#endif
94#ifdef PR_SETSTACKSIZE
95 { PR_SETSTACKSIZE, "PR_SETSTACKSIZE" },
96#endif
97#ifdef PR_GETSTACKSIZE
98 { PR_GETSTACKSIZE, "PR_GETSTACKSIZE" },
99#endif
100#ifdef PR_MAXPPROCS
101 { PR_MAXPPROCS, "PR_MAXPPROCS" },
102#endif
103#ifdef PR_UNBLKONEXEC
104 { PR_UNBLKONEXEC, "PR_UNBLKONEXEC" },
105#endif
106#ifdef PR_ATOMICSIM
107 { PR_ATOMICSIM, "PR_ATOMICSIM" },
108#endif
109#ifdef PR_SETEXITSIG
110 { PR_SETEXITSIG, "PR_SETEXITSIG" },
111#endif
112#ifdef PR_RESIDENT
113 { PR_RESIDENT, "PR_RESIDENT" },
114#endif
115#ifdef PR_ATTACHADDR
116 { PR_ATTACHADDR, "PR_ATTACHADDR" },
117#endif
118#ifdef PR_DETACHADDR
119 { PR_DETACHADDR, "PR_DETACHADDR" },
120#endif
121#ifdef PR_TERMCHILD
122 { PR_TERMCHILD, "PR_TERMCHILD" },
123#endif
124#ifdef PR_GETSHMASK
125 { PR_GETSHMASK, "PR_GETSHMASK" },
126#endif
127#ifdef PR_GETNSHARE
128 { PR_GETNSHARE, "PR_GETNSHARE" },
129#endif
130#if defined(PR_SET_PDEATHSIG)
131 { PR_SET_PDEATHSIG, "PR_SET_PDEATHSIG" },
132#endif
Wichert Akkerman8829a551999-06-11 13:18:40 +0000133#ifdef PR_COREPID
134 { PR_COREPID, "PR_COREPID" },
135#endif
136#ifdef PR_ATTACHADDRPERM
137 { PR_ATTACHADDRPERM, "PR_ATTACHADDRPERM" },
138#endif
139#ifdef PR_PTHREADEXIT
140 { PR_PTHREADEXIT, "PR_PTHREADEXIT" },
141#endif
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000142#ifdef PR_SET_PDEATHSIG
143 { PR_SET_PDEATHSIG, "PR_SET_PDEATHSIG" },
144#endif
145#ifdef PR_GET_PDEATHSIG
146 { PR_GET_PDEATHSIG, "PR_GET_PDEATHSIG" },
147#endif
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000148#ifdef PR_GET_UNALIGN
149 { PR_GET_UNALIGN, "PR_GET_UNALIGN" },
150#endif
151#ifdef PR_SET_UNALIGN
152 { PR_SET_UNALIGN, "PR_SET_UNALIGN" },
153#endif
154#ifdef PR_GET_KEEPCAPS
155 { PR_GET_KEEPCAPS, "PR_GET_KEEP_CAPS" },
156#endif
157#ifdef PR_SET_KEEPCAPS
158 { PR_SET_KEEPCAPS, "PR_SET_KEEP_CAPS" },
159#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000160 { 0, NULL },
161};
162
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000163
164const char *
165unalignctl_string (unsigned int ctl)
166{
167 static char buf[16];
168
169 switch (ctl) {
170#ifdef PR_UNALIGN_NOPRINT
171 case PR_UNALIGN_NOPRINT:
172 return "NOPRINT";
173#endif
174#ifdef PR_UNALIGN_SIGBUS
175 case PR_UNALIGN_SIGBUS:
176 return "SIGBUS";
177#endif
178 default:
179 break;
180 }
181 sprintf(buf, "%x", ctl);
182 return buf;
183}
184
185
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000186int
187sys_prctl(tcp)
188struct tcb *tcp;
189{
190 int i;
191
192 if (entering(tcp)) {
193 printxval(prctl_options, tcp->u_arg[0], "PR_???");
194 switch (tcp->u_arg[0]) {
195#ifdef PR_GETNSHARE
196 case PR_GETNSHARE:
197 break;
198#endif
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000199#ifdef PR_SET_DEATHSIG
200 case PR_GET_PDEATHSIG:
201 break;
202#endif
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000203#ifdef PR_SET_UNALIGN
204 case PR_SET_UNALIGN:
205 tprintf(", %s", unalignctl_string(tcp->u_arg[1]));
206 break;
207#endif
208#ifdef PR_GET_UNALIGN
209 case PR_GET_UNALIGN:
210 tprintf(", %#lx", tcp->u_arg[1]);
211 break;
212#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000213 default:
214 for (i = 1; i < tcp->u_nargs; i++)
215 tprintf(", %#lx", tcp->u_arg[i]);
216 break;
217 }
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000218 } else {
219 switch (tcp->u_arg[0]) {
220#ifdef PR_GET_PDEATHSIG
221 case PR_GET_PDEATHSIG:
222 for (i=1; i<tcp->u_nargs; i++)
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000223 tprintf(", %#lx", tcp->u_arg[i]);
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000224 break;
225#endif
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000226#ifdef PR_SET_UNALIGN
227 case PR_SET_UNALIGN:
228 break;
229#endif
230#ifdef PR_GET_UNALIGN
231 case PR_GET_UNALIGN:
232 {
233 int ctl;
234
235 umove(tcp, tcp->u_arg[1], &ctl);
236 tcp->auxstr = unalignctl_string(ctl);
237 return RVAL_STR;
238 }
239#endif
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000240 default:
241 break;
242 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000243 }
244 return 0;
245}
246
247#endif /* HAVE_PRCTL */
248
249int
250sys_gethostid(tcp)
251struct tcb *tcp;
252{
253 if (exiting(tcp))
254 return RVAL_HEX;
255 return 0;
256}
257
258int
259sys_sethostname(tcp)
260struct tcb *tcp;
261{
262 if (entering(tcp)) {
263 printpathn(tcp, tcp->u_arg[0], tcp->u_arg[1]);
264 tprintf(", %lu", tcp->u_arg[1]);
265 }
266 return 0;
267}
268
269int
270sys_gethostname(tcp)
271struct tcb *tcp;
272{
273 if (exiting(tcp)) {
274 if (syserror(tcp))
275 tprintf("%#lx", tcp->u_arg[0]);
276 else
277 printpath(tcp, tcp->u_arg[0]);
278 tprintf(", %lu", tcp->u_arg[1]);
279 }
280 return 0;
281}
282
283int
284sys_setdomainname(tcp)
285struct tcb *tcp;
286{
287 if (entering(tcp)) {
288 printpathn(tcp, tcp->u_arg[0], tcp->u_arg[1]);
289 tprintf(", %lu", tcp->u_arg[1]);
290 }
291 return 0;
292}
293
Wichert Akkerman5daa0281999-03-15 19:49:42 +0000294#if !defined(LINUX)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000295
296int
297sys_getdomainname(tcp)
298struct tcb *tcp;
299{
300 if (exiting(tcp)) {
301 if (syserror(tcp))
302 tprintf("%#lx", tcp->u_arg[0]);
303 else
304 printpath(tcp, tcp->u_arg[0]);
305 tprintf(", %lu", tcp->u_arg[1]);
306 }
307 return 0;
308}
309#endif /* !LINUX */
310
311int
312sys_exit(tcp)
313struct tcb *tcp;
314{
315 if (exiting(tcp)) {
316 fprintf(stderr, "_exit returned!\n");
317 return -1;
318 }
319 /* special case: we stop tracing this process, finish line now */
320 tprintf("%ld) ", tcp->u_arg[0]);
321 tabto(acolumn);
322 tprintf("= ?");
323 printtrailer(tcp);
324 return 0;
325}
326
327int
328internal_exit(tcp)
329struct tcb *tcp;
330{
331 if (entering(tcp))
332 tcp->flags |= TCB_EXITING;
333 return 0;
334}
335
336#ifdef SVR4
337
338int
339sys_fork(tcp)
340struct tcb *tcp;
341{
342 if (exiting(tcp)) {
343 if (getrval2(tcp)) {
344 tcp->auxstr = "child process";
345 return RVAL_UDECIMAL | RVAL_STR;
346 }
347 }
348 return 0;
349}
350
351int
352internal_fork(tcp)
353struct tcb *tcp;
354{
355 struct tcb *tcpchild;
356
357 if (exiting(tcp)) {
358 if (getrval2(tcp))
359 return 0;
360 if (!followfork)
361 return 0;
362 if (nprocs == MAX_PROCS) {
363 tcp->flags &= ~TCB_FOLLOWFORK;
364 fprintf(stderr, "sys_fork: tcb table full\n");
365 return 0;
366 }
367 else
368 tcp->flags |= TCB_FOLLOWFORK;
369 if (syserror(tcp))
370 return 0;
371 if ((tcpchild = alloctcb(tcp->u_rval)) == NULL) {
372 fprintf(stderr, "sys_fork: tcb table full\n");
373 return 0;
374 }
375 proc_open(tcpchild, 1);
376 }
377 return 0;
378}
379
380#else /* !SVR4 */
381
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000382#ifdef LINUX
383
384/* defines copied from linux/sched.h since we can't include that
385 * ourselves (it conflicts with *lots* of libc includes)
386 */
387#define CSIGNAL 0x000000ff /* signal mask to be sent at exit */
388#define CLONE_VM 0x00000100 /* set if VM shared between processes */
389#define CLONE_FS 0x00000200 /* set if fs info shared between processes */
390#define CLONE_FILES 0x00000400 /* set if open files shared between processes */
391#define CLONE_SIGHAND 0x00000800 /* set if signal handlers shared */
392#define CLONE_PID 0x00001000 /* set if pid shared */
393#define CLONE_PTRACE 0x00002000 /* set if we want to let tracing continue on the child too */
394#define CLONE_VFORK 0x00004000 /* set if the parent wants the child to wake it up on mm_release */
395#define CLONE_PARENT 0x00008000 /* set if we want to have the same parent as the cloner */
396
397static struct xlat clone_flags[] = {
398 { CLONE_VM, "CLONE_VM" },
399 { CLONE_FS, "CLONE_FS" },
400 { CLONE_FILES, "CLONE_FILES" },
401 { CLONE_SIGHAND, "CLONE_SIGHAND" },
402 { CLONE_PID, "CLONE_PID" },
403 { CLONE_PTRACE, "CLONE_PTRACE" },
404 { CLONE_VFORK, "CLONE_VFORK" },
405 { CLONE_PARENT, "CLONE_PARENT" },
406 { 0, NULL },
407};
408
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000409int
410sys_clone(tcp)
411struct tcb *tcp;
412{
413 if (exiting(tcp)) {
414 tprintf("child_stack=%#lx, flags=", tcp->u_arg[1]);
415 if (printflags(clone_flags, tcp->u_arg[0]) == 0)
416 tprintf("0");
417 }
418 return 0;
419}
420
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000421#endif
422
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000423int
424sys_fork(tcp)
425struct tcb *tcp;
426{
427 if (exiting(tcp))
428 return RVAL_UDECIMAL;
429 return 0;
430}
431
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000432int
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000433change_syscall(tcp, new)
434struct tcb *tcp;
435int new;
436{
437#if defined(LINUX)
438#if defined(I386)
439 /* Attempt to make vfork into fork, which we can follow. */
440 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(ORIG_EAX * 4), new) < 0)
441 return -1;
442 return 0;
443#elif defined(POWERPC)
444 if (ptrace(PTRACE_POKEUSER, tcp->pid, (CHAR*)(4*PT_R0), new) < 0)
445 return -1;
446#elif defined(S390)
447 long pc;
448 if (upeek(tcp->pid, PT_PSWADDR,&pc)<0)
449 return -1;
450 if (ptrace(PTRACE_POKETEXT, tcp->pid, (char*)(pc-4), new)<0)
451 return -1;
452 return 0;
453#elif defined(M68K)
Wichert Akkermanc7926982000-04-10 22:22:31 +0000454 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(4*PT_ORIG_D0), new)<0)
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000455 return -1;
456 return 0;
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000457#elif defined(SPARC)
458 struct pt_regs regs;
459 if (ptrace(PTRACE_GETREGS, tcp->pid, (char*)&regs, 0)<0)
460 return -1;
461 reg.r_g1=new;
462 if (ptrace(PTRACE_SETREGS, tcp->pid, (char*)&regs, 0)<0)
463 return -1;
464 return 0;
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000465#elif defined(MIPS)
Wichert Akkermanc7926982000-04-10 22:22:31 +0000466 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(REG_V0), new)<0)
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000467 return -1;
468 return 0;
469#elif defined(ALPHA)
Wichert Akkermanc7926982000-04-10 22:22:31 +0000470 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(REG_A3), new)<0)
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000471 return -1;
472 return 0;
473#else
474#warning Do not know how to handle change_syscall for this architecture
475#endif /* architecture */
476#endif /* LINUX */
477 return -1;
478}
479
480int
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000481setarg(tcp, argnum)
482 struct tcb *tcp;
483 int argnum;
484{
485#if defined (IA64)
486 {
487 unsigned long *bsp, *ap;
488
489 if (upeek(tcp->pid, PT_AR_BSP, (long *) &bsp) , 0)
490 return -1;
491
492 ap = ia64_rse_skip_regs(bsp, argnum);
493 errno = 0;
494 ptrace(PTRACE_POKEDATA, tcp->pid, ap, tcp->u_arg[argnum]);
495 if (errno)
496 return -1;
497
498 }
Wichert Akkerman12f75d12000-02-14 16:23:40 +0000499#elif defined(I386)
500 {
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000501 ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(4*argnum), tcp->u_arg[argnum]);
Wichert Akkerman12f75d12000-02-14 16:23:40 +0000502 if (errno)
503 return -1;
504 }
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000505#else
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000506# warning Sorry, setargs not implemented for this architecture.
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000507#endif
508 return 0;
509}
510
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000511#ifdef SYS_clone
512int
513internal_clone(tcp)
514struct tcb *tcp;
515{
Ulrich Drepper90512f01999-12-24 07:22:25 +0000516 struct tcb *tcpchild;
517 int pid;
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000518 if (entering(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000519 if (!followfork)
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000520 return 0;
521 if (nprocs == MAX_PROCS) {
522 tcp->flags &= ~TCB_FOLLOWFORK;
523 fprintf(stderr, "sys_fork: tcb table full\n");
524 return 0;
525 }
526 tcp->flags |= TCB_FOLLOWFORK;
527
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000528 tcp->u_arg[0] |= CLONE_PTRACE;
529 setarg(tcp, 0);
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000530 } else {
531 if (!(tcp->flags & TCB_FOLLOWFORK))
532 return 0;
533
534 if (syserror(tcp))
535 return 0;
536
537 pid = tcp->u_rval;
538 if ((tcpchild = alloctcb(pid)) == NULL) {
539 fprintf(stderr, " [tcb table full]\n");
540 kill(pid, SIGKILL); /* XXX */
541 return 0;
542 }
543
544 /* For fork we need to re-attach, but thanks to CLONE_PTRACE we're
545 * already attached.
546 */
Ulrich Drepper90512f01999-12-24 07:22:25 +0000547 tcpchild->flags |= TCB_ATTACHED;
548 newoutf(tcpchild);
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000549 tcp->nchildren++;
550 if (!qflag)
551 fprintf(stderr, "Process %d attached\n", pid);
552 }
553 return 0;
554}
555#endif
556
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000557int
558internal_fork(tcp)
559struct tcb *tcp;
560{
561 struct tcb *tcpchild;
562 int pid;
Nate Sammonsccd8f211999-03-29 22:57:54 +0000563 int dont_follow = 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000564
565#ifdef SYS_vfork
Nate Sammonsccd8f211999-03-29 22:57:54 +0000566 if (tcp->scno == SYS_vfork) {
Nate Sammonsccd8f211999-03-29 22:57:54 +0000567 /* Attempt to make vfork into fork, which we can follow. */
568 if (!followvfork ||
Pavel Machek9a9f10b2000-02-01 16:22:52 +0000569 change_syscall(tcp, SYS_fork) < 0)
Nate Sammonsccd8f211999-03-29 22:57:54 +0000570 dont_follow = 1;
Nate Sammonsccd8f211999-03-29 22:57:54 +0000571 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000572#endif
573 if (entering(tcp)) {
Nate Sammonsccd8f211999-03-29 22:57:54 +0000574 if (!followfork || dont_follow)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000575 return 0;
576 if (nprocs == MAX_PROCS) {
577 tcp->flags &= ~TCB_FOLLOWFORK;
578 fprintf(stderr, "sys_fork: tcb table full\n");
579 return 0;
580 }
581 tcp->flags |= TCB_FOLLOWFORK;
582 if (setbpt(tcp) < 0)
583 return 0;
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000584 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000585 else {
586 int bpt = tcp->flags & TCB_BPTSET;
587
588 if (!(tcp->flags & TCB_FOLLOWFORK))
589 return 0;
590 if (bpt)
591 clearbpt(tcp);
592
593 if (syserror(tcp))
594 return 0;
595
596 pid = tcp->u_rval;
597 if ((tcpchild = alloctcb(pid)) == NULL) {
598 fprintf(stderr, " [tcb table full]\n");
599 kill(pid, SIGKILL); /* XXX */
600 return 0;
601 }
602#ifdef LINUX
603 if (ptrace(PTRACE_ATTACH, pid, (char *) 1, 0) < 0) {
604 perror("PTRACE_ATTACH");
605 fprintf(stderr, "Too late?\n");
606 droptcb(tcpchild);
607 return 0;
608 }
609#endif /* LINUX */
610#ifdef SUNOS4
611#ifdef oldway
612 /* The child must have run before it can be attached. */
613 {
614 struct timeval tv;
615 tv.tv_sec = 0;
616 tv.tv_usec = 10000;
617 select(0, NULL, NULL, NULL, &tv);
618 }
619 if (ptrace(PTRACE_ATTACH, pid, (char *)1, 0) < 0) {
620 perror("PTRACE_ATTACH");
621 fprintf(stderr, "Too late?\n");
622 droptcb(tcpchild);
623 return 0;
624 }
625#else /* !oldway */
626 /* Try to catch the new process as soon as possible. */
627 {
628 int i;
629 for (i = 0; i < 1024; i++)
630 if (ptrace(PTRACE_ATTACH, pid, (char *) 1, 0) >= 0)
631 break;
632 if (i == 1024) {
633 perror("PTRACE_ATTACH");
634 fprintf(stderr, "Too late?\n");
635 droptcb(tcpchild);
636 return 0;
637 }
638 }
639#endif /* !oldway */
640#endif /* SUNOS4 */
641 tcpchild->flags |= TCB_ATTACHED;
642 /* Child has BPT too, must be removed on first occasion */
643 if (bpt) {
644 tcpchild->flags |= TCB_BPTSET;
645 tcpchild->baddr = tcp->baddr;
646 memcpy(tcpchild->inst, tcp->inst,
647 sizeof tcpchild->inst);
648 }
649 newoutf(tcpchild);
650 tcpchild->parent = tcp;
651 tcp->nchildren++;
652 if (!qflag)
653 fprintf(stderr, "Process %d attached\n", pid);
654 }
655 return 0;
656}
657
658#endif /* !SVR4 */
659
660#if defined(SUNOS4) || defined(LINUX)
661
662int
663sys_vfork(tcp)
664struct tcb *tcp;
665{
666 if (exiting(tcp))
667 return RVAL_UDECIMAL;
668 return 0;
669}
670
671#endif /* SUNOS4 || LINUX */
672
673#ifndef LINUX
674
675static char idstr[16];
676
677int
678sys_getpid(tcp)
679struct tcb *tcp;
680{
681 if (exiting(tcp)) {
682 sprintf(idstr, "ppid %lu", getrval2(tcp));
683 tcp->auxstr = idstr;
684 return RVAL_STR;
685 }
686 return 0;
687}
688
689int
690sys_getuid(tcp)
691struct tcb *tcp;
692{
693 if (exiting(tcp)) {
694 sprintf(idstr, "euid %lu", getrval2(tcp));
695 tcp->auxstr = idstr;
696 return RVAL_STR;
697 }
698 return 0;
699}
700
701int
702sys_getgid(tcp)
703struct tcb *tcp;
704{
705 if (exiting(tcp)) {
706 sprintf(idstr, "egid %lu", getrval2(tcp));
707 tcp->auxstr = idstr;
708 return RVAL_STR;
709 }
710 return 0;
711}
712
713#endif /* !LINUX */
714
715#ifdef LINUX
716
717int
718sys_setuid(tcp)
719struct tcb *tcp;
720{
721 if (entering(tcp)) {
722 tprintf("%u", (uid_t) tcp->u_arg[0]);
723 }
724 return 0;
725}
726
727int
728sys_setgid(tcp)
729struct tcb *tcp;
730{
731 if (entering(tcp)) {
732 tprintf("%u", (gid_t) tcp->u_arg[0]);
733 }
734 return 0;
735}
736
737int
738sys_getresuid(tcp)
739 struct tcb *tcp;
740{
741 if (exiting(tcp)) {
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000742 __kernel_uid_t uid;
743 if (syserror(tcp))
744 tprintf("%#lx, %#lx, %#lx", tcp->u_arg[0],
745 tcp->u_arg[1], tcp->u_arg[2]);
746 else {
747 if (umove(tcp, tcp->u_arg[0], &uid) < 0)
748 tprintf("%#lx, ", tcp->u_arg[0]);
749 else
750 tprintf("ruid %lu, ", (unsigned long) uid);
751 if (umove(tcp, tcp->u_arg[0], &uid) < 0)
752 tprintf("%#lx, ", tcp->u_arg[0]);
753 else
754 tprintf("euid %lu, ", (unsigned long) uid);
755 if (umove(tcp, tcp->u_arg[0], &uid) < 0)
756 tprintf("%#lx", tcp->u_arg[0]);
757 else
758 tprintf("suid %lu", (unsigned long) uid);
759 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000760 }
761 return 0;
762}
763
764int
765sys_getresgid(tcp)
766struct tcb *tcp;
767{
768 if (exiting(tcp)) {
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000769 __kernel_gid_t gid;
770 if (syserror(tcp))
771 tprintf("%#lx, %#lx, %#lx", tcp->u_arg[0],
772 tcp->u_arg[1], tcp->u_arg[2]);
773 else {
774 if (umove(tcp, tcp->u_arg[0], &gid) < 0)
775 tprintf("%#lx, ", tcp->u_arg[0]);
776 else
777 tprintf("rgid %lu, ", (unsigned long) gid);
778 if (umove(tcp, tcp->u_arg[0], &gid) < 0)
779 tprintf("%#lx, ", tcp->u_arg[0]);
780 else
781 tprintf("egid %lu, ", (unsigned long) gid);
782 if (umove(tcp, tcp->u_arg[0], &gid) < 0)
783 tprintf("%#lx", tcp->u_arg[0]);
784 else
785 tprintf("sgid %lu", (unsigned long) gid);
786 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000787 }
788 return 0;
789}
790
791#endif /* LINUX */
792
793int
794sys_setreuid(tcp)
795struct tcb *tcp;
796{
797 if (entering(tcp)) {
798 tprintf("%lu, %lu",
799 (unsigned long) (uid_t) tcp->u_arg[0],
800 (unsigned long) (uid_t) tcp->u_arg[1]);
801 }
802 return 0;
803}
804
805int
806sys_setregid(tcp)
807struct tcb *tcp;
808{
809 if (entering(tcp)) {
810 tprintf("%lu, %lu",
811 (unsigned long) (gid_t) tcp->u_arg[0],
812 (unsigned long) (gid_t) tcp->u_arg[1]);
813 }
814 return 0;
815}
816
817#ifdef LINUX
818int
819sys_setresuid(tcp)
820 struct tcb *tcp;
821{
822 if (entering(tcp)) {
823 tprintf("ruid %u, euid %u, suid %u",
824 (uid_t) tcp->u_arg[0],
825 (uid_t) tcp->u_arg[1],
826 (uid_t) tcp->u_arg[2]);
827 }
828 return 0;
829}
830int
831sys_setresgid(tcp)
832 struct tcb *tcp;
833{
834 if (entering(tcp)) {
835 tprintf("rgid %u, egid %u, sgid %u",
836 (uid_t) tcp->u_arg[0],
837 (uid_t) tcp->u_arg[1],
838 (uid_t) tcp->u_arg[2]);
839 }
840 return 0;
841}
842
843#endif /* LINUX */
844
845int
846sys_setgroups(tcp)
847struct tcb *tcp;
848{
849 int i, len;
850 GETGROUPS_T *gidset;
851
852 if (entering(tcp)) {
853 len = tcp->u_arg[0];
854 tprintf("%u, ", len);
855 if (len <= 0) {
856 tprintf("[]");
857 return 0;
858 }
859 gidset = (GETGROUPS_T *) malloc(len * sizeof(GETGROUPS_T));
860 if (gidset == NULL) {
861 fprintf(stderr, "sys_setgroups: out of memory\n");
862 return -1;
863 }
864 if (!verbose(tcp))
865 tprintf("%#lx", tcp->u_arg[1]);
866 else if (umoven(tcp, tcp->u_arg[1],
867 len * sizeof(GETGROUPS_T), (char *) gidset) < 0)
868 tprintf("[?]");
869 else {
870 tprintf("[");
871 for (i = 0; i < len; i++)
872 tprintf("%s%lu", i ? ", " : "",
873 (unsigned long) gidset[i]);
874 tprintf("]");
875 }
876 free((char *) gidset);
877 }
878 return 0;
879}
880
881int
882sys_getgroups(tcp)
883struct tcb *tcp;
884{
885 int i, len;
886 GETGROUPS_T *gidset;
887
888 if (entering(tcp)) {
889 len = tcp->u_arg[0];
890 tprintf("%u, ", len);
891 } else {
892 len = tcp->u_rval;
893 if (len <= 0) {
894 tprintf("[]");
895 return 0;
896 }
897 gidset = (GETGROUPS_T *) malloc(len * sizeof(GETGROUPS_T));
898 if (gidset == NULL) {
899 fprintf(stderr, "sys_getgroups: out of memory\n");
900 return -1;
901 }
902 if (!tcp->u_arg[1])
903 tprintf("NULL");
904 else if (!verbose(tcp) || tcp->u_arg[0] == 0)
905 tprintf("%#lx", tcp->u_arg[1]);
906 else if (umoven(tcp, tcp->u_arg[1],
907 len * sizeof(GETGROUPS_T), (char *) gidset) < 0)
908 tprintf("[?]");
909 else {
910 tprintf("[");
911 for (i = 0; i < len; i++)
912 tprintf("%s%lu", i ? ", " : "",
913 (unsigned long) gidset[i]);
914 tprintf("]");
915 }
916 free((char *)gidset);
917 }
918 return 0;
919}
920
921int
922sys_setpgrp(tcp)
923struct tcb *tcp;
924{
925 if (entering(tcp)) {
926#ifndef SVR4
927 tprintf("%lu, %lu", tcp->u_arg[0], tcp->u_arg[1]);
928#endif /* !SVR4 */
929 }
930 return 0;
931}
932
933int
934sys_getpgrp(tcp)
935struct tcb *tcp;
936{
937 if (entering(tcp)) {
938#ifndef SVR4
939 tprintf("%lu", tcp->u_arg[0]);
940#endif /* !SVR4 */
941 }
942 return 0;
943}
944
945int
946sys_getsid(tcp)
947struct tcb *tcp;
948{
949 if (entering(tcp)) {
950 tprintf("%lu", tcp->u_arg[0]);
951 }
952 return 0;
953}
954
955int
956sys_setsid(tcp)
957struct tcb *tcp;
958{
959 return 0;
960}
961
962int
963sys_getpgid(tcp)
964struct tcb *tcp;
965{
966 if (entering(tcp)) {
967 tprintf("%lu", tcp->u_arg[0]);
968 }
969 return 0;
970}
971
972int
973sys_setpgid(tcp)
974struct tcb *tcp;
975{
976 if (entering(tcp)) {
977 tprintf("%lu, %lu", tcp->u_arg[0], tcp->u_arg[1]);
978 }
979 return 0;
980}
981
982void
983fake_execve(tcp, program, argv, envp)
984struct tcb *tcp;
985char *program;
986char *argv[];
987char *envp[];
988{
989 int i;
990
991#ifdef ARM
992 if (!(qual_flags[SYS_execve - __NR_SYSCALL_BASE] & QUAL_TRACE))
993 return;
994#else
995 if (!(qual_flags[SYS_execve] & QUAL_TRACE))
996 return;
997#endif /* !ARM */
998 printleader(tcp);
999 tprintf("execve(");
1000 string_quote(program);
1001 tprintf(", [");
1002 for (i = 0; argv[i] != NULL; i++) {
1003 if (i != 0)
1004 tprintf(", ");
1005 string_quote(argv[i]);
1006 }
1007 for (i = 0; envp[i] != NULL; i++)
1008 ;
1009 tprintf("], [/* %d var%s */]) ", i, (i != 1) ? "s" : "");
1010 tabto(acolumn);
1011 tprintf("= 0");
1012 printtrailer(tcp);
1013}
1014
1015static void
1016printargv(tcp, addr)
1017struct tcb *tcp;
1018long addr;
1019{
1020 char *cp;
1021 char *sep;
1022 int max = max_strlen / 2;
1023
1024 for (sep = ""; --max >= 0; sep = ", ") {
1025 if (!abbrev(tcp))
1026 max++;
1027 if (umove(tcp, addr, &cp) < 0) {
1028 tprintf("%#lx", addr);
1029 return;
1030 }
1031 if (cp == 0)
1032 break;
1033 tprintf(sep);
1034 printstr(tcp, (long) cp, -1);
1035 addr += sizeof(char *);
1036 }
1037 if (cp)
1038 tprintf(", ...");
1039}
1040
1041static void
1042printargc(fmt, tcp, addr)
1043char *fmt;
1044struct tcb *tcp;
1045long addr;
1046{
1047 int count;
1048 char *cp;
1049
1050 for (count = 0; umove(tcp, addr, &cp) >= 0 && cp != NULL; count++) {
1051 addr += sizeof(char *);
1052 }
1053 tprintf(fmt, count, count == 1 ? "" : "s");
1054}
1055
1056int
1057sys_execv(tcp)
1058struct tcb *tcp;
1059{
1060 if (entering(tcp)) {
1061 printpath(tcp, tcp->u_arg[0]);
1062 if (!verbose(tcp))
1063 tprintf(", %#lx", tcp->u_arg[1]);
1064#if 0
1065 else if (abbrev(tcp))
1066 printargc(", [/* %d arg%s */]", tcp, tcp->u_arg[1]);
1067#endif
1068 else {
1069 tprintf(", [");
1070 printargv(tcp, tcp->u_arg[1]);
1071 tprintf("]");
1072 }
1073 }
1074 return 0;
1075}
1076
1077int
1078sys_execve(tcp)
1079struct tcb *tcp;
1080{
1081 if (entering(tcp)) {
1082 printpath(tcp, tcp->u_arg[0]);
1083 if (!verbose(tcp))
1084 tprintf(", %#lx", tcp->u_arg[1]);
1085#if 0
1086 else if (abbrev(tcp))
1087 printargc(", [/* %d arg%s */]", tcp, tcp->u_arg[1]);
1088#endif
1089 else {
1090 tprintf(", [");
1091 printargv(tcp, tcp->u_arg[1]);
1092 tprintf("]");
1093 }
1094 if (!verbose(tcp))
1095 tprintf(", %#lx", tcp->u_arg[2]);
1096 else if (abbrev(tcp))
1097 printargc(", [/* %d var%s */]", tcp, tcp->u_arg[2]);
1098 else {
1099 tprintf(", [");
1100 printargv(tcp, tcp->u_arg[2]);
1101 tprintf("]");
1102 }
1103 }
1104#ifdef LINUX
1105#if defined(ALPHA) || defined(SPARC) || defined(POWERPC)
1106 tcp->flags |= TCB_WAITEXECVE;
1107#endif /* ALPHA || SPARC || POWERPC */
1108#endif /* LINUX */
1109 return 0;
1110}
1111
1112int
1113internal_exec(tcp)
1114struct tcb *tcp;
1115{
1116#ifdef SUNOS4
1117 if (exiting(tcp) && !syserror(tcp) && followfork)
1118 fixvfork(tcp);
1119#endif /* SUNOS4 */
1120 return 0;
1121}
1122
1123#ifdef LINUX
1124#ifndef __WCLONE
1125#define __WCLONE 0x8000000
1126#endif
1127#endif /* LINUX */
1128
1129static struct xlat wait4_options[] = {
1130 { WNOHANG, "WNOHANG" },
1131#ifndef WSTOPPED
1132 { WUNTRACED, "WUNTRACED" },
1133#endif
1134#ifdef WEXITED
1135 { WEXITED, "WEXITED" },
1136#endif
1137#ifdef WTRAPPED
1138 { WTRAPPED, "WTRAPPED" },
1139#endif
1140#ifdef WSTOPPED
1141 { WSTOPPED, "WSTOPPED" },
1142#endif
1143#ifdef WCONTINUED
1144 { WCONTINUED, "WCONTINUED" },
1145#endif
1146#ifdef WNOWAIT
1147 { WNOWAIT, "WNOWAIT" },
1148#endif
1149#ifdef __WCLONE
1150 { __WCLONE, "__WCLONE" },
1151#endif
1152 { 0, NULL },
1153};
1154
1155static int
1156printstatus(status)
1157int status;
1158{
1159 int exited = 0;
1160
1161 /*
1162 * Here is a tricky presentation problem. This solution
1163 * is still not entirely satisfactory but since there
1164 * are no wait status constructors it will have to do.
1165 */
1166 if (WIFSTOPPED(status))
1167 tprintf("[WIFSTOPPED(s) && WSTOPSIG(s) == %s]",
Nate Sammonsce780fc1999-03-29 23:23:13 +00001168 signame(WSTOPSIG(status)));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001169 else if WIFSIGNALED(status)
1170 tprintf("[WIFSIGNALED(s) && WTERMSIG(s) == %s%s]",
Nate Sammonsce780fc1999-03-29 23:23:13 +00001171 signame(WTERMSIG(status)),
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001172 WCOREDUMP(status) ? " && WCOREDUMP(s)" : "");
1173 else if WIFEXITED(status) {
1174 tprintf("[WIFEXITED(s) && WEXITSTATUS(s) == %d]",
1175 WEXITSTATUS(status));
1176 exited = 1;
1177 }
1178 else
1179 tprintf("[%#x]", status);
1180 return exited;
1181}
1182
1183static int
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001184printwaitn(tcp, n, bitness)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001185struct tcb *tcp;
1186int n;
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001187int bitness;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001188{
1189 int status;
1190 int exited = 0;
1191
1192 if (entering(tcp)) {
1193 tprintf("%ld, ", tcp->u_arg[0]);
1194 } else {
1195 /* status */
1196 if (!tcp->u_arg[1])
1197 tprintf("NULL");
1198 else if (syserror(tcp) || tcp->u_rval == 0)
1199 tprintf("%#lx", tcp->u_arg[1]);
1200 else if (umove(tcp, tcp->u_arg[1], &status) < 0)
1201 tprintf("[?]");
1202 else
1203 exited = printstatus(status);
1204 /* options */
1205 tprintf(", ");
1206 if (!printflags(wait4_options, tcp->u_arg[2]))
1207 tprintf("0");
1208 if (n == 4) {
1209 tprintf(", ");
1210 /* usage */
1211 if (!tcp->u_arg[3])
1212 tprintf("NULL");
1213#ifdef LINUX
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001214 else if (tcp->u_rval > 0) {
1215#ifdef LINUX_64BIT
1216 if (bitness)
1217 printrusage32(tcp, tcp->u_arg[3]);
1218 else
1219#endif
1220 printrusage(tcp, tcp->u_arg[3]);
1221 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001222#endif /* LINUX */
1223#ifdef SUNOS4
1224 else if (tcp->u_rval > 0 && exited)
1225 printrusage(tcp, tcp->u_arg[3]);
1226#endif /* SUNOS4 */
1227 else
1228 tprintf("%#lx", tcp->u_arg[3]);
1229 }
1230 }
1231 return 0;
1232}
1233
1234int
1235internal_wait(tcp)
1236struct tcb *tcp;
1237{
1238 if (entering(tcp)) {
Wichert Akkerman5daa0281999-03-15 19:49:42 +00001239 /* WTA: fix bug with hanging children */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001240 if (!(tcp->u_arg[2] & WNOHANG) && tcp->nchildren > 0) {
1241 /* There are traced children */
1242 tcp->flags |= TCB_SUSPENDED;
1243 tcp->waitpid = tcp->u_arg[0];
1244 }
1245 }
1246 return 0;
1247}
1248
1249#ifdef SVR4
1250
1251int
1252sys_wait(tcp)
1253struct tcb *tcp;
1254{
1255 if (exiting(tcp)) {
1256 /* The library wrapper stuffs this into the user variable. */
1257 if (!syserror(tcp))
1258 printstatus(getrval2(tcp));
1259 }
1260 return 0;
1261}
1262
1263#endif /* SVR4 */
1264
1265int
1266sys_waitpid(tcp)
1267struct tcb *tcp;
1268{
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001269 return printwaitn(tcp, 3, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001270}
1271
1272int
1273sys_wait4(tcp)
1274struct tcb *tcp;
1275{
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001276 return printwaitn(tcp, 4, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001277}
1278
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001279#ifdef ALPHA
1280int
1281sys_osf_wait4(tcp)
1282struct tcb *tcp;
1283{
1284 return printwaitn(tcp, 4, 1);
1285}
1286#endif
1287
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001288#ifdef SVR4
1289
1290static struct xlat waitid_types[] = {
1291 { P_PID, "P_PID" },
1292 { P_PPID, "P_PPID" },
1293 { P_PGID, "P_PGID" },
1294 { P_SID, "P_SID" },
1295 { P_CID, "P_CID" },
1296 { P_UID, "P_UID" },
1297 { P_GID, "P_GID" },
1298 { P_ALL, "P_ALL" },
1299#ifdef P_LWPID
1300 { P_LWPID, "P_LWPID" },
1301#endif
1302 { 0, NULL },
1303};
1304
1305static struct xlat siginfo_codes[] = {
1306#ifdef SI_NOINFO
1307 { SI_NOINFO, "SI_NOINFO" },
1308#endif
1309#ifdef SI_USER
1310 { SI_USER, "SI_USER" },
1311#endif
1312#ifdef SI_LWP
1313 { SI_LWP, "SI_LWP" },
1314#endif
1315#ifdef SI_QUEUE
1316 { SI_QUEUE, "SI_QUEUE" },
1317#endif
1318#ifdef SI_TIMER
1319 { SI_TIMER, "SI_TIMER" },
1320#endif
1321#ifdef SI_ASYNCIO
1322 { SI_ASYNCIO, "SI_ASYNCIO" },
1323#endif
1324#ifdef SI_MESGQ
1325 { SI_MESGQ, "SI_MESGQ" },
1326#endif
1327 { 0, NULL },
1328};
1329
1330static struct xlat sigtrap_codes[] = {
1331 { TRAP_BRKPT, "TRAP_BRKPT" },
1332 { TRAP_TRACE, "TRAP_TRACE" },
1333 { 0, NULL },
1334};
1335
1336static struct xlat sigcld_codes[] = {
1337 { CLD_EXITED, "CLD_EXITED" },
1338 { CLD_KILLED, "CLD_KILLED" },
1339 { CLD_DUMPED, "CLD_DUMPED" },
1340 { CLD_TRAPPED, "CLD_TRAPPED" },
1341 { CLD_STOPPED, "CLD_STOPPED" },
1342 { CLD_CONTINUED,"CLD_CONTINUED" },
1343 { 0, NULL },
1344};
1345
1346static struct xlat sigpoll_codes[] = {
1347 { POLL_IN, "POLL_IN" },
1348 { POLL_OUT, "POLL_OUT" },
1349 { POLL_MSG, "POLL_MSG" },
1350 { POLL_ERR, "POLL_ERR" },
1351 { POLL_PRI, "POLL_PRI" },
1352 { POLL_HUP, "POLL_HUP" },
1353 { 0, NULL },
1354};
1355
1356static struct xlat sigprof_codes[] = {
1357#ifdef PROF_SIG
1358 { PROF_SIG, "PROF_SIG" },
1359#endif
1360 { 0, NULL },
1361};
1362
1363static struct xlat sigill_codes[] = {
1364 { ILL_ILLOPC, "ILL_ILLOPC" },
1365 { ILL_ILLOPN, "ILL_ILLOPN" },
1366 { ILL_ILLADR, "ILL_ILLADR" },
1367 { ILL_ILLTRP, "ILL_ILLTRP" },
1368 { ILL_PRVOPC, "ILL_PRVOPC" },
1369 { ILL_PRVREG, "ILL_PRVREG" },
1370 { ILL_COPROC, "ILL_COPROC" },
1371 { ILL_BADSTK, "ILL_BADSTK" },
1372 { 0, NULL },
1373};
1374
1375static struct xlat sigemt_codes[] = {
1376#ifdef EMT_TAGOVF
1377 { EMT_TAGOVF, "EMT_TAGOVF" },
1378#endif
1379 { 0, NULL },
1380};
1381
1382static struct xlat sigfpe_codes[] = {
1383 { FPE_INTDIV, "FPE_INTDIV" },
1384 { FPE_INTOVF, "FPE_INTOVF" },
1385 { FPE_FLTDIV, "FPE_FLTDIV" },
1386 { FPE_FLTOVF, "FPE_FLTOVF" },
1387 { FPE_FLTUND, "FPE_FLTUND" },
1388 { FPE_FLTRES, "FPE_FLTRES" },
1389 { FPE_FLTINV, "FPE_FLTINV" },
1390 { FPE_FLTSUB, "FPE_FLTSUB" },
1391 { 0, NULL },
1392};
1393
1394static struct xlat sigsegv_codes[] = {
1395 { SEGV_MAPERR, "SEGV_MAPERR" },
1396 { SEGV_ACCERR, "SEGV_ACCERR" },
1397 { 0, NULL },
1398};
1399
1400static struct xlat sigbus_codes[] = {
1401 { BUS_ADRALN, "BUS_ADRALN" },
1402 { BUS_ADRERR, "BUS_ADRERR" },
1403 { BUS_OBJERR, "BUS_OBJERR" },
1404 { 0, NULL },
1405};
1406
1407void
1408printsiginfo(sip)
1409siginfo_t *sip;
1410{
1411 char *code;
1412
1413 tprintf("{si_signo=");
1414 printsignal(sip->si_signo);
1415 code = xlookup(siginfo_codes, sip->si_code);
1416 if (!code) {
1417 switch (sip->si_signo) {
1418 case SIGTRAP:
1419 code = xlookup(sigtrap_codes, sip->si_code);
1420 break;
1421 case SIGCHLD:
1422 code = xlookup(sigcld_codes, sip->si_code);
1423 break;
1424 case SIGPOLL:
1425 code = xlookup(sigpoll_codes, sip->si_code);
1426 break;
1427 case SIGPROF:
1428 code = xlookup(sigprof_codes, sip->si_code);
1429 break;
1430 case SIGILL:
1431 code = xlookup(sigill_codes, sip->si_code);
1432 break;
1433 case SIGEMT:
1434 code = xlookup(sigemt_codes, sip->si_code);
1435 break;
1436 case SIGFPE:
1437 code = xlookup(sigfpe_codes, sip->si_code);
1438 break;
1439 case SIGSEGV:
1440 code = xlookup(sigsegv_codes, sip->si_code);
1441 break;
1442 case SIGBUS:
1443 code = xlookup(sigbus_codes, sip->si_code);
1444 break;
1445 }
1446 }
1447 if (code)
1448 tprintf(", si_code=%s", code);
1449 else
1450 tprintf(", si_code=%#x", sip->si_code);
1451#ifdef SI_NOINFO
1452 if (sip->si_code != SI_NOINFO) {
1453#endif
1454 if (sip->si_errno) {
1455 if (sip->si_errno < 0 || sip->si_errno >= nerrnos)
1456 tprintf(", si_errno=%d", sip->si_errno);
1457 else
1458 tprintf(", si_errno=%s",
1459 errnoent[sip->si_errno]);
1460 }
1461 if (SI_FROMUSER(sip)) {
1462#ifdef SI_QUEUE
1463 tprintf(", si_pid=%ld, si_uid=%ld",
1464 sip->si_pid, sip->si_uid);
1465 switch (sip->si_code) {
1466 case SI_QUEUE:
1467#ifdef SI_TIMER
1468 case SI_TIMER:
1469#endif /* SI_QUEUE */
1470 case SI_ASYNCIO:
1471#ifdef SI_MESGQ
1472 case SI_MESGQ:
1473#endif /* SI_MESGQ */
1474 tprintf(", si_value=%d",
1475 sip->si_value.sival_int);
1476 break;
1477 }
1478#endif /* SI_QUEUE */
1479 }
1480 else {
1481 switch (sip->si_signo) {
1482 case SIGCHLD:
1483 tprintf(", si_pid=%ld, si_status=",
1484 sip->si_pid);
1485 if (sip->si_code == CLD_EXITED)
1486 tprintf("%d", sip->si_status);
1487 else
1488 printsignal(sip->si_status);
1489 break;
1490 case SIGILL: case SIGFPE:
1491 case SIGSEGV: case SIGBUS:
1492 tprintf(", si_addr=%#lx",
1493 (unsigned long) sip->si_addr);
1494 break;
1495 case SIGPOLL:
1496 switch (sip->si_code) {
1497 case POLL_IN: case POLL_OUT: case POLL_MSG:
1498 tprintf(", si_band=%ld",
1499 (long) sip->si_band);
1500 break;
1501 }
1502 break;
1503 }
1504 }
1505 tprintf(", ...");
1506#ifdef SI_NOINFO
1507 }
1508#endif
1509 tprintf("}");
1510}
1511
1512int
1513sys_waitid(tcp)
1514struct tcb *tcp;
1515{
1516 siginfo_t si;
1517 int exited;
1518
1519 if (entering(tcp)) {
1520 printxval(waitid_types, tcp->u_arg[0], "P_???");
1521 tprintf(", %ld, ", tcp->u_arg[1]);
1522 if (tcp->nchildren > 0) {
1523 /* There are traced children */
1524 tcp->flags |= TCB_SUSPENDED;
1525 tcp->waitpid = tcp->u_arg[0];
1526 }
1527 }
1528 else {
1529 /* siginfo */
1530 exited = 0;
1531 if (!tcp->u_arg[2])
1532 tprintf("NULL");
1533 else if (syserror(tcp))
1534 tprintf("%#lx", tcp->u_arg[2]);
1535 else if (umove(tcp, tcp->u_arg[2], &si) < 0)
1536 tprintf("{???}");
1537 else
1538 printsiginfo(&si);
1539 /* options */
1540 tprintf(", ");
1541 if (!printflags(wait4_options, tcp->u_arg[3]))
1542 tprintf("0");
1543 }
1544 return 0;
1545}
1546
1547#endif /* SVR4 */
1548
1549int
1550sys_alarm(tcp)
1551struct tcb *tcp;
1552{
1553 if (entering(tcp))
1554 tprintf("%lu", tcp->u_arg[0]);
1555 return 0;
1556}
1557
1558int
1559sys_uname(tcp)
1560struct tcb *tcp;
1561{
1562 struct utsname uname;
1563
1564 if (exiting(tcp)) {
1565 if (syserror(tcp) || !verbose(tcp))
1566 tprintf("%#lx", tcp->u_arg[0]);
1567 else if (umove(tcp, tcp->u_arg[0], &uname) < 0)
1568 tprintf("{...}");
1569 else if (!abbrev(tcp)) {
1570
1571 tprintf("{sysname=\"%s\", nodename=\"%s\", ",
1572 uname.sysname, uname.nodename);
1573 tprintf("release=\"%s\", version=\"%s\", ",
1574 uname.release, uname.version);
1575 tprintf("machine=\"%s\"", uname.machine);
1576#ifdef LINUX
1577#ifndef __GLIBC__
1578 tprintf(", domainname=\"%s\"", uname.domainname);
1579#endif /* __GLIBC__ */
1580#endif /* LINUX */
1581 tprintf("}");
1582 }
1583 else
1584 tprintf("{sys=\"%s\", node=\"%s\", ...}",
1585 uname.sysname, uname.nodename);
1586 }
1587 return 0;
1588}
1589
1590#ifndef SVR4
1591
1592static struct xlat ptrace_cmds[] = {
1593 { PTRACE_TRACEME, "PTRACE_TRACEME" },
1594 { PTRACE_PEEKTEXT, "PTRACE_PEEKTEXT", },
1595 { PTRACE_PEEKDATA, "PTRACE_PEEKDATA", },
1596 { PTRACE_PEEKUSER, "PTRACE_PEEKUSER", },
1597 { PTRACE_POKETEXT, "PTRACE_POKETEXT", },
1598 { PTRACE_POKEDATA, "PTRACE_POKEDATA", },
1599 { PTRACE_POKEUSER, "PTRACE_POKEUSER", },
1600 { PTRACE_CONT, "PTRACE_CONT" },
1601 { PTRACE_KILL, "PTRACE_KILL" },
1602 { PTRACE_SINGLESTEP, "PTRACE_SINGLESTEP" },
1603 { PTRACE_ATTACH, "PTRACE_ATTACH" },
1604 { PTRACE_DETACH, "PTRACE_DETACH" },
1605#ifdef SUNOS4
1606 { PTRACE_GETREGS, "PTRACE_GETREGS" },
1607 { PTRACE_SETREGS, "PTRACE_SETREGS" },
1608 { PTRACE_GETFPREGS, "PTRACE_GETFPREGS", },
1609 { PTRACE_SETFPREGS, "PTRACE_SETFPREGS", },
1610 { PTRACE_READDATA, "PTRACE_READDATA" },
1611 { PTRACE_WRITEDATA, "PTRACE_WRITEDATA" },
1612 { PTRACE_READTEXT, "PTRACE_READTEXT" },
1613 { PTRACE_WRITETEXT, "PTRACE_WRITETEXT" },
1614 { PTRACE_GETFPAREGS, "PTRACE_GETFPAREGS" },
1615 { PTRACE_SETFPAREGS, "PTRACE_SETFPAREGS" },
1616#ifdef SPARC
1617 { PTRACE_GETWINDOW, "PTRACE_GETWINDOW" },
1618 { PTRACE_SETWINDOW, "PTRACE_SETWINDOW" },
1619#else /* !SPARC */
1620 { PTRACE_22, "PTRACE_PTRACE_22" },
1621 { PTRACE_23, "PTRACE_PTRACE_23" },
1622#endif /* !SPARC */
1623#endif /* SUNOS4 */
1624 { PTRACE_SYSCALL, "PTRACE_SYSCALL" },
1625#ifdef SUNOS4
1626 { PTRACE_DUMPCORE, "PTRACE_DUMPCORE" },
1627#ifdef I386
1628 { PTRACE_SETWRBKPT, "PTRACE_SETWRBKPT" },
1629 { PTRACE_SETACBKPT, "PTRACE_SETACBKPT" },
1630 { PTRACE_CLRDR7, "PTRACE_CLRDR7" },
1631#else /* !I386 */
1632 { PTRACE_26, "PTRACE_26" },
1633 { PTRACE_27, "PTRACE_27" },
1634 { PTRACE_28, "PTRACE_28" },
1635#endif /* !I386 */
1636 { PTRACE_GETUCODE, "PTRACE_GETUCODE" },
1637#endif /* SUNOS4 */
1638 { 0, NULL },
1639};
1640
1641#ifndef SUNOS4_KERNEL_ARCH_KLUDGE
1642static
1643#endif /* !SUNOS4_KERNEL_ARCH_KLUDGE */
1644struct xlat struct_user_offsets[] = {
1645#ifdef LINUX
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00001646#ifdef S390
1647 { PT_PSWMASK, "psw_mask" },
1648 { PT_PSWADDR, "psw_addr" },
1649 { PT_GPR0, "gpr0" },
1650 { PT_GPR1, "gpr1" },
1651 { PT_GPR2, "gpr2" },
1652 { PT_GPR3, "gpr3" },
1653 { PT_GPR4, "gpr4" },
1654 { PT_GPR5, "gpr5" },
1655 { PT_GPR6, "gpr6" },
1656 { PT_GPR7, "gpr7" },
1657 { PT_GPR8, "gpr8" },
1658 { PT_GPR9, "gpr9" },
1659 { PT_GPR10, "gpr10" },
1660 { PT_GPR11, "gpr11" },
1661 { PT_GPR12, "gpr12" },
1662 { PT_GPR13, "gpr13" },
1663 { PT_GPR14, "gpr14" },
1664 { PT_GPR15, "gpr15" },
1665 { PT_ACR0, "acr0" },
1666 { PT_ACR1, "acr1" },
1667 { PT_ACR2, "acr2" },
1668 { PT_ACR3, "acr3" },
1669 { PT_ACR4, "acr4" },
1670 { PT_ACR5, "acr5" },
1671 { PT_ACR6, "acr6" },
1672 { PT_ACR7, "acr7" },
1673 { PT_ACR8, "acr8" },
1674 { PT_ACR9, "acr9" },
1675 { PT_ACR10, "acr10" },
1676 { PT_ACR11, "acr11" },
1677 { PT_ACR12, "acr12" },
1678 { PT_ACR13, "acr13" },
1679 { PT_ACR14, "acr14" },
1680 { PT_ACR15, "acr15" },
1681 { PT_ORIGGPR2, "orig_gpr2" },
1682 { PT_FPC, "fpc" },
1683 { PT_FPR0_HI, "fpr0.hi" },
1684 { PT_FPR0_LO, "fpr0.lo" },
1685 { PT_FPR1_HI, "fpr1.hi" },
1686 { PT_FPR1_LO, "fpr1.lo" },
1687 { PT_FPR2_HI, "fpr2.hi" },
1688 { PT_FPR2_LO, "fpr2.lo" },
1689 { PT_FPR3_HI, "fpr3.hi" },
1690 { PT_FPR3_LO, "fpr3.lo" },
1691 { PT_FPR4_HI, "fpr4.hi" },
1692 { PT_FPR4_LO, "fpr4.lo" },
1693 { PT_FPR5_HI, "fpr5.hi" },
1694 { PT_FPR5_LO, "fpr5.lo" },
1695 { PT_FPR6_HI, "fpr6.hi" },
1696 { PT_FPR6_LO, "fpr6.lo" },
1697 { PT_FPR7_HI, "fpr7.hi" },
1698 { PT_FPR7_LO, "fpr7.lo" },
1699 { PT_FPR8_HI, "fpr8.hi" },
1700 { PT_FPR8_LO, "fpr8.lo" },
1701 { PT_FPR9_HI, "fpr9.hi" },
1702 { PT_FPR9_LO, "fpr9.lo" },
1703 { PT_FPR10_HI, "fpr10.hi" },
1704 { PT_FPR10_LO, "fpr10.lo" },
1705 { PT_FPR11_HI, "fpr11.hi" },
1706 { PT_FPR11_LO, "fpr11.lo" },
1707 { PT_FPR12_HI, "fpr12.hi" },
1708 { PT_FPR12_LO, "fpr12.lo" },
1709 { PT_FPR13_HI, "fpr13.hi" },
1710 { PT_FPR13_LO, "fpr13.lo" },
1711 { PT_FPR14_HI, "fpr14.hi" },
1712 { PT_FPR14_LO, "fpr14.lo" },
1713 { PT_FPR15_HI, "fpr15.hi" },
1714 { PT_FPR15_LO, "fpr15.lo" },
1715 { PT_CR_9, "cr9" },
1716 { PT_CR_10, "cr10" },
1717 { PT_CR_11, "cr11" },
1718#endif
1719#if defined(SPARC)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001720 /* XXX No support for these offsets yet. */
1721#elif defined(POWERPC)
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00001722 { 4*PT_R0, "4*PT_R0" },
1723 { 4*PT_R1, "4*PT_R1" },
1724 { 4*PT_R2, "4*PT_R2" },
1725 { 4*PT_R3, "4*PT_R3" },
1726 { 4*PT_R4, "4*PT_R4" },
1727 { 4*PT_R5, "4*PT_R5" },
1728 { 4*PT_R6, "4*PT_R6" },
1729 { 4*PT_R7, "4*PT_R7" },
1730 { 4*PT_R8, "4*PT_R8" },
1731 { 4*PT_R9, "4*PT_R9" },
1732 { 4*PT_R10, "4*PT_R10" },
1733 { 4*PT_R11, "4*PT_R11" },
1734 { 4*PT_R12, "4*PT_R12" },
1735 { 4*PT_R13, "4*PT_R13" },
1736 { 4*PT_R14, "4*PT_R14" },
1737 { 4*PT_R15, "4*PT_R15" },
1738 { 4*PT_R16, "4*PT_R16" },
1739 { 4*PT_R17, "4*PT_R17" },
1740 { 4*PT_R18, "4*PT_R18" },
1741 { 4*PT_R19, "4*PT_R19" },
1742 { 4*PT_R20, "4*PT_R20" },
1743 { 4*PT_R21, "4*PT_R21" },
1744 { 4*PT_R22, "4*PT_R22" },
1745 { 4*PT_R23, "4*PT_R23" },
1746 { 4*PT_R24, "4*PT_R24" },
1747 { 4*PT_R25, "4*PT_R25" },
1748 { 4*PT_R26, "4*PT_R26" },
1749 { 4*PT_R27, "4*PT_R27" },
1750 { 4*PT_R28, "4*PT_R28" },
1751 { 4*PT_R29, "4*PT_R29" },
1752 { 4*PT_R30, "4*PT_R30" },
1753 { 4*PT_R31, "4*PT_R31" },
1754 { 4*PT_NIP, "4*PT_NIP" },
1755 { 4*PT_MSR, "4*PT_MSR" },
1756 { 4*PT_ORIG_R3, "4*PT_ORIG_R3" },
1757 { 4*PT_CTR, "4*PT_CTR" },
1758 { 4*PT_LNK, "4*PT_LNK" },
1759 { 4*PT_XER, "4*PT_XER" },
1760 { 4*PT_CCR, "4*PT_CCR" },
1761 { 4*PT_FPR0, "4*PT_FPR0" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001762#else
1763#ifdef ALPHA
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00001764 { 0, "r0" },
1765 { 1, "r1" },
1766 { 2, "r2" },
1767 { 3, "r3" },
1768 { 4, "r4" },
1769 { 5, "r5" },
1770 { 6, "r6" },
1771 { 7, "r7" },
1772 { 8, "r8" },
1773 { 9, "r9" },
1774 { 10, "r10" },
1775 { 11, "r11" },
1776 { 12, "r12" },
1777 { 13, "r13" },
1778 { 14, "r14" },
1779 { 15, "r15" },
1780 { 16, "r16" },
1781 { 17, "r17" },
1782 { 18, "r18" },
1783 { 19, "r19" },
1784 { 20, "r20" },
1785 { 21, "r21" },
1786 { 22, "r22" },
1787 { 23, "r23" },
1788 { 24, "r24" },
1789 { 25, "r25" },
1790 { 26, "r26" },
1791 { 27, "r27" },
1792 { 28, "r28" },
1793 { 29, "gp" },
1794 { 30, "fp" },
1795 { 31, "zero" },
1796 { 32, "fp0" },
1797 { 33, "fp" },
1798 { 34, "fp2" },
1799 { 35, "fp3" },
1800 { 36, "fp4" },
1801 { 37, "fp5" },
1802 { 38, "fp6" },
1803 { 39, "fp7" },
1804 { 40, "fp8" },
1805 { 41, "fp9" },
1806 { 42, "fp10" },
1807 { 43, "fp11" },
1808 { 44, "fp12" },
1809 { 45, "fp13" },
1810 { 46, "fp14" },
1811 { 47, "fp15" },
1812 { 48, "fp16" },
1813 { 49, "fp17" },
1814 { 50, "fp18" },
1815 { 51, "fp19" },
1816 { 52, "fp20" },
1817 { 53, "fp21" },
1818 { 54, "fp22" },
1819 { 55, "fp23" },
1820 { 56, "fp24" },
1821 { 57, "fp25" },
1822 { 58, "fp26" },
1823 { 59, "fp27" },
1824 { 60, "fp28" },
1825 { 61, "fp29" },
1826 { 62, "fp30" },
1827 { 63, "fp31" },
1828 { 64, "pc" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001829#else /* !ALPHA */
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001830#ifdef IA64
1831 { PT_F32, "f32" }, { PT_F33, "f33" }, { PT_F34, "f34" },
1832 { PT_F35, "f35" }, { PT_F36, "f36" }, { PT_F37, "f37" },
1833 { PT_F38, "f38" }, { PT_F39, "f39" }, { PT_F40, "f40" },
1834 { PT_F41, "f41" }, { PT_F42, "f42" }, { PT_F43, "f43" },
1835 { PT_F44, "f44" }, { PT_F45, "f45" }, { PT_F46, "f46" },
1836 { PT_F47, "f47" }, { PT_F48, "f48" }, { PT_F49, "f49" },
1837 { PT_F50, "f50" }, { PT_F51, "f51" }, { PT_F52, "f52" },
1838 { PT_F53, "f53" }, { PT_F54, "f54" }, { PT_F55, "f55" },
1839 { PT_F56, "f56" }, { PT_F57, "f57" }, { PT_F58, "f58" },
1840 { PT_F59, "f59" }, { PT_F60, "f60" }, { PT_F61, "f61" },
1841 { PT_F62, "f62" }, { PT_F63, "f63" }, { PT_F64, "f64" },
1842 { PT_F65, "f65" }, { PT_F66, "f66" }, { PT_F67, "f67" },
1843 { PT_F68, "f68" }, { PT_F69, "f69" }, { PT_F70, "f70" },
1844 { PT_F71, "f71" }, { PT_F72, "f72" }, { PT_F73, "f73" },
1845 { PT_F74, "f74" }, { PT_F75, "f75" }, { PT_F76, "f76" },
1846 { PT_F77, "f77" }, { PT_F78, "f78" }, { PT_F79, "f79" },
1847 { PT_F80, "f80" }, { PT_F81, "f81" }, { PT_F82, "f82" },
1848 { PT_F83, "f83" }, { PT_F84, "f84" }, { PT_F85, "f85" },
1849 { PT_F86, "f86" }, { PT_F87, "f87" }, { PT_F88, "f88" },
1850 { PT_F89, "f89" }, { PT_F90, "f90" }, { PT_F91, "f91" },
1851 { PT_F92, "f92" }, { PT_F93, "f93" }, { PT_F94, "f94" },
1852 { PT_F95, "f95" }, { PT_F96, "f96" }, { PT_F97, "f97" },
1853 { PT_F98, "f98" }, { PT_F99, "f99" }, { PT_F100, "f100" },
1854 { PT_F101, "f101" }, { PT_F102, "f102" }, { PT_F103, "f103" },
1855 { PT_F104, "f104" }, { PT_F105, "f105" }, { PT_F106, "f106" },
1856 { PT_F107, "f107" }, { PT_F108, "f108" }, { PT_F109, "f109" },
1857 { PT_F110, "f110" }, { PT_F111, "f111" }, { PT_F112, "f112" },
1858 { PT_F113, "f113" }, { PT_F114, "f114" }, { PT_F115, "f115" },
1859 { PT_F116, "f116" }, { PT_F117, "f117" }, { PT_F118, "f118" },
1860 { PT_F119, "f119" }, { PT_F120, "f120" }, { PT_F121, "f121" },
1861 { PT_F122, "f122" }, { PT_F123, "f123" }, { PT_F124, "f124" },
1862 { PT_F125, "f125" }, { PT_F126, "f126" }, { PT_F127, "f127" },
1863 /* switch stack: */
1864 { PT_F2, "f2" }, { PT_F3, "f3" }, { PT_F4, "f4" },
1865 { PT_F5, "f5" }, { PT_F10, "f10" }, { PT_F11, "f11" },
1866 { PT_F12, "f12" }, { PT_F13, "f13" }, { PT_F14, "f14" },
1867 { PT_F15, "f15" }, { PT_F16, "f16" }, { PT_F17, "f17" },
1868 { PT_F18, "f18" }, { PT_F19, "f19" }, { PT_F20, "f20" },
1869 { PT_F21, "f21" }, { PT_F22, "f22" }, { PT_F23, "f23" },
1870 { PT_F24, "f24" }, { PT_F25, "f25" }, { PT_F26, "f26" },
1871 { PT_F27, "f27" }, { PT_F28, "f28" }, { PT_F29, "f29" },
1872 { PT_F30, "f30" }, { PT_F31, "f31" }, { PT_R4, "r4" },
1873 { PT_R5, "r5" }, { PT_R6, "r6" }, { PT_R7, "r7" },
1874 { PT_K_B0, "kb0" },
1875 { PT_B1, "b1" }, { PT_B2, "b2" }, { PT_B3, "b3" },
1876 { PT_B4, "b4" }, { PT_B5, "b5" },
1877 { PT_K_AR_PFS, "kar.pfs" },
1878 { PT_AR_LC, "ar.lc" }, { PT_K_AR_UNAT, "kar.unat" },
1879 { PT_K_AR_RNAT, "kar.rnat" }, { PT_K_AR_BSPSTORE, "kar.bspstore" },
1880 { PT_K_PR, "k.pr" },
1881 /* pt_regs */
1882 { PT_CR_IPSR, "cr.ipsr" }, { PT_CR_IIP, "cr.iip" },
1883 { PT_CR_IFS, "cr.ifs" }, { PT_AR_UNAT, "ar.unat" },
1884 { PT_AR_PFS, "ar.pfs" }, { PT_AR_RSC, "ar.rsc" },
1885 { PT_AR_RNAT, "ar.rnat" }, { PT_AR_BSPSTORE, "ar.bspstore" },
1886 { PT_PR, "pr" }, { PT_B6, "b6" }, { PT_AR_BSP, "ar.bsp" },
1887 { PT_R1, "r1" }, { PT_R2, "r2" }, { PT_R3, "r3" },
1888 { PT_R12, "r12" }, { PT_R13, "r13" }, { PT_R14, "r14" },
1889 { PT_R15, "r15" }, { PT_R8, "r8" }, { PT_R9, "r9" },
1890 { PT_R10, "r10" }, { PT_R11, "r11" }, { PT_R16, "r16" },
1891 { PT_R17, "r17" }, { PT_R18, "r18" }, { PT_R19, "r19" },
1892 { PT_R20, "r20" }, { PT_R21, "r21" }, { PT_R22, "r22" },
1893 { PT_R23, "r23" }, { PT_R24, "r24" }, { PT_R25, "r25" },
1894 { PT_R26, "r26" }, { PT_R27, "r27" }, { PT_R28, "r28" },
1895 { PT_R29, "r29" }, { PT_R30, "r30" }, { PT_R31, "r31" },
1896 { PT_AR_CCV, "ar.ccv" }, { PT_AR_FPSR, "ar.fpsr" },
1897 { PT_B0, "b0" }, { PT_B7, "b7" }, { PT_F6, "f6" },
1898 { PT_F7, "f7" }, { PT_F8, "f8" }, { PT_F9, "f9" },
1899#else /* !IA64 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001900#ifdef I386
1901 { 4*EBX, "4*EBX" },
1902 { 4*ECX, "4*ECX" },
1903 { 4*EDX, "4*EDX" },
1904 { 4*ESI, "4*ESI" },
1905 { 4*EDI, "4*EDI" },
1906 { 4*EBP, "4*EBP" },
1907 { 4*EAX, "4*EAX" },
1908 { 4*DS, "4*DS" },
1909 { 4*ES, "4*ES" },
1910 { 4*FS, "4*FS" },
1911 { 4*GS, "4*GS" },
1912 { 4*ORIG_EAX, "4*ORIG_EAX" },
1913 { 4*EIP, "4*EIP" },
1914 { 4*CS, "4*CS" },
1915 { 4*EFL, "4*EFL" },
1916 { 4*UESP, "4*UESP" },
1917 { 4*SS, "4*SS" },
1918#else /* !I386 */
1919#ifdef M68K
1920 { 4*PT_D1, "4*PT_D1" },
1921 { 4*PT_D2, "4*PT_D2" },
1922 { 4*PT_D3, "4*PT_D3" },
1923 { 4*PT_D4, "4*PT_D4" },
1924 { 4*PT_D5, "4*PT_D5" },
1925 { 4*PT_D6, "4*PT_D6" },
1926 { 4*PT_D7, "4*PT_D7" },
1927 { 4*PT_A0, "4*PT_A0" },
1928 { 4*PT_A1, "4*PT_A1" },
1929 { 4*PT_A2, "4*PT_A2" },
1930 { 4*PT_A3, "4*PT_A3" },
1931 { 4*PT_A4, "4*PT_A4" },
1932 { 4*PT_A5, "4*PT_A5" },
1933 { 4*PT_A6, "4*PT_A6" },
1934 { 4*PT_D0, "4*PT_D0" },
1935 { 4*PT_USP, "4*PT_USP" },
1936 { 4*PT_ORIG_D0, "4*PT_ORIG_D0" },
1937 { 4*PT_SR, "4*PT_SR" },
1938 { 4*PT_PC, "4*PT_PC" },
1939#endif /* M68K */
1940#endif /* !I386 */
Wichert Akkerman12f75d12000-02-14 16:23:40 +00001941#if !defined(S390) && !defined(MIPS)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001942 { uoff(u_fpvalid), "offsetof(struct user, u_fpvalid)" },
Wichert Akkermanf90da011999-10-31 21:15:38 +00001943#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001944#ifdef I386
1945 { uoff(i387), "offsetof(struct user, i387)" },
1946#else /* !I386 */
1947#ifdef M68K
1948 { uoff(m68kfp), "offsetof(struct user, m68kfp)" },
1949#endif /* M68K */
1950#endif /* !I386 */
1951 { uoff(u_tsize), "offsetof(struct user, u_tsize)" },
1952 { uoff(u_dsize), "offsetof(struct user, u_dsize)" },
1953 { uoff(u_ssize), "offsetof(struct user, u_ssize)" },
1954 { uoff(start_code), "offsetof(struct user, start_code)" },
1955 { uoff(start_stack), "offsetof(struct user, start_stack)" },
1956 { uoff(signal), "offsetof(struct user, signal)" },
Wichert Akkerman12f75d12000-02-14 16:23:40 +00001957#if !defined(S390) && !defined(MIPS)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001958 { uoff(reserved), "offsetof(struct user, reserved)" },
Wichert Akkermanf90da011999-10-31 21:15:38 +00001959#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001960 { uoff(u_ar0), "offsetof(struct user, u_ar0)" },
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00001961#if !defined(ARM) && !defined(MIPS) && !defined(S390)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001962 { uoff(u_fpstate), "offsetof(struct user, u_fpstate)" },
1963#endif
1964 { uoff(magic), "offsetof(struct user, magic)" },
1965 { uoff(u_comm), "offsetof(struct user, u_comm)" },
1966#ifdef I386
1967 { uoff(u_debugreg), "offsetof(struct user, u_debugreg)" },
1968#endif /* I386 */
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001969#endif /* !IA64 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001970#endif /* !ALPHA */
1971#endif /* !POWERPC/!SPARC */
1972#endif /* LINUX */
1973#ifdef SUNOS4
1974 { uoff(u_pcb), "offsetof(struct user, u_pcb)" },
1975 { uoff(u_procp), "offsetof(struct user, u_procp)" },
1976 { uoff(u_ar0), "offsetof(struct user, u_ar0)" },
1977 { uoff(u_comm[0]), "offsetof(struct user, u_comm[0])" },
1978 { uoff(u_arg[0]), "offsetof(struct user, u_arg[0])" },
1979 { uoff(u_ap), "offsetof(struct user, u_ap)" },
1980 { uoff(u_qsave), "offsetof(struct user, u_qsave)" },
1981 { uoff(u_rval1), "offsetof(struct user, u_rval1)" },
1982 { uoff(u_rval2), "offsetof(struct user, u_rval2)" },
1983 { uoff(u_error), "offsetof(struct user, u_error)" },
1984 { uoff(u_eosys), "offsetof(struct user, u_eosys)" },
1985 { uoff(u_ssave), "offsetof(struct user, u_ssave)" },
1986 { uoff(u_signal[0]), "offsetof(struct user, u_signal)" },
1987 { uoff(u_sigmask[0]), "offsetof(struct user, u_sigmask)" },
1988 { uoff(u_sigonstack), "offsetof(struct user, u_sigonstack)" },
1989 { uoff(u_sigintr), "offsetof(struct user, u_sigintr)" },
1990 { uoff(u_sigreset), "offsetof(struct user, u_sigreset)" },
1991 { uoff(u_oldmask), "offsetof(struct user, u_oldmask)" },
1992 { uoff(u_code), "offsetof(struct user, u_code)" },
1993 { uoff(u_addr), "offsetof(struct user, u_addr)" },
1994 { uoff(u_sigstack), "offsetof(struct user, u_sigstack)" },
1995 { uoff(u_ofile), "offsetof(struct user, u_ofile)" },
1996 { uoff(u_pofile), "offsetof(struct user, u_pofile)" },
1997 { uoff(u_ofile_arr[0]), "offsetof(struct user, u_ofile_arr[0])" },
1998 { uoff(u_pofile_arr[0]),"offsetof(struct user, u_pofile_arr[0])"},
1999 { uoff(u_lastfile), "offsetof(struct user, u_lastfile)" },
2000 { uoff(u_cwd), "offsetof(struct user, u_cwd)" },
2001 { uoff(u_cdir), "offsetof(struct user, u_cdir)" },
2002 { uoff(u_rdir), "offsetof(struct user, u_rdir)" },
2003 { uoff(u_cmask), "offsetof(struct user, u_cmask)" },
2004 { uoff(u_ru), "offsetof(struct user, u_ru)" },
2005 { uoff(u_cru), "offsetof(struct user, u_cru)" },
2006 { uoff(u_timer[0]), "offsetof(struct user, u_timer[0])" },
2007 { uoff(u_XXX[0]), "offsetof(struct user, u_XXX[0])" },
2008 { uoff(u_ioch), "offsetof(struct user, u_ioch)" },
2009 { uoff(u_start), "offsetof(struct user, u_start)" },
2010 { uoff(u_acflag), "offsetof(struct user, u_acflag)" },
2011 { uoff(u_prof.pr_base), "offsetof(struct user, u_prof.pr_base)" },
2012 { uoff(u_prof.pr_size), "offsetof(struct user, u_prof.pr_size)" },
2013 { uoff(u_prof.pr_off), "offsetof(struct user, u_prof.pr_off)" },
2014 { uoff(u_prof.pr_scale),"offsetof(struct user, u_prof.pr_scale)"},
2015 { uoff(u_rlimit[0]), "offsetof(struct user, u_rlimit)" },
2016 { uoff(u_exdata.Ux_A), "offsetof(struct user, u_exdata.Ux_A)" },
2017 { uoff(u_exdata.ux_shell[0]),"offsetof(struct user, u_exdata.ux_shell[0])"},
2018 { uoff(u_lofault), "offsetof(struct user, u_lofault)" },
2019#endif /* SUNOS4 */
2020 { sizeof(struct user), "sizeof(struct user)" },
2021 { 0, NULL },
2022};
2023
2024int
2025sys_ptrace(tcp)
2026struct tcb *tcp;
2027{
2028 char *cmd;
2029 struct xlat *x;
2030 long addr;
2031
2032 cmd = xlookup(ptrace_cmds, tcp->u_arg[0]);
2033 if (!cmd)
2034 cmd = "PTRACE_???";
2035 if (entering(tcp)) {
2036 tprintf("%s, %lu, ", cmd, tcp->u_arg[1]);
2037 addr = tcp->u_arg[2];
2038 if (tcp->u_arg[0] == PTRACE_PEEKUSER
2039 || tcp->u_arg[0] == PTRACE_POKEUSER) {
2040 for (x = struct_user_offsets; x->str; x++) {
2041 if (x->val >= addr)
2042 break;
2043 }
2044 if (!x->str)
2045 tprintf("%#lx, ", addr);
2046 else if (x->val > addr && x != struct_user_offsets) {
2047 x--;
2048 tprintf("%s + %ld, ", x->str, addr - x->val);
2049 }
2050 else
2051 tprintf("%s, ", x->str);
2052 }
2053 else
2054 tprintf("%#lx, ", tcp->u_arg[2]);
2055#ifdef LINUX
2056 switch (tcp->u_arg[0]) {
2057 case PTRACE_PEEKDATA:
2058 case PTRACE_PEEKTEXT:
2059 case PTRACE_PEEKUSER:
2060 break;
2061 case PTRACE_CONT:
2062 case PTRACE_SINGLESTEP:
2063 case PTRACE_SYSCALL:
2064 case PTRACE_DETACH:
2065 printsignal(tcp->u_arg[3]);
2066 break;
2067 default:
2068 tprintf("%#lx", tcp->u_arg[3]);
2069 break;
2070 }
2071 } else {
2072 switch (tcp->u_arg[0]) {
2073 case PTRACE_PEEKDATA:
2074 case PTRACE_PEEKTEXT:
2075 case PTRACE_PEEKUSER:
2076 printnum(tcp, tcp->u_arg[3], "%#x");
2077 break;
2078 }
2079 }
2080#endif /* LINUX */
2081#ifdef SUNOS4
2082 if (tcp->u_arg[0] == PTRACE_WRITEDATA ||
2083 tcp->u_arg[0] == PTRACE_WRITETEXT) {
2084 tprintf("%lu, ", tcp->u_arg[3]);
2085 printstr(tcp, tcp->u_arg[4], tcp->u_arg[3]);
2086 } else if (tcp->u_arg[0] != PTRACE_READDATA &&
2087 tcp->u_arg[0] != PTRACE_READTEXT) {
2088 tprintf("%#lx", tcp->u_arg[3]);
2089 }
2090 } else {
2091 if (tcp->u_arg[0] == PTRACE_READDATA ||
2092 tcp->u_arg[0] == PTRACE_READTEXT) {
2093 tprintf("%lu, ", tcp->u_arg[3]);
2094 printstr(tcp, tcp->u_arg[4], tcp->u_arg[3]);
2095 }
2096 }
2097#endif /* SUNOS4 */
2098 return 0;
2099}
2100
2101#endif /* !SVR4 */