blob: c4615a24b16ad61c5b93f36b77763c098eb38a73 [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
1113int
1114sys_setuid(tcp)
1115struct tcb *tcp;
1116{
1117 if (entering(tcp)) {
1118 tprintf("%u", (uid_t) tcp->u_arg[0]);
1119 }
1120 return 0;
1121}
1122
1123int
1124sys_setgid(tcp)
1125struct tcb *tcp;
1126{
1127 if (entering(tcp)) {
1128 tprintf("%u", (gid_t) tcp->u_arg[0]);
1129 }
1130 return 0;
1131}
1132
1133int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001134sys_getresuid(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001135{
1136 if (exiting(tcp)) {
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001137 __kernel_uid_t uid;
1138 if (syserror(tcp))
1139 tprintf("%#lx, %#lx, %#lx", tcp->u_arg[0],
1140 tcp->u_arg[1], tcp->u_arg[2]);
1141 else {
1142 if (umove(tcp, tcp->u_arg[0], &uid) < 0)
1143 tprintf("%#lx, ", tcp->u_arg[0]);
1144 else
Roland McGrath83bd47a2003-11-13 22:32:26 +00001145 tprintf("[%lu], ", (unsigned long) uid);
Roland McGrath9bd6b422003-02-24 07:13:51 +00001146 if (umove(tcp, tcp->u_arg[1], &uid) < 0)
1147 tprintf("%#lx, ", tcp->u_arg[1]);
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001148 else
Roland McGrath83bd47a2003-11-13 22:32:26 +00001149 tprintf("[%lu], ", (unsigned long) uid);
Roland McGrath9bd6b422003-02-24 07:13:51 +00001150 if (umove(tcp, tcp->u_arg[2], &uid) < 0)
1151 tprintf("%#lx", tcp->u_arg[2]);
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001152 else
Roland McGrath83bd47a2003-11-13 22:32:26 +00001153 tprintf("[%lu]", (unsigned long) uid);
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001154 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001155 }
1156 return 0;
1157}
1158
1159int
1160sys_getresgid(tcp)
1161struct tcb *tcp;
1162{
1163 if (exiting(tcp)) {
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001164 __kernel_gid_t gid;
1165 if (syserror(tcp))
1166 tprintf("%#lx, %#lx, %#lx", tcp->u_arg[0],
1167 tcp->u_arg[1], tcp->u_arg[2]);
1168 else {
1169 if (umove(tcp, tcp->u_arg[0], &gid) < 0)
1170 tprintf("%#lx, ", tcp->u_arg[0]);
1171 else
Roland McGrath83bd47a2003-11-13 22:32:26 +00001172 tprintf("[%lu], ", (unsigned long) gid);
Roland McGrathd2450922003-02-24 10:18:07 +00001173 if (umove(tcp, tcp->u_arg[1], &gid) < 0)
1174 tprintf("%#lx, ", tcp->u_arg[1]);
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001175 else
Roland McGrath83bd47a2003-11-13 22:32:26 +00001176 tprintf("[%lu], ", (unsigned long) gid);
Roland McGrathd2450922003-02-24 10:18:07 +00001177 if (umove(tcp, tcp->u_arg[2], &gid) < 0)
1178 tprintf("%#lx", tcp->u_arg[2]);
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001179 else
Roland McGrath83bd47a2003-11-13 22:32:26 +00001180 tprintf("[%lu]", (unsigned long) gid);
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001181 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001182 }
1183 return 0;
1184}
1185
1186#endif /* LINUX */
1187
1188int
1189sys_setreuid(tcp)
1190struct tcb *tcp;
1191{
1192 if (entering(tcp)) {
Roland McGrath83bd47a2003-11-13 22:32:26 +00001193 printuid("", tcp->u_arg[0]);
1194 printuid(", ", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001195 }
1196 return 0;
1197}
1198
1199int
1200sys_setregid(tcp)
1201struct tcb *tcp;
1202{
1203 if (entering(tcp)) {
Roland McGrath83bd47a2003-11-13 22:32:26 +00001204 printuid("", tcp->u_arg[0]);
1205 printuid(", ", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001206 }
1207 return 0;
1208}
1209
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001210#if defined(LINUX) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001211int
1212sys_setresuid(tcp)
1213 struct tcb *tcp;
1214{
1215 if (entering(tcp)) {
Roland McGrath83bd47a2003-11-13 22:32:26 +00001216 printuid("", tcp->u_arg[0]);
1217 printuid(", ", tcp->u_arg[1]);
1218 printuid(", ", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001219 }
1220 return 0;
1221}
1222int
1223sys_setresgid(tcp)
1224 struct tcb *tcp;
1225{
1226 if (entering(tcp)) {
Roland McGrath83bd47a2003-11-13 22:32:26 +00001227 printuid("", tcp->u_arg[0]);
1228 printuid(", ", tcp->u_arg[1]);
1229 printuid(", ", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001230 }
1231 return 0;
1232}
1233
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001234#endif /* LINUX || FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001235
1236int
1237sys_setgroups(tcp)
1238struct tcb *tcp;
1239{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001240 if (entering(tcp)) {
Roland McGrathaa524c82005-06-01 19:22:06 +00001241 unsigned long len, size, start, cur, end, abbrev_end;
1242 GETGROUPS_T gid;
1243 int failed = 0;
1244
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001245 len = tcp->u_arg[0];
Roland McGrathaa524c82005-06-01 19:22:06 +00001246 tprintf("%lu, ", len);
1247 if (len == 0) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001248 tprintf("[]");
1249 return 0;
1250 }
Roland McGrathaa524c82005-06-01 19:22:06 +00001251 start = tcp->u_arg[1];
1252 if (start == 0) {
1253 tprintf("NULL");
1254 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001255 }
Roland McGrathaa524c82005-06-01 19:22:06 +00001256 size = len * sizeof(gid);
1257 end = start + size;
1258 if (!verbose(tcp) || size / sizeof(gid) != len || end < start) {
1259 tprintf("%#lx", start);
1260 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001261 }
Roland McGrathaa524c82005-06-01 19:22:06 +00001262 if (abbrev(tcp)) {
1263 abbrev_end = start + max_strlen * sizeof(gid);
1264 if (abbrev_end < start)
1265 abbrev_end = end;
1266 } else {
1267 abbrev_end = end;
1268 }
1269 tprintf("[");
1270 for (cur = start; cur < end; cur += sizeof(gid)) {
1271 if (cur > start)
1272 tprintf(", ");
1273 if (cur >= abbrev_end) {
1274 tprintf("...");
1275 break;
1276 }
1277 if (umoven(tcp, cur, sizeof(gid), (char *) &gid) < 0) {
1278 tprintf("?");
1279 failed = 1;
1280 break;
1281 }
1282 tprintf("%lu", (unsigned long) gid);
1283 }
1284 tprintf("]");
1285 if (failed)
1286 tprintf(" %#lx", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001287 }
1288 return 0;
1289}
1290
1291int
1292sys_getgroups(tcp)
1293struct tcb *tcp;
1294{
Roland McGrathaa524c82005-06-01 19:22:06 +00001295 unsigned long len;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001296
1297 if (entering(tcp)) {
1298 len = tcp->u_arg[0];
Roland McGrathaa524c82005-06-01 19:22:06 +00001299 tprintf("%lu, ", len);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001300 } else {
Roland McGrathaa524c82005-06-01 19:22:06 +00001301 unsigned long size, start, cur, end, abbrev_end;
1302 GETGROUPS_T gid;
1303 int failed = 0;
1304
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001305 len = tcp->u_rval;
Roland McGrathaa524c82005-06-01 19:22:06 +00001306 if (len == 0) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001307 tprintf("[]");
1308 return 0;
1309 }
Roland McGrathaa524c82005-06-01 19:22:06 +00001310 start = tcp->u_arg[1];
1311 if (start == 0) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001312 tprintf("NULL");
Roland McGrathaa524c82005-06-01 19:22:06 +00001313 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001314 }
Roland McGrathaa524c82005-06-01 19:22:06 +00001315 if (tcp->u_arg[0] == 0) {
1316 tprintf("%#lx", start);
1317 return 0;
1318 }
1319 size = len * sizeof(gid);
1320 end = start + size;
1321 if (!verbose(tcp) || tcp->u_arg[0] == 0 ||
1322 size / sizeof(gid) != len || end < start) {
1323 tprintf("%#lx", start);
1324 return 0;
1325 }
1326 if (abbrev(tcp)) {
1327 abbrev_end = start + max_strlen * sizeof(gid);
1328 if (abbrev_end < start)
1329 abbrev_end = end;
1330 } else {
1331 abbrev_end = end;
1332 }
1333 tprintf("[");
1334 for (cur = start; cur < end; cur += sizeof(gid)) {
1335 if (cur > start)
1336 tprintf(", ");
1337 if (cur >= abbrev_end) {
1338 tprintf("...");
1339 break;
1340 }
1341 if (umoven(tcp, cur, sizeof(gid), (char *) &gid) < 0) {
1342 tprintf("?");
1343 failed = 1;
1344 break;
1345 }
1346 tprintf("%lu", (unsigned long) gid);
1347 }
1348 tprintf("]");
1349 if (failed)
1350 tprintf(" %#lx", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001351 }
1352 return 0;
1353}
1354
Roland McGrath83bd47a2003-11-13 22:32:26 +00001355#ifdef LINUX
1356int
1357sys_setgroups32(tcp)
1358struct tcb *tcp;
1359{
Roland McGrath83bd47a2003-11-13 22:32:26 +00001360 if (entering(tcp)) {
Roland McGrathaa524c82005-06-01 19:22:06 +00001361 unsigned long len, size, start, cur, end, abbrev_end;
1362 GETGROUPS32_T gid;
1363 int failed = 0;
1364
Roland McGrath83bd47a2003-11-13 22:32:26 +00001365 len = tcp->u_arg[0];
Roland McGrathaa524c82005-06-01 19:22:06 +00001366 tprintf("%lu, ", len);
1367 if (len == 0) {
Roland McGrath83bd47a2003-11-13 22:32:26 +00001368 tprintf("[]");
1369 return 0;
1370 }
Roland McGrathaa524c82005-06-01 19:22:06 +00001371 start = tcp->u_arg[1];
1372 if (start == 0) {
1373 tprintf("NULL");
1374 return 0;
Roland McGrath83bd47a2003-11-13 22:32:26 +00001375 }
Roland McGrathaa524c82005-06-01 19:22:06 +00001376 size = len * sizeof(gid);
1377 end = start + size;
1378 if (!verbose(tcp) || size / sizeof(gid) != len || end < start) {
1379 tprintf("%#lx", start);
1380 return 0;
Roland McGrath83bd47a2003-11-13 22:32:26 +00001381 }
Roland McGrathaa524c82005-06-01 19:22:06 +00001382 if (abbrev(tcp)) {
1383 abbrev_end = start + max_strlen * sizeof(gid);
1384 if (abbrev_end < start)
1385 abbrev_end = end;
1386 } else {
1387 abbrev_end = end;
1388 }
1389 tprintf("[");
1390 for (cur = start; cur < end; cur += sizeof(gid)) {
1391 if (cur > start)
1392 tprintf(", ");
1393 if (cur >= abbrev_end) {
1394 tprintf("...");
1395 break;
1396 }
1397 if (umoven(tcp, cur, sizeof(gid), (char *) &gid) < 0) {
1398 tprintf("?");
1399 failed = 1;
1400 break;
1401 }
1402 tprintf("%lu", (unsigned long) gid);
1403 }
1404 tprintf("]");
1405 if (failed)
1406 tprintf(" %#lx", tcp->u_arg[1]);
Roland McGrath83bd47a2003-11-13 22:32:26 +00001407 }
1408 return 0;
1409}
1410
1411int
1412sys_getgroups32(tcp)
1413struct tcb *tcp;
1414{
Roland McGrathaa524c82005-06-01 19:22:06 +00001415 unsigned long len;
Roland McGrath83bd47a2003-11-13 22:32:26 +00001416
1417 if (entering(tcp)) {
1418 len = tcp->u_arg[0];
Roland McGrathaa524c82005-06-01 19:22:06 +00001419 tprintf("%lu, ", len);
Roland McGrath83bd47a2003-11-13 22:32:26 +00001420 } else {
Roland McGrathaa524c82005-06-01 19:22:06 +00001421 unsigned long size, start, cur, end, abbrev_end;
1422 GETGROUPS32_T gid;
1423 int failed = 0;
1424
Roland McGrath83bd47a2003-11-13 22:32:26 +00001425 len = tcp->u_rval;
Roland McGrathaa524c82005-06-01 19:22:06 +00001426 if (len == 0) {
Roland McGrath83bd47a2003-11-13 22:32:26 +00001427 tprintf("[]");
1428 return 0;
1429 }
Roland McGrathaa524c82005-06-01 19:22:06 +00001430 start = tcp->u_arg[1];
1431 if (start == 0) {
Roland McGrath83bd47a2003-11-13 22:32:26 +00001432 tprintf("NULL");
Roland McGrathaa524c82005-06-01 19:22:06 +00001433 return 0;
Roland McGrath83bd47a2003-11-13 22:32:26 +00001434 }
Roland McGrathaa524c82005-06-01 19:22:06 +00001435 size = len * sizeof(gid);
1436 end = start + size;
1437 if (!verbose(tcp) || tcp->u_arg[0] == 0 ||
1438 size / sizeof(gid) != len || end < start) {
1439 tprintf("%#lx", start);
1440 return 0;
1441 }
1442 if (abbrev(tcp)) {
1443 abbrev_end = start + max_strlen * sizeof(gid);
1444 if (abbrev_end < start)
1445 abbrev_end = end;
1446 } else {
1447 abbrev_end = end;
1448 }
1449 tprintf("[");
1450 for (cur = start; cur < end; cur += sizeof(gid)) {
1451 if (cur > start)
1452 tprintf(", ");
1453 if (cur >= abbrev_end) {
1454 tprintf("...");
1455 break;
1456 }
1457 if (umoven(tcp, cur, sizeof(gid), (char *) &gid) < 0) {
1458 tprintf("?");
1459 failed = 1;
1460 break;
1461 }
1462 tprintf("%lu", (unsigned long) gid);
1463 }
1464 tprintf("]");
1465 if (failed)
1466 tprintf(" %#lx", tcp->u_arg[1]);
Roland McGrath83bd47a2003-11-13 22:32:26 +00001467 }
1468 return 0;
1469}
1470#endif /* LINUX */
1471
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001472#if defined(ALPHA) || defined(SUNOS4) || defined(SVR4)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001473int
1474sys_setpgrp(tcp)
1475struct tcb *tcp;
1476{
1477 if (entering(tcp)) {
1478#ifndef SVR4
1479 tprintf("%lu, %lu", tcp->u_arg[0], tcp->u_arg[1]);
1480#endif /* !SVR4 */
1481 }
1482 return 0;
1483}
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001484#endif /* ALPHA || SUNOS4 || SVR4 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001485
1486int
1487sys_getpgrp(tcp)
1488struct tcb *tcp;
1489{
1490 if (entering(tcp)) {
1491#ifndef SVR4
1492 tprintf("%lu", tcp->u_arg[0]);
1493#endif /* !SVR4 */
1494 }
1495 return 0;
1496}
1497
1498int
1499sys_getsid(tcp)
1500struct tcb *tcp;
1501{
1502 if (entering(tcp)) {
1503 tprintf("%lu", tcp->u_arg[0]);
1504 }
1505 return 0;
1506}
1507
1508int
1509sys_setsid(tcp)
1510struct tcb *tcp;
1511{
1512 return 0;
1513}
1514
1515int
1516sys_getpgid(tcp)
1517struct tcb *tcp;
1518{
1519 if (entering(tcp)) {
1520 tprintf("%lu", tcp->u_arg[0]);
1521 }
1522 return 0;
1523}
1524
1525int
1526sys_setpgid(tcp)
1527struct tcb *tcp;
1528{
1529 if (entering(tcp)) {
1530 tprintf("%lu, %lu", tcp->u_arg[0], tcp->u_arg[1]);
1531 }
1532 return 0;
1533}
1534
John Hughesc61eb3d2002-05-17 11:37:50 +00001535#if UNIXWARE >= 2
1536
1537#include <sys/privilege.h>
1538
1539
Roland McGrathd9f816f2004-09-04 03:39:20 +00001540static const struct xlat procpriv_cmds [] = {
John Hughesc61eb3d2002-05-17 11:37:50 +00001541 { SETPRV, "SETPRV" },
1542 { CLRPRV, "CLRPRV" },
1543 { PUTPRV, "PUTPRV" },
1544 { GETPRV, "GETPRV" },
1545 { CNTPRV, "CNTPRV" },
1546 { 0, NULL },
1547};
1548
1549
Roland McGrathd9f816f2004-09-04 03:39:20 +00001550static const struct xlat procpriv_priv [] = {
John Hughesc61eb3d2002-05-17 11:37:50 +00001551 { P_OWNER, "P_OWNER" },
1552 { P_AUDIT, "P_AUDIT" },
1553 { P_COMPAT, "P_COMPAT" },
1554 { P_DACREAD, "P_DACREAD" },
1555 { P_DACWRITE, "P_DACWRITE" },
1556 { P_DEV, "P_DEV" },
1557 { P_FILESYS, "P_FILESYS" },
1558 { P_MACREAD, "P_MACREAD" },
1559 { P_MACWRITE, "P_MACWRITE" },
1560 { P_MOUNT, "P_MOUNT" },
1561 { P_MULTIDIR, "P_MULTIDIR" },
1562 { P_SETPLEVEL, "P_SETPLEVEL" },
1563 { P_SETSPRIV, "P_SETSPRIV" },
1564 { P_SETUID, "P_SETUID" },
1565 { P_SYSOPS, "P_SYSOPS" },
1566 { P_SETUPRIV, "P_SETUPRIV" },
1567 { P_DRIVER, "P_DRIVER" },
1568 { P_RTIME, "P_RTIME" },
1569 { P_MACUPGRADE, "P_MACUPGRADE" },
1570 { P_FSYSRANGE, "P_FSYSRANGE" },
1571 { P_SETFLEVEL, "P_SETFLEVEL" },
1572 { P_AUDITWR, "P_AUDITWR" },
1573 { P_TSHAR, "P_TSHAR" },
1574 { P_PLOCK, "P_PLOCK" },
1575 { P_CORE, "P_CORE" },
1576 { P_LOADMOD, "P_LOADMOD" },
1577 { P_BIND, "P_BIND" },
1578 { P_ALLPRIVS, "P_ALLPRIVS" },
1579 { 0, NULL },
1580};
1581
1582
Roland McGrathd9f816f2004-09-04 03:39:20 +00001583static const struct xlat procpriv_type [] = {
John Hughesc61eb3d2002-05-17 11:37:50 +00001584 { PS_FIX, "PS_FIX" },
1585 { PS_INH, "PS_INH" },
1586 { PS_MAX, "PS_MAX" },
1587 { PS_WKG, "PS_WKG" },
1588 { 0, NULL },
1589};
1590
1591
1592static void
Dmitry V. Levinab9008b2007-01-11 22:05:04 +00001593printpriv(struct tcb *tcp, long addr, int len, const struct xlat *opt)
John Hughesc61eb3d2002-05-17 11:37:50 +00001594{
1595 priv_t buf [128];
1596 int max = verbose (tcp) ? sizeof buf / sizeof buf [0] : 10;
1597 int dots = len > max;
1598 int i;
Roland McGrath5a223472002-12-15 23:58:26 +00001599
John Hughesc61eb3d2002-05-17 11:37:50 +00001600 if (len > max) len = max;
Roland McGrath5a223472002-12-15 23:58:26 +00001601
John Hughesc61eb3d2002-05-17 11:37:50 +00001602 if (len <= 0 ||
1603 umoven (tcp, addr, len * sizeof buf[0], (char *) buf) < 0)
1604 {
1605 tprintf ("%#lx", addr);
1606 return;
1607 }
1608
1609 tprintf ("[");
1610
1611 for (i = 0; i < len; ++i) {
Dmitry V. Levinab9008b2007-01-11 22:05:04 +00001612 const char *t, *p;
John Hughesc61eb3d2002-05-17 11:37:50 +00001613
1614 if (i) tprintf (", ");
1615
1616 if ((t = xlookup (procpriv_type, buf [i] & PS_TYPE)) &&
1617 (p = xlookup (procpriv_priv, buf [i] & ~PS_TYPE)))
1618 {
1619 tprintf ("%s|%s", t, p);
1620 }
1621 else {
1622 tprintf ("%#lx", buf [i]);
1623 }
1624 }
1625
1626 if (dots) tprintf (" ...");
1627
1628 tprintf ("]");
1629}
1630
1631
1632int
1633sys_procpriv(tcp)
1634struct tcb *tcp;
1635{
1636 if (entering(tcp)) {
1637 printxval(procpriv_cmds, tcp->u_arg[0], "???PRV");
1638 switch (tcp->u_arg[0]) {
1639 case CNTPRV:
1640 tprintf(", %#lx, %ld", tcp->u_arg[1], tcp->u_arg[2]);
1641 break;
1642
1643 case GETPRV:
1644 break;
1645
1646 default:
1647 tprintf (", ");
1648 printpriv (tcp, tcp->u_arg[1], tcp->u_arg[2]);
1649 tprintf (", %ld", tcp->u_arg[2]);
1650 }
1651 }
1652 else if (tcp->u_arg[0] == GETPRV) {
1653 if (syserror (tcp)) {
1654 tprintf(", %#lx, %ld", tcp->u_arg[1], tcp->u_arg[2]);
1655 }
1656 else {
1657 tprintf (", ");
1658 printpriv (tcp, tcp->u_arg[1], tcp->u_rval);
1659 tprintf (", %ld", tcp->u_arg[2]);
1660 }
1661 }
Roland McGrath5a223472002-12-15 23:58:26 +00001662
John Hughesc61eb3d2002-05-17 11:37:50 +00001663 return 0;
1664}
1665
Dmitry V. Levine5e60852009-12-31 22:50:49 +00001666#endif /* UNIXWARE */
John Hughesc61eb3d2002-05-17 11:37:50 +00001667
1668
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001669static void
Dmitry V. Levin30145dd2010-09-06 22:08:24 +00001670printargv(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001671{
Roland McGrath85a3bc42007-08-02 02:13:05 +00001672 union {
Andreas Schwab99c85692009-08-28 19:36:20 +02001673 unsigned int p32;
1674 unsigned long p64;
Roland McGrath85a3bc42007-08-02 02:13:05 +00001675 char data[sizeof(long)];
1676 } cp;
Dmitry V. Levin30145dd2010-09-06 22:08:24 +00001677 const char *sep;
Roland McGrath85a3bc42007-08-02 02:13:05 +00001678 int n = 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001679
Roland McGrath85a3bc42007-08-02 02:13:05 +00001680 cp.p64 = 1;
1681 for (sep = ""; !abbrev(tcp) || n < max_strlen / 2; sep = ", ", ++n) {
1682 if (umoven(tcp, addr, personality_wordsize[current_personality],
1683 cp.data) < 0) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001684 tprintf("%#lx", addr);
1685 return;
1686 }
Roland McGrath85a3bc42007-08-02 02:13:05 +00001687 if (personality_wordsize[current_personality] == 4)
1688 cp.p64 = cp.p32;
1689 if (cp.p64 == 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001690 break;
Dmitry V. Levin4bcd5ef2009-06-01 10:32:27 +00001691 tprintf("%s", sep);
Roland McGrath85a3bc42007-08-02 02:13:05 +00001692 printstr(tcp, cp.p64, -1);
1693 addr += personality_wordsize[current_personality];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001694 }
Roland McGrath85a3bc42007-08-02 02:13:05 +00001695 if (cp.p64)
1696 tprintf("%s...", sep);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001697}
1698
1699static void
Dmitry V. Levin30145dd2010-09-06 22:08:24 +00001700printargc(const char *fmt, struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001701{
1702 int count;
1703 char *cp;
1704
1705 for (count = 0; umove(tcp, addr, &cp) >= 0 && cp != NULL; count++) {
1706 addr += sizeof(char *);
1707 }
1708 tprintf(fmt, count, count == 1 ? "" : "s");
1709}
1710
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001711#if defined(SPARC) || defined(SPARC64) || defined(SUNOS4)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001712int
Dmitry V. Levine5e60852009-12-31 22:50:49 +00001713sys_execv(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001714{
1715 if (entering(tcp)) {
1716 printpath(tcp, tcp->u_arg[0]);
1717 if (!verbose(tcp))
1718 tprintf(", %#lx", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001719 else {
1720 tprintf(", [");
1721 printargv(tcp, tcp->u_arg[1]);
1722 tprintf("]");
1723 }
1724 }
1725 return 0;
1726}
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001727#endif /* SPARC || SPARC64 || SUNOS4 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001728
1729int
Dmitry V. Levine5e60852009-12-31 22:50:49 +00001730sys_execve(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001731{
1732 if (entering(tcp)) {
1733 printpath(tcp, tcp->u_arg[0]);
1734 if (!verbose(tcp))
1735 tprintf(", %#lx", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001736 else {
1737 tprintf(", [");
1738 printargv(tcp, tcp->u_arg[1]);
1739 tprintf("]");
1740 }
1741 if (!verbose(tcp))
1742 tprintf(", %#lx", tcp->u_arg[2]);
1743 else if (abbrev(tcp))
1744 printargc(", [/* %d var%s */]", tcp, tcp->u_arg[2]);
1745 else {
1746 tprintf(", [");
1747 printargv(tcp, tcp->u_arg[2]);
1748 tprintf("]");
1749 }
1750 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001751 return 0;
1752}
1753
Roland McGrath5ef24ab2004-02-20 02:22:35 +00001754#if UNIXWARE > 2
John Hughes4e36a812001-04-18 15:11:51 +00001755
1756int sys_rexecve(tcp)
1757struct tcb *tcp;
1758{
1759 if (entering (tcp)) {
1760 sys_execve (tcp);
1761 tprintf (", %ld", tcp->u_arg[3]);
1762 }
1763 return 0;
1764}
1765
Roland McGrath5ef24ab2004-02-20 02:22:35 +00001766#endif
John Hughes4e36a812001-04-18 15:11:51 +00001767
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001768int
1769internal_exec(tcp)
1770struct tcb *tcp;
1771{
1772#ifdef SUNOS4
1773 if (exiting(tcp) && !syserror(tcp) && followfork)
1774 fixvfork(tcp);
1775#endif /* SUNOS4 */
Roland McGrathfdb097f2004-07-12 07:38:55 +00001776#if defined LINUX && defined TCB_WAITEXECVE
1777 if (exiting(tcp) && syserror(tcp))
1778 tcp->flags &= ~TCB_WAITEXECVE;
1779 else
1780 tcp->flags |= TCB_WAITEXECVE;
1781#endif /* LINUX && TCB_WAITEXECVE */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001782 return 0;
1783}
1784
1785#ifdef LINUX
Roland McGrath7ec1d352002-12-17 04:50:44 +00001786#ifndef __WNOTHREAD
1787#define __WNOTHREAD 0x20000000
1788#endif
1789#ifndef __WALL
1790#define __WALL 0x40000000
1791#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001792#ifndef __WCLONE
Roland McGrath7ec1d352002-12-17 04:50:44 +00001793#define __WCLONE 0x80000000
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001794#endif
1795#endif /* LINUX */
1796
Roland McGrathd9f816f2004-09-04 03:39:20 +00001797static const struct xlat wait4_options[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001798 { WNOHANG, "WNOHANG" },
1799#ifndef WSTOPPED
1800 { WUNTRACED, "WUNTRACED" },
1801#endif
1802#ifdef WEXITED
1803 { WEXITED, "WEXITED" },
1804#endif
1805#ifdef WTRAPPED
1806 { WTRAPPED, "WTRAPPED" },
1807#endif
1808#ifdef WSTOPPED
1809 { WSTOPPED, "WSTOPPED" },
1810#endif
1811#ifdef WCONTINUED
1812 { WCONTINUED, "WCONTINUED" },
1813#endif
1814#ifdef WNOWAIT
1815 { WNOWAIT, "WNOWAIT" },
1816#endif
1817#ifdef __WCLONE
1818 { __WCLONE, "__WCLONE" },
1819#endif
Roland McGrath7ec1d352002-12-17 04:50:44 +00001820#ifdef __WALL
1821 { __WALL, "__WALL" },
1822#endif
1823#ifdef __WNOTHREAD
1824 { __WNOTHREAD, "__WNOTHREAD" },
1825#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001826 { 0, NULL },
1827};
1828
Roland McGrath5e02a572004-10-19 23:33:47 +00001829#if !defined WCOREFLAG && defined WCOREFLG
1830# define WCOREFLAG WCOREFLG
1831#endif
1832#ifndef WCOREFLAG
Dmitry V. Levine5e60852009-12-31 22:50:49 +00001833# define WCOREFLAG 0x80
Roland McGrath5e02a572004-10-19 23:33:47 +00001834#endif
Dmitry V. Levine5e60852009-12-31 22:50:49 +00001835#ifndef WCOREDUMP
1836# define WCOREDUMP(status) ((status) & 0200)
1837#endif
1838
Roland McGrath5e02a572004-10-19 23:33:47 +00001839
1840#ifndef W_STOPCODE
1841#define W_STOPCODE(sig) ((sig) << 8 | 0x7f)
1842#endif
1843#ifndef W_EXITCODE
1844#define W_EXITCODE(ret, sig) ((ret) << 8 | (sig))
1845#endif
1846
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001847static int
1848printstatus(status)
1849int status;
1850{
1851 int exited = 0;
1852
1853 /*
1854 * Here is a tricky presentation problem. This solution
1855 * is still not entirely satisfactory but since there
1856 * are no wait status constructors it will have to do.
1857 */
Roland McGrath79fbda52004-04-14 02:45:55 +00001858 if (WIFSTOPPED(status)) {
1859 tprintf("[{WIFSTOPPED(s) && WSTOPSIG(s) == %s}",
Nate Sammonsce780fc1999-03-29 23:23:13 +00001860 signame(WSTOPSIG(status)));
Roland McGrath79fbda52004-04-14 02:45:55 +00001861 status &= ~W_STOPCODE(WSTOPSIG(status));
1862 }
1863 else if (WIFSIGNALED(status)) {
1864 tprintf("[{WIFSIGNALED(s) && WTERMSIG(s) == %s%s}",
Nate Sammonsce780fc1999-03-29 23:23:13 +00001865 signame(WTERMSIG(status)),
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001866 WCOREDUMP(status) ? " && WCOREDUMP(s)" : "");
Roland McGrath79fbda52004-04-14 02:45:55 +00001867 status &= ~(W_EXITCODE(0, WTERMSIG(status)) | WCOREFLAG);
1868 }
1869 else if (WIFEXITED(status)) {
1870 tprintf("[{WIFEXITED(s) && WEXITSTATUS(s) == %d}",
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001871 WEXITSTATUS(status));
1872 exited = 1;
Roland McGrath79fbda52004-04-14 02:45:55 +00001873 status &= ~W_EXITCODE(WEXITSTATUS(status), 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001874 }
Roland McGrath79fbda52004-04-14 02:45:55 +00001875 else {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001876 tprintf("[%#x]", status);
Roland McGrath79fbda52004-04-14 02:45:55 +00001877 return 0;
1878 }
1879
1880 if (status == 0)
1881 tprintf("]");
1882 else
Roland McGrathf8cc83c2004-06-04 01:24:07 +00001883 tprintf(" | %#x]", status);
Roland McGrath79fbda52004-04-14 02:45:55 +00001884
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001885 return exited;
1886}
1887
1888static int
Denys Vlasenko59432db2009-01-26 19:09:35 +00001889printwaitn(struct tcb *tcp, int n, int bitness)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001890{
1891 int status;
1892 int exited = 0;
1893
1894 if (entering(tcp)) {
Denys Vlasenkoe740fd32009-04-16 12:06:16 +00001895#ifdef LINUX
1896 /* On Linux, kernel-side pid_t is typedef'ed to int
1897 * on all arches. Also, glibc-2.8 truncates wait3 and wait4
Denys Vlasenko59432db2009-01-26 19:09:35 +00001898 * pid argument to int on 64bit arches, producing,
1899 * for example, wait4(4294967295, ...) instead of -1
Denys Vlasenkoe740fd32009-04-16 12:06:16 +00001900 * in strace. We have to use int here, not long.
1901 */
1902 int pid = tcp->u_arg[0];
1903 tprintf("%d, ", pid);
1904#else
1905 /*
1906 * Sign-extend a 32-bit value when that's what it is.
Roland McGrath5b63d962008-07-18 02:16:47 +00001907 */
1908 long pid = tcp->u_arg[0];
1909 if (personality_wordsize[current_personality] < sizeof pid)
1910 pid = (long) (int) pid;
1911 tprintf("%ld, ", pid);
Denys Vlasenkoe740fd32009-04-16 12:06:16 +00001912#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001913 } else {
1914 /* status */
1915 if (!tcp->u_arg[1])
1916 tprintf("NULL");
1917 else if (syserror(tcp) || tcp->u_rval == 0)
1918 tprintf("%#lx", tcp->u_arg[1]);
1919 else if (umove(tcp, tcp->u_arg[1], &status) < 0)
1920 tprintf("[?]");
1921 else
1922 exited = printstatus(status);
1923 /* options */
1924 tprintf(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +00001925 printflags(wait4_options, tcp->u_arg[2], "W???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001926 if (n == 4) {
1927 tprintf(", ");
1928 /* usage */
1929 if (!tcp->u_arg[3])
1930 tprintf("NULL");
1931#ifdef LINUX
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001932 else if (tcp->u_rval > 0) {
Denys Vlasenko59432db2009-01-26 19:09:35 +00001933#ifdef ALPHA
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001934 if (bitness)
1935 printrusage32(tcp, tcp->u_arg[3]);
1936 else
1937#endif
1938 printrusage(tcp, tcp->u_arg[3]);
1939 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001940#endif /* LINUX */
1941#ifdef SUNOS4
1942 else if (tcp->u_rval > 0 && exited)
1943 printrusage(tcp, tcp->u_arg[3]);
1944#endif /* SUNOS4 */
1945 else
1946 tprintf("%#lx", tcp->u_arg[3]);
1947 }
1948 }
1949 return 0;
1950}
1951
1952int
Roland McGrathc74c0b72004-09-01 19:39:46 +00001953internal_wait(tcp, flagarg)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001954struct tcb *tcp;
Roland McGrathc74c0b72004-09-01 19:39:46 +00001955int flagarg;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001956{
Roland McGrathe85bbfe2003-01-09 06:53:31 +00001957 int got_kids;
1958
1959#ifdef TCB_CLONE_THREAD
1960 if (tcp->flags & TCB_CLONE_THREAD)
1961 /* The children we wait for are our parent's children. */
1962 got_kids = (tcp->parent->nchildren
Wang Chao21b8db42010-08-27 17:43:16 +08001963 > tcp->parent->nclone_threads);
Roland McGrathe85bbfe2003-01-09 06:53:31 +00001964 else
Wang Chao21b8db42010-08-27 17:43:16 +08001965 got_kids = (tcp->nchildren > tcp->nclone_threads);
Roland McGrathe85bbfe2003-01-09 06:53:31 +00001966#else
1967 got_kids = tcp->nchildren > 0;
1968#endif
1969
1970 if (entering(tcp) && got_kids) {
Roland McGrathb69f81b2002-12-21 23:25:18 +00001971 /* There are children that this parent should block for.
1972 But ptrace made us the parent of the traced children
1973 and the real parent will get ECHILD from the wait call.
1974
1975 XXX If we attached with strace -f -p PID, then there
1976 may be untraced dead children the parent could be reaping
1977 now, but we make him block. */
1978
1979 /* ??? WTA: fix bug with hanging children */
1980
Roland McGrathc74c0b72004-09-01 19:39:46 +00001981 if (!(tcp->u_arg[flagarg] & WNOHANG)) {
Roland McGrath09623452003-05-23 02:27:13 +00001982 /*
1983 * There are traced children. We'll make the parent
1984 * block to avoid a false ECHILD error due to our
1985 * ptrace having stolen the children. However,
1986 * we shouldn't block if there are zombies to reap.
1987 * XXX doesn't handle pgrp matches (u_arg[0]==0,<-1)
1988 */
Roland McGrathfccfb942003-10-01 21:59:44 +00001989 struct tcb *child = NULL;
Roland McGrath09623452003-05-23 02:27:13 +00001990 if (tcp->nzombies > 0 &&
1991 (tcp->u_arg[0] == -1 ||
Roland McGrathfccfb942003-10-01 21:59:44 +00001992 (child = pid2tcb(tcp->u_arg[0])) == NULL))
Roland McGrath09623452003-05-23 02:27:13 +00001993 return 0;
Roland McGrathfccfb942003-10-01 21:59:44 +00001994 if (tcp->u_arg[0] > 0) {
1995 /*
1996 * If the parent waits for a specified child
1997 * PID, then it must get ECHILD right away
1998 * if that PID is not one of its children.
1999 * Make sure that the requested PID matches
2000 * one of the parent's children that we are
2001 * tracing, and don't suspend it otherwise.
2002 */
2003 if (child == NULL)
2004 child = pid2tcb(tcp->u_arg[0]);
2005 if (child == NULL || child->parent != (
2006#ifdef TCB_CLONE_THREAD
2007 (tcp->flags & TCB_CLONE_THREAD)
2008 ? tcp->parent :
2009#endif
Roland McGrathd56a6562005-08-03 11:23:43 +00002010 tcp) ||
2011 (child->flags & TCB_EXITING))
Roland McGrathfccfb942003-10-01 21:59:44 +00002012 return 0;
2013 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002014 tcp->flags |= TCB_SUSPENDED;
2015 tcp->waitpid = tcp->u_arg[0];
Roland McGrathe85bbfe2003-01-09 06:53:31 +00002016#ifdef TCB_CLONE_THREAD
2017 if (tcp->flags & TCB_CLONE_THREAD)
2018 tcp->parent->nclone_waiting++;
2019#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002020 }
2021 }
Roland McGrathe85bbfe2003-01-09 06:53:31 +00002022 if (exiting(tcp) && tcp->u_error == ECHILD && got_kids) {
Roland McGrathc74c0b72004-09-01 19:39:46 +00002023 if (tcp->u_arg[flagarg] & WNOHANG) {
Roland McGrathb69f81b2002-12-21 23:25:18 +00002024 /* We must force a fake result of 0 instead of
2025 the ECHILD error. */
Roland McGrathb69f81b2002-12-21 23:25:18 +00002026 return force_result(tcp, 0, 0);
2027 }
Roland McGrathb69f81b2002-12-21 23:25:18 +00002028 }
Roland McGrath09623452003-05-23 02:27:13 +00002029 else if (exiting(tcp) && tcp->u_error == 0 && tcp->u_rval > 0 &&
2030 tcp->nzombies > 0 && pid2tcb(tcp->u_rval) == NULL) {
2031 /*
2032 * We just reaped a child we don't know about,
2033 * presumably a zombie we already droptcb'd.
2034 */
2035 tcp->nzombies--;
2036 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002037 return 0;
2038}
2039
2040#ifdef SVR4
2041
2042int
2043sys_wait(tcp)
2044struct tcb *tcp;
2045{
2046 if (exiting(tcp)) {
2047 /* The library wrapper stuffs this into the user variable. */
2048 if (!syserror(tcp))
2049 printstatus(getrval2(tcp));
2050 }
2051 return 0;
2052}
2053
2054#endif /* SVR4 */
2055
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002056#ifdef FREEBSD
2057int
2058sys_wait(tcp)
2059struct tcb *tcp;
2060{
2061 int status;
Roland McGrath5a223472002-12-15 23:58:26 +00002062
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002063 if (exiting(tcp)) {
2064 if (!syserror(tcp)) {
2065 if (umove(tcp, tcp->u_arg[0], &status) < 0)
2066 tprintf("%#lx", tcp->u_arg[0]);
2067 else
2068 printstatus(status);
2069 }
2070 }
2071 return 0;
2072}
2073#endif
2074
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002075int
2076sys_waitpid(tcp)
2077struct tcb *tcp;
2078{
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00002079 return printwaitn(tcp, 3, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002080}
2081
2082int
2083sys_wait4(tcp)
2084struct tcb *tcp;
2085{
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00002086 return printwaitn(tcp, 4, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002087}
2088
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00002089#ifdef ALPHA
2090int
2091sys_osf_wait4(tcp)
2092struct tcb *tcp;
2093{
2094 return printwaitn(tcp, 4, 1);
2095}
2096#endif
2097
Roland McGrathc74c0b72004-09-01 19:39:46 +00002098#if defined SVR4 || defined LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002099
Roland McGrathd9f816f2004-09-04 03:39:20 +00002100static const struct xlat waitid_types[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002101 { P_PID, "P_PID" },
Roland McGrathc74c0b72004-09-01 19:39:46 +00002102#ifdef P_PPID
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002103 { P_PPID, "P_PPID" },
Roland McGrathc74c0b72004-09-01 19:39:46 +00002104#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002105 { P_PGID, "P_PGID" },
Roland McGrathc74c0b72004-09-01 19:39:46 +00002106#ifdef P_SID
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002107 { P_SID, "P_SID" },
Roland McGrathc74c0b72004-09-01 19:39:46 +00002108#endif
2109#ifdef P_CID
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002110 { P_CID, "P_CID" },
Roland McGrathc74c0b72004-09-01 19:39:46 +00002111#endif
2112#ifdef P_UID
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002113 { P_UID, "P_UID" },
Roland McGrathc74c0b72004-09-01 19:39:46 +00002114#endif
2115#ifdef P_GID
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002116 { P_GID, "P_GID" },
Roland McGrathc74c0b72004-09-01 19:39:46 +00002117#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002118 { P_ALL, "P_ALL" },
2119#ifdef P_LWPID
2120 { P_LWPID, "P_LWPID" },
2121#endif
2122 { 0, NULL },
2123};
2124
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002125int
Dmitry V. Levin3eb94912010-09-09 23:08:59 +00002126sys_waitid(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002127{
2128 siginfo_t si;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002129
2130 if (entering(tcp)) {
2131 printxval(waitid_types, tcp->u_arg[0], "P_???");
2132 tprintf(", %ld, ", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002133 }
2134 else {
2135 /* siginfo */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002136 if (!tcp->u_arg[2])
2137 tprintf("NULL");
2138 else if (syserror(tcp))
2139 tprintf("%#lx", tcp->u_arg[2]);
2140 else if (umove(tcp, tcp->u_arg[2], &si) < 0)
2141 tprintf("{???}");
2142 else
Denys Vlasenkof535b542009-01-13 18:30:55 +00002143 printsiginfo(&si, verbose(tcp));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002144 /* options */
2145 tprintf(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +00002146 printflags(wait4_options, tcp->u_arg[3], "W???");
Roland McGrath39426a32004-10-06 22:02:59 +00002147 if (tcp->u_nargs > 4) {
2148 /* usage */
2149 tprintf(", ");
2150 if (!tcp->u_arg[4])
2151 tprintf("NULL");
2152 else if (tcp->u_error)
2153 tprintf("%#lx", tcp->u_arg[4]);
2154 else
2155 printrusage(tcp, tcp->u_arg[4]);
2156 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002157 }
2158 return 0;
2159}
2160
Roland McGrathc74c0b72004-09-01 19:39:46 +00002161#endif /* SVR4 or LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002162
2163int
2164sys_alarm(tcp)
2165struct tcb *tcp;
2166{
2167 if (entering(tcp))
2168 tprintf("%lu", tcp->u_arg[0]);
2169 return 0;
2170}
2171
2172int
2173sys_uname(tcp)
2174struct tcb *tcp;
2175{
2176 struct utsname uname;
2177
2178 if (exiting(tcp)) {
2179 if (syserror(tcp) || !verbose(tcp))
2180 tprintf("%#lx", tcp->u_arg[0]);
2181 else if (umove(tcp, tcp->u_arg[0], &uname) < 0)
2182 tprintf("{...}");
2183 else if (!abbrev(tcp)) {
2184
2185 tprintf("{sysname=\"%s\", nodename=\"%s\", ",
2186 uname.sysname, uname.nodename);
2187 tprintf("release=\"%s\", version=\"%s\", ",
2188 uname.release, uname.version);
2189 tprintf("machine=\"%s\"", uname.machine);
2190#ifdef LINUX
2191#ifndef __GLIBC__
2192 tprintf(", domainname=\"%s\"", uname.domainname);
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002193#endif
2194#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002195 tprintf("}");
2196 }
2197 else
2198 tprintf("{sys=\"%s\", node=\"%s\", ...}",
2199 uname.sysname, uname.nodename);
2200 }
2201 return 0;
2202}
2203
2204#ifndef SVR4
2205
Roland McGratheb9e2e82009-06-02 16:49:22 -07002206static const struct xlat ptrace_cmds[] = {
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002207# ifndef FREEBSD
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002208 { PTRACE_TRACEME, "PTRACE_TRACEME" },
2209 { PTRACE_PEEKTEXT, "PTRACE_PEEKTEXT", },
2210 { PTRACE_PEEKDATA, "PTRACE_PEEKDATA", },
2211 { PTRACE_PEEKUSER, "PTRACE_PEEKUSER", },
2212 { PTRACE_POKETEXT, "PTRACE_POKETEXT", },
2213 { PTRACE_POKEDATA, "PTRACE_POKEDATA", },
2214 { PTRACE_POKEUSER, "PTRACE_POKEUSER", },
2215 { PTRACE_CONT, "PTRACE_CONT" },
2216 { PTRACE_KILL, "PTRACE_KILL" },
2217 { PTRACE_SINGLESTEP, "PTRACE_SINGLESTEP" },
2218 { PTRACE_ATTACH, "PTRACE_ATTACH" },
2219 { PTRACE_DETACH, "PTRACE_DETACH" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002220# ifdef PTRACE_GETREGS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002221 { PTRACE_GETREGS, "PTRACE_GETREGS" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002222# endif
2223# ifdef PTRACE_SETREGS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002224 { PTRACE_SETREGS, "PTRACE_SETREGS" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002225# endif
2226# ifdef PTRACE_GETFPREGS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002227 { PTRACE_GETFPREGS, "PTRACE_GETFPREGS", },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002228# endif
2229# ifdef PTRACE_SETFPREGS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002230 { PTRACE_SETFPREGS, "PTRACE_SETFPREGS", },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002231# endif
2232# ifdef PTRACE_GETFPXREGS
Roland McGrathbf621d42003-01-14 09:46:21 +00002233 { PTRACE_GETFPXREGS, "PTRACE_GETFPXREGS", },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002234# endif
2235# ifdef PTRACE_SETFPXREGS
Roland McGrathbf621d42003-01-14 09:46:21 +00002236 { PTRACE_SETFPXREGS, "PTRACE_SETFPXREGS", },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002237# endif
2238# ifdef PTRACE_GETVRREGS
Roland McGrathf04bb482005-05-09 07:45:33 +00002239 { PTRACE_GETVRREGS, "PTRACE_GETVRREGS", },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002240# endif
2241# ifdef PTRACE_SETVRREGS
Roland McGrathf04bb482005-05-09 07:45:33 +00002242 { PTRACE_SETVRREGS, "PTRACE_SETVRREGS", },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002243# endif
2244# ifdef PTRACE_SETOPTIONS
Denys Vlasenkof535b542009-01-13 18:30:55 +00002245 { PTRACE_SETOPTIONS, "PTRACE_SETOPTIONS", },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002246# endif
2247# ifdef PTRACE_GETEVENTMSG
Denys Vlasenkof535b542009-01-13 18:30:55 +00002248 { PTRACE_GETEVENTMSG, "PTRACE_GETEVENTMSG", },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002249# endif
2250# ifdef PTRACE_GETSIGINFO
Denys Vlasenkof535b542009-01-13 18:30:55 +00002251 { PTRACE_GETSIGINFO, "PTRACE_GETSIGINFO", },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002252# endif
2253# ifdef PTRACE_SETSIGINFO
Denys Vlasenkof535b542009-01-13 18:30:55 +00002254 { PTRACE_SETSIGINFO, "PTRACE_SETSIGINFO", },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002255# endif
2256# ifdef PTRACE_SET_SYSCALL
2257 { PTRACE_SET_SYSCALL, "PTRACE_SET_SYSCALL", },
2258# endif
2259# ifdef SUNOS4
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002260 { PTRACE_READDATA, "PTRACE_READDATA" },
2261 { PTRACE_WRITEDATA, "PTRACE_WRITEDATA" },
2262 { PTRACE_READTEXT, "PTRACE_READTEXT" },
2263 { PTRACE_WRITETEXT, "PTRACE_WRITETEXT" },
2264 { PTRACE_GETFPAREGS, "PTRACE_GETFPAREGS" },
2265 { PTRACE_SETFPAREGS, "PTRACE_SETFPAREGS" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002266# ifdef SPARC
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002267 { PTRACE_GETWINDOW, "PTRACE_GETWINDOW" },
2268 { PTRACE_SETWINDOW, "PTRACE_SETWINDOW" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002269# else /* !SPARC */
2270 { PTRACE_22, "PTRACE_22" },
2271 { PTRACE_23, "PTRACE_3" },
2272# endif /* !SPARC */
2273# endif /* SUNOS4 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002274 { PTRACE_SYSCALL, "PTRACE_SYSCALL" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002275# ifdef SUNOS4
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002276 { PTRACE_DUMPCORE, "PTRACE_DUMPCORE" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002277# ifdef I386
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002278 { PTRACE_SETWRBKPT, "PTRACE_SETWRBKPT" },
2279 { PTRACE_SETACBKPT, "PTRACE_SETACBKPT" },
2280 { PTRACE_CLRDR7, "PTRACE_CLRDR7" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002281# else /* !I386 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002282 { PTRACE_26, "PTRACE_26" },
2283 { PTRACE_27, "PTRACE_27" },
2284 { PTRACE_28, "PTRACE_28" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002285# endif /* !I386 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002286 { PTRACE_GETUCODE, "PTRACE_GETUCODE" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002287# endif /* SUNOS4 */
Denys Vlasenkof535b542009-01-13 18:30:55 +00002288
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002289# else /* FREEBSD */
Denys Vlasenkof535b542009-01-13 18:30:55 +00002290
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002291 { PT_TRACE_ME, "PT_TRACE_ME" },
2292 { PT_READ_I, "PT_READ_I" },
2293 { PT_READ_D, "PT_READ_D" },
2294 { PT_WRITE_I, "PT_WRITE_I" },
2295 { PT_WRITE_D, "PT_WRITE_D" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002296# ifdef PT_READ_U
John Hughesa2278142001-09-28 16:21:30 +00002297 { PT_READ_U, "PT_READ_U" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002298# endif
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002299 { PT_CONTINUE, "PT_CONTINUE" },
2300 { PT_KILL, "PT_KILL" },
2301 { PT_STEP, "PT_STEP" },
2302 { PT_ATTACH, "PT_ATTACH" },
2303 { PT_DETACH, "PT_DETACH" },
2304 { PT_GETREGS, "PT_GETREGS" },
2305 { PT_SETREGS, "PT_SETREGS" },
2306 { PT_GETFPREGS, "PT_GETFPREGS" },
2307 { PT_SETFPREGS, "PT_SETFPREGS" },
2308 { PT_GETDBREGS, "PT_GETDBREGS" },
2309 { PT_SETDBREGS, "PT_SETDBREGS" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002310# endif /* FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002311 { 0, NULL },
2312};
2313
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002314# ifndef FREEBSD
2315# ifdef PTRACE_SETOPTIONS
Denys Vlasenkof535b542009-01-13 18:30:55 +00002316static const struct xlat ptrace_setoptions_flags[] = {
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002317# ifdef PTRACE_O_TRACESYSGOOD
Denys Vlasenkof535b542009-01-13 18:30:55 +00002318 { PTRACE_O_TRACESYSGOOD,"PTRACE_O_TRACESYSGOOD" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002319# endif
2320# ifdef PTRACE_O_TRACEFORK
Denys Vlasenkof535b542009-01-13 18:30:55 +00002321 { PTRACE_O_TRACEFORK, "PTRACE_O_TRACEFORK" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002322# endif
2323# ifdef PTRACE_O_TRACEVFORK
Denys Vlasenkof535b542009-01-13 18:30:55 +00002324 { PTRACE_O_TRACEVFORK, "PTRACE_O_TRACEVFORK" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002325# endif
2326# ifdef PTRACE_O_TRACECLONE
Denys Vlasenkof535b542009-01-13 18:30:55 +00002327 { PTRACE_O_TRACECLONE, "PTRACE_O_TRACECLONE" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002328# endif
2329# ifdef PTRACE_O_TRACEEXEC
Denys Vlasenkof535b542009-01-13 18:30:55 +00002330 { PTRACE_O_TRACEEXEC, "PTRACE_O_TRACEEXEC" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002331# endif
2332# ifdef PTRACE_O_TRACEVFORKDONE
Denys Vlasenkof535b542009-01-13 18:30:55 +00002333 { PTRACE_O_TRACEVFORKDONE,"PTRACE_O_TRACEVFORKDONE"},
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002334# endif
2335# ifdef PTRACE_O_TRACEEXIT
Denys Vlasenkof535b542009-01-13 18:30:55 +00002336 { PTRACE_O_TRACEEXIT, "PTRACE_O_TRACEEXIT" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002337# endif
Denys Vlasenkof535b542009-01-13 18:30:55 +00002338 { 0, NULL },
2339};
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002340# endif /* PTRACE_SETOPTIONS */
2341# endif /* !FREEBSD */
Denys Vlasenkof535b542009-01-13 18:30:55 +00002342
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002343# ifndef FREEBSD
Roland McGrathd9f816f2004-09-04 03:39:20 +00002344const struct xlat struct_user_offsets[] = {
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002345# ifdef LINUX
2346# if defined(S390) || defined(S390X)
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00002347 { PT_PSWMASK, "psw_mask" },
2348 { PT_PSWADDR, "psw_addr" },
2349 { PT_GPR0, "gpr0" },
2350 { PT_GPR1, "gpr1" },
2351 { PT_GPR2, "gpr2" },
2352 { PT_GPR3, "gpr3" },
2353 { PT_GPR4, "gpr4" },
2354 { PT_GPR5, "gpr5" },
2355 { PT_GPR6, "gpr6" },
2356 { PT_GPR7, "gpr7" },
2357 { PT_GPR8, "gpr8" },
2358 { PT_GPR9, "gpr9" },
2359 { PT_GPR10, "gpr10" },
2360 { PT_GPR11, "gpr11" },
2361 { PT_GPR12, "gpr12" },
2362 { PT_GPR13, "gpr13" },
2363 { PT_GPR14, "gpr14" },
2364 { PT_GPR15, "gpr15" },
2365 { PT_ACR0, "acr0" },
2366 { PT_ACR1, "acr1" },
2367 { PT_ACR2, "acr2" },
2368 { PT_ACR3, "acr3" },
2369 { PT_ACR4, "acr4" },
2370 { PT_ACR5, "acr5" },
2371 { PT_ACR6, "acr6" },
2372 { PT_ACR7, "acr7" },
2373 { PT_ACR8, "acr8" },
2374 { PT_ACR9, "acr9" },
2375 { PT_ACR10, "acr10" },
2376 { PT_ACR11, "acr11" },
2377 { PT_ACR12, "acr12" },
2378 { PT_ACR13, "acr13" },
2379 { PT_ACR14, "acr14" },
2380 { PT_ACR15, "acr15" },
2381 { PT_ORIGGPR2, "orig_gpr2" },
2382 { PT_FPC, "fpc" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002383# if defined(S390)
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00002384 { PT_FPR0_HI, "fpr0.hi" },
2385 { PT_FPR0_LO, "fpr0.lo" },
2386 { PT_FPR1_HI, "fpr1.hi" },
2387 { PT_FPR1_LO, "fpr1.lo" },
2388 { PT_FPR2_HI, "fpr2.hi" },
2389 { PT_FPR2_LO, "fpr2.lo" },
2390 { PT_FPR3_HI, "fpr3.hi" },
2391 { PT_FPR3_LO, "fpr3.lo" },
2392 { PT_FPR4_HI, "fpr4.hi" },
2393 { PT_FPR4_LO, "fpr4.lo" },
2394 { PT_FPR5_HI, "fpr5.hi" },
2395 { PT_FPR5_LO, "fpr5.lo" },
2396 { PT_FPR6_HI, "fpr6.hi" },
2397 { PT_FPR6_LO, "fpr6.lo" },
2398 { PT_FPR7_HI, "fpr7.hi" },
2399 { PT_FPR7_LO, "fpr7.lo" },
2400 { PT_FPR8_HI, "fpr8.hi" },
2401 { PT_FPR8_LO, "fpr8.lo" },
2402 { PT_FPR9_HI, "fpr9.hi" },
2403 { PT_FPR9_LO, "fpr9.lo" },
2404 { PT_FPR10_HI, "fpr10.hi" },
2405 { PT_FPR10_LO, "fpr10.lo" },
2406 { PT_FPR11_HI, "fpr11.hi" },
2407 { PT_FPR11_LO, "fpr11.lo" },
2408 { PT_FPR12_HI, "fpr12.hi" },
2409 { PT_FPR12_LO, "fpr12.lo" },
2410 { PT_FPR13_HI, "fpr13.hi" },
2411 { PT_FPR13_LO, "fpr13.lo" },
2412 { PT_FPR14_HI, "fpr14.hi" },
2413 { PT_FPR14_LO, "fpr14.lo" },
2414 { PT_FPR15_HI, "fpr15.hi" },
2415 { PT_FPR15_LO, "fpr15.lo" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002416# endif
2417# if defined(S390X)
Michal Ludvig10a88d02002-10-07 14:31:00 +00002418 { PT_FPR0, "fpr0" },
2419 { PT_FPR1, "fpr1" },
2420 { PT_FPR2, "fpr2" },
2421 { PT_FPR3, "fpr3" },
2422 { PT_FPR4, "fpr4" },
2423 { PT_FPR5, "fpr5" },
2424 { PT_FPR6, "fpr6" },
2425 { PT_FPR7, "fpr7" },
2426 { PT_FPR8, "fpr8" },
2427 { PT_FPR9, "fpr9" },
2428 { PT_FPR10, "fpr10" },
2429 { PT_FPR11, "fpr11" },
2430 { PT_FPR12, "fpr12" },
2431 { PT_FPR13, "fpr13" },
2432 { PT_FPR14, "fpr14" },
2433 { PT_FPR15, "fpr15" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002434# endif
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00002435 { PT_CR_9, "cr9" },
2436 { PT_CR_10, "cr10" },
2437 { PT_CR_11, "cr11" },
Michal Ludvig10a88d02002-10-07 14:31:00 +00002438 { PT_IEEE_IP, "ieee_exception_ip" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002439# elif defined(SPARC)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002440 /* XXX No support for these offsets yet. */
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002441# elif defined(HPPA)
Wichert Akkermanc1652e22001-03-27 12:17:16 +00002442 /* XXX No support for these offsets yet. */
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002443# elif defined(POWERPC)
2444# ifndef PT_ORIG_R3
2445# define PT_ORIG_R3 34
2446# endif
2447# define REGSIZE (sizeof(unsigned long))
Roland McGratheb285352003-01-14 09:59:00 +00002448 { REGSIZE*PT_R0, "r0" },
2449 { REGSIZE*PT_R1, "r1" },
2450 { REGSIZE*PT_R2, "r2" },
2451 { REGSIZE*PT_R3, "r3" },
2452 { REGSIZE*PT_R4, "r4" },
2453 { REGSIZE*PT_R5, "r5" },
2454 { REGSIZE*PT_R6, "r6" },
2455 { REGSIZE*PT_R7, "r7" },
2456 { REGSIZE*PT_R8, "r8" },
2457 { REGSIZE*PT_R9, "r9" },
2458 { REGSIZE*PT_R10, "r10" },
2459 { REGSIZE*PT_R11, "r11" },
2460 { REGSIZE*PT_R12, "r12" },
2461 { REGSIZE*PT_R13, "r13" },
2462 { REGSIZE*PT_R14, "r14" },
2463 { REGSIZE*PT_R15, "r15" },
2464 { REGSIZE*PT_R16, "r16" },
2465 { REGSIZE*PT_R17, "r17" },
2466 { REGSIZE*PT_R18, "r18" },
2467 { REGSIZE*PT_R19, "r19" },
2468 { REGSIZE*PT_R20, "r20" },
2469 { REGSIZE*PT_R21, "r21" },
2470 { REGSIZE*PT_R22, "r22" },
2471 { REGSIZE*PT_R23, "r23" },
2472 { REGSIZE*PT_R24, "r24" },
2473 { REGSIZE*PT_R25, "r25" },
2474 { REGSIZE*PT_R26, "r26" },
2475 { REGSIZE*PT_R27, "r27" },
2476 { REGSIZE*PT_R28, "r28" },
2477 { REGSIZE*PT_R29, "r29" },
2478 { REGSIZE*PT_R30, "r30" },
2479 { REGSIZE*PT_R31, "r31" },
2480 { REGSIZE*PT_NIP, "NIP" },
2481 { REGSIZE*PT_MSR, "MSR" },
2482 { REGSIZE*PT_ORIG_R3, "ORIG_R3" },
2483 { REGSIZE*PT_CTR, "CTR" },
2484 { REGSIZE*PT_LNK, "LNK" },
2485 { REGSIZE*PT_XER, "XER" },
2486 { REGSIZE*PT_CCR, "CCR" },
2487 { REGSIZE*PT_FPR0, "FPR0" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002488# undef REGSIZE
2489# elif defined(ALPHA)
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00002490 { 0, "r0" },
2491 { 1, "r1" },
2492 { 2, "r2" },
2493 { 3, "r3" },
2494 { 4, "r4" },
2495 { 5, "r5" },
2496 { 6, "r6" },
2497 { 7, "r7" },
2498 { 8, "r8" },
2499 { 9, "r9" },
2500 { 10, "r10" },
2501 { 11, "r11" },
2502 { 12, "r12" },
2503 { 13, "r13" },
2504 { 14, "r14" },
2505 { 15, "r15" },
2506 { 16, "r16" },
2507 { 17, "r17" },
2508 { 18, "r18" },
2509 { 19, "r19" },
2510 { 20, "r20" },
2511 { 21, "r21" },
2512 { 22, "r22" },
2513 { 23, "r23" },
2514 { 24, "r24" },
2515 { 25, "r25" },
2516 { 26, "r26" },
2517 { 27, "r27" },
2518 { 28, "r28" },
2519 { 29, "gp" },
2520 { 30, "fp" },
2521 { 31, "zero" },
2522 { 32, "fp0" },
2523 { 33, "fp" },
2524 { 34, "fp2" },
2525 { 35, "fp3" },
2526 { 36, "fp4" },
2527 { 37, "fp5" },
2528 { 38, "fp6" },
2529 { 39, "fp7" },
2530 { 40, "fp8" },
2531 { 41, "fp9" },
2532 { 42, "fp10" },
2533 { 43, "fp11" },
2534 { 44, "fp12" },
2535 { 45, "fp13" },
2536 { 46, "fp14" },
2537 { 47, "fp15" },
2538 { 48, "fp16" },
2539 { 49, "fp17" },
2540 { 50, "fp18" },
2541 { 51, "fp19" },
2542 { 52, "fp20" },
2543 { 53, "fp21" },
2544 { 54, "fp22" },
2545 { 55, "fp23" },
2546 { 56, "fp24" },
2547 { 57, "fp25" },
2548 { 58, "fp26" },
2549 { 59, "fp27" },
2550 { 60, "fp28" },
2551 { 61, "fp29" },
2552 { 62, "fp30" },
2553 { 63, "fp31" },
2554 { 64, "pc" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002555# elif defined(IA64)
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00002556 { PT_F32, "f32" }, { PT_F33, "f33" }, { PT_F34, "f34" },
2557 { PT_F35, "f35" }, { PT_F36, "f36" }, { PT_F37, "f37" },
2558 { PT_F38, "f38" }, { PT_F39, "f39" }, { PT_F40, "f40" },
2559 { PT_F41, "f41" }, { PT_F42, "f42" }, { PT_F43, "f43" },
2560 { PT_F44, "f44" }, { PT_F45, "f45" }, { PT_F46, "f46" },
2561 { PT_F47, "f47" }, { PT_F48, "f48" }, { PT_F49, "f49" },
2562 { PT_F50, "f50" }, { PT_F51, "f51" }, { PT_F52, "f52" },
2563 { PT_F53, "f53" }, { PT_F54, "f54" }, { PT_F55, "f55" },
2564 { PT_F56, "f56" }, { PT_F57, "f57" }, { PT_F58, "f58" },
2565 { PT_F59, "f59" }, { PT_F60, "f60" }, { PT_F61, "f61" },
2566 { PT_F62, "f62" }, { PT_F63, "f63" }, { PT_F64, "f64" },
2567 { PT_F65, "f65" }, { PT_F66, "f66" }, { PT_F67, "f67" },
2568 { PT_F68, "f68" }, { PT_F69, "f69" }, { PT_F70, "f70" },
2569 { PT_F71, "f71" }, { PT_F72, "f72" }, { PT_F73, "f73" },
2570 { PT_F74, "f74" }, { PT_F75, "f75" }, { PT_F76, "f76" },
2571 { PT_F77, "f77" }, { PT_F78, "f78" }, { PT_F79, "f79" },
2572 { PT_F80, "f80" }, { PT_F81, "f81" }, { PT_F82, "f82" },
2573 { PT_F83, "f83" }, { PT_F84, "f84" }, { PT_F85, "f85" },
2574 { PT_F86, "f86" }, { PT_F87, "f87" }, { PT_F88, "f88" },
2575 { PT_F89, "f89" }, { PT_F90, "f90" }, { PT_F91, "f91" },
2576 { PT_F92, "f92" }, { PT_F93, "f93" }, { PT_F94, "f94" },
2577 { PT_F95, "f95" }, { PT_F96, "f96" }, { PT_F97, "f97" },
2578 { PT_F98, "f98" }, { PT_F99, "f99" }, { PT_F100, "f100" },
2579 { PT_F101, "f101" }, { PT_F102, "f102" }, { PT_F103, "f103" },
2580 { PT_F104, "f104" }, { PT_F105, "f105" }, { PT_F106, "f106" },
2581 { PT_F107, "f107" }, { PT_F108, "f108" }, { PT_F109, "f109" },
2582 { PT_F110, "f110" }, { PT_F111, "f111" }, { PT_F112, "f112" },
2583 { PT_F113, "f113" }, { PT_F114, "f114" }, { PT_F115, "f115" },
2584 { PT_F116, "f116" }, { PT_F117, "f117" }, { PT_F118, "f118" },
2585 { PT_F119, "f119" }, { PT_F120, "f120" }, { PT_F121, "f121" },
2586 { PT_F122, "f122" }, { PT_F123, "f123" }, { PT_F124, "f124" },
2587 { PT_F125, "f125" }, { PT_F126, "f126" }, { PT_F127, "f127" },
2588 /* switch stack: */
2589 { PT_F2, "f2" }, { PT_F3, "f3" }, { PT_F4, "f4" },
2590 { PT_F5, "f5" }, { PT_F10, "f10" }, { PT_F11, "f11" },
2591 { PT_F12, "f12" }, { PT_F13, "f13" }, { PT_F14, "f14" },
2592 { PT_F15, "f15" }, { PT_F16, "f16" }, { PT_F17, "f17" },
2593 { PT_F18, "f18" }, { PT_F19, "f19" }, { PT_F20, "f20" },
2594 { PT_F21, "f21" }, { PT_F22, "f22" }, { PT_F23, "f23" },
2595 { PT_F24, "f24" }, { PT_F25, "f25" }, { PT_F26, "f26" },
2596 { PT_F27, "f27" }, { PT_F28, "f28" }, { PT_F29, "f29" },
2597 { PT_F30, "f30" }, { PT_F31, "f31" }, { PT_R4, "r4" },
2598 { PT_R5, "r5" }, { PT_R6, "r6" }, { PT_R7, "r7" },
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00002599 { PT_B1, "b1" }, { PT_B2, "b2" }, { PT_B3, "b3" },
2600 { PT_B4, "b4" }, { PT_B5, "b5" },
Roland McGrathca4e10c2004-01-13 10:13:20 +00002601 { PT_AR_EC, "ar.ec" }, { PT_AR_LC, "ar.lc" },
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00002602 /* pt_regs */
Roland McGrathca4e10c2004-01-13 10:13:20 +00002603 { PT_CR_IPSR, "psr" }, { PT_CR_IIP, "ip" },
2604 { PT_CFM, "cfm" }, { PT_AR_UNAT, "ar.unat" },
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00002605 { PT_AR_PFS, "ar.pfs" }, { PT_AR_RSC, "ar.rsc" },
2606 { PT_AR_RNAT, "ar.rnat" }, { PT_AR_BSPSTORE, "ar.bspstore" },
2607 { PT_PR, "pr" }, { PT_B6, "b6" }, { PT_AR_BSP, "ar.bsp" },
2608 { PT_R1, "r1" }, { PT_R2, "r2" }, { PT_R3, "r3" },
2609 { PT_R12, "r12" }, { PT_R13, "r13" }, { PT_R14, "r14" },
2610 { PT_R15, "r15" }, { PT_R8, "r8" }, { PT_R9, "r9" },
2611 { PT_R10, "r10" }, { PT_R11, "r11" }, { PT_R16, "r16" },
2612 { PT_R17, "r17" }, { PT_R18, "r18" }, { PT_R19, "r19" },
2613 { PT_R20, "r20" }, { PT_R21, "r21" }, { PT_R22, "r22" },
2614 { PT_R23, "r23" }, { PT_R24, "r24" }, { PT_R25, "r25" },
2615 { PT_R26, "r26" }, { PT_R27, "r27" }, { PT_R28, "r28" },
2616 { PT_R29, "r29" }, { PT_R30, "r30" }, { PT_R31, "r31" },
2617 { PT_AR_CCV, "ar.ccv" }, { PT_AR_FPSR, "ar.fpsr" },
2618 { PT_B0, "b0" }, { PT_B7, "b7" }, { PT_F6, "f6" },
2619 { PT_F7, "f7" }, { PT_F8, "f8" }, { PT_F9, "f9" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002620# ifdef PT_AR_CSD
Roland McGrathfb1bc072004-03-01 21:29:24 +00002621 { PT_AR_CSD, "ar.csd" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002622# endif
2623# ifdef PT_AR_SSD
Roland McGrathfb1bc072004-03-01 21:29:24 +00002624 { PT_AR_SSD, "ar.ssd" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002625# endif
Roland McGrathca4e10c2004-01-13 10:13:20 +00002626 { PT_DBR, "dbr" }, { PT_IBR, "ibr" }, { PT_PMD, "pmd" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002627# elif defined(I386)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002628 { 4*EBX, "4*EBX" },
2629 { 4*ECX, "4*ECX" },
2630 { 4*EDX, "4*EDX" },
2631 { 4*ESI, "4*ESI" },
2632 { 4*EDI, "4*EDI" },
2633 { 4*EBP, "4*EBP" },
2634 { 4*EAX, "4*EAX" },
2635 { 4*DS, "4*DS" },
2636 { 4*ES, "4*ES" },
2637 { 4*FS, "4*FS" },
2638 { 4*GS, "4*GS" },
2639 { 4*ORIG_EAX, "4*ORIG_EAX" },
2640 { 4*EIP, "4*EIP" },
2641 { 4*CS, "4*CS" },
2642 { 4*EFL, "4*EFL" },
2643 { 4*UESP, "4*UESP" },
2644 { 4*SS, "4*SS" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002645# elif defined(X86_64)
Roland McGratha4f9f2d2005-06-07 23:21:20 +00002646 { 8*R15, "8*R15" },
2647 { 8*R14, "8*R14" },
2648 { 8*R13, "8*R13" },
2649 { 8*R12, "8*R12" },
Michal Ludvig0e035502002-09-23 15:41:01 +00002650 { 8*RBP, "8*RBP" },
Roland McGratha4f9f2d2005-06-07 23:21:20 +00002651 { 8*RBX, "8*RBX" },
2652 { 8*R11, "8*R11" },
2653 { 8*R10, "8*R10" },
2654 { 8*R9, "8*R9" },
2655 { 8*R8, "8*R8" },
Michal Ludvig0e035502002-09-23 15:41:01 +00002656 { 8*RAX, "8*RAX" },
Roland McGratha4f9f2d2005-06-07 23:21:20 +00002657 { 8*RCX, "8*RCX" },
2658 { 8*RDX, "8*RDX" },
2659 { 8*RSI, "8*RSI" },
2660 { 8*RDI, "8*RDI" },
Roland McGratha4f9f2d2005-06-07 23:21:20 +00002661 { 8*ORIG_RAX, "8*ORIG_RAX" },
Michal Ludvig0e035502002-09-23 15:41:01 +00002662 { 8*RIP, "8*RIP" },
2663 { 8*CS, "8*CS" },
2664 { 8*EFLAGS, "8*EFL" },
Roland McGratha4f9f2d2005-06-07 23:21:20 +00002665 { 8*RSP, "8*RSP" },
Michal Ludvig0e035502002-09-23 15:41:01 +00002666 { 8*SS, "8*SS" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002667# elif defined(M68K)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002668 { 4*PT_D1, "4*PT_D1" },
2669 { 4*PT_D2, "4*PT_D2" },
2670 { 4*PT_D3, "4*PT_D3" },
2671 { 4*PT_D4, "4*PT_D4" },
2672 { 4*PT_D5, "4*PT_D5" },
2673 { 4*PT_D6, "4*PT_D6" },
2674 { 4*PT_D7, "4*PT_D7" },
2675 { 4*PT_A0, "4*PT_A0" },
2676 { 4*PT_A1, "4*PT_A1" },
2677 { 4*PT_A2, "4*PT_A2" },
2678 { 4*PT_A3, "4*PT_A3" },
2679 { 4*PT_A4, "4*PT_A4" },
2680 { 4*PT_A5, "4*PT_A5" },
2681 { 4*PT_A6, "4*PT_A6" },
2682 { 4*PT_D0, "4*PT_D0" },
2683 { 4*PT_USP, "4*PT_USP" },
2684 { 4*PT_ORIG_D0, "4*PT_ORIG_D0" },
2685 { 4*PT_SR, "4*PT_SR" },
2686 { 4*PT_PC, "4*PT_PC" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002687# elif defined(SH)
Denys Vlasenkoadedb512008-12-30 18:47:55 +00002688 { 4*REG_REG0, "4*REG_REG0" },
2689 { 4*(REG_REG0+1), "4*REG_REG1" },
2690 { 4*(REG_REG0+2), "4*REG_REG2" },
2691 { 4*(REG_REG0+3), "4*REG_REG3" },
2692 { 4*(REG_REG0+4), "4*REG_REG4" },
2693 { 4*(REG_REG0+5), "4*REG_REG5" },
2694 { 4*(REG_REG0+6), "4*REG_REG6" },
2695 { 4*(REG_REG0+7), "4*REG_REG7" },
2696 { 4*(REG_REG0+8), "4*REG_REG8" },
2697 { 4*(REG_REG0+9), "4*REG_REG9" },
2698 { 4*(REG_REG0+10), "4*REG_REG10" },
2699 { 4*(REG_REG0+11), "4*REG_REG11" },
2700 { 4*(REG_REG0+12), "4*REG_REG12" },
2701 { 4*(REG_REG0+13), "4*REG_REG13" },
2702 { 4*(REG_REG0+14), "4*REG_REG14" },
2703 { 4*REG_REG15, "4*REG_REG15" },
2704 { 4*REG_PC, "4*REG_PC" },
2705 { 4*REG_PR, "4*REG_PR" },
2706 { 4*REG_SR, "4*REG_SR" },
2707 { 4*REG_GBR, "4*REG_GBR" },
2708 { 4*REG_MACH, "4*REG_MACH" },
2709 { 4*REG_MACL, "4*REG_MACL" },
2710 { 4*REG_SYSCALL, "4*REG_SYSCALL" },
2711 { 4*REG_FPUL, "4*REG_FPUL" },
2712 { 4*REG_FPREG0, "4*REG_FPREG0" },
2713 { 4*(REG_FPREG0+1), "4*REG_FPREG1" },
2714 { 4*(REG_FPREG0+2), "4*REG_FPREG2" },
2715 { 4*(REG_FPREG0+3), "4*REG_FPREG3" },
2716 { 4*(REG_FPREG0+4), "4*REG_FPREG4" },
2717 { 4*(REG_FPREG0+5), "4*REG_FPREG5" },
2718 { 4*(REG_FPREG0+6), "4*REG_FPREG6" },
2719 { 4*(REG_FPREG0+7), "4*REG_FPREG7" },
2720 { 4*(REG_FPREG0+8), "4*REG_FPREG8" },
2721 { 4*(REG_FPREG0+9), "4*REG_FPREG9" },
2722 { 4*(REG_FPREG0+10), "4*REG_FPREG10" },
2723 { 4*(REG_FPREG0+11), "4*REG_FPREG11" },
2724 { 4*(REG_FPREG0+12), "4*REG_FPREG12" },
2725 { 4*(REG_FPREG0+13), "4*REG_FPREG13" },
2726 { 4*(REG_FPREG0+14), "4*REG_FPREG14" },
2727 { 4*REG_FPREG15, "4*REG_FPREG15" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002728# ifdef REG_XDREG0
Denys Vlasenkoadedb512008-12-30 18:47:55 +00002729 { 4*REG_XDREG0, "4*REG_XDREG0" },
2730 { 4*(REG_XDREG0+2), "4*REG_XDREG2" },
2731 { 4*(REG_XDREG0+4), "4*REG_XDREG4" },
2732 { 4*(REG_XDREG0+6), "4*REG_XDREG6" },
2733 { 4*(REG_XDREG0+8), "4*REG_XDREG8" },
2734 { 4*(REG_XDREG0+10), "4*REG_XDREG10" },
2735 { 4*(REG_XDREG0+12), "4*REG_XDREG12" },
2736 { 4*REG_XDREG14, "4*REG_XDREG14" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002737# endif
Denys Vlasenkoadedb512008-12-30 18:47:55 +00002738 { 4*REG_FPSCR, "4*REG_FPSCR" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002739# elif defined(SH64)
Roland McGrathe1e584b2003-06-02 19:18:58 +00002740 { 0, "PC(L)" },
2741 { 4, "PC(U)" },
2742 { 8, "SR(L)" },
2743 { 12, "SR(U)" },
2744 { 16, "syscall no.(L)" },
2745 { 20, "syscall_no.(U)" },
2746 { 24, "R0(L)" },
2747 { 28, "R0(U)" },
2748 { 32, "R1(L)" },
2749 { 36, "R1(U)" },
2750 { 40, "R2(L)" },
2751 { 44, "R2(U)" },
2752 { 48, "R3(L)" },
2753 { 52, "R3(U)" },
2754 { 56, "R4(L)" },
2755 { 60, "R4(U)" },
2756 { 64, "R5(L)" },
2757 { 68, "R5(U)" },
2758 { 72, "R6(L)" },
2759 { 76, "R6(U)" },
2760 { 80, "R7(L)" },
2761 { 84, "R7(U)" },
2762 { 88, "R8(L)" },
2763 { 92, "R8(U)" },
2764 { 96, "R9(L)" },
2765 { 100, "R9(U)" },
2766 { 104, "R10(L)" },
2767 { 108, "R10(U)" },
2768 { 112, "R11(L)" },
2769 { 116, "R11(U)" },
2770 { 120, "R12(L)" },
2771 { 124, "R12(U)" },
2772 { 128, "R13(L)" },
2773 { 132, "R13(U)" },
2774 { 136, "R14(L)" },
2775 { 140, "R14(U)" },
2776 { 144, "R15(L)" },
2777 { 148, "R15(U)" },
2778 { 152, "R16(L)" },
2779 { 156, "R16(U)" },
2780 { 160, "R17(L)" },
2781 { 164, "R17(U)" },
2782 { 168, "R18(L)" },
2783 { 172, "R18(U)" },
2784 { 176, "R19(L)" },
2785 { 180, "R19(U)" },
2786 { 184, "R20(L)" },
2787 { 188, "R20(U)" },
2788 { 192, "R21(L)" },
2789 { 196, "R21(U)" },
2790 { 200, "R22(L)" },
2791 { 204, "R22(U)" },
2792 { 208, "R23(L)" },
2793 { 212, "R23(U)" },
2794 { 216, "R24(L)" },
2795 { 220, "R24(U)" },
2796 { 224, "R25(L)" },
2797 { 228, "R25(U)" },
2798 { 232, "R26(L)" },
2799 { 236, "R26(U)" },
2800 { 240, "R27(L)" },
2801 { 244, "R27(U)" },
2802 { 248, "R28(L)" },
2803 { 252, "R28(U)" },
2804 { 256, "R29(L)" },
2805 { 260, "R29(U)" },
2806 { 264, "R30(L)" },
2807 { 268, "R30(U)" },
2808 { 272, "R31(L)" },
2809 { 276, "R31(U)" },
2810 { 280, "R32(L)" },
2811 { 284, "R32(U)" },
2812 { 288, "R33(L)" },
2813 { 292, "R33(U)" },
2814 { 296, "R34(L)" },
2815 { 300, "R34(U)" },
2816 { 304, "R35(L)" },
2817 { 308, "R35(U)" },
2818 { 312, "R36(L)" },
2819 { 316, "R36(U)" },
2820 { 320, "R37(L)" },
2821 { 324, "R37(U)" },
2822 { 328, "R38(L)" },
2823 { 332, "R38(U)" },
2824 { 336, "R39(L)" },
2825 { 340, "R39(U)" },
2826 { 344, "R40(L)" },
2827 { 348, "R40(U)" },
2828 { 352, "R41(L)" },
2829 { 356, "R41(U)" },
2830 { 360, "R42(L)" },
2831 { 364, "R42(U)" },
2832 { 368, "R43(L)" },
2833 { 372, "R43(U)" },
2834 { 376, "R44(L)" },
2835 { 380, "R44(U)" },
2836 { 384, "R45(L)" },
2837 { 388, "R45(U)" },
2838 { 392, "R46(L)" },
2839 { 396, "R46(U)" },
2840 { 400, "R47(L)" },
2841 { 404, "R47(U)" },
2842 { 408, "R48(L)" },
2843 { 412, "R48(U)" },
2844 { 416, "R49(L)" },
2845 { 420, "R49(U)" },
2846 { 424, "R50(L)" },
2847 { 428, "R50(U)" },
2848 { 432, "R51(L)" },
2849 { 436, "R51(U)" },
2850 { 440, "R52(L)" },
2851 { 444, "R52(U)" },
2852 { 448, "R53(L)" },
2853 { 452, "R53(U)" },
2854 { 456, "R54(L)" },
2855 { 460, "R54(U)" },
2856 { 464, "R55(L)" },
2857 { 468, "R55(U)" },
2858 { 472, "R56(L)" },
2859 { 476, "R56(U)" },
2860 { 480, "R57(L)" },
2861 { 484, "R57(U)" },
2862 { 488, "R58(L)" },
2863 { 492, "R58(U)" },
2864 { 496, "R59(L)" },
2865 { 500, "R59(U)" },
2866 { 504, "R60(L)" },
2867 { 508, "R60(U)" },
2868 { 512, "R61(L)" },
2869 { 516, "R61(U)" },
2870 { 520, "R62(L)" },
2871 { 524, "R62(U)" },
2872 { 528, "TR0(L)" },
2873 { 532, "TR0(U)" },
2874 { 536, "TR1(L)" },
2875 { 540, "TR1(U)" },
2876 { 544, "TR2(L)" },
2877 { 548, "TR2(U)" },
2878 { 552, "TR3(L)" },
2879 { 556, "TR3(U)" },
2880 { 560, "TR4(L)" },
2881 { 564, "TR4(U)" },
2882 { 568, "TR5(L)" },
2883 { 572, "TR5(U)" },
2884 { 576, "TR6(L)" },
2885 { 580, "TR6(U)" },
2886 { 584, "TR7(L)" },
2887 { 588, "TR7(U)" },
Denys Vlasenkoadedb512008-12-30 18:47:55 +00002888 /* This entry is in case pt_regs contains dregs (depends on
2889 the kernel build options). */
Roland McGrathe1e584b2003-06-02 19:18:58 +00002890 { uoff(regs), "offsetof(struct user, regs)" },
2891 { uoff(fpu), "offsetof(struct user, fpu)" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002892# elif defined(ARM)
Roland McGrath0f87c492003-06-03 23:29:04 +00002893 { uoff(regs.ARM_r0), "r0" },
2894 { uoff(regs.ARM_r1), "r1" },
2895 { uoff(regs.ARM_r2), "r2" },
2896 { uoff(regs.ARM_r3), "r3" },
2897 { uoff(regs.ARM_r4), "r4" },
2898 { uoff(regs.ARM_r5), "r5" },
2899 { uoff(regs.ARM_r6), "r6" },
2900 { uoff(regs.ARM_r7), "r7" },
2901 { uoff(regs.ARM_r8), "r8" },
2902 { uoff(regs.ARM_r9), "r9" },
2903 { uoff(regs.ARM_r10), "r10" },
2904 { uoff(regs.ARM_fp), "fp" },
2905 { uoff(regs.ARM_ip), "ip" },
2906 { uoff(regs.ARM_sp), "sp" },
2907 { uoff(regs.ARM_lr), "lr" },
2908 { uoff(regs.ARM_pc), "pc" },
2909 { uoff(regs.ARM_cpsr), "cpsr" },
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +00002910# elif defined(AVR32)
2911 { uoff(regs.sr), "sr" },
2912 { uoff(regs.pc), "pc" },
2913 { uoff(regs.lr), "lr" },
2914 { uoff(regs.sp), "sp" },
2915 { uoff(regs.r12), "r12" },
2916 { uoff(regs.r11), "r11" },
2917 { uoff(regs.r10), "r10" },
2918 { uoff(regs.r9), "r9" },
2919 { uoff(regs.r8), "r8" },
2920 { uoff(regs.r7), "r7" },
2921 { uoff(regs.r6), "r6" },
2922 { uoff(regs.r5), "r5" },
2923 { uoff(regs.r4), "r4" },
2924 { uoff(regs.r3), "r3" },
2925 { uoff(regs.r2), "r2" },
2926 { uoff(regs.r1), "r1" },
2927 { uoff(regs.r0), "r0" },
2928 { uoff(regs.r12_orig), "orig_r12" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002929# elif defined(MIPS)
Roland McGrath542c2c62008-05-20 01:11:56 +00002930 { 0, "r0" },
2931 { 1, "r1" },
2932 { 2, "r2" },
2933 { 3, "r3" },
2934 { 4, "r4" },
2935 { 5, "r5" },
2936 { 6, "r6" },
2937 { 7, "r7" },
2938 { 8, "r8" },
2939 { 9, "r9" },
2940 { 10, "r10" },
2941 { 11, "r11" },
2942 { 12, "r12" },
2943 { 13, "r13" },
2944 { 14, "r14" },
2945 { 15, "r15" },
2946 { 16, "r16" },
2947 { 17, "r17" },
2948 { 18, "r18" },
2949 { 19, "r19" },
2950 { 20, "r20" },
2951 { 21, "r21" },
2952 { 22, "r22" },
2953 { 23, "r23" },
2954 { 24, "r24" },
2955 { 25, "r25" },
2956 { 26, "r26" },
2957 { 27, "r27" },
2958 { 28, "r28" },
2959 { 29, "r29" },
2960 { 30, "r30" },
2961 { 31, "r31" },
2962 { 32, "f0" },
2963 { 33, "f1" },
2964 { 34, "f2" },
2965 { 35, "f3" },
2966 { 36, "f4" },
2967 { 37, "f5" },
2968 { 38, "f6" },
2969 { 39, "f7" },
2970 { 40, "f8" },
2971 { 41, "f9" },
2972 { 42, "f10" },
2973 { 43, "f11" },
2974 { 44, "f12" },
2975 { 45, "f13" },
2976 { 46, "f14" },
2977 { 47, "f15" },
2978 { 48, "f16" },
2979 { 49, "f17" },
2980 { 50, "f18" },
2981 { 51, "f19" },
2982 { 52, "f20" },
2983 { 53, "f21" },
2984 { 54, "f22" },
2985 { 55, "f23" },
2986 { 56, "f24" },
2987 { 57, "f25" },
2988 { 58, "f26" },
2989 { 59, "f27" },
2990 { 60, "f28" },
2991 { 61, "f29" },
2992 { 62, "f30" },
2993 { 63, "f31" },
2994 { 64, "pc" },
2995 { 65, "cause" },
2996 { 66, "badvaddr" },
2997 { 67, "mmhi" },
2998 { 68, "mmlo" },
2999 { 69, "fpcsr" },
3000 { 70, "fpeir" },
Chris Metcalfc8c66982009-12-28 10:00:15 -05003001# elif defined(TILE)
3002 { PTREGS_OFFSET_REG(0), "r0" },
3003 { PTREGS_OFFSET_REG(1), "r1" },
3004 { PTREGS_OFFSET_REG(2), "r2" },
3005 { PTREGS_OFFSET_REG(3), "r3" },
3006 { PTREGS_OFFSET_REG(4), "r4" },
3007 { PTREGS_OFFSET_REG(5), "r5" },
3008 { PTREGS_OFFSET_REG(6), "r6" },
3009 { PTREGS_OFFSET_REG(7), "r7" },
3010 { PTREGS_OFFSET_REG(8), "r8" },
3011 { PTREGS_OFFSET_REG(9), "r9" },
3012 { PTREGS_OFFSET_REG(10), "r10" },
3013 { PTREGS_OFFSET_REG(11), "r11" },
3014 { PTREGS_OFFSET_REG(12), "r12" },
3015 { PTREGS_OFFSET_REG(13), "r13" },
3016 { PTREGS_OFFSET_REG(14), "r14" },
3017 { PTREGS_OFFSET_REG(15), "r15" },
3018 { PTREGS_OFFSET_REG(16), "r16" },
3019 { PTREGS_OFFSET_REG(17), "r17" },
3020 { PTREGS_OFFSET_REG(18), "r18" },
3021 { PTREGS_OFFSET_REG(19), "r19" },
3022 { PTREGS_OFFSET_REG(20), "r20" },
3023 { PTREGS_OFFSET_REG(21), "r21" },
3024 { PTREGS_OFFSET_REG(22), "r22" },
3025 { PTREGS_OFFSET_REG(23), "r23" },
3026 { PTREGS_OFFSET_REG(24), "r24" },
3027 { PTREGS_OFFSET_REG(25), "r25" },
3028 { PTREGS_OFFSET_REG(26), "r26" },
3029 { PTREGS_OFFSET_REG(27), "r27" },
3030 { PTREGS_OFFSET_REG(28), "r28" },
3031 { PTREGS_OFFSET_REG(29), "r29" },
3032 { PTREGS_OFFSET_REG(30), "r30" },
3033 { PTREGS_OFFSET_REG(31), "r31" },
3034 { PTREGS_OFFSET_REG(32), "r32" },
3035 { PTREGS_OFFSET_REG(33), "r33" },
3036 { PTREGS_OFFSET_REG(34), "r34" },
3037 { PTREGS_OFFSET_REG(35), "r35" },
3038 { PTREGS_OFFSET_REG(36), "r36" },
3039 { PTREGS_OFFSET_REG(37), "r37" },
3040 { PTREGS_OFFSET_REG(38), "r38" },
3041 { PTREGS_OFFSET_REG(39), "r39" },
3042 { PTREGS_OFFSET_REG(40), "r40" },
3043 { PTREGS_OFFSET_REG(41), "r41" },
3044 { PTREGS_OFFSET_REG(42), "r42" },
3045 { PTREGS_OFFSET_REG(43), "r43" },
3046 { PTREGS_OFFSET_REG(44), "r44" },
3047 { PTREGS_OFFSET_REG(45), "r45" },
3048 { PTREGS_OFFSET_REG(46), "r46" },
3049 { PTREGS_OFFSET_REG(47), "r47" },
3050 { PTREGS_OFFSET_REG(48), "r48" },
3051 { PTREGS_OFFSET_REG(49), "r49" },
3052 { PTREGS_OFFSET_REG(50), "r50" },
3053 { PTREGS_OFFSET_REG(51), "r51" },
3054 { PTREGS_OFFSET_REG(52), "r52" },
3055 { PTREGS_OFFSET_TP, "tp" },
3056 { PTREGS_OFFSET_SP, "sp" },
3057 { PTREGS_OFFSET_LR, "lr" },
3058 { PTREGS_OFFSET_PC, "pc" },
3059 { PTREGS_OFFSET_EX1, "ex1" },
3060 { PTREGS_OFFSET_FAULTNUM, "faultnum" },
3061 { PTREGS_OFFSET_ORIG_R0, "orig_r0" },
3062 { PTREGS_OFFSET_FLAGS, "flags" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003063# endif
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00003064# ifdef CRISV10
3065 { 4*PT_FRAMETYPE, "4*PT_FRAMETYPE" },
3066 { 4*PT_ORIG_R10, "4*PT_ORIG_R10" },
3067 { 4*PT_R13, "4*PT_R13" },
3068 { 4*PT_R12, "4*PT_R12" },
3069 { 4*PT_R11, "4*PT_R11" },
3070 { 4*PT_R10, "4*PT_R10" },
3071 { 4*PT_R9, "4*PT_R9" },
3072 { 4*PT_R8, "4*PT_R8" },
3073 { 4*PT_R7, "4*PT_R7" },
3074 { 4*PT_R6, "4*PT_R6" },
3075 { 4*PT_R5, "4*PT_R5" },
3076 { 4*PT_R4, "4*PT_R4" },
3077 { 4*PT_R3, "4*PT_R3" },
3078 { 4*PT_R2, "4*PT_R2" },
3079 { 4*PT_R1, "4*PT_R1" },
3080 { 4*PT_R0, "4*PT_R0" },
3081 { 4*PT_MOF, "4*PT_MOF" },
3082 { 4*PT_DCCR, "4*PT_DCCR" },
3083 { 4*PT_SRP, "4*PT_SRP" },
3084 { 4*PT_IRP, "4*PT_IRP" },
3085 { 4*PT_CSRINSTR, "4*PT_CSRINSTR" },
3086 { 4*PT_CSRADDR, "4*PT_CSRADDR" },
3087 { 4*PT_CSRDATA, "4*PT_CSRDATA" },
3088 { 4*PT_USP, "4*PT_USP" },
3089# endif
3090# ifdef CRISV32
3091 { 4*PT_ORIG_R10, "4*PT_ORIG_R10" },
3092 { 4*PT_R0, "4*PT_R0" },
3093 { 4*PT_R1, "4*PT_R1" },
3094 { 4*PT_R2, "4*PT_R2" },
3095 { 4*PT_R3, "4*PT_R3" },
3096 { 4*PT_R4, "4*PT_R4" },
3097 { 4*PT_R5, "4*PT_R5" },
3098 { 4*PT_R6, "4*PT_R6" },
3099 { 4*PT_R7, "4*PT_R7" },
3100 { 4*PT_R8, "4*PT_R8" },
3101 { 4*PT_R9, "4*PT_R9" },
3102 { 4*PT_R10, "4*PT_R10" },
3103 { 4*PT_R11, "4*PT_R11" },
3104 { 4*PT_R12, "4*PT_R12" },
3105 { 4*PT_R13, "4*PT_R13" },
3106 { 4*PT_ACR, "4*PT_ACR" },
3107 { 4*PT_SRS, "4*PT_SRS" },
3108 { 4*PT_MOF, "4*PT_MOF" },
3109 { 4*PT_SPC, "4*PT_SPC" },
3110 { 4*PT_CCS, "4*PT_CCS" },
3111 { 4*PT_SRP, "4*PT_SRP" },
3112 { 4*PT_ERP, "4*PT_ERP" },
3113 { 4*PT_EXS, "4*PT_EXS" },
3114 { 4*PT_EDA, "4*PT_EDA" },
3115 { 4*PT_USP, "4*PT_USP" },
3116 { 4*PT_PPC, "4*PT_PPC" },
3117 { 4*PT_BP_CTRL, "4*PT_BP_CTRL" },
3118 { 4*PT_BP+4, "4*PT_BP+4" },
3119 { 4*PT_BP+8, "4*PT_BP+8" },
3120 { 4*PT_BP+12, "4*PT_BP+12" },
3121 { 4*PT_BP+16, "4*PT_BP+16" },
3122 { 4*PT_BP+20, "4*PT_BP+20" },
3123 { 4*PT_BP+24, "4*PT_BP+24" },
3124 { 4*PT_BP+28, "4*PT_BP+28" },
3125 { 4*PT_BP+32, "4*PT_BP+32" },
3126 { 4*PT_BP+36, "4*PT_BP+36" },
3127 { 4*PT_BP+40, "4*PT_BP+40" },
3128 { 4*PT_BP+44, "4*PT_BP+44" },
3129 { 4*PT_BP+48, "4*PT_BP+48" },
3130 { 4*PT_BP+52, "4*PT_BP+52" },
3131 { 4*PT_BP+56, "4*PT_BP+56" },
3132# endif
Edgar E. Iglesias939caba2010-07-06 14:21:07 +02003133# ifdef MICROBLAZE
3134 { PT_GPR(0), "r0" },
3135 { PT_GPR(1), "r1" },
3136 { PT_GPR(2), "r2" },
3137 { PT_GPR(3), "r3" },
3138 { PT_GPR(4), "r4" },
3139 { PT_GPR(5), "r5" },
3140 { PT_GPR(6), "r6" },
3141 { PT_GPR(7), "r7" },
3142 { PT_GPR(8), "r8" },
3143 { PT_GPR(9), "r9" },
3144 { PT_GPR(10), "r10" },
3145 { PT_GPR(11), "r11" },
3146 { PT_GPR(12), "r12" },
3147 { PT_GPR(13), "r13" },
3148 { PT_GPR(14), "r14" },
3149 { PT_GPR(15), "r15" },
3150 { PT_GPR(16), "r16" },
3151 { PT_GPR(17), "r17" },
3152 { PT_GPR(18), "r18" },
3153 { PT_GPR(19), "r19" },
3154 { PT_GPR(20), "r20" },
3155 { PT_GPR(21), "r21" },
3156 { PT_GPR(22), "r22" },
3157 { PT_GPR(23), "r23" },
3158 { PT_GPR(24), "r24" },
3159 { PT_GPR(25), "r25" },
3160 { PT_GPR(26), "r26" },
3161 { PT_GPR(27), "r27" },
3162 { PT_GPR(28), "r28" },
3163 { PT_GPR(29), "r29" },
3164 { PT_GPR(30), "r30" },
3165 { PT_GPR(31), "r31" },
3166 { PT_PC, "rpc", },
3167 { PT_MSR, "rmsr", },
3168 { PT_EAR, "rear", },
3169 { PT_ESR, "resr", },
3170 { PT_FSR, "rfsr", },
3171 { PT_KERNEL_MODE, "kernel_mode", },
3172# endif
Roland McGrath542c2c62008-05-20 01:11:56 +00003173
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00003174# if !defined(SPARC) && !defined(HPPA) && !defined(POWERPC) \
3175 && !defined(ALPHA) && !defined(IA64) \
Edgar E. Iglesias939caba2010-07-06 14:21:07 +02003176 && !defined(CRISV10) && !defined(CRISV32) && !defined(MICROBLAZE)
Chris Metcalfc8c66982009-12-28 10:00:15 -05003177# if !defined(S390) && !defined(S390X) && !defined(MIPS) && !defined(SPARC64) && !defined(AVR32) && !defined(BFIN) && !defined(TILE)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003178 { uoff(u_fpvalid), "offsetof(struct user, u_fpvalid)" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003179# endif
3180# if defined(I386) || defined(X86_64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003181 { uoff(i387), "offsetof(struct user, i387)" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003182# endif
3183# if defined(M68K)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003184 { uoff(m68kfp), "offsetof(struct user, m68kfp)" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003185# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003186 { uoff(u_tsize), "offsetof(struct user, u_tsize)" },
3187 { uoff(u_dsize), "offsetof(struct user, u_dsize)" },
3188 { uoff(u_ssize), "offsetof(struct user, u_ssize)" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003189# if !defined(SPARC64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003190 { uoff(start_code), "offsetof(struct user, start_code)" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003191# endif
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +00003192# if defined(AVR32) || defined(SH64)
Roland McGrathe1e584b2003-06-02 19:18:58 +00003193 { uoff(start_data), "offsetof(struct user, start_data)" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003194# endif
3195# if !defined(SPARC64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003196 { uoff(start_stack), "offsetof(struct user, start_stack)" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003197# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003198 { uoff(signal), "offsetof(struct user, signal)" },
Chris Metcalfc8c66982009-12-28 10:00:15 -05003199# if !defined(AVR32) && !defined(S390) && !defined(S390X) && !defined(MIPS) && !defined(SH) && !defined(SH64) && !defined(SPARC64) && !defined(TILE)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003200 { uoff(reserved), "offsetof(struct user, reserved)" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003201# endif
3202# if !defined(SPARC64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003203 { uoff(u_ar0), "offsetof(struct user, u_ar0)" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003204# endif
Chris Metcalfc8c66982009-12-28 10:00:15 -05003205# if !defined(ARM) && !defined(AVR32) && !defined(MIPS) && !defined(S390) && !defined(S390X) && !defined(SPARC64) && !defined(BFIN) && !defined(TILE)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003206 { uoff(u_fpstate), "offsetof(struct user, u_fpstate)" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003207# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003208 { uoff(magic), "offsetof(struct user, magic)" },
3209 { uoff(u_comm), "offsetof(struct user, u_comm)" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003210# if defined(I386) || defined(X86_64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003211 { uoff(u_debugreg), "offsetof(struct user, u_debugreg)" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003212# endif
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00003213# endif /* !defined(many arches) */
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003214
3215# endif /* LINUX */
3216
3217# ifdef SUNOS4
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003218 { uoff(u_pcb), "offsetof(struct user, u_pcb)" },
3219 { uoff(u_procp), "offsetof(struct user, u_procp)" },
3220 { uoff(u_ar0), "offsetof(struct user, u_ar0)" },
3221 { uoff(u_comm[0]), "offsetof(struct user, u_comm[0])" },
3222 { uoff(u_arg[0]), "offsetof(struct user, u_arg[0])" },
3223 { uoff(u_ap), "offsetof(struct user, u_ap)" },
3224 { uoff(u_qsave), "offsetof(struct user, u_qsave)" },
3225 { uoff(u_rval1), "offsetof(struct user, u_rval1)" },
3226 { uoff(u_rval2), "offsetof(struct user, u_rval2)" },
3227 { uoff(u_error), "offsetof(struct user, u_error)" },
3228 { uoff(u_eosys), "offsetof(struct user, u_eosys)" },
3229 { uoff(u_ssave), "offsetof(struct user, u_ssave)" },
3230 { uoff(u_signal[0]), "offsetof(struct user, u_signal)" },
3231 { uoff(u_sigmask[0]), "offsetof(struct user, u_sigmask)" },
3232 { uoff(u_sigonstack), "offsetof(struct user, u_sigonstack)" },
3233 { uoff(u_sigintr), "offsetof(struct user, u_sigintr)" },
3234 { uoff(u_sigreset), "offsetof(struct user, u_sigreset)" },
3235 { uoff(u_oldmask), "offsetof(struct user, u_oldmask)" },
3236 { uoff(u_code), "offsetof(struct user, u_code)" },
3237 { uoff(u_addr), "offsetof(struct user, u_addr)" },
3238 { uoff(u_sigstack), "offsetof(struct user, u_sigstack)" },
3239 { uoff(u_ofile), "offsetof(struct user, u_ofile)" },
3240 { uoff(u_pofile), "offsetof(struct user, u_pofile)" },
3241 { uoff(u_ofile_arr[0]), "offsetof(struct user, u_ofile_arr[0])" },
3242 { uoff(u_pofile_arr[0]),"offsetof(struct user, u_pofile_arr[0])"},
3243 { uoff(u_lastfile), "offsetof(struct user, u_lastfile)" },
3244 { uoff(u_cwd), "offsetof(struct user, u_cwd)" },
3245 { uoff(u_cdir), "offsetof(struct user, u_cdir)" },
3246 { uoff(u_rdir), "offsetof(struct user, u_rdir)" },
3247 { uoff(u_cmask), "offsetof(struct user, u_cmask)" },
3248 { uoff(u_ru), "offsetof(struct user, u_ru)" },
3249 { uoff(u_cru), "offsetof(struct user, u_cru)" },
3250 { uoff(u_timer[0]), "offsetof(struct user, u_timer[0])" },
3251 { uoff(u_XXX[0]), "offsetof(struct user, u_XXX[0])" },
3252 { uoff(u_ioch), "offsetof(struct user, u_ioch)" },
3253 { uoff(u_start), "offsetof(struct user, u_start)" },
3254 { uoff(u_acflag), "offsetof(struct user, u_acflag)" },
3255 { uoff(u_prof.pr_base), "offsetof(struct user, u_prof.pr_base)" },
3256 { uoff(u_prof.pr_size), "offsetof(struct user, u_prof.pr_size)" },
3257 { uoff(u_prof.pr_off), "offsetof(struct user, u_prof.pr_off)" },
3258 { uoff(u_prof.pr_scale),"offsetof(struct user, u_prof.pr_scale)"},
3259 { uoff(u_rlimit[0]), "offsetof(struct user, u_rlimit)" },
3260 { uoff(u_exdata.Ux_A), "offsetof(struct user, u_exdata.Ux_A)" },
3261 { uoff(u_exdata.ux_shell[0]),"offsetof(struct user, u_exdata.ux_shell[0])"},
3262 { uoff(u_lofault), "offsetof(struct user, u_lofault)" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003263# endif /* SUNOS4 */
3264# ifndef HPPA
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003265 { sizeof(struct user), "sizeof(struct user)" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003266# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003267 { 0, NULL },
3268};
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003269# endif /* !FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003270
3271int
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003272sys_ptrace(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003273{
Roland McGrathd9f816f2004-09-04 03:39:20 +00003274 const struct xlat *x;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003275 long addr;
3276
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003277 if (entering(tcp)) {
Roland McGrathbf621d42003-01-14 09:46:21 +00003278 printxval(ptrace_cmds, tcp->u_arg[0],
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003279# ifndef FREEBSD
Roland McGrathbf621d42003-01-14 09:46:21 +00003280 "PTRACE_???"
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003281# else
Roland McGrathbf621d42003-01-14 09:46:21 +00003282 "PT_???"
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003283# endif
Roland McGrathbf621d42003-01-14 09:46:21 +00003284 );
3285 tprintf(", %lu, ", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003286 addr = tcp->u_arg[2];
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003287# ifndef FREEBSD
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003288 if (tcp->u_arg[0] == PTRACE_PEEKUSER
3289 || tcp->u_arg[0] == PTRACE_POKEUSER) {
3290 for (x = struct_user_offsets; x->str; x++) {
3291 if (x->val >= addr)
3292 break;
3293 }
3294 if (!x->str)
3295 tprintf("%#lx, ", addr);
3296 else if (x->val > addr && x != struct_user_offsets) {
3297 x--;
3298 tprintf("%s + %ld, ", x->str, addr - x->val);
3299 }
3300 else
3301 tprintf("%s, ", x->str);
3302 }
3303 else
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003304# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003305 tprintf("%#lx, ", tcp->u_arg[2]);
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003306# ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003307 switch (tcp->u_arg[0]) {
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003308# ifndef IA64
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003309 case PTRACE_PEEKDATA:
3310 case PTRACE_PEEKTEXT:
3311 case PTRACE_PEEKUSER:
3312 break;
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003313# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003314 case PTRACE_CONT:
3315 case PTRACE_SINGLESTEP:
3316 case PTRACE_SYSCALL:
3317 case PTRACE_DETACH:
3318 printsignal(tcp->u_arg[3]);
3319 break;
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003320# ifdef PTRACE_SETOPTIONS
Denys Vlasenkof535b542009-01-13 18:30:55 +00003321 case PTRACE_SETOPTIONS:
3322 printflags(ptrace_setoptions_flags, tcp->u_arg[3], "PTRACE_O_???");
3323 break;
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003324# endif
3325# ifdef PTRACE_SETSIGINFO
Denys Vlasenkof535b542009-01-13 18:30:55 +00003326 case PTRACE_SETSIGINFO: {
3327 siginfo_t si;
3328 if (!tcp->u_arg[3])
3329 tprintf("NULL");
3330 else if (syserror(tcp))
3331 tprintf("%#lx", tcp->u_arg[3]);
3332 else if (umove(tcp, tcp->u_arg[3], &si) < 0)
3333 tprintf("{???}");
3334 else
3335 printsiginfo(&si, verbose(tcp));
3336 break;
3337 }
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003338# endif
3339# ifdef PTRACE_GETSIGINFO
Denys Vlasenkof535b542009-01-13 18:30:55 +00003340 case PTRACE_GETSIGINFO:
3341 /* Don't print anything, do it at syscall return. */
3342 break;
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003343# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003344 default:
3345 tprintf("%#lx", tcp->u_arg[3]);
3346 break;
3347 }
3348 } else {
3349 switch (tcp->u_arg[0]) {
3350 case PTRACE_PEEKDATA:
3351 case PTRACE_PEEKTEXT:
3352 case PTRACE_PEEKUSER:
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003353# ifdef IA64
Roland McGrath1e868062007-11-19 22:11:45 +00003354 return RVAL_HEX;
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003355# else
Roland McGratheb285352003-01-14 09:59:00 +00003356 printnum(tcp, tcp->u_arg[3], "%#lx");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003357 break;
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003358# endif
3359# ifdef PTRACE_GETSIGINFO
Denys Vlasenkof535b542009-01-13 18:30:55 +00003360 case PTRACE_GETSIGINFO: {
3361 siginfo_t si;
3362 if (!tcp->u_arg[3])
3363 tprintf("NULL");
3364 else if (syserror(tcp))
3365 tprintf("%#lx", tcp->u_arg[3]);
3366 else if (umove(tcp, tcp->u_arg[3], &si) < 0)
3367 tprintf("{???}");
3368 else
3369 printsiginfo(&si, verbose(tcp));
3370 break;
3371 }
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003372# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003373 }
3374 }
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003375# endif /* LINUX */
3376# ifdef SUNOS4
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003377 if (tcp->u_arg[0] == PTRACE_WRITEDATA ||
3378 tcp->u_arg[0] == PTRACE_WRITETEXT) {
3379 tprintf("%lu, ", tcp->u_arg[3]);
3380 printstr(tcp, tcp->u_arg[4], tcp->u_arg[3]);
3381 } else if (tcp->u_arg[0] != PTRACE_READDATA &&
3382 tcp->u_arg[0] != PTRACE_READTEXT) {
3383 tprintf("%#lx", tcp->u_arg[3]);
3384 }
3385 } else {
3386 if (tcp->u_arg[0] == PTRACE_READDATA ||
3387 tcp->u_arg[0] == PTRACE_READTEXT) {
3388 tprintf("%lu, ", tcp->u_arg[3]);
3389 printstr(tcp, tcp->u_arg[4], tcp->u_arg[3]);
3390 }
3391 }
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003392# endif /* SUNOS4 */
3393# ifdef FREEBSD
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00003394 tprintf("%lu", tcp->u_arg[3]);
3395 }
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003396# endif /* FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003397 return 0;
3398}
3399
3400#endif /* !SVR4 */
Roland McGrath5a223472002-12-15 23:58:26 +00003401
3402#ifdef LINUX
Roland McGrath51942a92007-07-05 18:59:11 +00003403# ifndef FUTEX_CMP_REQUEUE
3404# define FUTEX_CMP_REQUEUE 4
3405# endif
3406# ifndef FUTEX_WAKE_OP
3407# define FUTEX_WAKE_OP 5
3408# endif
3409# ifndef FUTEX_LOCK_PI
3410# define FUTEX_LOCK_PI 6
3411# define FUTEX_UNLOCK_PI 7
3412# define FUTEX_TRYLOCK_PI 8
3413# endif
Roland McGrath1aeaf742008-07-18 01:27:39 +00003414# ifndef FUTEX_WAIT_BITSET
3415# define FUTEX_WAIT_BITSET 9
3416# endif
3417# ifndef FUTEX_WAKE_BITSET
3418# define FUTEX_WAKE_BITSET 10
Roland McGrath51942a92007-07-05 18:59:11 +00003419# endif
Andreas Schwab85f58322009-08-12 09:54:42 +02003420# ifndef FUTEX_WAIT_REQUEUE_PI
3421# define FUTEX_WAIT_REQUEUE_PI 11
3422# endif
3423# ifndef FUTEX_CMP_REQUEUE_PI
3424# define FUTEX_CMP_REQUEUE_PI 12
3425# endif
Roland McGrath51942a92007-07-05 18:59:11 +00003426# ifndef FUTEX_PRIVATE_FLAG
3427# define FUTEX_PRIVATE_FLAG 128
3428# endif
Andreas Schwab85f58322009-08-12 09:54:42 +02003429# ifndef FUTEX_CLOCK_REALTIME
3430# define FUTEX_CLOCK_REALTIME 256
3431# endif
Roland McGrathd9f816f2004-09-04 03:39:20 +00003432static const struct xlat futexops[] = {
Roland McGrath51942a92007-07-05 18:59:11 +00003433 { FUTEX_WAIT, "FUTEX_WAIT" },
3434 { FUTEX_WAKE, "FUTEX_WAKE" },
3435 { FUTEX_FD, "FUTEX_FD" },
3436 { FUTEX_REQUEUE, "FUTEX_REQUEUE" },
3437 { FUTEX_CMP_REQUEUE, "FUTEX_CMP_REQUEUE" },
3438 { FUTEX_WAKE_OP, "FUTEX_WAKE_OP" },
3439 { FUTEX_LOCK_PI, "FUTEX_LOCK_PI" },
3440 { FUTEX_UNLOCK_PI, "FUTEX_UNLOCK_PI" },
3441 { FUTEX_TRYLOCK_PI, "FUTEX_TRYLOCK_PI" },
Roland McGrath1aeaf742008-07-18 01:27:39 +00003442 { FUTEX_WAIT_BITSET, "FUTEX_WAIT_BITSET" },
3443 { FUTEX_WAKE_BITSET, "FUTEX_WAKE_BITSET" },
Andreas Schwab85f58322009-08-12 09:54:42 +02003444 { FUTEX_WAIT_REQUEUE_PI, "FUTEX_WAIT_REQUEUE_PI" },
3445 { FUTEX_CMP_REQUEUE_PI, "FUTEX_CMP_REQUEUE_PI" },
Roland McGrath51942a92007-07-05 18:59:11 +00003446 { FUTEX_WAIT|FUTEX_PRIVATE_FLAG, "FUTEX_WAIT_PRIVATE" },
3447 { FUTEX_WAKE|FUTEX_PRIVATE_FLAG, "FUTEX_WAKE_PRIVATE" },
3448 { FUTEX_FD|FUTEX_PRIVATE_FLAG, "FUTEX_FD_PRIVATE" },
3449 { FUTEX_REQUEUE|FUTEX_PRIVATE_FLAG, "FUTEX_REQUEUE_PRIVATE" },
3450 { FUTEX_CMP_REQUEUE|FUTEX_PRIVATE_FLAG, "FUTEX_CMP_REQUEUE_PRIVATE" },
3451 { FUTEX_WAKE_OP|FUTEX_PRIVATE_FLAG, "FUTEX_WAKE_OP_PRIVATE" },
3452 { FUTEX_LOCK_PI|FUTEX_PRIVATE_FLAG, "FUTEX_LOCK_PI_PRIVATE" },
3453 { FUTEX_UNLOCK_PI|FUTEX_PRIVATE_FLAG, "FUTEX_UNLOCK_PI_PRIVATE" },
3454 { FUTEX_TRYLOCK_PI|FUTEX_PRIVATE_FLAG, "FUTEX_TRYLOCK_PI_PRIVATE" },
Roland McGrath1aeaf742008-07-18 01:27:39 +00003455 { FUTEX_WAIT_BITSET|FUTEX_PRIVATE_FLAG, "FUTEX_WAIT_BITSET_PRIVATE" },
3456 { FUTEX_WAKE_BITSET|FUTEX_PRIVATE_FLAG, "FUTEX_WAKE_BITSET_PRIVATE" },
Andreas Schwab85f58322009-08-12 09:54:42 +02003457 { FUTEX_WAIT_REQUEUE_PI|FUTEX_PRIVATE_FLAG, "FUTEX_WAIT_REQUEUE_PI_PRIVATE" },
3458 { FUTEX_CMP_REQUEUE_PI|FUTEX_PRIVATE_FLAG, "FUTEX_CMP_REQUEUE_PI_PRIVATE" },
3459 { FUTEX_WAIT_BITSET|FUTEX_CLOCK_REALTIME, "FUTEX_WAIT_BITSET|FUTEX_CLOCK_REALTIME" },
3460 { FUTEX_WAIT_BITSET|FUTEX_PRIVATE_FLAG|FUTEX_CLOCK_REALTIME, "FUTEX_WAIT_BITSET_PRIVATE|FUTEX_CLOCK_REALTIME" },
3461 { FUTEX_WAIT_REQUEUE_PI|FUTEX_CLOCK_REALTIME, "FUTEX_WAIT_REQUEUE_PI|FUTEX_CLOCK_REALTIME" },
3462 { 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 +00003463 { 0, NULL }
3464};
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003465# ifndef FUTEX_OP_SET
3466# define FUTEX_OP_SET 0
3467# define FUTEX_OP_ADD 1
3468# define FUTEX_OP_OR 2
3469# define FUTEX_OP_ANDN 3
3470# define FUTEX_OP_XOR 4
3471# define FUTEX_OP_CMP_EQ 0
3472# define FUTEX_OP_CMP_NE 1
3473# define FUTEX_OP_CMP_LT 2
3474# define FUTEX_OP_CMP_LE 3
3475# define FUTEX_OP_CMP_GT 4
3476# define FUTEX_OP_CMP_GE 5
3477# endif
Roland McGrath51942a92007-07-05 18:59:11 +00003478static const struct xlat futexwakeops[] = {
3479 { FUTEX_OP_SET, "FUTEX_OP_SET" },
3480 { FUTEX_OP_ADD, "FUTEX_OP_ADD" },
3481 { FUTEX_OP_OR, "FUTEX_OP_OR" },
3482 { FUTEX_OP_ANDN, "FUTEX_OP_ANDN" },
3483 { FUTEX_OP_XOR, "FUTEX_OP_XOR" },
3484 { 0, NULL }
3485};
3486static const struct xlat futexwakecmps[] = {
3487 { FUTEX_OP_CMP_EQ, "FUTEX_OP_CMP_EQ" },
3488 { FUTEX_OP_CMP_NE, "FUTEX_OP_CMP_NE" },
3489 { FUTEX_OP_CMP_LT, "FUTEX_OP_CMP_LT" },
3490 { FUTEX_OP_CMP_LE, "FUTEX_OP_CMP_LE" },
3491 { FUTEX_OP_CMP_GT, "FUTEX_OP_CMP_GT" },
3492 { FUTEX_OP_CMP_GE, "FUTEX_OP_CMP_GE" },
3493 { 0, NULL }
Roland McGrath5a223472002-12-15 23:58:26 +00003494};
3495
3496int
Denys Vlasenko1d632462009-04-14 12:51:00 +00003497sys_futex(struct tcb *tcp)
Roland McGrath5a223472002-12-15 23:58:26 +00003498{
Denys Vlasenko1d632462009-04-14 12:51:00 +00003499 if (entering(tcp)) {
3500 long int cmd = tcp->u_arg[1] & 127;
3501 tprintf("%p, ", (void *) tcp->u_arg[0]);
3502 printxval(futexops, tcp->u_arg[1], "FUTEX_???");
3503 tprintf(", %ld", tcp->u_arg[2]);
3504 if (cmd == FUTEX_WAKE_BITSET)
3505 tprintf(", %lx", tcp->u_arg[5]);
3506 else if (cmd == FUTEX_WAIT) {
3507 tprintf(", ");
3508 printtv(tcp, tcp->u_arg[3]);
3509 } else if (cmd == FUTEX_WAIT_BITSET) {
3510 tprintf(", ");
3511 printtv(tcp, tcp->u_arg[3]);
3512 tprintf(", %lx", tcp->u_arg[5]);
3513 } else if (cmd == FUTEX_REQUEUE)
3514 tprintf(", %ld, %p", tcp->u_arg[3], (void *) tcp->u_arg[4]);
Andreas Schwab85f58322009-08-12 09:54:42 +02003515 else if (cmd == FUTEX_CMP_REQUEUE || cmd == FUTEX_CMP_REQUEUE_PI)
Denys Vlasenko1d632462009-04-14 12:51:00 +00003516 tprintf(", %ld, %p, %ld", tcp->u_arg[3], (void *) tcp->u_arg[4], tcp->u_arg[5]);
3517 else if (cmd == FUTEX_WAKE_OP) {
3518 tprintf(", %ld, %p, {", tcp->u_arg[3], (void *) tcp->u_arg[4]);
3519 if ((tcp->u_arg[5] >> 28) & 8)
3520 tprintf("FUTEX_OP_OPARG_SHIFT|");
3521 printxval(futexwakeops, (tcp->u_arg[5] >> 28) & 0x7, "FUTEX_OP_???");
3522 tprintf(", %ld, ", (tcp->u_arg[5] >> 12) & 0xfff);
3523 if ((tcp->u_arg[5] >> 24) & 8)
3524 tprintf("FUTEX_OP_OPARG_SHIFT|");
3525 printxval(futexwakecmps, (tcp->u_arg[5] >> 24) & 0x7, "FUTEX_OP_CMP_???");
3526 tprintf(", %ld}", tcp->u_arg[5] & 0xfff);
Andreas Schwab85f58322009-08-12 09:54:42 +02003527 } else if (cmd == FUTEX_WAIT_REQUEUE_PI) {
3528 tprintf(", ");
3529 printtv(tcp, tcp->u_arg[3]);
3530 tprintf(", %p", (void *) tcp->u_arg[4]);
Denys Vlasenko1d632462009-04-14 12:51:00 +00003531 }
Roland McGrath51942a92007-07-05 18:59:11 +00003532 }
Denys Vlasenko1d632462009-04-14 12:51:00 +00003533 return 0;
Roland McGrath5a223472002-12-15 23:58:26 +00003534}
3535
3536static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00003537print_affinitylist(struct tcb *tcp, long list, unsigned int len)
Roland McGrath5a223472002-12-15 23:58:26 +00003538{
Denys Vlasenko1d632462009-04-14 12:51:00 +00003539 int first = 1;
Dmitry V. Levin62e05962009-11-03 14:38:44 +00003540 unsigned long w, min_len;
3541
3542 if (abbrev(tcp) && len / sizeof(w) > max_strlen)
3543 min_len = len - max_strlen * sizeof(w);
3544 else
3545 min_len = 0;
3546 for (; len >= sizeof(w) && len > min_len;
3547 len -= sizeof(w), list += sizeof(w)) {
3548 if (umove(tcp, list, &w) < 0)
3549 break;
3550 if (first)
3551 tprintf("{");
3552 else
3553 tprintf(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00003554 first = 0;
Dmitry V. Levin62e05962009-11-03 14:38:44 +00003555 tprintf("%lx", w);
Denys Vlasenko1d632462009-04-14 12:51:00 +00003556 }
Dmitry V. Levin62e05962009-11-03 14:38:44 +00003557 if (len) {
3558 if (first)
3559 tprintf("%#lx", list);
3560 else
3561 tprintf(", %s}", (len >= sizeof(w) && len > min_len ?
3562 "???" : "..."));
3563 } else {
3564 tprintf(first ? "{}" : "}");
3565 }
Roland McGrath5a223472002-12-15 23:58:26 +00003566}
3567
3568int
Denys Vlasenko1d632462009-04-14 12:51:00 +00003569sys_sched_setaffinity(struct tcb *tcp)
Roland McGrath5a223472002-12-15 23:58:26 +00003570{
Denys Vlasenko1d632462009-04-14 12:51:00 +00003571 if (entering(tcp)) {
3572 tprintf("%ld, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
3573 print_affinitylist(tcp, tcp->u_arg[2], tcp->u_arg[1]);
3574 }
3575 return 0;
Roland McGrath5a223472002-12-15 23:58:26 +00003576}
3577
3578int
Denys Vlasenko1d632462009-04-14 12:51:00 +00003579sys_sched_getaffinity(struct tcb *tcp)
Roland McGrath5a223472002-12-15 23:58:26 +00003580{
Denys Vlasenko1d632462009-04-14 12:51:00 +00003581 if (entering(tcp)) {
3582 tprintf("%ld, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
3583 } else {
3584 if (tcp->u_rval == -1)
3585 tprintf("%#lx", tcp->u_arg[2]);
3586 else
3587 print_affinitylist(tcp, tcp->u_arg[2], tcp->u_rval);
3588 }
3589 return 0;
Roland McGrath5a223472002-12-15 23:58:26 +00003590}
Roland McGrath279d3782004-03-01 20:27:37 +00003591
Roland McGrathd9f816f2004-09-04 03:39:20 +00003592static const struct xlat schedulers[] = {
Roland McGrath279d3782004-03-01 20:27:37 +00003593 { SCHED_OTHER, "SCHED_OTHER" },
3594 { SCHED_RR, "SCHED_RR" },
3595 { SCHED_FIFO, "SCHED_FIFO" },
3596 { 0, NULL }
3597};
3598
3599int
Denys Vlasenko1d632462009-04-14 12:51:00 +00003600sys_sched_getscheduler(struct tcb *tcp)
Roland McGrath279d3782004-03-01 20:27:37 +00003601{
Denys Vlasenko1d632462009-04-14 12:51:00 +00003602 if (entering(tcp)) {
3603 tprintf("%d", (int) tcp->u_arg[0]);
3604 } else if (! syserror(tcp)) {
3605 tcp->auxstr = xlookup (schedulers, tcp->u_rval);
3606 if (tcp->auxstr != NULL)
3607 return RVAL_STR;
3608 }
3609 return 0;
Roland McGrath279d3782004-03-01 20:27:37 +00003610}
3611
3612int
Denys Vlasenko1d632462009-04-14 12:51:00 +00003613sys_sched_setscheduler(struct tcb *tcp)
Roland McGrath279d3782004-03-01 20:27:37 +00003614{
Denys Vlasenko1d632462009-04-14 12:51:00 +00003615 if (entering(tcp)) {
3616 struct sched_param p;
3617 tprintf("%d, ", (int) tcp->u_arg[0]);
3618 printxval(schedulers, tcp->u_arg[1], "SCHED_???");
3619 if (umove(tcp, tcp->u_arg[2], &p) < 0)
3620 tprintf(", %#lx", tcp->u_arg[2]);
3621 else
3622 tprintf(", { %d }", p.__sched_priority);
3623 }
3624 return 0;
Roland McGrath279d3782004-03-01 20:27:37 +00003625}
3626
3627int
Denys Vlasenko1d632462009-04-14 12:51:00 +00003628sys_sched_getparam(struct tcb *tcp)
Roland McGrath279d3782004-03-01 20:27:37 +00003629{
Denys Vlasenko1d632462009-04-14 12:51:00 +00003630 if (entering(tcp)) {
3631 tprintf("%d, ", (int) tcp->u_arg[0]);
3632 } else {
3633 struct sched_param p;
3634 if (umove(tcp, tcp->u_arg[1], &p) < 0)
3635 tprintf("%#lx", tcp->u_arg[1]);
3636 else
3637 tprintf("{ %d }", p.__sched_priority);
3638 }
3639 return 0;
Roland McGrath279d3782004-03-01 20:27:37 +00003640}
3641
3642int
Denys Vlasenko1d632462009-04-14 12:51:00 +00003643sys_sched_setparam(struct tcb *tcp)
Roland McGrath279d3782004-03-01 20:27:37 +00003644{
Denys Vlasenko1d632462009-04-14 12:51:00 +00003645 if (entering(tcp)) {
3646 struct sched_param p;
3647 if (umove(tcp, tcp->u_arg[1], &p) < 0)
3648 tprintf("%d, %#lx", (int) tcp->u_arg[0], tcp->u_arg[1]);
3649 else
3650 tprintf("%d, { %d }", (int) tcp->u_arg[0], p.__sched_priority);
3651 }
3652 return 0;
Roland McGrath279d3782004-03-01 20:27:37 +00003653}
3654
3655int
Denys Vlasenko1d632462009-04-14 12:51:00 +00003656sys_sched_get_priority_min(struct tcb *tcp)
Roland McGrath279d3782004-03-01 20:27:37 +00003657{
Denys Vlasenko1d632462009-04-14 12:51:00 +00003658 if (entering(tcp)) {
3659 printxval(schedulers, tcp->u_arg[0], "SCHED_???");
3660 }
3661 return 0;
Roland McGrath279d3782004-03-01 20:27:37 +00003662}
Roland McGrathc2d5eb02005-02-02 04:16:56 +00003663
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003664# ifdef X86_64
3665# include <asm/prctl.h>
Roland McGrathc2d5eb02005-02-02 04:16:56 +00003666
3667static const struct xlat archvals[] = {
3668 { ARCH_SET_GS, "ARCH_SET_GS" },
3669 { ARCH_SET_FS, "ARCH_SET_FS" },
3670 { ARCH_GET_FS, "ARCH_GET_FS" },
3671 { ARCH_GET_GS, "ARCH_GET_GS" },
3672 { 0, NULL },
3673};
3674
3675int
Denys Vlasenko1d632462009-04-14 12:51:00 +00003676sys_arch_prctl(struct tcb *tcp)
Roland McGrathc2d5eb02005-02-02 04:16:56 +00003677{
Denys Vlasenko1d632462009-04-14 12:51:00 +00003678 if (entering(tcp)) {
3679 printxval(archvals, tcp->u_arg[0], "ARCH_???");
3680 if (tcp->u_arg[0] == ARCH_SET_GS
3681 || tcp->u_arg[0] == ARCH_SET_FS
3682 ) {
3683 tprintf(", %#lx", tcp->u_arg[1]);
3684 }
3685 } else {
3686 if (tcp->u_arg[0] == ARCH_GET_GS
3687 || tcp->u_arg[0] == ARCH_GET_FS
3688 ) {
3689 long int v;
3690 if (!syserror(tcp) && umove(tcp, tcp->u_arg[1], &v) != -1)
3691 tprintf(", [%#lx]", v);
3692 else
3693 tprintf(", %#lx", tcp->u_arg[1]);
3694 }
Roland McGrathc2d5eb02005-02-02 04:16:56 +00003695 }
Denys Vlasenko1d632462009-04-14 12:51:00 +00003696 return 0;
Roland McGrathc2d5eb02005-02-02 04:16:56 +00003697}
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003698# endif /* X86_64 */
Roland McGrathc2d5eb02005-02-02 04:16:56 +00003699
Roland McGrathdb8319f2007-08-02 01:37:55 +00003700
3701int
Denys Vlasenko1d632462009-04-14 12:51:00 +00003702sys_getcpu(struct tcb *tcp)
Roland McGrathdb8319f2007-08-02 01:37:55 +00003703{
3704 if (exiting(tcp)) {
3705 unsigned u;
3706 if (tcp->u_arg[0] == 0)
3707 tprintf("NULL, ");
3708 else if (umove(tcp, tcp->u_arg[0], &u) < 0)
3709 tprintf("%#lx, ", tcp->u_arg[0]);
3710 else
3711 tprintf("[%u], ", u);
3712 if (tcp->u_arg[1] == 0)
3713 tprintf("NULL, ");
3714 else if (umove(tcp, tcp->u_arg[1], &u) < 0)
3715 tprintf("%#lx, ", tcp->u_arg[1]);
3716 else
3717 tprintf("[%u], ", u);
3718 tprintf("%#lx", tcp->u_arg[2]);
3719 }
3720 return 0;
3721}
3722
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003723#endif /* LINUX */