blob: 3fb37ece1b24c4fb80ae2cd28ed5383b87f63040 [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
Roland McGrath6d1a65c2004-07-12 07:44:08 +000060#if defined (SPARC) || defined (SPARC64)
Wichert Akkerman00a82ee2001-03-28 20:29:17 +000061# define fpq kernel_fpq
62# define fq kernel_fq
63# define fpu kernel_fpu
Roland McGrath6d1a65c2004-07-12 07:44:08 +000064#endif /* SPARC || SPARC64 */
Wichert Akkerman00a82ee2001-03-28 20:29:17 +000065#include <asm/reg.h>
Roland McGrath6d1a65c2004-07-12 07:44:08 +000066#if defined (SPARC) || defined (SPARC64)
Wichert Akkerman00a82ee2001-03-28 20:29:17 +000067# undef fpq
68# undef fq
Roland McGrath5a223472002-12-15 23:58:26 +000069# undef fpu
Roland McGrath6d1a65c2004-07-12 07:44:08 +000070#endif /* SPARC || SPARC64 */
Wichert Akkerman00a82ee2001-03-28 20:29:17 +000071#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
Roland McGrathfb1bc072004-03-01 21:29:24 +000085# ifdef HAVE_STRUCT_IA64_FPREG
86# define ia64_fpreg XXX_ia64_fpreg
87# endif
88# ifdef HAVE_STRUCT_PT_ALL_USER_REGS
89# define pt_all_user_regs XXX_pt_all_user_regs
90# endif
Roland McGrath5bd7cf82003-01-24 04:31:18 +000091#include <linux/ptrace.h>
Roland McGrathfb1bc072004-03-01 21:29:24 +000092# undef ia64_fpreg
93# undef pt_all_user_regs
Roland McGrath5bd7cf82003-01-24 04:31:18 +000094#endif
95
Roland McGrath6d1a65c2004-07-12 07:44:08 +000096#if defined (LINUX) && defined (SPARC64)
97# define r_pc r_tpc
98# undef PTRACE_GETREGS
99# define PTRACE_GETREGS PTRACE_GETREGS64
100# undef PTRACE_SETREGS
101# define PTRACE_SETREGS PTRACE_SETREGS64
102#endif /* LINUX && SPARC64 */
103
Roland McGrath5a223472002-12-15 23:58:26 +0000104#ifdef HAVE_LINUX_FUTEX_H
105#include <linux/futex.h>
106#endif
107#if defined LINUX
108# ifndef FUTEX_WAIT
109# define FUTEX_WAIT 0
110# endif
111# ifndef FUTEX_WAKE
112# define FUTEX_WAKE 1
113# endif
114# ifndef FUTEX_FD
115# define FUTEX_FD 2
116# endif
Roland McGrath88812d62003-06-26 22:27:23 +0000117# ifndef FUTEX_REQUEUE
118# define FUTEX_REQUEUE 3
119# endif
Roland McGrath5a223472002-12-15 23:58:26 +0000120#endif
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000121
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000122#ifdef LINUX
Roland McGrath279d3782004-03-01 20:27:37 +0000123#include <sched.h>
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000124#include <asm/posix_types.h>
125#undef GETGROUPS_T
126#define GETGROUPS_T __kernel_gid_t
Roland McGrath83bd47a2003-11-13 22:32:26 +0000127#undef GETGROUPS32_T
128#define GETGROUPS32_T __kernel_gid32_t
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000129#endif /* LINUX */
130
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000131#if defined(LINUX) && defined(IA64)
132# include <asm/ptrace_offsets.h>
133# include <asm/rse.h>
134#endif
135
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000136#ifdef HAVE_PRCTL
137#include <sys/prctl.h>
138#endif
139
140#ifndef WCOREDUMP
141#define WCOREDUMP(status) ((status) & 0200)
142#endif
143
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000144/* WTA: this was `&& !defined(LINUXSPARC)', this seems unneeded though? */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000145#if defined(HAVE_PRCTL)
Roland McGrathd9f816f2004-09-04 03:39:20 +0000146static const struct xlat prctl_options[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000147#ifdef PR_MAXPROCS
148 { PR_MAXPROCS, "PR_MAXPROCS" },
149#endif
150#ifdef PR_ISBLOCKED
151 { PR_ISBLOCKED, "PR_ISBLOCKED" },
152#endif
153#ifdef PR_SETSTACKSIZE
154 { PR_SETSTACKSIZE, "PR_SETSTACKSIZE" },
155#endif
156#ifdef PR_GETSTACKSIZE
157 { PR_GETSTACKSIZE, "PR_GETSTACKSIZE" },
158#endif
159#ifdef PR_MAXPPROCS
160 { PR_MAXPPROCS, "PR_MAXPPROCS" },
161#endif
162#ifdef PR_UNBLKONEXEC
163 { PR_UNBLKONEXEC, "PR_UNBLKONEXEC" },
164#endif
165#ifdef PR_ATOMICSIM
166 { PR_ATOMICSIM, "PR_ATOMICSIM" },
167#endif
168#ifdef PR_SETEXITSIG
169 { PR_SETEXITSIG, "PR_SETEXITSIG" },
170#endif
171#ifdef PR_RESIDENT
172 { PR_RESIDENT, "PR_RESIDENT" },
173#endif
174#ifdef PR_ATTACHADDR
175 { PR_ATTACHADDR, "PR_ATTACHADDR" },
176#endif
177#ifdef PR_DETACHADDR
178 { PR_DETACHADDR, "PR_DETACHADDR" },
179#endif
180#ifdef PR_TERMCHILD
181 { PR_TERMCHILD, "PR_TERMCHILD" },
182#endif
183#ifdef PR_GETSHMASK
184 { PR_GETSHMASK, "PR_GETSHMASK" },
185#endif
186#ifdef PR_GETNSHARE
187 { PR_GETNSHARE, "PR_GETNSHARE" },
188#endif
189#if defined(PR_SET_PDEATHSIG)
190 { PR_SET_PDEATHSIG, "PR_SET_PDEATHSIG" },
191#endif
Wichert Akkerman8829a551999-06-11 13:18:40 +0000192#ifdef PR_COREPID
193 { PR_COREPID, "PR_COREPID" },
194#endif
195#ifdef PR_ATTACHADDRPERM
196 { PR_ATTACHADDRPERM, "PR_ATTACHADDRPERM" },
197#endif
198#ifdef PR_PTHREADEXIT
199 { PR_PTHREADEXIT, "PR_PTHREADEXIT" },
200#endif
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000201#ifdef PR_SET_PDEATHSIG
202 { PR_SET_PDEATHSIG, "PR_SET_PDEATHSIG" },
203#endif
204#ifdef PR_GET_PDEATHSIG
205 { PR_GET_PDEATHSIG, "PR_GET_PDEATHSIG" },
206#endif
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000207#ifdef PR_GET_UNALIGN
208 { PR_GET_UNALIGN, "PR_GET_UNALIGN" },
209#endif
210#ifdef PR_SET_UNALIGN
211 { PR_SET_UNALIGN, "PR_SET_UNALIGN" },
212#endif
213#ifdef PR_GET_KEEPCAPS
214 { PR_GET_KEEPCAPS, "PR_GET_KEEP_CAPS" },
215#endif
216#ifdef PR_SET_KEEPCAPS
217 { PR_SET_KEEPCAPS, "PR_SET_KEEP_CAPS" },
218#endif
Roland McGrathe5039fb2007-11-03 23:58:07 +0000219#ifdef PR_GET_FPEMU
220 { PR_GET_FPEMU, "PR_GET_FPEMU" },
221#endif
222#ifdef PR_SET_FPEMU
223 { PR_SET_FPEMU, "PR_SET_FPEMU" },
224#endif
225#ifdef PR_GET_FPEXC
226 { PR_GET_FPEXC, "PR_GET_FPEXC" },
227#endif
228#ifdef PR_SET_FPEXC
229 { PR_SET_FPEXC, "PR_SET_FPEXC" },
230#endif
231#ifdef PR_GET_TIMING
232 { PR_GET_TIMING, "PR_GET_TIMING" },
233#endif
234#ifdef PR_SET_TIMING
235 { PR_SET_TIMING, "PR_SET_TIMING" },
236#endif
237#ifdef PR_SET_NAME
238 { PR_SET_NAME, "PR_SET_NAME" },
239#endif
240#ifdef PR_GET_NAME
241 { PR_GET_NAME, "PR_GET_NAME" },
242#endif
243#ifdef PR_GET_ENDIAN
244 { PR_GET_ENDIAN, "PR_GET_ENDIAN" },
245#endif
246#ifdef PR_SET_ENDIAN
247 { PR_SET_ENDIAN, "PR_SET_ENDIAN" },
248#endif
249#ifdef PR_GET_SECCOMP
250 { PR_GET_SECCOMP, "PR_GET_SECCOMP" },
251#endif
252#ifdef PR_SET_SECCOMP
253 { PR_SET_SECCOMP, "PR_SET_SECCOMP" },
254#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000255 { 0, NULL },
256};
257
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000258
Roland McGratha4d48532005-06-08 20:45:28 +0000259static const char *
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000260unalignctl_string (unsigned int ctl)
261{
262 static char buf[16];
263
264 switch (ctl) {
265#ifdef PR_UNALIGN_NOPRINT
266 case PR_UNALIGN_NOPRINT:
267 return "NOPRINT";
268#endif
269#ifdef PR_UNALIGN_SIGBUS
270 case PR_UNALIGN_SIGBUS:
271 return "SIGBUS";
272#endif
273 default:
274 break;
275 }
276 sprintf(buf, "%x", ctl);
277 return buf;
278}
279
280
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000281int
282sys_prctl(tcp)
283struct tcb *tcp;
284{
285 int i;
286
287 if (entering(tcp)) {
288 printxval(prctl_options, tcp->u_arg[0], "PR_???");
289 switch (tcp->u_arg[0]) {
290#ifdef PR_GETNSHARE
291 case PR_GETNSHARE:
292 break;
293#endif
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000294#ifdef PR_SET_DEATHSIG
295 case PR_GET_PDEATHSIG:
296 break;
297#endif
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000298#ifdef PR_SET_UNALIGN
299 case PR_SET_UNALIGN:
300 tprintf(", %s", unalignctl_string(tcp->u_arg[1]));
301 break;
302#endif
303#ifdef PR_GET_UNALIGN
304 case PR_GET_UNALIGN:
305 tprintf(", %#lx", tcp->u_arg[1]);
306 break;
307#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000308 default:
309 for (i = 1; i < tcp->u_nargs; i++)
310 tprintf(", %#lx", tcp->u_arg[i]);
311 break;
312 }
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000313 } else {
314 switch (tcp->u_arg[0]) {
315#ifdef PR_GET_PDEATHSIG
316 case PR_GET_PDEATHSIG:
317 for (i=1; i<tcp->u_nargs; i++)
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000318 tprintf(", %#lx", tcp->u_arg[i]);
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000319 break;
320#endif
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000321#ifdef PR_SET_UNALIGN
322 case PR_SET_UNALIGN:
323 break;
324#endif
325#ifdef PR_GET_UNALIGN
326 case PR_GET_UNALIGN:
327 {
328 int ctl;
329
330 umove(tcp, tcp->u_arg[1], &ctl);
331 tcp->auxstr = unalignctl_string(ctl);
332 return RVAL_STR;
333 }
334#endif
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000335 default:
336 break;
337 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000338 }
339 return 0;
340}
341
342#endif /* HAVE_PRCTL */
343
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +0000344#if defined(FREEBSD) || defined(SUNOS4) || defined(SVR4)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000345int
346sys_gethostid(tcp)
347struct tcb *tcp;
348{
349 if (exiting(tcp))
350 return RVAL_HEX;
351 return 0;
352}
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +0000353#endif /* FREEBSD || SUNOS4 || SVR4 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000354
355int
356sys_sethostname(tcp)
357struct tcb *tcp;
358{
359 if (entering(tcp)) {
360 printpathn(tcp, tcp->u_arg[0], tcp->u_arg[1]);
361 tprintf(", %lu", tcp->u_arg[1]);
362 }
363 return 0;
364}
365
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +0000366#if defined(ALPHA) || defined(FREEBSD) || defined(SUNOS4) || defined(SVR4)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000367int
368sys_gethostname(tcp)
369struct tcb *tcp;
370{
371 if (exiting(tcp)) {
372 if (syserror(tcp))
373 tprintf("%#lx", tcp->u_arg[0]);
374 else
375 printpath(tcp, tcp->u_arg[0]);
376 tprintf(", %lu", tcp->u_arg[1]);
377 }
378 return 0;
379}
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +0000380#endif /* ALPHA || FREEBSD || SUNOS4 || SVR4 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000381
382int
383sys_setdomainname(tcp)
384struct tcb *tcp;
385{
386 if (entering(tcp)) {
387 printpathn(tcp, tcp->u_arg[0], tcp->u_arg[1]);
388 tprintf(", %lu", tcp->u_arg[1]);
389 }
390 return 0;
391}
392
Wichert Akkerman5daa0281999-03-15 19:49:42 +0000393#if !defined(LINUX)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000394
395int
396sys_getdomainname(tcp)
397struct tcb *tcp;
398{
399 if (exiting(tcp)) {
400 if (syserror(tcp))
401 tprintf("%#lx", tcp->u_arg[0]);
402 else
403 printpath(tcp, tcp->u_arg[0]);
404 tprintf(", %lu", tcp->u_arg[1]);
405 }
406 return 0;
407}
408#endif /* !LINUX */
409
410int
411sys_exit(tcp)
412struct tcb *tcp;
413{
414 if (exiting(tcp)) {
415 fprintf(stderr, "_exit returned!\n");
416 return -1;
417 }
418 /* special case: we stop tracing this process, finish line now */
419 tprintf("%ld) ", tcp->u_arg[0]);
420 tabto(acolumn);
421 tprintf("= ?");
422 printtrailer(tcp);
423 return 0;
424}
425
426int
427internal_exit(tcp)
428struct tcb *tcp;
429{
Roland McGrathe85bbfe2003-01-09 06:53:31 +0000430 if (entering(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000431 tcp->flags |= TCB_EXITING;
Roland McGrathe85bbfe2003-01-09 06:53:31 +0000432#ifdef __NR_exit_group
Roland McGrath08267b82004-02-20 22:56:43 +0000433# ifdef IA64
434 if (ia32) {
435 if (tcp->scno == 252)
436 tcp->flags |= TCB_GROUP_EXITING;
437 } else
438# endif
Roland McGratha4f9f2d2005-06-07 23:21:20 +0000439 if (known_scno(tcp) == __NR_exit_group)
Roland McGrathe85bbfe2003-01-09 06:53:31 +0000440 tcp->flags |= TCB_GROUP_EXITING;
441#endif
442 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000443 return 0;
444}
445
Roland McGrathee9d4352002-12-18 04:16:10 +0000446/* TCP is creating a child we want to follow.
447 If there will be space in tcbtab for it, set TCB_FOLLOWFORK and return 0.
448 If not, clear TCB_FOLLOWFORK, print an error, and return 1. */
449static int
450fork_tcb(struct tcb *tcp)
451{
452 if (nprocs == tcbtabsize) {
Roland McGrath7b54a7a2004-06-04 01:50:45 +0000453 if (expand_tcbtab()) {
Roland McGrathee9d4352002-12-18 04:16:10 +0000454 tcp->flags &= ~TCB_FOLLOWFORK;
Dmitry V. Levin76860f62006-10-11 22:55:25 +0000455 return 1;
Roland McGrathee9d4352002-12-18 04:16:10 +0000456 }
Roland McGrathee9d4352002-12-18 04:16:10 +0000457 }
458
459 tcp->flags |= TCB_FOLLOWFORK;
460 return 0;
461}
462
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000463#ifdef USE_PROCFS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000464
465int
466sys_fork(tcp)
467struct tcb *tcp;
468{
469 if (exiting(tcp)) {
470 if (getrval2(tcp)) {
471 tcp->auxstr = "child process";
472 return RVAL_UDECIMAL | RVAL_STR;
473 }
474 }
475 return 0;
476}
477
John Hughes4e36a812001-04-18 15:11:51 +0000478#if UNIXWARE > 2
479
480int
481sys_rfork(tcp)
482struct tcb *tcp;
483{
484 if (entering(tcp)) {
485 tprintf ("%ld", tcp->u_arg[0]);
486 }
487 else {
488 if (getrval2(tcp)) {
489 tcp->auxstr = "child process";
490 return RVAL_UDECIMAL | RVAL_STR;
491 }
492 }
493 return 0;
494}
495
496#endif
497
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000498int
499internal_fork(tcp)
500struct tcb *tcp;
501{
502 struct tcb *tcpchild;
503
504 if (exiting(tcp)) {
Roland McGrathf3a0e1b2003-02-20 02:45:22 +0000505#ifdef SYS_rfork
Roland McGratha4f9f2d2005-06-07 23:21:20 +0000506 if (known_scno(tcp) == SYS_rfork && !(tcp->u_arg[0]&RFPROC))
Roland McGrathf3a0e1b2003-02-20 02:45:22 +0000507 return 0;
508#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000509 if (getrval2(tcp))
510 return 0;
511 if (!followfork)
512 return 0;
Roland McGrathee9d4352002-12-18 04:16:10 +0000513 if (fork_tcb(tcp))
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000514 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000515 if (syserror(tcp))
516 return 0;
Dmitry V. Levin76860f62006-10-11 22:55:25 +0000517 if ((tcpchild = alloctcb(tcp->u_rval)) == NULL)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000518 return 0;
Wichert Akkerman2e4ffe52000-09-03 23:57:48 +0000519 if (proc_open(tcpchild, 2) < 0)
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000520 droptcb(tcpchild);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000521 }
522 return 0;
523}
524
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000525#else /* !USE_PROCFS */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000526
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000527#ifdef LINUX
528
529/* defines copied from linux/sched.h since we can't include that
530 * ourselves (it conflicts with *lots* of libc includes)
531 */
532#define CSIGNAL 0x000000ff /* signal mask to be sent at exit */
533#define CLONE_VM 0x00000100 /* set if VM shared between processes */
534#define CLONE_FS 0x00000200 /* set if fs info shared between processes */
535#define CLONE_FILES 0x00000400 /* set if open files shared between processes */
536#define CLONE_SIGHAND 0x00000800 /* set if signal handlers shared */
Roland McGrath909875b2002-12-22 03:34:36 +0000537#define CLONE_IDLETASK 0x00001000 /* kernel-only flag */
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000538#define CLONE_PTRACE 0x00002000 /* set if we want to let tracing continue on the child too */
539#define CLONE_VFORK 0x00004000 /* set if the parent wants the child to wake it up on mm_release */
540#define CLONE_PARENT 0x00008000 /* set if we want to have the same parent as the cloner */
Roland McGrath909875b2002-12-22 03:34:36 +0000541#define CLONE_THREAD 0x00010000 /* Same thread group? */
542#define CLONE_NEWNS 0x00020000 /* New namespace group? */
543#define CLONE_SYSVSEM 0x00040000 /* share system V SEM_UNDO semantics */
544#define CLONE_SETTLS 0x00080000 /* create a new TLS for the child */
545#define CLONE_PARENT_SETTID 0x00100000 /* set the TID in the parent */
546#define CLONE_CHILD_CLEARTID 0x00200000 /* clear the TID in the child */
547#define CLONE_DETACHED 0x00400000 /* parent wants no child-exit signal */
548#define CLONE_UNTRACED 0x00800000 /* set if the tracing process can't force CLONE_PTRACE on this clone */
549#define CLONE_CHILD_SETTID 0x01000000 /* set the TID in the child */
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000550
Roland McGrathd9f816f2004-09-04 03:39:20 +0000551static const struct xlat clone_flags[] = {
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000552 { CLONE_VM, "CLONE_VM" },
553 { CLONE_FS, "CLONE_FS" },
554 { CLONE_FILES, "CLONE_FILES" },
555 { CLONE_SIGHAND, "CLONE_SIGHAND" },
Roland McGrath909875b2002-12-22 03:34:36 +0000556 { CLONE_IDLETASK, "CLONE_IDLETASK"},
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000557 { CLONE_PTRACE, "CLONE_PTRACE" },
558 { CLONE_VFORK, "CLONE_VFORK" },
559 { CLONE_PARENT, "CLONE_PARENT" },
Roland McGrath909875b2002-12-22 03:34:36 +0000560 { CLONE_THREAD, "CLONE_THREAD" },
561 { CLONE_NEWNS, "CLONE_NEWNS" },
562 { CLONE_SYSVSEM, "CLONE_SYSVSEM" },
563 { CLONE_SETTLS, "CLONE_SETTLS" },
564 { CLONE_PARENT_SETTID,"CLONE_PARENT_SETTID" },
565 { CLONE_CHILD_CLEARTID,"CLONE_CHILD_CLEARTID" },
566 { CLONE_DETACHED, "CLONE_DETACHED" },
567 { CLONE_UNTRACED, "CLONE_UNTRACED" },
568 { CLONE_CHILD_SETTID,"CLONE_CHILD_SETTID" },
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000569 { 0, NULL },
570};
571
Roland McGrath909875b2002-12-22 03:34:36 +0000572# ifdef I386
573# include <asm/ldt.h>
Roland McGrath7decfb22004-03-01 22:10:52 +0000574# ifdef HAVE_STRUCT_USER_DESC
575# define modify_ldt_ldt_s user_desc
576# endif
Roland McGrath909875b2002-12-22 03:34:36 +0000577extern void print_ldt_entry();
578# endif
579
Roland McGrath9677b3a2003-03-12 09:54:36 +0000580# if defined IA64
581# define ARG_FLAGS 0
582# define ARG_STACK 1
Roland McGratha4f9f2d2005-06-07 23:21:20 +0000583# define ARG_STACKSIZE (known_scno(tcp) == SYS_clone2 ? 2 : -1)
584# define ARG_PTID (known_scno(tcp) == SYS_clone2 ? 3 : 2)
585# define ARG_CTID (known_scno(tcp) == SYS_clone2 ? 4 : 3)
586# define ARG_TLS (known_scno(tcp) == SYS_clone2 ? 5 : 4)
Roland McGrathfe5fdb22003-05-23 00:29:05 +0000587# elif defined S390 || defined S390X
Roland McGrath9677b3a2003-03-12 09:54:36 +0000588# define ARG_STACK 0
589# define ARG_FLAGS 1
590# define ARG_PTID 2
Roland McGrathfe5fdb22003-05-23 00:29:05 +0000591# define ARG_CTID 3
592# define ARG_TLS 4
Roland McGrath9c555e72003-07-09 09:47:59 +0000593# elif defined X86_64 || defined ALPHA
Roland McGrath361aac52003-03-18 07:43:42 +0000594# define ARG_FLAGS 0
595# define ARG_STACK 1
596# define ARG_PTID 2
597# define ARG_CTID 3
598# define ARG_TLS 4
Roland McGrath9677b3a2003-03-12 09:54:36 +0000599# else
600# define ARG_FLAGS 0
601# define ARG_STACK 1
602# define ARG_PTID 2
603# define ARG_TLS 3
604# define ARG_CTID 4
605# endif
606
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000607int
608sys_clone(tcp)
609struct tcb *tcp;
610{
611 if (exiting(tcp)) {
Roland McGrath9677b3a2003-03-12 09:54:36 +0000612 unsigned long flags = tcp->u_arg[ARG_FLAGS];
613 tprintf("child_stack=%#lx, ", tcp->u_arg[ARG_STACK]);
614# ifdef ARG_STACKSIZE
615 if (ARG_STACKSIZE != -1)
616 tprintf("stack_size=%#lx, ",
617 tcp->u_arg[ARG_STACKSIZE]);
Roland McGrathb4968be2003-01-20 09:04:33 +0000618# endif
Roland McGrath9677b3a2003-03-12 09:54:36 +0000619 tprintf("flags=");
Roland McGrathb2dee132005-06-01 19:02:36 +0000620 printflags(clone_flags, flags &~ CSIGNAL, NULL);
Roland McGrath984154d2003-05-23 01:08:42 +0000621 if ((flags & CSIGNAL) != 0)
622 tprintf("|%s", signame(flags & CSIGNAL));
Roland McGrathb4968be2003-01-20 09:04:33 +0000623 if ((flags & (CLONE_PARENT_SETTID|CLONE_CHILD_SETTID
Roland McGrath9677b3a2003-03-12 09:54:36 +0000624 |CLONE_CHILD_CLEARTID|CLONE_SETTLS)) == 0)
Roland McGrath909875b2002-12-22 03:34:36 +0000625 return 0;
Roland McGrath6f67a982003-03-21 07:33:15 +0000626 if (flags & CLONE_PARENT_SETTID)
627 tprintf(", parent_tidptr=%#lx", tcp->u_arg[ARG_PTID]);
Roland McGrathb4968be2003-01-20 09:04:33 +0000628 if (flags & CLONE_SETTLS) {
Roland McGrath9677b3a2003-03-12 09:54:36 +0000629# ifdef I386
Roland McGrath909875b2002-12-22 03:34:36 +0000630 struct modify_ldt_ldt_s copy;
Roland McGrath9677b3a2003-03-12 09:54:36 +0000631 if (umove(tcp, tcp->u_arg[ARG_TLS], &copy) != -1) {
Roland McGrath909875b2002-12-22 03:34:36 +0000632 tprintf(", {entry_number:%d, ",
633 copy.entry_number);
634 if (!verbose(tcp))
635 tprintf("...}");
636 else
637 print_ldt_entry(&copy);
638 }
639 else
Roland McGrath9677b3a2003-03-12 09:54:36 +0000640# endif
Roland McGrath43f2c842003-03-12 09:58:14 +0000641 tprintf(", tls=%#lx", tcp->u_arg[ARG_TLS]);
Roland McGrath909875b2002-12-22 03:34:36 +0000642 }
Roland McGrath9677b3a2003-03-12 09:54:36 +0000643 if (flags & (CLONE_CHILD_SETTID|CLONE_CHILD_CLEARTID))
644 tprintf(", child_tidptr=%#lx", tcp->u_arg[ARG_CTID]);
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000645 }
646 return 0;
647}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000648
649int
650sys_unshare(struct tcb *tcp)
651{
652 if (entering(tcp))
653 printflags(clone_flags, tcp->u_arg[0], "CLONE_???");
654 return 0;
655}
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000656#endif
657
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000658int
659sys_fork(tcp)
660struct tcb *tcp;
661{
662 if (exiting(tcp))
663 return RVAL_UDECIMAL;
664 return 0;
665}
666
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000667int
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000668change_syscall(tcp, new)
669struct tcb *tcp;
670int new;
671{
672#if defined(LINUX)
673#if defined(I386)
674 /* Attempt to make vfork into fork, which we can follow. */
Roland McGrath5a223472002-12-15 23:58:26 +0000675 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(ORIG_EAX * 4), new) < 0)
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000676 return -1;
677 return 0;
Michal Ludvig0e035502002-09-23 15:41:01 +0000678#elif defined(X86_64)
679 /* Attempt to make vfork into fork, which we can follow. */
Roland McGrath5a223472002-12-15 23:58:26 +0000680 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(ORIG_RAX * 8), new) < 0)
Michal Ludvig0e035502002-09-23 15:41:01 +0000681 return -1;
682 return 0;
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000683#elif defined(POWERPC)
Roland McGratheb285352003-01-14 09:59:00 +0000684 if (ptrace(PTRACE_POKEUSER, tcp->pid,
685 (char*)(sizeof(unsigned long)*PT_R0), new) < 0)
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000686 return -1;
Roland McGrath43b286f2003-01-10 11:14:41 +0000687 return 0;
Michal Ludvig10a88d02002-10-07 14:31:00 +0000688#elif defined(S390) || defined(S390X)
689 /* s390 linux after 2.4.7 has a hook in entry.S to allow this */
690 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(PT_GPR2), new)<0)
691 return -1;
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000692 return 0;
693#elif defined(M68K)
Wichert Akkermanc7926982000-04-10 22:22:31 +0000694 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(4*PT_ORIG_D0), new)<0)
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000695 return -1;
696 return 0;
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000697#elif defined(SPARC) || defined(SPARC64)
Wichert Akkerman00a82ee2001-03-28 20:29:17 +0000698 struct regs regs;
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000699 if (ptrace(PTRACE_GETREGS, tcp->pid, (char*)&regs, 0)<0)
700 return -1;
Wichert Akkerman00a82ee2001-03-28 20:29:17 +0000701 regs.r_g1=new;
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000702 if (ptrace(PTRACE_SETREGS, tcp->pid, (char*)&regs, 0)<0)
703 return -1;
704 return 0;
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000705#elif defined(MIPS)
Wichert Akkermanc7926982000-04-10 22:22:31 +0000706 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(REG_V0), new)<0)
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000707 return -1;
708 return 0;
709#elif defined(ALPHA)
Wichert Akkermanc7926982000-04-10 22:22:31 +0000710 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(REG_A3), new)<0)
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000711 return -1;
712 return 0;
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000713#elif defined(IA64)
Roland McGrath08267b82004-02-20 22:56:43 +0000714 if (ia32) {
715 switch (new) {
716 case 2: break; /* x86 SYS_fork */
717 case SYS_clone: new = 120; break;
718 default:
719 fprintf(stderr, "%s: unexpected syscall %d\n",
720 __FUNCTION__, new);
721 return -1;
722 }
723 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(PT_R1), new)<0)
724 return -1;
725 } else if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(PT_R15), new)<0)
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000726 return -1;
727 return 0;
Wichert Akkermanc1652e22001-03-27 12:17:16 +0000728#elif defined(HPPA)
729 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(PT_GR20), new)<0)
730 return -1;
731 return 0;
Wichert Akkermanccef6372002-05-01 16:39:22 +0000732#elif defined(SH)
Roland McGrathac971c22003-03-31 01:03:33 +0000733 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(4*(REG_REG0+3)), new)<0)
Wichert Akkermanccef6372002-05-01 16:39:22 +0000734 return -1;
735 return 0;
Roland McGrathf5a47772003-06-26 22:40:42 +0000736#elif defined(SH64)
Roland McGrathe1e584b2003-06-02 19:18:58 +0000737 /* Top half of reg encodes the no. of args n as 0x1n.
738 Assume 0 args as kernel never actually checks... */
739 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(REG_SYSCALL),
740 0x100000 | new) < 0)
741 return -1;
742 return 0;
Roland McGrathf691bd22006-04-25 07:34:41 +0000743#elif defined(ARM)
744 /* Some kernels support this, some (pre-2.6.16 or so) don't. */
745# ifndef PTRACE_SET_SYSCALL
746# define PTRACE_SET_SYSCALL 23
747# endif
748
749 if (ptrace (PTRACE_SET_SYSCALL, tcp->pid, 0, new) != 0)
750 return -1;
751
752 return 0;
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000753#else
754#warning Do not know how to handle change_syscall for this architecture
755#endif /* architecture */
756#endif /* LINUX */
757 return -1;
758}
759
Roland McGratha4d48532005-06-08 20:45:28 +0000760#if 0
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000761int
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000762setarg(tcp, argnum)
763 struct tcb *tcp;
764 int argnum;
765{
766#if defined (IA64)
767 {
768 unsigned long *bsp, *ap;
769
770 if (upeek(tcp->pid, PT_AR_BSP, (long *) &bsp) , 0)
771 return -1;
772
773 ap = ia64_rse_skip_regs(bsp, argnum);
774 errno = 0;
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000775 ptrace(PTRACE_POKEDATA, tcp->pid, (char *) ap, tcp->u_arg[argnum]);
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000776 if (errno)
777 return -1;
778
779 }
Wichert Akkerman12f75d12000-02-14 16:23:40 +0000780#elif defined(I386)
781 {
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000782 ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(4*argnum), tcp->u_arg[argnum]);
Wichert Akkerman12f75d12000-02-14 16:23:40 +0000783 if (errno)
784 return -1;
785 }
Michal Ludvig0e035502002-09-23 15:41:01 +0000786#elif defined(X86_64)
787 {
788 ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(8*(long)argnum), tcp->u_arg[argnum]);
789 if (errno)
790 return -1;
791 }
Roland McGrath3bb9c3d2002-12-16 20:40:48 +0000792#elif defined(POWERPC)
793#ifndef PT_ORIG_R3
794#define PT_ORIG_R3 34
795#endif
796 {
797 ptrace(PTRACE_POKEUSER, tcp->pid,
Roland McGratheb285352003-01-14 09:59:00 +0000798 (char*)((argnum==0 ? PT_ORIG_R3 : argnum+PT_R3)*sizeof(unsigned long)),
Roland McGrath3bb9c3d2002-12-16 20:40:48 +0000799 tcp->u_arg[argnum]);
800 if (errno)
801 return -1;
802 }
Ralf Baechlee3816102000-08-01 00:06:06 +0000803#elif defined(MIPS)
804 {
805 errno = 0;
806 if (argnum < 4)
807 ptrace(PTRACE_POKEUSER, tcp->pid,
808 (char*)(REG_A0 + argnum), tcp->u_arg[argnum]);
809 else {
810 unsigned long *sp;
811
812 if (upeek(tcp->pid, REG_SP, (long *) &sp) , 0)
813 return -1;
814
815 ptrace(PTRACE_POKEDATA, tcp->pid,
816 (char*)(sp + argnum - 4), tcp->u_arg[argnum]);
817 }
818 if (errno)
819 return -1;
820 }
Michal Ludvig10a88d02002-10-07 14:31:00 +0000821#elif defined(S390) || defined(S390X)
822 {
823 if(argnum <= 5)
824 ptrace(PTRACE_POKEUSER, tcp->pid,
Roland McGrath5a223472002-12-15 23:58:26 +0000825 (char *) (argnum==0 ? PT_ORIGGPR2 :
826 PT_GPR2 + argnum*sizeof(long)),
Michal Ludvig10a88d02002-10-07 14:31:00 +0000827 tcp->u_arg[argnum]);
828 else
829 return -E2BIG;
830 if (errno)
831 return -1;
832 }
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000833#else
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000834# warning Sorry, setargs not implemented for this architecture.
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000835#endif
836 return 0;
837}
Roland McGratha4d48532005-06-08 20:45:28 +0000838#endif
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000839
Roland McGrathe85bbfe2003-01-09 06:53:31 +0000840#if defined SYS_clone || defined SYS_clone2
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000841int
842internal_clone(tcp)
843struct tcb *tcp;
844{
Ulrich Drepper90512f01999-12-24 07:22:25 +0000845 struct tcb *tcpchild;
846 int pid;
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000847 if (entering(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000848 if (!followfork)
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000849 return 0;
Roland McGrathee9d4352002-12-18 04:16:10 +0000850 if (fork_tcb(tcp))
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000851 return 0;
Wichert Akkerman9b0c31d2000-09-03 21:56:29 +0000852 if (setbpt(tcp) < 0)
853 return 0;
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000854 } else {
Wichert Akkerman9b0c31d2000-09-03 21:56:29 +0000855 int bpt = tcp->flags & TCB_BPTSET;
856
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000857 if (!(tcp->flags & TCB_FOLLOWFORK))
858 return 0;
859
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000860 if (syserror(tcp)) {
861 if (bpt)
862 clearbpt(tcp);
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000863 return 0;
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000864 }
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000865
866 pid = tcp->u_rval;
Roland McGrathe85bbfe2003-01-09 06:53:31 +0000867
868#ifdef CLONE_PTRACE /* See new setbpt code. */
869 tcpchild = pid2tcb(pid);
870 if (tcpchild != NULL) {
871 /* The child already reported its startup trap
872 before the parent reported its syscall return. */
873 if ((tcpchild->flags
874 & (TCB_STARTUP|TCB_ATTACHED|TCB_SUSPENDED))
875 != (TCB_STARTUP|TCB_ATTACHED|TCB_SUSPENDED))
876 fprintf(stderr, "\
877[preattached child %d of %d in weird state!]\n",
878 pid, tcp->pid);
879 }
880 else
881#endif
Dmitry V. Levin76860f62006-10-11 22:55:25 +0000882 if (fork_tcb(tcp) || (tcpchild = alloctcb(pid)) == NULL) {
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000883 if (bpt)
884 clearbpt(tcp);
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000885 kill(pid, SIGKILL); /* XXX */
886 return 0;
887 }
888
Roland McGrathe85bbfe2003-01-09 06:53:31 +0000889#ifndef CLONE_PTRACE
Wichert Akkerman9b0c31d2000-09-03 21:56:29 +0000890 /* Attach to the new child */
891 if (ptrace(PTRACE_ATTACH, pid, (char *) 1, 0) < 0) {
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000892 if (bpt)
893 clearbpt(tcp);
Wichert Akkerman9b0c31d2000-09-03 21:56:29 +0000894 perror("PTRACE_ATTACH");
895 fprintf(stderr, "Too late?\n");
896 droptcb(tcpchild);
897 return 0;
898 }
Roland McGrathe85bbfe2003-01-09 06:53:31 +0000899#endif
Wichert Akkerman9b0c31d2000-09-03 21:56:29 +0000900
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000901 if (bpt)
902 clearbpt(tcp);
903
Ulrich Drepper90512f01999-12-24 07:22:25 +0000904 tcpchild->flags |= TCB_ATTACHED;
Roland McGrathe85bbfe2003-01-09 06:53:31 +0000905 /* Child has BPT too, must be removed on first occasion. */
Wichert Akkerman9b0c31d2000-09-03 21:56:29 +0000906 if (bpt) {
907 tcpchild->flags |= TCB_BPTSET;
908 tcpchild->baddr = tcp->baddr;
909 memcpy(tcpchild->inst, tcp->inst,
910 sizeof tcpchild->inst);
911 }
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000912 tcpchild->parent = tcp;
Roland McGrathe85bbfe2003-01-09 06:53:31 +0000913 tcp->nchildren++;
914 if (tcpchild->flags & TCB_SUSPENDED) {
915 /* The child was born suspended, due to our having
916 forced CLONE_PTRACE. */
917 if (bpt)
918 clearbpt(tcpchild);
919
920 tcpchild->flags &= ~(TCB_SUSPENDED|TCB_STARTUP);
921 if (ptrace(PTRACE_SYSCALL, pid, (char *) 1, 0) < 0) {
922 perror("resume: ptrace(PTRACE_SYSCALL, ...)");
923 return -1;
924 }
925
926 if (!qflag)
927 fprintf(stderr, "\
928Process %u resumed (parent %d ready)\n",
929 pid, tcp->pid);
930 }
931 else {
Roland McGrathe85bbfe2003-01-09 06:53:31 +0000932 if (!qflag)
933 fprintf(stderr, "Process %d attached\n", pid);
934 }
935
936#ifdef TCB_CLONE_THREAD
Roland McGrath984154d2003-05-23 01:08:42 +0000937 {
938 /*
939 * Save the flags used in this call,
940 * in case we point TCP to our parent below.
941 */
942 int call_flags = tcp->u_arg[ARG_FLAGS];
943 if ((tcp->flags & TCB_CLONE_THREAD) &&
944 tcp->parent != NULL) {
945 /* The parent in this clone is itself a
946 thread belonging to another process.
947 There is no meaning to the parentage
948 relationship of the new child with the
949 thread, only with the process. We
950 associate the new thread with our
951 parent. Since this is done for every
952 new thread, there will never be a
953 TCB_CLONE_THREAD process that has
954 children. */
955 --tcp->nchildren;
956 tcp = tcp->parent;
957 tcpchild->parent = tcp;
958 ++tcp->nchildren;
959 }
960 if (call_flags & CLONE_THREAD) {
961 tcpchild->flags |= TCB_CLONE_THREAD;
962 ++tcp->nclone_threads;
963 }
964 if (call_flags & CLONE_DETACHED) {
965 tcpchild->flags |= TCB_CLONE_DETACHED;
966 ++tcp->nclone_detached;
967 }
Roland McGrathe85bbfe2003-01-09 06:53:31 +0000968 }
969#endif
970
971 }
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000972 return 0;
973}
974#endif
975
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000976int
977internal_fork(tcp)
978struct tcb *tcp;
979{
Roland McGrathe85bbfe2003-01-09 06:53:31 +0000980#ifdef LINUX
981 /* We do special magic with clone for any clone or fork. */
982 return internal_clone(tcp);
983#else
984
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000985 struct tcb *tcpchild;
986 int pid;
Nate Sammonsccd8f211999-03-29 22:57:54 +0000987 int dont_follow = 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000988
989#ifdef SYS_vfork
Roland McGratha4f9f2d2005-06-07 23:21:20 +0000990 if (known_scno(tcp) == SYS_vfork) {
Nate Sammonsccd8f211999-03-29 22:57:54 +0000991 /* Attempt to make vfork into fork, which we can follow. */
Roland McGrath5a223472002-12-15 23:58:26 +0000992 if (!followvfork ||
Pavel Machek9a9f10b2000-02-01 16:22:52 +0000993 change_syscall(tcp, SYS_fork) < 0)
Nate Sammonsccd8f211999-03-29 22:57:54 +0000994 dont_follow = 1;
Nate Sammonsccd8f211999-03-29 22:57:54 +0000995 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000996#endif
997 if (entering(tcp)) {
Nate Sammonsccd8f211999-03-29 22:57:54 +0000998 if (!followfork || dont_follow)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000999 return 0;
Roland McGrathee9d4352002-12-18 04:16:10 +00001000 if (fork_tcb(tcp))
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001001 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001002 if (setbpt(tcp) < 0)
1003 return 0;
Wichert Akkerman7a0b6491999-12-23 15:08:17 +00001004 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001005 else {
1006 int bpt = tcp->flags & TCB_BPTSET;
1007
1008 if (!(tcp->flags & TCB_FOLLOWFORK))
1009 return 0;
1010 if (bpt)
1011 clearbpt(tcp);
1012
1013 if (syserror(tcp))
1014 return 0;
1015
1016 pid = tcp->u_rval;
Dmitry V. Levin76860f62006-10-11 22:55:25 +00001017 if (fork_tcb(tcp) || (tcpchild = alloctcb(pid)) == NULL) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001018 kill(pid, SIGKILL); /* XXX */
1019 return 0;
1020 }
1021#ifdef LINUX
Wichert Akkermanc1652e22001-03-27 12:17:16 +00001022#ifdef HPPA
1023 /* The child must have run before it can be attached. */
1024 /* This must be a bug in the parisc kernel, but I havn't
1025 * identified it yet. Seems to be an issue associated
1026 * with attaching to a process (which sends it a signal)
1027 * before that process has ever been scheduled. When
1028 * debugging, I started seeing crashes in
1029 * arch/parisc/kernel/signal.c:do_signal(), apparently
1030 * caused by r8 getting corrupt over the dequeue_signal()
1031 * call. Didn't make much sense though...
1032 */
1033 {
1034 struct timeval tv;
1035 tv.tv_sec = 0;
1036 tv.tv_usec = 10000;
1037 select(0, NULL, NULL, NULL, &tv);
1038 }
1039#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001040 if (ptrace(PTRACE_ATTACH, pid, (char *) 1, 0) < 0) {
1041 perror("PTRACE_ATTACH");
1042 fprintf(stderr, "Too late?\n");
1043 droptcb(tcpchild);
1044 return 0;
1045 }
1046#endif /* LINUX */
1047#ifdef SUNOS4
1048#ifdef oldway
1049 /* The child must have run before it can be attached. */
1050 {
1051 struct timeval tv;
1052 tv.tv_sec = 0;
1053 tv.tv_usec = 10000;
1054 select(0, NULL, NULL, NULL, &tv);
1055 }
1056 if (ptrace(PTRACE_ATTACH, pid, (char *)1, 0) < 0) {
1057 perror("PTRACE_ATTACH");
1058 fprintf(stderr, "Too late?\n");
1059 droptcb(tcpchild);
1060 return 0;
1061 }
1062#else /* !oldway */
1063 /* Try to catch the new process as soon as possible. */
1064 {
1065 int i;
1066 for (i = 0; i < 1024; i++)
1067 if (ptrace(PTRACE_ATTACH, pid, (char *) 1, 0) >= 0)
1068 break;
1069 if (i == 1024) {
1070 perror("PTRACE_ATTACH");
1071 fprintf(stderr, "Too late?\n");
1072 droptcb(tcpchild);
1073 return 0;
1074 }
1075 }
1076#endif /* !oldway */
1077#endif /* SUNOS4 */
1078 tcpchild->flags |= TCB_ATTACHED;
1079 /* Child has BPT too, must be removed on first occasion */
1080 if (bpt) {
1081 tcpchild->flags |= TCB_BPTSET;
1082 tcpchild->baddr = tcp->baddr;
1083 memcpy(tcpchild->inst, tcp->inst,
1084 sizeof tcpchild->inst);
1085 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001086 tcpchild->parent = tcp;
1087 tcp->nchildren++;
1088 if (!qflag)
1089 fprintf(stderr, "Process %d attached\n", pid);
1090 }
1091 return 0;
Roland McGrathe85bbfe2003-01-09 06:53:31 +00001092#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001093}
1094
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001095#endif /* !USE_PROCFS */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001096
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001097#if defined(SUNOS4) || defined(LINUX) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001098
1099int
1100sys_vfork(tcp)
1101struct tcb *tcp;
1102{
1103 if (exiting(tcp))
1104 return RVAL_UDECIMAL;
1105 return 0;
1106}
1107
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001108#endif /* SUNOS4 || LINUX || FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001109
1110#ifndef LINUX
1111
1112static char idstr[16];
1113
1114int
1115sys_getpid(tcp)
1116struct tcb *tcp;
1117{
1118 if (exiting(tcp)) {
1119 sprintf(idstr, "ppid %lu", getrval2(tcp));
1120 tcp->auxstr = idstr;
1121 return RVAL_STR;
1122 }
1123 return 0;
1124}
1125
1126int
1127sys_getuid(tcp)
1128struct tcb *tcp;
1129{
1130 if (exiting(tcp)) {
1131 sprintf(idstr, "euid %lu", getrval2(tcp));
1132 tcp->auxstr = idstr;
1133 return RVAL_STR;
1134 }
1135 return 0;
1136}
1137
1138int
1139sys_getgid(tcp)
1140struct tcb *tcp;
1141{
1142 if (exiting(tcp)) {
1143 sprintf(idstr, "egid %lu", getrval2(tcp));
1144 tcp->auxstr = idstr;
1145 return RVAL_STR;
1146 }
1147 return 0;
1148}
1149
1150#endif /* !LINUX */
1151
1152#ifdef LINUX
1153
1154int
1155sys_setuid(tcp)
1156struct tcb *tcp;
1157{
1158 if (entering(tcp)) {
1159 tprintf("%u", (uid_t) tcp->u_arg[0]);
1160 }
1161 return 0;
1162}
1163
1164int
1165sys_setgid(tcp)
1166struct tcb *tcp;
1167{
1168 if (entering(tcp)) {
1169 tprintf("%u", (gid_t) tcp->u_arg[0]);
1170 }
1171 return 0;
1172}
1173
1174int
1175sys_getresuid(tcp)
1176 struct tcb *tcp;
1177{
1178 if (exiting(tcp)) {
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001179 __kernel_uid_t uid;
1180 if (syserror(tcp))
1181 tprintf("%#lx, %#lx, %#lx", tcp->u_arg[0],
1182 tcp->u_arg[1], tcp->u_arg[2]);
1183 else {
1184 if (umove(tcp, tcp->u_arg[0], &uid) < 0)
1185 tprintf("%#lx, ", tcp->u_arg[0]);
1186 else
Roland McGrath83bd47a2003-11-13 22:32:26 +00001187 tprintf("[%lu], ", (unsigned long) uid);
Roland McGrath9bd6b422003-02-24 07:13:51 +00001188 if (umove(tcp, tcp->u_arg[1], &uid) < 0)
1189 tprintf("%#lx, ", tcp->u_arg[1]);
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001190 else
Roland McGrath83bd47a2003-11-13 22:32:26 +00001191 tprintf("[%lu], ", (unsigned long) uid);
Roland McGrath9bd6b422003-02-24 07:13:51 +00001192 if (umove(tcp, tcp->u_arg[2], &uid) < 0)
1193 tprintf("%#lx", tcp->u_arg[2]);
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001194 else
Roland McGrath83bd47a2003-11-13 22:32:26 +00001195 tprintf("[%lu]", (unsigned long) uid);
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001196 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001197 }
1198 return 0;
1199}
1200
1201int
1202sys_getresgid(tcp)
1203struct tcb *tcp;
1204{
1205 if (exiting(tcp)) {
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001206 __kernel_gid_t gid;
1207 if (syserror(tcp))
1208 tprintf("%#lx, %#lx, %#lx", tcp->u_arg[0],
1209 tcp->u_arg[1], tcp->u_arg[2]);
1210 else {
1211 if (umove(tcp, tcp->u_arg[0], &gid) < 0)
1212 tprintf("%#lx, ", tcp->u_arg[0]);
1213 else
Roland McGrath83bd47a2003-11-13 22:32:26 +00001214 tprintf("[%lu], ", (unsigned long) gid);
Roland McGrathd2450922003-02-24 10:18:07 +00001215 if (umove(tcp, tcp->u_arg[1], &gid) < 0)
1216 tprintf("%#lx, ", tcp->u_arg[1]);
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001217 else
Roland McGrath83bd47a2003-11-13 22:32:26 +00001218 tprintf("[%lu], ", (unsigned long) gid);
Roland McGrathd2450922003-02-24 10:18:07 +00001219 if (umove(tcp, tcp->u_arg[2], &gid) < 0)
1220 tprintf("%#lx", tcp->u_arg[2]);
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001221 else
Roland McGrath83bd47a2003-11-13 22:32:26 +00001222 tprintf("[%lu]", (unsigned long) gid);
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001223 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001224 }
1225 return 0;
1226}
1227
1228#endif /* LINUX */
1229
1230int
1231sys_setreuid(tcp)
1232struct tcb *tcp;
1233{
1234 if (entering(tcp)) {
Roland McGrath83bd47a2003-11-13 22:32:26 +00001235 printuid("", tcp->u_arg[0]);
1236 printuid(", ", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001237 }
1238 return 0;
1239}
1240
1241int
1242sys_setregid(tcp)
1243struct tcb *tcp;
1244{
1245 if (entering(tcp)) {
Roland McGrath83bd47a2003-11-13 22:32:26 +00001246 printuid("", tcp->u_arg[0]);
1247 printuid(", ", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001248 }
1249 return 0;
1250}
1251
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001252#if defined(LINUX) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001253int
1254sys_setresuid(tcp)
1255 struct tcb *tcp;
1256{
1257 if (entering(tcp)) {
Roland McGrath83bd47a2003-11-13 22:32:26 +00001258 printuid("", tcp->u_arg[0]);
1259 printuid(", ", tcp->u_arg[1]);
1260 printuid(", ", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001261 }
1262 return 0;
1263}
1264int
1265sys_setresgid(tcp)
1266 struct tcb *tcp;
1267{
1268 if (entering(tcp)) {
Roland McGrath83bd47a2003-11-13 22:32:26 +00001269 printuid("", tcp->u_arg[0]);
1270 printuid(", ", tcp->u_arg[1]);
1271 printuid(", ", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001272 }
1273 return 0;
1274}
1275
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001276#endif /* LINUX || FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001277
1278int
1279sys_setgroups(tcp)
1280struct tcb *tcp;
1281{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001282 if (entering(tcp)) {
Roland McGrathaa524c82005-06-01 19:22:06 +00001283 unsigned long len, size, start, cur, end, abbrev_end;
1284 GETGROUPS_T gid;
1285 int failed = 0;
1286
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001287 len = tcp->u_arg[0];
Roland McGrathaa524c82005-06-01 19:22:06 +00001288 tprintf("%lu, ", len);
1289 if (len == 0) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001290 tprintf("[]");
1291 return 0;
1292 }
Roland McGrathaa524c82005-06-01 19:22:06 +00001293 start = tcp->u_arg[1];
1294 if (start == 0) {
1295 tprintf("NULL");
1296 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001297 }
Roland McGrathaa524c82005-06-01 19:22:06 +00001298 size = len * sizeof(gid);
1299 end = start + size;
1300 if (!verbose(tcp) || size / sizeof(gid) != len || end < start) {
1301 tprintf("%#lx", start);
1302 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001303 }
Roland McGrathaa524c82005-06-01 19:22:06 +00001304 if (abbrev(tcp)) {
1305 abbrev_end = start + max_strlen * sizeof(gid);
1306 if (abbrev_end < start)
1307 abbrev_end = end;
1308 } else {
1309 abbrev_end = end;
1310 }
1311 tprintf("[");
1312 for (cur = start; cur < end; cur += sizeof(gid)) {
1313 if (cur > start)
1314 tprintf(", ");
1315 if (cur >= abbrev_end) {
1316 tprintf("...");
1317 break;
1318 }
1319 if (umoven(tcp, cur, sizeof(gid), (char *) &gid) < 0) {
1320 tprintf("?");
1321 failed = 1;
1322 break;
1323 }
1324 tprintf("%lu", (unsigned long) gid);
1325 }
1326 tprintf("]");
1327 if (failed)
1328 tprintf(" %#lx", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001329 }
1330 return 0;
1331}
1332
1333int
1334sys_getgroups(tcp)
1335struct tcb *tcp;
1336{
Roland McGrathaa524c82005-06-01 19:22:06 +00001337 unsigned long len;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001338
1339 if (entering(tcp)) {
1340 len = tcp->u_arg[0];
Roland McGrathaa524c82005-06-01 19:22:06 +00001341 tprintf("%lu, ", len);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001342 } else {
Roland McGrathaa524c82005-06-01 19:22:06 +00001343 unsigned long size, start, cur, end, abbrev_end;
1344 GETGROUPS_T gid;
1345 int failed = 0;
1346
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001347 len = tcp->u_rval;
Roland McGrathaa524c82005-06-01 19:22:06 +00001348 if (len == 0) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001349 tprintf("[]");
1350 return 0;
1351 }
Roland McGrathaa524c82005-06-01 19:22:06 +00001352 start = tcp->u_arg[1];
1353 if (start == 0) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001354 tprintf("NULL");
Roland McGrathaa524c82005-06-01 19:22:06 +00001355 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001356 }
Roland McGrathaa524c82005-06-01 19:22:06 +00001357 if (tcp->u_arg[0] == 0) {
1358 tprintf("%#lx", start);
1359 return 0;
1360 }
1361 size = len * sizeof(gid);
1362 end = start + size;
1363 if (!verbose(tcp) || tcp->u_arg[0] == 0 ||
1364 size / sizeof(gid) != len || end < start) {
1365 tprintf("%#lx", start);
1366 return 0;
1367 }
1368 if (abbrev(tcp)) {
1369 abbrev_end = start + max_strlen * sizeof(gid);
1370 if (abbrev_end < start)
1371 abbrev_end = end;
1372 } else {
1373 abbrev_end = end;
1374 }
1375 tprintf("[");
1376 for (cur = start; cur < end; cur += sizeof(gid)) {
1377 if (cur > start)
1378 tprintf(", ");
1379 if (cur >= abbrev_end) {
1380 tprintf("...");
1381 break;
1382 }
1383 if (umoven(tcp, cur, sizeof(gid), (char *) &gid) < 0) {
1384 tprintf("?");
1385 failed = 1;
1386 break;
1387 }
1388 tprintf("%lu", (unsigned long) gid);
1389 }
1390 tprintf("]");
1391 if (failed)
1392 tprintf(" %#lx", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001393 }
1394 return 0;
1395}
1396
Roland McGrath83bd47a2003-11-13 22:32:26 +00001397#ifdef LINUX
1398int
1399sys_setgroups32(tcp)
1400struct tcb *tcp;
1401{
Roland McGrath83bd47a2003-11-13 22:32:26 +00001402 if (entering(tcp)) {
Roland McGrathaa524c82005-06-01 19:22:06 +00001403 unsigned long len, size, start, cur, end, abbrev_end;
1404 GETGROUPS32_T gid;
1405 int failed = 0;
1406
Roland McGrath83bd47a2003-11-13 22:32:26 +00001407 len = tcp->u_arg[0];
Roland McGrathaa524c82005-06-01 19:22:06 +00001408 tprintf("%lu, ", len);
1409 if (len == 0) {
Roland McGrath83bd47a2003-11-13 22:32:26 +00001410 tprintf("[]");
1411 return 0;
1412 }
Roland McGrathaa524c82005-06-01 19:22:06 +00001413 start = tcp->u_arg[1];
1414 if (start == 0) {
1415 tprintf("NULL");
1416 return 0;
Roland McGrath83bd47a2003-11-13 22:32:26 +00001417 }
Roland McGrathaa524c82005-06-01 19:22:06 +00001418 size = len * sizeof(gid);
1419 end = start + size;
1420 if (!verbose(tcp) || size / sizeof(gid) != len || end < start) {
1421 tprintf("%#lx", start);
1422 return 0;
Roland McGrath83bd47a2003-11-13 22:32:26 +00001423 }
Roland McGrathaa524c82005-06-01 19:22:06 +00001424 if (abbrev(tcp)) {
1425 abbrev_end = start + max_strlen * sizeof(gid);
1426 if (abbrev_end < start)
1427 abbrev_end = end;
1428 } else {
1429 abbrev_end = end;
1430 }
1431 tprintf("[");
1432 for (cur = start; cur < end; cur += sizeof(gid)) {
1433 if (cur > start)
1434 tprintf(", ");
1435 if (cur >= abbrev_end) {
1436 tprintf("...");
1437 break;
1438 }
1439 if (umoven(tcp, cur, sizeof(gid), (char *) &gid) < 0) {
1440 tprintf("?");
1441 failed = 1;
1442 break;
1443 }
1444 tprintf("%lu", (unsigned long) gid);
1445 }
1446 tprintf("]");
1447 if (failed)
1448 tprintf(" %#lx", tcp->u_arg[1]);
Roland McGrath83bd47a2003-11-13 22:32:26 +00001449 }
1450 return 0;
1451}
1452
1453int
1454sys_getgroups32(tcp)
1455struct tcb *tcp;
1456{
Roland McGrathaa524c82005-06-01 19:22:06 +00001457 unsigned long len;
Roland McGrath83bd47a2003-11-13 22:32:26 +00001458
1459 if (entering(tcp)) {
1460 len = tcp->u_arg[0];
Roland McGrathaa524c82005-06-01 19:22:06 +00001461 tprintf("%lu, ", len);
Roland McGrath83bd47a2003-11-13 22:32:26 +00001462 } else {
Roland McGrathaa524c82005-06-01 19:22:06 +00001463 unsigned long size, start, cur, end, abbrev_end;
1464 GETGROUPS32_T gid;
1465 int failed = 0;
1466
Roland McGrath83bd47a2003-11-13 22:32:26 +00001467 len = tcp->u_rval;
Roland McGrathaa524c82005-06-01 19:22:06 +00001468 if (len == 0) {
Roland McGrath83bd47a2003-11-13 22:32:26 +00001469 tprintf("[]");
1470 return 0;
1471 }
Roland McGrathaa524c82005-06-01 19:22:06 +00001472 start = tcp->u_arg[1];
1473 if (start == 0) {
Roland McGrath83bd47a2003-11-13 22:32:26 +00001474 tprintf("NULL");
Roland McGrathaa524c82005-06-01 19:22:06 +00001475 return 0;
Roland McGrath83bd47a2003-11-13 22:32:26 +00001476 }
Roland McGrathaa524c82005-06-01 19:22:06 +00001477 size = len * sizeof(gid);
1478 end = start + size;
1479 if (!verbose(tcp) || tcp->u_arg[0] == 0 ||
1480 size / sizeof(gid) != len || end < start) {
1481 tprintf("%#lx", start);
1482 return 0;
1483 }
1484 if (abbrev(tcp)) {
1485 abbrev_end = start + max_strlen * sizeof(gid);
1486 if (abbrev_end < start)
1487 abbrev_end = end;
1488 } else {
1489 abbrev_end = end;
1490 }
1491 tprintf("[");
1492 for (cur = start; cur < end; cur += sizeof(gid)) {
1493 if (cur > start)
1494 tprintf(", ");
1495 if (cur >= abbrev_end) {
1496 tprintf("...");
1497 break;
1498 }
1499 if (umoven(tcp, cur, sizeof(gid), (char *) &gid) < 0) {
1500 tprintf("?");
1501 failed = 1;
1502 break;
1503 }
1504 tprintf("%lu", (unsigned long) gid);
1505 }
1506 tprintf("]");
1507 if (failed)
1508 tprintf(" %#lx", tcp->u_arg[1]);
Roland McGrath83bd47a2003-11-13 22:32:26 +00001509 }
1510 return 0;
1511}
1512#endif /* LINUX */
1513
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001514#if defined(ALPHA) || defined(SUNOS4) || defined(SVR4)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001515int
1516sys_setpgrp(tcp)
1517struct tcb *tcp;
1518{
1519 if (entering(tcp)) {
1520#ifndef SVR4
1521 tprintf("%lu, %lu", tcp->u_arg[0], tcp->u_arg[1]);
1522#endif /* !SVR4 */
1523 }
1524 return 0;
1525}
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001526#endif /* ALPHA || SUNOS4 || SVR4 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001527
1528int
1529sys_getpgrp(tcp)
1530struct tcb *tcp;
1531{
1532 if (entering(tcp)) {
1533#ifndef SVR4
1534 tprintf("%lu", tcp->u_arg[0]);
1535#endif /* !SVR4 */
1536 }
1537 return 0;
1538}
1539
1540int
1541sys_getsid(tcp)
1542struct tcb *tcp;
1543{
1544 if (entering(tcp)) {
1545 tprintf("%lu", tcp->u_arg[0]);
1546 }
1547 return 0;
1548}
1549
1550int
1551sys_setsid(tcp)
1552struct tcb *tcp;
1553{
1554 return 0;
1555}
1556
1557int
1558sys_getpgid(tcp)
1559struct tcb *tcp;
1560{
1561 if (entering(tcp)) {
1562 tprintf("%lu", tcp->u_arg[0]);
1563 }
1564 return 0;
1565}
1566
1567int
1568sys_setpgid(tcp)
1569struct tcb *tcp;
1570{
1571 if (entering(tcp)) {
1572 tprintf("%lu, %lu", tcp->u_arg[0], tcp->u_arg[1]);
1573 }
1574 return 0;
1575}
1576
John Hughesc61eb3d2002-05-17 11:37:50 +00001577#if UNIXWARE >= 2
1578
1579#include <sys/privilege.h>
1580
1581
Roland McGrathd9f816f2004-09-04 03:39:20 +00001582static const struct xlat procpriv_cmds [] = {
John Hughesc61eb3d2002-05-17 11:37:50 +00001583 { SETPRV, "SETPRV" },
1584 { CLRPRV, "CLRPRV" },
1585 { PUTPRV, "PUTPRV" },
1586 { GETPRV, "GETPRV" },
1587 { CNTPRV, "CNTPRV" },
1588 { 0, NULL },
1589};
1590
1591
Roland McGrathd9f816f2004-09-04 03:39:20 +00001592static const struct xlat procpriv_priv [] = {
John Hughesc61eb3d2002-05-17 11:37:50 +00001593 { P_OWNER, "P_OWNER" },
1594 { P_AUDIT, "P_AUDIT" },
1595 { P_COMPAT, "P_COMPAT" },
1596 { P_DACREAD, "P_DACREAD" },
1597 { P_DACWRITE, "P_DACWRITE" },
1598 { P_DEV, "P_DEV" },
1599 { P_FILESYS, "P_FILESYS" },
1600 { P_MACREAD, "P_MACREAD" },
1601 { P_MACWRITE, "P_MACWRITE" },
1602 { P_MOUNT, "P_MOUNT" },
1603 { P_MULTIDIR, "P_MULTIDIR" },
1604 { P_SETPLEVEL, "P_SETPLEVEL" },
1605 { P_SETSPRIV, "P_SETSPRIV" },
1606 { P_SETUID, "P_SETUID" },
1607 { P_SYSOPS, "P_SYSOPS" },
1608 { P_SETUPRIV, "P_SETUPRIV" },
1609 { P_DRIVER, "P_DRIVER" },
1610 { P_RTIME, "P_RTIME" },
1611 { P_MACUPGRADE, "P_MACUPGRADE" },
1612 { P_FSYSRANGE, "P_FSYSRANGE" },
1613 { P_SETFLEVEL, "P_SETFLEVEL" },
1614 { P_AUDITWR, "P_AUDITWR" },
1615 { P_TSHAR, "P_TSHAR" },
1616 { P_PLOCK, "P_PLOCK" },
1617 { P_CORE, "P_CORE" },
1618 { P_LOADMOD, "P_LOADMOD" },
1619 { P_BIND, "P_BIND" },
1620 { P_ALLPRIVS, "P_ALLPRIVS" },
1621 { 0, NULL },
1622};
1623
1624
Roland McGrathd9f816f2004-09-04 03:39:20 +00001625static const struct xlat procpriv_type [] = {
John Hughesc61eb3d2002-05-17 11:37:50 +00001626 { PS_FIX, "PS_FIX" },
1627 { PS_INH, "PS_INH" },
1628 { PS_MAX, "PS_MAX" },
1629 { PS_WKG, "PS_WKG" },
1630 { 0, NULL },
1631};
1632
1633
1634static void
Dmitry V. Levinab9008b2007-01-11 22:05:04 +00001635printpriv(struct tcb *tcp, long addr, int len, const struct xlat *opt)
John Hughesc61eb3d2002-05-17 11:37:50 +00001636{
1637 priv_t buf [128];
1638 int max = verbose (tcp) ? sizeof buf / sizeof buf [0] : 10;
1639 int dots = len > max;
1640 int i;
Roland McGrath5a223472002-12-15 23:58:26 +00001641
John Hughesc61eb3d2002-05-17 11:37:50 +00001642 if (len > max) len = max;
Roland McGrath5a223472002-12-15 23:58:26 +00001643
John Hughesc61eb3d2002-05-17 11:37:50 +00001644 if (len <= 0 ||
1645 umoven (tcp, addr, len * sizeof buf[0], (char *) buf) < 0)
1646 {
1647 tprintf ("%#lx", addr);
1648 return;
1649 }
1650
1651 tprintf ("[");
1652
1653 for (i = 0; i < len; ++i) {
Dmitry V. Levinab9008b2007-01-11 22:05:04 +00001654 const char *t, *p;
John Hughesc61eb3d2002-05-17 11:37:50 +00001655
1656 if (i) tprintf (", ");
1657
1658 if ((t = xlookup (procpriv_type, buf [i] & PS_TYPE)) &&
1659 (p = xlookup (procpriv_priv, buf [i] & ~PS_TYPE)))
1660 {
1661 tprintf ("%s|%s", t, p);
1662 }
1663 else {
1664 tprintf ("%#lx", buf [i]);
1665 }
1666 }
1667
1668 if (dots) tprintf (" ...");
1669
1670 tprintf ("]");
1671}
1672
1673
1674int
1675sys_procpriv(tcp)
1676struct tcb *tcp;
1677{
1678 if (entering(tcp)) {
1679 printxval(procpriv_cmds, tcp->u_arg[0], "???PRV");
1680 switch (tcp->u_arg[0]) {
1681 case CNTPRV:
1682 tprintf(", %#lx, %ld", tcp->u_arg[1], tcp->u_arg[2]);
1683 break;
1684
1685 case GETPRV:
1686 break;
1687
1688 default:
1689 tprintf (", ");
1690 printpriv (tcp, tcp->u_arg[1], tcp->u_arg[2]);
1691 tprintf (", %ld", tcp->u_arg[2]);
1692 }
1693 }
1694 else if (tcp->u_arg[0] == GETPRV) {
1695 if (syserror (tcp)) {
1696 tprintf(", %#lx, %ld", tcp->u_arg[1], tcp->u_arg[2]);
1697 }
1698 else {
1699 tprintf (", ");
1700 printpriv (tcp, tcp->u_arg[1], tcp->u_rval);
1701 tprintf (", %ld", tcp->u_arg[2]);
1702 }
1703 }
Roland McGrath5a223472002-12-15 23:58:26 +00001704
John Hughesc61eb3d2002-05-17 11:37:50 +00001705 return 0;
1706}
1707
1708#endif
1709
1710
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001711static void
1712printargv(tcp, addr)
1713struct tcb *tcp;
1714long addr;
1715{
Roland McGrath85a3bc42007-08-02 02:13:05 +00001716 union {
1717 int p32;
1718 long p64;
1719 char data[sizeof(long)];
1720 } cp;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001721 char *sep;
Roland McGrath85a3bc42007-08-02 02:13:05 +00001722 int n = 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001723
Roland McGrath85a3bc42007-08-02 02:13:05 +00001724 cp.p64 = 1;
1725 for (sep = ""; !abbrev(tcp) || n < max_strlen / 2; sep = ", ", ++n) {
1726 if (umoven(tcp, addr, personality_wordsize[current_personality],
1727 cp.data) < 0) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001728 tprintf("%#lx", addr);
1729 return;
1730 }
Roland McGrath85a3bc42007-08-02 02:13:05 +00001731 if (personality_wordsize[current_personality] == 4)
1732 cp.p64 = cp.p32;
1733 if (cp.p64 == 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001734 break;
1735 tprintf(sep);
Roland McGrath85a3bc42007-08-02 02:13:05 +00001736 printstr(tcp, cp.p64, -1);
1737 addr += personality_wordsize[current_personality];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001738 }
Roland McGrath85a3bc42007-08-02 02:13:05 +00001739 if (cp.p64)
1740 tprintf("%s...", sep);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001741}
1742
1743static void
1744printargc(fmt, tcp, addr)
1745char *fmt;
1746struct tcb *tcp;
1747long addr;
1748{
1749 int count;
1750 char *cp;
1751
1752 for (count = 0; umove(tcp, addr, &cp) >= 0 && cp != NULL; count++) {
1753 addr += sizeof(char *);
1754 }
1755 tprintf(fmt, count, count == 1 ? "" : "s");
1756}
1757
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001758#if defined(SPARC) || defined(SPARC64) || defined(SUNOS4)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001759int
1760sys_execv(tcp)
1761struct tcb *tcp;
1762{
1763 if (entering(tcp)) {
1764 printpath(tcp, tcp->u_arg[0]);
1765 if (!verbose(tcp))
1766 tprintf(", %#lx", tcp->u_arg[1]);
1767#if 0
1768 else if (abbrev(tcp))
1769 printargc(", [/* %d arg%s */]", tcp, tcp->u_arg[1]);
1770#endif
1771 else {
1772 tprintf(", [");
1773 printargv(tcp, tcp->u_arg[1]);
1774 tprintf("]");
1775 }
1776 }
1777 return 0;
1778}
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001779#endif /* SPARC || SPARC64 || SUNOS4 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001780
1781int
1782sys_execve(tcp)
1783struct tcb *tcp;
1784{
1785 if (entering(tcp)) {
1786 printpath(tcp, tcp->u_arg[0]);
1787 if (!verbose(tcp))
1788 tprintf(", %#lx", tcp->u_arg[1]);
1789#if 0
1790 else if (abbrev(tcp))
1791 printargc(", [/* %d arg%s */]", tcp, tcp->u_arg[1]);
1792#endif
1793 else {
1794 tprintf(", [");
1795 printargv(tcp, tcp->u_arg[1]);
1796 tprintf("]");
1797 }
1798 if (!verbose(tcp))
1799 tprintf(", %#lx", tcp->u_arg[2]);
1800 else if (abbrev(tcp))
1801 printargc(", [/* %d var%s */]", tcp, tcp->u_arg[2]);
1802 else {
1803 tprintf(", [");
1804 printargv(tcp, tcp->u_arg[2]);
1805 tprintf("]");
1806 }
1807 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001808 return 0;
1809}
1810
Roland McGrath5ef24ab2004-02-20 02:22:35 +00001811#if UNIXWARE > 2
John Hughes4e36a812001-04-18 15:11:51 +00001812
1813int sys_rexecve(tcp)
1814struct tcb *tcp;
1815{
1816 if (entering (tcp)) {
1817 sys_execve (tcp);
1818 tprintf (", %ld", tcp->u_arg[3]);
1819 }
1820 return 0;
1821}
1822
Roland McGrath5ef24ab2004-02-20 02:22:35 +00001823#endif
John Hughes4e36a812001-04-18 15:11:51 +00001824
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001825int
1826internal_exec(tcp)
1827struct tcb *tcp;
1828{
1829#ifdef SUNOS4
1830 if (exiting(tcp) && !syserror(tcp) && followfork)
1831 fixvfork(tcp);
1832#endif /* SUNOS4 */
Roland McGrathfdb097f2004-07-12 07:38:55 +00001833#if defined LINUX && defined TCB_WAITEXECVE
1834 if (exiting(tcp) && syserror(tcp))
1835 tcp->flags &= ~TCB_WAITEXECVE;
1836 else
1837 tcp->flags |= TCB_WAITEXECVE;
1838#endif /* LINUX && TCB_WAITEXECVE */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001839 return 0;
1840}
1841
1842#ifdef LINUX
Roland McGrath7ec1d352002-12-17 04:50:44 +00001843#ifndef __WNOTHREAD
1844#define __WNOTHREAD 0x20000000
1845#endif
1846#ifndef __WALL
1847#define __WALL 0x40000000
1848#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001849#ifndef __WCLONE
Roland McGrath7ec1d352002-12-17 04:50:44 +00001850#define __WCLONE 0x80000000
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001851#endif
1852#endif /* LINUX */
1853
Roland McGrathd9f816f2004-09-04 03:39:20 +00001854static const struct xlat wait4_options[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001855 { WNOHANG, "WNOHANG" },
1856#ifndef WSTOPPED
1857 { WUNTRACED, "WUNTRACED" },
1858#endif
1859#ifdef WEXITED
1860 { WEXITED, "WEXITED" },
1861#endif
1862#ifdef WTRAPPED
1863 { WTRAPPED, "WTRAPPED" },
1864#endif
1865#ifdef WSTOPPED
1866 { WSTOPPED, "WSTOPPED" },
1867#endif
1868#ifdef WCONTINUED
1869 { WCONTINUED, "WCONTINUED" },
1870#endif
1871#ifdef WNOWAIT
1872 { WNOWAIT, "WNOWAIT" },
1873#endif
1874#ifdef __WCLONE
1875 { __WCLONE, "__WCLONE" },
1876#endif
Roland McGrath7ec1d352002-12-17 04:50:44 +00001877#ifdef __WALL
1878 { __WALL, "__WALL" },
1879#endif
1880#ifdef __WNOTHREAD
1881 { __WNOTHREAD, "__WNOTHREAD" },
1882#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001883 { 0, NULL },
1884};
1885
Roland McGrath5e02a572004-10-19 23:33:47 +00001886#if !defined WCOREFLAG && defined WCOREFLG
1887# define WCOREFLAG WCOREFLG
1888#endif
1889#ifndef WCOREFLAG
1890#define WCOREFLAG 0x80
1891#endif
1892
1893#ifndef W_STOPCODE
1894#define W_STOPCODE(sig) ((sig) << 8 | 0x7f)
1895#endif
1896#ifndef W_EXITCODE
1897#define W_EXITCODE(ret, sig) ((ret) << 8 | (sig))
1898#endif
1899
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001900static int
1901printstatus(status)
1902int status;
1903{
1904 int exited = 0;
1905
1906 /*
1907 * Here is a tricky presentation problem. This solution
1908 * is still not entirely satisfactory but since there
1909 * are no wait status constructors it will have to do.
1910 */
Roland McGrath79fbda52004-04-14 02:45:55 +00001911 if (WIFSTOPPED(status)) {
1912 tprintf("[{WIFSTOPPED(s) && WSTOPSIG(s) == %s}",
Nate Sammonsce780fc1999-03-29 23:23:13 +00001913 signame(WSTOPSIG(status)));
Roland McGrath79fbda52004-04-14 02:45:55 +00001914 status &= ~W_STOPCODE(WSTOPSIG(status));
1915 }
1916 else if (WIFSIGNALED(status)) {
1917 tprintf("[{WIFSIGNALED(s) && WTERMSIG(s) == %s%s}",
Nate Sammonsce780fc1999-03-29 23:23:13 +00001918 signame(WTERMSIG(status)),
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001919 WCOREDUMP(status) ? " && WCOREDUMP(s)" : "");
Roland McGrath79fbda52004-04-14 02:45:55 +00001920 status &= ~(W_EXITCODE(0, WTERMSIG(status)) | WCOREFLAG);
1921 }
1922 else if (WIFEXITED(status)) {
1923 tprintf("[{WIFEXITED(s) && WEXITSTATUS(s) == %d}",
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001924 WEXITSTATUS(status));
1925 exited = 1;
Roland McGrath79fbda52004-04-14 02:45:55 +00001926 status &= ~W_EXITCODE(WEXITSTATUS(status), 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001927 }
Roland McGrath79fbda52004-04-14 02:45:55 +00001928 else {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001929 tprintf("[%#x]", status);
Roland McGrath79fbda52004-04-14 02:45:55 +00001930 return 0;
1931 }
1932
1933 if (status == 0)
1934 tprintf("]");
1935 else
Roland McGrathf8cc83c2004-06-04 01:24:07 +00001936 tprintf(" | %#x]", status);
Roland McGrath79fbda52004-04-14 02:45:55 +00001937
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001938 return exited;
1939}
1940
1941static int
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001942printwaitn(tcp, n, bitness)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001943struct tcb *tcp;
1944int n;
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001945int bitness;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001946{
1947 int status;
1948 int exited = 0;
1949
1950 if (entering(tcp)) {
1951 tprintf("%ld, ", tcp->u_arg[0]);
1952 } else {
1953 /* status */
1954 if (!tcp->u_arg[1])
1955 tprintf("NULL");
1956 else if (syserror(tcp) || tcp->u_rval == 0)
1957 tprintf("%#lx", tcp->u_arg[1]);
1958 else if (umove(tcp, tcp->u_arg[1], &status) < 0)
1959 tprintf("[?]");
1960 else
1961 exited = printstatus(status);
1962 /* options */
1963 tprintf(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +00001964 printflags(wait4_options, tcp->u_arg[2], "W???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001965 if (n == 4) {
1966 tprintf(", ");
1967 /* usage */
1968 if (!tcp->u_arg[3])
1969 tprintf("NULL");
1970#ifdef LINUX
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001971 else if (tcp->u_rval > 0) {
1972#ifdef LINUX_64BIT
1973 if (bitness)
1974 printrusage32(tcp, tcp->u_arg[3]);
1975 else
1976#endif
1977 printrusage(tcp, tcp->u_arg[3]);
1978 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001979#endif /* LINUX */
1980#ifdef SUNOS4
1981 else if (tcp->u_rval > 0 && exited)
1982 printrusage(tcp, tcp->u_arg[3]);
1983#endif /* SUNOS4 */
1984 else
1985 tprintf("%#lx", tcp->u_arg[3]);
1986 }
1987 }
1988 return 0;
1989}
1990
1991int
Roland McGrathc74c0b72004-09-01 19:39:46 +00001992internal_wait(tcp, flagarg)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001993struct tcb *tcp;
Roland McGrathc74c0b72004-09-01 19:39:46 +00001994int flagarg;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001995{
Roland McGrathe85bbfe2003-01-09 06:53:31 +00001996 int got_kids;
1997
1998#ifdef TCB_CLONE_THREAD
1999 if (tcp->flags & TCB_CLONE_THREAD)
2000 /* The children we wait for are our parent's children. */
2001 got_kids = (tcp->parent->nchildren
2002 > tcp->parent->nclone_detached);
2003 else
2004 got_kids = (tcp->nchildren > tcp->nclone_detached);
2005#else
2006 got_kids = tcp->nchildren > 0;
2007#endif
2008
2009 if (entering(tcp) && got_kids) {
Roland McGrathb69f81b2002-12-21 23:25:18 +00002010 /* There are children that this parent should block for.
2011 But ptrace made us the parent of the traced children
2012 and the real parent will get ECHILD from the wait call.
2013
2014 XXX If we attached with strace -f -p PID, then there
2015 may be untraced dead children the parent could be reaping
2016 now, but we make him block. */
2017
2018 /* ??? WTA: fix bug with hanging children */
2019
Roland McGrathc74c0b72004-09-01 19:39:46 +00002020 if (!(tcp->u_arg[flagarg] & WNOHANG)) {
Roland McGrath09623452003-05-23 02:27:13 +00002021 /*
2022 * There are traced children. We'll make the parent
2023 * block to avoid a false ECHILD error due to our
2024 * ptrace having stolen the children. However,
2025 * we shouldn't block if there are zombies to reap.
2026 * XXX doesn't handle pgrp matches (u_arg[0]==0,<-1)
2027 */
Roland McGrathfccfb942003-10-01 21:59:44 +00002028 struct tcb *child = NULL;
Roland McGrath09623452003-05-23 02:27:13 +00002029 if (tcp->nzombies > 0 &&
2030 (tcp->u_arg[0] == -1 ||
Roland McGrathfccfb942003-10-01 21:59:44 +00002031 (child = pid2tcb(tcp->u_arg[0])) == NULL))
Roland McGrath09623452003-05-23 02:27:13 +00002032 return 0;
Roland McGrathfccfb942003-10-01 21:59:44 +00002033 if (tcp->u_arg[0] > 0) {
2034 /*
2035 * If the parent waits for a specified child
2036 * PID, then it must get ECHILD right away
2037 * if that PID is not one of its children.
2038 * Make sure that the requested PID matches
2039 * one of the parent's children that we are
2040 * tracing, and don't suspend it otherwise.
2041 */
2042 if (child == NULL)
2043 child = pid2tcb(tcp->u_arg[0]);
2044 if (child == NULL || child->parent != (
2045#ifdef TCB_CLONE_THREAD
2046 (tcp->flags & TCB_CLONE_THREAD)
2047 ? tcp->parent :
2048#endif
Roland McGrathd56a6562005-08-03 11:23:43 +00002049 tcp) ||
2050 (child->flags & TCB_EXITING))
Roland McGrathfccfb942003-10-01 21:59:44 +00002051 return 0;
2052 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002053 tcp->flags |= TCB_SUSPENDED;
2054 tcp->waitpid = tcp->u_arg[0];
Roland McGrathe85bbfe2003-01-09 06:53:31 +00002055#ifdef TCB_CLONE_THREAD
2056 if (tcp->flags & TCB_CLONE_THREAD)
2057 tcp->parent->nclone_waiting++;
2058#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002059 }
2060 }
Roland McGrathe85bbfe2003-01-09 06:53:31 +00002061 if (exiting(tcp) && tcp->u_error == ECHILD && got_kids) {
Roland McGrathc74c0b72004-09-01 19:39:46 +00002062 if (tcp->u_arg[flagarg] & WNOHANG) {
Roland McGrathb69f81b2002-12-21 23:25:18 +00002063 /* We must force a fake result of 0 instead of
2064 the ECHILD error. */
2065 extern int force_result();
2066 return force_result(tcp, 0, 0);
2067 }
Roland McGrathb69f81b2002-12-21 23:25:18 +00002068 }
Roland McGrath09623452003-05-23 02:27:13 +00002069 else if (exiting(tcp) && tcp->u_error == 0 && tcp->u_rval > 0 &&
2070 tcp->nzombies > 0 && pid2tcb(tcp->u_rval) == NULL) {
2071 /*
2072 * We just reaped a child we don't know about,
2073 * presumably a zombie we already droptcb'd.
2074 */
2075 tcp->nzombies--;
2076 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002077 return 0;
2078}
2079
2080#ifdef SVR4
2081
2082int
2083sys_wait(tcp)
2084struct tcb *tcp;
2085{
2086 if (exiting(tcp)) {
2087 /* The library wrapper stuffs this into the user variable. */
2088 if (!syserror(tcp))
2089 printstatus(getrval2(tcp));
2090 }
2091 return 0;
2092}
2093
2094#endif /* SVR4 */
2095
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002096#ifdef FREEBSD
2097int
2098sys_wait(tcp)
2099struct tcb *tcp;
2100{
2101 int status;
Roland McGrath5a223472002-12-15 23:58:26 +00002102
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002103 if (exiting(tcp)) {
2104 if (!syserror(tcp)) {
2105 if (umove(tcp, tcp->u_arg[0], &status) < 0)
2106 tprintf("%#lx", tcp->u_arg[0]);
2107 else
2108 printstatus(status);
2109 }
2110 }
2111 return 0;
2112}
2113#endif
2114
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002115int
2116sys_waitpid(tcp)
2117struct tcb *tcp;
2118{
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00002119 return printwaitn(tcp, 3, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002120}
2121
2122int
2123sys_wait4(tcp)
2124struct tcb *tcp;
2125{
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00002126 return printwaitn(tcp, 4, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002127}
2128
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00002129#ifdef ALPHA
2130int
2131sys_osf_wait4(tcp)
2132struct tcb *tcp;
2133{
2134 return printwaitn(tcp, 4, 1);
2135}
2136#endif
2137
Roland McGrathc74c0b72004-09-01 19:39:46 +00002138#if defined SVR4 || defined LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002139
Roland McGrathd9f816f2004-09-04 03:39:20 +00002140static const struct xlat waitid_types[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002141 { P_PID, "P_PID" },
Roland McGrathc74c0b72004-09-01 19:39:46 +00002142#ifdef P_PPID
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002143 { P_PPID, "P_PPID" },
Roland McGrathc74c0b72004-09-01 19:39:46 +00002144#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002145 { P_PGID, "P_PGID" },
Roland McGrathc74c0b72004-09-01 19:39:46 +00002146#ifdef P_SID
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002147 { P_SID, "P_SID" },
Roland McGrathc74c0b72004-09-01 19:39:46 +00002148#endif
2149#ifdef P_CID
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002150 { P_CID, "P_CID" },
Roland McGrathc74c0b72004-09-01 19:39:46 +00002151#endif
2152#ifdef P_UID
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002153 { P_UID, "P_UID" },
Roland McGrathc74c0b72004-09-01 19:39:46 +00002154#endif
2155#ifdef P_GID
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002156 { P_GID, "P_GID" },
Roland McGrathc74c0b72004-09-01 19:39:46 +00002157#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002158 { P_ALL, "P_ALL" },
2159#ifdef P_LWPID
2160 { P_LWPID, "P_LWPID" },
2161#endif
2162 { 0, NULL },
2163};
2164
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002165int
2166sys_waitid(tcp)
2167struct tcb *tcp;
2168{
2169 siginfo_t si;
2170 int exited;
2171
2172 if (entering(tcp)) {
2173 printxval(waitid_types, tcp->u_arg[0], "P_???");
2174 tprintf(", %ld, ", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002175 }
2176 else {
2177 /* siginfo */
2178 exited = 0;
2179 if (!tcp->u_arg[2])
2180 tprintf("NULL");
2181 else if (syserror(tcp))
2182 tprintf("%#lx", tcp->u_arg[2]);
2183 else if (umove(tcp, tcp->u_arg[2], &si) < 0)
2184 tprintf("{???}");
2185 else
John Hughes58265892001-10-18 15:13:53 +00002186 printsiginfo(&si, verbose (tcp));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002187 /* options */
2188 tprintf(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +00002189 printflags(wait4_options, tcp->u_arg[3], "W???");
Roland McGrath39426a32004-10-06 22:02:59 +00002190 if (tcp->u_nargs > 4) {
2191 /* usage */
2192 tprintf(", ");
2193 if (!tcp->u_arg[4])
2194 tprintf("NULL");
2195 else if (tcp->u_error)
2196 tprintf("%#lx", tcp->u_arg[4]);
2197 else
2198 printrusage(tcp, tcp->u_arg[4]);
2199 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002200 }
2201 return 0;
2202}
2203
Roland McGrathc74c0b72004-09-01 19:39:46 +00002204#endif /* SVR4 or LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002205
2206int
2207sys_alarm(tcp)
2208struct tcb *tcp;
2209{
2210 if (entering(tcp))
2211 tprintf("%lu", tcp->u_arg[0]);
2212 return 0;
2213}
2214
2215int
2216sys_uname(tcp)
2217struct tcb *tcp;
2218{
2219 struct utsname uname;
2220
2221 if (exiting(tcp)) {
2222 if (syserror(tcp) || !verbose(tcp))
2223 tprintf("%#lx", tcp->u_arg[0]);
2224 else if (umove(tcp, tcp->u_arg[0], &uname) < 0)
2225 tprintf("{...}");
2226 else if (!abbrev(tcp)) {
2227
2228 tprintf("{sysname=\"%s\", nodename=\"%s\", ",
2229 uname.sysname, uname.nodename);
2230 tprintf("release=\"%s\", version=\"%s\", ",
2231 uname.release, uname.version);
2232 tprintf("machine=\"%s\"", uname.machine);
2233#ifdef LINUX
2234#ifndef __GLIBC__
2235 tprintf(", domainname=\"%s\"", uname.domainname);
2236#endif /* __GLIBC__ */
2237#endif /* LINUX */
2238 tprintf("}");
2239 }
2240 else
2241 tprintf("{sys=\"%s\", node=\"%s\", ...}",
2242 uname.sysname, uname.nodename);
2243 }
2244 return 0;
2245}
2246
2247#ifndef SVR4
2248
Roland McGrathd9f816f2004-09-04 03:39:20 +00002249static const struct xlat ptrace_cmds[] = {
Roland McGrath5a223472002-12-15 23:58:26 +00002250#ifndef FREEBSD
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002251 { PTRACE_TRACEME, "PTRACE_TRACEME" },
2252 { PTRACE_PEEKTEXT, "PTRACE_PEEKTEXT", },
2253 { PTRACE_PEEKDATA, "PTRACE_PEEKDATA", },
2254 { PTRACE_PEEKUSER, "PTRACE_PEEKUSER", },
2255 { PTRACE_POKETEXT, "PTRACE_POKETEXT", },
2256 { PTRACE_POKEDATA, "PTRACE_POKEDATA", },
2257 { PTRACE_POKEUSER, "PTRACE_POKEUSER", },
2258 { PTRACE_CONT, "PTRACE_CONT" },
2259 { PTRACE_KILL, "PTRACE_KILL" },
2260 { PTRACE_SINGLESTEP, "PTRACE_SINGLESTEP" },
2261 { PTRACE_ATTACH, "PTRACE_ATTACH" },
2262 { PTRACE_DETACH, "PTRACE_DETACH" },
Roland McGrathbf621d42003-01-14 09:46:21 +00002263#ifdef PTRACE_GETREGS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002264 { PTRACE_GETREGS, "PTRACE_GETREGS" },
Roland McGrathbf621d42003-01-14 09:46:21 +00002265#endif
2266#ifdef PTRACE_SETREGS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002267 { PTRACE_SETREGS, "PTRACE_SETREGS" },
Roland McGrathbf621d42003-01-14 09:46:21 +00002268#endif
2269#ifdef PTRACE_GETFPREGS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002270 { PTRACE_GETFPREGS, "PTRACE_GETFPREGS", },
Roland McGrathbf621d42003-01-14 09:46:21 +00002271#endif
2272#ifdef PTRACE_SETFPREGS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002273 { PTRACE_SETFPREGS, "PTRACE_SETFPREGS", },
Roland McGrathbf621d42003-01-14 09:46:21 +00002274#endif
2275#ifdef PTRACE_GETFPXREGS
2276 { PTRACE_GETFPXREGS, "PTRACE_GETFPXREGS", },
2277#endif
2278#ifdef PTRACE_SETFPXREGS
2279 { PTRACE_SETFPXREGS, "PTRACE_SETFPXREGS", },
2280#endif
Roland McGrathf04bb482005-05-09 07:45:33 +00002281#ifdef PTRACE_GETVRREGS
2282 { PTRACE_GETVRREGS, "PTRACE_GETVRREGS", },
2283#endif
2284#ifdef PTRACE_SETVRREGS
2285 { PTRACE_SETVRREGS, "PTRACE_SETVRREGS", },
2286#endif
Roland McGrathbf621d42003-01-14 09:46:21 +00002287#ifdef SUNOS4
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002288 { PTRACE_READDATA, "PTRACE_READDATA" },
2289 { PTRACE_WRITEDATA, "PTRACE_WRITEDATA" },
2290 { PTRACE_READTEXT, "PTRACE_READTEXT" },
2291 { PTRACE_WRITETEXT, "PTRACE_WRITETEXT" },
2292 { PTRACE_GETFPAREGS, "PTRACE_GETFPAREGS" },
2293 { PTRACE_SETFPAREGS, "PTRACE_SETFPAREGS" },
2294#ifdef SPARC
2295 { PTRACE_GETWINDOW, "PTRACE_GETWINDOW" },
2296 { PTRACE_SETWINDOW, "PTRACE_SETWINDOW" },
2297#else /* !SPARC */
2298 { PTRACE_22, "PTRACE_PTRACE_22" },
2299 { PTRACE_23, "PTRACE_PTRACE_23" },
2300#endif /* !SPARC */
2301#endif /* SUNOS4 */
2302 { PTRACE_SYSCALL, "PTRACE_SYSCALL" },
2303#ifdef SUNOS4
2304 { PTRACE_DUMPCORE, "PTRACE_DUMPCORE" },
2305#ifdef I386
2306 { PTRACE_SETWRBKPT, "PTRACE_SETWRBKPT" },
2307 { PTRACE_SETACBKPT, "PTRACE_SETACBKPT" },
2308 { PTRACE_CLRDR7, "PTRACE_CLRDR7" },
2309#else /* !I386 */
2310 { PTRACE_26, "PTRACE_26" },
2311 { PTRACE_27, "PTRACE_27" },
2312 { PTRACE_28, "PTRACE_28" },
2313#endif /* !I386 */
2314 { PTRACE_GETUCODE, "PTRACE_GETUCODE" },
2315#endif /* SUNOS4 */
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002316#else /* FREEBSD */
2317 { PT_TRACE_ME, "PT_TRACE_ME" },
2318 { PT_READ_I, "PT_READ_I" },
2319 { PT_READ_D, "PT_READ_D" },
2320 { PT_WRITE_I, "PT_WRITE_I" },
2321 { PT_WRITE_D, "PT_WRITE_D" },
John Hughesa2278142001-09-28 16:21:30 +00002322#ifdef PT_READ_U
2323 { PT_READ_U, "PT_READ_U" },
2324#endif
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002325 { PT_CONTINUE, "PT_CONTINUE" },
2326 { PT_KILL, "PT_KILL" },
2327 { PT_STEP, "PT_STEP" },
2328 { PT_ATTACH, "PT_ATTACH" },
2329 { PT_DETACH, "PT_DETACH" },
2330 { PT_GETREGS, "PT_GETREGS" },
2331 { PT_SETREGS, "PT_SETREGS" },
2332 { PT_GETFPREGS, "PT_GETFPREGS" },
2333 { PT_SETFPREGS, "PT_SETFPREGS" },
2334 { PT_GETDBREGS, "PT_GETDBREGS" },
2335 { PT_SETDBREGS, "PT_SETDBREGS" },
2336#endif /* FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002337 { 0, NULL },
2338};
2339
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002340#ifndef FREEBSD
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002341#ifndef SUNOS4_KERNEL_ARCH_KLUDGE
2342static
2343#endif /* !SUNOS4_KERNEL_ARCH_KLUDGE */
Roland McGrathd9f816f2004-09-04 03:39:20 +00002344const struct xlat struct_user_offsets[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002345#ifdef LINUX
Michal Ludvig10a88d02002-10-07 14:31:00 +00002346#if defined(S390) || defined(S390X)
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00002347 { PT_PSWMASK, "psw_mask" },
2348 { PT_PSWADDR, "psw_addr" },
2349 { PT_GPR0, "gpr0" },
2350 { PT_GPR1, "gpr1" },
2351 { PT_GPR2, "gpr2" },
2352 { PT_GPR3, "gpr3" },
2353 { PT_GPR4, "gpr4" },
2354 { PT_GPR5, "gpr5" },
2355 { PT_GPR6, "gpr6" },
2356 { PT_GPR7, "gpr7" },
2357 { PT_GPR8, "gpr8" },
2358 { PT_GPR9, "gpr9" },
2359 { PT_GPR10, "gpr10" },
2360 { PT_GPR11, "gpr11" },
2361 { PT_GPR12, "gpr12" },
2362 { PT_GPR13, "gpr13" },
2363 { PT_GPR14, "gpr14" },
2364 { PT_GPR15, "gpr15" },
2365 { PT_ACR0, "acr0" },
2366 { PT_ACR1, "acr1" },
2367 { PT_ACR2, "acr2" },
2368 { PT_ACR3, "acr3" },
2369 { PT_ACR4, "acr4" },
2370 { PT_ACR5, "acr5" },
2371 { PT_ACR6, "acr6" },
2372 { PT_ACR7, "acr7" },
2373 { PT_ACR8, "acr8" },
2374 { PT_ACR9, "acr9" },
2375 { PT_ACR10, "acr10" },
2376 { PT_ACR11, "acr11" },
2377 { PT_ACR12, "acr12" },
2378 { PT_ACR13, "acr13" },
2379 { PT_ACR14, "acr14" },
2380 { PT_ACR15, "acr15" },
2381 { PT_ORIGGPR2, "orig_gpr2" },
2382 { PT_FPC, "fpc" },
Michal Ludvig10a88d02002-10-07 14:31:00 +00002383#if defined(S390)
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00002384 { PT_FPR0_HI, "fpr0.hi" },
2385 { PT_FPR0_LO, "fpr0.lo" },
2386 { PT_FPR1_HI, "fpr1.hi" },
2387 { PT_FPR1_LO, "fpr1.lo" },
2388 { PT_FPR2_HI, "fpr2.hi" },
2389 { PT_FPR2_LO, "fpr2.lo" },
2390 { PT_FPR3_HI, "fpr3.hi" },
2391 { PT_FPR3_LO, "fpr3.lo" },
2392 { PT_FPR4_HI, "fpr4.hi" },
2393 { PT_FPR4_LO, "fpr4.lo" },
2394 { PT_FPR5_HI, "fpr5.hi" },
2395 { PT_FPR5_LO, "fpr5.lo" },
2396 { PT_FPR6_HI, "fpr6.hi" },
2397 { PT_FPR6_LO, "fpr6.lo" },
2398 { PT_FPR7_HI, "fpr7.hi" },
2399 { PT_FPR7_LO, "fpr7.lo" },
2400 { PT_FPR8_HI, "fpr8.hi" },
2401 { PT_FPR8_LO, "fpr8.lo" },
2402 { PT_FPR9_HI, "fpr9.hi" },
2403 { PT_FPR9_LO, "fpr9.lo" },
2404 { PT_FPR10_HI, "fpr10.hi" },
2405 { PT_FPR10_LO, "fpr10.lo" },
2406 { PT_FPR11_HI, "fpr11.hi" },
2407 { PT_FPR11_LO, "fpr11.lo" },
2408 { PT_FPR12_HI, "fpr12.hi" },
2409 { PT_FPR12_LO, "fpr12.lo" },
2410 { PT_FPR13_HI, "fpr13.hi" },
2411 { PT_FPR13_LO, "fpr13.lo" },
2412 { PT_FPR14_HI, "fpr14.hi" },
2413 { PT_FPR14_LO, "fpr14.lo" },
2414 { PT_FPR15_HI, "fpr15.hi" },
2415 { PT_FPR15_LO, "fpr15.lo" },
Michal Ludvig10a88d02002-10-07 14:31:00 +00002416#endif
2417#if defined(S390X)
2418 { PT_FPR0, "fpr0" },
2419 { PT_FPR1, "fpr1" },
2420 { PT_FPR2, "fpr2" },
2421 { PT_FPR3, "fpr3" },
2422 { PT_FPR4, "fpr4" },
2423 { PT_FPR5, "fpr5" },
2424 { PT_FPR6, "fpr6" },
2425 { PT_FPR7, "fpr7" },
2426 { PT_FPR8, "fpr8" },
2427 { PT_FPR9, "fpr9" },
2428 { PT_FPR10, "fpr10" },
2429 { PT_FPR11, "fpr11" },
2430 { PT_FPR12, "fpr12" },
2431 { PT_FPR13, "fpr13" },
2432 { PT_FPR14, "fpr14" },
2433 { PT_FPR15, "fpr15" },
2434#endif
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00002435 { PT_CR_9, "cr9" },
2436 { PT_CR_10, "cr10" },
2437 { PT_CR_11, "cr11" },
Michal Ludvig10a88d02002-10-07 14:31:00 +00002438 { PT_IEEE_IP, "ieee_exception_ip" },
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00002439#endif
2440#if defined(SPARC)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002441 /* XXX No support for these offsets yet. */
Wichert Akkermanc1652e22001-03-27 12:17:16 +00002442#elif defined(HPPA)
2443 /* XXX No support for these offsets yet. */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002444#elif defined(POWERPC)
Roland McGrath5a223472002-12-15 23:58:26 +00002445#ifndef PT_ORIG_R3
2446#define PT_ORIG_R3 34
2447#endif
Roland McGratheb285352003-01-14 09:59:00 +00002448#define REGSIZE (sizeof(unsigned long))
2449 { REGSIZE*PT_R0, "r0" },
2450 { REGSIZE*PT_R1, "r1" },
2451 { REGSIZE*PT_R2, "r2" },
2452 { REGSIZE*PT_R3, "r3" },
2453 { REGSIZE*PT_R4, "r4" },
2454 { REGSIZE*PT_R5, "r5" },
2455 { REGSIZE*PT_R6, "r6" },
2456 { REGSIZE*PT_R7, "r7" },
2457 { REGSIZE*PT_R8, "r8" },
2458 { REGSIZE*PT_R9, "r9" },
2459 { REGSIZE*PT_R10, "r10" },
2460 { REGSIZE*PT_R11, "r11" },
2461 { REGSIZE*PT_R12, "r12" },
2462 { REGSIZE*PT_R13, "r13" },
2463 { REGSIZE*PT_R14, "r14" },
2464 { REGSIZE*PT_R15, "r15" },
2465 { REGSIZE*PT_R16, "r16" },
2466 { REGSIZE*PT_R17, "r17" },
2467 { REGSIZE*PT_R18, "r18" },
2468 { REGSIZE*PT_R19, "r19" },
2469 { REGSIZE*PT_R20, "r20" },
2470 { REGSIZE*PT_R21, "r21" },
2471 { REGSIZE*PT_R22, "r22" },
2472 { REGSIZE*PT_R23, "r23" },
2473 { REGSIZE*PT_R24, "r24" },
2474 { REGSIZE*PT_R25, "r25" },
2475 { REGSIZE*PT_R26, "r26" },
2476 { REGSIZE*PT_R27, "r27" },
2477 { REGSIZE*PT_R28, "r28" },
2478 { REGSIZE*PT_R29, "r29" },
2479 { REGSIZE*PT_R30, "r30" },
2480 { REGSIZE*PT_R31, "r31" },
2481 { REGSIZE*PT_NIP, "NIP" },
2482 { REGSIZE*PT_MSR, "MSR" },
2483 { REGSIZE*PT_ORIG_R3, "ORIG_R3" },
2484 { REGSIZE*PT_CTR, "CTR" },
2485 { REGSIZE*PT_LNK, "LNK" },
2486 { REGSIZE*PT_XER, "XER" },
2487 { REGSIZE*PT_CCR, "CCR" },
2488 { REGSIZE*PT_FPR0, "FPR0" },
2489#undef REGSIZE
Roland McGrath5a223472002-12-15 23:58:26 +00002490#else
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002491#ifdef ALPHA
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00002492 { 0, "r0" },
2493 { 1, "r1" },
2494 { 2, "r2" },
2495 { 3, "r3" },
2496 { 4, "r4" },
2497 { 5, "r5" },
2498 { 6, "r6" },
2499 { 7, "r7" },
2500 { 8, "r8" },
2501 { 9, "r9" },
2502 { 10, "r10" },
2503 { 11, "r11" },
2504 { 12, "r12" },
2505 { 13, "r13" },
2506 { 14, "r14" },
2507 { 15, "r15" },
2508 { 16, "r16" },
2509 { 17, "r17" },
2510 { 18, "r18" },
2511 { 19, "r19" },
2512 { 20, "r20" },
2513 { 21, "r21" },
2514 { 22, "r22" },
2515 { 23, "r23" },
2516 { 24, "r24" },
2517 { 25, "r25" },
2518 { 26, "r26" },
2519 { 27, "r27" },
2520 { 28, "r28" },
2521 { 29, "gp" },
2522 { 30, "fp" },
2523 { 31, "zero" },
2524 { 32, "fp0" },
2525 { 33, "fp" },
2526 { 34, "fp2" },
2527 { 35, "fp3" },
2528 { 36, "fp4" },
2529 { 37, "fp5" },
2530 { 38, "fp6" },
2531 { 39, "fp7" },
2532 { 40, "fp8" },
2533 { 41, "fp9" },
2534 { 42, "fp10" },
2535 { 43, "fp11" },
2536 { 44, "fp12" },
2537 { 45, "fp13" },
2538 { 46, "fp14" },
2539 { 47, "fp15" },
2540 { 48, "fp16" },
2541 { 49, "fp17" },
2542 { 50, "fp18" },
2543 { 51, "fp19" },
2544 { 52, "fp20" },
2545 { 53, "fp21" },
2546 { 54, "fp22" },
2547 { 55, "fp23" },
2548 { 56, "fp24" },
2549 { 57, "fp25" },
2550 { 58, "fp26" },
2551 { 59, "fp27" },
2552 { 60, "fp28" },
2553 { 61, "fp29" },
2554 { 62, "fp30" },
2555 { 63, "fp31" },
2556 { 64, "pc" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002557#else /* !ALPHA */
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00002558#ifdef IA64
2559 { PT_F32, "f32" }, { PT_F33, "f33" }, { PT_F34, "f34" },
2560 { PT_F35, "f35" }, { PT_F36, "f36" }, { PT_F37, "f37" },
2561 { PT_F38, "f38" }, { PT_F39, "f39" }, { PT_F40, "f40" },
2562 { PT_F41, "f41" }, { PT_F42, "f42" }, { PT_F43, "f43" },
2563 { PT_F44, "f44" }, { PT_F45, "f45" }, { PT_F46, "f46" },
2564 { PT_F47, "f47" }, { PT_F48, "f48" }, { PT_F49, "f49" },
2565 { PT_F50, "f50" }, { PT_F51, "f51" }, { PT_F52, "f52" },
2566 { PT_F53, "f53" }, { PT_F54, "f54" }, { PT_F55, "f55" },
2567 { PT_F56, "f56" }, { PT_F57, "f57" }, { PT_F58, "f58" },
2568 { PT_F59, "f59" }, { PT_F60, "f60" }, { PT_F61, "f61" },
2569 { PT_F62, "f62" }, { PT_F63, "f63" }, { PT_F64, "f64" },
2570 { PT_F65, "f65" }, { PT_F66, "f66" }, { PT_F67, "f67" },
2571 { PT_F68, "f68" }, { PT_F69, "f69" }, { PT_F70, "f70" },
2572 { PT_F71, "f71" }, { PT_F72, "f72" }, { PT_F73, "f73" },
2573 { PT_F74, "f74" }, { PT_F75, "f75" }, { PT_F76, "f76" },
2574 { PT_F77, "f77" }, { PT_F78, "f78" }, { PT_F79, "f79" },
2575 { PT_F80, "f80" }, { PT_F81, "f81" }, { PT_F82, "f82" },
2576 { PT_F83, "f83" }, { PT_F84, "f84" }, { PT_F85, "f85" },
2577 { PT_F86, "f86" }, { PT_F87, "f87" }, { PT_F88, "f88" },
2578 { PT_F89, "f89" }, { PT_F90, "f90" }, { PT_F91, "f91" },
2579 { PT_F92, "f92" }, { PT_F93, "f93" }, { PT_F94, "f94" },
2580 { PT_F95, "f95" }, { PT_F96, "f96" }, { PT_F97, "f97" },
2581 { PT_F98, "f98" }, { PT_F99, "f99" }, { PT_F100, "f100" },
2582 { PT_F101, "f101" }, { PT_F102, "f102" }, { PT_F103, "f103" },
2583 { PT_F104, "f104" }, { PT_F105, "f105" }, { PT_F106, "f106" },
2584 { PT_F107, "f107" }, { PT_F108, "f108" }, { PT_F109, "f109" },
2585 { PT_F110, "f110" }, { PT_F111, "f111" }, { PT_F112, "f112" },
2586 { PT_F113, "f113" }, { PT_F114, "f114" }, { PT_F115, "f115" },
2587 { PT_F116, "f116" }, { PT_F117, "f117" }, { PT_F118, "f118" },
2588 { PT_F119, "f119" }, { PT_F120, "f120" }, { PT_F121, "f121" },
2589 { PT_F122, "f122" }, { PT_F123, "f123" }, { PT_F124, "f124" },
2590 { PT_F125, "f125" }, { PT_F126, "f126" }, { PT_F127, "f127" },
2591 /* switch stack: */
2592 { PT_F2, "f2" }, { PT_F3, "f3" }, { PT_F4, "f4" },
2593 { PT_F5, "f5" }, { PT_F10, "f10" }, { PT_F11, "f11" },
2594 { PT_F12, "f12" }, { PT_F13, "f13" }, { PT_F14, "f14" },
2595 { PT_F15, "f15" }, { PT_F16, "f16" }, { PT_F17, "f17" },
2596 { PT_F18, "f18" }, { PT_F19, "f19" }, { PT_F20, "f20" },
2597 { PT_F21, "f21" }, { PT_F22, "f22" }, { PT_F23, "f23" },
2598 { PT_F24, "f24" }, { PT_F25, "f25" }, { PT_F26, "f26" },
2599 { PT_F27, "f27" }, { PT_F28, "f28" }, { PT_F29, "f29" },
2600 { PT_F30, "f30" }, { PT_F31, "f31" }, { PT_R4, "r4" },
2601 { PT_R5, "r5" }, { PT_R6, "r6" }, { PT_R7, "r7" },
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00002602 { PT_B1, "b1" }, { PT_B2, "b2" }, { PT_B3, "b3" },
2603 { PT_B4, "b4" }, { PT_B5, "b5" },
Roland McGrathca4e10c2004-01-13 10:13:20 +00002604 { PT_AR_EC, "ar.ec" }, { PT_AR_LC, "ar.lc" },
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00002605 /* pt_regs */
Roland McGrathca4e10c2004-01-13 10:13:20 +00002606 { PT_CR_IPSR, "psr" }, { PT_CR_IIP, "ip" },
2607 { PT_CFM, "cfm" }, { PT_AR_UNAT, "ar.unat" },
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00002608 { PT_AR_PFS, "ar.pfs" }, { PT_AR_RSC, "ar.rsc" },
2609 { PT_AR_RNAT, "ar.rnat" }, { PT_AR_BSPSTORE, "ar.bspstore" },
2610 { PT_PR, "pr" }, { PT_B6, "b6" }, { PT_AR_BSP, "ar.bsp" },
2611 { PT_R1, "r1" }, { PT_R2, "r2" }, { PT_R3, "r3" },
2612 { PT_R12, "r12" }, { PT_R13, "r13" }, { PT_R14, "r14" },
2613 { PT_R15, "r15" }, { PT_R8, "r8" }, { PT_R9, "r9" },
2614 { PT_R10, "r10" }, { PT_R11, "r11" }, { PT_R16, "r16" },
2615 { PT_R17, "r17" }, { PT_R18, "r18" }, { PT_R19, "r19" },
2616 { PT_R20, "r20" }, { PT_R21, "r21" }, { PT_R22, "r22" },
2617 { PT_R23, "r23" }, { PT_R24, "r24" }, { PT_R25, "r25" },
2618 { PT_R26, "r26" }, { PT_R27, "r27" }, { PT_R28, "r28" },
2619 { PT_R29, "r29" }, { PT_R30, "r30" }, { PT_R31, "r31" },
2620 { PT_AR_CCV, "ar.ccv" }, { PT_AR_FPSR, "ar.fpsr" },
2621 { PT_B0, "b0" }, { PT_B7, "b7" }, { PT_F6, "f6" },
2622 { PT_F7, "f7" }, { PT_F8, "f8" }, { PT_F9, "f9" },
Roland McGrathfb1bc072004-03-01 21:29:24 +00002623# ifdef PT_AR_CSD
2624 { PT_AR_CSD, "ar.csd" },
2625# endif
2626# ifdef PT_AR_SSD
2627 { PT_AR_SSD, "ar.ssd" },
2628# endif
Roland McGrathca4e10c2004-01-13 10:13:20 +00002629 { PT_DBR, "dbr" }, { PT_IBR, "ibr" }, { PT_PMD, "pmd" },
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00002630#else /* !IA64 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002631#ifdef I386
2632 { 4*EBX, "4*EBX" },
2633 { 4*ECX, "4*ECX" },
2634 { 4*EDX, "4*EDX" },
2635 { 4*ESI, "4*ESI" },
2636 { 4*EDI, "4*EDI" },
2637 { 4*EBP, "4*EBP" },
2638 { 4*EAX, "4*EAX" },
2639 { 4*DS, "4*DS" },
2640 { 4*ES, "4*ES" },
2641 { 4*FS, "4*FS" },
2642 { 4*GS, "4*GS" },
2643 { 4*ORIG_EAX, "4*ORIG_EAX" },
2644 { 4*EIP, "4*EIP" },
2645 { 4*CS, "4*CS" },
2646 { 4*EFL, "4*EFL" },
2647 { 4*UESP, "4*UESP" },
2648 { 4*SS, "4*SS" },
2649#else /* !I386 */
Michal Ludvig0e035502002-09-23 15:41:01 +00002650#ifdef X86_64
Roland McGratha4f9f2d2005-06-07 23:21:20 +00002651 { 8*R15, "8*R15" },
2652 { 8*R14, "8*R14" },
2653 { 8*R13, "8*R13" },
2654 { 8*R12, "8*R12" },
Michal Ludvig0e035502002-09-23 15:41:01 +00002655 { 8*RBP, "8*RBP" },
Roland McGratha4f9f2d2005-06-07 23:21:20 +00002656 { 8*RBX, "8*RBX" },
2657 { 8*R11, "8*R11" },
2658 { 8*R10, "8*R10" },
2659 { 8*R9, "8*R9" },
2660 { 8*R8, "8*R8" },
Michal Ludvig0e035502002-09-23 15:41:01 +00002661 { 8*RAX, "8*RAX" },
Roland McGratha4f9f2d2005-06-07 23:21:20 +00002662 { 8*RCX, "8*RCX" },
2663 { 8*RDX, "8*RDX" },
2664 { 8*RSI, "8*RSI" },
2665 { 8*RDI, "8*RDI" },
Michal Ludvig0e035502002-09-23 15:41:01 +00002666#if 0
Roland McGratha4f9f2d2005-06-07 23:21:20 +00002667 { DS, "DS" },
2668 { ES, "ES" },
2669 { FS, "FS" },
2670 { GS, "GS" },
Michal Ludvig0e035502002-09-23 15:41:01 +00002671#endif
Roland McGratha4f9f2d2005-06-07 23:21:20 +00002672 { 8*ORIG_RAX, "8*ORIG_RAX" },
Michal Ludvig0e035502002-09-23 15:41:01 +00002673 { 8*RIP, "8*RIP" },
2674 { 8*CS, "8*CS" },
2675 { 8*EFLAGS, "8*EFL" },
Roland McGratha4f9f2d2005-06-07 23:21:20 +00002676 { 8*RSP, "8*RSP" },
Michal Ludvig0e035502002-09-23 15:41:01 +00002677 { 8*SS, "8*SS" },
Michal Ludvig0e035502002-09-23 15:41:01 +00002678#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002679#ifdef M68K
2680 { 4*PT_D1, "4*PT_D1" },
2681 { 4*PT_D2, "4*PT_D2" },
2682 { 4*PT_D3, "4*PT_D3" },
2683 { 4*PT_D4, "4*PT_D4" },
2684 { 4*PT_D5, "4*PT_D5" },
2685 { 4*PT_D6, "4*PT_D6" },
2686 { 4*PT_D7, "4*PT_D7" },
2687 { 4*PT_A0, "4*PT_A0" },
2688 { 4*PT_A1, "4*PT_A1" },
2689 { 4*PT_A2, "4*PT_A2" },
2690 { 4*PT_A3, "4*PT_A3" },
2691 { 4*PT_A4, "4*PT_A4" },
2692 { 4*PT_A5, "4*PT_A5" },
2693 { 4*PT_A6, "4*PT_A6" },
2694 { 4*PT_D0, "4*PT_D0" },
2695 { 4*PT_USP, "4*PT_USP" },
2696 { 4*PT_ORIG_D0, "4*PT_ORIG_D0" },
2697 { 4*PT_SR, "4*PT_SR" },
2698 { 4*PT_PC, "4*PT_PC" },
2699#endif /* M68K */
2700#endif /* !I386 */
Wichert Akkermanccef6372002-05-01 16:39:22 +00002701#ifdef SH
2702 { 4*REG_REG0, "4*REG_REG0" },
2703 { 4*(REG_REG0+1), "4*REG_REG1" },
2704 { 4*(REG_REG0+2), "4*REG_REG2" },
2705 { 4*(REG_REG0+3), "4*REG_REG3" },
2706 { 4*(REG_REG0+4), "4*REG_REG4" },
2707 { 4*(REG_REG0+5), "4*REG_REG5" },
2708 { 4*(REG_REG0+6), "4*REG_REG6" },
2709 { 4*(REG_REG0+7), "4*REG_REG7" },
2710 { 4*(REG_REG0+8), "4*REG_REG8" },
2711 { 4*(REG_REG0+9), "4*REG_REG9" },
2712 { 4*(REG_REG0+10), "4*REG_REG10" },
2713 { 4*(REG_REG0+11), "4*REG_REG11" },
2714 { 4*(REG_REG0+12), "4*REG_REG12" },
2715 { 4*(REG_REG0+13), "4*REG_REG13" },
2716 { 4*(REG_REG0+14), "4*REG_REG14" },
2717 { 4*REG_REG15, "4*REG_REG15" },
2718 { 4*REG_PC, "4*REG_PC" },
2719 { 4*REG_PR, "4*REG_PR" },
2720 { 4*REG_SR, "4*REG_SR" },
2721 { 4*REG_GBR, "4*REG_GBR" },
2722 { 4*REG_MACH, "4*REG_MACH" },
2723 { 4*REG_MACL, "4*REG_MACL" },
2724 { 4*REG_SYSCALL, "4*REG_SYSCALL" },
2725 { 4*REG_FPUL, "4*REG_FPUL" },
2726 { 4*REG_FPREG0, "4*REG_FPREG0" },
2727 { 4*(REG_FPREG0+1), "4*REG_FPREG1" },
2728 { 4*(REG_FPREG0+2), "4*REG_FPREG2" },
2729 { 4*(REG_FPREG0+3), "4*REG_FPREG3" },
2730 { 4*(REG_FPREG0+4), "4*REG_FPREG4" },
2731 { 4*(REG_FPREG0+5), "4*REG_FPREG5" },
2732 { 4*(REG_FPREG0+6), "4*REG_FPREG6" },
2733 { 4*(REG_FPREG0+7), "4*REG_FPREG7" },
2734 { 4*(REG_FPREG0+8), "4*REG_FPREG8" },
2735 { 4*(REG_FPREG0+9), "4*REG_FPREG9" },
2736 { 4*(REG_FPREG0+10), "4*REG_FPREG10" },
2737 { 4*(REG_FPREG0+11), "4*REG_FPREG11" },
2738 { 4*(REG_FPREG0+12), "4*REG_FPREG12" },
2739 { 4*(REG_FPREG0+13), "4*REG_FPREG13" },
2740 { 4*(REG_FPREG0+14), "4*REG_FPREG14" },
2741 { 4*REG_FPREG15, "4*REG_FPREG15" },
Roland McGrathc0f8bbd2003-08-21 09:58:00 +00002742#ifdef REG_XDREG0
Wichert Akkermanccef6372002-05-01 16:39:22 +00002743 { 4*REG_XDREG0, "4*REG_XDREG0" },
2744 { 4*(REG_XDREG0+2), "4*REG_XDREG2" },
2745 { 4*(REG_XDREG0+4), "4*REG_XDREG4" },
2746 { 4*(REG_XDREG0+6), "4*REG_XDREG6" },
2747 { 4*(REG_XDREG0+8), "4*REG_XDREG8" },
2748 { 4*(REG_XDREG0+10), "4*REG_XDREG10" },
2749 { 4*(REG_XDREG0+12), "4*REG_XDREG12" },
2750 { 4*REG_XDREG14, "4*REG_XDREG14" },
Roland McGrathc0f8bbd2003-08-21 09:58:00 +00002751#endif
Wichert Akkermanccef6372002-05-01 16:39:22 +00002752 { 4*REG_FPSCR, "4*REG_FPSCR" },
2753#endif /* SH */
Roland McGrathf5a47772003-06-26 22:40:42 +00002754#ifdef SH64
Roland McGrathe1e584b2003-06-02 19:18:58 +00002755 { 0, "PC(L)" },
2756 { 4, "PC(U)" },
2757 { 8, "SR(L)" },
2758 { 12, "SR(U)" },
2759 { 16, "syscall no.(L)" },
2760 { 20, "syscall_no.(U)" },
2761 { 24, "R0(L)" },
2762 { 28, "R0(U)" },
2763 { 32, "R1(L)" },
2764 { 36, "R1(U)" },
2765 { 40, "R2(L)" },
2766 { 44, "R2(U)" },
2767 { 48, "R3(L)" },
2768 { 52, "R3(U)" },
2769 { 56, "R4(L)" },
2770 { 60, "R4(U)" },
2771 { 64, "R5(L)" },
2772 { 68, "R5(U)" },
2773 { 72, "R6(L)" },
2774 { 76, "R6(U)" },
2775 { 80, "R7(L)" },
2776 { 84, "R7(U)" },
2777 { 88, "R8(L)" },
2778 { 92, "R8(U)" },
2779 { 96, "R9(L)" },
2780 { 100, "R9(U)" },
2781 { 104, "R10(L)" },
2782 { 108, "R10(U)" },
2783 { 112, "R11(L)" },
2784 { 116, "R11(U)" },
2785 { 120, "R12(L)" },
2786 { 124, "R12(U)" },
2787 { 128, "R13(L)" },
2788 { 132, "R13(U)" },
2789 { 136, "R14(L)" },
2790 { 140, "R14(U)" },
2791 { 144, "R15(L)" },
2792 { 148, "R15(U)" },
2793 { 152, "R16(L)" },
2794 { 156, "R16(U)" },
2795 { 160, "R17(L)" },
2796 { 164, "R17(U)" },
2797 { 168, "R18(L)" },
2798 { 172, "R18(U)" },
2799 { 176, "R19(L)" },
2800 { 180, "R19(U)" },
2801 { 184, "R20(L)" },
2802 { 188, "R20(U)" },
2803 { 192, "R21(L)" },
2804 { 196, "R21(U)" },
2805 { 200, "R22(L)" },
2806 { 204, "R22(U)" },
2807 { 208, "R23(L)" },
2808 { 212, "R23(U)" },
2809 { 216, "R24(L)" },
2810 { 220, "R24(U)" },
2811 { 224, "R25(L)" },
2812 { 228, "R25(U)" },
2813 { 232, "R26(L)" },
2814 { 236, "R26(U)" },
2815 { 240, "R27(L)" },
2816 { 244, "R27(U)" },
2817 { 248, "R28(L)" },
2818 { 252, "R28(U)" },
2819 { 256, "R29(L)" },
2820 { 260, "R29(U)" },
2821 { 264, "R30(L)" },
2822 { 268, "R30(U)" },
2823 { 272, "R31(L)" },
2824 { 276, "R31(U)" },
2825 { 280, "R32(L)" },
2826 { 284, "R32(U)" },
2827 { 288, "R33(L)" },
2828 { 292, "R33(U)" },
2829 { 296, "R34(L)" },
2830 { 300, "R34(U)" },
2831 { 304, "R35(L)" },
2832 { 308, "R35(U)" },
2833 { 312, "R36(L)" },
2834 { 316, "R36(U)" },
2835 { 320, "R37(L)" },
2836 { 324, "R37(U)" },
2837 { 328, "R38(L)" },
2838 { 332, "R38(U)" },
2839 { 336, "R39(L)" },
2840 { 340, "R39(U)" },
2841 { 344, "R40(L)" },
2842 { 348, "R40(U)" },
2843 { 352, "R41(L)" },
2844 { 356, "R41(U)" },
2845 { 360, "R42(L)" },
2846 { 364, "R42(U)" },
2847 { 368, "R43(L)" },
2848 { 372, "R43(U)" },
2849 { 376, "R44(L)" },
2850 { 380, "R44(U)" },
2851 { 384, "R45(L)" },
2852 { 388, "R45(U)" },
2853 { 392, "R46(L)" },
2854 { 396, "R46(U)" },
2855 { 400, "R47(L)" },
2856 { 404, "R47(U)" },
2857 { 408, "R48(L)" },
2858 { 412, "R48(U)" },
2859 { 416, "R49(L)" },
2860 { 420, "R49(U)" },
2861 { 424, "R50(L)" },
2862 { 428, "R50(U)" },
2863 { 432, "R51(L)" },
2864 { 436, "R51(U)" },
2865 { 440, "R52(L)" },
2866 { 444, "R52(U)" },
2867 { 448, "R53(L)" },
2868 { 452, "R53(U)" },
2869 { 456, "R54(L)" },
2870 { 460, "R54(U)" },
2871 { 464, "R55(L)" },
2872 { 468, "R55(U)" },
2873 { 472, "R56(L)" },
2874 { 476, "R56(U)" },
2875 { 480, "R57(L)" },
2876 { 484, "R57(U)" },
2877 { 488, "R58(L)" },
2878 { 492, "R58(U)" },
2879 { 496, "R59(L)" },
2880 { 500, "R59(U)" },
2881 { 504, "R60(L)" },
2882 { 508, "R60(U)" },
2883 { 512, "R61(L)" },
2884 { 516, "R61(U)" },
2885 { 520, "R62(L)" },
2886 { 524, "R62(U)" },
2887 { 528, "TR0(L)" },
2888 { 532, "TR0(U)" },
2889 { 536, "TR1(L)" },
2890 { 540, "TR1(U)" },
2891 { 544, "TR2(L)" },
2892 { 548, "TR2(U)" },
2893 { 552, "TR3(L)" },
2894 { 556, "TR3(U)" },
2895 { 560, "TR4(L)" },
2896 { 564, "TR4(U)" },
2897 { 568, "TR5(L)" },
2898 { 572, "TR5(U)" },
2899 { 576, "TR6(L)" },
2900 { 580, "TR6(U)" },
2901 { 584, "TR7(L)" },
2902 { 588, "TR7(U)" },
2903 /* This entry is in case pt_regs contains dregs (depends on
2904 the kernel build options). */
2905 { uoff(regs), "offsetof(struct user, regs)" },
2906 { uoff(fpu), "offsetof(struct user, fpu)" },
2907#endif
Roland McGrath0f87c492003-06-03 23:29:04 +00002908#ifdef ARM
2909 { uoff(regs.ARM_r0), "r0" },
2910 { uoff(regs.ARM_r1), "r1" },
2911 { uoff(regs.ARM_r2), "r2" },
2912 { uoff(regs.ARM_r3), "r3" },
2913 { uoff(regs.ARM_r4), "r4" },
2914 { uoff(regs.ARM_r5), "r5" },
2915 { uoff(regs.ARM_r6), "r6" },
2916 { uoff(regs.ARM_r7), "r7" },
2917 { uoff(regs.ARM_r8), "r8" },
2918 { uoff(regs.ARM_r9), "r9" },
2919 { uoff(regs.ARM_r10), "r10" },
2920 { uoff(regs.ARM_fp), "fp" },
2921 { uoff(regs.ARM_ip), "ip" },
2922 { uoff(regs.ARM_sp), "sp" },
2923 { uoff(regs.ARM_lr), "lr" },
2924 { uoff(regs.ARM_pc), "pc" },
2925 { uoff(regs.ARM_cpsr), "cpsr" },
2926#endif
Wichert Akkermanccef6372002-05-01 16:39:22 +00002927
Roland McGrath6d1a65c2004-07-12 07:44:08 +00002928#if !defined(S390) && !defined(S390X) && !defined(MIPS) && !defined(SPARC64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002929 { uoff(u_fpvalid), "offsetof(struct user, u_fpvalid)" },
Wichert Akkermanf90da011999-10-31 21:15:38 +00002930#endif
Michal Ludvig0e035502002-09-23 15:41:01 +00002931#if defined(I386) || defined(X86_64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002932 { uoff(i387), "offsetof(struct user, i387)" },
2933#else /* !I386 */
2934#ifdef M68K
2935 { uoff(m68kfp), "offsetof(struct user, m68kfp)" },
2936#endif /* M68K */
2937#endif /* !I386 */
2938 { uoff(u_tsize), "offsetof(struct user, u_tsize)" },
2939 { uoff(u_dsize), "offsetof(struct user, u_dsize)" },
2940 { uoff(u_ssize), "offsetof(struct user, u_ssize)" },
Roland McGrath6d1a65c2004-07-12 07:44:08 +00002941#if !defined(SPARC64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002942 { uoff(start_code), "offsetof(struct user, start_code)" },
Roland McGrath6d1a65c2004-07-12 07:44:08 +00002943#endif
Roland McGrathf5a47772003-06-26 22:40:42 +00002944#ifdef SH64
Roland McGrathe1e584b2003-06-02 19:18:58 +00002945 { uoff(start_data), "offsetof(struct user, start_data)" },
2946#endif
Roland McGrath6d1a65c2004-07-12 07:44:08 +00002947#if !defined(SPARC64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002948 { uoff(start_stack), "offsetof(struct user, start_stack)" },
Roland McGrath6d1a65c2004-07-12 07:44:08 +00002949#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002950 { uoff(signal), "offsetof(struct user, signal)" },
Roland McGrath6d1a65c2004-07-12 07:44:08 +00002951#if !defined(S390) && !defined(S390X) && !defined(MIPS) && !defined(SH) && !defined(SH64) && !defined(SPARC64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002952 { uoff(reserved), "offsetof(struct user, reserved)" },
Wichert Akkermanf90da011999-10-31 21:15:38 +00002953#endif
Roland McGrath6d1a65c2004-07-12 07:44:08 +00002954#if !defined(SPARC64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002955 { uoff(u_ar0), "offsetof(struct user, u_ar0)" },
Roland McGrath6d1a65c2004-07-12 07:44:08 +00002956#endif
2957#if !defined(ARM) && !defined(MIPS) && !defined(S390) && !defined(S390X) && !defined(SPARC64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002958 { uoff(u_fpstate), "offsetof(struct user, u_fpstate)" },
2959#endif
2960 { uoff(magic), "offsetof(struct user, magic)" },
2961 { uoff(u_comm), "offsetof(struct user, u_comm)" },
Michal Ludvig0e035502002-09-23 15:41:01 +00002962#if defined(I386) || defined(X86_64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002963 { uoff(u_debugreg), "offsetof(struct user, u_debugreg)" },
2964#endif /* I386 */
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00002965#endif /* !IA64 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002966#endif /* !ALPHA */
2967#endif /* !POWERPC/!SPARC */
2968#endif /* LINUX */
2969#ifdef SUNOS4
2970 { uoff(u_pcb), "offsetof(struct user, u_pcb)" },
2971 { uoff(u_procp), "offsetof(struct user, u_procp)" },
2972 { uoff(u_ar0), "offsetof(struct user, u_ar0)" },
2973 { uoff(u_comm[0]), "offsetof(struct user, u_comm[0])" },
2974 { uoff(u_arg[0]), "offsetof(struct user, u_arg[0])" },
2975 { uoff(u_ap), "offsetof(struct user, u_ap)" },
2976 { uoff(u_qsave), "offsetof(struct user, u_qsave)" },
2977 { uoff(u_rval1), "offsetof(struct user, u_rval1)" },
2978 { uoff(u_rval2), "offsetof(struct user, u_rval2)" },
2979 { uoff(u_error), "offsetof(struct user, u_error)" },
2980 { uoff(u_eosys), "offsetof(struct user, u_eosys)" },
2981 { uoff(u_ssave), "offsetof(struct user, u_ssave)" },
2982 { uoff(u_signal[0]), "offsetof(struct user, u_signal)" },
2983 { uoff(u_sigmask[0]), "offsetof(struct user, u_sigmask)" },
2984 { uoff(u_sigonstack), "offsetof(struct user, u_sigonstack)" },
2985 { uoff(u_sigintr), "offsetof(struct user, u_sigintr)" },
2986 { uoff(u_sigreset), "offsetof(struct user, u_sigreset)" },
2987 { uoff(u_oldmask), "offsetof(struct user, u_oldmask)" },
2988 { uoff(u_code), "offsetof(struct user, u_code)" },
2989 { uoff(u_addr), "offsetof(struct user, u_addr)" },
2990 { uoff(u_sigstack), "offsetof(struct user, u_sigstack)" },
2991 { uoff(u_ofile), "offsetof(struct user, u_ofile)" },
2992 { uoff(u_pofile), "offsetof(struct user, u_pofile)" },
2993 { uoff(u_ofile_arr[0]), "offsetof(struct user, u_ofile_arr[0])" },
2994 { uoff(u_pofile_arr[0]),"offsetof(struct user, u_pofile_arr[0])"},
2995 { uoff(u_lastfile), "offsetof(struct user, u_lastfile)" },
2996 { uoff(u_cwd), "offsetof(struct user, u_cwd)" },
2997 { uoff(u_cdir), "offsetof(struct user, u_cdir)" },
2998 { uoff(u_rdir), "offsetof(struct user, u_rdir)" },
2999 { uoff(u_cmask), "offsetof(struct user, u_cmask)" },
3000 { uoff(u_ru), "offsetof(struct user, u_ru)" },
3001 { uoff(u_cru), "offsetof(struct user, u_cru)" },
3002 { uoff(u_timer[0]), "offsetof(struct user, u_timer[0])" },
3003 { uoff(u_XXX[0]), "offsetof(struct user, u_XXX[0])" },
3004 { uoff(u_ioch), "offsetof(struct user, u_ioch)" },
3005 { uoff(u_start), "offsetof(struct user, u_start)" },
3006 { uoff(u_acflag), "offsetof(struct user, u_acflag)" },
3007 { uoff(u_prof.pr_base), "offsetof(struct user, u_prof.pr_base)" },
3008 { uoff(u_prof.pr_size), "offsetof(struct user, u_prof.pr_size)" },
3009 { uoff(u_prof.pr_off), "offsetof(struct user, u_prof.pr_off)" },
3010 { uoff(u_prof.pr_scale),"offsetof(struct user, u_prof.pr_scale)"},
3011 { uoff(u_rlimit[0]), "offsetof(struct user, u_rlimit)" },
3012 { uoff(u_exdata.Ux_A), "offsetof(struct user, u_exdata.Ux_A)" },
3013 { uoff(u_exdata.ux_shell[0]),"offsetof(struct user, u_exdata.ux_shell[0])"},
3014 { uoff(u_lofault), "offsetof(struct user, u_lofault)" },
3015#endif /* SUNOS4 */
Wichert Akkermanc1652e22001-03-27 12:17:16 +00003016#ifndef HPPA
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003017 { sizeof(struct user), "sizeof(struct user)" },
Wichert Akkermanc1652e22001-03-27 12:17:16 +00003018#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003019 { 0, NULL },
3020};
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00003021#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003022
3023int
3024sys_ptrace(tcp)
3025struct tcb *tcp;
3026{
Roland McGrathd9f816f2004-09-04 03:39:20 +00003027 const struct xlat *x;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003028 long addr;
3029
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003030 if (entering(tcp)) {
Roland McGrathbf621d42003-01-14 09:46:21 +00003031 printxval(ptrace_cmds, tcp->u_arg[0],
3032#ifndef FREEBSD
3033 "PTRACE_???"
3034#else
3035 "PT_???"
3036#endif
3037 );
3038 tprintf(", %lu, ", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003039 addr = tcp->u_arg[2];
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00003040#ifndef FREEBSD
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003041 if (tcp->u_arg[0] == PTRACE_PEEKUSER
3042 || tcp->u_arg[0] == PTRACE_POKEUSER) {
3043 for (x = struct_user_offsets; x->str; x++) {
3044 if (x->val >= addr)
3045 break;
3046 }
3047 if (!x->str)
3048 tprintf("%#lx, ", addr);
3049 else if (x->val > addr && x != struct_user_offsets) {
3050 x--;
3051 tprintf("%s + %ld, ", x->str, addr - x->val);
3052 }
3053 else
3054 tprintf("%s, ", x->str);
3055 }
3056 else
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00003057#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003058 tprintf("%#lx, ", tcp->u_arg[2]);
3059#ifdef LINUX
3060 switch (tcp->u_arg[0]) {
Roland McGrath1e868062007-11-19 22:11:45 +00003061#ifndef IA64
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003062 case PTRACE_PEEKDATA:
3063 case PTRACE_PEEKTEXT:
3064 case PTRACE_PEEKUSER:
3065 break;
Roland McGrath1e868062007-11-19 22:11:45 +00003066#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003067 case PTRACE_CONT:
3068 case PTRACE_SINGLESTEP:
3069 case PTRACE_SYSCALL:
3070 case PTRACE_DETACH:
3071 printsignal(tcp->u_arg[3]);
3072 break;
3073 default:
3074 tprintf("%#lx", tcp->u_arg[3]);
3075 break;
3076 }
3077 } else {
3078 switch (tcp->u_arg[0]) {
3079 case PTRACE_PEEKDATA:
3080 case PTRACE_PEEKTEXT:
3081 case PTRACE_PEEKUSER:
Roland McGrath1e868062007-11-19 22:11:45 +00003082#ifdef IA64
3083 return RVAL_HEX;
3084#else
Roland McGratheb285352003-01-14 09:59:00 +00003085 printnum(tcp, tcp->u_arg[3], "%#lx");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003086 break;
Roland McGrath1e868062007-11-19 22:11:45 +00003087#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003088 }
3089 }
3090#endif /* LINUX */
3091#ifdef SUNOS4
3092 if (tcp->u_arg[0] == PTRACE_WRITEDATA ||
3093 tcp->u_arg[0] == PTRACE_WRITETEXT) {
3094 tprintf("%lu, ", tcp->u_arg[3]);
3095 printstr(tcp, tcp->u_arg[4], tcp->u_arg[3]);
3096 } else if (tcp->u_arg[0] != PTRACE_READDATA &&
3097 tcp->u_arg[0] != PTRACE_READTEXT) {
3098 tprintf("%#lx", tcp->u_arg[3]);
3099 }
3100 } else {
3101 if (tcp->u_arg[0] == PTRACE_READDATA ||
3102 tcp->u_arg[0] == PTRACE_READTEXT) {
3103 tprintf("%lu, ", tcp->u_arg[3]);
3104 printstr(tcp, tcp->u_arg[4], tcp->u_arg[3]);
3105 }
3106 }
3107#endif /* SUNOS4 */
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00003108#ifdef FREEBSD
3109 tprintf("%lu", tcp->u_arg[3]);
3110 }
3111#endif /* FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003112 return 0;
3113}
3114
3115#endif /* !SVR4 */
Roland McGrath5a223472002-12-15 23:58:26 +00003116
3117#ifdef LINUX
Roland McGrath51942a92007-07-05 18:59:11 +00003118# ifndef FUTEX_CMP_REQUEUE
3119# define FUTEX_CMP_REQUEUE 4
3120# endif
3121# ifndef FUTEX_WAKE_OP
3122# define FUTEX_WAKE_OP 5
3123# endif
3124# ifndef FUTEX_LOCK_PI
3125# define FUTEX_LOCK_PI 6
3126# define FUTEX_UNLOCK_PI 7
3127# define FUTEX_TRYLOCK_PI 8
3128# endif
3129# ifndef FUTEX_CMP_REQUEUE_PI
3130# define FUTEX_CMP_REQUEUE_PI 9
3131# endif
3132# ifndef FUTEX_PRIVATE_FLAG
3133# define FUTEX_PRIVATE_FLAG 128
3134# endif
Roland McGrathd9f816f2004-09-04 03:39:20 +00003135static const struct xlat futexops[] = {
Roland McGrath51942a92007-07-05 18:59:11 +00003136 { FUTEX_WAIT, "FUTEX_WAIT" },
3137 { FUTEX_WAKE, "FUTEX_WAKE" },
3138 { FUTEX_FD, "FUTEX_FD" },
3139 { FUTEX_REQUEUE, "FUTEX_REQUEUE" },
3140 { FUTEX_CMP_REQUEUE, "FUTEX_CMP_REQUEUE" },
3141 { FUTEX_WAKE_OP, "FUTEX_WAKE_OP" },
3142 { FUTEX_LOCK_PI, "FUTEX_LOCK_PI" },
3143 { FUTEX_UNLOCK_PI, "FUTEX_UNLOCK_PI" },
3144 { FUTEX_TRYLOCK_PI, "FUTEX_TRYLOCK_PI" },
3145 { FUTEX_CMP_REQUEUE_PI, "FUTEX_CMP_REQUEUE_PI" },
3146 { FUTEX_WAIT|FUTEX_PRIVATE_FLAG, "FUTEX_WAIT_PRIVATE" },
3147 { FUTEX_WAKE|FUTEX_PRIVATE_FLAG, "FUTEX_WAKE_PRIVATE" },
3148 { FUTEX_FD|FUTEX_PRIVATE_FLAG, "FUTEX_FD_PRIVATE" },
3149 { FUTEX_REQUEUE|FUTEX_PRIVATE_FLAG, "FUTEX_REQUEUE_PRIVATE" },
3150 { FUTEX_CMP_REQUEUE|FUTEX_PRIVATE_FLAG, "FUTEX_CMP_REQUEUE_PRIVATE" },
3151 { FUTEX_WAKE_OP|FUTEX_PRIVATE_FLAG, "FUTEX_WAKE_OP_PRIVATE" },
3152 { FUTEX_LOCK_PI|FUTEX_PRIVATE_FLAG, "FUTEX_LOCK_PI_PRIVATE" },
3153 { FUTEX_UNLOCK_PI|FUTEX_PRIVATE_FLAG, "FUTEX_UNLOCK_PI_PRIVATE" },
3154 { FUTEX_TRYLOCK_PI|FUTEX_PRIVATE_FLAG, "FUTEX_TRYLOCK_PI_PRIVATE" },
3155 { FUTEX_CMP_REQUEUE_PI|FUTEX_PRIVATE_FLAG, "FUTEX_CMP_REQUEUE_PI_PRIVATE" },
3156 { 0, NULL }
3157};
3158#ifndef FUTEX_OP_SET
3159# define FUTEX_OP_SET 0
3160# define FUTEX_OP_ADD 1
3161# define FUTEX_OP_OR 2
3162# define FUTEX_OP_ANDN 3
3163# define FUTEX_OP_XOR 4
3164# define FUTEX_OP_CMP_EQ 0
3165# define FUTEX_OP_CMP_NE 1
3166# define FUTEX_OP_CMP_LT 2
3167# define FUTEX_OP_CMP_LE 3
3168# define FUTEX_OP_CMP_GT 4
3169# define FUTEX_OP_CMP_GE 5
3170#endif
3171static const struct xlat futexwakeops[] = {
3172 { FUTEX_OP_SET, "FUTEX_OP_SET" },
3173 { FUTEX_OP_ADD, "FUTEX_OP_ADD" },
3174 { FUTEX_OP_OR, "FUTEX_OP_OR" },
3175 { FUTEX_OP_ANDN, "FUTEX_OP_ANDN" },
3176 { FUTEX_OP_XOR, "FUTEX_OP_XOR" },
3177 { 0, NULL }
3178};
3179static const struct xlat futexwakecmps[] = {
3180 { FUTEX_OP_CMP_EQ, "FUTEX_OP_CMP_EQ" },
3181 { FUTEX_OP_CMP_NE, "FUTEX_OP_CMP_NE" },
3182 { FUTEX_OP_CMP_LT, "FUTEX_OP_CMP_LT" },
3183 { FUTEX_OP_CMP_LE, "FUTEX_OP_CMP_LE" },
3184 { FUTEX_OP_CMP_GT, "FUTEX_OP_CMP_GT" },
3185 { FUTEX_OP_CMP_GE, "FUTEX_OP_CMP_GE" },
3186 { 0, NULL }
Roland McGrath5a223472002-12-15 23:58:26 +00003187};
3188
3189int
3190sys_futex(tcp)
3191struct tcb *tcp;
3192{
3193 if (entering(tcp)) {
Roland McGrath51942a92007-07-05 18:59:11 +00003194 long int cmd = tcp->u_arg[1] & ~FUTEX_PRIVATE_FLAG;
Roland McGrath5a223472002-12-15 23:58:26 +00003195 tprintf("%p, ", (void *) tcp->u_arg[0]);
Roland McGrath88812d62003-06-26 22:27:23 +00003196 printxval(futexops, tcp->u_arg[1], "FUTEX_???");
Roland McGrath8dfa04a2003-03-05 04:07:55 +00003197 tprintf(", %ld", tcp->u_arg[2]);
Roland McGrath51942a92007-07-05 18:59:11 +00003198 if (cmd == FUTEX_WAIT) {
Roland McGrath8dfa04a2003-03-05 04:07:55 +00003199 tprintf(", ");
3200 printtv(tcp, tcp->u_arg[3]);
Roland McGrath51942a92007-07-05 18:59:11 +00003201 } else if (cmd == FUTEX_REQUEUE)
Roland McGrath88812d62003-06-26 22:27:23 +00003202 tprintf(", %ld, %p", tcp->u_arg[3], (void *) tcp->u_arg[4]);
Roland McGrath51942a92007-07-05 18:59:11 +00003203 else if (cmd == FUTEX_CMP_REQUEUE)
3204 tprintf(", %ld, %p, %ld", tcp->u_arg[3], (void *) tcp->u_arg[4], tcp->u_arg[5]);
3205 else if (cmd == FUTEX_WAKE_OP) {
3206 tprintf(", %ld, %p, {", tcp->u_arg[3], (void *) tcp->u_arg[4]);
3207 if ((tcp->u_arg[5] >> 28) & 8)
3208 tprintf("FUTEX_OP_OPARG_SHIFT|");
3209 printxval(futexwakeops, (tcp->u_arg[5] >> 28) & 0x7, "FUTEX_OP_???");
3210 tprintf(", %ld, ", (tcp->u_arg[5] >> 12) & 0xfff);
3211 if ((tcp->u_arg[5] >> 24) & 8)
3212 tprintf("FUTEX_OP_OPARG_SHIFT|");
3213 printxval(futexwakecmps, (tcp->u_arg[5] >> 24) & 0x7, "FUTEX_OP_CMP_???");
3214 tprintf(", %ld}", tcp->u_arg[5] & 0xfff);
3215 }
Roland McGrath5a223472002-12-15 23:58:26 +00003216 }
3217 return 0;
3218}
3219
3220static void
Roland McGrath79fbda52004-04-14 02:45:55 +00003221print_affinitylist(tcp, list, len)
3222struct tcb *tcp;
3223long list;
Roland McGrath5a223472002-12-15 23:58:26 +00003224unsigned int len;
3225{
3226 int first = 1;
3227 tprintf(" {");
Roland McGratha2f34962003-05-23 00:14:04 +00003228 while (len >= sizeof (unsigned long)) {
Roland McGrath79fbda52004-04-14 02:45:55 +00003229 unsigned long w;
3230 umove(tcp, list, &w);
3231 tprintf("%s %lx", first ? "" : ",", w);
Roland McGrath5a223472002-12-15 23:58:26 +00003232 first = 0;
3233 len -= sizeof (unsigned long);
Roland McGrath79fbda52004-04-14 02:45:55 +00003234 list += sizeof(unsigned long);
Roland McGrath5a223472002-12-15 23:58:26 +00003235 }
3236 tprintf(" }");
3237}
3238
3239int
3240sys_sched_setaffinity(tcp)
3241struct tcb *tcp;
3242{
3243 if (entering(tcp)) {
3244 tprintf("%ld, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
Roland McGrath79fbda52004-04-14 02:45:55 +00003245 print_affinitylist(tcp, tcp->u_arg[2], tcp->u_arg[1]);
Roland McGrath5a223472002-12-15 23:58:26 +00003246 }
3247 return 0;
3248}
3249
3250int
3251sys_sched_getaffinity(tcp)
3252struct tcb *tcp;
3253{
3254 if (entering(tcp)) {
3255 tprintf("%ld, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
3256 } else {
Roland McGrath79fbda52004-04-14 02:45:55 +00003257 if (tcp->u_rval == -1)
3258 tprintf("%#lx", tcp->u_arg[2]);
3259 else
3260 print_affinitylist(tcp, tcp->u_arg[2], tcp->u_rval);
Roland McGrath5a223472002-12-15 23:58:26 +00003261 }
3262 return 0;
3263}
Roland McGrath279d3782004-03-01 20:27:37 +00003264
Roland McGrathd9f816f2004-09-04 03:39:20 +00003265static const struct xlat schedulers[] = {
Roland McGrath279d3782004-03-01 20:27:37 +00003266 { SCHED_OTHER, "SCHED_OTHER" },
3267 { SCHED_RR, "SCHED_RR" },
3268 { SCHED_FIFO, "SCHED_FIFO" },
3269 { 0, NULL }
3270};
3271
3272int
3273sys_sched_getscheduler(tcp)
3274struct tcb *tcp;
3275{
3276 if (entering(tcp)) {
3277 tprintf("%d", (int) tcp->u_arg[0]);
3278 } else if (! syserror(tcp)) {
3279 tcp->auxstr = xlookup (schedulers, tcp->u_rval);
3280 if (tcp->auxstr != NULL)
3281 return RVAL_STR;
3282 }
3283 return 0;
3284}
3285
3286int
3287sys_sched_setscheduler(tcp)
3288struct tcb *tcp;
3289{
3290 if (entering(tcp)) {
3291 struct sched_param p;
3292 tprintf("%d, ", (int) tcp->u_arg[0]);
3293 printxval(schedulers, tcp->u_arg[1], "SCHED_???");
3294 if (umove(tcp, tcp->u_arg[2], &p) < 0)
Roland McGrathc2d5eb02005-02-02 04:16:56 +00003295 tprintf(", %#lx", tcp->u_arg[2]);
Roland McGrath279d3782004-03-01 20:27:37 +00003296 else
3297 tprintf(", { %d }", p.__sched_priority);
3298 }
3299 return 0;
3300}
3301
3302int
3303sys_sched_getparam(tcp)
3304struct tcb *tcp;
3305{
3306 if (entering(tcp)) {
3307 tprintf("%d, ", (int) tcp->u_arg[0]);
3308 } else {
3309 struct sched_param p;
3310 if (umove(tcp, tcp->u_arg[1], &p) < 0)
Roland McGrathc2d5eb02005-02-02 04:16:56 +00003311 tprintf("%#lx", tcp->u_arg[1]);
Roland McGrath279d3782004-03-01 20:27:37 +00003312 else
3313 tprintf("{ %d }", p.__sched_priority);
3314 }
3315 return 0;
3316}
3317
3318int
3319sys_sched_setparam(tcp)
3320struct tcb *tcp;
3321{
3322 if (entering(tcp)) {
3323 struct sched_param p;
3324 if (umove(tcp, tcp->u_arg[1], &p) < 0)
Roland McGrathc2d5eb02005-02-02 04:16:56 +00003325 tprintf("%d, %#lx", (int) tcp->u_arg[0], tcp->u_arg[1]);
Roland McGrath279d3782004-03-01 20:27:37 +00003326 else
3327 tprintf("%d, { %d }", (int) tcp->u_arg[0], p.__sched_priority);
3328 }
3329 return 0;
3330}
3331
3332int
3333sys_sched_get_priority_min(tcp)
3334struct tcb *tcp;
3335{
3336 if (entering(tcp)) {
3337 printxval(schedulers, tcp->u_arg[0], "SCHED_???");
3338 }
3339 return 0;
3340}
Roland McGrathc2d5eb02005-02-02 04:16:56 +00003341
3342#ifdef X86_64
3343#include <asm/prctl.h>
3344
3345static const struct xlat archvals[] = {
3346 { ARCH_SET_GS, "ARCH_SET_GS" },
3347 { ARCH_SET_FS, "ARCH_SET_FS" },
3348 { ARCH_GET_FS, "ARCH_GET_FS" },
3349 { ARCH_GET_GS, "ARCH_GET_GS" },
3350 { 0, NULL },
3351};
3352
3353int
3354sys_arch_prctl(tcp)
3355struct tcb *tcp;
3356{
3357 if (entering(tcp)) {
3358 printxval(archvals, tcp->u_arg[0], "ARCH_???");
3359 if (tcp->u_arg[0] == ARCH_SET_GS
3360 || tcp->u_arg[0] == ARCH_SET_FS)
3361 tprintf(", %#lx", tcp->u_arg[1]);
3362 } else {
3363 if (tcp->u_arg[0] == ARCH_GET_GS
3364 || tcp->u_arg[0] == ARCH_GET_FS) {
3365 long int v;
3366 if (!syserror(tcp) && umove(tcp, tcp->u_arg[1], &v) != -1)
3367 tprintf(", [%#lx]", v);
3368 else
3369 tprintf(", %#lx", tcp->u_arg[1]);
3370 }
3371 }
3372 return 0;
3373}
3374#endif
3375
Roland McGrathdb8319f2007-08-02 01:37:55 +00003376
3377int
3378sys_getcpu(tcp)
3379struct tcb *tcp;
3380{
3381 if (exiting(tcp)) {
3382 unsigned u;
3383 if (tcp->u_arg[0] == 0)
3384 tprintf("NULL, ");
3385 else if (umove(tcp, tcp->u_arg[0], &u) < 0)
3386 tprintf("%#lx, ", tcp->u_arg[0]);
3387 else
3388 tprintf("[%u], ", u);
3389 if (tcp->u_arg[1] == 0)
3390 tprintf("NULL, ");
3391 else if (umove(tcp, tcp->u_arg[1], &u) < 0)
3392 tprintf("%#lx, ", tcp->u_arg[1]);
3393 else
3394 tprintf("[%u], ", u);
3395 tprintf("%#lx", tcp->u_arg[2]);
3396 }
3397 return 0;
3398}
3399
Roland McGrath5a223472002-12-15 23:58:26 +00003400#endif