/*
 * Copyright (c) 1991, 1992 Paul Kranenburg <pk@cs.few.eur.nl>
 * Copyright (c) 1993 Branko Lankester <branko@hacktic.nl>
 * Copyright (c) 1993, 1994, 1995, 1996 Rick Sladkey <jrs@world.std.com>
 * Copyright (c) 1996-1999 Wichert Akkerman <wichert@cistron.nl>
 * Copyright (c) 1999 IBM Deutschland Entwicklung GmbH, IBM Corporation
 *                     Linux for s390 port by D.J. Barrow
 *                    <barrow_dj@mail.yahoo.com,djbarrow@de.ibm.com>
 * 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 <signal.h>
#include <sys/syscall.h>
#include <sys/user.h>
#include <sys/param.h>
#include <fcntl.h>
#if HAVE_SYS_UIO_H
#include <sys/uio.h>
#endif
#ifdef SUNOS4
#include <machine/reg.h>
#include <a.out.h>
#include <link.h>
#endif /* SUNOS4 */

#if defined(linux) && (__GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ < 1))
#include <linux/ptrace.h>
#endif

#if defined(LINUX) && defined(IA64)
# include <asm/ptrace_offsets.h>
# include <asm/rse.h>
#endif

#ifdef HAVE_SYS_REG_H
#include <sys/reg.h>
# define PTRACE_PEEKUSR PTRACE_PEEKUSER
#elif defined(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

#ifdef SUNOS4_KERNEL_ARCH_KLUDGE
#include <sys/utsname.h>
#endif /* SUNOS4_KERNEL_ARCH_KLUDGE */

#if defined(LINUXSPARC)

# define fpq kernel_fpq
# define fq kernel_fq
# define fpu kernel_fpu
# include <asm/reg.h>
# undef fpq
# undef fq
# undef fpu

#if defined (SPARC64)
# define r_pc r_tpc
# undef PTRACE_GETREGS
# define PTRACE_GETREGS PTRACE_GETREGS64
# undef PTRACE_SETREGS
# define PTRACE_SETREGS PTRACE_SETREGS64
#endif /* SPARC64 */

#if !defined(__GLIBC__)

#include <linux/unistd.h>

#define _hack_syscall5(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4,\
          type5,arg5,syscall) \
