blob: 48237c3f718d9eab311dc9160858e6a3b1d8097b [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 Akkerman15dea971999-10-06 13:06:34 +000081#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000082
Roland McGrath5bd7cf82003-01-24 04:31:18 +000083#ifdef HAVE_LINUX_PTRACE_H
84#undef PTRACE_SYSCALL
85#include <linux/ptrace.h>
86#endif
87
Roland McGrath5a223472002-12-15 23:58:26 +000088#ifdef HAVE_LINUX_FUTEX_H
89#include <linux/futex.h>
90#endif
91#if defined LINUX
92# ifndef FUTEX_WAIT
93# define FUTEX_WAIT 0
94# endif
95# ifndef FUTEX_WAKE
96# define FUTEX_WAKE 1
97# endif
98# ifndef FUTEX_FD
99# define FUTEX_FD 2
100# endif
Roland McGrath88812d62003-06-26 22:27:23 +0000101# ifndef FUTEX_REQUEUE
102# define FUTEX_REQUEUE 3
103# endif
Roland McGrath5a223472002-12-15 23:58:26 +0000104#endif
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000105
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000106#ifdef LINUX
Roland McGrath279d3782004-03-01 20:27:37 +0000107#include <sched.h>
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000108#include <asm/posix_types.h>
109#undef GETGROUPS_T
110#define GETGROUPS_T __kernel_gid_t
Roland McGrath83bd47a2003-11-13 22:32:26 +0000111#undef GETGROUPS32_T
112#define GETGROUPS32_T __kernel_gid32_t
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000113#endif /* LINUX */
114
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000115#if defined(LINUX) && defined(IA64)
116# include <asm/ptrace_offsets.h>
117# include <asm/rse.h>
118#endif
119
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000120#ifdef HAVE_PRCTL
121#include <sys/prctl.h>
122#endif
123
124#ifndef WCOREDUMP
125#define WCOREDUMP(status) ((status) & 0200)
126#endif
127
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000128/* WTA: this was `&& !defined(LINUXSPARC)', this seems unneeded though? */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000129#if defined(HAVE_PRCTL)
130static struct xlat prctl_options[] = {
131#ifdef PR_MAXPROCS
132 { PR_MAXPROCS, "PR_MAXPROCS" },
133#endif
134#ifdef PR_ISBLOCKED
135 { PR_ISBLOCKED, "PR_ISBLOCKED" },
136#endif
137#ifdef PR_SETSTACKSIZE
138 { PR_SETSTACKSIZE, "PR_SETSTACKSIZE" },
139#endif
140#ifdef PR_GETSTACKSIZE
141 { PR_GETSTACKSIZE, "PR_GETSTACKSIZE" },
142#endif
143#ifdef PR_MAXPPROCS
144 { PR_MAXPPROCS, "PR_MAXPPROCS" },
145#endif
146#ifdef PR_UNBLKONEXEC
147 { PR_UNBLKONEXEC, "PR_UNBLKONEXEC" },
148#endif
149#ifdef PR_ATOMICSIM
150 { PR_ATOMICSIM, "PR_ATOMICSIM" },
151#endif
152#ifdef PR_SETEXITSIG
153 { PR_SETEXITSIG, "PR_SETEXITSIG" },
154#endif
155#ifdef PR_RESIDENT
156 { PR_RESIDENT, "PR_RESIDENT" },
157#endif
158#ifdef PR_ATTACHADDR
159 { PR_ATTACHADDR, "PR_ATTACHADDR" },
160#endif
161#ifdef PR_DETACHADDR
162 { PR_DETACHADDR, "PR_DETACHADDR" },
163#endif
164#ifdef PR_TERMCHILD
165 { PR_TERMCHILD, "PR_TERMCHILD" },
166#endif
167#ifdef PR_GETSHMASK
168 { PR_GETSHMASK, "PR_GETSHMASK" },
169#endif
170#ifdef PR_GETNSHARE
171 { PR_GETNSHARE, "PR_GETNSHARE" },
172#endif
173#if defined(PR_SET_PDEATHSIG)
174 { PR_SET_PDEATHSIG, "PR_SET_PDEATHSIG" },
175#endif
Wichert Akkerman8829a551999-06-11 13:18:40 +0000176#ifdef PR_COREPID
177 { PR_COREPID, "PR_COREPID" },
178#endif
179#ifdef PR_ATTACHADDRPERM
180 { PR_ATTACHADDRPERM, "PR_ATTACHADDRPERM" },
181#endif
182#ifdef PR_PTHREADEXIT
183 { PR_PTHREADEXIT, "PR_PTHREADEXIT" },
184#endif
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000185#ifdef PR_SET_PDEATHSIG
186 { PR_SET_PDEATHSIG, "PR_SET_PDEATHSIG" },
187#endif
188#ifdef PR_GET_PDEATHSIG
189 { PR_GET_PDEATHSIG, "PR_GET_PDEATHSIG" },
190#endif
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000191#ifdef PR_GET_UNALIGN
192 { PR_GET_UNALIGN, "PR_GET_UNALIGN" },
193#endif
194#ifdef PR_SET_UNALIGN
195 { PR_SET_UNALIGN, "PR_SET_UNALIGN" },
196#endif
197#ifdef PR_GET_KEEPCAPS
198 { PR_GET_KEEPCAPS, "PR_GET_KEEP_CAPS" },
199#endif
200#ifdef PR_SET_KEEPCAPS
201 { PR_SET_KEEPCAPS, "PR_SET_KEEP_CAPS" },
202#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000203 { 0, NULL },
204};
205
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000206
207const char *
208unalignctl_string (unsigned int ctl)
209{
210 static char buf[16];
211
212 switch (ctl) {
213#ifdef PR_UNALIGN_NOPRINT
214 case PR_UNALIGN_NOPRINT:
215 return "NOPRINT";
216#endif
217#ifdef PR_UNALIGN_SIGBUS
218 case PR_UNALIGN_SIGBUS:
219 return "SIGBUS";
220#endif
221 default:
222 break;
223 }
224 sprintf(buf, "%x", ctl);
225 return buf;
226}
227
228
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000229int
230sys_prctl(tcp)
231struct tcb *tcp;
232{
233 int i;
234
235 if (entering(tcp)) {
236 printxval(prctl_options, tcp->u_arg[0], "PR_???");
237 switch (tcp->u_arg[0]) {
238#ifdef PR_GETNSHARE
239 case PR_GETNSHARE:
240 break;
241#endif
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000242#ifdef PR_SET_DEATHSIG
243 case PR_GET_PDEATHSIG:
244 break;
245#endif
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000246#ifdef PR_SET_UNALIGN
247 case PR_SET_UNALIGN:
248 tprintf(", %s", unalignctl_string(tcp->u_arg[1]));
249 break;
250#endif
251#ifdef PR_GET_UNALIGN
252 case PR_GET_UNALIGN:
253 tprintf(", %#lx", tcp->u_arg[1]);
254 break;
255#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000256 default:
257 for (i = 1; i < tcp->u_nargs; i++)
258 tprintf(", %#lx", tcp->u_arg[i]);
259 break;
260 }
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000261 } else {
262 switch (tcp->u_arg[0]) {
263#ifdef PR_GET_PDEATHSIG
264 case PR_GET_PDEATHSIG:
265 for (i=1; i<tcp->u_nargs; i++)
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000266 tprintf(", %#lx", tcp->u_arg[i]);
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000267 break;
268#endif
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000269#ifdef PR_SET_UNALIGN
270 case PR_SET_UNALIGN:
271 break;
272#endif
273#ifdef PR_GET_UNALIGN
274 case PR_GET_UNALIGN:
275 {
276 int ctl;
277
278 umove(tcp, tcp->u_arg[1], &ctl);
279 tcp->auxstr = unalignctl_string(ctl);
280 return RVAL_STR;
281 }
282#endif
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000283 default:
284 break;
285 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000286 }
287 return 0;
288}
289
290#endif /* HAVE_PRCTL */
291
292int
293sys_gethostid(tcp)
294struct tcb *tcp;
295{
296 if (exiting(tcp))
297 return RVAL_HEX;
298 return 0;
299}
300
301int
302sys_sethostname(tcp)
303struct tcb *tcp;
304{
305 if (entering(tcp)) {
306 printpathn(tcp, tcp->u_arg[0], tcp->u_arg[1]);
307 tprintf(", %lu", tcp->u_arg[1]);
308 }
309 return 0;
310}
311
312int
313sys_gethostname(tcp)
314struct tcb *tcp;
315{
316 if (exiting(tcp)) {
317 if (syserror(tcp))
318 tprintf("%#lx", tcp->u_arg[0]);
319 else
320 printpath(tcp, tcp->u_arg[0]);
321 tprintf(", %lu", tcp->u_arg[1]);
322 }
323 return 0;
324}
325
326int
327sys_setdomainname(tcp)
328struct tcb *tcp;
329{
330 if (entering(tcp)) {
331 printpathn(tcp, tcp->u_arg[0], tcp->u_arg[1]);
332 tprintf(", %lu", tcp->u_arg[1]);
333 }
334 return 0;
335}
336
Wichert Akkerman5daa0281999-03-15 19:49:42 +0000337#if !defined(LINUX)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000338
339int
340sys_getdomainname(tcp)
341struct tcb *tcp;
342{
343 if (exiting(tcp)) {
344 if (syserror(tcp))
345 tprintf("%#lx", tcp->u_arg[0]);
346 else
347 printpath(tcp, tcp->u_arg[0]);
348 tprintf(", %lu", tcp->u_arg[1]);
349 }
350 return 0;
351}
352#endif /* !LINUX */
353
354int
355sys_exit(tcp)
356struct tcb *tcp;
357{
358 if (exiting(tcp)) {
359 fprintf(stderr, "_exit returned!\n");
360 return -1;
361 }
362 /* special case: we stop tracing this process, finish line now */
363 tprintf("%ld) ", tcp->u_arg[0]);
364 tabto(acolumn);
365 tprintf("= ?");
366 printtrailer(tcp);
367 return 0;
368}
369
370int
371internal_exit(tcp)
372struct tcb *tcp;
373{
Roland McGrathe85bbfe2003-01-09 06:53:31 +0000374 if (entering(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000375 tcp->flags |= TCB_EXITING;
Roland McGrathe85bbfe2003-01-09 06:53:31 +0000376#ifdef __NR_exit_group
Roland McGrath08267b82004-02-20 22:56:43 +0000377# ifdef IA64
378 if (ia32) {
379 if (tcp->scno == 252)
380 tcp->flags |= TCB_GROUP_EXITING;
381 } else
382# endif
Roland McGrathe85bbfe2003-01-09 06:53:31 +0000383 if (tcp->scno == __NR_exit_group)
384 tcp->flags |= TCB_GROUP_EXITING;
385#endif
386 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000387 return 0;
388}
389
Roland McGrathee9d4352002-12-18 04:16:10 +0000390/* TCP is creating a child we want to follow.
391 If there will be space in tcbtab for it, set TCB_FOLLOWFORK and return 0.
392 If not, clear TCB_FOLLOWFORK, print an error, and return 1. */
393static int
394fork_tcb(struct tcb *tcp)
395{
396 if (nprocs == tcbtabsize) {
397 /* Allocate some more TCBs and expand the table.
398 We don't want to relocate the TCBs because our
399 callers have pointers and it would be a pain.
400 So tcbtab is a table of pointers. Since we never
401 free the TCBs, we allocate a single chunk of many. */
402 struct tcb **newtab = (struct tcb **)
403 realloc(tcbtab, 2 * tcbtabsize * sizeof tcbtab[0]);
404 struct tcb *newtcbs = (struct tcb *) calloc(tcbtabsize,
405 sizeof *newtcbs);
406 int i;
407 if (newtab == NULL || newtcbs == NULL) {
408 if (newtab != NULL)
409 free(newtab);
410 tcp->flags &= ~TCB_FOLLOWFORK;
411 fprintf(stderr, "sys_fork: tcb table full\n");
412 return 1;
413 }
414 for (i = tcbtabsize; i < 2 * tcbtabsize; ++i)
415 newtab[i] = &newtcbs[i - tcbtabsize];
416 tcbtabsize *= 2;
417 tcbtab = newtab;
418 }
419
420 tcp->flags |= TCB_FOLLOWFORK;
421 return 0;
422}
423
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000424#ifdef USE_PROCFS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000425
426int
427sys_fork(tcp)
428struct tcb *tcp;
429{
430 if (exiting(tcp)) {
431 if (getrval2(tcp)) {
432 tcp->auxstr = "child process";
433 return RVAL_UDECIMAL | RVAL_STR;
434 }
435 }
436 return 0;
437}
438
John Hughes4e36a812001-04-18 15:11:51 +0000439#if UNIXWARE > 2
440
441int
442sys_rfork(tcp)
443struct tcb *tcp;
444{
445 if (entering(tcp)) {
446 tprintf ("%ld", tcp->u_arg[0]);
447 }
448 else {
449 if (getrval2(tcp)) {
450 tcp->auxstr = "child process";
451 return RVAL_UDECIMAL | RVAL_STR;
452 }
453 }
454 return 0;
455}
456
457#endif
458
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000459int
460internal_fork(tcp)
461struct tcb *tcp;
462{
463 struct tcb *tcpchild;
464
465 if (exiting(tcp)) {
Roland McGrathf3a0e1b2003-02-20 02:45:22 +0000466#ifdef SYS_rfork
467 if (tcp->scno == SYS_rfork && !(tcp->u_arg[0]&RFPROC))
468 return 0;
469#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000470 if (getrval2(tcp))
471 return 0;
472 if (!followfork)
473 return 0;
Roland McGrathee9d4352002-12-18 04:16:10 +0000474 if (fork_tcb(tcp))
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000475 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000476 if (syserror(tcp))
477 return 0;
478 if ((tcpchild = alloctcb(tcp->u_rval)) == NULL) {
479 fprintf(stderr, "sys_fork: tcb table full\n");
480 return 0;
481 }
Wichert Akkerman2e4ffe52000-09-03 23:57:48 +0000482 if (proc_open(tcpchild, 2) < 0)
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000483 droptcb(tcpchild);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000484 }
485 return 0;
486}
487
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000488#else /* !USE_PROCFS */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000489
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000490#ifdef LINUX
491
492/* defines copied from linux/sched.h since we can't include that
493 * ourselves (it conflicts with *lots* of libc includes)
494 */
495#define CSIGNAL 0x000000ff /* signal mask to be sent at exit */
496#define CLONE_VM 0x00000100 /* set if VM shared between processes */
497#define CLONE_FS 0x00000200 /* set if fs info shared between processes */
498#define CLONE_FILES 0x00000400 /* set if open files shared between processes */
499#define CLONE_SIGHAND 0x00000800 /* set if signal handlers shared */
Roland McGrath909875b2002-12-22 03:34:36 +0000500#define CLONE_IDLETASK 0x00001000 /* kernel-only flag */
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000501#define CLONE_PTRACE 0x00002000 /* set if we want to let tracing continue on the child too */
502#define CLONE_VFORK 0x00004000 /* set if the parent wants the child to wake it up on mm_release */
503#define CLONE_PARENT 0x00008000 /* set if we want to have the same parent as the cloner */
Roland McGrath909875b2002-12-22 03:34:36 +0000504#define CLONE_THREAD 0x00010000 /* Same thread group? */
505#define CLONE_NEWNS 0x00020000 /* New namespace group? */
506#define CLONE_SYSVSEM 0x00040000 /* share system V SEM_UNDO semantics */
507#define CLONE_SETTLS 0x00080000 /* create a new TLS for the child */
508#define CLONE_PARENT_SETTID 0x00100000 /* set the TID in the parent */
509#define CLONE_CHILD_CLEARTID 0x00200000 /* clear the TID in the child */
510#define CLONE_DETACHED 0x00400000 /* parent wants no child-exit signal */
511#define CLONE_UNTRACED 0x00800000 /* set if the tracing process can't force CLONE_PTRACE on this clone */
512#define CLONE_CHILD_SETTID 0x01000000 /* set the TID in the child */
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000513
514static struct xlat clone_flags[] = {
515 { CLONE_VM, "CLONE_VM" },
516 { CLONE_FS, "CLONE_FS" },
517 { CLONE_FILES, "CLONE_FILES" },
518 { CLONE_SIGHAND, "CLONE_SIGHAND" },
Roland McGrath909875b2002-12-22 03:34:36 +0000519 { CLONE_IDLETASK, "CLONE_IDLETASK"},
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000520 { CLONE_PTRACE, "CLONE_PTRACE" },
521 { CLONE_VFORK, "CLONE_VFORK" },
522 { CLONE_PARENT, "CLONE_PARENT" },
Roland McGrath909875b2002-12-22 03:34:36 +0000523 { CLONE_THREAD, "CLONE_THREAD" },
524 { CLONE_NEWNS, "CLONE_NEWNS" },
525 { CLONE_SYSVSEM, "CLONE_SYSVSEM" },
526 { CLONE_SETTLS, "CLONE_SETTLS" },
527 { CLONE_PARENT_SETTID,"CLONE_PARENT_SETTID" },
528 { CLONE_CHILD_CLEARTID,"CLONE_CHILD_CLEARTID" },
529 { CLONE_DETACHED, "CLONE_DETACHED" },
530 { CLONE_UNTRACED, "CLONE_UNTRACED" },
531 { CLONE_CHILD_SETTID,"CLONE_CHILD_SETTID" },
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000532 { 0, NULL },
533};
534
Roland McGrath909875b2002-12-22 03:34:36 +0000535# ifdef I386
536# include <asm/ldt.h>
537extern void print_ldt_entry();
538# endif
539
Roland McGrath9677b3a2003-03-12 09:54:36 +0000540# if defined IA64
541# define ARG_FLAGS 0
542# define ARG_STACK 1
543# define ARG_STACKSIZE (tcp->scno == SYS_clone2 ? 2 : -1)
Roland McGrathc03981d2003-03-14 10:32:36 +0000544# define ARG_PTID (tcp->scno == SYS_clone2 ? 3 : 2)
545# define ARG_CTID (tcp->scno == SYS_clone2 ? 4 : 3)
546# define ARG_TLS (tcp->scno == SYS_clone2 ? 5 : 4)
Roland McGrathfe5fdb22003-05-23 00:29:05 +0000547# elif defined S390 || defined S390X
Roland McGrath9677b3a2003-03-12 09:54:36 +0000548# define ARG_STACK 0
549# define ARG_FLAGS 1
550# define ARG_PTID 2
Roland McGrathfe5fdb22003-05-23 00:29:05 +0000551# define ARG_CTID 3
552# define ARG_TLS 4
Roland McGrath9c555e72003-07-09 09:47:59 +0000553# elif defined X86_64 || defined ALPHA
Roland McGrath361aac52003-03-18 07:43:42 +0000554# define ARG_FLAGS 0
555# define ARG_STACK 1
556# define ARG_PTID 2
557# define ARG_CTID 3
558# define ARG_TLS 4
Roland McGrath9677b3a2003-03-12 09:54:36 +0000559# else
560# define ARG_FLAGS 0
561# define ARG_STACK 1
562# define ARG_PTID 2
563# define ARG_TLS 3
564# define ARG_CTID 4
565# endif
566
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000567int
568sys_clone(tcp)
569struct tcb *tcp;
570{
571 if (exiting(tcp)) {
Roland McGrath9677b3a2003-03-12 09:54:36 +0000572 unsigned long flags = tcp->u_arg[ARG_FLAGS];
573 tprintf("child_stack=%#lx, ", tcp->u_arg[ARG_STACK]);
574# ifdef ARG_STACKSIZE
575 if (ARG_STACKSIZE != -1)
576 tprintf("stack_size=%#lx, ",
577 tcp->u_arg[ARG_STACKSIZE]);
Roland McGrathb4968be2003-01-20 09:04:33 +0000578# endif
Roland McGrath9677b3a2003-03-12 09:54:36 +0000579 tprintf("flags=");
Roland McGrath984154d2003-05-23 01:08:42 +0000580 if (printflags(clone_flags, flags &~ CSIGNAL) == 0)
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000581 tprintf("0");
Roland McGrath984154d2003-05-23 01:08:42 +0000582 if ((flags & CSIGNAL) != 0)
583 tprintf("|%s", signame(flags & CSIGNAL));
Roland McGrathb4968be2003-01-20 09:04:33 +0000584 if ((flags & (CLONE_PARENT_SETTID|CLONE_CHILD_SETTID
Roland McGrath9677b3a2003-03-12 09:54:36 +0000585 |CLONE_CHILD_CLEARTID|CLONE_SETTLS)) == 0)
Roland McGrath909875b2002-12-22 03:34:36 +0000586 return 0;
Roland McGrath6f67a982003-03-21 07:33:15 +0000587 if (flags & CLONE_PARENT_SETTID)
588 tprintf(", parent_tidptr=%#lx", tcp->u_arg[ARG_PTID]);
Roland McGrathb4968be2003-01-20 09:04:33 +0000589 if (flags & CLONE_SETTLS) {
Roland McGrath9677b3a2003-03-12 09:54:36 +0000590# ifdef I386
Roland McGrath909875b2002-12-22 03:34:36 +0000591 struct modify_ldt_ldt_s copy;
Roland McGrath9677b3a2003-03-12 09:54:36 +0000592 if (umove(tcp, tcp->u_arg[ARG_TLS], &copy) != -1) {
Roland McGrath909875b2002-12-22 03:34:36 +0000593 tprintf(", {entry_number:%d, ",
594 copy.entry_number);
595 if (!verbose(tcp))
596 tprintf("...}");
597 else
598 print_ldt_entry(&copy);
599 }
600 else
Roland McGrath9677b3a2003-03-12 09:54:36 +0000601# endif
Roland McGrath43f2c842003-03-12 09:58:14 +0000602 tprintf(", tls=%#lx", tcp->u_arg[ARG_TLS]);
Roland McGrath909875b2002-12-22 03:34:36 +0000603 }
Roland McGrath9677b3a2003-03-12 09:54:36 +0000604 if (flags & (CLONE_CHILD_SETTID|CLONE_CHILD_CLEARTID))
605 tprintf(", child_tidptr=%#lx", tcp->u_arg[ARG_CTID]);
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000606 }
607 return 0;
608}
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000609#endif
610
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000611int
612sys_fork(tcp)
613struct tcb *tcp;
614{
615 if (exiting(tcp))
616 return RVAL_UDECIMAL;
617 return 0;
618}
619
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000620int
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000621change_syscall(tcp, new)
622struct tcb *tcp;
623int new;
624{
625#if defined(LINUX)
626#if defined(I386)
627 /* Attempt to make vfork into fork, which we can follow. */
Roland McGrath5a223472002-12-15 23:58:26 +0000628 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(ORIG_EAX * 4), new) < 0)
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000629 return -1;
630 return 0;
Michal Ludvig0e035502002-09-23 15:41:01 +0000631#elif defined(X86_64)
632 /* Attempt to make vfork into fork, which we can follow. */
Roland McGrath5a223472002-12-15 23:58:26 +0000633 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(ORIG_RAX * 8), new) < 0)
Michal Ludvig0e035502002-09-23 15:41:01 +0000634 return -1;
635 return 0;
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000636#elif defined(POWERPC)
Roland McGratheb285352003-01-14 09:59:00 +0000637 if (ptrace(PTRACE_POKEUSER, tcp->pid,
638 (char*)(sizeof(unsigned long)*PT_R0), new) < 0)
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000639 return -1;
Roland McGrath43b286f2003-01-10 11:14:41 +0000640 return 0;
Michal Ludvig10a88d02002-10-07 14:31:00 +0000641#elif defined(S390) || defined(S390X)
642 /* s390 linux after 2.4.7 has a hook in entry.S to allow this */
643 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(PT_GPR2), new)<0)
644 return -1;
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000645 return 0;
646#elif defined(M68K)
Wichert Akkermanc7926982000-04-10 22:22:31 +0000647 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(4*PT_ORIG_D0), new)<0)
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000648 return -1;
649 return 0;
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000650#elif defined(SPARC)
Wichert Akkerman00a82ee2001-03-28 20:29:17 +0000651 struct regs regs;
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000652 if (ptrace(PTRACE_GETREGS, tcp->pid, (char*)&regs, 0)<0)
653 return -1;
Wichert Akkerman00a82ee2001-03-28 20:29:17 +0000654 regs.r_g1=new;
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000655 if (ptrace(PTRACE_SETREGS, tcp->pid, (char*)&regs, 0)<0)
656 return -1;
657 return 0;
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000658#elif defined(MIPS)
Wichert Akkermanc7926982000-04-10 22:22:31 +0000659 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(REG_V0), new)<0)
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000660 return -1;
661 return 0;
662#elif defined(ALPHA)
Wichert Akkermanc7926982000-04-10 22:22:31 +0000663 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(REG_A3), new)<0)
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000664 return -1;
665 return 0;
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000666#elif defined(IA64)
Roland McGrath08267b82004-02-20 22:56:43 +0000667 if (ia32) {
668 switch (new) {
669 case 2: break; /* x86 SYS_fork */
670 case SYS_clone: new = 120; break;
671 default:
672 fprintf(stderr, "%s: unexpected syscall %d\n",
673 __FUNCTION__, new);
674 return -1;
675 }
676 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(PT_R1), new)<0)
677 return -1;
678 } else if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(PT_R15), new)<0)
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000679 return -1;
680 return 0;
Wichert Akkermanc1652e22001-03-27 12:17:16 +0000681#elif defined(HPPA)
682 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(PT_GR20), new)<0)
683 return -1;
684 return 0;
Wichert Akkermanccef6372002-05-01 16:39:22 +0000685#elif defined(SH)
Roland McGrathac971c22003-03-31 01:03:33 +0000686 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(4*(REG_REG0+3)), new)<0)
Wichert Akkermanccef6372002-05-01 16:39:22 +0000687 return -1;
688 return 0;
Roland McGrathf5a47772003-06-26 22:40:42 +0000689#elif defined(SH64)
Roland McGrathe1e584b2003-06-02 19:18:58 +0000690 /* Top half of reg encodes the no. of args n as 0x1n.
691 Assume 0 args as kernel never actually checks... */
692 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(REG_SYSCALL),
693 0x100000 | new) < 0)
694 return -1;
695 return 0;
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000696#else
697#warning Do not know how to handle change_syscall for this architecture
698#endif /* architecture */
699#endif /* LINUX */
700 return -1;
701}
702
703int
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000704setarg(tcp, argnum)
705 struct tcb *tcp;
706 int argnum;
707{
708#if defined (IA64)
709 {
710 unsigned long *bsp, *ap;
711
712 if (upeek(tcp->pid, PT_AR_BSP, (long *) &bsp) , 0)
713 return -1;
714
715 ap = ia64_rse_skip_regs(bsp, argnum);
716 errno = 0;
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000717 ptrace(PTRACE_POKEDATA, tcp->pid, (char *) ap, tcp->u_arg[argnum]);
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000718 if (errno)
719 return -1;
720
721 }
Wichert Akkerman12f75d12000-02-14 16:23:40 +0000722#elif defined(I386)
723 {
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000724 ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(4*argnum), tcp->u_arg[argnum]);
Wichert Akkerman12f75d12000-02-14 16:23:40 +0000725 if (errno)
726 return -1;
727 }
Michal Ludvig0e035502002-09-23 15:41:01 +0000728#elif defined(X86_64)
729 {
730 ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(8*(long)argnum), tcp->u_arg[argnum]);
731 if (errno)
732 return -1;
733 }
Roland McGrath3bb9c3d2002-12-16 20:40:48 +0000734#elif defined(POWERPC)
735#ifndef PT_ORIG_R3
736#define PT_ORIG_R3 34
737#endif
738 {
739 ptrace(PTRACE_POKEUSER, tcp->pid,
Roland McGratheb285352003-01-14 09:59:00 +0000740 (char*)((argnum==0 ? PT_ORIG_R3 : argnum+PT_R3)*sizeof(unsigned long)),
Roland McGrath3bb9c3d2002-12-16 20:40:48 +0000741 tcp->u_arg[argnum]);
742 if (errno)
743 return -1;
744 }
Ralf Baechlee3816102000-08-01 00:06:06 +0000745#elif defined(MIPS)
746 {
747 errno = 0;
748 if (argnum < 4)
749 ptrace(PTRACE_POKEUSER, tcp->pid,
750 (char*)(REG_A0 + argnum), tcp->u_arg[argnum]);
751 else {
752 unsigned long *sp;
753
754 if (upeek(tcp->pid, REG_SP, (long *) &sp) , 0)
755 return -1;
756
757 ptrace(PTRACE_POKEDATA, tcp->pid,
758 (char*)(sp + argnum - 4), tcp->u_arg[argnum]);
759 }
760 if (errno)
761 return -1;
762 }
Michal Ludvig10a88d02002-10-07 14:31:00 +0000763#elif defined(S390) || defined(S390X)
764 {
765 if(argnum <= 5)
766 ptrace(PTRACE_POKEUSER, tcp->pid,
Roland McGrath5a223472002-12-15 23:58:26 +0000767 (char *) (argnum==0 ? PT_ORIGGPR2 :
768 PT_GPR2 + argnum*sizeof(long)),
Michal Ludvig10a88d02002-10-07 14:31:00 +0000769 tcp->u_arg[argnum]);
770 else
771 return -E2BIG;
772 if (errno)
773 return -1;
774 }
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000775#else
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000776# warning Sorry, setargs not implemented for this architecture.
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000777#endif
778 return 0;
779}
780
Roland McGrathe85bbfe2003-01-09 06:53:31 +0000781#if defined SYS_clone || defined SYS_clone2
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000782int
783internal_clone(tcp)
784struct tcb *tcp;
785{
Ulrich Drepper90512f01999-12-24 07:22:25 +0000786 struct tcb *tcpchild;
787 int pid;
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000788 if (entering(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000789 if (!followfork)
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000790 return 0;
Roland McGrathee9d4352002-12-18 04:16:10 +0000791 if (fork_tcb(tcp))
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000792 return 0;
Wichert Akkerman9b0c31d2000-09-03 21:56:29 +0000793 if (setbpt(tcp) < 0)
794 return 0;
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000795 } else {
Wichert Akkerman9b0c31d2000-09-03 21:56:29 +0000796 int bpt = tcp->flags & TCB_BPTSET;
797
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000798 if (!(tcp->flags & TCB_FOLLOWFORK))
799 return 0;
800
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000801 if (syserror(tcp)) {
802 if (bpt)
803 clearbpt(tcp);
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000804 return 0;
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000805 }
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000806
807 pid = tcp->u_rval;
Roland McGrathe85bbfe2003-01-09 06:53:31 +0000808
809#ifdef CLONE_PTRACE /* See new setbpt code. */
810 tcpchild = pid2tcb(pid);
811 if (tcpchild != NULL) {
812 /* The child already reported its startup trap
813 before the parent reported its syscall return. */
814 if ((tcpchild->flags
815 & (TCB_STARTUP|TCB_ATTACHED|TCB_SUSPENDED))
816 != (TCB_STARTUP|TCB_ATTACHED|TCB_SUSPENDED))
817 fprintf(stderr, "\
818[preattached child %d of %d in weird state!]\n",
819 pid, tcp->pid);
820 }
821 else
822#endif
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000823 if ((tcpchild = alloctcb(pid)) == NULL) {
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000824 if (bpt)
825 clearbpt(tcp);
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000826 fprintf(stderr, " [tcb table full]\n");
827 kill(pid, SIGKILL); /* XXX */
828 return 0;
829 }
830
Roland McGrathe85bbfe2003-01-09 06:53:31 +0000831#ifndef CLONE_PTRACE
Wichert Akkerman9b0c31d2000-09-03 21:56:29 +0000832 /* Attach to the new child */
833 if (ptrace(PTRACE_ATTACH, pid, (char *) 1, 0) < 0) {
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000834 if (bpt)
835 clearbpt(tcp);
Wichert Akkerman9b0c31d2000-09-03 21:56:29 +0000836 perror("PTRACE_ATTACH");
837 fprintf(stderr, "Too late?\n");
838 droptcb(tcpchild);
839 return 0;
840 }
Roland McGrathe85bbfe2003-01-09 06:53:31 +0000841#endif
Wichert Akkerman9b0c31d2000-09-03 21:56:29 +0000842
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000843 if (bpt)
844 clearbpt(tcp);
845
Ulrich Drepper90512f01999-12-24 07:22:25 +0000846 tcpchild->flags |= TCB_ATTACHED;
Roland McGrathe85bbfe2003-01-09 06:53:31 +0000847 /* Child has BPT too, must be removed on first occasion. */
Wichert Akkerman9b0c31d2000-09-03 21:56:29 +0000848 if (bpt) {
849 tcpchild->flags |= TCB_BPTSET;
850 tcpchild->baddr = tcp->baddr;
851 memcpy(tcpchild->inst, tcp->inst,
852 sizeof tcpchild->inst);
853 }
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000854 tcpchild->parent = tcp;
Roland McGrathe85bbfe2003-01-09 06:53:31 +0000855 tcp->nchildren++;
856 if (tcpchild->flags & TCB_SUSPENDED) {
857 /* The child was born suspended, due to our having
858 forced CLONE_PTRACE. */
859 if (bpt)
860 clearbpt(tcpchild);
861
862 tcpchild->flags &= ~(TCB_SUSPENDED|TCB_STARTUP);
863 if (ptrace(PTRACE_SYSCALL, pid, (char *) 1, 0) < 0) {
864 perror("resume: ptrace(PTRACE_SYSCALL, ...)");
865 return -1;
866 }
867
868 if (!qflag)
869 fprintf(stderr, "\
870Process %u resumed (parent %d ready)\n",
871 pid, tcp->pid);
872 }
873 else {
874 newoutf(tcpchild);
875 if (!qflag)
876 fprintf(stderr, "Process %d attached\n", pid);
877 }
878
879#ifdef TCB_CLONE_THREAD
Roland McGrath984154d2003-05-23 01:08:42 +0000880 {
881 /*
882 * Save the flags used in this call,
883 * in case we point TCP to our parent below.
884 */
885 int call_flags = tcp->u_arg[ARG_FLAGS];
886 if ((tcp->flags & TCB_CLONE_THREAD) &&
887 tcp->parent != NULL) {
888 /* The parent in this clone is itself a
889 thread belonging to another process.
890 There is no meaning to the parentage
891 relationship of the new child with the
892 thread, only with the process. We
893 associate the new thread with our
894 parent. Since this is done for every
895 new thread, there will never be a
896 TCB_CLONE_THREAD process that has
897 children. */
898 --tcp->nchildren;
899 tcp = tcp->parent;
900 tcpchild->parent = tcp;
901 ++tcp->nchildren;
902 }
903 if (call_flags & CLONE_THREAD) {
904 tcpchild->flags |= TCB_CLONE_THREAD;
905 ++tcp->nclone_threads;
906 }
907 if (call_flags & CLONE_DETACHED) {
908 tcpchild->flags |= TCB_CLONE_DETACHED;
909 ++tcp->nclone_detached;
910 }
Roland McGrathe85bbfe2003-01-09 06:53:31 +0000911 }
912#endif
913
914 }
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000915 return 0;
916}
917#endif
918
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000919int
920internal_fork(tcp)
921struct tcb *tcp;
922{
Roland McGrathe85bbfe2003-01-09 06:53:31 +0000923#ifdef LINUX
924 /* We do special magic with clone for any clone or fork. */
925 return internal_clone(tcp);
926#else
927
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000928 struct tcb *tcpchild;
929 int pid;
Nate Sammonsccd8f211999-03-29 22:57:54 +0000930 int dont_follow = 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000931
932#ifdef SYS_vfork
Nate Sammonsccd8f211999-03-29 22:57:54 +0000933 if (tcp->scno == SYS_vfork) {
Nate Sammonsccd8f211999-03-29 22:57:54 +0000934 /* Attempt to make vfork into fork, which we can follow. */
Roland McGrath5a223472002-12-15 23:58:26 +0000935 if (!followvfork ||
Pavel Machek9a9f10b2000-02-01 16:22:52 +0000936 change_syscall(tcp, SYS_fork) < 0)
Nate Sammonsccd8f211999-03-29 22:57:54 +0000937 dont_follow = 1;
Nate Sammonsccd8f211999-03-29 22:57:54 +0000938 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000939#endif
940 if (entering(tcp)) {
Nate Sammonsccd8f211999-03-29 22:57:54 +0000941 if (!followfork || dont_follow)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000942 return 0;
Roland McGrathee9d4352002-12-18 04:16:10 +0000943 if (fork_tcb(tcp))
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000944 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000945 if (setbpt(tcp) < 0)
946 return 0;
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000947 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000948 else {
949 int bpt = tcp->flags & TCB_BPTSET;
950
951 if (!(tcp->flags & TCB_FOLLOWFORK))
952 return 0;
953 if (bpt)
954 clearbpt(tcp);
955
956 if (syserror(tcp))
957 return 0;
958
959 pid = tcp->u_rval;
960 if ((tcpchild = alloctcb(pid)) == NULL) {
961 fprintf(stderr, " [tcb table full]\n");
962 kill(pid, SIGKILL); /* XXX */
963 return 0;
964 }
965#ifdef LINUX
Wichert Akkermanc1652e22001-03-27 12:17:16 +0000966#ifdef HPPA
967 /* The child must have run before it can be attached. */
968 /* This must be a bug in the parisc kernel, but I havn't
969 * identified it yet. Seems to be an issue associated
970 * with attaching to a process (which sends it a signal)
971 * before that process has ever been scheduled. When
972 * debugging, I started seeing crashes in
973 * arch/parisc/kernel/signal.c:do_signal(), apparently
974 * caused by r8 getting corrupt over the dequeue_signal()
975 * call. Didn't make much sense though...
976 */
977 {
978 struct timeval tv;
979 tv.tv_sec = 0;
980 tv.tv_usec = 10000;
981 select(0, NULL, NULL, NULL, &tv);
982 }
983#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000984 if (ptrace(PTRACE_ATTACH, pid, (char *) 1, 0) < 0) {
985 perror("PTRACE_ATTACH");
986 fprintf(stderr, "Too late?\n");
987 droptcb(tcpchild);
988 return 0;
989 }
990#endif /* LINUX */
991#ifdef SUNOS4
992#ifdef oldway
993 /* The child must have run before it can be attached. */
994 {
995 struct timeval tv;
996 tv.tv_sec = 0;
997 tv.tv_usec = 10000;
998 select(0, NULL, NULL, NULL, &tv);
999 }
1000 if (ptrace(PTRACE_ATTACH, pid, (char *)1, 0) < 0) {
1001 perror("PTRACE_ATTACH");
1002 fprintf(stderr, "Too late?\n");
1003 droptcb(tcpchild);
1004 return 0;
1005 }
1006#else /* !oldway */
1007 /* Try to catch the new process as soon as possible. */
1008 {
1009 int i;
1010 for (i = 0; i < 1024; i++)
1011 if (ptrace(PTRACE_ATTACH, pid, (char *) 1, 0) >= 0)
1012 break;
1013 if (i == 1024) {
1014 perror("PTRACE_ATTACH");
1015 fprintf(stderr, "Too late?\n");
1016 droptcb(tcpchild);
1017 return 0;
1018 }
1019 }
1020#endif /* !oldway */
1021#endif /* SUNOS4 */
1022 tcpchild->flags |= TCB_ATTACHED;
1023 /* Child has BPT too, must be removed on first occasion */
1024 if (bpt) {
1025 tcpchild->flags |= TCB_BPTSET;
1026 tcpchild->baddr = tcp->baddr;
1027 memcpy(tcpchild->inst, tcp->inst,
1028 sizeof tcpchild->inst);
1029 }
1030 newoutf(tcpchild);
1031 tcpchild->parent = tcp;
1032 tcp->nchildren++;
1033 if (!qflag)
1034 fprintf(stderr, "Process %d attached\n", pid);
1035 }
1036 return 0;
Roland McGrathe85bbfe2003-01-09 06:53:31 +00001037#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001038}
1039
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001040#endif /* !USE_PROCFS */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001041
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001042#if defined(SUNOS4) || defined(LINUX) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001043
1044int
1045sys_vfork(tcp)
1046struct tcb *tcp;
1047{
1048 if (exiting(tcp))
1049 return RVAL_UDECIMAL;
1050 return 0;
1051}
1052
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001053#endif /* SUNOS4 || LINUX || FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001054
1055#ifndef LINUX
1056
1057static char idstr[16];
1058
1059int
1060sys_getpid(tcp)
1061struct tcb *tcp;
1062{
1063 if (exiting(tcp)) {
1064 sprintf(idstr, "ppid %lu", getrval2(tcp));
1065 tcp->auxstr = idstr;
1066 return RVAL_STR;
1067 }
1068 return 0;
1069}
1070
1071int
1072sys_getuid(tcp)
1073struct tcb *tcp;
1074{
1075 if (exiting(tcp)) {
1076 sprintf(idstr, "euid %lu", getrval2(tcp));
1077 tcp->auxstr = idstr;
1078 return RVAL_STR;
1079 }
1080 return 0;
1081}
1082
1083int
1084sys_getgid(tcp)
1085struct tcb *tcp;
1086{
1087 if (exiting(tcp)) {
1088 sprintf(idstr, "egid %lu", getrval2(tcp));
1089 tcp->auxstr = idstr;
1090 return RVAL_STR;
1091 }
1092 return 0;
1093}
1094
1095#endif /* !LINUX */
1096
1097#ifdef LINUX
1098
1099int
1100sys_setuid(tcp)
1101struct tcb *tcp;
1102{
1103 if (entering(tcp)) {
1104 tprintf("%u", (uid_t) tcp->u_arg[0]);
1105 }
1106 return 0;
1107}
1108
1109int
1110sys_setgid(tcp)
1111struct tcb *tcp;
1112{
1113 if (entering(tcp)) {
1114 tprintf("%u", (gid_t) tcp->u_arg[0]);
1115 }
1116 return 0;
1117}
1118
1119int
1120sys_getresuid(tcp)
1121 struct tcb *tcp;
1122{
1123 if (exiting(tcp)) {
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001124 __kernel_uid_t uid;
1125 if (syserror(tcp))
1126 tprintf("%#lx, %#lx, %#lx", tcp->u_arg[0],
1127 tcp->u_arg[1], tcp->u_arg[2]);
1128 else {
1129 if (umove(tcp, tcp->u_arg[0], &uid) < 0)
1130 tprintf("%#lx, ", tcp->u_arg[0]);
1131 else
Roland McGrath83bd47a2003-11-13 22:32:26 +00001132 tprintf("[%lu], ", (unsigned long) uid);
Roland McGrath9bd6b422003-02-24 07:13:51 +00001133 if (umove(tcp, tcp->u_arg[1], &uid) < 0)
1134 tprintf("%#lx, ", tcp->u_arg[1]);
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001135 else
Roland McGrath83bd47a2003-11-13 22:32:26 +00001136 tprintf("[%lu], ", (unsigned long) uid);
Roland McGrath9bd6b422003-02-24 07:13:51 +00001137 if (umove(tcp, tcp->u_arg[2], &uid) < 0)
1138 tprintf("%#lx", tcp->u_arg[2]);
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001139 else
Roland McGrath83bd47a2003-11-13 22:32:26 +00001140 tprintf("[%lu]", (unsigned long) uid);
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001141 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001142 }
1143 return 0;
1144}
1145
1146int
1147sys_getresgid(tcp)
1148struct tcb *tcp;
1149{
1150 if (exiting(tcp)) {
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001151 __kernel_gid_t gid;
1152 if (syserror(tcp))
1153 tprintf("%#lx, %#lx, %#lx", tcp->u_arg[0],
1154 tcp->u_arg[1], tcp->u_arg[2]);
1155 else {
1156 if (umove(tcp, tcp->u_arg[0], &gid) < 0)
1157 tprintf("%#lx, ", tcp->u_arg[0]);
1158 else
Roland McGrath83bd47a2003-11-13 22:32:26 +00001159 tprintf("[%lu], ", (unsigned long) gid);
Roland McGrathd2450922003-02-24 10:18:07 +00001160 if (umove(tcp, tcp->u_arg[1], &gid) < 0)
1161 tprintf("%#lx, ", tcp->u_arg[1]);
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001162 else
Roland McGrath83bd47a2003-11-13 22:32:26 +00001163 tprintf("[%lu], ", (unsigned long) gid);
Roland McGrathd2450922003-02-24 10:18:07 +00001164 if (umove(tcp, tcp->u_arg[2], &gid) < 0)
1165 tprintf("%#lx", tcp->u_arg[2]);
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001166 else
Roland McGrath83bd47a2003-11-13 22:32:26 +00001167 tprintf("[%lu]", (unsigned long) gid);
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001168 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001169 }
1170 return 0;
1171}
1172
1173#endif /* LINUX */
1174
1175int
1176sys_setreuid(tcp)
1177struct tcb *tcp;
1178{
1179 if (entering(tcp)) {
Roland McGrath83bd47a2003-11-13 22:32:26 +00001180 printuid("", tcp->u_arg[0]);
1181 printuid(", ", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001182 }
1183 return 0;
1184}
1185
1186int
1187sys_setregid(tcp)
1188struct tcb *tcp;
1189{
1190 if (entering(tcp)) {
Roland McGrath83bd47a2003-11-13 22:32:26 +00001191 printuid("", tcp->u_arg[0]);
1192 printuid(", ", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001193 }
1194 return 0;
1195}
1196
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001197#if defined(LINUX) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001198int
1199sys_setresuid(tcp)
1200 struct tcb *tcp;
1201{
1202 if (entering(tcp)) {
Roland McGrath83bd47a2003-11-13 22:32:26 +00001203 printuid("", tcp->u_arg[0]);
1204 printuid(", ", tcp->u_arg[1]);
1205 printuid(", ", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001206 }
1207 return 0;
1208}
1209int
1210sys_setresgid(tcp)
1211 struct tcb *tcp;
1212{
1213 if (entering(tcp)) {
Roland McGrath83bd47a2003-11-13 22:32:26 +00001214 printuid("", tcp->u_arg[0]);
1215 printuid(", ", tcp->u_arg[1]);
1216 printuid(", ", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001217 }
1218 return 0;
1219}
1220
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001221#endif /* LINUX || FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001222
1223int
1224sys_setgroups(tcp)
1225struct tcb *tcp;
1226{
1227 int i, len;
1228 GETGROUPS_T *gidset;
1229
1230 if (entering(tcp)) {
1231 len = tcp->u_arg[0];
1232 tprintf("%u, ", len);
1233 if (len <= 0) {
1234 tprintf("[]");
1235 return 0;
1236 }
1237 gidset = (GETGROUPS_T *) malloc(len * sizeof(GETGROUPS_T));
1238 if (gidset == NULL) {
1239 fprintf(stderr, "sys_setgroups: out of memory\n");
1240 return -1;
1241 }
1242 if (!verbose(tcp))
1243 tprintf("%#lx", tcp->u_arg[1]);
1244 else if (umoven(tcp, tcp->u_arg[1],
1245 len * sizeof(GETGROUPS_T), (char *) gidset) < 0)
1246 tprintf("[?]");
1247 else {
1248 tprintf("[");
1249 for (i = 0; i < len; i++)
1250 tprintf("%s%lu", i ? ", " : "",
1251 (unsigned long) gidset[i]);
1252 tprintf("]");
1253 }
1254 free((char *) gidset);
1255 }
1256 return 0;
1257}
1258
1259int
1260sys_getgroups(tcp)
1261struct tcb *tcp;
1262{
1263 int i, len;
1264 GETGROUPS_T *gidset;
1265
1266 if (entering(tcp)) {
1267 len = tcp->u_arg[0];
1268 tprintf("%u, ", len);
1269 } else {
1270 len = tcp->u_rval;
1271 if (len <= 0) {
1272 tprintf("[]");
1273 return 0;
1274 }
1275 gidset = (GETGROUPS_T *) malloc(len * sizeof(GETGROUPS_T));
1276 if (gidset == NULL) {
1277 fprintf(stderr, "sys_getgroups: out of memory\n");
1278 return -1;
1279 }
1280 if (!tcp->u_arg[1])
1281 tprintf("NULL");
1282 else if (!verbose(tcp) || tcp->u_arg[0] == 0)
1283 tprintf("%#lx", tcp->u_arg[1]);
1284 else if (umoven(tcp, tcp->u_arg[1],
1285 len * sizeof(GETGROUPS_T), (char *) gidset) < 0)
1286 tprintf("[?]");
1287 else {
1288 tprintf("[");
1289 for (i = 0; i < len; i++)
1290 tprintf("%s%lu", i ? ", " : "",
1291 (unsigned long) gidset[i]);
1292 tprintf("]");
1293 }
1294 free((char *)gidset);
1295 }
1296 return 0;
1297}
1298
Roland McGrath83bd47a2003-11-13 22:32:26 +00001299#ifdef LINUX
1300int
1301sys_setgroups32(tcp)
1302struct tcb *tcp;
1303{
1304 int i, len;
1305 GETGROUPS32_T *gidset;
1306
1307 if (entering(tcp)) {
1308 len = tcp->u_arg[0];
1309 tprintf("%u, ", len);
1310 if (len <= 0) {
1311 tprintf("[]");
1312 return 0;
1313 }
1314 gidset = (GETGROUPS32_T *) malloc(len * sizeof(GETGROUPS32_T));
1315 if (gidset == NULL) {
1316 fprintf(stderr, "sys_setgroups32: out of memory\n");
1317 return -1;
1318 }
1319 if (!verbose(tcp))
1320 tprintf("%#lx", tcp->u_arg[1]);
1321 else if (umoven(tcp, tcp->u_arg[1],
1322 len * sizeof(GETGROUPS32_T), (char *) gidset) < 0)
1323 tprintf("[?]");
1324 else {
1325 tprintf("[");
1326 for (i = 0; i < len; i++)
1327 tprintf("%s%lu", i ? ", " : "",
1328 (unsigned long) gidset[i]);
1329 tprintf("]");
1330 }
1331 free((char *) gidset);
1332 }
1333 return 0;
1334}
1335
1336int
1337sys_getgroups32(tcp)
1338struct tcb *tcp;
1339{
1340 int i, len;
1341 GETGROUPS32_T *gidset;
1342
1343 if (entering(tcp)) {
1344 len = tcp->u_arg[0];
1345 tprintf("%u, ", len);
1346 } else {
1347 len = tcp->u_rval;
1348 if (len <= 0) {
1349 tprintf("[]");
1350 return 0;
1351 }
1352 gidset = (GETGROUPS32_T *) malloc(len * sizeof(GETGROUPS32_T));
1353 if (gidset == NULL) {
1354 fprintf(stderr, "sys_getgroups32: out of memory\n");
1355 return -1;
1356 }
1357 if (!tcp->u_arg[1])
1358 tprintf("NULL");
1359 else if (!verbose(tcp) || tcp->u_arg[0] == 0)
1360 tprintf("%#lx", tcp->u_arg[1]);
1361 else if (umoven(tcp, tcp->u_arg[1],
1362 len * sizeof(GETGROUPS32_T), (char *) gidset) < 0)
1363 tprintf("[?]");
1364 else {
1365 tprintf("[");
1366 for (i = 0; i < len; i++)
1367 tprintf("%s%lu", i ? ", " : "",
1368 (unsigned long) gidset[i]);
1369 tprintf("]");
1370 }
1371 free((char *)gidset);
1372 }
1373 return 0;
1374}
1375#endif /* LINUX */
1376
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001377int
1378sys_setpgrp(tcp)
1379struct tcb *tcp;
1380{
1381 if (entering(tcp)) {
1382#ifndef SVR4
1383 tprintf("%lu, %lu", tcp->u_arg[0], tcp->u_arg[1]);
1384#endif /* !SVR4 */
1385 }
1386 return 0;
1387}
1388
1389int
1390sys_getpgrp(tcp)
1391struct tcb *tcp;
1392{
1393 if (entering(tcp)) {
1394#ifndef SVR4
1395 tprintf("%lu", tcp->u_arg[0]);
1396#endif /* !SVR4 */
1397 }
1398 return 0;
1399}
1400
1401int
1402sys_getsid(tcp)
1403struct tcb *tcp;
1404{
1405 if (entering(tcp)) {
1406 tprintf("%lu", tcp->u_arg[0]);
1407 }
1408 return 0;
1409}
1410
1411int
1412sys_setsid(tcp)
1413struct tcb *tcp;
1414{
1415 return 0;
1416}
1417
1418int
1419sys_getpgid(tcp)
1420struct tcb *tcp;
1421{
1422 if (entering(tcp)) {
1423 tprintf("%lu", tcp->u_arg[0]);
1424 }
1425 return 0;
1426}
1427
1428int
1429sys_setpgid(tcp)
1430struct tcb *tcp;
1431{
1432 if (entering(tcp)) {
1433 tprintf("%lu, %lu", tcp->u_arg[0], tcp->u_arg[1]);
1434 }
1435 return 0;
1436}
1437
John Hughesc61eb3d2002-05-17 11:37:50 +00001438#if UNIXWARE >= 2
1439
1440#include <sys/privilege.h>
1441
1442
1443static struct xlat procpriv_cmds [] = {
1444 { SETPRV, "SETPRV" },
1445 { CLRPRV, "CLRPRV" },
1446 { PUTPRV, "PUTPRV" },
1447 { GETPRV, "GETPRV" },
1448 { CNTPRV, "CNTPRV" },
1449 { 0, NULL },
1450};
1451
1452
1453static struct xlat procpriv_priv [] = {
1454 { P_OWNER, "P_OWNER" },
1455 { P_AUDIT, "P_AUDIT" },
1456 { P_COMPAT, "P_COMPAT" },
1457 { P_DACREAD, "P_DACREAD" },
1458 { P_DACWRITE, "P_DACWRITE" },
1459 { P_DEV, "P_DEV" },
1460 { P_FILESYS, "P_FILESYS" },
1461 { P_MACREAD, "P_MACREAD" },
1462 { P_MACWRITE, "P_MACWRITE" },
1463 { P_MOUNT, "P_MOUNT" },
1464 { P_MULTIDIR, "P_MULTIDIR" },
1465 { P_SETPLEVEL, "P_SETPLEVEL" },
1466 { P_SETSPRIV, "P_SETSPRIV" },
1467 { P_SETUID, "P_SETUID" },
1468 { P_SYSOPS, "P_SYSOPS" },
1469 { P_SETUPRIV, "P_SETUPRIV" },
1470 { P_DRIVER, "P_DRIVER" },
1471 { P_RTIME, "P_RTIME" },
1472 { P_MACUPGRADE, "P_MACUPGRADE" },
1473 { P_FSYSRANGE, "P_FSYSRANGE" },
1474 { P_SETFLEVEL, "P_SETFLEVEL" },
1475 { P_AUDITWR, "P_AUDITWR" },
1476 { P_TSHAR, "P_TSHAR" },
1477 { P_PLOCK, "P_PLOCK" },
1478 { P_CORE, "P_CORE" },
1479 { P_LOADMOD, "P_LOADMOD" },
1480 { P_BIND, "P_BIND" },
1481 { P_ALLPRIVS, "P_ALLPRIVS" },
1482 { 0, NULL },
1483};
1484
1485
1486static struct xlat procpriv_type [] = {
1487 { PS_FIX, "PS_FIX" },
1488 { PS_INH, "PS_INH" },
1489 { PS_MAX, "PS_MAX" },
1490 { PS_WKG, "PS_WKG" },
1491 { 0, NULL },
1492};
1493
1494
1495static void
1496printpriv(tcp, addr, len, opt)
1497struct tcb *tcp;
1498long addr;
1499int len;
1500struct xlat *opt;
1501{
1502 priv_t buf [128];
1503 int max = verbose (tcp) ? sizeof buf / sizeof buf [0] : 10;
1504 int dots = len > max;
1505 int i;
Roland McGrath5a223472002-12-15 23:58:26 +00001506
John Hughesc61eb3d2002-05-17 11:37:50 +00001507 if (len > max) len = max;
Roland McGrath5a223472002-12-15 23:58:26 +00001508
John Hughesc61eb3d2002-05-17 11:37:50 +00001509 if (len <= 0 ||
1510 umoven (tcp, addr, len * sizeof buf[0], (char *) buf) < 0)
1511 {
1512 tprintf ("%#lx", addr);
1513 return;
1514 }
1515
1516 tprintf ("[");
1517
1518 for (i = 0; i < len; ++i) {
1519 char *t, *p;
1520
1521 if (i) tprintf (", ");
1522
1523 if ((t = xlookup (procpriv_type, buf [i] & PS_TYPE)) &&
1524 (p = xlookup (procpriv_priv, buf [i] & ~PS_TYPE)))
1525 {
1526 tprintf ("%s|%s", t, p);
1527 }
1528 else {
1529 tprintf ("%#lx", buf [i]);
1530 }
1531 }
1532
1533 if (dots) tprintf (" ...");
1534
1535 tprintf ("]");
1536}
1537
1538
1539int
1540sys_procpriv(tcp)
1541struct tcb *tcp;
1542{
1543 if (entering(tcp)) {
1544 printxval(procpriv_cmds, tcp->u_arg[0], "???PRV");
1545 switch (tcp->u_arg[0]) {
1546 case CNTPRV:
1547 tprintf(", %#lx, %ld", tcp->u_arg[1], tcp->u_arg[2]);
1548 break;
1549
1550 case GETPRV:
1551 break;
1552
1553 default:
1554 tprintf (", ");
1555 printpriv (tcp, tcp->u_arg[1], tcp->u_arg[2]);
1556 tprintf (", %ld", tcp->u_arg[2]);
1557 }
1558 }
1559 else if (tcp->u_arg[0] == GETPRV) {
1560 if (syserror (tcp)) {
1561 tprintf(", %#lx, %ld", tcp->u_arg[1], tcp->u_arg[2]);
1562 }
1563 else {
1564 tprintf (", ");
1565 printpriv (tcp, tcp->u_arg[1], tcp->u_rval);
1566 tprintf (", %ld", tcp->u_arg[2]);
1567 }
1568 }
Roland McGrath5a223472002-12-15 23:58:26 +00001569
John Hughesc61eb3d2002-05-17 11:37:50 +00001570 return 0;
1571}
1572
1573#endif
1574
1575
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001576void
1577fake_execve(tcp, program, argv, envp)
1578struct tcb *tcp;
1579char *program;
1580char *argv[];
1581char *envp[];
1582{
1583 int i;
1584
1585#ifdef ARM
1586 if (!(qual_flags[SYS_execve - __NR_SYSCALL_BASE] & QUAL_TRACE))
1587 return;
1588#else
1589 if (!(qual_flags[SYS_execve] & QUAL_TRACE))
1590 return;
1591#endif /* !ARM */
1592 printleader(tcp);
1593 tprintf("execve(");
1594 string_quote(program);
1595 tprintf(", [");
1596 for (i = 0; argv[i] != NULL; i++) {
1597 if (i != 0)
1598 tprintf(", ");
1599 string_quote(argv[i]);
1600 }
1601 for (i = 0; envp[i] != NULL; i++)
1602 ;
1603 tprintf("], [/* %d var%s */]) ", i, (i != 1) ? "s" : "");
1604 tabto(acolumn);
1605 tprintf("= 0");
1606 printtrailer(tcp);
1607}
1608
1609static void
1610printargv(tcp, addr)
1611struct tcb *tcp;
1612long addr;
1613{
1614 char *cp;
1615 char *sep;
1616 int max = max_strlen / 2;
1617
1618 for (sep = ""; --max >= 0; sep = ", ") {
1619 if (!abbrev(tcp))
1620 max++;
1621 if (umove(tcp, addr, &cp) < 0) {
1622 tprintf("%#lx", addr);
1623 return;
1624 }
1625 if (cp == 0)
1626 break;
1627 tprintf(sep);
1628 printstr(tcp, (long) cp, -1);
1629 addr += sizeof(char *);
1630 }
1631 if (cp)
1632 tprintf(", ...");
1633}
1634
1635static void
1636printargc(fmt, tcp, addr)
1637char *fmt;
1638struct tcb *tcp;
1639long addr;
1640{
1641 int count;
1642 char *cp;
1643
1644 for (count = 0; umove(tcp, addr, &cp) >= 0 && cp != NULL; count++) {
1645 addr += sizeof(char *);
1646 }
1647 tprintf(fmt, count, count == 1 ? "" : "s");
1648}
1649
1650int
1651sys_execv(tcp)
1652struct tcb *tcp;
1653{
1654 if (entering(tcp)) {
1655 printpath(tcp, tcp->u_arg[0]);
1656 if (!verbose(tcp))
1657 tprintf(", %#lx", tcp->u_arg[1]);
1658#if 0
1659 else if (abbrev(tcp))
1660 printargc(", [/* %d arg%s */]", tcp, tcp->u_arg[1]);
1661#endif
1662 else {
1663 tprintf(", [");
1664 printargv(tcp, tcp->u_arg[1]);
1665 tprintf("]");
1666 }
1667 }
1668 return 0;
1669}
1670
1671int
1672sys_execve(tcp)
1673struct tcb *tcp;
1674{
1675 if (entering(tcp)) {
1676 printpath(tcp, tcp->u_arg[0]);
1677 if (!verbose(tcp))
1678 tprintf(", %#lx", tcp->u_arg[1]);
1679#if 0
1680 else if (abbrev(tcp))
1681 printargc(", [/* %d arg%s */]", tcp, tcp->u_arg[1]);
1682#endif
1683 else {
1684 tprintf(", [");
1685 printargv(tcp, tcp->u_arg[1]);
1686 tprintf("]");
1687 }
1688 if (!verbose(tcp))
1689 tprintf(", %#lx", tcp->u_arg[2]);
1690 else if (abbrev(tcp))
1691 printargc(", [/* %d var%s */]", tcp, tcp->u_arg[2]);
1692 else {
1693 tprintf(", [");
1694 printargv(tcp, tcp->u_arg[2]);
1695 tprintf("]");
1696 }
1697 }
Roland McGrathb4968be2003-01-20 09:04:33 +00001698#if defined LINUX && defined TCB_WAITEXECVE
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001699 tcp->flags |= TCB_WAITEXECVE;
Roland McGrathb4968be2003-01-20 09:04:33 +00001700#endif /* LINUX && TCB_WAITEXECVE */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001701 return 0;
1702}
1703
Roland McGrath5ef24ab2004-02-20 02:22:35 +00001704#if UNIXWARE > 2
John Hughes4e36a812001-04-18 15:11:51 +00001705
1706int sys_rexecve(tcp)
1707struct tcb *tcp;
1708{
1709 if (entering (tcp)) {
1710 sys_execve (tcp);
1711 tprintf (", %ld", tcp->u_arg[3]);
1712 }
1713 return 0;
1714}
1715
Roland McGrath5ef24ab2004-02-20 02:22:35 +00001716#endif
John Hughes4e36a812001-04-18 15:11:51 +00001717
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001718int
1719internal_exec(tcp)
1720struct tcb *tcp;
1721{
1722#ifdef SUNOS4
1723 if (exiting(tcp) && !syserror(tcp) && followfork)
1724 fixvfork(tcp);
1725#endif /* SUNOS4 */
1726 return 0;
1727}
1728
1729#ifdef LINUX
Roland McGrath7ec1d352002-12-17 04:50:44 +00001730#ifndef __WNOTHREAD
1731#define __WNOTHREAD 0x20000000
1732#endif
1733#ifndef __WALL
1734#define __WALL 0x40000000
1735#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001736#ifndef __WCLONE
Roland McGrath7ec1d352002-12-17 04:50:44 +00001737#define __WCLONE 0x80000000
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001738#endif
1739#endif /* LINUX */
1740
1741static struct xlat wait4_options[] = {
1742 { WNOHANG, "WNOHANG" },
1743#ifndef WSTOPPED
1744 { WUNTRACED, "WUNTRACED" },
1745#endif
1746#ifdef WEXITED
1747 { WEXITED, "WEXITED" },
1748#endif
1749#ifdef WTRAPPED
1750 { WTRAPPED, "WTRAPPED" },
1751#endif
1752#ifdef WSTOPPED
1753 { WSTOPPED, "WSTOPPED" },
1754#endif
1755#ifdef WCONTINUED
1756 { WCONTINUED, "WCONTINUED" },
1757#endif
1758#ifdef WNOWAIT
1759 { WNOWAIT, "WNOWAIT" },
1760#endif
1761#ifdef __WCLONE
1762 { __WCLONE, "__WCLONE" },
1763#endif
Roland McGrath7ec1d352002-12-17 04:50:44 +00001764#ifdef __WALL
1765 { __WALL, "__WALL" },
1766#endif
1767#ifdef __WNOTHREAD
1768 { __WNOTHREAD, "__WNOTHREAD" },
1769#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001770 { 0, NULL },
1771};
1772
1773static int
1774printstatus(status)
1775int status;
1776{
1777 int exited = 0;
1778
1779 /*
1780 * Here is a tricky presentation problem. This solution
1781 * is still not entirely satisfactory but since there
1782 * are no wait status constructors it will have to do.
1783 */
1784 if (WIFSTOPPED(status))
1785 tprintf("[WIFSTOPPED(s) && WSTOPSIG(s) == %s]",
Nate Sammonsce780fc1999-03-29 23:23:13 +00001786 signame(WSTOPSIG(status)));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001787 else if WIFSIGNALED(status)
1788 tprintf("[WIFSIGNALED(s) && WTERMSIG(s) == %s%s]",
Nate Sammonsce780fc1999-03-29 23:23:13 +00001789 signame(WTERMSIG(status)),
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001790 WCOREDUMP(status) ? " && WCOREDUMP(s)" : "");
1791 else if WIFEXITED(status) {
1792 tprintf("[WIFEXITED(s) && WEXITSTATUS(s) == %d]",
1793 WEXITSTATUS(status));
1794 exited = 1;
1795 }
1796 else
1797 tprintf("[%#x]", status);
1798 return exited;
1799}
1800
1801static int
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001802printwaitn(tcp, n, bitness)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001803struct tcb *tcp;
1804int n;
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001805int bitness;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001806{
1807 int status;
1808 int exited = 0;
1809
1810 if (entering(tcp)) {
1811 tprintf("%ld, ", tcp->u_arg[0]);
1812 } else {
1813 /* status */
1814 if (!tcp->u_arg[1])
1815 tprintf("NULL");
1816 else if (syserror(tcp) || tcp->u_rval == 0)
1817 tprintf("%#lx", tcp->u_arg[1]);
1818 else if (umove(tcp, tcp->u_arg[1], &status) < 0)
1819 tprintf("[?]");
1820 else
1821 exited = printstatus(status);
1822 /* options */
1823 tprintf(", ");
1824 if (!printflags(wait4_options, tcp->u_arg[2]))
1825 tprintf("0");
1826 if (n == 4) {
1827 tprintf(", ");
1828 /* usage */
1829 if (!tcp->u_arg[3])
1830 tprintf("NULL");
1831#ifdef LINUX
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001832 else if (tcp->u_rval > 0) {
1833#ifdef LINUX_64BIT
1834 if (bitness)
1835 printrusage32(tcp, tcp->u_arg[3]);
1836 else
1837#endif
1838 printrusage(tcp, tcp->u_arg[3]);
1839 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001840#endif /* LINUX */
1841#ifdef SUNOS4
1842 else if (tcp->u_rval > 0 && exited)
1843 printrusage(tcp, tcp->u_arg[3]);
1844#endif /* SUNOS4 */
1845 else
1846 tprintf("%#lx", tcp->u_arg[3]);
1847 }
1848 }
1849 return 0;
1850}
1851
1852int
1853internal_wait(tcp)
1854struct tcb *tcp;
1855{
Roland McGrathe85bbfe2003-01-09 06:53:31 +00001856 int got_kids;
1857
1858#ifdef TCB_CLONE_THREAD
1859 if (tcp->flags & TCB_CLONE_THREAD)
1860 /* The children we wait for are our parent's children. */
1861 got_kids = (tcp->parent->nchildren
1862 > tcp->parent->nclone_detached);
1863 else
1864 got_kids = (tcp->nchildren > tcp->nclone_detached);
1865#else
1866 got_kids = tcp->nchildren > 0;
1867#endif
1868
1869 if (entering(tcp) && got_kids) {
Roland McGrathb69f81b2002-12-21 23:25:18 +00001870 /* There are children that this parent should block for.
1871 But ptrace made us the parent of the traced children
1872 and the real parent will get ECHILD from the wait call.
1873
1874 XXX If we attached with strace -f -p PID, then there
1875 may be untraced dead children the parent could be reaping
1876 now, but we make him block. */
1877
1878 /* ??? WTA: fix bug with hanging children */
1879
1880 if (!(tcp->u_arg[2] & WNOHANG)) {
Roland McGrath09623452003-05-23 02:27:13 +00001881 /*
1882 * There are traced children. We'll make the parent
1883 * block to avoid a false ECHILD error due to our
1884 * ptrace having stolen the children. However,
1885 * we shouldn't block if there are zombies to reap.
1886 * XXX doesn't handle pgrp matches (u_arg[0]==0,<-1)
1887 */
Roland McGrathfccfb942003-10-01 21:59:44 +00001888 struct tcb *child = NULL;
Roland McGrath09623452003-05-23 02:27:13 +00001889 if (tcp->nzombies > 0 &&
1890 (tcp->u_arg[0] == -1 ||
Roland McGrathfccfb942003-10-01 21:59:44 +00001891 (child = pid2tcb(tcp->u_arg[0])) == NULL))
Roland McGrath09623452003-05-23 02:27:13 +00001892 return 0;
Roland McGrathfccfb942003-10-01 21:59:44 +00001893 if (tcp->u_arg[0] > 0) {
1894 /*
1895 * If the parent waits for a specified child
1896 * PID, then it must get ECHILD right away
1897 * if that PID is not one of its children.
1898 * Make sure that the requested PID matches
1899 * one of the parent's children that we are
1900 * tracing, and don't suspend it otherwise.
1901 */
1902 if (child == NULL)
1903 child = pid2tcb(tcp->u_arg[0]);
1904 if (child == NULL || child->parent != (
1905#ifdef TCB_CLONE_THREAD
1906 (tcp->flags & TCB_CLONE_THREAD)
1907 ? tcp->parent :
1908#endif
1909 tcp))
1910 return 0;
1911 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001912 tcp->flags |= TCB_SUSPENDED;
1913 tcp->waitpid = tcp->u_arg[0];
Roland McGrathe85bbfe2003-01-09 06:53:31 +00001914#ifdef TCB_CLONE_THREAD
1915 if (tcp->flags & TCB_CLONE_THREAD)
1916 tcp->parent->nclone_waiting++;
1917#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001918 }
1919 }
Roland McGrathe85bbfe2003-01-09 06:53:31 +00001920 if (exiting(tcp) && tcp->u_error == ECHILD && got_kids) {
Roland McGrathb69f81b2002-12-21 23:25:18 +00001921 if (tcp->u_arg[2] & WNOHANG) {
1922 /* We must force a fake result of 0 instead of
1923 the ECHILD error. */
1924 extern int force_result();
1925 return force_result(tcp, 0, 0);
1926 }
Roland McGrathb69f81b2002-12-21 23:25:18 +00001927 }
Roland McGrath09623452003-05-23 02:27:13 +00001928 else if (exiting(tcp) && tcp->u_error == 0 && tcp->u_rval > 0 &&
1929 tcp->nzombies > 0 && pid2tcb(tcp->u_rval) == NULL) {
1930 /*
1931 * We just reaped a child we don't know about,
1932 * presumably a zombie we already droptcb'd.
1933 */
1934 tcp->nzombies--;
1935 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001936 return 0;
1937}
1938
1939#ifdef SVR4
1940
1941int
1942sys_wait(tcp)
1943struct tcb *tcp;
1944{
1945 if (exiting(tcp)) {
1946 /* The library wrapper stuffs this into the user variable. */
1947 if (!syserror(tcp))
1948 printstatus(getrval2(tcp));
1949 }
1950 return 0;
1951}
1952
1953#endif /* SVR4 */
1954
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001955#ifdef FREEBSD
1956int
1957sys_wait(tcp)
1958struct tcb *tcp;
1959{
1960 int status;
Roland McGrath5a223472002-12-15 23:58:26 +00001961
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001962 if (exiting(tcp)) {
1963 if (!syserror(tcp)) {
1964 if (umove(tcp, tcp->u_arg[0], &status) < 0)
1965 tprintf("%#lx", tcp->u_arg[0]);
1966 else
1967 printstatus(status);
1968 }
1969 }
1970 return 0;
1971}
1972#endif
1973
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001974int
1975sys_waitpid(tcp)
1976struct tcb *tcp;
1977{
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001978 return printwaitn(tcp, 3, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001979}
1980
1981int
1982sys_wait4(tcp)
1983struct tcb *tcp;
1984{
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001985 return printwaitn(tcp, 4, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001986}
1987
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001988#ifdef ALPHA
1989int
1990sys_osf_wait4(tcp)
1991struct tcb *tcp;
1992{
1993 return printwaitn(tcp, 4, 1);
1994}
1995#endif
1996
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001997#ifdef SVR4
1998
1999static struct xlat waitid_types[] = {
2000 { P_PID, "P_PID" },
2001 { P_PPID, "P_PPID" },
2002 { P_PGID, "P_PGID" },
2003 { P_SID, "P_SID" },
2004 { P_CID, "P_CID" },
2005 { P_UID, "P_UID" },
2006 { P_GID, "P_GID" },
2007 { P_ALL, "P_ALL" },
2008#ifdef P_LWPID
2009 { P_LWPID, "P_LWPID" },
2010#endif
2011 { 0, NULL },
2012};
2013
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002014int
2015sys_waitid(tcp)
2016struct tcb *tcp;
2017{
2018 siginfo_t si;
2019 int exited;
2020
2021 if (entering(tcp)) {
2022 printxval(waitid_types, tcp->u_arg[0], "P_???");
2023 tprintf(", %ld, ", tcp->u_arg[1]);
2024 if (tcp->nchildren > 0) {
2025 /* There are traced children */
2026 tcp->flags |= TCB_SUSPENDED;
2027 tcp->waitpid = tcp->u_arg[0];
2028 }
2029 }
2030 else {
2031 /* siginfo */
2032 exited = 0;
2033 if (!tcp->u_arg[2])
2034 tprintf("NULL");
2035 else if (syserror(tcp))
2036 tprintf("%#lx", tcp->u_arg[2]);
2037 else if (umove(tcp, tcp->u_arg[2], &si) < 0)
2038 tprintf("{???}");
2039 else
John Hughes58265892001-10-18 15:13:53 +00002040 printsiginfo(&si, verbose (tcp));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002041 /* options */
2042 tprintf(", ");
2043 if (!printflags(wait4_options, tcp->u_arg[3]))
2044 tprintf("0");
2045 }
2046 return 0;
2047}
2048
2049#endif /* SVR4 */
2050
2051int
2052sys_alarm(tcp)
2053struct tcb *tcp;
2054{
2055 if (entering(tcp))
2056 tprintf("%lu", tcp->u_arg[0]);
2057 return 0;
2058}
2059
2060int
2061sys_uname(tcp)
2062struct tcb *tcp;
2063{
2064 struct utsname uname;
2065
2066 if (exiting(tcp)) {
2067 if (syserror(tcp) || !verbose(tcp))
2068 tprintf("%#lx", tcp->u_arg[0]);
2069 else if (umove(tcp, tcp->u_arg[0], &uname) < 0)
2070 tprintf("{...}");
2071 else if (!abbrev(tcp)) {
2072
2073 tprintf("{sysname=\"%s\", nodename=\"%s\", ",
2074 uname.sysname, uname.nodename);
2075 tprintf("release=\"%s\", version=\"%s\", ",
2076 uname.release, uname.version);
2077 tprintf("machine=\"%s\"", uname.machine);
2078#ifdef LINUX
2079#ifndef __GLIBC__
2080 tprintf(", domainname=\"%s\"", uname.domainname);
2081#endif /* __GLIBC__ */
2082#endif /* LINUX */
2083 tprintf("}");
2084 }
2085 else
2086 tprintf("{sys=\"%s\", node=\"%s\", ...}",
2087 uname.sysname, uname.nodename);
2088 }
2089 return 0;
2090}
2091
2092#ifndef SVR4
2093
2094static struct xlat ptrace_cmds[] = {
Roland McGrath5a223472002-12-15 23:58:26 +00002095#ifndef FREEBSD
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002096 { PTRACE_TRACEME, "PTRACE_TRACEME" },
2097 { PTRACE_PEEKTEXT, "PTRACE_PEEKTEXT", },
2098 { PTRACE_PEEKDATA, "PTRACE_PEEKDATA", },
2099 { PTRACE_PEEKUSER, "PTRACE_PEEKUSER", },
2100 { PTRACE_POKETEXT, "PTRACE_POKETEXT", },
2101 { PTRACE_POKEDATA, "PTRACE_POKEDATA", },
2102 { PTRACE_POKEUSER, "PTRACE_POKEUSER", },
2103 { PTRACE_CONT, "PTRACE_CONT" },
2104 { PTRACE_KILL, "PTRACE_KILL" },
2105 { PTRACE_SINGLESTEP, "PTRACE_SINGLESTEP" },
2106 { PTRACE_ATTACH, "PTRACE_ATTACH" },
2107 { PTRACE_DETACH, "PTRACE_DETACH" },
Roland McGrathbf621d42003-01-14 09:46:21 +00002108#ifdef PTRACE_GETREGS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002109 { PTRACE_GETREGS, "PTRACE_GETREGS" },
Roland McGrathbf621d42003-01-14 09:46:21 +00002110#endif
2111#ifdef PTRACE_SETREGS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002112 { PTRACE_SETREGS, "PTRACE_SETREGS" },
Roland McGrathbf621d42003-01-14 09:46:21 +00002113#endif
2114#ifdef PTRACE_GETFPREGS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002115 { PTRACE_GETFPREGS, "PTRACE_GETFPREGS", },
Roland McGrathbf621d42003-01-14 09:46:21 +00002116#endif
2117#ifdef PTRACE_SETFPREGS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002118 { PTRACE_SETFPREGS, "PTRACE_SETFPREGS", },
Roland McGrathbf621d42003-01-14 09:46:21 +00002119#endif
2120#ifdef PTRACE_GETFPXREGS
2121 { PTRACE_GETFPXREGS, "PTRACE_GETFPXREGS", },
2122#endif
2123#ifdef PTRACE_SETFPXREGS
2124 { PTRACE_SETFPXREGS, "PTRACE_SETFPXREGS", },
2125#endif
2126#ifdef SUNOS4
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002127 { PTRACE_READDATA, "PTRACE_READDATA" },
2128 { PTRACE_WRITEDATA, "PTRACE_WRITEDATA" },
2129 { PTRACE_READTEXT, "PTRACE_READTEXT" },
2130 { PTRACE_WRITETEXT, "PTRACE_WRITETEXT" },
2131 { PTRACE_GETFPAREGS, "PTRACE_GETFPAREGS" },
2132 { PTRACE_SETFPAREGS, "PTRACE_SETFPAREGS" },
2133#ifdef SPARC
2134 { PTRACE_GETWINDOW, "PTRACE_GETWINDOW" },
2135 { PTRACE_SETWINDOW, "PTRACE_SETWINDOW" },
2136#else /* !SPARC */
2137 { PTRACE_22, "PTRACE_PTRACE_22" },
2138 { PTRACE_23, "PTRACE_PTRACE_23" },
2139#endif /* !SPARC */
2140#endif /* SUNOS4 */
2141 { PTRACE_SYSCALL, "PTRACE_SYSCALL" },
2142#ifdef SUNOS4
2143 { PTRACE_DUMPCORE, "PTRACE_DUMPCORE" },
2144#ifdef I386
2145 { PTRACE_SETWRBKPT, "PTRACE_SETWRBKPT" },
2146 { PTRACE_SETACBKPT, "PTRACE_SETACBKPT" },
2147 { PTRACE_CLRDR7, "PTRACE_CLRDR7" },
2148#else /* !I386 */
2149 { PTRACE_26, "PTRACE_26" },
2150 { PTRACE_27, "PTRACE_27" },
2151 { PTRACE_28, "PTRACE_28" },
2152#endif /* !I386 */
2153 { PTRACE_GETUCODE, "PTRACE_GETUCODE" },
2154#endif /* SUNOS4 */
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002155#else /* FREEBSD */
2156 { PT_TRACE_ME, "PT_TRACE_ME" },
2157 { PT_READ_I, "PT_READ_I" },
2158 { PT_READ_D, "PT_READ_D" },
2159 { PT_WRITE_I, "PT_WRITE_I" },
2160 { PT_WRITE_D, "PT_WRITE_D" },
John Hughesa2278142001-09-28 16:21:30 +00002161#ifdef PT_READ_U
2162 { PT_READ_U, "PT_READ_U" },
2163#endif
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002164 { PT_CONTINUE, "PT_CONTINUE" },
2165 { PT_KILL, "PT_KILL" },
2166 { PT_STEP, "PT_STEP" },
2167 { PT_ATTACH, "PT_ATTACH" },
2168 { PT_DETACH, "PT_DETACH" },
2169 { PT_GETREGS, "PT_GETREGS" },
2170 { PT_SETREGS, "PT_SETREGS" },
2171 { PT_GETFPREGS, "PT_GETFPREGS" },
2172 { PT_SETFPREGS, "PT_SETFPREGS" },
2173 { PT_GETDBREGS, "PT_GETDBREGS" },
2174 { PT_SETDBREGS, "PT_SETDBREGS" },
2175#endif /* FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002176 { 0, NULL },
2177};
2178
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002179#ifndef FREEBSD
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002180#ifndef SUNOS4_KERNEL_ARCH_KLUDGE
2181static
2182#endif /* !SUNOS4_KERNEL_ARCH_KLUDGE */
2183struct xlat struct_user_offsets[] = {
2184#ifdef LINUX
Michal Ludvig10a88d02002-10-07 14:31:00 +00002185#if defined(S390) || defined(S390X)
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00002186 { PT_PSWMASK, "psw_mask" },
2187 { PT_PSWADDR, "psw_addr" },
2188 { PT_GPR0, "gpr0" },
2189 { PT_GPR1, "gpr1" },
2190 { PT_GPR2, "gpr2" },
2191 { PT_GPR3, "gpr3" },
2192 { PT_GPR4, "gpr4" },
2193 { PT_GPR5, "gpr5" },
2194 { PT_GPR6, "gpr6" },
2195 { PT_GPR7, "gpr7" },
2196 { PT_GPR8, "gpr8" },
2197 { PT_GPR9, "gpr9" },
2198 { PT_GPR10, "gpr10" },
2199 { PT_GPR11, "gpr11" },
2200 { PT_GPR12, "gpr12" },
2201 { PT_GPR13, "gpr13" },
2202 { PT_GPR14, "gpr14" },
2203 { PT_GPR15, "gpr15" },
2204 { PT_ACR0, "acr0" },
2205 { PT_ACR1, "acr1" },
2206 { PT_ACR2, "acr2" },
2207 { PT_ACR3, "acr3" },
2208 { PT_ACR4, "acr4" },
2209 { PT_ACR5, "acr5" },
2210 { PT_ACR6, "acr6" },
2211 { PT_ACR7, "acr7" },
2212 { PT_ACR8, "acr8" },
2213 { PT_ACR9, "acr9" },
2214 { PT_ACR10, "acr10" },
2215 { PT_ACR11, "acr11" },
2216 { PT_ACR12, "acr12" },
2217 { PT_ACR13, "acr13" },
2218 { PT_ACR14, "acr14" },
2219 { PT_ACR15, "acr15" },
2220 { PT_ORIGGPR2, "orig_gpr2" },
2221 { PT_FPC, "fpc" },
Michal Ludvig10a88d02002-10-07 14:31:00 +00002222#if defined(S390)
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00002223 { PT_FPR0_HI, "fpr0.hi" },
2224 { PT_FPR0_LO, "fpr0.lo" },
2225 { PT_FPR1_HI, "fpr1.hi" },
2226 { PT_FPR1_LO, "fpr1.lo" },
2227 { PT_FPR2_HI, "fpr2.hi" },
2228 { PT_FPR2_LO, "fpr2.lo" },
2229 { PT_FPR3_HI, "fpr3.hi" },
2230 { PT_FPR3_LO, "fpr3.lo" },
2231 { PT_FPR4_HI, "fpr4.hi" },
2232 { PT_FPR4_LO, "fpr4.lo" },
2233 { PT_FPR5_HI, "fpr5.hi" },
2234 { PT_FPR5_LO, "fpr5.lo" },
2235 { PT_FPR6_HI, "fpr6.hi" },
2236 { PT_FPR6_LO, "fpr6.lo" },
2237 { PT_FPR7_HI, "fpr7.hi" },
2238 { PT_FPR7_LO, "fpr7.lo" },
2239 { PT_FPR8_HI, "fpr8.hi" },
2240 { PT_FPR8_LO, "fpr8.lo" },
2241 { PT_FPR9_HI, "fpr9.hi" },
2242 { PT_FPR9_LO, "fpr9.lo" },
2243 { PT_FPR10_HI, "fpr10.hi" },
2244 { PT_FPR10_LO, "fpr10.lo" },
2245 { PT_FPR11_HI, "fpr11.hi" },
2246 { PT_FPR11_LO, "fpr11.lo" },
2247 { PT_FPR12_HI, "fpr12.hi" },
2248 { PT_FPR12_LO, "fpr12.lo" },
2249 { PT_FPR13_HI, "fpr13.hi" },
2250 { PT_FPR13_LO, "fpr13.lo" },
2251 { PT_FPR14_HI, "fpr14.hi" },
2252 { PT_FPR14_LO, "fpr14.lo" },
2253 { PT_FPR15_HI, "fpr15.hi" },
2254 { PT_FPR15_LO, "fpr15.lo" },
Michal Ludvig10a88d02002-10-07 14:31:00 +00002255#endif
2256#if defined(S390X)
2257 { PT_FPR0, "fpr0" },
2258 { PT_FPR1, "fpr1" },
2259 { PT_FPR2, "fpr2" },
2260 { PT_FPR3, "fpr3" },
2261 { PT_FPR4, "fpr4" },
2262 { PT_FPR5, "fpr5" },
2263 { PT_FPR6, "fpr6" },
2264 { PT_FPR7, "fpr7" },
2265 { PT_FPR8, "fpr8" },
2266 { PT_FPR9, "fpr9" },
2267 { PT_FPR10, "fpr10" },
2268 { PT_FPR11, "fpr11" },
2269 { PT_FPR12, "fpr12" },
2270 { PT_FPR13, "fpr13" },
2271 { PT_FPR14, "fpr14" },
2272 { PT_FPR15, "fpr15" },
2273#endif
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00002274 { PT_CR_9, "cr9" },
2275 { PT_CR_10, "cr10" },
2276 { PT_CR_11, "cr11" },
Michal Ludvig10a88d02002-10-07 14:31:00 +00002277 { PT_IEEE_IP, "ieee_exception_ip" },
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00002278#endif
2279#if defined(SPARC)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002280 /* XXX No support for these offsets yet. */
Wichert Akkermanc1652e22001-03-27 12:17:16 +00002281#elif defined(HPPA)
2282 /* XXX No support for these offsets yet. */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002283#elif defined(POWERPC)
Roland McGrath5a223472002-12-15 23:58:26 +00002284#ifndef PT_ORIG_R3
2285#define PT_ORIG_R3 34
2286#endif
Roland McGratheb285352003-01-14 09:59:00 +00002287#define REGSIZE (sizeof(unsigned long))
2288 { REGSIZE*PT_R0, "r0" },
2289 { REGSIZE*PT_R1, "r1" },
2290 { REGSIZE*PT_R2, "r2" },
2291 { REGSIZE*PT_R3, "r3" },
2292 { REGSIZE*PT_R4, "r4" },
2293 { REGSIZE*PT_R5, "r5" },
2294 { REGSIZE*PT_R6, "r6" },
2295 { REGSIZE*PT_R7, "r7" },
2296 { REGSIZE*PT_R8, "r8" },
2297 { REGSIZE*PT_R9, "r9" },
2298 { REGSIZE*PT_R10, "r10" },
2299 { REGSIZE*PT_R11, "r11" },
2300 { REGSIZE*PT_R12, "r12" },
2301 { REGSIZE*PT_R13, "r13" },
2302 { REGSIZE*PT_R14, "r14" },
2303 { REGSIZE*PT_R15, "r15" },
2304 { REGSIZE*PT_R16, "r16" },
2305 { REGSIZE*PT_R17, "r17" },
2306 { REGSIZE*PT_R18, "r18" },
2307 { REGSIZE*PT_R19, "r19" },
2308 { REGSIZE*PT_R20, "r20" },
2309 { REGSIZE*PT_R21, "r21" },
2310 { REGSIZE*PT_R22, "r22" },
2311 { REGSIZE*PT_R23, "r23" },
2312 { REGSIZE*PT_R24, "r24" },
2313 { REGSIZE*PT_R25, "r25" },
2314 { REGSIZE*PT_R26, "r26" },
2315 { REGSIZE*PT_R27, "r27" },
2316 { REGSIZE*PT_R28, "r28" },
2317 { REGSIZE*PT_R29, "r29" },
2318 { REGSIZE*PT_R30, "r30" },
2319 { REGSIZE*PT_R31, "r31" },
2320 { REGSIZE*PT_NIP, "NIP" },
2321 { REGSIZE*PT_MSR, "MSR" },
2322 { REGSIZE*PT_ORIG_R3, "ORIG_R3" },
2323 { REGSIZE*PT_CTR, "CTR" },
2324 { REGSIZE*PT_LNK, "LNK" },
2325 { REGSIZE*PT_XER, "XER" },
2326 { REGSIZE*PT_CCR, "CCR" },
2327 { REGSIZE*PT_FPR0, "FPR0" },
2328#undef REGSIZE
Roland McGrath5a223472002-12-15 23:58:26 +00002329#else
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002330#ifdef ALPHA
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00002331 { 0, "r0" },
2332 { 1, "r1" },
2333 { 2, "r2" },
2334 { 3, "r3" },
2335 { 4, "r4" },
2336 { 5, "r5" },
2337 { 6, "r6" },
2338 { 7, "r7" },
2339 { 8, "r8" },
2340 { 9, "r9" },
2341 { 10, "r10" },
2342 { 11, "r11" },
2343 { 12, "r12" },
2344 { 13, "r13" },
2345 { 14, "r14" },
2346 { 15, "r15" },
2347 { 16, "r16" },
2348 { 17, "r17" },
2349 { 18, "r18" },
2350 { 19, "r19" },
2351 { 20, "r20" },
2352 { 21, "r21" },
2353 { 22, "r22" },
2354 { 23, "r23" },
2355 { 24, "r24" },
2356 { 25, "r25" },
2357 { 26, "r26" },
2358 { 27, "r27" },
2359 { 28, "r28" },
2360 { 29, "gp" },
2361 { 30, "fp" },
2362 { 31, "zero" },
2363 { 32, "fp0" },
2364 { 33, "fp" },
2365 { 34, "fp2" },
2366 { 35, "fp3" },
2367 { 36, "fp4" },
2368 { 37, "fp5" },
2369 { 38, "fp6" },
2370 { 39, "fp7" },
2371 { 40, "fp8" },
2372 { 41, "fp9" },
2373 { 42, "fp10" },
2374 { 43, "fp11" },
2375 { 44, "fp12" },
2376 { 45, "fp13" },
2377 { 46, "fp14" },
2378 { 47, "fp15" },
2379 { 48, "fp16" },
2380 { 49, "fp17" },
2381 { 50, "fp18" },
2382 { 51, "fp19" },
2383 { 52, "fp20" },
2384 { 53, "fp21" },
2385 { 54, "fp22" },
2386 { 55, "fp23" },
2387 { 56, "fp24" },
2388 { 57, "fp25" },
2389 { 58, "fp26" },
2390 { 59, "fp27" },
2391 { 60, "fp28" },
2392 { 61, "fp29" },
2393 { 62, "fp30" },
2394 { 63, "fp31" },
2395 { 64, "pc" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002396#else /* !ALPHA */
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00002397#ifdef IA64
2398 { PT_F32, "f32" }, { PT_F33, "f33" }, { PT_F34, "f34" },
2399 { PT_F35, "f35" }, { PT_F36, "f36" }, { PT_F37, "f37" },
2400 { PT_F38, "f38" }, { PT_F39, "f39" }, { PT_F40, "f40" },
2401 { PT_F41, "f41" }, { PT_F42, "f42" }, { PT_F43, "f43" },
2402 { PT_F44, "f44" }, { PT_F45, "f45" }, { PT_F46, "f46" },
2403 { PT_F47, "f47" }, { PT_F48, "f48" }, { PT_F49, "f49" },
2404 { PT_F50, "f50" }, { PT_F51, "f51" }, { PT_F52, "f52" },
2405 { PT_F53, "f53" }, { PT_F54, "f54" }, { PT_F55, "f55" },
2406 { PT_F56, "f56" }, { PT_F57, "f57" }, { PT_F58, "f58" },
2407 { PT_F59, "f59" }, { PT_F60, "f60" }, { PT_F61, "f61" },
2408 { PT_F62, "f62" }, { PT_F63, "f63" }, { PT_F64, "f64" },
2409 { PT_F65, "f65" }, { PT_F66, "f66" }, { PT_F67, "f67" },
2410 { PT_F68, "f68" }, { PT_F69, "f69" }, { PT_F70, "f70" },
2411 { PT_F71, "f71" }, { PT_F72, "f72" }, { PT_F73, "f73" },
2412 { PT_F74, "f74" }, { PT_F75, "f75" }, { PT_F76, "f76" },
2413 { PT_F77, "f77" }, { PT_F78, "f78" }, { PT_F79, "f79" },
2414 { PT_F80, "f80" }, { PT_F81, "f81" }, { PT_F82, "f82" },
2415 { PT_F83, "f83" }, { PT_F84, "f84" }, { PT_F85, "f85" },
2416 { PT_F86, "f86" }, { PT_F87, "f87" }, { PT_F88, "f88" },
2417 { PT_F89, "f89" }, { PT_F90, "f90" }, { PT_F91, "f91" },
2418 { PT_F92, "f92" }, { PT_F93, "f93" }, { PT_F94, "f94" },
2419 { PT_F95, "f95" }, { PT_F96, "f96" }, { PT_F97, "f97" },
2420 { PT_F98, "f98" }, { PT_F99, "f99" }, { PT_F100, "f100" },
2421 { PT_F101, "f101" }, { PT_F102, "f102" }, { PT_F103, "f103" },
2422 { PT_F104, "f104" }, { PT_F105, "f105" }, { PT_F106, "f106" },
2423 { PT_F107, "f107" }, { PT_F108, "f108" }, { PT_F109, "f109" },
2424 { PT_F110, "f110" }, { PT_F111, "f111" }, { PT_F112, "f112" },
2425 { PT_F113, "f113" }, { PT_F114, "f114" }, { PT_F115, "f115" },
2426 { PT_F116, "f116" }, { PT_F117, "f117" }, { PT_F118, "f118" },
2427 { PT_F119, "f119" }, { PT_F120, "f120" }, { PT_F121, "f121" },
2428 { PT_F122, "f122" }, { PT_F123, "f123" }, { PT_F124, "f124" },
2429 { PT_F125, "f125" }, { PT_F126, "f126" }, { PT_F127, "f127" },
2430 /* switch stack: */
2431 { PT_F2, "f2" }, { PT_F3, "f3" }, { PT_F4, "f4" },
2432 { PT_F5, "f5" }, { PT_F10, "f10" }, { PT_F11, "f11" },
2433 { PT_F12, "f12" }, { PT_F13, "f13" }, { PT_F14, "f14" },
2434 { PT_F15, "f15" }, { PT_F16, "f16" }, { PT_F17, "f17" },
2435 { PT_F18, "f18" }, { PT_F19, "f19" }, { PT_F20, "f20" },
2436 { PT_F21, "f21" }, { PT_F22, "f22" }, { PT_F23, "f23" },
2437 { PT_F24, "f24" }, { PT_F25, "f25" }, { PT_F26, "f26" },
2438 { PT_F27, "f27" }, { PT_F28, "f28" }, { PT_F29, "f29" },
2439 { PT_F30, "f30" }, { PT_F31, "f31" }, { PT_R4, "r4" },
2440 { PT_R5, "r5" }, { PT_R6, "r6" }, { PT_R7, "r7" },
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00002441 { PT_B1, "b1" }, { PT_B2, "b2" }, { PT_B3, "b3" },
2442 { PT_B4, "b4" }, { PT_B5, "b5" },
Roland McGrathca4e10c2004-01-13 10:13:20 +00002443 { PT_AR_EC, "ar.ec" }, { PT_AR_LC, "ar.lc" },
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00002444 /* pt_regs */
Roland McGrathca4e10c2004-01-13 10:13:20 +00002445 { PT_CR_IPSR, "psr" }, { PT_CR_IIP, "ip" },
2446 { PT_CFM, "cfm" }, { PT_AR_UNAT, "ar.unat" },
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00002447 { PT_AR_PFS, "ar.pfs" }, { PT_AR_RSC, "ar.rsc" },
2448 { PT_AR_RNAT, "ar.rnat" }, { PT_AR_BSPSTORE, "ar.bspstore" },
2449 { PT_PR, "pr" }, { PT_B6, "b6" }, { PT_AR_BSP, "ar.bsp" },
2450 { PT_R1, "r1" }, { PT_R2, "r2" }, { PT_R3, "r3" },
2451 { PT_R12, "r12" }, { PT_R13, "r13" }, { PT_R14, "r14" },
2452 { PT_R15, "r15" }, { PT_R8, "r8" }, { PT_R9, "r9" },
2453 { PT_R10, "r10" }, { PT_R11, "r11" }, { PT_R16, "r16" },
2454 { PT_R17, "r17" }, { PT_R18, "r18" }, { PT_R19, "r19" },
2455 { PT_R20, "r20" }, { PT_R21, "r21" }, { PT_R22, "r22" },
2456 { PT_R23, "r23" }, { PT_R24, "r24" }, { PT_R25, "r25" },
2457 { PT_R26, "r26" }, { PT_R27, "r27" }, { PT_R28, "r28" },
2458 { PT_R29, "r29" }, { PT_R30, "r30" }, { PT_R31, "r31" },
2459 { PT_AR_CCV, "ar.ccv" }, { PT_AR_FPSR, "ar.fpsr" },
2460 { PT_B0, "b0" }, { PT_B7, "b7" }, { PT_F6, "f6" },
2461 { PT_F7, "f7" }, { PT_F8, "f8" }, { PT_F9, "f9" },
Roland McGrathca4e10c2004-01-13 10:13:20 +00002462 { PT_AR_CSD, "ar.csd" }, { PT_AR_SSD, "ar.ssd" },
2463 { PT_DBR, "dbr" }, { PT_IBR, "ibr" }, { PT_PMD, "pmd" },
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00002464#else /* !IA64 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002465#ifdef I386
2466 { 4*EBX, "4*EBX" },
2467 { 4*ECX, "4*ECX" },
2468 { 4*EDX, "4*EDX" },
2469 { 4*ESI, "4*ESI" },
2470 { 4*EDI, "4*EDI" },
2471 { 4*EBP, "4*EBP" },
2472 { 4*EAX, "4*EAX" },
2473 { 4*DS, "4*DS" },
2474 { 4*ES, "4*ES" },
2475 { 4*FS, "4*FS" },
2476 { 4*GS, "4*GS" },
2477 { 4*ORIG_EAX, "4*ORIG_EAX" },
2478 { 4*EIP, "4*EIP" },
2479 { 4*CS, "4*CS" },
2480 { 4*EFL, "4*EFL" },
2481 { 4*UESP, "4*UESP" },
2482 { 4*SS, "4*SS" },
2483#else /* !I386 */
Michal Ludvig0e035502002-09-23 15:41:01 +00002484#ifdef X86_64
2485 { 8*RDI, "8*RDI" },
2486 { 8*RSI, "8*RSI" },
2487 { 8*RDX, "8*RDX" },
2488 { 8*R10, "8*R10" },
2489 { 8*R8, "8*R8" },
2490 { 8*R9, "8*R9" },
2491 { 8*RBX, "8*RBX" },
2492 { 8*RCX, "8*RCX" },
2493 { 8*RBP, "8*RBP" },
2494 { 8*RAX, "8*RAX" },
2495#if 0
2496 { 8*DS, "8*DS" },
2497 { 8*ES, "8*ES" },
2498 { 8*FS, "8*FS" },
2499 { 8*GS, "8*GS" },
2500#endif
2501 { 8*ORIG_RAX, "8*ORIG_EAX" },
2502 { 8*RIP, "8*RIP" },
2503 { 8*CS, "8*CS" },
2504 { 8*EFLAGS, "8*EFL" },
2505 { 8*RSP, "8*RSP" },
2506 { 8*SS, "8*SS" },
2507 { 8*R11, "8*R11" },
2508 { 8*R12, "8*R12" },
2509 { 8*R13, "8*R13" },
2510 { 8*R14, "8*R14" },
2511 { 8*R15, "8*R15" },
2512#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002513#ifdef M68K
2514 { 4*PT_D1, "4*PT_D1" },
2515 { 4*PT_D2, "4*PT_D2" },
2516 { 4*PT_D3, "4*PT_D3" },
2517 { 4*PT_D4, "4*PT_D4" },
2518 { 4*PT_D5, "4*PT_D5" },
2519 { 4*PT_D6, "4*PT_D6" },
2520 { 4*PT_D7, "4*PT_D7" },
2521 { 4*PT_A0, "4*PT_A0" },
2522 { 4*PT_A1, "4*PT_A1" },
2523 { 4*PT_A2, "4*PT_A2" },
2524 { 4*PT_A3, "4*PT_A3" },
2525 { 4*PT_A4, "4*PT_A4" },
2526 { 4*PT_A5, "4*PT_A5" },
2527 { 4*PT_A6, "4*PT_A6" },
2528 { 4*PT_D0, "4*PT_D0" },
2529 { 4*PT_USP, "4*PT_USP" },
2530 { 4*PT_ORIG_D0, "4*PT_ORIG_D0" },
2531 { 4*PT_SR, "4*PT_SR" },
2532 { 4*PT_PC, "4*PT_PC" },
2533#endif /* M68K */
2534#endif /* !I386 */
Wichert Akkermanccef6372002-05-01 16:39:22 +00002535#ifdef SH
2536 { 4*REG_REG0, "4*REG_REG0" },
2537 { 4*(REG_REG0+1), "4*REG_REG1" },
2538 { 4*(REG_REG0+2), "4*REG_REG2" },
2539 { 4*(REG_REG0+3), "4*REG_REG3" },
2540 { 4*(REG_REG0+4), "4*REG_REG4" },
2541 { 4*(REG_REG0+5), "4*REG_REG5" },
2542 { 4*(REG_REG0+6), "4*REG_REG6" },
2543 { 4*(REG_REG0+7), "4*REG_REG7" },
2544 { 4*(REG_REG0+8), "4*REG_REG8" },
2545 { 4*(REG_REG0+9), "4*REG_REG9" },
2546 { 4*(REG_REG0+10), "4*REG_REG10" },
2547 { 4*(REG_REG0+11), "4*REG_REG11" },
2548 { 4*(REG_REG0+12), "4*REG_REG12" },
2549 { 4*(REG_REG0+13), "4*REG_REG13" },
2550 { 4*(REG_REG0+14), "4*REG_REG14" },
2551 { 4*REG_REG15, "4*REG_REG15" },
2552 { 4*REG_PC, "4*REG_PC" },
2553 { 4*REG_PR, "4*REG_PR" },
2554 { 4*REG_SR, "4*REG_SR" },
2555 { 4*REG_GBR, "4*REG_GBR" },
2556 { 4*REG_MACH, "4*REG_MACH" },
2557 { 4*REG_MACL, "4*REG_MACL" },
2558 { 4*REG_SYSCALL, "4*REG_SYSCALL" },
2559 { 4*REG_FPUL, "4*REG_FPUL" },
2560 { 4*REG_FPREG0, "4*REG_FPREG0" },
2561 { 4*(REG_FPREG0+1), "4*REG_FPREG1" },
2562 { 4*(REG_FPREG0+2), "4*REG_FPREG2" },
2563 { 4*(REG_FPREG0+3), "4*REG_FPREG3" },
2564 { 4*(REG_FPREG0+4), "4*REG_FPREG4" },
2565 { 4*(REG_FPREG0+5), "4*REG_FPREG5" },
2566 { 4*(REG_FPREG0+6), "4*REG_FPREG6" },
2567 { 4*(REG_FPREG0+7), "4*REG_FPREG7" },
2568 { 4*(REG_FPREG0+8), "4*REG_FPREG8" },
2569 { 4*(REG_FPREG0+9), "4*REG_FPREG9" },
2570 { 4*(REG_FPREG0+10), "4*REG_FPREG10" },
2571 { 4*(REG_FPREG0+11), "4*REG_FPREG11" },
2572 { 4*(REG_FPREG0+12), "4*REG_FPREG12" },
2573 { 4*(REG_FPREG0+13), "4*REG_FPREG13" },
2574 { 4*(REG_FPREG0+14), "4*REG_FPREG14" },
2575 { 4*REG_FPREG15, "4*REG_FPREG15" },
Roland McGrathc0f8bbd2003-08-21 09:58:00 +00002576#ifdef REG_XDREG0
Wichert Akkermanccef6372002-05-01 16:39:22 +00002577 { 4*REG_XDREG0, "4*REG_XDREG0" },
2578 { 4*(REG_XDREG0+2), "4*REG_XDREG2" },
2579 { 4*(REG_XDREG0+4), "4*REG_XDREG4" },
2580 { 4*(REG_XDREG0+6), "4*REG_XDREG6" },
2581 { 4*(REG_XDREG0+8), "4*REG_XDREG8" },
2582 { 4*(REG_XDREG0+10), "4*REG_XDREG10" },
2583 { 4*(REG_XDREG0+12), "4*REG_XDREG12" },
2584 { 4*REG_XDREG14, "4*REG_XDREG14" },
Roland McGrathc0f8bbd2003-08-21 09:58:00 +00002585#endif
Wichert Akkermanccef6372002-05-01 16:39:22 +00002586 { 4*REG_FPSCR, "4*REG_FPSCR" },
2587#endif /* SH */
Roland McGrathf5a47772003-06-26 22:40:42 +00002588#ifdef SH64
Roland McGrathe1e584b2003-06-02 19:18:58 +00002589 { 0, "PC(L)" },
2590 { 4, "PC(U)" },
2591 { 8, "SR(L)" },
2592 { 12, "SR(U)" },
2593 { 16, "syscall no.(L)" },
2594 { 20, "syscall_no.(U)" },
2595 { 24, "R0(L)" },
2596 { 28, "R0(U)" },
2597 { 32, "R1(L)" },
2598 { 36, "R1(U)" },
2599 { 40, "R2(L)" },
2600 { 44, "R2(U)" },
2601 { 48, "R3(L)" },
2602 { 52, "R3(U)" },
2603 { 56, "R4(L)" },
2604 { 60, "R4(U)" },
2605 { 64, "R5(L)" },
2606 { 68, "R5(U)" },
2607 { 72, "R6(L)" },
2608 { 76, "R6(U)" },
2609 { 80, "R7(L)" },
2610 { 84, "R7(U)" },
2611 { 88, "R8(L)" },
2612 { 92, "R8(U)" },
2613 { 96, "R9(L)" },
2614 { 100, "R9(U)" },
2615 { 104, "R10(L)" },
2616 { 108, "R10(U)" },
2617 { 112, "R11(L)" },
2618 { 116, "R11(U)" },
2619 { 120, "R12(L)" },
2620 { 124, "R12(U)" },
2621 { 128, "R13(L)" },
2622 { 132, "R13(U)" },
2623 { 136, "R14(L)" },
2624 { 140, "R14(U)" },
2625 { 144, "R15(L)" },
2626 { 148, "R15(U)" },
2627 { 152, "R16(L)" },
2628 { 156, "R16(U)" },
2629 { 160, "R17(L)" },
2630 { 164, "R17(U)" },
2631 { 168, "R18(L)" },
2632 { 172, "R18(U)" },
2633 { 176, "R19(L)" },
2634 { 180, "R19(U)" },
2635 { 184, "R20(L)" },
2636 { 188, "R20(U)" },
2637 { 192, "R21(L)" },
2638 { 196, "R21(U)" },
2639 { 200, "R22(L)" },
2640 { 204, "R22(U)" },
2641 { 208, "R23(L)" },
2642 { 212, "R23(U)" },
2643 { 216, "R24(L)" },
2644 { 220, "R24(U)" },
2645 { 224, "R25(L)" },
2646 { 228, "R25(U)" },
2647 { 232, "R26(L)" },
2648 { 236, "R26(U)" },
2649 { 240, "R27(L)" },
2650 { 244, "R27(U)" },
2651 { 248, "R28(L)" },
2652 { 252, "R28(U)" },
2653 { 256, "R29(L)" },
2654 { 260, "R29(U)" },
2655 { 264, "R30(L)" },
2656 { 268, "R30(U)" },
2657 { 272, "R31(L)" },
2658 { 276, "R31(U)" },
2659 { 280, "R32(L)" },
2660 { 284, "R32(U)" },
2661 { 288, "R33(L)" },
2662 { 292, "R33(U)" },
2663 { 296, "R34(L)" },
2664 { 300, "R34(U)" },
2665 { 304, "R35(L)" },
2666 { 308, "R35(U)" },
2667 { 312, "R36(L)" },
2668 { 316, "R36(U)" },
2669 { 320, "R37(L)" },
2670 { 324, "R37(U)" },
2671 { 328, "R38(L)" },
2672 { 332, "R38(U)" },
2673 { 336, "R39(L)" },
2674 { 340, "R39(U)" },
2675 { 344, "R40(L)" },
2676 { 348, "R40(U)" },
2677 { 352, "R41(L)" },
2678 { 356, "R41(U)" },
2679 { 360, "R42(L)" },
2680 { 364, "R42(U)" },
2681 { 368, "R43(L)" },
2682 { 372, "R43(U)" },
2683 { 376, "R44(L)" },
2684 { 380, "R44(U)" },
2685 { 384, "R45(L)" },
2686 { 388, "R45(U)" },
2687 { 392, "R46(L)" },
2688 { 396, "R46(U)" },
2689 { 400, "R47(L)" },
2690 { 404, "R47(U)" },
2691 { 408, "R48(L)" },
2692 { 412, "R48(U)" },
2693 { 416, "R49(L)" },
2694 { 420, "R49(U)" },
2695 { 424, "R50(L)" },
2696 { 428, "R50(U)" },
2697 { 432, "R51(L)" },
2698 { 436, "R51(U)" },
2699 { 440, "R52(L)" },
2700 { 444, "R52(U)" },
2701 { 448, "R53(L)" },
2702 { 452, "R53(U)" },
2703 { 456, "R54(L)" },
2704 { 460, "R54(U)" },
2705 { 464, "R55(L)" },
2706 { 468, "R55(U)" },
2707 { 472, "R56(L)" },
2708 { 476, "R56(U)" },
2709 { 480, "R57(L)" },
2710 { 484, "R57(U)" },
2711 { 488, "R58(L)" },
2712 { 492, "R58(U)" },
2713 { 496, "R59(L)" },
2714 { 500, "R59(U)" },
2715 { 504, "R60(L)" },
2716 { 508, "R60(U)" },
2717 { 512, "R61(L)" },
2718 { 516, "R61(U)" },
2719 { 520, "R62(L)" },
2720 { 524, "R62(U)" },
2721 { 528, "TR0(L)" },
2722 { 532, "TR0(U)" },
2723 { 536, "TR1(L)" },
2724 { 540, "TR1(U)" },
2725 { 544, "TR2(L)" },
2726 { 548, "TR2(U)" },
2727 { 552, "TR3(L)" },
2728 { 556, "TR3(U)" },
2729 { 560, "TR4(L)" },
2730 { 564, "TR4(U)" },
2731 { 568, "TR5(L)" },
2732 { 572, "TR5(U)" },
2733 { 576, "TR6(L)" },
2734 { 580, "TR6(U)" },
2735 { 584, "TR7(L)" },
2736 { 588, "TR7(U)" },
2737 /* This entry is in case pt_regs contains dregs (depends on
2738 the kernel build options). */
2739 { uoff(regs), "offsetof(struct user, regs)" },
2740 { uoff(fpu), "offsetof(struct user, fpu)" },
2741#endif
Roland McGrath0f87c492003-06-03 23:29:04 +00002742#ifdef ARM
2743 { uoff(regs.ARM_r0), "r0" },
2744 { uoff(regs.ARM_r1), "r1" },
2745 { uoff(regs.ARM_r2), "r2" },
2746 { uoff(regs.ARM_r3), "r3" },
2747 { uoff(regs.ARM_r4), "r4" },
2748 { uoff(regs.ARM_r5), "r5" },
2749 { uoff(regs.ARM_r6), "r6" },
2750 { uoff(regs.ARM_r7), "r7" },
2751 { uoff(regs.ARM_r8), "r8" },
2752 { uoff(regs.ARM_r9), "r9" },
2753 { uoff(regs.ARM_r10), "r10" },
2754 { uoff(regs.ARM_fp), "fp" },
2755 { uoff(regs.ARM_ip), "ip" },
2756 { uoff(regs.ARM_sp), "sp" },
2757 { uoff(regs.ARM_lr), "lr" },
2758 { uoff(regs.ARM_pc), "pc" },
2759 { uoff(regs.ARM_cpsr), "cpsr" },
2760#endif
Wichert Akkermanccef6372002-05-01 16:39:22 +00002761
Michal Ludvig10a88d02002-10-07 14:31:00 +00002762#if !defined(S390) && !defined(S390X) && !defined(MIPS)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002763 { uoff(u_fpvalid), "offsetof(struct user, u_fpvalid)" },
Wichert Akkermanf90da011999-10-31 21:15:38 +00002764#endif
Michal Ludvig0e035502002-09-23 15:41:01 +00002765#if defined(I386) || defined(X86_64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002766 { uoff(i387), "offsetof(struct user, i387)" },
2767#else /* !I386 */
2768#ifdef M68K
2769 { uoff(m68kfp), "offsetof(struct user, m68kfp)" },
2770#endif /* M68K */
2771#endif /* !I386 */
2772 { uoff(u_tsize), "offsetof(struct user, u_tsize)" },
2773 { uoff(u_dsize), "offsetof(struct user, u_dsize)" },
2774 { uoff(u_ssize), "offsetof(struct user, u_ssize)" },
2775 { uoff(start_code), "offsetof(struct user, start_code)" },
Roland McGrathf5a47772003-06-26 22:40:42 +00002776#ifdef SH64
Roland McGrathe1e584b2003-06-02 19:18:58 +00002777 { uoff(start_data), "offsetof(struct user, start_data)" },
2778#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002779 { uoff(start_stack), "offsetof(struct user, start_stack)" },
2780 { uoff(signal), "offsetof(struct user, signal)" },
Roland McGrathf5a47772003-06-26 22:40:42 +00002781#if !defined(S390) && !defined(S390X) && !defined(MIPS) && !defined(SH) && !defined(SH64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002782 { uoff(reserved), "offsetof(struct user, reserved)" },
Wichert Akkermanf90da011999-10-31 21:15:38 +00002783#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002784 { uoff(u_ar0), "offsetof(struct user, u_ar0)" },
Michal Ludvig10a88d02002-10-07 14:31:00 +00002785#if !defined(ARM) && !defined(MIPS) && !defined(S390) && !defined(S390X)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002786 { uoff(u_fpstate), "offsetof(struct user, u_fpstate)" },
2787#endif
2788 { uoff(magic), "offsetof(struct user, magic)" },
2789 { uoff(u_comm), "offsetof(struct user, u_comm)" },
Michal Ludvig0e035502002-09-23 15:41:01 +00002790#if defined(I386) || defined(X86_64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002791 { uoff(u_debugreg), "offsetof(struct user, u_debugreg)" },
2792#endif /* I386 */
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00002793#endif /* !IA64 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002794#endif /* !ALPHA */
2795#endif /* !POWERPC/!SPARC */
2796#endif /* LINUX */
2797#ifdef SUNOS4
2798 { uoff(u_pcb), "offsetof(struct user, u_pcb)" },
2799 { uoff(u_procp), "offsetof(struct user, u_procp)" },
2800 { uoff(u_ar0), "offsetof(struct user, u_ar0)" },
2801 { uoff(u_comm[0]), "offsetof(struct user, u_comm[0])" },
2802 { uoff(u_arg[0]), "offsetof(struct user, u_arg[0])" },
2803 { uoff(u_ap), "offsetof(struct user, u_ap)" },
2804 { uoff(u_qsave), "offsetof(struct user, u_qsave)" },
2805 { uoff(u_rval1), "offsetof(struct user, u_rval1)" },
2806 { uoff(u_rval2), "offsetof(struct user, u_rval2)" },
2807 { uoff(u_error), "offsetof(struct user, u_error)" },
2808 { uoff(u_eosys), "offsetof(struct user, u_eosys)" },
2809 { uoff(u_ssave), "offsetof(struct user, u_ssave)" },
2810 { uoff(u_signal[0]), "offsetof(struct user, u_signal)" },
2811 { uoff(u_sigmask[0]), "offsetof(struct user, u_sigmask)" },
2812 { uoff(u_sigonstack), "offsetof(struct user, u_sigonstack)" },
2813 { uoff(u_sigintr), "offsetof(struct user, u_sigintr)" },
2814 { uoff(u_sigreset), "offsetof(struct user, u_sigreset)" },
2815 { uoff(u_oldmask), "offsetof(struct user, u_oldmask)" },
2816 { uoff(u_code), "offsetof(struct user, u_code)" },
2817 { uoff(u_addr), "offsetof(struct user, u_addr)" },
2818 { uoff(u_sigstack), "offsetof(struct user, u_sigstack)" },
2819 { uoff(u_ofile), "offsetof(struct user, u_ofile)" },
2820 { uoff(u_pofile), "offsetof(struct user, u_pofile)" },
2821 { uoff(u_ofile_arr[0]), "offsetof(struct user, u_ofile_arr[0])" },
2822 { uoff(u_pofile_arr[0]),"offsetof(struct user, u_pofile_arr[0])"},
2823 { uoff(u_lastfile), "offsetof(struct user, u_lastfile)" },
2824 { uoff(u_cwd), "offsetof(struct user, u_cwd)" },
2825 { uoff(u_cdir), "offsetof(struct user, u_cdir)" },
2826 { uoff(u_rdir), "offsetof(struct user, u_rdir)" },
2827 { uoff(u_cmask), "offsetof(struct user, u_cmask)" },
2828 { uoff(u_ru), "offsetof(struct user, u_ru)" },
2829 { uoff(u_cru), "offsetof(struct user, u_cru)" },
2830 { uoff(u_timer[0]), "offsetof(struct user, u_timer[0])" },
2831 { uoff(u_XXX[0]), "offsetof(struct user, u_XXX[0])" },
2832 { uoff(u_ioch), "offsetof(struct user, u_ioch)" },
2833 { uoff(u_start), "offsetof(struct user, u_start)" },
2834 { uoff(u_acflag), "offsetof(struct user, u_acflag)" },
2835 { uoff(u_prof.pr_base), "offsetof(struct user, u_prof.pr_base)" },
2836 { uoff(u_prof.pr_size), "offsetof(struct user, u_prof.pr_size)" },
2837 { uoff(u_prof.pr_off), "offsetof(struct user, u_prof.pr_off)" },
2838 { uoff(u_prof.pr_scale),"offsetof(struct user, u_prof.pr_scale)"},
2839 { uoff(u_rlimit[0]), "offsetof(struct user, u_rlimit)" },
2840 { uoff(u_exdata.Ux_A), "offsetof(struct user, u_exdata.Ux_A)" },
2841 { uoff(u_exdata.ux_shell[0]),"offsetof(struct user, u_exdata.ux_shell[0])"},
2842 { uoff(u_lofault), "offsetof(struct user, u_lofault)" },
2843#endif /* SUNOS4 */
Wichert Akkermanc1652e22001-03-27 12:17:16 +00002844#ifndef HPPA
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002845 { sizeof(struct user), "sizeof(struct user)" },
Wichert Akkermanc1652e22001-03-27 12:17:16 +00002846#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002847 { 0, NULL },
2848};
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002849#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002850
2851int
2852sys_ptrace(tcp)
2853struct tcb *tcp;
2854{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002855 struct xlat *x;
2856 long addr;
2857
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002858 if (entering(tcp)) {
Roland McGrathbf621d42003-01-14 09:46:21 +00002859 printxval(ptrace_cmds, tcp->u_arg[0],
2860#ifndef FREEBSD
2861 "PTRACE_???"
2862#else
2863 "PT_???"
2864#endif
2865 );
2866 tprintf(", %lu, ", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002867 addr = tcp->u_arg[2];
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002868#ifndef FREEBSD
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002869 if (tcp->u_arg[0] == PTRACE_PEEKUSER
2870 || tcp->u_arg[0] == PTRACE_POKEUSER) {
2871 for (x = struct_user_offsets; x->str; x++) {
2872 if (x->val >= addr)
2873 break;
2874 }
2875 if (!x->str)
2876 tprintf("%#lx, ", addr);
2877 else if (x->val > addr && x != struct_user_offsets) {
2878 x--;
2879 tprintf("%s + %ld, ", x->str, addr - x->val);
2880 }
2881 else
2882 tprintf("%s, ", x->str);
2883 }
2884 else
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002885#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002886 tprintf("%#lx, ", tcp->u_arg[2]);
2887#ifdef LINUX
2888 switch (tcp->u_arg[0]) {
2889 case PTRACE_PEEKDATA:
2890 case PTRACE_PEEKTEXT:
2891 case PTRACE_PEEKUSER:
2892 break;
2893 case PTRACE_CONT:
2894 case PTRACE_SINGLESTEP:
2895 case PTRACE_SYSCALL:
2896 case PTRACE_DETACH:
2897 printsignal(tcp->u_arg[3]);
2898 break;
2899 default:
2900 tprintf("%#lx", tcp->u_arg[3]);
2901 break;
2902 }
2903 } else {
2904 switch (tcp->u_arg[0]) {
2905 case PTRACE_PEEKDATA:
2906 case PTRACE_PEEKTEXT:
2907 case PTRACE_PEEKUSER:
Roland McGratheb285352003-01-14 09:59:00 +00002908 printnum(tcp, tcp->u_arg[3], "%#lx");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002909 break;
2910 }
2911 }
2912#endif /* LINUX */
2913#ifdef SUNOS4
2914 if (tcp->u_arg[0] == PTRACE_WRITEDATA ||
2915 tcp->u_arg[0] == PTRACE_WRITETEXT) {
2916 tprintf("%lu, ", tcp->u_arg[3]);
2917 printstr(tcp, tcp->u_arg[4], tcp->u_arg[3]);
2918 } else if (tcp->u_arg[0] != PTRACE_READDATA &&
2919 tcp->u_arg[0] != PTRACE_READTEXT) {
2920 tprintf("%#lx", tcp->u_arg[3]);
2921 }
2922 } else {
2923 if (tcp->u_arg[0] == PTRACE_READDATA ||
2924 tcp->u_arg[0] == PTRACE_READTEXT) {
2925 tprintf("%lu, ", tcp->u_arg[3]);
2926 printstr(tcp, tcp->u_arg[4], tcp->u_arg[3]);
2927 }
2928 }
2929#endif /* SUNOS4 */
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002930#ifdef FREEBSD
2931 tprintf("%lu", tcp->u_arg[3]);
2932 }
2933#endif /* FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002934 return 0;
2935}
2936
2937#endif /* !SVR4 */
Roland McGrath5a223472002-12-15 23:58:26 +00002938
2939#ifdef LINUX
2940static struct xlat futexops[] = {
2941 { FUTEX_WAIT, "FUTEX_WAIT" },
2942 { FUTEX_WAKE, "FUTEX_WAKE" },
2943 { FUTEX_FD, "FUTEX_FD" },
Roland McGrath88812d62003-06-26 22:27:23 +00002944 { FUTEX_REQUEUE,"FUTEX_REQUEUE" },
Roland McGrath5a223472002-12-15 23:58:26 +00002945 { 0, NULL }
2946};
2947
2948int
2949sys_futex(tcp)
2950struct tcb *tcp;
2951{
2952 if (entering(tcp)) {
2953 tprintf("%p, ", (void *) tcp->u_arg[0]);
Roland McGrath88812d62003-06-26 22:27:23 +00002954 printxval(futexops, tcp->u_arg[1], "FUTEX_???");
Roland McGrath8dfa04a2003-03-05 04:07:55 +00002955 tprintf(", %ld", tcp->u_arg[2]);
2956 if (tcp->u_arg[1] == FUTEX_WAIT) {
2957 tprintf(", ");
2958 printtv(tcp, tcp->u_arg[3]);
Roland McGrath88812d62003-06-26 22:27:23 +00002959 } else if (tcp->u_arg[1] == FUTEX_REQUEUE)
2960 tprintf(", %ld, %p", tcp->u_arg[3], (void *) tcp->u_arg[4]);
Roland McGrath5a223472002-12-15 23:58:26 +00002961 }
2962 return 0;
2963}
2964
2965static void
2966print_affinitylist(list, len)
2967unsigned long *list;
2968unsigned int len;
2969{
2970 int first = 1;
2971 tprintf(" {");
Roland McGratha2f34962003-05-23 00:14:04 +00002972 while (len >= sizeof (unsigned long)) {
Roland McGrath5a223472002-12-15 23:58:26 +00002973 tprintf("%s %lx", first ? "" : ",", *list++);
2974 first = 0;
2975 len -= sizeof (unsigned long);
2976 }
2977 tprintf(" }");
2978}
2979
2980int
2981sys_sched_setaffinity(tcp)
2982struct tcb *tcp;
2983{
2984 if (entering(tcp)) {
2985 tprintf("%ld, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
2986 print_affinitylist((unsigned long *) tcp->u_arg[2], tcp->u_arg[1]);
2987 }
2988 return 0;
2989}
2990
2991int
2992sys_sched_getaffinity(tcp)
2993struct tcb *tcp;
2994{
2995 if (entering(tcp)) {
2996 tprintf("%ld, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
2997 } else {
2998 print_affinitylist((unsigned long *) tcp->u_arg[2], tcp->u_rval);
2999 }
3000 return 0;
3001}
Roland McGrath279d3782004-03-01 20:27:37 +00003002
3003static struct xlat schedulers[] = {
3004 { SCHED_OTHER, "SCHED_OTHER" },
3005 { SCHED_RR, "SCHED_RR" },
3006 { SCHED_FIFO, "SCHED_FIFO" },
3007 { 0, NULL }
3008};
3009
3010int
3011sys_sched_getscheduler(tcp)
3012struct tcb *tcp;
3013{
3014 if (entering(tcp)) {
3015 tprintf("%d", (int) tcp->u_arg[0]);
3016 } else if (! syserror(tcp)) {
3017 tcp->auxstr = xlookup (schedulers, tcp->u_rval);
3018 if (tcp->auxstr != NULL)
3019 return RVAL_STR;
3020 }
3021 return 0;
3022}
3023
3024int
3025sys_sched_setscheduler(tcp)
3026struct tcb *tcp;
3027{
3028 if (entering(tcp)) {
3029 struct sched_param p;
3030 tprintf("%d, ", (int) tcp->u_arg[0]);
3031 printxval(schedulers, tcp->u_arg[1], "SCHED_???");
3032 if (umove(tcp, tcp->u_arg[2], &p) < 0)
3033 tprintf(", %lx", tcp->u_arg[2]);
3034 else
3035 tprintf(", { %d }", p.__sched_priority);
3036 }
3037 return 0;
3038}
3039
3040int
3041sys_sched_getparam(tcp)
3042struct tcb *tcp;
3043{
3044 if (entering(tcp)) {
3045 tprintf("%d, ", (int) tcp->u_arg[0]);
3046 } else {
3047 struct sched_param p;
3048 if (umove(tcp, tcp->u_arg[1], &p) < 0)
3049 tprintf("%lx", tcp->u_arg[1]);
3050 else
3051 tprintf("{ %d }", p.__sched_priority);
3052 }
3053 return 0;
3054}
3055
3056int
3057sys_sched_setparam(tcp)
3058struct tcb *tcp;
3059{
3060 if (entering(tcp)) {
3061 struct sched_param p;
3062 if (umove(tcp, tcp->u_arg[1], &p) < 0)
3063 tprintf("%d, %lx", (int) tcp->u_arg[0], tcp->u_arg[1]);
3064 else
3065 tprintf("%d, { %d }", (int) tcp->u_arg[0], p.__sched_priority);
3066 }
3067 return 0;
3068}
3069
3070int
3071sys_sched_get_priority_min(tcp)
3072struct tcb *tcp;
3073{
3074 if (entering(tcp)) {
3075 printxval(schedulers, tcp->u_arg[0], "SCHED_???");
3076 }
3077 return 0;
3078}
Roland McGrath5a223472002-12-15 23:58:26 +00003079#endif