blob: 764abaf6f1bb88b6b84fd50821e783f54c6c3fca [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
446internal_exit(tcp)
447struct tcb *tcp;
448{
Roland McGrathe85bbfe2003-01-09 06:53:31 +0000449 if (entering(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000450 tcp->flags |= TCB_EXITING;
Roland McGrathe85bbfe2003-01-09 06:53:31 +0000451#ifdef __NR_exit_group
Roland McGrath08267b82004-02-20 22:56:43 +0000452# ifdef IA64
453 if (ia32) {
454 if (tcp->scno == 252)
455 tcp->flags |= TCB_GROUP_EXITING;
456 } else
457# endif
Roland McGratha4f9f2d2005-06-07 23:21:20 +0000458 if (known_scno(tcp) == __NR_exit_group)
Roland McGrathe85bbfe2003-01-09 06:53:31 +0000459 tcp->flags |= TCB_GROUP_EXITING;
460#endif
461 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000462 return 0;
463}
464
Roland McGratheb9e2e82009-06-02 16:49:22 -0700465/* TCP is creating a child we want to follow.
466 If there will be space in tcbtab for it, set TCB_FOLLOWFORK and return 0.
467 If not, clear TCB_FOLLOWFORK, print an error, and return 1. */
468static void
469fork_tcb(struct tcb *tcp)
470{
471 if (nprocs == tcbtabsize)
472 expand_tcbtab();
473
474 tcp->flags |= TCB_FOLLOWFORK;
475}
476
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000477#ifdef USE_PROCFS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000478
479int
Denys Vlasenko418d66a2009-01-17 01:52:54 +0000480sys_fork(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000481{
Dmitry V. Levin21a75342008-09-03 01:22:18 +0000482 if (exiting(tcp) && !syserror(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000483 if (getrval2(tcp)) {
484 tcp->auxstr = "child process";
485 return RVAL_UDECIMAL | RVAL_STR;
486 }
487 }
488 return 0;
489}
490
John Hughes4e36a812001-04-18 15:11:51 +0000491#if UNIXWARE > 2
492
493int
494sys_rfork(tcp)
495struct tcb *tcp;
496{
497 if (entering(tcp)) {
498 tprintf ("%ld", tcp->u_arg[0]);
499 }
Dmitry V. Levin21a75342008-09-03 01:22:18 +0000500 else if (!syserror(tcp)) {
John Hughes4e36a812001-04-18 15:11:51 +0000501 if (getrval2(tcp)) {
502 tcp->auxstr = "child process";
503 return RVAL_UDECIMAL | RVAL_STR;
504 }
505 }
506 return 0;
507}
508
509#endif
510
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000511int
512internal_fork(tcp)
513struct tcb *tcp;
514{
515 struct tcb *tcpchild;
516
517 if (exiting(tcp)) {
Roland McGrathf3a0e1b2003-02-20 02:45:22 +0000518#ifdef SYS_rfork
Roland McGratha4f9f2d2005-06-07 23:21:20 +0000519 if (known_scno(tcp) == SYS_rfork && !(tcp->u_arg[0]&RFPROC))
Roland McGrathf3a0e1b2003-02-20 02:45:22 +0000520 return 0;
521#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000522 if (getrval2(tcp))
523 return 0;
524 if (!followfork)
525 return 0;
Roland McGratheb9e2e82009-06-02 16:49:22 -0700526 fork_tcb(tcp);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000527 if (syserror(tcp))
528 return 0;
Denys Vlasenko418d66a2009-01-17 01:52:54 +0000529 tcpchild = alloctcb(tcp->u_rval);
Wichert Akkerman2e4ffe52000-09-03 23:57:48 +0000530 if (proc_open(tcpchild, 2) < 0)
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +0000531 droptcb(tcpchild);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000532 }
533 return 0;
534}
535
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000536#else /* !USE_PROCFS */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000537
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000538#ifdef LINUX
539
540/* defines copied from linux/sched.h since we can't include that
541 * ourselves (it conflicts with *lots* of libc includes)
542 */
543#define CSIGNAL 0x000000ff /* signal mask to be sent at exit */
544#define CLONE_VM 0x00000100 /* set if VM shared between processes */
545#define CLONE_FS 0x00000200 /* set if fs info shared between processes */
546#define CLONE_FILES 0x00000400 /* set if open files shared between processes */
547#define CLONE_SIGHAND 0x00000800 /* set if signal handlers shared */
Roland McGrath909875b2002-12-22 03:34:36 +0000548#define CLONE_IDLETASK 0x00001000 /* kernel-only flag */
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000549#define CLONE_PTRACE 0x00002000 /* set if we want to let tracing continue on the child too */
550#define CLONE_VFORK 0x00004000 /* set if the parent wants the child to wake it up on mm_release */
551#define CLONE_PARENT 0x00008000 /* set if we want to have the same parent as the cloner */
Roland McGrath909875b2002-12-22 03:34:36 +0000552#define CLONE_THREAD 0x00010000 /* Same thread group? */
553#define CLONE_NEWNS 0x00020000 /* New namespace group? */
554#define CLONE_SYSVSEM 0x00040000 /* share system V SEM_UNDO semantics */
555#define CLONE_SETTLS 0x00080000 /* create a new TLS for the child */
556#define CLONE_PARENT_SETTID 0x00100000 /* set the TID in the parent */
557#define CLONE_CHILD_CLEARTID 0x00200000 /* clear the TID in the child */
Roland McGrath909875b2002-12-22 03:34:36 +0000558#define CLONE_UNTRACED 0x00800000 /* set if the tracing process can't force CLONE_PTRACE on this clone */
559#define CLONE_CHILD_SETTID 0x01000000 /* set the TID in the child */
Dmitry V. Levine3d4b682010-12-03 17:19:51 +0000560#define CLONE_STOPPED 0x02000000 /* Start in stopped state */
561#define CLONE_NEWUTS 0x04000000 /* New utsname group? */
562#define CLONE_NEWIPC 0x08000000 /* New ipcs */
563#define CLONE_NEWUSER 0x10000000 /* New user namespace */
564#define CLONE_NEWPID 0x20000000 /* New pid namespace */
565#define CLONE_NEWNET 0x40000000 /* New network namespace */
566#define CLONE_IO 0x80000000 /* Clone io context */
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000567
Roland McGrathd9f816f2004-09-04 03:39:20 +0000568static const struct xlat clone_flags[] = {
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000569 { CLONE_VM, "CLONE_VM" },
570 { CLONE_FS, "CLONE_FS" },
571 { CLONE_FILES, "CLONE_FILES" },
572 { CLONE_SIGHAND, "CLONE_SIGHAND" },
Roland McGrath909875b2002-12-22 03:34:36 +0000573 { CLONE_IDLETASK, "CLONE_IDLETASK"},
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000574 { CLONE_PTRACE, "CLONE_PTRACE" },
575 { CLONE_VFORK, "CLONE_VFORK" },
576 { CLONE_PARENT, "CLONE_PARENT" },
Roland McGrath909875b2002-12-22 03:34:36 +0000577 { CLONE_THREAD, "CLONE_THREAD" },
578 { CLONE_NEWNS, "CLONE_NEWNS" },
579 { CLONE_SYSVSEM, "CLONE_SYSVSEM" },
580 { CLONE_SETTLS, "CLONE_SETTLS" },
581 { CLONE_PARENT_SETTID,"CLONE_PARENT_SETTID" },
582 { CLONE_CHILD_CLEARTID,"CLONE_CHILD_CLEARTID" },
Roland McGrath909875b2002-12-22 03:34:36 +0000583 { CLONE_UNTRACED, "CLONE_UNTRACED" },
584 { CLONE_CHILD_SETTID,"CLONE_CHILD_SETTID" },
Dmitry V. Levine3d4b682010-12-03 17:19:51 +0000585 { CLONE_STOPPED, "CLONE_STOPPED" },
586 { CLONE_NEWUTS, "CLONE_NEWUTS" },
587 { CLONE_NEWIPC, "CLONE_NEWIPC" },
588 { CLONE_NEWUSER, "CLONE_NEWUSER" },
589 { CLONE_NEWPID, "CLONE_NEWPID" },
590 { CLONE_NEWNET, "CLONE_NEWNET" },
591 { CLONE_IO, "CLONE_IO" },
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000592 { 0, NULL },
593};
594
Roland McGrath909875b2002-12-22 03:34:36 +0000595# ifdef I386
596# include <asm/ldt.h>
Roland McGrath7decfb22004-03-01 22:10:52 +0000597# ifdef HAVE_STRUCT_USER_DESC
598# define modify_ldt_ldt_s user_desc
599# endif
Roland McGrath909875b2002-12-22 03:34:36 +0000600extern void print_ldt_entry();
601# endif
602
Roland McGrath9677b3a2003-03-12 09:54:36 +0000603# if defined IA64
604# define ARG_FLAGS 0
605# define ARG_STACK 1
Roland McGratha4f9f2d2005-06-07 23:21:20 +0000606# define ARG_STACKSIZE (known_scno(tcp) == SYS_clone2 ? 2 : -1)
607# define ARG_PTID (known_scno(tcp) == SYS_clone2 ? 3 : 2)
608# define ARG_CTID (known_scno(tcp) == SYS_clone2 ? 4 : 3)
609# define ARG_TLS (known_scno(tcp) == SYS_clone2 ? 5 : 4)
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +0000610# elif defined S390 || defined S390X || defined CRISV10 || defined CRISV32
Roland McGrath9677b3a2003-03-12 09:54:36 +0000611# define ARG_STACK 0
612# define ARG_FLAGS 1
613# define ARG_PTID 2
Roland McGrathfe5fdb22003-05-23 00:29:05 +0000614# define ARG_CTID 3
615# define ARG_TLS 4
Roland McGrath9c555e72003-07-09 09:47:59 +0000616# elif defined X86_64 || defined ALPHA
Roland McGrath361aac52003-03-18 07:43:42 +0000617# define ARG_FLAGS 0
618# define ARG_STACK 1
619# define ARG_PTID 2
620# define ARG_CTID 3
621# define ARG_TLS 4
Roland McGrath9677b3a2003-03-12 09:54:36 +0000622# else
623# define ARG_FLAGS 0
624# define ARG_STACK 1
625# define ARG_PTID 2
626# define ARG_TLS 3
627# define ARG_CTID 4
628# endif
629
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000630int
631sys_clone(tcp)
632struct tcb *tcp;
633{
634 if (exiting(tcp)) {
Wang Chaocbdd1902010-09-02 15:08:59 +0800635 const char *sep = "|";
Roland McGrath9677b3a2003-03-12 09:54:36 +0000636 unsigned long flags = tcp->u_arg[ARG_FLAGS];
637 tprintf("child_stack=%#lx, ", tcp->u_arg[ARG_STACK]);
638# ifdef ARG_STACKSIZE
639 if (ARG_STACKSIZE != -1)
640 tprintf("stack_size=%#lx, ",
641 tcp->u_arg[ARG_STACKSIZE]);
Roland McGrathb4968be2003-01-20 09:04:33 +0000642# endif
Roland McGrath9677b3a2003-03-12 09:54:36 +0000643 tprintf("flags=");
Wang Chaocbdd1902010-09-02 15:08:59 +0800644 if (!printflags(clone_flags, flags &~ CSIGNAL, NULL))
645 sep = "";
Roland McGrath984154d2003-05-23 01:08:42 +0000646 if ((flags & CSIGNAL) != 0)
Wang Chaocbdd1902010-09-02 15:08:59 +0800647 tprintf("%s%s", sep, signame(flags & CSIGNAL));
Roland McGrathb4968be2003-01-20 09:04:33 +0000648 if ((flags & (CLONE_PARENT_SETTID|CLONE_CHILD_SETTID
Roland McGrath9677b3a2003-03-12 09:54:36 +0000649 |CLONE_CHILD_CLEARTID|CLONE_SETTLS)) == 0)
Roland McGrath909875b2002-12-22 03:34:36 +0000650 return 0;
Roland McGrath6f67a982003-03-21 07:33:15 +0000651 if (flags & CLONE_PARENT_SETTID)
652 tprintf(", parent_tidptr=%#lx", tcp->u_arg[ARG_PTID]);
Roland McGrathb4968be2003-01-20 09:04:33 +0000653 if (flags & CLONE_SETTLS) {
Roland McGrath9677b3a2003-03-12 09:54:36 +0000654# ifdef I386
Roland McGrath909875b2002-12-22 03:34:36 +0000655 struct modify_ldt_ldt_s copy;
Roland McGrath9677b3a2003-03-12 09:54:36 +0000656 if (umove(tcp, tcp->u_arg[ARG_TLS], &copy) != -1) {
Roland McGrath909875b2002-12-22 03:34:36 +0000657 tprintf(", {entry_number:%d, ",
658 copy.entry_number);
659 if (!verbose(tcp))
660 tprintf("...}");
661 else
662 print_ldt_entry(&copy);
663 }
664 else
Roland McGrath9677b3a2003-03-12 09:54:36 +0000665# endif
Roland McGrath43f2c842003-03-12 09:58:14 +0000666 tprintf(", tls=%#lx", tcp->u_arg[ARG_TLS]);
Roland McGrath909875b2002-12-22 03:34:36 +0000667 }
Roland McGrath9677b3a2003-03-12 09:54:36 +0000668 if (flags & (CLONE_CHILD_SETTID|CLONE_CHILD_CLEARTID))
669 tprintf(", child_tidptr=%#lx", tcp->u_arg[ARG_CTID]);
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000670 }
671 return 0;
672}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000673
674int
675sys_unshare(struct tcb *tcp)
676{
677 if (entering(tcp))
678 printflags(clone_flags, tcp->u_arg[0], "CLONE_???");
679 return 0;
680}
Dmitry V. Levine5e60852009-12-31 22:50:49 +0000681#endif /* LINUX */
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000682
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000683int
684sys_fork(tcp)
685struct tcb *tcp;
686{
687 if (exiting(tcp))
688 return RVAL_UDECIMAL;
689 return 0;
690}
691
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000692int
Denys Vlasenko418d66a2009-01-17 01:52:54 +0000693change_syscall(struct tcb *tcp, int new)
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000694{
Dmitry V. Levine5e60852009-12-31 22:50:49 +0000695#ifdef LINUX
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000696#if defined(I386)
697 /* Attempt to make vfork into fork, which we can follow. */
Roland McGrath5a223472002-12-15 23:58:26 +0000698 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(ORIG_EAX * 4), new) < 0)
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000699 return -1;
700 return 0;
Michal Ludvig0e035502002-09-23 15:41:01 +0000701#elif defined(X86_64)
702 /* Attempt to make vfork into fork, which we can follow. */
Roland McGrath5a223472002-12-15 23:58:26 +0000703 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(ORIG_RAX * 8), new) < 0)
Michal Ludvig0e035502002-09-23 15:41:01 +0000704 return -1;
705 return 0;
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000706#elif defined(POWERPC)
Roland McGratheb285352003-01-14 09:59:00 +0000707 if (ptrace(PTRACE_POKEUSER, tcp->pid,
708 (char*)(sizeof(unsigned long)*PT_R0), new) < 0)
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000709 return -1;
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000710 return 0;
Michal Ludvig10a88d02002-10-07 14:31:00 +0000711#elif defined(S390) || defined(S390X)
712 /* s390 linux after 2.4.7 has a hook in entry.S to allow this */
713 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(PT_GPR2), new)<0)
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +0000714 return -1;
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000715 return 0;
716#elif defined(M68K)
Wichert Akkermanc7926982000-04-10 22:22:31 +0000717 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(4*PT_ORIG_D0), new)<0)
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +0000718 return -1;
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000719 return 0;
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000720#elif defined(SPARC) || defined(SPARC64)
Mike Frysinger8566c502009-10-12 11:05:14 -0400721 struct pt_regs regs;
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000722 if (ptrace(PTRACE_GETREGS, tcp->pid, (char*)&regs, 0)<0)
723 return -1;
Mike Frysinger8566c502009-10-12 11:05:14 -0400724 regs.u_regs[U_REG_G1] = new;
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000725 if (ptrace(PTRACE_SETREGS, tcp->pid, (char*)&regs, 0)<0)
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +0000726 return -1;
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000727 return 0;
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000728#elif defined(MIPS)
Wichert Akkermanc7926982000-04-10 22:22:31 +0000729 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(REG_V0), new)<0)
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +0000730 return -1;
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000731 return 0;
732#elif defined(ALPHA)
Wichert Akkermanc7926982000-04-10 22:22:31 +0000733 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(REG_A3), new)<0)
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +0000734 return -1;
735 return 0;
736#elif defined(AVR32)
737 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(REG_R8), new) < 0)
738 return -1;
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000739 return 0;
Dmitry V. Levin87ea1f42008-11-10 22:21:41 +0000740#elif defined(BFIN)
741 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(REG_P0), new)<0)
742 return -1;
743 return 0;
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000744#elif defined(IA64)
Roland McGrath08267b82004-02-20 22:56:43 +0000745 if (ia32) {
746 switch (new) {
Denys Vlasenko418d66a2009-01-17 01:52:54 +0000747 case 2:
748 break; /* x86 SYS_fork */
749 case SYS_clone:
750 new = 120;
751 break;
752 default:
Roland McGrath08267b82004-02-20 22:56:43 +0000753 fprintf(stderr, "%s: unexpected syscall %d\n",
754 __FUNCTION__, new);
755 return -1;
756 }
757 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(PT_R1), new)<0)
758 return -1;
759 } else if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(PT_R15), new)<0)
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000760 return -1;
761 return 0;
Wichert Akkermanc1652e22001-03-27 12:17:16 +0000762#elif defined(HPPA)
763 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(PT_GR20), new)<0)
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +0000764 return -1;
Wichert Akkermanc1652e22001-03-27 12:17:16 +0000765 return 0;
Wichert Akkermanccef6372002-05-01 16:39:22 +0000766#elif defined(SH)
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000767 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(4*(REG_REG0+3)), new)<0)
768 return -1;
769 return 0;
Roland McGrathf5a47772003-06-26 22:40:42 +0000770#elif defined(SH64)
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000771 /* Top half of reg encodes the no. of args n as 0x1n.
772 Assume 0 args as kernel never actually checks... */
773 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(REG_SYSCALL),
774 0x100000 | new) < 0)
775 return -1;
776 return 0;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +0000777#elif defined(CRISV10) || defined(CRISV32)
778 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(4*PT_R9), new) < 0)
779 return -1;
780 return 0;
Roland McGrathf691bd22006-04-25 07:34:41 +0000781#elif defined(ARM)
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000782 /* Some kernels support this, some (pre-2.6.16 or so) don't. */
Roland McGrathf691bd22006-04-25 07:34:41 +0000783# ifndef PTRACE_SET_SYSCALL
784# define PTRACE_SET_SYSCALL 23
785# endif
786
Dmitry V. Levin76740062009-09-18 11:30:14 +0000787 if (ptrace (PTRACE_SET_SYSCALL, tcp->pid, 0, new & 0xffff) != 0)
Roland McGrathf691bd22006-04-25 07:34:41 +0000788 return -1;
789
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000790 return 0;
Chris Metcalfc8c66982009-12-28 10:00:15 -0500791#elif defined(TILE)
792 if (ptrace(PTRACE_POKEUSER, tcp->pid,
793 (char*)PTREGS_OFFSET_REG(0),
794 new) != 0)
795 return -1;
796 return 0;
Edgar E. Iglesias939caba2010-07-06 14:21:07 +0200797#elif defined(MICROBLAZE)
798 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(PT_GPR(0)), new)<0)
799 return -1;
800 return 0;
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000801#else
802#warning Do not know how to handle change_syscall for this architecture
803#endif /* architecture */
804#endif /* LINUX */
805 return -1;
806}
807
Dmitry V. Levin257e1572009-12-26 17:55:24 +0000808#ifdef LINUX
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000809int
Wang Chaoca8ab8d2010-11-12 17:26:08 +0800810handle_new_child(struct tcb *tcp, int pid, int bpt)
811{
812 struct tcb *tcpchild;
813
814#ifdef CLONE_PTRACE /* See new setbpt code. */
815 tcpchild = pid2tcb(pid);
816 if (tcpchild != NULL) {
817 /* The child already reported its startup trap
818 before the parent reported its syscall return. */
819 if ((tcpchild->flags
820 & (TCB_STARTUP|TCB_ATTACHED|TCB_SUSPENDED))
821 != (TCB_STARTUP|TCB_ATTACHED|TCB_SUSPENDED))
822 fprintf(stderr, "\
823[preattached child %d of %d in weird state!]\n",
824 pid, tcp->pid);
825 }
826 else
827#endif /* CLONE_PTRACE */
828 {
829 fork_tcb(tcp);
830 tcpchild = alloctcb(pid);
831 }
832
833#ifndef CLONE_PTRACE
834 /* Attach to the new child */
835 if (ptrace(PTRACE_ATTACH, pid, (char *) 1, 0) < 0) {
836 if (bpt)
837 clearbpt(tcp);
838 perror("PTRACE_ATTACH");
839 fprintf(stderr, "Too late?\n");
840 droptcb(tcpchild);
841 return 0;
842 }
843#endif /* !CLONE_PTRACE */
844
845 if (bpt)
846 clearbpt(tcp);
847
848 tcpchild->flags |= TCB_ATTACHED;
849 /* Child has BPT too, must be removed on first occasion. */
850 if (bpt) {
851 tcpchild->flags |= TCB_BPTSET;
852 tcpchild->baddr = tcp->baddr;
853 memcpy(tcpchild->inst, tcp->inst,
854 sizeof tcpchild->inst);
855 }
856 tcpchild->parent = tcp;
857 tcp->nchildren++;
858 if (tcpchild->flags & TCB_SUSPENDED) {
859 /* The child was born suspended, due to our having
860 forced CLONE_PTRACE. */
861 if (bpt)
862 clearbpt(tcpchild);
863
864 tcpchild->flags &= ~(TCB_SUSPENDED|TCB_STARTUP);
865 if (ptrace_restart(PTRACE_SYSCALL, tcpchild, 0) < 0)
866 return -1;
867
868 if (!qflag)
869 fprintf(stderr, "\
870Process %u resumed (parent %d ready)\n",
871 pid, tcp->pid);
872 }
873 else {
874 if (!qflag)
875 fprintf(stderr, "Process %d attached\n", pid);
876 }
877
878#ifdef TCB_CLONE_THREAD
879 if (sysent[tcp->scno].sys_func == sys_clone)
880 {
881 /*
882 * Save the flags used in this call,
883 * in case we point TCP to our parent below.
884 */
885 int call_flags = tcp->u_arg[ARG_FLAGS];
886 if ((tcp->flags & TCB_CLONE_THREAD) &&
887 tcp->parent != NULL) {
888 /* The parent in this clone is itself a
889 thread belonging to another process.
890 There is no meaning to the parentage
891 relationship of the new child with the
892 thread, only with the process. We
893 associate the new thread with our
894 parent. Since this is done for every
895 new thread, there will never be a
896 TCB_CLONE_THREAD process that has
897 children. */
898 --tcp->nchildren;
899 tcp = tcp->parent;
900 tcpchild->parent = tcp;
901 ++tcp->nchildren;
902 }
903 if (call_flags & CLONE_THREAD) {
904 tcpchild->flags |= TCB_CLONE_THREAD;
905 ++tcp->nclone_threads;
906 }
907 if ((call_flags & CLONE_PARENT) &&
908 !(call_flags & CLONE_THREAD)) {
909 --tcp->nchildren;
910 tcpchild->parent = NULL;
911 if (tcp->parent != NULL) {
912 tcp = tcp->parent;
913 tcpchild->parent = tcp;
914 ++tcp->nchildren;
915 }
916 }
917 }
918#endif /* TCB_CLONE_THREAD */
919 return 0;
920}
921
922int
Dmitry V. Levin257e1572009-12-26 17:55:24 +0000923internal_fork(struct tcb *tcp)
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000924{
Wang Chaoca8ab8d2010-11-12 17:26:08 +0800925 if ((ptrace_setoptions
926 & (PTRACE_O_TRACECLONE | PTRACE_O_TRACEFORK | PTRACE_O_TRACEVFORK))
927 == (PTRACE_O_TRACECLONE | PTRACE_O_TRACEFORK | PTRACE_O_TRACEVFORK))
928 return 0;
929
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000930 if (entering(tcp)) {
Wang Chaoe636c852010-09-16 11:20:56 +0800931 tcp->flags &= ~TCB_FOLLOWFORK;
Roland McGratheb9e2e82009-06-02 16:49:22 -0700932 if (!followfork)
933 return 0;
Wang Chaoe636c852010-09-16 11:20:56 +0800934 /*
935 * In occasion of using PTRACE_O_TRACECLONE, we won't see the
936 * new child if clone is called with flag CLONE_UNTRACED, so
937 * we keep the same logic with that option and don't trace it.
938 */
939 if ((sysent[tcp->scno].sys_func == sys_clone) &&
940 (tcp->u_arg[ARG_FLAGS] & CLONE_UNTRACED))
941 return 0;
Roland McGratheb9e2e82009-06-02 16:49:22 -0700942 fork_tcb(tcp);
943 if (setbpt(tcp) < 0)
944 return 0;
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000945 } else {
Dmitry V. Levin257e1572009-12-26 17:55:24 +0000946 int pid;
947 int bpt;
Roland McGratheb9e2e82009-06-02 16:49:22 -0700948
949 if (!(tcp->flags & TCB_FOLLOWFORK))
950 return 0;
Wichert Akkerman9b0c31d2000-09-03 21:56:29 +0000951
Dmitry V. Levin257e1572009-12-26 17:55:24 +0000952 bpt = tcp->flags & TCB_BPTSET;
953
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000954 if (syserror(tcp)) {
955 if (bpt)
956 clearbpt(tcp);
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000957 return 0;
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000958 }
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000959
960 pid = tcp->u_rval;
Roland McGrathe85bbfe2003-01-09 06:53:31 +0000961
Wang Chaoca8ab8d2010-11-12 17:26:08 +0800962 return handle_new_child(tcp, pid, bpt);
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +0000963 }
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000964 return 0;
965}
Dmitry V. Levin257e1572009-12-26 17:55:24 +0000966
967#else /* !LINUX */
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000968
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000969int
970internal_fork(tcp)
971struct tcb *tcp;
972{
973 struct tcb *tcpchild;
974 int pid;
Roland McGratheb9e2e82009-06-02 16:49:22 -0700975 int dont_follow = 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000976
977#ifdef SYS_vfork
Roland McGratha4f9f2d2005-06-07 23:21:20 +0000978 if (known_scno(tcp) == SYS_vfork) {
Nate Sammonsccd8f211999-03-29 22:57:54 +0000979 /* Attempt to make vfork into fork, which we can follow. */
Roland McGrath41c48222008-07-18 00:25:10 +0000980 if (change_syscall(tcp, SYS_fork) < 0)
Roland McGratheb9e2e82009-06-02 16:49:22 -0700981 dont_follow = 1;
Nate Sammonsccd8f211999-03-29 22:57:54 +0000982 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000983#endif
984 if (entering(tcp)) {
Roland McGratheb9e2e82009-06-02 16:49:22 -0700985 if (!followfork || dont_follow)
986 return 0;
987 fork_tcb(tcp);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000988 if (setbpt(tcp) < 0)
989 return 0;
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +0000990 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000991 else {
992 int bpt = tcp->flags & TCB_BPTSET;
993
Roland McGratheb9e2e82009-06-02 16:49:22 -0700994 if (!(tcp->flags & TCB_FOLLOWFORK))
995 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000996 if (bpt)
997 clearbpt(tcp);
998
999 if (syserror(tcp))
1000 return 0;
1001
1002 pid = tcp->u_rval;
Roland McGratheb9e2e82009-06-02 16:49:22 -07001003 fork_tcb(tcp);
Denys Vlasenko418d66a2009-01-17 01:52:54 +00001004 tcpchild = alloctcb(pid);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001005#ifdef SUNOS4
1006#ifdef oldway
1007 /* The child must have run before it can be attached. */
1008 {
1009 struct timeval tv;
1010 tv.tv_sec = 0;
1011 tv.tv_usec = 10000;
1012 select(0, NULL, NULL, NULL, &tv);
1013 }
1014 if (ptrace(PTRACE_ATTACH, pid, (char *)1, 0) < 0) {
1015 perror("PTRACE_ATTACH");
1016 fprintf(stderr, "Too late?\n");
1017 droptcb(tcpchild);
1018 return 0;
1019 }
1020#else /* !oldway */
1021 /* Try to catch the new process as soon as possible. */
1022 {
1023 int i;
1024 for (i = 0; i < 1024; i++)
1025 if (ptrace(PTRACE_ATTACH, pid, (char *) 1, 0) >= 0)
1026 break;
1027 if (i == 1024) {
1028 perror("PTRACE_ATTACH");
1029 fprintf(stderr, "Too late?\n");
1030 droptcb(tcpchild);
1031 return 0;
1032 }
1033 }
1034#endif /* !oldway */
1035#endif /* SUNOS4 */
1036 tcpchild->flags |= TCB_ATTACHED;
1037 /* Child has BPT too, must be removed on first occasion */
1038 if (bpt) {
1039 tcpchild->flags |= TCB_BPTSET;
1040 tcpchild->baddr = tcp->baddr;
1041 memcpy(tcpchild->inst, tcp->inst,
1042 sizeof tcpchild->inst);
1043 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001044 tcpchild->parent = tcp;
1045 tcp->nchildren++;
1046 if (!qflag)
1047 fprintf(stderr, "Process %d attached\n", pid);
1048 }
1049 return 0;
1050}
1051
Dmitry V. Levin257e1572009-12-26 17:55:24 +00001052#endif /* !LINUX */
1053
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001054#endif /* !USE_PROCFS */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001055
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001056#if defined(SUNOS4) || defined(LINUX) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001057
1058int
1059sys_vfork(tcp)
1060struct tcb *tcp;
1061{
1062 if (exiting(tcp))
1063 return RVAL_UDECIMAL;
1064 return 0;
1065}
1066
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001067#endif /* SUNOS4 || LINUX || FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001068
1069#ifndef LINUX
1070
1071static char idstr[16];
1072
1073int
1074sys_getpid(tcp)
1075struct tcb *tcp;
1076{
1077 if (exiting(tcp)) {
1078 sprintf(idstr, "ppid %lu", getrval2(tcp));
1079 tcp->auxstr = idstr;
1080 return RVAL_STR;
1081 }
1082 return 0;
1083}
1084
1085int
1086sys_getuid(tcp)
1087struct tcb *tcp;
1088{
1089 if (exiting(tcp)) {
1090 sprintf(idstr, "euid %lu", getrval2(tcp));
1091 tcp->auxstr = idstr;
1092 return RVAL_STR;
1093 }
1094 return 0;
1095}
1096
1097int
1098sys_getgid(tcp)
1099struct tcb *tcp;
1100{
1101 if (exiting(tcp)) {
1102 sprintf(idstr, "egid %lu", getrval2(tcp));
1103 tcp->auxstr = idstr;
1104 return RVAL_STR;
1105 }
1106 return 0;
1107}
1108
1109#endif /* !LINUX */
1110
1111#ifdef LINUX
1112
Dmitry V. Levin50a218d2011-01-18 17:36:20 +00001113int sys_getuid(struct tcb *tcp)
1114{
1115 if (exiting(tcp))
1116 tcp->u_rval = (uid_t) tcp->u_rval;
1117 return RVAL_UDECIMAL;
1118}
1119
1120int sys_setfsuid(struct tcb *tcp)
1121{
1122 if (entering(tcp))
1123 tprintf("%u", (uid_t) tcp->u_arg[0]);
1124 else
1125 tcp->u_rval = (uid_t) tcp->u_rval;
1126 return RVAL_UDECIMAL;
1127}
1128
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001129int
1130sys_setuid(tcp)
1131struct tcb *tcp;
1132{
1133 if (entering(tcp)) {
1134 tprintf("%u", (uid_t) tcp->u_arg[0]);
1135 }
1136 return 0;
1137}
1138
1139int
1140sys_setgid(tcp)
1141struct tcb *tcp;
1142{
1143 if (entering(tcp)) {
1144 tprintf("%u", (gid_t) tcp->u_arg[0]);
1145 }
1146 return 0;
1147}
1148
1149int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001150sys_getresuid(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001151{
1152 if (exiting(tcp)) {
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001153 __kernel_uid_t uid;
1154 if (syserror(tcp))
1155 tprintf("%#lx, %#lx, %#lx", tcp->u_arg[0],
1156 tcp->u_arg[1], tcp->u_arg[2]);
1157 else {
1158 if (umove(tcp, tcp->u_arg[0], &uid) < 0)
1159 tprintf("%#lx, ", tcp->u_arg[0]);
1160 else
Roland McGrath83bd47a2003-11-13 22:32:26 +00001161 tprintf("[%lu], ", (unsigned long) uid);
Roland McGrath9bd6b422003-02-24 07:13:51 +00001162 if (umove(tcp, tcp->u_arg[1], &uid) < 0)
1163 tprintf("%#lx, ", tcp->u_arg[1]);
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001164 else
Roland McGrath83bd47a2003-11-13 22:32:26 +00001165 tprintf("[%lu], ", (unsigned long) uid);
Roland McGrath9bd6b422003-02-24 07:13:51 +00001166 if (umove(tcp, tcp->u_arg[2], &uid) < 0)
1167 tprintf("%#lx", tcp->u_arg[2]);
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001168 else
Roland McGrath83bd47a2003-11-13 22:32:26 +00001169 tprintf("[%lu]", (unsigned long) uid);
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001170 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001171 }
1172 return 0;
1173}
1174
1175int
1176sys_getresgid(tcp)
1177struct tcb *tcp;
1178{
1179 if (exiting(tcp)) {
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001180 __kernel_gid_t gid;
1181 if (syserror(tcp))
1182 tprintf("%#lx, %#lx, %#lx", tcp->u_arg[0],
1183 tcp->u_arg[1], tcp->u_arg[2]);
1184 else {
1185 if (umove(tcp, tcp->u_arg[0], &gid) < 0)
1186 tprintf("%#lx, ", tcp->u_arg[0]);
1187 else
Roland McGrath83bd47a2003-11-13 22:32:26 +00001188 tprintf("[%lu], ", (unsigned long) gid);
Roland McGrathd2450922003-02-24 10:18:07 +00001189 if (umove(tcp, tcp->u_arg[1], &gid) < 0)
1190 tprintf("%#lx, ", tcp->u_arg[1]);
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001191 else
Roland McGrath83bd47a2003-11-13 22:32:26 +00001192 tprintf("[%lu], ", (unsigned long) gid);
Roland McGrathd2450922003-02-24 10:18:07 +00001193 if (umove(tcp, tcp->u_arg[2], &gid) < 0)
1194 tprintf("%#lx", tcp->u_arg[2]);
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001195 else
Roland McGrath83bd47a2003-11-13 22:32:26 +00001196 tprintf("[%lu]", (unsigned long) gid);
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001197 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001198 }
1199 return 0;
1200}
1201
1202#endif /* LINUX */
1203
1204int
1205sys_setreuid(tcp)
1206struct tcb *tcp;
1207{
1208 if (entering(tcp)) {
Roland McGrath83bd47a2003-11-13 22:32:26 +00001209 printuid("", tcp->u_arg[0]);
1210 printuid(", ", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001211 }
1212 return 0;
1213}
1214
1215int
1216sys_setregid(tcp)
1217struct tcb *tcp;
1218{
1219 if (entering(tcp)) {
Roland McGrath83bd47a2003-11-13 22:32:26 +00001220 printuid("", tcp->u_arg[0]);
1221 printuid(", ", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001222 }
1223 return 0;
1224}
1225
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001226#if defined(LINUX) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001227int
1228sys_setresuid(tcp)
1229 struct tcb *tcp;
1230{
1231 if (entering(tcp)) {
Roland McGrath83bd47a2003-11-13 22:32:26 +00001232 printuid("", tcp->u_arg[0]);
1233 printuid(", ", tcp->u_arg[1]);
1234 printuid(", ", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001235 }
1236 return 0;
1237}
1238int
1239sys_setresgid(tcp)
1240 struct tcb *tcp;
1241{
1242 if (entering(tcp)) {
Roland McGrath83bd47a2003-11-13 22:32:26 +00001243 printuid("", tcp->u_arg[0]);
1244 printuid(", ", tcp->u_arg[1]);
1245 printuid(", ", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001246 }
1247 return 0;
1248}
1249
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001250#endif /* LINUX || FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001251
1252int
1253sys_setgroups(tcp)
1254struct tcb *tcp;
1255{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001256 if (entering(tcp)) {
Roland McGrathaa524c82005-06-01 19:22:06 +00001257 unsigned long len, size, start, cur, end, abbrev_end;
1258 GETGROUPS_T gid;
1259 int failed = 0;
1260
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001261 len = tcp->u_arg[0];
Roland McGrathaa524c82005-06-01 19:22:06 +00001262 tprintf("%lu, ", len);
1263 if (len == 0) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001264 tprintf("[]");
1265 return 0;
1266 }
Roland McGrathaa524c82005-06-01 19:22:06 +00001267 start = tcp->u_arg[1];
1268 if (start == 0) {
1269 tprintf("NULL");
1270 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001271 }
Roland McGrathaa524c82005-06-01 19:22:06 +00001272 size = len * sizeof(gid);
1273 end = start + size;
1274 if (!verbose(tcp) || size / sizeof(gid) != len || end < start) {
1275 tprintf("%#lx", start);
1276 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001277 }
Roland McGrathaa524c82005-06-01 19:22:06 +00001278 if (abbrev(tcp)) {
1279 abbrev_end = start + max_strlen * sizeof(gid);
1280 if (abbrev_end < start)
1281 abbrev_end = end;
1282 } else {
1283 abbrev_end = end;
1284 }
1285 tprintf("[");
1286 for (cur = start; cur < end; cur += sizeof(gid)) {
1287 if (cur > start)
1288 tprintf(", ");
1289 if (cur >= abbrev_end) {
1290 tprintf("...");
1291 break;
1292 }
1293 if (umoven(tcp, cur, sizeof(gid), (char *) &gid) < 0) {
1294 tprintf("?");
1295 failed = 1;
1296 break;
1297 }
1298 tprintf("%lu", (unsigned long) gid);
1299 }
1300 tprintf("]");
1301 if (failed)
1302 tprintf(" %#lx", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001303 }
1304 return 0;
1305}
1306
1307int
1308sys_getgroups(tcp)
1309struct tcb *tcp;
1310{
Roland McGrathaa524c82005-06-01 19:22:06 +00001311 unsigned long len;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001312
1313 if (entering(tcp)) {
1314 len = tcp->u_arg[0];
Roland McGrathaa524c82005-06-01 19:22:06 +00001315 tprintf("%lu, ", len);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001316 } else {
Roland McGrathaa524c82005-06-01 19:22:06 +00001317 unsigned long size, start, cur, end, abbrev_end;
1318 GETGROUPS_T gid;
1319 int failed = 0;
1320
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001321 len = tcp->u_rval;
Roland McGrathaa524c82005-06-01 19:22:06 +00001322 if (len == 0) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001323 tprintf("[]");
1324 return 0;
1325 }
Roland McGrathaa524c82005-06-01 19:22:06 +00001326 start = tcp->u_arg[1];
1327 if (start == 0) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001328 tprintf("NULL");
Roland McGrathaa524c82005-06-01 19:22:06 +00001329 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001330 }
Roland McGrathaa524c82005-06-01 19:22:06 +00001331 if (tcp->u_arg[0] == 0) {
1332 tprintf("%#lx", start);
1333 return 0;
1334 }
1335 size = len * sizeof(gid);
1336 end = start + size;
1337 if (!verbose(tcp) || tcp->u_arg[0] == 0 ||
1338 size / sizeof(gid) != len || end < start) {
1339 tprintf("%#lx", start);
1340 return 0;
1341 }
1342 if (abbrev(tcp)) {
1343 abbrev_end = start + max_strlen * sizeof(gid);
1344 if (abbrev_end < start)
1345 abbrev_end = end;
1346 } else {
1347 abbrev_end = end;
1348 }
1349 tprintf("[");
1350 for (cur = start; cur < end; cur += sizeof(gid)) {
1351 if (cur > start)
1352 tprintf(", ");
1353 if (cur >= abbrev_end) {
1354 tprintf("...");
1355 break;
1356 }
1357 if (umoven(tcp, cur, sizeof(gid), (char *) &gid) < 0) {
1358 tprintf("?");
1359 failed = 1;
1360 break;
1361 }
1362 tprintf("%lu", (unsigned long) gid);
1363 }
1364 tprintf("]");
1365 if (failed)
1366 tprintf(" %#lx", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001367 }
1368 return 0;
1369}
1370
Roland McGrath83bd47a2003-11-13 22:32:26 +00001371#ifdef LINUX
1372int
1373sys_setgroups32(tcp)
1374struct tcb *tcp;
1375{
Roland McGrath83bd47a2003-11-13 22:32:26 +00001376 if (entering(tcp)) {
Roland McGrathaa524c82005-06-01 19:22:06 +00001377 unsigned long len, size, start, cur, end, abbrev_end;
1378 GETGROUPS32_T gid;
1379 int failed = 0;
1380
Roland McGrath83bd47a2003-11-13 22:32:26 +00001381 len = tcp->u_arg[0];
Roland McGrathaa524c82005-06-01 19:22:06 +00001382 tprintf("%lu, ", len);
1383 if (len == 0) {
Roland McGrath83bd47a2003-11-13 22:32:26 +00001384 tprintf("[]");
1385 return 0;
1386 }
Roland McGrathaa524c82005-06-01 19:22:06 +00001387 start = tcp->u_arg[1];
1388 if (start == 0) {
1389 tprintf("NULL");
1390 return 0;
Roland McGrath83bd47a2003-11-13 22:32:26 +00001391 }
Roland McGrathaa524c82005-06-01 19:22:06 +00001392 size = len * sizeof(gid);
1393 end = start + size;
1394 if (!verbose(tcp) || size / sizeof(gid) != len || end < start) {
1395 tprintf("%#lx", start);
1396 return 0;
Roland McGrath83bd47a2003-11-13 22:32:26 +00001397 }
Roland McGrathaa524c82005-06-01 19:22:06 +00001398 if (abbrev(tcp)) {
1399 abbrev_end = start + max_strlen * sizeof(gid);
1400 if (abbrev_end < start)
1401 abbrev_end = end;
1402 } else {
1403 abbrev_end = end;
1404 }
1405 tprintf("[");
1406 for (cur = start; cur < end; cur += sizeof(gid)) {
1407 if (cur > start)
1408 tprintf(", ");
1409 if (cur >= abbrev_end) {
1410 tprintf("...");
1411 break;
1412 }
1413 if (umoven(tcp, cur, sizeof(gid), (char *) &gid) < 0) {
1414 tprintf("?");
1415 failed = 1;
1416 break;
1417 }
1418 tprintf("%lu", (unsigned long) gid);
1419 }
1420 tprintf("]");
1421 if (failed)
1422 tprintf(" %#lx", tcp->u_arg[1]);
Roland McGrath83bd47a2003-11-13 22:32:26 +00001423 }
1424 return 0;
1425}
1426
1427int
1428sys_getgroups32(tcp)
1429struct tcb *tcp;
1430{
Roland McGrathaa524c82005-06-01 19:22:06 +00001431 unsigned long len;
Roland McGrath83bd47a2003-11-13 22:32:26 +00001432
1433 if (entering(tcp)) {
1434 len = tcp->u_arg[0];
Roland McGrathaa524c82005-06-01 19:22:06 +00001435 tprintf("%lu, ", len);
Roland McGrath83bd47a2003-11-13 22:32:26 +00001436 } else {
Roland McGrathaa524c82005-06-01 19:22:06 +00001437 unsigned long size, start, cur, end, abbrev_end;
1438 GETGROUPS32_T gid;
1439 int failed = 0;
1440
Roland McGrath83bd47a2003-11-13 22:32:26 +00001441 len = tcp->u_rval;
Roland McGrathaa524c82005-06-01 19:22:06 +00001442 if (len == 0) {
Roland McGrath83bd47a2003-11-13 22:32:26 +00001443 tprintf("[]");
1444 return 0;
1445 }
Roland McGrathaa524c82005-06-01 19:22:06 +00001446 start = tcp->u_arg[1];
1447 if (start == 0) {
Roland McGrath83bd47a2003-11-13 22:32:26 +00001448 tprintf("NULL");
Roland McGrathaa524c82005-06-01 19:22:06 +00001449 return 0;
Roland McGrath83bd47a2003-11-13 22:32:26 +00001450 }
Roland McGrathaa524c82005-06-01 19:22:06 +00001451 size = len * sizeof(gid);
1452 end = start + size;
1453 if (!verbose(tcp) || tcp->u_arg[0] == 0 ||
1454 size / sizeof(gid) != len || end < start) {
1455 tprintf("%#lx", start);
1456 return 0;
1457 }
1458 if (abbrev(tcp)) {
1459 abbrev_end = start + max_strlen * sizeof(gid);
1460 if (abbrev_end < start)
1461 abbrev_end = end;
1462 } else {
1463 abbrev_end = end;
1464 }
1465 tprintf("[");
1466 for (cur = start; cur < end; cur += sizeof(gid)) {
1467 if (cur > start)
1468 tprintf(", ");
1469 if (cur >= abbrev_end) {
1470 tprintf("...");
1471 break;
1472 }
1473 if (umoven(tcp, cur, sizeof(gid), (char *) &gid) < 0) {
1474 tprintf("?");
1475 failed = 1;
1476 break;
1477 }
1478 tprintf("%lu", (unsigned long) gid);
1479 }
1480 tprintf("]");
1481 if (failed)
1482 tprintf(" %#lx", tcp->u_arg[1]);
Roland McGrath83bd47a2003-11-13 22:32:26 +00001483 }
1484 return 0;
1485}
1486#endif /* LINUX */
1487
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001488#if defined(ALPHA) || defined(SUNOS4) || defined(SVR4)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001489int
1490sys_setpgrp(tcp)
1491struct tcb *tcp;
1492{
1493 if (entering(tcp)) {
1494#ifndef SVR4
1495 tprintf("%lu, %lu", tcp->u_arg[0], tcp->u_arg[1]);
1496#endif /* !SVR4 */
1497 }
1498 return 0;
1499}
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001500#endif /* ALPHA || SUNOS4 || SVR4 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001501
1502int
1503sys_getpgrp(tcp)
1504struct tcb *tcp;
1505{
1506 if (entering(tcp)) {
1507#ifndef SVR4
1508 tprintf("%lu", tcp->u_arg[0]);
1509#endif /* !SVR4 */
1510 }
1511 return 0;
1512}
1513
1514int
1515sys_getsid(tcp)
1516struct tcb *tcp;
1517{
1518 if (entering(tcp)) {
1519 tprintf("%lu", tcp->u_arg[0]);
1520 }
1521 return 0;
1522}
1523
1524int
1525sys_setsid(tcp)
1526struct tcb *tcp;
1527{
1528 return 0;
1529}
1530
1531int
1532sys_getpgid(tcp)
1533struct tcb *tcp;
1534{
1535 if (entering(tcp)) {
1536 tprintf("%lu", tcp->u_arg[0]);
1537 }
1538 return 0;
1539}
1540
1541int
1542sys_setpgid(tcp)
1543struct tcb *tcp;
1544{
1545 if (entering(tcp)) {
1546 tprintf("%lu, %lu", tcp->u_arg[0], tcp->u_arg[1]);
1547 }
1548 return 0;
1549}
1550
John Hughesc61eb3d2002-05-17 11:37:50 +00001551#if UNIXWARE >= 2
1552
1553#include <sys/privilege.h>
1554
1555
Roland McGrathd9f816f2004-09-04 03:39:20 +00001556static const struct xlat procpriv_cmds [] = {
John Hughesc61eb3d2002-05-17 11:37:50 +00001557 { SETPRV, "SETPRV" },
1558 { CLRPRV, "CLRPRV" },
1559 { PUTPRV, "PUTPRV" },
1560 { GETPRV, "GETPRV" },
1561 { CNTPRV, "CNTPRV" },
1562 { 0, NULL },
1563};
1564
1565
Roland McGrathd9f816f2004-09-04 03:39:20 +00001566static const struct xlat procpriv_priv [] = {
John Hughesc61eb3d2002-05-17 11:37:50 +00001567 { P_OWNER, "P_OWNER" },
1568 { P_AUDIT, "P_AUDIT" },
1569 { P_COMPAT, "P_COMPAT" },
1570 { P_DACREAD, "P_DACREAD" },
1571 { P_DACWRITE, "P_DACWRITE" },
1572 { P_DEV, "P_DEV" },
1573 { P_FILESYS, "P_FILESYS" },
1574 { P_MACREAD, "P_MACREAD" },
1575 { P_MACWRITE, "P_MACWRITE" },
1576 { P_MOUNT, "P_MOUNT" },
1577 { P_MULTIDIR, "P_MULTIDIR" },
1578 { P_SETPLEVEL, "P_SETPLEVEL" },
1579 { P_SETSPRIV, "P_SETSPRIV" },
1580 { P_SETUID, "P_SETUID" },
1581 { P_SYSOPS, "P_SYSOPS" },
1582 { P_SETUPRIV, "P_SETUPRIV" },
1583 { P_DRIVER, "P_DRIVER" },
1584 { P_RTIME, "P_RTIME" },
1585 { P_MACUPGRADE, "P_MACUPGRADE" },
1586 { P_FSYSRANGE, "P_FSYSRANGE" },
1587 { P_SETFLEVEL, "P_SETFLEVEL" },
1588 { P_AUDITWR, "P_AUDITWR" },
1589 { P_TSHAR, "P_TSHAR" },
1590 { P_PLOCK, "P_PLOCK" },
1591 { P_CORE, "P_CORE" },
1592 { P_LOADMOD, "P_LOADMOD" },
1593 { P_BIND, "P_BIND" },
1594 { P_ALLPRIVS, "P_ALLPRIVS" },
1595 { 0, NULL },
1596};
1597
1598
Roland McGrathd9f816f2004-09-04 03:39:20 +00001599static const struct xlat procpriv_type [] = {
John Hughesc61eb3d2002-05-17 11:37:50 +00001600 { PS_FIX, "PS_FIX" },
1601 { PS_INH, "PS_INH" },
1602 { PS_MAX, "PS_MAX" },
1603 { PS_WKG, "PS_WKG" },
1604 { 0, NULL },
1605};
1606
1607
1608static void
Dmitry V. Levinab9008b2007-01-11 22:05:04 +00001609printpriv(struct tcb *tcp, long addr, int len, const struct xlat *opt)
John Hughesc61eb3d2002-05-17 11:37:50 +00001610{
1611 priv_t buf [128];
1612 int max = verbose (tcp) ? sizeof buf / sizeof buf [0] : 10;
1613 int dots = len > max;
1614 int i;
Roland McGrath5a223472002-12-15 23:58:26 +00001615
John Hughesc61eb3d2002-05-17 11:37:50 +00001616 if (len > max) len = max;
Roland McGrath5a223472002-12-15 23:58:26 +00001617
John Hughesc61eb3d2002-05-17 11:37:50 +00001618 if (len <= 0 ||
1619 umoven (tcp, addr, len * sizeof buf[0], (char *) buf) < 0)
1620 {
1621 tprintf ("%#lx", addr);
1622 return;
1623 }
1624
1625 tprintf ("[");
1626
1627 for (i = 0; i < len; ++i) {
Dmitry V. Levinab9008b2007-01-11 22:05:04 +00001628 const char *t, *p;
John Hughesc61eb3d2002-05-17 11:37:50 +00001629
1630 if (i) tprintf (", ");
1631
1632 if ((t = xlookup (procpriv_type, buf [i] & PS_TYPE)) &&
1633 (p = xlookup (procpriv_priv, buf [i] & ~PS_TYPE)))
1634 {
1635 tprintf ("%s|%s", t, p);
1636 }
1637 else {
1638 tprintf ("%#lx", buf [i]);
1639 }
1640 }
1641
1642 if (dots) tprintf (" ...");
1643
1644 tprintf ("]");
1645}
1646
1647
1648int
1649sys_procpriv(tcp)
1650struct tcb *tcp;
1651{
1652 if (entering(tcp)) {
1653 printxval(procpriv_cmds, tcp->u_arg[0], "???PRV");
1654 switch (tcp->u_arg[0]) {
1655 case CNTPRV:
1656 tprintf(", %#lx, %ld", tcp->u_arg[1], tcp->u_arg[2]);
1657 break;
1658
1659 case GETPRV:
1660 break;
1661
1662 default:
1663 tprintf (", ");
1664 printpriv (tcp, tcp->u_arg[1], tcp->u_arg[2]);
1665 tprintf (", %ld", tcp->u_arg[2]);
1666 }
1667 }
1668 else if (tcp->u_arg[0] == GETPRV) {
1669 if (syserror (tcp)) {
1670 tprintf(", %#lx, %ld", tcp->u_arg[1], tcp->u_arg[2]);
1671 }
1672 else {
1673 tprintf (", ");
1674 printpriv (tcp, tcp->u_arg[1], tcp->u_rval);
1675 tprintf (", %ld", tcp->u_arg[2]);
1676 }
1677 }
Roland McGrath5a223472002-12-15 23:58:26 +00001678
John Hughesc61eb3d2002-05-17 11:37:50 +00001679 return 0;
1680}
1681
Dmitry V. Levine5e60852009-12-31 22:50:49 +00001682#endif /* UNIXWARE */
John Hughesc61eb3d2002-05-17 11:37:50 +00001683
1684
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001685static void
Dmitry V. Levin30145dd2010-09-06 22:08:24 +00001686printargv(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001687{
Roland McGrath85a3bc42007-08-02 02:13:05 +00001688 union {
Andreas Schwab99c85692009-08-28 19:36:20 +02001689 unsigned int p32;
1690 unsigned long p64;
Roland McGrath85a3bc42007-08-02 02:13:05 +00001691 char data[sizeof(long)];
1692 } cp;
Dmitry V. Levin30145dd2010-09-06 22:08:24 +00001693 const char *sep;
Roland McGrath85a3bc42007-08-02 02:13:05 +00001694 int n = 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001695
Roland McGrath85a3bc42007-08-02 02:13:05 +00001696 cp.p64 = 1;
1697 for (sep = ""; !abbrev(tcp) || n < max_strlen / 2; sep = ", ", ++n) {
1698 if (umoven(tcp, addr, personality_wordsize[current_personality],
1699 cp.data) < 0) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001700 tprintf("%#lx", addr);
1701 return;
1702 }
Roland McGrath85a3bc42007-08-02 02:13:05 +00001703 if (personality_wordsize[current_personality] == 4)
1704 cp.p64 = cp.p32;
1705 if (cp.p64 == 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001706 break;
Dmitry V. Levin4bcd5ef2009-06-01 10:32:27 +00001707 tprintf("%s", sep);
Roland McGrath85a3bc42007-08-02 02:13:05 +00001708 printstr(tcp, cp.p64, -1);
1709 addr += personality_wordsize[current_personality];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001710 }
Roland McGrath85a3bc42007-08-02 02:13:05 +00001711 if (cp.p64)
1712 tprintf("%s...", sep);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001713}
1714
1715static void
Dmitry V. Levin30145dd2010-09-06 22:08:24 +00001716printargc(const char *fmt, struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001717{
1718 int count;
1719 char *cp;
1720
1721 for (count = 0; umove(tcp, addr, &cp) >= 0 && cp != NULL; count++) {
1722 addr += sizeof(char *);
1723 }
1724 tprintf(fmt, count, count == 1 ? "" : "s");
1725}
1726
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001727#if defined(SPARC) || defined(SPARC64) || defined(SUNOS4)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001728int
Dmitry V. Levine5e60852009-12-31 22:50:49 +00001729sys_execv(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001730{
1731 if (entering(tcp)) {
1732 printpath(tcp, tcp->u_arg[0]);
1733 if (!verbose(tcp))
1734 tprintf(", %#lx", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001735 else {
1736 tprintf(", [");
1737 printargv(tcp, tcp->u_arg[1]);
1738 tprintf("]");
1739 }
1740 }
1741 return 0;
1742}
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001743#endif /* SPARC || SPARC64 || SUNOS4 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001744
1745int
Dmitry V. Levine5e60852009-12-31 22:50:49 +00001746sys_execve(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001747{
1748 if (entering(tcp)) {
1749 printpath(tcp, tcp->u_arg[0]);
1750 if (!verbose(tcp))
1751 tprintf(", %#lx", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001752 else {
1753 tprintf(", [");
1754 printargv(tcp, tcp->u_arg[1]);
1755 tprintf("]");
1756 }
1757 if (!verbose(tcp))
1758 tprintf(", %#lx", tcp->u_arg[2]);
1759 else if (abbrev(tcp))
1760 printargc(", [/* %d var%s */]", tcp, tcp->u_arg[2]);
1761 else {
1762 tprintf(", [");
1763 printargv(tcp, tcp->u_arg[2]);
1764 tprintf("]");
1765 }
1766 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001767 return 0;
1768}
1769
Roland McGrath5ef24ab2004-02-20 02:22:35 +00001770#if UNIXWARE > 2
John Hughes4e36a812001-04-18 15:11:51 +00001771
1772int sys_rexecve(tcp)
1773struct tcb *tcp;
1774{
1775 if (entering (tcp)) {
1776 sys_execve (tcp);
1777 tprintf (", %ld", tcp->u_arg[3]);
1778 }
1779 return 0;
1780}
1781
Roland McGrath5ef24ab2004-02-20 02:22:35 +00001782#endif
John Hughes4e36a812001-04-18 15:11:51 +00001783
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001784int
1785internal_exec(tcp)
1786struct tcb *tcp;
1787{
1788#ifdef SUNOS4
1789 if (exiting(tcp) && !syserror(tcp) && followfork)
1790 fixvfork(tcp);
1791#endif /* SUNOS4 */
Roland McGrathfdb097f2004-07-12 07:38:55 +00001792#if defined LINUX && defined TCB_WAITEXECVE
1793 if (exiting(tcp) && syserror(tcp))
1794 tcp->flags &= ~TCB_WAITEXECVE;
1795 else
1796 tcp->flags |= TCB_WAITEXECVE;
1797#endif /* LINUX && TCB_WAITEXECVE */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001798 return 0;
1799}
1800
1801#ifdef LINUX
Roland McGrath7ec1d352002-12-17 04:50:44 +00001802#ifndef __WNOTHREAD
1803#define __WNOTHREAD 0x20000000
1804#endif
1805#ifndef __WALL
1806#define __WALL 0x40000000
1807#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001808#ifndef __WCLONE
Roland McGrath7ec1d352002-12-17 04:50:44 +00001809#define __WCLONE 0x80000000
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001810#endif
1811#endif /* LINUX */
1812
Roland McGrathd9f816f2004-09-04 03:39:20 +00001813static const struct xlat wait4_options[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001814 { WNOHANG, "WNOHANG" },
1815#ifndef WSTOPPED
1816 { WUNTRACED, "WUNTRACED" },
1817#endif
1818#ifdef WEXITED
1819 { WEXITED, "WEXITED" },
1820#endif
1821#ifdef WTRAPPED
1822 { WTRAPPED, "WTRAPPED" },
1823#endif
1824#ifdef WSTOPPED
1825 { WSTOPPED, "WSTOPPED" },
1826#endif
1827#ifdef WCONTINUED
1828 { WCONTINUED, "WCONTINUED" },
1829#endif
1830#ifdef WNOWAIT
1831 { WNOWAIT, "WNOWAIT" },
1832#endif
1833#ifdef __WCLONE
1834 { __WCLONE, "__WCLONE" },
1835#endif
Roland McGrath7ec1d352002-12-17 04:50:44 +00001836#ifdef __WALL
1837 { __WALL, "__WALL" },
1838#endif
1839#ifdef __WNOTHREAD
1840 { __WNOTHREAD, "__WNOTHREAD" },
1841#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001842 { 0, NULL },
1843};
1844
Roland McGrath5e02a572004-10-19 23:33:47 +00001845#if !defined WCOREFLAG && defined WCOREFLG
1846# define WCOREFLAG WCOREFLG
1847#endif
1848#ifndef WCOREFLAG
Dmitry V. Levine5e60852009-12-31 22:50:49 +00001849# define WCOREFLAG 0x80
Roland McGrath5e02a572004-10-19 23:33:47 +00001850#endif
Dmitry V. Levine5e60852009-12-31 22:50:49 +00001851#ifndef WCOREDUMP
1852# define WCOREDUMP(status) ((status) & 0200)
1853#endif
1854
Roland McGrath5e02a572004-10-19 23:33:47 +00001855
1856#ifndef W_STOPCODE
1857#define W_STOPCODE(sig) ((sig) << 8 | 0x7f)
1858#endif
1859#ifndef W_EXITCODE
1860#define W_EXITCODE(ret, sig) ((ret) << 8 | (sig))
1861#endif
1862
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001863static int
1864printstatus(status)
1865int status;
1866{
1867 int exited = 0;
1868
1869 /*
1870 * Here is a tricky presentation problem. This solution
1871 * is still not entirely satisfactory but since there
1872 * are no wait status constructors it will have to do.
1873 */
Roland McGrath79fbda52004-04-14 02:45:55 +00001874 if (WIFSTOPPED(status)) {
1875 tprintf("[{WIFSTOPPED(s) && WSTOPSIG(s) == %s}",
Nate Sammonsce780fc1999-03-29 23:23:13 +00001876 signame(WSTOPSIG(status)));
Roland McGrath79fbda52004-04-14 02:45:55 +00001877 status &= ~W_STOPCODE(WSTOPSIG(status));
1878 }
1879 else if (WIFSIGNALED(status)) {
1880 tprintf("[{WIFSIGNALED(s) && WTERMSIG(s) == %s%s}",
Nate Sammonsce780fc1999-03-29 23:23:13 +00001881 signame(WTERMSIG(status)),
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001882 WCOREDUMP(status) ? " && WCOREDUMP(s)" : "");
Roland McGrath79fbda52004-04-14 02:45:55 +00001883 status &= ~(W_EXITCODE(0, WTERMSIG(status)) | WCOREFLAG);
1884 }
1885 else if (WIFEXITED(status)) {
1886 tprintf("[{WIFEXITED(s) && WEXITSTATUS(s) == %d}",
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001887 WEXITSTATUS(status));
1888 exited = 1;
Roland McGrath79fbda52004-04-14 02:45:55 +00001889 status &= ~W_EXITCODE(WEXITSTATUS(status), 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001890 }
Roland McGrath79fbda52004-04-14 02:45:55 +00001891 else {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001892 tprintf("[%#x]", status);
Roland McGrath79fbda52004-04-14 02:45:55 +00001893 return 0;
1894 }
1895
1896 if (status == 0)
1897 tprintf("]");
1898 else
Roland McGrathf8cc83c2004-06-04 01:24:07 +00001899 tprintf(" | %#x]", status);
Roland McGrath79fbda52004-04-14 02:45:55 +00001900
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001901 return exited;
1902}
1903
1904static int
Denys Vlasenko59432db2009-01-26 19:09:35 +00001905printwaitn(struct tcb *tcp, int n, int bitness)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001906{
1907 int status;
1908 int exited = 0;
1909
1910 if (entering(tcp)) {
Denys Vlasenkoe740fd32009-04-16 12:06:16 +00001911#ifdef LINUX
1912 /* On Linux, kernel-side pid_t is typedef'ed to int
1913 * on all arches. Also, glibc-2.8 truncates wait3 and wait4
Denys Vlasenko59432db2009-01-26 19:09:35 +00001914 * pid argument to int on 64bit arches, producing,
1915 * for example, wait4(4294967295, ...) instead of -1
Denys Vlasenkoe740fd32009-04-16 12:06:16 +00001916 * in strace. We have to use int here, not long.
1917 */
1918 int pid = tcp->u_arg[0];
1919 tprintf("%d, ", pid);
1920#else
1921 /*
1922 * Sign-extend a 32-bit value when that's what it is.
Roland McGrath5b63d962008-07-18 02:16:47 +00001923 */
1924 long pid = tcp->u_arg[0];
1925 if (personality_wordsize[current_personality] < sizeof pid)
1926 pid = (long) (int) pid;
1927 tprintf("%ld, ", pid);
Denys Vlasenkoe740fd32009-04-16 12:06:16 +00001928#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001929 } else {
1930 /* status */
1931 if (!tcp->u_arg[1])
1932 tprintf("NULL");
1933 else if (syserror(tcp) || tcp->u_rval == 0)
1934 tprintf("%#lx", tcp->u_arg[1]);
1935 else if (umove(tcp, tcp->u_arg[1], &status) < 0)
1936 tprintf("[?]");
1937 else
1938 exited = printstatus(status);
1939 /* options */
1940 tprintf(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +00001941 printflags(wait4_options, tcp->u_arg[2], "W???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001942 if (n == 4) {
1943 tprintf(", ");
1944 /* usage */
1945 if (!tcp->u_arg[3])
1946 tprintf("NULL");
1947#ifdef LINUX
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001948 else if (tcp->u_rval > 0) {
Denys Vlasenko59432db2009-01-26 19:09:35 +00001949#ifdef ALPHA
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001950 if (bitness)
1951 printrusage32(tcp, tcp->u_arg[3]);
1952 else
1953#endif
1954 printrusage(tcp, tcp->u_arg[3]);
1955 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001956#endif /* LINUX */
1957#ifdef SUNOS4
1958 else if (tcp->u_rval > 0 && exited)
1959 printrusage(tcp, tcp->u_arg[3]);
1960#endif /* SUNOS4 */
1961 else
1962 tprintf("%#lx", tcp->u_arg[3]);
1963 }
1964 }
1965 return 0;
1966}
1967
1968int
Roland McGrathc74c0b72004-09-01 19:39:46 +00001969internal_wait(tcp, flagarg)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001970struct tcb *tcp;
Roland McGrathc74c0b72004-09-01 19:39:46 +00001971int flagarg;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001972{
Roland McGrathe85bbfe2003-01-09 06:53:31 +00001973 int got_kids;
1974
1975#ifdef TCB_CLONE_THREAD
1976 if (tcp->flags & TCB_CLONE_THREAD)
1977 /* The children we wait for are our parent's children. */
1978 got_kids = (tcp->parent->nchildren
Wang Chao21b8db42010-08-27 17:43:16 +08001979 > tcp->parent->nclone_threads);
Roland McGrathe85bbfe2003-01-09 06:53:31 +00001980 else
Wang Chao21b8db42010-08-27 17:43:16 +08001981 got_kids = (tcp->nchildren > tcp->nclone_threads);
Roland McGrathe85bbfe2003-01-09 06:53:31 +00001982#else
1983 got_kids = tcp->nchildren > 0;
1984#endif
1985
1986 if (entering(tcp) && got_kids) {
Roland McGrathb69f81b2002-12-21 23:25:18 +00001987 /* There are children that this parent should block for.
1988 But ptrace made us the parent of the traced children
1989 and the real parent will get ECHILD from the wait call.
1990
1991 XXX If we attached with strace -f -p PID, then there
1992 may be untraced dead children the parent could be reaping
1993 now, but we make him block. */
1994
1995 /* ??? WTA: fix bug with hanging children */
1996
Roland McGrathc74c0b72004-09-01 19:39:46 +00001997 if (!(tcp->u_arg[flagarg] & WNOHANG)) {
Roland McGrath09623452003-05-23 02:27:13 +00001998 /*
1999 * There are traced children. We'll make the parent
2000 * block to avoid a false ECHILD error due to our
2001 * ptrace having stolen the children. However,
2002 * we shouldn't block if there are zombies to reap.
2003 * XXX doesn't handle pgrp matches (u_arg[0]==0,<-1)
2004 */
Roland McGrathfccfb942003-10-01 21:59:44 +00002005 struct tcb *child = NULL;
Roland McGrath09623452003-05-23 02:27:13 +00002006 if (tcp->nzombies > 0 &&
2007 (tcp->u_arg[0] == -1 ||
Roland McGrathfccfb942003-10-01 21:59:44 +00002008 (child = pid2tcb(tcp->u_arg[0])) == NULL))
Roland McGrath09623452003-05-23 02:27:13 +00002009 return 0;
Roland McGrathfccfb942003-10-01 21:59:44 +00002010 if (tcp->u_arg[0] > 0) {
2011 /*
2012 * If the parent waits for a specified child
2013 * PID, then it must get ECHILD right away
2014 * if that PID is not one of its children.
2015 * Make sure that the requested PID matches
2016 * one of the parent's children that we are
2017 * tracing, and don't suspend it otherwise.
2018 */
2019 if (child == NULL)
2020 child = pid2tcb(tcp->u_arg[0]);
2021 if (child == NULL || child->parent != (
2022#ifdef TCB_CLONE_THREAD
2023 (tcp->flags & TCB_CLONE_THREAD)
2024 ? tcp->parent :
2025#endif
Roland McGrathd56a6562005-08-03 11:23:43 +00002026 tcp) ||
2027 (child->flags & TCB_EXITING))
Roland McGrathfccfb942003-10-01 21:59:44 +00002028 return 0;
2029 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002030 tcp->flags |= TCB_SUSPENDED;
2031 tcp->waitpid = tcp->u_arg[0];
Roland McGrathe85bbfe2003-01-09 06:53:31 +00002032#ifdef TCB_CLONE_THREAD
2033 if (tcp->flags & TCB_CLONE_THREAD)
2034 tcp->parent->nclone_waiting++;
2035#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002036 }
2037 }
Roland McGrathe85bbfe2003-01-09 06:53:31 +00002038 if (exiting(tcp) && tcp->u_error == ECHILD && got_kids) {
Roland McGrathc74c0b72004-09-01 19:39:46 +00002039 if (tcp->u_arg[flagarg] & WNOHANG) {
Roland McGrathb69f81b2002-12-21 23:25:18 +00002040 /* We must force a fake result of 0 instead of
2041 the ECHILD error. */
Roland McGrathb69f81b2002-12-21 23:25:18 +00002042 return force_result(tcp, 0, 0);
2043 }
Roland McGrathb69f81b2002-12-21 23:25:18 +00002044 }
Roland McGrath09623452003-05-23 02:27:13 +00002045 else if (exiting(tcp) && tcp->u_error == 0 && tcp->u_rval > 0 &&
2046 tcp->nzombies > 0 && pid2tcb(tcp->u_rval) == NULL) {
2047 /*
2048 * We just reaped a child we don't know about,
2049 * presumably a zombie we already droptcb'd.
2050 */
2051 tcp->nzombies--;
2052 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002053 return 0;
2054}
2055
2056#ifdef SVR4
2057
2058int
2059sys_wait(tcp)
2060struct tcb *tcp;
2061{
2062 if (exiting(tcp)) {
2063 /* The library wrapper stuffs this into the user variable. */
2064 if (!syserror(tcp))
2065 printstatus(getrval2(tcp));
2066 }
2067 return 0;
2068}
2069
2070#endif /* SVR4 */
2071
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002072#ifdef FREEBSD
2073int
2074sys_wait(tcp)
2075struct tcb *tcp;
2076{
2077 int status;
Roland McGrath5a223472002-12-15 23:58:26 +00002078
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002079 if (exiting(tcp)) {
2080 if (!syserror(tcp)) {
2081 if (umove(tcp, tcp->u_arg[0], &status) < 0)
2082 tprintf("%#lx", tcp->u_arg[0]);
2083 else
2084 printstatus(status);
2085 }
2086 }
2087 return 0;
2088}
2089#endif
2090
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002091int
2092sys_waitpid(tcp)
2093struct tcb *tcp;
2094{
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00002095 return printwaitn(tcp, 3, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002096}
2097
2098int
2099sys_wait4(tcp)
2100struct tcb *tcp;
2101{
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00002102 return printwaitn(tcp, 4, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002103}
2104
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00002105#ifdef ALPHA
2106int
2107sys_osf_wait4(tcp)
2108struct tcb *tcp;
2109{
2110 return printwaitn(tcp, 4, 1);
2111}
2112#endif
2113
Roland McGrathc74c0b72004-09-01 19:39:46 +00002114#if defined SVR4 || defined LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002115
Roland McGrathd9f816f2004-09-04 03:39:20 +00002116static const struct xlat waitid_types[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002117 { P_PID, "P_PID" },
Roland McGrathc74c0b72004-09-01 19:39:46 +00002118#ifdef P_PPID
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002119 { P_PPID, "P_PPID" },
Roland McGrathc74c0b72004-09-01 19:39:46 +00002120#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002121 { P_PGID, "P_PGID" },
Roland McGrathc74c0b72004-09-01 19:39:46 +00002122#ifdef P_SID
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002123 { P_SID, "P_SID" },
Roland McGrathc74c0b72004-09-01 19:39:46 +00002124#endif
2125#ifdef P_CID
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002126 { P_CID, "P_CID" },
Roland McGrathc74c0b72004-09-01 19:39:46 +00002127#endif
2128#ifdef P_UID
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002129 { P_UID, "P_UID" },
Roland McGrathc74c0b72004-09-01 19:39:46 +00002130#endif
2131#ifdef P_GID
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002132 { P_GID, "P_GID" },
Roland McGrathc74c0b72004-09-01 19:39:46 +00002133#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002134 { P_ALL, "P_ALL" },
2135#ifdef P_LWPID
2136 { P_LWPID, "P_LWPID" },
2137#endif
2138 { 0, NULL },
2139};
2140
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002141int
Dmitry V. Levin3eb94912010-09-09 23:08:59 +00002142sys_waitid(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002143{
2144 siginfo_t si;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002145
2146 if (entering(tcp)) {
2147 printxval(waitid_types, tcp->u_arg[0], "P_???");
2148 tprintf(", %ld, ", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002149 }
2150 else {
2151 /* siginfo */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002152 if (!tcp->u_arg[2])
2153 tprintf("NULL");
2154 else if (syserror(tcp))
2155 tprintf("%#lx", tcp->u_arg[2]);
2156 else if (umove(tcp, tcp->u_arg[2], &si) < 0)
2157 tprintf("{???}");
2158 else
Denys Vlasenkof535b542009-01-13 18:30:55 +00002159 printsiginfo(&si, verbose(tcp));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002160 /* options */
2161 tprintf(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +00002162 printflags(wait4_options, tcp->u_arg[3], "W???");
Roland McGrath39426a32004-10-06 22:02:59 +00002163 if (tcp->u_nargs > 4) {
2164 /* usage */
2165 tprintf(", ");
2166 if (!tcp->u_arg[4])
2167 tprintf("NULL");
2168 else if (tcp->u_error)
2169 tprintf("%#lx", tcp->u_arg[4]);
2170 else
2171 printrusage(tcp, tcp->u_arg[4]);
2172 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002173 }
2174 return 0;
2175}
2176
Roland McGrathc74c0b72004-09-01 19:39:46 +00002177#endif /* SVR4 or LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002178
2179int
2180sys_alarm(tcp)
2181struct tcb *tcp;
2182{
2183 if (entering(tcp))
2184 tprintf("%lu", tcp->u_arg[0]);
2185 return 0;
2186}
2187
2188int
2189sys_uname(tcp)
2190struct tcb *tcp;
2191{
2192 struct utsname uname;
2193
2194 if (exiting(tcp)) {
2195 if (syserror(tcp) || !verbose(tcp))
2196 tprintf("%#lx", tcp->u_arg[0]);
2197 else if (umove(tcp, tcp->u_arg[0], &uname) < 0)
2198 tprintf("{...}");
2199 else if (!abbrev(tcp)) {
2200
2201 tprintf("{sysname=\"%s\", nodename=\"%s\", ",
2202 uname.sysname, uname.nodename);
2203 tprintf("release=\"%s\", version=\"%s\", ",
2204 uname.release, uname.version);
2205 tprintf("machine=\"%s\"", uname.machine);
2206#ifdef LINUX
2207#ifndef __GLIBC__
2208 tprintf(", domainname=\"%s\"", uname.domainname);
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002209#endif
2210#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002211 tprintf("}");
2212 }
2213 else
2214 tprintf("{sys=\"%s\", node=\"%s\", ...}",
2215 uname.sysname, uname.nodename);
2216 }
2217 return 0;
2218}
2219
2220#ifndef SVR4
2221
Roland McGratheb9e2e82009-06-02 16:49:22 -07002222static const struct xlat ptrace_cmds[] = {
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002223# ifndef FREEBSD
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002224 { PTRACE_TRACEME, "PTRACE_TRACEME" },
2225 { PTRACE_PEEKTEXT, "PTRACE_PEEKTEXT", },
2226 { PTRACE_PEEKDATA, "PTRACE_PEEKDATA", },
2227 { PTRACE_PEEKUSER, "PTRACE_PEEKUSER", },
2228 { PTRACE_POKETEXT, "PTRACE_POKETEXT", },
2229 { PTRACE_POKEDATA, "PTRACE_POKEDATA", },
2230 { PTRACE_POKEUSER, "PTRACE_POKEUSER", },
2231 { PTRACE_CONT, "PTRACE_CONT" },
2232 { PTRACE_KILL, "PTRACE_KILL" },
2233 { PTRACE_SINGLESTEP, "PTRACE_SINGLESTEP" },
2234 { PTRACE_ATTACH, "PTRACE_ATTACH" },
2235 { PTRACE_DETACH, "PTRACE_DETACH" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002236# ifdef PTRACE_GETREGS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002237 { PTRACE_GETREGS, "PTRACE_GETREGS" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002238# endif
2239# ifdef PTRACE_SETREGS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002240 { PTRACE_SETREGS, "PTRACE_SETREGS" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002241# endif
2242# ifdef PTRACE_GETFPREGS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002243 { PTRACE_GETFPREGS, "PTRACE_GETFPREGS", },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002244# endif
2245# ifdef PTRACE_SETFPREGS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002246 { PTRACE_SETFPREGS, "PTRACE_SETFPREGS", },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002247# endif
2248# ifdef PTRACE_GETFPXREGS
Roland McGrathbf621d42003-01-14 09:46:21 +00002249 { PTRACE_GETFPXREGS, "PTRACE_GETFPXREGS", },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002250# endif
2251# ifdef PTRACE_SETFPXREGS
Roland McGrathbf621d42003-01-14 09:46:21 +00002252 { PTRACE_SETFPXREGS, "PTRACE_SETFPXREGS", },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002253# endif
2254# ifdef PTRACE_GETVRREGS
Roland McGrathf04bb482005-05-09 07:45:33 +00002255 { PTRACE_GETVRREGS, "PTRACE_GETVRREGS", },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002256# endif
2257# ifdef PTRACE_SETVRREGS
Roland McGrathf04bb482005-05-09 07:45:33 +00002258 { PTRACE_SETVRREGS, "PTRACE_SETVRREGS", },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002259# endif
2260# ifdef PTRACE_SETOPTIONS
Denys Vlasenkof535b542009-01-13 18:30:55 +00002261 { PTRACE_SETOPTIONS, "PTRACE_SETOPTIONS", },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002262# endif
2263# ifdef PTRACE_GETEVENTMSG
Denys Vlasenkof535b542009-01-13 18:30:55 +00002264 { PTRACE_GETEVENTMSG, "PTRACE_GETEVENTMSG", },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002265# endif
2266# ifdef PTRACE_GETSIGINFO
Denys Vlasenkof535b542009-01-13 18:30:55 +00002267 { PTRACE_GETSIGINFO, "PTRACE_GETSIGINFO", },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002268# endif
2269# ifdef PTRACE_SETSIGINFO
Denys Vlasenkof535b542009-01-13 18:30:55 +00002270 { PTRACE_SETSIGINFO, "PTRACE_SETSIGINFO", },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002271# endif
2272# ifdef PTRACE_SET_SYSCALL
2273 { PTRACE_SET_SYSCALL, "PTRACE_SET_SYSCALL", },
2274# endif
2275# ifdef SUNOS4
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002276 { PTRACE_READDATA, "PTRACE_READDATA" },
2277 { PTRACE_WRITEDATA, "PTRACE_WRITEDATA" },
2278 { PTRACE_READTEXT, "PTRACE_READTEXT" },
2279 { PTRACE_WRITETEXT, "PTRACE_WRITETEXT" },
2280 { PTRACE_GETFPAREGS, "PTRACE_GETFPAREGS" },
2281 { PTRACE_SETFPAREGS, "PTRACE_SETFPAREGS" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002282# ifdef SPARC
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002283 { PTRACE_GETWINDOW, "PTRACE_GETWINDOW" },
2284 { PTRACE_SETWINDOW, "PTRACE_SETWINDOW" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002285# else /* !SPARC */
2286 { PTRACE_22, "PTRACE_22" },
2287 { PTRACE_23, "PTRACE_3" },
2288# endif /* !SPARC */
2289# endif /* SUNOS4 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002290 { PTRACE_SYSCALL, "PTRACE_SYSCALL" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002291# ifdef SUNOS4
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002292 { PTRACE_DUMPCORE, "PTRACE_DUMPCORE" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002293# ifdef I386
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002294 { PTRACE_SETWRBKPT, "PTRACE_SETWRBKPT" },
2295 { PTRACE_SETACBKPT, "PTRACE_SETACBKPT" },
2296 { PTRACE_CLRDR7, "PTRACE_CLRDR7" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002297# else /* !I386 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002298 { PTRACE_26, "PTRACE_26" },
2299 { PTRACE_27, "PTRACE_27" },
2300 { PTRACE_28, "PTRACE_28" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002301# endif /* !I386 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002302 { PTRACE_GETUCODE, "PTRACE_GETUCODE" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002303# endif /* SUNOS4 */
Denys Vlasenkof535b542009-01-13 18:30:55 +00002304
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002305# else /* FREEBSD */
Denys Vlasenkof535b542009-01-13 18:30:55 +00002306
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002307 { PT_TRACE_ME, "PT_TRACE_ME" },
2308 { PT_READ_I, "PT_READ_I" },
2309 { PT_READ_D, "PT_READ_D" },
2310 { PT_WRITE_I, "PT_WRITE_I" },
2311 { PT_WRITE_D, "PT_WRITE_D" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002312# ifdef PT_READ_U
John Hughesa2278142001-09-28 16:21:30 +00002313 { PT_READ_U, "PT_READ_U" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002314# endif
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002315 { PT_CONTINUE, "PT_CONTINUE" },
2316 { PT_KILL, "PT_KILL" },
2317 { PT_STEP, "PT_STEP" },
2318 { PT_ATTACH, "PT_ATTACH" },
2319 { PT_DETACH, "PT_DETACH" },
2320 { PT_GETREGS, "PT_GETREGS" },
2321 { PT_SETREGS, "PT_SETREGS" },
2322 { PT_GETFPREGS, "PT_GETFPREGS" },
2323 { PT_SETFPREGS, "PT_SETFPREGS" },
2324 { PT_GETDBREGS, "PT_GETDBREGS" },
2325 { PT_SETDBREGS, "PT_SETDBREGS" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002326# endif /* FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002327 { 0, NULL },
2328};
2329
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002330# ifndef FREEBSD
2331# ifdef PTRACE_SETOPTIONS
Denys Vlasenkof535b542009-01-13 18:30:55 +00002332static const struct xlat ptrace_setoptions_flags[] = {
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002333# ifdef PTRACE_O_TRACESYSGOOD
Denys Vlasenkof535b542009-01-13 18:30:55 +00002334 { PTRACE_O_TRACESYSGOOD,"PTRACE_O_TRACESYSGOOD" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002335# endif
2336# ifdef PTRACE_O_TRACEFORK
Denys Vlasenkof535b542009-01-13 18:30:55 +00002337 { PTRACE_O_TRACEFORK, "PTRACE_O_TRACEFORK" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002338# endif
2339# ifdef PTRACE_O_TRACEVFORK
Denys Vlasenkof535b542009-01-13 18:30:55 +00002340 { PTRACE_O_TRACEVFORK, "PTRACE_O_TRACEVFORK" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002341# endif
2342# ifdef PTRACE_O_TRACECLONE
Denys Vlasenkof535b542009-01-13 18:30:55 +00002343 { PTRACE_O_TRACECLONE, "PTRACE_O_TRACECLONE" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002344# endif
2345# ifdef PTRACE_O_TRACEEXEC
Denys Vlasenkof535b542009-01-13 18:30:55 +00002346 { PTRACE_O_TRACEEXEC, "PTRACE_O_TRACEEXEC" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002347# endif
2348# ifdef PTRACE_O_TRACEVFORKDONE
Denys Vlasenkof535b542009-01-13 18:30:55 +00002349 { PTRACE_O_TRACEVFORKDONE,"PTRACE_O_TRACEVFORKDONE"},
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002350# endif
2351# ifdef PTRACE_O_TRACEEXIT
Denys Vlasenkof535b542009-01-13 18:30:55 +00002352 { PTRACE_O_TRACEEXIT, "PTRACE_O_TRACEEXIT" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002353# endif
Denys Vlasenkof535b542009-01-13 18:30:55 +00002354 { 0, NULL },
2355};
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002356# endif /* PTRACE_SETOPTIONS */
2357# endif /* !FREEBSD */
Denys Vlasenkof535b542009-01-13 18:30:55 +00002358
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002359# ifndef FREEBSD
Roland McGrathd9f816f2004-09-04 03:39:20 +00002360const struct xlat struct_user_offsets[] = {
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002361# ifdef LINUX
2362# if defined(S390) || defined(S390X)
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00002363 { PT_PSWMASK, "psw_mask" },
2364 { PT_PSWADDR, "psw_addr" },
2365 { PT_GPR0, "gpr0" },
2366 { PT_GPR1, "gpr1" },
2367 { PT_GPR2, "gpr2" },
2368 { PT_GPR3, "gpr3" },
2369 { PT_GPR4, "gpr4" },
2370 { PT_GPR5, "gpr5" },
2371 { PT_GPR6, "gpr6" },
2372 { PT_GPR7, "gpr7" },
2373 { PT_GPR8, "gpr8" },
2374 { PT_GPR9, "gpr9" },
2375 { PT_GPR10, "gpr10" },
2376 { PT_GPR11, "gpr11" },
2377 { PT_GPR12, "gpr12" },
2378 { PT_GPR13, "gpr13" },
2379 { PT_GPR14, "gpr14" },
2380 { PT_GPR15, "gpr15" },
2381 { PT_ACR0, "acr0" },
2382 { PT_ACR1, "acr1" },
2383 { PT_ACR2, "acr2" },
2384 { PT_ACR3, "acr3" },
2385 { PT_ACR4, "acr4" },
2386 { PT_ACR5, "acr5" },
2387 { PT_ACR6, "acr6" },
2388 { PT_ACR7, "acr7" },
2389 { PT_ACR8, "acr8" },
2390 { PT_ACR9, "acr9" },
2391 { PT_ACR10, "acr10" },
2392 { PT_ACR11, "acr11" },
2393 { PT_ACR12, "acr12" },
2394 { PT_ACR13, "acr13" },
2395 { PT_ACR14, "acr14" },
2396 { PT_ACR15, "acr15" },
2397 { PT_ORIGGPR2, "orig_gpr2" },
2398 { PT_FPC, "fpc" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002399# if defined(S390)
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00002400 { PT_FPR0_HI, "fpr0.hi" },
2401 { PT_FPR0_LO, "fpr0.lo" },
2402 { PT_FPR1_HI, "fpr1.hi" },
2403 { PT_FPR1_LO, "fpr1.lo" },
2404 { PT_FPR2_HI, "fpr2.hi" },
2405 { PT_FPR2_LO, "fpr2.lo" },
2406 { PT_FPR3_HI, "fpr3.hi" },
2407 { PT_FPR3_LO, "fpr3.lo" },
2408 { PT_FPR4_HI, "fpr4.hi" },
2409 { PT_FPR4_LO, "fpr4.lo" },
2410 { PT_FPR5_HI, "fpr5.hi" },
2411 { PT_FPR5_LO, "fpr5.lo" },
2412 { PT_FPR6_HI, "fpr6.hi" },
2413 { PT_FPR6_LO, "fpr6.lo" },
2414 { PT_FPR7_HI, "fpr7.hi" },
2415 { PT_FPR7_LO, "fpr7.lo" },
2416 { PT_FPR8_HI, "fpr8.hi" },
2417 { PT_FPR8_LO, "fpr8.lo" },
2418 { PT_FPR9_HI, "fpr9.hi" },
2419 { PT_FPR9_LO, "fpr9.lo" },
2420 { PT_FPR10_HI, "fpr10.hi" },
2421 { PT_FPR10_LO, "fpr10.lo" },
2422 { PT_FPR11_HI, "fpr11.hi" },
2423 { PT_FPR11_LO, "fpr11.lo" },
2424 { PT_FPR12_HI, "fpr12.hi" },
2425 { PT_FPR12_LO, "fpr12.lo" },
2426 { PT_FPR13_HI, "fpr13.hi" },
2427 { PT_FPR13_LO, "fpr13.lo" },
2428 { PT_FPR14_HI, "fpr14.hi" },
2429 { PT_FPR14_LO, "fpr14.lo" },
2430 { PT_FPR15_HI, "fpr15.hi" },
2431 { PT_FPR15_LO, "fpr15.lo" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002432# endif
2433# if defined(S390X)
Michal Ludvig10a88d02002-10-07 14:31:00 +00002434 { PT_FPR0, "fpr0" },
2435 { PT_FPR1, "fpr1" },
2436 { PT_FPR2, "fpr2" },
2437 { PT_FPR3, "fpr3" },
2438 { PT_FPR4, "fpr4" },
2439 { PT_FPR5, "fpr5" },
2440 { PT_FPR6, "fpr6" },
2441 { PT_FPR7, "fpr7" },
2442 { PT_FPR8, "fpr8" },
2443 { PT_FPR9, "fpr9" },
2444 { PT_FPR10, "fpr10" },
2445 { PT_FPR11, "fpr11" },
2446 { PT_FPR12, "fpr12" },
2447 { PT_FPR13, "fpr13" },
2448 { PT_FPR14, "fpr14" },
2449 { PT_FPR15, "fpr15" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002450# endif
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00002451 { PT_CR_9, "cr9" },
2452 { PT_CR_10, "cr10" },
2453 { PT_CR_11, "cr11" },
Michal Ludvig10a88d02002-10-07 14:31:00 +00002454 { PT_IEEE_IP, "ieee_exception_ip" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002455# elif defined(SPARC)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002456 /* XXX No support for these offsets yet. */
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002457# elif defined(HPPA)
Wichert Akkermanc1652e22001-03-27 12:17:16 +00002458 /* XXX No support for these offsets yet. */
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002459# elif defined(POWERPC)
2460# ifndef PT_ORIG_R3
2461# define PT_ORIG_R3 34
2462# endif
2463# define REGSIZE (sizeof(unsigned long))
Roland McGratheb285352003-01-14 09:59:00 +00002464 { REGSIZE*PT_R0, "r0" },
2465 { REGSIZE*PT_R1, "r1" },
2466 { REGSIZE*PT_R2, "r2" },
2467 { REGSIZE*PT_R3, "r3" },
2468 { REGSIZE*PT_R4, "r4" },
2469 { REGSIZE*PT_R5, "r5" },
2470 { REGSIZE*PT_R6, "r6" },
2471 { REGSIZE*PT_R7, "r7" },
2472 { REGSIZE*PT_R8, "r8" },
2473 { REGSIZE*PT_R9, "r9" },
2474 { REGSIZE*PT_R10, "r10" },
2475 { REGSIZE*PT_R11, "r11" },
2476 { REGSIZE*PT_R12, "r12" },
2477 { REGSIZE*PT_R13, "r13" },
2478 { REGSIZE*PT_R14, "r14" },
2479 { REGSIZE*PT_R15, "r15" },
2480 { REGSIZE*PT_R16, "r16" },
2481 { REGSIZE*PT_R17, "r17" },
2482 { REGSIZE*PT_R18, "r18" },
2483 { REGSIZE*PT_R19, "r19" },
2484 { REGSIZE*PT_R20, "r20" },
2485 { REGSIZE*PT_R21, "r21" },
2486 { REGSIZE*PT_R22, "r22" },
2487 { REGSIZE*PT_R23, "r23" },
2488 { REGSIZE*PT_R24, "r24" },
2489 { REGSIZE*PT_R25, "r25" },
2490 { REGSIZE*PT_R26, "r26" },
2491 { REGSIZE*PT_R27, "r27" },
2492 { REGSIZE*PT_R28, "r28" },
2493 { REGSIZE*PT_R29, "r29" },
2494 { REGSIZE*PT_R30, "r30" },
2495 { REGSIZE*PT_R31, "r31" },
2496 { REGSIZE*PT_NIP, "NIP" },
2497 { REGSIZE*PT_MSR, "MSR" },
2498 { REGSIZE*PT_ORIG_R3, "ORIG_R3" },
2499 { REGSIZE*PT_CTR, "CTR" },
2500 { REGSIZE*PT_LNK, "LNK" },
2501 { REGSIZE*PT_XER, "XER" },
2502 { REGSIZE*PT_CCR, "CCR" },
2503 { REGSIZE*PT_FPR0, "FPR0" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002504# undef REGSIZE
2505# elif defined(ALPHA)
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00002506 { 0, "r0" },
2507 { 1, "r1" },
2508 { 2, "r2" },
2509 { 3, "r3" },
2510 { 4, "r4" },
2511 { 5, "r5" },
2512 { 6, "r6" },
2513 { 7, "r7" },
2514 { 8, "r8" },
2515 { 9, "r9" },
2516 { 10, "r10" },
2517 { 11, "r11" },
2518 { 12, "r12" },
2519 { 13, "r13" },
2520 { 14, "r14" },
2521 { 15, "r15" },
2522 { 16, "r16" },
2523 { 17, "r17" },
2524 { 18, "r18" },
2525 { 19, "r19" },
2526 { 20, "r20" },
2527 { 21, "r21" },
2528 { 22, "r22" },
2529 { 23, "r23" },
2530 { 24, "r24" },
2531 { 25, "r25" },
2532 { 26, "r26" },
2533 { 27, "r27" },
2534 { 28, "r28" },
2535 { 29, "gp" },
2536 { 30, "fp" },
2537 { 31, "zero" },
2538 { 32, "fp0" },
2539 { 33, "fp" },
2540 { 34, "fp2" },
2541 { 35, "fp3" },
2542 { 36, "fp4" },
2543 { 37, "fp5" },
2544 { 38, "fp6" },
2545 { 39, "fp7" },
2546 { 40, "fp8" },
2547 { 41, "fp9" },
2548 { 42, "fp10" },
2549 { 43, "fp11" },
2550 { 44, "fp12" },
2551 { 45, "fp13" },
2552 { 46, "fp14" },
2553 { 47, "fp15" },
2554 { 48, "fp16" },
2555 { 49, "fp17" },
2556 { 50, "fp18" },
2557 { 51, "fp19" },
2558 { 52, "fp20" },
2559 { 53, "fp21" },
2560 { 54, "fp22" },
2561 { 55, "fp23" },
2562 { 56, "fp24" },
2563 { 57, "fp25" },
2564 { 58, "fp26" },
2565 { 59, "fp27" },
2566 { 60, "fp28" },
2567 { 61, "fp29" },
2568 { 62, "fp30" },
2569 { 63, "fp31" },
2570 { 64, "pc" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002571# elif defined(IA64)
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00002572 { PT_F32, "f32" }, { PT_F33, "f33" }, { PT_F34, "f34" },
2573 { PT_F35, "f35" }, { PT_F36, "f36" }, { PT_F37, "f37" },
2574 { PT_F38, "f38" }, { PT_F39, "f39" }, { PT_F40, "f40" },
2575 { PT_F41, "f41" }, { PT_F42, "f42" }, { PT_F43, "f43" },
2576 { PT_F44, "f44" }, { PT_F45, "f45" }, { PT_F46, "f46" },
2577 { PT_F47, "f47" }, { PT_F48, "f48" }, { PT_F49, "f49" },
2578 { PT_F50, "f50" }, { PT_F51, "f51" }, { PT_F52, "f52" },
2579 { PT_F53, "f53" }, { PT_F54, "f54" }, { PT_F55, "f55" },
2580 { PT_F56, "f56" }, { PT_F57, "f57" }, { PT_F58, "f58" },
2581 { PT_F59, "f59" }, { PT_F60, "f60" }, { PT_F61, "f61" },
2582 { PT_F62, "f62" }, { PT_F63, "f63" }, { PT_F64, "f64" },
2583 { PT_F65, "f65" }, { PT_F66, "f66" }, { PT_F67, "f67" },
2584 { PT_F68, "f68" }, { PT_F69, "f69" }, { PT_F70, "f70" },
2585 { PT_F71, "f71" }, { PT_F72, "f72" }, { PT_F73, "f73" },
2586 { PT_F74, "f74" }, { PT_F75, "f75" }, { PT_F76, "f76" },
2587 { PT_F77, "f77" }, { PT_F78, "f78" }, { PT_F79, "f79" },
2588 { PT_F80, "f80" }, { PT_F81, "f81" }, { PT_F82, "f82" },
2589 { PT_F83, "f83" }, { PT_F84, "f84" }, { PT_F85, "f85" },
2590 { PT_F86, "f86" }, { PT_F87, "f87" }, { PT_F88, "f88" },
2591 { PT_F89, "f89" }, { PT_F90, "f90" }, { PT_F91, "f91" },
2592 { PT_F92, "f92" }, { PT_F93, "f93" }, { PT_F94, "f94" },
2593 { PT_F95, "f95" }, { PT_F96, "f96" }, { PT_F97, "f97" },
2594 { PT_F98, "f98" }, { PT_F99, "f99" }, { PT_F100, "f100" },
2595 { PT_F101, "f101" }, { PT_F102, "f102" }, { PT_F103, "f103" },
2596 { PT_F104, "f104" }, { PT_F105, "f105" }, { PT_F106, "f106" },
2597 { PT_F107, "f107" }, { PT_F108, "f108" }, { PT_F109, "f109" },
2598 { PT_F110, "f110" }, { PT_F111, "f111" }, { PT_F112, "f112" },
2599 { PT_F113, "f113" }, { PT_F114, "f114" }, { PT_F115, "f115" },
2600 { PT_F116, "f116" }, { PT_F117, "f117" }, { PT_F118, "f118" },
2601 { PT_F119, "f119" }, { PT_F120, "f120" }, { PT_F121, "f121" },
2602 { PT_F122, "f122" }, { PT_F123, "f123" }, { PT_F124, "f124" },
2603 { PT_F125, "f125" }, { PT_F126, "f126" }, { PT_F127, "f127" },
2604 /* switch stack: */
2605 { PT_F2, "f2" }, { PT_F3, "f3" }, { PT_F4, "f4" },
2606 { PT_F5, "f5" }, { PT_F10, "f10" }, { PT_F11, "f11" },
2607 { PT_F12, "f12" }, { PT_F13, "f13" }, { PT_F14, "f14" },
2608 { PT_F15, "f15" }, { PT_F16, "f16" }, { PT_F17, "f17" },
2609 { PT_F18, "f18" }, { PT_F19, "f19" }, { PT_F20, "f20" },
2610 { PT_F21, "f21" }, { PT_F22, "f22" }, { PT_F23, "f23" },
2611 { PT_F24, "f24" }, { PT_F25, "f25" }, { PT_F26, "f26" },
2612 { PT_F27, "f27" }, { PT_F28, "f28" }, { PT_F29, "f29" },
2613 { PT_F30, "f30" }, { PT_F31, "f31" }, { PT_R4, "r4" },
2614 { PT_R5, "r5" }, { PT_R6, "r6" }, { PT_R7, "r7" },
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00002615 { PT_B1, "b1" }, { PT_B2, "b2" }, { PT_B3, "b3" },
2616 { PT_B4, "b4" }, { PT_B5, "b5" },
Roland McGrathca4e10c2004-01-13 10:13:20 +00002617 { PT_AR_EC, "ar.ec" }, { PT_AR_LC, "ar.lc" },
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00002618 /* pt_regs */
Roland McGrathca4e10c2004-01-13 10:13:20 +00002619 { PT_CR_IPSR, "psr" }, { PT_CR_IIP, "ip" },
2620 { PT_CFM, "cfm" }, { PT_AR_UNAT, "ar.unat" },
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00002621 { PT_AR_PFS, "ar.pfs" }, { PT_AR_RSC, "ar.rsc" },
2622 { PT_AR_RNAT, "ar.rnat" }, { PT_AR_BSPSTORE, "ar.bspstore" },
2623 { PT_PR, "pr" }, { PT_B6, "b6" }, { PT_AR_BSP, "ar.bsp" },
2624 { PT_R1, "r1" }, { PT_R2, "r2" }, { PT_R3, "r3" },
2625 { PT_R12, "r12" }, { PT_R13, "r13" }, { PT_R14, "r14" },
2626 { PT_R15, "r15" }, { PT_R8, "r8" }, { PT_R9, "r9" },
2627 { PT_R10, "r10" }, { PT_R11, "r11" }, { PT_R16, "r16" },
2628 { PT_R17, "r17" }, { PT_R18, "r18" }, { PT_R19, "r19" },
2629 { PT_R20, "r20" }, { PT_R21, "r21" }, { PT_R22, "r22" },
2630 { PT_R23, "r23" }, { PT_R24, "r24" }, { PT_R25, "r25" },
2631 { PT_R26, "r26" }, { PT_R27, "r27" }, { PT_R28, "r28" },
2632 { PT_R29, "r29" }, { PT_R30, "r30" }, { PT_R31, "r31" },
2633 { PT_AR_CCV, "ar.ccv" }, { PT_AR_FPSR, "ar.fpsr" },
2634 { PT_B0, "b0" }, { PT_B7, "b7" }, { PT_F6, "f6" },
2635 { PT_F7, "f7" }, { PT_F8, "f8" }, { PT_F9, "f9" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002636# ifdef PT_AR_CSD
Roland McGrathfb1bc072004-03-01 21:29:24 +00002637 { PT_AR_CSD, "ar.csd" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002638# endif
2639# ifdef PT_AR_SSD
Roland McGrathfb1bc072004-03-01 21:29:24 +00002640 { PT_AR_SSD, "ar.ssd" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002641# endif
Roland McGrathca4e10c2004-01-13 10:13:20 +00002642 { PT_DBR, "dbr" }, { PT_IBR, "ibr" }, { PT_PMD, "pmd" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002643# elif defined(I386)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002644 { 4*EBX, "4*EBX" },
2645 { 4*ECX, "4*ECX" },
2646 { 4*EDX, "4*EDX" },
2647 { 4*ESI, "4*ESI" },
2648 { 4*EDI, "4*EDI" },
2649 { 4*EBP, "4*EBP" },
2650 { 4*EAX, "4*EAX" },
2651 { 4*DS, "4*DS" },
2652 { 4*ES, "4*ES" },
2653 { 4*FS, "4*FS" },
2654 { 4*GS, "4*GS" },
2655 { 4*ORIG_EAX, "4*ORIG_EAX" },
2656 { 4*EIP, "4*EIP" },
2657 { 4*CS, "4*CS" },
2658 { 4*EFL, "4*EFL" },
2659 { 4*UESP, "4*UESP" },
2660 { 4*SS, "4*SS" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002661# elif defined(X86_64)
Roland McGratha4f9f2d2005-06-07 23:21:20 +00002662 { 8*R15, "8*R15" },
2663 { 8*R14, "8*R14" },
2664 { 8*R13, "8*R13" },
2665 { 8*R12, "8*R12" },
Michal Ludvig0e035502002-09-23 15:41:01 +00002666 { 8*RBP, "8*RBP" },
Roland McGratha4f9f2d2005-06-07 23:21:20 +00002667 { 8*RBX, "8*RBX" },
2668 { 8*R11, "8*R11" },
2669 { 8*R10, "8*R10" },
2670 { 8*R9, "8*R9" },
2671 { 8*R8, "8*R8" },
Michal Ludvig0e035502002-09-23 15:41:01 +00002672 { 8*RAX, "8*RAX" },
Roland McGratha4f9f2d2005-06-07 23:21:20 +00002673 { 8*RCX, "8*RCX" },
2674 { 8*RDX, "8*RDX" },
2675 { 8*RSI, "8*RSI" },
2676 { 8*RDI, "8*RDI" },
Roland McGratha4f9f2d2005-06-07 23:21:20 +00002677 { 8*ORIG_RAX, "8*ORIG_RAX" },
Michal Ludvig0e035502002-09-23 15:41:01 +00002678 { 8*RIP, "8*RIP" },
2679 { 8*CS, "8*CS" },
2680 { 8*EFLAGS, "8*EFL" },
Roland McGratha4f9f2d2005-06-07 23:21:20 +00002681 { 8*RSP, "8*RSP" },
Michal Ludvig0e035502002-09-23 15:41:01 +00002682 { 8*SS, "8*SS" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002683# elif defined(M68K)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002684 { 4*PT_D1, "4*PT_D1" },
2685 { 4*PT_D2, "4*PT_D2" },
2686 { 4*PT_D3, "4*PT_D3" },
2687 { 4*PT_D4, "4*PT_D4" },
2688 { 4*PT_D5, "4*PT_D5" },
2689 { 4*PT_D6, "4*PT_D6" },
2690 { 4*PT_D7, "4*PT_D7" },
2691 { 4*PT_A0, "4*PT_A0" },
2692 { 4*PT_A1, "4*PT_A1" },
2693 { 4*PT_A2, "4*PT_A2" },
2694 { 4*PT_A3, "4*PT_A3" },
2695 { 4*PT_A4, "4*PT_A4" },
2696 { 4*PT_A5, "4*PT_A5" },
2697 { 4*PT_A6, "4*PT_A6" },
2698 { 4*PT_D0, "4*PT_D0" },
2699 { 4*PT_USP, "4*PT_USP" },
2700 { 4*PT_ORIG_D0, "4*PT_ORIG_D0" },
2701 { 4*PT_SR, "4*PT_SR" },
2702 { 4*PT_PC, "4*PT_PC" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002703# elif defined(SH)
Denys Vlasenkoadedb512008-12-30 18:47:55 +00002704 { 4*REG_REG0, "4*REG_REG0" },
2705 { 4*(REG_REG0+1), "4*REG_REG1" },
2706 { 4*(REG_REG0+2), "4*REG_REG2" },
2707 { 4*(REG_REG0+3), "4*REG_REG3" },
2708 { 4*(REG_REG0+4), "4*REG_REG4" },
2709 { 4*(REG_REG0+5), "4*REG_REG5" },
2710 { 4*(REG_REG0+6), "4*REG_REG6" },
2711 { 4*(REG_REG0+7), "4*REG_REG7" },
2712 { 4*(REG_REG0+8), "4*REG_REG8" },
2713 { 4*(REG_REG0+9), "4*REG_REG9" },
2714 { 4*(REG_REG0+10), "4*REG_REG10" },
2715 { 4*(REG_REG0+11), "4*REG_REG11" },
2716 { 4*(REG_REG0+12), "4*REG_REG12" },
2717 { 4*(REG_REG0+13), "4*REG_REG13" },
2718 { 4*(REG_REG0+14), "4*REG_REG14" },
2719 { 4*REG_REG15, "4*REG_REG15" },
2720 { 4*REG_PC, "4*REG_PC" },
2721 { 4*REG_PR, "4*REG_PR" },
2722 { 4*REG_SR, "4*REG_SR" },
2723 { 4*REG_GBR, "4*REG_GBR" },
2724 { 4*REG_MACH, "4*REG_MACH" },
2725 { 4*REG_MACL, "4*REG_MACL" },
2726 { 4*REG_SYSCALL, "4*REG_SYSCALL" },
2727 { 4*REG_FPUL, "4*REG_FPUL" },
2728 { 4*REG_FPREG0, "4*REG_FPREG0" },
2729 { 4*(REG_FPREG0+1), "4*REG_FPREG1" },
2730 { 4*(REG_FPREG0+2), "4*REG_FPREG2" },
2731 { 4*(REG_FPREG0+3), "4*REG_FPREG3" },
2732 { 4*(REG_FPREG0+4), "4*REG_FPREG4" },
2733 { 4*(REG_FPREG0+5), "4*REG_FPREG5" },
2734 { 4*(REG_FPREG0+6), "4*REG_FPREG6" },
2735 { 4*(REG_FPREG0+7), "4*REG_FPREG7" },
2736 { 4*(REG_FPREG0+8), "4*REG_FPREG8" },
2737 { 4*(REG_FPREG0+9), "4*REG_FPREG9" },
2738 { 4*(REG_FPREG0+10), "4*REG_FPREG10" },
2739 { 4*(REG_FPREG0+11), "4*REG_FPREG11" },
2740 { 4*(REG_FPREG0+12), "4*REG_FPREG12" },
2741 { 4*(REG_FPREG0+13), "4*REG_FPREG13" },
2742 { 4*(REG_FPREG0+14), "4*REG_FPREG14" },
2743 { 4*REG_FPREG15, "4*REG_FPREG15" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002744# ifdef REG_XDREG0
Denys Vlasenkoadedb512008-12-30 18:47:55 +00002745 { 4*REG_XDREG0, "4*REG_XDREG0" },
2746 { 4*(REG_XDREG0+2), "4*REG_XDREG2" },
2747 { 4*(REG_XDREG0+4), "4*REG_XDREG4" },
2748 { 4*(REG_XDREG0+6), "4*REG_XDREG6" },
2749 { 4*(REG_XDREG0+8), "4*REG_XDREG8" },
2750 { 4*(REG_XDREG0+10), "4*REG_XDREG10" },
2751 { 4*(REG_XDREG0+12), "4*REG_XDREG12" },
2752 { 4*REG_XDREG14, "4*REG_XDREG14" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002753# endif
Denys Vlasenkoadedb512008-12-30 18:47:55 +00002754 { 4*REG_FPSCR, "4*REG_FPSCR" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002755# elif defined(SH64)
Roland McGrathe1e584b2003-06-02 19:18:58 +00002756 { 0, "PC(L)" },
2757 { 4, "PC(U)" },
2758 { 8, "SR(L)" },
2759 { 12, "SR(U)" },
2760 { 16, "syscall no.(L)" },
2761 { 20, "syscall_no.(U)" },
2762 { 24, "R0(L)" },
2763 { 28, "R0(U)" },
2764 { 32, "R1(L)" },
2765 { 36, "R1(U)" },
2766 { 40, "R2(L)" },
2767 { 44, "R2(U)" },
2768 { 48, "R3(L)" },
2769 { 52, "R3(U)" },
2770 { 56, "R4(L)" },
2771 { 60, "R4(U)" },
2772 { 64, "R5(L)" },
2773 { 68, "R5(U)" },
2774 { 72, "R6(L)" },
2775 { 76, "R6(U)" },
2776 { 80, "R7(L)" },
2777 { 84, "R7(U)" },
2778 { 88, "R8(L)" },
2779 { 92, "R8(U)" },
2780 { 96, "R9(L)" },
2781 { 100, "R9(U)" },
2782 { 104, "R10(L)" },
2783 { 108, "R10(U)" },
2784 { 112, "R11(L)" },
2785 { 116, "R11(U)" },
2786 { 120, "R12(L)" },
2787 { 124, "R12(U)" },
2788 { 128, "R13(L)" },
2789 { 132, "R13(U)" },
2790 { 136, "R14(L)" },
2791 { 140, "R14(U)" },
2792 { 144, "R15(L)" },
2793 { 148, "R15(U)" },
2794 { 152, "R16(L)" },
2795 { 156, "R16(U)" },
2796 { 160, "R17(L)" },
2797 { 164, "R17(U)" },
2798 { 168, "R18(L)" },
2799 { 172, "R18(U)" },
2800 { 176, "R19(L)" },
2801 { 180, "R19(U)" },
2802 { 184, "R20(L)" },
2803 { 188, "R20(U)" },
2804 { 192, "R21(L)" },
2805 { 196, "R21(U)" },
2806 { 200, "R22(L)" },
2807 { 204, "R22(U)" },
2808 { 208, "R23(L)" },
2809 { 212, "R23(U)" },
2810 { 216, "R24(L)" },
2811 { 220, "R24(U)" },
2812 { 224, "R25(L)" },
2813 { 228, "R25(U)" },
2814 { 232, "R26(L)" },
2815 { 236, "R26(U)" },
2816 { 240, "R27(L)" },
2817 { 244, "R27(U)" },
2818 { 248, "R28(L)" },
2819 { 252, "R28(U)" },
2820 { 256, "R29(L)" },
2821 { 260, "R29(U)" },
2822 { 264, "R30(L)" },
2823 { 268, "R30(U)" },
2824 { 272, "R31(L)" },
2825 { 276, "R31(U)" },
2826 { 280, "R32(L)" },
2827 { 284, "R32(U)" },
2828 { 288, "R33(L)" },
2829 { 292, "R33(U)" },
2830 { 296, "R34(L)" },
2831 { 300, "R34(U)" },
2832 { 304, "R35(L)" },
2833 { 308, "R35(U)" },
2834 { 312, "R36(L)" },
2835 { 316, "R36(U)" },
2836 { 320, "R37(L)" },
2837 { 324, "R37(U)" },
2838 { 328, "R38(L)" },
2839 { 332, "R38(U)" },
2840 { 336, "R39(L)" },
2841 { 340, "R39(U)" },
2842 { 344, "R40(L)" },
2843 { 348, "R40(U)" },
2844 { 352, "R41(L)" },
2845 { 356, "R41(U)" },
2846 { 360, "R42(L)" },
2847 { 364, "R42(U)" },
2848 { 368, "R43(L)" },
2849 { 372, "R43(U)" },
2850 { 376, "R44(L)" },
2851 { 380, "R44(U)" },
2852 { 384, "R45(L)" },
2853 { 388, "R45(U)" },
2854 { 392, "R46(L)" },
2855 { 396, "R46(U)" },
2856 { 400, "R47(L)" },
2857 { 404, "R47(U)" },
2858 { 408, "R48(L)" },
2859 { 412, "R48(U)" },
2860 { 416, "R49(L)" },
2861 { 420, "R49(U)" },
2862 { 424, "R50(L)" },
2863 { 428, "R50(U)" },
2864 { 432, "R51(L)" },
2865 { 436, "R51(U)" },
2866 { 440, "R52(L)" },
2867 { 444, "R52(U)" },
2868 { 448, "R53(L)" },
2869 { 452, "R53(U)" },
2870 { 456, "R54(L)" },
2871 { 460, "R54(U)" },
2872 { 464, "R55(L)" },
2873 { 468, "R55(U)" },
2874 { 472, "R56(L)" },
2875 { 476, "R56(U)" },
2876 { 480, "R57(L)" },
2877 { 484, "R57(U)" },
2878 { 488, "R58(L)" },
2879 { 492, "R58(U)" },
2880 { 496, "R59(L)" },
2881 { 500, "R59(U)" },
2882 { 504, "R60(L)" },
2883 { 508, "R60(U)" },
2884 { 512, "R61(L)" },
2885 { 516, "R61(U)" },
2886 { 520, "R62(L)" },
2887 { 524, "R62(U)" },
2888 { 528, "TR0(L)" },
2889 { 532, "TR0(U)" },
2890 { 536, "TR1(L)" },
2891 { 540, "TR1(U)" },
2892 { 544, "TR2(L)" },
2893 { 548, "TR2(U)" },
2894 { 552, "TR3(L)" },
2895 { 556, "TR3(U)" },
2896 { 560, "TR4(L)" },
2897 { 564, "TR4(U)" },
2898 { 568, "TR5(L)" },
2899 { 572, "TR5(U)" },
2900 { 576, "TR6(L)" },
2901 { 580, "TR6(U)" },
2902 { 584, "TR7(L)" },
2903 { 588, "TR7(U)" },
Denys Vlasenkoadedb512008-12-30 18:47:55 +00002904 /* This entry is in case pt_regs contains dregs (depends on
2905 the kernel build options). */
Roland McGrathe1e584b2003-06-02 19:18:58 +00002906 { uoff(regs), "offsetof(struct user, regs)" },
2907 { uoff(fpu), "offsetof(struct user, fpu)" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002908# elif defined(ARM)
Roland McGrath0f87c492003-06-03 23:29:04 +00002909 { uoff(regs.ARM_r0), "r0" },
2910 { uoff(regs.ARM_r1), "r1" },
2911 { uoff(regs.ARM_r2), "r2" },
2912 { uoff(regs.ARM_r3), "r3" },
2913 { uoff(regs.ARM_r4), "r4" },
2914 { uoff(regs.ARM_r5), "r5" },
2915 { uoff(regs.ARM_r6), "r6" },
2916 { uoff(regs.ARM_r7), "r7" },
2917 { uoff(regs.ARM_r8), "r8" },
2918 { uoff(regs.ARM_r9), "r9" },
2919 { uoff(regs.ARM_r10), "r10" },
2920 { uoff(regs.ARM_fp), "fp" },
2921 { uoff(regs.ARM_ip), "ip" },
2922 { uoff(regs.ARM_sp), "sp" },
2923 { uoff(regs.ARM_lr), "lr" },
2924 { uoff(regs.ARM_pc), "pc" },
2925 { uoff(regs.ARM_cpsr), "cpsr" },
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +00002926# elif defined(AVR32)
2927 { uoff(regs.sr), "sr" },
2928 { uoff(regs.pc), "pc" },
2929 { uoff(regs.lr), "lr" },
2930 { uoff(regs.sp), "sp" },
2931 { uoff(regs.r12), "r12" },
2932 { uoff(regs.r11), "r11" },
2933 { uoff(regs.r10), "r10" },
2934 { uoff(regs.r9), "r9" },
2935 { uoff(regs.r8), "r8" },
2936 { uoff(regs.r7), "r7" },
2937 { uoff(regs.r6), "r6" },
2938 { uoff(regs.r5), "r5" },
2939 { uoff(regs.r4), "r4" },
2940 { uoff(regs.r3), "r3" },
2941 { uoff(regs.r2), "r2" },
2942 { uoff(regs.r1), "r1" },
2943 { uoff(regs.r0), "r0" },
2944 { uoff(regs.r12_orig), "orig_r12" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002945# elif defined(MIPS)
Roland McGrath542c2c62008-05-20 01:11:56 +00002946 { 0, "r0" },
2947 { 1, "r1" },
2948 { 2, "r2" },
2949 { 3, "r3" },
2950 { 4, "r4" },
2951 { 5, "r5" },
2952 { 6, "r6" },
2953 { 7, "r7" },
2954 { 8, "r8" },
2955 { 9, "r9" },
2956 { 10, "r10" },
2957 { 11, "r11" },
2958 { 12, "r12" },
2959 { 13, "r13" },
2960 { 14, "r14" },
2961 { 15, "r15" },
2962 { 16, "r16" },
2963 { 17, "r17" },
2964 { 18, "r18" },
2965 { 19, "r19" },
2966 { 20, "r20" },
2967 { 21, "r21" },
2968 { 22, "r22" },
2969 { 23, "r23" },
2970 { 24, "r24" },
2971 { 25, "r25" },
2972 { 26, "r26" },
2973 { 27, "r27" },
2974 { 28, "r28" },
2975 { 29, "r29" },
2976 { 30, "r30" },
2977 { 31, "r31" },
2978 { 32, "f0" },
2979 { 33, "f1" },
2980 { 34, "f2" },
2981 { 35, "f3" },
2982 { 36, "f4" },
2983 { 37, "f5" },
2984 { 38, "f6" },
2985 { 39, "f7" },
2986 { 40, "f8" },
2987 { 41, "f9" },
2988 { 42, "f10" },
2989 { 43, "f11" },
2990 { 44, "f12" },
2991 { 45, "f13" },
2992 { 46, "f14" },
2993 { 47, "f15" },
2994 { 48, "f16" },
2995 { 49, "f17" },
2996 { 50, "f18" },
2997 { 51, "f19" },
2998 { 52, "f20" },
2999 { 53, "f21" },
3000 { 54, "f22" },
3001 { 55, "f23" },
3002 { 56, "f24" },
3003 { 57, "f25" },
3004 { 58, "f26" },
3005 { 59, "f27" },
3006 { 60, "f28" },
3007 { 61, "f29" },
3008 { 62, "f30" },
3009 { 63, "f31" },
3010 { 64, "pc" },
3011 { 65, "cause" },
3012 { 66, "badvaddr" },
3013 { 67, "mmhi" },
3014 { 68, "mmlo" },
3015 { 69, "fpcsr" },
3016 { 70, "fpeir" },
Chris Metcalfc8c66982009-12-28 10:00:15 -05003017# elif defined(TILE)
3018 { PTREGS_OFFSET_REG(0), "r0" },
3019 { PTREGS_OFFSET_REG(1), "r1" },
3020 { PTREGS_OFFSET_REG(2), "r2" },
3021 { PTREGS_OFFSET_REG(3), "r3" },
3022 { PTREGS_OFFSET_REG(4), "r4" },
3023 { PTREGS_OFFSET_REG(5), "r5" },
3024 { PTREGS_OFFSET_REG(6), "r6" },
3025 { PTREGS_OFFSET_REG(7), "r7" },
3026 { PTREGS_OFFSET_REG(8), "r8" },
3027 { PTREGS_OFFSET_REG(9), "r9" },
3028 { PTREGS_OFFSET_REG(10), "r10" },
3029 { PTREGS_OFFSET_REG(11), "r11" },
3030 { PTREGS_OFFSET_REG(12), "r12" },
3031 { PTREGS_OFFSET_REG(13), "r13" },
3032 { PTREGS_OFFSET_REG(14), "r14" },
3033 { PTREGS_OFFSET_REG(15), "r15" },
3034 { PTREGS_OFFSET_REG(16), "r16" },
3035 { PTREGS_OFFSET_REG(17), "r17" },
3036 { PTREGS_OFFSET_REG(18), "r18" },
3037 { PTREGS_OFFSET_REG(19), "r19" },
3038 { PTREGS_OFFSET_REG(20), "r20" },
3039 { PTREGS_OFFSET_REG(21), "r21" },
3040 { PTREGS_OFFSET_REG(22), "r22" },
3041 { PTREGS_OFFSET_REG(23), "r23" },
3042 { PTREGS_OFFSET_REG(24), "r24" },
3043 { PTREGS_OFFSET_REG(25), "r25" },
3044 { PTREGS_OFFSET_REG(26), "r26" },
3045 { PTREGS_OFFSET_REG(27), "r27" },
3046 { PTREGS_OFFSET_REG(28), "r28" },
3047 { PTREGS_OFFSET_REG(29), "r29" },
3048 { PTREGS_OFFSET_REG(30), "r30" },
3049 { PTREGS_OFFSET_REG(31), "r31" },
3050 { PTREGS_OFFSET_REG(32), "r32" },
3051 { PTREGS_OFFSET_REG(33), "r33" },
3052 { PTREGS_OFFSET_REG(34), "r34" },
3053 { PTREGS_OFFSET_REG(35), "r35" },
3054 { PTREGS_OFFSET_REG(36), "r36" },
3055 { PTREGS_OFFSET_REG(37), "r37" },
3056 { PTREGS_OFFSET_REG(38), "r38" },
3057 { PTREGS_OFFSET_REG(39), "r39" },
3058 { PTREGS_OFFSET_REG(40), "r40" },
3059 { PTREGS_OFFSET_REG(41), "r41" },
3060 { PTREGS_OFFSET_REG(42), "r42" },
3061 { PTREGS_OFFSET_REG(43), "r43" },
3062 { PTREGS_OFFSET_REG(44), "r44" },
3063 { PTREGS_OFFSET_REG(45), "r45" },
3064 { PTREGS_OFFSET_REG(46), "r46" },
3065 { PTREGS_OFFSET_REG(47), "r47" },
3066 { PTREGS_OFFSET_REG(48), "r48" },
3067 { PTREGS_OFFSET_REG(49), "r49" },
3068 { PTREGS_OFFSET_REG(50), "r50" },
3069 { PTREGS_OFFSET_REG(51), "r51" },
3070 { PTREGS_OFFSET_REG(52), "r52" },
3071 { PTREGS_OFFSET_TP, "tp" },
3072 { PTREGS_OFFSET_SP, "sp" },
3073 { PTREGS_OFFSET_LR, "lr" },
3074 { PTREGS_OFFSET_PC, "pc" },
3075 { PTREGS_OFFSET_EX1, "ex1" },
3076 { PTREGS_OFFSET_FAULTNUM, "faultnum" },
3077 { PTREGS_OFFSET_ORIG_R0, "orig_r0" },
3078 { PTREGS_OFFSET_FLAGS, "flags" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003079# endif
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00003080# ifdef CRISV10
3081 { 4*PT_FRAMETYPE, "4*PT_FRAMETYPE" },
3082 { 4*PT_ORIG_R10, "4*PT_ORIG_R10" },
3083 { 4*PT_R13, "4*PT_R13" },
3084 { 4*PT_R12, "4*PT_R12" },
3085 { 4*PT_R11, "4*PT_R11" },
3086 { 4*PT_R10, "4*PT_R10" },
3087 { 4*PT_R9, "4*PT_R9" },
3088 { 4*PT_R8, "4*PT_R8" },
3089 { 4*PT_R7, "4*PT_R7" },
3090 { 4*PT_R6, "4*PT_R6" },
3091 { 4*PT_R5, "4*PT_R5" },
3092 { 4*PT_R4, "4*PT_R4" },
3093 { 4*PT_R3, "4*PT_R3" },
3094 { 4*PT_R2, "4*PT_R2" },
3095 { 4*PT_R1, "4*PT_R1" },
3096 { 4*PT_R0, "4*PT_R0" },
3097 { 4*PT_MOF, "4*PT_MOF" },
3098 { 4*PT_DCCR, "4*PT_DCCR" },
3099 { 4*PT_SRP, "4*PT_SRP" },
3100 { 4*PT_IRP, "4*PT_IRP" },
3101 { 4*PT_CSRINSTR, "4*PT_CSRINSTR" },
3102 { 4*PT_CSRADDR, "4*PT_CSRADDR" },
3103 { 4*PT_CSRDATA, "4*PT_CSRDATA" },
3104 { 4*PT_USP, "4*PT_USP" },
3105# endif
3106# ifdef CRISV32
3107 { 4*PT_ORIG_R10, "4*PT_ORIG_R10" },
3108 { 4*PT_R0, "4*PT_R0" },
3109 { 4*PT_R1, "4*PT_R1" },
3110 { 4*PT_R2, "4*PT_R2" },
3111 { 4*PT_R3, "4*PT_R3" },
3112 { 4*PT_R4, "4*PT_R4" },
3113 { 4*PT_R5, "4*PT_R5" },
3114 { 4*PT_R6, "4*PT_R6" },
3115 { 4*PT_R7, "4*PT_R7" },
3116 { 4*PT_R8, "4*PT_R8" },
3117 { 4*PT_R9, "4*PT_R9" },
3118 { 4*PT_R10, "4*PT_R10" },
3119 { 4*PT_R11, "4*PT_R11" },
3120 { 4*PT_R12, "4*PT_R12" },
3121 { 4*PT_R13, "4*PT_R13" },
3122 { 4*PT_ACR, "4*PT_ACR" },
3123 { 4*PT_SRS, "4*PT_SRS" },
3124 { 4*PT_MOF, "4*PT_MOF" },
3125 { 4*PT_SPC, "4*PT_SPC" },
3126 { 4*PT_CCS, "4*PT_CCS" },
3127 { 4*PT_SRP, "4*PT_SRP" },
3128 { 4*PT_ERP, "4*PT_ERP" },
3129 { 4*PT_EXS, "4*PT_EXS" },
3130 { 4*PT_EDA, "4*PT_EDA" },
3131 { 4*PT_USP, "4*PT_USP" },
3132 { 4*PT_PPC, "4*PT_PPC" },
3133 { 4*PT_BP_CTRL, "4*PT_BP_CTRL" },
3134 { 4*PT_BP+4, "4*PT_BP+4" },
3135 { 4*PT_BP+8, "4*PT_BP+8" },
3136 { 4*PT_BP+12, "4*PT_BP+12" },
3137 { 4*PT_BP+16, "4*PT_BP+16" },
3138 { 4*PT_BP+20, "4*PT_BP+20" },
3139 { 4*PT_BP+24, "4*PT_BP+24" },
3140 { 4*PT_BP+28, "4*PT_BP+28" },
3141 { 4*PT_BP+32, "4*PT_BP+32" },
3142 { 4*PT_BP+36, "4*PT_BP+36" },
3143 { 4*PT_BP+40, "4*PT_BP+40" },
3144 { 4*PT_BP+44, "4*PT_BP+44" },
3145 { 4*PT_BP+48, "4*PT_BP+48" },
3146 { 4*PT_BP+52, "4*PT_BP+52" },
3147 { 4*PT_BP+56, "4*PT_BP+56" },
3148# endif
Edgar E. Iglesias939caba2010-07-06 14:21:07 +02003149# ifdef MICROBLAZE
3150 { PT_GPR(0), "r0" },
3151 { PT_GPR(1), "r1" },
3152 { PT_GPR(2), "r2" },
3153 { PT_GPR(3), "r3" },
3154 { PT_GPR(4), "r4" },
3155 { PT_GPR(5), "r5" },
3156 { PT_GPR(6), "r6" },
3157 { PT_GPR(7), "r7" },
3158 { PT_GPR(8), "r8" },
3159 { PT_GPR(9), "r9" },
3160 { PT_GPR(10), "r10" },
3161 { PT_GPR(11), "r11" },
3162 { PT_GPR(12), "r12" },
3163 { PT_GPR(13), "r13" },
3164 { PT_GPR(14), "r14" },
3165 { PT_GPR(15), "r15" },
3166 { PT_GPR(16), "r16" },
3167 { PT_GPR(17), "r17" },
3168 { PT_GPR(18), "r18" },
3169 { PT_GPR(19), "r19" },
3170 { PT_GPR(20), "r20" },
3171 { PT_GPR(21), "r21" },
3172 { PT_GPR(22), "r22" },
3173 { PT_GPR(23), "r23" },
3174 { PT_GPR(24), "r24" },
3175 { PT_GPR(25), "r25" },
3176 { PT_GPR(26), "r26" },
3177 { PT_GPR(27), "r27" },
3178 { PT_GPR(28), "r28" },
3179 { PT_GPR(29), "r29" },
3180 { PT_GPR(30), "r30" },
3181 { PT_GPR(31), "r31" },
3182 { PT_PC, "rpc", },
3183 { PT_MSR, "rmsr", },
3184 { PT_EAR, "rear", },
3185 { PT_ESR, "resr", },
3186 { PT_FSR, "rfsr", },
3187 { PT_KERNEL_MODE, "kernel_mode", },
3188# endif
Roland McGrath542c2c62008-05-20 01:11:56 +00003189
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00003190# if !defined(SPARC) && !defined(HPPA) && !defined(POWERPC) \
3191 && !defined(ALPHA) && !defined(IA64) \
Edgar E. Iglesias939caba2010-07-06 14:21:07 +02003192 && !defined(CRISV10) && !defined(CRISV32) && !defined(MICROBLAZE)
Chris Metcalfc8c66982009-12-28 10:00:15 -05003193# if !defined(S390) && !defined(S390X) && !defined(MIPS) && !defined(SPARC64) && !defined(AVR32) && !defined(BFIN) && !defined(TILE)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003194 { uoff(u_fpvalid), "offsetof(struct user, u_fpvalid)" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003195# endif
3196# if defined(I386) || defined(X86_64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003197 { uoff(i387), "offsetof(struct user, i387)" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003198# endif
3199# if defined(M68K)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003200 { uoff(m68kfp), "offsetof(struct user, m68kfp)" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003201# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003202 { uoff(u_tsize), "offsetof(struct user, u_tsize)" },
3203 { uoff(u_dsize), "offsetof(struct user, u_dsize)" },
3204 { uoff(u_ssize), "offsetof(struct user, u_ssize)" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003205# if !defined(SPARC64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003206 { uoff(start_code), "offsetof(struct user, start_code)" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003207# endif
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +00003208# if defined(AVR32) || defined(SH64)
Roland McGrathe1e584b2003-06-02 19:18:58 +00003209 { uoff(start_data), "offsetof(struct user, start_data)" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003210# endif
3211# if !defined(SPARC64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003212 { uoff(start_stack), "offsetof(struct user, start_stack)" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003213# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003214 { uoff(signal), "offsetof(struct user, signal)" },
Chris Metcalfc8c66982009-12-28 10:00:15 -05003215# if !defined(AVR32) && !defined(S390) && !defined(S390X) && !defined(MIPS) && !defined(SH) && !defined(SH64) && !defined(SPARC64) && !defined(TILE)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003216 { uoff(reserved), "offsetof(struct user, reserved)" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003217# endif
3218# if !defined(SPARC64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003219 { uoff(u_ar0), "offsetof(struct user, u_ar0)" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003220# endif
Chris Metcalfc8c66982009-12-28 10:00:15 -05003221# if !defined(ARM) && !defined(AVR32) && !defined(MIPS) && !defined(S390) && !defined(S390X) && !defined(SPARC64) && !defined(BFIN) && !defined(TILE)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003222 { uoff(u_fpstate), "offsetof(struct user, u_fpstate)" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003223# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003224 { uoff(magic), "offsetof(struct user, magic)" },
3225 { uoff(u_comm), "offsetof(struct user, u_comm)" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003226# if defined(I386) || defined(X86_64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003227 { uoff(u_debugreg), "offsetof(struct user, u_debugreg)" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003228# endif
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00003229# endif /* !defined(many arches) */
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003230
3231# endif /* LINUX */
3232
3233# ifdef SUNOS4
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003234 { uoff(u_pcb), "offsetof(struct user, u_pcb)" },
3235 { uoff(u_procp), "offsetof(struct user, u_procp)" },
3236 { uoff(u_ar0), "offsetof(struct user, u_ar0)" },
3237 { uoff(u_comm[0]), "offsetof(struct user, u_comm[0])" },
3238 { uoff(u_arg[0]), "offsetof(struct user, u_arg[0])" },
3239 { uoff(u_ap), "offsetof(struct user, u_ap)" },
3240 { uoff(u_qsave), "offsetof(struct user, u_qsave)" },
3241 { uoff(u_rval1), "offsetof(struct user, u_rval1)" },
3242 { uoff(u_rval2), "offsetof(struct user, u_rval2)" },
3243 { uoff(u_error), "offsetof(struct user, u_error)" },
3244 { uoff(u_eosys), "offsetof(struct user, u_eosys)" },
3245 { uoff(u_ssave), "offsetof(struct user, u_ssave)" },
3246 { uoff(u_signal[0]), "offsetof(struct user, u_signal)" },
3247 { uoff(u_sigmask[0]), "offsetof(struct user, u_sigmask)" },
3248 { uoff(u_sigonstack), "offsetof(struct user, u_sigonstack)" },
3249 { uoff(u_sigintr), "offsetof(struct user, u_sigintr)" },
3250 { uoff(u_sigreset), "offsetof(struct user, u_sigreset)" },
3251 { uoff(u_oldmask), "offsetof(struct user, u_oldmask)" },
3252 { uoff(u_code), "offsetof(struct user, u_code)" },
3253 { uoff(u_addr), "offsetof(struct user, u_addr)" },
3254 { uoff(u_sigstack), "offsetof(struct user, u_sigstack)" },
3255 { uoff(u_ofile), "offsetof(struct user, u_ofile)" },
3256 { uoff(u_pofile), "offsetof(struct user, u_pofile)" },
3257 { uoff(u_ofile_arr[0]), "offsetof(struct user, u_ofile_arr[0])" },
3258 { uoff(u_pofile_arr[0]),"offsetof(struct user, u_pofile_arr[0])"},
3259 { uoff(u_lastfile), "offsetof(struct user, u_lastfile)" },
3260 { uoff(u_cwd), "offsetof(struct user, u_cwd)" },
3261 { uoff(u_cdir), "offsetof(struct user, u_cdir)" },
3262 { uoff(u_rdir), "offsetof(struct user, u_rdir)" },
3263 { uoff(u_cmask), "offsetof(struct user, u_cmask)" },
3264 { uoff(u_ru), "offsetof(struct user, u_ru)" },
3265 { uoff(u_cru), "offsetof(struct user, u_cru)" },
3266 { uoff(u_timer[0]), "offsetof(struct user, u_timer[0])" },
3267 { uoff(u_XXX[0]), "offsetof(struct user, u_XXX[0])" },
3268 { uoff(u_ioch), "offsetof(struct user, u_ioch)" },
3269 { uoff(u_start), "offsetof(struct user, u_start)" },
3270 { uoff(u_acflag), "offsetof(struct user, u_acflag)" },
3271 { uoff(u_prof.pr_base), "offsetof(struct user, u_prof.pr_base)" },
3272 { uoff(u_prof.pr_size), "offsetof(struct user, u_prof.pr_size)" },
3273 { uoff(u_prof.pr_off), "offsetof(struct user, u_prof.pr_off)" },
3274 { uoff(u_prof.pr_scale),"offsetof(struct user, u_prof.pr_scale)"},
3275 { uoff(u_rlimit[0]), "offsetof(struct user, u_rlimit)" },
3276 { uoff(u_exdata.Ux_A), "offsetof(struct user, u_exdata.Ux_A)" },
3277 { uoff(u_exdata.ux_shell[0]),"offsetof(struct user, u_exdata.ux_shell[0])"},
3278 { uoff(u_lofault), "offsetof(struct user, u_lofault)" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003279# endif /* SUNOS4 */
3280# ifndef HPPA
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003281 { sizeof(struct user), "sizeof(struct user)" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003282# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003283 { 0, NULL },
3284};
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003285# endif /* !FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003286
3287int
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003288sys_ptrace(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003289{
Roland McGrathd9f816f2004-09-04 03:39:20 +00003290 const struct xlat *x;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003291 long addr;
3292
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003293 if (entering(tcp)) {
Roland McGrathbf621d42003-01-14 09:46:21 +00003294 printxval(ptrace_cmds, tcp->u_arg[0],
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003295# ifndef FREEBSD
Roland McGrathbf621d42003-01-14 09:46:21 +00003296 "PTRACE_???"
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003297# else
Roland McGrathbf621d42003-01-14 09:46:21 +00003298 "PT_???"
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003299# endif
Roland McGrathbf621d42003-01-14 09:46:21 +00003300 );
3301 tprintf(", %lu, ", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003302 addr = tcp->u_arg[2];
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003303# ifndef FREEBSD
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003304 if (tcp->u_arg[0] == PTRACE_PEEKUSER
3305 || tcp->u_arg[0] == PTRACE_POKEUSER) {
3306 for (x = struct_user_offsets; x->str; x++) {
3307 if (x->val >= addr)
3308 break;
3309 }
3310 if (!x->str)
3311 tprintf("%#lx, ", addr);
3312 else if (x->val > addr && x != struct_user_offsets) {
3313 x--;
3314 tprintf("%s + %ld, ", x->str, addr - x->val);
3315 }
3316 else
3317 tprintf("%s, ", x->str);
3318 }
3319 else
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003320# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003321 tprintf("%#lx, ", tcp->u_arg[2]);
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003322# ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003323 switch (tcp->u_arg[0]) {
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003324# ifndef IA64
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003325 case PTRACE_PEEKDATA:
3326 case PTRACE_PEEKTEXT:
3327 case PTRACE_PEEKUSER:
3328 break;
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003329# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003330 case PTRACE_CONT:
3331 case PTRACE_SINGLESTEP:
3332 case PTRACE_SYSCALL:
3333 case PTRACE_DETACH:
3334 printsignal(tcp->u_arg[3]);
3335 break;
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003336# ifdef PTRACE_SETOPTIONS
Denys Vlasenkof535b542009-01-13 18:30:55 +00003337 case PTRACE_SETOPTIONS:
3338 printflags(ptrace_setoptions_flags, tcp->u_arg[3], "PTRACE_O_???");
3339 break;
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003340# endif
3341# ifdef PTRACE_SETSIGINFO
Denys Vlasenkof535b542009-01-13 18:30:55 +00003342 case PTRACE_SETSIGINFO: {
3343 siginfo_t si;
3344 if (!tcp->u_arg[3])
3345 tprintf("NULL");
3346 else if (syserror(tcp))
3347 tprintf("%#lx", tcp->u_arg[3]);
3348 else if (umove(tcp, tcp->u_arg[3], &si) < 0)
3349 tprintf("{???}");
3350 else
3351 printsiginfo(&si, verbose(tcp));
3352 break;
3353 }
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003354# endif
3355# ifdef PTRACE_GETSIGINFO
Denys Vlasenkof535b542009-01-13 18:30:55 +00003356 case PTRACE_GETSIGINFO:
3357 /* Don't print anything, do it at syscall return. */
3358 break;
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003359# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003360 default:
3361 tprintf("%#lx", tcp->u_arg[3]);
3362 break;
3363 }
3364 } else {
3365 switch (tcp->u_arg[0]) {
3366 case PTRACE_PEEKDATA:
3367 case PTRACE_PEEKTEXT:
3368 case PTRACE_PEEKUSER:
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003369# ifdef IA64
Roland McGrath1e868062007-11-19 22:11:45 +00003370 return RVAL_HEX;
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003371# else
Roland McGratheb285352003-01-14 09:59:00 +00003372 printnum(tcp, tcp->u_arg[3], "%#lx");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003373 break;
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003374# endif
3375# ifdef PTRACE_GETSIGINFO
Denys Vlasenkof535b542009-01-13 18:30:55 +00003376 case PTRACE_GETSIGINFO: {
3377 siginfo_t si;
3378 if (!tcp->u_arg[3])
3379 tprintf("NULL");
3380 else if (syserror(tcp))
3381 tprintf("%#lx", tcp->u_arg[3]);
3382 else if (umove(tcp, tcp->u_arg[3], &si) < 0)
3383 tprintf("{???}");
3384 else
3385 printsiginfo(&si, verbose(tcp));
3386 break;
3387 }
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003388# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003389 }
3390 }
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003391# endif /* LINUX */
3392# ifdef SUNOS4
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003393 if (tcp->u_arg[0] == PTRACE_WRITEDATA ||
3394 tcp->u_arg[0] == PTRACE_WRITETEXT) {
3395 tprintf("%lu, ", tcp->u_arg[3]);
3396 printstr(tcp, tcp->u_arg[4], tcp->u_arg[3]);
3397 } else if (tcp->u_arg[0] != PTRACE_READDATA &&
3398 tcp->u_arg[0] != PTRACE_READTEXT) {
3399 tprintf("%#lx", tcp->u_arg[3]);
3400 }
3401 } else {
3402 if (tcp->u_arg[0] == PTRACE_READDATA ||
3403 tcp->u_arg[0] == PTRACE_READTEXT) {
3404 tprintf("%lu, ", tcp->u_arg[3]);
3405 printstr(tcp, tcp->u_arg[4], tcp->u_arg[3]);
3406 }
3407 }
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003408# endif /* SUNOS4 */
3409# ifdef FREEBSD
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00003410 tprintf("%lu", tcp->u_arg[3]);
3411 }
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003412# endif /* FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003413 return 0;
3414}
3415
3416#endif /* !SVR4 */
Roland McGrath5a223472002-12-15 23:58:26 +00003417
3418#ifdef LINUX
Roland McGrath51942a92007-07-05 18:59:11 +00003419# ifndef FUTEX_CMP_REQUEUE
3420# define FUTEX_CMP_REQUEUE 4
3421# endif
3422# ifndef FUTEX_WAKE_OP
3423# define FUTEX_WAKE_OP 5
3424# endif
3425# ifndef FUTEX_LOCK_PI
3426# define FUTEX_LOCK_PI 6
3427# define FUTEX_UNLOCK_PI 7
3428# define FUTEX_TRYLOCK_PI 8
3429# endif
Roland McGrath1aeaf742008-07-18 01:27:39 +00003430# ifndef FUTEX_WAIT_BITSET
3431# define FUTEX_WAIT_BITSET 9
3432# endif
3433# ifndef FUTEX_WAKE_BITSET
3434# define FUTEX_WAKE_BITSET 10
Roland McGrath51942a92007-07-05 18:59:11 +00003435# endif
Andreas Schwab85f58322009-08-12 09:54:42 +02003436# ifndef FUTEX_WAIT_REQUEUE_PI
3437# define FUTEX_WAIT_REQUEUE_PI 11
3438# endif
3439# ifndef FUTEX_CMP_REQUEUE_PI
3440# define FUTEX_CMP_REQUEUE_PI 12
3441# endif
Roland McGrath51942a92007-07-05 18:59:11 +00003442# ifndef FUTEX_PRIVATE_FLAG
3443# define FUTEX_PRIVATE_FLAG 128
3444# endif
Andreas Schwab85f58322009-08-12 09:54:42 +02003445# ifndef FUTEX_CLOCK_REALTIME
3446# define FUTEX_CLOCK_REALTIME 256
3447# endif
Roland McGrathd9f816f2004-09-04 03:39:20 +00003448static const struct xlat futexops[] = {
Roland McGrath51942a92007-07-05 18:59:11 +00003449 { FUTEX_WAIT, "FUTEX_WAIT" },
3450 { FUTEX_WAKE, "FUTEX_WAKE" },
3451 { FUTEX_FD, "FUTEX_FD" },
3452 { FUTEX_REQUEUE, "FUTEX_REQUEUE" },
3453 { FUTEX_CMP_REQUEUE, "FUTEX_CMP_REQUEUE" },
3454 { FUTEX_WAKE_OP, "FUTEX_WAKE_OP" },
3455 { FUTEX_LOCK_PI, "FUTEX_LOCK_PI" },
3456 { FUTEX_UNLOCK_PI, "FUTEX_UNLOCK_PI" },
3457 { FUTEX_TRYLOCK_PI, "FUTEX_TRYLOCK_PI" },
Roland McGrath1aeaf742008-07-18 01:27:39 +00003458 { FUTEX_WAIT_BITSET, "FUTEX_WAIT_BITSET" },
3459 { FUTEX_WAKE_BITSET, "FUTEX_WAKE_BITSET" },
Andreas Schwab85f58322009-08-12 09:54:42 +02003460 { FUTEX_WAIT_REQUEUE_PI, "FUTEX_WAIT_REQUEUE_PI" },
3461 { FUTEX_CMP_REQUEUE_PI, "FUTEX_CMP_REQUEUE_PI" },
Roland McGrath51942a92007-07-05 18:59:11 +00003462 { FUTEX_WAIT|FUTEX_PRIVATE_FLAG, "FUTEX_WAIT_PRIVATE" },
3463 { FUTEX_WAKE|FUTEX_PRIVATE_FLAG, "FUTEX_WAKE_PRIVATE" },
3464 { FUTEX_FD|FUTEX_PRIVATE_FLAG, "FUTEX_FD_PRIVATE" },
3465 { FUTEX_REQUEUE|FUTEX_PRIVATE_FLAG, "FUTEX_REQUEUE_PRIVATE" },
3466 { FUTEX_CMP_REQUEUE|FUTEX_PRIVATE_FLAG, "FUTEX_CMP_REQUEUE_PRIVATE" },
3467 { FUTEX_WAKE_OP|FUTEX_PRIVATE_FLAG, "FUTEX_WAKE_OP_PRIVATE" },
3468 { FUTEX_LOCK_PI|FUTEX_PRIVATE_FLAG, "FUTEX_LOCK_PI_PRIVATE" },
3469 { FUTEX_UNLOCK_PI|FUTEX_PRIVATE_FLAG, "FUTEX_UNLOCK_PI_PRIVATE" },
3470 { FUTEX_TRYLOCK_PI|FUTEX_PRIVATE_FLAG, "FUTEX_TRYLOCK_PI_PRIVATE" },
Roland McGrath1aeaf742008-07-18 01:27:39 +00003471 { FUTEX_WAIT_BITSET|FUTEX_PRIVATE_FLAG, "FUTEX_WAIT_BITSET_PRIVATE" },
3472 { FUTEX_WAKE_BITSET|FUTEX_PRIVATE_FLAG, "FUTEX_WAKE_BITSET_PRIVATE" },
Andreas Schwab85f58322009-08-12 09:54:42 +02003473 { FUTEX_WAIT_REQUEUE_PI|FUTEX_PRIVATE_FLAG, "FUTEX_WAIT_REQUEUE_PI_PRIVATE" },
3474 { FUTEX_CMP_REQUEUE_PI|FUTEX_PRIVATE_FLAG, "FUTEX_CMP_REQUEUE_PI_PRIVATE" },
3475 { FUTEX_WAIT_BITSET|FUTEX_CLOCK_REALTIME, "FUTEX_WAIT_BITSET|FUTEX_CLOCK_REALTIME" },
3476 { FUTEX_WAIT_BITSET|FUTEX_PRIVATE_FLAG|FUTEX_CLOCK_REALTIME, "FUTEX_WAIT_BITSET_PRIVATE|FUTEX_CLOCK_REALTIME" },
3477 { FUTEX_WAIT_REQUEUE_PI|FUTEX_CLOCK_REALTIME, "FUTEX_WAIT_REQUEUE_PI|FUTEX_CLOCK_REALTIME" },
3478 { 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 +00003479 { 0, NULL }
3480};
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003481# ifndef FUTEX_OP_SET
3482# define FUTEX_OP_SET 0
3483# define FUTEX_OP_ADD 1
3484# define FUTEX_OP_OR 2
3485# define FUTEX_OP_ANDN 3
3486# define FUTEX_OP_XOR 4
3487# define FUTEX_OP_CMP_EQ 0
3488# define FUTEX_OP_CMP_NE 1
3489# define FUTEX_OP_CMP_LT 2
3490# define FUTEX_OP_CMP_LE 3
3491# define FUTEX_OP_CMP_GT 4
3492# define FUTEX_OP_CMP_GE 5
3493# endif
Roland McGrath51942a92007-07-05 18:59:11 +00003494static const struct xlat futexwakeops[] = {
3495 { FUTEX_OP_SET, "FUTEX_OP_SET" },
3496 { FUTEX_OP_ADD, "FUTEX_OP_ADD" },
3497 { FUTEX_OP_OR, "FUTEX_OP_OR" },
3498 { FUTEX_OP_ANDN, "FUTEX_OP_ANDN" },
3499 { FUTEX_OP_XOR, "FUTEX_OP_XOR" },
3500 { 0, NULL }
3501};
3502static const struct xlat futexwakecmps[] = {
3503 { FUTEX_OP_CMP_EQ, "FUTEX_OP_CMP_EQ" },
3504 { FUTEX_OP_CMP_NE, "FUTEX_OP_CMP_NE" },
3505 { FUTEX_OP_CMP_LT, "FUTEX_OP_CMP_LT" },
3506 { FUTEX_OP_CMP_LE, "FUTEX_OP_CMP_LE" },
3507 { FUTEX_OP_CMP_GT, "FUTEX_OP_CMP_GT" },
3508 { FUTEX_OP_CMP_GE, "FUTEX_OP_CMP_GE" },
3509 { 0, NULL }
Roland McGrath5a223472002-12-15 23:58:26 +00003510};
3511
3512int
Denys Vlasenko1d632462009-04-14 12:51:00 +00003513sys_futex(struct tcb *tcp)
Roland McGrath5a223472002-12-15 23:58:26 +00003514{
Denys Vlasenko1d632462009-04-14 12:51:00 +00003515 if (entering(tcp)) {
3516 long int cmd = tcp->u_arg[1] & 127;
3517 tprintf("%p, ", (void *) tcp->u_arg[0]);
3518 printxval(futexops, tcp->u_arg[1], "FUTEX_???");
3519 tprintf(", %ld", tcp->u_arg[2]);
3520 if (cmd == FUTEX_WAKE_BITSET)
3521 tprintf(", %lx", tcp->u_arg[5]);
3522 else if (cmd == FUTEX_WAIT) {
3523 tprintf(", ");
3524 printtv(tcp, tcp->u_arg[3]);
3525 } else if (cmd == FUTEX_WAIT_BITSET) {
3526 tprintf(", ");
3527 printtv(tcp, tcp->u_arg[3]);
3528 tprintf(", %lx", tcp->u_arg[5]);
3529 } else if (cmd == FUTEX_REQUEUE)
3530 tprintf(", %ld, %p", tcp->u_arg[3], (void *) tcp->u_arg[4]);
Andreas Schwab85f58322009-08-12 09:54:42 +02003531 else if (cmd == FUTEX_CMP_REQUEUE || cmd == FUTEX_CMP_REQUEUE_PI)
Denys Vlasenko1d632462009-04-14 12:51:00 +00003532 tprintf(", %ld, %p, %ld", tcp->u_arg[3], (void *) tcp->u_arg[4], tcp->u_arg[5]);
3533 else if (cmd == FUTEX_WAKE_OP) {
3534 tprintf(", %ld, %p, {", tcp->u_arg[3], (void *) tcp->u_arg[4]);
3535 if ((tcp->u_arg[5] >> 28) & 8)
3536 tprintf("FUTEX_OP_OPARG_SHIFT|");
3537 printxval(futexwakeops, (tcp->u_arg[5] >> 28) & 0x7, "FUTEX_OP_???");
3538 tprintf(", %ld, ", (tcp->u_arg[5] >> 12) & 0xfff);
3539 if ((tcp->u_arg[5] >> 24) & 8)
3540 tprintf("FUTEX_OP_OPARG_SHIFT|");
3541 printxval(futexwakecmps, (tcp->u_arg[5] >> 24) & 0x7, "FUTEX_OP_CMP_???");
3542 tprintf(", %ld}", tcp->u_arg[5] & 0xfff);
Andreas Schwab85f58322009-08-12 09:54:42 +02003543 } else if (cmd == FUTEX_WAIT_REQUEUE_PI) {
3544 tprintf(", ");
3545 printtv(tcp, tcp->u_arg[3]);
3546 tprintf(", %p", (void *) tcp->u_arg[4]);
Denys Vlasenko1d632462009-04-14 12:51:00 +00003547 }
Roland McGrath51942a92007-07-05 18:59:11 +00003548 }
Denys Vlasenko1d632462009-04-14 12:51:00 +00003549 return 0;
Roland McGrath5a223472002-12-15 23:58:26 +00003550}
3551
3552static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00003553print_affinitylist(struct tcb *tcp, long list, unsigned int len)
Roland McGrath5a223472002-12-15 23:58:26 +00003554{
Denys Vlasenko1d632462009-04-14 12:51:00 +00003555 int first = 1;
Dmitry V. Levin62e05962009-11-03 14:38:44 +00003556 unsigned long w, min_len;
3557
3558 if (abbrev(tcp) && len / sizeof(w) > max_strlen)
3559 min_len = len - max_strlen * sizeof(w);
3560 else
3561 min_len = 0;
3562 for (; len >= sizeof(w) && len > min_len;
3563 len -= sizeof(w), list += sizeof(w)) {
3564 if (umove(tcp, list, &w) < 0)
3565 break;
3566 if (first)
3567 tprintf("{");
3568 else
3569 tprintf(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00003570 first = 0;
Dmitry V. Levin62e05962009-11-03 14:38:44 +00003571 tprintf("%lx", w);
Denys Vlasenko1d632462009-04-14 12:51:00 +00003572 }
Dmitry V. Levin62e05962009-11-03 14:38:44 +00003573 if (len) {
3574 if (first)
3575 tprintf("%#lx", list);
3576 else
3577 tprintf(", %s}", (len >= sizeof(w) && len > min_len ?
3578 "???" : "..."));
3579 } else {
3580 tprintf(first ? "{}" : "}");
3581 }
Roland McGrath5a223472002-12-15 23:58:26 +00003582}
3583
3584int
Denys Vlasenko1d632462009-04-14 12:51:00 +00003585sys_sched_setaffinity(struct tcb *tcp)
Roland McGrath5a223472002-12-15 23:58:26 +00003586{
Denys Vlasenko1d632462009-04-14 12:51:00 +00003587 if (entering(tcp)) {
3588 tprintf("%ld, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
3589 print_affinitylist(tcp, tcp->u_arg[2], tcp->u_arg[1]);
3590 }
3591 return 0;
Roland McGrath5a223472002-12-15 23:58:26 +00003592}
3593
3594int
Denys Vlasenko1d632462009-04-14 12:51:00 +00003595sys_sched_getaffinity(struct tcb *tcp)
Roland McGrath5a223472002-12-15 23:58:26 +00003596{
Denys Vlasenko1d632462009-04-14 12:51:00 +00003597 if (entering(tcp)) {
3598 tprintf("%ld, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
3599 } else {
3600 if (tcp->u_rval == -1)
3601 tprintf("%#lx", tcp->u_arg[2]);
3602 else
3603 print_affinitylist(tcp, tcp->u_arg[2], tcp->u_rval);
3604 }
3605 return 0;
Roland McGrath5a223472002-12-15 23:58:26 +00003606}
Roland McGrath279d3782004-03-01 20:27:37 +00003607
Roland McGrathd9f816f2004-09-04 03:39:20 +00003608static const struct xlat schedulers[] = {
Roland McGrath279d3782004-03-01 20:27:37 +00003609 { SCHED_OTHER, "SCHED_OTHER" },
3610 { SCHED_RR, "SCHED_RR" },
3611 { SCHED_FIFO, "SCHED_FIFO" },
3612 { 0, NULL }
3613};
3614
3615int
Denys Vlasenko1d632462009-04-14 12:51:00 +00003616sys_sched_getscheduler(struct tcb *tcp)
Roland McGrath279d3782004-03-01 20:27:37 +00003617{
Denys Vlasenko1d632462009-04-14 12:51:00 +00003618 if (entering(tcp)) {
3619 tprintf("%d", (int) tcp->u_arg[0]);
3620 } else if (! syserror(tcp)) {
3621 tcp->auxstr = xlookup (schedulers, tcp->u_rval);
3622 if (tcp->auxstr != NULL)
3623 return RVAL_STR;
3624 }
3625 return 0;
Roland McGrath279d3782004-03-01 20:27:37 +00003626}
3627
3628int
Denys Vlasenko1d632462009-04-14 12:51:00 +00003629sys_sched_setscheduler(struct tcb *tcp)
Roland McGrath279d3782004-03-01 20:27:37 +00003630{
Denys Vlasenko1d632462009-04-14 12:51:00 +00003631 if (entering(tcp)) {
3632 struct sched_param p;
3633 tprintf("%d, ", (int) tcp->u_arg[0]);
3634 printxval(schedulers, tcp->u_arg[1], "SCHED_???");
3635 if (umove(tcp, tcp->u_arg[2], &p) < 0)
3636 tprintf(", %#lx", tcp->u_arg[2]);
3637 else
3638 tprintf(", { %d }", p.__sched_priority);
3639 }
3640 return 0;
Roland McGrath279d3782004-03-01 20:27:37 +00003641}
3642
3643int
Denys Vlasenko1d632462009-04-14 12:51:00 +00003644sys_sched_getparam(struct tcb *tcp)
Roland McGrath279d3782004-03-01 20:27:37 +00003645{
Denys Vlasenko1d632462009-04-14 12:51:00 +00003646 if (entering(tcp)) {
3647 tprintf("%d, ", (int) tcp->u_arg[0]);
3648 } else {
3649 struct sched_param p;
3650 if (umove(tcp, tcp->u_arg[1], &p) < 0)
3651 tprintf("%#lx", tcp->u_arg[1]);
3652 else
3653 tprintf("{ %d }", p.__sched_priority);
3654 }
3655 return 0;
Roland McGrath279d3782004-03-01 20:27:37 +00003656}
3657
3658int
Denys Vlasenko1d632462009-04-14 12:51:00 +00003659sys_sched_setparam(struct tcb *tcp)
Roland McGrath279d3782004-03-01 20:27:37 +00003660{
Denys Vlasenko1d632462009-04-14 12:51:00 +00003661 if (entering(tcp)) {
3662 struct sched_param p;
3663 if (umove(tcp, tcp->u_arg[1], &p) < 0)
3664 tprintf("%d, %#lx", (int) tcp->u_arg[0], tcp->u_arg[1]);
3665 else
3666 tprintf("%d, { %d }", (int) tcp->u_arg[0], p.__sched_priority);
3667 }
3668 return 0;
Roland McGrath279d3782004-03-01 20:27:37 +00003669}
3670
3671int
Denys Vlasenko1d632462009-04-14 12:51:00 +00003672sys_sched_get_priority_min(struct tcb *tcp)
Roland McGrath279d3782004-03-01 20:27:37 +00003673{
Denys Vlasenko1d632462009-04-14 12:51:00 +00003674 if (entering(tcp)) {
3675 printxval(schedulers, tcp->u_arg[0], "SCHED_???");
3676 }
3677 return 0;
Roland McGrath279d3782004-03-01 20:27:37 +00003678}
Roland McGrathc2d5eb02005-02-02 04:16:56 +00003679
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003680# ifdef X86_64
3681# include <asm/prctl.h>
Roland McGrathc2d5eb02005-02-02 04:16:56 +00003682
3683static const struct xlat archvals[] = {
3684 { ARCH_SET_GS, "ARCH_SET_GS" },
3685 { ARCH_SET_FS, "ARCH_SET_FS" },
3686 { ARCH_GET_FS, "ARCH_GET_FS" },
3687 { ARCH_GET_GS, "ARCH_GET_GS" },
3688 { 0, NULL },
3689};
3690
3691int
Denys Vlasenko1d632462009-04-14 12:51:00 +00003692sys_arch_prctl(struct tcb *tcp)
Roland McGrathc2d5eb02005-02-02 04:16:56 +00003693{
Denys Vlasenko1d632462009-04-14 12:51:00 +00003694 if (entering(tcp)) {
3695 printxval(archvals, tcp->u_arg[0], "ARCH_???");
3696 if (tcp->u_arg[0] == ARCH_SET_GS
3697 || tcp->u_arg[0] == ARCH_SET_FS
3698 ) {
3699 tprintf(", %#lx", tcp->u_arg[1]);
3700 }
3701 } else {
3702 if (tcp->u_arg[0] == ARCH_GET_GS
3703 || tcp->u_arg[0] == ARCH_GET_FS
3704 ) {
3705 long int v;
3706 if (!syserror(tcp) && umove(tcp, tcp->u_arg[1], &v) != -1)
3707 tprintf(", [%#lx]", v);
3708 else
3709 tprintf(", %#lx", tcp->u_arg[1]);
3710 }
Roland McGrathc2d5eb02005-02-02 04:16:56 +00003711 }
Denys Vlasenko1d632462009-04-14 12:51:00 +00003712 return 0;
Roland McGrathc2d5eb02005-02-02 04:16:56 +00003713}
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003714# endif /* X86_64 */
Roland McGrathc2d5eb02005-02-02 04:16:56 +00003715
Roland McGrathdb8319f2007-08-02 01:37:55 +00003716
3717int
Denys Vlasenko1d632462009-04-14 12:51:00 +00003718sys_getcpu(struct tcb *tcp)
Roland McGrathdb8319f2007-08-02 01:37:55 +00003719{
3720 if (exiting(tcp)) {
3721 unsigned u;
3722 if (tcp->u_arg[0] == 0)
3723 tprintf("NULL, ");
3724 else if (umove(tcp, tcp->u_arg[0], &u) < 0)
3725 tprintf("%#lx, ", tcp->u_arg[0]);
3726 else
3727 tprintf("[%u], ", u);
3728 if (tcp->u_arg[1] == 0)
3729 tprintf("NULL, ");
3730 else if (umove(tcp, tcp->u_arg[1], &u) < 0)
3731 tprintf("%#lx, ", tcp->u_arg[1]);
3732 else
3733 tprintf("[%u], ", u);
3734 tprintf("%#lx", tcp->u_arg[2]);
3735 }
3736 return 0;
3737}
3738
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003739#endif /* LINUX */