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