blob: f7af19681bca514bea6cc7f82f5a6f71cd34e99b [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 */
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000560
Roland McGrathd9f816f2004-09-04 03:39:20 +0000561static const struct xlat clone_flags[] = {
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000562 { CLONE_VM, "CLONE_VM" },
563 { CLONE_FS, "CLONE_FS" },
564 { CLONE_FILES, "CLONE_FILES" },
565 { CLONE_SIGHAND, "CLONE_SIGHAND" },
Roland McGrath909875b2002-12-22 03:34:36 +0000566 { CLONE_IDLETASK, "CLONE_IDLETASK"},
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000567 { CLONE_PTRACE, "CLONE_PTRACE" },
568 { CLONE_VFORK, "CLONE_VFORK" },
569 { CLONE_PARENT, "CLONE_PARENT" },
Roland McGrath909875b2002-12-22 03:34:36 +0000570 { CLONE_THREAD, "CLONE_THREAD" },
571 { CLONE_NEWNS, "CLONE_NEWNS" },
572 { CLONE_SYSVSEM, "CLONE_SYSVSEM" },
573 { CLONE_SETTLS, "CLONE_SETTLS" },
574 { CLONE_PARENT_SETTID,"CLONE_PARENT_SETTID" },
575 { CLONE_CHILD_CLEARTID,"CLONE_CHILD_CLEARTID" },
Roland McGrath909875b2002-12-22 03:34:36 +0000576 { CLONE_UNTRACED, "CLONE_UNTRACED" },
577 { CLONE_CHILD_SETTID,"CLONE_CHILD_SETTID" },
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000578 { 0, NULL },
579};
580
Roland McGrath909875b2002-12-22 03:34:36 +0000581# ifdef I386
582# include <asm/ldt.h>
Roland McGrath7decfb22004-03-01 22:10:52 +0000583# ifdef HAVE_STRUCT_USER_DESC
584# define modify_ldt_ldt_s user_desc
585# endif
Roland McGrath909875b2002-12-22 03:34:36 +0000586extern void print_ldt_entry();
587# endif
588
Roland McGrath9677b3a2003-03-12 09:54:36 +0000589# if defined IA64
590# define ARG_FLAGS 0
591# define ARG_STACK 1
Roland McGratha4f9f2d2005-06-07 23:21:20 +0000592# define ARG_STACKSIZE (known_scno(tcp) == SYS_clone2 ? 2 : -1)
593# define ARG_PTID (known_scno(tcp) == SYS_clone2 ? 3 : 2)
594# define ARG_CTID (known_scno(tcp) == SYS_clone2 ? 4 : 3)
595# define ARG_TLS (known_scno(tcp) == SYS_clone2 ? 5 : 4)
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +0000596# elif defined S390 || defined S390X || defined CRISV10 || defined CRISV32
Roland McGrath9677b3a2003-03-12 09:54:36 +0000597# define ARG_STACK 0
598# define ARG_FLAGS 1
599# define ARG_PTID 2
Roland McGrathfe5fdb22003-05-23 00:29:05 +0000600# define ARG_CTID 3
601# define ARG_TLS 4
Roland McGrath9c555e72003-07-09 09:47:59 +0000602# elif defined X86_64 || defined ALPHA
Roland McGrath361aac52003-03-18 07:43:42 +0000603# define ARG_FLAGS 0
604# define ARG_STACK 1
605# define ARG_PTID 2
606# define ARG_CTID 3
607# define ARG_TLS 4
Roland McGrath9677b3a2003-03-12 09:54:36 +0000608# else
609# define ARG_FLAGS 0
610# define ARG_STACK 1
611# define ARG_PTID 2
612# define ARG_TLS 3
613# define ARG_CTID 4
614# endif
615
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000616int
617sys_clone(tcp)
618struct tcb *tcp;
619{
620 if (exiting(tcp)) {
Roland McGrath9677b3a2003-03-12 09:54:36 +0000621 unsigned long flags = tcp->u_arg[ARG_FLAGS];
622 tprintf("child_stack=%#lx, ", tcp->u_arg[ARG_STACK]);
623# ifdef ARG_STACKSIZE
624 if (ARG_STACKSIZE != -1)
625 tprintf("stack_size=%#lx, ",
626 tcp->u_arg[ARG_STACKSIZE]);
Roland McGrathb4968be2003-01-20 09:04:33 +0000627# endif
Roland McGrath9677b3a2003-03-12 09:54:36 +0000628 tprintf("flags=");
Roland McGrathb2dee132005-06-01 19:02:36 +0000629 printflags(clone_flags, flags &~ CSIGNAL, NULL);
Roland McGrath984154d2003-05-23 01:08:42 +0000630 if ((flags & CSIGNAL) != 0)
631 tprintf("|%s", signame(flags & CSIGNAL));
Roland McGrathb4968be2003-01-20 09:04:33 +0000632 if ((flags & (CLONE_PARENT_SETTID|CLONE_CHILD_SETTID
Roland McGrath9677b3a2003-03-12 09:54:36 +0000633 |CLONE_CHILD_CLEARTID|CLONE_SETTLS)) == 0)
Roland McGrath909875b2002-12-22 03:34:36 +0000634 return 0;
Roland McGrath6f67a982003-03-21 07:33:15 +0000635 if (flags & CLONE_PARENT_SETTID)
636 tprintf(", parent_tidptr=%#lx", tcp->u_arg[ARG_PTID]);
Roland McGrathb4968be2003-01-20 09:04:33 +0000637 if (flags & CLONE_SETTLS) {
Roland McGrath9677b3a2003-03-12 09:54:36 +0000638# ifdef I386
Roland McGrath909875b2002-12-22 03:34:36 +0000639 struct modify_ldt_ldt_s copy;
Roland McGrath9677b3a2003-03-12 09:54:36 +0000640 if (umove(tcp, tcp->u_arg[ARG_TLS], &copy) != -1) {
Roland McGrath909875b2002-12-22 03:34:36 +0000641 tprintf(", {entry_number:%d, ",
642 copy.entry_number);
643 if (!verbose(tcp))
644 tprintf("...}");
645 else
646 print_ldt_entry(&copy);
647 }
648 else
Roland McGrath9677b3a2003-03-12 09:54:36 +0000649# endif
Roland McGrath43f2c842003-03-12 09:58:14 +0000650 tprintf(", tls=%#lx", tcp->u_arg[ARG_TLS]);
Roland McGrath909875b2002-12-22 03:34:36 +0000651 }
Roland McGrath9677b3a2003-03-12 09:54:36 +0000652 if (flags & (CLONE_CHILD_SETTID|CLONE_CHILD_CLEARTID))
653 tprintf(", child_tidptr=%#lx", tcp->u_arg[ARG_CTID]);
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000654 }
655 return 0;
656}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000657
658int
659sys_unshare(struct tcb *tcp)
660{
661 if (entering(tcp))
662 printflags(clone_flags, tcp->u_arg[0], "CLONE_???");
663 return 0;
664}
Dmitry V. Levine5e60852009-12-31 22:50:49 +0000665#endif /* LINUX */
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000666
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000667int
668sys_fork(tcp)
669struct tcb *tcp;
670{
671 if (exiting(tcp))
672 return RVAL_UDECIMAL;
673 return 0;
674}
675
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000676int
Denys Vlasenko418d66a2009-01-17 01:52:54 +0000677change_syscall(struct tcb *tcp, int new)
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000678{
Dmitry V. Levine5e60852009-12-31 22:50:49 +0000679#ifdef LINUX
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000680#if defined(I386)
681 /* Attempt to make vfork into fork, which we can follow. */
Roland McGrath5a223472002-12-15 23:58:26 +0000682 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(ORIG_EAX * 4), new) < 0)
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000683 return -1;
684 return 0;
Michal Ludvig0e035502002-09-23 15:41:01 +0000685#elif defined(X86_64)
686 /* Attempt to make vfork into fork, which we can follow. */
Roland McGrath5a223472002-12-15 23:58:26 +0000687 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(ORIG_RAX * 8), new) < 0)
Michal Ludvig0e035502002-09-23 15:41:01 +0000688 return -1;
689 return 0;
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000690#elif defined(POWERPC)
Roland McGratheb285352003-01-14 09:59:00 +0000691 if (ptrace(PTRACE_POKEUSER, tcp->pid,
692 (char*)(sizeof(unsigned long)*PT_R0), new) < 0)
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000693 return -1;
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000694 return 0;
Michal Ludvig10a88d02002-10-07 14:31:00 +0000695#elif defined(S390) || defined(S390X)
696 /* s390 linux after 2.4.7 has a hook in entry.S to allow this */
697 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(PT_GPR2), new)<0)
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +0000698 return -1;
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000699 return 0;
700#elif defined(M68K)
Wichert Akkermanc7926982000-04-10 22:22:31 +0000701 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(4*PT_ORIG_D0), new)<0)
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +0000702 return -1;
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000703 return 0;
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000704#elif defined(SPARC) || defined(SPARC64)
Mike Frysinger8566c502009-10-12 11:05:14 -0400705 struct pt_regs regs;
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000706 if (ptrace(PTRACE_GETREGS, tcp->pid, (char*)&regs, 0)<0)
707 return -1;
Mike Frysinger8566c502009-10-12 11:05:14 -0400708 regs.u_regs[U_REG_G1] = new;
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000709 if (ptrace(PTRACE_SETREGS, tcp->pid, (char*)&regs, 0)<0)
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +0000710 return -1;
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000711 return 0;
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000712#elif defined(MIPS)
Wichert Akkermanc7926982000-04-10 22:22:31 +0000713 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(REG_V0), 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(ALPHA)
Wichert Akkermanc7926982000-04-10 22:22:31 +0000717 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(REG_A3), new)<0)
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +0000718 return -1;
719 return 0;
720#elif defined(AVR32)
721 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(REG_R8), new) < 0)
722 return -1;
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000723 return 0;
Dmitry V. Levin87ea1f42008-11-10 22:21:41 +0000724#elif defined(BFIN)
725 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(REG_P0), new)<0)
726 return -1;
727 return 0;
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000728#elif defined(IA64)
Roland McGrath08267b82004-02-20 22:56:43 +0000729 if (ia32) {
730 switch (new) {
Denys Vlasenko418d66a2009-01-17 01:52:54 +0000731 case 2:
732 break; /* x86 SYS_fork */
733 case SYS_clone:
734 new = 120;
735 break;
736 default:
Roland McGrath08267b82004-02-20 22:56:43 +0000737 fprintf(stderr, "%s: unexpected syscall %d\n",
738 __FUNCTION__, new);
739 return -1;
740 }
741 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(PT_R1), new)<0)
742 return -1;
743 } else if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(PT_R15), new)<0)
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000744 return -1;
745 return 0;
Wichert Akkermanc1652e22001-03-27 12:17:16 +0000746#elif defined(HPPA)
747 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(PT_GR20), new)<0)
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +0000748 return -1;
Wichert Akkermanc1652e22001-03-27 12:17:16 +0000749 return 0;
Wichert Akkermanccef6372002-05-01 16:39:22 +0000750#elif defined(SH)
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000751 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(4*(REG_REG0+3)), new)<0)
752 return -1;
753 return 0;
Roland McGrathf5a47772003-06-26 22:40:42 +0000754#elif defined(SH64)
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000755 /* Top half of reg encodes the no. of args n as 0x1n.
756 Assume 0 args as kernel never actually checks... */
757 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(REG_SYSCALL),
758 0x100000 | new) < 0)
759 return -1;
760 return 0;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +0000761#elif defined(CRISV10) || defined(CRISV32)
762 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(4*PT_R9), new) < 0)
763 return -1;
764 return 0;
Roland McGrathf691bd22006-04-25 07:34:41 +0000765#elif defined(ARM)
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000766 /* Some kernels support this, some (pre-2.6.16 or so) don't. */
Roland McGrathf691bd22006-04-25 07:34:41 +0000767# ifndef PTRACE_SET_SYSCALL
768# define PTRACE_SET_SYSCALL 23
769# endif
770
Dmitry V. Levin76740062009-09-18 11:30:14 +0000771 if (ptrace (PTRACE_SET_SYSCALL, tcp->pid, 0, new & 0xffff) != 0)
Roland McGrathf691bd22006-04-25 07:34:41 +0000772 return -1;
773
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000774 return 0;
Chris Metcalfc8c66982009-12-28 10:00:15 -0500775#elif defined(TILE)
776 if (ptrace(PTRACE_POKEUSER, tcp->pid,
777 (char*)PTREGS_OFFSET_REG(0),
778 new) != 0)
779 return -1;
780 return 0;
Edgar E. Iglesias939caba2010-07-06 14:21:07 +0200781#elif defined(MICROBLAZE)
782 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(PT_GPR(0)), new)<0)
783 return -1;
784 return 0;
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000785#else
786#warning Do not know how to handle change_syscall for this architecture
787#endif /* architecture */
788#endif /* LINUX */
789 return -1;
790}
791
Dmitry V. Levin257e1572009-12-26 17:55:24 +0000792#ifdef LINUX
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000793int
Dmitry V. Levin257e1572009-12-26 17:55:24 +0000794internal_fork(struct tcb *tcp)
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000795{
796 if (entering(tcp)) {
Roland McGratheb9e2e82009-06-02 16:49:22 -0700797 if (!followfork)
798 return 0;
799 fork_tcb(tcp);
800 if (setbpt(tcp) < 0)
801 return 0;
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000802 } else {
Dmitry V. Levin257e1572009-12-26 17:55:24 +0000803 struct tcb *tcpchild;
804 int pid;
805 int bpt;
Roland McGratheb9e2e82009-06-02 16:49:22 -0700806
807 if (!(tcp->flags & TCB_FOLLOWFORK))
808 return 0;
Wichert Akkerman9b0c31d2000-09-03 21:56:29 +0000809
Dmitry V. Levin257e1572009-12-26 17:55:24 +0000810 bpt = tcp->flags & TCB_BPTSET;
811
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000812 if (syserror(tcp)) {
813 if (bpt)
814 clearbpt(tcp);
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000815 return 0;
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000816 }
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000817
818 pid = tcp->u_rval;
Roland McGrathe85bbfe2003-01-09 06:53:31 +0000819
820#ifdef CLONE_PTRACE /* See new setbpt code. */
821 tcpchild = pid2tcb(pid);
822 if (tcpchild != NULL) {
823 /* The child already reported its startup trap
824 before the parent reported its syscall return. */
825 if ((tcpchild->flags
826 & (TCB_STARTUP|TCB_ATTACHED|TCB_SUSPENDED))
827 != (TCB_STARTUP|TCB_ATTACHED|TCB_SUSPENDED))
828 fprintf(stderr, "\
829[preattached child %d of %d in weird state!]\n",
830 pid, tcp->pid);
831 }
832 else
Dmitry V. Levin257e1572009-12-26 17:55:24 +0000833#endif /* CLONE_PTRACE */
Denys Vlasenkodb78f762009-01-26 12:55:40 +0000834 {
Roland McGratheb9e2e82009-06-02 16:49:22 -0700835 fork_tcb(tcp);
Denys Vlasenkodb78f762009-01-26 12:55:40 +0000836 tcpchild = alloctcb(pid);
837 }
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000838
Roland McGrathe85bbfe2003-01-09 06:53:31 +0000839#ifndef CLONE_PTRACE
Wichert Akkerman9b0c31d2000-09-03 21:56:29 +0000840 /* Attach to the new child */
841 if (ptrace(PTRACE_ATTACH, pid, (char *) 1, 0) < 0) {
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000842 if (bpt)
843 clearbpt(tcp);
Wichert Akkerman9b0c31d2000-09-03 21:56:29 +0000844 perror("PTRACE_ATTACH");
845 fprintf(stderr, "Too late?\n");
846 droptcb(tcpchild);
847 return 0;
848 }
Dmitry V. Levin257e1572009-12-26 17:55:24 +0000849#endif /* !CLONE_PTRACE */
Wichert Akkerman9b0c31d2000-09-03 21:56:29 +0000850
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000851 if (bpt)
852 clearbpt(tcp);
853
Ulrich Drepper90512f01999-12-24 07:22:25 +0000854 tcpchild->flags |= TCB_ATTACHED;
Roland McGrathe85bbfe2003-01-09 06:53:31 +0000855 /* Child has BPT too, must be removed on first occasion. */
Wichert Akkerman9b0c31d2000-09-03 21:56:29 +0000856 if (bpt) {
857 tcpchild->flags |= TCB_BPTSET;
858 tcpchild->baddr = tcp->baddr;
859 memcpy(tcpchild->inst, tcp->inst,
860 sizeof tcpchild->inst);
861 }
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000862 tcpchild->parent = tcp;
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +0000863 tcp->nchildren++;
Roland McGrathe85bbfe2003-01-09 06:53:31 +0000864 if (tcpchild->flags & TCB_SUSPENDED) {
865 /* The child was born suspended, due to our having
866 forced CLONE_PTRACE. */
867 if (bpt)
868 clearbpt(tcpchild);
869
870 tcpchild->flags &= ~(TCB_SUSPENDED|TCB_STARTUP);
Denys Vlasenko732d1bf2008-12-17 19:21:59 +0000871 if (ptrace_restart(PTRACE_SYSCALL, tcpchild, 0) < 0)
Roland McGrathe85bbfe2003-01-09 06:53:31 +0000872 return -1;
Roland McGrathe85bbfe2003-01-09 06:53:31 +0000873
874 if (!qflag)
875 fprintf(stderr, "\
876Process %u resumed (parent %d ready)\n",
877 pid, tcp->pid);
878 }
879 else {
Roland McGrathe85bbfe2003-01-09 06:53:31 +0000880 if (!qflag)
881 fprintf(stderr, "Process %d attached\n", pid);
882 }
883
884#ifdef TCB_CLONE_THREAD
Roland McGrath984154d2003-05-23 01:08:42 +0000885 {
886 /*
887 * Save the flags used in this call,
888 * in case we point TCP to our parent below.
889 */
890 int call_flags = tcp->u_arg[ARG_FLAGS];
891 if ((tcp->flags & TCB_CLONE_THREAD) &&
892 tcp->parent != NULL) {
893 /* The parent in this clone is itself a
894 thread belonging to another process.
895 There is no meaning to the parentage
896 relationship of the new child with the
897 thread, only with the process. We
898 associate the new thread with our
899 parent. Since this is done for every
900 new thread, there will never be a
901 TCB_CLONE_THREAD process that has
902 children. */
903 --tcp->nchildren;
904 tcp = tcp->parent;
905 tcpchild->parent = tcp;
906 ++tcp->nchildren;
907 }
908 if (call_flags & CLONE_THREAD) {
909 tcpchild->flags |= TCB_CLONE_THREAD;
910 ++tcp->nclone_threads;
911 }
Wang Chao5a22b312010-08-05 14:58:37 +0800912 if ((call_flags & CLONE_PARENT) &&
913 !(call_flags & CLONE_THREAD)) {
914 --tcp->nchildren;
915 tcpchild->parent = NULL;
916 if (tcp->parent != NULL) {
917 tcp = tcp->parent;
918 tcpchild->parent = tcp;
919 ++tcp->nchildren;
920 }
921 }
Roland McGrathe85bbfe2003-01-09 06:53:31 +0000922 }
Dmitry V. Levin257e1572009-12-26 17:55:24 +0000923#endif /* TCB_CLONE_THREAD */
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +0000924 }
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000925 return 0;
926}
Dmitry V. Levin257e1572009-12-26 17:55:24 +0000927
928#else /* !LINUX */
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000929
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000930int
931internal_fork(tcp)
932struct tcb *tcp;
933{
934 struct tcb *tcpchild;
935 int pid;
Roland McGratheb9e2e82009-06-02 16:49:22 -0700936 int dont_follow = 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000937
938#ifdef SYS_vfork
Roland McGratha4f9f2d2005-06-07 23:21:20 +0000939 if (known_scno(tcp) == SYS_vfork) {
Nate Sammonsccd8f211999-03-29 22:57:54 +0000940 /* Attempt to make vfork into fork, which we can follow. */
Roland McGrath41c48222008-07-18 00:25:10 +0000941 if (change_syscall(tcp, SYS_fork) < 0)
Roland McGratheb9e2e82009-06-02 16:49:22 -0700942 dont_follow = 1;
Nate Sammonsccd8f211999-03-29 22:57:54 +0000943 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000944#endif
945 if (entering(tcp)) {
Roland McGratheb9e2e82009-06-02 16:49:22 -0700946 if (!followfork || dont_follow)
947 return 0;
948 fork_tcb(tcp);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000949 if (setbpt(tcp) < 0)
950 return 0;
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +0000951 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000952 else {
953 int bpt = tcp->flags & TCB_BPTSET;
954
Roland McGratheb9e2e82009-06-02 16:49:22 -0700955 if (!(tcp->flags & TCB_FOLLOWFORK))
956 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000957 if (bpt)
958 clearbpt(tcp);
959
960 if (syserror(tcp))
961 return 0;
962
963 pid = tcp->u_rval;
Roland McGratheb9e2e82009-06-02 16:49:22 -0700964 fork_tcb(tcp);
Denys Vlasenko418d66a2009-01-17 01:52:54 +0000965 tcpchild = alloctcb(pid);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000966#ifdef SUNOS4
967#ifdef oldway
968 /* The child must have run before it can be attached. */
969 {
970 struct timeval tv;
971 tv.tv_sec = 0;
972 tv.tv_usec = 10000;
973 select(0, NULL, NULL, NULL, &tv);
974 }
975 if (ptrace(PTRACE_ATTACH, pid, (char *)1, 0) < 0) {
976 perror("PTRACE_ATTACH");
977 fprintf(stderr, "Too late?\n");
978 droptcb(tcpchild);
979 return 0;
980 }
981#else /* !oldway */
982 /* Try to catch the new process as soon as possible. */
983 {
984 int i;
985 for (i = 0; i < 1024; i++)
986 if (ptrace(PTRACE_ATTACH, pid, (char *) 1, 0) >= 0)
987 break;
988 if (i == 1024) {
989 perror("PTRACE_ATTACH");
990 fprintf(stderr, "Too late?\n");
991 droptcb(tcpchild);
992 return 0;
993 }
994 }
995#endif /* !oldway */
996#endif /* SUNOS4 */
997 tcpchild->flags |= TCB_ATTACHED;
998 /* Child has BPT too, must be removed on first occasion */
999 if (bpt) {
1000 tcpchild->flags |= TCB_BPTSET;
1001 tcpchild->baddr = tcp->baddr;
1002 memcpy(tcpchild->inst, tcp->inst,
1003 sizeof tcpchild->inst);
1004 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001005 tcpchild->parent = tcp;
1006 tcp->nchildren++;
1007 if (!qflag)
1008 fprintf(stderr, "Process %d attached\n", pid);
1009 }
1010 return 0;
1011}
1012
Dmitry V. Levin257e1572009-12-26 17:55:24 +00001013#endif /* !LINUX */
1014
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001015#endif /* !USE_PROCFS */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001016
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001017#if defined(SUNOS4) || defined(LINUX) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001018
1019int
1020sys_vfork(tcp)
1021struct tcb *tcp;
1022{
1023 if (exiting(tcp))
1024 return RVAL_UDECIMAL;
1025 return 0;
1026}
1027
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001028#endif /* SUNOS4 || LINUX || FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001029
1030#ifndef LINUX
1031
1032static char idstr[16];
1033
1034int
1035sys_getpid(tcp)
1036struct tcb *tcp;
1037{
1038 if (exiting(tcp)) {
1039 sprintf(idstr, "ppid %lu", getrval2(tcp));
1040 tcp->auxstr = idstr;
1041 return RVAL_STR;
1042 }
1043 return 0;
1044}
1045
1046int
1047sys_getuid(tcp)
1048struct tcb *tcp;
1049{
1050 if (exiting(tcp)) {
1051 sprintf(idstr, "euid %lu", getrval2(tcp));
1052 tcp->auxstr = idstr;
1053 return RVAL_STR;
1054 }
1055 return 0;
1056}
1057
1058int
1059sys_getgid(tcp)
1060struct tcb *tcp;
1061{
1062 if (exiting(tcp)) {
1063 sprintf(idstr, "egid %lu", getrval2(tcp));
1064 tcp->auxstr = idstr;
1065 return RVAL_STR;
1066 }
1067 return 0;
1068}
1069
1070#endif /* !LINUX */
1071
1072#ifdef LINUX
1073
1074int
1075sys_setuid(tcp)
1076struct tcb *tcp;
1077{
1078 if (entering(tcp)) {
1079 tprintf("%u", (uid_t) tcp->u_arg[0]);
1080 }
1081 return 0;
1082}
1083
1084int
1085sys_setgid(tcp)
1086struct tcb *tcp;
1087{
1088 if (entering(tcp)) {
1089 tprintf("%u", (gid_t) tcp->u_arg[0]);
1090 }
1091 return 0;
1092}
1093
1094int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001095sys_getresuid(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001096{
1097 if (exiting(tcp)) {
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001098 __kernel_uid_t uid;
1099 if (syserror(tcp))
1100 tprintf("%#lx, %#lx, %#lx", tcp->u_arg[0],
1101 tcp->u_arg[1], tcp->u_arg[2]);
1102 else {
1103 if (umove(tcp, tcp->u_arg[0], &uid) < 0)
1104 tprintf("%#lx, ", tcp->u_arg[0]);
1105 else
Roland McGrath83bd47a2003-11-13 22:32:26 +00001106 tprintf("[%lu], ", (unsigned long) uid);
Roland McGrath9bd6b422003-02-24 07:13:51 +00001107 if (umove(tcp, tcp->u_arg[1], &uid) < 0)
1108 tprintf("%#lx, ", tcp->u_arg[1]);
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001109 else
Roland McGrath83bd47a2003-11-13 22:32:26 +00001110 tprintf("[%lu], ", (unsigned long) uid);
Roland McGrath9bd6b422003-02-24 07:13:51 +00001111 if (umove(tcp, tcp->u_arg[2], &uid) < 0)
1112 tprintf("%#lx", tcp->u_arg[2]);
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001113 else
Roland McGrath83bd47a2003-11-13 22:32:26 +00001114 tprintf("[%lu]", (unsigned long) uid);
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001115 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001116 }
1117 return 0;
1118}
1119
1120int
1121sys_getresgid(tcp)
1122struct tcb *tcp;
1123{
1124 if (exiting(tcp)) {
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001125 __kernel_gid_t gid;
1126 if (syserror(tcp))
1127 tprintf("%#lx, %#lx, %#lx", tcp->u_arg[0],
1128 tcp->u_arg[1], tcp->u_arg[2]);
1129 else {
1130 if (umove(tcp, tcp->u_arg[0], &gid) < 0)
1131 tprintf("%#lx, ", tcp->u_arg[0]);
1132 else
Roland McGrath83bd47a2003-11-13 22:32:26 +00001133 tprintf("[%lu], ", (unsigned long) gid);
Roland McGrathd2450922003-02-24 10:18:07 +00001134 if (umove(tcp, tcp->u_arg[1], &gid) < 0)
1135 tprintf("%#lx, ", tcp->u_arg[1]);
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001136 else
Roland McGrath83bd47a2003-11-13 22:32:26 +00001137 tprintf("[%lu], ", (unsigned long) gid);
Roland McGrathd2450922003-02-24 10:18:07 +00001138 if (umove(tcp, tcp->u_arg[2], &gid) < 0)
1139 tprintf("%#lx", tcp->u_arg[2]);
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001140 else
Roland McGrath83bd47a2003-11-13 22:32:26 +00001141 tprintf("[%lu]", (unsigned long) gid);
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001142 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001143 }
1144 return 0;
1145}
1146
1147#endif /* LINUX */
1148
1149int
1150sys_setreuid(tcp)
1151struct tcb *tcp;
1152{
1153 if (entering(tcp)) {
Roland McGrath83bd47a2003-11-13 22:32:26 +00001154 printuid("", tcp->u_arg[0]);
1155 printuid(", ", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001156 }
1157 return 0;
1158}
1159
1160int
1161sys_setregid(tcp)
1162struct tcb *tcp;
1163{
1164 if (entering(tcp)) {
Roland McGrath83bd47a2003-11-13 22:32:26 +00001165 printuid("", tcp->u_arg[0]);
1166 printuid(", ", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001167 }
1168 return 0;
1169}
1170
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001171#if defined(LINUX) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001172int
1173sys_setresuid(tcp)
1174 struct tcb *tcp;
1175{
1176 if (entering(tcp)) {
Roland McGrath83bd47a2003-11-13 22:32:26 +00001177 printuid("", tcp->u_arg[0]);
1178 printuid(", ", tcp->u_arg[1]);
1179 printuid(", ", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001180 }
1181 return 0;
1182}
1183int
1184sys_setresgid(tcp)
1185 struct tcb *tcp;
1186{
1187 if (entering(tcp)) {
Roland McGrath83bd47a2003-11-13 22:32:26 +00001188 printuid("", tcp->u_arg[0]);
1189 printuid(", ", tcp->u_arg[1]);
1190 printuid(", ", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001191 }
1192 return 0;
1193}
1194
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001195#endif /* LINUX || FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001196
1197int
1198sys_setgroups(tcp)
1199struct tcb *tcp;
1200{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001201 if (entering(tcp)) {
Roland McGrathaa524c82005-06-01 19:22:06 +00001202 unsigned long len, size, start, cur, end, abbrev_end;
1203 GETGROUPS_T gid;
1204 int failed = 0;
1205
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001206 len = tcp->u_arg[0];
Roland McGrathaa524c82005-06-01 19:22:06 +00001207 tprintf("%lu, ", len);
1208 if (len == 0) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001209 tprintf("[]");
1210 return 0;
1211 }
Roland McGrathaa524c82005-06-01 19:22:06 +00001212 start = tcp->u_arg[1];
1213 if (start == 0) {
1214 tprintf("NULL");
1215 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001216 }
Roland McGrathaa524c82005-06-01 19:22:06 +00001217 size = len * sizeof(gid);
1218 end = start + size;
1219 if (!verbose(tcp) || size / sizeof(gid) != len || end < start) {
1220 tprintf("%#lx", start);
1221 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001222 }
Roland McGrathaa524c82005-06-01 19:22:06 +00001223 if (abbrev(tcp)) {
1224 abbrev_end = start + max_strlen * sizeof(gid);
1225 if (abbrev_end < start)
1226 abbrev_end = end;
1227 } else {
1228 abbrev_end = end;
1229 }
1230 tprintf("[");
1231 for (cur = start; cur < end; cur += sizeof(gid)) {
1232 if (cur > start)
1233 tprintf(", ");
1234 if (cur >= abbrev_end) {
1235 tprintf("...");
1236 break;
1237 }
1238 if (umoven(tcp, cur, sizeof(gid), (char *) &gid) < 0) {
1239 tprintf("?");
1240 failed = 1;
1241 break;
1242 }
1243 tprintf("%lu", (unsigned long) gid);
1244 }
1245 tprintf("]");
1246 if (failed)
1247 tprintf(" %#lx", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001248 }
1249 return 0;
1250}
1251
1252int
1253sys_getgroups(tcp)
1254struct tcb *tcp;
1255{
Roland McGrathaa524c82005-06-01 19:22:06 +00001256 unsigned long len;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001257
1258 if (entering(tcp)) {
1259 len = tcp->u_arg[0];
Roland McGrathaa524c82005-06-01 19:22:06 +00001260 tprintf("%lu, ", len);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001261 } else {
Roland McGrathaa524c82005-06-01 19:22:06 +00001262 unsigned long size, start, cur, end, abbrev_end;
1263 GETGROUPS_T gid;
1264 int failed = 0;
1265
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001266 len = tcp->u_rval;
Roland McGrathaa524c82005-06-01 19:22:06 +00001267 if (len == 0) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001268 tprintf("[]");
1269 return 0;
1270 }
Roland McGrathaa524c82005-06-01 19:22:06 +00001271 start = tcp->u_arg[1];
1272 if (start == 0) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001273 tprintf("NULL");
Roland McGrathaa524c82005-06-01 19:22:06 +00001274 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001275 }
Roland McGrathaa524c82005-06-01 19:22:06 +00001276 if (tcp->u_arg[0] == 0) {
1277 tprintf("%#lx", start);
1278 return 0;
1279 }
1280 size = len * sizeof(gid);
1281 end = start + size;
1282 if (!verbose(tcp) || tcp->u_arg[0] == 0 ||
1283 size / sizeof(gid) != len || end < start) {
1284 tprintf("%#lx", start);
1285 return 0;
1286 }
1287 if (abbrev(tcp)) {
1288 abbrev_end = start + max_strlen * sizeof(gid);
1289 if (abbrev_end < start)
1290 abbrev_end = end;
1291 } else {
1292 abbrev_end = end;
1293 }
1294 tprintf("[");
1295 for (cur = start; cur < end; cur += sizeof(gid)) {
1296 if (cur > start)
1297 tprintf(", ");
1298 if (cur >= abbrev_end) {
1299 tprintf("...");
1300 break;
1301 }
1302 if (umoven(tcp, cur, sizeof(gid), (char *) &gid) < 0) {
1303 tprintf("?");
1304 failed = 1;
1305 break;
1306 }
1307 tprintf("%lu", (unsigned long) gid);
1308 }
1309 tprintf("]");
1310 if (failed)
1311 tprintf(" %#lx", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001312 }
1313 return 0;
1314}
1315
Roland McGrath83bd47a2003-11-13 22:32:26 +00001316#ifdef LINUX
1317int
1318sys_setgroups32(tcp)
1319struct tcb *tcp;
1320{
Roland McGrath83bd47a2003-11-13 22:32:26 +00001321 if (entering(tcp)) {
Roland McGrathaa524c82005-06-01 19:22:06 +00001322 unsigned long len, size, start, cur, end, abbrev_end;
1323 GETGROUPS32_T gid;
1324 int failed = 0;
1325
Roland McGrath83bd47a2003-11-13 22:32:26 +00001326 len = tcp->u_arg[0];
Roland McGrathaa524c82005-06-01 19:22:06 +00001327 tprintf("%lu, ", len);
1328 if (len == 0) {
Roland McGrath83bd47a2003-11-13 22:32:26 +00001329 tprintf("[]");
1330 return 0;
1331 }
Roland McGrathaa524c82005-06-01 19:22:06 +00001332 start = tcp->u_arg[1];
1333 if (start == 0) {
1334 tprintf("NULL");
1335 return 0;
Roland McGrath83bd47a2003-11-13 22:32:26 +00001336 }
Roland McGrathaa524c82005-06-01 19:22:06 +00001337 size = len * sizeof(gid);
1338 end = start + size;
1339 if (!verbose(tcp) || size / sizeof(gid) != len || end < start) {
1340 tprintf("%#lx", start);
1341 return 0;
Roland McGrath83bd47a2003-11-13 22:32:26 +00001342 }
Roland McGrathaa524c82005-06-01 19:22:06 +00001343 if (abbrev(tcp)) {
1344 abbrev_end = start + max_strlen * sizeof(gid);
1345 if (abbrev_end < start)
1346 abbrev_end = end;
1347 } else {
1348 abbrev_end = end;
1349 }
1350 tprintf("[");
1351 for (cur = start; cur < end; cur += sizeof(gid)) {
1352 if (cur > start)
1353 tprintf(", ");
1354 if (cur >= abbrev_end) {
1355 tprintf("...");
1356 break;
1357 }
1358 if (umoven(tcp, cur, sizeof(gid), (char *) &gid) < 0) {
1359 tprintf("?");
1360 failed = 1;
1361 break;
1362 }
1363 tprintf("%lu", (unsigned long) gid);
1364 }
1365 tprintf("]");
1366 if (failed)
1367 tprintf(" %#lx", tcp->u_arg[1]);
Roland McGrath83bd47a2003-11-13 22:32:26 +00001368 }
1369 return 0;
1370}
1371
1372int
1373sys_getgroups32(tcp)
1374struct tcb *tcp;
1375{
Roland McGrathaa524c82005-06-01 19:22:06 +00001376 unsigned long len;
Roland McGrath83bd47a2003-11-13 22:32:26 +00001377
1378 if (entering(tcp)) {
1379 len = tcp->u_arg[0];
Roland McGrathaa524c82005-06-01 19:22:06 +00001380 tprintf("%lu, ", len);
Roland McGrath83bd47a2003-11-13 22:32:26 +00001381 } else {
Roland McGrathaa524c82005-06-01 19:22:06 +00001382 unsigned long size, start, cur, end, abbrev_end;
1383 GETGROUPS32_T gid;
1384 int failed = 0;
1385
Roland McGrath83bd47a2003-11-13 22:32:26 +00001386 len = tcp->u_rval;
Roland McGrathaa524c82005-06-01 19:22:06 +00001387 if (len == 0) {
Roland McGrath83bd47a2003-11-13 22:32:26 +00001388 tprintf("[]");
1389 return 0;
1390 }
Roland McGrathaa524c82005-06-01 19:22:06 +00001391 start = tcp->u_arg[1];
1392 if (start == 0) {
Roland McGrath83bd47a2003-11-13 22:32:26 +00001393 tprintf("NULL");
Roland McGrathaa524c82005-06-01 19:22:06 +00001394 return 0;
Roland McGrath83bd47a2003-11-13 22:32:26 +00001395 }
Roland McGrathaa524c82005-06-01 19:22:06 +00001396 size = len * sizeof(gid);
1397 end = start + size;
1398 if (!verbose(tcp) || tcp->u_arg[0] == 0 ||
1399 size / sizeof(gid) != len || end < start) {
1400 tprintf("%#lx", start);
1401 return 0;
1402 }
1403 if (abbrev(tcp)) {
1404 abbrev_end = start + max_strlen * sizeof(gid);
1405 if (abbrev_end < start)
1406 abbrev_end = end;
1407 } else {
1408 abbrev_end = end;
1409 }
1410 tprintf("[");
1411 for (cur = start; cur < end; cur += sizeof(gid)) {
1412 if (cur > start)
1413 tprintf(", ");
1414 if (cur >= abbrev_end) {
1415 tprintf("...");
1416 break;
1417 }
1418 if (umoven(tcp, cur, sizeof(gid), (char *) &gid) < 0) {
1419 tprintf("?");
1420 failed = 1;
1421 break;
1422 }
1423 tprintf("%lu", (unsigned long) gid);
1424 }
1425 tprintf("]");
1426 if (failed)
1427 tprintf(" %#lx", tcp->u_arg[1]);
Roland McGrath83bd47a2003-11-13 22:32:26 +00001428 }
1429 return 0;
1430}
1431#endif /* LINUX */
1432
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001433#if defined(ALPHA) || defined(SUNOS4) || defined(SVR4)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001434int
1435sys_setpgrp(tcp)
1436struct tcb *tcp;
1437{
1438 if (entering(tcp)) {
1439#ifndef SVR4
1440 tprintf("%lu, %lu", tcp->u_arg[0], tcp->u_arg[1]);
1441#endif /* !SVR4 */
1442 }
1443 return 0;
1444}
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001445#endif /* ALPHA || SUNOS4 || SVR4 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001446
1447int
1448sys_getpgrp(tcp)
1449struct tcb *tcp;
1450{
1451 if (entering(tcp)) {
1452#ifndef SVR4
1453 tprintf("%lu", tcp->u_arg[0]);
1454#endif /* !SVR4 */
1455 }
1456 return 0;
1457}
1458
1459int
1460sys_getsid(tcp)
1461struct tcb *tcp;
1462{
1463 if (entering(tcp)) {
1464 tprintf("%lu", tcp->u_arg[0]);
1465 }
1466 return 0;
1467}
1468
1469int
1470sys_setsid(tcp)
1471struct tcb *tcp;
1472{
1473 return 0;
1474}
1475
1476int
1477sys_getpgid(tcp)
1478struct tcb *tcp;
1479{
1480 if (entering(tcp)) {
1481 tprintf("%lu", tcp->u_arg[0]);
1482 }
1483 return 0;
1484}
1485
1486int
1487sys_setpgid(tcp)
1488struct tcb *tcp;
1489{
1490 if (entering(tcp)) {
1491 tprintf("%lu, %lu", tcp->u_arg[0], tcp->u_arg[1]);
1492 }
1493 return 0;
1494}
1495
John Hughesc61eb3d2002-05-17 11:37:50 +00001496#if UNIXWARE >= 2
1497
1498#include <sys/privilege.h>
1499
1500
Roland McGrathd9f816f2004-09-04 03:39:20 +00001501static const struct xlat procpriv_cmds [] = {
John Hughesc61eb3d2002-05-17 11:37:50 +00001502 { SETPRV, "SETPRV" },
1503 { CLRPRV, "CLRPRV" },
1504 { PUTPRV, "PUTPRV" },
1505 { GETPRV, "GETPRV" },
1506 { CNTPRV, "CNTPRV" },
1507 { 0, NULL },
1508};
1509
1510
Roland McGrathd9f816f2004-09-04 03:39:20 +00001511static const struct xlat procpriv_priv [] = {
John Hughesc61eb3d2002-05-17 11:37:50 +00001512 { P_OWNER, "P_OWNER" },
1513 { P_AUDIT, "P_AUDIT" },
1514 { P_COMPAT, "P_COMPAT" },
1515 { P_DACREAD, "P_DACREAD" },
1516 { P_DACWRITE, "P_DACWRITE" },
1517 { P_DEV, "P_DEV" },
1518 { P_FILESYS, "P_FILESYS" },
1519 { P_MACREAD, "P_MACREAD" },
1520 { P_MACWRITE, "P_MACWRITE" },
1521 { P_MOUNT, "P_MOUNT" },
1522 { P_MULTIDIR, "P_MULTIDIR" },
1523 { P_SETPLEVEL, "P_SETPLEVEL" },
1524 { P_SETSPRIV, "P_SETSPRIV" },
1525 { P_SETUID, "P_SETUID" },
1526 { P_SYSOPS, "P_SYSOPS" },
1527 { P_SETUPRIV, "P_SETUPRIV" },
1528 { P_DRIVER, "P_DRIVER" },
1529 { P_RTIME, "P_RTIME" },
1530 { P_MACUPGRADE, "P_MACUPGRADE" },
1531 { P_FSYSRANGE, "P_FSYSRANGE" },
1532 { P_SETFLEVEL, "P_SETFLEVEL" },
1533 { P_AUDITWR, "P_AUDITWR" },
1534 { P_TSHAR, "P_TSHAR" },
1535 { P_PLOCK, "P_PLOCK" },
1536 { P_CORE, "P_CORE" },
1537 { P_LOADMOD, "P_LOADMOD" },
1538 { P_BIND, "P_BIND" },
1539 { P_ALLPRIVS, "P_ALLPRIVS" },
1540 { 0, NULL },
1541};
1542
1543
Roland McGrathd9f816f2004-09-04 03:39:20 +00001544static const struct xlat procpriv_type [] = {
John Hughesc61eb3d2002-05-17 11:37:50 +00001545 { PS_FIX, "PS_FIX" },
1546 { PS_INH, "PS_INH" },
1547 { PS_MAX, "PS_MAX" },
1548 { PS_WKG, "PS_WKG" },
1549 { 0, NULL },
1550};
1551
1552
1553static void
Dmitry V. Levinab9008b2007-01-11 22:05:04 +00001554printpriv(struct tcb *tcp, long addr, int len, const struct xlat *opt)
John Hughesc61eb3d2002-05-17 11:37:50 +00001555{
1556 priv_t buf [128];
1557 int max = verbose (tcp) ? sizeof buf / sizeof buf [0] : 10;
1558 int dots = len > max;
1559 int i;
Roland McGrath5a223472002-12-15 23:58:26 +00001560
John Hughesc61eb3d2002-05-17 11:37:50 +00001561 if (len > max) len = max;
Roland McGrath5a223472002-12-15 23:58:26 +00001562
John Hughesc61eb3d2002-05-17 11:37:50 +00001563 if (len <= 0 ||
1564 umoven (tcp, addr, len * sizeof buf[0], (char *) buf) < 0)
1565 {
1566 tprintf ("%#lx", addr);
1567 return;
1568 }
1569
1570 tprintf ("[");
1571
1572 for (i = 0; i < len; ++i) {
Dmitry V. Levinab9008b2007-01-11 22:05:04 +00001573 const char *t, *p;
John Hughesc61eb3d2002-05-17 11:37:50 +00001574
1575 if (i) tprintf (", ");
1576
1577 if ((t = xlookup (procpriv_type, buf [i] & PS_TYPE)) &&
1578 (p = xlookup (procpriv_priv, buf [i] & ~PS_TYPE)))
1579 {
1580 tprintf ("%s|%s", t, p);
1581 }
1582 else {
1583 tprintf ("%#lx", buf [i]);
1584 }
1585 }
1586
1587 if (dots) tprintf (" ...");
1588
1589 tprintf ("]");
1590}
1591
1592
1593int
1594sys_procpriv(tcp)
1595struct tcb *tcp;
1596{
1597 if (entering(tcp)) {
1598 printxval(procpriv_cmds, tcp->u_arg[0], "???PRV");
1599 switch (tcp->u_arg[0]) {
1600 case CNTPRV:
1601 tprintf(", %#lx, %ld", tcp->u_arg[1], tcp->u_arg[2]);
1602 break;
1603
1604 case GETPRV:
1605 break;
1606
1607 default:
1608 tprintf (", ");
1609 printpriv (tcp, tcp->u_arg[1], tcp->u_arg[2]);
1610 tprintf (", %ld", tcp->u_arg[2]);
1611 }
1612 }
1613 else if (tcp->u_arg[0] == GETPRV) {
1614 if (syserror (tcp)) {
1615 tprintf(", %#lx, %ld", tcp->u_arg[1], tcp->u_arg[2]);
1616 }
1617 else {
1618 tprintf (", ");
1619 printpriv (tcp, tcp->u_arg[1], tcp->u_rval);
1620 tprintf (", %ld", tcp->u_arg[2]);
1621 }
1622 }
Roland McGrath5a223472002-12-15 23:58:26 +00001623
John Hughesc61eb3d2002-05-17 11:37:50 +00001624 return 0;
1625}
1626
Dmitry V. Levine5e60852009-12-31 22:50:49 +00001627#endif /* UNIXWARE */
John Hughesc61eb3d2002-05-17 11:37:50 +00001628
1629
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001630static void
1631printargv(tcp, addr)
1632struct tcb *tcp;
1633long addr;
1634{
Roland McGrath85a3bc42007-08-02 02:13:05 +00001635 union {
Andreas Schwab99c85692009-08-28 19:36:20 +02001636 unsigned int p32;
1637 unsigned long p64;
Roland McGrath85a3bc42007-08-02 02:13:05 +00001638 char data[sizeof(long)];
1639 } cp;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001640 char *sep;
Roland McGrath85a3bc42007-08-02 02:13:05 +00001641 int n = 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001642
Roland McGrath85a3bc42007-08-02 02:13:05 +00001643 cp.p64 = 1;
1644 for (sep = ""; !abbrev(tcp) || n < max_strlen / 2; sep = ", ", ++n) {
1645 if (umoven(tcp, addr, personality_wordsize[current_personality],
1646 cp.data) < 0) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001647 tprintf("%#lx", addr);
1648 return;
1649 }
Roland McGrath85a3bc42007-08-02 02:13:05 +00001650 if (personality_wordsize[current_personality] == 4)
1651 cp.p64 = cp.p32;
1652 if (cp.p64 == 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001653 break;
Dmitry V. Levin4bcd5ef2009-06-01 10:32:27 +00001654 tprintf("%s", sep);
Roland McGrath85a3bc42007-08-02 02:13:05 +00001655 printstr(tcp, cp.p64, -1);
1656 addr += personality_wordsize[current_personality];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001657 }
Roland McGrath85a3bc42007-08-02 02:13:05 +00001658 if (cp.p64)
1659 tprintf("%s...", sep);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001660}
1661
1662static void
1663printargc(fmt, tcp, addr)
1664char *fmt;
1665struct tcb *tcp;
1666long addr;
1667{
1668 int count;
1669 char *cp;
1670
1671 for (count = 0; umove(tcp, addr, &cp) >= 0 && cp != NULL; count++) {
1672 addr += sizeof(char *);
1673 }
1674 tprintf(fmt, count, count == 1 ? "" : "s");
1675}
1676
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001677#if defined(SPARC) || defined(SPARC64) || defined(SUNOS4)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001678int
Dmitry V. Levine5e60852009-12-31 22:50:49 +00001679sys_execv(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001680{
1681 if (entering(tcp)) {
1682 printpath(tcp, tcp->u_arg[0]);
1683 if (!verbose(tcp))
1684 tprintf(", %#lx", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001685 else {
1686 tprintf(", [");
1687 printargv(tcp, tcp->u_arg[1]);
1688 tprintf("]");
1689 }
1690 }
1691 return 0;
1692}
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001693#endif /* SPARC || SPARC64 || SUNOS4 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001694
1695int
Dmitry V. Levine5e60852009-12-31 22:50:49 +00001696sys_execve(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001697{
1698 if (entering(tcp)) {
1699 printpath(tcp, tcp->u_arg[0]);
1700 if (!verbose(tcp))
1701 tprintf(", %#lx", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001702 else {
1703 tprintf(", [");
1704 printargv(tcp, tcp->u_arg[1]);
1705 tprintf("]");
1706 }
1707 if (!verbose(tcp))
1708 tprintf(", %#lx", tcp->u_arg[2]);
1709 else if (abbrev(tcp))
1710 printargc(", [/* %d var%s */]", tcp, tcp->u_arg[2]);
1711 else {
1712 tprintf(", [");
1713 printargv(tcp, tcp->u_arg[2]);
1714 tprintf("]");
1715 }
1716 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001717 return 0;
1718}
1719
Roland McGrath5ef24ab2004-02-20 02:22:35 +00001720#if UNIXWARE > 2
John Hughes4e36a812001-04-18 15:11:51 +00001721
1722int sys_rexecve(tcp)
1723struct tcb *tcp;
1724{
1725 if (entering (tcp)) {
1726 sys_execve (tcp);
1727 tprintf (", %ld", tcp->u_arg[3]);
1728 }
1729 return 0;
1730}
1731
Roland McGrath5ef24ab2004-02-20 02:22:35 +00001732#endif
John Hughes4e36a812001-04-18 15:11:51 +00001733
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001734int
1735internal_exec(tcp)
1736struct tcb *tcp;
1737{
1738#ifdef SUNOS4
1739 if (exiting(tcp) && !syserror(tcp) && followfork)
1740 fixvfork(tcp);
1741#endif /* SUNOS4 */
Roland McGrathfdb097f2004-07-12 07:38:55 +00001742#if defined LINUX && defined TCB_WAITEXECVE
1743 if (exiting(tcp) && syserror(tcp))
1744 tcp->flags &= ~TCB_WAITEXECVE;
1745 else
1746 tcp->flags |= TCB_WAITEXECVE;
1747#endif /* LINUX && TCB_WAITEXECVE */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001748 return 0;
1749}
1750
1751#ifdef LINUX
Roland McGrath7ec1d352002-12-17 04:50:44 +00001752#ifndef __WNOTHREAD
1753#define __WNOTHREAD 0x20000000
1754#endif
1755#ifndef __WALL
1756#define __WALL 0x40000000
1757#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001758#ifndef __WCLONE
Roland McGrath7ec1d352002-12-17 04:50:44 +00001759#define __WCLONE 0x80000000
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001760#endif
1761#endif /* LINUX */
1762
Roland McGrathd9f816f2004-09-04 03:39:20 +00001763static const struct xlat wait4_options[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001764 { WNOHANG, "WNOHANG" },
1765#ifndef WSTOPPED
1766 { WUNTRACED, "WUNTRACED" },
1767#endif
1768#ifdef WEXITED
1769 { WEXITED, "WEXITED" },
1770#endif
1771#ifdef WTRAPPED
1772 { WTRAPPED, "WTRAPPED" },
1773#endif
1774#ifdef WSTOPPED
1775 { WSTOPPED, "WSTOPPED" },
1776#endif
1777#ifdef WCONTINUED
1778 { WCONTINUED, "WCONTINUED" },
1779#endif
1780#ifdef WNOWAIT
1781 { WNOWAIT, "WNOWAIT" },
1782#endif
1783#ifdef __WCLONE
1784 { __WCLONE, "__WCLONE" },
1785#endif
Roland McGrath7ec1d352002-12-17 04:50:44 +00001786#ifdef __WALL
1787 { __WALL, "__WALL" },
1788#endif
1789#ifdef __WNOTHREAD
1790 { __WNOTHREAD, "__WNOTHREAD" },
1791#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001792 { 0, NULL },
1793};
1794
Roland McGrath5e02a572004-10-19 23:33:47 +00001795#if !defined WCOREFLAG && defined WCOREFLG
1796# define WCOREFLAG WCOREFLG
1797#endif
1798#ifndef WCOREFLAG
Dmitry V. Levine5e60852009-12-31 22:50:49 +00001799# define WCOREFLAG 0x80
Roland McGrath5e02a572004-10-19 23:33:47 +00001800#endif
Dmitry V. Levine5e60852009-12-31 22:50:49 +00001801#ifndef WCOREDUMP
1802# define WCOREDUMP(status) ((status) & 0200)
1803#endif
1804
Roland McGrath5e02a572004-10-19 23:33:47 +00001805
1806#ifndef W_STOPCODE
1807#define W_STOPCODE(sig) ((sig) << 8 | 0x7f)
1808#endif
1809#ifndef W_EXITCODE
1810#define W_EXITCODE(ret, sig) ((ret) << 8 | (sig))
1811#endif
1812
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001813static int
1814printstatus(status)
1815int status;
1816{
1817 int exited = 0;
1818
1819 /*
1820 * Here is a tricky presentation problem. This solution
1821 * is still not entirely satisfactory but since there
1822 * are no wait status constructors it will have to do.
1823 */
Roland McGrath79fbda52004-04-14 02:45:55 +00001824 if (WIFSTOPPED(status)) {
1825 tprintf("[{WIFSTOPPED(s) && WSTOPSIG(s) == %s}",
Nate Sammonsce780fc1999-03-29 23:23:13 +00001826 signame(WSTOPSIG(status)));
Roland McGrath79fbda52004-04-14 02:45:55 +00001827 status &= ~W_STOPCODE(WSTOPSIG(status));
1828 }
1829 else if (WIFSIGNALED(status)) {
1830 tprintf("[{WIFSIGNALED(s) && WTERMSIG(s) == %s%s}",
Nate Sammonsce780fc1999-03-29 23:23:13 +00001831 signame(WTERMSIG(status)),
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001832 WCOREDUMP(status) ? " && WCOREDUMP(s)" : "");
Roland McGrath79fbda52004-04-14 02:45:55 +00001833 status &= ~(W_EXITCODE(0, WTERMSIG(status)) | WCOREFLAG);
1834 }
1835 else if (WIFEXITED(status)) {
1836 tprintf("[{WIFEXITED(s) && WEXITSTATUS(s) == %d}",
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001837 WEXITSTATUS(status));
1838 exited = 1;
Roland McGrath79fbda52004-04-14 02:45:55 +00001839 status &= ~W_EXITCODE(WEXITSTATUS(status), 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001840 }
Roland McGrath79fbda52004-04-14 02:45:55 +00001841 else {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001842 tprintf("[%#x]", status);
Roland McGrath79fbda52004-04-14 02:45:55 +00001843 return 0;
1844 }
1845
1846 if (status == 0)
1847 tprintf("]");
1848 else
Roland McGrathf8cc83c2004-06-04 01:24:07 +00001849 tprintf(" | %#x]", status);
Roland McGrath79fbda52004-04-14 02:45:55 +00001850
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001851 return exited;
1852}
1853
1854static int
Denys Vlasenko59432db2009-01-26 19:09:35 +00001855printwaitn(struct tcb *tcp, int n, int bitness)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001856{
1857 int status;
1858 int exited = 0;
1859
1860 if (entering(tcp)) {
Denys Vlasenkoe740fd32009-04-16 12:06:16 +00001861#ifdef LINUX
1862 /* On Linux, kernel-side pid_t is typedef'ed to int
1863 * on all arches. Also, glibc-2.8 truncates wait3 and wait4
Denys Vlasenko59432db2009-01-26 19:09:35 +00001864 * pid argument to int on 64bit arches, producing,
1865 * for example, wait4(4294967295, ...) instead of -1
Denys Vlasenkoe740fd32009-04-16 12:06:16 +00001866 * in strace. We have to use int here, not long.
1867 */
1868 int pid = tcp->u_arg[0];
1869 tprintf("%d, ", pid);
1870#else
1871 /*
1872 * Sign-extend a 32-bit value when that's what it is.
Roland McGrath5b63d962008-07-18 02:16:47 +00001873 */
1874 long pid = tcp->u_arg[0];
1875 if (personality_wordsize[current_personality] < sizeof pid)
1876 pid = (long) (int) pid;
1877 tprintf("%ld, ", pid);
Denys Vlasenkoe740fd32009-04-16 12:06:16 +00001878#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001879 } else {
1880 /* status */
1881 if (!tcp->u_arg[1])
1882 tprintf("NULL");
1883 else if (syserror(tcp) || tcp->u_rval == 0)
1884 tprintf("%#lx", tcp->u_arg[1]);
1885 else if (umove(tcp, tcp->u_arg[1], &status) < 0)
1886 tprintf("[?]");
1887 else
1888 exited = printstatus(status);
1889 /* options */
1890 tprintf(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +00001891 printflags(wait4_options, tcp->u_arg[2], "W???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001892 if (n == 4) {
1893 tprintf(", ");
1894 /* usage */
1895 if (!tcp->u_arg[3])
1896 tprintf("NULL");
1897#ifdef LINUX
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001898 else if (tcp->u_rval > 0) {
Denys Vlasenko59432db2009-01-26 19:09:35 +00001899#ifdef ALPHA
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001900 if (bitness)
1901 printrusage32(tcp, tcp->u_arg[3]);
1902 else
1903#endif
1904 printrusage(tcp, tcp->u_arg[3]);
1905 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001906#endif /* LINUX */
1907#ifdef SUNOS4
1908 else if (tcp->u_rval > 0 && exited)
1909 printrusage(tcp, tcp->u_arg[3]);
1910#endif /* SUNOS4 */
1911 else
1912 tprintf("%#lx", tcp->u_arg[3]);
1913 }
1914 }
1915 return 0;
1916}
1917
1918int
Roland McGrathc74c0b72004-09-01 19:39:46 +00001919internal_wait(tcp, flagarg)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001920struct tcb *tcp;
Roland McGrathc74c0b72004-09-01 19:39:46 +00001921int flagarg;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001922{
Roland McGrathe85bbfe2003-01-09 06:53:31 +00001923 int got_kids;
1924
1925#ifdef TCB_CLONE_THREAD
1926 if (tcp->flags & TCB_CLONE_THREAD)
1927 /* The children we wait for are our parent's children. */
1928 got_kids = (tcp->parent->nchildren
Wang Chao21b8db42010-08-27 17:43:16 +08001929 > tcp->parent->nclone_threads);
Roland McGrathe85bbfe2003-01-09 06:53:31 +00001930 else
Wang Chao21b8db42010-08-27 17:43:16 +08001931 got_kids = (tcp->nchildren > tcp->nclone_threads);
Roland McGrathe85bbfe2003-01-09 06:53:31 +00001932#else
1933 got_kids = tcp->nchildren > 0;
1934#endif
1935
1936 if (entering(tcp) && got_kids) {
Roland McGrathb69f81b2002-12-21 23:25:18 +00001937 /* There are children that this parent should block for.
1938 But ptrace made us the parent of the traced children
1939 and the real parent will get ECHILD from the wait call.
1940
1941 XXX If we attached with strace -f -p PID, then there
1942 may be untraced dead children the parent could be reaping
1943 now, but we make him block. */
1944
1945 /* ??? WTA: fix bug with hanging children */
1946
Roland McGrathc74c0b72004-09-01 19:39:46 +00001947 if (!(tcp->u_arg[flagarg] & WNOHANG)) {
Roland McGrath09623452003-05-23 02:27:13 +00001948 /*
1949 * There are traced children. We'll make the parent
1950 * block to avoid a false ECHILD error due to our
1951 * ptrace having stolen the children. However,
1952 * we shouldn't block if there are zombies to reap.
1953 * XXX doesn't handle pgrp matches (u_arg[0]==0,<-1)
1954 */
Roland McGrathfccfb942003-10-01 21:59:44 +00001955 struct tcb *child = NULL;
Roland McGrath09623452003-05-23 02:27:13 +00001956 if (tcp->nzombies > 0 &&
1957 (tcp->u_arg[0] == -1 ||
Roland McGrathfccfb942003-10-01 21:59:44 +00001958 (child = pid2tcb(tcp->u_arg[0])) == NULL))
Roland McGrath09623452003-05-23 02:27:13 +00001959 return 0;
Roland McGrathfccfb942003-10-01 21:59:44 +00001960 if (tcp->u_arg[0] > 0) {
1961 /*
1962 * If the parent waits for a specified child
1963 * PID, then it must get ECHILD right away
1964 * if that PID is not one of its children.
1965 * Make sure that the requested PID matches
1966 * one of the parent's children that we are
1967 * tracing, and don't suspend it otherwise.
1968 */
1969 if (child == NULL)
1970 child = pid2tcb(tcp->u_arg[0]);
1971 if (child == NULL || child->parent != (
1972#ifdef TCB_CLONE_THREAD
1973 (tcp->flags & TCB_CLONE_THREAD)
1974 ? tcp->parent :
1975#endif
Roland McGrathd56a6562005-08-03 11:23:43 +00001976 tcp) ||
1977 (child->flags & TCB_EXITING))
Roland McGrathfccfb942003-10-01 21:59:44 +00001978 return 0;
1979 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001980 tcp->flags |= TCB_SUSPENDED;
1981 tcp->waitpid = tcp->u_arg[0];
Roland McGrathe85bbfe2003-01-09 06:53:31 +00001982#ifdef TCB_CLONE_THREAD
1983 if (tcp->flags & TCB_CLONE_THREAD)
1984 tcp->parent->nclone_waiting++;
1985#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001986 }
1987 }
Roland McGrathe85bbfe2003-01-09 06:53:31 +00001988 if (exiting(tcp) && tcp->u_error == ECHILD && got_kids) {
Roland McGrathc74c0b72004-09-01 19:39:46 +00001989 if (tcp->u_arg[flagarg] & WNOHANG) {
Roland McGrathb69f81b2002-12-21 23:25:18 +00001990 /* We must force a fake result of 0 instead of
1991 the ECHILD error. */
Roland McGrathb69f81b2002-12-21 23:25:18 +00001992 return force_result(tcp, 0, 0);
1993 }
Roland McGrathb69f81b2002-12-21 23:25:18 +00001994 }
Roland McGrath09623452003-05-23 02:27:13 +00001995 else if (exiting(tcp) && tcp->u_error == 0 && tcp->u_rval > 0 &&
1996 tcp->nzombies > 0 && pid2tcb(tcp->u_rval) == NULL) {
1997 /*
1998 * We just reaped a child we don't know about,
1999 * presumably a zombie we already droptcb'd.
2000 */
2001 tcp->nzombies--;
2002 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002003 return 0;
2004}
2005
2006#ifdef SVR4
2007
2008int
2009sys_wait(tcp)
2010struct tcb *tcp;
2011{
2012 if (exiting(tcp)) {
2013 /* The library wrapper stuffs this into the user variable. */
2014 if (!syserror(tcp))
2015 printstatus(getrval2(tcp));
2016 }
2017 return 0;
2018}
2019
2020#endif /* SVR4 */
2021
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002022#ifdef FREEBSD
2023int
2024sys_wait(tcp)
2025struct tcb *tcp;
2026{
2027 int status;
Roland McGrath5a223472002-12-15 23:58:26 +00002028
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002029 if (exiting(tcp)) {
2030 if (!syserror(tcp)) {
2031 if (umove(tcp, tcp->u_arg[0], &status) < 0)
2032 tprintf("%#lx", tcp->u_arg[0]);
2033 else
2034 printstatus(status);
2035 }
2036 }
2037 return 0;
2038}
2039#endif
2040
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002041int
2042sys_waitpid(tcp)
2043struct tcb *tcp;
2044{
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00002045 return printwaitn(tcp, 3, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002046}
2047
2048int
2049sys_wait4(tcp)
2050struct tcb *tcp;
2051{
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00002052 return printwaitn(tcp, 4, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002053}
2054
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00002055#ifdef ALPHA
2056int
2057sys_osf_wait4(tcp)
2058struct tcb *tcp;
2059{
2060 return printwaitn(tcp, 4, 1);
2061}
2062#endif
2063
Roland McGrathc74c0b72004-09-01 19:39:46 +00002064#if defined SVR4 || defined LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002065
Roland McGrathd9f816f2004-09-04 03:39:20 +00002066static const struct xlat waitid_types[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002067 { P_PID, "P_PID" },
Roland McGrathc74c0b72004-09-01 19:39:46 +00002068#ifdef P_PPID
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002069 { P_PPID, "P_PPID" },
Roland McGrathc74c0b72004-09-01 19:39:46 +00002070#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002071 { P_PGID, "P_PGID" },
Roland McGrathc74c0b72004-09-01 19:39:46 +00002072#ifdef P_SID
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002073 { P_SID, "P_SID" },
Roland McGrathc74c0b72004-09-01 19:39:46 +00002074#endif
2075#ifdef P_CID
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002076 { P_CID, "P_CID" },
Roland McGrathc74c0b72004-09-01 19:39:46 +00002077#endif
2078#ifdef P_UID
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002079 { P_UID, "P_UID" },
Roland McGrathc74c0b72004-09-01 19:39:46 +00002080#endif
2081#ifdef P_GID
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002082 { P_GID, "P_GID" },
Roland McGrathc74c0b72004-09-01 19:39:46 +00002083#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002084 { P_ALL, "P_ALL" },
2085#ifdef P_LWPID
2086 { P_LWPID, "P_LWPID" },
2087#endif
2088 { 0, NULL },
2089};
2090
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002091int
2092sys_waitid(tcp)
2093struct tcb *tcp;
2094{
2095 siginfo_t si;
2096 int exited;
2097
2098 if (entering(tcp)) {
2099 printxval(waitid_types, tcp->u_arg[0], "P_???");
2100 tprintf(", %ld, ", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002101 }
2102 else {
2103 /* siginfo */
2104 exited = 0;
2105 if (!tcp->u_arg[2])
2106 tprintf("NULL");
2107 else if (syserror(tcp))
2108 tprintf("%#lx", tcp->u_arg[2]);
2109 else if (umove(tcp, tcp->u_arg[2], &si) < 0)
2110 tprintf("{???}");
2111 else
Denys Vlasenkof535b542009-01-13 18:30:55 +00002112 printsiginfo(&si, verbose(tcp));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002113 /* options */
2114 tprintf(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +00002115 printflags(wait4_options, tcp->u_arg[3], "W???");
Roland McGrath39426a32004-10-06 22:02:59 +00002116 if (tcp->u_nargs > 4) {
2117 /* usage */
2118 tprintf(", ");
2119 if (!tcp->u_arg[4])
2120 tprintf("NULL");
2121 else if (tcp->u_error)
2122 tprintf("%#lx", tcp->u_arg[4]);
2123 else
2124 printrusage(tcp, tcp->u_arg[4]);
2125 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002126 }
2127 return 0;
2128}
2129
Roland McGrathc74c0b72004-09-01 19:39:46 +00002130#endif /* SVR4 or LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002131
2132int
2133sys_alarm(tcp)
2134struct tcb *tcp;
2135{
2136 if (entering(tcp))
2137 tprintf("%lu", tcp->u_arg[0]);
2138 return 0;
2139}
2140
2141int
2142sys_uname(tcp)
2143struct tcb *tcp;
2144{
2145 struct utsname uname;
2146
2147 if (exiting(tcp)) {
2148 if (syserror(tcp) || !verbose(tcp))
2149 tprintf("%#lx", tcp->u_arg[0]);
2150 else if (umove(tcp, tcp->u_arg[0], &uname) < 0)
2151 tprintf("{...}");
2152 else if (!abbrev(tcp)) {
2153
2154 tprintf("{sysname=\"%s\", nodename=\"%s\", ",
2155 uname.sysname, uname.nodename);
2156 tprintf("release=\"%s\", version=\"%s\", ",
2157 uname.release, uname.version);
2158 tprintf("machine=\"%s\"", uname.machine);
2159#ifdef LINUX
2160#ifndef __GLIBC__
2161 tprintf(", domainname=\"%s\"", uname.domainname);
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002162#endif
2163#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002164 tprintf("}");
2165 }
2166 else
2167 tprintf("{sys=\"%s\", node=\"%s\", ...}",
2168 uname.sysname, uname.nodename);
2169 }
2170 return 0;
2171}
2172
2173#ifndef SVR4
2174
Roland McGratheb9e2e82009-06-02 16:49:22 -07002175static const struct xlat ptrace_cmds[] = {
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002176# ifndef FREEBSD
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002177 { PTRACE_TRACEME, "PTRACE_TRACEME" },
2178 { PTRACE_PEEKTEXT, "PTRACE_PEEKTEXT", },
2179 { PTRACE_PEEKDATA, "PTRACE_PEEKDATA", },
2180 { PTRACE_PEEKUSER, "PTRACE_PEEKUSER", },
2181 { PTRACE_POKETEXT, "PTRACE_POKETEXT", },
2182 { PTRACE_POKEDATA, "PTRACE_POKEDATA", },
2183 { PTRACE_POKEUSER, "PTRACE_POKEUSER", },
2184 { PTRACE_CONT, "PTRACE_CONT" },
2185 { PTRACE_KILL, "PTRACE_KILL" },
2186 { PTRACE_SINGLESTEP, "PTRACE_SINGLESTEP" },
2187 { PTRACE_ATTACH, "PTRACE_ATTACH" },
2188 { PTRACE_DETACH, "PTRACE_DETACH" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002189# ifdef PTRACE_GETREGS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002190 { PTRACE_GETREGS, "PTRACE_GETREGS" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002191# endif
2192# ifdef PTRACE_SETREGS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002193 { PTRACE_SETREGS, "PTRACE_SETREGS" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002194# endif
2195# ifdef PTRACE_GETFPREGS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002196 { PTRACE_GETFPREGS, "PTRACE_GETFPREGS", },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002197# endif
2198# ifdef PTRACE_SETFPREGS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002199 { PTRACE_SETFPREGS, "PTRACE_SETFPREGS", },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002200# endif
2201# ifdef PTRACE_GETFPXREGS
Roland McGrathbf621d42003-01-14 09:46:21 +00002202 { PTRACE_GETFPXREGS, "PTRACE_GETFPXREGS", },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002203# endif
2204# ifdef PTRACE_SETFPXREGS
Roland McGrathbf621d42003-01-14 09:46:21 +00002205 { PTRACE_SETFPXREGS, "PTRACE_SETFPXREGS", },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002206# endif
2207# ifdef PTRACE_GETVRREGS
Roland McGrathf04bb482005-05-09 07:45:33 +00002208 { PTRACE_GETVRREGS, "PTRACE_GETVRREGS", },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002209# endif
2210# ifdef PTRACE_SETVRREGS
Roland McGrathf04bb482005-05-09 07:45:33 +00002211 { PTRACE_SETVRREGS, "PTRACE_SETVRREGS", },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002212# endif
2213# ifdef PTRACE_SETOPTIONS
Denys Vlasenkof535b542009-01-13 18:30:55 +00002214 { PTRACE_SETOPTIONS, "PTRACE_SETOPTIONS", },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002215# endif
2216# ifdef PTRACE_GETEVENTMSG
Denys Vlasenkof535b542009-01-13 18:30:55 +00002217 { PTRACE_GETEVENTMSG, "PTRACE_GETEVENTMSG", },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002218# endif
2219# ifdef PTRACE_GETSIGINFO
Denys Vlasenkof535b542009-01-13 18:30:55 +00002220 { PTRACE_GETSIGINFO, "PTRACE_GETSIGINFO", },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002221# endif
2222# ifdef PTRACE_SETSIGINFO
Denys Vlasenkof535b542009-01-13 18:30:55 +00002223 { PTRACE_SETSIGINFO, "PTRACE_SETSIGINFO", },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002224# endif
2225# ifdef PTRACE_SET_SYSCALL
2226 { PTRACE_SET_SYSCALL, "PTRACE_SET_SYSCALL", },
2227# endif
2228# ifdef SUNOS4
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002229 { PTRACE_READDATA, "PTRACE_READDATA" },
2230 { PTRACE_WRITEDATA, "PTRACE_WRITEDATA" },
2231 { PTRACE_READTEXT, "PTRACE_READTEXT" },
2232 { PTRACE_WRITETEXT, "PTRACE_WRITETEXT" },
2233 { PTRACE_GETFPAREGS, "PTRACE_GETFPAREGS" },
2234 { PTRACE_SETFPAREGS, "PTRACE_SETFPAREGS" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002235# ifdef SPARC
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002236 { PTRACE_GETWINDOW, "PTRACE_GETWINDOW" },
2237 { PTRACE_SETWINDOW, "PTRACE_SETWINDOW" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002238# else /* !SPARC */
2239 { PTRACE_22, "PTRACE_22" },
2240 { PTRACE_23, "PTRACE_3" },
2241# endif /* !SPARC */
2242# endif /* SUNOS4 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002243 { PTRACE_SYSCALL, "PTRACE_SYSCALL" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002244# ifdef SUNOS4
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002245 { PTRACE_DUMPCORE, "PTRACE_DUMPCORE" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002246# ifdef I386
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002247 { PTRACE_SETWRBKPT, "PTRACE_SETWRBKPT" },
2248 { PTRACE_SETACBKPT, "PTRACE_SETACBKPT" },
2249 { PTRACE_CLRDR7, "PTRACE_CLRDR7" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002250# else /* !I386 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002251 { PTRACE_26, "PTRACE_26" },
2252 { PTRACE_27, "PTRACE_27" },
2253 { PTRACE_28, "PTRACE_28" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002254# endif /* !I386 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002255 { PTRACE_GETUCODE, "PTRACE_GETUCODE" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002256# endif /* SUNOS4 */
Denys Vlasenkof535b542009-01-13 18:30:55 +00002257
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002258# else /* FREEBSD */
Denys Vlasenkof535b542009-01-13 18:30:55 +00002259
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002260 { PT_TRACE_ME, "PT_TRACE_ME" },
2261 { PT_READ_I, "PT_READ_I" },
2262 { PT_READ_D, "PT_READ_D" },
2263 { PT_WRITE_I, "PT_WRITE_I" },
2264 { PT_WRITE_D, "PT_WRITE_D" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002265# ifdef PT_READ_U
John Hughesa2278142001-09-28 16:21:30 +00002266 { PT_READ_U, "PT_READ_U" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002267# endif
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002268 { PT_CONTINUE, "PT_CONTINUE" },
2269 { PT_KILL, "PT_KILL" },
2270 { PT_STEP, "PT_STEP" },
2271 { PT_ATTACH, "PT_ATTACH" },
2272 { PT_DETACH, "PT_DETACH" },
2273 { PT_GETREGS, "PT_GETREGS" },
2274 { PT_SETREGS, "PT_SETREGS" },
2275 { PT_GETFPREGS, "PT_GETFPREGS" },
2276 { PT_SETFPREGS, "PT_SETFPREGS" },
2277 { PT_GETDBREGS, "PT_GETDBREGS" },
2278 { PT_SETDBREGS, "PT_SETDBREGS" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002279# endif /* FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002280 { 0, NULL },
2281};
2282
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002283# ifndef FREEBSD
2284# ifdef PTRACE_SETOPTIONS
Denys Vlasenkof535b542009-01-13 18:30:55 +00002285static const struct xlat ptrace_setoptions_flags[] = {
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002286# ifdef PTRACE_O_TRACESYSGOOD
Denys Vlasenkof535b542009-01-13 18:30:55 +00002287 { PTRACE_O_TRACESYSGOOD,"PTRACE_O_TRACESYSGOOD" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002288# endif
2289# ifdef PTRACE_O_TRACEFORK
Denys Vlasenkof535b542009-01-13 18:30:55 +00002290 { PTRACE_O_TRACEFORK, "PTRACE_O_TRACEFORK" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002291# endif
2292# ifdef PTRACE_O_TRACEVFORK
Denys Vlasenkof535b542009-01-13 18:30:55 +00002293 { PTRACE_O_TRACEVFORK, "PTRACE_O_TRACEVFORK" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002294# endif
2295# ifdef PTRACE_O_TRACECLONE
Denys Vlasenkof535b542009-01-13 18:30:55 +00002296 { PTRACE_O_TRACECLONE, "PTRACE_O_TRACECLONE" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002297# endif
2298# ifdef PTRACE_O_TRACEEXEC
Denys Vlasenkof535b542009-01-13 18:30:55 +00002299 { PTRACE_O_TRACEEXEC, "PTRACE_O_TRACEEXEC" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002300# endif
2301# ifdef PTRACE_O_TRACEVFORKDONE
Denys Vlasenkof535b542009-01-13 18:30:55 +00002302 { PTRACE_O_TRACEVFORKDONE,"PTRACE_O_TRACEVFORKDONE"},
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002303# endif
2304# ifdef PTRACE_O_TRACEEXIT
Denys Vlasenkof535b542009-01-13 18:30:55 +00002305 { PTRACE_O_TRACEEXIT, "PTRACE_O_TRACEEXIT" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002306# endif
Denys Vlasenkof535b542009-01-13 18:30:55 +00002307 { 0, NULL },
2308};
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002309# endif /* PTRACE_SETOPTIONS */
2310# endif /* !FREEBSD */
Denys Vlasenkof535b542009-01-13 18:30:55 +00002311
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002312# ifndef FREEBSD
Roland McGrathd9f816f2004-09-04 03:39:20 +00002313const struct xlat struct_user_offsets[] = {
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002314# ifdef LINUX
2315# if defined(S390) || defined(S390X)
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00002316 { PT_PSWMASK, "psw_mask" },
2317 { PT_PSWADDR, "psw_addr" },
2318 { PT_GPR0, "gpr0" },
2319 { PT_GPR1, "gpr1" },
2320 { PT_GPR2, "gpr2" },
2321 { PT_GPR3, "gpr3" },
2322 { PT_GPR4, "gpr4" },
2323 { PT_GPR5, "gpr5" },
2324 { PT_GPR6, "gpr6" },
2325 { PT_GPR7, "gpr7" },
2326 { PT_GPR8, "gpr8" },
2327 { PT_GPR9, "gpr9" },
2328 { PT_GPR10, "gpr10" },
2329 { PT_GPR11, "gpr11" },
2330 { PT_GPR12, "gpr12" },
2331 { PT_GPR13, "gpr13" },
2332 { PT_GPR14, "gpr14" },
2333 { PT_GPR15, "gpr15" },
2334 { PT_ACR0, "acr0" },
2335 { PT_ACR1, "acr1" },
2336 { PT_ACR2, "acr2" },
2337 { PT_ACR3, "acr3" },
2338 { PT_ACR4, "acr4" },
2339 { PT_ACR5, "acr5" },
2340 { PT_ACR6, "acr6" },
2341 { PT_ACR7, "acr7" },
2342 { PT_ACR8, "acr8" },
2343 { PT_ACR9, "acr9" },
2344 { PT_ACR10, "acr10" },
2345 { PT_ACR11, "acr11" },
2346 { PT_ACR12, "acr12" },
2347 { PT_ACR13, "acr13" },
2348 { PT_ACR14, "acr14" },
2349 { PT_ACR15, "acr15" },
2350 { PT_ORIGGPR2, "orig_gpr2" },
2351 { PT_FPC, "fpc" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002352# if defined(S390)
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00002353 { PT_FPR0_HI, "fpr0.hi" },
2354 { PT_FPR0_LO, "fpr0.lo" },
2355 { PT_FPR1_HI, "fpr1.hi" },
2356 { PT_FPR1_LO, "fpr1.lo" },
2357 { PT_FPR2_HI, "fpr2.hi" },
2358 { PT_FPR2_LO, "fpr2.lo" },
2359 { PT_FPR3_HI, "fpr3.hi" },
2360 { PT_FPR3_LO, "fpr3.lo" },
2361 { PT_FPR4_HI, "fpr4.hi" },
2362 { PT_FPR4_LO, "fpr4.lo" },
2363 { PT_FPR5_HI, "fpr5.hi" },
2364 { PT_FPR5_LO, "fpr5.lo" },
2365 { PT_FPR6_HI, "fpr6.hi" },
2366 { PT_FPR6_LO, "fpr6.lo" },
2367 { PT_FPR7_HI, "fpr7.hi" },
2368 { PT_FPR7_LO, "fpr7.lo" },
2369 { PT_FPR8_HI, "fpr8.hi" },
2370 { PT_FPR8_LO, "fpr8.lo" },
2371 { PT_FPR9_HI, "fpr9.hi" },
2372 { PT_FPR9_LO, "fpr9.lo" },
2373 { PT_FPR10_HI, "fpr10.hi" },
2374 { PT_FPR10_LO, "fpr10.lo" },
2375 { PT_FPR11_HI, "fpr11.hi" },
2376 { PT_FPR11_LO, "fpr11.lo" },
2377 { PT_FPR12_HI, "fpr12.hi" },
2378 { PT_FPR12_LO, "fpr12.lo" },
2379 { PT_FPR13_HI, "fpr13.hi" },
2380 { PT_FPR13_LO, "fpr13.lo" },
2381 { PT_FPR14_HI, "fpr14.hi" },
2382 { PT_FPR14_LO, "fpr14.lo" },
2383 { PT_FPR15_HI, "fpr15.hi" },
2384 { PT_FPR15_LO, "fpr15.lo" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002385# endif
2386# if defined(S390X)
Michal Ludvig10a88d02002-10-07 14:31:00 +00002387 { PT_FPR0, "fpr0" },
2388 { PT_FPR1, "fpr1" },
2389 { PT_FPR2, "fpr2" },
2390 { PT_FPR3, "fpr3" },
2391 { PT_FPR4, "fpr4" },
2392 { PT_FPR5, "fpr5" },
2393 { PT_FPR6, "fpr6" },
2394 { PT_FPR7, "fpr7" },
2395 { PT_FPR8, "fpr8" },
2396 { PT_FPR9, "fpr9" },
2397 { PT_FPR10, "fpr10" },
2398 { PT_FPR11, "fpr11" },
2399 { PT_FPR12, "fpr12" },
2400 { PT_FPR13, "fpr13" },
2401 { PT_FPR14, "fpr14" },
2402 { PT_FPR15, "fpr15" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002403# endif
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00002404 { PT_CR_9, "cr9" },
2405 { PT_CR_10, "cr10" },
2406 { PT_CR_11, "cr11" },
Michal Ludvig10a88d02002-10-07 14:31:00 +00002407 { PT_IEEE_IP, "ieee_exception_ip" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002408# elif defined(SPARC)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002409 /* XXX No support for these offsets yet. */
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002410# elif defined(HPPA)
Wichert Akkermanc1652e22001-03-27 12:17:16 +00002411 /* XXX No support for these offsets yet. */
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002412# elif defined(POWERPC)
2413# ifndef PT_ORIG_R3
2414# define PT_ORIG_R3 34
2415# endif
2416# define REGSIZE (sizeof(unsigned long))
Roland McGratheb285352003-01-14 09:59:00 +00002417 { REGSIZE*PT_R0, "r0" },
2418 { REGSIZE*PT_R1, "r1" },
2419 { REGSIZE*PT_R2, "r2" },
2420 { REGSIZE*PT_R3, "r3" },
2421 { REGSIZE*PT_R4, "r4" },
2422 { REGSIZE*PT_R5, "r5" },
2423 { REGSIZE*PT_R6, "r6" },
2424 { REGSIZE*PT_R7, "r7" },
2425 { REGSIZE*PT_R8, "r8" },
2426 { REGSIZE*PT_R9, "r9" },
2427 { REGSIZE*PT_R10, "r10" },
2428 { REGSIZE*PT_R11, "r11" },
2429 { REGSIZE*PT_R12, "r12" },
2430 { REGSIZE*PT_R13, "r13" },
2431 { REGSIZE*PT_R14, "r14" },
2432 { REGSIZE*PT_R15, "r15" },
2433 { REGSIZE*PT_R16, "r16" },
2434 { REGSIZE*PT_R17, "r17" },
2435 { REGSIZE*PT_R18, "r18" },
2436 { REGSIZE*PT_R19, "r19" },
2437 { REGSIZE*PT_R20, "r20" },
2438 { REGSIZE*PT_R21, "r21" },
2439 { REGSIZE*PT_R22, "r22" },
2440 { REGSIZE*PT_R23, "r23" },
2441 { REGSIZE*PT_R24, "r24" },
2442 { REGSIZE*PT_R25, "r25" },
2443 { REGSIZE*PT_R26, "r26" },
2444 { REGSIZE*PT_R27, "r27" },
2445 { REGSIZE*PT_R28, "r28" },
2446 { REGSIZE*PT_R29, "r29" },
2447 { REGSIZE*PT_R30, "r30" },
2448 { REGSIZE*PT_R31, "r31" },
2449 { REGSIZE*PT_NIP, "NIP" },
2450 { REGSIZE*PT_MSR, "MSR" },
2451 { REGSIZE*PT_ORIG_R3, "ORIG_R3" },
2452 { REGSIZE*PT_CTR, "CTR" },
2453 { REGSIZE*PT_LNK, "LNK" },
2454 { REGSIZE*PT_XER, "XER" },
2455 { REGSIZE*PT_CCR, "CCR" },
2456 { REGSIZE*PT_FPR0, "FPR0" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002457# undef REGSIZE
2458# elif defined(ALPHA)
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00002459 { 0, "r0" },
2460 { 1, "r1" },
2461 { 2, "r2" },
2462 { 3, "r3" },
2463 { 4, "r4" },
2464 { 5, "r5" },
2465 { 6, "r6" },
2466 { 7, "r7" },
2467 { 8, "r8" },
2468 { 9, "r9" },
2469 { 10, "r10" },
2470 { 11, "r11" },
2471 { 12, "r12" },
2472 { 13, "r13" },
2473 { 14, "r14" },
2474 { 15, "r15" },
2475 { 16, "r16" },
2476 { 17, "r17" },
2477 { 18, "r18" },
2478 { 19, "r19" },
2479 { 20, "r20" },
2480 { 21, "r21" },
2481 { 22, "r22" },
2482 { 23, "r23" },
2483 { 24, "r24" },
2484 { 25, "r25" },
2485 { 26, "r26" },
2486 { 27, "r27" },
2487 { 28, "r28" },
2488 { 29, "gp" },
2489 { 30, "fp" },
2490 { 31, "zero" },
2491 { 32, "fp0" },
2492 { 33, "fp" },
2493 { 34, "fp2" },
2494 { 35, "fp3" },
2495 { 36, "fp4" },
2496 { 37, "fp5" },
2497 { 38, "fp6" },
2498 { 39, "fp7" },
2499 { 40, "fp8" },
2500 { 41, "fp9" },
2501 { 42, "fp10" },
2502 { 43, "fp11" },
2503 { 44, "fp12" },
2504 { 45, "fp13" },
2505 { 46, "fp14" },
2506 { 47, "fp15" },
2507 { 48, "fp16" },
2508 { 49, "fp17" },
2509 { 50, "fp18" },
2510 { 51, "fp19" },
2511 { 52, "fp20" },
2512 { 53, "fp21" },
2513 { 54, "fp22" },
2514 { 55, "fp23" },
2515 { 56, "fp24" },
2516 { 57, "fp25" },
2517 { 58, "fp26" },
2518 { 59, "fp27" },
2519 { 60, "fp28" },
2520 { 61, "fp29" },
2521 { 62, "fp30" },
2522 { 63, "fp31" },
2523 { 64, "pc" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002524# elif defined(IA64)
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00002525 { PT_F32, "f32" }, { PT_F33, "f33" }, { PT_F34, "f34" },
2526 { PT_F35, "f35" }, { PT_F36, "f36" }, { PT_F37, "f37" },
2527 { PT_F38, "f38" }, { PT_F39, "f39" }, { PT_F40, "f40" },
2528 { PT_F41, "f41" }, { PT_F42, "f42" }, { PT_F43, "f43" },
2529 { PT_F44, "f44" }, { PT_F45, "f45" }, { PT_F46, "f46" },
2530 { PT_F47, "f47" }, { PT_F48, "f48" }, { PT_F49, "f49" },
2531 { PT_F50, "f50" }, { PT_F51, "f51" }, { PT_F52, "f52" },
2532 { PT_F53, "f53" }, { PT_F54, "f54" }, { PT_F55, "f55" },
2533 { PT_F56, "f56" }, { PT_F57, "f57" }, { PT_F58, "f58" },
2534 { PT_F59, "f59" }, { PT_F60, "f60" }, { PT_F61, "f61" },
2535 { PT_F62, "f62" }, { PT_F63, "f63" }, { PT_F64, "f64" },
2536 { PT_F65, "f65" }, { PT_F66, "f66" }, { PT_F67, "f67" },
2537 { PT_F68, "f68" }, { PT_F69, "f69" }, { PT_F70, "f70" },
2538 { PT_F71, "f71" }, { PT_F72, "f72" }, { PT_F73, "f73" },
2539 { PT_F74, "f74" }, { PT_F75, "f75" }, { PT_F76, "f76" },
2540 { PT_F77, "f77" }, { PT_F78, "f78" }, { PT_F79, "f79" },
2541 { PT_F80, "f80" }, { PT_F81, "f81" }, { PT_F82, "f82" },
2542 { PT_F83, "f83" }, { PT_F84, "f84" }, { PT_F85, "f85" },
2543 { PT_F86, "f86" }, { PT_F87, "f87" }, { PT_F88, "f88" },
2544 { PT_F89, "f89" }, { PT_F90, "f90" }, { PT_F91, "f91" },
2545 { PT_F92, "f92" }, { PT_F93, "f93" }, { PT_F94, "f94" },
2546 { PT_F95, "f95" }, { PT_F96, "f96" }, { PT_F97, "f97" },
2547 { PT_F98, "f98" }, { PT_F99, "f99" }, { PT_F100, "f100" },
2548 { PT_F101, "f101" }, { PT_F102, "f102" }, { PT_F103, "f103" },
2549 { PT_F104, "f104" }, { PT_F105, "f105" }, { PT_F106, "f106" },
2550 { PT_F107, "f107" }, { PT_F108, "f108" }, { PT_F109, "f109" },
2551 { PT_F110, "f110" }, { PT_F111, "f111" }, { PT_F112, "f112" },
2552 { PT_F113, "f113" }, { PT_F114, "f114" }, { PT_F115, "f115" },
2553 { PT_F116, "f116" }, { PT_F117, "f117" }, { PT_F118, "f118" },
2554 { PT_F119, "f119" }, { PT_F120, "f120" }, { PT_F121, "f121" },
2555 { PT_F122, "f122" }, { PT_F123, "f123" }, { PT_F124, "f124" },
2556 { PT_F125, "f125" }, { PT_F126, "f126" }, { PT_F127, "f127" },
2557 /* switch stack: */
2558 { PT_F2, "f2" }, { PT_F3, "f3" }, { PT_F4, "f4" },
2559 { PT_F5, "f5" }, { PT_F10, "f10" }, { PT_F11, "f11" },
2560 { PT_F12, "f12" }, { PT_F13, "f13" }, { PT_F14, "f14" },
2561 { PT_F15, "f15" }, { PT_F16, "f16" }, { PT_F17, "f17" },
2562 { PT_F18, "f18" }, { PT_F19, "f19" }, { PT_F20, "f20" },
2563 { PT_F21, "f21" }, { PT_F22, "f22" }, { PT_F23, "f23" },
2564 { PT_F24, "f24" }, { PT_F25, "f25" }, { PT_F26, "f26" },
2565 { PT_F27, "f27" }, { PT_F28, "f28" }, { PT_F29, "f29" },
2566 { PT_F30, "f30" }, { PT_F31, "f31" }, { PT_R4, "r4" },
2567 { PT_R5, "r5" }, { PT_R6, "r6" }, { PT_R7, "r7" },
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00002568 { PT_B1, "b1" }, { PT_B2, "b2" }, { PT_B3, "b3" },
2569 { PT_B4, "b4" }, { PT_B5, "b5" },
Roland McGrathca4e10c2004-01-13 10:13:20 +00002570 { PT_AR_EC, "ar.ec" }, { PT_AR_LC, "ar.lc" },
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00002571 /* pt_regs */
Roland McGrathca4e10c2004-01-13 10:13:20 +00002572 { PT_CR_IPSR, "psr" }, { PT_CR_IIP, "ip" },
2573 { PT_CFM, "cfm" }, { PT_AR_UNAT, "ar.unat" },
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00002574 { PT_AR_PFS, "ar.pfs" }, { PT_AR_RSC, "ar.rsc" },
2575 { PT_AR_RNAT, "ar.rnat" }, { PT_AR_BSPSTORE, "ar.bspstore" },
2576 { PT_PR, "pr" }, { PT_B6, "b6" }, { PT_AR_BSP, "ar.bsp" },
2577 { PT_R1, "r1" }, { PT_R2, "r2" }, { PT_R3, "r3" },
2578 { PT_R12, "r12" }, { PT_R13, "r13" }, { PT_R14, "r14" },
2579 { PT_R15, "r15" }, { PT_R8, "r8" }, { PT_R9, "r9" },
2580 { PT_R10, "r10" }, { PT_R11, "r11" }, { PT_R16, "r16" },
2581 { PT_R17, "r17" }, { PT_R18, "r18" }, { PT_R19, "r19" },
2582 { PT_R20, "r20" }, { PT_R21, "r21" }, { PT_R22, "r22" },
2583 { PT_R23, "r23" }, { PT_R24, "r24" }, { PT_R25, "r25" },
2584 { PT_R26, "r26" }, { PT_R27, "r27" }, { PT_R28, "r28" },
2585 { PT_R29, "r29" }, { PT_R30, "r30" }, { PT_R31, "r31" },
2586 { PT_AR_CCV, "ar.ccv" }, { PT_AR_FPSR, "ar.fpsr" },
2587 { PT_B0, "b0" }, { PT_B7, "b7" }, { PT_F6, "f6" },
2588 { PT_F7, "f7" }, { PT_F8, "f8" }, { PT_F9, "f9" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002589# ifdef PT_AR_CSD
Roland McGrathfb1bc072004-03-01 21:29:24 +00002590 { PT_AR_CSD, "ar.csd" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002591# endif
2592# ifdef PT_AR_SSD
Roland McGrathfb1bc072004-03-01 21:29:24 +00002593 { PT_AR_SSD, "ar.ssd" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002594# endif
Roland McGrathca4e10c2004-01-13 10:13:20 +00002595 { PT_DBR, "dbr" }, { PT_IBR, "ibr" }, { PT_PMD, "pmd" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002596# elif defined(I386)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002597 { 4*EBX, "4*EBX" },
2598 { 4*ECX, "4*ECX" },
2599 { 4*EDX, "4*EDX" },
2600 { 4*ESI, "4*ESI" },
2601 { 4*EDI, "4*EDI" },
2602 { 4*EBP, "4*EBP" },
2603 { 4*EAX, "4*EAX" },
2604 { 4*DS, "4*DS" },
2605 { 4*ES, "4*ES" },
2606 { 4*FS, "4*FS" },
2607 { 4*GS, "4*GS" },
2608 { 4*ORIG_EAX, "4*ORIG_EAX" },
2609 { 4*EIP, "4*EIP" },
2610 { 4*CS, "4*CS" },
2611 { 4*EFL, "4*EFL" },
2612 { 4*UESP, "4*UESP" },
2613 { 4*SS, "4*SS" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002614# elif defined(X86_64)
Roland McGratha4f9f2d2005-06-07 23:21:20 +00002615 { 8*R15, "8*R15" },
2616 { 8*R14, "8*R14" },
2617 { 8*R13, "8*R13" },
2618 { 8*R12, "8*R12" },
Michal Ludvig0e035502002-09-23 15:41:01 +00002619 { 8*RBP, "8*RBP" },
Roland McGratha4f9f2d2005-06-07 23:21:20 +00002620 { 8*RBX, "8*RBX" },
2621 { 8*R11, "8*R11" },
2622 { 8*R10, "8*R10" },
2623 { 8*R9, "8*R9" },
2624 { 8*R8, "8*R8" },
Michal Ludvig0e035502002-09-23 15:41:01 +00002625 { 8*RAX, "8*RAX" },
Roland McGratha4f9f2d2005-06-07 23:21:20 +00002626 { 8*RCX, "8*RCX" },
2627 { 8*RDX, "8*RDX" },
2628 { 8*RSI, "8*RSI" },
2629 { 8*RDI, "8*RDI" },
Roland McGratha4f9f2d2005-06-07 23:21:20 +00002630 { 8*ORIG_RAX, "8*ORIG_RAX" },
Michal Ludvig0e035502002-09-23 15:41:01 +00002631 { 8*RIP, "8*RIP" },
2632 { 8*CS, "8*CS" },
2633 { 8*EFLAGS, "8*EFL" },
Roland McGratha4f9f2d2005-06-07 23:21:20 +00002634 { 8*RSP, "8*RSP" },
Michal Ludvig0e035502002-09-23 15:41:01 +00002635 { 8*SS, "8*SS" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002636# elif defined(M68K)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002637 { 4*PT_D1, "4*PT_D1" },
2638 { 4*PT_D2, "4*PT_D2" },
2639 { 4*PT_D3, "4*PT_D3" },
2640 { 4*PT_D4, "4*PT_D4" },
2641 { 4*PT_D5, "4*PT_D5" },
2642 { 4*PT_D6, "4*PT_D6" },
2643 { 4*PT_D7, "4*PT_D7" },
2644 { 4*PT_A0, "4*PT_A0" },
2645 { 4*PT_A1, "4*PT_A1" },
2646 { 4*PT_A2, "4*PT_A2" },
2647 { 4*PT_A3, "4*PT_A3" },
2648 { 4*PT_A4, "4*PT_A4" },
2649 { 4*PT_A5, "4*PT_A5" },
2650 { 4*PT_A6, "4*PT_A6" },
2651 { 4*PT_D0, "4*PT_D0" },
2652 { 4*PT_USP, "4*PT_USP" },
2653 { 4*PT_ORIG_D0, "4*PT_ORIG_D0" },
2654 { 4*PT_SR, "4*PT_SR" },
2655 { 4*PT_PC, "4*PT_PC" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002656# elif defined(SH)
Denys Vlasenkoadedb512008-12-30 18:47:55 +00002657 { 4*REG_REG0, "4*REG_REG0" },
2658 { 4*(REG_REG0+1), "4*REG_REG1" },
2659 { 4*(REG_REG0+2), "4*REG_REG2" },
2660 { 4*(REG_REG0+3), "4*REG_REG3" },
2661 { 4*(REG_REG0+4), "4*REG_REG4" },
2662 { 4*(REG_REG0+5), "4*REG_REG5" },
2663 { 4*(REG_REG0+6), "4*REG_REG6" },
2664 { 4*(REG_REG0+7), "4*REG_REG7" },
2665 { 4*(REG_REG0+8), "4*REG_REG8" },
2666 { 4*(REG_REG0+9), "4*REG_REG9" },
2667 { 4*(REG_REG0+10), "4*REG_REG10" },
2668 { 4*(REG_REG0+11), "4*REG_REG11" },
2669 { 4*(REG_REG0+12), "4*REG_REG12" },
2670 { 4*(REG_REG0+13), "4*REG_REG13" },
2671 { 4*(REG_REG0+14), "4*REG_REG14" },
2672 { 4*REG_REG15, "4*REG_REG15" },
2673 { 4*REG_PC, "4*REG_PC" },
2674 { 4*REG_PR, "4*REG_PR" },
2675 { 4*REG_SR, "4*REG_SR" },
2676 { 4*REG_GBR, "4*REG_GBR" },
2677 { 4*REG_MACH, "4*REG_MACH" },
2678 { 4*REG_MACL, "4*REG_MACL" },
2679 { 4*REG_SYSCALL, "4*REG_SYSCALL" },
2680 { 4*REG_FPUL, "4*REG_FPUL" },
2681 { 4*REG_FPREG0, "4*REG_FPREG0" },
2682 { 4*(REG_FPREG0+1), "4*REG_FPREG1" },
2683 { 4*(REG_FPREG0+2), "4*REG_FPREG2" },
2684 { 4*(REG_FPREG0+3), "4*REG_FPREG3" },
2685 { 4*(REG_FPREG0+4), "4*REG_FPREG4" },
2686 { 4*(REG_FPREG0+5), "4*REG_FPREG5" },
2687 { 4*(REG_FPREG0+6), "4*REG_FPREG6" },
2688 { 4*(REG_FPREG0+7), "4*REG_FPREG7" },
2689 { 4*(REG_FPREG0+8), "4*REG_FPREG8" },
2690 { 4*(REG_FPREG0+9), "4*REG_FPREG9" },
2691 { 4*(REG_FPREG0+10), "4*REG_FPREG10" },
2692 { 4*(REG_FPREG0+11), "4*REG_FPREG11" },
2693 { 4*(REG_FPREG0+12), "4*REG_FPREG12" },
2694 { 4*(REG_FPREG0+13), "4*REG_FPREG13" },
2695 { 4*(REG_FPREG0+14), "4*REG_FPREG14" },
2696 { 4*REG_FPREG15, "4*REG_FPREG15" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002697# ifdef REG_XDREG0
Denys Vlasenkoadedb512008-12-30 18:47:55 +00002698 { 4*REG_XDREG0, "4*REG_XDREG0" },
2699 { 4*(REG_XDREG0+2), "4*REG_XDREG2" },
2700 { 4*(REG_XDREG0+4), "4*REG_XDREG4" },
2701 { 4*(REG_XDREG0+6), "4*REG_XDREG6" },
2702 { 4*(REG_XDREG0+8), "4*REG_XDREG8" },
2703 { 4*(REG_XDREG0+10), "4*REG_XDREG10" },
2704 { 4*(REG_XDREG0+12), "4*REG_XDREG12" },
2705 { 4*REG_XDREG14, "4*REG_XDREG14" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002706# endif
Denys Vlasenkoadedb512008-12-30 18:47:55 +00002707 { 4*REG_FPSCR, "4*REG_FPSCR" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002708# elif defined(SH64)
Roland McGrathe1e584b2003-06-02 19:18:58 +00002709 { 0, "PC(L)" },
2710 { 4, "PC(U)" },
2711 { 8, "SR(L)" },
2712 { 12, "SR(U)" },
2713 { 16, "syscall no.(L)" },
2714 { 20, "syscall_no.(U)" },
2715 { 24, "R0(L)" },
2716 { 28, "R0(U)" },
2717 { 32, "R1(L)" },
2718 { 36, "R1(U)" },
2719 { 40, "R2(L)" },
2720 { 44, "R2(U)" },
2721 { 48, "R3(L)" },
2722 { 52, "R3(U)" },
2723 { 56, "R4(L)" },
2724 { 60, "R4(U)" },
2725 { 64, "R5(L)" },
2726 { 68, "R5(U)" },
2727 { 72, "R6(L)" },
2728 { 76, "R6(U)" },
2729 { 80, "R7(L)" },
2730 { 84, "R7(U)" },
2731 { 88, "R8(L)" },
2732 { 92, "R8(U)" },
2733 { 96, "R9(L)" },
2734 { 100, "R9(U)" },
2735 { 104, "R10(L)" },
2736 { 108, "R10(U)" },
2737 { 112, "R11(L)" },
2738 { 116, "R11(U)" },
2739 { 120, "R12(L)" },
2740 { 124, "R12(U)" },
2741 { 128, "R13(L)" },
2742 { 132, "R13(U)" },
2743 { 136, "R14(L)" },
2744 { 140, "R14(U)" },
2745 { 144, "R15(L)" },
2746 { 148, "R15(U)" },
2747 { 152, "R16(L)" },
2748 { 156, "R16(U)" },
2749 { 160, "R17(L)" },
2750 { 164, "R17(U)" },
2751 { 168, "R18(L)" },
2752 { 172, "R18(U)" },
2753 { 176, "R19(L)" },
2754 { 180, "R19(U)" },
2755 { 184, "R20(L)" },
2756 { 188, "R20(U)" },
2757 { 192, "R21(L)" },
2758 { 196, "R21(U)" },
2759 { 200, "R22(L)" },
2760 { 204, "R22(U)" },
2761 { 208, "R23(L)" },
2762 { 212, "R23(U)" },
2763 { 216, "R24(L)" },
2764 { 220, "R24(U)" },
2765 { 224, "R25(L)" },
2766 { 228, "R25(U)" },
2767 { 232, "R26(L)" },
2768 { 236, "R26(U)" },
2769 { 240, "R27(L)" },
2770 { 244, "R27(U)" },
2771 { 248, "R28(L)" },
2772 { 252, "R28(U)" },
2773 { 256, "R29(L)" },
2774 { 260, "R29(U)" },
2775 { 264, "R30(L)" },
2776 { 268, "R30(U)" },
2777 { 272, "R31(L)" },
2778 { 276, "R31(U)" },
2779 { 280, "R32(L)" },
2780 { 284, "R32(U)" },
2781 { 288, "R33(L)" },
2782 { 292, "R33(U)" },
2783 { 296, "R34(L)" },
2784 { 300, "R34(U)" },
2785 { 304, "R35(L)" },
2786 { 308, "R35(U)" },
2787 { 312, "R36(L)" },
2788 { 316, "R36(U)" },
2789 { 320, "R37(L)" },
2790 { 324, "R37(U)" },
2791 { 328, "R38(L)" },
2792 { 332, "R38(U)" },
2793 { 336, "R39(L)" },
2794 { 340, "R39(U)" },
2795 { 344, "R40(L)" },
2796 { 348, "R40(U)" },
2797 { 352, "R41(L)" },
2798 { 356, "R41(U)" },
2799 { 360, "R42(L)" },
2800 { 364, "R42(U)" },
2801 { 368, "R43(L)" },
2802 { 372, "R43(U)" },
2803 { 376, "R44(L)" },
2804 { 380, "R44(U)" },
2805 { 384, "R45(L)" },
2806 { 388, "R45(U)" },
2807 { 392, "R46(L)" },
2808 { 396, "R46(U)" },
2809 { 400, "R47(L)" },
2810 { 404, "R47(U)" },
2811 { 408, "R48(L)" },
2812 { 412, "R48(U)" },
2813 { 416, "R49(L)" },
2814 { 420, "R49(U)" },
2815 { 424, "R50(L)" },
2816 { 428, "R50(U)" },
2817 { 432, "R51(L)" },
2818 { 436, "R51(U)" },
2819 { 440, "R52(L)" },
2820 { 444, "R52(U)" },
2821 { 448, "R53(L)" },
2822 { 452, "R53(U)" },
2823 { 456, "R54(L)" },
2824 { 460, "R54(U)" },
2825 { 464, "R55(L)" },
2826 { 468, "R55(U)" },
2827 { 472, "R56(L)" },
2828 { 476, "R56(U)" },
2829 { 480, "R57(L)" },
2830 { 484, "R57(U)" },
2831 { 488, "R58(L)" },
2832 { 492, "R58(U)" },
2833 { 496, "R59(L)" },
2834 { 500, "R59(U)" },
2835 { 504, "R60(L)" },
2836 { 508, "R60(U)" },
2837 { 512, "R61(L)" },
2838 { 516, "R61(U)" },
2839 { 520, "R62(L)" },
2840 { 524, "R62(U)" },
2841 { 528, "TR0(L)" },
2842 { 532, "TR0(U)" },
2843 { 536, "TR1(L)" },
2844 { 540, "TR1(U)" },
2845 { 544, "TR2(L)" },
2846 { 548, "TR2(U)" },
2847 { 552, "TR3(L)" },
2848 { 556, "TR3(U)" },
2849 { 560, "TR4(L)" },
2850 { 564, "TR4(U)" },
2851 { 568, "TR5(L)" },
2852 { 572, "TR5(U)" },
2853 { 576, "TR6(L)" },
2854 { 580, "TR6(U)" },
2855 { 584, "TR7(L)" },
2856 { 588, "TR7(U)" },
Denys Vlasenkoadedb512008-12-30 18:47:55 +00002857 /* This entry is in case pt_regs contains dregs (depends on
2858 the kernel build options). */
Roland McGrathe1e584b2003-06-02 19:18:58 +00002859 { uoff(regs), "offsetof(struct user, regs)" },
2860 { uoff(fpu), "offsetof(struct user, fpu)" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002861# elif defined(ARM)
Roland McGrath0f87c492003-06-03 23:29:04 +00002862 { uoff(regs.ARM_r0), "r0" },
2863 { uoff(regs.ARM_r1), "r1" },
2864 { uoff(regs.ARM_r2), "r2" },
2865 { uoff(regs.ARM_r3), "r3" },
2866 { uoff(regs.ARM_r4), "r4" },
2867 { uoff(regs.ARM_r5), "r5" },
2868 { uoff(regs.ARM_r6), "r6" },
2869 { uoff(regs.ARM_r7), "r7" },
2870 { uoff(regs.ARM_r8), "r8" },
2871 { uoff(regs.ARM_r9), "r9" },
2872 { uoff(regs.ARM_r10), "r10" },
2873 { uoff(regs.ARM_fp), "fp" },
2874 { uoff(regs.ARM_ip), "ip" },
2875 { uoff(regs.ARM_sp), "sp" },
2876 { uoff(regs.ARM_lr), "lr" },
2877 { uoff(regs.ARM_pc), "pc" },
2878 { uoff(regs.ARM_cpsr), "cpsr" },
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +00002879# elif defined(AVR32)
2880 { uoff(regs.sr), "sr" },
2881 { uoff(regs.pc), "pc" },
2882 { uoff(regs.lr), "lr" },
2883 { uoff(regs.sp), "sp" },
2884 { uoff(regs.r12), "r12" },
2885 { uoff(regs.r11), "r11" },
2886 { uoff(regs.r10), "r10" },
2887 { uoff(regs.r9), "r9" },
2888 { uoff(regs.r8), "r8" },
2889 { uoff(regs.r7), "r7" },
2890 { uoff(regs.r6), "r6" },
2891 { uoff(regs.r5), "r5" },
2892 { uoff(regs.r4), "r4" },
2893 { uoff(regs.r3), "r3" },
2894 { uoff(regs.r2), "r2" },
2895 { uoff(regs.r1), "r1" },
2896 { uoff(regs.r0), "r0" },
2897 { uoff(regs.r12_orig), "orig_r12" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002898# elif defined(MIPS)
Roland McGrath542c2c62008-05-20 01:11:56 +00002899 { 0, "r0" },
2900 { 1, "r1" },
2901 { 2, "r2" },
2902 { 3, "r3" },
2903 { 4, "r4" },
2904 { 5, "r5" },
2905 { 6, "r6" },
2906 { 7, "r7" },
2907 { 8, "r8" },
2908 { 9, "r9" },
2909 { 10, "r10" },
2910 { 11, "r11" },
2911 { 12, "r12" },
2912 { 13, "r13" },
2913 { 14, "r14" },
2914 { 15, "r15" },
2915 { 16, "r16" },
2916 { 17, "r17" },
2917 { 18, "r18" },
2918 { 19, "r19" },
2919 { 20, "r20" },
2920 { 21, "r21" },
2921 { 22, "r22" },
2922 { 23, "r23" },
2923 { 24, "r24" },
2924 { 25, "r25" },
2925 { 26, "r26" },
2926 { 27, "r27" },
2927 { 28, "r28" },
2928 { 29, "r29" },
2929 { 30, "r30" },
2930 { 31, "r31" },
2931 { 32, "f0" },
2932 { 33, "f1" },
2933 { 34, "f2" },
2934 { 35, "f3" },
2935 { 36, "f4" },
2936 { 37, "f5" },
2937 { 38, "f6" },
2938 { 39, "f7" },
2939 { 40, "f8" },
2940 { 41, "f9" },
2941 { 42, "f10" },
2942 { 43, "f11" },
2943 { 44, "f12" },
2944 { 45, "f13" },
2945 { 46, "f14" },
2946 { 47, "f15" },
2947 { 48, "f16" },
2948 { 49, "f17" },
2949 { 50, "f18" },
2950 { 51, "f19" },
2951 { 52, "f20" },
2952 { 53, "f21" },
2953 { 54, "f22" },
2954 { 55, "f23" },
2955 { 56, "f24" },
2956 { 57, "f25" },
2957 { 58, "f26" },
2958 { 59, "f27" },
2959 { 60, "f28" },
2960 { 61, "f29" },
2961 { 62, "f30" },
2962 { 63, "f31" },
2963 { 64, "pc" },
2964 { 65, "cause" },
2965 { 66, "badvaddr" },
2966 { 67, "mmhi" },
2967 { 68, "mmlo" },
2968 { 69, "fpcsr" },
2969 { 70, "fpeir" },
Chris Metcalfc8c66982009-12-28 10:00:15 -05002970# elif defined(TILE)
2971 { PTREGS_OFFSET_REG(0), "r0" },
2972 { PTREGS_OFFSET_REG(1), "r1" },
2973 { PTREGS_OFFSET_REG(2), "r2" },
2974 { PTREGS_OFFSET_REG(3), "r3" },
2975 { PTREGS_OFFSET_REG(4), "r4" },
2976 { PTREGS_OFFSET_REG(5), "r5" },
2977 { PTREGS_OFFSET_REG(6), "r6" },
2978 { PTREGS_OFFSET_REG(7), "r7" },
2979 { PTREGS_OFFSET_REG(8), "r8" },
2980 { PTREGS_OFFSET_REG(9), "r9" },
2981 { PTREGS_OFFSET_REG(10), "r10" },
2982 { PTREGS_OFFSET_REG(11), "r11" },
2983 { PTREGS_OFFSET_REG(12), "r12" },
2984 { PTREGS_OFFSET_REG(13), "r13" },
2985 { PTREGS_OFFSET_REG(14), "r14" },
2986 { PTREGS_OFFSET_REG(15), "r15" },
2987 { PTREGS_OFFSET_REG(16), "r16" },
2988 { PTREGS_OFFSET_REG(17), "r17" },
2989 { PTREGS_OFFSET_REG(18), "r18" },
2990 { PTREGS_OFFSET_REG(19), "r19" },
2991 { PTREGS_OFFSET_REG(20), "r20" },
2992 { PTREGS_OFFSET_REG(21), "r21" },
2993 { PTREGS_OFFSET_REG(22), "r22" },
2994 { PTREGS_OFFSET_REG(23), "r23" },
2995 { PTREGS_OFFSET_REG(24), "r24" },
2996 { PTREGS_OFFSET_REG(25), "r25" },
2997 { PTREGS_OFFSET_REG(26), "r26" },
2998 { PTREGS_OFFSET_REG(27), "r27" },
2999 { PTREGS_OFFSET_REG(28), "r28" },
3000 { PTREGS_OFFSET_REG(29), "r29" },
3001 { PTREGS_OFFSET_REG(30), "r30" },
3002 { PTREGS_OFFSET_REG(31), "r31" },
3003 { PTREGS_OFFSET_REG(32), "r32" },
3004 { PTREGS_OFFSET_REG(33), "r33" },
3005 { PTREGS_OFFSET_REG(34), "r34" },
3006 { PTREGS_OFFSET_REG(35), "r35" },
3007 { PTREGS_OFFSET_REG(36), "r36" },
3008 { PTREGS_OFFSET_REG(37), "r37" },
3009 { PTREGS_OFFSET_REG(38), "r38" },
3010 { PTREGS_OFFSET_REG(39), "r39" },
3011 { PTREGS_OFFSET_REG(40), "r40" },
3012 { PTREGS_OFFSET_REG(41), "r41" },
3013 { PTREGS_OFFSET_REG(42), "r42" },
3014 { PTREGS_OFFSET_REG(43), "r43" },
3015 { PTREGS_OFFSET_REG(44), "r44" },
3016 { PTREGS_OFFSET_REG(45), "r45" },
3017 { PTREGS_OFFSET_REG(46), "r46" },
3018 { PTREGS_OFFSET_REG(47), "r47" },
3019 { PTREGS_OFFSET_REG(48), "r48" },
3020 { PTREGS_OFFSET_REG(49), "r49" },
3021 { PTREGS_OFFSET_REG(50), "r50" },
3022 { PTREGS_OFFSET_REG(51), "r51" },
3023 { PTREGS_OFFSET_REG(52), "r52" },
3024 { PTREGS_OFFSET_TP, "tp" },
3025 { PTREGS_OFFSET_SP, "sp" },
3026 { PTREGS_OFFSET_LR, "lr" },
3027 { PTREGS_OFFSET_PC, "pc" },
3028 { PTREGS_OFFSET_EX1, "ex1" },
3029 { PTREGS_OFFSET_FAULTNUM, "faultnum" },
3030 { PTREGS_OFFSET_ORIG_R0, "orig_r0" },
3031 { PTREGS_OFFSET_FLAGS, "flags" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003032# endif
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00003033# ifdef CRISV10
3034 { 4*PT_FRAMETYPE, "4*PT_FRAMETYPE" },
3035 { 4*PT_ORIG_R10, "4*PT_ORIG_R10" },
3036 { 4*PT_R13, "4*PT_R13" },
3037 { 4*PT_R12, "4*PT_R12" },
3038 { 4*PT_R11, "4*PT_R11" },
3039 { 4*PT_R10, "4*PT_R10" },
3040 { 4*PT_R9, "4*PT_R9" },
3041 { 4*PT_R8, "4*PT_R8" },
3042 { 4*PT_R7, "4*PT_R7" },
3043 { 4*PT_R6, "4*PT_R6" },
3044 { 4*PT_R5, "4*PT_R5" },
3045 { 4*PT_R4, "4*PT_R4" },
3046 { 4*PT_R3, "4*PT_R3" },
3047 { 4*PT_R2, "4*PT_R2" },
3048 { 4*PT_R1, "4*PT_R1" },
3049 { 4*PT_R0, "4*PT_R0" },
3050 { 4*PT_MOF, "4*PT_MOF" },
3051 { 4*PT_DCCR, "4*PT_DCCR" },
3052 { 4*PT_SRP, "4*PT_SRP" },
3053 { 4*PT_IRP, "4*PT_IRP" },
3054 { 4*PT_CSRINSTR, "4*PT_CSRINSTR" },
3055 { 4*PT_CSRADDR, "4*PT_CSRADDR" },
3056 { 4*PT_CSRDATA, "4*PT_CSRDATA" },
3057 { 4*PT_USP, "4*PT_USP" },
3058# endif
3059# ifdef CRISV32
3060 { 4*PT_ORIG_R10, "4*PT_ORIG_R10" },
3061 { 4*PT_R0, "4*PT_R0" },
3062 { 4*PT_R1, "4*PT_R1" },
3063 { 4*PT_R2, "4*PT_R2" },
3064 { 4*PT_R3, "4*PT_R3" },
3065 { 4*PT_R4, "4*PT_R4" },
3066 { 4*PT_R5, "4*PT_R5" },
3067 { 4*PT_R6, "4*PT_R6" },
3068 { 4*PT_R7, "4*PT_R7" },
3069 { 4*PT_R8, "4*PT_R8" },
3070 { 4*PT_R9, "4*PT_R9" },
3071 { 4*PT_R10, "4*PT_R10" },
3072 { 4*PT_R11, "4*PT_R11" },
3073 { 4*PT_R12, "4*PT_R12" },
3074 { 4*PT_R13, "4*PT_R13" },
3075 { 4*PT_ACR, "4*PT_ACR" },
3076 { 4*PT_SRS, "4*PT_SRS" },
3077 { 4*PT_MOF, "4*PT_MOF" },
3078 { 4*PT_SPC, "4*PT_SPC" },
3079 { 4*PT_CCS, "4*PT_CCS" },
3080 { 4*PT_SRP, "4*PT_SRP" },
3081 { 4*PT_ERP, "4*PT_ERP" },
3082 { 4*PT_EXS, "4*PT_EXS" },
3083 { 4*PT_EDA, "4*PT_EDA" },
3084 { 4*PT_USP, "4*PT_USP" },
3085 { 4*PT_PPC, "4*PT_PPC" },
3086 { 4*PT_BP_CTRL, "4*PT_BP_CTRL" },
3087 { 4*PT_BP+4, "4*PT_BP+4" },
3088 { 4*PT_BP+8, "4*PT_BP+8" },
3089 { 4*PT_BP+12, "4*PT_BP+12" },
3090 { 4*PT_BP+16, "4*PT_BP+16" },
3091 { 4*PT_BP+20, "4*PT_BP+20" },
3092 { 4*PT_BP+24, "4*PT_BP+24" },
3093 { 4*PT_BP+28, "4*PT_BP+28" },
3094 { 4*PT_BP+32, "4*PT_BP+32" },
3095 { 4*PT_BP+36, "4*PT_BP+36" },
3096 { 4*PT_BP+40, "4*PT_BP+40" },
3097 { 4*PT_BP+44, "4*PT_BP+44" },
3098 { 4*PT_BP+48, "4*PT_BP+48" },
3099 { 4*PT_BP+52, "4*PT_BP+52" },
3100 { 4*PT_BP+56, "4*PT_BP+56" },
3101# endif
Edgar E. Iglesias939caba2010-07-06 14:21:07 +02003102# ifdef MICROBLAZE
3103 { PT_GPR(0), "r0" },
3104 { PT_GPR(1), "r1" },
3105 { PT_GPR(2), "r2" },
3106 { PT_GPR(3), "r3" },
3107 { PT_GPR(4), "r4" },
3108 { PT_GPR(5), "r5" },
3109 { PT_GPR(6), "r6" },
3110 { PT_GPR(7), "r7" },
3111 { PT_GPR(8), "r8" },
3112 { PT_GPR(9), "r9" },
3113 { PT_GPR(10), "r10" },
3114 { PT_GPR(11), "r11" },
3115 { PT_GPR(12), "r12" },
3116 { PT_GPR(13), "r13" },
3117 { PT_GPR(14), "r14" },
3118 { PT_GPR(15), "r15" },
3119 { PT_GPR(16), "r16" },
3120 { PT_GPR(17), "r17" },
3121 { PT_GPR(18), "r18" },
3122 { PT_GPR(19), "r19" },
3123 { PT_GPR(20), "r20" },
3124 { PT_GPR(21), "r21" },
3125 { PT_GPR(22), "r22" },
3126 { PT_GPR(23), "r23" },
3127 { PT_GPR(24), "r24" },
3128 { PT_GPR(25), "r25" },
3129 { PT_GPR(26), "r26" },
3130 { PT_GPR(27), "r27" },
3131 { PT_GPR(28), "r28" },
3132 { PT_GPR(29), "r29" },
3133 { PT_GPR(30), "r30" },
3134 { PT_GPR(31), "r31" },
3135 { PT_PC, "rpc", },
3136 { PT_MSR, "rmsr", },
3137 { PT_EAR, "rear", },
3138 { PT_ESR, "resr", },
3139 { PT_FSR, "rfsr", },
3140 { PT_KERNEL_MODE, "kernel_mode", },
3141# endif
Roland McGrath542c2c62008-05-20 01:11:56 +00003142
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00003143# if !defined(SPARC) && !defined(HPPA) && !defined(POWERPC) \
3144 && !defined(ALPHA) && !defined(IA64) \
Edgar E. Iglesias939caba2010-07-06 14:21:07 +02003145 && !defined(CRISV10) && !defined(CRISV32) && !defined(MICROBLAZE)
Chris Metcalfc8c66982009-12-28 10:00:15 -05003146# if !defined(S390) && !defined(S390X) && !defined(MIPS) && !defined(SPARC64) && !defined(AVR32) && !defined(BFIN) && !defined(TILE)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003147 { uoff(u_fpvalid), "offsetof(struct user, u_fpvalid)" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003148# endif
3149# if defined(I386) || defined(X86_64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003150 { uoff(i387), "offsetof(struct user, i387)" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003151# endif
3152# if defined(M68K)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003153 { uoff(m68kfp), "offsetof(struct user, m68kfp)" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003154# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003155 { uoff(u_tsize), "offsetof(struct user, u_tsize)" },
3156 { uoff(u_dsize), "offsetof(struct user, u_dsize)" },
3157 { uoff(u_ssize), "offsetof(struct user, u_ssize)" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003158# if !defined(SPARC64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003159 { uoff(start_code), "offsetof(struct user, start_code)" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003160# endif
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +00003161# if defined(AVR32) || defined(SH64)
Roland McGrathe1e584b2003-06-02 19:18:58 +00003162 { uoff(start_data), "offsetof(struct user, start_data)" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003163# endif
3164# if !defined(SPARC64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003165 { uoff(start_stack), "offsetof(struct user, start_stack)" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003166# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003167 { uoff(signal), "offsetof(struct user, signal)" },
Chris Metcalfc8c66982009-12-28 10:00:15 -05003168# if !defined(AVR32) && !defined(S390) && !defined(S390X) && !defined(MIPS) && !defined(SH) && !defined(SH64) && !defined(SPARC64) && !defined(TILE)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003169 { uoff(reserved), "offsetof(struct user, reserved)" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003170# endif
3171# if !defined(SPARC64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003172 { uoff(u_ar0), "offsetof(struct user, u_ar0)" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003173# endif
Chris Metcalfc8c66982009-12-28 10:00:15 -05003174# if !defined(ARM) && !defined(AVR32) && !defined(MIPS) && !defined(S390) && !defined(S390X) && !defined(SPARC64) && !defined(BFIN) && !defined(TILE)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003175 { uoff(u_fpstate), "offsetof(struct user, u_fpstate)" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003176# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003177 { uoff(magic), "offsetof(struct user, magic)" },
3178 { uoff(u_comm), "offsetof(struct user, u_comm)" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003179# if defined(I386) || defined(X86_64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003180 { uoff(u_debugreg), "offsetof(struct user, u_debugreg)" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003181# endif
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00003182# endif /* !defined(many arches) */
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003183
3184# endif /* LINUX */
3185
3186# ifdef SUNOS4
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003187 { uoff(u_pcb), "offsetof(struct user, u_pcb)" },
3188 { uoff(u_procp), "offsetof(struct user, u_procp)" },
3189 { uoff(u_ar0), "offsetof(struct user, u_ar0)" },
3190 { uoff(u_comm[0]), "offsetof(struct user, u_comm[0])" },
3191 { uoff(u_arg[0]), "offsetof(struct user, u_arg[0])" },
3192 { uoff(u_ap), "offsetof(struct user, u_ap)" },
3193 { uoff(u_qsave), "offsetof(struct user, u_qsave)" },
3194 { uoff(u_rval1), "offsetof(struct user, u_rval1)" },
3195 { uoff(u_rval2), "offsetof(struct user, u_rval2)" },
3196 { uoff(u_error), "offsetof(struct user, u_error)" },
3197 { uoff(u_eosys), "offsetof(struct user, u_eosys)" },
3198 { uoff(u_ssave), "offsetof(struct user, u_ssave)" },
3199 { uoff(u_signal[0]), "offsetof(struct user, u_signal)" },
3200 { uoff(u_sigmask[0]), "offsetof(struct user, u_sigmask)" },
3201 { uoff(u_sigonstack), "offsetof(struct user, u_sigonstack)" },
3202 { uoff(u_sigintr), "offsetof(struct user, u_sigintr)" },
3203 { uoff(u_sigreset), "offsetof(struct user, u_sigreset)" },
3204 { uoff(u_oldmask), "offsetof(struct user, u_oldmask)" },
3205 { uoff(u_code), "offsetof(struct user, u_code)" },
3206 { uoff(u_addr), "offsetof(struct user, u_addr)" },
3207 { uoff(u_sigstack), "offsetof(struct user, u_sigstack)" },
3208 { uoff(u_ofile), "offsetof(struct user, u_ofile)" },
3209 { uoff(u_pofile), "offsetof(struct user, u_pofile)" },
3210 { uoff(u_ofile_arr[0]), "offsetof(struct user, u_ofile_arr[0])" },
3211 { uoff(u_pofile_arr[0]),"offsetof(struct user, u_pofile_arr[0])"},
3212 { uoff(u_lastfile), "offsetof(struct user, u_lastfile)" },
3213 { uoff(u_cwd), "offsetof(struct user, u_cwd)" },
3214 { uoff(u_cdir), "offsetof(struct user, u_cdir)" },
3215 { uoff(u_rdir), "offsetof(struct user, u_rdir)" },
3216 { uoff(u_cmask), "offsetof(struct user, u_cmask)" },
3217 { uoff(u_ru), "offsetof(struct user, u_ru)" },
3218 { uoff(u_cru), "offsetof(struct user, u_cru)" },
3219 { uoff(u_timer[0]), "offsetof(struct user, u_timer[0])" },
3220 { uoff(u_XXX[0]), "offsetof(struct user, u_XXX[0])" },
3221 { uoff(u_ioch), "offsetof(struct user, u_ioch)" },
3222 { uoff(u_start), "offsetof(struct user, u_start)" },
3223 { uoff(u_acflag), "offsetof(struct user, u_acflag)" },
3224 { uoff(u_prof.pr_base), "offsetof(struct user, u_prof.pr_base)" },
3225 { uoff(u_prof.pr_size), "offsetof(struct user, u_prof.pr_size)" },
3226 { uoff(u_prof.pr_off), "offsetof(struct user, u_prof.pr_off)" },
3227 { uoff(u_prof.pr_scale),"offsetof(struct user, u_prof.pr_scale)"},
3228 { uoff(u_rlimit[0]), "offsetof(struct user, u_rlimit)" },
3229 { uoff(u_exdata.Ux_A), "offsetof(struct user, u_exdata.Ux_A)" },
3230 { uoff(u_exdata.ux_shell[0]),"offsetof(struct user, u_exdata.ux_shell[0])"},
3231 { uoff(u_lofault), "offsetof(struct user, u_lofault)" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003232# endif /* SUNOS4 */
3233# ifndef HPPA
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003234 { sizeof(struct user), "sizeof(struct user)" },
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003235# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003236 { 0, NULL },
3237};
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003238# endif /* !FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003239
3240int
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003241sys_ptrace(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003242{
Roland McGrathd9f816f2004-09-04 03:39:20 +00003243 const struct xlat *x;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003244 long addr;
3245
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003246 if (entering(tcp)) {
Roland McGrathbf621d42003-01-14 09:46:21 +00003247 printxval(ptrace_cmds, tcp->u_arg[0],
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003248# ifndef FREEBSD
Roland McGrathbf621d42003-01-14 09:46:21 +00003249 "PTRACE_???"
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003250# else
Roland McGrathbf621d42003-01-14 09:46:21 +00003251 "PT_???"
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003252# endif
Roland McGrathbf621d42003-01-14 09:46:21 +00003253 );
3254 tprintf(", %lu, ", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003255 addr = tcp->u_arg[2];
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003256# ifndef FREEBSD
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003257 if (tcp->u_arg[0] == PTRACE_PEEKUSER
3258 || tcp->u_arg[0] == PTRACE_POKEUSER) {
3259 for (x = struct_user_offsets; x->str; x++) {
3260 if (x->val >= addr)
3261 break;
3262 }
3263 if (!x->str)
3264 tprintf("%#lx, ", addr);
3265 else if (x->val > addr && x != struct_user_offsets) {
3266 x--;
3267 tprintf("%s + %ld, ", x->str, addr - x->val);
3268 }
3269 else
3270 tprintf("%s, ", x->str);
3271 }
3272 else
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003273# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003274 tprintf("%#lx, ", tcp->u_arg[2]);
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003275# ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003276 switch (tcp->u_arg[0]) {
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003277# ifndef IA64
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003278 case PTRACE_PEEKDATA:
3279 case PTRACE_PEEKTEXT:
3280 case PTRACE_PEEKUSER:
3281 break;
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003282# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003283 case PTRACE_CONT:
3284 case PTRACE_SINGLESTEP:
3285 case PTRACE_SYSCALL:
3286 case PTRACE_DETACH:
3287 printsignal(tcp->u_arg[3]);
3288 break;
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003289# ifdef PTRACE_SETOPTIONS
Denys Vlasenkof535b542009-01-13 18:30:55 +00003290 case PTRACE_SETOPTIONS:
3291 printflags(ptrace_setoptions_flags, tcp->u_arg[3], "PTRACE_O_???");
3292 break;
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003293# endif
3294# ifdef PTRACE_SETSIGINFO
Denys Vlasenkof535b542009-01-13 18:30:55 +00003295 case PTRACE_SETSIGINFO: {
3296 siginfo_t si;
3297 if (!tcp->u_arg[3])
3298 tprintf("NULL");
3299 else if (syserror(tcp))
3300 tprintf("%#lx", tcp->u_arg[3]);
3301 else if (umove(tcp, tcp->u_arg[3], &si) < 0)
3302 tprintf("{???}");
3303 else
3304 printsiginfo(&si, verbose(tcp));
3305 break;
3306 }
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003307# endif
3308# ifdef PTRACE_GETSIGINFO
Denys Vlasenkof535b542009-01-13 18:30:55 +00003309 case PTRACE_GETSIGINFO:
3310 /* Don't print anything, do it at syscall return. */
3311 break;
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003312# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003313 default:
3314 tprintf("%#lx", tcp->u_arg[3]);
3315 break;
3316 }
3317 } else {
3318 switch (tcp->u_arg[0]) {
3319 case PTRACE_PEEKDATA:
3320 case PTRACE_PEEKTEXT:
3321 case PTRACE_PEEKUSER:
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003322# ifdef IA64
Roland McGrath1e868062007-11-19 22:11:45 +00003323 return RVAL_HEX;
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003324# else
Roland McGratheb285352003-01-14 09:59:00 +00003325 printnum(tcp, tcp->u_arg[3], "%#lx");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003326 break;
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003327# endif
3328# ifdef PTRACE_GETSIGINFO
Denys Vlasenkof535b542009-01-13 18:30:55 +00003329 case PTRACE_GETSIGINFO: {
3330 siginfo_t si;
3331 if (!tcp->u_arg[3])
3332 tprintf("NULL");
3333 else if (syserror(tcp))
3334 tprintf("%#lx", tcp->u_arg[3]);
3335 else if (umove(tcp, tcp->u_arg[3], &si) < 0)
3336 tprintf("{???}");
3337 else
3338 printsiginfo(&si, verbose(tcp));
3339 break;
3340 }
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003341# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003342 }
3343 }
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003344# endif /* LINUX */
3345# ifdef SUNOS4
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003346 if (tcp->u_arg[0] == PTRACE_WRITEDATA ||
3347 tcp->u_arg[0] == PTRACE_WRITETEXT) {
3348 tprintf("%lu, ", tcp->u_arg[3]);
3349 printstr(tcp, tcp->u_arg[4], tcp->u_arg[3]);
3350 } else if (tcp->u_arg[0] != PTRACE_READDATA &&
3351 tcp->u_arg[0] != PTRACE_READTEXT) {
3352 tprintf("%#lx", tcp->u_arg[3]);
3353 }
3354 } else {
3355 if (tcp->u_arg[0] == PTRACE_READDATA ||
3356 tcp->u_arg[0] == PTRACE_READTEXT) {
3357 tprintf("%lu, ", tcp->u_arg[3]);
3358 printstr(tcp, tcp->u_arg[4], tcp->u_arg[3]);
3359 }
3360 }
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003361# endif /* SUNOS4 */
3362# ifdef FREEBSD
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00003363 tprintf("%lu", tcp->u_arg[3]);
3364 }
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003365# endif /* FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003366 return 0;
3367}
3368
3369#endif /* !SVR4 */
Roland McGrath5a223472002-12-15 23:58:26 +00003370
3371#ifdef LINUX
Roland McGrath51942a92007-07-05 18:59:11 +00003372# ifndef FUTEX_CMP_REQUEUE
3373# define FUTEX_CMP_REQUEUE 4
3374# endif
3375# ifndef FUTEX_WAKE_OP
3376# define FUTEX_WAKE_OP 5
3377# endif
3378# ifndef FUTEX_LOCK_PI
3379# define FUTEX_LOCK_PI 6
3380# define FUTEX_UNLOCK_PI 7
3381# define FUTEX_TRYLOCK_PI 8
3382# endif
Roland McGrath1aeaf742008-07-18 01:27:39 +00003383# ifndef FUTEX_WAIT_BITSET
3384# define FUTEX_WAIT_BITSET 9
3385# endif
3386# ifndef FUTEX_WAKE_BITSET
3387# define FUTEX_WAKE_BITSET 10
Roland McGrath51942a92007-07-05 18:59:11 +00003388# endif
Andreas Schwab85f58322009-08-12 09:54:42 +02003389# ifndef FUTEX_WAIT_REQUEUE_PI
3390# define FUTEX_WAIT_REQUEUE_PI 11
3391# endif
3392# ifndef FUTEX_CMP_REQUEUE_PI
3393# define FUTEX_CMP_REQUEUE_PI 12
3394# endif
Roland McGrath51942a92007-07-05 18:59:11 +00003395# ifndef FUTEX_PRIVATE_FLAG
3396# define FUTEX_PRIVATE_FLAG 128
3397# endif
Andreas Schwab85f58322009-08-12 09:54:42 +02003398# ifndef FUTEX_CLOCK_REALTIME
3399# define FUTEX_CLOCK_REALTIME 256
3400# endif
Roland McGrathd9f816f2004-09-04 03:39:20 +00003401static const struct xlat futexops[] = {
Roland McGrath51942a92007-07-05 18:59:11 +00003402 { FUTEX_WAIT, "FUTEX_WAIT" },
3403 { FUTEX_WAKE, "FUTEX_WAKE" },
3404 { FUTEX_FD, "FUTEX_FD" },
3405 { FUTEX_REQUEUE, "FUTEX_REQUEUE" },
3406 { FUTEX_CMP_REQUEUE, "FUTEX_CMP_REQUEUE" },
3407 { FUTEX_WAKE_OP, "FUTEX_WAKE_OP" },
3408 { FUTEX_LOCK_PI, "FUTEX_LOCK_PI" },
3409 { FUTEX_UNLOCK_PI, "FUTEX_UNLOCK_PI" },
3410 { FUTEX_TRYLOCK_PI, "FUTEX_TRYLOCK_PI" },
Roland McGrath1aeaf742008-07-18 01:27:39 +00003411 { FUTEX_WAIT_BITSET, "FUTEX_WAIT_BITSET" },
3412 { FUTEX_WAKE_BITSET, "FUTEX_WAKE_BITSET" },
Andreas Schwab85f58322009-08-12 09:54:42 +02003413 { FUTEX_WAIT_REQUEUE_PI, "FUTEX_WAIT_REQUEUE_PI" },
3414 { FUTEX_CMP_REQUEUE_PI, "FUTEX_CMP_REQUEUE_PI" },
Roland McGrath51942a92007-07-05 18:59:11 +00003415 { FUTEX_WAIT|FUTEX_PRIVATE_FLAG, "FUTEX_WAIT_PRIVATE" },
3416 { FUTEX_WAKE|FUTEX_PRIVATE_FLAG, "FUTEX_WAKE_PRIVATE" },
3417 { FUTEX_FD|FUTEX_PRIVATE_FLAG, "FUTEX_FD_PRIVATE" },
3418 { FUTEX_REQUEUE|FUTEX_PRIVATE_FLAG, "FUTEX_REQUEUE_PRIVATE" },
3419 { FUTEX_CMP_REQUEUE|FUTEX_PRIVATE_FLAG, "FUTEX_CMP_REQUEUE_PRIVATE" },
3420 { FUTEX_WAKE_OP|FUTEX_PRIVATE_FLAG, "FUTEX_WAKE_OP_PRIVATE" },
3421 { FUTEX_LOCK_PI|FUTEX_PRIVATE_FLAG, "FUTEX_LOCK_PI_PRIVATE" },
3422 { FUTEX_UNLOCK_PI|FUTEX_PRIVATE_FLAG, "FUTEX_UNLOCK_PI_PRIVATE" },
3423 { FUTEX_TRYLOCK_PI|FUTEX_PRIVATE_FLAG, "FUTEX_TRYLOCK_PI_PRIVATE" },
Roland McGrath1aeaf742008-07-18 01:27:39 +00003424 { FUTEX_WAIT_BITSET|FUTEX_PRIVATE_FLAG, "FUTEX_WAIT_BITSET_PRIVATE" },
3425 { FUTEX_WAKE_BITSET|FUTEX_PRIVATE_FLAG, "FUTEX_WAKE_BITSET_PRIVATE" },
Andreas Schwab85f58322009-08-12 09:54:42 +02003426 { FUTEX_WAIT_REQUEUE_PI|FUTEX_PRIVATE_FLAG, "FUTEX_WAIT_REQUEUE_PI_PRIVATE" },
3427 { FUTEX_CMP_REQUEUE_PI|FUTEX_PRIVATE_FLAG, "FUTEX_CMP_REQUEUE_PI_PRIVATE" },
3428 { FUTEX_WAIT_BITSET|FUTEX_CLOCK_REALTIME, "FUTEX_WAIT_BITSET|FUTEX_CLOCK_REALTIME" },
3429 { FUTEX_WAIT_BITSET|FUTEX_PRIVATE_FLAG|FUTEX_CLOCK_REALTIME, "FUTEX_WAIT_BITSET_PRIVATE|FUTEX_CLOCK_REALTIME" },
3430 { FUTEX_WAIT_REQUEUE_PI|FUTEX_CLOCK_REALTIME, "FUTEX_WAIT_REQUEUE_PI|FUTEX_CLOCK_REALTIME" },
3431 { 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 +00003432 { 0, NULL }
3433};
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003434# ifndef FUTEX_OP_SET
3435# define FUTEX_OP_SET 0
3436# define FUTEX_OP_ADD 1
3437# define FUTEX_OP_OR 2
3438# define FUTEX_OP_ANDN 3
3439# define FUTEX_OP_XOR 4
3440# define FUTEX_OP_CMP_EQ 0
3441# define FUTEX_OP_CMP_NE 1
3442# define FUTEX_OP_CMP_LT 2
3443# define FUTEX_OP_CMP_LE 3
3444# define FUTEX_OP_CMP_GT 4
3445# define FUTEX_OP_CMP_GE 5
3446# endif
Roland McGrath51942a92007-07-05 18:59:11 +00003447static const struct xlat futexwakeops[] = {
3448 { FUTEX_OP_SET, "FUTEX_OP_SET" },
3449 { FUTEX_OP_ADD, "FUTEX_OP_ADD" },
3450 { FUTEX_OP_OR, "FUTEX_OP_OR" },
3451 { FUTEX_OP_ANDN, "FUTEX_OP_ANDN" },
3452 { FUTEX_OP_XOR, "FUTEX_OP_XOR" },
3453 { 0, NULL }
3454};
3455static const struct xlat futexwakecmps[] = {
3456 { FUTEX_OP_CMP_EQ, "FUTEX_OP_CMP_EQ" },
3457 { FUTEX_OP_CMP_NE, "FUTEX_OP_CMP_NE" },
3458 { FUTEX_OP_CMP_LT, "FUTEX_OP_CMP_LT" },
3459 { FUTEX_OP_CMP_LE, "FUTEX_OP_CMP_LE" },
3460 { FUTEX_OP_CMP_GT, "FUTEX_OP_CMP_GT" },
3461 { FUTEX_OP_CMP_GE, "FUTEX_OP_CMP_GE" },
3462 { 0, NULL }
Roland McGrath5a223472002-12-15 23:58:26 +00003463};
3464
3465int
Denys Vlasenko1d632462009-04-14 12:51:00 +00003466sys_futex(struct tcb *tcp)
Roland McGrath5a223472002-12-15 23:58:26 +00003467{
Denys Vlasenko1d632462009-04-14 12:51:00 +00003468 if (entering(tcp)) {
3469 long int cmd = tcp->u_arg[1] & 127;
3470 tprintf("%p, ", (void *) tcp->u_arg[0]);
3471 printxval(futexops, tcp->u_arg[1], "FUTEX_???");
3472 tprintf(", %ld", tcp->u_arg[2]);
3473 if (cmd == FUTEX_WAKE_BITSET)
3474 tprintf(", %lx", tcp->u_arg[5]);
3475 else if (cmd == FUTEX_WAIT) {
3476 tprintf(", ");
3477 printtv(tcp, tcp->u_arg[3]);
3478 } else if (cmd == FUTEX_WAIT_BITSET) {
3479 tprintf(", ");
3480 printtv(tcp, tcp->u_arg[3]);
3481 tprintf(", %lx", tcp->u_arg[5]);
3482 } else if (cmd == FUTEX_REQUEUE)
3483 tprintf(", %ld, %p", tcp->u_arg[3], (void *) tcp->u_arg[4]);
Andreas Schwab85f58322009-08-12 09:54:42 +02003484 else if (cmd == FUTEX_CMP_REQUEUE || cmd == FUTEX_CMP_REQUEUE_PI)
Denys Vlasenko1d632462009-04-14 12:51:00 +00003485 tprintf(", %ld, %p, %ld", tcp->u_arg[3], (void *) tcp->u_arg[4], tcp->u_arg[5]);
3486 else if (cmd == FUTEX_WAKE_OP) {
3487 tprintf(", %ld, %p, {", tcp->u_arg[3], (void *) tcp->u_arg[4]);
3488 if ((tcp->u_arg[5] >> 28) & 8)
3489 tprintf("FUTEX_OP_OPARG_SHIFT|");
3490 printxval(futexwakeops, (tcp->u_arg[5] >> 28) & 0x7, "FUTEX_OP_???");
3491 tprintf(", %ld, ", (tcp->u_arg[5] >> 12) & 0xfff);
3492 if ((tcp->u_arg[5] >> 24) & 8)
3493 tprintf("FUTEX_OP_OPARG_SHIFT|");
3494 printxval(futexwakecmps, (tcp->u_arg[5] >> 24) & 0x7, "FUTEX_OP_CMP_???");
3495 tprintf(", %ld}", tcp->u_arg[5] & 0xfff);
Andreas Schwab85f58322009-08-12 09:54:42 +02003496 } else if (cmd == FUTEX_WAIT_REQUEUE_PI) {
3497 tprintf(", ");
3498 printtv(tcp, tcp->u_arg[3]);
3499 tprintf(", %p", (void *) tcp->u_arg[4]);
Denys Vlasenko1d632462009-04-14 12:51:00 +00003500 }
Roland McGrath51942a92007-07-05 18:59:11 +00003501 }
Denys Vlasenko1d632462009-04-14 12:51:00 +00003502 return 0;
Roland McGrath5a223472002-12-15 23:58:26 +00003503}
3504
3505static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00003506print_affinitylist(struct tcb *tcp, long list, unsigned int len)
Roland McGrath5a223472002-12-15 23:58:26 +00003507{
Denys Vlasenko1d632462009-04-14 12:51:00 +00003508 int first = 1;
Dmitry V. Levin62e05962009-11-03 14:38:44 +00003509 unsigned long w, min_len;
3510
3511 if (abbrev(tcp) && len / sizeof(w) > max_strlen)
3512 min_len = len - max_strlen * sizeof(w);
3513 else
3514 min_len = 0;
3515 for (; len >= sizeof(w) && len > min_len;
3516 len -= sizeof(w), list += sizeof(w)) {
3517 if (umove(tcp, list, &w) < 0)
3518 break;
3519 if (first)
3520 tprintf("{");
3521 else
3522 tprintf(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00003523 first = 0;
Dmitry V. Levin62e05962009-11-03 14:38:44 +00003524 tprintf("%lx", w);
Denys Vlasenko1d632462009-04-14 12:51:00 +00003525 }
Dmitry V. Levin62e05962009-11-03 14:38:44 +00003526 if (len) {
3527 if (first)
3528 tprintf("%#lx", list);
3529 else
3530 tprintf(", %s}", (len >= sizeof(w) && len > min_len ?
3531 "???" : "..."));
3532 } else {
3533 tprintf(first ? "{}" : "}");
3534 }
Roland McGrath5a223472002-12-15 23:58:26 +00003535}
3536
3537int
Denys Vlasenko1d632462009-04-14 12:51:00 +00003538sys_sched_setaffinity(struct tcb *tcp)
Roland McGrath5a223472002-12-15 23:58:26 +00003539{
Denys Vlasenko1d632462009-04-14 12:51:00 +00003540 if (entering(tcp)) {
3541 tprintf("%ld, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
3542 print_affinitylist(tcp, tcp->u_arg[2], tcp->u_arg[1]);
3543 }
3544 return 0;
Roland McGrath5a223472002-12-15 23:58:26 +00003545}
3546
3547int
Denys Vlasenko1d632462009-04-14 12:51:00 +00003548sys_sched_getaffinity(struct tcb *tcp)
Roland McGrath5a223472002-12-15 23:58:26 +00003549{
Denys Vlasenko1d632462009-04-14 12:51:00 +00003550 if (entering(tcp)) {
3551 tprintf("%ld, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
3552 } else {
3553 if (tcp->u_rval == -1)
3554 tprintf("%#lx", tcp->u_arg[2]);
3555 else
3556 print_affinitylist(tcp, tcp->u_arg[2], tcp->u_rval);
3557 }
3558 return 0;
Roland McGrath5a223472002-12-15 23:58:26 +00003559}
Roland McGrath279d3782004-03-01 20:27:37 +00003560
Roland McGrathd9f816f2004-09-04 03:39:20 +00003561static const struct xlat schedulers[] = {
Roland McGrath279d3782004-03-01 20:27:37 +00003562 { SCHED_OTHER, "SCHED_OTHER" },
3563 { SCHED_RR, "SCHED_RR" },
3564 { SCHED_FIFO, "SCHED_FIFO" },
3565 { 0, NULL }
3566};
3567
3568int
Denys Vlasenko1d632462009-04-14 12:51:00 +00003569sys_sched_getscheduler(struct tcb *tcp)
Roland McGrath279d3782004-03-01 20:27:37 +00003570{
Denys Vlasenko1d632462009-04-14 12:51:00 +00003571 if (entering(tcp)) {
3572 tprintf("%d", (int) tcp->u_arg[0]);
3573 } else if (! syserror(tcp)) {
3574 tcp->auxstr = xlookup (schedulers, tcp->u_rval);
3575 if (tcp->auxstr != NULL)
3576 return RVAL_STR;
3577 }
3578 return 0;
Roland McGrath279d3782004-03-01 20:27:37 +00003579}
3580
3581int
Denys Vlasenko1d632462009-04-14 12:51:00 +00003582sys_sched_setscheduler(struct tcb *tcp)
Roland McGrath279d3782004-03-01 20:27:37 +00003583{
Denys Vlasenko1d632462009-04-14 12:51:00 +00003584 if (entering(tcp)) {
3585 struct sched_param p;
3586 tprintf("%d, ", (int) tcp->u_arg[0]);
3587 printxval(schedulers, tcp->u_arg[1], "SCHED_???");
3588 if (umove(tcp, tcp->u_arg[2], &p) < 0)
3589 tprintf(", %#lx", tcp->u_arg[2]);
3590 else
3591 tprintf(", { %d }", p.__sched_priority);
3592 }
3593 return 0;
Roland McGrath279d3782004-03-01 20:27:37 +00003594}
3595
3596int
Denys Vlasenko1d632462009-04-14 12:51:00 +00003597sys_sched_getparam(struct tcb *tcp)
Roland McGrath279d3782004-03-01 20:27:37 +00003598{
Denys Vlasenko1d632462009-04-14 12:51:00 +00003599 if (entering(tcp)) {
3600 tprintf("%d, ", (int) tcp->u_arg[0]);
3601 } else {
3602 struct sched_param p;
3603 if (umove(tcp, tcp->u_arg[1], &p) < 0)
3604 tprintf("%#lx", tcp->u_arg[1]);
3605 else
3606 tprintf("{ %d }", p.__sched_priority);
3607 }
3608 return 0;
Roland McGrath279d3782004-03-01 20:27:37 +00003609}
3610
3611int
Denys Vlasenko1d632462009-04-14 12:51:00 +00003612sys_sched_setparam(struct tcb *tcp)
Roland McGrath279d3782004-03-01 20:27:37 +00003613{
Denys Vlasenko1d632462009-04-14 12:51:00 +00003614 if (entering(tcp)) {
3615 struct sched_param p;
3616 if (umove(tcp, tcp->u_arg[1], &p) < 0)
3617 tprintf("%d, %#lx", (int) tcp->u_arg[0], tcp->u_arg[1]);
3618 else
3619 tprintf("%d, { %d }", (int) tcp->u_arg[0], p.__sched_priority);
3620 }
3621 return 0;
Roland McGrath279d3782004-03-01 20:27:37 +00003622}
3623
3624int
Denys Vlasenko1d632462009-04-14 12:51:00 +00003625sys_sched_get_priority_min(struct tcb *tcp)
Roland McGrath279d3782004-03-01 20:27:37 +00003626{
Denys Vlasenko1d632462009-04-14 12:51:00 +00003627 if (entering(tcp)) {
3628 printxval(schedulers, tcp->u_arg[0], "SCHED_???");
3629 }
3630 return 0;
Roland McGrath279d3782004-03-01 20:27:37 +00003631}
Roland McGrathc2d5eb02005-02-02 04:16:56 +00003632
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003633# ifdef X86_64
3634# include <asm/prctl.h>
Roland McGrathc2d5eb02005-02-02 04:16:56 +00003635
3636static const struct xlat archvals[] = {
3637 { ARCH_SET_GS, "ARCH_SET_GS" },
3638 { ARCH_SET_FS, "ARCH_SET_FS" },
3639 { ARCH_GET_FS, "ARCH_GET_FS" },
3640 { ARCH_GET_GS, "ARCH_GET_GS" },
3641 { 0, NULL },
3642};
3643
3644int
Denys Vlasenko1d632462009-04-14 12:51:00 +00003645sys_arch_prctl(struct tcb *tcp)
Roland McGrathc2d5eb02005-02-02 04:16:56 +00003646{
Denys Vlasenko1d632462009-04-14 12:51:00 +00003647 if (entering(tcp)) {
3648 printxval(archvals, tcp->u_arg[0], "ARCH_???");
3649 if (tcp->u_arg[0] == ARCH_SET_GS
3650 || tcp->u_arg[0] == ARCH_SET_FS
3651 ) {
3652 tprintf(", %#lx", tcp->u_arg[1]);
3653 }
3654 } else {
3655 if (tcp->u_arg[0] == ARCH_GET_GS
3656 || tcp->u_arg[0] == ARCH_GET_FS
3657 ) {
3658 long int v;
3659 if (!syserror(tcp) && umove(tcp, tcp->u_arg[1], &v) != -1)
3660 tprintf(", [%#lx]", v);
3661 else
3662 tprintf(", %#lx", tcp->u_arg[1]);
3663 }
Roland McGrathc2d5eb02005-02-02 04:16:56 +00003664 }
Denys Vlasenko1d632462009-04-14 12:51:00 +00003665 return 0;
Roland McGrathc2d5eb02005-02-02 04:16:56 +00003666}
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003667# endif /* X86_64 */
Roland McGrathc2d5eb02005-02-02 04:16:56 +00003668
Roland McGrathdb8319f2007-08-02 01:37:55 +00003669
3670int
Denys Vlasenko1d632462009-04-14 12:51:00 +00003671sys_getcpu(struct tcb *tcp)
Roland McGrathdb8319f2007-08-02 01:37:55 +00003672{
3673 if (exiting(tcp)) {
3674 unsigned u;
3675 if (tcp->u_arg[0] == 0)
3676 tprintf("NULL, ");
3677 else if (umove(tcp, tcp->u_arg[0], &u) < 0)
3678 tprintf("%#lx, ", tcp->u_arg[0]);
3679 else
3680 tprintf("[%u], ", u);
3681 if (tcp->u_arg[1] == 0)
3682 tprintf("NULL, ");
3683 else if (umove(tcp, tcp->u_arg[1], &u) < 0)
3684 tprintf("%#lx, ", tcp->u_arg[1]);
3685 else
3686 tprintf("[%u], ", u);
3687 tprintf("%#lx", tcp->u_arg[2]);
3688 }
3689 return 0;
3690}
3691
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00003692#endif /* LINUX */