blob: ed5d2a8d3d0d77affed02edb3373641ba68d3f41 [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;
Michal Ludvig0e035502002-09-23 15:41:01 +0000498#elif defined(X86_64)
499 /* Attempt to make vfork into fork, which we can follow. */
500 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(ORIG_RAX * 8), new) < 0)
501 return -1;
502 return 0;
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000503#elif defined(POWERPC)
Wichert Akkerman5c4c69b2001-04-12 09:00:47 +0000504 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(4*PT_R0), new) < 0)
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000505 return -1;
506#elif defined(S390)
507 long pc;
508 if (upeek(tcp->pid, PT_PSWADDR,&pc)<0)
509 return -1;
510 if (ptrace(PTRACE_POKETEXT, tcp->pid, (char*)(pc-4), new)<0)
511 return -1;
512 return 0;
513#elif defined(M68K)
Wichert Akkermanc7926982000-04-10 22:22:31 +0000514 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(4*PT_ORIG_D0), new)<0)
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000515 return -1;
516 return 0;
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000517#elif defined(SPARC)
Wichert Akkerman00a82ee2001-03-28 20:29:17 +0000518 struct regs regs;
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000519 if (ptrace(PTRACE_GETREGS, tcp->pid, (char*)&regs, 0)<0)
520 return -1;
Wichert Akkerman00a82ee2001-03-28 20:29:17 +0000521 regs.r_g1=new;
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000522 if (ptrace(PTRACE_SETREGS, tcp->pid, (char*)&regs, 0)<0)
523 return -1;
524 return 0;
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000525#elif defined(MIPS)
Wichert Akkermanc7926982000-04-10 22:22:31 +0000526 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(REG_V0), new)<0)
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000527 return -1;
528 return 0;
529#elif defined(ALPHA)
Wichert Akkermanc7926982000-04-10 22:22:31 +0000530 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(REG_A3), new)<0)
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000531 return -1;
532 return 0;
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000533#elif defined(IA64)
534 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(PT_R15), new)<0)
535 return -1;
536 return 0;
Wichert Akkermanc1652e22001-03-27 12:17:16 +0000537#elif defined(HPPA)
538 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(PT_GR20), new)<0)
539 return -1;
540 return 0;
Wichert Akkermanccef6372002-05-01 16:39:22 +0000541#elif defined(SH)
542 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(REG_SYSCALL), new)<0)
543 return -1;
544 return 0;
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000545#else
546#warning Do not know how to handle change_syscall for this architecture
547#endif /* architecture */
548#endif /* LINUX */
549 return -1;
550}
551
552int
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000553setarg(tcp, argnum)
554 struct tcb *tcp;
555 int argnum;
556{
557#if defined (IA64)
558 {
559 unsigned long *bsp, *ap;
560
561 if (upeek(tcp->pid, PT_AR_BSP, (long *) &bsp) , 0)
562 return -1;
563
564 ap = ia64_rse_skip_regs(bsp, argnum);
565 errno = 0;
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000566 ptrace(PTRACE_POKEDATA, tcp->pid, (char *) ap, tcp->u_arg[argnum]);
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000567 if (errno)
568 return -1;
569
570 }
Wichert Akkerman12f75d12000-02-14 16:23:40 +0000571#elif defined(I386)
572 {
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000573 ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(4*argnum), tcp->u_arg[argnum]);
Wichert Akkerman12f75d12000-02-14 16:23:40 +0000574 if (errno)
575 return -1;
576 }
Michal Ludvig0e035502002-09-23 15:41:01 +0000577#elif defined(X86_64)
578 {
579 ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(8*(long)argnum), tcp->u_arg[argnum]);
580 if (errno)
581 return -1;
582 }
Ralf Baechlee3816102000-08-01 00:06:06 +0000583#elif defined(MIPS)
584 {
585 errno = 0;
586 if (argnum < 4)
587 ptrace(PTRACE_POKEUSER, tcp->pid,
588 (char*)(REG_A0 + argnum), tcp->u_arg[argnum]);
589 else {
590 unsigned long *sp;
591
592 if (upeek(tcp->pid, REG_SP, (long *) &sp) , 0)
593 return -1;
594
595 ptrace(PTRACE_POKEDATA, tcp->pid,
596 (char*)(sp + argnum - 4), tcp->u_arg[argnum]);
597 }
598 if (errno)
599 return -1;
600 }
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000601#else
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000602# warning Sorry, setargs not implemented for this architecture.
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000603#endif
604 return 0;
605}
606
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000607#ifdef SYS_clone
608int
609internal_clone(tcp)
610struct tcb *tcp;
611{
Ulrich Drepper90512f01999-12-24 07:22:25 +0000612 struct tcb *tcpchild;
613 int pid;
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000614 if (entering(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000615 if (!followfork)
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000616 return 0;
617 if (nprocs == MAX_PROCS) {
618 tcp->flags &= ~TCB_FOLLOWFORK;
619 fprintf(stderr, "sys_fork: tcb table full\n");
620 return 0;
621 }
622 tcp->flags |= TCB_FOLLOWFORK;
623
Wichert Akkerman9b0c31d2000-09-03 21:56:29 +0000624
625 if (setbpt(tcp) < 0)
626 return 0;
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000627 } else {
Wichert Akkerman9b0c31d2000-09-03 21:56:29 +0000628 int bpt = tcp->flags & TCB_BPTSET;
629
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000630 if (!(tcp->flags & TCB_FOLLOWFORK))
631 return 0;
632
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000633 if (syserror(tcp)) {
634 if (bpt)
635 clearbpt(tcp);
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000636 return 0;
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000637 }
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000638
639 pid = tcp->u_rval;
640 if ((tcpchild = alloctcb(pid)) == NULL) {
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000641 if (bpt)
642 clearbpt(tcp);
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000643 fprintf(stderr, " [tcb table full]\n");
644 kill(pid, SIGKILL); /* XXX */
645 return 0;
646 }
647
Wichert Akkerman9b0c31d2000-09-03 21:56:29 +0000648 /* Attach to the new child */
649 if (ptrace(PTRACE_ATTACH, pid, (char *) 1, 0) < 0) {
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000650 if (bpt)
651 clearbpt(tcp);
Wichert Akkerman9b0c31d2000-09-03 21:56:29 +0000652 perror("PTRACE_ATTACH");
653 fprintf(stderr, "Too late?\n");
654 droptcb(tcpchild);
655 return 0;
656 }
657
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000658 if (bpt)
659 clearbpt(tcp);
660
Ulrich Drepper90512f01999-12-24 07:22:25 +0000661 tcpchild->flags |= TCB_ATTACHED;
Wichert Akkerman9b0c31d2000-09-03 21:56:29 +0000662 if (bpt) {
663 tcpchild->flags |= TCB_BPTSET;
664 tcpchild->baddr = tcp->baddr;
665 memcpy(tcpchild->inst, tcp->inst,
666 sizeof tcpchild->inst);
667 }
Ulrich Drepper90512f01999-12-24 07:22:25 +0000668 newoutf(tcpchild);
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000669 tcpchild->parent = tcp;
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000670 tcp->nchildren++;
671 if (!qflag)
672 fprintf(stderr, "Process %d attached\n", pid);
673 }
674 return 0;
675}
676#endif
677
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000678int
679internal_fork(tcp)
680struct tcb *tcp;
681{
682 struct tcb *tcpchild;
683 int pid;
Nate Sammonsccd8f211999-03-29 22:57:54 +0000684 int dont_follow = 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000685
686#ifdef SYS_vfork
Nate Sammonsccd8f211999-03-29 22:57:54 +0000687 if (tcp->scno == SYS_vfork) {
Nate Sammonsccd8f211999-03-29 22:57:54 +0000688 /* Attempt to make vfork into fork, which we can follow. */
689 if (!followvfork ||
Pavel Machek9a9f10b2000-02-01 16:22:52 +0000690 change_syscall(tcp, SYS_fork) < 0)
Nate Sammonsccd8f211999-03-29 22:57:54 +0000691 dont_follow = 1;
Nate Sammonsccd8f211999-03-29 22:57:54 +0000692 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000693#endif
694 if (entering(tcp)) {
Nate Sammonsccd8f211999-03-29 22:57:54 +0000695 if (!followfork || dont_follow)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000696 return 0;
697 if (nprocs == MAX_PROCS) {
698 tcp->flags &= ~TCB_FOLLOWFORK;
699 fprintf(stderr, "sys_fork: tcb table full\n");
700 return 0;
701 }
702 tcp->flags |= TCB_FOLLOWFORK;
703 if (setbpt(tcp) < 0)
704 return 0;
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000705 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000706 else {
707 int bpt = tcp->flags & TCB_BPTSET;
708
709 if (!(tcp->flags & TCB_FOLLOWFORK))
710 return 0;
711 if (bpt)
712 clearbpt(tcp);
713
714 if (syserror(tcp))
715 return 0;
716
717 pid = tcp->u_rval;
718 if ((tcpchild = alloctcb(pid)) == NULL) {
719 fprintf(stderr, " [tcb table full]\n");
720 kill(pid, SIGKILL); /* XXX */
721 return 0;
722 }
723#ifdef LINUX
Wichert Akkermanc1652e22001-03-27 12:17:16 +0000724#ifdef HPPA
725 /* The child must have run before it can be attached. */
726 /* This must be a bug in the parisc kernel, but I havn't
727 * identified it yet. Seems to be an issue associated
728 * with attaching to a process (which sends it a signal)
729 * before that process has ever been scheduled. When
730 * debugging, I started seeing crashes in
731 * arch/parisc/kernel/signal.c:do_signal(), apparently
732 * caused by r8 getting corrupt over the dequeue_signal()
733 * call. Didn't make much sense though...
734 */
735 {
736 struct timeval tv;
737 tv.tv_sec = 0;
738 tv.tv_usec = 10000;
739 select(0, NULL, NULL, NULL, &tv);
740 }
741#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000742 if (ptrace(PTRACE_ATTACH, pid, (char *) 1, 0) < 0) {
743 perror("PTRACE_ATTACH");
744 fprintf(stderr, "Too late?\n");
745 droptcb(tcpchild);
746 return 0;
747 }
748#endif /* LINUX */
749#ifdef SUNOS4
750#ifdef oldway
751 /* The child must have run before it can be attached. */
752 {
753 struct timeval tv;
754 tv.tv_sec = 0;
755 tv.tv_usec = 10000;
756 select(0, NULL, NULL, NULL, &tv);
757 }
758 if (ptrace(PTRACE_ATTACH, pid, (char *)1, 0) < 0) {
759 perror("PTRACE_ATTACH");
760 fprintf(stderr, "Too late?\n");
761 droptcb(tcpchild);
762 return 0;
763 }
764#else /* !oldway */
765 /* Try to catch the new process as soon as possible. */
766 {
767 int i;
768 for (i = 0; i < 1024; i++)
769 if (ptrace(PTRACE_ATTACH, pid, (char *) 1, 0) >= 0)
770 break;
771 if (i == 1024) {
772 perror("PTRACE_ATTACH");
773 fprintf(stderr, "Too late?\n");
774 droptcb(tcpchild);
775 return 0;
776 }
777 }
778#endif /* !oldway */
779#endif /* SUNOS4 */
780 tcpchild->flags |= TCB_ATTACHED;
781 /* Child has BPT too, must be removed on first occasion */
782 if (bpt) {
783 tcpchild->flags |= TCB_BPTSET;
784 tcpchild->baddr = tcp->baddr;
785 memcpy(tcpchild->inst, tcp->inst,
786 sizeof tcpchild->inst);
787 }
788 newoutf(tcpchild);
789 tcpchild->parent = tcp;
790 tcp->nchildren++;
791 if (!qflag)
792 fprintf(stderr, "Process %d attached\n", pid);
793 }
794 return 0;
795}
796
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000797#endif /* !USE_PROCFS */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000798
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000799#if defined(SUNOS4) || defined(LINUX) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000800
801int
802sys_vfork(tcp)
803struct tcb *tcp;
804{
805 if (exiting(tcp))
806 return RVAL_UDECIMAL;
807 return 0;
808}
809
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000810#endif /* SUNOS4 || LINUX || FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000811
812#ifndef LINUX
813
814static char idstr[16];
815
816int
817sys_getpid(tcp)
818struct tcb *tcp;
819{
820 if (exiting(tcp)) {
821 sprintf(idstr, "ppid %lu", getrval2(tcp));
822 tcp->auxstr = idstr;
823 return RVAL_STR;
824 }
825 return 0;
826}
827
828int
829sys_getuid(tcp)
830struct tcb *tcp;
831{
832 if (exiting(tcp)) {
833 sprintf(idstr, "euid %lu", getrval2(tcp));
834 tcp->auxstr = idstr;
835 return RVAL_STR;
836 }
837 return 0;
838}
839
840int
841sys_getgid(tcp)
842struct tcb *tcp;
843{
844 if (exiting(tcp)) {
845 sprintf(idstr, "egid %lu", getrval2(tcp));
846 tcp->auxstr = idstr;
847 return RVAL_STR;
848 }
849 return 0;
850}
851
852#endif /* !LINUX */
853
854#ifdef LINUX
855
856int
857sys_setuid(tcp)
858struct tcb *tcp;
859{
860 if (entering(tcp)) {
861 tprintf("%u", (uid_t) tcp->u_arg[0]);
862 }
863 return 0;
864}
865
866int
867sys_setgid(tcp)
868struct tcb *tcp;
869{
870 if (entering(tcp)) {
871 tprintf("%u", (gid_t) tcp->u_arg[0]);
872 }
873 return 0;
874}
875
876int
877sys_getresuid(tcp)
878 struct tcb *tcp;
879{
880 if (exiting(tcp)) {
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000881 __kernel_uid_t uid;
882 if (syserror(tcp))
883 tprintf("%#lx, %#lx, %#lx", tcp->u_arg[0],
884 tcp->u_arg[1], tcp->u_arg[2]);
885 else {
886 if (umove(tcp, tcp->u_arg[0], &uid) < 0)
887 tprintf("%#lx, ", tcp->u_arg[0]);
888 else
889 tprintf("ruid %lu, ", (unsigned long) uid);
890 if (umove(tcp, tcp->u_arg[0], &uid) < 0)
891 tprintf("%#lx, ", tcp->u_arg[0]);
892 else
893 tprintf("euid %lu, ", (unsigned long) uid);
894 if (umove(tcp, tcp->u_arg[0], &uid) < 0)
895 tprintf("%#lx", tcp->u_arg[0]);
896 else
897 tprintf("suid %lu", (unsigned long) uid);
898 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000899 }
900 return 0;
901}
902
903int
904sys_getresgid(tcp)
905struct tcb *tcp;
906{
907 if (exiting(tcp)) {
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000908 __kernel_gid_t gid;
909 if (syserror(tcp))
910 tprintf("%#lx, %#lx, %#lx", tcp->u_arg[0],
911 tcp->u_arg[1], tcp->u_arg[2]);
912 else {
913 if (umove(tcp, tcp->u_arg[0], &gid) < 0)
914 tprintf("%#lx, ", tcp->u_arg[0]);
915 else
916 tprintf("rgid %lu, ", (unsigned long) gid);
917 if (umove(tcp, tcp->u_arg[0], &gid) < 0)
918 tprintf("%#lx, ", tcp->u_arg[0]);
919 else
920 tprintf("egid %lu, ", (unsigned long) gid);
921 if (umove(tcp, tcp->u_arg[0], &gid) < 0)
922 tprintf("%#lx", tcp->u_arg[0]);
923 else
924 tprintf("sgid %lu", (unsigned long) gid);
925 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000926 }
927 return 0;
928}
929
930#endif /* LINUX */
931
932int
933sys_setreuid(tcp)
934struct tcb *tcp;
935{
936 if (entering(tcp)) {
937 tprintf("%lu, %lu",
938 (unsigned long) (uid_t) tcp->u_arg[0],
939 (unsigned long) (uid_t) tcp->u_arg[1]);
940 }
941 return 0;
942}
943
944int
945sys_setregid(tcp)
946struct tcb *tcp;
947{
948 if (entering(tcp)) {
949 tprintf("%lu, %lu",
950 (unsigned long) (gid_t) tcp->u_arg[0],
951 (unsigned long) (gid_t) tcp->u_arg[1]);
952 }
953 return 0;
954}
955
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000956#if defined(LINUX) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000957int
958sys_setresuid(tcp)
959 struct tcb *tcp;
960{
961 if (entering(tcp)) {
962 tprintf("ruid %u, euid %u, suid %u",
963 (uid_t) tcp->u_arg[0],
964 (uid_t) tcp->u_arg[1],
965 (uid_t) tcp->u_arg[2]);
966 }
967 return 0;
968}
969int
970sys_setresgid(tcp)
971 struct tcb *tcp;
972{
973 if (entering(tcp)) {
974 tprintf("rgid %u, egid %u, sgid %u",
975 (uid_t) tcp->u_arg[0],
976 (uid_t) tcp->u_arg[1],
977 (uid_t) tcp->u_arg[2]);
978 }
979 return 0;
980}
981
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000982#endif /* LINUX || FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000983
984int
985sys_setgroups(tcp)
986struct tcb *tcp;
987{
988 int i, len;
989 GETGROUPS_T *gidset;
990
991 if (entering(tcp)) {
992 len = tcp->u_arg[0];
993 tprintf("%u, ", len);
994 if (len <= 0) {
995 tprintf("[]");
996 return 0;
997 }
998 gidset = (GETGROUPS_T *) malloc(len * sizeof(GETGROUPS_T));
999 if (gidset == NULL) {
1000 fprintf(stderr, "sys_setgroups: out of memory\n");
1001 return -1;
1002 }
1003 if (!verbose(tcp))
1004 tprintf("%#lx", tcp->u_arg[1]);
1005 else if (umoven(tcp, tcp->u_arg[1],
1006 len * sizeof(GETGROUPS_T), (char *) gidset) < 0)
1007 tprintf("[?]");
1008 else {
1009 tprintf("[");
1010 for (i = 0; i < len; i++)
1011 tprintf("%s%lu", i ? ", " : "",
1012 (unsigned long) gidset[i]);
1013 tprintf("]");
1014 }
1015 free((char *) gidset);
1016 }
1017 return 0;
1018}
1019
1020int
1021sys_getgroups(tcp)
1022struct tcb *tcp;
1023{
1024 int i, len;
1025 GETGROUPS_T *gidset;
1026
1027 if (entering(tcp)) {
1028 len = tcp->u_arg[0];
1029 tprintf("%u, ", len);
1030 } else {
1031 len = tcp->u_rval;
1032 if (len <= 0) {
1033 tprintf("[]");
1034 return 0;
1035 }
1036 gidset = (GETGROUPS_T *) malloc(len * sizeof(GETGROUPS_T));
1037 if (gidset == NULL) {
1038 fprintf(stderr, "sys_getgroups: out of memory\n");
1039 return -1;
1040 }
1041 if (!tcp->u_arg[1])
1042 tprintf("NULL");
1043 else if (!verbose(tcp) || tcp->u_arg[0] == 0)
1044 tprintf("%#lx", tcp->u_arg[1]);
1045 else if (umoven(tcp, tcp->u_arg[1],
1046 len * sizeof(GETGROUPS_T), (char *) gidset) < 0)
1047 tprintf("[?]");
1048 else {
1049 tprintf("[");
1050 for (i = 0; i < len; i++)
1051 tprintf("%s%lu", i ? ", " : "",
1052 (unsigned long) gidset[i]);
1053 tprintf("]");
1054 }
1055 free((char *)gidset);
1056 }
1057 return 0;
1058}
1059
1060int
1061sys_setpgrp(tcp)
1062struct tcb *tcp;
1063{
1064 if (entering(tcp)) {
1065#ifndef SVR4
1066 tprintf("%lu, %lu", tcp->u_arg[0], tcp->u_arg[1]);
1067#endif /* !SVR4 */
1068 }
1069 return 0;
1070}
1071
1072int
1073sys_getpgrp(tcp)
1074struct tcb *tcp;
1075{
1076 if (entering(tcp)) {
1077#ifndef SVR4
1078 tprintf("%lu", tcp->u_arg[0]);
1079#endif /* !SVR4 */
1080 }
1081 return 0;
1082}
1083
1084int
1085sys_getsid(tcp)
1086struct tcb *tcp;
1087{
1088 if (entering(tcp)) {
1089 tprintf("%lu", tcp->u_arg[0]);
1090 }
1091 return 0;
1092}
1093
1094int
1095sys_setsid(tcp)
1096struct tcb *tcp;
1097{
1098 return 0;
1099}
1100
1101int
1102sys_getpgid(tcp)
1103struct tcb *tcp;
1104{
1105 if (entering(tcp)) {
1106 tprintf("%lu", tcp->u_arg[0]);
1107 }
1108 return 0;
1109}
1110
1111int
1112sys_setpgid(tcp)
1113struct tcb *tcp;
1114{
1115 if (entering(tcp)) {
1116 tprintf("%lu, %lu", tcp->u_arg[0], tcp->u_arg[1]);
1117 }
1118 return 0;
1119}
1120
John Hughesc61eb3d2002-05-17 11:37:50 +00001121#if UNIXWARE >= 2
1122
1123#include <sys/privilege.h>
1124
1125
1126static struct xlat procpriv_cmds [] = {
1127 { SETPRV, "SETPRV" },
1128 { CLRPRV, "CLRPRV" },
1129 { PUTPRV, "PUTPRV" },
1130 { GETPRV, "GETPRV" },
1131 { CNTPRV, "CNTPRV" },
1132 { 0, NULL },
1133};
1134
1135
1136static struct xlat procpriv_priv [] = {
1137 { P_OWNER, "P_OWNER" },
1138 { P_AUDIT, "P_AUDIT" },
1139 { P_COMPAT, "P_COMPAT" },
1140 { P_DACREAD, "P_DACREAD" },
1141 { P_DACWRITE, "P_DACWRITE" },
1142 { P_DEV, "P_DEV" },
1143 { P_FILESYS, "P_FILESYS" },
1144 { P_MACREAD, "P_MACREAD" },
1145 { P_MACWRITE, "P_MACWRITE" },
1146 { P_MOUNT, "P_MOUNT" },
1147 { P_MULTIDIR, "P_MULTIDIR" },
1148 { P_SETPLEVEL, "P_SETPLEVEL" },
1149 { P_SETSPRIV, "P_SETSPRIV" },
1150 { P_SETUID, "P_SETUID" },
1151 { P_SYSOPS, "P_SYSOPS" },
1152 { P_SETUPRIV, "P_SETUPRIV" },
1153 { P_DRIVER, "P_DRIVER" },
1154 { P_RTIME, "P_RTIME" },
1155 { P_MACUPGRADE, "P_MACUPGRADE" },
1156 { P_FSYSRANGE, "P_FSYSRANGE" },
1157 { P_SETFLEVEL, "P_SETFLEVEL" },
1158 { P_AUDITWR, "P_AUDITWR" },
1159 { P_TSHAR, "P_TSHAR" },
1160 { P_PLOCK, "P_PLOCK" },
1161 { P_CORE, "P_CORE" },
1162 { P_LOADMOD, "P_LOADMOD" },
1163 { P_BIND, "P_BIND" },
1164 { P_ALLPRIVS, "P_ALLPRIVS" },
1165 { 0, NULL },
1166};
1167
1168
1169static struct xlat procpriv_type [] = {
1170 { PS_FIX, "PS_FIX" },
1171 { PS_INH, "PS_INH" },
1172 { PS_MAX, "PS_MAX" },
1173 { PS_WKG, "PS_WKG" },
1174 { 0, NULL },
1175};
1176
1177
1178static void
1179printpriv(tcp, addr, len, opt)
1180struct tcb *tcp;
1181long addr;
1182int len;
1183struct xlat *opt;
1184{
1185 priv_t buf [128];
1186 int max = verbose (tcp) ? sizeof buf / sizeof buf [0] : 10;
1187 int dots = len > max;
1188 int i;
1189
1190 if (len > max) len = max;
1191
1192 if (len <= 0 ||
1193 umoven (tcp, addr, len * sizeof buf[0], (char *) buf) < 0)
1194 {
1195 tprintf ("%#lx", addr);
1196 return;
1197 }
1198
1199 tprintf ("[");
1200
1201 for (i = 0; i < len; ++i) {
1202 char *t, *p;
1203
1204 if (i) tprintf (", ");
1205
1206 if ((t = xlookup (procpriv_type, buf [i] & PS_TYPE)) &&
1207 (p = xlookup (procpriv_priv, buf [i] & ~PS_TYPE)))
1208 {
1209 tprintf ("%s|%s", t, p);
1210 }
1211 else {
1212 tprintf ("%#lx", buf [i]);
1213 }
1214 }
1215
1216 if (dots) tprintf (" ...");
1217
1218 tprintf ("]");
1219}
1220
1221
1222int
1223sys_procpriv(tcp)
1224struct tcb *tcp;
1225{
1226 if (entering(tcp)) {
1227 printxval(procpriv_cmds, tcp->u_arg[0], "???PRV");
1228 switch (tcp->u_arg[0]) {
1229 case CNTPRV:
1230 tprintf(", %#lx, %ld", tcp->u_arg[1], tcp->u_arg[2]);
1231 break;
1232
1233 case GETPRV:
1234 break;
1235
1236 default:
1237 tprintf (", ");
1238 printpriv (tcp, tcp->u_arg[1], tcp->u_arg[2]);
1239 tprintf (", %ld", tcp->u_arg[2]);
1240 }
1241 }
1242 else if (tcp->u_arg[0] == GETPRV) {
1243 if (syserror (tcp)) {
1244 tprintf(", %#lx, %ld", tcp->u_arg[1], tcp->u_arg[2]);
1245 }
1246 else {
1247 tprintf (", ");
1248 printpriv (tcp, tcp->u_arg[1], tcp->u_rval);
1249 tprintf (", %ld", tcp->u_arg[2]);
1250 }
1251 }
1252
1253 return 0;
1254}
1255
1256#endif
1257
1258
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001259void
1260fake_execve(tcp, program, argv, envp)
1261struct tcb *tcp;
1262char *program;
1263char *argv[];
1264char *envp[];
1265{
1266 int i;
1267
1268#ifdef ARM
1269 if (!(qual_flags[SYS_execve - __NR_SYSCALL_BASE] & QUAL_TRACE))
1270 return;
1271#else
1272 if (!(qual_flags[SYS_execve] & QUAL_TRACE))
1273 return;
1274#endif /* !ARM */
1275 printleader(tcp);
1276 tprintf("execve(");
1277 string_quote(program);
1278 tprintf(", [");
1279 for (i = 0; argv[i] != NULL; i++) {
1280 if (i != 0)
1281 tprintf(", ");
1282 string_quote(argv[i]);
1283 }
1284 for (i = 0; envp[i] != NULL; i++)
1285 ;
1286 tprintf("], [/* %d var%s */]) ", i, (i != 1) ? "s" : "");
1287 tabto(acolumn);
1288 tprintf("= 0");
1289 printtrailer(tcp);
1290}
1291
1292static void
1293printargv(tcp, addr)
1294struct tcb *tcp;
1295long addr;
1296{
1297 char *cp;
1298 char *sep;
1299 int max = max_strlen / 2;
1300
1301 for (sep = ""; --max >= 0; sep = ", ") {
1302 if (!abbrev(tcp))
1303 max++;
1304 if (umove(tcp, addr, &cp) < 0) {
1305 tprintf("%#lx", addr);
1306 return;
1307 }
1308 if (cp == 0)
1309 break;
1310 tprintf(sep);
1311 printstr(tcp, (long) cp, -1);
1312 addr += sizeof(char *);
1313 }
1314 if (cp)
1315 tprintf(", ...");
1316}
1317
1318static void
1319printargc(fmt, tcp, addr)
1320char *fmt;
1321struct tcb *tcp;
1322long addr;
1323{
1324 int count;
1325 char *cp;
1326
1327 for (count = 0; umove(tcp, addr, &cp) >= 0 && cp != NULL; count++) {
1328 addr += sizeof(char *);
1329 }
1330 tprintf(fmt, count, count == 1 ? "" : "s");
1331}
1332
1333int
1334sys_execv(tcp)
1335struct tcb *tcp;
1336{
1337 if (entering(tcp)) {
1338 printpath(tcp, tcp->u_arg[0]);
1339 if (!verbose(tcp))
1340 tprintf(", %#lx", tcp->u_arg[1]);
1341#if 0
1342 else if (abbrev(tcp))
1343 printargc(", [/* %d arg%s */]", tcp, tcp->u_arg[1]);
1344#endif
1345 else {
1346 tprintf(", [");
1347 printargv(tcp, tcp->u_arg[1]);
1348 tprintf("]");
1349 }
1350 }
1351 return 0;
1352}
1353
1354int
1355sys_execve(tcp)
1356struct tcb *tcp;
1357{
1358 if (entering(tcp)) {
1359 printpath(tcp, tcp->u_arg[0]);
1360 if (!verbose(tcp))
1361 tprintf(", %#lx", tcp->u_arg[1]);
1362#if 0
1363 else if (abbrev(tcp))
1364 printargc(", [/* %d arg%s */]", tcp, tcp->u_arg[1]);
1365#endif
1366 else {
1367 tprintf(", [");
1368 printargv(tcp, tcp->u_arg[1]);
1369 tprintf("]");
1370 }
1371 if (!verbose(tcp))
1372 tprintf(", %#lx", tcp->u_arg[2]);
1373 else if (abbrev(tcp))
1374 printargc(", [/* %d var%s */]", tcp, tcp->u_arg[2]);
1375 else {
1376 tprintf(", [");
1377 printargv(tcp, tcp->u_arg[2]);
1378 tprintf("]");
1379 }
1380 }
1381#ifdef LINUX
Wichert Akkermanccef6372002-05-01 16:39:22 +00001382#if defined(ALPHA) || defined(SPARC) || defined(POWERPC) || defined(IA64) || defined(HPPA) || defined(SH)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001383 tcp->flags |= TCB_WAITEXECVE;
Wichert Akkermanccef6372002-05-01 16:39:22 +00001384#endif /* ALPHA || SPARC || POWERPC || IA64 || HPPA || SH */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001385#endif /* LINUX */
1386 return 0;
1387}
1388
John Hughes4e36a812001-04-18 15:11:51 +00001389#if UNIXWARE > 2
1390
1391int sys_rexecve(tcp)
1392struct tcb *tcp;
1393{
1394 if (entering (tcp)) {
1395 sys_execve (tcp);
1396 tprintf (", %ld", tcp->u_arg[3]);
1397 }
1398 return 0;
1399}
1400
1401#endif
1402
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001403int
1404internal_exec(tcp)
1405struct tcb *tcp;
1406{
1407#ifdef SUNOS4
1408 if (exiting(tcp) && !syserror(tcp) && followfork)
1409 fixvfork(tcp);
1410#endif /* SUNOS4 */
1411 return 0;
1412}
1413
1414#ifdef LINUX
1415#ifndef __WCLONE
1416#define __WCLONE 0x8000000
1417#endif
1418#endif /* LINUX */
1419
1420static struct xlat wait4_options[] = {
1421 { WNOHANG, "WNOHANG" },
1422#ifndef WSTOPPED
1423 { WUNTRACED, "WUNTRACED" },
1424#endif
1425#ifdef WEXITED
1426 { WEXITED, "WEXITED" },
1427#endif
1428#ifdef WTRAPPED
1429 { WTRAPPED, "WTRAPPED" },
1430#endif
1431#ifdef WSTOPPED
1432 { WSTOPPED, "WSTOPPED" },
1433#endif
1434#ifdef WCONTINUED
1435 { WCONTINUED, "WCONTINUED" },
1436#endif
1437#ifdef WNOWAIT
1438 { WNOWAIT, "WNOWAIT" },
1439#endif
1440#ifdef __WCLONE
1441 { __WCLONE, "__WCLONE" },
1442#endif
1443 { 0, NULL },
1444};
1445
1446static int
1447printstatus(status)
1448int status;
1449{
1450 int exited = 0;
1451
1452 /*
1453 * Here is a tricky presentation problem. This solution
1454 * is still not entirely satisfactory but since there
1455 * are no wait status constructors it will have to do.
1456 */
1457 if (WIFSTOPPED(status))
1458 tprintf("[WIFSTOPPED(s) && WSTOPSIG(s) == %s]",
Nate Sammonsce780fc1999-03-29 23:23:13 +00001459 signame(WSTOPSIG(status)));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001460 else if WIFSIGNALED(status)
1461 tprintf("[WIFSIGNALED(s) && WTERMSIG(s) == %s%s]",
Nate Sammonsce780fc1999-03-29 23:23:13 +00001462 signame(WTERMSIG(status)),
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001463 WCOREDUMP(status) ? " && WCOREDUMP(s)" : "");
1464 else if WIFEXITED(status) {
1465 tprintf("[WIFEXITED(s) && WEXITSTATUS(s) == %d]",
1466 WEXITSTATUS(status));
1467 exited = 1;
1468 }
1469 else
1470 tprintf("[%#x]", status);
1471 return exited;
1472}
1473
1474static int
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001475printwaitn(tcp, n, bitness)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001476struct tcb *tcp;
1477int n;
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001478int bitness;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001479{
1480 int status;
1481 int exited = 0;
1482
1483 if (entering(tcp)) {
1484 tprintf("%ld, ", tcp->u_arg[0]);
1485 } else {
1486 /* status */
1487 if (!tcp->u_arg[1])
1488 tprintf("NULL");
1489 else if (syserror(tcp) || tcp->u_rval == 0)
1490 tprintf("%#lx", tcp->u_arg[1]);
1491 else if (umove(tcp, tcp->u_arg[1], &status) < 0)
1492 tprintf("[?]");
1493 else
1494 exited = printstatus(status);
1495 /* options */
1496 tprintf(", ");
1497 if (!printflags(wait4_options, tcp->u_arg[2]))
1498 tprintf("0");
1499 if (n == 4) {
1500 tprintf(", ");
1501 /* usage */
1502 if (!tcp->u_arg[3])
1503 tprintf("NULL");
1504#ifdef LINUX
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001505 else if (tcp->u_rval > 0) {
1506#ifdef LINUX_64BIT
1507 if (bitness)
1508 printrusage32(tcp, tcp->u_arg[3]);
1509 else
1510#endif
1511 printrusage(tcp, tcp->u_arg[3]);
1512 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001513#endif /* LINUX */
1514#ifdef SUNOS4
1515 else if (tcp->u_rval > 0 && exited)
1516 printrusage(tcp, tcp->u_arg[3]);
1517#endif /* SUNOS4 */
1518 else
1519 tprintf("%#lx", tcp->u_arg[3]);
1520 }
1521 }
1522 return 0;
1523}
1524
1525int
1526internal_wait(tcp)
1527struct tcb *tcp;
1528{
1529 if (entering(tcp)) {
Wichert Akkerman5daa0281999-03-15 19:49:42 +00001530 /* WTA: fix bug with hanging children */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001531 if (!(tcp->u_arg[2] & WNOHANG) && tcp->nchildren > 0) {
1532 /* There are traced children */
1533 tcp->flags |= TCB_SUSPENDED;
1534 tcp->waitpid = tcp->u_arg[0];
1535 }
1536 }
1537 return 0;
1538}
1539
1540#ifdef SVR4
1541
1542int
1543sys_wait(tcp)
1544struct tcb *tcp;
1545{
1546 if (exiting(tcp)) {
1547 /* The library wrapper stuffs this into the user variable. */
1548 if (!syserror(tcp))
1549 printstatus(getrval2(tcp));
1550 }
1551 return 0;
1552}
1553
1554#endif /* SVR4 */
1555
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001556#ifdef FREEBSD
1557int
1558sys_wait(tcp)
1559struct tcb *tcp;
1560{
1561 int status;
1562
1563 if (exiting(tcp)) {
1564 if (!syserror(tcp)) {
1565 if (umove(tcp, tcp->u_arg[0], &status) < 0)
1566 tprintf("%#lx", tcp->u_arg[0]);
1567 else
1568 printstatus(status);
1569 }
1570 }
1571 return 0;
1572}
1573#endif
1574
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001575int
1576sys_waitpid(tcp)
1577struct tcb *tcp;
1578{
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001579 return printwaitn(tcp, 3, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001580}
1581
1582int
1583sys_wait4(tcp)
1584struct tcb *tcp;
1585{
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001586 return printwaitn(tcp, 4, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001587}
1588
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001589#ifdef ALPHA
1590int
1591sys_osf_wait4(tcp)
1592struct tcb *tcp;
1593{
1594 return printwaitn(tcp, 4, 1);
1595}
1596#endif
1597
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001598#ifdef SVR4
1599
1600static struct xlat waitid_types[] = {
1601 { P_PID, "P_PID" },
1602 { P_PPID, "P_PPID" },
1603 { P_PGID, "P_PGID" },
1604 { P_SID, "P_SID" },
1605 { P_CID, "P_CID" },
1606 { P_UID, "P_UID" },
1607 { P_GID, "P_GID" },
1608 { P_ALL, "P_ALL" },
1609#ifdef P_LWPID
1610 { P_LWPID, "P_LWPID" },
1611#endif
1612 { 0, NULL },
1613};
1614
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001615int
1616sys_waitid(tcp)
1617struct tcb *tcp;
1618{
1619 siginfo_t si;
1620 int exited;
1621
1622 if (entering(tcp)) {
1623 printxval(waitid_types, tcp->u_arg[0], "P_???");
1624 tprintf(", %ld, ", tcp->u_arg[1]);
1625 if (tcp->nchildren > 0) {
1626 /* There are traced children */
1627 tcp->flags |= TCB_SUSPENDED;
1628 tcp->waitpid = tcp->u_arg[0];
1629 }
1630 }
1631 else {
1632 /* siginfo */
1633 exited = 0;
1634 if (!tcp->u_arg[2])
1635 tprintf("NULL");
1636 else if (syserror(tcp))
1637 tprintf("%#lx", tcp->u_arg[2]);
1638 else if (umove(tcp, tcp->u_arg[2], &si) < 0)
1639 tprintf("{???}");
1640 else
John Hughes58265892001-10-18 15:13:53 +00001641 printsiginfo(&si, verbose (tcp));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001642 /* options */
1643 tprintf(", ");
1644 if (!printflags(wait4_options, tcp->u_arg[3]))
1645 tprintf("0");
1646 }
1647 return 0;
1648}
1649
1650#endif /* SVR4 */
1651
1652int
1653sys_alarm(tcp)
1654struct tcb *tcp;
1655{
1656 if (entering(tcp))
1657 tprintf("%lu", tcp->u_arg[0]);
1658 return 0;
1659}
1660
1661int
1662sys_uname(tcp)
1663struct tcb *tcp;
1664{
1665 struct utsname uname;
1666
1667 if (exiting(tcp)) {
1668 if (syserror(tcp) || !verbose(tcp))
1669 tprintf("%#lx", tcp->u_arg[0]);
1670 else if (umove(tcp, tcp->u_arg[0], &uname) < 0)
1671 tprintf("{...}");
1672 else if (!abbrev(tcp)) {
1673
1674 tprintf("{sysname=\"%s\", nodename=\"%s\", ",
1675 uname.sysname, uname.nodename);
1676 tprintf("release=\"%s\", version=\"%s\", ",
1677 uname.release, uname.version);
1678 tprintf("machine=\"%s\"", uname.machine);
1679#ifdef LINUX
1680#ifndef __GLIBC__
1681 tprintf(", domainname=\"%s\"", uname.domainname);
1682#endif /* __GLIBC__ */
1683#endif /* LINUX */
1684 tprintf("}");
1685 }
1686 else
1687 tprintf("{sys=\"%s\", node=\"%s\", ...}",
1688 uname.sysname, uname.nodename);
1689 }
1690 return 0;
1691}
1692
1693#ifndef SVR4
1694
1695static struct xlat ptrace_cmds[] = {
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001696#ifndef FREEBSD
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001697 { PTRACE_TRACEME, "PTRACE_TRACEME" },
1698 { PTRACE_PEEKTEXT, "PTRACE_PEEKTEXT", },
1699 { PTRACE_PEEKDATA, "PTRACE_PEEKDATA", },
1700 { PTRACE_PEEKUSER, "PTRACE_PEEKUSER", },
1701 { PTRACE_POKETEXT, "PTRACE_POKETEXT", },
1702 { PTRACE_POKEDATA, "PTRACE_POKEDATA", },
1703 { PTRACE_POKEUSER, "PTRACE_POKEUSER", },
1704 { PTRACE_CONT, "PTRACE_CONT" },
1705 { PTRACE_KILL, "PTRACE_KILL" },
1706 { PTRACE_SINGLESTEP, "PTRACE_SINGLESTEP" },
1707 { PTRACE_ATTACH, "PTRACE_ATTACH" },
1708 { PTRACE_DETACH, "PTRACE_DETACH" },
1709#ifdef SUNOS4
1710 { PTRACE_GETREGS, "PTRACE_GETREGS" },
1711 { PTRACE_SETREGS, "PTRACE_SETREGS" },
1712 { PTRACE_GETFPREGS, "PTRACE_GETFPREGS", },
1713 { PTRACE_SETFPREGS, "PTRACE_SETFPREGS", },
1714 { PTRACE_READDATA, "PTRACE_READDATA" },
1715 { PTRACE_WRITEDATA, "PTRACE_WRITEDATA" },
1716 { PTRACE_READTEXT, "PTRACE_READTEXT" },
1717 { PTRACE_WRITETEXT, "PTRACE_WRITETEXT" },
1718 { PTRACE_GETFPAREGS, "PTRACE_GETFPAREGS" },
1719 { PTRACE_SETFPAREGS, "PTRACE_SETFPAREGS" },
1720#ifdef SPARC
1721 { PTRACE_GETWINDOW, "PTRACE_GETWINDOW" },
1722 { PTRACE_SETWINDOW, "PTRACE_SETWINDOW" },
1723#else /* !SPARC */
1724 { PTRACE_22, "PTRACE_PTRACE_22" },
1725 { PTRACE_23, "PTRACE_PTRACE_23" },
1726#endif /* !SPARC */
1727#endif /* SUNOS4 */
1728 { PTRACE_SYSCALL, "PTRACE_SYSCALL" },
1729#ifdef SUNOS4
1730 { PTRACE_DUMPCORE, "PTRACE_DUMPCORE" },
1731#ifdef I386
1732 { PTRACE_SETWRBKPT, "PTRACE_SETWRBKPT" },
1733 { PTRACE_SETACBKPT, "PTRACE_SETACBKPT" },
1734 { PTRACE_CLRDR7, "PTRACE_CLRDR7" },
1735#else /* !I386 */
1736 { PTRACE_26, "PTRACE_26" },
1737 { PTRACE_27, "PTRACE_27" },
1738 { PTRACE_28, "PTRACE_28" },
1739#endif /* !I386 */
1740 { PTRACE_GETUCODE, "PTRACE_GETUCODE" },
1741#endif /* SUNOS4 */
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001742#else /* FREEBSD */
1743 { PT_TRACE_ME, "PT_TRACE_ME" },
1744 { PT_READ_I, "PT_READ_I" },
1745 { PT_READ_D, "PT_READ_D" },
1746 { PT_WRITE_I, "PT_WRITE_I" },
1747 { PT_WRITE_D, "PT_WRITE_D" },
John Hughesa2278142001-09-28 16:21:30 +00001748#ifdef PT_READ_U
1749 { PT_READ_U, "PT_READ_U" },
1750#endif
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001751 { PT_CONTINUE, "PT_CONTINUE" },
1752 { PT_KILL, "PT_KILL" },
1753 { PT_STEP, "PT_STEP" },
1754 { PT_ATTACH, "PT_ATTACH" },
1755 { PT_DETACH, "PT_DETACH" },
1756 { PT_GETREGS, "PT_GETREGS" },
1757 { PT_SETREGS, "PT_SETREGS" },
1758 { PT_GETFPREGS, "PT_GETFPREGS" },
1759 { PT_SETFPREGS, "PT_SETFPREGS" },
1760 { PT_GETDBREGS, "PT_GETDBREGS" },
1761 { PT_SETDBREGS, "PT_SETDBREGS" },
1762#endif /* FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001763 { 0, NULL },
1764};
1765
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001766#ifndef FREEBSD
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001767#ifndef SUNOS4_KERNEL_ARCH_KLUDGE
1768static
1769#endif /* !SUNOS4_KERNEL_ARCH_KLUDGE */
1770struct xlat struct_user_offsets[] = {
1771#ifdef LINUX
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00001772#ifdef S390
1773 { PT_PSWMASK, "psw_mask" },
1774 { PT_PSWADDR, "psw_addr" },
1775 { PT_GPR0, "gpr0" },
1776 { PT_GPR1, "gpr1" },
1777 { PT_GPR2, "gpr2" },
1778 { PT_GPR3, "gpr3" },
1779 { PT_GPR4, "gpr4" },
1780 { PT_GPR5, "gpr5" },
1781 { PT_GPR6, "gpr6" },
1782 { PT_GPR7, "gpr7" },
1783 { PT_GPR8, "gpr8" },
1784 { PT_GPR9, "gpr9" },
1785 { PT_GPR10, "gpr10" },
1786 { PT_GPR11, "gpr11" },
1787 { PT_GPR12, "gpr12" },
1788 { PT_GPR13, "gpr13" },
1789 { PT_GPR14, "gpr14" },
1790 { PT_GPR15, "gpr15" },
1791 { PT_ACR0, "acr0" },
1792 { PT_ACR1, "acr1" },
1793 { PT_ACR2, "acr2" },
1794 { PT_ACR3, "acr3" },
1795 { PT_ACR4, "acr4" },
1796 { PT_ACR5, "acr5" },
1797 { PT_ACR6, "acr6" },
1798 { PT_ACR7, "acr7" },
1799 { PT_ACR8, "acr8" },
1800 { PT_ACR9, "acr9" },
1801 { PT_ACR10, "acr10" },
1802 { PT_ACR11, "acr11" },
1803 { PT_ACR12, "acr12" },
1804 { PT_ACR13, "acr13" },
1805 { PT_ACR14, "acr14" },
1806 { PT_ACR15, "acr15" },
1807 { PT_ORIGGPR2, "orig_gpr2" },
1808 { PT_FPC, "fpc" },
1809 { PT_FPR0_HI, "fpr0.hi" },
1810 { PT_FPR0_LO, "fpr0.lo" },
1811 { PT_FPR1_HI, "fpr1.hi" },
1812 { PT_FPR1_LO, "fpr1.lo" },
1813 { PT_FPR2_HI, "fpr2.hi" },
1814 { PT_FPR2_LO, "fpr2.lo" },
1815 { PT_FPR3_HI, "fpr3.hi" },
1816 { PT_FPR3_LO, "fpr3.lo" },
1817 { PT_FPR4_HI, "fpr4.hi" },
1818 { PT_FPR4_LO, "fpr4.lo" },
1819 { PT_FPR5_HI, "fpr5.hi" },
1820 { PT_FPR5_LO, "fpr5.lo" },
1821 { PT_FPR6_HI, "fpr6.hi" },
1822 { PT_FPR6_LO, "fpr6.lo" },
1823 { PT_FPR7_HI, "fpr7.hi" },
1824 { PT_FPR7_LO, "fpr7.lo" },
1825 { PT_FPR8_HI, "fpr8.hi" },
1826 { PT_FPR8_LO, "fpr8.lo" },
1827 { PT_FPR9_HI, "fpr9.hi" },
1828 { PT_FPR9_LO, "fpr9.lo" },
1829 { PT_FPR10_HI, "fpr10.hi" },
1830 { PT_FPR10_LO, "fpr10.lo" },
1831 { PT_FPR11_HI, "fpr11.hi" },
1832 { PT_FPR11_LO, "fpr11.lo" },
1833 { PT_FPR12_HI, "fpr12.hi" },
1834 { PT_FPR12_LO, "fpr12.lo" },
1835 { PT_FPR13_HI, "fpr13.hi" },
1836 { PT_FPR13_LO, "fpr13.lo" },
1837 { PT_FPR14_HI, "fpr14.hi" },
1838 { PT_FPR14_LO, "fpr14.lo" },
1839 { PT_FPR15_HI, "fpr15.hi" },
1840 { PT_FPR15_LO, "fpr15.lo" },
1841 { PT_CR_9, "cr9" },
1842 { PT_CR_10, "cr10" },
1843 { PT_CR_11, "cr11" },
1844#endif
1845#if defined(SPARC)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001846 /* XXX No support for these offsets yet. */
Wichert Akkermanc1652e22001-03-27 12:17:16 +00001847#elif defined(HPPA)
1848 /* XXX No support for these offsets yet. */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001849#elif defined(POWERPC)
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00001850 { 4*PT_R0, "4*PT_R0" },
1851 { 4*PT_R1, "4*PT_R1" },
1852 { 4*PT_R2, "4*PT_R2" },
1853 { 4*PT_R3, "4*PT_R3" },
1854 { 4*PT_R4, "4*PT_R4" },
1855 { 4*PT_R5, "4*PT_R5" },
1856 { 4*PT_R6, "4*PT_R6" },
1857 { 4*PT_R7, "4*PT_R7" },
1858 { 4*PT_R8, "4*PT_R8" },
1859 { 4*PT_R9, "4*PT_R9" },
1860 { 4*PT_R10, "4*PT_R10" },
1861 { 4*PT_R11, "4*PT_R11" },
1862 { 4*PT_R12, "4*PT_R12" },
1863 { 4*PT_R13, "4*PT_R13" },
1864 { 4*PT_R14, "4*PT_R14" },
1865 { 4*PT_R15, "4*PT_R15" },
1866 { 4*PT_R16, "4*PT_R16" },
1867 { 4*PT_R17, "4*PT_R17" },
1868 { 4*PT_R18, "4*PT_R18" },
1869 { 4*PT_R19, "4*PT_R19" },
1870 { 4*PT_R20, "4*PT_R20" },
1871 { 4*PT_R21, "4*PT_R21" },
1872 { 4*PT_R22, "4*PT_R22" },
1873 { 4*PT_R23, "4*PT_R23" },
1874 { 4*PT_R24, "4*PT_R24" },
1875 { 4*PT_R25, "4*PT_R25" },
1876 { 4*PT_R26, "4*PT_R26" },
1877 { 4*PT_R27, "4*PT_R27" },
1878 { 4*PT_R28, "4*PT_R28" },
1879 { 4*PT_R29, "4*PT_R29" },
1880 { 4*PT_R30, "4*PT_R30" },
1881 { 4*PT_R31, "4*PT_R31" },
1882 { 4*PT_NIP, "4*PT_NIP" },
1883 { 4*PT_MSR, "4*PT_MSR" },
1884 { 4*PT_ORIG_R3, "4*PT_ORIG_R3" },
1885 { 4*PT_CTR, "4*PT_CTR" },
1886 { 4*PT_LNK, "4*PT_LNK" },
1887 { 4*PT_XER, "4*PT_XER" },
1888 { 4*PT_CCR, "4*PT_CCR" },
1889 { 4*PT_FPR0, "4*PT_FPR0" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001890#else
1891#ifdef ALPHA
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00001892 { 0, "r0" },
1893 { 1, "r1" },
1894 { 2, "r2" },
1895 { 3, "r3" },
1896 { 4, "r4" },
1897 { 5, "r5" },
1898 { 6, "r6" },
1899 { 7, "r7" },
1900 { 8, "r8" },
1901 { 9, "r9" },
1902 { 10, "r10" },
1903 { 11, "r11" },
1904 { 12, "r12" },
1905 { 13, "r13" },
1906 { 14, "r14" },
1907 { 15, "r15" },
1908 { 16, "r16" },
1909 { 17, "r17" },
1910 { 18, "r18" },
1911 { 19, "r19" },
1912 { 20, "r20" },
1913 { 21, "r21" },
1914 { 22, "r22" },
1915 { 23, "r23" },
1916 { 24, "r24" },
1917 { 25, "r25" },
1918 { 26, "r26" },
1919 { 27, "r27" },
1920 { 28, "r28" },
1921 { 29, "gp" },
1922 { 30, "fp" },
1923 { 31, "zero" },
1924 { 32, "fp0" },
1925 { 33, "fp" },
1926 { 34, "fp2" },
1927 { 35, "fp3" },
1928 { 36, "fp4" },
1929 { 37, "fp5" },
1930 { 38, "fp6" },
1931 { 39, "fp7" },
1932 { 40, "fp8" },
1933 { 41, "fp9" },
1934 { 42, "fp10" },
1935 { 43, "fp11" },
1936 { 44, "fp12" },
1937 { 45, "fp13" },
1938 { 46, "fp14" },
1939 { 47, "fp15" },
1940 { 48, "fp16" },
1941 { 49, "fp17" },
1942 { 50, "fp18" },
1943 { 51, "fp19" },
1944 { 52, "fp20" },
1945 { 53, "fp21" },
1946 { 54, "fp22" },
1947 { 55, "fp23" },
1948 { 56, "fp24" },
1949 { 57, "fp25" },
1950 { 58, "fp26" },
1951 { 59, "fp27" },
1952 { 60, "fp28" },
1953 { 61, "fp29" },
1954 { 62, "fp30" },
1955 { 63, "fp31" },
1956 { 64, "pc" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001957#else /* !ALPHA */
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001958#ifdef IA64
1959 { PT_F32, "f32" }, { PT_F33, "f33" }, { PT_F34, "f34" },
1960 { PT_F35, "f35" }, { PT_F36, "f36" }, { PT_F37, "f37" },
1961 { PT_F38, "f38" }, { PT_F39, "f39" }, { PT_F40, "f40" },
1962 { PT_F41, "f41" }, { PT_F42, "f42" }, { PT_F43, "f43" },
1963 { PT_F44, "f44" }, { PT_F45, "f45" }, { PT_F46, "f46" },
1964 { PT_F47, "f47" }, { PT_F48, "f48" }, { PT_F49, "f49" },
1965 { PT_F50, "f50" }, { PT_F51, "f51" }, { PT_F52, "f52" },
1966 { PT_F53, "f53" }, { PT_F54, "f54" }, { PT_F55, "f55" },
1967 { PT_F56, "f56" }, { PT_F57, "f57" }, { PT_F58, "f58" },
1968 { PT_F59, "f59" }, { PT_F60, "f60" }, { PT_F61, "f61" },
1969 { PT_F62, "f62" }, { PT_F63, "f63" }, { PT_F64, "f64" },
1970 { PT_F65, "f65" }, { PT_F66, "f66" }, { PT_F67, "f67" },
1971 { PT_F68, "f68" }, { PT_F69, "f69" }, { PT_F70, "f70" },
1972 { PT_F71, "f71" }, { PT_F72, "f72" }, { PT_F73, "f73" },
1973 { PT_F74, "f74" }, { PT_F75, "f75" }, { PT_F76, "f76" },
1974 { PT_F77, "f77" }, { PT_F78, "f78" }, { PT_F79, "f79" },
1975 { PT_F80, "f80" }, { PT_F81, "f81" }, { PT_F82, "f82" },
1976 { PT_F83, "f83" }, { PT_F84, "f84" }, { PT_F85, "f85" },
1977 { PT_F86, "f86" }, { PT_F87, "f87" }, { PT_F88, "f88" },
1978 { PT_F89, "f89" }, { PT_F90, "f90" }, { PT_F91, "f91" },
1979 { PT_F92, "f92" }, { PT_F93, "f93" }, { PT_F94, "f94" },
1980 { PT_F95, "f95" }, { PT_F96, "f96" }, { PT_F97, "f97" },
1981 { PT_F98, "f98" }, { PT_F99, "f99" }, { PT_F100, "f100" },
1982 { PT_F101, "f101" }, { PT_F102, "f102" }, { PT_F103, "f103" },
1983 { PT_F104, "f104" }, { PT_F105, "f105" }, { PT_F106, "f106" },
1984 { PT_F107, "f107" }, { PT_F108, "f108" }, { PT_F109, "f109" },
1985 { PT_F110, "f110" }, { PT_F111, "f111" }, { PT_F112, "f112" },
1986 { PT_F113, "f113" }, { PT_F114, "f114" }, { PT_F115, "f115" },
1987 { PT_F116, "f116" }, { PT_F117, "f117" }, { PT_F118, "f118" },
1988 { PT_F119, "f119" }, { PT_F120, "f120" }, { PT_F121, "f121" },
1989 { PT_F122, "f122" }, { PT_F123, "f123" }, { PT_F124, "f124" },
1990 { PT_F125, "f125" }, { PT_F126, "f126" }, { PT_F127, "f127" },
1991 /* switch stack: */
1992 { PT_F2, "f2" }, { PT_F3, "f3" }, { PT_F4, "f4" },
1993 { PT_F5, "f5" }, { PT_F10, "f10" }, { PT_F11, "f11" },
1994 { PT_F12, "f12" }, { PT_F13, "f13" }, { PT_F14, "f14" },
1995 { PT_F15, "f15" }, { PT_F16, "f16" }, { PT_F17, "f17" },
1996 { PT_F18, "f18" }, { PT_F19, "f19" }, { PT_F20, "f20" },
1997 { PT_F21, "f21" }, { PT_F22, "f22" }, { PT_F23, "f23" },
1998 { PT_F24, "f24" }, { PT_F25, "f25" }, { PT_F26, "f26" },
1999 { PT_F27, "f27" }, { PT_F28, "f28" }, { PT_F29, "f29" },
2000 { PT_F30, "f30" }, { PT_F31, "f31" }, { PT_R4, "r4" },
2001 { PT_R5, "r5" }, { PT_R6, "r6" }, { PT_R7, "r7" },
Wichert Akkerman82b162e2001-08-03 11:51:28 +00002002 { PT_B0, "kb0" },
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00002003 { PT_B1, "b1" }, { PT_B2, "b2" }, { PT_B3, "b3" },
2004 { PT_B4, "b4" }, { PT_B5, "b5" },
Wichert Akkerman82b162e2001-08-03 11:51:28 +00002005 { PT_AR_PFS, "kar.pfs" },
2006 { PT_AR_LC, "ar.lc" }, { PT_AR_UNAT, "kar.unat" },
2007 { PT_AR_RNAT, "kar.rnat" }, { PT_AR_BSPSTORE, "kar.bspstore" },
2008 { PT_PR, "k.pr" },
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00002009 /* pt_regs */
2010 { PT_CR_IPSR, "cr.ipsr" }, { PT_CR_IIP, "cr.iip" },
Wichert Akkerman82b162e2001-08-03 11:51:28 +00002011 /*{ PT_CR_IFS, "cr.ifs" },*/ { PT_AR_UNAT, "ar.unat" },
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00002012 { PT_AR_PFS, "ar.pfs" }, { PT_AR_RSC, "ar.rsc" },
2013 { PT_AR_RNAT, "ar.rnat" }, { PT_AR_BSPSTORE, "ar.bspstore" },
2014 { PT_PR, "pr" }, { PT_B6, "b6" }, { PT_AR_BSP, "ar.bsp" },
2015 { PT_R1, "r1" }, { PT_R2, "r2" }, { PT_R3, "r3" },
2016 { PT_R12, "r12" }, { PT_R13, "r13" }, { PT_R14, "r14" },
2017 { PT_R15, "r15" }, { PT_R8, "r8" }, { PT_R9, "r9" },
2018 { PT_R10, "r10" }, { PT_R11, "r11" }, { PT_R16, "r16" },
2019 { PT_R17, "r17" }, { PT_R18, "r18" }, { PT_R19, "r19" },
2020 { PT_R20, "r20" }, { PT_R21, "r21" }, { PT_R22, "r22" },
2021 { PT_R23, "r23" }, { PT_R24, "r24" }, { PT_R25, "r25" },
2022 { PT_R26, "r26" }, { PT_R27, "r27" }, { PT_R28, "r28" },
2023 { PT_R29, "r29" }, { PT_R30, "r30" }, { PT_R31, "r31" },
2024 { PT_AR_CCV, "ar.ccv" }, { PT_AR_FPSR, "ar.fpsr" },
2025 { PT_B0, "b0" }, { PT_B7, "b7" }, { PT_F6, "f6" },
2026 { PT_F7, "f7" }, { PT_F8, "f8" }, { PT_F9, "f9" },
2027#else /* !IA64 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002028#ifdef I386
2029 { 4*EBX, "4*EBX" },
2030 { 4*ECX, "4*ECX" },
2031 { 4*EDX, "4*EDX" },
2032 { 4*ESI, "4*ESI" },
2033 { 4*EDI, "4*EDI" },
2034 { 4*EBP, "4*EBP" },
2035 { 4*EAX, "4*EAX" },
2036 { 4*DS, "4*DS" },
2037 { 4*ES, "4*ES" },
2038 { 4*FS, "4*FS" },
2039 { 4*GS, "4*GS" },
2040 { 4*ORIG_EAX, "4*ORIG_EAX" },
2041 { 4*EIP, "4*EIP" },
2042 { 4*CS, "4*CS" },
2043 { 4*EFL, "4*EFL" },
2044 { 4*UESP, "4*UESP" },
2045 { 4*SS, "4*SS" },
2046#else /* !I386 */
Michal Ludvig0e035502002-09-23 15:41:01 +00002047#ifdef X86_64
2048 { 8*RDI, "8*RDI" },
2049 { 8*RSI, "8*RSI" },
2050 { 8*RDX, "8*RDX" },
2051 { 8*R10, "8*R10" },
2052 { 8*R8, "8*R8" },
2053 { 8*R9, "8*R9" },
2054 { 8*RBX, "8*RBX" },
2055 { 8*RCX, "8*RCX" },
2056 { 8*RBP, "8*RBP" },
2057 { 8*RAX, "8*RAX" },
2058#if 0
2059 { 8*DS, "8*DS" },
2060 { 8*ES, "8*ES" },
2061 { 8*FS, "8*FS" },
2062 { 8*GS, "8*GS" },
2063#endif
2064 { 8*ORIG_RAX, "8*ORIG_EAX" },
2065 { 8*RIP, "8*RIP" },
2066 { 8*CS, "8*CS" },
2067 { 8*EFLAGS, "8*EFL" },
2068 { 8*RSP, "8*RSP" },
2069 { 8*SS, "8*SS" },
2070 { 8*R11, "8*R11" },
2071 { 8*R12, "8*R12" },
2072 { 8*R13, "8*R13" },
2073 { 8*R14, "8*R14" },
2074 { 8*R15, "8*R15" },
2075#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002076#ifdef M68K
2077 { 4*PT_D1, "4*PT_D1" },
2078 { 4*PT_D2, "4*PT_D2" },
2079 { 4*PT_D3, "4*PT_D3" },
2080 { 4*PT_D4, "4*PT_D4" },
2081 { 4*PT_D5, "4*PT_D5" },
2082 { 4*PT_D6, "4*PT_D6" },
2083 { 4*PT_D7, "4*PT_D7" },
2084 { 4*PT_A0, "4*PT_A0" },
2085 { 4*PT_A1, "4*PT_A1" },
2086 { 4*PT_A2, "4*PT_A2" },
2087 { 4*PT_A3, "4*PT_A3" },
2088 { 4*PT_A4, "4*PT_A4" },
2089 { 4*PT_A5, "4*PT_A5" },
2090 { 4*PT_A6, "4*PT_A6" },
2091 { 4*PT_D0, "4*PT_D0" },
2092 { 4*PT_USP, "4*PT_USP" },
2093 { 4*PT_ORIG_D0, "4*PT_ORIG_D0" },
2094 { 4*PT_SR, "4*PT_SR" },
2095 { 4*PT_PC, "4*PT_PC" },
2096#endif /* M68K */
2097#endif /* !I386 */
Wichert Akkermanccef6372002-05-01 16:39:22 +00002098#ifdef SH
2099 { 4*REG_REG0, "4*REG_REG0" },
2100 { 4*(REG_REG0+1), "4*REG_REG1" },
2101 { 4*(REG_REG0+2), "4*REG_REG2" },
2102 { 4*(REG_REG0+3), "4*REG_REG3" },
2103 { 4*(REG_REG0+4), "4*REG_REG4" },
2104 { 4*(REG_REG0+5), "4*REG_REG5" },
2105 { 4*(REG_REG0+6), "4*REG_REG6" },
2106 { 4*(REG_REG0+7), "4*REG_REG7" },
2107 { 4*(REG_REG0+8), "4*REG_REG8" },
2108 { 4*(REG_REG0+9), "4*REG_REG9" },
2109 { 4*(REG_REG0+10), "4*REG_REG10" },
2110 { 4*(REG_REG0+11), "4*REG_REG11" },
2111 { 4*(REG_REG0+12), "4*REG_REG12" },
2112 { 4*(REG_REG0+13), "4*REG_REG13" },
2113 { 4*(REG_REG0+14), "4*REG_REG14" },
2114 { 4*REG_REG15, "4*REG_REG15" },
2115 { 4*REG_PC, "4*REG_PC" },
2116 { 4*REG_PR, "4*REG_PR" },
2117 { 4*REG_SR, "4*REG_SR" },
2118 { 4*REG_GBR, "4*REG_GBR" },
2119 { 4*REG_MACH, "4*REG_MACH" },
2120 { 4*REG_MACL, "4*REG_MACL" },
2121 { 4*REG_SYSCALL, "4*REG_SYSCALL" },
2122 { 4*REG_FPUL, "4*REG_FPUL" },
2123 { 4*REG_FPREG0, "4*REG_FPREG0" },
2124 { 4*(REG_FPREG0+1), "4*REG_FPREG1" },
2125 { 4*(REG_FPREG0+2), "4*REG_FPREG2" },
2126 { 4*(REG_FPREG0+3), "4*REG_FPREG3" },
2127 { 4*(REG_FPREG0+4), "4*REG_FPREG4" },
2128 { 4*(REG_FPREG0+5), "4*REG_FPREG5" },
2129 { 4*(REG_FPREG0+6), "4*REG_FPREG6" },
2130 { 4*(REG_FPREG0+7), "4*REG_FPREG7" },
2131 { 4*(REG_FPREG0+8), "4*REG_FPREG8" },
2132 { 4*(REG_FPREG0+9), "4*REG_FPREG9" },
2133 { 4*(REG_FPREG0+10), "4*REG_FPREG10" },
2134 { 4*(REG_FPREG0+11), "4*REG_FPREG11" },
2135 { 4*(REG_FPREG0+12), "4*REG_FPREG12" },
2136 { 4*(REG_FPREG0+13), "4*REG_FPREG13" },
2137 { 4*(REG_FPREG0+14), "4*REG_FPREG14" },
2138 { 4*REG_FPREG15, "4*REG_FPREG15" },
2139 { 4*REG_XDREG0, "4*REG_XDREG0" },
2140 { 4*(REG_XDREG0+2), "4*REG_XDREG2" },
2141 { 4*(REG_XDREG0+4), "4*REG_XDREG4" },
2142 { 4*(REG_XDREG0+6), "4*REG_XDREG6" },
2143 { 4*(REG_XDREG0+8), "4*REG_XDREG8" },
2144 { 4*(REG_XDREG0+10), "4*REG_XDREG10" },
2145 { 4*(REG_XDREG0+12), "4*REG_XDREG12" },
2146 { 4*REG_XDREG14, "4*REG_XDREG14" },
2147 { 4*REG_FPSCR, "4*REG_FPSCR" },
2148#endif /* SH */
2149
Wichert Akkerman12f75d12000-02-14 16:23:40 +00002150#if !defined(S390) && !defined(MIPS)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002151 { uoff(u_fpvalid), "offsetof(struct user, u_fpvalid)" },
Wichert Akkermanf90da011999-10-31 21:15:38 +00002152#endif
Michal Ludvig0e035502002-09-23 15:41:01 +00002153#if defined(I386) || defined(X86_64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002154 { uoff(i387), "offsetof(struct user, i387)" },
2155#else /* !I386 */
2156#ifdef M68K
2157 { uoff(m68kfp), "offsetof(struct user, m68kfp)" },
2158#endif /* M68K */
2159#endif /* !I386 */
2160 { uoff(u_tsize), "offsetof(struct user, u_tsize)" },
2161 { uoff(u_dsize), "offsetof(struct user, u_dsize)" },
2162 { uoff(u_ssize), "offsetof(struct user, u_ssize)" },
2163 { uoff(start_code), "offsetof(struct user, start_code)" },
2164 { uoff(start_stack), "offsetof(struct user, start_stack)" },
2165 { uoff(signal), "offsetof(struct user, signal)" },
Wichert Akkermanccef6372002-05-01 16:39:22 +00002166#if !defined(S390) && !defined(MIPS) && !defined(SH)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002167 { uoff(reserved), "offsetof(struct user, reserved)" },
Wichert Akkermanf90da011999-10-31 21:15:38 +00002168#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002169 { uoff(u_ar0), "offsetof(struct user, u_ar0)" },
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00002170#if !defined(ARM) && !defined(MIPS) && !defined(S390)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002171 { uoff(u_fpstate), "offsetof(struct user, u_fpstate)" },
2172#endif
2173 { uoff(magic), "offsetof(struct user, magic)" },
2174 { uoff(u_comm), "offsetof(struct user, u_comm)" },
Michal Ludvig0e035502002-09-23 15:41:01 +00002175#if defined(I386) || defined(X86_64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002176 { uoff(u_debugreg), "offsetof(struct user, u_debugreg)" },
2177#endif /* I386 */
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00002178#endif /* !IA64 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002179#endif /* !ALPHA */
2180#endif /* !POWERPC/!SPARC */
2181#endif /* LINUX */
2182#ifdef SUNOS4
2183 { uoff(u_pcb), "offsetof(struct user, u_pcb)" },
2184 { uoff(u_procp), "offsetof(struct user, u_procp)" },
2185 { uoff(u_ar0), "offsetof(struct user, u_ar0)" },
2186 { uoff(u_comm[0]), "offsetof(struct user, u_comm[0])" },
2187 { uoff(u_arg[0]), "offsetof(struct user, u_arg[0])" },
2188 { uoff(u_ap), "offsetof(struct user, u_ap)" },
2189 { uoff(u_qsave), "offsetof(struct user, u_qsave)" },
2190 { uoff(u_rval1), "offsetof(struct user, u_rval1)" },
2191 { uoff(u_rval2), "offsetof(struct user, u_rval2)" },
2192 { uoff(u_error), "offsetof(struct user, u_error)" },
2193 { uoff(u_eosys), "offsetof(struct user, u_eosys)" },
2194 { uoff(u_ssave), "offsetof(struct user, u_ssave)" },
2195 { uoff(u_signal[0]), "offsetof(struct user, u_signal)" },
2196 { uoff(u_sigmask[0]), "offsetof(struct user, u_sigmask)" },
2197 { uoff(u_sigonstack), "offsetof(struct user, u_sigonstack)" },
2198 { uoff(u_sigintr), "offsetof(struct user, u_sigintr)" },
2199 { uoff(u_sigreset), "offsetof(struct user, u_sigreset)" },
2200 { uoff(u_oldmask), "offsetof(struct user, u_oldmask)" },
2201 { uoff(u_code), "offsetof(struct user, u_code)" },
2202 { uoff(u_addr), "offsetof(struct user, u_addr)" },
2203 { uoff(u_sigstack), "offsetof(struct user, u_sigstack)" },
2204 { uoff(u_ofile), "offsetof(struct user, u_ofile)" },
2205 { uoff(u_pofile), "offsetof(struct user, u_pofile)" },
2206 { uoff(u_ofile_arr[0]), "offsetof(struct user, u_ofile_arr[0])" },
2207 { uoff(u_pofile_arr[0]),"offsetof(struct user, u_pofile_arr[0])"},
2208 { uoff(u_lastfile), "offsetof(struct user, u_lastfile)" },
2209 { uoff(u_cwd), "offsetof(struct user, u_cwd)" },
2210 { uoff(u_cdir), "offsetof(struct user, u_cdir)" },
2211 { uoff(u_rdir), "offsetof(struct user, u_rdir)" },
2212 { uoff(u_cmask), "offsetof(struct user, u_cmask)" },
2213 { uoff(u_ru), "offsetof(struct user, u_ru)" },
2214 { uoff(u_cru), "offsetof(struct user, u_cru)" },
2215 { uoff(u_timer[0]), "offsetof(struct user, u_timer[0])" },
2216 { uoff(u_XXX[0]), "offsetof(struct user, u_XXX[0])" },
2217 { uoff(u_ioch), "offsetof(struct user, u_ioch)" },
2218 { uoff(u_start), "offsetof(struct user, u_start)" },
2219 { uoff(u_acflag), "offsetof(struct user, u_acflag)" },
2220 { uoff(u_prof.pr_base), "offsetof(struct user, u_prof.pr_base)" },
2221 { uoff(u_prof.pr_size), "offsetof(struct user, u_prof.pr_size)" },
2222 { uoff(u_prof.pr_off), "offsetof(struct user, u_prof.pr_off)" },
2223 { uoff(u_prof.pr_scale),"offsetof(struct user, u_prof.pr_scale)"},
2224 { uoff(u_rlimit[0]), "offsetof(struct user, u_rlimit)" },
2225 { uoff(u_exdata.Ux_A), "offsetof(struct user, u_exdata.Ux_A)" },
2226 { uoff(u_exdata.ux_shell[0]),"offsetof(struct user, u_exdata.ux_shell[0])"},
2227 { uoff(u_lofault), "offsetof(struct user, u_lofault)" },
2228#endif /* SUNOS4 */
Wichert Akkermanc1652e22001-03-27 12:17:16 +00002229#ifndef HPPA
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002230 { sizeof(struct user), "sizeof(struct user)" },
Wichert Akkermanc1652e22001-03-27 12:17:16 +00002231#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002232 { 0, NULL },
2233};
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002234#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002235
2236int
2237sys_ptrace(tcp)
2238struct tcb *tcp;
2239{
2240 char *cmd;
2241 struct xlat *x;
2242 long addr;
2243
2244 cmd = xlookup(ptrace_cmds, tcp->u_arg[0]);
2245 if (!cmd)
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002246#ifndef FREEBSD
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002247 cmd = "PTRACE_???";
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002248#else
2249 cmd = "PT_???";
2250#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002251 if (entering(tcp)) {
2252 tprintf("%s, %lu, ", cmd, tcp->u_arg[1]);
2253 addr = tcp->u_arg[2];
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002254#ifndef FREEBSD
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002255 if (tcp->u_arg[0] == PTRACE_PEEKUSER
2256 || tcp->u_arg[0] == PTRACE_POKEUSER) {
2257 for (x = struct_user_offsets; x->str; x++) {
2258 if (x->val >= addr)
2259 break;
2260 }
2261 if (!x->str)
2262 tprintf("%#lx, ", addr);
2263 else if (x->val > addr && x != struct_user_offsets) {
2264 x--;
2265 tprintf("%s + %ld, ", x->str, addr - x->val);
2266 }
2267 else
2268 tprintf("%s, ", x->str);
2269 }
2270 else
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002271#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002272 tprintf("%#lx, ", tcp->u_arg[2]);
2273#ifdef LINUX
2274 switch (tcp->u_arg[0]) {
2275 case PTRACE_PEEKDATA:
2276 case PTRACE_PEEKTEXT:
2277 case PTRACE_PEEKUSER:
2278 break;
2279 case PTRACE_CONT:
2280 case PTRACE_SINGLESTEP:
2281 case PTRACE_SYSCALL:
2282 case PTRACE_DETACH:
2283 printsignal(tcp->u_arg[3]);
2284 break;
2285 default:
2286 tprintf("%#lx", tcp->u_arg[3]);
2287 break;
2288 }
2289 } else {
2290 switch (tcp->u_arg[0]) {
2291 case PTRACE_PEEKDATA:
2292 case PTRACE_PEEKTEXT:
2293 case PTRACE_PEEKUSER:
2294 printnum(tcp, tcp->u_arg[3], "%#x");
2295 break;
2296 }
2297 }
2298#endif /* LINUX */
2299#ifdef SUNOS4
2300 if (tcp->u_arg[0] == PTRACE_WRITEDATA ||
2301 tcp->u_arg[0] == PTRACE_WRITETEXT) {
2302 tprintf("%lu, ", tcp->u_arg[3]);
2303 printstr(tcp, tcp->u_arg[4], tcp->u_arg[3]);
2304 } else if (tcp->u_arg[0] != PTRACE_READDATA &&
2305 tcp->u_arg[0] != PTRACE_READTEXT) {
2306 tprintf("%#lx", tcp->u_arg[3]);
2307 }
2308 } else {
2309 if (tcp->u_arg[0] == PTRACE_READDATA ||
2310 tcp->u_arg[0] == PTRACE_READTEXT) {
2311 tprintf("%lu, ", tcp->u_arg[3]);
2312 printstr(tcp, tcp->u_arg[4], tcp->u_arg[3]);
2313 }
2314 }
2315#endif /* SUNOS4 */
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002316#ifdef FREEBSD
2317 tprintf("%lu", tcp->u_arg[3]);
2318 }
2319#endif /* FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002320 return 0;
2321}
2322
2323#endif /* !SVR4 */