- *
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * $Id$
- */
-
-#include "defs.h"
-
-#include <fcntl.h>
-#include <sys/stat.h>
-#include <sys/time.h>
-#include <sys/wait.h>
-#include <sys/resource.h>
-#include <sys/utsname.h>
-#include <sys/user.h>
-#include <sys/syscall.h>
-#include <signal.h>
-#ifdef SUNOS4
-#include <machine/reg.h>
-#endif /* SUNOS4 */
-
-#ifdef FREEBSD
-#include <sys/ptrace.h>
-#endif
-
-#ifdef HAVE_SYS_REG_H
-# include <sys/reg.h>
-#ifndef PTRACE_PEEKUSR
-# define PTRACE_PEEKUSR PTRACE_PEEKUSER
-#endif
-#ifndef PTRACE_POKEUSR
-# define PTRACE_POKEUSR PTRACE_POKEUSER
-#endif
-#endif
-
-#ifdef HAVE_LINUX_PTRACE_H
-#undef PTRACE_SYSCALL
-# ifdef HAVE_STRUCT_IA64_FPREG
-# define ia64_fpreg XXX_ia64_fpreg
-# endif
-# ifdef HAVE_STRUCT_PT_ALL_USER_REGS
-# define pt_all_user_regs XXX_pt_all_user_regs
-# endif
-#include <linux/ptrace.h>
-# undef ia64_fpreg
-# undef pt_all_user_regs
-#endif
-
-#if defined (LINUX) && defined (SPARC64)
-# define r_pc r_tpc
-# undef PTRACE_GETREGS
-# define PTRACE_GETREGS PTRACE_GETREGS64
-# undef PTRACE_SETREGS
-# define PTRACE_SETREGS PTRACE_SETREGS64
-#endif /* LINUX && SPARC64 */
-
-#ifdef HAVE_LINUX_FUTEX_H
-# include <linux/futex.h>
-#endif
-#ifdef LINUX
-# ifndef FUTEX_WAIT
-# define FUTEX_WAIT 0
-# endif
-# ifndef FUTEX_WAKE
-# define FUTEX_WAKE 1
-# endif
-# ifndef FUTEX_FD
-# define FUTEX_FD 2
-# endif
-# ifndef FUTEX_REQUEUE
-# define FUTEX_REQUEUE 3
-# endif
-#endif /* LINUX */
-
-#ifdef LINUX
-#include <sched.h>
-#include <asm/posix_types.h>
-#undef GETGROUPS_T
-#define GETGROUPS_T __kernel_gid_t
-#undef GETGROUPS32_T
-#define GETGROUPS32_T __kernel_gid32_t
-#endif /* LINUX */
-
-#if defined(LINUX) && defined(IA64)
-# include <asm/ptrace_offsets.h>
-# include <asm/rse.h>
-#endif
-
-#ifdef HAVE_PRCTL
-# include <sys/prctl.h>
-
-static const struct xlat prctl_options[] = {
-#ifdef PR_MAXPROCS
- { PR_MAXPROCS, "PR_MAXPROCS" },
-#endif
-#ifdef PR_ISBLOCKED
- { PR_ISBLOCKED, "PR_ISBLOCKED" },
-#endif
-#ifdef PR_SETSTACKSIZE
- { PR_SETSTACKSIZE, "PR_SETSTACKSIZE" },
-#endif
-#ifdef PR_GETSTACKSIZE
- { PR_GETSTACKSIZE, "PR_GETSTACKSIZE" },
-#endif
-#ifdef PR_MAXPPROCS
- { PR_MAXPPROCS, "PR_MAXPPROCS" },
-#endif
-#ifdef PR_UNBLKONEXEC
- { PR_UNBLKONEXEC, "PR_UNBLKONEXEC" },
-#endif
-#ifdef PR_ATOMICSIM
- { PR_ATOMICSIM, "PR_ATOMICSIM" },
-#endif
-#ifdef PR_SETEXITSIG
- { PR_SETEXITSIG, "PR_SETEXITSIG" },
-#endif
-#ifdef PR_RESIDENT
- { PR_RESIDENT, "PR_RESIDENT" },
-#endif
-#ifdef PR_ATTACHADDR
- { PR_ATTACHADDR, "PR_ATTACHADDR" },
-#endif
-#ifdef PR_DETACHADDR
- { PR_DETACHADDR, "PR_DETACHADDR" },
-#endif
-#ifdef PR_TERMCHILD
- { PR_TERMCHILD, "PR_TERMCHILD" },
-#endif
-#ifdef PR_GETSHMASK
- { PR_GETSHMASK, "PR_GETSHMASK" },
-#endif
-#ifdef PR_GETNSHARE
- { PR_GETNSHARE, "PR_GETNSHARE" },
-#endif
-#ifdef PR_COREPID
- { PR_COREPID, "PR_COREPID" },
-#endif
-#ifdef PR_ATTACHADDRPERM
- { PR_ATTACHADDRPERM, "PR_ATTACHADDRPERM" },
-#endif
-#ifdef PR_PTHREADEXIT
- { PR_PTHREADEXIT, "PR_PTHREADEXIT" },
-#endif
-#ifdef PR_SET_PDEATHSIG
- { PR_SET_PDEATHSIG, "PR_SET_PDEATHSIG" },
-#endif
-#ifdef PR_GET_PDEATHSIG
- { PR_GET_PDEATHSIG, "PR_GET_PDEATHSIG" },
-#endif
-#ifdef PR_GET_DUMPABLE
- { PR_GET_DUMPABLE, "PR_GET_DUMPABLE" },
-#endif
-#ifdef PR_SET_DUMPABLE
- { PR_SET_DUMPABLE, "PR_SET_DUMPABLE" },
-#endif
-#ifdef PR_GET_UNALIGN
- { PR_GET_UNALIGN, "PR_GET_UNALIGN" },
-#endif
-#ifdef PR_SET_UNALIGN
- { PR_SET_UNALIGN, "PR_SET_UNALIGN" },
-#endif
-#ifdef PR_GET_KEEPCAPS
- { PR_GET_KEEPCAPS, "PR_GET_KEEPCAPS" },
-#endif
-#ifdef PR_SET_KEEPCAPS
- { PR_SET_KEEPCAPS, "PR_SET_KEEPCAPS" },
-#endif
-#ifdef PR_GET_FPEMU
- { PR_GET_FPEMU, "PR_GET_FPEMU" },
-#endif
-#ifdef PR_SET_FPEMU
- { PR_SET_FPEMU, "PR_SET_FPEMU" },
-#endif
-#ifdef PR_GET_FPEXC
- { PR_GET_FPEXC, "PR_GET_FPEXC" },
-#endif
-#ifdef PR_SET_FPEXC
- { PR_SET_FPEXC, "PR_SET_FPEXC" },
-#endif
-#ifdef PR_GET_TIMING
- { PR_GET_TIMING, "PR_GET_TIMING" },
-#endif
-#ifdef PR_SET_TIMING
- { PR_SET_TIMING, "PR_SET_TIMING" },
-#endif
-#ifdef PR_SET_NAME
- { PR_SET_NAME, "PR_SET_NAME" },
-#endif
-#ifdef PR_GET_NAME
- { PR_GET_NAME, "PR_GET_NAME" },
-#endif
-#ifdef PR_GET_ENDIAN
- { PR_GET_ENDIAN, "PR_GET_ENDIAN" },
-#endif
-#ifdef PR_SET_ENDIAN
- { PR_SET_ENDIAN, "PR_SET_ENDIAN" },
-#endif
-#ifdef PR_GET_SECCOMP
- { PR_GET_SECCOMP, "PR_GET_SECCOMP" },
-#endif
-#ifdef PR_SET_SECCOMP
- { PR_SET_SECCOMP, "PR_SET_SECCOMP" },
-#endif
-#ifdef PR_GET_TSC
- { PR_GET_TSC, "PR_GET_TSC" },
-#endif
-#ifdef PR_SET_TSC
- { PR_SET_TSC, "PR_SET_TSC" },
-#endif
-#ifdef PR_GET_SECUREBITS
- { PR_GET_SECUREBITS, "PR_GET_SECUREBITS" },
-#endif
-#ifdef PR_SET_SECUREBITS
- { PR_SET_SECUREBITS, "PR_SET_SECUREBITS" },
-#endif
- { 0, NULL },
-};
-
-
-static const char *
-unalignctl_string(unsigned int ctl)
-{
- static char buf[16];
-
- switch (ctl) {
-#ifdef PR_UNALIGN_NOPRINT
- case PR_UNALIGN_NOPRINT:
- return "NOPRINT";
-#endif
-#ifdef PR_UNALIGN_SIGBUS
- case PR_UNALIGN_SIGBUS:
- return "SIGBUS";
-#endif
- default:
- break;
- }
- sprintf(buf, "%x", ctl);
- return buf;
-}
-
-
-int
-sys_prctl(struct tcb *tcp)
-{
- int i;
-
- if (entering(tcp)) {
- printxval(prctl_options, tcp->u_arg[0], "PR_???");
- switch (tcp->u_arg[0]) {
-#ifdef PR_GETNSHARE
- case PR_GETNSHARE:
- break;
-#endif
-#ifdef PR_SET_PDEATHSIG
- case PR_SET_PDEATHSIG:
- tprintf(", %lu", tcp->u_arg[1]);
- break;
-#endif
-#ifdef PR_GET_PDEATHSIG
- case PR_GET_PDEATHSIG:
- break;
-#endif
-#ifdef PR_SET_DUMPABLE
- case PR_SET_DUMPABLE:
- tprintf(", %lu", tcp->u_arg[1]);
- break;
-#endif
-#ifdef PR_GET_DUMPABLE
- case PR_GET_DUMPABLE:
- break;
-#endif
-#ifdef PR_SET_UNALIGN
- case PR_SET_UNALIGN:
- tprintf(", %s", unalignctl_string(tcp->u_arg[1]));
- break;
-#endif
-#ifdef PR_GET_UNALIGN
- case PR_GET_UNALIGN:
- tprintf(", %#lx", tcp->u_arg[1]);
- break;
-#endif
-#ifdef PR_SET_KEEPCAPS
- case PR_SET_KEEPCAPS:
- tprintf(", %lu", tcp->u_arg[1]);
- break;
-#endif
-#ifdef PR_GET_KEEPCAPS
- case PR_GET_KEEPCAPS:
- break;
-#endif
- default:
- for (i = 1; i < tcp->u_nargs; i++)
- tprintf(", %#lx", tcp->u_arg[i]);
- break;
- }
- } else {
- switch (tcp->u_arg[0]) {
-#ifdef PR_GET_PDEATHSIG
- case PR_GET_PDEATHSIG:
- if (umove(tcp, tcp->u_arg[1], &i) < 0)
- tprintf(", %#lx", tcp->u_arg[1]);
- else
- tprintf(", {%u}", i);
- break;
-#endif
-#ifdef PR_GET_DUMPABLE
- case PR_GET_DUMPABLE:
- return RVAL_UDECIMAL;
-#endif
-#ifdef PR_GET_UNALIGN
- case PR_GET_UNALIGN:
- if (syserror(tcp) || umove(tcp, tcp->u_arg[1], &i) < 0)
- break;
- tcp->auxstr = unalignctl_string(i);
- return RVAL_STR;
-#endif
-#ifdef PR_GET_KEEPCAPS
- case PR_GET_KEEPCAPS:
- return RVAL_UDECIMAL;
-#endif
- default:
- break;
- }
- }
- return 0;
-}
-#endif /* HAVE_PRCTL */
-
-#if defined(FREEBSD) || defined(SUNOS4) || defined(SVR4)
-int
-sys_gethostid(struct tcb *tcp)
-{
- if (exiting(tcp))
- return RVAL_HEX;
- return 0;
-}
-#endif /* FREEBSD || SUNOS4 || SVR4 */
-
-int
-sys_sethostname(struct tcb *tcp)
-{
- if (entering(tcp)) {
- printpathn(tcp, tcp->u_arg[0], tcp->u_arg[1]);
- tprintf(", %lu", tcp->u_arg[1]);
- }
- return 0;
-}
-
-#if defined(ALPHA) || defined(FREEBSD) || defined(SUNOS4) || defined(SVR4)
-int
-sys_gethostname(struct tcb *tcp)
-{
- if (exiting(tcp)) {
- if (syserror(tcp))
- tprintf("%#lx", tcp->u_arg[0]);
- else
- printpath(tcp, tcp->u_arg[0]);
- tprintf(", %lu", tcp->u_arg[1]);
- }
- return 0;
-}
-#endif /* ALPHA || FREEBSD || SUNOS4 || SVR4 */
-
-int
-sys_setdomainname(struct tcb *tcp)
-{
- if (entering(tcp)) {
- printpathn(tcp, tcp->u_arg[0], tcp->u_arg[1]);
- tprintf(", %lu", tcp->u_arg[1]);
- }
- return 0;
-}
-
-#if !defined(LINUX)
-
-int
-sys_getdomainname(struct tcb *tcp)
-{
- if (exiting(tcp)) {
- if (syserror(tcp))
- tprintf("%#lx", tcp->u_arg[0]);
- else
- printpath(tcp, tcp->u_arg[0]);
- tprintf(", %lu", tcp->u_arg[1]);
- }
- return 0;
-}
-#endif /* !LINUX */
-
-int
-sys_exit(struct tcb *tcp)
-{
- if (exiting(tcp)) {
- fprintf(stderr, "_exit returned!\n");
- return -1;
- }
- /* special case: we stop tracing this process, finish line now */
- tprintf("%ld) ", tcp->u_arg[0]);
- tabto(acolumn);
- tprintf("= ?");
- printtrailer();
- return 0;
-}
-
-#ifdef USE_PROCFS
-
-int
-sys_fork(struct tcb *tcp)
-{
- if (exiting(tcp) && !syserror(tcp)) {
- if (getrval2(tcp)) {
- tcp->auxstr = "child process";
- return RVAL_UDECIMAL | RVAL_STR;
- }
- }
- return 0;
-}
-
-#if UNIXWARE > 2
-
-int
-sys_rfork(struct tcb *tcp)
-{
- if (entering(tcp)) {
- tprintf("%ld", tcp->u_arg[0]);
- }
- else if (!syserror(tcp)) {
- if (getrval2(tcp)) {
- tcp->auxstr = "child process";
- return RVAL_UDECIMAL | RVAL_STR;
- }
- }
- return 0;
-}
-
-#endif
-
-int
-internal_fork(struct tcb *tcp)
-{
- struct tcb *tcpchild;
-
- if (exiting(tcp)) {
-#ifdef SYS_rfork
- if (known_scno(tcp) == SYS_rfork && !(tcp->u_arg[0]&RFPROC))
- return 0;
-#endif
- if (getrval2(tcp))
- return 0;
- if (!followfork)
- return 0;
- if (syserror(tcp))
- return 0;
- tcpchild = alloctcb(tcp->u_rval);
- if (proc_open(tcpchild, 2) < 0)
- droptcb(tcpchild);
- }
- return 0;
-}
-
-#else /* !USE_PROCFS */
-
-#ifdef LINUX
-
-/* defines copied from linux/sched.h since we can't include that
- * ourselves (it conflicts with *lots* of libc includes)
- */
-#define CSIGNAL 0x000000ff /* signal mask to be sent at exit */
-#define CLONE_VM 0x00000100 /* set if VM shared between processes */
-#define CLONE_FS 0x00000200 /* set if fs info shared between processes */
-#define CLONE_FILES 0x00000400 /* set if open files shared between processes */
-#define CLONE_SIGHAND 0x00000800 /* set if signal handlers shared */
-#define CLONE_IDLETASK 0x00001000 /* kernel-only flag */
-#define CLONE_PTRACE 0x00002000 /* set if we want to let tracing continue on the child too */
-#define CLONE_VFORK 0x00004000 /* set if the parent wants the child to wake it up on mm_release */
-#define CLONE_PARENT 0x00008000 /* set if we want to have the same parent as the cloner */
-#define CLONE_THREAD 0x00010000 /* Same thread group? */
-#define CLONE_NEWNS 0x00020000 /* New namespace group? */
-#define CLONE_SYSVSEM 0x00040000 /* share system V SEM_UNDO semantics */
-#define CLONE_SETTLS 0x00080000 /* create a new TLS for the child */
-#define CLONE_PARENT_SETTID 0x00100000 /* set the TID in the parent */
-#define CLONE_CHILD_CLEARTID 0x00200000 /* clear the TID in the child */
-#define CLONE_UNTRACED 0x00800000 /* set if the tracing process can't force CLONE_PTRACE on this clone */
-#define CLONE_CHILD_SETTID 0x01000000 /* set the TID in the child */
-#define CLONE_STOPPED 0x02000000 /* Start in stopped state */
-#define CLONE_NEWUTS 0x04000000 /* New utsname group? */
-#define CLONE_NEWIPC 0x08000000 /* New ipcs */
-#define CLONE_NEWUSER 0x10000000 /* New user namespace */
-#define CLONE_NEWPID 0x20000000 /* New pid namespace */
-#define CLONE_NEWNET 0x40000000 /* New network namespace */
-#define CLONE_IO 0x80000000 /* Clone io context */
-
-static const struct xlat clone_flags[] = {
- { CLONE_VM, "CLONE_VM" },
- { CLONE_FS, "CLONE_FS" },
- { CLONE_FILES, "CLONE_FILES" },
- { CLONE_SIGHAND, "CLONE_SIGHAND" },
- { CLONE_IDLETASK, "CLONE_IDLETASK"},
- { CLONE_PTRACE, "CLONE_PTRACE" },
- { CLONE_VFORK, "CLONE_VFORK" },
- { CLONE_PARENT, "CLONE_PARENT" },
- { CLONE_THREAD, "CLONE_THREAD" },
- { CLONE_NEWNS, "CLONE_NEWNS" },
- { CLONE_SYSVSEM, "CLONE_SYSVSEM" },
- { CLONE_SETTLS, "CLONE_SETTLS" },
- { CLONE_PARENT_SETTID,"CLONE_PARENT_SETTID" },
- { CLONE_CHILD_CLEARTID,"CLONE_CHILD_CLEARTID" },
- { CLONE_UNTRACED, "CLONE_UNTRACED" },
- { CLONE_CHILD_SETTID,"CLONE_CHILD_SETTID" },
- { CLONE_STOPPED, "CLONE_STOPPED" },
- { CLONE_NEWUTS, "CLONE_NEWUTS" },
- { CLONE_NEWIPC, "CLONE_NEWIPC" },
- { CLONE_NEWUSER, "CLONE_NEWUSER" },
- { CLONE_NEWPID, "CLONE_NEWPID" },
- { CLONE_NEWNET, "CLONE_NEWNET" },
- { CLONE_IO, "CLONE_IO" },
- { 0, NULL },
-};
-
-# ifdef I386
-# include <asm/ldt.h>
-# ifdef HAVE_STRUCT_USER_DESC
-# define modify_ldt_ldt_s user_desc
-# endif
-extern void print_ldt_entry();
-# endif
-
-# if defined IA64
-# define ARG_FLAGS 0
-# define ARG_STACK 1
-# define ARG_STACKSIZE (known_scno(tcp) == SYS_clone2 ? 2 : -1)
-# define ARG_PTID (known_scno(tcp) == SYS_clone2 ? 3 : 2)
-# define ARG_CTID (known_scno(tcp) == SYS_clone2 ? 4 : 3)
-# define ARG_TLS (known_scno(tcp) == SYS_clone2 ? 5 : 4)
-# elif defined S390 || defined S390X || defined CRISV10 || defined CRISV32
-# define ARG_STACK 0
-# define ARG_FLAGS 1
-# define ARG_PTID 2
-# define ARG_CTID 3
-# define ARG_TLS 4
-# elif defined X86_64 || defined ALPHA
-# define ARG_FLAGS 0
-# define ARG_STACK 1
-# define ARG_PTID 2
-# define ARG_CTID 3
-# define ARG_TLS 4
-# else
-# define ARG_FLAGS 0
-# define ARG_STACK 1
-# define ARG_PTID 2
-# define ARG_TLS 3
-# define ARG_CTID 4
-# endif
-
-int
-sys_clone(struct tcb *tcp)
-{
- if (exiting(tcp)) {
- const char *sep = "|";
- unsigned long flags = tcp->u_arg[ARG_FLAGS];
- tprintf("child_stack=%#lx, ", tcp->u_arg[ARG_STACK]);
-# ifdef ARG_STACKSIZE
- if (ARG_STACKSIZE != -1)
- tprintf("stack_size=%#lx, ",
- tcp->u_arg[ARG_STACKSIZE]);
-# endif
- tprintf("flags=");
- if (!printflags(clone_flags, flags &~ CSIGNAL, NULL))
- sep = "";
- if ((flags & CSIGNAL) != 0)
- tprintf("%s%s", sep, signame(flags & CSIGNAL));
- if ((flags & (CLONE_PARENT_SETTID|CLONE_CHILD_SETTID
- |CLONE_CHILD_CLEARTID|CLONE_SETTLS)) == 0)
- return 0;
- if (flags & CLONE_PARENT_SETTID)
- tprintf(", parent_tidptr=%#lx", tcp->u_arg[ARG_PTID]);
- if (flags & CLONE_SETTLS) {
-# ifdef I386
- struct modify_ldt_ldt_s copy;
- if (umove(tcp, tcp->u_arg[ARG_TLS], ©) != -1) {
- tprintf(", {entry_number:%d, ",
- copy.entry_number);
- if (!verbose(tcp))
- tprintf("...}");
- else
- print_ldt_entry(©);
- }
- else
-# endif
- tprintf(", tls=%#lx", tcp->u_arg[ARG_TLS]);
- }
- if (flags & (CLONE_CHILD_SETTID|CLONE_CHILD_CLEARTID))
- tprintf(", child_tidptr=%#lx", tcp->u_arg[ARG_CTID]);
- }
- return 0;
-}
-
-int
-sys_unshare(struct tcb *tcp)
-{
- if (entering(tcp))
- printflags(clone_flags, tcp->u_arg[0], "CLONE_???");
- return 0;
-}
-#endif /* LINUX */
-
-int
-sys_fork(struct tcb *tcp)
-{
- if (exiting(tcp))
- return RVAL_UDECIMAL;
- return 0;
-}
-
-int
-change_syscall(struct tcb *tcp, int new)
-{
-#ifdef LINUX
-#if defined(I386)
- /* Attempt to make vfork into fork, which we can follow. */
- if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(ORIG_EAX * 4), new) < 0)
- return -1;
- return 0;
-#elif defined(X86_64)
- /* Attempt to make vfork into fork, which we can follow. */
- if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(ORIG_RAX * 8), new) < 0)
- return -1;
- return 0;
-#elif defined(POWERPC)
- if (ptrace(PTRACE_POKEUSER, tcp->pid,
- (char*)(sizeof(unsigned long)*PT_R0), new) < 0)
- return -1;
- return 0;
-#elif defined(S390) || defined(S390X)
- /* s390 linux after 2.4.7 has a hook in entry.S to allow this */
- if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(PT_GPR2), new) < 0)
- return -1;
- return 0;
-#elif defined(M68K)
- if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(4*PT_ORIG_D0), new) < 0)
- return -1;
- return 0;
-#elif defined(SPARC) || defined(SPARC64)
- struct pt_regs regs;
- if (ptrace(PTRACE_GETREGS, tcp->pid, (char*)®s, 0) < 0)
- return -1;
- regs.u_regs[U_REG_G1] = new;
- if (ptrace(PTRACE_SETREGS, tcp->pid, (char*)®s, 0) < 0)
- return -1;
- return 0;
-#elif defined(MIPS)
- if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(REG_V0), new) < 0)
- return -1;
- return 0;
-#elif defined(ALPHA)
- if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(REG_A3), new) < 0)
- return -1;
- return 0;
-#elif defined(AVR32)
- if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(REG_R8), new) < 0)
- return -1;
- return 0;
-#elif defined(BFIN)
- if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(REG_P0), new) < 0)
- return -1;
- return 0;
-#elif defined(IA64)
- if (ia32) {
- switch (new) {
- case 2:
- break; /* x86 SYS_fork */
- case SYS_clone:
- new = 120;
- break;
- default:
- fprintf(stderr, "%s: unexpected syscall %d\n",
- __FUNCTION__, new);
- return -1;
- }
- if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(PT_R1), new) < 0)
- return -1;
- } else if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(PT_R15), new) < 0)
- return -1;
- return 0;
-#elif defined(HPPA)
- if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(PT_GR20), new) < 0)
- return -1;
- return 0;
-#elif defined(SH)
- if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(4*(REG_REG0+3)), new) < 0)
- return -1;
- return 0;
-#elif defined(SH64)
- /* Top half of reg encodes the no. of args n as 0x1n.
- Assume 0 args as kernel never actually checks... */
- if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(REG_SYSCALL),
- 0x100000 | new) < 0)
- return -1;
- return 0;
-#elif defined(CRISV10) || defined(CRISV32)
- if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(4*PT_R9), new) < 0)
- return -1;
- return 0;
-#elif defined(ARM)
- /* Some kernels support this, some (pre-2.6.16 or so) don't. */
-# ifndef PTRACE_SET_SYSCALL
-# define PTRACE_SET_SYSCALL 23
-# endif
-
- if (ptrace(PTRACE_SET_SYSCALL, tcp->pid, 0, new & 0xffff) != 0)
- return -1;
-
- return 0;
-#elif defined(TILE)
- if (ptrace(PTRACE_POKEUSER, tcp->pid,
- (char*)PTREGS_OFFSET_REG(0),
- new) != 0)
- return -1;
- return 0;
-#elif defined(MICROBLAZE)
- if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(PT_GPR(0)), new) < 0)
- return -1;
- return 0;
-#else
-#warning Do not know how to handle change_syscall for this architecture
-#endif /* architecture */
-#endif /* LINUX */
- return -1;
-}
-
-#ifdef LINUX
-
-int
-internal_fork(struct tcb *tcp)
-{
- if ((ptrace_setoptions
- & (PTRACE_O_TRACECLONE | PTRACE_O_TRACEFORK | PTRACE_O_TRACEVFORK))
- == (PTRACE_O_TRACECLONE | PTRACE_O_TRACEFORK | PTRACE_O_TRACEVFORK))
- return 0;
-
- if (!followfork)
- return 0;
-
- if (entering(tcp)) {
- /*
- * We won't see the new child if clone is called with
- * CLONE_UNTRACED, so we keep the same logic with that option
- * and don't trace it.
- */
- if ((sysent[tcp->scno].sys_func == sys_clone) &&
- (tcp->u_arg[ARG_FLAGS] & CLONE_UNTRACED))
- return 0;
- setbpt(tcp);
- } else {
- if (tcp->flags & TCB_BPTSET)
- clearbpt(tcp);
- }
- return 0;
-}
-
-#else /* !LINUX */
-
-int
-internal_fork(struct tcb *tcp)
-{
- struct tcb *tcpchild;
- int pid;
- int dont_follow = 0;
-
-#ifdef SYS_vfork
- if (known_scno(tcp) == SYS_vfork) {
- /* Attempt to make vfork into fork, which we can follow. */
- if (change_syscall(tcp, SYS_fork) < 0)
- dont_follow = 1;
- }
-#endif
-
- if (!followfork)
- return 0;
-
- if (entering(tcp)) {
- if (dont_follow)
- return 0;
- setbpt(tcp);
- }
- else {
- int bpt = tcp->flags & TCB_BPTSET;
-
- if (bpt)
- clearbpt(tcp);
-
- if (syserror(tcp))
- return 0;
-
- pid = tcp->u_rval;
- tcpchild = alloctcb(pid);
-#ifdef SUNOS4
-#ifdef oldway
- /* The child must have run before it can be attached. */
- {
- struct timeval tv;
- tv.tv_sec = 0;
- tv.tv_usec = 10000;
- select(0, NULL, NULL, NULL, &tv);
- }
- if (ptrace(PTRACE_ATTACH, pid, (char *)1, 0) < 0) {
- perror("PTRACE_ATTACH");
- fprintf(stderr, "Too late?\n");
- droptcb(tcpchild);
- return 0;
- }
-#else /* !oldway */
- /* Try to catch the new process as soon as possible. */
- {
- int i;
- for (i = 0; i < 1024; i++)
- if (ptrace(PTRACE_ATTACH, pid, (char *) 1, 0) >= 0)
- break;
- if (i == 1024) {
- perror("PTRACE_ATTACH");
- fprintf(stderr, "Too late?\n");
- droptcb(tcpchild);
- return 0;
- }
- }
-#endif /* !oldway */
-#endif /* SUNOS4 */
- tcpchild->flags |= TCB_ATTACHED;
- /* Child has BPT too, must be removed on first occasion */
- if (bpt) {
- tcpchild->flags |= TCB_BPTSET;
- tcpchild->baddr = tcp->baddr;
- memcpy(tcpchild->inst, tcp->inst,
- sizeof tcpchild->inst);
- }
- if (!qflag)
- fprintf(stderr, "Process %d attached\n", pid);
- }
- return 0;
-}
-
-#endif /* !LINUX */
-
-#endif /* !USE_PROCFS */
-
-#if defined(SUNOS4) || defined(LINUX) || defined(FREEBSD)
-
-int
-sys_vfork(struct tcb *tcp)
-{
- if (exiting(tcp))
- return RVAL_UDECIMAL;
- return 0;
-}
-
-#endif /* SUNOS4 || LINUX || FREEBSD */
-
-#ifndef LINUX
-
-static char idstr[16];
-
-int
-sys_getpid(struct tcb *tcp)
-{
- if (exiting(tcp)) {
- sprintf(idstr, "ppid %lu", getrval2(tcp));
- tcp->auxstr = idstr;
- return RVAL_STR;
- }
- return 0;
-}
-
-int
-sys_getuid(struct tcb *tcp)
-{
- if (exiting(tcp)) {
- sprintf(idstr, "euid %lu", getrval2(tcp));
- tcp->auxstr = idstr;
- return RVAL_STR;
- }
- return 0;
-}
-
-int
-sys_getgid(struct tcb *tcp)
-{
- if (exiting(tcp)) {
- sprintf(idstr, "egid %lu", getrval2(tcp));
- tcp->auxstr = idstr;
- return RVAL_STR;
- }
- return 0;
-}
-
-#endif /* !LINUX */
-
-#ifdef LINUX
-
-int sys_getuid(struct tcb *tcp)
-{
- if (exiting(tcp))
- tcp->u_rval = (uid_t) tcp->u_rval;
- return RVAL_UDECIMAL;
-}
-
-int sys_setfsuid(struct tcb *tcp)
-{
- if (entering(tcp))
- tprintf("%u", (uid_t) tcp->u_arg[0]);
- else
- tcp->u_rval = (uid_t) tcp->u_rval;
- return RVAL_UDECIMAL;
-}
-
-int
-sys_setuid(struct tcb *tcp)
-{
- if (entering(tcp)) {
- tprintf("%u", (uid_t) tcp->u_arg[0]);
- }
- return 0;
-}
-
-int
-sys_setgid(struct tcb *tcp)
-{
- if (entering(tcp)) {
- tprintf("%u", (gid_t) tcp->u_arg[0]);
- }
- return 0;
-}
-
-int
-sys_getresuid(struct tcb *tcp)
-{
- if (exiting(tcp)) {
- __kernel_uid_t uid;
- if (syserror(tcp))
- tprintf("%#lx, %#lx, %#lx", tcp->u_arg[0],
- tcp->u_arg[1], tcp->u_arg[2]);
- else {
- if (umove(tcp, tcp->u_arg[0], &uid) < 0)
- tprintf("%#lx, ", tcp->u_arg[0]);
- else
- tprintf("[%lu], ", (unsigned long) uid);
- if (umove(tcp, tcp->u_arg[1], &uid) < 0)
- tprintf("%#lx, ", tcp->u_arg[1]);
- else
- tprintf("[%lu], ", (unsigned long) uid);
- if (umove(tcp, tcp->u_arg[2], &uid) < 0)
- tprintf("%#lx", tcp->u_arg[2]);
- else
- tprintf("[%lu]", (unsigned long) uid);
- }
- }
- return 0;
-}
-
-int
-sys_getresgid(struct tcb *tcp)
-{
- if (exiting(tcp)) {
- __kernel_gid_t gid;
- if (syserror(tcp))
- tprintf("%#lx, %#lx, %#lx", tcp->u_arg[0],
- tcp->u_arg[1], tcp->u_arg[2]);
- else {
- if (umove(tcp, tcp->u_arg[0], &gid) < 0)
- tprintf("%#lx, ", tcp->u_arg[0]);
- else
- tprintf("[%lu], ", (unsigned long) gid);
- if (umove(tcp, tcp->u_arg[1], &gid) < 0)
- tprintf("%#lx, ", tcp->u_arg[1]);
- else
- tprintf("[%lu], ", (unsigned long) gid);
- if (umove(tcp, tcp->u_arg[2], &gid) < 0)
- tprintf("%#lx", tcp->u_arg[2]);
- else
- tprintf("[%lu]", (unsigned long) gid);
- }
- }
- return 0;
-}
-
-#endif /* LINUX */
-
-int
-sys_setreuid(struct tcb *tcp)
-{
- if (entering(tcp)) {
- printuid("", tcp->u_arg[0]);
- printuid(", ", tcp->u_arg[1]);
- }
- return 0;
-}
-
-int
-sys_setregid(struct tcb *tcp)
-{
- if (entering(tcp)) {
- printuid("", tcp->u_arg[0]);
- printuid(", ", tcp->u_arg[1]);
- }
- return 0;
-}
-
-#if defined(LINUX) || defined(FREEBSD)
-int
-sys_setresuid(struct tcb *tcp)
-{
- if (entering(tcp)) {
- printuid("", tcp->u_arg[0]);
- printuid(", ", tcp->u_arg[1]);
- printuid(", ", tcp->u_arg[2]);
- }
- return 0;
-}
-int
-sys_setresgid(struct tcb *tcp)
-{
- if (entering(tcp)) {
- printuid("", tcp->u_arg[0]);
- printuid(", ", tcp->u_arg[1]);
- printuid(", ", tcp->u_arg[2]);
- }
- return 0;
-}
-
-#endif /* LINUX || FREEBSD */
-
-int
-sys_setgroups(struct tcb *tcp)
-{
- if (entering(tcp)) {
- unsigned long len, size, start, cur, end, abbrev_end;
- GETGROUPS_T gid;
- int failed = 0;
-
- len = tcp->u_arg[0];
- tprintf("%lu, ", len);
- if (len == 0) {
- tprintf("[]");
- return 0;
- }
- start = tcp->u_arg[1];
- if (start == 0) {
- tprintf("NULL");
- return 0;
- }
- size = len * sizeof(gid);
- end = start + size;
- if (!verbose(tcp) || size / sizeof(gid) != len || end < start) {
- tprintf("%#lx", start);
- return 0;
- }
- if (abbrev(tcp)) {
- abbrev_end = start + max_strlen * sizeof(gid);
- if (abbrev_end < start)
- abbrev_end = end;
- } else {
- abbrev_end = end;
- }
- tprintf("[");
- for (cur = start; cur < end; cur += sizeof(gid)) {
- if (cur > start)
- tprintf(", ");
- if (cur >= abbrev_end) {
- tprintf("...");
- break;
- }
- if (umoven(tcp, cur, sizeof(gid), (char *) &gid) < 0) {
- tprintf("?");
- failed = 1;
- break;
- }
- tprintf("%lu", (unsigned long) gid);
- }
- tprintf("]");
- if (failed)
- tprintf(" %#lx", tcp->u_arg[1]);
- }
- return 0;
-}
-
-int
-sys_getgroups(struct tcb *tcp)
-{
- unsigned long len;
-
- if (entering(tcp)) {
- len = tcp->u_arg[0];
- tprintf("%lu, ", len);
- } else {
- unsigned long size, start, cur, end, abbrev_end;
- GETGROUPS_T gid;
- int failed = 0;
-
- len = tcp->u_rval;
- if (len == 0) {
- tprintf("[]");
- return 0;
- }
- start = tcp->u_arg[1];
- if (start == 0) {
- tprintf("NULL");
- return 0;
- }
- if (tcp->u_arg[0] == 0) {
- tprintf("%#lx", start);
- return 0;
- }
- size = len * sizeof(gid);
- end = start + size;
- if (!verbose(tcp) || tcp->u_arg[0] == 0 ||
- size / sizeof(gid) != len || end < start) {
- tprintf("%#lx", start);
- return 0;
- }
- if (abbrev(tcp)) {
- abbrev_end = start + max_strlen * sizeof(gid);
- if (abbrev_end < start)
- abbrev_end = end;
- } else {
- abbrev_end = end;
- }
- tprintf("[");
- for (cur = start; cur < end; cur += sizeof(gid)) {
- if (cur > start)
- tprintf(", ");
- if (cur >= abbrev_end) {
- tprintf("...");
- break;
- }
- if (umoven(tcp, cur, sizeof(gid), (char *) &gid) < 0) {
- tprintf("?");
- failed = 1;
- break;
- }
- tprintf("%lu", (unsigned long) gid);
- }
- tprintf("]");
- if (failed)
- tprintf(" %#lx", tcp->u_arg[1]);
- }
- return 0;
-}
-
-#ifdef LINUX
-int
-sys_setgroups32(struct tcb *tcp)
-{
- if (entering(tcp)) {
- unsigned long len, size, start, cur, end, abbrev_end;
- GETGROUPS32_T gid;
- int failed = 0;
-
- len = tcp->u_arg[0];
- tprintf("%lu, ", len);
- if (len == 0) {
- tprintf("[]");
- return 0;
- }
- start = tcp->u_arg[1];
- if (start == 0) {
- tprintf("NULL");
- return 0;
- }
- size = len * sizeof(gid);
- end = start + size;
- if (!verbose(tcp) || size / sizeof(gid) != len || end < start) {
- tprintf("%#lx", start);
- return 0;
- }
- if (abbrev(tcp)) {
- abbrev_end = start + max_strlen * sizeof(gid);
- if (abbrev_end < start)
- abbrev_end = end;
- } else {
- abbrev_end = end;
- }
- tprintf("[");
- for (cur = start; cur < end; cur += sizeof(gid)) {
- if (cur > start)
- tprintf(", ");
- if (cur >= abbrev_end) {
- tprintf("...");
- break;
- }
- if (umoven(tcp, cur, sizeof(gid), (char *) &gid) < 0) {
- tprintf("?");
- failed = 1;
- break;
- }
- tprintf("%lu", (unsigned long) gid);
- }
- tprintf("]");
- if (failed)
- tprintf(" %#lx", tcp->u_arg[1]);
- }
- return 0;
-}
-
-int
-sys_getgroups32(struct tcb *tcp)
-{
- unsigned long len;
-
- if (entering(tcp)) {
- len = tcp->u_arg[0];
- tprintf("%lu, ", len);
- } else {
- unsigned long size, start, cur, end, abbrev_end;
- GETGROUPS32_T gid;
- int failed = 0;
-
- len = tcp->u_rval;
- if (len == 0) {
- tprintf("[]");
- return 0;
- }
- start = tcp->u_arg[1];
- if (start == 0) {
- tprintf("NULL");
- return 0;
- }
- size = len * sizeof(gid);
- end = start + size;
- if (!verbose(tcp) || tcp->u_arg[0] == 0 ||
- size / sizeof(gid) != len || end < start) {
- tprintf("%#lx", start);
- return 0;
- }
- if (abbrev(tcp)) {
- abbrev_end = start + max_strlen * sizeof(gid);
- if (abbrev_end < start)
- abbrev_end = end;
- } else {
- abbrev_end = end;
- }
- tprintf("[");
- for (cur = start; cur < end; cur += sizeof(gid)) {
- if (cur > start)
- tprintf(", ");
- if (cur >= abbrev_end) {
- tprintf("...");
- break;
- }
- if (umoven(tcp, cur, sizeof(gid), (char *) &gid) < 0) {
- tprintf("?");
- failed = 1;
- break;
- }
- tprintf("%lu", (unsigned long) gid);
- }
- tprintf("]");
- if (failed)
- tprintf(" %#lx", tcp->u_arg[1]);
- }
- return 0;
-}
-#endif /* LINUX */
-
-#if defined(ALPHA) || defined(SUNOS4) || defined(SVR4)
-int
-sys_setpgrp(struct tcb *tcp)
-{
- if (entering(tcp)) {
-#ifndef SVR4
- tprintf("%lu, %lu", tcp->u_arg[0], tcp->u_arg[1]);
-#endif /* !SVR4 */
- }
- return 0;
-}
-#endif /* ALPHA || SUNOS4 || SVR4 */
-
-int
-sys_getpgrp(struct tcb *tcp)
-{
- if (entering(tcp)) {
-#ifndef SVR4
- tprintf("%lu", tcp->u_arg[0]);
-#endif /* !SVR4 */
- }
- return 0;
-}
-
-int
-sys_getsid(struct tcb *tcp)
-{
- if (entering(tcp)) {
- tprintf("%lu", tcp->u_arg[0]);
- }
- return 0;
-}
-
-int
-sys_setsid(struct tcb *tcp)
-{
- return 0;
-}
-
-int
-sys_getpgid(struct tcb *tcp)
-{
- if (entering(tcp)) {
- tprintf("%lu", tcp->u_arg[0]);
- }
- return 0;
-}
-
-int
-sys_setpgid(struct tcb *tcp)
-{
- if (entering(tcp)) {
- tprintf("%lu, %lu", tcp->u_arg[0], tcp->u_arg[1]);
- }
- return 0;
-}
-
-#if UNIXWARE >= 2
-
-#include <sys/privilege.h>
-
-
-static const struct xlat procpriv_cmds[] = {
- { SETPRV, "SETPRV" },
- { CLRPRV, "CLRPRV" },
- { PUTPRV, "PUTPRV" },
- { GETPRV, "GETPRV" },
- { CNTPRV, "CNTPRV" },
- { 0, NULL },
-};
-
-
-static const struct xlat procpriv_priv[] = {
- { P_OWNER, "P_OWNER" },
- { P_AUDIT, "P_AUDIT" },
- { P_COMPAT, "P_COMPAT" },
- { P_DACREAD, "P_DACREAD" },
- { P_DACWRITE, "P_DACWRITE" },
- { P_DEV, "P_DEV" },
- { P_FILESYS, "P_FILESYS" },
- { P_MACREAD, "P_MACREAD" },
- { P_MACWRITE, "P_MACWRITE" },
- { P_MOUNT, "P_MOUNT" },
- { P_MULTIDIR, "P_MULTIDIR" },
- { P_SETPLEVEL, "P_SETPLEVEL" },
- { P_SETSPRIV, "P_SETSPRIV" },
- { P_SETUID, "P_SETUID" },
- { P_SYSOPS, "P_SYSOPS" },
- { P_SETUPRIV, "P_SETUPRIV" },
- { P_DRIVER, "P_DRIVER" },
- { P_RTIME, "P_RTIME" },
- { P_MACUPGRADE, "P_MACUPGRADE" },
- { P_FSYSRANGE, "P_FSYSRANGE" },
- { P_SETFLEVEL, "P_SETFLEVEL" },
- { P_AUDITWR, "P_AUDITWR" },
- { P_TSHAR, "P_TSHAR" },
- { P_PLOCK, "P_PLOCK" },
- { P_CORE, "P_CORE" },
- { P_LOADMOD, "P_LOADMOD" },
- { P_BIND, "P_BIND" },
- { P_ALLPRIVS, "P_ALLPRIVS" },
- { 0, NULL },
-};
-
-
-static const struct xlat procpriv_type[] = {
- { PS_FIX, "PS_FIX" },
- { PS_INH, "PS_INH" },
- { PS_MAX, "PS_MAX" },
- { PS_WKG, "PS_WKG" },
- { 0, NULL },
-};
-
-
-static void
-printpriv(struct tcb *tcp, long addr, int len, const struct xlat *opt)
-{
- priv_t buf[128];
- int max = verbose(tcp) ? ARRAY_SIZE(buf) : 10;
- int dots = len > max;
- int i;
-
- if (len > max) len = max;
-
- if (len <= 0 ||
- umoven(tcp, addr, len * sizeof buf[0], (char *) buf) < 0)
- {
- tprintf("%#lx", addr);
- return;
- }
-
- tprintf("[");
-
- for (i = 0; i < len; ++i) {
- const char *t, *p;
-
- if (i) tprintf(", ");
-
- if ((t = xlookup(procpriv_type, buf[i] & PS_TYPE)) &&
- (p = xlookup(procpriv_priv, buf[i] & ~PS_TYPE)))
- {
- tprintf("%s|%s", t, p);
- }
- else {
- tprintf("%#lx", buf[i]);
- }
- }
-
- if (dots) tprintf(" ...");
-
- tprintf("]");
-}
-
-
-int
-sys_procpriv(struct tcb *tcp)
-{
- if (entering(tcp)) {
- printxval(procpriv_cmds, tcp->u_arg[0], "???PRV");
- switch (tcp->u_arg[0]) {
- case CNTPRV:
- tprintf(", %#lx, %ld", tcp->u_arg[1], tcp->u_arg[2]);
- break;
-
- case GETPRV:
- break;
-
- default:
- tprintf(", ");
- printpriv(tcp, tcp->u_arg[1], tcp->u_arg[2]);
- tprintf(", %ld", tcp->u_arg[2]);
- }
- }
- else if (tcp->u_arg[0] == GETPRV) {
- if (syserror(tcp)) {
- tprintf(", %#lx, %ld", tcp->u_arg[1], tcp->u_arg[2]);
- }
- else {
- tprintf(", ");
- printpriv(tcp, tcp->u_arg[1], tcp->u_rval);
- tprintf(", %ld", tcp->u_arg[2]);
- }
- }
-
- return 0;
-}
-
-#endif /* UNIXWARE */
-
-
-static void
-printargv(struct tcb *tcp, long addr)
-{
- union {
- unsigned int p32;
- unsigned long p64;
- char data[sizeof(long)];
- } cp;
- const char *sep;
- int n = 0;
-
- cp.p64 = 1;
- for (sep = ""; !abbrev(tcp) || n < max_strlen / 2; sep = ", ", ++n) {
- if (umoven(tcp, addr, personality_wordsize[current_personality],
- cp.data) < 0) {
- tprintf("%#lx", addr);
- return;
- }
- if (personality_wordsize[current_personality] == 4)
- cp.p64 = cp.p32;
- if (cp.p64 == 0)
- break;
- tprintf("%s", sep);
- printstr(tcp, cp.p64, -1);
- addr += personality_wordsize[current_personality];
- }
- if (cp.p64)
- tprintf("%s...", sep);
-}
-
-static void
-printargc(const char *fmt, struct tcb *tcp, long addr)
-{
- int count;
- char *cp;
-
- for (count = 0; umove(tcp, addr, &cp) >= 0 && cp != NULL; count++) {
- addr += sizeof(char *);
- }
- tprintf(fmt, count, count == 1 ? "" : "s");
-}
-
-#if defined(SPARC) || defined(SPARC64) || defined(SUNOS4)
-int
-sys_execv(struct tcb *tcp)
-{
- if (entering(tcp)) {
- printpath(tcp, tcp->u_arg[0]);
- if (!verbose(tcp))
- tprintf(", %#lx", tcp->u_arg[1]);
- else {
- tprintf(", [");
- printargv(tcp, tcp->u_arg[1]);
- tprintf("]");
- }
- }
- return 0;
-}
-#endif /* SPARC || SPARC64 || SUNOS4 */
-
-int
-sys_execve(struct tcb *tcp)
-{
- if (entering(tcp)) {
- printpath(tcp, tcp->u_arg[0]);
- if (!verbose(tcp))
- tprintf(", %#lx", tcp->u_arg[1]);
- else {
- tprintf(", [");
- printargv(tcp, tcp->u_arg[1]);
- tprintf("]");
- }
- if (!verbose(tcp))
- tprintf(", %#lx", tcp->u_arg[2]);
- else if (abbrev(tcp))
- printargc(", [/* %d var%s */]", tcp, tcp->u_arg[2]);
- else {
- tprintf(", [");
- printargv(tcp, tcp->u_arg[2]);
- tprintf("]");
- }
- }
- return 0;
-}
-
-#if UNIXWARE > 2
-
-int sys_rexecve(struct tcb *tcp)
-{
- if (entering(tcp)) {
- sys_execve(tcp);
- tprintf(", %ld", tcp->u_arg[3]);
- }
- return 0;
-}
-
-#endif
-
-int
-internal_exec(struct tcb *tcp)
-{
-#ifdef SUNOS4
- if (exiting(tcp) && !syserror(tcp) && followfork)
- fixvfork(tcp);
-#endif /* SUNOS4 */
-#if defined LINUX && defined TCB_WAITEXECVE
- if (exiting(tcp) && syserror(tcp))
- tcp->flags &= ~TCB_WAITEXECVE;
- else {
- /* Maybe we have post-execve SIGTRAP suppressed? */
- if (!(ptrace_setoptions & PTRACE_O_TRACEEXEC))
- tcp->flags |= TCB_WAITEXECVE; /* no */
- }
-#endif /* LINUX && TCB_WAITEXECVE */
- return 0;
-}
-
-#ifdef LINUX
-#ifndef __WNOTHREAD
-#define __WNOTHREAD 0x20000000
-#endif
-#ifndef __WALL
-#define __WALL 0x40000000
-#endif
-#ifndef __WCLONE
-#define __WCLONE 0x80000000
-#endif
-#endif /* LINUX */
-
-static const struct xlat wait4_options[] = {
- { WNOHANG, "WNOHANG" },
-#ifndef WSTOPPED
- { WUNTRACED, "WUNTRACED" },
-#endif
-#ifdef WEXITED
- { WEXITED, "WEXITED" },
-#endif
-#ifdef WTRAPPED
- { WTRAPPED, "WTRAPPED" },
-#endif
-#ifdef WSTOPPED
- { WSTOPPED, "WSTOPPED" },
-#endif
-#ifdef WCONTINUED
- { WCONTINUED, "WCONTINUED" },
-#endif
-#ifdef WNOWAIT
- { WNOWAIT, "WNOWAIT" },
-#endif
-#ifdef __WCLONE
- { __WCLONE, "__WCLONE" },
-#endif
-#ifdef __WALL
- { __WALL, "__WALL" },
-#endif
-#ifdef __WNOTHREAD
- { __WNOTHREAD, "__WNOTHREAD" },
-#endif
- { 0, NULL },
-};
-
-#if !defined WCOREFLAG && defined WCOREFLG
-# define WCOREFLAG WCOREFLG
-#endif
-#ifndef WCOREFLAG
-# define WCOREFLAG 0x80
-#endif
-#ifndef WCOREDUMP
-# define WCOREDUMP(status) ((status) & 0200)
-#endif
-
-
-#ifndef W_STOPCODE
-#define W_STOPCODE(sig) ((sig) << 8 | 0x7f)
-#endif
-#ifndef W_EXITCODE
-#define W_EXITCODE(ret, sig) ((ret) << 8 | (sig))
-#endif
-
-static int
-printstatus(int status)
-{
- int exited = 0;
-
- /*
- * Here is a tricky presentation problem. This solution
- * is still not entirely satisfactory but since there
- * are no wait status constructors it will have to do.
- */
- if (WIFSTOPPED(status)) {
- tprintf("[{WIFSTOPPED(s) && WSTOPSIG(s) == %s}",
- signame(WSTOPSIG(status)));
- status &= ~W_STOPCODE(WSTOPSIG(status));
- }
- else if (WIFSIGNALED(status)) {
- tprintf("[{WIFSIGNALED(s) && WTERMSIG(s) == %s%s}",
- signame(WTERMSIG(status)),
- WCOREDUMP(status) ? " && WCOREDUMP(s)" : "");
- status &= ~(W_EXITCODE(0, WTERMSIG(status)) | WCOREFLAG);
- }
- else if (WIFEXITED(status)) {
- tprintf("[{WIFEXITED(s) && WEXITSTATUS(s) == %d}",
- WEXITSTATUS(status));
- exited = 1;
- status &= ~W_EXITCODE(WEXITSTATUS(status), 0);
- }
- else {
- tprintf("[%#x]", status);
- return 0;
- }
-
- if (status == 0)
- tprintf("]");
- else
- tprintf(" | %#x]", status);
-
- return exited;
-}
-
-static int
-printwaitn(struct tcb *tcp, int n, int bitness)
-{
- int status;
-#ifdef SUNOS4
- int exited = 0;
-#endif
-
- if (entering(tcp)) {
-#ifdef LINUX
- /* On Linux, kernel-side pid_t is typedef'ed to int
- * on all arches. Also, glibc-2.8 truncates wait3 and wait4
- * pid argument to int on 64bit arches, producing,
- * for example, wait4(4294967295, ...) instead of -1
- * in strace. We have to use int here, not long.
- */
- int pid = tcp->u_arg[0];
- tprintf("%d, ", pid);
-#else
- /*
- * Sign-extend a 32-bit value when that's what it is.
- */
- long pid = tcp->u_arg[0];
- if (personality_wordsize[current_personality] < sizeof pid)
- pid = (long) (int) pid;
- tprintf("%ld, ", pid);
-#endif
- } else {
- /* status */
- if (!tcp->u_arg[1])
- tprintf("NULL");
- else if (syserror(tcp) || tcp->u_rval == 0)
- tprintf("%#lx", tcp->u_arg[1]);
- else if (umove(tcp, tcp->u_arg[1], &status) < 0)
- tprintf("[?]");
- else
-#ifdef SUNOS4
- exited =
-#endif
- printstatus(status);
- /* options */
- tprintf(", ");
- printflags(wait4_options, tcp->u_arg[2], "W???");
- if (n == 4) {
- tprintf(", ");
- /* usage */
- if (!tcp->u_arg[3])
- tprintf("NULL");
-#ifdef LINUX
- else if (tcp->u_rval > 0) {
-#ifdef ALPHA
- if (bitness)
- printrusage32(tcp, tcp->u_arg[3]);
- else
-#endif
- printrusage(tcp, tcp->u_arg[3]);
- }
-#endif /* LINUX */
-#ifdef SUNOS4
- else if (tcp->u_rval > 0 && exited)
- printrusage(tcp, tcp->u_arg[3]);
-#endif /* SUNOS4 */
- else
- tprintf("%#lx", tcp->u_arg[3]);
- }
- }
- return 0;
-}
-
-#ifdef SVR4
-
-int
-sys_wait(struct tcb *tcp)
-{
- if (exiting(tcp)) {
- /* The library wrapper stuffs this into the user variable. */
- if (!syserror(tcp))
- printstatus(getrval2(tcp));
- }
- return 0;
-}
-
-#endif /* SVR4 */
-
-#ifdef FREEBSD
-int
-sys_wait(struct tcb *tcp)
-{
- int status;
-
- if (exiting(tcp)) {
- if (!syserror(tcp)) {
- if (umove(tcp, tcp->u_arg[0], &status) < 0)
- tprintf("%#lx", tcp->u_arg[0]);
- else
- printstatus(status);
- }
- }
- return 0;
-}
-#endif
-
-int
-sys_waitpid(struct tcb *tcp)
-{
- return printwaitn(tcp, 3, 0);
-}
-
-int
-sys_wait4(struct tcb *tcp)
-{
- return printwaitn(tcp, 4, 0);
-}
-
-#ifdef ALPHA
-int
-sys_osf_wait4(struct tcb *tcp)
-{
- return printwaitn(tcp, 4, 1);
-}
-#endif
-
-#if defined SVR4 || defined LINUX
-
-static const struct xlat waitid_types[] = {
- { P_PID, "P_PID" },
-#ifdef P_PPID
- { P_PPID, "P_PPID" },
-#endif
- { P_PGID, "P_PGID" },
-#ifdef P_SID
- { P_SID, "P_SID" },
-#endif
-#ifdef P_CID
- { P_CID, "P_CID" },
-#endif
-#ifdef P_UID
- { P_UID, "P_UID" },
-#endif
-#ifdef P_GID
- { P_GID, "P_GID" },
-#endif
- { P_ALL, "P_ALL" },
-#ifdef P_LWPID
- { P_LWPID, "P_LWPID" },
-#endif
- { 0, NULL },
-};
-
-int
-sys_waitid(struct tcb *tcp)
-{
- siginfo_t si;
-
- if (entering(tcp)) {
- printxval(waitid_types, tcp->u_arg[0], "P_???");
- tprintf(", %ld, ", tcp->u_arg[1]);
- }
- else {
- /* siginfo */
- if (!tcp->u_arg[2])
- tprintf("NULL");
- else if (syserror(tcp))
- tprintf("%#lx", tcp->u_arg[2]);
- else if (umove(tcp, tcp->u_arg[2], &si) < 0)
- tprintf("{???}");
- else
- printsiginfo(&si, verbose(tcp));
- /* options */
- tprintf(", ");
- printflags(wait4_options, tcp->u_arg[3], "W???");
- if (tcp->u_nargs > 4) {
- /* usage */
- tprintf(", ");
- if (!tcp->u_arg[4])
- tprintf("NULL");
- else if (tcp->u_error)
- tprintf("%#lx", tcp->u_arg[4]);
- else
- printrusage(tcp, tcp->u_arg[4]);
- }
- }
- return 0;
-}
-
-#endif /* SVR4 or LINUX */
-
-int
-sys_alarm(struct tcb *tcp)
-{
- if (entering(tcp))
- tprintf("%lu", tcp->u_arg[0]);
- return 0;
-}
-
-int
-sys_uname(struct tcb *tcp)
-{
- struct utsname uname;
-
- if (exiting(tcp)) {
- if (syserror(tcp) || !verbose(tcp))
- tprintf("%#lx", tcp->u_arg[0]);
- else if (umove(tcp, tcp->u_arg[0], &uname) < 0)
- tprintf("{...}");
- else if (!abbrev(tcp)) {