blob: ea8b15c9a24a50bda27b32e1ef0e3c44df0e6c14 [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>
Wichert Akkermanccef6372002-05-01 16:39:22 +00009 * Copyright (c) 2000 PocketPenguins Inc. Linux for Hitachi SuperH
10 * port by Greg Banks <gbanks@pocketpenguins.com>
11
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +000012 *
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000013 * All rights reserved.
14 *
15 * Redistribution and use in source and binary forms, with or without
16 * modification, are permitted provided that the following conditions
17 * are met:
18 * 1. Redistributions of source code must retain the above copyright
19 * notice, this list of conditions and the following disclaimer.
20 * 2. Redistributions in binary form must reproduce the above copyright
21 * notice, this list of conditions and the following disclaimer in the
22 * documentation and/or other materials provided with the distribution.
23 * 3. The name of the author may not be used to endorse or promote products
24 * derived from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
27 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
28 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
29 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
30 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
31 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
35 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 *
37 * $Id$
38 */
39
40#include "defs.h"
41
42#include <fcntl.h>
43#include <sys/stat.h>
44#include <sys/time.h>
45#include <sys/wait.h>
46#include <sys/resource.h>
47#include <sys/utsname.h>
48#include <sys/user.h>
49#include <sys/syscall.h>
50#include <signal.h>
51#ifdef SUNOS4
52#include <machine/reg.h>
53#endif /* SUNOS4 */
54
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +000055#ifdef FREEBSD
56#include <sys/ptrace.h>
57#endif
58
Wichert Akkerman00a82ee2001-03-28 20:29:17 +000059#if HAVE_ASM_REG_H
60#ifdef SPARC
61# define fpq kernel_fpq
62# define fq kernel_fq
63# define fpu kernel_fpu
64#endif
65#include <asm/reg.h>
66#ifdef SPARC
67# undef fpq
68# undef fq
69# undef fpu
70#endif
71#endif /* HAVE_ASM_REG_H */
72
Wichert Akkerman36915a11999-07-13 15:45:02 +000073#ifdef HAVE_SYS_REG_H
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000074# include <sys/reg.h>
Wichert Akkerman15dea971999-10-06 13:06:34 +000075#ifndef PTRACE_PEEKUSR
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000076# define PTRACE_PEEKUSR PTRACE_PEEKUSER
Wichert Akkerman15dea971999-10-06 13:06:34 +000077#endif
78#ifndef PTRACE_POKEUSR
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000079# define PTRACE_POKEUSR PTRACE_POKEUSER
80#endif
Wichert Akkermanfaf72222000-02-19 23:59:03 +000081#elif defined(HAVE_LINUX_PTRACE_H)
82#undef PTRACE_SYSCALL
83#include <linux/ptrace.h>
Wichert Akkerman15dea971999-10-06 13:06:34 +000084#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000085
Wichert Akkermanfaf72222000-02-19 23:59:03 +000086
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000087#ifdef LINUX
Wichert Akkerman2e2553a1999-05-09 00:29:58 +000088#include <asm/posix_types.h>
89#undef GETGROUPS_T
90#define GETGROUPS_T __kernel_gid_t
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000091#endif /* LINUX */
92
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +000093#if defined(LINUX) && defined(IA64)
94# include <asm/ptrace_offsets.h>
95# include <asm/rse.h>
96#endif
97
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000098#ifdef HAVE_PRCTL
99#include <sys/prctl.h>
100#endif
101
102#ifndef WCOREDUMP
103#define WCOREDUMP(status) ((status) & 0200)
104#endif
105
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000106/* WTA: this was `&& !defined(LINUXSPARC)', this seems unneeded though? */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000107#if defined(HAVE_PRCTL)
108static struct xlat prctl_options[] = {
109#ifdef PR_MAXPROCS
110 { PR_MAXPROCS, "PR_MAXPROCS" },
111#endif
112#ifdef PR_ISBLOCKED
113 { PR_ISBLOCKED, "PR_ISBLOCKED" },
114#endif
115#ifdef PR_SETSTACKSIZE
116 { PR_SETSTACKSIZE, "PR_SETSTACKSIZE" },
117#endif
118#ifdef PR_GETSTACKSIZE
119 { PR_GETSTACKSIZE, "PR_GETSTACKSIZE" },
120#endif
121#ifdef PR_MAXPPROCS
122 { PR_MAXPPROCS, "PR_MAXPPROCS" },
123#endif
124#ifdef PR_UNBLKONEXEC
125 { PR_UNBLKONEXEC, "PR_UNBLKONEXEC" },
126#endif
127#ifdef PR_ATOMICSIM
128 { PR_ATOMICSIM, "PR_ATOMICSIM" },
129#endif
130#ifdef PR_SETEXITSIG
131 { PR_SETEXITSIG, "PR_SETEXITSIG" },
132#endif
133#ifdef PR_RESIDENT
134 { PR_RESIDENT, "PR_RESIDENT" },
135#endif
136#ifdef PR_ATTACHADDR
137 { PR_ATTACHADDR, "PR_ATTACHADDR" },
138#endif
139#ifdef PR_DETACHADDR
140 { PR_DETACHADDR, "PR_DETACHADDR" },
141#endif
142#ifdef PR_TERMCHILD
143 { PR_TERMCHILD, "PR_TERMCHILD" },
144#endif
145#ifdef PR_GETSHMASK
146 { PR_GETSHMASK, "PR_GETSHMASK" },
147#endif
148#ifdef PR_GETNSHARE
149 { PR_GETNSHARE, "PR_GETNSHARE" },
150#endif
151#if defined(PR_SET_PDEATHSIG)
152 { PR_SET_PDEATHSIG, "PR_SET_PDEATHSIG" },
153#endif
Wichert Akkerman8829a551999-06-11 13:18:40 +0000154#ifdef PR_COREPID
155 { PR_COREPID, "PR_COREPID" },
156#endif
157#ifdef PR_ATTACHADDRPERM
158 { PR_ATTACHADDRPERM, "PR_ATTACHADDRPERM" },
159#endif
160#ifdef PR_PTHREADEXIT
161 { PR_PTHREADEXIT, "PR_PTHREADEXIT" },
162#endif
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000163#ifdef PR_SET_PDEATHSIG
164 { PR_SET_PDEATHSIG, "PR_SET_PDEATHSIG" },
165#endif
166#ifdef PR_GET_PDEATHSIG
167 { PR_GET_PDEATHSIG, "PR_GET_PDEATHSIG" },
168#endif
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000169#ifdef PR_GET_UNALIGN
170 { PR_GET_UNALIGN, "PR_GET_UNALIGN" },
171#endif
172#ifdef PR_SET_UNALIGN
173 { PR_SET_UNALIGN, "PR_SET_UNALIGN" },
174#endif
175#ifdef PR_GET_KEEPCAPS
176 { PR_GET_KEEPCAPS, "PR_GET_KEEP_CAPS" },
177#endif
178#ifdef PR_SET_KEEPCAPS
179 { PR_SET_KEEPCAPS, "PR_SET_KEEP_CAPS" },
180#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000181 { 0, NULL },
182};
183
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000184
185const char *
186unalignctl_string (unsigned int ctl)
187{
188 static char buf[16];
189
190 switch (ctl) {
191#ifdef PR_UNALIGN_NOPRINT
192 case PR_UNALIGN_NOPRINT:
193 return "NOPRINT";
194#endif
195#ifdef PR_UNALIGN_SIGBUS
196 case PR_UNALIGN_SIGBUS:
197 return "SIGBUS";
198#endif
199 default:
200 break;
201 }
202 sprintf(buf, "%x", ctl);
203 return buf;
204}
205
206
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000207int
208sys_prctl(tcp)
209struct tcb *tcp;
210{
211 int i;
212
213 if (entering(tcp)) {
214 printxval(prctl_options, tcp->u_arg[0], "PR_???");
215 switch (tcp->u_arg[0]) {
216#ifdef PR_GETNSHARE
217 case PR_GETNSHARE:
218 break;
219#endif
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000220#ifdef PR_SET_DEATHSIG
221 case PR_GET_PDEATHSIG:
222 break;
223#endif
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000224#ifdef PR_SET_UNALIGN
225 case PR_SET_UNALIGN:
226 tprintf(", %s", unalignctl_string(tcp->u_arg[1]));
227 break;
228#endif
229#ifdef PR_GET_UNALIGN
230 case PR_GET_UNALIGN:
231 tprintf(", %#lx", tcp->u_arg[1]);
232 break;
233#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000234 default:
235 for (i = 1; i < tcp->u_nargs; i++)
236 tprintf(", %#lx", tcp->u_arg[i]);
237 break;
238 }
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000239 } else {
240 switch (tcp->u_arg[0]) {
241#ifdef PR_GET_PDEATHSIG
242 case PR_GET_PDEATHSIG:
243 for (i=1; i<tcp->u_nargs; i++)
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000244 tprintf(", %#lx", tcp->u_arg[i]);
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000245 break;
246#endif
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000247#ifdef PR_SET_UNALIGN
248 case PR_SET_UNALIGN:
249 break;
250#endif
251#ifdef PR_GET_UNALIGN
252 case PR_GET_UNALIGN:
253 {
254 int ctl;
255
256 umove(tcp, tcp->u_arg[1], &ctl);
257 tcp->auxstr = unalignctl_string(ctl);
258 return RVAL_STR;
259 }
260#endif
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000261 default:
262 break;
263 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000264 }
265 return 0;
266}
267
268#endif /* HAVE_PRCTL */
269
270int
271sys_gethostid(tcp)
272struct tcb *tcp;
273{
274 if (exiting(tcp))
275 return RVAL_HEX;
276 return 0;
277}
278
279int
280sys_sethostname(tcp)
281struct tcb *tcp;
282{
283 if (entering(tcp)) {
284 printpathn(tcp, tcp->u_arg[0], tcp->u_arg[1]);
285 tprintf(", %lu", tcp->u_arg[1]);
286 }
287 return 0;
288}
289
290int
291sys_gethostname(tcp)
292struct tcb *tcp;
293{
294 if (exiting(tcp)) {
295 if (syserror(tcp))
296 tprintf("%#lx", tcp->u_arg[0]);
297 else
298 printpath(tcp, tcp->u_arg[0]);
299 tprintf(", %lu", tcp->u_arg[1]);
300 }
301 return 0;
302}
303
304int
305sys_setdomainname(tcp)
306struct tcb *tcp;
307{
308 if (entering(tcp)) {
309 printpathn(tcp, tcp->u_arg[0], tcp->u_arg[1]);
310 tprintf(", %lu", tcp->u_arg[1]);
311 }
312 return 0;
313}
314
Wichert Akkerman5daa0281999-03-15 19:49:42 +0000315#if !defined(LINUX)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000316
317int
318sys_getdomainname(tcp)
319struct tcb *tcp;
320{
321 if (exiting(tcp)) {
322 if (syserror(tcp))
323 tprintf("%#lx", tcp->u_arg[0]);
324 else
325 printpath(tcp, tcp->u_arg[0]);
326 tprintf(", %lu", tcp->u_arg[1]);
327 }
328 return 0;
329}
330#endif /* !LINUX */
331
332int
333sys_exit(tcp)
334struct tcb *tcp;
335{
336 if (exiting(tcp)) {
337 fprintf(stderr, "_exit returned!\n");
338 return -1;
339 }
340 /* special case: we stop tracing this process, finish line now */
341 tprintf("%ld) ", tcp->u_arg[0]);
342 tabto(acolumn);
343 tprintf("= ?");
344 printtrailer(tcp);
345 return 0;
346}
347
348int
349internal_exit(tcp)
350struct tcb *tcp;
351{
352 if (entering(tcp))
353 tcp->flags |= TCB_EXITING;
354 return 0;
355}
356
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000357#ifdef USE_PROCFS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000358
359int
360sys_fork(tcp)
361struct tcb *tcp;
362{
363 if (exiting(tcp)) {
364 if (getrval2(tcp)) {
365 tcp->auxstr = "child process";
366 return RVAL_UDECIMAL | RVAL_STR;
367 }
368 }
369 return 0;
370}
371
John Hughes4e36a812001-04-18 15:11:51 +0000372#if UNIXWARE > 2
373
374int
375sys_rfork(tcp)
376struct tcb *tcp;
377{
378 if (entering(tcp)) {
379 tprintf ("%ld", tcp->u_arg[0]);
380 }
381 else {
382 if (getrval2(tcp)) {
383 tcp->auxstr = "child process";
384 return RVAL_UDECIMAL | RVAL_STR;
385 }
386 }
387 return 0;
388}
389
390#endif
391
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000392int
393internal_fork(tcp)
394struct tcb *tcp;
395{
396 struct tcb *tcpchild;
397
398 if (exiting(tcp)) {
399 if (getrval2(tcp))
400 return 0;
401 if (!followfork)
402 return 0;
403 if (nprocs == MAX_PROCS) {
404 tcp->flags &= ~TCB_FOLLOWFORK;
405 fprintf(stderr, "sys_fork: tcb table full\n");
406 return 0;
407 }
408 else
409 tcp->flags |= TCB_FOLLOWFORK;
410 if (syserror(tcp))
411 return 0;
412 if ((tcpchild = alloctcb(tcp->u_rval)) == NULL) {
413 fprintf(stderr, "sys_fork: tcb table full\n");
414 return 0;
415 }
Wichert Akkerman2e4ffe52000-09-03 23:57:48 +0000416 if (proc_open(tcpchild, 2) < 0)
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000417 droptcb(tcpchild);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000418 }
419 return 0;
420}
421
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000422#else /* !USE_PROCFS */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000423
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000424#ifdef LINUX
425
426/* defines copied from linux/sched.h since we can't include that
427 * ourselves (it conflicts with *lots* of libc includes)
428 */
429#define CSIGNAL 0x000000ff /* signal mask to be sent at exit */
430#define CLONE_VM 0x00000100 /* set if VM shared between processes */
431#define CLONE_FS 0x00000200 /* set if fs info shared between processes */
432#define CLONE_FILES 0x00000400 /* set if open files shared between processes */
433#define CLONE_SIGHAND 0x00000800 /* set if signal handlers shared */
434#define CLONE_PID 0x00001000 /* set if pid shared */
435#define CLONE_PTRACE 0x00002000 /* set if we want to let tracing continue on the child too */
436#define CLONE_VFORK 0x00004000 /* set if the parent wants the child to wake it up on mm_release */
437#define CLONE_PARENT 0x00008000 /* set if we want to have the same parent as the cloner */
438
439static struct xlat clone_flags[] = {
440 { CLONE_VM, "CLONE_VM" },
441 { CLONE_FS, "CLONE_FS" },
442 { CLONE_FILES, "CLONE_FILES" },
443 { CLONE_SIGHAND, "CLONE_SIGHAND" },
444 { CLONE_PID, "CLONE_PID" },
445 { CLONE_PTRACE, "CLONE_PTRACE" },
446 { CLONE_VFORK, "CLONE_VFORK" },
447 { CLONE_PARENT, "CLONE_PARENT" },
448 { 0, NULL },
449};
450
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000451int
452sys_clone(tcp)
453struct tcb *tcp;
454{
455 if (exiting(tcp)) {
456 tprintf("child_stack=%#lx, flags=", tcp->u_arg[1]);
457 if (printflags(clone_flags, tcp->u_arg[0]) == 0)
458 tprintf("0");
459 }
460 return 0;
461}
462
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000463int
464sys_clone2(tcp)
465struct tcb *tcp;
466{
467 if (exiting(tcp)) {
468 tprintf("child_stack=%#lx, stack_size=%#lx, flags=",
469 tcp->u_arg[1], tcp->u_arg[2]);
470 if (printflags(clone_flags, tcp->u_arg[0]) == 0)
471 tprintf("0");
472 }
473 return 0;
474}
475
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000476#endif
477
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000478int
479sys_fork(tcp)
480struct tcb *tcp;
481{
482 if (exiting(tcp))
483 return RVAL_UDECIMAL;
484 return 0;
485}
486
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000487int
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000488change_syscall(tcp, new)
489struct tcb *tcp;
490int new;
491{
492#if defined(LINUX)
493#if defined(I386)
494 /* Attempt to make vfork into fork, which we can follow. */
495 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(ORIG_EAX * 4), new) < 0)
496 return -1;
497 return 0;
498#elif defined(POWERPC)
Wichert Akkerman5c4c69b2001-04-12 09:00:47 +0000499 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(4*PT_R0), new) < 0)
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000500 return -1;
501#elif defined(S390)
502 long pc;
503 if (upeek(tcp->pid, PT_PSWADDR,&pc)<0)
504 return -1;
505 if (ptrace(PTRACE_POKETEXT, tcp->pid, (char*)(pc-4), new)<0)
506 return -1;
507 return 0;
508#elif defined(M68K)
Wichert Akkermanc7926982000-04-10 22:22:31 +0000509 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(4*PT_ORIG_D0), new)<0)
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000510 return -1;
511 return 0;
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000512#elif defined(SPARC)
Wichert Akkerman00a82ee2001-03-28 20:29:17 +0000513 struct regs regs;
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000514 if (ptrace(PTRACE_GETREGS, tcp->pid, (char*)&regs, 0)<0)
515 return -1;
Wichert Akkerman00a82ee2001-03-28 20:29:17 +0000516 regs.r_g1=new;
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000517 if (ptrace(PTRACE_SETREGS, tcp->pid, (char*)&regs, 0)<0)
518 return -1;
519 return 0;
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000520#elif defined(MIPS)
Wichert Akkermanc7926982000-04-10 22:22:31 +0000521 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(REG_V0), new)<0)
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000522 return -1;
523 return 0;
524#elif defined(ALPHA)
Wichert Akkermanc7926982000-04-10 22:22:31 +0000525 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(REG_A3), new)<0)
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000526 return -1;
527 return 0;
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000528#elif defined(IA64)
529 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(PT_R15), new)<0)
530 return -1;
531 return 0;
Wichert Akkermanc1652e22001-03-27 12:17:16 +0000532#elif defined(HPPA)
533 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(PT_GR20), new)<0)
534 return -1;
535 return 0;
Wichert Akkermanccef6372002-05-01 16:39:22 +0000536#elif defined(SH)
537 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(REG_SYSCALL), new)<0)
538 return -1;
539 return 0;
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000540#else
541#warning Do not know how to handle change_syscall for this architecture
542#endif /* architecture */
543#endif /* LINUX */
544 return -1;
545}
546
547int
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000548setarg(tcp, argnum)
549 struct tcb *tcp;
550 int argnum;
551{
552#if defined (IA64)
553 {
554 unsigned long *bsp, *ap;
555
556 if (upeek(tcp->pid, PT_AR_BSP, (long *) &bsp) , 0)
557 return -1;
558
559 ap = ia64_rse_skip_regs(bsp, argnum);
560 errno = 0;
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000561 ptrace(PTRACE_POKEDATA, tcp->pid, (char *) ap, tcp->u_arg[argnum]);
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000562 if (errno)
563 return -1;
564
565 }
Wichert Akkerman12f75d12000-02-14 16:23:40 +0000566#elif defined(I386)
567 {
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000568 ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(4*argnum), tcp->u_arg[argnum]);
Wichert Akkerman12f75d12000-02-14 16:23:40 +0000569 if (errno)
570 return -1;
571 }
Ralf Baechlee3816102000-08-01 00:06:06 +0000572#elif defined(MIPS)
573 {
574 errno = 0;
575 if (argnum < 4)
576 ptrace(PTRACE_POKEUSER, tcp->pid,
577 (char*)(REG_A0 + argnum), tcp->u_arg[argnum]);
578 else {
579 unsigned long *sp;
580
581 if (upeek(tcp->pid, REG_SP, (long *) &sp) , 0)
582 return -1;
583
584 ptrace(PTRACE_POKEDATA, tcp->pid,
585 (char*)(sp + argnum - 4), tcp->u_arg[argnum]);
586 }
587 if (errno)
588 return -1;
589 }
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000590#else
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000591# warning Sorry, setargs not implemented for this architecture.
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000592#endif
593 return 0;
594}
595
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000596#ifdef SYS_clone
597int
598internal_clone(tcp)
599struct tcb *tcp;
600{
Ulrich Drepper90512f01999-12-24 07:22:25 +0000601 struct tcb *tcpchild;
602 int pid;
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000603 if (entering(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000604 if (!followfork)
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000605 return 0;
606 if (nprocs == MAX_PROCS) {
607 tcp->flags &= ~TCB_FOLLOWFORK;
608 fprintf(stderr, "sys_fork: tcb table full\n");
609 return 0;
610 }
611 tcp->flags |= TCB_FOLLOWFORK;
612
Wichert Akkerman9b0c31d2000-09-03 21:56:29 +0000613
614 if (setbpt(tcp) < 0)
615 return 0;
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000616 } else {
Wichert Akkerman9b0c31d2000-09-03 21:56:29 +0000617 int bpt = tcp->flags & TCB_BPTSET;
618
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000619 if (!(tcp->flags & TCB_FOLLOWFORK))
620 return 0;
621
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000622 if (syserror(tcp)) {
623 if (bpt)
624 clearbpt(tcp);
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000625 return 0;
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000626 }
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000627
628 pid = tcp->u_rval;
629 if ((tcpchild = alloctcb(pid)) == NULL) {
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000630 if (bpt)
631 clearbpt(tcp);
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000632 fprintf(stderr, " [tcb table full]\n");
633 kill(pid, SIGKILL); /* XXX */
634 return 0;
635 }
636
Wichert Akkerman9b0c31d2000-09-03 21:56:29 +0000637 /* Attach to the new child */
638 if (ptrace(PTRACE_ATTACH, pid, (char *) 1, 0) < 0) {
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000639 if (bpt)
640 clearbpt(tcp);
Wichert Akkerman9b0c31d2000-09-03 21:56:29 +0000641 perror("PTRACE_ATTACH");
642 fprintf(stderr, "Too late?\n");
643 droptcb(tcpchild);
644 return 0;
645 }
646
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000647 if (bpt)
648 clearbpt(tcp);
649
Ulrich Drepper90512f01999-12-24 07:22:25 +0000650 tcpchild->flags |= TCB_ATTACHED;
Wichert Akkerman9b0c31d2000-09-03 21:56:29 +0000651 if (bpt) {
652 tcpchild->flags |= TCB_BPTSET;
653 tcpchild->baddr = tcp->baddr;
654 memcpy(tcpchild->inst, tcp->inst,
655 sizeof tcpchild->inst);
656 }
Ulrich Drepper90512f01999-12-24 07:22:25 +0000657 newoutf(tcpchild);
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000658 tcpchild->parent = tcp;
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000659 tcp->nchildren++;
660 if (!qflag)
661 fprintf(stderr, "Process %d attached\n", pid);
662 }
663 return 0;
664}
665#endif
666
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000667int
668internal_fork(tcp)
669struct tcb *tcp;
670{
671 struct tcb *tcpchild;
672 int pid;
Nate Sammonsccd8f211999-03-29 22:57:54 +0000673 int dont_follow = 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000674
675#ifdef SYS_vfork
Nate Sammonsccd8f211999-03-29 22:57:54 +0000676 if (tcp->scno == SYS_vfork) {
Nate Sammonsccd8f211999-03-29 22:57:54 +0000677 /* Attempt to make vfork into fork, which we can follow. */
678 if (!followvfork ||
Pavel Machek9a9f10b2000-02-01 16:22:52 +0000679 change_syscall(tcp, SYS_fork) < 0)
Nate Sammonsccd8f211999-03-29 22:57:54 +0000680 dont_follow = 1;
Nate Sammonsccd8f211999-03-29 22:57:54 +0000681 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000682#endif
683 if (entering(tcp)) {
Nate Sammonsccd8f211999-03-29 22:57:54 +0000684 if (!followfork || dont_follow)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000685 return 0;
686 if (nprocs == MAX_PROCS) {
687 tcp->flags &= ~TCB_FOLLOWFORK;
688 fprintf(stderr, "sys_fork: tcb table full\n");
689 return 0;
690 }
691 tcp->flags |= TCB_FOLLOWFORK;
692 if (setbpt(tcp) < 0)
693 return 0;
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000694 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000695 else {
696 int bpt = tcp->flags & TCB_BPTSET;
697
698 if (!(tcp->flags & TCB_FOLLOWFORK))
699 return 0;
700 if (bpt)
701 clearbpt(tcp);
702
703 if (syserror(tcp))
704 return 0;
705
706 pid = tcp->u_rval;
707 if ((tcpchild = alloctcb(pid)) == NULL) {
708 fprintf(stderr, " [tcb table full]\n");
709 kill(pid, SIGKILL); /* XXX */
710 return 0;
711 }
712#ifdef LINUX
Wichert Akkermanc1652e22001-03-27 12:17:16 +0000713#ifdef HPPA
714 /* The child must have run before it can be attached. */
715 /* This must be a bug in the parisc kernel, but I havn't
716 * identified it yet. Seems to be an issue associated
717 * with attaching to a process (which sends it a signal)
718 * before that process has ever been scheduled. When
719 * debugging, I started seeing crashes in
720 * arch/parisc/kernel/signal.c:do_signal(), apparently
721 * caused by r8 getting corrupt over the dequeue_signal()
722 * call. Didn't make much sense though...
723 */
724 {
725 struct timeval tv;
726 tv.tv_sec = 0;
727 tv.tv_usec = 10000;
728 select(0, NULL, NULL, NULL, &tv);
729 }
730#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000731 if (ptrace(PTRACE_ATTACH, pid, (char *) 1, 0) < 0) {
732 perror("PTRACE_ATTACH");
733 fprintf(stderr, "Too late?\n");
734 droptcb(tcpchild);
735 return 0;
736 }
737#endif /* LINUX */
738#ifdef SUNOS4
739#ifdef oldway
740 /* The child must have run before it can be attached. */
741 {
742 struct timeval tv;
743 tv.tv_sec = 0;
744 tv.tv_usec = 10000;
745 select(0, NULL, NULL, NULL, &tv);
746 }
747 if (ptrace(PTRACE_ATTACH, pid, (char *)1, 0) < 0) {
748 perror("PTRACE_ATTACH");
749 fprintf(stderr, "Too late?\n");
750 droptcb(tcpchild);
751 return 0;
752 }
753#else /* !oldway */
754 /* Try to catch the new process as soon as possible. */
755 {
756 int i;
757 for (i = 0; i < 1024; i++)
758 if (ptrace(PTRACE_ATTACH, pid, (char *) 1, 0) >= 0)
759 break;
760 if (i == 1024) {
761 perror("PTRACE_ATTACH");
762 fprintf(stderr, "Too late?\n");
763 droptcb(tcpchild);
764 return 0;
765 }
766 }
767#endif /* !oldway */
768#endif /* SUNOS4 */
769 tcpchild->flags |= TCB_ATTACHED;
770 /* Child has BPT too, must be removed on first occasion */
771 if (bpt) {
772 tcpchild->flags |= TCB_BPTSET;
773 tcpchild->baddr = tcp->baddr;
774 memcpy(tcpchild->inst, tcp->inst,
775 sizeof tcpchild->inst);
776 }
777 newoutf(tcpchild);
778 tcpchild->parent = tcp;
779 tcp->nchildren++;
780 if (!qflag)
781 fprintf(stderr, "Process %d attached\n", pid);
782 }
783 return 0;
784}
785
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000786#endif /* !USE_PROCFS */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000787
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000788#if defined(SUNOS4) || defined(LINUX) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000789
790int
791sys_vfork(tcp)
792struct tcb *tcp;
793{
794 if (exiting(tcp))
795 return RVAL_UDECIMAL;
796 return 0;
797}
798
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000799#endif /* SUNOS4 || LINUX || FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000800
801#ifndef LINUX
802
803static char idstr[16];
804
805int
806sys_getpid(tcp)
807struct tcb *tcp;
808{
809 if (exiting(tcp)) {
810 sprintf(idstr, "ppid %lu", getrval2(tcp));
811 tcp->auxstr = idstr;
812 return RVAL_STR;
813 }
814 return 0;
815}
816
817int
818sys_getuid(tcp)
819struct tcb *tcp;
820{
821 if (exiting(tcp)) {
822 sprintf(idstr, "euid %lu", getrval2(tcp));
823 tcp->auxstr = idstr;
824 return RVAL_STR;
825 }
826 return 0;
827}
828
829int
830sys_getgid(tcp)
831struct tcb *tcp;
832{
833 if (exiting(tcp)) {
834 sprintf(idstr, "egid %lu", getrval2(tcp));
835 tcp->auxstr = idstr;
836 return RVAL_STR;
837 }
838 return 0;
839}
840
841#endif /* !LINUX */
842
843#ifdef LINUX
844
845int
846sys_setuid(tcp)
847struct tcb *tcp;
848{
849 if (entering(tcp)) {
850 tprintf("%u", (uid_t) tcp->u_arg[0]);
851 }
852 return 0;
853}
854
855int
856sys_setgid(tcp)
857struct tcb *tcp;
858{
859 if (entering(tcp)) {
860 tprintf("%u", (gid_t) tcp->u_arg[0]);
861 }
862 return 0;
863}
864
865int
866sys_getresuid(tcp)
867 struct tcb *tcp;
868{
869 if (exiting(tcp)) {
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000870 __kernel_uid_t uid;
871 if (syserror(tcp))
872 tprintf("%#lx, %#lx, %#lx", tcp->u_arg[0],
873 tcp->u_arg[1], tcp->u_arg[2]);
874 else {
875 if (umove(tcp, tcp->u_arg[0], &uid) < 0)
876 tprintf("%#lx, ", tcp->u_arg[0]);
877 else
878 tprintf("ruid %lu, ", (unsigned long) uid);
879 if (umove(tcp, tcp->u_arg[0], &uid) < 0)
880 tprintf("%#lx, ", tcp->u_arg[0]);
881 else
882 tprintf("euid %lu, ", (unsigned long) uid);
883 if (umove(tcp, tcp->u_arg[0], &uid) < 0)
884 tprintf("%#lx", tcp->u_arg[0]);
885 else
886 tprintf("suid %lu", (unsigned long) uid);
887 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000888 }
889 return 0;
890}
891
892int
893sys_getresgid(tcp)
894struct tcb *tcp;
895{
896 if (exiting(tcp)) {
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000897 __kernel_gid_t gid;
898 if (syserror(tcp))
899 tprintf("%#lx, %#lx, %#lx", tcp->u_arg[0],
900 tcp->u_arg[1], tcp->u_arg[2]);
901 else {
902 if (umove(tcp, tcp->u_arg[0], &gid) < 0)
903 tprintf("%#lx, ", tcp->u_arg[0]);
904 else
905 tprintf("rgid %lu, ", (unsigned long) gid);
906 if (umove(tcp, tcp->u_arg[0], &gid) < 0)
907 tprintf("%#lx, ", tcp->u_arg[0]);
908 else
909 tprintf("egid %lu, ", (unsigned long) gid);
910 if (umove(tcp, tcp->u_arg[0], &gid) < 0)
911 tprintf("%#lx", tcp->u_arg[0]);
912 else
913 tprintf("sgid %lu", (unsigned long) gid);
914 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000915 }
916 return 0;
917}
918
919#endif /* LINUX */
920
921int
922sys_setreuid(tcp)
923struct tcb *tcp;
924{
925 if (entering(tcp)) {
926 tprintf("%lu, %lu",
927 (unsigned long) (uid_t) tcp->u_arg[0],
928 (unsigned long) (uid_t) tcp->u_arg[1]);
929 }
930 return 0;
931}
932
933int
934sys_setregid(tcp)
935struct tcb *tcp;
936{
937 if (entering(tcp)) {
938 tprintf("%lu, %lu",
939 (unsigned long) (gid_t) tcp->u_arg[0],
940 (unsigned long) (gid_t) tcp->u_arg[1]);
941 }
942 return 0;
943}
944
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000945#if defined(LINUX) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000946int
947sys_setresuid(tcp)
948 struct tcb *tcp;
949{
950 if (entering(tcp)) {
951 tprintf("ruid %u, euid %u, suid %u",
952 (uid_t) tcp->u_arg[0],
953 (uid_t) tcp->u_arg[1],
954 (uid_t) tcp->u_arg[2]);
955 }
956 return 0;
957}
958int
959sys_setresgid(tcp)
960 struct tcb *tcp;
961{
962 if (entering(tcp)) {
963 tprintf("rgid %u, egid %u, sgid %u",
964 (uid_t) tcp->u_arg[0],
965 (uid_t) tcp->u_arg[1],
966 (uid_t) tcp->u_arg[2]);
967 }
968 return 0;
969}
970
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000971#endif /* LINUX || FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000972
973int
974sys_setgroups(tcp)
975struct tcb *tcp;
976{
977 int i, len;
978 GETGROUPS_T *gidset;
979
980 if (entering(tcp)) {
981 len = tcp->u_arg[0];
982 tprintf("%u, ", len);
983 if (len <= 0) {
984 tprintf("[]");
985 return 0;
986 }
987 gidset = (GETGROUPS_T *) malloc(len * sizeof(GETGROUPS_T));
988 if (gidset == NULL) {
989 fprintf(stderr, "sys_setgroups: out of memory\n");
990 return -1;
991 }
992 if (!verbose(tcp))
993 tprintf("%#lx", tcp->u_arg[1]);
994 else if (umoven(tcp, tcp->u_arg[1],
995 len * sizeof(GETGROUPS_T), (char *) gidset) < 0)
996 tprintf("[?]");
997 else {
998 tprintf("[");
999 for (i = 0; i < len; i++)
1000 tprintf("%s%lu", i ? ", " : "",
1001 (unsigned long) gidset[i]);
1002 tprintf("]");
1003 }
1004 free((char *) gidset);
1005 }
1006 return 0;
1007}
1008
1009int
1010sys_getgroups(tcp)
1011struct tcb *tcp;
1012{
1013 int i, len;
1014 GETGROUPS_T *gidset;
1015
1016 if (entering(tcp)) {
1017 len = tcp->u_arg[0];
1018 tprintf("%u, ", len);
1019 } else {
1020 len = tcp->u_rval;
1021 if (len <= 0) {
1022 tprintf("[]");
1023 return 0;
1024 }
1025 gidset = (GETGROUPS_T *) malloc(len * sizeof(GETGROUPS_T));
1026 if (gidset == NULL) {
1027 fprintf(stderr, "sys_getgroups: out of memory\n");
1028 return -1;
1029 }
1030 if (!tcp->u_arg[1])
1031 tprintf("NULL");
1032 else if (!verbose(tcp) || tcp->u_arg[0] == 0)
1033 tprintf("%#lx", tcp->u_arg[1]);
1034 else if (umoven(tcp, tcp->u_arg[1],
1035 len * sizeof(GETGROUPS_T), (char *) gidset) < 0)
1036 tprintf("[?]");
1037 else {
1038 tprintf("[");
1039 for (i = 0; i < len; i++)
1040 tprintf("%s%lu", i ? ", " : "",
1041 (unsigned long) gidset[i]);
1042 tprintf("]");
1043 }
1044 free((char *)gidset);
1045 }
1046 return 0;
1047}
1048
1049int
1050sys_setpgrp(tcp)
1051struct tcb *tcp;
1052{
1053 if (entering(tcp)) {
1054#ifndef SVR4
1055 tprintf("%lu, %lu", tcp->u_arg[0], tcp->u_arg[1]);
1056#endif /* !SVR4 */
1057 }
1058 return 0;
1059}
1060
1061int
1062sys_getpgrp(tcp)
1063struct tcb *tcp;
1064{
1065 if (entering(tcp)) {
1066#ifndef SVR4
1067 tprintf("%lu", tcp->u_arg[0]);
1068#endif /* !SVR4 */
1069 }
1070 return 0;
1071}
1072
1073int
1074sys_getsid(tcp)
1075struct tcb *tcp;
1076{
1077 if (entering(tcp)) {
1078 tprintf("%lu", tcp->u_arg[0]);
1079 }
1080 return 0;
1081}
1082
1083int
1084sys_setsid(tcp)
1085struct tcb *tcp;
1086{
1087 return 0;
1088}
1089
1090int
1091sys_getpgid(tcp)
1092struct tcb *tcp;
1093{
1094 if (entering(tcp)) {
1095 tprintf("%lu", tcp->u_arg[0]);
1096 }
1097 return 0;
1098}
1099
1100int
1101sys_setpgid(tcp)
1102struct tcb *tcp;
1103{
1104 if (entering(tcp)) {
1105 tprintf("%lu, %lu", tcp->u_arg[0], tcp->u_arg[1]);
1106 }
1107 return 0;
1108}
1109
John Hughesc61eb3d2002-05-17 11:37:50 +00001110#if UNIXWARE >= 2
1111
1112#include <sys/privilege.h>
1113
1114
1115static struct xlat procpriv_cmds [] = {
1116 { SETPRV, "SETPRV" },
1117 { CLRPRV, "CLRPRV" },
1118 { PUTPRV, "PUTPRV" },
1119 { GETPRV, "GETPRV" },
1120 { CNTPRV, "CNTPRV" },
1121 { 0, NULL },
1122};
1123
1124
1125static struct xlat procpriv_priv [] = {
1126 { P_OWNER, "P_OWNER" },
1127 { P_AUDIT, "P_AUDIT" },
1128 { P_COMPAT, "P_COMPAT" },
1129 { P_DACREAD, "P_DACREAD" },
1130 { P_DACWRITE, "P_DACWRITE" },
1131 { P_DEV, "P_DEV" },
1132 { P_FILESYS, "P_FILESYS" },
1133 { P_MACREAD, "P_MACREAD" },
1134 { P_MACWRITE, "P_MACWRITE" },
1135 { P_MOUNT, "P_MOUNT" },
1136 { P_MULTIDIR, "P_MULTIDIR" },
1137 { P_SETPLEVEL, "P_SETPLEVEL" },
1138 { P_SETSPRIV, "P_SETSPRIV" },
1139 { P_SETUID, "P_SETUID" },
1140 { P_SYSOPS, "P_SYSOPS" },
1141 { P_SETUPRIV, "P_SETUPRIV" },
1142 { P_DRIVER, "P_DRIVER" },
1143 { P_RTIME, "P_RTIME" },
1144 { P_MACUPGRADE, "P_MACUPGRADE" },
1145 { P_FSYSRANGE, "P_FSYSRANGE" },
1146 { P_SETFLEVEL, "P_SETFLEVEL" },
1147 { P_AUDITWR, "P_AUDITWR" },
1148 { P_TSHAR, "P_TSHAR" },
1149 { P_PLOCK, "P_PLOCK" },
1150 { P_CORE, "P_CORE" },
1151 { P_LOADMOD, "P_LOADMOD" },
1152 { P_BIND, "P_BIND" },
1153 { P_ALLPRIVS, "P_ALLPRIVS" },
1154 { 0, NULL },
1155};
1156
1157
1158static struct xlat procpriv_type [] = {
1159 { PS_FIX, "PS_FIX" },
1160 { PS_INH, "PS_INH" },
1161 { PS_MAX, "PS_MAX" },
1162 { PS_WKG, "PS_WKG" },
1163 { 0, NULL },
1164};
1165
1166
1167static void
1168printpriv(tcp, addr, len, opt)
1169struct tcb *tcp;
1170long addr;
1171int len;
1172struct xlat *opt;
1173{
1174 priv_t buf [128];
1175 int max = verbose (tcp) ? sizeof buf / sizeof buf [0] : 10;
1176 int dots = len > max;
1177 int i;
1178
1179 if (len > max) len = max;
1180
1181 if (len <= 0 ||
1182 umoven (tcp, addr, len * sizeof buf[0], (char *) buf) < 0)
1183 {
1184 tprintf ("%#lx", addr);
1185 return;
1186 }
1187
1188 tprintf ("[");
1189
1190 for (i = 0; i < len; ++i) {
1191 char *t, *p;
1192
1193 if (i) tprintf (", ");
1194
1195 if ((t = xlookup (procpriv_type, buf [i] & PS_TYPE)) &&
1196 (p = xlookup (procpriv_priv, buf [i] & ~PS_TYPE)))
1197 {
1198 tprintf ("%s|%s", t, p);
1199 }
1200 else {
1201 tprintf ("%#lx", buf [i]);
1202 }
1203 }
1204
1205 if (dots) tprintf (" ...");
1206
1207 tprintf ("]");
1208}
1209
1210
1211int
1212sys_procpriv(tcp)
1213struct tcb *tcp;
1214{
1215 if (entering(tcp)) {
1216 printxval(procpriv_cmds, tcp->u_arg[0], "???PRV");
1217 switch (tcp->u_arg[0]) {
1218 case CNTPRV:
1219 tprintf(", %#lx, %ld", tcp->u_arg[1], tcp->u_arg[2]);
1220 break;
1221
1222 case GETPRV:
1223 break;
1224
1225 default:
1226 tprintf (", ");
1227 printpriv (tcp, tcp->u_arg[1], tcp->u_arg[2]);
1228 tprintf (", %ld", tcp->u_arg[2]);
1229 }
1230 }
1231 else if (tcp->u_arg[0] == GETPRV) {
1232 if (syserror (tcp)) {
1233 tprintf(", %#lx, %ld", tcp->u_arg[1], tcp->u_arg[2]);
1234 }
1235 else {
1236 tprintf (", ");
1237 printpriv (tcp, tcp->u_arg[1], tcp->u_rval);
1238 tprintf (", %ld", tcp->u_arg[2]);
1239 }
1240 }
1241
1242 return 0;
1243}
1244
1245#endif
1246
1247
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001248void
1249fake_execve(tcp, program, argv, envp)
1250struct tcb *tcp;
1251char *program;
1252char *argv[];
1253char *envp[];
1254{
1255 int i;
1256
1257#ifdef ARM
1258 if (!(qual_flags[SYS_execve - __NR_SYSCALL_BASE] & QUAL_TRACE))
1259 return;
1260#else
1261 if (!(qual_flags[SYS_execve] & QUAL_TRACE))
1262 return;
1263#endif /* !ARM */
1264 printleader(tcp);
1265 tprintf("execve(");
1266 string_quote(program);
1267 tprintf(", [");
1268 for (i = 0; argv[i] != NULL; i++) {
1269 if (i != 0)
1270 tprintf(", ");
1271 string_quote(argv[i]);
1272 }
1273 for (i = 0; envp[i] != NULL; i++)
1274 ;
1275 tprintf("], [/* %d var%s */]) ", i, (i != 1) ? "s" : "");
1276 tabto(acolumn);
1277 tprintf("= 0");
1278 printtrailer(tcp);
1279}
1280
1281static void
1282printargv(tcp, addr)
1283struct tcb *tcp;
1284long addr;
1285{
1286 char *cp;
1287 char *sep;
1288 int max = max_strlen / 2;
1289
1290 for (sep = ""; --max >= 0; sep = ", ") {
1291 if (!abbrev(tcp))
1292 max++;
1293 if (umove(tcp, addr, &cp) < 0) {
1294 tprintf("%#lx", addr);
1295 return;
1296 }
1297 if (cp == 0)
1298 break;
1299 tprintf(sep);
1300 printstr(tcp, (long) cp, -1);
1301 addr += sizeof(char *);
1302 }
1303 if (cp)
1304 tprintf(", ...");
1305}
1306
1307static void
1308printargc(fmt, tcp, addr)
1309char *fmt;
1310struct tcb *tcp;
1311long addr;
1312{
1313 int count;
1314 char *cp;
1315
1316 for (count = 0; umove(tcp, addr, &cp) >= 0 && cp != NULL; count++) {
1317 addr += sizeof(char *);
1318 }
1319 tprintf(fmt, count, count == 1 ? "" : "s");
1320}
1321
1322int
1323sys_execv(tcp)
1324struct tcb *tcp;
1325{
1326 if (entering(tcp)) {
1327 printpath(tcp, tcp->u_arg[0]);
1328 if (!verbose(tcp))
1329 tprintf(", %#lx", tcp->u_arg[1]);
1330#if 0
1331 else if (abbrev(tcp))
1332 printargc(", [/* %d arg%s */]", tcp, tcp->u_arg[1]);
1333#endif
1334 else {
1335 tprintf(", [");
1336 printargv(tcp, tcp->u_arg[1]);
1337 tprintf("]");
1338 }
1339 }
1340 return 0;
1341}
1342
1343int
1344sys_execve(tcp)
1345struct tcb *tcp;
1346{
1347 if (entering(tcp)) {
1348 printpath(tcp, tcp->u_arg[0]);
1349 if (!verbose(tcp))
1350 tprintf(", %#lx", tcp->u_arg[1]);
1351#if 0
1352 else if (abbrev(tcp))
1353 printargc(", [/* %d arg%s */]", tcp, tcp->u_arg[1]);
1354#endif
1355 else {
1356 tprintf(", [");
1357 printargv(tcp, tcp->u_arg[1]);
1358 tprintf("]");
1359 }
1360 if (!verbose(tcp))
1361 tprintf(", %#lx", tcp->u_arg[2]);
1362 else if (abbrev(tcp))
1363 printargc(", [/* %d var%s */]", tcp, tcp->u_arg[2]);
1364 else {
1365 tprintf(", [");
1366 printargv(tcp, tcp->u_arg[2]);
1367 tprintf("]");
1368 }
1369 }
1370#ifdef LINUX
Wichert Akkermanccef6372002-05-01 16:39:22 +00001371#if defined(ALPHA) || defined(SPARC) || defined(POWERPC) || defined(IA64) || defined(HPPA) || defined(SH)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001372 tcp->flags |= TCB_WAITEXECVE;
Wichert Akkermanccef6372002-05-01 16:39:22 +00001373#endif /* ALPHA || SPARC || POWERPC || IA64 || HPPA || SH */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001374#endif /* LINUX */
1375 return 0;
1376}
1377
John Hughes4e36a812001-04-18 15:11:51 +00001378#if UNIXWARE > 2
1379
1380int sys_rexecve(tcp)
1381struct tcb *tcp;
1382{
1383 if (entering (tcp)) {
1384 sys_execve (tcp);
1385 tprintf (", %ld", tcp->u_arg[3]);
1386 }
1387 return 0;
1388}
1389
1390#endif
1391
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001392int
1393internal_exec(tcp)
1394struct tcb *tcp;
1395{
1396#ifdef SUNOS4
1397 if (exiting(tcp) && !syserror(tcp) && followfork)
1398 fixvfork(tcp);
1399#endif /* SUNOS4 */
1400 return 0;
1401}
1402
1403#ifdef LINUX
1404#ifndef __WCLONE
1405#define __WCLONE 0x8000000
1406#endif
1407#endif /* LINUX */
1408
1409static struct xlat wait4_options[] = {
1410 { WNOHANG, "WNOHANG" },
1411#ifndef WSTOPPED
1412 { WUNTRACED, "WUNTRACED" },
1413#endif
1414#ifdef WEXITED
1415 { WEXITED, "WEXITED" },
1416#endif
1417#ifdef WTRAPPED
1418 { WTRAPPED, "WTRAPPED" },
1419#endif
1420#ifdef WSTOPPED
1421 { WSTOPPED, "WSTOPPED" },
1422#endif
1423#ifdef WCONTINUED
1424 { WCONTINUED, "WCONTINUED" },
1425#endif
1426#ifdef WNOWAIT
1427 { WNOWAIT, "WNOWAIT" },
1428#endif
1429#ifdef __WCLONE
1430 { __WCLONE, "__WCLONE" },
1431#endif
1432 { 0, NULL },
1433};
1434
1435static int
1436printstatus(status)
1437int status;
1438{
1439 int exited = 0;
1440
1441 /*
1442 * Here is a tricky presentation problem. This solution
1443 * is still not entirely satisfactory but since there
1444 * are no wait status constructors it will have to do.
1445 */
1446 if (WIFSTOPPED(status))
1447 tprintf("[WIFSTOPPED(s) && WSTOPSIG(s) == %s]",
Nate Sammonsce780fc1999-03-29 23:23:13 +00001448 signame(WSTOPSIG(status)));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001449 else if WIFSIGNALED(status)
1450 tprintf("[WIFSIGNALED(s) && WTERMSIG(s) == %s%s]",
Nate Sammonsce780fc1999-03-29 23:23:13 +00001451 signame(WTERMSIG(status)),
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001452 WCOREDUMP(status) ? " && WCOREDUMP(s)" : "");
1453 else if WIFEXITED(status) {
1454 tprintf("[WIFEXITED(s) && WEXITSTATUS(s) == %d]",
1455 WEXITSTATUS(status));
1456 exited = 1;
1457 }
1458 else
1459 tprintf("[%#x]", status);
1460 return exited;
1461}
1462
1463static int
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001464printwaitn(tcp, n, bitness)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001465struct tcb *tcp;
1466int n;
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001467int bitness;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001468{
1469 int status;
1470 int exited = 0;
1471
1472 if (entering(tcp)) {
1473 tprintf("%ld, ", tcp->u_arg[0]);
1474 } else {
1475 /* status */
1476 if (!tcp->u_arg[1])
1477 tprintf("NULL");
1478 else if (syserror(tcp) || tcp->u_rval == 0)
1479 tprintf("%#lx", tcp->u_arg[1]);
1480 else if (umove(tcp, tcp->u_arg[1], &status) < 0)
1481 tprintf("[?]");
1482 else
1483 exited = printstatus(status);
1484 /* options */
1485 tprintf(", ");
1486 if (!printflags(wait4_options, tcp->u_arg[2]))
1487 tprintf("0");
1488 if (n == 4) {
1489 tprintf(", ");
1490 /* usage */
1491 if (!tcp->u_arg[3])
1492 tprintf("NULL");
1493#ifdef LINUX
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001494 else if (tcp->u_rval > 0) {
1495#ifdef LINUX_64BIT
1496 if (bitness)
1497 printrusage32(tcp, tcp->u_arg[3]);
1498 else
1499#endif
1500 printrusage(tcp, tcp->u_arg[3]);
1501 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001502#endif /* LINUX */
1503#ifdef SUNOS4
1504 else if (tcp->u_rval > 0 && exited)
1505 printrusage(tcp, tcp->u_arg[3]);
1506#endif /* SUNOS4 */
1507 else
1508 tprintf("%#lx", tcp->u_arg[3]);
1509 }
1510 }
1511 return 0;
1512}
1513
1514int
1515internal_wait(tcp)
1516struct tcb *tcp;
1517{
1518 if (entering(tcp)) {
Wichert Akkerman5daa0281999-03-15 19:49:42 +00001519 /* WTA: fix bug with hanging children */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001520 if (!(tcp->u_arg[2] & WNOHANG) && tcp->nchildren > 0) {
1521 /* There are traced children */
1522 tcp->flags |= TCB_SUSPENDED;
1523 tcp->waitpid = tcp->u_arg[0];
1524 }
1525 }
1526 return 0;
1527}
1528
1529#ifdef SVR4
1530
1531int
1532sys_wait(tcp)
1533struct tcb *tcp;
1534{
1535 if (exiting(tcp)) {
1536 /* The library wrapper stuffs this into the user variable. */
1537 if (!syserror(tcp))
1538 printstatus(getrval2(tcp));
1539 }
1540 return 0;
1541}
1542
1543#endif /* SVR4 */
1544
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001545#ifdef FREEBSD
1546int
1547sys_wait(tcp)
1548struct tcb *tcp;
1549{
1550 int status;
1551
1552 if (exiting(tcp)) {
1553 if (!syserror(tcp)) {
1554 if (umove(tcp, tcp->u_arg[0], &status) < 0)
1555 tprintf("%#lx", tcp->u_arg[0]);
1556 else
1557 printstatus(status);
1558 }
1559 }
1560 return 0;
1561}
1562#endif
1563
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001564int
1565sys_waitpid(tcp)
1566struct tcb *tcp;
1567{
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001568 return printwaitn(tcp, 3, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001569}
1570
1571int
1572sys_wait4(tcp)
1573struct tcb *tcp;
1574{
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001575 return printwaitn(tcp, 4, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001576}
1577
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001578#ifdef ALPHA
1579int
1580sys_osf_wait4(tcp)
1581struct tcb *tcp;
1582{
1583 return printwaitn(tcp, 4, 1);
1584}
1585#endif
1586
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001587#ifdef SVR4
1588
1589static struct xlat waitid_types[] = {
1590 { P_PID, "P_PID" },
1591 { P_PPID, "P_PPID" },
1592 { P_PGID, "P_PGID" },
1593 { P_SID, "P_SID" },
1594 { P_CID, "P_CID" },
1595 { P_UID, "P_UID" },
1596 { P_GID, "P_GID" },
1597 { P_ALL, "P_ALL" },
1598#ifdef P_LWPID
1599 { P_LWPID, "P_LWPID" },
1600#endif
1601 { 0, NULL },
1602};
1603
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001604int
1605sys_waitid(tcp)
1606struct tcb *tcp;
1607{
1608 siginfo_t si;
1609 int exited;
1610
1611 if (entering(tcp)) {
1612 printxval(waitid_types, tcp->u_arg[0], "P_???");
1613 tprintf(", %ld, ", tcp->u_arg[1]);
1614 if (tcp->nchildren > 0) {
1615 /* There are traced children */
1616 tcp->flags |= TCB_SUSPENDED;
1617 tcp->waitpid = tcp->u_arg[0];
1618 }
1619 }
1620 else {
1621 /* siginfo */
1622 exited = 0;
1623 if (!tcp->u_arg[2])
1624 tprintf("NULL");
1625 else if (syserror(tcp))
1626 tprintf("%#lx", tcp->u_arg[2]);
1627 else if (umove(tcp, tcp->u_arg[2], &si) < 0)
1628 tprintf("{???}");
1629 else
John Hughes58265892001-10-18 15:13:53 +00001630 printsiginfo(&si, verbose (tcp));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001631 /* options */
1632 tprintf(", ");
1633 if (!printflags(wait4_options, tcp->u_arg[3]))
1634 tprintf("0");
1635 }
1636 return 0;
1637}
1638
1639#endif /* SVR4 */
1640
1641int
1642sys_alarm(tcp)
1643struct tcb *tcp;
1644{
1645 if (entering(tcp))
1646 tprintf("%lu", tcp->u_arg[0]);
1647 return 0;
1648}
1649
1650int
1651sys_uname(tcp)
1652struct tcb *tcp;
1653{
1654 struct utsname uname;
1655
1656 if (exiting(tcp)) {
1657 if (syserror(tcp) || !verbose(tcp))
1658 tprintf("%#lx", tcp->u_arg[0]);
1659 else if (umove(tcp, tcp->u_arg[0], &uname) < 0)
1660 tprintf("{...}");
1661 else if (!abbrev(tcp)) {
1662
1663 tprintf("{sysname=\"%s\", nodename=\"%s\", ",
1664 uname.sysname, uname.nodename);
1665 tprintf("release=\"%s\", version=\"%s\", ",
1666 uname.release, uname.version);
1667 tprintf("machine=\"%s\"", uname.machine);
1668#ifdef LINUX
1669#ifndef __GLIBC__
1670 tprintf(", domainname=\"%s\"", uname.domainname);
1671#endif /* __GLIBC__ */
1672#endif /* LINUX */
1673 tprintf("}");
1674 }
1675 else
1676 tprintf("{sys=\"%s\", node=\"%s\", ...}",
1677 uname.sysname, uname.nodename);
1678 }
1679 return 0;
1680}
1681
1682#ifndef SVR4
1683
1684static struct xlat ptrace_cmds[] = {
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001685#ifndef FREEBSD
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001686 { PTRACE_TRACEME, "PTRACE_TRACEME" },
1687 { PTRACE_PEEKTEXT, "PTRACE_PEEKTEXT", },
1688 { PTRACE_PEEKDATA, "PTRACE_PEEKDATA", },
1689 { PTRACE_PEEKUSER, "PTRACE_PEEKUSER", },
1690 { PTRACE_POKETEXT, "PTRACE_POKETEXT", },
1691 { PTRACE_POKEDATA, "PTRACE_POKEDATA", },
1692 { PTRACE_POKEUSER, "PTRACE_POKEUSER", },
1693 { PTRACE_CONT, "PTRACE_CONT" },
1694 { PTRACE_KILL, "PTRACE_KILL" },
1695 { PTRACE_SINGLESTEP, "PTRACE_SINGLESTEP" },
1696 { PTRACE_ATTACH, "PTRACE_ATTACH" },
1697 { PTRACE_DETACH, "PTRACE_DETACH" },
1698#ifdef SUNOS4
1699 { PTRACE_GETREGS, "PTRACE_GETREGS" },
1700 { PTRACE_SETREGS, "PTRACE_SETREGS" },
1701 { PTRACE_GETFPREGS, "PTRACE_GETFPREGS", },
1702 { PTRACE_SETFPREGS, "PTRACE_SETFPREGS", },
1703 { PTRACE_READDATA, "PTRACE_READDATA" },
1704 { PTRACE_WRITEDATA, "PTRACE_WRITEDATA" },
1705 { PTRACE_READTEXT, "PTRACE_READTEXT" },
1706 { PTRACE_WRITETEXT, "PTRACE_WRITETEXT" },
1707 { PTRACE_GETFPAREGS, "PTRACE_GETFPAREGS" },
1708 { PTRACE_SETFPAREGS, "PTRACE_SETFPAREGS" },
1709#ifdef SPARC
1710 { PTRACE_GETWINDOW, "PTRACE_GETWINDOW" },
1711 { PTRACE_SETWINDOW, "PTRACE_SETWINDOW" },
1712#else /* !SPARC */
1713 { PTRACE_22, "PTRACE_PTRACE_22" },
1714 { PTRACE_23, "PTRACE_PTRACE_23" },
1715#endif /* !SPARC */
1716#endif /* SUNOS4 */
1717 { PTRACE_SYSCALL, "PTRACE_SYSCALL" },
1718#ifdef SUNOS4
1719 { PTRACE_DUMPCORE, "PTRACE_DUMPCORE" },
1720#ifdef I386
1721 { PTRACE_SETWRBKPT, "PTRACE_SETWRBKPT" },
1722 { PTRACE_SETACBKPT, "PTRACE_SETACBKPT" },
1723 { PTRACE_CLRDR7, "PTRACE_CLRDR7" },
1724#else /* !I386 */
1725 { PTRACE_26, "PTRACE_26" },
1726 { PTRACE_27, "PTRACE_27" },
1727 { PTRACE_28, "PTRACE_28" },
1728#endif /* !I386 */
1729 { PTRACE_GETUCODE, "PTRACE_GETUCODE" },
1730#endif /* SUNOS4 */
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001731#else /* FREEBSD */
1732 { PT_TRACE_ME, "PT_TRACE_ME" },
1733 { PT_READ_I, "PT_READ_I" },
1734 { PT_READ_D, "PT_READ_D" },
1735 { PT_WRITE_I, "PT_WRITE_I" },
1736 { PT_WRITE_D, "PT_WRITE_D" },
John Hughesa2278142001-09-28 16:21:30 +00001737#ifdef PT_READ_U
1738 { PT_READ_U, "PT_READ_U" },
1739#endif
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001740 { PT_CONTINUE, "PT_CONTINUE" },
1741 { PT_KILL, "PT_KILL" },
1742 { PT_STEP, "PT_STEP" },
1743 { PT_ATTACH, "PT_ATTACH" },
1744 { PT_DETACH, "PT_DETACH" },
1745 { PT_GETREGS, "PT_GETREGS" },
1746 { PT_SETREGS, "PT_SETREGS" },
1747 { PT_GETFPREGS, "PT_GETFPREGS" },
1748 { PT_SETFPREGS, "PT_SETFPREGS" },
1749 { PT_GETDBREGS, "PT_GETDBREGS" },
1750 { PT_SETDBREGS, "PT_SETDBREGS" },
1751#endif /* FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001752 { 0, NULL },
1753};
1754
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001755#ifndef FREEBSD
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001756#ifndef SUNOS4_KERNEL_ARCH_KLUDGE
1757static
1758#endif /* !SUNOS4_KERNEL_ARCH_KLUDGE */
1759struct xlat struct_user_offsets[] = {
1760#ifdef LINUX
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00001761#ifdef S390
1762 { PT_PSWMASK, "psw_mask" },
1763 { PT_PSWADDR, "psw_addr" },
1764 { PT_GPR0, "gpr0" },
1765 { PT_GPR1, "gpr1" },
1766 { PT_GPR2, "gpr2" },
1767 { PT_GPR3, "gpr3" },
1768 { PT_GPR4, "gpr4" },
1769 { PT_GPR5, "gpr5" },
1770 { PT_GPR6, "gpr6" },
1771 { PT_GPR7, "gpr7" },
1772 { PT_GPR8, "gpr8" },
1773 { PT_GPR9, "gpr9" },
1774 { PT_GPR10, "gpr10" },
1775 { PT_GPR11, "gpr11" },
1776 { PT_GPR12, "gpr12" },
1777 { PT_GPR13, "gpr13" },
1778 { PT_GPR14, "gpr14" },
1779 { PT_GPR15, "gpr15" },
1780 { PT_ACR0, "acr0" },
1781 { PT_ACR1, "acr1" },
1782 { PT_ACR2, "acr2" },
1783 { PT_ACR3, "acr3" },
1784 { PT_ACR4, "acr4" },
1785 { PT_ACR5, "acr5" },
1786 { PT_ACR6, "acr6" },
1787 { PT_ACR7, "acr7" },
1788 { PT_ACR8, "acr8" },
1789 { PT_ACR9, "acr9" },
1790 { PT_ACR10, "acr10" },
1791 { PT_ACR11, "acr11" },
1792 { PT_ACR12, "acr12" },
1793 { PT_ACR13, "acr13" },
1794 { PT_ACR14, "acr14" },
1795 { PT_ACR15, "acr15" },
1796 { PT_ORIGGPR2, "orig_gpr2" },
1797 { PT_FPC, "fpc" },
1798 { PT_FPR0_HI, "fpr0.hi" },
1799 { PT_FPR0_LO, "fpr0.lo" },
1800 { PT_FPR1_HI, "fpr1.hi" },
1801 { PT_FPR1_LO, "fpr1.lo" },
1802 { PT_FPR2_HI, "fpr2.hi" },
1803 { PT_FPR2_LO, "fpr2.lo" },
1804 { PT_FPR3_HI, "fpr3.hi" },
1805 { PT_FPR3_LO, "fpr3.lo" },
1806 { PT_FPR4_HI, "fpr4.hi" },
1807 { PT_FPR4_LO, "fpr4.lo" },
1808 { PT_FPR5_HI, "fpr5.hi" },
1809 { PT_FPR5_LO, "fpr5.lo" },
1810 { PT_FPR6_HI, "fpr6.hi" },
1811 { PT_FPR6_LO, "fpr6.lo" },
1812 { PT_FPR7_HI, "fpr7.hi" },
1813 { PT_FPR7_LO, "fpr7.lo" },
1814 { PT_FPR8_HI, "fpr8.hi" },
1815 { PT_FPR8_LO, "fpr8.lo" },
1816 { PT_FPR9_HI, "fpr9.hi" },
1817 { PT_FPR9_LO, "fpr9.lo" },
1818 { PT_FPR10_HI, "fpr10.hi" },
1819 { PT_FPR10_LO, "fpr10.lo" },
1820 { PT_FPR11_HI, "fpr11.hi" },
1821 { PT_FPR11_LO, "fpr11.lo" },
1822 { PT_FPR12_HI, "fpr12.hi" },
1823 { PT_FPR12_LO, "fpr12.lo" },
1824 { PT_FPR13_HI, "fpr13.hi" },
1825 { PT_FPR13_LO, "fpr13.lo" },
1826 { PT_FPR14_HI, "fpr14.hi" },
1827 { PT_FPR14_LO, "fpr14.lo" },
1828 { PT_FPR15_HI, "fpr15.hi" },
1829 { PT_FPR15_LO, "fpr15.lo" },
1830 { PT_CR_9, "cr9" },
1831 { PT_CR_10, "cr10" },
1832 { PT_CR_11, "cr11" },
1833#endif
1834#if defined(SPARC)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001835 /* XXX No support for these offsets yet. */
Wichert Akkermanc1652e22001-03-27 12:17:16 +00001836#elif defined(HPPA)
1837 /* XXX No support for these offsets yet. */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001838#elif defined(POWERPC)
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00001839 { 4*PT_R0, "4*PT_R0" },
1840 { 4*PT_R1, "4*PT_R1" },
1841 { 4*PT_R2, "4*PT_R2" },
1842 { 4*PT_R3, "4*PT_R3" },
1843 { 4*PT_R4, "4*PT_R4" },
1844 { 4*PT_R5, "4*PT_R5" },
1845 { 4*PT_R6, "4*PT_R6" },
1846 { 4*PT_R7, "4*PT_R7" },
1847 { 4*PT_R8, "4*PT_R8" },
1848 { 4*PT_R9, "4*PT_R9" },
1849 { 4*PT_R10, "4*PT_R10" },
1850 { 4*PT_R11, "4*PT_R11" },
1851 { 4*PT_R12, "4*PT_R12" },
1852 { 4*PT_R13, "4*PT_R13" },
1853 { 4*PT_R14, "4*PT_R14" },
1854 { 4*PT_R15, "4*PT_R15" },
1855 { 4*PT_R16, "4*PT_R16" },
1856 { 4*PT_R17, "4*PT_R17" },
1857 { 4*PT_R18, "4*PT_R18" },
1858 { 4*PT_R19, "4*PT_R19" },
1859 { 4*PT_R20, "4*PT_R20" },
1860 { 4*PT_R21, "4*PT_R21" },
1861 { 4*PT_R22, "4*PT_R22" },
1862 { 4*PT_R23, "4*PT_R23" },
1863 { 4*PT_R24, "4*PT_R24" },
1864 { 4*PT_R25, "4*PT_R25" },
1865 { 4*PT_R26, "4*PT_R26" },
1866 { 4*PT_R27, "4*PT_R27" },
1867 { 4*PT_R28, "4*PT_R28" },
1868 { 4*PT_R29, "4*PT_R29" },
1869 { 4*PT_R30, "4*PT_R30" },
1870 { 4*PT_R31, "4*PT_R31" },
1871 { 4*PT_NIP, "4*PT_NIP" },
1872 { 4*PT_MSR, "4*PT_MSR" },
1873 { 4*PT_ORIG_R3, "4*PT_ORIG_R3" },
1874 { 4*PT_CTR, "4*PT_CTR" },
1875 { 4*PT_LNK, "4*PT_LNK" },
1876 { 4*PT_XER, "4*PT_XER" },
1877 { 4*PT_CCR, "4*PT_CCR" },
1878 { 4*PT_FPR0, "4*PT_FPR0" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001879#else
1880#ifdef ALPHA
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00001881 { 0, "r0" },
1882 { 1, "r1" },
1883 { 2, "r2" },
1884 { 3, "r3" },
1885 { 4, "r4" },
1886 { 5, "r5" },
1887 { 6, "r6" },
1888 { 7, "r7" },
1889 { 8, "r8" },
1890 { 9, "r9" },
1891 { 10, "r10" },
1892 { 11, "r11" },
1893 { 12, "r12" },
1894 { 13, "r13" },
1895 { 14, "r14" },
1896 { 15, "r15" },
1897 { 16, "r16" },
1898 { 17, "r17" },
1899 { 18, "r18" },
1900 { 19, "r19" },
1901 { 20, "r20" },
1902 { 21, "r21" },
1903 { 22, "r22" },
1904 { 23, "r23" },
1905 { 24, "r24" },
1906 { 25, "r25" },
1907 { 26, "r26" },
1908 { 27, "r27" },
1909 { 28, "r28" },
1910 { 29, "gp" },
1911 { 30, "fp" },
1912 { 31, "zero" },
1913 { 32, "fp0" },
1914 { 33, "fp" },
1915 { 34, "fp2" },
1916 { 35, "fp3" },
1917 { 36, "fp4" },
1918 { 37, "fp5" },
1919 { 38, "fp6" },
1920 { 39, "fp7" },
1921 { 40, "fp8" },
1922 { 41, "fp9" },
1923 { 42, "fp10" },
1924 { 43, "fp11" },
1925 { 44, "fp12" },
1926 { 45, "fp13" },
1927 { 46, "fp14" },
1928 { 47, "fp15" },
1929 { 48, "fp16" },
1930 { 49, "fp17" },
1931 { 50, "fp18" },
1932 { 51, "fp19" },
1933 { 52, "fp20" },
1934 { 53, "fp21" },
1935 { 54, "fp22" },
1936 { 55, "fp23" },
1937 { 56, "fp24" },
1938 { 57, "fp25" },
1939 { 58, "fp26" },
1940 { 59, "fp27" },
1941 { 60, "fp28" },
1942 { 61, "fp29" },
1943 { 62, "fp30" },
1944 { 63, "fp31" },
1945 { 64, "pc" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001946#else /* !ALPHA */
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001947#ifdef IA64
1948 { PT_F32, "f32" }, { PT_F33, "f33" }, { PT_F34, "f34" },
1949 { PT_F35, "f35" }, { PT_F36, "f36" }, { PT_F37, "f37" },
1950 { PT_F38, "f38" }, { PT_F39, "f39" }, { PT_F40, "f40" },
1951 { PT_F41, "f41" }, { PT_F42, "f42" }, { PT_F43, "f43" },
1952 { PT_F44, "f44" }, { PT_F45, "f45" }, { PT_F46, "f46" },
1953 { PT_F47, "f47" }, { PT_F48, "f48" }, { PT_F49, "f49" },
1954 { PT_F50, "f50" }, { PT_F51, "f51" }, { PT_F52, "f52" },
1955 { PT_F53, "f53" }, { PT_F54, "f54" }, { PT_F55, "f55" },
1956 { PT_F56, "f56" }, { PT_F57, "f57" }, { PT_F58, "f58" },
1957 { PT_F59, "f59" }, { PT_F60, "f60" }, { PT_F61, "f61" },
1958 { PT_F62, "f62" }, { PT_F63, "f63" }, { PT_F64, "f64" },
1959 { PT_F65, "f65" }, { PT_F66, "f66" }, { PT_F67, "f67" },
1960 { PT_F68, "f68" }, { PT_F69, "f69" }, { PT_F70, "f70" },
1961 { PT_F71, "f71" }, { PT_F72, "f72" }, { PT_F73, "f73" },
1962 { PT_F74, "f74" }, { PT_F75, "f75" }, { PT_F76, "f76" },
1963 { PT_F77, "f77" }, { PT_F78, "f78" }, { PT_F79, "f79" },
1964 { PT_F80, "f80" }, { PT_F81, "f81" }, { PT_F82, "f82" },
1965 { PT_F83, "f83" }, { PT_F84, "f84" }, { PT_F85, "f85" },
1966 { PT_F86, "f86" }, { PT_F87, "f87" }, { PT_F88, "f88" },
1967 { PT_F89, "f89" }, { PT_F90, "f90" }, { PT_F91, "f91" },
1968 { PT_F92, "f92" }, { PT_F93, "f93" }, { PT_F94, "f94" },
1969 { PT_F95, "f95" }, { PT_F96, "f96" }, { PT_F97, "f97" },
1970 { PT_F98, "f98" }, { PT_F99, "f99" }, { PT_F100, "f100" },
1971 { PT_F101, "f101" }, { PT_F102, "f102" }, { PT_F103, "f103" },
1972 { PT_F104, "f104" }, { PT_F105, "f105" }, { PT_F106, "f106" },
1973 { PT_F107, "f107" }, { PT_F108, "f108" }, { PT_F109, "f109" },
1974 { PT_F110, "f110" }, { PT_F111, "f111" }, { PT_F112, "f112" },
1975 { PT_F113, "f113" }, { PT_F114, "f114" }, { PT_F115, "f115" },
1976 { PT_F116, "f116" }, { PT_F117, "f117" }, { PT_F118, "f118" },
1977 { PT_F119, "f119" }, { PT_F120, "f120" }, { PT_F121, "f121" },
1978 { PT_F122, "f122" }, { PT_F123, "f123" }, { PT_F124, "f124" },
1979 { PT_F125, "f125" }, { PT_F126, "f126" }, { PT_F127, "f127" },
1980 /* switch stack: */
1981 { PT_F2, "f2" }, { PT_F3, "f3" }, { PT_F4, "f4" },
1982 { PT_F5, "f5" }, { PT_F10, "f10" }, { PT_F11, "f11" },
1983 { PT_F12, "f12" }, { PT_F13, "f13" }, { PT_F14, "f14" },
1984 { PT_F15, "f15" }, { PT_F16, "f16" }, { PT_F17, "f17" },
1985 { PT_F18, "f18" }, { PT_F19, "f19" }, { PT_F20, "f20" },
1986 { PT_F21, "f21" }, { PT_F22, "f22" }, { PT_F23, "f23" },
1987 { PT_F24, "f24" }, { PT_F25, "f25" }, { PT_F26, "f26" },
1988 { PT_F27, "f27" }, { PT_F28, "f28" }, { PT_F29, "f29" },
1989 { PT_F30, "f30" }, { PT_F31, "f31" }, { PT_R4, "r4" },
1990 { PT_R5, "r5" }, { PT_R6, "r6" }, { PT_R7, "r7" },
Wichert Akkerman82b162e2001-08-03 11:51:28 +00001991 { PT_B0, "kb0" },
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001992 { PT_B1, "b1" }, { PT_B2, "b2" }, { PT_B3, "b3" },
1993 { PT_B4, "b4" }, { PT_B5, "b5" },
Wichert Akkerman82b162e2001-08-03 11:51:28 +00001994 { PT_AR_PFS, "kar.pfs" },
1995 { PT_AR_LC, "ar.lc" }, { PT_AR_UNAT, "kar.unat" },
1996 { PT_AR_RNAT, "kar.rnat" }, { PT_AR_BSPSTORE, "kar.bspstore" },
1997 { PT_PR, "k.pr" },
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001998 /* pt_regs */
1999 { PT_CR_IPSR, "cr.ipsr" }, { PT_CR_IIP, "cr.iip" },
Wichert Akkerman82b162e2001-08-03 11:51:28 +00002000 /*{ PT_CR_IFS, "cr.ifs" },*/ { PT_AR_UNAT, "ar.unat" },
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00002001 { PT_AR_PFS, "ar.pfs" }, { PT_AR_RSC, "ar.rsc" },
2002 { PT_AR_RNAT, "ar.rnat" }, { PT_AR_BSPSTORE, "ar.bspstore" },
2003 { PT_PR, "pr" }, { PT_B6, "b6" }, { PT_AR_BSP, "ar.bsp" },
2004 { PT_R1, "r1" }, { PT_R2, "r2" }, { PT_R3, "r3" },
2005 { PT_R12, "r12" }, { PT_R13, "r13" }, { PT_R14, "r14" },
2006 { PT_R15, "r15" }, { PT_R8, "r8" }, { PT_R9, "r9" },
2007 { PT_R10, "r10" }, { PT_R11, "r11" }, { PT_R16, "r16" },
2008 { PT_R17, "r17" }, { PT_R18, "r18" }, { PT_R19, "r19" },
2009 { PT_R20, "r20" }, { PT_R21, "r21" }, { PT_R22, "r22" },
2010 { PT_R23, "r23" }, { PT_R24, "r24" }, { PT_R25, "r25" },
2011 { PT_R26, "r26" }, { PT_R27, "r27" }, { PT_R28, "r28" },
2012 { PT_R29, "r29" }, { PT_R30, "r30" }, { PT_R31, "r31" },
2013 { PT_AR_CCV, "ar.ccv" }, { PT_AR_FPSR, "ar.fpsr" },
2014 { PT_B0, "b0" }, { PT_B7, "b7" }, { PT_F6, "f6" },
2015 { PT_F7, "f7" }, { PT_F8, "f8" }, { PT_F9, "f9" },
2016#else /* !IA64 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002017#ifdef I386
2018 { 4*EBX, "4*EBX" },
2019 { 4*ECX, "4*ECX" },
2020 { 4*EDX, "4*EDX" },
2021 { 4*ESI, "4*ESI" },
2022 { 4*EDI, "4*EDI" },
2023 { 4*EBP, "4*EBP" },
2024 { 4*EAX, "4*EAX" },
2025 { 4*DS, "4*DS" },
2026 { 4*ES, "4*ES" },
2027 { 4*FS, "4*FS" },
2028 { 4*GS, "4*GS" },
2029 { 4*ORIG_EAX, "4*ORIG_EAX" },
2030 { 4*EIP, "4*EIP" },
2031 { 4*CS, "4*CS" },
2032 { 4*EFL, "4*EFL" },
2033 { 4*UESP, "4*UESP" },
2034 { 4*SS, "4*SS" },
2035#else /* !I386 */
2036#ifdef M68K
2037 { 4*PT_D1, "4*PT_D1" },
2038 { 4*PT_D2, "4*PT_D2" },
2039 { 4*PT_D3, "4*PT_D3" },
2040 { 4*PT_D4, "4*PT_D4" },
2041 { 4*PT_D5, "4*PT_D5" },
2042 { 4*PT_D6, "4*PT_D6" },
2043 { 4*PT_D7, "4*PT_D7" },
2044 { 4*PT_A0, "4*PT_A0" },
2045 { 4*PT_A1, "4*PT_A1" },
2046 { 4*PT_A2, "4*PT_A2" },
2047 { 4*PT_A3, "4*PT_A3" },
2048 { 4*PT_A4, "4*PT_A4" },
2049 { 4*PT_A5, "4*PT_A5" },
2050 { 4*PT_A6, "4*PT_A6" },
2051 { 4*PT_D0, "4*PT_D0" },
2052 { 4*PT_USP, "4*PT_USP" },
2053 { 4*PT_ORIG_D0, "4*PT_ORIG_D0" },
2054 { 4*PT_SR, "4*PT_SR" },
2055 { 4*PT_PC, "4*PT_PC" },
2056#endif /* M68K */
2057#endif /* !I386 */
Wichert Akkermanccef6372002-05-01 16:39:22 +00002058#ifdef SH
2059 { 4*REG_REG0, "4*REG_REG0" },
2060 { 4*(REG_REG0+1), "4*REG_REG1" },
2061 { 4*(REG_REG0+2), "4*REG_REG2" },
2062 { 4*(REG_REG0+3), "4*REG_REG3" },
2063 { 4*(REG_REG0+4), "4*REG_REG4" },
2064 { 4*(REG_REG0+5), "4*REG_REG5" },
2065 { 4*(REG_REG0+6), "4*REG_REG6" },
2066 { 4*(REG_REG0+7), "4*REG_REG7" },
2067 { 4*(REG_REG0+8), "4*REG_REG8" },
2068 { 4*(REG_REG0+9), "4*REG_REG9" },
2069 { 4*(REG_REG0+10), "4*REG_REG10" },
2070 { 4*(REG_REG0+11), "4*REG_REG11" },
2071 { 4*(REG_REG0+12), "4*REG_REG12" },
2072 { 4*(REG_REG0+13), "4*REG_REG13" },
2073 { 4*(REG_REG0+14), "4*REG_REG14" },
2074 { 4*REG_REG15, "4*REG_REG15" },
2075 { 4*REG_PC, "4*REG_PC" },
2076 { 4*REG_PR, "4*REG_PR" },
2077 { 4*REG_SR, "4*REG_SR" },
2078 { 4*REG_GBR, "4*REG_GBR" },
2079 { 4*REG_MACH, "4*REG_MACH" },
2080 { 4*REG_MACL, "4*REG_MACL" },
2081 { 4*REG_SYSCALL, "4*REG_SYSCALL" },
2082 { 4*REG_FPUL, "4*REG_FPUL" },
2083 { 4*REG_FPREG0, "4*REG_FPREG0" },
2084 { 4*(REG_FPREG0+1), "4*REG_FPREG1" },
2085 { 4*(REG_FPREG0+2), "4*REG_FPREG2" },
2086 { 4*(REG_FPREG0+3), "4*REG_FPREG3" },
2087 { 4*(REG_FPREG0+4), "4*REG_FPREG4" },
2088 { 4*(REG_FPREG0+5), "4*REG_FPREG5" },
2089 { 4*(REG_FPREG0+6), "4*REG_FPREG6" },
2090 { 4*(REG_FPREG0+7), "4*REG_FPREG7" },
2091 { 4*(REG_FPREG0+8), "4*REG_FPREG8" },
2092 { 4*(REG_FPREG0+9), "4*REG_FPREG9" },
2093 { 4*(REG_FPREG0+10), "4*REG_FPREG10" },
2094 { 4*(REG_FPREG0+11), "4*REG_FPREG11" },
2095 { 4*(REG_FPREG0+12), "4*REG_FPREG12" },
2096 { 4*(REG_FPREG0+13), "4*REG_FPREG13" },
2097 { 4*(REG_FPREG0+14), "4*REG_FPREG14" },
2098 { 4*REG_FPREG15, "4*REG_FPREG15" },
2099 { 4*REG_XDREG0, "4*REG_XDREG0" },
2100 { 4*(REG_XDREG0+2), "4*REG_XDREG2" },
2101 { 4*(REG_XDREG0+4), "4*REG_XDREG4" },
2102 { 4*(REG_XDREG0+6), "4*REG_XDREG6" },
2103 { 4*(REG_XDREG0+8), "4*REG_XDREG8" },
2104 { 4*(REG_XDREG0+10), "4*REG_XDREG10" },
2105 { 4*(REG_XDREG0+12), "4*REG_XDREG12" },
2106 { 4*REG_XDREG14, "4*REG_XDREG14" },
2107 { 4*REG_FPSCR, "4*REG_FPSCR" },
2108#endif /* SH */
2109
Wichert Akkerman12f75d12000-02-14 16:23:40 +00002110#if !defined(S390) && !defined(MIPS)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002111 { uoff(u_fpvalid), "offsetof(struct user, u_fpvalid)" },
Wichert Akkermanf90da011999-10-31 21:15:38 +00002112#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002113#ifdef I386
2114 { uoff(i387), "offsetof(struct user, i387)" },
2115#else /* !I386 */
2116#ifdef M68K
2117 { uoff(m68kfp), "offsetof(struct user, m68kfp)" },
2118#endif /* M68K */
2119#endif /* !I386 */
2120 { uoff(u_tsize), "offsetof(struct user, u_tsize)" },
2121 { uoff(u_dsize), "offsetof(struct user, u_dsize)" },
2122 { uoff(u_ssize), "offsetof(struct user, u_ssize)" },
2123 { uoff(start_code), "offsetof(struct user, start_code)" },
2124 { uoff(start_stack), "offsetof(struct user, start_stack)" },
2125 { uoff(signal), "offsetof(struct user, signal)" },
Wichert Akkermanccef6372002-05-01 16:39:22 +00002126#if !defined(S390) && !defined(MIPS) && !defined(SH)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002127 { uoff(reserved), "offsetof(struct user, reserved)" },
Wichert Akkermanf90da011999-10-31 21:15:38 +00002128#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002129 { uoff(u_ar0), "offsetof(struct user, u_ar0)" },
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00002130#if !defined(ARM) && !defined(MIPS) && !defined(S390)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002131 { uoff(u_fpstate), "offsetof(struct user, u_fpstate)" },
2132#endif
2133 { uoff(magic), "offsetof(struct user, magic)" },
2134 { uoff(u_comm), "offsetof(struct user, u_comm)" },
2135#ifdef I386
2136 { uoff(u_debugreg), "offsetof(struct user, u_debugreg)" },
2137#endif /* I386 */
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00002138#endif /* !IA64 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002139#endif /* !ALPHA */
2140#endif /* !POWERPC/!SPARC */
2141#endif /* LINUX */
2142#ifdef SUNOS4
2143 { uoff(u_pcb), "offsetof(struct user, u_pcb)" },
2144 { uoff(u_procp), "offsetof(struct user, u_procp)" },
2145 { uoff(u_ar0), "offsetof(struct user, u_ar0)" },
2146 { uoff(u_comm[0]), "offsetof(struct user, u_comm[0])" },
2147 { uoff(u_arg[0]), "offsetof(struct user, u_arg[0])" },
2148 { uoff(u_ap), "offsetof(struct user, u_ap)" },
2149 { uoff(u_qsave), "offsetof(struct user, u_qsave)" },
2150 { uoff(u_rval1), "offsetof(struct user, u_rval1)" },
2151 { uoff(u_rval2), "offsetof(struct user, u_rval2)" },
2152 { uoff(u_error), "offsetof(struct user, u_error)" },
2153 { uoff(u_eosys), "offsetof(struct user, u_eosys)" },
2154 { uoff(u_ssave), "offsetof(struct user, u_ssave)" },
2155 { uoff(u_signal[0]), "offsetof(struct user, u_signal)" },
2156 { uoff(u_sigmask[0]), "offsetof(struct user, u_sigmask)" },
2157 { uoff(u_sigonstack), "offsetof(struct user, u_sigonstack)" },
2158 { uoff(u_sigintr), "offsetof(struct user, u_sigintr)" },
2159 { uoff(u_sigreset), "offsetof(struct user, u_sigreset)" },
2160 { uoff(u_oldmask), "offsetof(struct user, u_oldmask)" },
2161 { uoff(u_code), "offsetof(struct user, u_code)" },
2162 { uoff(u_addr), "offsetof(struct user, u_addr)" },
2163 { uoff(u_sigstack), "offsetof(struct user, u_sigstack)" },
2164 { uoff(u_ofile), "offsetof(struct user, u_ofile)" },
2165 { uoff(u_pofile), "offsetof(struct user, u_pofile)" },
2166 { uoff(u_ofile_arr[0]), "offsetof(struct user, u_ofile_arr[0])" },
2167 { uoff(u_pofile_arr[0]),"offsetof(struct user, u_pofile_arr[0])"},
2168 { uoff(u_lastfile), "offsetof(struct user, u_lastfile)" },
2169 { uoff(u_cwd), "offsetof(struct user, u_cwd)" },
2170 { uoff(u_cdir), "offsetof(struct user, u_cdir)" },
2171 { uoff(u_rdir), "offsetof(struct user, u_rdir)" },
2172 { uoff(u_cmask), "offsetof(struct user, u_cmask)" },
2173 { uoff(u_ru), "offsetof(struct user, u_ru)" },
2174 { uoff(u_cru), "offsetof(struct user, u_cru)" },
2175 { uoff(u_timer[0]), "offsetof(struct user, u_timer[0])" },
2176 { uoff(u_XXX[0]), "offsetof(struct user, u_XXX[0])" },
2177 { uoff(u_ioch), "offsetof(struct user, u_ioch)" },
2178 { uoff(u_start), "offsetof(struct user, u_start)" },
2179 { uoff(u_acflag), "offsetof(struct user, u_acflag)" },
2180 { uoff(u_prof.pr_base), "offsetof(struct user, u_prof.pr_base)" },
2181 { uoff(u_prof.pr_size), "offsetof(struct user, u_prof.pr_size)" },
2182 { uoff(u_prof.pr_off), "offsetof(struct user, u_prof.pr_off)" },
2183 { uoff(u_prof.pr_scale),"offsetof(struct user, u_prof.pr_scale)"},
2184 { uoff(u_rlimit[0]), "offsetof(struct user, u_rlimit)" },
2185 { uoff(u_exdata.Ux_A), "offsetof(struct user, u_exdata.Ux_A)" },
2186 { uoff(u_exdata.ux_shell[0]),"offsetof(struct user, u_exdata.ux_shell[0])"},
2187 { uoff(u_lofault), "offsetof(struct user, u_lofault)" },
2188#endif /* SUNOS4 */
Wichert Akkermanc1652e22001-03-27 12:17:16 +00002189#ifndef HPPA
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002190 { sizeof(struct user), "sizeof(struct user)" },
Wichert Akkermanc1652e22001-03-27 12:17:16 +00002191#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002192 { 0, NULL },
2193};
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002194#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002195
2196int
2197sys_ptrace(tcp)
2198struct tcb *tcp;
2199{
2200 char *cmd;
2201 struct xlat *x;
2202 long addr;
2203
2204 cmd = xlookup(ptrace_cmds, tcp->u_arg[0]);
2205 if (!cmd)
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002206#ifndef FREEBSD
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002207 cmd = "PTRACE_???";
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002208#else
2209 cmd = "PT_???";
2210#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002211 if (entering(tcp)) {
2212 tprintf("%s, %lu, ", cmd, tcp->u_arg[1]);
2213 addr = tcp->u_arg[2];
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002214#ifndef FREEBSD
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002215 if (tcp->u_arg[0] == PTRACE_PEEKUSER
2216 || tcp->u_arg[0] == PTRACE_POKEUSER) {
2217 for (x = struct_user_offsets; x->str; x++) {
2218 if (x->val >= addr)
2219 break;
2220 }
2221 if (!x->str)
2222 tprintf("%#lx, ", addr);
2223 else if (x->val > addr && x != struct_user_offsets) {
2224 x--;
2225 tprintf("%s + %ld, ", x->str, addr - x->val);
2226 }
2227 else
2228 tprintf("%s, ", x->str);
2229 }
2230 else
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002231#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002232 tprintf("%#lx, ", tcp->u_arg[2]);
2233#ifdef LINUX
2234 switch (tcp->u_arg[0]) {
2235 case PTRACE_PEEKDATA:
2236 case PTRACE_PEEKTEXT:
2237 case PTRACE_PEEKUSER:
2238 break;
2239 case PTRACE_CONT:
2240 case PTRACE_SINGLESTEP:
2241 case PTRACE_SYSCALL:
2242 case PTRACE_DETACH:
2243 printsignal(tcp->u_arg[3]);
2244 break;
2245 default:
2246 tprintf("%#lx", tcp->u_arg[3]);
2247 break;
2248 }
2249 } else {
2250 switch (tcp->u_arg[0]) {
2251 case PTRACE_PEEKDATA:
2252 case PTRACE_PEEKTEXT:
2253 case PTRACE_PEEKUSER:
2254 printnum(tcp, tcp->u_arg[3], "%#x");
2255 break;
2256 }
2257 }
2258#endif /* LINUX */
2259#ifdef SUNOS4
2260 if (tcp->u_arg[0] == PTRACE_WRITEDATA ||
2261 tcp->u_arg[0] == PTRACE_WRITETEXT) {
2262 tprintf("%lu, ", tcp->u_arg[3]);
2263 printstr(tcp, tcp->u_arg[4], tcp->u_arg[3]);
2264 } else if (tcp->u_arg[0] != PTRACE_READDATA &&
2265 tcp->u_arg[0] != PTRACE_READTEXT) {
2266 tprintf("%#lx", tcp->u_arg[3]);
2267 }
2268 } else {
2269 if (tcp->u_arg[0] == PTRACE_READDATA ||
2270 tcp->u_arg[0] == PTRACE_READTEXT) {
2271 tprintf("%lu, ", tcp->u_arg[3]);
2272 printstr(tcp, tcp->u_arg[4], tcp->u_arg[3]);
2273 }
2274 }
2275#endif /* SUNOS4 */
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002276#ifdef FREEBSD
2277 tprintf("%lu", tcp->u_arg[3]);
2278 }
2279#endif /* FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002280 return 0;
2281}
2282
2283#endif /* !SVR4 */