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