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