blob: 06ef7f203d1e60f55c1eaea84e67ee4fa2945f89 [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
Roland McGrath5a223472002-12-15 23:58:26 +000069# undef fpu
Wichert Akkerman00a82ee2001-03-28 20:29:17 +000070#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
Roland McGrath5a223472002-12-15 23:58:26 +000086#ifdef HAVE_LINUX_FUTEX_H
87#include <linux/futex.h>
88#endif
89#if defined LINUX
90# ifndef FUTEX_WAIT
91# define FUTEX_WAIT 0
92# endif
93# ifndef FUTEX_WAKE
94# define FUTEX_WAKE 1
95# endif
96# ifndef FUTEX_FD
97# define FUTEX_FD 2
98# endif
99#endif
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000100
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000101#ifdef LINUX
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000102#include <asm/posix_types.h>
103#undef GETGROUPS_T
104#define GETGROUPS_T __kernel_gid_t
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000105#endif /* LINUX */
106
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000107#if defined(LINUX) && defined(IA64)
108# include <asm/ptrace_offsets.h>
109# include <asm/rse.h>
110#endif
111
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000112#ifdef HAVE_PRCTL
113#include <sys/prctl.h>
114#endif
115
116#ifndef WCOREDUMP
117#define WCOREDUMP(status) ((status) & 0200)
118#endif
119
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000120/* WTA: this was `&& !defined(LINUXSPARC)', this seems unneeded though? */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000121#if defined(HAVE_PRCTL)
122static struct xlat prctl_options[] = {
123#ifdef PR_MAXPROCS
124 { PR_MAXPROCS, "PR_MAXPROCS" },
125#endif
126#ifdef PR_ISBLOCKED
127 { PR_ISBLOCKED, "PR_ISBLOCKED" },
128#endif
129#ifdef PR_SETSTACKSIZE
130 { PR_SETSTACKSIZE, "PR_SETSTACKSIZE" },
131#endif
132#ifdef PR_GETSTACKSIZE
133 { PR_GETSTACKSIZE, "PR_GETSTACKSIZE" },
134#endif
135#ifdef PR_MAXPPROCS
136 { PR_MAXPPROCS, "PR_MAXPPROCS" },
137#endif
138#ifdef PR_UNBLKONEXEC
139 { PR_UNBLKONEXEC, "PR_UNBLKONEXEC" },
140#endif
141#ifdef PR_ATOMICSIM
142 { PR_ATOMICSIM, "PR_ATOMICSIM" },
143#endif
144#ifdef PR_SETEXITSIG
145 { PR_SETEXITSIG, "PR_SETEXITSIG" },
146#endif
147#ifdef PR_RESIDENT
148 { PR_RESIDENT, "PR_RESIDENT" },
149#endif
150#ifdef PR_ATTACHADDR
151 { PR_ATTACHADDR, "PR_ATTACHADDR" },
152#endif
153#ifdef PR_DETACHADDR
154 { PR_DETACHADDR, "PR_DETACHADDR" },
155#endif
156#ifdef PR_TERMCHILD
157 { PR_TERMCHILD, "PR_TERMCHILD" },
158#endif
159#ifdef PR_GETSHMASK
160 { PR_GETSHMASK, "PR_GETSHMASK" },
161#endif
162#ifdef PR_GETNSHARE
163 { PR_GETNSHARE, "PR_GETNSHARE" },
164#endif
165#if defined(PR_SET_PDEATHSIG)
166 { PR_SET_PDEATHSIG, "PR_SET_PDEATHSIG" },
167#endif
Wichert Akkerman8829a551999-06-11 13:18:40 +0000168#ifdef PR_COREPID
169 { PR_COREPID, "PR_COREPID" },
170#endif
171#ifdef PR_ATTACHADDRPERM
172 { PR_ATTACHADDRPERM, "PR_ATTACHADDRPERM" },
173#endif
174#ifdef PR_PTHREADEXIT
175 { PR_PTHREADEXIT, "PR_PTHREADEXIT" },
176#endif
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000177#ifdef PR_SET_PDEATHSIG
178 { PR_SET_PDEATHSIG, "PR_SET_PDEATHSIG" },
179#endif
180#ifdef PR_GET_PDEATHSIG
181 { PR_GET_PDEATHSIG, "PR_GET_PDEATHSIG" },
182#endif
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000183#ifdef PR_GET_UNALIGN
184 { PR_GET_UNALIGN, "PR_GET_UNALIGN" },
185#endif
186#ifdef PR_SET_UNALIGN
187 { PR_SET_UNALIGN, "PR_SET_UNALIGN" },
188#endif
189#ifdef PR_GET_KEEPCAPS
190 { PR_GET_KEEPCAPS, "PR_GET_KEEP_CAPS" },
191#endif
192#ifdef PR_SET_KEEPCAPS
193 { PR_SET_KEEPCAPS, "PR_SET_KEEP_CAPS" },
194#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000195 { 0, NULL },
196};
197
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000198
199const char *
200unalignctl_string (unsigned int ctl)
201{
202 static char buf[16];
203
204 switch (ctl) {
205#ifdef PR_UNALIGN_NOPRINT
206 case PR_UNALIGN_NOPRINT:
207 return "NOPRINT";
208#endif
209#ifdef PR_UNALIGN_SIGBUS
210 case PR_UNALIGN_SIGBUS:
211 return "SIGBUS";
212#endif
213 default:
214 break;
215 }
216 sprintf(buf, "%x", ctl);
217 return buf;
218}
219
220
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000221int
222sys_prctl(tcp)
223struct tcb *tcp;
224{
225 int i;
226
227 if (entering(tcp)) {
228 printxval(prctl_options, tcp->u_arg[0], "PR_???");
229 switch (tcp->u_arg[0]) {
230#ifdef PR_GETNSHARE
231 case PR_GETNSHARE:
232 break;
233#endif
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000234#ifdef PR_SET_DEATHSIG
235 case PR_GET_PDEATHSIG:
236 break;
237#endif
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000238#ifdef PR_SET_UNALIGN
239 case PR_SET_UNALIGN:
240 tprintf(", %s", unalignctl_string(tcp->u_arg[1]));
241 break;
242#endif
243#ifdef PR_GET_UNALIGN
244 case PR_GET_UNALIGN:
245 tprintf(", %#lx", tcp->u_arg[1]);
246 break;
247#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000248 default:
249 for (i = 1; i < tcp->u_nargs; i++)
250 tprintf(", %#lx", tcp->u_arg[i]);
251 break;
252 }
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000253 } else {
254 switch (tcp->u_arg[0]) {
255#ifdef PR_GET_PDEATHSIG
256 case PR_GET_PDEATHSIG:
257 for (i=1; i<tcp->u_nargs; i++)
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000258 tprintf(", %#lx", tcp->u_arg[i]);
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000259 break;
260#endif
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000261#ifdef PR_SET_UNALIGN
262 case PR_SET_UNALIGN:
263 break;
264#endif
265#ifdef PR_GET_UNALIGN
266 case PR_GET_UNALIGN:
267 {
268 int ctl;
269
270 umove(tcp, tcp->u_arg[1], &ctl);
271 tcp->auxstr = unalignctl_string(ctl);
272 return RVAL_STR;
273 }
274#endif
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000275 default:
276 break;
277 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000278 }
279 return 0;
280}
281
282#endif /* HAVE_PRCTL */
283
284int
285sys_gethostid(tcp)
286struct tcb *tcp;
287{
288 if (exiting(tcp))
289 return RVAL_HEX;
290 return 0;
291}
292
293int
294sys_sethostname(tcp)
295struct tcb *tcp;
296{
297 if (entering(tcp)) {
298 printpathn(tcp, tcp->u_arg[0], tcp->u_arg[1]);
299 tprintf(", %lu", tcp->u_arg[1]);
300 }
301 return 0;
302}
303
304int
305sys_gethostname(tcp)
306struct tcb *tcp;
307{
308 if (exiting(tcp)) {
309 if (syserror(tcp))
310 tprintf("%#lx", tcp->u_arg[0]);
311 else
312 printpath(tcp, tcp->u_arg[0]);
313 tprintf(", %lu", tcp->u_arg[1]);
314 }
315 return 0;
316}
317
318int
319sys_setdomainname(tcp)
320struct tcb *tcp;
321{
322 if (entering(tcp)) {
323 printpathn(tcp, tcp->u_arg[0], tcp->u_arg[1]);
324 tprintf(", %lu", tcp->u_arg[1]);
325 }
326 return 0;
327}
328
Wichert Akkerman5daa0281999-03-15 19:49:42 +0000329#if !defined(LINUX)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000330
331int
332sys_getdomainname(tcp)
333struct tcb *tcp;
334{
335 if (exiting(tcp)) {
336 if (syserror(tcp))
337 tprintf("%#lx", tcp->u_arg[0]);
338 else
339 printpath(tcp, tcp->u_arg[0]);
340 tprintf(", %lu", tcp->u_arg[1]);
341 }
342 return 0;
343}
344#endif /* !LINUX */
345
346int
347sys_exit(tcp)
348struct tcb *tcp;
349{
350 if (exiting(tcp)) {
351 fprintf(stderr, "_exit returned!\n");
352 return -1;
353 }
354 /* special case: we stop tracing this process, finish line now */
355 tprintf("%ld) ", tcp->u_arg[0]);
356 tabto(acolumn);
357 tprintf("= ?");
358 printtrailer(tcp);
359 return 0;
360}
361
362int
363internal_exit(tcp)
364struct tcb *tcp;
365{
366 if (entering(tcp))
367 tcp->flags |= TCB_EXITING;
368 return 0;
369}
370
Roland McGrathee9d4352002-12-18 04:16:10 +0000371/* TCP is creating a child we want to follow.
372 If there will be space in tcbtab for it, set TCB_FOLLOWFORK and return 0.
373 If not, clear TCB_FOLLOWFORK, print an error, and return 1. */
374static int
375fork_tcb(struct tcb *tcp)
376{
377 if (nprocs == tcbtabsize) {
378 /* Allocate some more TCBs and expand the table.
379 We don't want to relocate the TCBs because our
380 callers have pointers and it would be a pain.
381 So tcbtab is a table of pointers. Since we never
382 free the TCBs, we allocate a single chunk of many. */
383 struct tcb **newtab = (struct tcb **)
384 realloc(tcbtab, 2 * tcbtabsize * sizeof tcbtab[0]);
385 struct tcb *newtcbs = (struct tcb *) calloc(tcbtabsize,
386 sizeof *newtcbs);
387 int i;
388 if (newtab == NULL || newtcbs == NULL) {
389 if (newtab != NULL)
390 free(newtab);
391 tcp->flags &= ~TCB_FOLLOWFORK;
392 fprintf(stderr, "sys_fork: tcb table full\n");
393 return 1;
394 }
395 for (i = tcbtabsize; i < 2 * tcbtabsize; ++i)
396 newtab[i] = &newtcbs[i - tcbtabsize];
397 tcbtabsize *= 2;
398 tcbtab = newtab;
399 }
400
401 tcp->flags |= TCB_FOLLOWFORK;
402 return 0;
403}
404
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000405#ifdef USE_PROCFS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000406
407int
408sys_fork(tcp)
409struct tcb *tcp;
410{
411 if (exiting(tcp)) {
412 if (getrval2(tcp)) {
413 tcp->auxstr = "child process";
414 return RVAL_UDECIMAL | RVAL_STR;
415 }
416 }
417 return 0;
418}
419
John Hughes4e36a812001-04-18 15:11:51 +0000420#if UNIXWARE > 2
421
422int
423sys_rfork(tcp)
424struct tcb *tcp;
425{
426 if (entering(tcp)) {
427 tprintf ("%ld", tcp->u_arg[0]);
428 }
429 else {
430 if (getrval2(tcp)) {
431 tcp->auxstr = "child process";
432 return RVAL_UDECIMAL | RVAL_STR;
433 }
434 }
435 return 0;
436}
437
438#endif
439
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000440int
441internal_fork(tcp)
442struct tcb *tcp;
443{
444 struct tcb *tcpchild;
445
446 if (exiting(tcp)) {
447 if (getrval2(tcp))
448 return 0;
449 if (!followfork)
450 return 0;
Roland McGrathee9d4352002-12-18 04:16:10 +0000451 if (fork_tcb(tcp))
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000452 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000453 if (syserror(tcp))
454 return 0;
455 if ((tcpchild = alloctcb(tcp->u_rval)) == NULL) {
456 fprintf(stderr, "sys_fork: tcb table full\n");
457 return 0;
458 }
Wichert Akkerman2e4ffe52000-09-03 23:57:48 +0000459 if (proc_open(tcpchild, 2) < 0)
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000460 droptcb(tcpchild);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000461 }
462 return 0;
463}
464
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000465#else /* !USE_PROCFS */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000466
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000467#ifdef LINUX
468
469/* defines copied from linux/sched.h since we can't include that
470 * ourselves (it conflicts with *lots* of libc includes)
471 */
472#define CSIGNAL 0x000000ff /* signal mask to be sent at exit */
473#define CLONE_VM 0x00000100 /* set if VM shared between processes */
474#define CLONE_FS 0x00000200 /* set if fs info shared between processes */
475#define CLONE_FILES 0x00000400 /* set if open files shared between processes */
476#define CLONE_SIGHAND 0x00000800 /* set if signal handlers shared */
477#define CLONE_PID 0x00001000 /* set if pid shared */
478#define CLONE_PTRACE 0x00002000 /* set if we want to let tracing continue on the child too */
479#define CLONE_VFORK 0x00004000 /* set if the parent wants the child to wake it up on mm_release */
480#define CLONE_PARENT 0x00008000 /* set if we want to have the same parent as the cloner */
481
482static struct xlat clone_flags[] = {
483 { CLONE_VM, "CLONE_VM" },
484 { CLONE_FS, "CLONE_FS" },
485 { CLONE_FILES, "CLONE_FILES" },
486 { CLONE_SIGHAND, "CLONE_SIGHAND" },
487 { CLONE_PID, "CLONE_PID" },
488 { CLONE_PTRACE, "CLONE_PTRACE" },
489 { CLONE_VFORK, "CLONE_VFORK" },
490 { CLONE_PARENT, "CLONE_PARENT" },
491 { 0, NULL },
492};
493
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000494int
495sys_clone(tcp)
496struct tcb *tcp;
497{
498 if (exiting(tcp)) {
499 tprintf("child_stack=%#lx, flags=", tcp->u_arg[1]);
500 if (printflags(clone_flags, tcp->u_arg[0]) == 0)
501 tprintf("0");
502 }
503 return 0;
504}
505
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000506int
507sys_clone2(tcp)
508struct tcb *tcp;
509{
510 if (exiting(tcp)) {
511 tprintf("child_stack=%#lx, stack_size=%#lx, flags=",
512 tcp->u_arg[1], tcp->u_arg[2]);
513 if (printflags(clone_flags, tcp->u_arg[0]) == 0)
514 tprintf("0");
515 }
516 return 0;
517}
518
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000519#endif
520
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000521int
522sys_fork(tcp)
523struct tcb *tcp;
524{
525 if (exiting(tcp))
526 return RVAL_UDECIMAL;
527 return 0;
528}
529
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000530int
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000531change_syscall(tcp, new)
532struct tcb *tcp;
533int new;
534{
535#if defined(LINUX)
536#if defined(I386)
537 /* Attempt to make vfork into fork, which we can follow. */
Roland McGrath5a223472002-12-15 23:58:26 +0000538 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(ORIG_EAX * 4), new) < 0)
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000539 return -1;
540 return 0;
Michal Ludvig0e035502002-09-23 15:41:01 +0000541#elif defined(X86_64)
542 /* Attempt to make vfork into fork, which we can follow. */
Roland McGrath5a223472002-12-15 23:58:26 +0000543 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(ORIG_RAX * 8), new) < 0)
Michal Ludvig0e035502002-09-23 15:41:01 +0000544 return -1;
545 return 0;
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000546#elif defined(POWERPC)
Wichert Akkerman5c4c69b2001-04-12 09:00:47 +0000547 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(4*PT_R0), new) < 0)
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000548 return -1;
Michal Ludvig10a88d02002-10-07 14:31:00 +0000549#elif defined(S390) || defined(S390X)
550 /* s390 linux after 2.4.7 has a hook in entry.S to allow this */
551 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(PT_GPR2), new)<0)
552 return -1;
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000553 return 0;
554#elif defined(M68K)
Wichert Akkermanc7926982000-04-10 22:22:31 +0000555 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(4*PT_ORIG_D0), new)<0)
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000556 return -1;
557 return 0;
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000558#elif defined(SPARC)
Wichert Akkerman00a82ee2001-03-28 20:29:17 +0000559 struct regs regs;
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000560 if (ptrace(PTRACE_GETREGS, tcp->pid, (char*)&regs, 0)<0)
561 return -1;
Wichert Akkerman00a82ee2001-03-28 20:29:17 +0000562 regs.r_g1=new;
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000563 if (ptrace(PTRACE_SETREGS, tcp->pid, (char*)&regs, 0)<0)
564 return -1;
565 return 0;
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000566#elif defined(MIPS)
Wichert Akkermanc7926982000-04-10 22:22:31 +0000567 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(REG_V0), new)<0)
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000568 return -1;
569 return 0;
570#elif defined(ALPHA)
Wichert Akkermanc7926982000-04-10 22:22:31 +0000571 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(REG_A3), new)<0)
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000572 return -1;
573 return 0;
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000574#elif defined(IA64)
575 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(PT_R15), new)<0)
576 return -1;
577 return 0;
Wichert Akkermanc1652e22001-03-27 12:17:16 +0000578#elif defined(HPPA)
579 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(PT_GR20), new)<0)
580 return -1;
581 return 0;
Wichert Akkermanccef6372002-05-01 16:39:22 +0000582#elif defined(SH)
583 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(REG_SYSCALL), new)<0)
584 return -1;
585 return 0;
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000586#else
587#warning Do not know how to handle change_syscall for this architecture
588#endif /* architecture */
589#endif /* LINUX */
590 return -1;
591}
592
593int
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000594setarg(tcp, argnum)
595 struct tcb *tcp;
596 int argnum;
597{
598#if defined (IA64)
599 {
600 unsigned long *bsp, *ap;
601
602 if (upeek(tcp->pid, PT_AR_BSP, (long *) &bsp) , 0)
603 return -1;
604
605 ap = ia64_rse_skip_regs(bsp, argnum);
606 errno = 0;
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000607 ptrace(PTRACE_POKEDATA, tcp->pid, (char *) ap, tcp->u_arg[argnum]);
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000608 if (errno)
609 return -1;
610
611 }
Wichert Akkerman12f75d12000-02-14 16:23:40 +0000612#elif defined(I386)
613 {
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000614 ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(4*argnum), tcp->u_arg[argnum]);
Wichert Akkerman12f75d12000-02-14 16:23:40 +0000615 if (errno)
616 return -1;
617 }
Michal Ludvig0e035502002-09-23 15:41:01 +0000618#elif defined(X86_64)
619 {
620 ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(8*(long)argnum), tcp->u_arg[argnum]);
621 if (errno)
622 return -1;
623 }
Roland McGrath3bb9c3d2002-12-16 20:40:48 +0000624#elif defined(POWERPC)
625#ifndef PT_ORIG_R3
626#define PT_ORIG_R3 34
627#endif
628 {
629 ptrace(PTRACE_POKEUSER, tcp->pid,
630 (char*)((argnum==0 ? PT_ORIG_R3 : argnum+PT_R3)*4),
631 tcp->u_arg[argnum]);
632 if (errno)
633 return -1;
634 }
Ralf Baechlee3816102000-08-01 00:06:06 +0000635#elif defined(MIPS)
636 {
637 errno = 0;
638 if (argnum < 4)
639 ptrace(PTRACE_POKEUSER, tcp->pid,
640 (char*)(REG_A0 + argnum), tcp->u_arg[argnum]);
641 else {
642 unsigned long *sp;
643
644 if (upeek(tcp->pid, REG_SP, (long *) &sp) , 0)
645 return -1;
646
647 ptrace(PTRACE_POKEDATA, tcp->pid,
648 (char*)(sp + argnum - 4), tcp->u_arg[argnum]);
649 }
650 if (errno)
651 return -1;
652 }
Michal Ludvig10a88d02002-10-07 14:31:00 +0000653#elif defined(S390) || defined(S390X)
654 {
655 if(argnum <= 5)
656 ptrace(PTRACE_POKEUSER, tcp->pid,
Roland McGrath5a223472002-12-15 23:58:26 +0000657 (char *) (argnum==0 ? PT_ORIGGPR2 :
658 PT_GPR2 + argnum*sizeof(long)),
Michal Ludvig10a88d02002-10-07 14:31:00 +0000659 tcp->u_arg[argnum]);
660 else
661 return -E2BIG;
662 if (errno)
663 return -1;
664 }
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000665#else
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000666# warning Sorry, setargs not implemented for this architecture.
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000667#endif
668 return 0;
669}
670
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000671#ifdef SYS_clone
672int
673internal_clone(tcp)
674struct tcb *tcp;
675{
Ulrich Drepper90512f01999-12-24 07:22:25 +0000676 struct tcb *tcpchild;
677 int pid;
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000678 if (entering(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000679 if (!followfork)
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000680 return 0;
Roland McGrathee9d4352002-12-18 04:16:10 +0000681 if (fork_tcb(tcp))
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000682 return 0;
Wichert Akkerman9b0c31d2000-09-03 21:56:29 +0000683 if (setbpt(tcp) < 0)
684 return 0;
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000685 } else {
Wichert Akkerman9b0c31d2000-09-03 21:56:29 +0000686 int bpt = tcp->flags & TCB_BPTSET;
687
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000688 if (!(tcp->flags & TCB_FOLLOWFORK))
689 return 0;
690
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000691 if (syserror(tcp)) {
692 if (bpt)
693 clearbpt(tcp);
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000694 return 0;
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000695 }
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000696
697 pid = tcp->u_rval;
698 if ((tcpchild = alloctcb(pid)) == NULL) {
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000699 if (bpt)
700 clearbpt(tcp);
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000701 fprintf(stderr, " [tcb table full]\n");
702 kill(pid, SIGKILL); /* XXX */
703 return 0;
704 }
705
Wichert Akkerman9b0c31d2000-09-03 21:56:29 +0000706 /* Attach to the new child */
707 if (ptrace(PTRACE_ATTACH, pid, (char *) 1, 0) < 0) {
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000708 if (bpt)
709 clearbpt(tcp);
Wichert Akkerman9b0c31d2000-09-03 21:56:29 +0000710 perror("PTRACE_ATTACH");
711 fprintf(stderr, "Too late?\n");
712 droptcb(tcpchild);
713 return 0;
714 }
715
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000716 if (bpt)
717 clearbpt(tcp);
718
Ulrich Drepper90512f01999-12-24 07:22:25 +0000719 tcpchild->flags |= TCB_ATTACHED;
Wichert Akkerman9b0c31d2000-09-03 21:56:29 +0000720 if (bpt) {
721 tcpchild->flags |= TCB_BPTSET;
722 tcpchild->baddr = tcp->baddr;
723 memcpy(tcpchild->inst, tcp->inst,
724 sizeof tcpchild->inst);
725 }
Ulrich Drepper90512f01999-12-24 07:22:25 +0000726 newoutf(tcpchild);
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000727 tcpchild->parent = tcp;
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000728 tcp->nchildren++;
729 if (!qflag)
730 fprintf(stderr, "Process %d attached\n", pid);
731 }
732 return 0;
733}
734#endif
735
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000736int
737internal_fork(tcp)
738struct tcb *tcp;
739{
740 struct tcb *tcpchild;
741 int pid;
Nate Sammonsccd8f211999-03-29 22:57:54 +0000742 int dont_follow = 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000743
744#ifdef SYS_vfork
Nate Sammonsccd8f211999-03-29 22:57:54 +0000745 if (tcp->scno == SYS_vfork) {
Nate Sammonsccd8f211999-03-29 22:57:54 +0000746 /* Attempt to make vfork into fork, which we can follow. */
Roland McGrath5a223472002-12-15 23:58:26 +0000747 if (!followvfork ||
Pavel Machek9a9f10b2000-02-01 16:22:52 +0000748 change_syscall(tcp, SYS_fork) < 0)
Nate Sammonsccd8f211999-03-29 22:57:54 +0000749 dont_follow = 1;
Nate Sammonsccd8f211999-03-29 22:57:54 +0000750 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000751#endif
752 if (entering(tcp)) {
Nate Sammonsccd8f211999-03-29 22:57:54 +0000753 if (!followfork || dont_follow)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000754 return 0;
Roland McGrathee9d4352002-12-18 04:16:10 +0000755 if (fork_tcb(tcp))
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000756 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000757 if (setbpt(tcp) < 0)
758 return 0;
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000759 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000760 else {
761 int bpt = tcp->flags & TCB_BPTSET;
762
763 if (!(tcp->flags & TCB_FOLLOWFORK))
764 return 0;
765 if (bpt)
766 clearbpt(tcp);
767
768 if (syserror(tcp))
769 return 0;
770
771 pid = tcp->u_rval;
772 if ((tcpchild = alloctcb(pid)) == NULL) {
773 fprintf(stderr, " [tcb table full]\n");
774 kill(pid, SIGKILL); /* XXX */
775 return 0;
776 }
777#ifdef LINUX
Wichert Akkermanc1652e22001-03-27 12:17:16 +0000778#ifdef HPPA
779 /* The child must have run before it can be attached. */
780 /* This must be a bug in the parisc kernel, but I havn't
781 * identified it yet. Seems to be an issue associated
782 * with attaching to a process (which sends it a signal)
783 * before that process has ever been scheduled. When
784 * debugging, I started seeing crashes in
785 * arch/parisc/kernel/signal.c:do_signal(), apparently
786 * caused by r8 getting corrupt over the dequeue_signal()
787 * call. Didn't make much sense though...
788 */
789 {
790 struct timeval tv;
791 tv.tv_sec = 0;
792 tv.tv_usec = 10000;
793 select(0, NULL, NULL, NULL, &tv);
794 }
795#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000796 if (ptrace(PTRACE_ATTACH, pid, (char *) 1, 0) < 0) {
797 perror("PTRACE_ATTACH");
798 fprintf(stderr, "Too late?\n");
799 droptcb(tcpchild);
800 return 0;
801 }
802#endif /* LINUX */
803#ifdef SUNOS4
804#ifdef oldway
805 /* The child must have run before it can be attached. */
806 {
807 struct timeval tv;
808 tv.tv_sec = 0;
809 tv.tv_usec = 10000;
810 select(0, NULL, NULL, NULL, &tv);
811 }
812 if (ptrace(PTRACE_ATTACH, pid, (char *)1, 0) < 0) {
813 perror("PTRACE_ATTACH");
814 fprintf(stderr, "Too late?\n");
815 droptcb(tcpchild);
816 return 0;
817 }
818#else /* !oldway */
819 /* Try to catch the new process as soon as possible. */
820 {
821 int i;
822 for (i = 0; i < 1024; i++)
823 if (ptrace(PTRACE_ATTACH, pid, (char *) 1, 0) >= 0)
824 break;
825 if (i == 1024) {
826 perror("PTRACE_ATTACH");
827 fprintf(stderr, "Too late?\n");
828 droptcb(tcpchild);
829 return 0;
830 }
831 }
832#endif /* !oldway */
833#endif /* SUNOS4 */
834 tcpchild->flags |= TCB_ATTACHED;
835 /* Child has BPT too, must be removed on first occasion */
836 if (bpt) {
837 tcpchild->flags |= TCB_BPTSET;
838 tcpchild->baddr = tcp->baddr;
839 memcpy(tcpchild->inst, tcp->inst,
840 sizeof tcpchild->inst);
841 }
842 newoutf(tcpchild);
843 tcpchild->parent = tcp;
844 tcp->nchildren++;
845 if (!qflag)
846 fprintf(stderr, "Process %d attached\n", pid);
847 }
848 return 0;
849}
850
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000851#endif /* !USE_PROCFS */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000852
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000853#if defined(SUNOS4) || defined(LINUX) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000854
855int
856sys_vfork(tcp)
857struct tcb *tcp;
858{
859 if (exiting(tcp))
860 return RVAL_UDECIMAL;
861 return 0;
862}
863
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000864#endif /* SUNOS4 || LINUX || FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000865
866#ifndef LINUX
867
868static char idstr[16];
869
870int
871sys_getpid(tcp)
872struct tcb *tcp;
873{
874 if (exiting(tcp)) {
875 sprintf(idstr, "ppid %lu", getrval2(tcp));
876 tcp->auxstr = idstr;
877 return RVAL_STR;
878 }
879 return 0;
880}
881
882int
883sys_getuid(tcp)
884struct tcb *tcp;
885{
886 if (exiting(tcp)) {
887 sprintf(idstr, "euid %lu", getrval2(tcp));
888 tcp->auxstr = idstr;
889 return RVAL_STR;
890 }
891 return 0;
892}
893
894int
895sys_getgid(tcp)
896struct tcb *tcp;
897{
898 if (exiting(tcp)) {
899 sprintf(idstr, "egid %lu", getrval2(tcp));
900 tcp->auxstr = idstr;
901 return RVAL_STR;
902 }
903 return 0;
904}
905
906#endif /* !LINUX */
907
908#ifdef LINUX
909
910int
911sys_setuid(tcp)
912struct tcb *tcp;
913{
914 if (entering(tcp)) {
915 tprintf("%u", (uid_t) tcp->u_arg[0]);
916 }
917 return 0;
918}
919
920int
921sys_setgid(tcp)
922struct tcb *tcp;
923{
924 if (entering(tcp)) {
925 tprintf("%u", (gid_t) tcp->u_arg[0]);
926 }
927 return 0;
928}
929
930int
931sys_getresuid(tcp)
932 struct tcb *tcp;
933{
934 if (exiting(tcp)) {
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000935 __kernel_uid_t uid;
936 if (syserror(tcp))
937 tprintf("%#lx, %#lx, %#lx", tcp->u_arg[0],
938 tcp->u_arg[1], tcp->u_arg[2]);
939 else {
940 if (umove(tcp, tcp->u_arg[0], &uid) < 0)
941 tprintf("%#lx, ", tcp->u_arg[0]);
942 else
943 tprintf("ruid %lu, ", (unsigned long) uid);
944 if (umove(tcp, tcp->u_arg[0], &uid) < 0)
945 tprintf("%#lx, ", tcp->u_arg[0]);
946 else
947 tprintf("euid %lu, ", (unsigned long) uid);
948 if (umove(tcp, tcp->u_arg[0], &uid) < 0)
949 tprintf("%#lx", tcp->u_arg[0]);
950 else
951 tprintf("suid %lu", (unsigned long) uid);
952 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000953 }
954 return 0;
955}
956
957int
958sys_getresgid(tcp)
959struct tcb *tcp;
960{
961 if (exiting(tcp)) {
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000962 __kernel_gid_t gid;
963 if (syserror(tcp))
964 tprintf("%#lx, %#lx, %#lx", tcp->u_arg[0],
965 tcp->u_arg[1], tcp->u_arg[2]);
966 else {
967 if (umove(tcp, tcp->u_arg[0], &gid) < 0)
968 tprintf("%#lx, ", tcp->u_arg[0]);
969 else
970 tprintf("rgid %lu, ", (unsigned long) gid);
971 if (umove(tcp, tcp->u_arg[0], &gid) < 0)
972 tprintf("%#lx, ", tcp->u_arg[0]);
973 else
974 tprintf("egid %lu, ", (unsigned long) gid);
975 if (umove(tcp, tcp->u_arg[0], &gid) < 0)
976 tprintf("%#lx", tcp->u_arg[0]);
977 else
978 tprintf("sgid %lu", (unsigned long) gid);
979 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000980 }
981 return 0;
982}
983
984#endif /* LINUX */
985
986int
987sys_setreuid(tcp)
988struct tcb *tcp;
989{
990 if (entering(tcp)) {
991 tprintf("%lu, %lu",
992 (unsigned long) (uid_t) tcp->u_arg[0],
993 (unsigned long) (uid_t) tcp->u_arg[1]);
994 }
995 return 0;
996}
997
998int
999sys_setregid(tcp)
1000struct tcb *tcp;
1001{
1002 if (entering(tcp)) {
1003 tprintf("%lu, %lu",
1004 (unsigned long) (gid_t) tcp->u_arg[0],
1005 (unsigned long) (gid_t) tcp->u_arg[1]);
1006 }
1007 return 0;
1008}
1009
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001010#if defined(LINUX) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001011int
1012sys_setresuid(tcp)
1013 struct tcb *tcp;
1014{
1015 if (entering(tcp)) {
1016 tprintf("ruid %u, euid %u, suid %u",
1017 (uid_t) tcp->u_arg[0],
1018 (uid_t) tcp->u_arg[1],
1019 (uid_t) tcp->u_arg[2]);
1020 }
1021 return 0;
1022}
1023int
1024sys_setresgid(tcp)
1025 struct tcb *tcp;
1026{
1027 if (entering(tcp)) {
1028 tprintf("rgid %u, egid %u, sgid %u",
1029 (uid_t) tcp->u_arg[0],
1030 (uid_t) tcp->u_arg[1],
1031 (uid_t) tcp->u_arg[2]);
1032 }
1033 return 0;
1034}
1035
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001036#endif /* LINUX || FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001037
1038int
1039sys_setgroups(tcp)
1040struct tcb *tcp;
1041{
1042 int i, len;
1043 GETGROUPS_T *gidset;
1044
1045 if (entering(tcp)) {
1046 len = tcp->u_arg[0];
1047 tprintf("%u, ", len);
1048 if (len <= 0) {
1049 tprintf("[]");
1050 return 0;
1051 }
1052 gidset = (GETGROUPS_T *) malloc(len * sizeof(GETGROUPS_T));
1053 if (gidset == NULL) {
1054 fprintf(stderr, "sys_setgroups: out of memory\n");
1055 return -1;
1056 }
1057 if (!verbose(tcp))
1058 tprintf("%#lx", tcp->u_arg[1]);
1059 else if (umoven(tcp, tcp->u_arg[1],
1060 len * sizeof(GETGROUPS_T), (char *) gidset) < 0)
1061 tprintf("[?]");
1062 else {
1063 tprintf("[");
1064 for (i = 0; i < len; i++)
1065 tprintf("%s%lu", i ? ", " : "",
1066 (unsigned long) gidset[i]);
1067 tprintf("]");
1068 }
1069 free((char *) gidset);
1070 }
1071 return 0;
1072}
1073
1074int
1075sys_getgroups(tcp)
1076struct tcb *tcp;
1077{
1078 int i, len;
1079 GETGROUPS_T *gidset;
1080
1081 if (entering(tcp)) {
1082 len = tcp->u_arg[0];
1083 tprintf("%u, ", len);
1084 } else {
1085 len = tcp->u_rval;
1086 if (len <= 0) {
1087 tprintf("[]");
1088 return 0;
1089 }
1090 gidset = (GETGROUPS_T *) malloc(len * sizeof(GETGROUPS_T));
1091 if (gidset == NULL) {
1092 fprintf(stderr, "sys_getgroups: out of memory\n");
1093 return -1;
1094 }
1095 if (!tcp->u_arg[1])
1096 tprintf("NULL");
1097 else if (!verbose(tcp) || tcp->u_arg[0] == 0)
1098 tprintf("%#lx", tcp->u_arg[1]);
1099 else if (umoven(tcp, tcp->u_arg[1],
1100 len * sizeof(GETGROUPS_T), (char *) gidset) < 0)
1101 tprintf("[?]");
1102 else {
1103 tprintf("[");
1104 for (i = 0; i < len; i++)
1105 tprintf("%s%lu", i ? ", " : "",
1106 (unsigned long) gidset[i]);
1107 tprintf("]");
1108 }
1109 free((char *)gidset);
1110 }
1111 return 0;
1112}
1113
1114int
1115sys_setpgrp(tcp)
1116struct tcb *tcp;
1117{
1118 if (entering(tcp)) {
1119#ifndef SVR4
1120 tprintf("%lu, %lu", tcp->u_arg[0], tcp->u_arg[1]);
1121#endif /* !SVR4 */
1122 }
1123 return 0;
1124}
1125
1126int
1127sys_getpgrp(tcp)
1128struct tcb *tcp;
1129{
1130 if (entering(tcp)) {
1131#ifndef SVR4
1132 tprintf("%lu", tcp->u_arg[0]);
1133#endif /* !SVR4 */
1134 }
1135 return 0;
1136}
1137
1138int
1139sys_getsid(tcp)
1140struct tcb *tcp;
1141{
1142 if (entering(tcp)) {
1143 tprintf("%lu", tcp->u_arg[0]);
1144 }
1145 return 0;
1146}
1147
1148int
1149sys_setsid(tcp)
1150struct tcb *tcp;
1151{
1152 return 0;
1153}
1154
1155int
1156sys_getpgid(tcp)
1157struct tcb *tcp;
1158{
1159 if (entering(tcp)) {
1160 tprintf("%lu", tcp->u_arg[0]);
1161 }
1162 return 0;
1163}
1164
1165int
1166sys_setpgid(tcp)
1167struct tcb *tcp;
1168{
1169 if (entering(tcp)) {
1170 tprintf("%lu, %lu", tcp->u_arg[0], tcp->u_arg[1]);
1171 }
1172 return 0;
1173}
1174
John Hughesc61eb3d2002-05-17 11:37:50 +00001175#if UNIXWARE >= 2
1176
1177#include <sys/privilege.h>
1178
1179
1180static struct xlat procpriv_cmds [] = {
1181 { SETPRV, "SETPRV" },
1182 { CLRPRV, "CLRPRV" },
1183 { PUTPRV, "PUTPRV" },
1184 { GETPRV, "GETPRV" },
1185 { CNTPRV, "CNTPRV" },
1186 { 0, NULL },
1187};
1188
1189
1190static struct xlat procpriv_priv [] = {
1191 { P_OWNER, "P_OWNER" },
1192 { P_AUDIT, "P_AUDIT" },
1193 { P_COMPAT, "P_COMPAT" },
1194 { P_DACREAD, "P_DACREAD" },
1195 { P_DACWRITE, "P_DACWRITE" },
1196 { P_DEV, "P_DEV" },
1197 { P_FILESYS, "P_FILESYS" },
1198 { P_MACREAD, "P_MACREAD" },
1199 { P_MACWRITE, "P_MACWRITE" },
1200 { P_MOUNT, "P_MOUNT" },
1201 { P_MULTIDIR, "P_MULTIDIR" },
1202 { P_SETPLEVEL, "P_SETPLEVEL" },
1203 { P_SETSPRIV, "P_SETSPRIV" },
1204 { P_SETUID, "P_SETUID" },
1205 { P_SYSOPS, "P_SYSOPS" },
1206 { P_SETUPRIV, "P_SETUPRIV" },
1207 { P_DRIVER, "P_DRIVER" },
1208 { P_RTIME, "P_RTIME" },
1209 { P_MACUPGRADE, "P_MACUPGRADE" },
1210 { P_FSYSRANGE, "P_FSYSRANGE" },
1211 { P_SETFLEVEL, "P_SETFLEVEL" },
1212 { P_AUDITWR, "P_AUDITWR" },
1213 { P_TSHAR, "P_TSHAR" },
1214 { P_PLOCK, "P_PLOCK" },
1215 { P_CORE, "P_CORE" },
1216 { P_LOADMOD, "P_LOADMOD" },
1217 { P_BIND, "P_BIND" },
1218 { P_ALLPRIVS, "P_ALLPRIVS" },
1219 { 0, NULL },
1220};
1221
1222
1223static struct xlat procpriv_type [] = {
1224 { PS_FIX, "PS_FIX" },
1225 { PS_INH, "PS_INH" },
1226 { PS_MAX, "PS_MAX" },
1227 { PS_WKG, "PS_WKG" },
1228 { 0, NULL },
1229};
1230
1231
1232static void
1233printpriv(tcp, addr, len, opt)
1234struct tcb *tcp;
1235long addr;
1236int len;
1237struct xlat *opt;
1238{
1239 priv_t buf [128];
1240 int max = verbose (tcp) ? sizeof buf / sizeof buf [0] : 10;
1241 int dots = len > max;
1242 int i;
Roland McGrath5a223472002-12-15 23:58:26 +00001243
John Hughesc61eb3d2002-05-17 11:37:50 +00001244 if (len > max) len = max;
Roland McGrath5a223472002-12-15 23:58:26 +00001245
John Hughesc61eb3d2002-05-17 11:37:50 +00001246 if (len <= 0 ||
1247 umoven (tcp, addr, len * sizeof buf[0], (char *) buf) < 0)
1248 {
1249 tprintf ("%#lx", addr);
1250 return;
1251 }
1252
1253 tprintf ("[");
1254
1255 for (i = 0; i < len; ++i) {
1256 char *t, *p;
1257
1258 if (i) tprintf (", ");
1259
1260 if ((t = xlookup (procpriv_type, buf [i] & PS_TYPE)) &&
1261 (p = xlookup (procpriv_priv, buf [i] & ~PS_TYPE)))
1262 {
1263 tprintf ("%s|%s", t, p);
1264 }
1265 else {
1266 tprintf ("%#lx", buf [i]);
1267 }
1268 }
1269
1270 if (dots) tprintf (" ...");
1271
1272 tprintf ("]");
1273}
1274
1275
1276int
1277sys_procpriv(tcp)
1278struct tcb *tcp;
1279{
1280 if (entering(tcp)) {
1281 printxval(procpriv_cmds, tcp->u_arg[0], "???PRV");
1282 switch (tcp->u_arg[0]) {
1283 case CNTPRV:
1284 tprintf(", %#lx, %ld", tcp->u_arg[1], tcp->u_arg[2]);
1285 break;
1286
1287 case GETPRV:
1288 break;
1289
1290 default:
1291 tprintf (", ");
1292 printpriv (tcp, tcp->u_arg[1], tcp->u_arg[2]);
1293 tprintf (", %ld", tcp->u_arg[2]);
1294 }
1295 }
1296 else if (tcp->u_arg[0] == GETPRV) {
1297 if (syserror (tcp)) {
1298 tprintf(", %#lx, %ld", tcp->u_arg[1], tcp->u_arg[2]);
1299 }
1300 else {
1301 tprintf (", ");
1302 printpriv (tcp, tcp->u_arg[1], tcp->u_rval);
1303 tprintf (", %ld", tcp->u_arg[2]);
1304 }
1305 }
Roland McGrath5a223472002-12-15 23:58:26 +00001306
John Hughesc61eb3d2002-05-17 11:37:50 +00001307 return 0;
1308}
1309
1310#endif
1311
1312
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001313void
1314fake_execve(tcp, program, argv, envp)
1315struct tcb *tcp;
1316char *program;
1317char *argv[];
1318char *envp[];
1319{
1320 int i;
1321
1322#ifdef ARM
1323 if (!(qual_flags[SYS_execve - __NR_SYSCALL_BASE] & QUAL_TRACE))
1324 return;
1325#else
1326 if (!(qual_flags[SYS_execve] & QUAL_TRACE))
1327 return;
1328#endif /* !ARM */
1329 printleader(tcp);
1330 tprintf("execve(");
1331 string_quote(program);
1332 tprintf(", [");
1333 for (i = 0; argv[i] != NULL; i++) {
1334 if (i != 0)
1335 tprintf(", ");
1336 string_quote(argv[i]);
1337 }
1338 for (i = 0; envp[i] != NULL; i++)
1339 ;
1340 tprintf("], [/* %d var%s */]) ", i, (i != 1) ? "s" : "");
1341 tabto(acolumn);
1342 tprintf("= 0");
1343 printtrailer(tcp);
1344}
1345
1346static void
1347printargv(tcp, addr)
1348struct tcb *tcp;
1349long addr;
1350{
1351 char *cp;
1352 char *sep;
1353 int max = max_strlen / 2;
1354
1355 for (sep = ""; --max >= 0; sep = ", ") {
1356 if (!abbrev(tcp))
1357 max++;
1358 if (umove(tcp, addr, &cp) < 0) {
1359 tprintf("%#lx", addr);
1360 return;
1361 }
1362 if (cp == 0)
1363 break;
1364 tprintf(sep);
1365 printstr(tcp, (long) cp, -1);
1366 addr += sizeof(char *);
1367 }
1368 if (cp)
1369 tprintf(", ...");
1370}
1371
1372static void
1373printargc(fmt, tcp, addr)
1374char *fmt;
1375struct tcb *tcp;
1376long addr;
1377{
1378 int count;
1379 char *cp;
1380
1381 for (count = 0; umove(tcp, addr, &cp) >= 0 && cp != NULL; count++) {
1382 addr += sizeof(char *);
1383 }
1384 tprintf(fmt, count, count == 1 ? "" : "s");
1385}
1386
1387int
1388sys_execv(tcp)
1389struct tcb *tcp;
1390{
1391 if (entering(tcp)) {
1392 printpath(tcp, tcp->u_arg[0]);
1393 if (!verbose(tcp))
1394 tprintf(", %#lx", tcp->u_arg[1]);
1395#if 0
1396 else if (abbrev(tcp))
1397 printargc(", [/* %d arg%s */]", tcp, tcp->u_arg[1]);
1398#endif
1399 else {
1400 tprintf(", [");
1401 printargv(tcp, tcp->u_arg[1]);
1402 tprintf("]");
1403 }
1404 }
1405 return 0;
1406}
1407
1408int
1409sys_execve(tcp)
1410struct tcb *tcp;
1411{
1412 if (entering(tcp)) {
1413 printpath(tcp, tcp->u_arg[0]);
1414 if (!verbose(tcp))
1415 tprintf(", %#lx", tcp->u_arg[1]);
1416#if 0
1417 else if (abbrev(tcp))
1418 printargc(", [/* %d arg%s */]", tcp, tcp->u_arg[1]);
1419#endif
1420 else {
1421 tprintf(", [");
1422 printargv(tcp, tcp->u_arg[1]);
1423 tprintf("]");
1424 }
1425 if (!verbose(tcp))
1426 tprintf(", %#lx", tcp->u_arg[2]);
1427 else if (abbrev(tcp))
1428 printargc(", [/* %d var%s */]", tcp, tcp->u_arg[2]);
1429 else {
1430 tprintf(", [");
1431 printargv(tcp, tcp->u_arg[2]);
1432 tprintf("]");
1433 }
1434 }
1435#ifdef LINUX
Wichert Akkermanccef6372002-05-01 16:39:22 +00001436#if defined(ALPHA) || defined(SPARC) || defined(POWERPC) || defined(IA64) || defined(HPPA) || defined(SH)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001437 tcp->flags |= TCB_WAITEXECVE;
Wichert Akkermanccef6372002-05-01 16:39:22 +00001438#endif /* ALPHA || SPARC || POWERPC || IA64 || HPPA || SH */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001439#endif /* LINUX */
1440 return 0;
1441}
1442
John Hughes4e36a812001-04-18 15:11:51 +00001443#if UNIXWARE > 2
1444
1445int sys_rexecve(tcp)
1446struct tcb *tcp;
1447{
1448 if (entering (tcp)) {
1449 sys_execve (tcp);
1450 tprintf (", %ld", tcp->u_arg[3]);
1451 }
1452 return 0;
1453}
1454
1455#endif
1456
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001457int
1458internal_exec(tcp)
1459struct tcb *tcp;
1460{
1461#ifdef SUNOS4
1462 if (exiting(tcp) && !syserror(tcp) && followfork)
1463 fixvfork(tcp);
1464#endif /* SUNOS4 */
1465 return 0;
1466}
1467
1468#ifdef LINUX
Roland McGrath7ec1d352002-12-17 04:50:44 +00001469#ifndef __WNOTHREAD
1470#define __WNOTHREAD 0x20000000
1471#endif
1472#ifndef __WALL
1473#define __WALL 0x40000000
1474#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001475#ifndef __WCLONE
Roland McGrath7ec1d352002-12-17 04:50:44 +00001476#define __WCLONE 0x80000000
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001477#endif
1478#endif /* LINUX */
1479
1480static struct xlat wait4_options[] = {
1481 { WNOHANG, "WNOHANG" },
1482#ifndef WSTOPPED
1483 { WUNTRACED, "WUNTRACED" },
1484#endif
1485#ifdef WEXITED
1486 { WEXITED, "WEXITED" },
1487#endif
1488#ifdef WTRAPPED
1489 { WTRAPPED, "WTRAPPED" },
1490#endif
1491#ifdef WSTOPPED
1492 { WSTOPPED, "WSTOPPED" },
1493#endif
1494#ifdef WCONTINUED
1495 { WCONTINUED, "WCONTINUED" },
1496#endif
1497#ifdef WNOWAIT
1498 { WNOWAIT, "WNOWAIT" },
1499#endif
1500#ifdef __WCLONE
1501 { __WCLONE, "__WCLONE" },
1502#endif
Roland McGrath7ec1d352002-12-17 04:50:44 +00001503#ifdef __WALL
1504 { __WALL, "__WALL" },
1505#endif
1506#ifdef __WNOTHREAD
1507 { __WNOTHREAD, "__WNOTHREAD" },
1508#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001509 { 0, NULL },
1510};
1511
1512static int
1513printstatus(status)
1514int status;
1515{
1516 int exited = 0;
1517
1518 /*
1519 * Here is a tricky presentation problem. This solution
1520 * is still not entirely satisfactory but since there
1521 * are no wait status constructors it will have to do.
1522 */
1523 if (WIFSTOPPED(status))
1524 tprintf("[WIFSTOPPED(s) && WSTOPSIG(s) == %s]",
Nate Sammonsce780fc1999-03-29 23:23:13 +00001525 signame(WSTOPSIG(status)));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001526 else if WIFSIGNALED(status)
1527 tprintf("[WIFSIGNALED(s) && WTERMSIG(s) == %s%s]",
Nate Sammonsce780fc1999-03-29 23:23:13 +00001528 signame(WTERMSIG(status)),
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001529 WCOREDUMP(status) ? " && WCOREDUMP(s)" : "");
1530 else if WIFEXITED(status) {
1531 tprintf("[WIFEXITED(s) && WEXITSTATUS(s) == %d]",
1532 WEXITSTATUS(status));
1533 exited = 1;
1534 }
1535 else
1536 tprintf("[%#x]", status);
1537 return exited;
1538}
1539
1540static int
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001541printwaitn(tcp, n, bitness)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001542struct tcb *tcp;
1543int n;
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001544int bitness;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001545{
1546 int status;
1547 int exited = 0;
1548
1549 if (entering(tcp)) {
1550 tprintf("%ld, ", tcp->u_arg[0]);
1551 } else {
1552 /* status */
1553 if (!tcp->u_arg[1])
1554 tprintf("NULL");
1555 else if (syserror(tcp) || tcp->u_rval == 0)
1556 tprintf("%#lx", tcp->u_arg[1]);
1557 else if (umove(tcp, tcp->u_arg[1], &status) < 0)
1558 tprintf("[?]");
1559 else
1560 exited = printstatus(status);
1561 /* options */
1562 tprintf(", ");
1563 if (!printflags(wait4_options, tcp->u_arg[2]))
1564 tprintf("0");
1565 if (n == 4) {
1566 tprintf(", ");
1567 /* usage */
1568 if (!tcp->u_arg[3])
1569 tprintf("NULL");
1570#ifdef LINUX
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001571 else if (tcp->u_rval > 0) {
1572#ifdef LINUX_64BIT
1573 if (bitness)
1574 printrusage32(tcp, tcp->u_arg[3]);
1575 else
1576#endif
1577 printrusage(tcp, tcp->u_arg[3]);
1578 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001579#endif /* LINUX */
1580#ifdef SUNOS4
1581 else if (tcp->u_rval > 0 && exited)
1582 printrusage(tcp, tcp->u_arg[3]);
1583#endif /* SUNOS4 */
1584 else
1585 tprintf("%#lx", tcp->u_arg[3]);
1586 }
1587 }
1588 return 0;
1589}
1590
1591int
1592internal_wait(tcp)
1593struct tcb *tcp;
1594{
1595 if (entering(tcp)) {
Wichert Akkerman5daa0281999-03-15 19:49:42 +00001596 /* WTA: fix bug with hanging children */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001597 if (!(tcp->u_arg[2] & WNOHANG) && tcp->nchildren > 0) {
1598 /* There are traced children */
1599 tcp->flags |= TCB_SUSPENDED;
1600 tcp->waitpid = tcp->u_arg[0];
1601 }
1602 }
1603 return 0;
1604}
1605
1606#ifdef SVR4
1607
1608int
1609sys_wait(tcp)
1610struct tcb *tcp;
1611{
1612 if (exiting(tcp)) {
1613 /* The library wrapper stuffs this into the user variable. */
1614 if (!syserror(tcp))
1615 printstatus(getrval2(tcp));
1616 }
1617 return 0;
1618}
1619
1620#endif /* SVR4 */
1621
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001622#ifdef FREEBSD
1623int
1624sys_wait(tcp)
1625struct tcb *tcp;
1626{
1627 int status;
Roland McGrath5a223472002-12-15 23:58:26 +00001628
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001629 if (exiting(tcp)) {
1630 if (!syserror(tcp)) {
1631 if (umove(tcp, tcp->u_arg[0], &status) < 0)
1632 tprintf("%#lx", tcp->u_arg[0]);
1633 else
1634 printstatus(status);
1635 }
1636 }
1637 return 0;
1638}
1639#endif
1640
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001641int
1642sys_waitpid(tcp)
1643struct tcb *tcp;
1644{
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001645 return printwaitn(tcp, 3, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001646}
1647
1648int
1649sys_wait4(tcp)
1650struct tcb *tcp;
1651{
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001652 return printwaitn(tcp, 4, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001653}
1654
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001655#ifdef ALPHA
1656int
1657sys_osf_wait4(tcp)
1658struct tcb *tcp;
1659{
1660 return printwaitn(tcp, 4, 1);
1661}
1662#endif
1663
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001664#ifdef SVR4
1665
1666static struct xlat waitid_types[] = {
1667 { P_PID, "P_PID" },
1668 { P_PPID, "P_PPID" },
1669 { P_PGID, "P_PGID" },
1670 { P_SID, "P_SID" },
1671 { P_CID, "P_CID" },
1672 { P_UID, "P_UID" },
1673 { P_GID, "P_GID" },
1674 { P_ALL, "P_ALL" },
1675#ifdef P_LWPID
1676 { P_LWPID, "P_LWPID" },
1677#endif
1678 { 0, NULL },
1679};
1680
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001681int
1682sys_waitid(tcp)
1683struct tcb *tcp;
1684{
1685 siginfo_t si;
1686 int exited;
1687
1688 if (entering(tcp)) {
1689 printxval(waitid_types, tcp->u_arg[0], "P_???");
1690 tprintf(", %ld, ", tcp->u_arg[1]);
1691 if (tcp->nchildren > 0) {
1692 /* There are traced children */
1693 tcp->flags |= TCB_SUSPENDED;
1694 tcp->waitpid = tcp->u_arg[0];
1695 }
1696 }
1697 else {
1698 /* siginfo */
1699 exited = 0;
1700 if (!tcp->u_arg[2])
1701 tprintf("NULL");
1702 else if (syserror(tcp))
1703 tprintf("%#lx", tcp->u_arg[2]);
1704 else if (umove(tcp, tcp->u_arg[2], &si) < 0)
1705 tprintf("{???}");
1706 else
John Hughes58265892001-10-18 15:13:53 +00001707 printsiginfo(&si, verbose (tcp));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001708 /* options */
1709 tprintf(", ");
1710 if (!printflags(wait4_options, tcp->u_arg[3]))
1711 tprintf("0");
1712 }
1713 return 0;
1714}
1715
1716#endif /* SVR4 */
1717
1718int
1719sys_alarm(tcp)
1720struct tcb *tcp;
1721{
1722 if (entering(tcp))
1723 tprintf("%lu", tcp->u_arg[0]);
1724 return 0;
1725}
1726
1727int
1728sys_uname(tcp)
1729struct tcb *tcp;
1730{
1731 struct utsname uname;
1732
1733 if (exiting(tcp)) {
1734 if (syserror(tcp) || !verbose(tcp))
1735 tprintf("%#lx", tcp->u_arg[0]);
1736 else if (umove(tcp, tcp->u_arg[0], &uname) < 0)
1737 tprintf("{...}");
1738 else if (!abbrev(tcp)) {
1739
1740 tprintf("{sysname=\"%s\", nodename=\"%s\", ",
1741 uname.sysname, uname.nodename);
1742 tprintf("release=\"%s\", version=\"%s\", ",
1743 uname.release, uname.version);
1744 tprintf("machine=\"%s\"", uname.machine);
1745#ifdef LINUX
1746#ifndef __GLIBC__
1747 tprintf(", domainname=\"%s\"", uname.domainname);
1748#endif /* __GLIBC__ */
1749#endif /* LINUX */
1750 tprintf("}");
1751 }
1752 else
1753 tprintf("{sys=\"%s\", node=\"%s\", ...}",
1754 uname.sysname, uname.nodename);
1755 }
1756 return 0;
1757}
1758
1759#ifndef SVR4
1760
1761static struct xlat ptrace_cmds[] = {
Roland McGrath5a223472002-12-15 23:58:26 +00001762#ifndef FREEBSD
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001763 { PTRACE_TRACEME, "PTRACE_TRACEME" },
1764 { PTRACE_PEEKTEXT, "PTRACE_PEEKTEXT", },
1765 { PTRACE_PEEKDATA, "PTRACE_PEEKDATA", },
1766 { PTRACE_PEEKUSER, "PTRACE_PEEKUSER", },
1767 { PTRACE_POKETEXT, "PTRACE_POKETEXT", },
1768 { PTRACE_POKEDATA, "PTRACE_POKEDATA", },
1769 { PTRACE_POKEUSER, "PTRACE_POKEUSER", },
1770 { PTRACE_CONT, "PTRACE_CONT" },
1771 { PTRACE_KILL, "PTRACE_KILL" },
1772 { PTRACE_SINGLESTEP, "PTRACE_SINGLESTEP" },
1773 { PTRACE_ATTACH, "PTRACE_ATTACH" },
1774 { PTRACE_DETACH, "PTRACE_DETACH" },
1775#ifdef SUNOS4
1776 { PTRACE_GETREGS, "PTRACE_GETREGS" },
1777 { PTRACE_SETREGS, "PTRACE_SETREGS" },
1778 { PTRACE_GETFPREGS, "PTRACE_GETFPREGS", },
1779 { PTRACE_SETFPREGS, "PTRACE_SETFPREGS", },
1780 { PTRACE_READDATA, "PTRACE_READDATA" },
1781 { PTRACE_WRITEDATA, "PTRACE_WRITEDATA" },
1782 { PTRACE_READTEXT, "PTRACE_READTEXT" },
1783 { PTRACE_WRITETEXT, "PTRACE_WRITETEXT" },
1784 { PTRACE_GETFPAREGS, "PTRACE_GETFPAREGS" },
1785 { PTRACE_SETFPAREGS, "PTRACE_SETFPAREGS" },
1786#ifdef SPARC
1787 { PTRACE_GETWINDOW, "PTRACE_GETWINDOW" },
1788 { PTRACE_SETWINDOW, "PTRACE_SETWINDOW" },
1789#else /* !SPARC */
1790 { PTRACE_22, "PTRACE_PTRACE_22" },
1791 { PTRACE_23, "PTRACE_PTRACE_23" },
1792#endif /* !SPARC */
1793#endif /* SUNOS4 */
1794 { PTRACE_SYSCALL, "PTRACE_SYSCALL" },
1795#ifdef SUNOS4
1796 { PTRACE_DUMPCORE, "PTRACE_DUMPCORE" },
1797#ifdef I386
1798 { PTRACE_SETWRBKPT, "PTRACE_SETWRBKPT" },
1799 { PTRACE_SETACBKPT, "PTRACE_SETACBKPT" },
1800 { PTRACE_CLRDR7, "PTRACE_CLRDR7" },
1801#else /* !I386 */
1802 { PTRACE_26, "PTRACE_26" },
1803 { PTRACE_27, "PTRACE_27" },
1804 { PTRACE_28, "PTRACE_28" },
1805#endif /* !I386 */
1806 { PTRACE_GETUCODE, "PTRACE_GETUCODE" },
1807#endif /* SUNOS4 */
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001808#else /* FREEBSD */
1809 { PT_TRACE_ME, "PT_TRACE_ME" },
1810 { PT_READ_I, "PT_READ_I" },
1811 { PT_READ_D, "PT_READ_D" },
1812 { PT_WRITE_I, "PT_WRITE_I" },
1813 { PT_WRITE_D, "PT_WRITE_D" },
John Hughesa2278142001-09-28 16:21:30 +00001814#ifdef PT_READ_U
1815 { PT_READ_U, "PT_READ_U" },
1816#endif
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001817 { PT_CONTINUE, "PT_CONTINUE" },
1818 { PT_KILL, "PT_KILL" },
1819 { PT_STEP, "PT_STEP" },
1820 { PT_ATTACH, "PT_ATTACH" },
1821 { PT_DETACH, "PT_DETACH" },
1822 { PT_GETREGS, "PT_GETREGS" },
1823 { PT_SETREGS, "PT_SETREGS" },
1824 { PT_GETFPREGS, "PT_GETFPREGS" },
1825 { PT_SETFPREGS, "PT_SETFPREGS" },
1826 { PT_GETDBREGS, "PT_GETDBREGS" },
1827 { PT_SETDBREGS, "PT_SETDBREGS" },
1828#endif /* FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001829 { 0, NULL },
1830};
1831
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001832#ifndef FREEBSD
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001833#ifndef SUNOS4_KERNEL_ARCH_KLUDGE
1834static
1835#endif /* !SUNOS4_KERNEL_ARCH_KLUDGE */
1836struct xlat struct_user_offsets[] = {
1837#ifdef LINUX
Michal Ludvig10a88d02002-10-07 14:31:00 +00001838#if defined(S390) || defined(S390X)
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00001839 { PT_PSWMASK, "psw_mask" },
1840 { PT_PSWADDR, "psw_addr" },
1841 { PT_GPR0, "gpr0" },
1842 { PT_GPR1, "gpr1" },
1843 { PT_GPR2, "gpr2" },
1844 { PT_GPR3, "gpr3" },
1845 { PT_GPR4, "gpr4" },
1846 { PT_GPR5, "gpr5" },
1847 { PT_GPR6, "gpr6" },
1848 { PT_GPR7, "gpr7" },
1849 { PT_GPR8, "gpr8" },
1850 { PT_GPR9, "gpr9" },
1851 { PT_GPR10, "gpr10" },
1852 { PT_GPR11, "gpr11" },
1853 { PT_GPR12, "gpr12" },
1854 { PT_GPR13, "gpr13" },
1855 { PT_GPR14, "gpr14" },
1856 { PT_GPR15, "gpr15" },
1857 { PT_ACR0, "acr0" },
1858 { PT_ACR1, "acr1" },
1859 { PT_ACR2, "acr2" },
1860 { PT_ACR3, "acr3" },
1861 { PT_ACR4, "acr4" },
1862 { PT_ACR5, "acr5" },
1863 { PT_ACR6, "acr6" },
1864 { PT_ACR7, "acr7" },
1865 { PT_ACR8, "acr8" },
1866 { PT_ACR9, "acr9" },
1867 { PT_ACR10, "acr10" },
1868 { PT_ACR11, "acr11" },
1869 { PT_ACR12, "acr12" },
1870 { PT_ACR13, "acr13" },
1871 { PT_ACR14, "acr14" },
1872 { PT_ACR15, "acr15" },
1873 { PT_ORIGGPR2, "orig_gpr2" },
1874 { PT_FPC, "fpc" },
Michal Ludvig10a88d02002-10-07 14:31:00 +00001875#if defined(S390)
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00001876 { PT_FPR0_HI, "fpr0.hi" },
1877 { PT_FPR0_LO, "fpr0.lo" },
1878 { PT_FPR1_HI, "fpr1.hi" },
1879 { PT_FPR1_LO, "fpr1.lo" },
1880 { PT_FPR2_HI, "fpr2.hi" },
1881 { PT_FPR2_LO, "fpr2.lo" },
1882 { PT_FPR3_HI, "fpr3.hi" },
1883 { PT_FPR3_LO, "fpr3.lo" },
1884 { PT_FPR4_HI, "fpr4.hi" },
1885 { PT_FPR4_LO, "fpr4.lo" },
1886 { PT_FPR5_HI, "fpr5.hi" },
1887 { PT_FPR5_LO, "fpr5.lo" },
1888 { PT_FPR6_HI, "fpr6.hi" },
1889 { PT_FPR6_LO, "fpr6.lo" },
1890 { PT_FPR7_HI, "fpr7.hi" },
1891 { PT_FPR7_LO, "fpr7.lo" },
1892 { PT_FPR8_HI, "fpr8.hi" },
1893 { PT_FPR8_LO, "fpr8.lo" },
1894 { PT_FPR9_HI, "fpr9.hi" },
1895 { PT_FPR9_LO, "fpr9.lo" },
1896 { PT_FPR10_HI, "fpr10.hi" },
1897 { PT_FPR10_LO, "fpr10.lo" },
1898 { PT_FPR11_HI, "fpr11.hi" },
1899 { PT_FPR11_LO, "fpr11.lo" },
1900 { PT_FPR12_HI, "fpr12.hi" },
1901 { PT_FPR12_LO, "fpr12.lo" },
1902 { PT_FPR13_HI, "fpr13.hi" },
1903 { PT_FPR13_LO, "fpr13.lo" },
1904 { PT_FPR14_HI, "fpr14.hi" },
1905 { PT_FPR14_LO, "fpr14.lo" },
1906 { PT_FPR15_HI, "fpr15.hi" },
1907 { PT_FPR15_LO, "fpr15.lo" },
Michal Ludvig10a88d02002-10-07 14:31:00 +00001908#endif
1909#if defined(S390X)
1910 { PT_FPR0, "fpr0" },
1911 { PT_FPR1, "fpr1" },
1912 { PT_FPR2, "fpr2" },
1913 { PT_FPR3, "fpr3" },
1914 { PT_FPR4, "fpr4" },
1915 { PT_FPR5, "fpr5" },
1916 { PT_FPR6, "fpr6" },
1917 { PT_FPR7, "fpr7" },
1918 { PT_FPR8, "fpr8" },
1919 { PT_FPR9, "fpr9" },
1920 { PT_FPR10, "fpr10" },
1921 { PT_FPR11, "fpr11" },
1922 { PT_FPR12, "fpr12" },
1923 { PT_FPR13, "fpr13" },
1924 { PT_FPR14, "fpr14" },
1925 { PT_FPR15, "fpr15" },
1926#endif
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00001927 { PT_CR_9, "cr9" },
1928 { PT_CR_10, "cr10" },
1929 { PT_CR_11, "cr11" },
Michal Ludvig10a88d02002-10-07 14:31:00 +00001930 { PT_IEEE_IP, "ieee_exception_ip" },
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00001931#endif
1932#if defined(SPARC)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001933 /* XXX No support for these offsets yet. */
Wichert Akkermanc1652e22001-03-27 12:17:16 +00001934#elif defined(HPPA)
1935 /* XXX No support for these offsets yet. */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001936#elif defined(POWERPC)
Roland McGrath5a223472002-12-15 23:58:26 +00001937#ifndef PT_ORIG_R3
1938#define PT_ORIG_R3 34
1939#endif
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00001940 { 4*PT_R0, "4*PT_R0" },
1941 { 4*PT_R1, "4*PT_R1" },
1942 { 4*PT_R2, "4*PT_R2" },
1943 { 4*PT_R3, "4*PT_R3" },
1944 { 4*PT_R4, "4*PT_R4" },
1945 { 4*PT_R5, "4*PT_R5" },
1946 { 4*PT_R6, "4*PT_R6" },
1947 { 4*PT_R7, "4*PT_R7" },
1948 { 4*PT_R8, "4*PT_R8" },
1949 { 4*PT_R9, "4*PT_R9" },
1950 { 4*PT_R10, "4*PT_R10" },
1951 { 4*PT_R11, "4*PT_R11" },
1952 { 4*PT_R12, "4*PT_R12" },
1953 { 4*PT_R13, "4*PT_R13" },
1954 { 4*PT_R14, "4*PT_R14" },
1955 { 4*PT_R15, "4*PT_R15" },
1956 { 4*PT_R16, "4*PT_R16" },
1957 { 4*PT_R17, "4*PT_R17" },
1958 { 4*PT_R18, "4*PT_R18" },
1959 { 4*PT_R19, "4*PT_R19" },
1960 { 4*PT_R20, "4*PT_R20" },
1961 { 4*PT_R21, "4*PT_R21" },
1962 { 4*PT_R22, "4*PT_R22" },
1963 { 4*PT_R23, "4*PT_R23" },
1964 { 4*PT_R24, "4*PT_R24" },
1965 { 4*PT_R25, "4*PT_R25" },
1966 { 4*PT_R26, "4*PT_R26" },
1967 { 4*PT_R27, "4*PT_R27" },
1968 { 4*PT_R28, "4*PT_R28" },
1969 { 4*PT_R29, "4*PT_R29" },
1970 { 4*PT_R30, "4*PT_R30" },
1971 { 4*PT_R31, "4*PT_R31" },
1972 { 4*PT_NIP, "4*PT_NIP" },
1973 { 4*PT_MSR, "4*PT_MSR" },
1974 { 4*PT_ORIG_R3, "4*PT_ORIG_R3" },
1975 { 4*PT_CTR, "4*PT_CTR" },
1976 { 4*PT_LNK, "4*PT_LNK" },
1977 { 4*PT_XER, "4*PT_XER" },
1978 { 4*PT_CCR, "4*PT_CCR" },
1979 { 4*PT_FPR0, "4*PT_FPR0" },
Roland McGrath5a223472002-12-15 23:58:26 +00001980#else
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001981#ifdef ALPHA
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00001982 { 0, "r0" },
1983 { 1, "r1" },
1984 { 2, "r2" },
1985 { 3, "r3" },
1986 { 4, "r4" },
1987 { 5, "r5" },
1988 { 6, "r6" },
1989 { 7, "r7" },
1990 { 8, "r8" },
1991 { 9, "r9" },
1992 { 10, "r10" },
1993 { 11, "r11" },
1994 { 12, "r12" },
1995 { 13, "r13" },
1996 { 14, "r14" },
1997 { 15, "r15" },
1998 { 16, "r16" },
1999 { 17, "r17" },
2000 { 18, "r18" },
2001 { 19, "r19" },
2002 { 20, "r20" },
2003 { 21, "r21" },
2004 { 22, "r22" },
2005 { 23, "r23" },
2006 { 24, "r24" },
2007 { 25, "r25" },
2008 { 26, "r26" },
2009 { 27, "r27" },
2010 { 28, "r28" },
2011 { 29, "gp" },
2012 { 30, "fp" },
2013 { 31, "zero" },
2014 { 32, "fp0" },
2015 { 33, "fp" },
2016 { 34, "fp2" },
2017 { 35, "fp3" },
2018 { 36, "fp4" },
2019 { 37, "fp5" },
2020 { 38, "fp6" },
2021 { 39, "fp7" },
2022 { 40, "fp8" },
2023 { 41, "fp9" },
2024 { 42, "fp10" },
2025 { 43, "fp11" },
2026 { 44, "fp12" },
2027 { 45, "fp13" },
2028 { 46, "fp14" },
2029 { 47, "fp15" },
2030 { 48, "fp16" },
2031 { 49, "fp17" },
2032 { 50, "fp18" },
2033 { 51, "fp19" },
2034 { 52, "fp20" },
2035 { 53, "fp21" },
2036 { 54, "fp22" },
2037 { 55, "fp23" },
2038 { 56, "fp24" },
2039 { 57, "fp25" },
2040 { 58, "fp26" },
2041 { 59, "fp27" },
2042 { 60, "fp28" },
2043 { 61, "fp29" },
2044 { 62, "fp30" },
2045 { 63, "fp31" },
2046 { 64, "pc" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002047#else /* !ALPHA */
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00002048#ifdef IA64
2049 { PT_F32, "f32" }, { PT_F33, "f33" }, { PT_F34, "f34" },
2050 { PT_F35, "f35" }, { PT_F36, "f36" }, { PT_F37, "f37" },
2051 { PT_F38, "f38" }, { PT_F39, "f39" }, { PT_F40, "f40" },
2052 { PT_F41, "f41" }, { PT_F42, "f42" }, { PT_F43, "f43" },
2053 { PT_F44, "f44" }, { PT_F45, "f45" }, { PT_F46, "f46" },
2054 { PT_F47, "f47" }, { PT_F48, "f48" }, { PT_F49, "f49" },
2055 { PT_F50, "f50" }, { PT_F51, "f51" }, { PT_F52, "f52" },
2056 { PT_F53, "f53" }, { PT_F54, "f54" }, { PT_F55, "f55" },
2057 { PT_F56, "f56" }, { PT_F57, "f57" }, { PT_F58, "f58" },
2058 { PT_F59, "f59" }, { PT_F60, "f60" }, { PT_F61, "f61" },
2059 { PT_F62, "f62" }, { PT_F63, "f63" }, { PT_F64, "f64" },
2060 { PT_F65, "f65" }, { PT_F66, "f66" }, { PT_F67, "f67" },
2061 { PT_F68, "f68" }, { PT_F69, "f69" }, { PT_F70, "f70" },
2062 { PT_F71, "f71" }, { PT_F72, "f72" }, { PT_F73, "f73" },
2063 { PT_F74, "f74" }, { PT_F75, "f75" }, { PT_F76, "f76" },
2064 { PT_F77, "f77" }, { PT_F78, "f78" }, { PT_F79, "f79" },
2065 { PT_F80, "f80" }, { PT_F81, "f81" }, { PT_F82, "f82" },
2066 { PT_F83, "f83" }, { PT_F84, "f84" }, { PT_F85, "f85" },
2067 { PT_F86, "f86" }, { PT_F87, "f87" }, { PT_F88, "f88" },
2068 { PT_F89, "f89" }, { PT_F90, "f90" }, { PT_F91, "f91" },
2069 { PT_F92, "f92" }, { PT_F93, "f93" }, { PT_F94, "f94" },
2070 { PT_F95, "f95" }, { PT_F96, "f96" }, { PT_F97, "f97" },
2071 { PT_F98, "f98" }, { PT_F99, "f99" }, { PT_F100, "f100" },
2072 { PT_F101, "f101" }, { PT_F102, "f102" }, { PT_F103, "f103" },
2073 { PT_F104, "f104" }, { PT_F105, "f105" }, { PT_F106, "f106" },
2074 { PT_F107, "f107" }, { PT_F108, "f108" }, { PT_F109, "f109" },
2075 { PT_F110, "f110" }, { PT_F111, "f111" }, { PT_F112, "f112" },
2076 { PT_F113, "f113" }, { PT_F114, "f114" }, { PT_F115, "f115" },
2077 { PT_F116, "f116" }, { PT_F117, "f117" }, { PT_F118, "f118" },
2078 { PT_F119, "f119" }, { PT_F120, "f120" }, { PT_F121, "f121" },
2079 { PT_F122, "f122" }, { PT_F123, "f123" }, { PT_F124, "f124" },
2080 { PT_F125, "f125" }, { PT_F126, "f126" }, { PT_F127, "f127" },
2081 /* switch stack: */
2082 { PT_F2, "f2" }, { PT_F3, "f3" }, { PT_F4, "f4" },
2083 { PT_F5, "f5" }, { PT_F10, "f10" }, { PT_F11, "f11" },
2084 { PT_F12, "f12" }, { PT_F13, "f13" }, { PT_F14, "f14" },
2085 { PT_F15, "f15" }, { PT_F16, "f16" }, { PT_F17, "f17" },
2086 { PT_F18, "f18" }, { PT_F19, "f19" }, { PT_F20, "f20" },
2087 { PT_F21, "f21" }, { PT_F22, "f22" }, { PT_F23, "f23" },
2088 { PT_F24, "f24" }, { PT_F25, "f25" }, { PT_F26, "f26" },
2089 { PT_F27, "f27" }, { PT_F28, "f28" }, { PT_F29, "f29" },
2090 { PT_F30, "f30" }, { PT_F31, "f31" }, { PT_R4, "r4" },
2091 { PT_R5, "r5" }, { PT_R6, "r6" }, { PT_R7, "r7" },
Wichert Akkerman82b162e2001-08-03 11:51:28 +00002092 { PT_B0, "kb0" },
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00002093 { PT_B1, "b1" }, { PT_B2, "b2" }, { PT_B3, "b3" },
2094 { PT_B4, "b4" }, { PT_B5, "b5" },
Wichert Akkerman82b162e2001-08-03 11:51:28 +00002095 { PT_AR_PFS, "kar.pfs" },
2096 { PT_AR_LC, "ar.lc" }, { PT_AR_UNAT, "kar.unat" },
2097 { PT_AR_RNAT, "kar.rnat" }, { PT_AR_BSPSTORE, "kar.bspstore" },
2098 { PT_PR, "k.pr" },
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00002099 /* pt_regs */
2100 { PT_CR_IPSR, "cr.ipsr" }, { PT_CR_IIP, "cr.iip" },
Wichert Akkerman82b162e2001-08-03 11:51:28 +00002101 /*{ PT_CR_IFS, "cr.ifs" },*/ { PT_AR_UNAT, "ar.unat" },
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00002102 { PT_AR_PFS, "ar.pfs" }, { PT_AR_RSC, "ar.rsc" },
2103 { PT_AR_RNAT, "ar.rnat" }, { PT_AR_BSPSTORE, "ar.bspstore" },
2104 { PT_PR, "pr" }, { PT_B6, "b6" }, { PT_AR_BSP, "ar.bsp" },
2105 { PT_R1, "r1" }, { PT_R2, "r2" }, { PT_R3, "r3" },
2106 { PT_R12, "r12" }, { PT_R13, "r13" }, { PT_R14, "r14" },
2107 { PT_R15, "r15" }, { PT_R8, "r8" }, { PT_R9, "r9" },
2108 { PT_R10, "r10" }, { PT_R11, "r11" }, { PT_R16, "r16" },
2109 { PT_R17, "r17" }, { PT_R18, "r18" }, { PT_R19, "r19" },
2110 { PT_R20, "r20" }, { PT_R21, "r21" }, { PT_R22, "r22" },
2111 { PT_R23, "r23" }, { PT_R24, "r24" }, { PT_R25, "r25" },
2112 { PT_R26, "r26" }, { PT_R27, "r27" }, { PT_R28, "r28" },
2113 { PT_R29, "r29" }, { PT_R30, "r30" }, { PT_R31, "r31" },
2114 { PT_AR_CCV, "ar.ccv" }, { PT_AR_FPSR, "ar.fpsr" },
2115 { PT_B0, "b0" }, { PT_B7, "b7" }, { PT_F6, "f6" },
2116 { PT_F7, "f7" }, { PT_F8, "f8" }, { PT_F9, "f9" },
2117#else /* !IA64 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002118#ifdef I386
2119 { 4*EBX, "4*EBX" },
2120 { 4*ECX, "4*ECX" },
2121 { 4*EDX, "4*EDX" },
2122 { 4*ESI, "4*ESI" },
2123 { 4*EDI, "4*EDI" },
2124 { 4*EBP, "4*EBP" },
2125 { 4*EAX, "4*EAX" },
2126 { 4*DS, "4*DS" },
2127 { 4*ES, "4*ES" },
2128 { 4*FS, "4*FS" },
2129 { 4*GS, "4*GS" },
2130 { 4*ORIG_EAX, "4*ORIG_EAX" },
2131 { 4*EIP, "4*EIP" },
2132 { 4*CS, "4*CS" },
2133 { 4*EFL, "4*EFL" },
2134 { 4*UESP, "4*UESP" },
2135 { 4*SS, "4*SS" },
2136#else /* !I386 */
Michal Ludvig0e035502002-09-23 15:41:01 +00002137#ifdef X86_64
2138 { 8*RDI, "8*RDI" },
2139 { 8*RSI, "8*RSI" },
2140 { 8*RDX, "8*RDX" },
2141 { 8*R10, "8*R10" },
2142 { 8*R8, "8*R8" },
2143 { 8*R9, "8*R9" },
2144 { 8*RBX, "8*RBX" },
2145 { 8*RCX, "8*RCX" },
2146 { 8*RBP, "8*RBP" },
2147 { 8*RAX, "8*RAX" },
2148#if 0
2149 { 8*DS, "8*DS" },
2150 { 8*ES, "8*ES" },
2151 { 8*FS, "8*FS" },
2152 { 8*GS, "8*GS" },
2153#endif
2154 { 8*ORIG_RAX, "8*ORIG_EAX" },
2155 { 8*RIP, "8*RIP" },
2156 { 8*CS, "8*CS" },
2157 { 8*EFLAGS, "8*EFL" },
2158 { 8*RSP, "8*RSP" },
2159 { 8*SS, "8*SS" },
2160 { 8*R11, "8*R11" },
2161 { 8*R12, "8*R12" },
2162 { 8*R13, "8*R13" },
2163 { 8*R14, "8*R14" },
2164 { 8*R15, "8*R15" },
2165#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002166#ifdef M68K
2167 { 4*PT_D1, "4*PT_D1" },
2168 { 4*PT_D2, "4*PT_D2" },
2169 { 4*PT_D3, "4*PT_D3" },
2170 { 4*PT_D4, "4*PT_D4" },
2171 { 4*PT_D5, "4*PT_D5" },
2172 { 4*PT_D6, "4*PT_D6" },
2173 { 4*PT_D7, "4*PT_D7" },
2174 { 4*PT_A0, "4*PT_A0" },
2175 { 4*PT_A1, "4*PT_A1" },
2176 { 4*PT_A2, "4*PT_A2" },
2177 { 4*PT_A3, "4*PT_A3" },
2178 { 4*PT_A4, "4*PT_A4" },
2179 { 4*PT_A5, "4*PT_A5" },
2180 { 4*PT_A6, "4*PT_A6" },
2181 { 4*PT_D0, "4*PT_D0" },
2182 { 4*PT_USP, "4*PT_USP" },
2183 { 4*PT_ORIG_D0, "4*PT_ORIG_D0" },
2184 { 4*PT_SR, "4*PT_SR" },
2185 { 4*PT_PC, "4*PT_PC" },
2186#endif /* M68K */
2187#endif /* !I386 */
Wichert Akkermanccef6372002-05-01 16:39:22 +00002188#ifdef SH
2189 { 4*REG_REG0, "4*REG_REG0" },
2190 { 4*(REG_REG0+1), "4*REG_REG1" },
2191 { 4*(REG_REG0+2), "4*REG_REG2" },
2192 { 4*(REG_REG0+3), "4*REG_REG3" },
2193 { 4*(REG_REG0+4), "4*REG_REG4" },
2194 { 4*(REG_REG0+5), "4*REG_REG5" },
2195 { 4*(REG_REG0+6), "4*REG_REG6" },
2196 { 4*(REG_REG0+7), "4*REG_REG7" },
2197 { 4*(REG_REG0+8), "4*REG_REG8" },
2198 { 4*(REG_REG0+9), "4*REG_REG9" },
2199 { 4*(REG_REG0+10), "4*REG_REG10" },
2200 { 4*(REG_REG0+11), "4*REG_REG11" },
2201 { 4*(REG_REG0+12), "4*REG_REG12" },
2202 { 4*(REG_REG0+13), "4*REG_REG13" },
2203 { 4*(REG_REG0+14), "4*REG_REG14" },
2204 { 4*REG_REG15, "4*REG_REG15" },
2205 { 4*REG_PC, "4*REG_PC" },
2206 { 4*REG_PR, "4*REG_PR" },
2207 { 4*REG_SR, "4*REG_SR" },
2208 { 4*REG_GBR, "4*REG_GBR" },
2209 { 4*REG_MACH, "4*REG_MACH" },
2210 { 4*REG_MACL, "4*REG_MACL" },
2211 { 4*REG_SYSCALL, "4*REG_SYSCALL" },
2212 { 4*REG_FPUL, "4*REG_FPUL" },
2213 { 4*REG_FPREG0, "4*REG_FPREG0" },
2214 { 4*(REG_FPREG0+1), "4*REG_FPREG1" },
2215 { 4*(REG_FPREG0+2), "4*REG_FPREG2" },
2216 { 4*(REG_FPREG0+3), "4*REG_FPREG3" },
2217 { 4*(REG_FPREG0+4), "4*REG_FPREG4" },
2218 { 4*(REG_FPREG0+5), "4*REG_FPREG5" },
2219 { 4*(REG_FPREG0+6), "4*REG_FPREG6" },
2220 { 4*(REG_FPREG0+7), "4*REG_FPREG7" },
2221 { 4*(REG_FPREG0+8), "4*REG_FPREG8" },
2222 { 4*(REG_FPREG0+9), "4*REG_FPREG9" },
2223 { 4*(REG_FPREG0+10), "4*REG_FPREG10" },
2224 { 4*(REG_FPREG0+11), "4*REG_FPREG11" },
2225 { 4*(REG_FPREG0+12), "4*REG_FPREG12" },
2226 { 4*(REG_FPREG0+13), "4*REG_FPREG13" },
2227 { 4*(REG_FPREG0+14), "4*REG_FPREG14" },
2228 { 4*REG_FPREG15, "4*REG_FPREG15" },
2229 { 4*REG_XDREG0, "4*REG_XDREG0" },
2230 { 4*(REG_XDREG0+2), "4*REG_XDREG2" },
2231 { 4*(REG_XDREG0+4), "4*REG_XDREG4" },
2232 { 4*(REG_XDREG0+6), "4*REG_XDREG6" },
2233 { 4*(REG_XDREG0+8), "4*REG_XDREG8" },
2234 { 4*(REG_XDREG0+10), "4*REG_XDREG10" },
2235 { 4*(REG_XDREG0+12), "4*REG_XDREG12" },
2236 { 4*REG_XDREG14, "4*REG_XDREG14" },
2237 { 4*REG_FPSCR, "4*REG_FPSCR" },
2238#endif /* SH */
2239
Michal Ludvig10a88d02002-10-07 14:31:00 +00002240#if !defined(S390) && !defined(S390X) && !defined(MIPS)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002241 { uoff(u_fpvalid), "offsetof(struct user, u_fpvalid)" },
Wichert Akkermanf90da011999-10-31 21:15:38 +00002242#endif
Michal Ludvig0e035502002-09-23 15:41:01 +00002243#if defined(I386) || defined(X86_64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002244 { uoff(i387), "offsetof(struct user, i387)" },
2245#else /* !I386 */
2246#ifdef M68K
2247 { uoff(m68kfp), "offsetof(struct user, m68kfp)" },
2248#endif /* M68K */
2249#endif /* !I386 */
2250 { uoff(u_tsize), "offsetof(struct user, u_tsize)" },
2251 { uoff(u_dsize), "offsetof(struct user, u_dsize)" },
2252 { uoff(u_ssize), "offsetof(struct user, u_ssize)" },
2253 { uoff(start_code), "offsetof(struct user, start_code)" },
2254 { uoff(start_stack), "offsetof(struct user, start_stack)" },
2255 { uoff(signal), "offsetof(struct user, signal)" },
Michal Ludvig10a88d02002-10-07 14:31:00 +00002256#if !defined(S390) && !defined(S390X) && !defined(MIPS) && !defined(SH)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002257 { uoff(reserved), "offsetof(struct user, reserved)" },
Wichert Akkermanf90da011999-10-31 21:15:38 +00002258#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002259 { uoff(u_ar0), "offsetof(struct user, u_ar0)" },
Michal Ludvig10a88d02002-10-07 14:31:00 +00002260#if !defined(ARM) && !defined(MIPS) && !defined(S390) && !defined(S390X)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002261 { uoff(u_fpstate), "offsetof(struct user, u_fpstate)" },
2262#endif
2263 { uoff(magic), "offsetof(struct user, magic)" },
2264 { uoff(u_comm), "offsetof(struct user, u_comm)" },
Michal Ludvig0e035502002-09-23 15:41:01 +00002265#if defined(I386) || defined(X86_64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002266 { uoff(u_debugreg), "offsetof(struct user, u_debugreg)" },
2267#endif /* I386 */
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00002268#endif /* !IA64 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002269#endif /* !ALPHA */
2270#endif /* !POWERPC/!SPARC */
2271#endif /* LINUX */
2272#ifdef SUNOS4
2273 { uoff(u_pcb), "offsetof(struct user, u_pcb)" },
2274 { uoff(u_procp), "offsetof(struct user, u_procp)" },
2275 { uoff(u_ar0), "offsetof(struct user, u_ar0)" },
2276 { uoff(u_comm[0]), "offsetof(struct user, u_comm[0])" },
2277 { uoff(u_arg[0]), "offsetof(struct user, u_arg[0])" },
2278 { uoff(u_ap), "offsetof(struct user, u_ap)" },
2279 { uoff(u_qsave), "offsetof(struct user, u_qsave)" },
2280 { uoff(u_rval1), "offsetof(struct user, u_rval1)" },
2281 { uoff(u_rval2), "offsetof(struct user, u_rval2)" },
2282 { uoff(u_error), "offsetof(struct user, u_error)" },
2283 { uoff(u_eosys), "offsetof(struct user, u_eosys)" },
2284 { uoff(u_ssave), "offsetof(struct user, u_ssave)" },
2285 { uoff(u_signal[0]), "offsetof(struct user, u_signal)" },
2286 { uoff(u_sigmask[0]), "offsetof(struct user, u_sigmask)" },
2287 { uoff(u_sigonstack), "offsetof(struct user, u_sigonstack)" },
2288 { uoff(u_sigintr), "offsetof(struct user, u_sigintr)" },
2289 { uoff(u_sigreset), "offsetof(struct user, u_sigreset)" },
2290 { uoff(u_oldmask), "offsetof(struct user, u_oldmask)" },
2291 { uoff(u_code), "offsetof(struct user, u_code)" },
2292 { uoff(u_addr), "offsetof(struct user, u_addr)" },
2293 { uoff(u_sigstack), "offsetof(struct user, u_sigstack)" },
2294 { uoff(u_ofile), "offsetof(struct user, u_ofile)" },
2295 { uoff(u_pofile), "offsetof(struct user, u_pofile)" },
2296 { uoff(u_ofile_arr[0]), "offsetof(struct user, u_ofile_arr[0])" },
2297 { uoff(u_pofile_arr[0]),"offsetof(struct user, u_pofile_arr[0])"},
2298 { uoff(u_lastfile), "offsetof(struct user, u_lastfile)" },
2299 { uoff(u_cwd), "offsetof(struct user, u_cwd)" },
2300 { uoff(u_cdir), "offsetof(struct user, u_cdir)" },
2301 { uoff(u_rdir), "offsetof(struct user, u_rdir)" },
2302 { uoff(u_cmask), "offsetof(struct user, u_cmask)" },
2303 { uoff(u_ru), "offsetof(struct user, u_ru)" },
2304 { uoff(u_cru), "offsetof(struct user, u_cru)" },
2305 { uoff(u_timer[0]), "offsetof(struct user, u_timer[0])" },
2306 { uoff(u_XXX[0]), "offsetof(struct user, u_XXX[0])" },
2307 { uoff(u_ioch), "offsetof(struct user, u_ioch)" },
2308 { uoff(u_start), "offsetof(struct user, u_start)" },
2309 { uoff(u_acflag), "offsetof(struct user, u_acflag)" },
2310 { uoff(u_prof.pr_base), "offsetof(struct user, u_prof.pr_base)" },
2311 { uoff(u_prof.pr_size), "offsetof(struct user, u_prof.pr_size)" },
2312 { uoff(u_prof.pr_off), "offsetof(struct user, u_prof.pr_off)" },
2313 { uoff(u_prof.pr_scale),"offsetof(struct user, u_prof.pr_scale)"},
2314 { uoff(u_rlimit[0]), "offsetof(struct user, u_rlimit)" },
2315 { uoff(u_exdata.Ux_A), "offsetof(struct user, u_exdata.Ux_A)" },
2316 { uoff(u_exdata.ux_shell[0]),"offsetof(struct user, u_exdata.ux_shell[0])"},
2317 { uoff(u_lofault), "offsetof(struct user, u_lofault)" },
2318#endif /* SUNOS4 */
Wichert Akkermanc1652e22001-03-27 12:17:16 +00002319#ifndef HPPA
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002320 { sizeof(struct user), "sizeof(struct user)" },
Wichert Akkermanc1652e22001-03-27 12:17:16 +00002321#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002322 { 0, NULL },
2323};
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002324#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002325
2326int
2327sys_ptrace(tcp)
2328struct tcb *tcp;
2329{
2330 char *cmd;
2331 struct xlat *x;
2332 long addr;
2333
2334 cmd = xlookup(ptrace_cmds, tcp->u_arg[0]);
2335 if (!cmd)
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002336#ifndef FREEBSD
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002337 cmd = "PTRACE_???";
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002338#else
2339 cmd = "PT_???";
Roland McGrath5a223472002-12-15 23:58:26 +00002340#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002341 if (entering(tcp)) {
2342 tprintf("%s, %lu, ", cmd, tcp->u_arg[1]);
2343 addr = tcp->u_arg[2];
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002344#ifndef FREEBSD
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002345 if (tcp->u_arg[0] == PTRACE_PEEKUSER
2346 || tcp->u_arg[0] == PTRACE_POKEUSER) {
2347 for (x = struct_user_offsets; x->str; x++) {
2348 if (x->val >= addr)
2349 break;
2350 }
2351 if (!x->str)
2352 tprintf("%#lx, ", addr);
2353 else if (x->val > addr && x != struct_user_offsets) {
2354 x--;
2355 tprintf("%s + %ld, ", x->str, addr - x->val);
2356 }
2357 else
2358 tprintf("%s, ", x->str);
2359 }
2360 else
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002361#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002362 tprintf("%#lx, ", tcp->u_arg[2]);
2363#ifdef LINUX
2364 switch (tcp->u_arg[0]) {
2365 case PTRACE_PEEKDATA:
2366 case PTRACE_PEEKTEXT:
2367 case PTRACE_PEEKUSER:
2368 break;
2369 case PTRACE_CONT:
2370 case PTRACE_SINGLESTEP:
2371 case PTRACE_SYSCALL:
2372 case PTRACE_DETACH:
2373 printsignal(tcp->u_arg[3]);
2374 break;
2375 default:
2376 tprintf("%#lx", tcp->u_arg[3]);
2377 break;
2378 }
2379 } else {
2380 switch (tcp->u_arg[0]) {
2381 case PTRACE_PEEKDATA:
2382 case PTRACE_PEEKTEXT:
2383 case PTRACE_PEEKUSER:
2384 printnum(tcp, tcp->u_arg[3], "%#x");
2385 break;
2386 }
2387 }
2388#endif /* LINUX */
2389#ifdef SUNOS4
2390 if (tcp->u_arg[0] == PTRACE_WRITEDATA ||
2391 tcp->u_arg[0] == PTRACE_WRITETEXT) {
2392 tprintf("%lu, ", tcp->u_arg[3]);
2393 printstr(tcp, tcp->u_arg[4], tcp->u_arg[3]);
2394 } else if (tcp->u_arg[0] != PTRACE_READDATA &&
2395 tcp->u_arg[0] != PTRACE_READTEXT) {
2396 tprintf("%#lx", tcp->u_arg[3]);
2397 }
2398 } else {
2399 if (tcp->u_arg[0] == PTRACE_READDATA ||
2400 tcp->u_arg[0] == PTRACE_READTEXT) {
2401 tprintf("%lu, ", tcp->u_arg[3]);
2402 printstr(tcp, tcp->u_arg[4], tcp->u_arg[3]);
2403 }
2404 }
2405#endif /* SUNOS4 */
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002406#ifdef FREEBSD
2407 tprintf("%lu", tcp->u_arg[3]);
2408 }
2409#endif /* FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002410 return 0;
2411}
2412
2413#endif /* !SVR4 */
Roland McGrath5a223472002-12-15 23:58:26 +00002414
2415#ifdef LINUX
2416static struct xlat futexops[] = {
2417 { FUTEX_WAIT, "FUTEX_WAIT" },
2418 { FUTEX_WAKE, "FUTEX_WAKE" },
2419 { FUTEX_FD, "FUTEX_FD" },
2420 { 0, NULL }
2421};
2422
2423int
2424sys_futex(tcp)
2425struct tcb *tcp;
2426{
2427 if (entering(tcp)) {
2428 tprintf("%p, ", (void *) tcp->u_arg[0]);
2429 printflags(futexops, tcp->u_arg[1]);
2430 tprintf(", %ld, ", tcp->u_arg[2]);
2431 printtv(tcp, tcp->u_arg[3]);
2432 }
2433 return 0;
2434}
2435
2436static void
2437print_affinitylist(list, len)
2438unsigned long *list;
2439unsigned int len;
2440{
2441 int first = 1;
2442 tprintf(" {");
2443 while (len > sizeof (unsigned long)) {
2444 tprintf("%s %lx", first ? "" : ",", *list++);
2445 first = 0;
2446 len -= sizeof (unsigned long);
2447 }
2448 tprintf(" }");
2449}
2450
2451int
2452sys_sched_setaffinity(tcp)
2453struct tcb *tcp;
2454{
2455 if (entering(tcp)) {
2456 tprintf("%ld, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
2457 print_affinitylist((unsigned long *) tcp->u_arg[2], tcp->u_arg[1]);
2458 }
2459 return 0;
2460}
2461
2462int
2463sys_sched_getaffinity(tcp)
2464struct tcb *tcp;
2465{
2466 if (entering(tcp)) {
2467 tprintf("%ld, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
2468 } else {
2469 print_affinitylist((unsigned long *) tcp->u_arg[2], tcp->u_rval);
2470 }
2471 return 0;
2472}
2473#endif