type name (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5) \
{ \
      long __res; \
\
__asm__ volatile ("or %%g0, %1, %%o0\n\t" \
                  "or %%g0, %2, %%o1\n\t" \
                  "or %%g0, %3, %%o2\n\t" \
                  "or %%g0, %4, %%o3\n\t" \
                  "or %%g0, %5, %%o4\n\t" \
                  "or %%g0, %6, %%g1\n\t" \
#if defined (SPARC64)
                  "t 0x6d\n\t" \
#else
                  "t 0x10\n\t" \
#endif
                  "bcc 1f\n\t" \
                  "or %%g0, %%o0, %0\n\t" \
                  "sub %%g0, %%o0, %0\n\t" \
                  "1:\n\t" \
                  : "=r" (__res) \
                  : "0" ((long)(arg1)),"1" ((long)(arg2)), \
                    "2" ((long)(arg3)),"3" ((long)(arg4)),"4" ((long)(arg5)), \
                    "i" (__NR_##syscall)  \
                  : "g1", "o0", "o1", "o2", "o3", "o4"); \
if (__res>=0) \
        return (type) __res; \
errno = -__res; \
return -1; \
}

static _hack_syscall5(int,_ptrace,int,__request,int,__pid,int,__addr,int,__data,int,__addr2,ptrace)

#define _ptrace

#endif

#endif

/* macros */
#ifndef MAX
#define MAX(a,b)		(((a) > (b)) ? (a) : (b))
#endif
#ifndef MIN
#define MIN(a,b)		(((a) < (b)) ? (a) : (b))
#endif

void
tv_tv(tv, a, b)
struct timeval *tv;
int a;
int b;
{
	tv->tv_sec = a;
	tv->tv_usec = b;
}

int
tv_nz(a)
struct timeval *a;
{
	return a->tv_sec || a->tv_usec;
}

int
tv_cmp(a, b)
struct timeval *a, *b;
{
	if (a->tv_sec < b->tv_sec
	    || (a->tv_sec == b->tv_sec && a->tv_usec < b->tv_usec))
		return -1;
	if (a->tv_sec > b->tv_sec
	    || (a->tv_sec == b->tv_sec && a->tv_usec > b->tv_usec))
		return 1;
	return 0;
}

double
tv_float(tv)
struct timeval *tv;
{
	return tv->tv_sec + tv->tv_usec/1000000.0;
}

void
tv_add(tv, a, b)
struct timeval *tv, *a, *b;
{
	tv->tv_sec = a->tv_sec + b->tv_sec;
	tv->tv_usec = a->tv_usec + b->tv_usec;
	if (tv->tv_usec > 1000000) {
		tv->tv_sec++;
		tv->tv_usec -= 1000000;
	}
}

void
tv_sub(tv, a, b)
struct timeval *tv, *a, *b;
{
	tv->tv_sec = a->tv_sec - b->tv_sec;
	tv->tv_usec = a->tv_usec - b->tv_usec;
	if (((long) tv->tv_usec) < 0) {
		tv->tv_sec--;
		tv->tv_usec += 1000000;
	}
}

void
tv_div(tv, a, n)
struct timeval *tv, *a;
int n;
{
	tv->tv_usec = (a->tv_sec % n * 1000000 + a->tv_usec + n / 2) / n;
	tv->tv_sec = a->tv_sec / n + tv->tv_usec / 1000000;
	tv->tv_usec %= 1000000;
}

void
tv_mul(tv, a, n)
struct timeval *tv, *a;
int n;
{
	tv->tv_usec = a->tv_usec * n;
	tv->tv_sec = a->tv_sec * n + a->tv_usec / 1000000;
	tv->tv_usec %= 1000000;
}

char *
xlookup(xlat, val)
const struct xlat *xlat;
int val;
{
	for (; xlat->str != NULL; xlat++)
		if (xlat->val == val)
			return xlat->str;
	return NULL;
}

/*
 * Print entry in struct xlat table, if there.
 */
void
printxval(xlat, val, dflt)
const struct xlat *xlat;
int val;
char *dflt;
{
	char *str = xlookup(xlat, val);

	if (str)
		tprintf("%s", str);
	else
		tprintf("%#x /* %s */", val, dflt);
}

/*
 * Interpret `xlat' as an array of flags
 * print the entries whose bits are on in `flags'
 * return # of flags printed.
 */
int
addflags(xlat, flags)
const struct xlat *xlat;
int flags;
{
	int n;

	for (n = 0; xlat->str; xlat++) {
		if (xlat->val && (flags & xlat->val) == xlat->val) {
			tprintf("|%s", xlat->str);
			flags &= ~xlat->val;
			n++;
		}
	}
	if (flags) {
		tprintf("|%#x", flags);
		n++;
	}
	return n;
}

int
printflags(xlat, flags)
const struct xlat *xlat;
int flags;
{
	int n;
	char *sep;

	if (flags == 0 && xlat->val == 0) {
		tprintf("%s", xlat->str);
		return 1;
	}

	sep = "";
	for (n = 0; xlat->str; xlat++) {
		if (xlat->val && (flags & xlat->val) == xlat->val) {
			tprintf("%s%s", sep, xlat->str);
			flags &= ~xlat->val;
			sep = "|";
			n++;
		}
	}
	if (flags) {
		tprintf("%s%#x", sep, flags);
		n++;
	}
	return n;
}

void
printnum(tcp, addr, fmt)
struct tcb *tcp;
long addr;
char *fmt;
{
	long num;

	if (!addr) {
		tprintf("NULL");
		return;
	}
	if (umove(tcp, addr, &num) < 0) {
		tprintf("%#lx", addr);
		return;
	}
	tprintf("[");
	tprintf(fmt, num);
	tprintf("]");
}

void
printuid(text, uid)
const char *text;
unsigned long uid;
{
	tprintf("%s", text);
	tprintf((uid == -1) ? "%ld" : "%lu", uid);
}

static char path[MAXPATHLEN + 1];

void
string_quote(str)
char *str;
{
	char buf[2 * MAXPATHLEN + 1];
	char *s;

	if (!strpbrk(str, "\"\'\\")) {
		tprintf("\"%s\"", str);
		return;
	}
	for (s = buf; *str; str++) {
		switch (*str) {
		case '\"': case '\'': case '\\':
			*s++ = '\\'; *s++ = *str; break;
		default:
			*s++ = *str; break;
		}
	}
	*s = '\0';
	tprintf("\"%s\"", buf);
}

void
printpath(tcp, addr)
struct tcb *tcp;
long addr;
{
	if (umovestr(tcp, addr, MAXPATHLEN, path) < 0)
		tprintf("%#lx", addr);
	else
		string_quote(path);
	return;
}

void
printpathn(tcp, addr, n)
struct tcb *tcp;
long addr;
int n;
{
	if (umovestr(tcp, addr, n, path) < 0)
		tprintf("%#lx", addr);
	else {
		path[n] = '\0';
		string_quote(path);
	}
}

void
printstr(tcp, addr, len)
struct tcb *tcp;
long addr;
int len;
{
	static unsigned char *str = NULL;
	static char *outstr;
	int i, n, c, usehex;
	char *s, *outend;

	if (!addr) {
		tprintf("NULL");
		return;
	}
	if (!str) {
		if ((str = malloc(max_strlen)) == NULL
		    || (outstr = malloc(2*max_strlen)) == NULL) {
			fprintf(stderr, "printstr: no memory\n");
			tprintf("%#lx", addr);
			return;
		}
	}
	outend = outstr + max_strlen * 2 - 10;
	if (len < 0) {
		n = max_strlen;
		if (umovestr(tcp, addr, n, (char *) str) < 0) {
			tprintf("%#lx", addr);
			return;
		}
	}
	else {
		n = MIN(len, max_strlen);
		if (umoven(tcp, addr, n, (char *) str) < 0) {
			tprintf("%#lx", addr);
			return;
		}
	}

	usehex = 0;
	if (xflag > 1)
		usehex = 1;
	else if (xflag) {
		for (i = 0; i < n; i++) {
			c = str[i];
			if (len < 0 && c == '\0')
				break;
			if (!isprint(c) && !isspace(c)) {
				usehex = 1;
				break;
			}
		}
	}

	s = outstr;
	*s++ = '\"';

	if (usehex) {
		for (i = 0; i < n; i++) {
			c = str[i];
			if (len < 0 && c == '\0')
				break;
			sprintf(s, "\\x%02x", c);
			s += 4;
			if (s > outend)
				break;
		}
	}
	else {
		for (i = 0; i < n; i++) {
			c = str[i];
			if (len < 0 && c == '\0')
				break;
			switch (c) {
			case '\"': case '\'': case '\\':
				*s++ = '\\'; *s++ = c; break;
			case '\f':
				*s++ = '\\'; *s++ = 'f'; break;
			case '\n':
				*s++ = '\\'; *s++ = 'n'; break;
			case '\r':
				*s++ = '\\'; *s++ = 'r'; break;
			case '\t':
				*s++ = '\\'; *s++ = 't'; break;
			case '\v':
				*s++ = '\\'; *s++ = 'v'; break;
			default:
				if (isprint(c))
					*s++ = c;
				else if (i < n - 1 && isdigit(str[i + 1])) {
					sprintf(s, "\\%03o", c);
					s += 4;
				}
				else {
					sprintf(s, "\\%o", c);
					s += strlen(s);
				}
				break;
			}
			if (s > outend)
				break;
		}
	}

	*s++ = '\"';
	if (i < len || (len < 0 && (i == n || s > outend))) {
		*s++ = '.'; *s++ = '.'; *s++ = '.';
	}
	*s = '\0';
	tprintf("%s", outstr);
}

#if HAVE_SYS_UIO_H
void
dumpiov(tcp, len, addr)
struct tcb * tcp;
int len;
long addr;
{
	struct iovec *iov;
	int i;


	if ((iov = (struct iovec *) malloc(len * sizeof *iov)) == NULL) {
		fprintf(stderr, "dump: No memory");
		return;
	}
	if (umoven(tcp, addr,
		   len * sizeof *iov, (char *) iov) >= 0) {

		for (i = 0; i < len; i++) {
                        /* include the buffer number to make it easy to
                         * match up the trace with the source */
                        tprintf(" * %lu bytes in buffer %d\n",
                                (unsigned long)iov[i].iov_len, i);
                        dumpstr(tcp, (long) iov[i].iov_base,
                                iov[i].iov_len);
                }
	}
	free((char *) iov);

}
#endif

void
dumpstr(tcp, addr, len)
struct tcb *tcp;
long addr;
int len;
{
	static int strsize = -1;
	static unsigned char *str;
	static char outstr[80];
	char *s;
	int i, j;

	if (strsize < len) {
		if (str)
			free(str);
		if ((str = malloc(len)) == NULL) {
			fprintf(stderr, "dump: no memory\n");
			return;
		}
		strsize = len;
	}

	if (umoven(tcp, addr, len, (char *) str) < 0)
		return;

	for (i = 0; i < len; i += 16) {
		s = outstr;
		sprintf(s, " | %05x ", i);
		s += 9;
		for (j = 0; j < 16; j++) {
			if (j == 8)
				*s++ = ' ';
			if (i + j < len) {
				sprintf(s, " %02x", str[i + j]);
				s += 3;
			}
			else {
				*s++ = ' '; *s++ = ' '; *s++ = ' ';
			}
		}
		*s++ = ' '; *s++ = ' ';
		for (j = 0; j < 16; j++) {
			if (j == 8)
				*s++ = ' ';
			if (i + j < len) {
				if (isprint(str[i + j]))
					*s++ = str[i + j];
				else
					*s++ = '.';
			}
			else
				*s++ = ' ';
		}
		tprintf("%s |\n", outstr);
	}
}

#define PAGMASK	(~(PAGSIZ - 1))
/*
 * move `len' bytes of data from process `pid'
 * at address `addr' to our space at `laddr'
 */
int
umoven(tcp, addr, len, laddr)
struct tcb *tcp;
long addr;
int len;
char *laddr;
{

#ifdef LINUX
	int pid = tcp->pid;
	int n, m;
	int started = 0;
	union {
		long val;
		char x[sizeof(long)];
	} u;

	if (addr & (sizeof(long) - 1)) {
		/* addr not a multiple of sizeof(long) */
		n = addr - (addr & -sizeof(long)); /* residue */
		addr &= -sizeof(long); /* residue */
		errno = 0;
		u.val = ptrace(PTRACE_PEEKDATA, pid, (char *) addr, 0);
		if (errno) {
			if (started && (errno==EPERM || errno==EIO)) {
				/* Ran into 'end of memory' - stupid "printpath" */
				return 0;
			}
			/* But if not started, we had a bogus address. */
			perror("ptrace: umoven");
			return -1;
		}
		started = 1;
		memcpy(laddr, &u.x[n], m = MIN(sizeof(long) - n, len));
		addr += sizeof(long), laddr += m, len -= m;
	}
	while (len) {
		errno = 0;
		u.val = ptrace(PTRACE_PEEKDATA, pid, (char *) addr, 0);
		if (errno) {
			if (started && (errno==EPERM || errno==EIO)) {
				/* Ran into 'end of memory' - stupid "printpath" */
				return 0;
			}
			if (addr != 0)
				perror("ptrace: umoven");
			return -1;
		}
		started = 1;
		memcpy(laddr, u.x, m = MIN(sizeof(long), len));
		addr += sizeof(long), laddr += m, len -= m;
	}
#endif /* LINUX */

#ifdef SUNOS4
	int pid = tcp->pid;
#if 0
	int n, m;
	union {
		long val;
		char x[sizeof(long)];
	} u;

	if (addr & (sizeof(long) - 1)) {
		/* addr not a multiple of sizeof(long) */
		n = addr - (addr & -sizeof(long)); /* residue */
		addr &= -sizeof(long); /* residue */
		errno = 0;
		u.val = ptrace(PTRACE_PEEKDATA, pid, (char *) addr, 0);
		if (errno) {
			perror("umoven");
			return -1;
		}
		memcpy(laddr, &u.x[n], m = MIN(sizeof(long) - n, len));
		addr += sizeof(long), laddr += m, len -= m;
	}
	while (len) {
		errno = 0;
		u.val = ptrace(PTRACE_PEEKDATA, pid, (char *) addr, 0);
		if (errno) {
			perror("umoven");
			return -1;
		}
		memcpy(laddr, u.x, m = MIN(sizeof(long), len));
		addr += sizeof(long), laddr += m, len -= m;
	}
#else /* !oldway */
	int n;

	while (len) {
		n = MIN(len, PAGSIZ);
		n = MIN(n, ((addr + PAGSIZ) & PAGMASK) - addr);
		if (ptrace(PTRACE_READDATA, pid,
			   (char *) addr, len, laddr) < 0) {
			perror("umoven: ptrace(PTRACE_READDATA, ...)");
			abort();
			return -1;
		}
		len -= n;
		addr += n;
		laddr += n;
	}
#endif /* !oldway */
#endif /* SUNOS4 */

#ifdef USE_PROCFS
#ifdef HAVE_MP_PROCFS
	int fd = tcp->pfd_as;
#else
	int fd = tcp->pfd;
#endif
	lseek(fd, addr, SEEK_SET);
	if (read(fd, laddr, len) == -1)
		return -1;
#endif /* USE_PROCFS */

	return 0;
}

/*
 * like `umove' but make the additional effort of looking
 * for a terminating zero byte.
 */
int
umovestr(tcp, addr, len, laddr)
struct tcb *tcp;
long addr;
int len;
char *laddr;
{
#ifdef USE_PROCFS
#ifdef HAVE_MP_PROCFS
	int fd = tcp->pfd_as;
#else
	int fd = tcp->pfd;
#endif
	/* Some systems (e.g. FreeBSD) can be upset if we read off the
	   end of valid memory,  avoid this by trying to read up
	   to page boundaries.  But we don't know what a page is (and
	   getpagesize(2) (if it exists) doesn't necessarily return
	   hardware page size).  Assume all pages >= 1024 (a-historical
	   I know) */

	int page = 1024; 	/* How to find this? */
	int move = page - (addr & (page - 1));
	int left = len;

	lseek(fd, addr, SEEK_SET);

	while (left) {
		if (move > left) move = left;
		if ((move = read(fd, laddr, move)) <= 0)
			return left != len ? 0 : -1;
		if (memchr (laddr, 0, move)) break;
		left -= move;
		laddr += move;
		addr += move;
		move = page;
	}
#else /* !USE_PROCFS */
	int started = 0;
	int pid = tcp->pid;
	int i, n, m;
	union {
		long val;
		char x[sizeof(long)];
	} u;

	if (addr & (sizeof(long) - 1)) {
		/* addr not a multiple of sizeof(long) */
		n = addr - (addr & -sizeof(long)); /* residue */
		addr &= -sizeof(long); /* residue */
		errno = 0;
		u.val = ptrace(PTRACE_PEEKDATA, pid, (char *)addr, 0);
		if (errno) {
			if (started && (errno==EPERM || errno==EIO)) {
				/* Ran into 'end of memory' - stupid "printpath" */
				return 0;
			}
			perror("umovestr");
			return -1;
		}
		started = 1;
		memcpy(laddr, &u.x[n], m = MIN(sizeof(long)-n,len));
		while (n & (sizeof(long) - 1))
			if (u.x[n++] == '\0')
				return 0;
		addr += sizeof(long), laddr += m, len -= m;
	}
	while (len) {
		errno = 0;
		u.val = ptrace(PTRACE_PEEKDATA, pid, (char *)addr, 0);
		if (errno) {
			if (started && (errno==EPERM || errno==EIO)) {
				/* Ran into 'end of memory' - stupid "printpath" */
				return 0;
			}
			perror("umovestr");
			return -1;
		}
		started = 1;
		memcpy(laddr, u.x, m = MIN(sizeof(long), len));
		for (i = 0; i < sizeof(long); i++)
			if (u.x[i] == '\0')
				return 0;

		addr += sizeof(long), laddr += m, len -= m;
	}
#endif /* !USE_PROCFS */
	return 0;
}

#ifdef LINUX
#if !defined (SPARC) && !defined(SPARC64)
#define PTRACE_WRITETEXT	101
#define PTRACE_WRITEDATA	102
#endif /* !SPARC && !SPARC64 */
#endif /* LINUX */

#ifdef SUNOS4

static int
uload(cmd, pid, addr, len, laddr)
int cmd;
int pid;
long addr;
int len;
char *laddr;
{
#if 0
	int n;

	while (len) {
		n = MIN(len, PAGSIZ);
		n = MIN(n, ((addr + PAGSIZ) & PAGMASK) - addr);
		if (ptrace(cmd, pid, (char *)addr, n, laddr) < 0) {
			perror("uload: ptrace(PTRACE_WRITE, ...)");
			return -1;
		}
		len -= n;
		addr += n;
		laddr += n;
	}
#else
	int peek, poke;
	int n, m;
	union {
		long val;
		char x[sizeof(long)];
	} u;

	if (cmd == PTRACE_WRITETEXT) {
		peek = PTRACE_PEEKTEXT;
		poke = PTRACE_POKETEXT;
	}
	else {
		peek = PTRACE_PEEKDATA;
		poke = PTRACE_POKEDATA;
	}
	if (addr & (sizeof(long) - 1)) {
		/* addr not a multiple of sizeof(long) */
		n = addr - (addr & -sizeof(long)); /* residue */
		addr &= -sizeof(long);
		errno = 0;
		u.val = ptrace(peek, pid, (char *) addr, 0);
		if (errno) {
			perror("uload: POKE");
			return -1;
		}
		memcpy(&u.x[n], laddr, m = MIN(sizeof(long) - n, len));
		if (ptrace(poke, pid, (char *)addr, u.val) < 0) {
			perror("uload: POKE");
			return -1;
		}
		addr += sizeof(long), laddr += m, len -= m;
	}
	while (len) {
		if (len < sizeof(long))
			u.val = ptrace(peek, pid, (char *) addr, 0);
		memcpy(u.x, laddr, m = MIN(sizeof(long), len));
		if (ptrace(poke, pid, (char *) addr, u.val) < 0) {
			perror("uload: POKE");
			return -1;
		}
		addr += sizeof(long), laddr += m, len -= m;
	}
#endif
	return 0;
}

int
tload(pid, addr, len, laddr)
int pid;
int addr, len;
char *laddr;
{
	return uload(PTRACE_WRITETEXT, pid, addr, len, laddr);
}

int
dload(pid, addr, len, laddr)
int pid;
int addr;
int len;
char *laddr;
{
	return uload(PTRACE_WRITEDATA, pid, addr, len, laddr);
}

#endif /* SUNOS4 */

#ifndef USE_PROCFS

int
upeek(pid, off, res)
int pid;
long off;
long *res;
{
	long val;

#ifdef SUNOS4_KERNEL_ARCH_KLUDGE
	{
		static int is_sun4m = -1;
		struct utsname name;

		/* Round up the usual suspects. */
		if (is_sun4m == -1) {
			if (uname(&name) < 0) {
				perror("upeek: uname?");
				exit(1);
			}
			is_sun4m = strcmp(name.machine, "sun4m") == 0;
			if (is_sun4m) {
				extern const struct xlat struct_user_offsets[];
				const struct xlat *x;

				for (x = struct_user_offsets; x->str; x++)
					x->val += 1024;
			}
		}
		if (is_sun4m)
			off += 1024;
	}
#endif /* SUNOS4_KERNEL_ARCH_KLUDGE */
	errno = 0;
	val = ptrace(PTRACE_PEEKUSER, pid, (char *) off, 0);
	if (val == -1 && errno) {
		char buf[60];
		sprintf(buf,"upeek: ptrace(PTRACE_PEEKUSER,%d,%lu,0)",pid,off);
		perror(buf);
		return -1;
	}
	*res = val;
	return 0;
}

#endif /* !USE_PROCFS */

long
getpc(tcp)
struct tcb *tcp;
{

#ifdef LINUX
	long pc;
#if defined(I386)
	if (upeek(tcp->pid, 4*EIP, &pc) < 0)
		return -1;
#elif defined(X86_64)
	if (upeek(tcp->pid, 8*RIP, &pc) < 0)
		return -1;
#elif defined(IA64)
	if (upeek(tcp->pid, PT_B0, &pc) < 0)
		return -1;
#elif defined(ARM)
	if (upeek(tcp->pid, 4*15, &pc) < 0)
		return -1;
#elif defined(POWERPC)
	if (upeek(tcp->pid, sizeof(unsigned long)*PT_NIP, &pc) < 0)
		return -1;
#elif defined(M68k)
	if (upeek(tcp->pid, 4*PT_PC, &pc) < 0)
		return -1;
#elif defined(ALPHA)
	if (upeek(tcp->pid, REG_PC, &pc) < 0)
		return -1;
#elif defined(MIPS)
 	if (upeek(tcp->pid, REG_EPC, &pc) < 0)
 		return -1;
#elif defined(SPARC) || defined(SPARC64)
	struct regs regs;
	if (ptrace(PTRACE_GETREGS,tcp->pid,(char *)&regs,0) < 0)
		return -1;
	pc = regs.r_pc;
#elif defined(S390) || defined(S390X)
	if(upeek(tcp->pid,PT_PSWADDR,&pc) < 0)
		return -1;
#elif defined(HPPA)
	if(upeek(tcp->pid,PT_IAOQ0,&pc) < 0)
		return -1;
#elif defined(SH)
       if (upeek(tcp->pid, 4*REG_PC ,&pc) < 0)
               return -1;
#elif defined(SH64)
       if (upeek(tcp->pid, REG_PC ,&pc) < 0)
               return -1;
#endif
	return pc;
#endif /* LINUX */

#ifdef SUNOS4
	/*
	 * Return current program counter for `pid'
	 * Assumes PC is never 0xffffffff
	 */
	struct regs regs;

	if (ptrace(PTRACE_GETREGS, tcp->pid, (char *) &regs, 0) < 0) {
		perror("getpc: ptrace(PTRACE_GETREGS, ...)");
		return -1;
	}
	return regs.r_pc;
#endif /* SUNOS4 */

#ifdef SVR4
	/* XXX */
	return 0;
#endif /* SVR4 */

#ifdef FREEBSD
	struct reg regs;
	pread(tcp->pfd_reg, &regs, sizeof(regs), 0);
	return regs.r_eip;
#endif /* FREEBSD */
}

void
printcall(tcp)
struct tcb *tcp;
{

#ifdef LINUX
#ifdef I386
	long eip;

	if (upeek(tcp->pid, 4*EIP, &eip) < 0) {
		tprintf("[????????] ");
		return;
	}
	tprintf("[%08lx] ", eip);
#elif defined(X86_64)
	long rip;

	if (upeek(tcp->pid, 8*RIP, &rip) < 0) {
		tprintf("[????????] ");
		return;
	}
	tprintf("[%16lx] ", rip);
#elif defined(IA64)
	long ip;

	if (upeek(tcp->pid, PT_B0, &ip) < 0) {
		tprintf("[????????] ");
		return;
	}
	tprintf("[%08lx] ", ip);
#elif defined(POWERPC)
	long pc;

	if (upeek(tcp->pid, sizeof(unsigned long)*PT_NIP, &pc) < 0) {
		tprintf ("[????????] ");
		return;
	}
	tprintf("[%08lx] ", pc);
#elif defined(M68k)
	long pc;

	if (upeek(tcp->pid, 4*PT_PC, &pc) < 0) {
		tprintf ("[????????] ");
		return;
	}
	tprintf("[%08lx] ", pc);
#elif defined(ALPHA)
	long pc;

	if (upeek(tcp->pid, REG_PC, &pc) < 0) {
		tprintf ("[????????] ");
		return;
	}
	tprintf("[%08lx] ", pc);
#elif defined(SPARC) || defined(SPARC64)
	struct regs regs;
	if (ptrace(PTRACE_GETREGS,tcp->pid,(char *)&regs,0) < 0) {
		tprintf("[????????] ");
		return;
	}
	tprintf("[%08lx] ", regs.r_pc);
#elif defined(HPPA)
	long pc;

	if(upeek(tcp->pid,PT_IAOQ0,&pc) < 0) {
		tprintf ("[????????] ");
		return;
	}
	tprintf("[%08lx] ", pc);
#elif defined(MIPS)
	long pc;

	if (upeek(tcp->pid, REG_EPC, &pc) < 0) {
		tprintf ("[????????] ");
		return;
	}
	tprintf("[%08lx] ", pc);
#elif defined(SH)
       long pc;

       if (upeek(tcp->pid, 4*REG_PC, &pc) < 0) {
               tprintf ("[????????] ");
               return;
       }
       tprintf("[%08lx] ", pc);
#elif defined(SH64)
	long pc;

	if (upeek(tcp->pid, REG_PC, &pc) < 0) {
		tprintf ("[????????] ");
		return;
	}
	tprintf("[%08lx] ", pc);
#elif defined(ARM)
	long pc;

	if (upeek(tcp->pid, 4*15, &pc) < 0) {
		tprintf("[????????] ");
		return;
	}
	tprintf("[%08lx] ", pc);
#endif /* !architecture */
#endif /* LINUX */

#ifdef SUNOS4
	struct regs regs;

	if (ptrace(PTRACE_GETREGS, tcp->pid, (char *) &regs, 0) < 0) {
		perror("printcall: ptrace(PTRACE_GETREGS, ...)");
		tprintf("[????????] ");
		return;
	}
	tprintf("[%08x] ", regs.r_o7);
#endif /* SUNOS4 */

#ifdef SVR4
	/* XXX */
	tprintf("[????????] ");
#endif

#ifdef FREEBSD
	struct reg regs;
	pread(tcp->pfd_reg, &regs, sizeof(regs), 0);
	tprintf("[%08x] ", regs.r_eip);
#endif /* FREEBSD */
}

#ifndef USE_PROCFS

#if defined LINUX

#include <sys/syscall.h>
#ifndef CLONE_PTRACE
# define CLONE_PTRACE    0x00002000
#endif

#ifdef IA64

/* We don't have fork()/vfork() syscalls on ia64 itself, but the ia32
   subsystem has them for x86... */
#define SYS_fork	2
#define SYS_vfork	190

typedef unsigned long *arg_setup_state;

static int
arg_setup(struct tcb *tcp, arg_setup_state *state)
{
	unsigned long *bsp, cfm, sof, sol;

	if (ia32)
		return 0;

	if (upeek(tcp->pid, PT_AR_BSP, (long *) &bsp) < 0)
		return -1;
	if (upeek(tcp->pid, PT_CFM, (long *) &cfm) < 0)
		return -1;

	sof = (cfm >> 0) & 0x7f;
	sol = (cfm >> 7) & 0x7f;
	bsp = ia64_rse_skip_regs(bsp, -sof + sol);

	*state = bsp;
	return 0;
}

# define arg_finish_change(tcp, state)	0

#ifdef SYS_fork
static int
get_arg0 (struct tcb *tcp, arg_setup_state *state, long *valp)
{
	int ret;

	if (ia32)
		ret = upeek (tcp->pid, PT_R11, valp);
	else
		ret = umoven (tcp,
			      (unsigned long) ia64_rse_skip_regs(*state, 0),
			      sizeof(long), (void *) valp);
	return ret;
}

static int
get_arg1 (struct tcb *tcp, arg_setup_state *state, long *valp)
{
	int ret;

	if (ia32)
		ret = upeek (tcp->pid, PT_R9, valp);
	else
		ret = umoven (tcp,
			      (unsigned long) ia64_rse_skip_regs(*state, 1),
			      sizeof(long), (void *) valp);
	return ret;
}
#endif

static int
set_arg0 (struct tcb *tcp, arg_setup_state *state, long val)
{
	int req = PTRACE_POKEDATA;
	void *ap;

	if (ia32) {
		ap = (void *) (intptr_t) PT_R11;	 /* r11 == EBX */
		req = PTRACE_POKEUSER;
	} else
		ap = ia64_rse_skip_regs(*state, 0);
	errno = 0;
	ptrace(req, tcp->pid, ap, val);
	return errno ? -1 : 0;
}

static int
set_arg1 (struct tcb *tcp, arg_setup_state *state, long val)
{
	int req = PTRACE_POKEDATA;
	void *ap;

	if (ia32) {
		ap = (void *) (intptr_t) PT_R9;		/* r9 == ECX */
		req = PTRACE_POKEUSER;
	} else
		ap = ia64_rse_skip_regs(*state, 1);
	errno = 0;
	ptrace(req, tcp->pid, ap, val);
	return errno ? -1 : 0;
}

#elif defined (SPARC) || defined (SPARC64)

typedef struct regs arg_setup_state;

# define arg_setup(tcp, state) \
  (ptrace (PTRACE_GETREGS, tcp->pid, (char *) (state), 0))
# define arg_finish_change(tcp, state) \
  (ptrace (PTRACE_SETREGS, tcp->pid, (char *) (state), 0))

# define get_arg0(tcp, state, valp) (*(valp) = (state)->r_o0, 0)
# define get_arg1(tcp, state, valp) (*(valp) = (state)->r_o1, 0)
# define set_arg0(tcp, state, val) ((state)->r_o0 = (val), 0)
# define set_arg1(tcp, state, val) ((state)->r_o1 = (val), 0)
# define restore_arg0(tcp, state, val) 0

#else

# if defined S390 || defined S390X
/* Note: this is only true for the `clone' system call, which handles
   arguments specially.  We could as well say that its first two arguments
   are swapped relative to other architectures, but that would just be
   another #ifdef in the calls.  */
#  define arg0_offset	PT_GPR3
#  define arg1_offset	PT_ORIGGPR2
#  define restore_arg0(tcp, state, val) ((void) (state), 0)
#  define restore_arg1(tcp, state, val) ((void) (state), 0)
#  define arg0_index	1
#  define arg1_index	0
# elif defined (ALPHA) || defined (MIPS)
#  define arg0_offset	REG_A0
#  define arg1_offset	(REG_A0+1)
# elif defined (POWERPC)
#  define arg0_offset	(sizeof(unsigned long)*PT_R3)
#  define arg1_offset	(sizeof(unsigned long)*PT_R4)
#  define restore_arg0(tcp, state, val) ((void) (state), 0)
# elif defined (HPPA)
#  define arg0_offset	 PT_GR26
#  define arg1_offset	 (PT_GR26-4)
# elif defined (X86_64)
#  define arg0_offset	((long)(8*(current_personality ? RBX : RDI)))
#  define arg1_offset	((long)(8*(current_personality ? RCX : RSI)))
# elif defined (SH)
#  define arg0_offset	(4*(REG_REG0+4))
#  define arg1_offset	(4*(REG_REG0+5))
# elif defined (SH64)
   /* ABI defines arg0 & 1 in r2 & r3 */
#  define arg0_offset   (REG_OFFSET+16)
#  define arg1_offset   (REG_OFFSET+24)
#  define restore_arg0(tcp, state, val) 0
# else
#  define arg0_offset	0
#  define arg1_offset	4
#  if defined ARM
#   define restore_arg0(tcp, state, val) 0
#  endif
# endif

typedef int arg_setup_state;

# define arg_setup(tcp, state) (0)
# define arg_finish_change(tcp, state)	0
# define get_arg0(tcp, cookie, valp) \
  (upeek ((tcp)->pid, arg0_offset, (valp)))
# define get_arg1(tcp, cookie, valp) \
  (upeek ((tcp)->pid, arg1_offset, (valp)))

static int
set_arg0 (struct tcb *tcp, void *cookie, long val)
{
	return ptrace (PTRACE_POKEUSER, tcp->pid, (char*)arg0_offset, val);
}

static int
set_arg1 (struct tcb *tcp, void *cookie, long val)
{
	return ptrace (PTRACE_POKEUSER, tcp->pid, (char*)arg1_offset, val);
}

#endif

#ifndef restore_arg0
# define restore_arg0(tcp, state, val) set_arg0((tcp), (state), (val))
#endif
#ifndef restore_arg1
# define restore_arg1(tcp, state, val) set_arg1((tcp), (state), (val))
#endif

#ifndef arg0_index
# define arg0_index 0
# define arg1_index 1
#endif

int
setbpt(tcp)
struct tcb *tcp;
{
	extern int change_syscall(struct tcb *, int);
	arg_setup_state state;

	if (tcp->flags & TCB_BPTSET) {
		fprintf(stderr, "PANIC: TCB already set in pid %u\n", tcp->pid);
		return -1;
	}

	switch (tcp->scno) {
#ifdef SYS_vfork
	case SYS_vfork:
#endif
#ifdef SYS_fork
	case SYS_fork:
#endif
#if defined SYS_fork || defined SYS_vfork
		if (arg_setup (tcp, &state) < 0
		    || get_arg0 (tcp, &state, &tcp->inst[0]) < 0
		    || get_arg1 (tcp, &state, &tcp->inst[1]) < 0
		    || change_syscall(tcp, SYS_clone) < 0
		    || set_arg0 (tcp, &state, CLONE_PTRACE|SIGCHLD) < 0
		    || set_arg1 (tcp, &state, 0) < 0
		    || arg_finish_change (tcp, &state) < 0)
			return -1;
		tcp->u_arg[arg0_index] = CLONE_PTRACE|SIGCHLD;
		tcp->u_arg[arg1_index] = 0;
		tcp->flags |= TCB_BPTSET;
		return 0;
#endif

	case SYS_clone:
#ifdef SYS_clone2
	case SYS_clone2:
#endif
		if ((tcp->u_arg[arg0_index] & CLONE_PTRACE) == 0
		    && (arg_setup (tcp, &state) < 0
			|| set_arg0 (tcp, &state,
				     tcp->u_arg[arg0_index] | CLONE_PTRACE) < 0
			|| arg_finish_change (tcp, &state) < 0))
			return -1;
		tcp->flags |= TCB_BPTSET;
		tcp->inst[0] = tcp->u_arg[arg0_index];
		tcp->inst[1] = tcp->u_arg[arg1_index];
		return 0;

	default:
		fprintf(stderr, "PANIC: setbpt for syscall %ld on %u???\n",
			tcp->scno, tcp->pid);
		break;
	}

	return -1;
}

int
clearbpt(tcp)
struct tcb *tcp;
{
	arg_setup_state state;
	if (arg_setup (tcp, &state) < 0
	    || restore_arg0 (tcp, &state, tcp->inst[0]) < 0
	    || restore_arg1 (tcp, &state, tcp->inst[1]) < 0
	    || arg_finish_change (tcp, &state))
		return -1;
	tcp->flags &= ~TCB_BPTSET;
	return 0;
}

#else

int
setbpt(tcp)
struct tcb *tcp;
{

#ifdef LINUX
#if defined (SPARC) || defined (SPARC64)
	/* We simply use the SunOS breakpoint code. */

	struct regs regs;
	unsigned long inst;
#define LOOPA	0x30800000	/* ba,a	0 */

	if (tcp->flags & TCB_BPTSET) {
		fprintf(stderr, "PANIC: TCB already set in pid %u\n", tcp->pid);
		return -1;
	}
	if (ptrace(PTRACE_GETREGS, tcp->pid, (char *)&regs, 0) < 0) {
		perror("setbpt: ptrace(PTRACE_GETREGS, ...)");
		return -1;
	}
	tcp->baddr = regs.r_o7 + 8;
	errno = 0;
	tcp->inst[0] = ptrace(PTRACE_PEEKTEXT, tcp->pid, (char *)tcp->baddr, 0);
	if(errno) {
		perror("setbpt: ptrace(PTRACE_PEEKTEXT, ...)");
		return -1;
	}

	/*
	 * XXX - BRUTAL MODE ON
	 * We cannot set a real BPT in the child, since it will not be
	 * traced at the moment it will reach the trap and would probably
	 * die with a core dump.
	 * Thus, we are force our way in by taking out two instructions
	 * and insert an eternal loop instead, in expectance of the SIGSTOP
	 * generated by out PTRACE_ATTACH.
	 * Of cause, if we evaporate ourselves in the middle of all this...
	 */
	errno = 0;
	inst = LOOPA;
#if defined (SPARC64)
	inst <<= 32;
	inst |= (tcp->inst[0] & 0xffffffffUL);
#endif
	ptrace(PTRACE_POKETEXT, tcp->pid, (char *) tcp->baddr, inst);
	if(errno) {
		perror("setbpt: ptrace(PTRACE_POKETEXT, ...)");
		return -1;
	}
	tcp->flags |= TCB_BPTSET;

#else /* !SPARC && !SPARC64 */
#ifdef IA64
	if (ia32) {
#		define LOOP	0x0000feeb
		if (tcp->flags & TCB_BPTSET) {
			fprintf(stderr, "PANIC: bpt already set in pid %u\n",
				tcp->pid);
			return -1;
		}
		if (upeek(tcp->pid, PT_CR_IIP, &tcp->baddr) < 0)
			return -1;
		if (debug)
			fprintf(stderr, "[%d] setting bpt at %lx\n",
				tcp->pid, tcp->baddr);
		tcp->inst[0] = ptrace(PTRACE_PEEKTEXT, tcp->pid,
				      (char *) tcp->baddr, 0);
		if (errno) {
			perror("setbpt: ptrace(PTRACE_PEEKTEXT, ...)");
			return -1;
		}
		ptrace(PTRACE_POKETEXT, tcp->pid, (char *) tcp->baddr, LOOP);
		if (errno) {
			perror("setbpt: ptrace(PTRACE_POKETEXT, ...)");
			return -1;
		}
		tcp->flags |= TCB_BPTSET;
	} else {
		/*
		 * Our strategy here is to replace the bundle that
		 * contained the clone() syscall with a bundle of the
		 * form:
		 *
		 *	{ 1: br 1b; br 1b; br 1b }
		 *
		 * This ensures that the newly forked child will loop
		 * endlessly until we've got a chance to attach to it.
		 */
#		define LOOP0	0x0000100000000017
#		define LOOP1	0x4000000000200000
		unsigned long addr, ipsr;
		pid_t pid;

		pid = tcp->pid;
		if (upeek(pid, PT_CR_IPSR, &ipsr) < 0)
			return -1;
		if (upeek(pid, PT_CR_IIP, &addr) < 0)
			return -1;
		/* store "ri" in low two bits */
		tcp->baddr = addr | ((ipsr >> 41) & 0x3);

		errno = 0;
		tcp->inst[0] = ptrace(PTRACE_PEEKTEXT, pid, (char *) addr + 0,
				      0);
		tcp->inst[1] = ptrace(PTRACE_PEEKTEXT, pid, (char *) addr + 8,
				      0);
		if (errno) {
			perror("setbpt: ptrace(PTRACE_PEEKTEXT, ...)");
			return -1;
		}

		errno = 0;
		ptrace(PTRACE_POKETEXT, pid, (char *) addr + 0, LOOP0);
		ptrace(PTRACE_POKETEXT, pid, (char *) addr + 8, LOOP1);
		if (errno) {
			perror("setbpt: ptrace(PTRACE_POKETEXT, ...)");
			return -1;
		}
		tcp->flags |= TCB_BPTSET;
	}
#else /* !IA64 */

#if defined (I386) || defined(X86_64)
#define LOOP	0x0000feeb
#elif defined (M68K)
#define LOOP	0x60fe0000
#elif defined (ALPHA)
#define LOOP	0xc3ffffff
#elif defined (POWERPC)
#define LOOP	0x48000000
#elif defined(ARM)
#define LOOP	0xEAFFFFFE
#elif defined(MIPS)
#define LOOP	0x1000ffff
#elif defined(S390)
#define LOOP	0xa7f40000	/* BRC 15,0 */
#elif defined(S390X)
#define LOOP   0xa7f4000000000000UL /* BRC 15,0 */
#elif defined(HPPA)
#define LOOP	0xe81f1ff7	/* b,l,n <loc>,r0 */
#elif defined(SH)
#ifdef __LITTLE_ENDIAN__
#define LOOP   0x0000affe
#else
#define LOOP   0xfeaf0000
#endif
#else
#error unknown architecture
#endif

	if (tcp->flags & TCB_BPTSET) {
		fprintf(stderr, "PANIC: bpt already set in pid %u\n", tcp->pid);
		return -1;
	}
#if defined (I386)
	if (upeek(tcp->pid, 4*EIP, &tcp->baddr) < 0)
		return -1;
#elif defined (X86_64)
	if (upeek(tcp->pid, 8*RIP, &tcp->baddr) < 0)
		return -1;
#elif defined (M68K)
	if (upeek(tcp->pid, 4*PT_PC, &tcp->baddr) < 0)
	  return -1;
#elif defined (ALPHA)
	return -1;
#elif defined (ARM)
	return -1;
#elif defined (MIPS)
	return -1;		/* FIXME: I do not know what i do - Flo */
#elif defined (POWERPC)
	if (upeek(tcp->pid, sizeof(unsigned long)*PT_NIP, &tcp->baddr) < 0)
		return -1;
#elif defined(S390) || defined(S390X)
	if (upeek(tcp->pid,PT_PSWADDR, &tcp->baddr) < 0)
		return -1;
#elif defined(HPPA)
	if (upeek(tcp->pid, PT_IAOQ0, &tcp->baddr) < 0)
		return -1;
	tcp->baddr &= ~0x03;
#elif defined(SH)
       if (upeek(tcp->pid, 4*REG_PC, &tcp->baddr) < 0)
               return -1;
#else
#error unknown architecture
#endif
	if (debug)
		fprintf(stderr, "[%d] setting bpt at %lx\n", tcp->pid, tcp->baddr);
	tcp->inst[0] = ptrace(PTRACE_PEEKTEXT, tcp->pid, (char *) tcp->baddr, 0);
	if (errno) {
		perror("setbpt: ptrace(PTRACE_PEEKTEXT, ...)");
		return -1;
	}
	ptrace(PTRACE_POKETEXT, tcp->pid, (char *) tcp->baddr, LOOP);
	if (errno) {
		perror("setbpt: ptrace(PTRACE_POKETEXT, ...)");
		return -1;
	}
	tcp->flags |= TCB_BPTSET;

#endif /* !IA64 */
#endif /* SPARC || SPARC64 */
#endif /* LINUX */

#ifdef SUNOS4
#ifdef SPARC	/* This code is slightly sparc specific */

	struct regs regs;
#define BPT	0x91d02001	/* ta	1 */
#define LOOP	0x10800000	/* ba	0 */
#define LOOPA	0x30800000	/* ba,a	0 */
#define NOP	0x01000000
#if LOOPA
	static int loopdeloop[1] = {LOOPA};
#else
	static int loopdeloop[2] = {LOOP, NOP};
#endif

	if (tcp->flags & TCB_BPTSET) {
		fprintf(stderr, "PANIC: TCB already set in pid %u\n", tcp->pid);
		return -1;
	}
	if (ptrace(PTRACE_GETREGS, tcp->pid, (char *)&regs, 0) < 0) {
		perror("setbpt: ptrace(PTRACE_GETREGS, ...)");
		return -1;
	}
	tcp->baddr = regs.r_o7 + 8;
	if (ptrace(PTRACE_READTEXT, tcp->pid, (char *)tcp->baddr,
				sizeof tcp->inst, (char *)tcp->inst) < 0) {
		perror("setbpt: ptrace(PTRACE_READTEXT, ...)");
		return -1;
	}

	/*
	 * XXX - BRUTAL MODE ON
	 * We cannot set a real BPT in the child, since it will not be
	 * traced at the moment it will reach the trap and would probably
	 * die with a core dump.
	 * Thus, we are force our way in by taking out two instructions
	 * and insert an eternal loop in stead, in expectance of the SIGSTOP
	 * generated by out PTRACE_ATTACH.
	 * Of cause, if we evaporate ourselves in the middle of all this...
	 */
	if (ptrace(PTRACE_WRITETEXT, tcp->pid, (char *) tcp->baddr,
			sizeof loopdeloop, (char *) loopdeloop) < 0) {
		perror("setbpt: ptrace(PTRACE_WRITETEXT, ...)");
		return -1;
	}
	tcp->flags |= TCB_BPTSET;

#endif /* SPARC */
#endif /* SUNOS4 */

	return 0;
}

int
clearbpt(tcp)
struct tcb *tcp;
{

#ifdef LINUX
#if defined(I386) || defined(X86_64)
	long eip;
#elif defined(POWERPC)
	long pc;
#elif defined(M68K)
	long pc;
#elif defined(ALPHA)
	long pc;
#elif defined(HPPA)
	long iaoq;
#elif defined(SH)
       long pc;
#endif /* architecture */

#if defined (SPARC) || defined (SPARC64)
	/* Again, we borrow the SunOS breakpoint code. */
	if (!(tcp->flags & TCB_BPTSET)) {
		fprintf(stderr, "PANIC: TCB not set in pid %u\n", tcp->pid);
		return -1;
	}
	errno = 0;
	ptrace(PTRACE_POKETEXT, tcp->pid, (char *) tcp->baddr, tcp->inst[0]);
	if(errno) {
		perror("clearbtp: ptrace(PTRACE_POKETEXT, ...)");
		return -1;
	}
	tcp->flags &= ~TCB_BPTSET;
#elif defined(IA64)
	if (ia32) {
		unsigned long addr;

		if (debug)
			fprintf(stderr, "[%d] clearing bpt\n", tcp->pid);
		if (!(tcp->flags & TCB_BPTSET)) {
			fprintf(stderr, "PANIC: TCB not set in pid %u\n", tcp->pid);
			return -1;
		}
		errno = 0;
		ptrace(PTRACE_POKETEXT, tcp->pid, (char *) tcp->baddr, tcp->inst[0]);
		if (errno) {
			perror("clearbtp: ptrace(PTRACE_POKETEXT, ...)");
			return -1;
		}
		tcp->flags &= ~TCB_BPTSET;

		if (upeek(tcp->pid, PT_CR_IIP, &addr) < 0)
			return -1;
		if (addr != tcp->baddr) {
			/* The breakpoint has not been reached yet.  */
			if (debug)
				fprintf(stderr,
					"NOTE: PC not at bpt (pc %#lx baddr %#lx)\n",
						addr, tcp->baddr);
			return 0;
		}
	} else {
		unsigned long addr, ipsr;
		pid_t pid;

		pid = tcp->pid;

		if (upeek(pid, PT_CR_IPSR, &ipsr) < 0)
			return -1;
		if (upeek(pid, PT_CR_IIP, &addr) < 0)
			return -1;

		/* restore original bundle: */
		errno = 0;
		ptrace(PTRACE_POKETEXT, pid, (char *) addr + 0, tcp->inst[0]);
		ptrace(PTRACE_POKETEXT, pid, (char *) addr + 8, tcp->inst[1]);
		if (errno) {
			perror("clearbpt: ptrace(PTRACE_POKETEXT, ...)");
			return -1;
		}

		/* restore original "ri" in ipsr: */
		ipsr = (ipsr & ~(0x3ul << 41)) | ((tcp->baddr & 0x3) << 41);
		errno = 0;
		ptrace(PTRACE_POKEUSER, pid, (char *) PT_CR_IPSR, ipsr);
		if (errno) {
			perror("clrbpt: ptrace(PTRACE_POKEUSER, ...)");
			return -1;
		}

		tcp->flags &= ~TCB_BPTSET;

		if (addr != (tcp->baddr & ~0x3)) {
			/* the breakpoint has not been reached yet.  */
			if (debug)
				fprintf(stderr, "NOTE: PC not at bpt (pc %#lx baddr %#lx)\n",
					addr, tcp->baddr);
			return 0;
		}
	}
#else /* !IA64  && !SPARC && !SPARC64 */

	if (debug)
		fprintf(stderr, "[%d] clearing bpt\n", tcp->pid);
	if (!(tcp->flags & TCB_BPTSET)) {
		fprintf(stderr, "PANIC: TCB not set in pid %u\n", tcp->pid);
		return -1;
	}
	errno = 0;
	ptrace(PTRACE_POKETEXT, tcp->pid, (char *) tcp->baddr, tcp->inst[0]);
	if (errno) {
		perror("clearbtp: ptrace(PTRACE_POKETEXT, ...)");
		return -1;
	}
	tcp->flags &= ~TCB_BPTSET;

#ifdef I386
	if (upeek(tcp->pid, 4*EIP, &eip) < 0)
		return -1;
	if (eip != tcp->baddr) {
		/* The breakpoint has not been reached yet.  */
		if (debug)
			fprintf(stderr,
				"NOTE: PC not at bpt (pc %#lx baddr %#lx)\n",
					eip, tcp->baddr);
		return 0;
	}
#elif defined(X86_64)
	if (upeek(tcp->pid, 8*RIP, &eip) < 0)
		return -1;
	if (eip != tcp->baddr) {
		/* The breakpoint has not been reached yet.  */
		if (debug)
			fprintf(stderr,
				"NOTE: PC not at bpt (pc %#lx baddr %#lx)\n",
					eip, tcp->baddr);
		return 0;
	}
#elif defined(POWERPC)
	if (upeek(tcp->pid, sizeof(unsigned long)*PT_NIP, &pc) < 0)
		return -1;
	if (pc != tcp->baddr) {
		/* The breakpoint has not been reached yet.  */
		if (debug)
			fprintf(stderr, "NOTE: PC not at bpt (pc %#lx baddr %#lx)\n",
				pc, tcp->baddr);
		return 0;
	}
#elif defined(M68K)
	if (upeek(tcp->pid, 4*PT_PC, &pc) < 0)
		return -1;
	if (pc != tcp->baddr) {
		/* The breakpoint has not been reached yet.  */
		if (debug)
			fprintf(stderr, "NOTE: PC not at bpt (pc %#lx baddr %#lx)\n",
				pc, tcp->baddr);
		return 0;
	}
#elif defined(ALPHA)
	if (upeek(tcp->pid, REG_PC, &pc) < 0)
		return -1;
	if (pc != tcp->baddr) {
		/* The breakpoint has not been reached yet.  */
		if (debug)
			fprintf(stderr, "NOTE: PC not at bpt (pc %#lx baddr %#lx)\n",
				pc, tcp->baddr);
		return 0;
	}
#elif defined(HPPA)
	if (upeek(tcp->pid, PT_IAOQ0, &iaoq) < 0)
		return -1;
	iaoq &= ~0x03;
	if (iaoq != tcp->baddr && iaoq != tcp->baddr + 4) {
		/* The breakpoint has not been reached yet.  */
		if (debug)
			fprintf(stderr, "NOTE: PC not at bpt (iaoq %#lx baddr %#lx)\n",
				iaoq, tcp->baddr);
		return 0;
	}
	iaoq = tcp->baddr | 3;
	/* We should be pointing at a 'ldi -1000,r1' in glibc, so it is
	 * safe to set both IAOQ0 and IAOQ1 to that so the PSW N bit
	 * has no significant effect.
	 */
	ptrace(PTRACE_POKEUSER, tcp->pid, (void *)PT_IAOQ0, iaoq);
	ptrace(PTRACE_POKEUSER, tcp->pid, (void *)PT_IAOQ1, iaoq);
#elif defined(SH)
       if (upeek(tcp->pid, 4*REG_PC, &pc) < 0)
               return -1;
        if (pc != tcp->baddr) {
                /* The breakpoint has not been reached yet.  */
                if (debug)
                        fprintf(stderr, "NOTE: PC not at bpt (pc %#lx baddr %#lx)\n",
                                pc, tcp->baddr);
                return 0;
        }

#endif /* arch */
#endif /* !SPARC && !SPARC64 && !IA64 */
#endif /* LINUX */

#ifdef SUNOS4
#ifdef SPARC

#if !LOOPA
	struct regs regs;
#endif

	if (!(tcp->flags & TCB_BPTSET)) {
		fprintf(stderr, "PANIC: TCB not set in pid %u\n", tcp->pid);
		return -1;
	}
	if (ptrace(PTRACE_WRITETEXT, tcp->pid, (char *) tcp->baddr,
				sizeof tcp->inst, (char *) tcp->inst) < 0) {
		perror("clearbtp: ptrace(PTRACE_WRITETEXT, ...)");
		return -1;
	}
	tcp->flags &= ~TCB_BPTSET;

#if !LOOPA
	/*
	 * Since we don't have a single instruction breakpoint, we may have
	 * to adjust the program counter after removing the our `breakpoint'.
	 */
	if (ptrace(PTRACE_GETREGS, tcp->pid, (char *)&regs, 0) < 0) {
		perror("clearbpt: ptrace(PTRACE_GETREGS, ...)");
		return -1;
	}
	if ((regs.r_pc < tcp->baddr) ||
				(regs.r_pc > tcp->baddr + 4)) {
		/* The breakpoint has not been reached yet */
		if (debug)
			fprintf(stderr,
				"NOTE: PC not at bpt (pc %#x baddr %#x)\n",
					regs.r_pc, tcp->parent->baddr);
		return 0;
	}
	if (regs.r_pc != tcp->baddr)
		if (debug)
			fprintf(stderr, "NOTE: PC adjusted (%#x -> %#x\n",
				regs.r_pc, tcp->baddr);

	regs.r_pc = tcp->baddr;
	if (ptrace(PTRACE_SETREGS, tcp->pid, (char *)&regs, 0) < 0) {
		perror("clearbpt: ptrace(PTRACE_SETREGS, ...)");
		return -1;
	}
#endif /* LOOPA */
#endif /* SPARC */
#endif /* SUNOS4 */

	return 0;
}

#endif

#endif /* !USE_PROCFS */

#ifdef SUNOS4

static int
getex(pid, hdr)
int pid;
struct exec *hdr;
{
	int n;

	for (n = 0; n < sizeof *hdr; n += 4) {
		long res;
		if (upeek(pid, uoff(u_exdata) + n, &res) < 0)
			return -1;
		memcpy(((char *) hdr) + n, &res, 4);
	}
	if (debug) {
		fprintf(stderr, "[struct exec: magic: %o version %u Mach %o\n",
			hdr->a_magic, hdr->a_toolversion, hdr->a_machtype);
		fprintf(stderr, "Text %lu Data %lu Bss %lu Syms %lu Entry %#lx]\n",
			hdr->a_text, hdr->a_data, hdr->a_bss, hdr->a_syms, hdr->a_entry);
	}
	return 0;
}

int
fixvfork(tcp)
struct tcb *tcp;
{
	int pid = tcp->pid;
	/*
	 * Change `vfork' in a freshly exec'ed dynamically linked
	 * executable's (internal) symbol table to plain old `fork'
	 */

	struct exec hdr;
	struct link_dynamic dyn;
	struct link_dynamic_2 ld;
	char *strtab, *cp;

	if (getex(pid, &hdr) < 0)
		return -1;
	if (!hdr.a_dynamic)
		return -1;

	if (umove(tcp, (int) N_DATADDR(hdr), &dyn) < 0) {
		fprintf(stderr, "Cannot read DYNAMIC\n");
		return -1;
	}
	if (umove(tcp, (int) dyn.ld_un.ld_2, &ld) < 0) {
		fprintf(stderr, "Cannot read link_dynamic_2\n");
		return -1;
	}
	if ((strtab = malloc((unsigned)ld.ld_symb_size)) == NULL) {
		fprintf(stderr, "fixvfork: out of memory\n");
		return -1;
	}
	if (umoven(tcp, (int)ld.ld_symbols+(int)N_TXTADDR(hdr),
					(int)ld.ld_symb_size, strtab) < 0)
		goto err;

#if 0
	for (cp = strtab; cp < strtab + ld.ld_symb_size; ) {
		fprintf(stderr, "[symbol: %s]\n", cp);
		cp += strlen(cp)+1;
	}
	return 0;
#endif
	for (cp = strtab; cp < strtab + ld.ld_symb_size; ) {
		if (strcmp(cp, "_vfork") == 0) {
			if (debug)
				fprintf(stderr, "fixvfork: FOUND _vfork\n");
			strcpy(cp, "_fork");
			break;
		}
		cp += strlen(cp)+1;
	}
	if (cp < strtab + ld.ld_symb_size)
		/*
		 * Write entire symbol table back to avoid
		 * memory alignment bugs in ptrace
		 */
		if (tload(pid, (int)ld.ld_symbols+(int)N_TXTADDR(hdr),
					(int)ld.ld_symb_size, strtab) < 0)
			goto err;

	free(strtab);
	return 0;

err:
	free(strtab);
	return -1;
}

#endif /* SUNOS4 */
