blob: dda3b9eef61fb6abdd4a08bf069816f65f363c88 [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 Akkermanbf79f2e2000-09-01 21:03:06 +0000379 if (proc_open(tcpchild, 1) < 0)
380 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;
478#else
479#warning Do not know how to handle change_syscall for this architecture
480#endif /* architecture */
481#endif /* LINUX */
482 return -1;
483}
484
485int
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000486setarg(tcp, argnum)
487 struct tcb *tcp;
488 int argnum;
489{
490#if defined (IA64)
491 {
492 unsigned long *bsp, *ap;
493
494 if (upeek(tcp->pid, PT_AR_BSP, (long *) &bsp) , 0)
495 return -1;
496
497 ap = ia64_rse_skip_regs(bsp, argnum);
498 errno = 0;
499 ptrace(PTRACE_POKEDATA, tcp->pid, ap, tcp->u_arg[argnum]);
500 if (errno)
501 return -1;
502
503 }
Wichert Akkerman12f75d12000-02-14 16:23:40 +0000504#elif defined(I386)
505 {
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000506 ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(4*argnum), tcp->u_arg[argnum]);
Wichert Akkerman12f75d12000-02-14 16:23:40 +0000507 if (errno)
508 return -1;
509 }
Ralf Baechlee3816102000-08-01 00:06:06 +0000510#elif defined(MIPS)
511 {
512 errno = 0;
513 if (argnum < 4)
514 ptrace(PTRACE_POKEUSER, tcp->pid,
515 (char*)(REG_A0 + argnum), tcp->u_arg[argnum]);
516 else {
517 unsigned long *sp;
518
519 if (upeek(tcp->pid, REG_SP, (long *) &sp) , 0)
520 return -1;
521
522 ptrace(PTRACE_POKEDATA, tcp->pid,
523 (char*)(sp + argnum - 4), tcp->u_arg[argnum]);
524 }
525 if (errno)
526 return -1;
527 }
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000528#else
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000529# warning Sorry, setargs not implemented for this architecture.
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000530#endif
531 return 0;
532}
533
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000534#ifdef SYS_clone
535int
536internal_clone(tcp)
537struct tcb *tcp;
538{
Ulrich Drepper90512f01999-12-24 07:22:25 +0000539 struct tcb *tcpchild;
540 int pid;
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000541 if (entering(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000542 if (!followfork)
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000543 return 0;
544 if (nprocs == MAX_PROCS) {
545 tcp->flags &= ~TCB_FOLLOWFORK;
546 fprintf(stderr, "sys_fork: tcb table full\n");
547 return 0;
548 }
549 tcp->flags |= TCB_FOLLOWFORK;
550
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000551 tcp->u_arg[0] |= CLONE_PTRACE;
552 setarg(tcp, 0);
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000553 } else {
554 if (!(tcp->flags & TCB_FOLLOWFORK))
555 return 0;
556
557 if (syserror(tcp))
558 return 0;
559
560 pid = tcp->u_rval;
561 if ((tcpchild = alloctcb(pid)) == NULL) {
562 fprintf(stderr, " [tcb table full]\n");
563 kill(pid, SIGKILL); /* XXX */
564 return 0;
565 }
566
567 /* For fork we need to re-attach, but thanks to CLONE_PTRACE we're
568 * already attached.
569 */
Ulrich Drepper90512f01999-12-24 07:22:25 +0000570 tcpchild->flags |= TCB_ATTACHED;
571 newoutf(tcpchild);
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000572 tcp->nchildren++;
573 if (!qflag)
574 fprintf(stderr, "Process %d attached\n", pid);
575 }
576 return 0;
577}
578#endif
579
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000580int
581internal_fork(tcp)
582struct tcb *tcp;
583{
584 struct tcb *tcpchild;
585 int pid;
Nate Sammonsccd8f211999-03-29 22:57:54 +0000586 int dont_follow = 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000587
588#ifdef SYS_vfork
Nate Sammonsccd8f211999-03-29 22:57:54 +0000589 if (tcp->scno == SYS_vfork) {
Nate Sammonsccd8f211999-03-29 22:57:54 +0000590 /* Attempt to make vfork into fork, which we can follow. */
591 if (!followvfork ||
Pavel Machek9a9f10b2000-02-01 16:22:52 +0000592 change_syscall(tcp, SYS_fork) < 0)
Nate Sammonsccd8f211999-03-29 22:57:54 +0000593 dont_follow = 1;
Nate Sammonsccd8f211999-03-29 22:57:54 +0000594 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000595#endif
596 if (entering(tcp)) {
Nate Sammonsccd8f211999-03-29 22:57:54 +0000597 if (!followfork || dont_follow)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000598 return 0;
599 if (nprocs == MAX_PROCS) {
600 tcp->flags &= ~TCB_FOLLOWFORK;
601 fprintf(stderr, "sys_fork: tcb table full\n");
602 return 0;
603 }
604 tcp->flags |= TCB_FOLLOWFORK;
605 if (setbpt(tcp) < 0)
606 return 0;
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000607 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000608 else {
609 int bpt = tcp->flags & TCB_BPTSET;
610
611 if (!(tcp->flags & TCB_FOLLOWFORK))
612 return 0;
613 if (bpt)
614 clearbpt(tcp);
615
616 if (syserror(tcp))
617 return 0;
618
619 pid = tcp->u_rval;
620 if ((tcpchild = alloctcb(pid)) == NULL) {
621 fprintf(stderr, " [tcb table full]\n");
622 kill(pid, SIGKILL); /* XXX */
623 return 0;
624 }
625#ifdef LINUX
626 if (ptrace(PTRACE_ATTACH, pid, (char *) 1, 0) < 0) {
627 perror("PTRACE_ATTACH");
628 fprintf(stderr, "Too late?\n");
629 droptcb(tcpchild);
630 return 0;
631 }
632#endif /* LINUX */
633#ifdef SUNOS4
634#ifdef oldway
635 /* The child must have run before it can be attached. */
636 {
637 struct timeval tv;
638 tv.tv_sec = 0;
639 tv.tv_usec = 10000;
640 select(0, NULL, NULL, NULL, &tv);
641 }
642 if (ptrace(PTRACE_ATTACH, pid, (char *)1, 0) < 0) {
643 perror("PTRACE_ATTACH");
644 fprintf(stderr, "Too late?\n");
645 droptcb(tcpchild);
646 return 0;
647 }
648#else /* !oldway */
649 /* Try to catch the new process as soon as possible. */
650 {
651 int i;
652 for (i = 0; i < 1024; i++)
653 if (ptrace(PTRACE_ATTACH, pid, (char *) 1, 0) >= 0)
654 break;
655 if (i == 1024) {
656 perror("PTRACE_ATTACH");
657 fprintf(stderr, "Too late?\n");
658 droptcb(tcpchild);
659 return 0;
660 }
661 }
662#endif /* !oldway */
663#endif /* SUNOS4 */
664 tcpchild->flags |= TCB_ATTACHED;
665 /* Child has BPT too, must be removed on first occasion */
666 if (bpt) {
667 tcpchild->flags |= TCB_BPTSET;
668 tcpchild->baddr = tcp->baddr;
669 memcpy(tcpchild->inst, tcp->inst,
670 sizeof tcpchild->inst);
671 }
672 newoutf(tcpchild);
673 tcpchild->parent = tcp;
674 tcp->nchildren++;
675 if (!qflag)
676 fprintf(stderr, "Process %d attached\n", pid);
677 }
678 return 0;
679}
680
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000681#endif /* !USE_PROCFS */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000682
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000683#if defined(SUNOS4) || defined(LINUX) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000684
685int
686sys_vfork(tcp)
687struct tcb *tcp;
688{
689 if (exiting(tcp))
690 return RVAL_UDECIMAL;
691 return 0;
692}
693
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000694#endif /* SUNOS4 || LINUX || FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000695
696#ifndef LINUX
697
698static char idstr[16];
699
700int
701sys_getpid(tcp)
702struct tcb *tcp;
703{
704 if (exiting(tcp)) {
705 sprintf(idstr, "ppid %lu", getrval2(tcp));
706 tcp->auxstr = idstr;
707 return RVAL_STR;
708 }
709 return 0;
710}
711
712int
713sys_getuid(tcp)
714struct tcb *tcp;
715{
716 if (exiting(tcp)) {
717 sprintf(idstr, "euid %lu", getrval2(tcp));
718 tcp->auxstr = idstr;
719 return RVAL_STR;
720 }
721 return 0;
722}
723
724int
725sys_getgid(tcp)
726struct tcb *tcp;
727{
728 if (exiting(tcp)) {
729 sprintf(idstr, "egid %lu", getrval2(tcp));
730 tcp->auxstr = idstr;
731 return RVAL_STR;
732 }
733 return 0;
734}
735
736#endif /* !LINUX */
737
738#ifdef LINUX
739
740int
741sys_setuid(tcp)
742struct tcb *tcp;
743{
744 if (entering(tcp)) {
745 tprintf("%u", (uid_t) tcp->u_arg[0]);
746 }
747 return 0;
748}
749
750int
751sys_setgid(tcp)
752struct tcb *tcp;
753{
754 if (entering(tcp)) {
755 tprintf("%u", (gid_t) tcp->u_arg[0]);
756 }
757 return 0;
758}
759
760int
761sys_getresuid(tcp)
762 struct tcb *tcp;
763{
764 if (exiting(tcp)) {
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000765 __kernel_uid_t uid;
766 if (syserror(tcp))
767 tprintf("%#lx, %#lx, %#lx", tcp->u_arg[0],
768 tcp->u_arg[1], tcp->u_arg[2]);
769 else {
770 if (umove(tcp, tcp->u_arg[0], &uid) < 0)
771 tprintf("%#lx, ", tcp->u_arg[0]);
772 else
773 tprintf("ruid %lu, ", (unsigned long) uid);
774 if (umove(tcp, tcp->u_arg[0], &uid) < 0)
775 tprintf("%#lx, ", tcp->u_arg[0]);
776 else
777 tprintf("euid %lu, ", (unsigned long) uid);
778 if (umove(tcp, tcp->u_arg[0], &uid) < 0)
779 tprintf("%#lx", tcp->u_arg[0]);
780 else
781 tprintf("suid %lu", (unsigned long) uid);
782 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000783 }
784 return 0;
785}
786
787int
788sys_getresgid(tcp)
789struct tcb *tcp;
790{
791 if (exiting(tcp)) {
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000792 __kernel_gid_t gid;
793 if (syserror(tcp))
794 tprintf("%#lx, %#lx, %#lx", tcp->u_arg[0],
795 tcp->u_arg[1], tcp->u_arg[2]);
796 else {
797 if (umove(tcp, tcp->u_arg[0], &gid) < 0)
798 tprintf("%#lx, ", tcp->u_arg[0]);
799 else
800 tprintf("rgid %lu, ", (unsigned long) gid);
801 if (umove(tcp, tcp->u_arg[0], &gid) < 0)
802 tprintf("%#lx, ", tcp->u_arg[0]);
803 else
804 tprintf("egid %lu, ", (unsigned long) gid);
805 if (umove(tcp, tcp->u_arg[0], &gid) < 0)
806 tprintf("%#lx", tcp->u_arg[0]);
807 else
808 tprintf("sgid %lu", (unsigned long) gid);
809 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000810 }
811 return 0;
812}
813
814#endif /* LINUX */
815
816int
817sys_setreuid(tcp)
818struct tcb *tcp;
819{
820 if (entering(tcp)) {
821 tprintf("%lu, %lu",
822 (unsigned long) (uid_t) tcp->u_arg[0],
823 (unsigned long) (uid_t) tcp->u_arg[1]);
824 }
825 return 0;
826}
827
828int
829sys_setregid(tcp)
830struct tcb *tcp;
831{
832 if (entering(tcp)) {
833 tprintf("%lu, %lu",
834 (unsigned long) (gid_t) tcp->u_arg[0],
835 (unsigned long) (gid_t) tcp->u_arg[1]);
836 }
837 return 0;
838}
839
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000840#if defined(LINUX) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000841int
842sys_setresuid(tcp)
843 struct tcb *tcp;
844{
845 if (entering(tcp)) {
846 tprintf("ruid %u, euid %u, suid %u",
847 (uid_t) tcp->u_arg[0],
848 (uid_t) tcp->u_arg[1],
849 (uid_t) tcp->u_arg[2]);
850 }
851 return 0;
852}
853int
854sys_setresgid(tcp)
855 struct tcb *tcp;
856{
857 if (entering(tcp)) {
858 tprintf("rgid %u, egid %u, sgid %u",
859 (uid_t) tcp->u_arg[0],
860 (uid_t) tcp->u_arg[1],
861 (uid_t) tcp->u_arg[2]);
862 }
863 return 0;
864}
865
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000866#endif /* LINUX || FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000867
868int
869sys_setgroups(tcp)
870struct tcb *tcp;
871{
872 int i, len;
873 GETGROUPS_T *gidset;
874
875 if (entering(tcp)) {
876 len = tcp->u_arg[0];
877 tprintf("%u, ", len);
878 if (len <= 0) {
879 tprintf("[]");
880 return 0;
881 }
882 gidset = (GETGROUPS_T *) malloc(len * sizeof(GETGROUPS_T));
883 if (gidset == NULL) {
884 fprintf(stderr, "sys_setgroups: out of memory\n");
885 return -1;
886 }
887 if (!verbose(tcp))
888 tprintf("%#lx", tcp->u_arg[1]);
889 else if (umoven(tcp, tcp->u_arg[1],
890 len * sizeof(GETGROUPS_T), (char *) gidset) < 0)
891 tprintf("[?]");
892 else {
893 tprintf("[");
894 for (i = 0; i < len; i++)
895 tprintf("%s%lu", i ? ", " : "",
896 (unsigned long) gidset[i]);
897 tprintf("]");
898 }
899 free((char *) gidset);
900 }
901 return 0;
902}
903
904int
905sys_getgroups(tcp)
906struct tcb *tcp;
907{
908 int i, len;
909 GETGROUPS_T *gidset;
910
911 if (entering(tcp)) {
912 len = tcp->u_arg[0];
913 tprintf("%u, ", len);
914 } else {
915 len = tcp->u_rval;
916 if (len <= 0) {
917 tprintf("[]");
918 return 0;
919 }
920 gidset = (GETGROUPS_T *) malloc(len * sizeof(GETGROUPS_T));
921 if (gidset == NULL) {
922 fprintf(stderr, "sys_getgroups: out of memory\n");
923 return -1;
924 }
925 if (!tcp->u_arg[1])
926 tprintf("NULL");
927 else if (!verbose(tcp) || tcp->u_arg[0] == 0)
928 tprintf("%#lx", tcp->u_arg[1]);
929 else if (umoven(tcp, tcp->u_arg[1],
930 len * sizeof(GETGROUPS_T), (char *) gidset) < 0)
931 tprintf("[?]");
932 else {
933 tprintf("[");
934 for (i = 0; i < len; i++)
935 tprintf("%s%lu", i ? ", " : "",
936 (unsigned long) gidset[i]);
937 tprintf("]");
938 }
939 free((char *)gidset);
940 }
941 return 0;
942}
943
944int
945sys_setpgrp(tcp)
946struct tcb *tcp;
947{
948 if (entering(tcp)) {
949#ifndef SVR4
950 tprintf("%lu, %lu", tcp->u_arg[0], tcp->u_arg[1]);
951#endif /* !SVR4 */
952 }
953 return 0;
954}
955
956int
957sys_getpgrp(tcp)
958struct tcb *tcp;
959{
960 if (entering(tcp)) {
961#ifndef SVR4
962 tprintf("%lu", tcp->u_arg[0]);
963#endif /* !SVR4 */
964 }
965 return 0;
966}
967
968int
969sys_getsid(tcp)
970struct tcb *tcp;
971{
972 if (entering(tcp)) {
973 tprintf("%lu", tcp->u_arg[0]);
974 }
975 return 0;
976}
977
978int
979sys_setsid(tcp)
980struct tcb *tcp;
981{
982 return 0;
983}
984
985int
986sys_getpgid(tcp)
987struct tcb *tcp;
988{
989 if (entering(tcp)) {
990 tprintf("%lu", tcp->u_arg[0]);
991 }
992 return 0;
993}
994
995int
996sys_setpgid(tcp)
997struct tcb *tcp;
998{
999 if (entering(tcp)) {
1000 tprintf("%lu, %lu", tcp->u_arg[0], tcp->u_arg[1]);
1001 }
1002 return 0;
1003}
1004
1005void
1006fake_execve(tcp, program, argv, envp)
1007struct tcb *tcp;
1008char *program;
1009char *argv[];
1010char *envp[];
1011{
1012 int i;
1013
1014#ifdef ARM
1015 if (!(qual_flags[SYS_execve - __NR_SYSCALL_BASE] & QUAL_TRACE))
1016 return;
1017#else
1018 if (!(qual_flags[SYS_execve] & QUAL_TRACE))
1019 return;
1020#endif /* !ARM */
1021 printleader(tcp);
1022 tprintf("execve(");
1023 string_quote(program);
1024 tprintf(", [");
1025 for (i = 0; argv[i] != NULL; i++) {
1026 if (i != 0)
1027 tprintf(", ");
1028 string_quote(argv[i]);
1029 }
1030 for (i = 0; envp[i] != NULL; i++)
1031 ;
1032 tprintf("], [/* %d var%s */]) ", i, (i != 1) ? "s" : "");
1033 tabto(acolumn);
1034 tprintf("= 0");
1035 printtrailer(tcp);
1036}
1037
1038static void
1039printargv(tcp, addr)
1040struct tcb *tcp;
1041long addr;
1042{
1043 char *cp;
1044 char *sep;
1045 int max = max_strlen / 2;
1046
1047 for (sep = ""; --max >= 0; sep = ", ") {
1048 if (!abbrev(tcp))
1049 max++;
1050 if (umove(tcp, addr, &cp) < 0) {
1051 tprintf("%#lx", addr);
1052 return;
1053 }
1054 if (cp == 0)
1055 break;
1056 tprintf(sep);
1057 printstr(tcp, (long) cp, -1);
1058 addr += sizeof(char *);
1059 }
1060 if (cp)
1061 tprintf(", ...");
1062}
1063
1064static void
1065printargc(fmt, tcp, addr)
1066char *fmt;
1067struct tcb *tcp;
1068long addr;
1069{
1070 int count;
1071 char *cp;
1072
1073 for (count = 0; umove(tcp, addr, &cp) >= 0 && cp != NULL; count++) {
1074 addr += sizeof(char *);
1075 }
1076 tprintf(fmt, count, count == 1 ? "" : "s");
1077}
1078
1079int
1080sys_execv(tcp)
1081struct tcb *tcp;
1082{
1083 if (entering(tcp)) {
1084 printpath(tcp, tcp->u_arg[0]);
1085 if (!verbose(tcp))
1086 tprintf(", %#lx", tcp->u_arg[1]);
1087#if 0
1088 else if (abbrev(tcp))
1089 printargc(", [/* %d arg%s */]", tcp, tcp->u_arg[1]);
1090#endif
1091 else {
1092 tprintf(", [");
1093 printargv(tcp, tcp->u_arg[1]);
1094 tprintf("]");
1095 }
1096 }
1097 return 0;
1098}
1099
1100int
1101sys_execve(tcp)
1102struct tcb *tcp;
1103{
1104 if (entering(tcp)) {
1105 printpath(tcp, tcp->u_arg[0]);
1106 if (!verbose(tcp))
1107 tprintf(", %#lx", tcp->u_arg[1]);
1108#if 0
1109 else if (abbrev(tcp))
1110 printargc(", [/* %d arg%s */]", tcp, tcp->u_arg[1]);
1111#endif
1112 else {
1113 tprintf(", [");
1114 printargv(tcp, tcp->u_arg[1]);
1115 tprintf("]");
1116 }
1117 if (!verbose(tcp))
1118 tprintf(", %#lx", tcp->u_arg[2]);
1119 else if (abbrev(tcp))
1120 printargc(", [/* %d var%s */]", tcp, tcp->u_arg[2]);
1121 else {
1122 tprintf(", [");
1123 printargv(tcp, tcp->u_arg[2]);
1124 tprintf("]");
1125 }
1126 }
1127#ifdef LINUX
1128#if defined(ALPHA) || defined(SPARC) || defined(POWERPC)
1129 tcp->flags |= TCB_WAITEXECVE;
1130#endif /* ALPHA || SPARC || POWERPC */
1131#endif /* LINUX */
1132 return 0;
1133}
1134
1135int
1136internal_exec(tcp)
1137struct tcb *tcp;
1138{
1139#ifdef SUNOS4
1140 if (exiting(tcp) && !syserror(tcp) && followfork)
1141 fixvfork(tcp);
1142#endif /* SUNOS4 */
1143 return 0;
1144}
1145
1146#ifdef LINUX
1147#ifndef __WCLONE
1148#define __WCLONE 0x8000000
1149#endif
1150#endif /* LINUX */
1151
1152static struct xlat wait4_options[] = {
1153 { WNOHANG, "WNOHANG" },
1154#ifndef WSTOPPED
1155 { WUNTRACED, "WUNTRACED" },
1156#endif
1157#ifdef WEXITED
1158 { WEXITED, "WEXITED" },
1159#endif
1160#ifdef WTRAPPED
1161 { WTRAPPED, "WTRAPPED" },
1162#endif
1163#ifdef WSTOPPED
1164 { WSTOPPED, "WSTOPPED" },
1165#endif
1166#ifdef WCONTINUED
1167 { WCONTINUED, "WCONTINUED" },
1168#endif
1169#ifdef WNOWAIT
1170 { WNOWAIT, "WNOWAIT" },
1171#endif
1172#ifdef __WCLONE
1173 { __WCLONE, "__WCLONE" },
1174#endif
1175 { 0, NULL },
1176};
1177
1178static int
1179printstatus(status)
1180int status;
1181{
1182 int exited = 0;
1183
1184 /*
1185 * Here is a tricky presentation problem. This solution
1186 * is still not entirely satisfactory but since there
1187 * are no wait status constructors it will have to do.
1188 */
1189 if (WIFSTOPPED(status))
1190 tprintf("[WIFSTOPPED(s) && WSTOPSIG(s) == %s]",
Nate Sammonsce780fc1999-03-29 23:23:13 +00001191 signame(WSTOPSIG(status)));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001192 else if WIFSIGNALED(status)
1193 tprintf("[WIFSIGNALED(s) && WTERMSIG(s) == %s%s]",
Nate Sammonsce780fc1999-03-29 23:23:13 +00001194 signame(WTERMSIG(status)),
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001195 WCOREDUMP(status) ? " && WCOREDUMP(s)" : "");
1196 else if WIFEXITED(status) {
1197 tprintf("[WIFEXITED(s) && WEXITSTATUS(s) == %d]",
1198 WEXITSTATUS(status));
1199 exited = 1;
1200 }
1201 else
1202 tprintf("[%#x]", status);
1203 return exited;
1204}
1205
1206static int
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001207printwaitn(tcp, n, bitness)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001208struct tcb *tcp;
1209int n;
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001210int bitness;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001211{
1212 int status;
1213 int exited = 0;
1214
1215 if (entering(tcp)) {
1216 tprintf("%ld, ", tcp->u_arg[0]);
1217 } else {
1218 /* status */
1219 if (!tcp->u_arg[1])
1220 tprintf("NULL");
1221 else if (syserror(tcp) || tcp->u_rval == 0)
1222 tprintf("%#lx", tcp->u_arg[1]);
1223 else if (umove(tcp, tcp->u_arg[1], &status) < 0)
1224 tprintf("[?]");
1225 else
1226 exited = printstatus(status);
1227 /* options */
1228 tprintf(", ");
1229 if (!printflags(wait4_options, tcp->u_arg[2]))
1230 tprintf("0");
1231 if (n == 4) {
1232 tprintf(", ");
1233 /* usage */
1234 if (!tcp->u_arg[3])
1235 tprintf("NULL");
1236#ifdef LINUX
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001237 else if (tcp->u_rval > 0) {
1238#ifdef LINUX_64BIT
1239 if (bitness)
1240 printrusage32(tcp, tcp->u_arg[3]);
1241 else
1242#endif
1243 printrusage(tcp, tcp->u_arg[3]);
1244 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001245#endif /* LINUX */
1246#ifdef SUNOS4
1247 else if (tcp->u_rval > 0 && exited)
1248 printrusage(tcp, tcp->u_arg[3]);
1249#endif /* SUNOS4 */
1250 else
1251 tprintf("%#lx", tcp->u_arg[3]);
1252 }
1253 }
1254 return 0;
1255}
1256
1257int
1258internal_wait(tcp)
1259struct tcb *tcp;
1260{
1261 if (entering(tcp)) {
Wichert Akkerman5daa0281999-03-15 19:49:42 +00001262 /* WTA: fix bug with hanging children */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001263 if (!(tcp->u_arg[2] & WNOHANG) && tcp->nchildren > 0) {
1264 /* There are traced children */
1265 tcp->flags |= TCB_SUSPENDED;
1266 tcp->waitpid = tcp->u_arg[0];
1267 }
1268 }
1269 return 0;
1270}
1271
1272#ifdef SVR4
1273
1274int
1275sys_wait(tcp)
1276struct tcb *tcp;
1277{
1278 if (exiting(tcp)) {
1279 /* The library wrapper stuffs this into the user variable. */
1280 if (!syserror(tcp))
1281 printstatus(getrval2(tcp));
1282 }
1283 return 0;
1284}
1285
1286#endif /* SVR4 */
1287
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001288#ifdef FREEBSD
1289int
1290sys_wait(tcp)
1291struct tcb *tcp;
1292{
1293 int status;
1294
1295 if (exiting(tcp)) {
1296 if (!syserror(tcp)) {
1297 if (umove(tcp, tcp->u_arg[0], &status) < 0)
1298 tprintf("%#lx", tcp->u_arg[0]);
1299 else
1300 printstatus(status);
1301 }
1302 }
1303 return 0;
1304}
1305#endif
1306
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001307int
1308sys_waitpid(tcp)
1309struct tcb *tcp;
1310{
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001311 return printwaitn(tcp, 3, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001312}
1313
1314int
1315sys_wait4(tcp)
1316struct tcb *tcp;
1317{
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001318 return printwaitn(tcp, 4, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001319}
1320
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001321#ifdef ALPHA
1322int
1323sys_osf_wait4(tcp)
1324struct tcb *tcp;
1325{
1326 return printwaitn(tcp, 4, 1);
1327}
1328#endif
1329
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001330#ifdef SVR4
1331
1332static struct xlat waitid_types[] = {
1333 { P_PID, "P_PID" },
1334 { P_PPID, "P_PPID" },
1335 { P_PGID, "P_PGID" },
1336 { P_SID, "P_SID" },
1337 { P_CID, "P_CID" },
1338 { P_UID, "P_UID" },
1339 { P_GID, "P_GID" },
1340 { P_ALL, "P_ALL" },
1341#ifdef P_LWPID
1342 { P_LWPID, "P_LWPID" },
1343#endif
1344 { 0, NULL },
1345};
1346
1347static struct xlat siginfo_codes[] = {
1348#ifdef SI_NOINFO
1349 { SI_NOINFO, "SI_NOINFO" },
1350#endif
1351#ifdef SI_USER
1352 { SI_USER, "SI_USER" },
1353#endif
1354#ifdef SI_LWP
1355 { SI_LWP, "SI_LWP" },
1356#endif
1357#ifdef SI_QUEUE
1358 { SI_QUEUE, "SI_QUEUE" },
1359#endif
1360#ifdef SI_TIMER
1361 { SI_TIMER, "SI_TIMER" },
1362#endif
1363#ifdef SI_ASYNCIO
1364 { SI_ASYNCIO, "SI_ASYNCIO" },
1365#endif
1366#ifdef SI_MESGQ
1367 { SI_MESGQ, "SI_MESGQ" },
1368#endif
1369 { 0, NULL },
1370};
1371
1372static struct xlat sigtrap_codes[] = {
1373 { TRAP_BRKPT, "TRAP_BRKPT" },
1374 { TRAP_TRACE, "TRAP_TRACE" },
1375 { 0, NULL },
1376};
1377
1378static struct xlat sigcld_codes[] = {
1379 { CLD_EXITED, "CLD_EXITED" },
1380 { CLD_KILLED, "CLD_KILLED" },
1381 { CLD_DUMPED, "CLD_DUMPED" },
1382 { CLD_TRAPPED, "CLD_TRAPPED" },
1383 { CLD_STOPPED, "CLD_STOPPED" },
1384 { CLD_CONTINUED,"CLD_CONTINUED" },
1385 { 0, NULL },
1386};
1387
1388static struct xlat sigpoll_codes[] = {
1389 { POLL_IN, "POLL_IN" },
1390 { POLL_OUT, "POLL_OUT" },
1391 { POLL_MSG, "POLL_MSG" },
1392 { POLL_ERR, "POLL_ERR" },
1393 { POLL_PRI, "POLL_PRI" },
1394 { POLL_HUP, "POLL_HUP" },
1395 { 0, NULL },
1396};
1397
1398static struct xlat sigprof_codes[] = {
1399#ifdef PROF_SIG
1400 { PROF_SIG, "PROF_SIG" },
1401#endif
1402 { 0, NULL },
1403};
1404
1405static struct xlat sigill_codes[] = {
1406 { ILL_ILLOPC, "ILL_ILLOPC" },
1407 { ILL_ILLOPN, "ILL_ILLOPN" },
1408 { ILL_ILLADR, "ILL_ILLADR" },
1409 { ILL_ILLTRP, "ILL_ILLTRP" },
1410 { ILL_PRVOPC, "ILL_PRVOPC" },
1411 { ILL_PRVREG, "ILL_PRVREG" },
1412 { ILL_COPROC, "ILL_COPROC" },
1413 { ILL_BADSTK, "ILL_BADSTK" },
1414 { 0, NULL },
1415};
1416
1417static struct xlat sigemt_codes[] = {
1418#ifdef EMT_TAGOVF
1419 { EMT_TAGOVF, "EMT_TAGOVF" },
1420#endif
1421 { 0, NULL },
1422};
1423
1424static struct xlat sigfpe_codes[] = {
1425 { FPE_INTDIV, "FPE_INTDIV" },
1426 { FPE_INTOVF, "FPE_INTOVF" },
1427 { FPE_FLTDIV, "FPE_FLTDIV" },
1428 { FPE_FLTOVF, "FPE_FLTOVF" },
1429 { FPE_FLTUND, "FPE_FLTUND" },
1430 { FPE_FLTRES, "FPE_FLTRES" },
1431 { FPE_FLTINV, "FPE_FLTINV" },
1432 { FPE_FLTSUB, "FPE_FLTSUB" },
1433 { 0, NULL },
1434};
1435
1436static struct xlat sigsegv_codes[] = {
1437 { SEGV_MAPERR, "SEGV_MAPERR" },
1438 { SEGV_ACCERR, "SEGV_ACCERR" },
1439 { 0, NULL },
1440};
1441
1442static struct xlat sigbus_codes[] = {
1443 { BUS_ADRALN, "BUS_ADRALN" },
1444 { BUS_ADRERR, "BUS_ADRERR" },
1445 { BUS_OBJERR, "BUS_OBJERR" },
1446 { 0, NULL },
1447};
1448
1449void
1450printsiginfo(sip)
1451siginfo_t *sip;
1452{
1453 char *code;
1454
1455 tprintf("{si_signo=");
1456 printsignal(sip->si_signo);
1457 code = xlookup(siginfo_codes, sip->si_code);
1458 if (!code) {
1459 switch (sip->si_signo) {
1460 case SIGTRAP:
1461 code = xlookup(sigtrap_codes, sip->si_code);
1462 break;
1463 case SIGCHLD:
1464 code = xlookup(sigcld_codes, sip->si_code);
1465 break;
1466 case SIGPOLL:
1467 code = xlookup(sigpoll_codes, sip->si_code);
1468 break;
1469 case SIGPROF:
1470 code = xlookup(sigprof_codes, sip->si_code);
1471 break;
1472 case SIGILL:
1473 code = xlookup(sigill_codes, sip->si_code);
1474 break;
1475 case SIGEMT:
1476 code = xlookup(sigemt_codes, sip->si_code);
1477 break;
1478 case SIGFPE:
1479 code = xlookup(sigfpe_codes, sip->si_code);
1480 break;
1481 case SIGSEGV:
1482 code = xlookup(sigsegv_codes, sip->si_code);
1483 break;
1484 case SIGBUS:
1485 code = xlookup(sigbus_codes, sip->si_code);
1486 break;
1487 }
1488 }
1489 if (code)
1490 tprintf(", si_code=%s", code);
1491 else
1492 tprintf(", si_code=%#x", sip->si_code);
1493#ifdef SI_NOINFO
1494 if (sip->si_code != SI_NOINFO) {
1495#endif
1496 if (sip->si_errno) {
1497 if (sip->si_errno < 0 || sip->si_errno >= nerrnos)
1498 tprintf(", si_errno=%d", sip->si_errno);
1499 else
1500 tprintf(", si_errno=%s",
1501 errnoent[sip->si_errno]);
1502 }
1503 if (SI_FROMUSER(sip)) {
1504#ifdef SI_QUEUE
1505 tprintf(", si_pid=%ld, si_uid=%ld",
1506 sip->si_pid, sip->si_uid);
1507 switch (sip->si_code) {
1508 case SI_QUEUE:
1509#ifdef SI_TIMER
1510 case SI_TIMER:
1511#endif /* SI_QUEUE */
1512 case SI_ASYNCIO:
1513#ifdef SI_MESGQ
1514 case SI_MESGQ:
1515#endif /* SI_MESGQ */
1516 tprintf(", si_value=%d",
1517 sip->si_value.sival_int);
1518 break;
1519 }
1520#endif /* SI_QUEUE */
1521 }
1522 else {
1523 switch (sip->si_signo) {
1524 case SIGCHLD:
1525 tprintf(", si_pid=%ld, si_status=",
1526 sip->si_pid);
1527 if (sip->si_code == CLD_EXITED)
1528 tprintf("%d", sip->si_status);
1529 else
1530 printsignal(sip->si_status);
1531 break;
1532 case SIGILL: case SIGFPE:
1533 case SIGSEGV: case SIGBUS:
1534 tprintf(", si_addr=%#lx",
1535 (unsigned long) sip->si_addr);
1536 break;
1537 case SIGPOLL:
1538 switch (sip->si_code) {
1539 case POLL_IN: case POLL_OUT: case POLL_MSG:
1540 tprintf(", si_band=%ld",
1541 (long) sip->si_band);
1542 break;
1543 }
1544 break;
1545 }
1546 }
1547 tprintf(", ...");
1548#ifdef SI_NOINFO
1549 }
1550#endif
1551 tprintf("}");
1552}
1553
1554int
1555sys_waitid(tcp)
1556struct tcb *tcp;
1557{
1558 siginfo_t si;
1559 int exited;
1560
1561 if (entering(tcp)) {
1562 printxval(waitid_types, tcp->u_arg[0], "P_???");
1563 tprintf(", %ld, ", tcp->u_arg[1]);
1564 if (tcp->nchildren > 0) {
1565 /* There are traced children */
1566 tcp->flags |= TCB_SUSPENDED;
1567 tcp->waitpid = tcp->u_arg[0];
1568 }
1569 }
1570 else {
1571 /* siginfo */
1572 exited = 0;
1573 if (!tcp->u_arg[2])
1574 tprintf("NULL");
1575 else if (syserror(tcp))
1576 tprintf("%#lx", tcp->u_arg[2]);
1577 else if (umove(tcp, tcp->u_arg[2], &si) < 0)
1578 tprintf("{???}");
1579 else
1580 printsiginfo(&si);
1581 /* options */
1582 tprintf(", ");
1583 if (!printflags(wait4_options, tcp->u_arg[3]))
1584 tprintf("0");
1585 }
1586 return 0;
1587}
1588
1589#endif /* SVR4 */
1590
1591int
1592sys_alarm(tcp)
1593struct tcb *tcp;
1594{
1595 if (entering(tcp))
1596 tprintf("%lu", tcp->u_arg[0]);
1597 return 0;
1598}
1599
1600int
1601sys_uname(tcp)
1602struct tcb *tcp;
1603{
1604 struct utsname uname;
1605
1606 if (exiting(tcp)) {
1607 if (syserror(tcp) || !verbose(tcp))
1608 tprintf("%#lx", tcp->u_arg[0]);
1609 else if (umove(tcp, tcp->u_arg[0], &uname) < 0)
1610 tprintf("{...}");
1611 else if (!abbrev(tcp)) {
1612
1613 tprintf("{sysname=\"%s\", nodename=\"%s\", ",
1614 uname.sysname, uname.nodename);
1615 tprintf("release=\"%s\", version=\"%s\", ",
1616 uname.release, uname.version);
1617 tprintf("machine=\"%s\"", uname.machine);
1618#ifdef LINUX
1619#ifndef __GLIBC__
1620 tprintf(", domainname=\"%s\"", uname.domainname);
1621#endif /* __GLIBC__ */
1622#endif /* LINUX */
1623 tprintf("}");
1624 }
1625 else
1626 tprintf("{sys=\"%s\", node=\"%s\", ...}",
1627 uname.sysname, uname.nodename);
1628 }
1629 return 0;
1630}
1631
1632#ifndef SVR4
1633
1634static struct xlat ptrace_cmds[] = {
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001635#ifndef FREEBSD
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001636 { PTRACE_TRACEME, "PTRACE_TRACEME" },
1637 { PTRACE_PEEKTEXT, "PTRACE_PEEKTEXT", },
1638 { PTRACE_PEEKDATA, "PTRACE_PEEKDATA", },
1639 { PTRACE_PEEKUSER, "PTRACE_PEEKUSER", },
1640 { PTRACE_POKETEXT, "PTRACE_POKETEXT", },
1641 { PTRACE_POKEDATA, "PTRACE_POKEDATA", },
1642 { PTRACE_POKEUSER, "PTRACE_POKEUSER", },
1643 { PTRACE_CONT, "PTRACE_CONT" },
1644 { PTRACE_KILL, "PTRACE_KILL" },
1645 { PTRACE_SINGLESTEP, "PTRACE_SINGLESTEP" },
1646 { PTRACE_ATTACH, "PTRACE_ATTACH" },
1647 { PTRACE_DETACH, "PTRACE_DETACH" },
1648#ifdef SUNOS4
1649 { PTRACE_GETREGS, "PTRACE_GETREGS" },
1650 { PTRACE_SETREGS, "PTRACE_SETREGS" },
1651 { PTRACE_GETFPREGS, "PTRACE_GETFPREGS", },
1652 { PTRACE_SETFPREGS, "PTRACE_SETFPREGS", },
1653 { PTRACE_READDATA, "PTRACE_READDATA" },
1654 { PTRACE_WRITEDATA, "PTRACE_WRITEDATA" },
1655 { PTRACE_READTEXT, "PTRACE_READTEXT" },
1656 { PTRACE_WRITETEXT, "PTRACE_WRITETEXT" },
1657 { PTRACE_GETFPAREGS, "PTRACE_GETFPAREGS" },
1658 { PTRACE_SETFPAREGS, "PTRACE_SETFPAREGS" },
1659#ifdef SPARC
1660 { PTRACE_GETWINDOW, "PTRACE_GETWINDOW" },
1661 { PTRACE_SETWINDOW, "PTRACE_SETWINDOW" },
1662#else /* !SPARC */
1663 { PTRACE_22, "PTRACE_PTRACE_22" },
1664 { PTRACE_23, "PTRACE_PTRACE_23" },
1665#endif /* !SPARC */
1666#endif /* SUNOS4 */
1667 { PTRACE_SYSCALL, "PTRACE_SYSCALL" },
1668#ifdef SUNOS4
1669 { PTRACE_DUMPCORE, "PTRACE_DUMPCORE" },
1670#ifdef I386
1671 { PTRACE_SETWRBKPT, "PTRACE_SETWRBKPT" },
1672 { PTRACE_SETACBKPT, "PTRACE_SETACBKPT" },
1673 { PTRACE_CLRDR7, "PTRACE_CLRDR7" },
1674#else /* !I386 */
1675 { PTRACE_26, "PTRACE_26" },
1676 { PTRACE_27, "PTRACE_27" },
1677 { PTRACE_28, "PTRACE_28" },
1678#endif /* !I386 */
1679 { PTRACE_GETUCODE, "PTRACE_GETUCODE" },
1680#endif /* SUNOS4 */
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001681#else /* FREEBSD */
1682 { PT_TRACE_ME, "PT_TRACE_ME" },
1683 { PT_READ_I, "PT_READ_I" },
1684 { PT_READ_D, "PT_READ_D" },
1685 { PT_WRITE_I, "PT_WRITE_I" },
1686 { PT_WRITE_D, "PT_WRITE_D" },
1687 { PT_READ_U, "PT_WRITE_U" },
1688 { PT_CONTINUE, "PT_CONTINUE" },
1689 { PT_KILL, "PT_KILL" },
1690 { PT_STEP, "PT_STEP" },
1691 { PT_ATTACH, "PT_ATTACH" },
1692 { PT_DETACH, "PT_DETACH" },
1693 { PT_GETREGS, "PT_GETREGS" },
1694 { PT_SETREGS, "PT_SETREGS" },
1695 { PT_GETFPREGS, "PT_GETFPREGS" },
1696 { PT_SETFPREGS, "PT_SETFPREGS" },
1697 { PT_GETDBREGS, "PT_GETDBREGS" },
1698 { PT_SETDBREGS, "PT_SETDBREGS" },
1699#endif /* FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001700 { 0, NULL },
1701};
1702
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001703#ifndef FREEBSD
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001704#ifndef SUNOS4_KERNEL_ARCH_KLUDGE
1705static
1706#endif /* !SUNOS4_KERNEL_ARCH_KLUDGE */
1707struct xlat struct_user_offsets[] = {
1708#ifdef LINUX
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00001709#ifdef S390
1710 { PT_PSWMASK, "psw_mask" },
1711 { PT_PSWADDR, "psw_addr" },
1712 { PT_GPR0, "gpr0" },
1713 { PT_GPR1, "gpr1" },
1714 { PT_GPR2, "gpr2" },
1715 { PT_GPR3, "gpr3" },
1716 { PT_GPR4, "gpr4" },
1717 { PT_GPR5, "gpr5" },
1718 { PT_GPR6, "gpr6" },
1719 { PT_GPR7, "gpr7" },
1720 { PT_GPR8, "gpr8" },
1721 { PT_GPR9, "gpr9" },
1722 { PT_GPR10, "gpr10" },
1723 { PT_GPR11, "gpr11" },
1724 { PT_GPR12, "gpr12" },
1725 { PT_GPR13, "gpr13" },
1726 { PT_GPR14, "gpr14" },
1727 { PT_GPR15, "gpr15" },
1728 { PT_ACR0, "acr0" },
1729 { PT_ACR1, "acr1" },
1730 { PT_ACR2, "acr2" },
1731 { PT_ACR3, "acr3" },
1732 { PT_ACR4, "acr4" },
1733 { PT_ACR5, "acr5" },
1734 { PT_ACR6, "acr6" },
1735 { PT_ACR7, "acr7" },
1736 { PT_ACR8, "acr8" },
1737 { PT_ACR9, "acr9" },
1738 { PT_ACR10, "acr10" },
1739 { PT_ACR11, "acr11" },
1740 { PT_ACR12, "acr12" },
1741 { PT_ACR13, "acr13" },
1742 { PT_ACR14, "acr14" },
1743 { PT_ACR15, "acr15" },
1744 { PT_ORIGGPR2, "orig_gpr2" },
1745 { PT_FPC, "fpc" },
1746 { PT_FPR0_HI, "fpr0.hi" },
1747 { PT_FPR0_LO, "fpr0.lo" },
1748 { PT_FPR1_HI, "fpr1.hi" },
1749 { PT_FPR1_LO, "fpr1.lo" },
1750 { PT_FPR2_HI, "fpr2.hi" },
1751 { PT_FPR2_LO, "fpr2.lo" },
1752 { PT_FPR3_HI, "fpr3.hi" },
1753 { PT_FPR3_LO, "fpr3.lo" },
1754 { PT_FPR4_HI, "fpr4.hi" },
1755 { PT_FPR4_LO, "fpr4.lo" },
1756 { PT_FPR5_HI, "fpr5.hi" },
1757 { PT_FPR5_LO, "fpr5.lo" },
1758 { PT_FPR6_HI, "fpr6.hi" },
1759 { PT_FPR6_LO, "fpr6.lo" },
1760 { PT_FPR7_HI, "fpr7.hi" },
1761 { PT_FPR7_LO, "fpr7.lo" },
1762 { PT_FPR8_HI, "fpr8.hi" },
1763 { PT_FPR8_LO, "fpr8.lo" },
1764 { PT_FPR9_HI, "fpr9.hi" },
1765 { PT_FPR9_LO, "fpr9.lo" },
1766 { PT_FPR10_HI, "fpr10.hi" },
1767 { PT_FPR10_LO, "fpr10.lo" },
1768 { PT_FPR11_HI, "fpr11.hi" },
1769 { PT_FPR11_LO, "fpr11.lo" },
1770 { PT_FPR12_HI, "fpr12.hi" },
1771 { PT_FPR12_LO, "fpr12.lo" },
1772 { PT_FPR13_HI, "fpr13.hi" },
1773 { PT_FPR13_LO, "fpr13.lo" },
1774 { PT_FPR14_HI, "fpr14.hi" },
1775 { PT_FPR14_LO, "fpr14.lo" },
1776 { PT_FPR15_HI, "fpr15.hi" },
1777 { PT_FPR15_LO, "fpr15.lo" },
1778 { PT_CR_9, "cr9" },
1779 { PT_CR_10, "cr10" },
1780 { PT_CR_11, "cr11" },
1781#endif
1782#if defined(SPARC)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001783 /* XXX No support for these offsets yet. */
1784#elif defined(POWERPC)
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00001785 { 4*PT_R0, "4*PT_R0" },
1786 { 4*PT_R1, "4*PT_R1" },
1787 { 4*PT_R2, "4*PT_R2" },
1788 { 4*PT_R3, "4*PT_R3" },
1789 { 4*PT_R4, "4*PT_R4" },
1790 { 4*PT_R5, "4*PT_R5" },
1791 { 4*PT_R6, "4*PT_R6" },
1792 { 4*PT_R7, "4*PT_R7" },
1793 { 4*PT_R8, "4*PT_R8" },
1794 { 4*PT_R9, "4*PT_R9" },
1795 { 4*PT_R10, "4*PT_R10" },
1796 { 4*PT_R11, "4*PT_R11" },
1797 { 4*PT_R12, "4*PT_R12" },
1798 { 4*PT_R13, "4*PT_R13" },
1799 { 4*PT_R14, "4*PT_R14" },
1800 { 4*PT_R15, "4*PT_R15" },
1801 { 4*PT_R16, "4*PT_R16" },
1802 { 4*PT_R17, "4*PT_R17" },
1803 { 4*PT_R18, "4*PT_R18" },
1804 { 4*PT_R19, "4*PT_R19" },
1805 { 4*PT_R20, "4*PT_R20" },
1806 { 4*PT_R21, "4*PT_R21" },
1807 { 4*PT_R22, "4*PT_R22" },
1808 { 4*PT_R23, "4*PT_R23" },
1809 { 4*PT_R24, "4*PT_R24" },
1810 { 4*PT_R25, "4*PT_R25" },
1811 { 4*PT_R26, "4*PT_R26" },
1812 { 4*PT_R27, "4*PT_R27" },
1813 { 4*PT_R28, "4*PT_R28" },
1814 { 4*PT_R29, "4*PT_R29" },
1815 { 4*PT_R30, "4*PT_R30" },
1816 { 4*PT_R31, "4*PT_R31" },
1817 { 4*PT_NIP, "4*PT_NIP" },
1818 { 4*PT_MSR, "4*PT_MSR" },
1819 { 4*PT_ORIG_R3, "4*PT_ORIG_R3" },
1820 { 4*PT_CTR, "4*PT_CTR" },
1821 { 4*PT_LNK, "4*PT_LNK" },
1822 { 4*PT_XER, "4*PT_XER" },
1823 { 4*PT_CCR, "4*PT_CCR" },
1824 { 4*PT_FPR0, "4*PT_FPR0" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001825#else
1826#ifdef ALPHA
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00001827 { 0, "r0" },
1828 { 1, "r1" },
1829 { 2, "r2" },
1830 { 3, "r3" },
1831 { 4, "r4" },
1832 { 5, "r5" },
1833 { 6, "r6" },
1834 { 7, "r7" },
1835 { 8, "r8" },
1836 { 9, "r9" },
1837 { 10, "r10" },
1838 { 11, "r11" },
1839 { 12, "r12" },
1840 { 13, "r13" },
1841 { 14, "r14" },
1842 { 15, "r15" },
1843 { 16, "r16" },
1844 { 17, "r17" },
1845 { 18, "r18" },
1846 { 19, "r19" },
1847 { 20, "r20" },
1848 { 21, "r21" },
1849 { 22, "r22" },
1850 { 23, "r23" },
1851 { 24, "r24" },
1852 { 25, "r25" },
1853 { 26, "r26" },
1854 { 27, "r27" },
1855 { 28, "r28" },
1856 { 29, "gp" },
1857 { 30, "fp" },
1858 { 31, "zero" },
1859 { 32, "fp0" },
1860 { 33, "fp" },
1861 { 34, "fp2" },
1862 { 35, "fp3" },
1863 { 36, "fp4" },
1864 { 37, "fp5" },
1865 { 38, "fp6" },
1866 { 39, "fp7" },
1867 { 40, "fp8" },
1868 { 41, "fp9" },
1869 { 42, "fp10" },
1870 { 43, "fp11" },
1871 { 44, "fp12" },
1872 { 45, "fp13" },
1873 { 46, "fp14" },
1874 { 47, "fp15" },
1875 { 48, "fp16" },
1876 { 49, "fp17" },
1877 { 50, "fp18" },
1878 { 51, "fp19" },
1879 { 52, "fp20" },
1880 { 53, "fp21" },
1881 { 54, "fp22" },
1882 { 55, "fp23" },
1883 { 56, "fp24" },
1884 { 57, "fp25" },
1885 { 58, "fp26" },
1886 { 59, "fp27" },
1887 { 60, "fp28" },
1888 { 61, "fp29" },
1889 { 62, "fp30" },
1890 { 63, "fp31" },
1891 { 64, "pc" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001892#else /* !ALPHA */
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001893#ifdef IA64
1894 { PT_F32, "f32" }, { PT_F33, "f33" }, { PT_F34, "f34" },
1895 { PT_F35, "f35" }, { PT_F36, "f36" }, { PT_F37, "f37" },
1896 { PT_F38, "f38" }, { PT_F39, "f39" }, { PT_F40, "f40" },
1897 { PT_F41, "f41" }, { PT_F42, "f42" }, { PT_F43, "f43" },
1898 { PT_F44, "f44" }, { PT_F45, "f45" }, { PT_F46, "f46" },
1899 { PT_F47, "f47" }, { PT_F48, "f48" }, { PT_F49, "f49" },
1900 { PT_F50, "f50" }, { PT_F51, "f51" }, { PT_F52, "f52" },
1901 { PT_F53, "f53" }, { PT_F54, "f54" }, { PT_F55, "f55" },
1902 { PT_F56, "f56" }, { PT_F57, "f57" }, { PT_F58, "f58" },
1903 { PT_F59, "f59" }, { PT_F60, "f60" }, { PT_F61, "f61" },
1904 { PT_F62, "f62" }, { PT_F63, "f63" }, { PT_F64, "f64" },
1905 { PT_F65, "f65" }, { PT_F66, "f66" }, { PT_F67, "f67" },
1906 { PT_F68, "f68" }, { PT_F69, "f69" }, { PT_F70, "f70" },
1907 { PT_F71, "f71" }, { PT_F72, "f72" }, { PT_F73, "f73" },
1908 { PT_F74, "f74" }, { PT_F75, "f75" }, { PT_F76, "f76" },
1909 { PT_F77, "f77" }, { PT_F78, "f78" }, { PT_F79, "f79" },
1910 { PT_F80, "f80" }, { PT_F81, "f81" }, { PT_F82, "f82" },
1911 { PT_F83, "f83" }, { PT_F84, "f84" }, { PT_F85, "f85" },
1912 { PT_F86, "f86" }, { PT_F87, "f87" }, { PT_F88, "f88" },
1913 { PT_F89, "f89" }, { PT_F90, "f90" }, { PT_F91, "f91" },
1914 { PT_F92, "f92" }, { PT_F93, "f93" }, { PT_F94, "f94" },
1915 { PT_F95, "f95" }, { PT_F96, "f96" }, { PT_F97, "f97" },
1916 { PT_F98, "f98" }, { PT_F99, "f99" }, { PT_F100, "f100" },
1917 { PT_F101, "f101" }, { PT_F102, "f102" }, { PT_F103, "f103" },
1918 { PT_F104, "f104" }, { PT_F105, "f105" }, { PT_F106, "f106" },
1919 { PT_F107, "f107" }, { PT_F108, "f108" }, { PT_F109, "f109" },
1920 { PT_F110, "f110" }, { PT_F111, "f111" }, { PT_F112, "f112" },
1921 { PT_F113, "f113" }, { PT_F114, "f114" }, { PT_F115, "f115" },
1922 { PT_F116, "f116" }, { PT_F117, "f117" }, { PT_F118, "f118" },
1923 { PT_F119, "f119" }, { PT_F120, "f120" }, { PT_F121, "f121" },
1924 { PT_F122, "f122" }, { PT_F123, "f123" }, { PT_F124, "f124" },
1925 { PT_F125, "f125" }, { PT_F126, "f126" }, { PT_F127, "f127" },
1926 /* switch stack: */
1927 { PT_F2, "f2" }, { PT_F3, "f3" }, { PT_F4, "f4" },
1928 { PT_F5, "f5" }, { PT_F10, "f10" }, { PT_F11, "f11" },
1929 { PT_F12, "f12" }, { PT_F13, "f13" }, { PT_F14, "f14" },
1930 { PT_F15, "f15" }, { PT_F16, "f16" }, { PT_F17, "f17" },
1931 { PT_F18, "f18" }, { PT_F19, "f19" }, { PT_F20, "f20" },
1932 { PT_F21, "f21" }, { PT_F22, "f22" }, { PT_F23, "f23" },
1933 { PT_F24, "f24" }, { PT_F25, "f25" }, { PT_F26, "f26" },
1934 { PT_F27, "f27" }, { PT_F28, "f28" }, { PT_F29, "f29" },
1935 { PT_F30, "f30" }, { PT_F31, "f31" }, { PT_R4, "r4" },
1936 { PT_R5, "r5" }, { PT_R6, "r6" }, { PT_R7, "r7" },
1937 { PT_K_B0, "kb0" },
1938 { PT_B1, "b1" }, { PT_B2, "b2" }, { PT_B3, "b3" },
1939 { PT_B4, "b4" }, { PT_B5, "b5" },
1940 { PT_K_AR_PFS, "kar.pfs" },
1941 { PT_AR_LC, "ar.lc" }, { PT_K_AR_UNAT, "kar.unat" },
1942 { PT_K_AR_RNAT, "kar.rnat" }, { PT_K_AR_BSPSTORE, "kar.bspstore" },
1943 { PT_K_PR, "k.pr" },
1944 /* pt_regs */
1945 { PT_CR_IPSR, "cr.ipsr" }, { PT_CR_IIP, "cr.iip" },
1946 { PT_CR_IFS, "cr.ifs" }, { PT_AR_UNAT, "ar.unat" },
1947 { PT_AR_PFS, "ar.pfs" }, { PT_AR_RSC, "ar.rsc" },
1948 { PT_AR_RNAT, "ar.rnat" }, { PT_AR_BSPSTORE, "ar.bspstore" },
1949 { PT_PR, "pr" }, { PT_B6, "b6" }, { PT_AR_BSP, "ar.bsp" },
1950 { PT_R1, "r1" }, { PT_R2, "r2" }, { PT_R3, "r3" },
1951 { PT_R12, "r12" }, { PT_R13, "r13" }, { PT_R14, "r14" },
1952 { PT_R15, "r15" }, { PT_R8, "r8" }, { PT_R9, "r9" },
1953 { PT_R10, "r10" }, { PT_R11, "r11" }, { PT_R16, "r16" },
1954 { PT_R17, "r17" }, { PT_R18, "r18" }, { PT_R19, "r19" },
1955 { PT_R20, "r20" }, { PT_R21, "r21" }, { PT_R22, "r22" },
1956 { PT_R23, "r23" }, { PT_R24, "r24" }, { PT_R25, "r25" },
1957 { PT_R26, "r26" }, { PT_R27, "r27" }, { PT_R28, "r28" },
1958 { PT_R29, "r29" }, { PT_R30, "r30" }, { PT_R31, "r31" },
1959 { PT_AR_CCV, "ar.ccv" }, { PT_AR_FPSR, "ar.fpsr" },
1960 { PT_B0, "b0" }, { PT_B7, "b7" }, { PT_F6, "f6" },
1961 { PT_F7, "f7" }, { PT_F8, "f8" }, { PT_F9, "f9" },
1962#else /* !IA64 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001963#ifdef I386
1964 { 4*EBX, "4*EBX" },
1965 { 4*ECX, "4*ECX" },
1966 { 4*EDX, "4*EDX" },
1967 { 4*ESI, "4*ESI" },
1968 { 4*EDI, "4*EDI" },
1969 { 4*EBP, "4*EBP" },
1970 { 4*EAX, "4*EAX" },
1971 { 4*DS, "4*DS" },
1972 { 4*ES, "4*ES" },
1973 { 4*FS, "4*FS" },
1974 { 4*GS, "4*GS" },
1975 { 4*ORIG_EAX, "4*ORIG_EAX" },
1976 { 4*EIP, "4*EIP" },
1977 { 4*CS, "4*CS" },
1978 { 4*EFL, "4*EFL" },
1979 { 4*UESP, "4*UESP" },
1980 { 4*SS, "4*SS" },
1981#else /* !I386 */
1982#ifdef M68K
1983 { 4*PT_D1, "4*PT_D1" },
1984 { 4*PT_D2, "4*PT_D2" },
1985 { 4*PT_D3, "4*PT_D3" },
1986 { 4*PT_D4, "4*PT_D4" },
1987 { 4*PT_D5, "4*PT_D5" },
1988 { 4*PT_D6, "4*PT_D6" },
1989 { 4*PT_D7, "4*PT_D7" },
1990 { 4*PT_A0, "4*PT_A0" },
1991 { 4*PT_A1, "4*PT_A1" },
1992 { 4*PT_A2, "4*PT_A2" },
1993 { 4*PT_A3, "4*PT_A3" },
1994 { 4*PT_A4, "4*PT_A4" },
1995 { 4*PT_A5, "4*PT_A5" },
1996 { 4*PT_A6, "4*PT_A6" },
1997 { 4*PT_D0, "4*PT_D0" },
1998 { 4*PT_USP, "4*PT_USP" },
1999 { 4*PT_ORIG_D0, "4*PT_ORIG_D0" },
2000 { 4*PT_SR, "4*PT_SR" },
2001 { 4*PT_PC, "4*PT_PC" },
2002#endif /* M68K */
2003#endif /* !I386 */
Wichert Akkerman12f75d12000-02-14 16:23:40 +00002004#if !defined(S390) && !defined(MIPS)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002005 { uoff(u_fpvalid), "offsetof(struct user, u_fpvalid)" },
Wichert Akkermanf90da011999-10-31 21:15:38 +00002006#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002007#ifdef I386
2008 { uoff(i387), "offsetof(struct user, i387)" },
2009#else /* !I386 */
2010#ifdef M68K
2011 { uoff(m68kfp), "offsetof(struct user, m68kfp)" },
2012#endif /* M68K */
2013#endif /* !I386 */
2014 { uoff(u_tsize), "offsetof(struct user, u_tsize)" },
2015 { uoff(u_dsize), "offsetof(struct user, u_dsize)" },
2016 { uoff(u_ssize), "offsetof(struct user, u_ssize)" },
2017 { uoff(start_code), "offsetof(struct user, start_code)" },
2018 { uoff(start_stack), "offsetof(struct user, start_stack)" },
2019 { uoff(signal), "offsetof(struct user, signal)" },
Wichert Akkerman12f75d12000-02-14 16:23:40 +00002020#if !defined(S390) && !defined(MIPS)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002021 { uoff(reserved), "offsetof(struct user, reserved)" },
Wichert Akkermanf90da011999-10-31 21:15:38 +00002022#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002023 { uoff(u_ar0), "offsetof(struct user, u_ar0)" },
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00002024#if !defined(ARM) && !defined(MIPS) && !defined(S390)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002025 { uoff(u_fpstate), "offsetof(struct user, u_fpstate)" },
2026#endif
2027 { uoff(magic), "offsetof(struct user, magic)" },
2028 { uoff(u_comm), "offsetof(struct user, u_comm)" },
2029#ifdef I386
2030 { uoff(u_debugreg), "offsetof(struct user, u_debugreg)" },
2031#endif /* I386 */
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00002032#endif /* !IA64 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002033#endif /* !ALPHA */
2034#endif /* !POWERPC/!SPARC */
2035#endif /* LINUX */
2036#ifdef SUNOS4
2037 { uoff(u_pcb), "offsetof(struct user, u_pcb)" },
2038 { uoff(u_procp), "offsetof(struct user, u_procp)" },
2039 { uoff(u_ar0), "offsetof(struct user, u_ar0)" },
2040 { uoff(u_comm[0]), "offsetof(struct user, u_comm[0])" },
2041 { uoff(u_arg[0]), "offsetof(struct user, u_arg[0])" },
2042 { uoff(u_ap), "offsetof(struct user, u_ap)" },
2043 { uoff(u_qsave), "offsetof(struct user, u_qsave)" },
2044 { uoff(u_rval1), "offsetof(struct user, u_rval1)" },
2045 { uoff(u_rval2), "offsetof(struct user, u_rval2)" },
2046 { uoff(u_error), "offsetof(struct user, u_error)" },
2047 { uoff(u_eosys), "offsetof(struct user, u_eosys)" },
2048 { uoff(u_ssave), "offsetof(struct user, u_ssave)" },
2049 { uoff(u_signal[0]), "offsetof(struct user, u_signal)" },
2050 { uoff(u_sigmask[0]), "offsetof(struct user, u_sigmask)" },
2051 { uoff(u_sigonstack), "offsetof(struct user, u_sigonstack)" },
2052 { uoff(u_sigintr), "offsetof(struct user, u_sigintr)" },
2053 { uoff(u_sigreset), "offsetof(struct user, u_sigreset)" },
2054 { uoff(u_oldmask), "offsetof(struct user, u_oldmask)" },
2055 { uoff(u_code), "offsetof(struct user, u_code)" },
2056 { uoff(u_addr), "offsetof(struct user, u_addr)" },
2057 { uoff(u_sigstack), "offsetof(struct user, u_sigstack)" },
2058 { uoff(u_ofile), "offsetof(struct user, u_ofile)" },
2059 { uoff(u_pofile), "offsetof(struct user, u_pofile)" },
2060 { uoff(u_ofile_arr[0]), "offsetof(struct user, u_ofile_arr[0])" },
2061 { uoff(u_pofile_arr[0]),"offsetof(struct user, u_pofile_arr[0])"},
2062 { uoff(u_lastfile), "offsetof(struct user, u_lastfile)" },
2063 { uoff(u_cwd), "offsetof(struct user, u_cwd)" },
2064 { uoff(u_cdir), "offsetof(struct user, u_cdir)" },
2065 { uoff(u_rdir), "offsetof(struct user, u_rdir)" },
2066 { uoff(u_cmask), "offsetof(struct user, u_cmask)" },
2067 { uoff(u_ru), "offsetof(struct user, u_ru)" },
2068 { uoff(u_cru), "offsetof(struct user, u_cru)" },
2069 { uoff(u_timer[0]), "offsetof(struct user, u_timer[0])" },
2070 { uoff(u_XXX[0]), "offsetof(struct user, u_XXX[0])" },
2071 { uoff(u_ioch), "offsetof(struct user, u_ioch)" },
2072 { uoff(u_start), "offsetof(struct user, u_start)" },
2073 { uoff(u_acflag), "offsetof(struct user, u_acflag)" },
2074 { uoff(u_prof.pr_base), "offsetof(struct user, u_prof.pr_base)" },
2075 { uoff(u_prof.pr_size), "offsetof(struct user, u_prof.pr_size)" },
2076 { uoff(u_prof.pr_off), "offsetof(struct user, u_prof.pr_off)" },
2077 { uoff(u_prof.pr_scale),"offsetof(struct user, u_prof.pr_scale)"},
2078 { uoff(u_rlimit[0]), "offsetof(struct user, u_rlimit)" },
2079 { uoff(u_exdata.Ux_A), "offsetof(struct user, u_exdata.Ux_A)" },
2080 { uoff(u_exdata.ux_shell[0]),"offsetof(struct user, u_exdata.ux_shell[0])"},
2081 { uoff(u_lofault), "offsetof(struct user, u_lofault)" },
2082#endif /* SUNOS4 */
2083 { sizeof(struct user), "sizeof(struct user)" },
2084 { 0, NULL },
2085};
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002086#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002087
2088int
2089sys_ptrace(tcp)
2090struct tcb *tcp;
2091{
2092 char *cmd;
2093 struct xlat *x;
2094 long addr;
2095
2096 cmd = xlookup(ptrace_cmds, tcp->u_arg[0]);
2097 if (!cmd)
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002098#ifndef FREEBSD
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002099 cmd = "PTRACE_???";
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002100#else
2101 cmd = "PT_???";
2102#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002103 if (entering(tcp)) {
2104 tprintf("%s, %lu, ", cmd, tcp->u_arg[1]);
2105 addr = tcp->u_arg[2];
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002106#ifndef FREEBSD
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002107 if (tcp->u_arg[0] == PTRACE_PEEKUSER
2108 || tcp->u_arg[0] == PTRACE_POKEUSER) {
2109 for (x = struct_user_offsets; x->str; x++) {
2110 if (x->val >= addr)
2111 break;
2112 }
2113 if (!x->str)
2114 tprintf("%#lx, ", addr);
2115 else if (x->val > addr && x != struct_user_offsets) {
2116 x--;
2117 tprintf("%s + %ld, ", x->str, addr - x->val);
2118 }
2119 else
2120 tprintf("%s, ", x->str);
2121 }
2122 else
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002123#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002124 tprintf("%#lx, ", tcp->u_arg[2]);
2125#ifdef LINUX
2126 switch (tcp->u_arg[0]) {
2127 case PTRACE_PEEKDATA:
2128 case PTRACE_PEEKTEXT:
2129 case PTRACE_PEEKUSER:
2130 break;
2131 case PTRACE_CONT:
2132 case PTRACE_SINGLESTEP:
2133 case PTRACE_SYSCALL:
2134 case PTRACE_DETACH:
2135 printsignal(tcp->u_arg[3]);
2136 break;
2137 default:
2138 tprintf("%#lx", tcp->u_arg[3]);
2139 break;
2140 }
2141 } else {
2142 switch (tcp->u_arg[0]) {
2143 case PTRACE_PEEKDATA:
2144 case PTRACE_PEEKTEXT:
2145 case PTRACE_PEEKUSER:
2146 printnum(tcp, tcp->u_arg[3], "%#x");
2147 break;
2148 }
2149 }
2150#endif /* LINUX */
2151#ifdef SUNOS4
2152 if (tcp->u_arg[0] == PTRACE_WRITEDATA ||
2153 tcp->u_arg[0] == PTRACE_WRITETEXT) {
2154 tprintf("%lu, ", tcp->u_arg[3]);
2155 printstr(tcp, tcp->u_arg[4], tcp->u_arg[3]);
2156 } else if (tcp->u_arg[0] != PTRACE_READDATA &&
2157 tcp->u_arg[0] != PTRACE_READTEXT) {
2158 tprintf("%#lx", tcp->u_arg[3]);
2159 }
2160 } else {
2161 if (tcp->u_arg[0] == PTRACE_READDATA ||
2162 tcp->u_arg[0] == PTRACE_READTEXT) {
2163 tprintf("%lu, ", tcp->u_arg[3]);
2164 printstr(tcp, tcp->u_arg[4], tcp->u_arg[3]);
2165 }
2166 }
2167#endif /* SUNOS4 */
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002168#ifdef FREEBSD
2169 tprintf("%lu", tcp->u_arg[3]);
2170 }
2171#endif /* FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002172 return 0;
2173}
2174
2175#endif /* !SVR4 */