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