blob: c6cd61f1bf3be25a5b61e9bfa1aa449e324004da [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 Akkerman36915a11999-07-13 15:45:02 +000059#ifdef HAVE_SYS_REG_H
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000060# include <sys/reg.h>
Wichert Akkerman15dea971999-10-06 13:06:34 +000061#ifndef PTRACE_PEEKUSR
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000062# define PTRACE_PEEKUSR PTRACE_PEEKUSER
Wichert Akkerman15dea971999-10-06 13:06:34 +000063#endif
64#ifndef PTRACE_POKEUSR
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000065# define PTRACE_POKEUSR PTRACE_POKEUSER
66#endif
Wichert Akkerman15dea971999-10-06 13:06:34 +000067#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000068
Roland McGrath5bd7cf82003-01-24 04:31:18 +000069#ifdef HAVE_LINUX_PTRACE_H
70#undef PTRACE_SYSCALL
Roland McGrathfb1bc072004-03-01 21:29:24 +000071# ifdef HAVE_STRUCT_IA64_FPREG
72# define ia64_fpreg XXX_ia64_fpreg
73# endif
74# ifdef HAVE_STRUCT_PT_ALL_USER_REGS
75# define pt_all_user_regs XXX_pt_all_user_regs
76# endif
Roland McGrath5bd7cf82003-01-24 04:31:18 +000077#include <linux/ptrace.h>
Roland McGrathfb1bc072004-03-01 21:29:24 +000078# undef ia64_fpreg
79# undef pt_all_user_regs
Roland McGrath5bd7cf82003-01-24 04:31:18 +000080#endif
81
Roland McGrath6d1a65c2004-07-12 07:44:08 +000082#if defined (LINUX) && defined (SPARC64)
83# define r_pc r_tpc
84# undef PTRACE_GETREGS
85# define PTRACE_GETREGS PTRACE_GETREGS64
86# undef PTRACE_SETREGS
87# define PTRACE_SETREGS PTRACE_SETREGS64
88#endif /* LINUX && SPARC64 */
89
Roland McGrath5a223472002-12-15 23:58:26 +000090#ifdef HAVE_LINUX_FUTEX_H
Dmitry V. Levine5e60852009-12-31 22:50:49 +000091# include <linux/futex.h>
Roland McGrath5a223472002-12-15 23:58:26 +000092#endif
Dmitry V. Levine5e60852009-12-31 22:50:49 +000093#ifdef LINUX
Roland McGrath5a223472002-12-15 23:58:26 +000094# ifndef FUTEX_WAIT
95# define FUTEX_WAIT 0
96# endif
97# ifndef FUTEX_WAKE
98# define FUTEX_WAKE 1
99# endif
100# ifndef FUTEX_FD
101# define FUTEX_FD 2
102# endif
Roland McGrath88812d62003-06-26 22:27:23 +0000103# ifndef FUTEX_REQUEUE
104# define FUTEX_REQUEUE 3
105# endif
Dmitry V. Levine5e60852009-12-31 22:50:49 +0000106#endif /* LINUX */
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000107
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000108#ifdef LINUX
Roland McGrath279d3782004-03-01 20:27:37 +0000109#include <sched.h>
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000110#include <asm/posix_types.h>
111#undef GETGROUPS_T
112#define GETGROUPS_T __kernel_gid_t
Roland McGrath83bd47a2003-11-13 22:32:26 +0000113#undef GETGROUPS32_T
114#define GETGROUPS32_T __kernel_gid32_t
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000115#endif /* LINUX */
116
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000117#if defined(LINUX) && defined(IA64)
118# include <asm/ptrace_offsets.h>
119# include <asm/rse.h>
120#endif
121
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000122#ifdef HAVE_PRCTL
Dmitry V. Levine5e60852009-12-31 22:50:49 +0000123# include <sys/prctl.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000124
Roland McGrathd9f816f2004-09-04 03:39:20 +0000125static const struct xlat prctl_options[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000126#ifdef PR_MAXPROCS
127 { PR_MAXPROCS, "PR_MAXPROCS" },
128#endif
129#ifdef PR_ISBLOCKED
130 { PR_ISBLOCKED, "PR_ISBLOCKED" },
131#endif
132#ifdef PR_SETSTACKSIZE
133 { PR_SETSTACKSIZE, "PR_SETSTACKSIZE" },
134#endif
135#ifdef PR_GETSTACKSIZE
136 { PR_GETSTACKSIZE, "PR_GETSTACKSIZE" },
137#endif
138#ifdef PR_MAXPPROCS
139 { PR_MAXPPROCS, "PR_MAXPPROCS" },
140#endif
141#ifdef PR_UNBLKONEXEC
142 { PR_UNBLKONEXEC, "PR_UNBLKONEXEC" },
143#endif
144#ifdef PR_ATOMICSIM
145 { PR_ATOMICSIM, "PR_ATOMICSIM" },
146#endif
147#ifdef PR_SETEXITSIG
148 { PR_SETEXITSIG, "PR_SETEXITSIG" },
149#endif
150#ifdef PR_RESIDENT
151 { PR_RESIDENT, "PR_RESIDENT" },
152#endif
153#ifdef PR_ATTACHADDR
154 { PR_ATTACHADDR, "PR_ATTACHADDR" },
155#endif
156#ifdef PR_DETACHADDR
157 { PR_DETACHADDR, "PR_DETACHADDR" },
158#endif
159#ifdef PR_TERMCHILD
160 { PR_TERMCHILD, "PR_TERMCHILD" },
161#endif
162#ifdef PR_GETSHMASK
163 { PR_GETSHMASK, "PR_GETSHMASK" },
164#endif
165#ifdef PR_GETNSHARE
166 { PR_GETNSHARE, "PR_GETNSHARE" },
167#endif
Wichert Akkerman8829a551999-06-11 13:18:40 +0000168#ifdef PR_COREPID
169 { PR_COREPID, "PR_COREPID" },
170#endif
171#ifdef PR_ATTACHADDRPERM
172 { PR_ATTACHADDRPERM, "PR_ATTACHADDRPERM" },
173#endif
174#ifdef PR_PTHREADEXIT
175 { PR_PTHREADEXIT, "PR_PTHREADEXIT" },
176#endif
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000177#ifdef PR_SET_PDEATHSIG
178 { PR_SET_PDEATHSIG, "PR_SET_PDEATHSIG" },
179#endif
180#ifdef PR_GET_PDEATHSIG
181 { PR_GET_PDEATHSIG, "PR_GET_PDEATHSIG" },
182#endif
Dmitry V. Levinf02cf212008-09-03 00:54:40 +0000183#ifdef PR_GET_DUMPABLE
184 { PR_GET_DUMPABLE, "PR_GET_DUMPABLE" },
185#endif
186#ifdef PR_SET_DUMPABLE
187 { PR_SET_DUMPABLE, "PR_SET_DUMPABLE" },
188#endif
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000189#ifdef PR_GET_UNALIGN
190 { PR_GET_UNALIGN, "PR_GET_UNALIGN" },
191#endif
192#ifdef PR_SET_UNALIGN
193 { PR_SET_UNALIGN, "PR_SET_UNALIGN" },
194#endif
195#ifdef PR_GET_KEEPCAPS
Dmitry V. Levin8dd31dd2008-11-11 00:25:22 +0000196 { PR_GET_KEEPCAPS, "PR_GET_KEEPCAPS" },
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000197#endif
198#ifdef PR_SET_KEEPCAPS
Dmitry V. Levin8dd31dd2008-11-11 00:25:22 +0000199 { PR_SET_KEEPCAPS, "PR_SET_KEEPCAPS" },
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000200#endif
Roland McGrathe5039fb2007-11-03 23:58:07 +0000201#ifdef PR_GET_FPEMU
202 { PR_GET_FPEMU, "PR_GET_FPEMU" },
203#endif
204#ifdef PR_SET_FPEMU
205 { PR_SET_FPEMU, "PR_SET_FPEMU" },
206#endif
207#ifdef PR_GET_FPEXC
208 { PR_GET_FPEXC, "PR_GET_FPEXC" },
209#endif
210#ifdef PR_SET_FPEXC
211 { PR_SET_FPEXC, "PR_SET_FPEXC" },
212#endif
213#ifdef PR_GET_TIMING
214 { PR_GET_TIMING, "PR_GET_TIMING" },
215#endif
216#ifdef PR_SET_TIMING
217 { PR_SET_TIMING, "PR_SET_TIMING" },
218#endif
219#ifdef PR_SET_NAME
220 { PR_SET_NAME, "PR_SET_NAME" },
221#endif
222#ifdef PR_GET_NAME
223 { PR_GET_NAME, "PR_GET_NAME" },
224#endif
225#ifdef PR_GET_ENDIAN
226 { PR_GET_ENDIAN, "PR_GET_ENDIAN" },
227#endif
228#ifdef PR_SET_ENDIAN
229 { PR_SET_ENDIAN, "PR_SET_ENDIAN" },
230#endif
231#ifdef PR_GET_SECCOMP
232 { PR_GET_SECCOMP, "PR_GET_SECCOMP" },
233#endif
234#ifdef PR_SET_SECCOMP
235 { PR_SET_SECCOMP, "PR_SET_SECCOMP" },
236#endif
Dmitry V. Levin8dd31dd2008-11-11 00:25:22 +0000237#ifdef PR_GET_TSC
238 { PR_GET_TSC, "PR_GET_TSC" },
239#endif
240#ifdef PR_SET_TSC
241 { PR_SET_TSC, "PR_SET_TSC" },
242#endif
243#ifdef PR_GET_SECUREBITS
244 { PR_GET_SECUREBITS, "PR_GET_SECUREBITS" },
245#endif
246#ifdef PR_SET_SECUREBITS
247 { PR_SET_SECUREBITS, "PR_SET_SECUREBITS" },
248#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000249 { 0, NULL },
250};
251
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000252
Roland McGratha4d48532005-06-08 20:45:28 +0000253static const char *
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000254unalignctl_string (unsigned int ctl)
255{
256 static char buf[16];
257
258 switch (ctl) {
259#ifdef PR_UNALIGN_NOPRINT
260 case PR_UNALIGN_NOPRINT:
261 return "NOPRINT";
262#endif
263#ifdef PR_UNALIGN_SIGBUS
264 case PR_UNALIGN_SIGBUS:
265 return "SIGBUS";
266#endif
267 default:
268 break;
269 }
270 sprintf(buf, "%x", ctl);
271 return buf;
272}
273
274
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000275int
276sys_prctl(tcp)
277struct tcb *tcp;
278{
279 int i;
280
281 if (entering(tcp)) {
282 printxval(prctl_options, tcp->u_arg[0], "PR_???");
283 switch (tcp->u_arg[0]) {
284#ifdef PR_GETNSHARE
285 case PR_GETNSHARE:
286 break;
287#endif
Dmitry V. Levin50f60132008-09-03 00:56:52 +0000288#ifdef PR_SET_PDEATHSIG
289 case PR_SET_PDEATHSIG:
290 tprintf(", %lu", tcp->u_arg[1]);
291 break;
292#endif
293#ifdef PR_GET_PDEATHSIG
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000294 case PR_GET_PDEATHSIG:
295 break;
296#endif
Dmitry V. Levin50f60132008-09-03 00:56:52 +0000297#ifdef PR_SET_DUMPABLE
298 case PR_SET_DUMPABLE:
299 tprintf(", %lu", tcp->u_arg[1]);
300 break;
301#endif
302#ifdef PR_GET_DUMPABLE
303 case PR_GET_DUMPABLE:
304 break;
305#endif
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000306#ifdef PR_SET_UNALIGN
307 case PR_SET_UNALIGN:
308 tprintf(", %s", unalignctl_string(tcp->u_arg[1]));
309 break;
310#endif
311#ifdef PR_GET_UNALIGN
312 case PR_GET_UNALIGN:
313 tprintf(", %#lx", tcp->u_arg[1]);
314 break;
315#endif
Dmitry V. Levin50f60132008-09-03 00:56:52 +0000316#ifdef PR_SET_KEEPCAPS
317 case PR_SET_KEEPCAPS:
318 tprintf(", %lu", tcp->u_arg[1]);
319 break;
320#endif
321#ifdef PR_GET_KEEPCAPS
322 case PR_GET_KEEPCAPS:
323 break;
324#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000325 default:
326 for (i = 1; i < tcp->u_nargs; i++)
327 tprintf(", %#lx", tcp->u_arg[i]);
328 break;
329 }
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000330 } else {
331 switch (tcp->u_arg[0]) {
332#ifdef PR_GET_PDEATHSIG
333 case PR_GET_PDEATHSIG:
Dmitry V. Levin50f60132008-09-03 00:56:52 +0000334 if (umove(tcp, tcp->u_arg[1], &i) < 0)
335 tprintf(", %#lx", tcp->u_arg[1]);
336 else
337 tprintf(", {%u}", i);
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000338 break;
339#endif
Dmitry V. Levin50f60132008-09-03 00:56:52 +0000340#ifdef PR_GET_DUMPABLE
341 case PR_GET_DUMPABLE:
342 return RVAL_UDECIMAL;
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000343#endif
344#ifdef PR_GET_UNALIGN
345 case PR_GET_UNALIGN:
Dmitry V. Levin50f60132008-09-03 00:56:52 +0000346 if (syserror(tcp) || umove(tcp, tcp->u_arg[1], &i) < 0)
347 break;
348 tcp->auxstr = unalignctl_string(i);
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000349 return RVAL_STR;
Dmitry V. Levin50f60132008-09-03 00:56:52 +0000350#endif
351#ifdef PR_GET_KEEPCAPS
352 case PR_GET_KEEPCAPS:
353 return RVAL_UDECIMAL;
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000354#endif
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000355 default:
356 break;
357 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000358 }
359 return 0;
360}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000361#endif /* HAVE_PRCTL */
362
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +0000363#if defined(FREEBSD) || defined(SUNOS4) || defined(SVR4)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000364int
365sys_gethostid(tcp)
366struct tcb *tcp;
367{
368 if (exiting(tcp))
369 return RVAL_HEX;
370 return 0;
371}
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +0000372#endif /* FREEBSD || SUNOS4 || SVR4 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000373
374int
375sys_sethostname(tcp)
376struct tcb *tcp;
377{
378 if (entering(tcp)) {
379 printpathn(tcp, tcp->u_arg[0], tcp->u_arg[1]);
380 tprintf(", %lu", tcp->u_arg[1]);
381 }
382 return 0;
383}
384
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +0000385#if defined(ALPHA) || defined(FREEBSD) || defined(SUNOS4) || defined(SVR4)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000386int
387sys_gethostname(tcp)
388struct tcb *tcp;
389{
390 if (exiting(tcp)) {
391 if (syserror(tcp))
392 tprintf("%#lx", tcp->u_arg[0]);
393 else
394 printpath(tcp, tcp->u_arg[0]);
395 tprintf(", %lu", tcp->u_arg[1]);
396 }
397 return 0;
398}
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +0000399#endif /* ALPHA || FREEBSD || SUNOS4 || SVR4 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000400
401int
402sys_setdomainname(tcp)
403struct tcb *tcp;
404{
405 if (entering(tcp)) {
406 printpathn(tcp, tcp->u_arg[0], tcp->u_arg[1]);
407 tprintf(", %lu", tcp->u_arg[1]);
408 }
409 return 0;
410}
411
Wichert Akkerman5daa0281999-03-15 19:49:42 +0000412#if !defined(LINUX)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000413
414int
415sys_getdomainname(tcp)
416struct tcb *tcp;
417{
418 if (exiting(tcp)) {
419 if (syserror(tcp))
420 tprintf("%#lx", tcp->u_arg[0]);
421 else
422 printpath(tcp, tcp->u_arg[0]);
423 tprintf(", %lu", tcp->u_arg[1]);
424 }
425 return 0;
426}
427#endif /* !LINUX */
428
429int
430sys_exit(tcp)
431struct tcb *tcp;
432{
433 if (exiting(tcp)) {
434 fprintf(stderr, "_exit returned!\n");
435 return -1;
436 }
437 /* special case: we stop tracing this process, finish line now */
438 tprintf("%ld) ", tcp->u_arg[0]);
439 tabto(acolumn);
440 tprintf("= ?");
Denys Vlasenkoef2fbf82009-01-06 21:45:06 +0000441 printtrailer();
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000442 return 0;
443}
444
445int
Dmitry V. Levinfde119c2011-02-18 23:16:20 +0000446internal_exit(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000447{
Roland McGrathe85bbfe2003-01-09 06:53:31 +0000448 if (entering(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000449 tcp->flags |= TCB_EXITING;
Roland McGrathe85bbfe2003-01-09 06:53:31 +0000450#ifdef __NR_exit_group
Roland McGratha4f9f2d2005-06-07 23:21:20 +0000451 if (known_scno(tcp) == __NR_exit_group)
Roland McGrathe85bbfe2003-01-09 06:53:31 +0000452 tcp->flags |= TCB_GROUP_EXITING;
453#endif
454 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000455 return 0;
456}
457
Roland McGratheb9e2e82009-06-02 16:49:22 -0700458/* TCP is creating a child we want to follow.
459 If there will be space in tcbtab for it, set TCB_FOLLOWFORK and return 0.
460 If not, clear TCB_FOLLOWFORK, print an error, and return 1. */
461static void
462fork_tcb(struct tcb *tcp)
463{
464 if (nprocs == tcbtabsize)
465 expand_tcbtab();
466
467 tcp->flags |= TCB_FOLLOWFORK;
468}
469
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000470#ifdef USE_PROCFS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000471
472int
Denys Vlasenko418d66a2009-01-17 01:52:54 +0000473sys_fork(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000474{
Dmitry V. Levin21a75342008-09-03 01:22:18 +0000475 if (exiting(tcp) && !syserror(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000476 if (getrval2(tcp)) {
477 tcp->auxstr = "child process";
478 return RVAL_UDECIMAL | RVAL_STR;
479 }
480 }
481 return 0;
482}
483
John Hughes4e36a812001-04-18 15:11:51 +0000484#if UNIXWARE > 2
485
486int
487sys_rfork(tcp)
488struct tcb *tcp;
489{
490 if (entering(tcp)) {
491 tprintf ("%ld", tcp->u_arg[0]);
492 }
Dmitry V. Levin21a75342008-09-03 01:22:18 +0000493 else if (!syserror(tcp)) {
John Hughes4e36a812001-04-18 15:11:51 +0000494 if (getrval2(tcp)) {
495 tcp->auxstr = "child process";
496 return RVAL_UDECIMAL | RVAL_STR;
497 }
498 }
499 return 0;
500}
501
502#endif
503
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000504int
505internal_fork(tcp)
506struct tcb *tcp;
507{
508 struct tcb *tcpchild;
509
510 if (exiting(tcp)) {
Roland McGrathf3a0e1b2003-02-20 02:45:22 +0000511#ifdef SYS_rfork
Roland McGratha4f9f2d2005-06-07 23:21:20 +0000512 if (known_scno(tcp) == SYS_rfork && !(tcp->u_arg[0]&RFPROC))
Roland McGrathf3a0e1b2003-02-20 02:45:22 +0000513 return 0;
514#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000515 if (getrval2(tcp))
516 return 0;
517 if (!followfork)
518 return 0;
Roland McGratheb9e2e82009-06-02 16:49:22 -0700519 fork_tcb(tcp);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000520 if (syserror(tcp))
521 return 0;
Denys Vlasenko418d66a2009-01-17 01:52:54 +0000522 tcpchild = alloctcb(tcp->u_rval);
Wichert Akkerman2e4ffe52000-09-03 23:57:48 +0000523 if (proc_open(tcpchild, 2) < 0)
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +0000524 droptcb(tcpchild);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000525 }
526 return 0;
527}
528
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000529#else /* !USE_PROCFS */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000530
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000531#ifdef LINUX
532
533/* defines copied from linux/sched.h since we can't include that
534 * ourselves (it conflicts with *lots* of libc includes)
535 */
536#define CSIGNAL 0x000000ff /* signal mask to be sent at exit */
537#define CLONE_VM 0x00000100 /* set if VM shared between processes */
538#define CLONE_FS 0x00000200 /* set if fs info shared between processes */
539#define CLONE_FILES 0x00000400 /* set if open files shared between processes */
540#define CLONE_SIGHAND 0x00000800 /* set if signal handlers shared */
Roland McGrath909875b2002-12-22 03:34:36 +0000541#define CLONE_IDLETASK 0x00001000 /* kernel-only flag */
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000542#define CLONE_PTRACE 0x00002000 /* set if we want to let tracing continue on the child too */
543#define CLONE_VFORK 0x00004000 /* set if the parent wants the child to wake it up on mm_release */
544#define CLONE_PARENT 0x00008000 /* set if we want to have the same parent as the cloner */
Roland McGrath909875b2002-12-22 03:34:36 +0000545#define CLONE_THREAD 0x00010000 /* Same thread group? */
546#define CLONE_NEWNS 0x00020000 /* New namespace group? */
547#define CLONE_SYSVSEM 0x00040000 /* share system V SEM_UNDO semantics */
548#define CLONE_SETTLS 0x00080000 /* create a new TLS for the child */
549#define CLONE_PARENT_SETTID 0x00100000 /* set the TID in the parent */
550#define CLONE_CHILD_CLEARTID 0x00200000 /* clear the TID in the child */
Roland McGrath909875b2002-12-22 03:34:36 +0000551#define CLONE_UNTRACED 0x00800000 /* set if the tracing process can't force CLONE_PTRACE on this clone */
552#define CLONE_CHILD_SETTID 0x01000000 /* set the TID in the child */
Dmitry V. Levine3d4b682010-12-03 17:19:51 +0000553#define CLONE_STOPPED 0x02000000 /* Start in stopped state */
554#define CLONE_NEWUTS 0x04000000 /* New utsname group? */
555#define CLONE_NEWIPC 0x08000000 /* New ipcs */
556#define CLONE_NEWUSER 0x10000000 /* New user namespace */
557#define CLONE_NEWPID 0x20000000 /* New pid namespace */
558#define CLONE_NEWNET 0x40000000 /* New network namespace */
559#define CLONE_IO 0x80000000 /* Clone io context */
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000560
Roland McGrathd9f816f2004-09-04 03:39:20 +0000561static const struct xlat clone_flags[] = {
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000562 { CLONE_VM, "CLONE_VM" },
563 { CLONE_FS, "CLONE_FS" },
564 { CLONE_FILES, "CLONE_FILES" },
565 { CLONE_SIGHAND, "CLONE_SIGHAND" },
Roland McGrath909875b2002-12-22 03:34:36 +0000566 { CLONE_IDLETASK, "CLONE_IDLETASK"},
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000567 { CLONE_PTRACE, "CLONE_PTRACE" },
568 { CLONE_VFORK, "CLONE_VFORK" },
569 { CLONE_PARENT, "CLONE_PARENT" },
Roland McGrath909875b2002-12-22 03:34:36 +0000570 { CLONE_THREAD, "CLONE_THREAD" },
571 { CLONE_NEWNS, "CLONE_NEWNS" },
572 { CLONE_SYSVSEM, "CLONE_SYSVSEM" },
573 { CLONE_SETTLS, "CLONE_SETTLS" },
574 { CLONE_PARENT_SETTID,"CLONE_PARENT_SETTID" },
575 { CLONE_CHILD_CLEARTID,"CLONE_CHILD_CLEARTID" },
Roland McGrath909875b2002-12-22 03:34:36 +0000576 { CLONE_UNTRACED, "CLONE_UNTRACED" },
577 { CLONE_CHILD_SETTID,"CLONE_CHILD_SETTID" },
Dmitry V. Levine3d4b682010-12-03 17:19:51 +0000578 { CLONE_STOPPED, "CLONE_STOPPED" },
579 { CLONE_NEWUTS, "CLONE_NEWUTS" },
580 { CLONE_NEWIPC, "CLONE_NEWIPC" },
581 { CLONE_NEWUSER, "CLONE_NEWUSER" },
582 { CLONE_NEWPID, "CLONE_NEWPID" },
583 { CLONE_NEWNET, "CLONE_NEWNET" },
584 { CLONE_IO, "CLONE_IO" },
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000585 { 0, NULL },
586};
587
Roland McGrath909875b2002-12-22 03:34:36 +0000588# ifdef I386
589# include <asm/ldt.h>
Roland McGrath7decfb22004-03-01 22:10:52 +0000590# ifdef HAVE_STRUCT_USER_DESC
591# define modify_ldt_ldt_s user_desc
592# endif
Roland McGrath909875b2002-12-22 03:34:36 +0000593extern void print_ldt_entry();
594# endif
595
Roland McGrath9677b3a2003-03-12 09:54:36 +0000596# if defined IA64
597# define ARG_FLAGS 0
598# define ARG_STACK 1
Roland McGratha4f9f2d2005-06-07 23:21:20 +0000599# define ARG_STACKSIZE (known_scno(tcp) == SYS_clone2 ? 2 : -1)
600# define ARG_PTID (known_scno(tcp) == SYS_clone2 ? 3 : 2)
601# define ARG_CTID (known_scno(tcp) == SYS_clone2 ? 4 : 3)
602# define ARG_TLS (known_scno(tcp) == SYS_clone2 ? 5 : 4)
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +0000603# elif defined S390 || defined S390X || defined CRISV10 || defined CRISV32
Roland McGrath9677b3a2003-03-12 09:54:36 +0000604# define ARG_STACK 0
605# define ARG_FLAGS 1
606# define ARG_PTID 2
Roland McGrathfe5fdb22003-05-23 00:29:05 +0000607# define ARG_CTID 3
608# define ARG_TLS 4
Roland McGrath9c555e72003-07-09 09:47:59 +0000609# elif defined X86_64 || defined ALPHA
Roland McGrath361aac52003-03-18 07:43:42 +0000610# define ARG_FLAGS 0
611# define ARG_STACK 1
612# define ARG_PTID 2
613# define ARG_CTID 3
614# define ARG_TLS 4
Roland McGrath9677b3a2003-03-12 09:54:36 +0000615# else
616# define ARG_FLAGS 0
617# define ARG_STACK 1
618# define ARG_PTID 2
619# define ARG_TLS 3
620# define ARG_CTID 4
621# endif
622
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000623int
624sys_clone(tcp)
625struct tcb *tcp;
626{
627 if (exiting(tcp)) {
Wang Chaocbdd1902010-09-02 15:08:59 +0800628 const char *sep = "|";
Roland McGrath9677b3a2003-03-12 09:54:36 +0000629 unsigned long flags = tcp->u_arg[ARG_FLAGS];
630 tprintf("child_stack=%#lx, ", tcp->u_arg[ARG_STACK]);
631# ifdef ARG_STACKSIZE
632 if (ARG_STACKSIZE != -1)
633 tprintf("stack_size=%#lx, ",
634 tcp->u_arg[ARG_STACKSIZE]);
Roland McGrathb4968be2003-01-20 09:04:33 +0000635# endif
Roland McGrath9677b3a2003-03-12 09:54:36 +0000636 tprintf("flags=");
Wang Chaocbdd1902010-09-02 15:08:59 +0800637 if (!printflags(clone_flags, flags &~ CSIGNAL, NULL))
638 sep = "";
Roland McGrath984154d2003-05-23 01:08:42 +0000639 if ((flags & CSIGNAL) != 0)
Wang Chaocbdd1902010-09-02 15:08:59 +0800640 tprintf("%s%s", sep, signame(flags & CSIGNAL));
Roland McGrathb4968be2003-01-20 09:04:33 +0000641 if ((flags & (CLONE_PARENT_SETTID|CLONE_CHILD_SETTID
Roland McGrath9677b3a2003-03-12 09:54:36 +0000642 |CLONE_CHILD_CLEARTID|CLONE_SETTLS)) == 0)
Roland McGrath909875b2002-12-22 03:34:36 +0000643 return 0;
Roland McGrath6f67a982003-03-21 07:33:15 +0000644 if (flags & CLONE_PARENT_SETTID)
645 tprintf(", parent_tidptr=%#lx", tcp->u_arg[ARG_PTID]);
Roland McGrathb4968be2003-01-20 09:04:33 +0000646 if (flags & CLONE_SETTLS) {
Roland McGrath9677b3a2003-03-12 09:54:36 +0000647# ifdef I386
Roland McGrath909875b2002-12-22 03:34:36 +0000648 struct modify_ldt_ldt_s copy;
Roland McGrath9677b3a2003-03-12 09:54:36 +0000649 if (umove(tcp, tcp->u_arg[ARG_TLS], &copy) != -1) {
Roland McGrath909875b2002-12-22 03:34:36 +0000650 tprintf(", {entry_number:%d, ",
651 copy.entry_number);
652 if (!verbose(tcp))
653 tprintf("...}");
654 else
655 print_ldt_entry(&copy);
656 }
657 else
Roland McGrath9677b3a2003-03-12 09:54:36 +0000658# endif
Roland McGrath43f2c842003-03-12 09:58:14 +0000659 tprintf(", tls=%#lx", tcp->u_arg[ARG_TLS]);
Roland McGrath909875b2002-12-22 03:34:36 +0000660 }
Roland McGrath9677b3a2003-03-12 09:54:36 +0000661 if (flags & (CLONE_CHILD_SETTID|CLONE_CHILD_CLEARTID))
662 tprintf(", child_tidptr=%#lx", tcp->u_arg[ARG_CTID]);
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000663 }
664 return 0;
665}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000666
667int
668sys_unshare(struct tcb *tcp)
669{
670 if (entering(tcp))
671 printflags(clone_flags, tcp->u_arg[0], "CLONE_???");
672 return 0;
673}
Dmitry V. Levine5e60852009-12-31 22:50:49 +0000674#endif /* LINUX */
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000675
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000676int
677sys_fork(tcp)
678struct tcb *tcp;
679{
680 if (exiting(tcp))
681 return RVAL_UDECIMAL;
682 return 0;
683}
684
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000685int
Denys Vlasenko418d66a2009-01-17 01:52:54 +0000686change_syscall(struct tcb *tcp, int new)
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000687{
Dmitry V. Levine5e60852009-12-31 22:50:49 +0000688#ifdef LINUX
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000689#if defined(I386)
690 /* Attempt to make vfork into fork, which we can follow. */
Roland McGrath5a223472002-12-15 23:58:26 +0000691 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(ORIG_EAX * 4), new) < 0)
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000692 return -1;
693 return 0;
Michal Ludvig0e035502002-09-23 15:41:01 +0000694#elif defined(X86_64)
695 /* Attempt to make vfork into fork, which we can follow. */
Roland McGrath5a223472002-12-15 23:58:26 +0000696 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(ORIG_RAX * 8), new) < 0)
Michal Ludvig0e035502002-09-23 15:41:01 +0000697 return -1;
698 return 0;
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000699#elif defined(POWERPC)
Roland McGratheb285352003-01-14 09:59:00 +0000700 if (ptrace(PTRACE_POKEUSER, tcp->pid,
701 (char*)(sizeof(unsigned long)*PT_R0), new) < 0)
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000702 return -1;
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000703 return 0;
Michal Ludvig10a88d02002-10-07 14:31:00 +0000704#elif defined(S390) || defined(S390X)
705 /* s390 linux after 2.4.7 has a hook in entry.S to allow this */
706 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(PT_GPR2), new)<0)
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +0000707 return -1;
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000708 return 0;
709#elif defined(M68K)
Wichert Akkermanc7926982000-04-10 22:22:31 +0000710 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(4*PT_ORIG_D0), new)<0)
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +0000711 return -1;
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000712 return 0;
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000713#elif defined(SPARC) || defined(SPARC64)
Mike Frysinger8566c502009-10-12 11:05:14 -0400714 struct pt_regs regs;
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000715 if (ptrace(PTRACE_GETREGS, tcp->pid, (char*)&regs, 0)<0)
716 return -1;
Mike Frysinger8566c502009-10-12 11:05:14 -0400717 regs.u_regs[U_REG_G1] = new;
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000718 if (ptrace(PTRACE_SETREGS, tcp->pid, (char*)&regs, 0)<0)
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +0000719 return -1;
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000720 return 0;
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000721#elif defined(MIPS)
Wichert Akkermanc7926982000-04-10 22:22:31 +0000722 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(REG_V0), new)<0)
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +0000723 return -1;
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000724 return 0;
725#elif defined(ALPHA)
Wichert Akkermanc7926982000-04-10 22:22:31 +0000726 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(REG_A3), new)<0)
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +0000727 return -1;
728 return 0;
729#elif defined(AVR32)
730 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(REG_R8), new) < 0)
731 return -1;
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000732 return 0;
Dmitry V. Levin87ea1f42008-11-10 22:21:41 +0000733#elif defined(BFIN)
734 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(REG_P0), new)<0)
735 return -1;
736 return 0;
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000737#elif defined(IA64)
Roland McGrath08267b82004-02-20 22:56:43 +0000738 if (ia32) {
739 switch (new) {
Denys Vlasenko418d66a2009-01-17 01:52:54 +0000740 case 2:
741 break; /* x86 SYS_fork */
742 case SYS_clone:
743 new = 120;
744 break;
745 default:
Roland McGrath08267b82004-02-20 22:56:43 +0000746 fprintf(stderr, "%s: unexpected syscall %d\n",
747 __FUNCTION__, new);
748 return -1;
749 }
750 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(PT_R1), new)<0)
751 return -1;
752 } else if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(PT_R15), new)<0)
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000753 return -1;
754 return 0;
Wichert Akkermanc1652e22001-03-27 12:17:16 +0000755#elif defined(HPPA)
756 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(PT_GR20), new)<0)
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +0000757 return -1;
Wichert Akkermanc1652e22001-03-27 12:17:16 +0000758 return 0;
Wichert Akkermanccef6372002-05-01 16:39:22 +0000759#elif defined(SH)
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000760 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(4*(REG_REG0+3)), new)<0)
761 return -1;
762 return 0;
Roland McGrathf5a47772003-06-26 22:40:42 +0000763#elif defined(SH64)
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000764 /* Top half of reg encodes the no. of args n as 0x1n.
765 Assume 0 args as kernel never actually checks... */
766 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(REG_SYSCALL),
767 0x100000 | new) < 0)
768 return -1;
769 return 0;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +0000770#elif defined(CRISV10) || defined(CRISV32)
771 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(4*PT_R9), new) < 0)
772 return -1;
773 return 0;
Roland McGrathf691bd22006-04-25 07:34:41 +0000774#elif defined(ARM)
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000775 /* Some kernels support this, some (pre-2.6.16 or so) don't. */
Roland McGrathf691bd22006-04-25 07:34:41 +0000776# ifndef PTRACE_SET_SYSCALL
777# define PTRACE_SET_SYSCALL 23
778# endif
779
Dmitry V. Levin76740062009-09-18 11:30:14 +0000780 if (ptrace (PTRACE_SET_SYSCALL, tcp->pid, 0, new & 0xffff) != 0)
Roland McGrathf691bd22006-04-25 07:34:41 +0000781 return -1;
782
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000783 return 0;
Chris Metcalfc8c66982009-12-28 10:00:15 -0500784#elif defined(TILE)
785 if (ptrace(PTRACE_POKEUSER, tcp->pid,
786 (char*)PTREGS_OFFSET_REG(0),
787 new) != 0)
788 return -1;
789 return 0;
Edgar E. Iglesias939caba2010-07-06 14:21:07 +0200790#elif defined(MICROBLAZE)
791 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(PT_GPR(0)), new)<0)
792 return -1;
793 return 0;
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000794#else
795#warning Do not know how to handle change_syscall for this architecture
796#endif /* architecture */
797#endif /* LINUX */
798 return -1;
799}
800
Dmitry V. Levin257e1572009-12-26 17:55:24 +0000801#ifdef LINUX
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000802int
Wang Chaoca8ab8d2010-11-12 17:26:08 +0800803handle_new_child(struct tcb *tcp, int pid, int bpt)
804{
805 struct tcb *tcpchild;
806
807#ifdef CLONE_PTRACE /* See new setbpt code. */
808 tcpchild = pid2tcb(pid);
809 if (tcpchild != NULL) {
810 /* The child already reported its startup trap
811 before the parent reported its syscall return. */
812 if ((tcpchild->flags
813 & (TCB_STARTUP|TCB_ATTACHED|TCB_SUSPENDED))
814 != (TCB_STARTUP|TCB_ATTACHED|TCB_SUSPENDED))
815 fprintf(stderr, "\
816[preattached child %d of %d in weird state!]\n",
817 pid, tcp->pid);
818 }
819 else
820#endif /* CLONE_PTRACE */
821 {
822 fork_tcb(tcp);
823 tcpchild = alloctcb(pid);
824 }
825
826#ifndef CLONE_PTRACE
827 /* Attach to the new child */
828 if (ptrace(PTRACE_ATTACH, pid, (char *) 1, 0) < 0) {
829 if (bpt)
830 clearbpt(tcp);
831 perror("PTRACE_ATTACH");
832 fprintf(stderr, "Too late?\n");
833 droptcb(tcpchild);
834 return 0;
835 }
836#endif /* !CLONE_PTRACE */
837
838 if (bpt)
839 clearbpt(tcp);
840
841 tcpchild->flags |= TCB_ATTACHED;
842 /* Child has BPT too, must be removed on first occasion. */
843 if (bpt) {
844 tcpchild->flags |= TCB_BPTSET;
845 tcpchild->baddr = tcp->baddr;
846 memcpy(tcpchild->inst, tcp->inst,
847 sizeof tcpchild->inst);
848 }
849 tcpchild->parent = tcp;
850 tcp->nchildren++;
851 if (tcpchild->flags & TCB_SUSPENDED) {
852 /* The child was born suspended, due to our having
853 forced CLONE_PTRACE. */
854 if (bpt)
855 clearbpt(tcpchild);
856
857 tcpchild->flags &= ~(TCB_SUSPENDED|TCB_STARTUP);
858 if (ptrace_restart(PTRACE_SYSCALL, tcpchild, 0) < 0)
859 return -1;
860
861 if (!qflag)
862 fprintf(stderr, "\
863Process %u resumed (parent %d ready)\n",
864 pid, tcp->pid);
865 }
866 else {
867 if (!qflag)
868 fprintf(stderr, "Process %d attached\n", pid);
869 }
870
871#ifdef TCB_CLONE_THREAD
872 if (sysent[tcp->scno].sys_func == sys_clone)
873 {
874 /*
875 * Save the flags used in this call,
876 * in case we point TCP to our parent below.
877 */
878 int call_flags = tcp->u_arg[ARG_FLAGS];
879 if ((tcp->flags & TCB_CLONE_THREAD) &&
880 tcp->parent != NULL) {
881 /* The parent in this clone is itself a
882 thread belonging to another process.
883 There is no meaning to the parentage
884 relationship of the new child with the
885 thread, only with the process. We
886 associate the new thread with our
887 parent. Since this is done for every
888 new thread, there will never be a
889 TCB_CLONE_THREAD process that has
890 children. */
891 --tcp->nchildren;
892 tcp = tcp->parent;
893 tcpchild->parent = tcp;
894 ++tcp->nchildren;
895 }
896 if (call_flags & CLONE_THREAD) {
897 tcpchild->flags |= TCB_CLONE_THREAD;
898 ++tcp->nclone_threads;
899 }
900 if ((call_flags & CLONE_PARENT) &&
901 !(call_flags & CLONE_THREAD)) {
902 --tcp->nchildren;
903 tcpchild->parent = NULL;
904 if (tcp->parent != NULL) {
905 tcp = tcp->parent;
906 tcpchild->parent = tcp;
907 ++tcp->nchildren;
908 }
909 }
910 }
911#endif /* TCB_CLONE_THREAD */
912 return 0;
913}
914
915int
Dmitry V. Levin257e1572009-12-26 17:55:24 +0000916internal_fork(struct tcb *tcp)
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000917{
Wang Chaoca8ab8d2010-11-12 17:26:08 +0800918 if ((ptrace_setoptions
919 & (PTRACE_O_TRACECLONE | PTRACE_O_TRACEFORK | PTRACE_O_TRACEVFORK))
920 == (PTRACE_O_TRACECLONE | PTRACE_O_TRACEFORK | PTRACE_O_TRACEVFORK))
921 return 0;
922
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000923 if (entering(tcp)) {
Wang Chaoe636c852010-09-16 11:20:56 +0800924 tcp->flags &= ~TCB_FOLLOWFORK;
Roland McGratheb9e2e82009-06-02 16:49:22 -0700925 if (!followfork)
926 return 0;
Wang Chaoe636c852010-09-16 11:20:56 +0800927 /*
928 * In occasion of using PTRACE_O_TRACECLONE, we won't see the
929 * new child if clone is called with flag CLONE_UNTRACED, so
930 * we keep the same logic with that option and don't trace it.
931 */
932 if ((sysent[tcp->scno].sys_func == sys_clone) &&
933 (tcp->u_arg[ARG_FLAGS] & CLONE_UNTRACED))
934 return 0;
Roland McGratheb9e2e82009-06-02 16:49:22 -0700935 fork_tcb(tcp);
936 if (setbpt(tcp) < 0)
937 return 0;
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000938 } else {
Dmitry V. Levin257e1572009-12-26 17:55:24 +0000939 int pid;
940 int bpt;
Roland McGratheb9e2e82009-06-02 16:49:22 -0700941
942 if (!(tcp->flags & TCB_FOLLOWFORK))
943 return 0;
Wichert Akkerman9b0c31d2000-09-03 21:56:29 +0000944
Dmitry V. Levin257e1572009-12-26 17:55:24 +0000945 bpt = tcp->flags & TCB_BPTSET;
946
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000947 if (syserror(tcp)) {
948 if (bpt)
949 clearbpt(tcp);
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000950 return 0;
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000951 }
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000952
953 pid = tcp->u_rval;
Roland McGrathe85bbfe2003-01-09 06:53:31 +0000954
Wang Chaoca8ab8d2010-11-12 17:26:08 +0800955 return handle_new_child(tcp, pid, bpt);
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +0000956 }
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000957 return 0;
958}
Dmitry V. Levin257e1572009-12-26 17:55:24 +0000959
960#else /* !LINUX */
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000961
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000962int
963internal_fork(tcp)
964struct tcb *tcp;
965{
966 struct tcb *tcpchild;
967 int pid;
Roland McGratheb9e2e82009-06-02 16:49:22 -0700968 int dont_follow = 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000969
970#ifdef SYS_vfork
Roland McGratha4f9f2d2005-06-07 23:21:20 +0000971 if (known_scno(tcp) == SYS_vfork) {
Nate Sammonsccd8f211999-03-29 22:57:54 +0000972 /* Attempt to make vfork into fork, which we can follow. */
Roland McGrath41c48222008-07-18 00:25:10 +0000973 if (change_syscall(tcp, SYS_fork) < 0)
Roland McGratheb9e2e82009-06-02 16:49:22 -0700974 dont_follow = 1;
Nate Sammonsccd8f211999-03-29 22:57:54 +0000975 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000976#endif
977 if (entering(tcp)) {
Roland McGratheb9e2e82009-06-02 16:49:22 -0700978 if (!followfork || dont_follow)
979 return 0;
980 fork_tcb(tcp);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000981 if (setbpt(tcp) < 0)
982 return 0;
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +0000983 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000984 else {
985 int bpt = tcp->flags & TCB_BPTSET;
986
Roland McGratheb9e2e82009-06-02 16:49:22 -0700987 if (!(tcp->flags & TCB_FOLLOWFORK))
988 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000989 if (bpt)
990 clearbpt(tcp);
991
992 if (syserror(tcp))
993 return 0;
994
995 pid = tcp->u_rval;
Roland McGratheb9e2e82009-06-02 16:49:22 -0700996 fork_tcb(tcp);
Denys Vlasenko418d66a2009-01-17 01:52:54 +0000997 tcpchild = alloctcb(pid);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000998#ifdef SUNOS4
999#ifdef oldway
1000 /* The child must have run before it can be attached. */
1001 {
1002 struct timeval tv;
1003 tv.tv_sec = 0;
1004 tv.tv_usec = 10000;
1005 select(0, NULL, NULL, NULL, &tv);
1006 }
1007 if (ptrace(PTRACE_ATTACH, pid, (char *)1, 0) < 0) {
1008 perror("PTRACE_ATTACH");
1009 fprintf(stderr, "Too late?\n");
1010 droptcb(tcpchild);
1011 return 0;
1012 }
1013#else /* !oldway */
1014 /* Try to catch the new process as soon as possible. */
1015 {
1016 int i;
1017 for (i = 0; i < 1024; i++)
1018 if (ptrace(PTRACE_ATTACH, pid, (char *) 1, 0) >= 0)
1019 break;
1020 if (i == 1024) {
1021 perror("PTRACE_ATTACH");
1022 fprintf(stderr, "Too late?\n");
1023 droptcb(tcpchild);
1024 return 0;
1025 }
1026 }
1027#endif /* !oldway */
1028#endif /* SUNOS4 */
1029 tcpchild->flags |= TCB_ATTACHED;
1030 /* Child has BPT too, must be removed on first occasion */
1031 if (bpt) {
1032 tcpchild->flags |= TCB_BPTSET;
1033 tcpchild->baddr = tcp->baddr;
1034 memcpy(tcpchild->inst, tcp->inst,
1035 sizeof tcpchild->inst);
1036 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001037 tcpchild->parent = tcp;
1038 tcp->nchildren++;
1039 if (!qflag)
1040 fprintf(stderr, "Process %d attached\n", pid);
1041 }
1042 return 0;
1043}
1044
Dmitry V. Levin257e1572009-12-26 17:55:24 +00001045#endif /* !LINUX */
1046
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001047#endif /* !USE_PROCFS */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001048
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001049#if defined(SUNOS4) || defined(LINUX) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001050
1051int
1052sys_vfork(tcp)
1053struct tcb *tcp;
1054{
1055 if (exiting(tcp))
1056 return RVAL_UDECIMAL;
1057 return 0;
1058}
1059
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001060#endif /* SUNOS4 || LINUX || FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001061
1062#ifndef LINUX
1063
1064static char idstr[16];
1065
1066int
1067sys_getpid(tcp)
1068struct tcb *tcp;
1069{
1070 if (exiting(tcp)) {
1071 sprintf(idstr, "ppid %lu", getrval2(tcp));
1072 tcp->auxstr = idstr;
1073 return RVAL_STR;
1074 }
1075 return 0;
1076}
1077
1078int
1079sys_getuid(tcp)
1080struct tcb *tcp;
1081{
1082 if (exiting(tcp)) {
1083 sprintf(idstr, "euid %lu", getrval2(tcp));
1084 tcp->auxstr = idstr;
1085 return RVAL_STR;
1086 }
1087 return 0;
1088}
1089
1090int
1091sys_getgid(tcp)
1092struct tcb *tcp;
1093{
1094 if (exiting(tcp)) {
1095 sprintf(idstr, "egid %lu", getrval2(tcp));
1096 tcp->auxstr = idstr;
1097 return RVAL_STR;
1098 }
1099 return 0;
1100}
1101
1102#endif /* !LINUX */
1103
1104#ifdef LINUX
1105
Dmitry V. Levin50a218d2011-01-18 17:36:20 +00001106int sys_getuid(struct tcb *tcp)
1107{
1108 if (exiting(tcp))
1109 tcp->u_rval = (uid_t) tcp->u_rval;
1110 return RVAL_UDECIMAL;
1111}
1112
1113int sys_setfsuid(struct tcb *tcp)
1114{
1115 if (entering(tcp))
1116 tprintf("%u", (uid_t) tcp->u_arg[0]);
1117 else
1118 tcp->u_rval = (uid_t) tcp->u_rval;
1119 return RVAL_UDECIMAL;
1120}
1121
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001122int
1123sys_setuid(tcp)
1124struct tcb *tcp;
1125{
1126 if (entering(tcp)) {
1127 tprintf("%u", (uid_t) tcp->u_arg[0]);
1128 }
1129 return 0;
1130}
1131
1132int
1133sys_setgid(tcp)
1134struct tcb *tcp;
1135{
1136 if (entering(tcp)) {
1137 tprintf("%u", (gid_t) tcp->u_arg[0]);
1138 }
1139 return 0;
1140}
1141
1142int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001143sys_getresuid(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001144{
1145 if (exiting(tcp)) {
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001146 __kernel_uid_t uid;
1147 if (syserror(tcp))
1148 tprintf("%#lx, %#lx, %#lx", tcp->u_arg[0],
1149 tcp->u_arg[1], tcp->u_arg[2]);
1150 else {
1151 if (umove(tcp, tcp->u_arg[0], &uid) < 0)
1152 tprintf("%#lx, ", tcp->u_arg[0]);
1153 else
Roland McGrath83bd47a2003-11-13 22:32:26 +00001154 tprintf("[%lu], ", (unsigned long) uid);
Roland McGrath9bd6b422003-02-24 07:13:51 +00001155 if (umove(tcp, tcp->u_arg[1], &uid) < 0)
1156 tprintf("%#lx, ", tcp->u_arg[1]);
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001157 else
Roland McGrath83bd47a2003-11-13 22:32:26 +00001158 tprintf("[%lu], ", (unsigned long) uid);
Roland McGrath9bd6b422003-02-24 07:13:51 +00001159 if (umove(tcp, tcp->u_arg[2], &uid) < 0)
1160 tprintf("%#lx", tcp->u_arg[2]);
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001161 else
Roland McGrath83bd47a2003-11-13 22:32:26 +00001162 tprintf("[%lu]", (unsigned long) uid);
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001163 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001164 }
1165 return 0;
1166}
1167
1168int
1169sys_getresgid(tcp)
1170struct tcb *tcp;
1171{
1172 if (exiting(tcp)) {
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001173 __kernel_gid_t gid;
1174 if (syserror(tcp))
1175 tprintf("%#lx, %#lx, %#lx", tcp->u_arg[0],
1176 tcp->u_arg[1], tcp->u_arg[2]);
1177 else {
1178 if (umove(tcp, tcp->u_arg[0], &gid) < 0)
1179 tprintf("%#lx, ", tcp->u_arg[0]);
1180 else
Roland McGrath83bd47a2003-11-13 22:32:26 +00001181 tprintf("[%lu], ", (unsigned long) gid);
Roland McGrathd2450922003-02-24 10:18:07 +00001182 if (umove(tcp, tcp->u_arg[1], &gid) < 0)
1183 tprintf("%#lx, ", tcp->u_arg[1]);
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001184 else
Roland McGrath83bd47a2003-11-13 22:32:26 +00001185 tprintf("[%lu], ", (unsigned long) gid);
Roland McGrathd2450922003-02-24 10:18:07 +00001186 if (umove(tcp, tcp->u_arg[2], &gid) < 0)
1187 tprintf("%#lx", tcp->u_arg[2]);
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001188 else
Roland McGrath83bd47a2003-11-13 22:32:26 +00001189 tprintf("[%lu]", (unsigned long) gid);
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001190 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001191 }
1192 return 0;
1193}
1194
1195#endif /* LINUX */
1196
1197int
1198sys_setreuid(tcp)
1199struct tcb *tcp;
1200{
1201 if (entering(tcp)) {
Roland McGrath83bd47a2003-11-13 22:32:26 +00001202 printuid("", tcp->u_arg[0]);
1203 printuid(", ", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001204 }
1205 return 0;
1206}
1207
1208int
1209sys_setregid(tcp)
1210struct tcb *tcp;
1211{
1212 if (entering(tcp)) {
Roland McGrath83bd47a2003-11-13 22:32:26 +00001213 printuid("", tcp->u_arg[0]);
1214 printuid(", ", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001215 }
1216 return 0;
1217}
1218
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001219#if defined(LINUX) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001220int
1221sys_setresuid(tcp)
1222 struct tcb *tcp;
1223{
1224 if (entering(tcp)) {
Roland McGrath83bd47a2003-11-13 22:32:26 +00001225 printuid("", tcp->u_arg[0]);
1226 printuid(", ", tcp->u_arg[1]);
1227 printuid(", ", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001228 }
1229 return 0;
1230}
1231int
1232sys_setresgid(tcp)
1233 struct tcb *tcp;
1234{
1235 if (entering(tcp)) {
Roland McGrath83bd47a2003-11-13 22:32:26 +00001236 printuid("", tcp->u_arg[0]);
1237 printuid(", ", tcp->u_arg[1]);
1238 printuid(", ", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001239 }
1240 return 0;
1241}
1242
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001243#endif /* LINUX || FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001244
1245int
1246sys_setgroups(tcp)
1247struct tcb *tcp;
1248{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001249 if (entering(tcp)) {
Roland McGrathaa524c82005-06-01 19:22:06 +00001250 unsigned long len, size, start, cur, end, abbrev_end;
1251 GETGROUPS_T gid;
1252 int failed = 0;
1253
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001254 len = tcp->u_arg[0];
Roland McGrathaa524c82005-06-01 19:22:06 +00001255 tprintf("%lu, ", len);
1256 if (len == 0) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001257 tprintf("[]");
1258 return 0;
1259 }
Roland McGrathaa524c82005-06-01 19:22:06 +00001260 start = tcp->u_arg[1];
1261 if (start == 0) {
1262 tprintf("NULL");
1263 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001264 }
Roland McGrathaa524c82005-06-01 19:22:06 +00001265 size = len * sizeof(gid);
1266 end = start + size;
1267 if (!verbose(tcp) || size / sizeof(gid) != len || end < start) {
1268 tprintf("%#lx", start);
1269 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001270 }
Roland McGrathaa524c82005-06-01 19:22:06 +00001271 if (abbrev(tcp)) {
1272 abbrev_end = start + max_strlen * sizeof(gid);
1273 if (abbrev_end < start)
1274 abbrev_end = end;
1275 } else {
1276 abbrev_end = end;
1277 }
1278 tprintf("[");
1279 for (cur = start; cur < end; cur += sizeof(gid)) {
1280 if (cur > start)
1281 tprintf(", ");
1282 if (cur >= abbrev_end) {
1283 tprintf("...");
1284 break;
1285 }
1286 if (umoven(tcp, cur, sizeof(gid), (char *) &gid) < 0) {
1287 tprintf("?");
1288 failed = 1;
1289 break;
1290 }
1291 tprintf("%lu", (unsigned long) gid);
1292 }
1293 tprintf("]");
1294 if (failed)
1295 tprintf(" %#lx", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001296 }
1297 return 0;
1298}
1299
1300int
1301sys_getgroups(tcp)
1302struct tcb *tcp;
1303{
Roland McGrathaa524c82005-06-01 19:22:06 +00001304 unsigned long len;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001305
1306 if (entering(tcp)) {
1307 len = tcp->u_arg[0];
Roland McGrathaa524c82005-06-01 19:22:06 +00001308 tprintf("%lu, ", len);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001309 } else {
Roland McGrathaa524c82005-06-01 19:22:06 +00001310 unsigned long size, start, cur, end, abbrev_end;
1311 GETGROUPS_T gid;
1312 int failed = 0;
1313
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001314 len = tcp->u_rval;
Roland McGrathaa524c82005-06-01 19:22:06 +00001315 if (len == 0) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001316 tprintf("[]");
1317 return 0;
1318 }
Roland McGrathaa524c82005-06-01 19:22:06 +00001319 start = tcp->u_arg[1];
1320 if (start == 0) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001321 tprintf("NULL");
Roland McGrathaa524c82005-06-01 19:22:06 +00001322 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001323 }
Roland McGrathaa524c82005-06-01 19:22:06 +00001324 if (tcp->u_arg[0] == 0) {
1325 tprintf("%#lx", start);
1326 return 0;
1327 }
1328 size = len * sizeof(gid);
1329 end = start + size;
1330 if (!verbose(tcp) || tcp->u_arg[0] == 0 ||
1331 size / sizeof(gid) != len || end < start) {
1332 tprintf("%#lx", start);
1333 return 0;
1334 }
1335 if (abbrev(tcp)) {
1336 abbrev_end = start + max_strlen * sizeof(gid);
1337 if (abbrev_end < start)
1338 abbrev_end = end;
1339 } else {
1340 abbrev_end = end;
1341 }
1342 tprintf("[");
1343 for (cur = start; cur < end; cur += sizeof(gid)) {
1344 if (cur > start)
1345 tprintf(", ");
1346 if (cur >= abbrev_end) {
1347 tprintf("...");
1348 break;
1349 }
1350 if (umoven(tcp, cur, sizeof(gid), (char *) &gid) < 0) {
1351 tprintf("?");
1352 failed = 1;
1353 break;
1354 }
1355 tprintf("%lu", (unsigned long) gid);
1356 }
1357 tprintf("]");
1358 if (failed)
1359 tprintf(" %#lx", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001360 }
1361 return 0;
1362}
1363
Roland McGrath83bd47a2003-11-13 22:32:26 +00001364#ifdef LINUX
1365int
1366sys_setgroups32(tcp)
1367struct tcb *tcp;
1368{
Roland McGrath83bd47a2003-11-13 22:32:26 +00001369 if (entering(tcp)) {
Roland McGrathaa524c82005-06-01 19:22:06 +00001370 unsigned long len, size, start, cur, end, abbrev_end;
1371 GETGROUPS32_T gid;
1372 int failed = 0;
1373
Roland McGrath83bd47a2003-11-13 22:32:26 +00001374 len = tcp->u_arg[0];
Roland McGrathaa524c82005-06-01 19:22:06 +00001375 tprintf("%lu, ", len);
1376 if (len == 0) {
Roland McGrath83bd47a2003-11-13 22:32:26 +00001377 tprintf("[]");
1378 return 0;
1379 }
Roland McGrathaa524c82005-06-01 19:22:06 +00001380 start = tcp->u_arg[1];
1381 if (start == 0) {
1382 tprintf("NULL");
1383 return 0;
Roland McGrath83bd47a2003-11-13 22:32:26 +00001384 }
Roland McGrathaa524c82005-06-01 19:22:06 +00001385 size = len * sizeof(gid);
1386 end = start + size;
1387 if (!verbose(tcp) || size / sizeof(gid) != len || end < start) {
1388 tprintf("%#lx", start);
1389 return 0;
Roland McGrath83bd47a2003-11-13 22:32:26 +00001390 }
Roland McGrathaa524c82005-06-01 19:22:06 +00001391 if (abbrev(tcp)) {
1392 abbrev_end = start + max_strlen * sizeof(gid);
1393 if (abbrev_end < start)
1394 abbrev_end = end;
1395 } else {
1396 abbrev_end = end;
1397 }
1398 tprintf("[");
1399 for (cur = start; cur < end; cur += sizeof(gid)) {
1400 if (cur > start)
1401 tprintf(", ");
1402 if (cur >= abbrev_end) {
1403 tprintf("...");
1404 break;
1405 }
1406 if (umoven(tcp, cur, sizeof(gid), (char *) &gid) < 0) {
1407 tprintf("?");
1408 failed = 1;
1409 break;
1410 }
1411 tprintf("%lu", (unsigned long) gid);
1412 }
1413 tprintf("]");
1414 if (failed)
1415 tprintf(" %#lx", tcp->u_arg[1]);
Roland McGrath83bd47a2003-11-13 22:32:26 +00001416 }
1417 return 0;
1418}
1419
1420int
1421sys_getgroups32(tcp)
1422struct tcb *tcp;
1423{
Roland McGrathaa524c82005-06-01 19:22:06 +00001424 unsigned long len;
Roland McGrath83bd47a2003-11-13 22:32:26 +00001425
1426 if (entering(tcp)) {
1427 len = tcp->u_arg[0];
Roland McGrathaa524c82005-06-01 19:22:06 +00001428 tprintf("%lu, ", len);
Roland McGrath83bd47a2003-11-13 22:32:26 +00001429 } else {
Roland McGrathaa524c82005-06-01 19:22:06 +00001430 unsigned long size, start, cur, end, abbrev_end;
1431 GETGROUPS32_T gid;
1432 int failed = 0;
1433
Roland McGrath83bd47a2003-11-13 22:32:26 +00001434 len = tcp->u_rval;
Roland McGrathaa524c82005-06-01 19:22:06 +00001435 if (len == 0) {
Roland McGrath83bd47a2003-11-13 22:32:26 +00001436 tprintf("[]");
1437 return 0;
1438 }
Roland McGrathaa524c82005-06-01 19:22:06 +00001439 start = tcp->u_arg[1];
1440 if (start == 0) {
Roland McGrath83bd47a2003-11-13 22:32:26 +00001441 tprintf("NULL");
Roland McGrathaa524c82005-06-01 19:22:06 +00001442 return 0;
Roland McGrath83bd47a2003-11-13 22:32:26 +00001443 }
Roland McGrathaa524c82005-06-01 19:22:06 +00001444 size = len * sizeof(gid);
1445 end = start + size;
1446 if (!verbose(tcp) || tcp->u_arg[0] == 0 ||
1447 size / sizeof(gid) != len || end < start) {
1448 tprintf("%#lx", start);
1449 return 0;
1450 }
1451 if (abbrev(tcp)) {
1452 abbrev_end = start + max_strlen * sizeof(gid);
1453 if (abbrev_end < start)
1454 abbrev_end = end;
1455 } else {
1456 abbrev_end = end;
1457 }
1458 tprintf("[");
1459 for (cur = start; cur < end; cur += sizeof(gid)) {
1460 if (cur > start)
1461 tprintf(", ");
1462 if (cur >= abbrev_end) {
1463 tprintf("...");
1464 break;
1465 }
1466 if (umoven(tcp, cur, sizeof(gid), (char *) &gid) < 0) {
1467 tprintf("?");
1468 failed = 1;
1469 break;
1470 }
1471 tprintf("%lu", (unsigned long) gid);
1472 }
1473 tprintf("]");
1474 if (failed)
1475 tprintf(" %#lx", tcp->u_arg[1]);
Roland McGrath83bd47a2003-11-13 22:32:26 +00001476 }
1477 return 0;
1478}
1479#endif /* LINUX */
1480
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001481#if defined(ALPHA) || defined(SUNOS4) || defined(SVR4)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001482int
1483sys_setpgrp(tcp)
1484struct tcb *tcp;
1485{
1486 if (entering(tcp)) {
1487#ifndef SVR4
1488 tprintf("%lu, %lu", tcp->u_arg[0], tcp->u_arg[1]);
1489#endif /* !SVR4 */
1490 }
1491 return 0;
1492}
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001493#endif /* ALPHA || SUNOS4 || SVR4 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001494
1495int
1496sys_getpgrp(tcp)
1497struct tcb *tcp;
1498{
1499 if (entering(tcp)) {
1500#ifndef SVR4
1501 tprintf("%lu", tcp->u_arg[0]);
1502#endif /* !SVR4 */
1503 }
1504 return 0;
1505}
1506
1507int
1508sys_getsid(tcp)
1509struct tcb *tcp;
1510{
1511 if (entering(tcp)) {
1512 tprintf("%lu", tcp->u_arg[0]);
1513 }
1514 return 0;
1515}
1516
1517int
1518sys_setsid(tcp)
1519struct tcb *tcp;
1520{
1521 return 0;
1522}
1523
1524int
1525sys_getpgid(tcp)
1526struct tcb *tcp;
1527{
1528 if (entering(tcp)) {
1529 tprintf("%lu", tcp->u_arg[0]);
1530 }
1531 return 0;
1532}
1533
1534int
1535sys_setpgid(tcp)
1536struct tcb *tcp;
1537{
1538 if (entering(tcp)) {
1539 tprintf("%lu, %lu", tcp->u_arg[0], tcp->u_arg[1]);
1540 }
1541 return 0;
1542}
1543
John Hughesc61eb3d2002-05-17 11:37:50 +00001544#if UNIXWARE >= 2
1545
1546#include <sys/privilege.h>
1547
1548
Roland McGrathd9f816f2004-09-04 03:39:20 +00001549static const struct xlat procpriv_cmds [] = {
John Hughesc61eb3d2002-05-17 11:37:50 +00001550 { SETPRV, "SETPRV" },
1551 { CLRPRV, "CLRPRV" },
1552 { PUTPRV, "PUTPRV" },
1553 { GETPRV, "GETPRV" },
1554 { CNTPRV, "CNTPRV" },
1555 { 0, NULL },
1556};
1557
1558
Roland McGrathd9f816f2004-09-04 03:39:20 +00001559static const struct xlat procpriv_priv [] = {
John Hughesc61eb3d2002-05-17 11:37:50 +00001560 { P_OWNER, "P_OWNER" },
1561 { P_AUDIT, "P_AUDIT" },
1562 { P_COMPAT, "P_COMPAT" },
1563 { P_DACREAD, "P_DACREAD" },
1564 { P_DACWRITE, "P_DACWRITE" },
1565 { P_DEV, "P_DEV" },
1566 { P_FILESYS, "P_FILESYS" },
1567 { P_MACREAD, "P_MACREAD" },
1568 { P_MACWRITE, "P_MACWRITE" },
1569 { P_MOUNT, "P_MOUNT" },
1570 { P_MULTIDIR, "P_MULTIDIR" },
1571 { P_SETPLEVEL, "P_SETPLEVEL" },
1572 { P_SETSPRIV, "P_SETSPRIV" },
1573 { P_SETUID, "P_SETUID" },
1574 { P_SYSOPS, "P_SYSOPS" },
1575 { P_SETUPRIV, "P_SETUPRIV" },
1576 { P_DRIVER, "P_DRIVER" },
1577 { P_RTIME, "P_RTIME" },
1578 { P_MACUPGRADE, "P_MACUPGRADE" },
1579 { P_FSYSRANGE, "P_FSYSRANGE" },
1580 { P_SETFLEVEL, "P_SETFLEVEL" },
1581 { P_AUDITWR, "P_AUDITWR" },
1582 { P_TSHAR, "P_TSHAR" },
1583 { P_PLOCK, "P_PLOCK" },
1584 { P_CORE, "P_CORE" },
1585 { P_LOADMOD, "P_LOADMOD" },
1586 { P_BIND, "P_BIND" },
1587 { P_ALLPRIVS, "P_ALLPRIVS" },
1588 { 0, NULL },
1589};
1590
1591
Roland McGrathd9f816f2004-09-04 03:39:20 +00001592static const struct xlat procpriv_type [] = {
John Hughesc61eb3d2002-05-17 11:37:50 +00001593 { PS_FIX, "PS_FIX" },
1594 { PS_INH, "PS_INH" },
1595 { PS_MAX, "PS_MAX" },
1596 { PS_WKG, "PS_WKG" },
1597 { 0, NULL },
1598};
1599
1600
1601static void
Dmitry V. Levinab9008b2007-01-11 22:05:04 +00001602printpriv(struct tcb *tcp, long addr, int len, const struct xlat *opt)
John Hughesc61eb3d2002-05-17 11:37:50 +00001603{
1604 priv_t buf [128];
1605 int max = verbose (tcp) ? sizeof buf / sizeof buf [0] : 10;
1606 int dots = len > max;
1607 int i;
Roland McGrath5a223472002-12-15 23:58:26 +00001608
John Hughesc61eb3d2002-05-17 11:37:50 +00001609 if (len > max) len = max;
Roland McGrath5a223472002-12-15 23:58:26 +00001610
John Hughesc61eb3d2002-05-17 11:37:50 +00001611 if (len <= 0 ||
1612 umoven (tcp, addr, len * sizeof buf[0], (char *) buf) < 0)
1613 {
1614 tprintf ("%#lx", addr);
1615 return;
1616 }
1617
1618 tprintf ("[");
1619
1620 for (i = 0; i < len; ++i) {
Dmitry V. Levinab9008b2007-01-11 22:05:04 +00001621 const char *t, *p;
John Hughesc61eb3d2002-05-17 11:37:50 +00001622
1623 if (i) tprintf (", ");
1624
1625 if ((t = xlookup (procpriv_type, buf [i] & PS_TYPE)) &&
1626 (p = xlookup (procpriv_priv, buf [i] & ~PS_TYPE)))
1627 {
1628 tprintf ("%s|%s", t, p);
1629 }
1630 else {
1631 tprintf ("%#lx", buf [i]);
1632 }
1633 }
1634
1635 if (dots) tprintf (" ...");
1636
1637 tprintf ("]");
1638}
1639
1640
1641int
1642sys_procpriv(tcp)
1643struct tcb *tcp;
1644{
1645 if (entering(tcp)) {
1646 printxval(procpriv_cmds, tcp->u_arg[0], "???PRV");
1647 switch (tcp->u_arg[0]) {
1648 case CNTPRV:
1649 tprintf(", %#lx, %ld", tcp->u_arg[1], tcp->u_arg[2]);
1650 break;
1651
1652 case GETPRV:
1653 break;
1654
1655 default:
1656 tprintf (", ");
1657 printpriv (tcp, tcp->u_arg[1], tcp->u_arg[2]);
1658 tprintf (", %ld", tcp->u_arg[2]);
1659 }
1660 }
1661 else if (tcp->u_arg[0] == GETPRV) {
1662 if (syserror (tcp)) {
1663 tprintf(", %#lx, %ld", tcp->u_arg[1], tcp->u_arg[2]);
1664 }
1665 else {
1666 tprintf (", ");
1667 printpriv (tcp, tcp->u_arg[1], tcp->u_rval);
1668 tprintf (", %ld", tcp->u_arg[2]);
1669 }
1670 }
Roland McGrath5a223472002-12-15 23:58:26 +00001671
John Hughesc61eb3d2002-05-17 11:37:50 +00001672 return 0;
1673}
1674
Dmitry V. Levine5e60852009-12-31 22:50:49 +00001675#endif /* UNIXWARE */
John Hughesc61eb3d2002-05-17 11:37:50 +00001676
1677
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001678static void
Dmitry V. Levin30145dd2010-09-06 22:08:24 +00001679printargv(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001680{
Roland McGrath85a3bc42007-08-02 02:13:05 +00001681 union {
Andreas Schwab99c85692009-08-28 19:36:20 +02001682 unsigned int p32;
1683 unsigned long p64;
Roland McGrath85a3bc42007-08-02 02:13:05 +00001684 char data[sizeof(long)];
1685 } cp;
Dmitry V. Levin30145dd2010-09-06 22:08:24 +00001686 const char *sep;
Roland McGrath85a3bc42007-08-02 02:13:05 +00001687 int n = 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001688
Roland McGrath85a3bc42007-08-02 02:13:05 +00001689 cp.p64 = 1;
1690 for (sep = ""; !abbrev(tcp) || n < max_strlen / 2; sep = ", ", ++n) {
1691 if (umoven(tcp, addr, personality_wordsize[current_personality],
1692 cp.data) < 0) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001693 tprintf("%#lx", addr);
1694 return;
1695 }
Roland McGrath85a3bc42007-08-02 02:13:05 +00001696 if (personality_wordsize[current_personality] == 4)
1697 cp.p64 = cp.p32;
1698 if (cp.p64 == 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001699 break;
Dmitry V. Levin4bcd5ef2009-06-01 10:32:27 +00001700 tprintf("%s", sep);
Roland McGrath85a3bc42007-08-02 02:13:05 +00001701 printstr(tcp, cp.p64, -1);
1702 addr += personality_wordsize[current_personality];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001703 }
Roland McGrath85a3bc42007-08-02 02:13:05 +00001704 if (cp.p64)
1705 tprintf("%s...", sep);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001706}
1707
1708static void
Dmitry V. Levin30145dd2010-09-06 22:08:24 +00001709printargc(const char *fmt, struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001710{
1711 int count;
1712 char *cp;
1713
1714 for (count = 0; umove(tcp, addr, &cp) >= 0 && cp != NULL; count++) {
1715 addr += sizeof(char *);
1716 }
1717 tprintf(fmt, count, count == 1 ? "" : "s");
1718}
1719
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001720#if defined(SPARC) || defined(SPARC64) || defined(SUNOS4)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001721int
Dmitry V. Levine5e60852009-12-31 22:50:49 +00001722sys_execv(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001723{
1724 if (entering(tcp)) {
1725 printpath(tcp, tcp->u_arg[0]);
1726 if (!verbose(tcp))
1727 tprintf(", %#lx", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001728 else {
1729 tprintf(", [");
1730 printargv(tcp, tcp->u_arg[1]);
1731 tprintf("]");
1732 }
1733 }
1734 return 0;
1735}
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001736#endif /* SPARC || SPARC64 || SUNOS4 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001737
1738int
Dmitry V. Levine5e60852009-12-31 22:50:49 +00001739sys_execve(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001740{
1741 if (entering(tcp)) {
1742 printpath(tcp, tcp->u_arg[0]);
1743 if (!verbose(tcp))
1744 tprintf(", %#lx", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001745 else {
1746 tprintf(", [");
1747 printargv(tcp, tcp->u_arg[1]);
1748 tprintf("]");
1749 }
1750 if (!verbose(tcp))
1751 tprintf(", %#lx", tcp->u_arg[2]);
1752 else if (abbrev(tcp))
1753 printargc(", [/* %d var%s */]", tcp, tcp->u_arg[2]);
1754 else {
1755 tprintf(", [");
1756 printargv(tcp, tcp->u_arg[2]);
1757 tprintf("]");
1758 }
1759 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001760 return 0;
1761}
1762
Roland McGrath5ef24ab2004-02-20 02:22:35 +00001763#if UNIXWARE > 2
John Hughes4e36a812001-04-18 15:11:51 +00001764
1765int sys_rexecve(tcp)
1766struct tcb *tcp;
1767{
1768 if (entering (tcp)) {
1769 sys_execve (tcp);
1770 tprintf (", %ld", tcp->u_arg[3]);
1771 }
1772 return 0;
1773}
1774
Roland McGrath5ef24ab2004-02-20 02:22:35 +00001775#endif
John Hughes4e36a812001-04-18 15:11:51 +00001776
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001777int
1778internal_exec(tcp)
1779struct tcb *tcp;
1780{
1781#ifdef SUNOS4
1782 if (exiting(tcp) && !syserror(tcp) && followfork)
1783 fixvfork(tcp);
1784#endif /* SUNOS4 */
Roland McGrathfdb097f2004-07-12 07:38:55 +00001785#if defined LINUX && defined TCB_WAITEXECVE
1786 if (exiting(tcp) && syserror(tcp))
1787 tcp->flags &= ~TCB_WAITEXECVE;
1788 else
1789 tcp->flags |= TCB_WAITEXECVE;
1790#endif /* LINUX && TCB_WAITEXECVE */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001791 return 0;
1792}
1793
1794#ifdef LINUX
Roland McGrath7ec1d352002-12-17 04:50:44 +00001795#ifndef __WNOTHREAD
1796#define __WNOTHREAD 0x20000000
1797#endif
1798#ifndef __WALL
1799#define __WALL 0x40000000
1800#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001801#ifndef __WCLONE
Roland McGrath7ec1d352002-12-17 04:50:44 +00001802#define __WCLONE 0x80000000
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001803#endif
1804#endif /* LINUX */
1805
Roland McGrathd9f816f2004-09-04 03:39:20 +00001806static const struct xlat wait4_options[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001807 { WNOHANG, "WNOHANG" },
1808#ifndef WSTOPPED
1809 { WUNTRACED, "WUNTRACED" },
1810#endif
1811#ifdef WEXITED
1812 { WEXITED, "WEXITED" },
1813#endif
1814#ifdef WTRAPPED
1815 { WTRAPPED, "WTRAPPED" },
1816#endif
1817#ifdef WSTOPPED
1818 { WSTOPPED, "WSTOPPED" },
1819#endif
1820#ifdef WCONTINUED
1821 { WCONTINUED, "WCONTINUED" },
1822#endif
1823#ifdef WNOWAIT
1824 { WNOWAIT, "WNOWAIT" },
1825#endif
1826#ifdef __WCLONE
1827 { __WCLONE, "__WCLONE" },
1828#endif
Roland McGrath7ec1d352002-12-17 04:50:44 +00001829#ifdef __WALL
1830 { __WALL, "__WALL" },
1831#endif
1832#ifdef __WNOTHREAD
1833 { __WNOTHREAD, "__WNOTHREAD" },
1834#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001835 { 0, NULL },
1836};
1837
Roland McGrath5e02a572004-10-19 23:33:47 +00001838#if !defined WCOREFLAG && defined WCOREFLG
1839# define WCOREFLAG WCOREFLG
1840#endif
1841#ifndef WCOREFLAG
Dmitry V. Levine5e60852009-12-31 22:50:49 +00001842# define WCOREFLAG 0x80
Roland McGrath5e02a572004-10-19 23:33:47 +00001843#endif
Dmitry V. Levine5e60852009-12-31 22:50:49 +00001844#ifndef WCOREDUMP
1845# define WCOREDUMP(status) ((status) & 0200)
1846#endif
1847
Roland McGrath5e02a572004-10-19 23:33:47 +00001848
1849#ifndef W_STOPCODE
1850#define W_STOPCODE(sig) ((sig) << 8 | 0x7f)
1851#endif
1852#ifndef W_EXITCODE
1853#define W_EXITCODE(ret, sig) ((ret) << 8 | (sig))
1854#endif
1855
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001856static int
1857printstatus(status)
1858int status;
1859{
1860 int exited = 0;
1861
1862 /*
1863 * Here is a tricky presentation problem. This solution
1864 * is still not entirely satisfactory but since there
1865 * are no wait status constructors it will have to do.
1866 */
Roland McGrath79fbda52004-04-14 02:45:55 +00001867 if (WIFSTOPPED(status)) {
1868 tprintf("[{WIFSTOPPED(s) && WSTOPSIG(s) == %s}",
Nate Sammonsce780fc1999-03-29 23:23:13 +00001869 signame(WSTOPSIG(status)));
Roland McGrath79fbda52004-04-14 02:45:55 +00001870 status &= ~W_STOPCODE(WSTOPSIG(status));
1871 }
1872 else if (WIFSIGNALED(status)) {
1873 tprintf("[{WIFSIGNALED(s) && WTERMSIG(s) == %s%s}",
Nate Sammonsce780fc1999-03-29 23:23:13 +00001874 signame(WTERMSIG(status)),
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001875 WCOREDUMP(status) ? " && WCOREDUMP(s)" : "");
Roland McGrath79fbda52004-04-14 02:45:55 +00001876 status &= ~(W_EXITCODE(0, WTERMSIG(status)) | WCOREFLAG);
1877 }
1878 else if (WIFEXITED(status)) {
1879 tprintf("[{WIFEXITED(s) && WEXITSTATUS(s) == %d}",
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001880 WEXITSTATUS(status));
1881 exited = 1;
Roland McGrath79fbda52004-04-14 02:45:55 +00001882 status &= ~W_EXITCODE(WEXITSTATUS(status), 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001883 }
Roland McGrath79fbda52004-04-14 02:45:55 +00001884 else {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001885 tprintf("[%#x]", status);
Roland McGrath79fbda52004-04-14 02:45:55 +00001886 return 0;
1887 }
1888
1889 if (status == 0)
1890 tprintf("]");
1891 else
Roland McGrathf8cc83c2004-06-04 01:24:07 +00001892 tprintf(" | %#x]", status);
Roland McGrath79fbda52004-04-14 02:45:55 +00001893
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001894 return exited;
1895}
1896
1897static int
Denys Vlasenko59432db2009-01-26 19:09:35 +00001898printwaitn(struct tcb *tcp, int n, int bitness)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001899{
1900 int status;
Dmitry V. Levind9a4b0a2011-02-23 00:27:12 +00001901#ifdef SUNOS4
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001902 int exited = 0;
Dmitry V. Levind9a4b0a2011-02-23 00:27:12 +00001903#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001904
1905 if (entering(tcp)) {
Denys Vlasenkoe740fd32009-04-16 12:06:16 +00001906#ifdef LINUX
1907 /* On Linux, kernel-side pid_t is typedef'ed to int
1908 * on all arches. Also, glibc-2.8 truncates wait3 and wait4
Denys Vlasenko59432db2009-01-26 19:09:35 +00001909 * pid argument to int on 64bit arches, producing,
1910 * for example, wait4(4294967295, ...) instead of -1
Denys Vlasenkoe740fd32009-04-16 12:06:16 +00001911 * in strace. We have to use int here, not long.
1912 */
1913 int pid = tcp->u_arg[0];
1914 tprintf("%d, ", pid);
1915#else
1916 /*
1917 * Sign-extend a 32-bit value when that's what it is.
Roland McGrath5b63d962008-07-18 02:16:47 +00001918 */
1919 long pid = tcp->u_arg[0];
1920 if (personality_wordsize[current_personality] < sizeof pid)
1921 pid = (long) (int) pid;
1922 tprintf("%ld, ", pid);
Denys Vlasenkoe740fd32009-04-16 12:06:16 +00001923#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001924 } else {
1925 /* status */
1926 if (!tcp->u_arg[1])
1927 tprintf("NULL");
1928 else if (syserror(tcp) || tcp->u_rval == 0)
1929 tprintf("%#lx", tcp->u_arg[1]);
1930 else if (umove(tcp, tcp->u_arg[1], &status) < 0)
1931 tprintf("[?]");
1932 else
Dmitry V. Levind9a4b0a2011-02-23 00:27:12 +00001933#ifdef SUNOS4
1934 exited =
1935#endif
1936 printstatus(status);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001937 /* options */
1938 tprintf(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +00001939 printflags(wait4_options, tcp->u_arg[2], "W???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001940 if (n == 4) {
1941 tprintf(", ");
1942 /* usage */
1943 if (!tcp->u_arg[3])
1944 tprintf("NULL");
1945#ifdef LINUX
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001946 else if (tcp->u_rval > 0) {
Denys Vlasenko59432db2009-01-26 19:09:35 +00001947#ifdef ALPHA
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001948 if (bitness)
1949 printrusage32(tcp, tcp->u_arg[3]);
1950 else
1951#endif
1952 printrusage(tcp, tcp->u_arg[3]);
1953 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001954#endif /* LINUX */
1955#ifdef SUNOS4
1956 else if (tcp->u_rval > 0 && exited)
1957 printrusage(tcp, tcp->u_arg[3]);
1958#endif /* SUNOS4 */
1959 else
1960 tprintf("%#lx", tcp->u_arg[3]);
1961 }
1962 }
1963 return 0;
1964}
1965
1966int
Roland McGrathc74c0b72004-09-01 19:39:46 +00001967internal_wait(tcp, flagarg)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001968struct tcb *tcp;
Roland McGrathc74c0b72004-09-01 19:39:46 +00001969int flagarg;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001970{
Roland McGrathe85bbfe2003-01-09 06:53:31 +00001971 int got_kids;
1972
1973#ifdef TCB_CLONE_THREAD
1974 if (tcp->flags & TCB_CLONE_THREAD)
1975 /* The children we wait for are our parent's children. */
1976 got_kids = (tcp->parent->nchildren
Wang Chao21b8db42010-08-27 17:43:16 +08001977 > tcp->parent->nclone_threads);
Roland McGrathe85bbfe2003-01-09 06:53:31 +00001978 else
Wang Chao21b8db42010-08-27 17:43:16 +08001979 got_kids = (tcp->nchildren > tcp->nclone_threads);
Roland McGrathe85bbfe2003-01-09 06:53:31 +00001980#else
1981 got_kids = tcp->nchildren > 0;
1982#endif
1983
1984 if (entering(tcp) && got_kids) {
Roland McGrathb69f81b2002-12-21 23:25:18 +00001985 /* There are children that this parent should block for.
1986 But ptrace made us the parent of the traced children
1987 and the real parent will get ECHILD from the wait call.
1988
1989 XXX If we attached with strace -f -p PID, then there
1990 may be untraced dead children the parent could be reaping
1991 now, but we make him block. */
1992
1993 /* ??? WTA: fix bug with hanging children */
1994
Roland McGrathc74c0b72004-09-01 19:39:46 +00001995 if (!(tcp->u_arg[flagarg] & WNOHANG)) {
Roland McGrath09623452003-05-23 02:27:13 +00001996 /*
1997 * There are traced children. We'll make the parent
1998 * block to avoid a false ECHILD error due to our
1999 * ptrace having stolen the children. However,
2000 * we shouldn't block if there are zombies to reap.
2001 * XXX doesn't handle pgrp matches (u_arg[0]==0,<-1)
2002 */
Roland McGrathfccfb942003-10-01 21:59:44 +00002003 struct tcb *child = NULL;
Roland McGrath09623452003-05-23 02:27:13 +00002004 if (tcp->nzombies > 0 &&
2005 (tcp->u_arg[0] == -1 ||
Roland McGrathfccfb942003-10-01 21:59:44 +00002006 (child = pid2tcb(tcp->u_arg[0])) == NULL))
Roland McGrath09623452003-05-23 02:27:13 +00002007 return 0;
Roland McGrathfccfb942003-10-01 21:59:44 +00002008 if (tcp->u_arg[0] > 0) {
2009 /*
2010 * If the parent waits for a specified child
2011 * PID, then it must get ECHILD right away
2012 * if that PID is not one of its children.
2013 * Make sure that the requested PID matches
2014 * one of the parent's children that we are
2015 * tracing, and don't suspend it otherwise.
2016 */
2017 if (child == NULL)
2018 child = pid2tcb(tcp->u_arg[0]);
2019 if (child == NULL || child->parent != (
2020#ifdef TCB_CLONE_THREAD
2021 (tcp->flags & TCB_CLONE_THREAD)
2022 ? tcp->parent :
2023#endif
Roland McGrathd56a6562005-08-03 11:23:43 +00002024 tcp) ||
2025 (child->flags & TCB_EXITING))
Roland McGrathfccfb942003-10-01 21:59:44 +00002026 return 0;
2027 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002028 tcp->flags |= TCB_SUSPENDED;
2029 tcp->waitpid = tcp->u_arg[0];
Roland McGrathe85bbfe2003-01-09 06:53:31 +00002030#ifdef TCB_CLONE_THREAD
2031 if (tcp->flags & TCB_CLONE_THREAD)
2032 tcp->parent->nclone_waiting++;
2033#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002034 }
2035 }
Roland McGrathe85bbfe2003-01-09 06:53:31 +00002036 if (exiting(tcp) && tcp->u_error == ECHILD && got_kids) {
Roland McGrathc74c0b72004-09-01 19:39:46 +00002037 if (tcp->u_arg[flagarg] & WNOHANG) {
Roland McGrathb69f81b2002-12-21 23:25:18 +00002038 /* We must force a fake result of 0 instead of
2039 the ECHILD error. */
Roland McGrathb69f81b2002-12-21 23:25:18 +00002040 return force_result(tcp, 0, 0);
2041 }
Roland McGrathb69f81b2002-12-21 23:25:18 +00002042 }
Roland McGrath09623452003-05-23 02:27:13 +00002043 else if (exiting(tcp) && tcp->u_error == 0 && tcp->u_rval > 0 &&
2044 tcp->nzombies > 0 && pid2tcb(tcp->u_rval) == NULL) {
2045 /*
2046 * We just reaped a child we don't know about,
2047 * presumably a zombie we already droptcb'd.
2048 */
2049 tcp->nzombies--;
2050 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002051 return 0;
2052}
2053
2054#ifdef SVR4
2055
2056int
2057sys_wait(tcp)
2058struct tcb *tcp;
2059{
2060 if (exiting(tcp)) {
2061 /* The library wrapper stuffs this into the user variable. */
2062 if (!syserror(tcp))
2063 printstatus(getrval2(tcp));
2064 }
2065 return 0;
2066}
2067
2068#endif /* SVR4 */
2069
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002070#ifdef FREEBSD
2071int
2072sys_wait(tcp)
2073struct tcb *tcp;
2074{
2075 int status;
Roland McGrath5a223472002-12-15 23:58:26 +00002076
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002077 if (exiting(tcp)) {
2078 if (!syserror(tcp)) {
2079 if (umove(tcp, tcp->u_arg[0], &status) < 0)
2080 tprintf("%#lx", tcp->u_arg[0]);
2081 else
2082 printstatus(status);
2083 }
2084 }
2085 return 0;
2086}
2087#endif
2088
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002089int
2090sys_waitpid(tcp)
2091struct tcb *tcp;
2092{
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00002093 return printwaitn(tcp, 3, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002094}
2095
2096int
2097sys_wait4(tcp)
2098struct tcb *tcp;
2099{
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00002100 return printwaitn(tcp, 4, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002101}
2102
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00002103#ifdef ALPHA
2104int
2105sys_osf_wait4(tcp)
2106struct tcb *tcp;
2107{
2108 return printwaitn(tcp, 4, 1);
2109}
2110#endif
2111
Roland McGrathc74c0b72004-09-01 19:39:46 +00002112#if defined SVR4 || defined LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002113
Roland McGrathd9f816f2004-09-04 03:39:20 +00002114static const struct xlat waitid_types[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002115 { P_PID, "P_PID" },
Roland McGrathc74c0b72004-09-01 19:39:46 +00002116#ifdef P_PPID
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002117 { P_PPID, "P_PPID" },
Roland McGrathc74c0b72004-09-01 19:39:46 +00002118#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002119 { P_PGID, "P_PGID" },
Roland McGrathc74c0b72004-09-01 19:39:46 +00002120#ifdef P_SID
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002121 { P_SID, "P_SID" },
Roland McGrathc74c0b72004-09-01 19:39:46 +00002122#endif
2123#ifdef P_CID
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002124 { P_CID, "P_CID" },
Roland McGrathc74c0b72004-09-01 19:39:46 +00002125#endif
2126#ifdef P_UID
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002127 { P_UID, "P_UID" },
Roland McGrathc74c0b72004-09-01 19:39:46 +00002128#endif
2129#ifdef P_GID
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002130 { P_GID, "P_GID" },
Roland McGrathc74c0b72004-09-01 19:39:46 +00002131#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002132 { P_ALL, "P_ALL" },
2133#ifdef P_LWPID
2134 { P_LWPID, "P_LWPID" },
2135#endif
2136 { 0, NULL },
2137};
2138
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002139int
Dmitry V. Levin3eb94912010-09-09 23:08:59 +00002140sys_waitid(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002141{
2142 siginfo_t si;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002143
2144 if (entering(tcp)) {
2145 printxval(waitid_types, tcp->u_arg[0], "P_???");
2146 tprintf(", %ld, ", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002147 }
2148 else {
2149 /* siginfo */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002150 if (!tcp->u_arg[2])
2151 tprintf("NULL");
2152 else if (syserror(tcp))
2153 tprintf("%#lx", tcp->u_arg[2]);
2154 else if (umove(tcp, tcp->u_arg[2], &si) < 0)
2155 tprintf("{???}");
2156 else
Denys Vlasenkof535b542009-01-13 18:30:55 +00002157 printsiginfo(&si, verbose(tcp));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002158 /* options */
2159 tprintf(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +00002160 printflags(wait4_options, tcp->u_arg[3], "W???");
Roland McGrath39426a32004-10-06 22:02:59 +00002161 if (tcp->u_nargs > 4) {
2162 /* usage */
2163 tprintf(", ");
2164 if (!tcp->u_arg[4])
2165 tprintf("NULL");
2166 else if (tcp->u_error)
2167 tprintf("%#lx", tcp->u_arg[4]);
2168 else
2169 printrusage(tcp, tcp->u_arg[4]);
2170 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002171 }
2172 return 0;
2173}
2174
Roland McGrathc74c0b72004-09-01 19:39:46 +00002175#endif /* SVR4 or LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002176
2177int
2178sys_alarm(tcp)
2179struct tcb *tcp;
2180{
2181 if (entering(tcp))
2182 tprintf("%lu", tcp->u_arg[0]);
2183 return 0;
2184}
2185
2186int
2187sys_uname(tcp)
2188struct tcb *tcp;
2189{
2190 struct utsname uname;
2191
2192 if (exiting(tcp)) {
2193 if (syserror(tcp) || !verbose(tcp))
2194 tprintf("%#lx", tcp->u_arg[0]);
2195 else if (umove(tcp, tcp->u_arg[0], &uname) < 0)
2196 tprintf("{...}");
2197 else if (!abbrev(tcp)) {
2198
2199 tprintf("{sysname=\"%s\", nodename=\"%s\", ",
2200 uname.sysname, uname.nodename);
2201 tprintf("release=\"%s\", version=\"%s\", ",
2202 uname.release, uname.version);
2203 tprintf("machine=\"%s\"", uname.machine);
2204#ifdef LINUX
2205#ifndef __GLIBC__
2206 tprintf(", domainname=\"%s\"", uname.domainname);
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002207#endif
2208#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002209 tprintf("}");
2210 }
2211 else
2212 tprintf("{sys=\"%s\", node=\"%s\", ...}",
2213 uname.sysname, uname.nodename);
2214 }
2215 return 0;
2216}
2217
2218#ifndef SVR4
2219
Roland McGratheb9e2e82009-06-02 16:49:22 -07002220static const struct xlat ptrace_cmds[] = {
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002221# ifndef FREEBSD
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002222 { PTRACE_TRACEME, "PTRACE_TRACEME" },
2223 { PTRACE_PEEKTEXT, "PTRACE_PEEKTEXT", },
2224 { PTRACE_PEEKDATA, "PTRACE_PEEKDATA", },
2225 { PTRACE_PEEKUSER, "PTRACE_PEEKUSER", },
2226 { PTRACE_POKETEXT, "PTRACE_POKETEXT", },
2227 { PTRACE_POKEDATA, "PTRACE_POKEDATA", },
2228 { PTRACE_POKEUSER, "PTRACE_POKEUSER", },
2229 { PTRACE_CONT, "PTRACE_CONT" },
2230 { PTRACE_KILL, "PTRACE_KILL" },
2231 { PTRACE_SINGLESTEP, "PTRACE_SINGLESTEP" },
2232 { PTRACE_ATTACH, "PTRACE_ATTACH" },
2233 { PTRACE_DETACH, "PTRACE_DETACH" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002234# ifdef PTRACE_GETREGS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002235 { PTRACE_GETREGS, "PTRACE_GETREGS" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002236# endif
2237# ifdef PTRACE_SETREGS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002238 { PTRACE_SETREGS, "PTRACE_SETREGS" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002239# endif
2240# ifdef PTRACE_GETFPREGS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002241 { PTRACE_GETFPREGS, "PTRACE_GETFPREGS", },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002242# endif
2243# ifdef PTRACE_SETFPREGS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002244 { PTRACE_SETFPREGS, "PTRACE_SETFPREGS", },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002245# endif
2246# ifdef PTRACE_GETFPXREGS
Roland McGrathbf621d42003-01-14 09:46:21 +00002247 { PTRACE_GETFPXREGS, "PTRACE_GETFPXREGS", },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002248# endif
2249# ifdef PTRACE_SETFPXREGS
Roland McGrathbf621d42003-01-14 09:46:21 +00002250 { PTRACE_SETFPXREGS, "PTRACE_SETFPXREGS", },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002251# endif
2252# ifdef PTRACE_GETVRREGS
Roland McGrathf04bb482005-05-09 07:45:33 +00002253 { PTRACE_GETVRREGS, "PTRACE_GETVRREGS", },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002254# endif
2255# ifdef PTRACE_SETVRREGS
Roland McGrathf04bb482005-05-09 07:45:33 +00002256 { PTRACE_SETVRREGS, "PTRACE_SETVRREGS", },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002257# endif
2258# ifdef PTRACE_SETOPTIONS
Denys Vlasenkof535b542009-01-13 18:30:55 +00002259 { PTRACE_SETOPTIONS, "PTRACE_SETOPTIONS", },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002260# endif
2261# ifdef PTRACE_GETEVENTMSG
Denys Vlasenkof535b542009-01-13 18:30:55 +00002262 { PTRACE_GETEVENTMSG, "PTRACE_GETEVENTMSG", },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002263# endif
2264# ifdef PTRACE_GETSIGINFO
Denys Vlasenkof535b542009-01-13 18:30:55 +00002265 { PTRACE_GETSIGINFO, "PTRACE_GETSIGINFO", },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002266# endif
2267# ifdef PTRACE_SETSIGINFO
Denys Vlasenkof535b542009-01-13 18:30:55 +00002268 { PTRACE_SETSIGINFO, "PTRACE_SETSIGINFO", },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002269# endif
2270# ifdef PTRACE_SET_SYSCALL
2271 { PTRACE_SET_SYSCALL, "PTRACE_SET_SYSCALL", },
2272# endif
2273# ifdef SUNOS4
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002274 { PTRACE_READDATA, "PTRACE_READDATA" },
2275 { PTRACE_WRITEDATA, "PTRACE_WRITEDATA" },
2276 { PTRACE_READTEXT, "PTRACE_READTEXT" },
2277 { PTRACE_WRITETEXT, "PTRACE_WRITETEXT" },
2278 { PTRACE_GETFPAREGS, "PTRACE_GETFPAREGS" },
2279 { PTRACE_SETFPAREGS, "PTRACE_SETFPAREGS" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002280# ifdef SPARC
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002281 { PTRACE_GETWINDOW, "PTRACE_GETWINDOW" },
2282 { PTRACE_SETWINDOW, "PTRACE_SETWINDOW" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002283# else /* !SPARC */
2284 { PTRACE_22, "PTRACE_22" },
2285 { PTRACE_23, "PTRACE_3" },
2286# endif /* !SPARC */
2287# endif /* SUNOS4 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002288 { PTRACE_SYSCALL, "PTRACE_SYSCALL" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002289# ifdef SUNOS4
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002290 { PTRACE_DUMPCORE, "PTRACE_DUMPCORE" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002291# ifdef I386
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002292 { PTRACE_SETWRBKPT, "PTRACE_SETWRBKPT" },
2293 { PTRACE_SETACBKPT, "PTRACE_SETACBKPT" },
2294 { PTRACE_CLRDR7, "PTRACE_CLRDR7" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002295# else /* !I386 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002296 { PTRACE_26, "PTRACE_26" },
2297 { PTRACE_27, "PTRACE_27" },
2298 { PTRACE_28, "PTRACE_28" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002299# endif /* !I386 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002300 { PTRACE_GETUCODE, "PTRACE_GETUCODE" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002301# endif /* SUNOS4 */
Denys Vlasenkof535b542009-01-13 18:30:55 +00002302
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002303# else /* FREEBSD */
Denys Vlasenkof535b542009-01-13 18:30:55 +00002304
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002305 { PT_TRACE_ME, "PT_TRACE_ME" },
2306 { PT_READ_I, "PT_READ_I" },
2307 { PT_READ_D, "PT_READ_D" },
2308 { PT_WRITE_I, "PT_WRITE_I" },
2309 { PT_WRITE_D, "PT_WRITE_D" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002310# ifdef PT_READ_U
John Hughesa2278142001-09-28 16:21:30 +00002311 { PT_READ_U, "PT_READ_U" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002312# endif
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002313 { PT_CONTINUE, "PT_CONTINUE" },
2314 { PT_KILL, "PT_KILL" },
2315 { PT_STEP, "PT_STEP" },
2316 { PT_ATTACH, "PT_ATTACH" },
2317 { PT_DETACH, "PT_DETACH" },
2318 { PT_GETREGS, "PT_GETREGS" },
2319 { PT_SETREGS, "PT_SETREGS" },
2320 { PT_GETFPREGS, "PT_GETFPREGS" },
2321 { PT_SETFPREGS, "PT_SETFPREGS" },
2322 { PT_GETDBREGS, "PT_GETDBREGS" },
2323 { PT_SETDBREGS, "PT_SETDBREGS" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002324# endif /* FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002325 { 0, NULL },
2326};
2327
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002328# ifndef FREEBSD
2329# ifdef PTRACE_SETOPTIONS
Denys Vlasenkof535b542009-01-13 18:30:55 +00002330static const struct xlat ptrace_setoptions_flags[] = {
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002331# ifdef PTRACE_O_TRACESYSGOOD
Denys Vlasenkof535b542009-01-13 18:30:55 +00002332 { PTRACE_O_TRACESYSGOOD,"PTRACE_O_TRACESYSGOOD" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002333# endif
2334# ifdef PTRACE_O_TRACEFORK
Denys Vlasenkof535b542009-01-13 18:30:55 +00002335 { PTRACE_O_TRACEFORK, "PTRACE_O_TRACEFORK" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002336# endif
2337# ifdef PTRACE_O_TRACEVFORK
Denys Vlasenkof535b542009-01-13 18:30:55 +00002338 { PTRACE_O_TRACEVFORK, "PTRACE_O_TRACEVFORK" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002339# endif
2340# ifdef PTRACE_O_TRACECLONE
Denys Vlasenkof535b542009-01-13 18:30:55 +00002341 { PTRACE_O_TRACECLONE, "PTRACE_O_TRACECLONE" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002342# endif
2343# ifdef PTRACE_O_TRACEEXEC
Denys Vlasenkof535b542009-01-13 18:30:55 +00002344 { PTRACE_O_TRACEEXEC, "PTRACE_O_TRACEEXEC" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002345# endif
2346# ifdef PTRACE_O_TRACEVFORKDONE
Denys Vlasenkof535b542009-01-13 18:30:55 +00002347 { PTRACE_O_TRACEVFORKDONE,"PTRACE_O_TRACEVFORKDONE"},
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002348# endif
2349# ifdef PTRACE_O_TRACEEXIT
Denys Vlasenkof535b542009-01-13 18:30:55 +00002350 { PTRACE_O_TRACEEXIT, "PTRACE_O_TRACEEXIT" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002351# endif
Denys Vlasenkof535b542009-01-13 18:30:55 +00002352 { 0, NULL },
2353};
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002354# endif /* PTRACE_SETOPTIONS */
2355# endif /* !FREEBSD */
Denys Vlasenkof535b542009-01-13 18:30:55 +00002356
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002357# ifndef FREEBSD
Roland McGrathd9f816f2004-09-04 03:39:20 +00002358const struct xlat struct_user_offsets[] = {
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002359# ifdef LINUX
2360# if defined(S390) || defined(S390X)
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00002361 { PT_PSWMASK, "psw_mask" },
2362 { PT_PSWADDR, "psw_addr" },
2363 { PT_GPR0, "gpr0" },
2364 { PT_GPR1, "gpr1" },
2365 { PT_GPR2, "gpr2" },
2366 { PT_GPR3, "gpr3" },
2367 { PT_GPR4, "gpr4" },
2368 { PT_GPR5, "gpr5" },
2369 { PT_GPR6, "gpr6" },
2370 { PT_GPR7, "gpr7" },
2371 { PT_GPR8, "gpr8" },
2372 { PT_GPR9, "gpr9" },
2373 { PT_GPR10, "gpr10" },
2374 { PT_GPR11, "gpr11" },
2375 { PT_GPR12, "gpr12" },
2376 { PT_GPR13, "gpr13" },
2377 { PT_GPR14, "gpr14" },
2378 { PT_GPR15, "gpr15" },
2379 { PT_ACR0, "acr0" },
2380 { PT_ACR1, "acr1" },
2381 { PT_ACR2, "acr2" },
2382 { PT_ACR3, "acr3" },
2383 { PT_ACR4, "acr4" },
2384 { PT_ACR5, "acr5" },
2385 { PT_ACR6, "acr6" },
2386 { PT_ACR7, "acr7" },
2387 { PT_ACR8, "acr8" },
2388 { PT_ACR9, "acr9" },
2389 { PT_ACR10, "acr10" },
2390 { PT_ACR11, "acr11" },
2391 { PT_ACR12, "acr12" },
2392 { PT_ACR13, "acr13" },
2393 { PT_ACR14, "acr14" },
2394 { PT_ACR15, "acr15" },
2395 { PT_ORIGGPR2, "orig_gpr2" },
2396 { PT_FPC, "fpc" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002397# if defined(S390)
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00002398 { PT_FPR0_HI, "fpr0.hi" },
2399 { PT_FPR0_LO, "fpr0.lo" },
2400 { PT_FPR1_HI, "fpr1.hi" },
2401 { PT_FPR1_LO, "fpr1.lo" },
2402 { PT_FPR2_HI, "fpr2.hi" },
2403 { PT_FPR2_LO, "fpr2.lo" },
2404 { PT_FPR3_HI, "fpr3.hi" },
2405 { PT_FPR3_LO, "fpr3.lo" },
2406 { PT_FPR4_HI, "fpr4.hi" },
2407 { PT_FPR4_LO, "fpr4.lo" },
2408 { PT_FPR5_HI, "fpr5.hi" },
2409 { PT_FPR5_LO, "fpr5.lo" },
2410 { PT_FPR6_HI, "fpr6.hi" },
2411 { PT_FPR6_LO, "fpr6.lo" },
2412 { PT_FPR7_HI, "fpr7.hi" },
2413 { PT_FPR7_LO, "fpr7.lo" },
2414 { PT_FPR8_HI, "fpr8.hi" },
2415 { PT_FPR8_LO, "fpr8.lo" },
2416 { PT_FPR9_HI, "fpr9.hi" },
2417 { PT_FPR9_LO, "fpr9.lo" },
2418 { PT_FPR10_HI, "fpr10.hi" },
2419 { PT_FPR10_LO, "fpr10.lo" },
2420 { PT_FPR11_HI, "fpr11.hi" },
2421 { PT_FPR11_LO, "fpr11.lo" },
2422 { PT_FPR12_HI, "fpr12.hi" },
2423 { PT_FPR12_LO, "fpr12.lo" },
2424 { PT_FPR13_HI, "fpr13.hi" },
2425 { PT_FPR13_LO, "fpr13.lo" },
2426 { PT_FPR14_HI, "fpr14.hi" },
2427 { PT_FPR14_LO, "fpr14.lo" },
2428 { PT_FPR15_HI, "fpr15.hi" },
2429 { PT_FPR15_LO, "fpr15.lo" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002430# endif
2431# if defined(S390X)
Michal Ludvig10a88d02002-10-07 14:31:00 +00002432 { PT_FPR0, "fpr0" },
2433 { PT_FPR1, "fpr1" },
2434 { PT_FPR2, "fpr2" },
2435 { PT_FPR3, "fpr3" },
2436 { PT_FPR4, "fpr4" },
2437 { PT_FPR5, "fpr5" },
2438 { PT_FPR6, "fpr6" },
2439 { PT_FPR7, "fpr7" },
2440 { PT_FPR8, "fpr8" },
2441 { PT_FPR9, "fpr9" },
2442 { PT_FPR10, "fpr10" },
2443 { PT_FPR11, "fpr11" },
2444 { PT_FPR12, "fpr12" },
2445 { PT_FPR13, "fpr13" },
2446 { PT_FPR14, "fpr14" },
2447 { PT_FPR15, "fpr15" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002448# endif
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00002449 { PT_CR_9, "cr9" },
2450 { PT_CR_10, "cr10" },
2451 { PT_CR_11, "cr11" },
Michal Ludvig10a88d02002-10-07 14:31:00 +00002452 { PT_IEEE_IP, "ieee_exception_ip" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002453# elif defined(SPARC)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002454 /* XXX No support for these offsets yet. */
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002455# elif defined(HPPA)
Wichert Akkermanc1652e22001-03-27 12:17:16 +00002456 /* XXX No support for these offsets yet. */
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002457# elif defined(POWERPC)
2458# ifndef PT_ORIG_R3
2459# define PT_ORIG_R3 34
2460# endif
2461# define REGSIZE (sizeof(unsigned long))
Roland McGratheb285352003-01-14 09:59:00 +00002462 { REGSIZE*PT_R0, "r0" },
2463 { REGSIZE*PT_R1, "r1" },
2464 { REGSIZE*PT_R2, "r2" },
2465 { REGSIZE*PT_R3, "r3" },
2466 { REGSIZE*PT_R4, "r4" },
2467 { REGSIZE*PT_R5, "r5" },
2468 { REGSIZE*PT_R6, "r6" },
2469 { REGSIZE*PT_R7, "r7" },
2470 { REGSIZE*PT_R8, "r8" },
2471 { REGSIZE*PT_R9, "r9" },
2472 { REGSIZE*PT_R10, "r10" },
2473 { REGSIZE*PT_R11, "r11" },
2474 { REGSIZE*PT_R12, "r12" },
2475 { REGSIZE*PT_R13, "r13" },
2476 { REGSIZE*PT_R14, "r14" },
2477 { REGSIZE*PT_R15, "r15" },
2478 { REGSIZE*PT_R16, "r16" },
2479 { REGSIZE*PT_R17, "r17" },
2480 { REGSIZE*PT_R18, "r18" },
2481 { REGSIZE*PT_R19, "r19" },
2482 { REGSIZE*PT_R20, "r20" },
2483 { REGSIZE*PT_R21, "r21" },
2484 { REGSIZE*PT_R22, "r22" },
2485 { REGSIZE*PT_R23, "r23" },
2486 { REGSIZE*PT_R24, "r24" },
2487 { REGSIZE*PT_R25, "r25" },
2488 { REGSIZE*PT_R26, "r26" },
2489 { REGSIZE*PT_R27, "r27" },
2490 { REGSIZE*PT_R28, "r28" },
2491 { REGSIZE*PT_R29, "r29" },
2492 { REGSIZE*PT_R30, "r30" },
2493 { REGSIZE*PT_R31, "r31" },
2494 { REGSIZE*PT_NIP, "NIP" },
2495 { REGSIZE*PT_MSR, "MSR" },
2496 { REGSIZE*PT_ORIG_R3, "ORIG_R3" },
2497 { REGSIZE*PT_CTR, "CTR" },
2498 { REGSIZE*PT_LNK, "LNK" },
2499 { REGSIZE*PT_XER, "XER" },
2500 { REGSIZE*PT_CCR, "CCR" },
2501 { REGSIZE*PT_FPR0, "FPR0" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002502# undef REGSIZE
2503# elif defined(ALPHA)
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00002504 { 0, "r0" },
2505 { 1, "r1" },
2506 { 2, "r2" },
2507 { 3, "r3" },
2508 { 4, "r4" },
2509 { 5, "r5" },
2510 { 6, "r6" },
2511 { 7, "r7" },
2512 { 8, "r8" },
2513 { 9, "r9" },
2514 { 10, "r10" },
2515 { 11, "r11" },
2516 { 12, "r12" },
2517 { 13, "r13" },
2518 { 14, "r14" },
2519 { 15, "r15" },
2520 { 16, "r16" },
2521 { 17, "r17" },
2522 { 18, "r18" },
2523 { 19, "r19" },
2524 { 20, "r20" },
2525 { 21, "r21" },
2526 { 22, "r22" },
2527 { 23, "r23" },
2528 { 24, "r24" },
2529 { 25, "r25" },
2530 { 26, "r26" },
2531 { 27, "r27" },
2532 { 28, "r28" },
2533 { 29, "gp" },
2534 { 30, "fp" },
2535 { 31, "zero" },
2536 { 32, "fp0" },
2537 { 33, "fp" },
2538 { 34, "fp2" },
2539 { 35, "fp3" },
2540 { 36, "fp4" },
2541 { 37, "fp5" },
2542 { 38, "fp6" },
2543 { 39, "fp7" },
2544 { 40, "fp8" },
2545 { 41, "fp9" },
2546 { 42, "fp10" },
2547 { 43, "fp11" },
2548 { 44, "fp12" },
2549 { 45, "fp13" },
2550 { 46, "fp14" },
2551 { 47, "fp15" },
2552 { 48, "fp16" },
2553 { 49, "fp17" },
2554 { 50, "fp18" },
2555 { 51, "fp19" },
2556 { 52, "fp20" },
2557 { 53, "fp21" },
2558 { 54, "fp22" },
2559 { 55, "fp23" },
2560 { 56, "fp24" },
2561 { 57, "fp25" },
2562 { 58, "fp26" },
2563 { 59, "fp27" },
2564 { 60, "fp28" },
2565 { 61, "fp29" },
2566 { 62, "fp30" },
2567 { 63, "fp31" },
2568 { 64, "pc" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002569# elif defined(IA64)
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00002570 { PT_F32, "f32" }, { PT_F33, "f33" }, { PT_F34, "f34" },
2571 { PT_F35, "f35" }, { PT_F36, "f36" }, { PT_F37, "f37" },
2572 { PT_F38, "f38" }, { PT_F39, "f39" }, { PT_F40, "f40" },
2573 { PT_F41, "f41" }, { PT_F42, "f42" }, { PT_F43, "f43" },
2574 { PT_F44, "f44" }, { PT_F45, "f45" }, { PT_F46, "f46" },
2575 { PT_F47, "f47" }, { PT_F48, "f48" }, { PT_F49, "f49" },
2576 { PT_F50, "f50" }, { PT_F51, "f51" }, { PT_F52, "f52" },
2577 { PT_F53, "f53" }, { PT_F54, "f54" }, { PT_F55, "f55" },
2578 { PT_F56, "f56" }, { PT_F57, "f57" }, { PT_F58, "f58" },
2579 { PT_F59, "f59" }, { PT_F60, "f60" }, { PT_F61, "f61" },
2580 { PT_F62, "f62" }, { PT_F63, "f63" }, { PT_F64, "f64" },
2581 { PT_F65, "f65" }, { PT_F66, "f66" }, { PT_F67, "f67" },
2582 { PT_F68, "f68" }, { PT_F69, "f69" }, { PT_F70, "f70" },
2583 { PT_F71, "f71" }, { PT_F72, "f72" }, { PT_F73, "f73" },
2584 { PT_F74, "f74" }, { PT_F75, "f75" }, { PT_F76, "f76" },
2585 { PT_F77, "f77" }, { PT_F78, "f78" }, { PT_F79, "f79" },
2586 { PT_F80, "f80" }, { PT_F81, "f81" }, { PT_F82, "f82" },
2587 { PT_F83, "f83" }, { PT_F84, "f84" }, { PT_F85, "f85" },
2588 { PT_F86, "f86" }, { PT_F87, "f87" }, { PT_F88, "f88" },
2589 { PT_F89, "f89" }, { PT_F90, "f90" }, { PT_F91, "f91" },
2590 { PT_F92, "f92" }, { PT_F93, "f93" }, { PT_F94, "f94" },
2591 { PT_F95, "f95" }, { PT_F96, "f96" }, { PT_F97, "f97" },
2592 { PT_F98, "f98" }, { PT_F99, "f99" }, { PT_F100, "f100" },
2593 { PT_F101, "f101" }, { PT_F102, "f102" }, { PT_F103, "f103" },
2594 { PT_F104, "f104" }, { PT_F105, "f105" }, { PT_F106, "f106" },
2595 { PT_F107, "f107" }, { PT_F108, "f108" }, { PT_F109, "f109" },
2596 { PT_F110, "f110" }, { PT_F111, "f111" }, { PT_F112, "f112" },
2597 { PT_F113, "f113" }, { PT_F114, "f114" }, { PT_F115, "f115" },
2598 { PT_F116, "f116" }, { PT_F117, "f117" }, { PT_F118, "f118" },
2599 { PT_F119, "f119" }, { PT_F120, "f120" }, { PT_F121, "f121" },
2600 { PT_F122, "f122" }, { PT_F123, "f123" }, { PT_F124, "f124" },
2601 { PT_F125, "f125" }, { PT_F126, "f126" }, { PT_F127, "f127" },
2602 /* switch stack: */
2603 { PT_F2, "f2" }, { PT_F3, "f3" }, { PT_F4, "f4" },
2604 { PT_F5, "f5" }, { PT_F10, "f10" }, { PT_F11, "f11" },
2605 { PT_F12, "f12" }, { PT_F13, "f13" }, { PT_F14, "f14" },
2606 { PT_F15, "f15" }, { PT_F16, "f16" }, { PT_F17, "f17" },
2607 { PT_F18, "f18" }, { PT_F19, "f19" }, { PT_F20, "f20" },
2608 { PT_F21, "f21" }, { PT_F22, "f22" }, { PT_F23, "f23" },
2609 { PT_F24, "f24" }, { PT_F25, "f25" }, { PT_F26, "f26" },
2610 { PT_F27, "f27" }, { PT_F28, "f28" }, { PT_F29, "f29" },
2611 { PT_F30, "f30" }, { PT_F31, "f31" }, { PT_R4, "r4" },
2612 { PT_R5, "r5" }, { PT_R6, "r6" }, { PT_R7, "r7" },
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00002613 { PT_B1, "b1" }, { PT_B2, "b2" }, { PT_B3, "b3" },
2614 { PT_B4, "b4" }, { PT_B5, "b5" },
Roland McGrathca4e10c2004-01-13 10:13:20 +00002615 { PT_AR_EC, "ar.ec" }, { PT_AR_LC, "ar.lc" },
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00002616 /* pt_regs */
Roland McGrathca4e10c2004-01-13 10:13:20 +00002617 { PT_CR_IPSR, "psr" }, { PT_CR_IIP, "ip" },
2618 { PT_CFM, "cfm" }, { PT_AR_UNAT, "ar.unat" },
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00002619 { PT_AR_PFS, "ar.pfs" }, { PT_AR_RSC, "ar.rsc" },
2620 { PT_AR_RNAT, "ar.rnat" }, { PT_AR_BSPSTORE, "ar.bspstore" },
2621 { PT_PR, "pr" }, { PT_B6, "b6" }, { PT_AR_BSP, "ar.bsp" },
2622 { PT_R1, "r1" }, { PT_R2, "r2" }, { PT_R3, "r3" },
2623 { PT_R12, "r12" }, { PT_R13, "r13" }, { PT_R14, "r14" },
2624 { PT_R15, "r15" }, { PT_R8, "r8" }, { PT_R9, "r9" },
2625 { PT_R10, "r10" }, { PT_R11, "r11" }, { PT_R16, "r16" },
2626 { PT_R17, "r17" }, { PT_R18, "r18" }, { PT_R19, "r19" },
2627 { PT_R20, "r20" }, { PT_R21, "r21" }, { PT_R22, "r22" },
2628 { PT_R23, "r23" }, { PT_R24, "r24" }, { PT_R25, "r25" },
2629 { PT_R26, "r26" }, { PT_R27, "r27" }, { PT_R28, "r28" },
2630 { PT_R29, "r29" }, { PT_R30, "r30" }, { PT_R31, "r31" },
2631 { PT_AR_CCV, "ar.ccv" }, { PT_AR_FPSR, "ar.fpsr" },
2632 { PT_B0, "b0" }, { PT_B7, "b7" }, { PT_F6, "f6" },
2633 { PT_F7, "f7" }, { PT_F8, "f8" }, { PT_F9, "f9" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002634# ifdef PT_AR_CSD
Roland McGrathfb1bc072004-03-01 21:29:24 +00002635 { PT_AR_CSD, "ar.csd" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002636# endif
2637# ifdef PT_AR_SSD
Roland McGrathfb1bc072004-03-01 21:29:24 +00002638 { PT_AR_SSD, "ar.ssd" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002639# endif
Roland McGrathca4e10c2004-01-13 10:13:20 +00002640 { PT_DBR, "dbr" }, { PT_IBR, "ibr" }, { PT_PMD, "pmd" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002641# elif defined(I386)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002642 { 4*EBX, "4*EBX" },
2643 { 4*ECX, "4*ECX" },
2644 { 4*EDX, "4*EDX" },
2645 { 4*ESI, "4*ESI" },
2646 { 4*EDI, "4*EDI" },
2647 { 4*EBP, "4*EBP" },
2648 { 4*EAX, "4*EAX" },
2649 { 4*DS, "4*DS" },
2650 { 4*ES, "4*ES" },
2651 { 4*FS, "4*FS" },
2652 { 4*GS, "4*GS" },
2653 { 4*ORIG_EAX, "4*ORIG_EAX" },
2654 { 4*EIP, "4*EIP" },
2655 { 4*CS, "4*CS" },
2656 { 4*EFL, "4*EFL" },
2657 { 4*UESP, "4*UESP" },
2658 { 4*SS, "4*SS" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002659# elif defined(X86_64)
Roland McGratha4f9f2d2005-06-07 23:21:20 +00002660 { 8*R15, "8*R15" },
2661 { 8*R14, "8*R14" },
2662 { 8*R13, "8*R13" },
2663 { 8*R12, "8*R12" },
Michal Ludvig0e035502002-09-23 15:41:01 +00002664 { 8*RBP, "8*RBP" },
Roland McGratha4f9f2d2005-06-07 23:21:20 +00002665 { 8*RBX, "8*RBX" },
2666 { 8*R11, "8*R11" },
2667 { 8*R10, "8*R10" },
2668 { 8*R9, "8*R9" },
2669 { 8*R8, "8*R8" },
Michal Ludvig0e035502002-09-23 15:41:01 +00002670 { 8*RAX, "8*RAX" },
Roland McGratha4f9f2d2005-06-07 23:21:20 +00002671 { 8*RCX, "8*RCX" },
2672 { 8*RDX, "8*RDX" },
2673 { 8*RSI, "8*RSI" },
2674 { 8*RDI, "8*RDI" },
Roland McGratha4f9f2d2005-06-07 23:21:20 +00002675 { 8*ORIG_RAX, "8*ORIG_RAX" },
Michal Ludvig0e035502002-09-23 15:41:01 +00002676 { 8*RIP, "8*RIP" },
2677 { 8*CS, "8*CS" },
2678 { 8*EFLAGS, "8*EFL" },
Roland McGratha4f9f2d2005-06-07 23:21:20 +00002679 { 8*RSP, "8*RSP" },
Michal Ludvig0e035502002-09-23 15:41:01 +00002680 { 8*SS, "8*SS" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002681# elif defined(M68K)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002682 { 4*PT_D1, "4*PT_D1" },
2683 { 4*PT_D2, "4*PT_D2" },
2684 { 4*PT_D3, "4*PT_D3" },
2685 { 4*PT_D4, "4*PT_D4" },
2686 { 4*PT_D5, "4*PT_D5" },
2687 { 4*PT_D6, "4*PT_D6" },
2688 { 4*PT_D7, "4*PT_D7" },
2689 { 4*PT_A0, "4*PT_A0" },
2690 { 4*PT_A1, "4*PT_A1" },
2691 { 4*PT_A2, "4*PT_A2" },
2692 { 4*PT_A3, "4*PT_A3" },
2693 { 4*PT_A4, "4*PT_A4" },
2694 { 4*PT_A5, "4*PT_A5" },
2695 { 4*PT_A6, "4*PT_A6" },
2696 { 4*PT_D0, "4*PT_D0" },
2697 { 4*PT_USP, "4*PT_USP" },
2698 { 4*PT_ORIG_D0, "4*PT_ORIG_D0" },
2699 { 4*PT_SR, "4*PT_SR" },
2700 { 4*PT_PC, "4*PT_PC" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002701# elif defined(SH)
Denys Vlasenkoadedb512008-12-30 18:47:55 +00002702 { 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" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002742# ifdef REG_XDREG0
Denys Vlasenkoadedb512008-12-30 18:47:55 +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" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002751# endif
Denys Vlasenkoadedb512008-12-30 18:47:55 +00002752 { 4*REG_FPSCR, "4*REG_FPSCR" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002753# elif defined(SH64)
Roland McGrathe1e584b2003-06-02 19:18:58 +00002754 { 0, "PC(L)" },
2755 { 4, "PC(U)" },
2756 { 8, "SR(L)" },
2757 { 12, "SR(U)" },
2758 { 16, "syscall no.(L)" },
2759 { 20, "syscall_no.(U)" },
2760 { 24, "R0(L)" },
2761 { 28, "R0(U)" },
2762 { 32, "R1(L)" },
2763 { 36, "R1(U)" },
2764 { 40, "R2(L)" },
2765 { 44, "R2(U)" },
2766 { 48, "R3(L)" },
2767 { 52, "R3(U)" },
2768 { 56, "R4(L)" },
2769 { 60, "R4(U)" },
2770 { 64, "R5(L)" },
2771 { 68, "R5(U)" },
2772 { 72, "R6(L)" },
2773 { 76, "R6(U)" },
2774 { 80, "R7(L)" },
2775 { 84, "R7(U)" },
2776 { 88, "R8(L)" },
2777 { 92, "R8(U)" },
2778 { 96, "R9(L)" },
2779 { 100, "R9(U)" },
2780 { 104, "R10(L)" },
2781 { 108, "R10(U)" },
2782 { 112, "R11(L)" },
2783 { 116, "R11(U)" },
2784 { 120, "R12(L)" },
2785 { 124, "R12(U)" },
2786 { 128, "R13(L)" },
2787 { 132, "R13(U)" },
2788 { 136, "R14(L)" },
2789 { 140, "R14(U)" },
2790 { 144, "R15(L)" },
2791 { 148, "R15(U)" },
2792 { 152, "R16(L)" },
2793 { 156, "R16(U)" },
2794 { 160, "R17(L)" },
2795 { 164, "R17(U)" },
2796 { 168, "R18(L)" },
2797 { 172, "R18(U)" },
2798 { 176, "R19(L)" },
2799 { 180, "R19(U)" },
2800 { 184, "R20(L)" },
2801 { 188, "R20(U)" },
2802 { 192, "R21(L)" },
2803 { 196, "R21(U)" },
2804 { 200, "R22(L)" },
2805 { 204, "R22(U)" },
2806 { 208, "R23(L)" },
2807 { 212, "R23(U)" },
2808 { 216, "R24(L)" },
2809 { 220, "R24(U)" },
2810 { 224, "R25(L)" },
2811 { 228, "R25(U)" },
2812 { 232, "R26(L)" },
2813 { 236, "R26(U)" },
2814 { 240, "R27(L)" },
2815 { 244, "R27(U)" },
2816 { 248, "R28(L)" },
2817 { 252, "R28(U)" },
2818 { 256, "R29(L)" },
2819 { 260, "R29(U)" },
2820 { 264, "R30(L)" },
2821 { 268, "R30(U)" },
2822 { 272, "R31(L)" },
2823 { 276, "R31(U)" },
2824 { 280, "R32(L)" },
2825 { 284, "R32(U)" },
2826 { 288, "R33(L)" },
2827 { 292, "R33(U)" },
2828 { 296, "R34(L)" },
2829 { 300, "R34(U)" },
2830 { 304, "R35(L)" },
2831 { 308, "R35(U)" },
2832 { 312, "R36(L)" },
2833 { 316, "R36(U)" },
2834 { 320, "R37(L)" },
2835 { 324, "R37(U)" },
2836 { 328, "R38(L)" },
2837 { 332, "R38(U)" },
2838 { 336, "R39(L)" },
2839 { 340, "R39(U)" },
2840 { 344, "R40(L)" },
2841 { 348, "R40(U)" },
2842 { 352, "R41(L)" },
2843 { 356, "R41(U)" },
2844 { 360, "R42(L)" },
2845 { 364, "R42(U)" },
2846 { 368, "R43(L)" },
2847 { 372, "R43(U)" },
2848 { 376, "R44(L)" },
2849 { 380, "R44(U)" },
2850 { 384, "R45(L)" },
2851 { 388, "R45(U)" },
2852 { 392, "R46(L)" },
2853 { 396, "R46(U)" },
2854 { 400, "R47(L)" },
2855 { 404, "R47(U)" },
2856 { 408, "R48(L)" },
2857 { 412, "R48(U)" },
2858 { 416, "R49(L)" },
2859 { 420, "R49(U)" },
2860 { 424, "R50(L)" },
2861 { 428, "R50(U)" },
2862 { 432, "R51(L)" },
2863 { 436, "R51(U)" },
2864 { 440, "R52(L)" },
2865 { 444, "R52(U)" },
2866 { 448, "R53(L)" },
2867 { 452, "R53(U)" },
2868 { 456, "R54(L)" },
2869 { 460, "R54(U)" },
2870 { 464, "R55(L)" },
2871 { 468, "R55(U)" },
2872 { 472, "R56(L)" },
2873 { 476, "R56(U)" },
2874 { 480, "R57(L)" },
2875 { 484, "R57(U)" },
2876 { 488, "R58(L)" },
2877 { 492, "R58(U)" },
2878 { 496, "R59(L)" },
2879 { 500, "R59(U)" },
2880 { 504, "R60(L)" },
2881 { 508, "R60(U)" },
2882 { 512, "R61(L)" },
2883 { 516, "R61(U)" },
2884 { 520, "R62(L)" },
2885 { 524, "R62(U)" },
2886 { 528, "TR0(L)" },
2887 { 532, "TR0(U)" },
2888 { 536, "TR1(L)" },
2889 { 540, "TR1(U)" },
2890 { 544, "TR2(L)" },
2891 { 548, "TR2(U)" },
2892 { 552, "TR3(L)" },
2893 { 556, "TR3(U)" },
2894 { 560, "TR4(L)" },
2895 { 564, "TR4(U)" },
2896 { 568, "TR5(L)" },
2897 { 572, "TR5(U)" },
2898 { 576, "TR6(L)" },
2899 { 580, "TR6(U)" },
2900 { 584, "TR7(L)" },
2901 { 588, "TR7(U)" },
Denys Vlasenkoadedb512008-12-30 18:47:55 +00002902 /* This entry is in case pt_regs contains dregs (depends on
2903 the kernel build options). */
Roland McGrathe1e584b2003-06-02 19:18:58 +00002904 { uoff(regs), "offsetof(struct user, regs)" },
2905 { uoff(fpu), "offsetof(struct user, fpu)" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002906# elif defined(ARM)
Roland McGrath0f87c492003-06-03 23:29:04 +00002907 { uoff(regs.ARM_r0), "r0" },
2908 { uoff(regs.ARM_r1), "r1" },
2909 { uoff(regs.ARM_r2), "r2" },
2910 { uoff(regs.ARM_r3), "r3" },
2911 { uoff(regs.ARM_r4), "r4" },
2912 { uoff(regs.ARM_r5), "r5" },
2913 { uoff(regs.ARM_r6), "r6" },
2914 { uoff(regs.ARM_r7), "r7" },
2915 { uoff(regs.ARM_r8), "r8" },
2916 { uoff(regs.ARM_r9), "r9" },
2917 { uoff(regs.ARM_r10), "r10" },
2918 { uoff(regs.ARM_fp), "fp" },
2919 { uoff(regs.ARM_ip), "ip" },
2920 { uoff(regs.ARM_sp), "sp" },
2921 { uoff(regs.ARM_lr), "lr" },
2922 { uoff(regs.ARM_pc), "pc" },
2923 { uoff(regs.ARM_cpsr), "cpsr" },
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +00002924# elif defined(AVR32)
2925 { uoff(regs.sr), "sr" },
2926 { uoff(regs.pc), "pc" },
2927 { uoff(regs.lr), "lr" },
2928 { uoff(regs.sp), "sp" },
2929 { uoff(regs.r12), "r12" },
2930 { uoff(regs.r11), "r11" },
2931 { uoff(regs.r10), "r10" },
2932 { uoff(regs.r9), "r9" },
2933 { uoff(regs.r8), "r8" },
2934 { uoff(regs.r7), "r7" },
2935 { uoff(regs.r6), "r6" },
2936 { uoff(regs.r5), "r5" },
2937 { uoff(regs.r4), "r4" },
2938 { uoff(regs.r3), "r3" },
2939 { uoff(regs.r2), "r2" },
2940 { uoff(regs.r1), "r1" },
2941 { uoff(regs.r0), "r0" },
2942 { uoff(regs.r12_orig), "orig_r12" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002943# elif defined(MIPS)
Roland McGrath542c2c62008-05-20 01:11:56 +00002944 { 0, "r0" },
2945 { 1, "r1" },
2946 { 2, "r2" },
2947 { 3, "r3" },
2948 { 4, "r4" },
2949 { 5, "r5" },
2950 { 6, "r6" },
2951 { 7, "r7" },
2952 { 8, "r8" },
2953 { 9, "r9" },
2954 { 10, "r10" },
2955 { 11, "r11" },
2956 { 12, "r12" },
2957 { 13, "r13" },
2958 { 14, "r14" },
2959 { 15, "r15" },
2960 { 16, "r16" },
2961 { 17, "r17" },
2962 { 18, "r18" },
2963 { 19, "r19" },
2964 { 20, "r20" },
2965 { 21, "r21" },
2966 { 22, "r22" },
2967 { 23, "r23" },
2968 { 24, "r24" },
2969 { 25, "r25" },
2970 { 26, "r26" },
2971 { 27, "r27" },
2972 { 28, "r28" },
2973 { 29, "r29" },
2974 { 30, "r30" },
2975 { 31, "r31" },
2976 { 32, "f0" },
2977 { 33, "f1" },
2978 { 34, "f2" },
2979 { 35, "f3" },
2980 { 36, "f4" },
2981 { 37, "f5" },
2982 { 38, "f6" },
2983 { 39, "f7" },
2984 { 40, "f8" },
2985 { 41, "f9" },
2986 { 42, "f10" },
2987 { 43, "f11" },
2988 { 44, "f12" },
2989 { 45, "f13" },
2990 { 46, "f14" },
2991 { 47, "f15" },
2992 { 48, "f16" },
2993 { 49, "f17" },
2994 { 50, "f18" },
2995 { 51, "f19" },
2996 { 52, "f20" },
2997 { 53, "f21" },
2998 { 54, "f22" },
2999 { 55, "f23" },
3000 { 56, "f24" },
3001 { 57, "f25" },
3002 { 58, "f26" },
3003 { 59, "f27" },
3004 { 60, "f28" },
3005 { 61, "f29" },
3006 { 62, "f30" },
3007 { 63, "f31" },
3008 { 64, "pc" },
3009 { 65, "cause" },
3010 { 66, "badvaddr" },
3011 { 67, "mmhi" },
3012 { 68, "mmlo" },
3013 { 69, "fpcsr" },
3014 { 70, "fpeir" },
Chris Metcalfc8c66982009-12-28 10:00:15 -05003015# elif defined(TILE)
3016 { PTREGS_OFFSET_REG(0), "r0" },
3017 { PTREGS_OFFSET_REG(1), "r1" },
3018 { PTREGS_OFFSET_REG(2), "r2" },
3019 { PTREGS_OFFSET_REG(3), "r3" },
3020 { PTREGS_OFFSET_REG(4), "r4" },
3021 { PTREGS_OFFSET_REG(5), "r5" },
3022 { PTREGS_OFFSET_REG(6), "r6" },
3023 { PTREGS_OFFSET_REG(7), "r7" },
3024 { PTREGS_OFFSET_REG(8), "r8" },
3025 { PTREGS_OFFSET_REG(9), "r9" },
3026 { PTREGS_OFFSET_REG(10), "r10" },
3027 { PTREGS_OFFSET_REG(11), "r11" },
3028 { PTREGS_OFFSET_REG(12), "r12" },
3029 { PTREGS_OFFSET_REG(13), "r13" },
3030 { PTREGS_OFFSET_REG(14), "r14" },
3031 { PTREGS_OFFSET_REG(15), "r15" },
3032 { PTREGS_OFFSET_REG(16), "r16" },
3033 { PTREGS_OFFSET_REG(17), "r17" },
3034 { PTREGS_OFFSET_REG(18), "r18" },
3035 { PTREGS_OFFSET_REG(19), "r19" },
3036 { PTREGS_OFFSET_REG(20), "r20" },
3037 { PTREGS_OFFSET_REG(21), "r21" },
3038 { PTREGS_OFFSET_REG(22), "r22" },
3039 { PTREGS_OFFSET_REG(23), "r23" },
3040 { PTREGS_OFFSET_REG(24), "r24" },
3041 { PTREGS_OFFSET_REG(25), "r25" },
3042 { PTREGS_OFFSET_REG(26), "r26" },
3043 { PTREGS_OFFSET_REG(27), "r27" },
3044 { PTREGS_OFFSET_REG(28), "r28" },
3045 { PTREGS_OFFSET_REG(29), "r29" },
3046 { PTREGS_OFFSET_REG(30), "r30" },
3047 { PTREGS_OFFSET_REG(31), "r31" },
3048 { PTREGS_OFFSET_REG(32), "r32" },
3049 { PTREGS_OFFSET_REG(33), "r33" },
3050 { PTREGS_OFFSET_REG(34), "r34" },
3051 { PTREGS_OFFSET_REG(35), "r35" },
3052 { PTREGS_OFFSET_REG(36), "r36" },
3053 { PTREGS_OFFSET_REG(37), "r37" },
3054 { PTREGS_OFFSET_REG(38), "r38" },
3055 { PTREGS_OFFSET_REG(39), "r39" },
3056 { PTREGS_OFFSET_REG(40), "r40" },
3057 { PTREGS_OFFSET_REG(41), "r41" },
3058 { PTREGS_OFFSET_REG(42), "r42" },
3059 { PTREGS_OFFSET_REG(43), "r43" },
3060 { PTREGS_OFFSET_REG(44), "r44" },
3061 { PTREGS_OFFSET_REG(45), "r45" },
3062 { PTREGS_OFFSET_REG(46), "r46" },
3063 { PTREGS_OFFSET_REG(47), "r47" },
3064 { PTREGS_OFFSET_REG(48), "r48" },
3065 { PTREGS_OFFSET_REG(49), "r49" },
3066 { PTREGS_OFFSET_REG(50), "r50" },
3067 { PTREGS_OFFSET_REG(51), "r51" },
3068 { PTREGS_OFFSET_REG(52), "r52" },
3069 { PTREGS_OFFSET_TP, "tp" },
3070 { PTREGS_OFFSET_SP, "sp" },
3071 { PTREGS_OFFSET_LR, "lr" },
3072 { PTREGS_OFFSET_PC, "pc" },
3073 { PTREGS_OFFSET_EX1, "ex1" },
3074 { PTREGS_OFFSET_FAULTNUM, "faultnum" },
3075 { PTREGS_OFFSET_ORIG_R0, "orig_r0" },
3076 { PTREGS_OFFSET_FLAGS, "flags" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003077# endif
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00003078# ifdef CRISV10
3079 { 4*PT_FRAMETYPE, "4*PT_FRAMETYPE" },
3080 { 4*PT_ORIG_R10, "4*PT_ORIG_R10" },
3081 { 4*PT_R13, "4*PT_R13" },
3082 { 4*PT_R12, "4*PT_R12" },
3083 { 4*PT_R11, "4*PT_R11" },
3084 { 4*PT_R10, "4*PT_R10" },
3085 { 4*PT_R9, "4*PT_R9" },
3086 { 4*PT_R8, "4*PT_R8" },
3087 { 4*PT_R7, "4*PT_R7" },
3088 { 4*PT_R6, "4*PT_R6" },
3089 { 4*PT_R5, "4*PT_R5" },
3090 { 4*PT_R4, "4*PT_R4" },
3091 { 4*PT_R3, "4*PT_R3" },
3092 { 4*PT_R2, "4*PT_R2" },
3093 { 4*PT_R1, "4*PT_R1" },
3094 { 4*PT_R0, "4*PT_R0" },
3095 { 4*PT_MOF, "4*PT_MOF" },
3096 { 4*PT_DCCR, "4*PT_DCCR" },
3097 { 4*PT_SRP, "4*PT_SRP" },
3098 { 4*PT_IRP, "4*PT_IRP" },
3099 { 4*PT_CSRINSTR, "4*PT_CSRINSTR" },
3100 { 4*PT_CSRADDR, "4*PT_CSRADDR" },
3101 { 4*PT_CSRDATA, "4*PT_CSRDATA" },
3102 { 4*PT_USP, "4*PT_USP" },
3103# endif
3104# ifdef CRISV32
3105 { 4*PT_ORIG_R10, "4*PT_ORIG_R10" },
3106 { 4*PT_R0, "4*PT_R0" },
3107 { 4*PT_R1, "4*PT_R1" },
3108 { 4*PT_R2, "4*PT_R2" },
3109 { 4*PT_R3, "4*PT_R3" },
3110 { 4*PT_R4, "4*PT_R4" },
3111 { 4*PT_R5, "4*PT_R5" },
3112 { 4*PT_R6, "4*PT_R6" },
3113 { 4*PT_R7, "4*PT_R7" },
3114 { 4*PT_R8, "4*PT_R8" },
3115 { 4*PT_R9, "4*PT_R9" },
3116 { 4*PT_R10, "4*PT_R10" },
3117 { 4*PT_R11, "4*PT_R11" },
3118 { 4*PT_R12, "4*PT_R12" },
3119 { 4*PT_R13, "4*PT_R13" },
3120 { 4*PT_ACR, "4*PT_ACR" },
3121 { 4*PT_SRS, "4*PT_SRS" },
3122 { 4*PT_MOF, "4*PT_MOF" },
3123 { 4*PT_SPC, "4*PT_SPC" },
3124 { 4*PT_CCS, "4*PT_CCS" },
3125 { 4*PT_SRP, "4*PT_SRP" },
3126 { 4*PT_ERP, "4*PT_ERP" },
3127 { 4*PT_EXS, "4*PT_EXS" },
3128 { 4*PT_EDA, "4*PT_EDA" },
3129 { 4*PT_USP, "4*PT_USP" },
3130 { 4*PT_PPC, "4*PT_PPC" },
3131 { 4*PT_BP_CTRL, "4*PT_BP_CTRL" },
3132 { 4*PT_BP+4, "4*PT_BP+4" },
3133 { 4*PT_BP+8, "4*PT_BP+8" },
3134 { 4*PT_BP+12, "4*PT_BP+12" },
3135 { 4*PT_BP+16, "4*PT_BP+16" },
3136 { 4*PT_BP+20, "4*PT_BP+20" },
3137 { 4*PT_BP+24, "4*PT_BP+24" },
3138 { 4*PT_BP+28, "4*PT_BP+28" },
3139 { 4*PT_BP+32, "4*PT_BP+32" },
3140 { 4*PT_BP+36, "4*PT_BP+36" },
3141 { 4*PT_BP+40, "4*PT_BP+40" },
3142 { 4*PT_BP+44, "4*PT_BP+44" },
3143 { 4*PT_BP+48, "4*PT_BP+48" },
3144 { 4*PT_BP+52, "4*PT_BP+52" },
3145 { 4*PT_BP+56, "4*PT_BP+56" },
3146# endif
Edgar E. Iglesias939caba2010-07-06 14:21:07 +02003147# ifdef MICROBLAZE
3148 { PT_GPR(0), "r0" },
3149 { PT_GPR(1), "r1" },
3150 { PT_GPR(2), "r2" },
3151 { PT_GPR(3), "r3" },
3152 { PT_GPR(4), "r4" },
3153 { PT_GPR(5), "r5" },
3154 { PT_GPR(6), "r6" },
3155 { PT_GPR(7), "r7" },
3156 { PT_GPR(8), "r8" },
3157 { PT_GPR(9), "r9" },
3158 { PT_GPR(10), "r10" },
3159 { PT_GPR(11), "r11" },
3160 { PT_GPR(12), "r12" },
3161 { PT_GPR(13), "r13" },
3162 { PT_GPR(14), "r14" },
3163 { PT_GPR(15), "r15" },
3164 { PT_GPR(16), "r16" },
3165 { PT_GPR(17), "r17" },
3166 { PT_GPR(18), "r18" },
3167 { PT_GPR(19), "r19" },
3168 { PT_GPR(20), "r20" },
3169 { PT_GPR(21), "r21" },
3170 { PT_GPR(22), "r22" },
3171 { PT_GPR(23), "r23" },
3172 { PT_GPR(24), "r24" },
3173 { PT_GPR(25), "r25" },
3174 { PT_GPR(26), "r26" },
3175 { PT_GPR(27), "r27" },
3176 { PT_GPR(28), "r28" },
3177 { PT_GPR(29), "r29" },
3178 { PT_GPR(30), "r30" },
3179 { PT_GPR(31), "r31" },
3180 { PT_PC, "rpc", },
3181 { PT_MSR, "rmsr", },
3182 { PT_EAR, "rear", },
3183 { PT_ESR, "resr", },
3184 { PT_FSR, "rfsr", },
3185 { PT_KERNEL_MODE, "kernel_mode", },
3186# endif
Roland McGrath542c2c62008-05-20 01:11:56 +00003187
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00003188# if !defined(SPARC) && !defined(HPPA) && !defined(POWERPC) \
3189 && !defined(ALPHA) && !defined(IA64) \
Edgar E. Iglesias939caba2010-07-06 14:21:07 +02003190 && !defined(CRISV10) && !defined(CRISV32) && !defined(MICROBLAZE)
Chris Metcalfc8c66982009-12-28 10:00:15 -05003191# if !defined(S390) && !defined(S390X) && !defined(MIPS) && !defined(SPARC64) && !defined(AVR32) && !defined(BFIN) && !defined(TILE)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003192 { uoff(u_fpvalid), "offsetof(struct user, u_fpvalid)" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003193# endif
3194# if defined(I386) || defined(X86_64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003195 { uoff(i387), "offsetof(struct user, i387)" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003196# endif
3197# if defined(M68K)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003198 { uoff(m68kfp), "offsetof(struct user, m68kfp)" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003199# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003200 { uoff(u_tsize), "offsetof(struct user, u_tsize)" },
3201 { uoff(u_dsize), "offsetof(struct user, u_dsize)" },
3202 { uoff(u_ssize), "offsetof(struct user, u_ssize)" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003203# if !defined(SPARC64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003204 { uoff(start_code), "offsetof(struct user, start_code)" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003205# endif
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +00003206# if defined(AVR32) || defined(SH64)
Roland McGrathe1e584b2003-06-02 19:18:58 +00003207 { uoff(start_data), "offsetof(struct user, start_data)" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003208# endif
3209# if !defined(SPARC64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003210 { uoff(start_stack), "offsetof(struct user, start_stack)" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003211# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003212 { uoff(signal), "offsetof(struct user, signal)" },
Chris Metcalfc8c66982009-12-28 10:00:15 -05003213# if !defined(AVR32) && !defined(S390) && !defined(S390X) && !defined(MIPS) && !defined(SH) && !defined(SH64) && !defined(SPARC64) && !defined(TILE)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003214 { uoff(reserved), "offsetof(struct user, reserved)" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003215# endif
3216# if !defined(SPARC64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003217 { uoff(u_ar0), "offsetof(struct user, u_ar0)" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003218# endif
Chris Metcalfc8c66982009-12-28 10:00:15 -05003219# if !defined(ARM) && !defined(AVR32) && !defined(MIPS) && !defined(S390) && !defined(S390X) && !defined(SPARC64) && !defined(BFIN) && !defined(TILE)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003220 { uoff(u_fpstate), "offsetof(struct user, u_fpstate)" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003221# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003222 { uoff(magic), "offsetof(struct user, magic)" },
3223 { uoff(u_comm), "offsetof(struct user, u_comm)" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003224# if defined(I386) || defined(X86_64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003225 { uoff(u_debugreg), "offsetof(struct user, u_debugreg)" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003226# endif
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00003227# endif /* !defined(many arches) */
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003228
3229# endif /* LINUX */
3230
3231# ifdef SUNOS4
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003232 { uoff(u_pcb), "offsetof(struct user, u_pcb)" },
3233 { uoff(u_procp), "offsetof(struct user, u_procp)" },
3234 { uoff(u_ar0), "offsetof(struct user, u_ar0)" },
3235 { uoff(u_comm[0]), "offsetof(struct user, u_comm[0])" },
3236 { uoff(u_arg[0]), "offsetof(struct user, u_arg[0])" },
3237 { uoff(u_ap), "offsetof(struct user, u_ap)" },
3238 { uoff(u_qsave), "offsetof(struct user, u_qsave)" },
3239 { uoff(u_rval1), "offsetof(struct user, u_rval1)" },
3240 { uoff(u_rval2), "offsetof(struct user, u_rval2)" },
3241 { uoff(u_error), "offsetof(struct user, u_error)" },
3242 { uoff(u_eosys), "offsetof(struct user, u_eosys)" },
3243 { uoff(u_ssave), "offsetof(struct user, u_ssave)" },
3244 { uoff(u_signal[0]), "offsetof(struct user, u_signal)" },
3245 { uoff(u_sigmask[0]), "offsetof(struct user, u_sigmask)" },
3246 { uoff(u_sigonstack), "offsetof(struct user, u_sigonstack)" },
3247 { uoff(u_sigintr), "offsetof(struct user, u_sigintr)" },
3248 { uoff(u_sigreset), "offsetof(struct user, u_sigreset)" },
3249 { uoff(u_oldmask), "offsetof(struct user, u_oldmask)" },
3250 { uoff(u_code), "offsetof(struct user, u_code)" },
3251 { uoff(u_addr), "offsetof(struct user, u_addr)" },
3252 { uoff(u_sigstack), "offsetof(struct user, u_sigstack)" },
3253 { uoff(u_ofile), "offsetof(struct user, u_ofile)" },
3254 { uoff(u_pofile), "offsetof(struct user, u_pofile)" },
3255 { uoff(u_ofile_arr[0]), "offsetof(struct user, u_ofile_arr[0])" },
3256 { uoff(u_pofile_arr[0]),"offsetof(struct user, u_pofile_arr[0])"},
3257 { uoff(u_lastfile), "offsetof(struct user, u_lastfile)" },
3258 { uoff(u_cwd), "offsetof(struct user, u_cwd)" },
3259 { uoff(u_cdir), "offsetof(struct user, u_cdir)" },
3260 { uoff(u_rdir), "offsetof(struct user, u_rdir)" },
3261 { uoff(u_cmask), "offsetof(struct user, u_cmask)" },
3262 { uoff(u_ru), "offsetof(struct user, u_ru)" },
3263 { uoff(u_cru), "offsetof(struct user, u_cru)" },
3264 { uoff(u_timer[0]), "offsetof(struct user, u_timer[0])" },
3265 { uoff(u_XXX[0]), "offsetof(struct user, u_XXX[0])" },
3266 { uoff(u_ioch), "offsetof(struct user, u_ioch)" },
3267 { uoff(u_start), "offsetof(struct user, u_start)" },
3268 { uoff(u_acflag), "offsetof(struct user, u_acflag)" },
3269 { uoff(u_prof.pr_base), "offsetof(struct user, u_prof.pr_base)" },
3270 { uoff(u_prof.pr_size), "offsetof(struct user, u_prof.pr_size)" },
3271 { uoff(u_prof.pr_off), "offsetof(struct user, u_prof.pr_off)" },
3272 { uoff(u_prof.pr_scale),"offsetof(struct user, u_prof.pr_scale)"},
3273 { uoff(u_rlimit[0]), "offsetof(struct user, u_rlimit)" },
3274 { uoff(u_exdata.Ux_A), "offsetof(struct user, u_exdata.Ux_A)" },
3275 { uoff(u_exdata.ux_shell[0]),"offsetof(struct user, u_exdata.ux_shell[0])"},
3276 { uoff(u_lofault), "offsetof(struct user, u_lofault)" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003277# endif /* SUNOS4 */
3278# ifndef HPPA
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003279 { sizeof(struct user), "sizeof(struct user)" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003280# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003281 { 0, NULL },
3282};
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003283# endif /* !FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003284
3285int
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003286sys_ptrace(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003287{
Roland McGrathd9f816f2004-09-04 03:39:20 +00003288 const struct xlat *x;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003289 long addr;
3290
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003291 if (entering(tcp)) {
Roland McGrathbf621d42003-01-14 09:46:21 +00003292 printxval(ptrace_cmds, tcp->u_arg[0],
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003293# ifndef FREEBSD
Roland McGrathbf621d42003-01-14 09:46:21 +00003294 "PTRACE_???"
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003295# else
Roland McGrathbf621d42003-01-14 09:46:21 +00003296 "PT_???"
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003297# endif
Roland McGrathbf621d42003-01-14 09:46:21 +00003298 );
3299 tprintf(", %lu, ", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003300 addr = tcp->u_arg[2];
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003301# ifndef FREEBSD
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003302 if (tcp->u_arg[0] == PTRACE_PEEKUSER
3303 || tcp->u_arg[0] == PTRACE_POKEUSER) {
3304 for (x = struct_user_offsets; x->str; x++) {
3305 if (x->val >= addr)
3306 break;
3307 }
3308 if (!x->str)
3309 tprintf("%#lx, ", addr);
3310 else if (x->val > addr && x != struct_user_offsets) {
3311 x--;
3312 tprintf("%s + %ld, ", x->str, addr - x->val);
3313 }
3314 else
3315 tprintf("%s, ", x->str);
3316 }
3317 else
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003318# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003319 tprintf("%#lx, ", tcp->u_arg[2]);
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003320# ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003321 switch (tcp->u_arg[0]) {
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003322# ifndef IA64
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003323 case PTRACE_PEEKDATA:
3324 case PTRACE_PEEKTEXT:
3325 case PTRACE_PEEKUSER:
3326 break;
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003327# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003328 case PTRACE_CONT:
3329 case PTRACE_SINGLESTEP:
3330 case PTRACE_SYSCALL:
3331 case PTRACE_DETACH:
3332 printsignal(tcp->u_arg[3]);
3333 break;
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003334# ifdef PTRACE_SETOPTIONS
Denys Vlasenkof535b542009-01-13 18:30:55 +00003335 case PTRACE_SETOPTIONS:
3336 printflags(ptrace_setoptions_flags, tcp->u_arg[3], "PTRACE_O_???");
3337 break;
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003338# endif
3339# ifdef PTRACE_SETSIGINFO
Denys Vlasenkof535b542009-01-13 18:30:55 +00003340 case PTRACE_SETSIGINFO: {
3341 siginfo_t si;
3342 if (!tcp->u_arg[3])
3343 tprintf("NULL");
3344 else if (syserror(tcp))
3345 tprintf("%#lx", tcp->u_arg[3]);
3346 else if (umove(tcp, tcp->u_arg[3], &si) < 0)
3347 tprintf("{???}");
3348 else
3349 printsiginfo(&si, verbose(tcp));
3350 break;
3351 }
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003352# endif
3353# ifdef PTRACE_GETSIGINFO
Denys Vlasenkof535b542009-01-13 18:30:55 +00003354 case PTRACE_GETSIGINFO:
3355 /* Don't print anything, do it at syscall return. */
3356 break;
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003357# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003358 default:
3359 tprintf("%#lx", tcp->u_arg[3]);
3360 break;
3361 }
3362 } else {
3363 switch (tcp->u_arg[0]) {
3364 case PTRACE_PEEKDATA:
3365 case PTRACE_PEEKTEXT:
3366 case PTRACE_PEEKUSER:
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003367# ifdef IA64
Roland McGrath1e868062007-11-19 22:11:45 +00003368 return RVAL_HEX;
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003369# else
Roland McGratheb285352003-01-14 09:59:00 +00003370 printnum(tcp, tcp->u_arg[3], "%#lx");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003371 break;
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003372# endif
3373# ifdef PTRACE_GETSIGINFO
Denys Vlasenkof535b542009-01-13 18:30:55 +00003374 case PTRACE_GETSIGINFO: {
3375 siginfo_t si;
3376 if (!tcp->u_arg[3])
3377 tprintf("NULL");
3378 else if (syserror(tcp))
3379 tprintf("%#lx", tcp->u_arg[3]);
3380 else if (umove(tcp, tcp->u_arg[3], &si) < 0)
3381 tprintf("{???}");
3382 else
3383 printsiginfo(&si, verbose(tcp));
3384 break;
3385 }
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003386# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003387 }
3388 }
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003389# endif /* LINUX */
3390# ifdef SUNOS4
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003391 if (tcp->u_arg[0] == PTRACE_WRITEDATA ||
3392 tcp->u_arg[0] == PTRACE_WRITETEXT) {
3393 tprintf("%lu, ", tcp->u_arg[3]);
3394 printstr(tcp, tcp->u_arg[4], tcp->u_arg[3]);
3395 } else if (tcp->u_arg[0] != PTRACE_READDATA &&
3396 tcp->u_arg[0] != PTRACE_READTEXT) {
3397 tprintf("%#lx", tcp->u_arg[3]);
3398 }
3399 } else {
3400 if (tcp->u_arg[0] == PTRACE_READDATA ||
3401 tcp->u_arg[0] == PTRACE_READTEXT) {
3402 tprintf("%lu, ", tcp->u_arg[3]);
3403 printstr(tcp, tcp->u_arg[4], tcp->u_arg[3]);
3404 }
3405 }
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003406# endif /* SUNOS4 */
3407# ifdef FREEBSD
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00003408 tprintf("%lu", tcp->u_arg[3]);
3409 }
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003410# endif /* FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003411 return 0;
3412}
3413
3414#endif /* !SVR4 */
Roland McGrath5a223472002-12-15 23:58:26 +00003415
3416#ifdef LINUX
Roland McGrath51942a92007-07-05 18:59:11 +00003417# ifndef FUTEX_CMP_REQUEUE
3418# define FUTEX_CMP_REQUEUE 4
3419# endif
3420# ifndef FUTEX_WAKE_OP
3421# define FUTEX_WAKE_OP 5
3422# endif
3423# ifndef FUTEX_LOCK_PI
3424# define FUTEX_LOCK_PI 6
3425# define FUTEX_UNLOCK_PI 7
3426# define FUTEX_TRYLOCK_PI 8
3427# endif
Roland McGrath1aeaf742008-07-18 01:27:39 +00003428# ifndef FUTEX_WAIT_BITSET
3429# define FUTEX_WAIT_BITSET 9
3430# endif
3431# ifndef FUTEX_WAKE_BITSET
3432# define FUTEX_WAKE_BITSET 10
Roland McGrath51942a92007-07-05 18:59:11 +00003433# endif
Andreas Schwab85f58322009-08-12 09:54:42 +02003434# ifndef FUTEX_WAIT_REQUEUE_PI
3435# define FUTEX_WAIT_REQUEUE_PI 11
3436# endif
3437# ifndef FUTEX_CMP_REQUEUE_PI
3438# define FUTEX_CMP_REQUEUE_PI 12
3439# endif
Roland McGrath51942a92007-07-05 18:59:11 +00003440# ifndef FUTEX_PRIVATE_FLAG
3441# define FUTEX_PRIVATE_FLAG 128
3442# endif
Andreas Schwab85f58322009-08-12 09:54:42 +02003443# ifndef FUTEX_CLOCK_REALTIME
3444# define FUTEX_CLOCK_REALTIME 256
3445# endif
Roland McGrathd9f816f2004-09-04 03:39:20 +00003446static const struct xlat futexops[] = {
Roland McGrath51942a92007-07-05 18:59:11 +00003447 { FUTEX_WAIT, "FUTEX_WAIT" },
3448 { FUTEX_WAKE, "FUTEX_WAKE" },
3449 { FUTEX_FD, "FUTEX_FD" },
3450 { FUTEX_REQUEUE, "FUTEX_REQUEUE" },
3451 { FUTEX_CMP_REQUEUE, "FUTEX_CMP_REQUEUE" },
3452 { FUTEX_WAKE_OP, "FUTEX_WAKE_OP" },
3453 { FUTEX_LOCK_PI, "FUTEX_LOCK_PI" },
3454 { FUTEX_UNLOCK_PI, "FUTEX_UNLOCK_PI" },
3455 { FUTEX_TRYLOCK_PI, "FUTEX_TRYLOCK_PI" },
Roland McGrath1aeaf742008-07-18 01:27:39 +00003456 { FUTEX_WAIT_BITSET, "FUTEX_WAIT_BITSET" },
3457 { FUTEX_WAKE_BITSET, "FUTEX_WAKE_BITSET" },
Andreas Schwab85f58322009-08-12 09:54:42 +02003458 { FUTEX_WAIT_REQUEUE_PI, "FUTEX_WAIT_REQUEUE_PI" },
3459 { FUTEX_CMP_REQUEUE_PI, "FUTEX_CMP_REQUEUE_PI" },
Roland McGrath51942a92007-07-05 18:59:11 +00003460 { FUTEX_WAIT|FUTEX_PRIVATE_FLAG, "FUTEX_WAIT_PRIVATE" },
3461 { FUTEX_WAKE|FUTEX_PRIVATE_FLAG, "FUTEX_WAKE_PRIVATE" },
3462 { FUTEX_FD|FUTEX_PRIVATE_FLAG, "FUTEX_FD_PRIVATE" },
3463 { FUTEX_REQUEUE|FUTEX_PRIVATE_FLAG, "FUTEX_REQUEUE_PRIVATE" },
3464 { FUTEX_CMP_REQUEUE|FUTEX_PRIVATE_FLAG, "FUTEX_CMP_REQUEUE_PRIVATE" },
3465 { FUTEX_WAKE_OP|FUTEX_PRIVATE_FLAG, "FUTEX_WAKE_OP_PRIVATE" },
3466 { FUTEX_LOCK_PI|FUTEX_PRIVATE_FLAG, "FUTEX_LOCK_PI_PRIVATE" },
3467 { FUTEX_UNLOCK_PI|FUTEX_PRIVATE_FLAG, "FUTEX_UNLOCK_PI_PRIVATE" },
3468 { FUTEX_TRYLOCK_PI|FUTEX_PRIVATE_FLAG, "FUTEX_TRYLOCK_PI_PRIVATE" },
Roland McGrath1aeaf742008-07-18 01:27:39 +00003469 { FUTEX_WAIT_BITSET|FUTEX_PRIVATE_FLAG, "FUTEX_WAIT_BITSET_PRIVATE" },
3470 { FUTEX_WAKE_BITSET|FUTEX_PRIVATE_FLAG, "FUTEX_WAKE_BITSET_PRIVATE" },
Andreas Schwab85f58322009-08-12 09:54:42 +02003471 { FUTEX_WAIT_REQUEUE_PI|FUTEX_PRIVATE_FLAG, "FUTEX_WAIT_REQUEUE_PI_PRIVATE" },
3472 { FUTEX_CMP_REQUEUE_PI|FUTEX_PRIVATE_FLAG, "FUTEX_CMP_REQUEUE_PI_PRIVATE" },
3473 { FUTEX_WAIT_BITSET|FUTEX_CLOCK_REALTIME, "FUTEX_WAIT_BITSET|FUTEX_CLOCK_REALTIME" },
3474 { FUTEX_WAIT_BITSET|FUTEX_PRIVATE_FLAG|FUTEX_CLOCK_REALTIME, "FUTEX_WAIT_BITSET_PRIVATE|FUTEX_CLOCK_REALTIME" },
3475 { FUTEX_WAIT_REQUEUE_PI|FUTEX_CLOCK_REALTIME, "FUTEX_WAIT_REQUEUE_PI|FUTEX_CLOCK_REALTIME" },
3476 { FUTEX_WAIT_REQUEUE_PI|FUTEX_PRIVATE_FLAG|FUTEX_CLOCK_REALTIME, "FUTEX_WAIT_REQUEUE_PI_PRIVATE|FUTEX_CLOCK_REALTIME" },
Roland McGrath51942a92007-07-05 18:59:11 +00003477 { 0, NULL }
3478};
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003479# ifndef FUTEX_OP_SET
3480# define FUTEX_OP_SET 0
3481# define FUTEX_OP_ADD 1
3482# define FUTEX_OP_OR 2
3483# define FUTEX_OP_ANDN 3
3484# define FUTEX_OP_XOR 4
3485# define FUTEX_OP_CMP_EQ 0
3486# define FUTEX_OP_CMP_NE 1
3487# define FUTEX_OP_CMP_LT 2
3488# define FUTEX_OP_CMP_LE 3
3489# define FUTEX_OP_CMP_GT 4
3490# define FUTEX_OP_CMP_GE 5
3491# endif
Roland McGrath51942a92007-07-05 18:59:11 +00003492static const struct xlat futexwakeops[] = {
3493 { FUTEX_OP_SET, "FUTEX_OP_SET" },
3494 { FUTEX_OP_ADD, "FUTEX_OP_ADD" },
3495 { FUTEX_OP_OR, "FUTEX_OP_OR" },
3496 { FUTEX_OP_ANDN, "FUTEX_OP_ANDN" },
3497 { FUTEX_OP_XOR, "FUTEX_OP_XOR" },
3498 { 0, NULL }
3499};
3500static const struct xlat futexwakecmps[] = {
3501 { FUTEX_OP_CMP_EQ, "FUTEX_OP_CMP_EQ" },
3502 { FUTEX_OP_CMP_NE, "FUTEX_OP_CMP_NE" },
3503 { FUTEX_OP_CMP_LT, "FUTEX_OP_CMP_LT" },
3504 { FUTEX_OP_CMP_LE, "FUTEX_OP_CMP_LE" },
3505 { FUTEX_OP_CMP_GT, "FUTEX_OP_CMP_GT" },
3506 { FUTEX_OP_CMP_GE, "FUTEX_OP_CMP_GE" },
3507 { 0, NULL }
Roland McGrath5a223472002-12-15 23:58:26 +00003508};
3509
3510int
Denys Vlasenko1d632462009-04-14 12:51:00 +00003511sys_futex(struct tcb *tcp)
Roland McGrath5a223472002-12-15 23:58:26 +00003512{
Denys Vlasenko1d632462009-04-14 12:51:00 +00003513 if (entering(tcp)) {
3514 long int cmd = tcp->u_arg[1] & 127;
3515 tprintf("%p, ", (void *) tcp->u_arg[0]);
3516 printxval(futexops, tcp->u_arg[1], "FUTEX_???");
3517 tprintf(", %ld", tcp->u_arg[2]);
3518 if (cmd == FUTEX_WAKE_BITSET)
3519 tprintf(", %lx", tcp->u_arg[5]);
3520 else if (cmd == FUTEX_WAIT) {
3521 tprintf(", ");
3522 printtv(tcp, tcp->u_arg[3]);
3523 } else if (cmd == FUTEX_WAIT_BITSET) {
3524 tprintf(", ");
3525 printtv(tcp, tcp->u_arg[3]);
3526 tprintf(", %lx", tcp->u_arg[5]);
3527 } else if (cmd == FUTEX_REQUEUE)
3528 tprintf(", %ld, %p", tcp->u_arg[3], (void *) tcp->u_arg[4]);
Andreas Schwab85f58322009-08-12 09:54:42 +02003529 else if (cmd == FUTEX_CMP_REQUEUE || cmd == FUTEX_CMP_REQUEUE_PI)
Denys Vlasenko1d632462009-04-14 12:51:00 +00003530 tprintf(", %ld, %p, %ld", tcp->u_arg[3], (void *) tcp->u_arg[4], tcp->u_arg[5]);
3531 else if (cmd == FUTEX_WAKE_OP) {
3532 tprintf(", %ld, %p, {", tcp->u_arg[3], (void *) tcp->u_arg[4]);
3533 if ((tcp->u_arg[5] >> 28) & 8)
3534 tprintf("FUTEX_OP_OPARG_SHIFT|");
3535 printxval(futexwakeops, (tcp->u_arg[5] >> 28) & 0x7, "FUTEX_OP_???");
3536 tprintf(", %ld, ", (tcp->u_arg[5] >> 12) & 0xfff);
3537 if ((tcp->u_arg[5] >> 24) & 8)
3538 tprintf("FUTEX_OP_OPARG_SHIFT|");
3539 printxval(futexwakecmps, (tcp->u_arg[5] >> 24) & 0x7, "FUTEX_OP_CMP_???");
3540 tprintf(", %ld}", tcp->u_arg[5] & 0xfff);
Andreas Schwab85f58322009-08-12 09:54:42 +02003541 } else if (cmd == FUTEX_WAIT_REQUEUE_PI) {
3542 tprintf(", ");
3543 printtv(tcp, tcp->u_arg[3]);
3544 tprintf(", %p", (void *) tcp->u_arg[4]);
Denys Vlasenko1d632462009-04-14 12:51:00 +00003545 }
Roland McGrath51942a92007-07-05 18:59:11 +00003546 }
Denys Vlasenko1d632462009-04-14 12:51:00 +00003547 return 0;
Roland McGrath5a223472002-12-15 23:58:26 +00003548}
3549
3550static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00003551print_affinitylist(struct tcb *tcp, long list, unsigned int len)
Roland McGrath5a223472002-12-15 23:58:26 +00003552{
Denys Vlasenko1d632462009-04-14 12:51:00 +00003553 int first = 1;
Dmitry V. Levin62e05962009-11-03 14:38:44 +00003554 unsigned long w, min_len;
3555
3556 if (abbrev(tcp) && len / sizeof(w) > max_strlen)
3557 min_len = len - max_strlen * sizeof(w);
3558 else
3559 min_len = 0;
3560 for (; len >= sizeof(w) && len > min_len;
3561 len -= sizeof(w), list += sizeof(w)) {
3562 if (umove(tcp, list, &w) < 0)
3563 break;
3564 if (first)
3565 tprintf("{");
3566 else
3567 tprintf(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00003568 first = 0;
Dmitry V. Levin62e05962009-11-03 14:38:44 +00003569 tprintf("%lx", w);
Denys Vlasenko1d632462009-04-14 12:51:00 +00003570 }
Dmitry V. Levin62e05962009-11-03 14:38:44 +00003571 if (len) {
3572 if (first)
3573 tprintf("%#lx", list);
3574 else
3575 tprintf(", %s}", (len >= sizeof(w) && len > min_len ?
3576 "???" : "..."));
3577 } else {
3578 tprintf(first ? "{}" : "}");
3579 }
Roland McGrath5a223472002-12-15 23:58:26 +00003580}
3581
3582int
Denys Vlasenko1d632462009-04-14 12:51:00 +00003583sys_sched_setaffinity(struct tcb *tcp)
Roland McGrath5a223472002-12-15 23:58:26 +00003584{
Denys Vlasenko1d632462009-04-14 12:51:00 +00003585 if (entering(tcp)) {
3586 tprintf("%ld, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
3587 print_affinitylist(tcp, tcp->u_arg[2], tcp->u_arg[1]);
3588 }
3589 return 0;
Roland McGrath5a223472002-12-15 23:58:26 +00003590}
3591
3592int
Denys Vlasenko1d632462009-04-14 12:51:00 +00003593sys_sched_getaffinity(struct tcb *tcp)
Roland McGrath5a223472002-12-15 23:58:26 +00003594{
Denys Vlasenko1d632462009-04-14 12:51:00 +00003595 if (entering(tcp)) {
3596 tprintf("%ld, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
3597 } else {
3598 if (tcp->u_rval == -1)
3599 tprintf("%#lx", tcp->u_arg[2]);
3600 else
3601 print_affinitylist(tcp, tcp->u_arg[2], tcp->u_rval);
3602 }
3603 return 0;
Roland McGrath5a223472002-12-15 23:58:26 +00003604}
Roland McGrath279d3782004-03-01 20:27:37 +00003605
Roland McGrathd9f816f2004-09-04 03:39:20 +00003606static const struct xlat schedulers[] = {
Roland McGrath279d3782004-03-01 20:27:37 +00003607 { SCHED_OTHER, "SCHED_OTHER" },
3608 { SCHED_RR, "SCHED_RR" },
3609 { SCHED_FIFO, "SCHED_FIFO" },
3610 { 0, NULL }
3611};
3612
3613int
Denys Vlasenko1d632462009-04-14 12:51:00 +00003614sys_sched_getscheduler(struct tcb *tcp)
Roland McGrath279d3782004-03-01 20:27:37 +00003615{
Denys Vlasenko1d632462009-04-14 12:51:00 +00003616 if (entering(tcp)) {
3617 tprintf("%d", (int) tcp->u_arg[0]);
3618 } else if (! syserror(tcp)) {
3619 tcp->auxstr = xlookup (schedulers, tcp->u_rval);
3620 if (tcp->auxstr != NULL)
3621 return RVAL_STR;
3622 }
3623 return 0;
Roland McGrath279d3782004-03-01 20:27:37 +00003624}
3625
3626int
Denys Vlasenko1d632462009-04-14 12:51:00 +00003627sys_sched_setscheduler(struct tcb *tcp)
Roland McGrath279d3782004-03-01 20:27:37 +00003628{
Denys Vlasenko1d632462009-04-14 12:51:00 +00003629 if (entering(tcp)) {
3630 struct sched_param p;
3631 tprintf("%d, ", (int) tcp->u_arg[0]);
3632 printxval(schedulers, tcp->u_arg[1], "SCHED_???");
3633 if (umove(tcp, tcp->u_arg[2], &p) < 0)
3634 tprintf(", %#lx", tcp->u_arg[2]);
3635 else
3636 tprintf(", { %d }", p.__sched_priority);
3637 }
3638 return 0;
Roland McGrath279d3782004-03-01 20:27:37 +00003639}
3640
3641int
Denys Vlasenko1d632462009-04-14 12:51:00 +00003642sys_sched_getparam(struct tcb *tcp)
Roland McGrath279d3782004-03-01 20:27:37 +00003643{
Denys Vlasenko1d632462009-04-14 12:51:00 +00003644 if (entering(tcp)) {
3645 tprintf("%d, ", (int) tcp->u_arg[0]);
3646 } else {
3647 struct sched_param p;
3648 if (umove(tcp, tcp->u_arg[1], &p) < 0)
3649 tprintf("%#lx", tcp->u_arg[1]);
3650 else
3651 tprintf("{ %d }", p.__sched_priority);
3652 }
3653 return 0;
Roland McGrath279d3782004-03-01 20:27:37 +00003654}
3655
3656int
Denys Vlasenko1d632462009-04-14 12:51:00 +00003657sys_sched_setparam(struct tcb *tcp)
Roland McGrath279d3782004-03-01 20:27:37 +00003658{
Denys Vlasenko1d632462009-04-14 12:51:00 +00003659 if (entering(tcp)) {
3660 struct sched_param p;
3661 if (umove(tcp, tcp->u_arg[1], &p) < 0)
3662 tprintf("%d, %#lx", (int) tcp->u_arg[0], tcp->u_arg[1]);
3663 else
3664 tprintf("%d, { %d }", (int) tcp->u_arg[0], p.__sched_priority);
3665 }
3666 return 0;
Roland McGrath279d3782004-03-01 20:27:37 +00003667}
3668
3669int
Denys Vlasenko1d632462009-04-14 12:51:00 +00003670sys_sched_get_priority_min(struct tcb *tcp)
Roland McGrath279d3782004-03-01 20:27:37 +00003671{
Denys Vlasenko1d632462009-04-14 12:51:00 +00003672 if (entering(tcp)) {
3673 printxval(schedulers, tcp->u_arg[0], "SCHED_???");
3674 }
3675 return 0;
Roland McGrath279d3782004-03-01 20:27:37 +00003676}
Roland McGrathc2d5eb02005-02-02 04:16:56 +00003677
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003678# ifdef X86_64
3679# include <asm/prctl.h>
Roland McGrathc2d5eb02005-02-02 04:16:56 +00003680
3681static const struct xlat archvals[] = {
3682 { ARCH_SET_GS, "ARCH_SET_GS" },
3683 { ARCH_SET_FS, "ARCH_SET_FS" },
3684 { ARCH_GET_FS, "ARCH_GET_FS" },
3685 { ARCH_GET_GS, "ARCH_GET_GS" },
3686 { 0, NULL },
3687};
3688
3689int
Denys Vlasenko1d632462009-04-14 12:51:00 +00003690sys_arch_prctl(struct tcb *tcp)
Roland McGrathc2d5eb02005-02-02 04:16:56 +00003691{
Denys Vlasenko1d632462009-04-14 12:51:00 +00003692 if (entering(tcp)) {
3693 printxval(archvals, tcp->u_arg[0], "ARCH_???");
3694 if (tcp->u_arg[0] == ARCH_SET_GS
3695 || tcp->u_arg[0] == ARCH_SET_FS
3696 ) {
3697 tprintf(", %#lx", tcp->u_arg[1]);
3698 }
3699 } else {
3700 if (tcp->u_arg[0] == ARCH_GET_GS
3701 || tcp->u_arg[0] == ARCH_GET_FS
3702 ) {
3703 long int v;
3704 if (!syserror(tcp) && umove(tcp, tcp->u_arg[1], &v) != -1)
3705 tprintf(", [%#lx]", v);
3706 else
3707 tprintf(", %#lx", tcp->u_arg[1]);
3708 }
Roland McGrathc2d5eb02005-02-02 04:16:56 +00003709 }
Denys Vlasenko1d632462009-04-14 12:51:00 +00003710 return 0;
Roland McGrathc2d5eb02005-02-02 04:16:56 +00003711}
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003712# endif /* X86_64 */
Roland McGrathc2d5eb02005-02-02 04:16:56 +00003713
Roland McGrathdb8319f2007-08-02 01:37:55 +00003714
3715int
Denys Vlasenko1d632462009-04-14 12:51:00 +00003716sys_getcpu(struct tcb *tcp)
Roland McGrathdb8319f2007-08-02 01:37:55 +00003717{
3718 if (exiting(tcp)) {
3719 unsigned u;
3720 if (tcp->u_arg[0] == 0)
3721 tprintf("NULL, ");
3722 else if (umove(tcp, tcp->u_arg[0], &u) < 0)
3723 tprintf("%#lx, ", tcp->u_arg[0]);
3724 else
3725 tprintf("[%u], ", u);
3726 if (tcp->u_arg[1] == 0)
3727 tprintf("NULL, ");
3728 else if (umove(tcp, tcp->u_arg[1], &u) < 0)
3729 tprintf("%#lx, ", tcp->u_arg[1]);
3730 else
3731 tprintf("[%u], ", u);
3732 tprintf("%#lx", tcp->u_arg[2]);
3733 }
3734 return 0;
3735}
3736
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003737#endif /* LINUX */