Page MenuHomeFreeBSD

D3851.diff
No OneTemporary

D3851.diff

Index: head/usr.bin/truss/Makefile
===================================================================
--- head/usr.bin/truss/Makefile
+++ head/usr.bin/truss/Makefile
@@ -2,87 +2,64 @@
NO_WERROR=
PROG= truss
-SRCS= main.c setup.c syscalls.c syscalls.h ioctl.c
-
-.if exists(${.CURDIR}/${MACHINE_ARCH}-fbsd.c)
-SRCS+= ${MACHINE_ARCH}-fbsd.c
-.else
-SRCS+= ${MACHINE_CPUARCH}-fbsd.c
-.endif
+SRCS= main.c setup.c syscalls.c ioctl.c
.PATH: ${.CURDIR:H}/kdump
SRCS+= utrace.c
CFLAGS+= -I${.CURDIR} -I. -I${.CURDIR}/../../sys
-CLEANFILES= syscalls.master syscalls.h ioctl.c
-
-.SUFFIXES: .master
-
-syscalls.master: ${.CURDIR}/../../sys/kern/syscalls.master
- cat ${.ALLSRC} > syscalls.master
-
-syscalls.h: syscalls.master
- /bin/sh ${.CURDIR}/../../sys/kern/makesyscalls.sh syscalls.master \
- ${.CURDIR}/i386.conf
+CLEANFILES= ioctl.c
ioctl.c: ${.CURDIR}/../kdump/mkioctls
env MACHINE=${MACHINE} CPP="${CPP}" \
/bin/sh ${.CURDIR}/../kdump/mkioctls return ${DESTDIR}${INCLUDEDIR} > ${.TARGET}
+# Define where to generate syscalls for each ABI.
+ABI_SYSPATH.freebsd= sys/kern
+ABI_SYSPATH.freebsd32= sys/compat/freebsd32
+ABI_SYSPATH.cloudabi64= sys/compat/cloudabi64
+ABI_SYSPATH.i386-linux= sys/i386/linux
+ABI_SYSPATH.amd64-linux32= sys/amd64/linux32
+
+ABIS+= freebsd
+# Each ABI is expected to have an ABI.c, MACHINE_ARCH-ABI.c or
+# MACHINE_CPUARCH-ABI.c file that will be used to map the syscall arguments.
.if ${MACHINE_CPUARCH} == "i386"
-SRCS+= i386-linux.c linux_syscalls.h
-CLEANFILES+=i386l-syscalls.master linux_syscalls.h
-
-i386l-syscalls.master: ${.CURDIR}/../../sys/i386/linux/syscalls.master
- cat ${.ALLSRC} > ${.TARGET}
-
-linux_syscalls.h: i386l-syscalls.master
- /bin/sh ${.CURDIR}/../../sys/kern/makesyscalls.sh ${.ALLSRC} \
- ${.CURDIR}/i386linux.conf
+ABIS+= i386-linux
.endif
-
.if ${MACHINE_CPUARCH} == "amd64"
-SRCS+= amd64-linux32.c linux32_syscalls.h
-CLEANFILES+=amd64l32-syscalls.master linux32_syscalls.h
-
-amd64l32-syscalls.master: ${.CURDIR}/../../sys/amd64/linux32/syscalls.master
- cat ${.ALLSRC} > ${.TARGET}
-
-linux32_syscalls.h: amd64l32-syscalls.master
- /bin/sh ${.CURDIR}/../../sys/kern/makesyscalls.sh ${.ALLSRC} \
- ${.CURDIR}/amd64linux32.conf
-
-SRCS+= amd64-fbsd32.c freebsd32_syscalls.h
-CLEANFILES+=fbsd32-syscalls.master freebsd32_syscalls.h
-
-fbsd32-syscalls.master: ${.CURDIR}/../../sys/compat/freebsd32/syscalls.master
- cat ${.ALLSRC} > ${.TARGET}
-
-freebsd32_syscalls.h: fbsd32-syscalls.master
- /bin/sh ${.CURDIR}/../../sys/kern/makesyscalls.sh ${.ALLSRC} \
- ${.CURDIR}/fbsd32.conf
-
-SRCS+= amd64-cloudabi64.c cloudabi64_syscalls.h
-CLEANFILES+=amd64cloudabi64-syscalls.master cloudabi64_syscalls.h
-
-amd64cloudabi64-syscalls.master: ${.CURDIR}/../../sys/compat/cloudabi64/syscalls.master
- cat ${.ALLSRC} > ${.TARGET}
-
-cloudabi64_syscalls.h: amd64cloudabi64-syscalls.master
- /bin/sh ${.CURDIR}/../../sys/kern/makesyscalls.sh ${.ALLSRC} \
- ${.CURDIR}/amd64cloudabi64.conf
+ABIS+= amd64-linux32
+ABIS+= freebsd32
+ABIS+= cloudabi64
.endif
-
.if ${MACHINE_ARCH} == "powerpc64"
-SRCS+= powerpc-fbsd.c freebsd32_syscalls.h
-CLEANFILES+=fbsd32-syscalls.master freebsd32_syscalls.h
-
-fbsd32-syscalls.master: ${.CURDIR}/../../sys/compat/freebsd32/syscalls.master
- cat ${.ALLSRC} > ${.TARGET}
+ABIS+= freebsd32
+.endif
-freebsd32_syscalls.h: fbsd32-syscalls.master
- /bin/sh ${.CURDIR}/../../sys/kern/makesyscalls.sh ${.ALLSRC} \
- ${.CURDIR}/fbsd32.conf
+.for abi in ${ABIS}
+# Find the right file to handle this ABI.
+abi_src=
+ABI_SRCS= ${abi}.c ${MACHINE_ARCH}-${abi}.c ${MACHINE_CPUARCH}-${abi}.c
+.for f in ${ABI_SRCS}
+.if exists(${.CURDIR}/${f}) && empty(abi_src)
+abi_src= ${f}
.endif
+.endfor
+SRCS:= ${SRCS} ${abi_src} ${abi}_syscalls.h
+CLEANFILES+= ${abi}_syscalls.conf ${abi}_syscalls.master ${abi}_syscalls.h
+${abi}_syscalls.conf: ${.CURDIR}/makesyscallsconf.sh
+ /bin/sh ${.CURDIR}/makesyscallsconf.sh ${abi} ${.TARGET}
+
+${abi}_syscalls.master: ${.CURDIR:H:H}/${ABI_SYSPATH.${abi}}/syscalls.master
+ cp -f ${.ALLSRC} ${.TARGET}
+
+${abi}_syscalls.h: ${abi}_syscalls.master ${abi}_syscalls.conf \
+ ${.CURDIR:H:H}/sys/kern/makesyscalls.sh
+ /bin/sh ${.CURDIR:H:H}/sys/kern/makesyscalls.sh \
+ ${abi}_syscalls.master ${abi}_syscalls.conf
+# Eliminate compiler warning about non-static global.
+ sed -i '' '/^const char \*/s/^/static /' ${.TARGET}.tmp
+ mv ${.TARGET}.tmp ${.TARGET}
+.endfor
.include <bsd.prog.mk>
Index: head/usr.bin/truss/Makefile.depend.amd64
===================================================================
--- head/usr.bin/truss/Makefile.depend.amd64
+++ head/usr.bin/truss/Makefile.depend.amd64
@@ -19,12 +19,12 @@
# local dependencies - needed for -jN in clean tree
amd64-cloudabi64.o: cloudabi64_syscalls.h
amd64-cloudabi64.po: cloudabi64_syscalls.h
-amd64-fbsd.o: syscalls.h
-amd64-fbsd.po: syscalls.h
-amd64-fbsd32.o: freebsd32_syscalls.h
-amd64-fbsd32.po: freebsd32_syscalls.h
-amd64-linux32.o: linux32_syscalls.h
-amd64-linux32.po: linux32_syscalls.h
+amd64-freebsd.o: freebsd_syscalls.h
+amd64-freebsd.po: freebsd_syscalls.h
+amd64-freebsd32.o: freebsd32_syscalls.h
+amd64-freebsd32.po: freebsd32_syscalls.h
+amd64-linux32.o: amd64-linux32_syscalls.h
+amd64-linux32.po: amd64-linux32_syscalls.h
ioctl.o: ioctl.c
ioctl.po: ioctl.c
.endif
Index: head/usr.bin/truss/aarch64-fbsd.c
===================================================================
--- head/usr.bin/truss/aarch64-fbsd.c
+++ head/usr.bin/truss/aarch64-fbsd.c
@@ -1,110 +0,0 @@
-/*
- * Copyright (c) 2015 The FreeBSD Foundation
- *
- * Portions of this software were developed by Konstantin Belousov
- * under sponsorship from the FreeBSD Foundation.
- *
- * 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.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
- */
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-/* FreeBSD/arm64-specific system call handling. */
-
-#include <sys/ptrace.h>
-#include <sys/syscall.h>
-
-#include <machine/reg.h>
-#include <machine/armreg.h>
-#include <machine/ucontext.h>
-
-#include <stdio.h>
-
-#include "truss.h"
-
-extern const char *syscallnames[]; /* silence compiler */
-#include "syscalls.h"
-
-static int
-aarch64_fetch_args(struct trussinfo *trussinfo, u_int narg)
-{
- struct reg regs;
- struct current_syscall *cs;
- lwpid_t tid;
- u_int i, reg, syscall_num;
-
- tid = trussinfo->curthread->tid;
- cs = &trussinfo->curthread->cs;
- if (ptrace(PT_GETREGS, tid, (caddr_t)&regs, 0) < 0) {
- fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
- return (-1);
- }
-
- /*
- * FreeBSD has two special kinds of system call redirections --
- * SYS_syscall, and SYS___syscall. The former is the old syscall()
- * routine, basically; the latter is for quad-aligned arguments.
- *
- * The system call argument count and code from ptrace() already
- * account for these, but we need to skip over the first argument.
- */
- syscall_num = regs.x[8];
- if (syscall_num == SYS_syscall || syscall_num == SYS___syscall) {
- reg = 1;
- syscall_num = regs.x[0];
- } else {
- reg = 0;
- }
-
- for (i = 0; i < narg && reg < 8; i++, reg++)
- cs->args[i] = regs.x[reg];
- return (0);
-}
-
-static int
-aarch64_fetch_retval(struct trussinfo *trussinfo, long *retval, int *errorp)
-{
- struct reg regs;
- lwpid_t tid;
-
- tid = trussinfo->curthread->tid;
- if (ptrace(PT_GETREGS, tid, (caddr_t)&regs, 0) < 0) {
- fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
- return (-1);
- }
-
- retval[0] = regs.x[0];
- retval[1] = regs.x[1];
- *errorp = !!(regs.spsr & PSR_C);
- return (0);
-}
-
-static struct procabi aarch64_fbsd = {
- "FreeBSD ELF64",
- syscallnames,
- nitems(syscallnames),
- aarch64_fetch_args,
- aarch64_fetch_retval
-};
-
-PROCABI(aarch64_fbsd);
Index: head/usr.bin/truss/aarch64-freebsd.c
===================================================================
--- head/usr.bin/truss/aarch64-freebsd.c
+++ head/usr.bin/truss/aarch64-freebsd.c
@@ -0,0 +1,109 @@
+/*
+ * Copyright (c) 2015 The FreeBSD Foundation
+ *
+ * Portions of this software were developed by Konstantin Belousov
+ * under sponsorship from the FreeBSD Foundation.
+ *
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+/* FreeBSD/arm64-specific system call handling. */
+
+#include <sys/ptrace.h>
+#include <sys/syscall.h>
+
+#include <machine/reg.h>
+#include <machine/armreg.h>
+#include <machine/ucontext.h>
+
+#include <stdio.h>
+
+#include "truss.h"
+
+#include "freebsd_syscalls.h"
+
+static int
+aarch64_fetch_args(struct trussinfo *trussinfo, u_int narg)
+{
+ struct reg regs;
+ struct current_syscall *cs;
+ lwpid_t tid;
+ u_int i, reg, syscall_num;
+
+ tid = trussinfo->curthread->tid;
+ cs = &trussinfo->curthread->cs;
+ if (ptrace(PT_GETREGS, tid, (caddr_t)&regs, 0) < 0) {
+ fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
+ return (-1);
+ }
+
+ /*
+ * FreeBSD has two special kinds of system call redirections --
+ * SYS_syscall, and SYS___syscall. The former is the old syscall()
+ * routine, basically; the latter is for quad-aligned arguments.
+ *
+ * The system call argument count and code from ptrace() already
+ * account for these, but we need to skip over the first argument.
+ */
+ syscall_num = regs.x[8];
+ if (syscall_num == SYS_syscall || syscall_num == SYS___syscall) {
+ reg = 1;
+ syscall_num = regs.x[0];
+ } else {
+ reg = 0;
+ }
+
+ for (i = 0; i < narg && reg < 8; i++, reg++)
+ cs->args[i] = regs.x[reg];
+ return (0);
+}
+
+static int
+aarch64_fetch_retval(struct trussinfo *trussinfo, long *retval, int *errorp)
+{
+ struct reg regs;
+ lwpid_t tid;
+
+ tid = trussinfo->curthread->tid;
+ if (ptrace(PT_GETREGS, tid, (caddr_t)&regs, 0) < 0) {
+ fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
+ return (-1);
+ }
+
+ retval[0] = regs.x[0];
+ retval[1] = regs.x[1];
+ *errorp = !!(regs.spsr & PSR_C);
+ return (0);
+}
+
+static struct procabi aarch64_freebsd = {
+ "FreeBSD ELF64",
+ syscallnames,
+ nitems(syscallnames),
+ aarch64_fetch_args,
+ aarch64_fetch_retval
+};
+
+PROCABI(aarch64_freebsd);
Index: head/usr.bin/truss/amd64-cloudabi64.c
===================================================================
--- head/usr.bin/truss/amd64-cloudabi64.c
+++ head/usr.bin/truss/amd64-cloudabi64.c
@@ -171,8 +171,8 @@
static struct procabi amd64_cloudabi64 = {
"CloudABI ELF64",
- cloudabi64_syscallnames,
- nitems(cloudabi64_syscallnames),
+ syscallnames,
+ nitems(syscallnames),
amd64_cloudabi64_fetch_args,
amd64_cloudabi64_fetch_retval
};
Index: head/usr.bin/truss/amd64-fbsd.c
===================================================================
--- head/usr.bin/truss/amd64-fbsd.c
+++ head/usr.bin/truss/amd64-fbsd.c
@@ -1,131 +0,0 @@
-/*
- * Copyright 1997 Sean Eric Fagan
- *
- * 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. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by Sean Eric Fagan
- * 4. Neither the name of the author may be used to endorse or promote
- * products derived from this software without specific prior written
- * permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
- */
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-/* FreeBSD/amd64-specific system call handling. */
-
-#include <sys/ptrace.h>
-#include <sys/syscall.h>
-
-#include <machine/reg.h>
-#include <machine/psl.h>
-
-#include <stdio.h>
-
-#include "truss.h"
-
-#include "syscalls.h"
-
-static int
-amd64_fetch_args(struct trussinfo *trussinfo, u_int narg)
-{
- struct ptrace_io_desc iorequest;
- struct reg regs;
- struct current_syscall *cs;
- lwpid_t tid;
- u_int i, reg;
-
- tid = trussinfo->curthread->tid;
- cs = &trussinfo->curthread->cs;
- if (ptrace(PT_GETREGS, tid, (caddr_t)&regs, 0) < 0) {
- fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
- return (-1);
- }
-
- /*
- * FreeBSD has two special kinds of system call redirections --
- * SYS_syscall, and SYS___syscall. The former is the old syscall()
- * routine, basically; the latter is for quad-aligned arguments.
- *
- * The system call argument count and code from ptrace() already
- * account for these, but we need to skip over %rax if it contains
- * either of these values.
- */
- reg = 0;
- switch (regs.r_rax) {
- case SYS_syscall:
- case SYS___syscall:
- reg++;
- break;
- }
-
- for (i = 0; i < narg && reg < 6; i++, reg++) {
- switch (reg) {
- case 0: cs->args[i] = regs.r_rdi; break;
- case 1: cs->args[i] = regs.r_rsi; break;
- case 2: cs->args[i] = regs.r_rdx; break;
- case 3: cs->args[i] = regs.r_rcx; break;
- case 4: cs->args[i] = regs.r_r8; break;
- case 5: cs->args[i] = regs.r_r9; break;
- }
- }
- if (narg > i) {
- iorequest.piod_op = PIOD_READ_D;
- iorequest.piod_offs = (void *)(regs.r_rsp + sizeof(register_t));
- iorequest.piod_addr = &cs->args[i];
- iorequest.piod_len = (narg - i) * sizeof(register_t);
- ptrace(PT_IO, tid, (caddr_t)&iorequest, 0);
- if (iorequest.piod_len == 0)
- return (-1);
- }
-
- return (0);
-}
-
-static int
-amd64_fetch_retval(struct trussinfo *trussinfo, long *retval, int *errorp)
-{
- struct reg regs;
- lwpid_t tid;
-
- tid = trussinfo->curthread->tid;
- if (ptrace(PT_GETREGS, tid, (caddr_t)&regs, 0) < 0) {
- fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
- return (-1);
- }
-
- retval[0] = regs.r_rax;
- retval[1] = regs.r_rdx;
- *errorp = !!(regs.r_rflags & PSL_C);
- return (0);
-}
-
-static struct procabi amd64_fbsd = {
- "FreeBSD ELF64",
- syscallnames,
- nitems(syscallnames),
- amd64_fetch_args,
- amd64_fetch_retval
-};
-
-PROCABI(amd64_fbsd);
Index: head/usr.bin/truss/amd64-fbsd32.c
===================================================================
--- head/usr.bin/truss/amd64-fbsd32.c
+++ head/usr.bin/truss/amd64-fbsd32.c
@@ -1,137 +0,0 @@
-/*
- * Copyright 1997 Sean Eric Fagan
- *
- * 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. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by Sean Eric Fagan
- * 4. Neither the name of the author may be used to endorse or promote
- * products derived from this software without specific prior written
- * permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
- */
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-/* FreeBSD/i386-specific system call handling. */
-
-#include <sys/ptrace.h>
-#include <sys/syscall.h>
-
-#include <machine/reg.h>
-#include <machine/psl.h>
-
-#include <stdio.h>
-#include <stdlib.h>
-
-#include "truss.h"
-
-#include "freebsd32_syscalls.h"
-
-static int
-amd64_fbsd32_fetch_args(struct trussinfo *trussinfo, u_int narg)
-{
- struct ptrace_io_desc iorequest;
- struct reg regs;
- struct current_syscall *cs;
- unsigned int args32[narg];
- unsigned long parm_offset;
- lwpid_t tid;
- u_int i;
-
- tid = trussinfo->curthread->tid;
- cs = &trussinfo->curthread->cs;
- if (ptrace(PT_GETREGS, tid, (caddr_t)&regs, 0) < 0) {
- fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
- return (-1);
- }
- parm_offset = regs.r_rsp + sizeof(int);
-
- /*
- * FreeBSD has two special kinds of system call redirections --
- * SYS_syscall, and SYS___syscall. The former is the old syscall()
- * routine, basically; the latter is for quad-aligned arguments.
- *
- * The system call argument count and code from ptrace() already
- * account for these, but we need to skip over the first argument.
- */
- switch (regs.r_rax) {
- case SYS_syscall:
- parm_offset += sizeof(int);
- break;
- case SYS___syscall:
- parm_offset += sizeof(quad_t);
- break;
- }
-
- iorequest.piod_op = PIOD_READ_D;
- iorequest.piod_offs = (void *)parm_offset;
- iorequest.piod_addr = args32;
- iorequest.piod_len = sizeof(args32);
- ptrace(PT_IO, tid, (caddr_t)&iorequest, 0);
- if (iorequest.piod_len == 0) {
- return (-1);
- }
-
- for (i = 0; i < narg; i++)
- cs->args[i] = args32[i];
- return (0);
-}
-
-static int
-amd64_fbsd32_fetch_retval(struct trussinfo *trussinfo, long *retval,
- int *errorp)
-{
- struct reg regs;
- lwpid_t tid;
-
- tid = trussinfo->curthread->tid;
- if (ptrace(PT_GETREGS, tid, (caddr_t)&regs, 0) < 0) {
- fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
- return (-1);
- }
-
- retval[0] = regs.r_rax & 0xffffffff;
- retval[1] = regs.r_rdx & 0xffffffff;
- *errorp = !!(regs.r_rflags & PSL_C);
- return (0);
-}
-
-static struct procabi amd64_fbsd32 = {
- "FreeBSD ELF32",
- freebsd32_syscallnames,
- nitems(freebsd32_syscallnames),
- amd64_fbsd32_fetch_args,
- amd64_fbsd32_fetch_retval
-};
-
-PROCABI(amd64_fbsd32);
-
-static struct procabi amd64_fbsd32_aout = {
- "FreeBSD a.out",
- freebsd32_syscallnames,
- nitems(freebsd32_syscallnames),
- amd64_fbsd32_fetch_args,
- amd64_fbsd32_fetch_retval
-};
-
-PROCABI(amd64_fbsd32_aout);
Index: head/usr.bin/truss/amd64-freebsd.c
===================================================================
--- head/usr.bin/truss/amd64-freebsd.c
+++ head/usr.bin/truss/amd64-freebsd.c
@@ -0,0 +1,131 @@
+/*
+ * Copyright 1997 Sean Eric Fagan
+ *
+ * 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. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by Sean Eric Fagan
+ * 4. Neither the name of the author may be used to endorse or promote
+ * products derived from this software without specific prior written
+ * permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+/* FreeBSD/amd64-specific system call handling. */
+
+#include <sys/ptrace.h>
+#include <sys/syscall.h>
+
+#include <machine/reg.h>
+#include <machine/psl.h>
+
+#include <stdio.h>
+
+#include "truss.h"
+
+#include "freebsd_syscalls.h"
+
+static int
+amd64_fetch_args(struct trussinfo *trussinfo, u_int narg)
+{
+ struct ptrace_io_desc iorequest;
+ struct reg regs;
+ struct current_syscall *cs;
+ lwpid_t tid;
+ u_int i, reg;
+
+ tid = trussinfo->curthread->tid;
+ cs = &trussinfo->curthread->cs;
+ if (ptrace(PT_GETREGS, tid, (caddr_t)&regs, 0) < 0) {
+ fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
+ return (-1);
+ }
+
+ /*
+ * FreeBSD has two special kinds of system call redirections --
+ * SYS_syscall, and SYS___syscall. The former is the old syscall()
+ * routine, basically; the latter is for quad-aligned arguments.
+ *
+ * The system call argument count and code from ptrace() already
+ * account for these, but we need to skip over %rax if it contains
+ * either of these values.
+ */
+ reg = 0;
+ switch (regs.r_rax) {
+ case SYS_syscall:
+ case SYS___syscall:
+ reg++;
+ break;
+ }
+
+ for (i = 0; i < narg && reg < 6; i++, reg++) {
+ switch (reg) {
+ case 0: cs->args[i] = regs.r_rdi; break;
+ case 1: cs->args[i] = regs.r_rsi; break;
+ case 2: cs->args[i] = regs.r_rdx; break;
+ case 3: cs->args[i] = regs.r_rcx; break;
+ case 4: cs->args[i] = regs.r_r8; break;
+ case 5: cs->args[i] = regs.r_r9; break;
+ }
+ }
+ if (narg > i) {
+ iorequest.piod_op = PIOD_READ_D;
+ iorequest.piod_offs = (void *)(regs.r_rsp + sizeof(register_t));
+ iorequest.piod_addr = &cs->args[i];
+ iorequest.piod_len = (narg - i) * sizeof(register_t);
+ ptrace(PT_IO, tid, (caddr_t)&iorequest, 0);
+ if (iorequest.piod_len == 0)
+ return (-1);
+ }
+
+ return (0);
+}
+
+static int
+amd64_fetch_retval(struct trussinfo *trussinfo, long *retval, int *errorp)
+{
+ struct reg regs;
+ lwpid_t tid;
+
+ tid = trussinfo->curthread->tid;
+ if (ptrace(PT_GETREGS, tid, (caddr_t)&regs, 0) < 0) {
+ fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
+ return (-1);
+ }
+
+ retval[0] = regs.r_rax;
+ retval[1] = regs.r_rdx;
+ *errorp = !!(regs.r_rflags & PSL_C);
+ return (0);
+}
+
+static struct procabi amd64_freebsd = {
+ "FreeBSD ELF64",
+ syscallnames,
+ nitems(syscallnames),
+ amd64_fetch_args,
+ amd64_fetch_retval
+};
+
+PROCABI(amd64_freebsd);
Index: head/usr.bin/truss/amd64-freebsd32.c
===================================================================
--- head/usr.bin/truss/amd64-freebsd32.c
+++ head/usr.bin/truss/amd64-freebsd32.c
@@ -0,0 +1,137 @@
+/*
+ * Copyright 1997 Sean Eric Fagan
+ *
+ * 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. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by Sean Eric Fagan
+ * 4. Neither the name of the author may be used to endorse or promote
+ * products derived from this software without specific prior written
+ * permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+/* FreeBSD/amd64-freebsd32-specific system call handling. */
+
+#include <sys/ptrace.h>
+#include <sys/syscall.h>
+
+#include <machine/reg.h>
+#include <machine/psl.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "truss.h"
+
+#include "freebsd32_syscalls.h"
+
+static int
+amd64_freebsd32_fetch_args(struct trussinfo *trussinfo, u_int narg)
+{
+ struct ptrace_io_desc iorequest;
+ struct reg regs;
+ struct current_syscall *cs;
+ unsigned int args32[narg];
+ unsigned long parm_offset;
+ lwpid_t tid;
+ u_int i;
+
+ tid = trussinfo->curthread->tid;
+ cs = &trussinfo->curthread->cs;
+ if (ptrace(PT_GETREGS, tid, (caddr_t)&regs, 0) < 0) {
+ fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
+ return (-1);
+ }
+ parm_offset = regs.r_rsp + sizeof(int);
+
+ /*
+ * FreeBSD has two special kinds of system call redirections --
+ * SYS_syscall, and SYS___syscall. The former is the old syscall()
+ * routine, basically; the latter is for quad-aligned arguments.
+ *
+ * The system call argument count and code from ptrace() already
+ * account for these, but we need to skip over the first argument.
+ */
+ switch (regs.r_rax) {
+ case SYS_syscall:
+ parm_offset += sizeof(int);
+ break;
+ case SYS___syscall:
+ parm_offset += sizeof(quad_t);
+ break;
+ }
+
+ iorequest.piod_op = PIOD_READ_D;
+ iorequest.piod_offs = (void *)parm_offset;
+ iorequest.piod_addr = args32;
+ iorequest.piod_len = sizeof(args32);
+ ptrace(PT_IO, tid, (caddr_t)&iorequest, 0);
+ if (iorequest.piod_len == 0) {
+ return (-1);
+ }
+
+ for (i = 0; i < narg; i++)
+ cs->args[i] = args32[i];
+ return (0);
+}
+
+static int
+amd64_freebsd32_fetch_retval(struct trussinfo *trussinfo, long *retval,
+ int *errorp)
+{
+ struct reg regs;
+ lwpid_t tid;
+
+ tid = trussinfo->curthread->tid;
+ if (ptrace(PT_GETREGS, tid, (caddr_t)&regs, 0) < 0) {
+ fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
+ return (-1);
+ }
+
+ retval[0] = regs.r_rax & 0xffffffff;
+ retval[1] = regs.r_rdx & 0xffffffff;
+ *errorp = !!(regs.r_rflags & PSL_C);
+ return (0);
+}
+
+static struct procabi amd64_freebsd32 = {
+ "FreeBSD ELF32",
+ syscallnames,
+ nitems(syscallnames),
+ amd64_freebsd32_fetch_args,
+ amd64_freebsd32_fetch_retval
+};
+
+PROCABI(amd64_freebsd32);
+
+static struct procabi amd64_freebsd32_aout = {
+ "FreeBSD a.out",
+ syscallnames,
+ nitems(syscallnames),
+ amd64_freebsd32_fetch_args,
+ amd64_freebsd32_fetch_retval
+};
+
+PROCABI(amd64_freebsd32_aout);
Index: head/usr.bin/truss/amd64-linux32.c
===================================================================
--- head/usr.bin/truss/amd64-linux32.c
+++ head/usr.bin/truss/amd64-linux32.c
@@ -43,7 +43,7 @@
#include "truss.h"
-#include "linux32_syscalls.h"
+#include "amd64-linux32_syscalls.h"
static int
amd64_linux32_fetch_args(struct trussinfo *trussinfo, u_int narg)
@@ -132,8 +132,8 @@
static struct procabi amd64_linux32 = {
"Linux ELF32",
- linux32_syscallnames,
- nitems(linux32_syscallnames),
+ syscallnames,
+ nitems(syscallnames),
amd64_linux32_fetch_args,
amd64_linux32_fetch_retval
};
Index: head/usr.bin/truss/amd64cloudabi64.conf
===================================================================
--- head/usr.bin/truss/amd64cloudabi64.conf
+++ head/usr.bin/truss/amd64cloudabi64.conf
@@ -1,13 +0,0 @@
-# $FreeBSD$
-
-sysnames="cloudabi64_syscalls.h"
-sysproto="/dev/null"
-sysproto_h="/dev/null"
-syshdr="/dev/null"
-sysmk="/dev/null"
-syssw="/dev/null"
-syshide="/dev/null"
-syscallprefix="SYS_"
-switchname="sysent"
-namesname="cloudabi64_syscallnames"
-systrace="/dev/null"
Index: head/usr.bin/truss/amd64linux32.conf
===================================================================
--- head/usr.bin/truss/amd64linux32.conf
+++ head/usr.bin/truss/amd64linux32.conf
@@ -1,13 +0,0 @@
-# $FreeBSD$
-
-sysnames="linux32_syscalls.h"
-sysproto="/dev/null"
-sysproto_h="/dev/null"
-syshdr="/dev/null"
-sysmk="/dev/null"
-syssw="/dev/null"
-syshide="/dev/null"
-syscallprefix="SYS_"
-switchname="sysent"
-namesname="linux32_syscallnames"
-systrace="/dev/null"
Index: head/usr.bin/truss/arm-fbsd.c
===================================================================
--- head/usr.bin/truss/arm-fbsd.c
+++ head/usr.bin/truss/arm-fbsd.c
@@ -1,138 +0,0 @@
-/*
- * Copyright 1997 Sean Eric Fagan
- *
- * 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. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by Sean Eric Fagan
- * 4. Neither the name of the author may be used to endorse or promote
- * products derived from this software without specific prior written
- * permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
- */
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-/* FreeBSD/arm-specific system call handling. */
-
-#include <sys/ptrace.h>
-#include <sys/syscall.h>
-
-#include <machine/reg.h>
-#include <machine/armreg.h>
-#include <machine/ucontext.h>
-
-#include <stdio.h>
-
-#include "truss.h"
-
-#include "syscalls.h"
-
-static int
-arm_fetch_args(struct trussinfo *trussinfo, u_int narg)
-{
- struct ptrace_io_desc iorequest;
- struct reg regs;
- struct current_syscall *cs;
- lwpid_t tid;
- u_int i, reg, syscall_num;
-
- tid = trussinfo->curthread->tid;
- cs = &trussinfo->curthread->cs;
- if (ptrace(PT_GETREGS, tid, (caddr_t)&regs, 0) < 0) {
- fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
- return (-1);
- }
-
- /*
- * FreeBSD has two special kinds of system call redirections --
- * SYS_syscall, and SYS___syscall. The former is the old syscall()
- * routine, basically; the latter is for quad-aligned arguments.
- *
- * The system call argument count and code from ptrace() already
- * account for these, but we need to skip over the first argument.
- */
-#ifdef __ARM_EABI__
- syscall_num = regs.r[7];
-#else
- if ((syscall_num = ptrace(PT_READ_I, tid,
- (caddr_t)(regs.r[_REG_PC] - INSN_SIZE), 0)) == -1) {
- fprintf(trussinfo->outfile, "-- CANNOT READ PC --\n");
- return (-1);
- }
- syscall_num = syscall_num & 0x000fffff;
-#endif
-
- reg = 0;
- switch (syscall_num) {
- case SYS_syscall:
- reg = 1;
- break;
- case SYS___syscall:
- reg = 2;
- break;
- }
-
- for (i = 0; i < narg && reg < 4; i++, reg++)
- cs->args[i] = regs.r[reg];
- if (narg > i) {
- iorequest.piod_op = PIOD_READ_D;
- iorequest.piod_offs = (void *)(regs.r_sp +
- 4 * sizeof(uint32_t));
- iorequest.piod_addr = &cs->args[i];
- iorequest.piod_len = (narg - i) * sizeof(cs->args[0]);
- ptrace(PT_IO, tid, (caddr_t)&iorequest, 0);
- if (iorequest.piod_len == 0)
- return (-1);
- }
-
- return (0);
-}
-
-static int
-arm_fetch_retval(struct trussinfo *trussinfo, long *retval, int *errorp)
-{
- struct reg regs;
- lwpid_t tid;
-
- tid = trussinfo->curthread->tid;
- if (ptrace(PT_GETREGS, tid, (caddr_t)&regs, 0) < 0) {
- fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
- return (-1);
- }
-
- /* XXX: Does not have the __ARMEB__ handling for __syscall(). */
- retval[0] = regs.r[0];
- retval[1] = regs.r[1];
- *errorp = !!(regs.r_cpsr & PSR_C);
- return (0);
-}
-
-static struct procabi arm_fbsd = {
- "FreeBSD ELF32",
- syscallnames,
- nitems(syscallnames),
- arm_fetch_args,
- arm_fetch_retval
-};
-
-PROCABI(arm_fbsd);
Index: head/usr.bin/truss/arm-freebsd.c
===================================================================
--- head/usr.bin/truss/arm-freebsd.c
+++ head/usr.bin/truss/arm-freebsd.c
@@ -0,0 +1,138 @@
+/*
+ * Copyright 1997 Sean Eric Fagan
+ *
+ * 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. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by Sean Eric Fagan
+ * 4. Neither the name of the author may be used to endorse or promote
+ * products derived from this software without specific prior written
+ * permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+/* FreeBSD/arm-specific system call handling. */
+
+#include <sys/ptrace.h>
+#include <sys/syscall.h>
+
+#include <machine/reg.h>
+#include <machine/armreg.h>
+#include <machine/ucontext.h>
+
+#include <stdio.h>
+
+#include "truss.h"
+
+#include "freebsd_syscalls.h"
+
+static int
+arm_fetch_args(struct trussinfo *trussinfo, u_int narg)
+{
+ struct ptrace_io_desc iorequest;
+ struct reg regs;
+ struct current_syscall *cs;
+ lwpid_t tid;
+ u_int i, reg, syscall_num;
+
+ tid = trussinfo->curthread->tid;
+ cs = &trussinfo->curthread->cs;
+ if (ptrace(PT_GETREGS, tid, (caddr_t)&regs, 0) < 0) {
+ fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
+ return (-1);
+ }
+
+ /*
+ * FreeBSD has two special kinds of system call redirections --
+ * SYS_syscall, and SYS___syscall. The former is the old syscall()
+ * routine, basically; the latter is for quad-aligned arguments.
+ *
+ * The system call argument count and code from ptrace() already
+ * account for these, but we need to skip over the first argument.
+ */
+#ifdef __ARM_EABI__
+ syscall_num = regs.r[7];
+#else
+ if ((syscall_num = ptrace(PT_READ_I, tid,
+ (caddr_t)(regs.r[_REG_PC] - INSN_SIZE), 0)) == -1) {
+ fprintf(trussinfo->outfile, "-- CANNOT READ PC --\n");
+ return (-1);
+ }
+ syscall_num = syscall_num & 0x000fffff;
+#endif
+
+ reg = 0;
+ switch (syscall_num) {
+ case SYS_syscall:
+ reg = 1;
+ break;
+ case SYS___syscall:
+ reg = 2;
+ break;
+ }
+
+ for (i = 0; i < narg && reg < 4; i++, reg++)
+ cs->args[i] = regs.r[reg];
+ if (narg > i) {
+ iorequest.piod_op = PIOD_READ_D;
+ iorequest.piod_offs = (void *)(regs.r_sp +
+ 4 * sizeof(uint32_t));
+ iorequest.piod_addr = &cs->args[i];
+ iorequest.piod_len = (narg - i) * sizeof(cs->args[0]);
+ ptrace(PT_IO, tid, (caddr_t)&iorequest, 0);
+ if (iorequest.piod_len == 0)
+ return (-1);
+ }
+
+ return (0);
+}
+
+static int
+arm_fetch_retval(struct trussinfo *trussinfo, long *retval, int *errorp)
+{
+ struct reg regs;
+ lwpid_t tid;
+
+ tid = trussinfo->curthread->tid;
+ if (ptrace(PT_GETREGS, tid, (caddr_t)&regs, 0) < 0) {
+ fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
+ return (-1);
+ }
+
+ /* XXX: Does not have the __ARMEB__ handling for __syscall(). */
+ retval[0] = regs.r[0];
+ retval[1] = regs.r[1];
+ *errorp = !!(regs.r_cpsr & PSR_C);
+ return (0);
+}
+
+static struct procabi arm_freebsd = {
+ "FreeBSD ELF32",
+ syscallnames,
+ nitems(syscallnames),
+ arm_fetch_args,
+ arm_fetch_retval
+};
+
+PROCABI(arm_freebsd);
Index: head/usr.bin/truss/fbsd32.conf
===================================================================
--- head/usr.bin/truss/fbsd32.conf
+++ head/usr.bin/truss/fbsd32.conf
@@ -1,13 +0,0 @@
-# $FreeBSD$
-
-sysnames="freebsd32_syscalls.h"
-sysproto="/dev/null"
-sysproto_h="/dev/null"
-syshdr="/dev/null"
-sysmk="/dev/null"
-syssw="/dev/null"
-syshide="/dev/null"
-syscallprefix="SYS_"
-switchname="sysent"
-namesname="freebsd32_syscallnames"
-systrace="/dev/null"
Index: head/usr.bin/truss/i386-fbsd.c
===================================================================
--- head/usr.bin/truss/i386-fbsd.c
+++ head/usr.bin/truss/i386-fbsd.c
@@ -1,131 +0,0 @@
-/*
- * Copyright 1997 Sean Eric Fagan
- *
- * 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. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by Sean Eric Fagan
- * 4. Neither the name of the author may be used to endorse or promote
- * products derived from this software without specific prior written
- * permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
- */
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-/* FreeBSD/i386-specific system call handling. */
-
-#include <sys/ptrace.h>
-#include <sys/syscall.h>
-
-#include <machine/reg.h>
-#include <machine/psl.h>
-
-#include <stdio.h>
-
-#include "truss.h"
-
-#include "syscalls.h"
-
-static int
-i386_fetch_args(struct trussinfo *trussinfo, u_int narg)
-{
- struct ptrace_io_desc iorequest;
- struct reg regs;
- struct current_syscall *cs;
- lwpid_t tid;
- unsigned int parm_offset;
-
- tid = trussinfo->curthread->tid;
- cs = &trussinfo->curthread->cs;
- if (ptrace(PT_GETREGS, tid, (caddr_t)&regs, 0) < 0) {
- fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
- return (-1);
- }
- parm_offset = regs.r_esp + sizeof(int);
-
- /*
- * FreeBSD has two special kinds of system call redirections --
- * SYS_syscall, and SYS___syscall. The former is the old syscall()
- * routine, basically; the latter is for quad-aligned arguments.
- *
- * The system call argument count and code from ptrace() already
- * account for these, but we need to skip over the first argument.
- */
- switch (regs.r_eax) {
- case SYS_syscall:
- parm_offset += sizeof(int);
- break;
- case SYS___syscall:
- parm_offset += sizeof(quad_t);
- break;
- }
-
- iorequest.piod_op = PIOD_READ_D;
- iorequest.piod_offs = (void *)parm_offset;
- iorequest.piod_addr = cs->args;
- iorequest.piod_len = narg * sizeof(unsigned long);
- ptrace(PT_IO, tid, (caddr_t)&iorequest, 0);
- if (iorequest.piod_len == 0)
- return (-1);
-
- return (0);
-}
-
-static int
-i386_fetch_retval(struct trussinfo *trussinfo, long *retval, int *errorp)
-{
- struct reg regs;
- lwpid_t tid;
-
- tid = trussinfo->curthread->tid;
- if (ptrace(PT_GETREGS, tid, (caddr_t)&regs, 0) < 0) {
- fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
- return (-1);
- }
-
- retval[0] = regs.r_eax;
- retval[1] = regs.r_edx;
- *errorp = !!(regs.r_eflags & PSL_C);
- return (0);
-}
-
-static struct procabi i386_fbsd = {
- "FreeBSD ELF32",
- syscallnames,
- nitems(syscallnames),
- i386_fetch_args,
- i386_fetch_retval
-};
-
-PROCABI(i386_fbsd);
-
-static struct procabi i386_fbsd_aout = {
- "FreeBSD a.out",
- syscallnames,
- nitems(syscallnames),
- i386_fetch_args,
- i386_fetch_retval
-};
-
-PROCABI(i386_fbsd_aout);
-
Index: head/usr.bin/truss/i386-freebsd.c
===================================================================
--- head/usr.bin/truss/i386-freebsd.c
+++ head/usr.bin/truss/i386-freebsd.c
@@ -0,0 +1,131 @@
+/*
+ * Copyright 1997 Sean Eric Fagan
+ *
+ * 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. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by Sean Eric Fagan
+ * 4. Neither the name of the author may be used to endorse or promote
+ * products derived from this software without specific prior written
+ * permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+/* FreeBSD/i386-specific system call handling. */
+
+#include <sys/ptrace.h>
+#include <sys/syscall.h>
+
+#include <machine/reg.h>
+#include <machine/psl.h>
+
+#include <stdio.h>
+
+#include "truss.h"
+
+#include "freebsd_syscalls.h"
+
+static int
+i386_fetch_args(struct trussinfo *trussinfo, u_int narg)
+{
+ struct ptrace_io_desc iorequest;
+ struct reg regs;
+ struct current_syscall *cs;
+ lwpid_t tid;
+ unsigned int parm_offset;
+
+ tid = trussinfo->curthread->tid;
+ cs = &trussinfo->curthread->cs;
+ if (ptrace(PT_GETREGS, tid, (caddr_t)&regs, 0) < 0) {
+ fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
+ return (-1);
+ }
+ parm_offset = regs.r_esp + sizeof(int);
+
+ /*
+ * FreeBSD has two special kinds of system call redirections --
+ * SYS_syscall, and SYS___syscall. The former is the old syscall()
+ * routine, basically; the latter is for quad-aligned arguments.
+ *
+ * The system call argument count and code from ptrace() already
+ * account for these, but we need to skip over the first argument.
+ */
+ switch (regs.r_eax) {
+ case SYS_syscall:
+ parm_offset += sizeof(int);
+ break;
+ case SYS___syscall:
+ parm_offset += sizeof(quad_t);
+ break;
+ }
+
+ iorequest.piod_op = PIOD_READ_D;
+ iorequest.piod_offs = (void *)parm_offset;
+ iorequest.piod_addr = cs->args;
+ iorequest.piod_len = narg * sizeof(unsigned long);
+ ptrace(PT_IO, tid, (caddr_t)&iorequest, 0);
+ if (iorequest.piod_len == 0)
+ return (-1);
+
+ return (0);
+}
+
+static int
+i386_fetch_retval(struct trussinfo *trussinfo, long *retval, int *errorp)
+{
+ struct reg regs;
+ lwpid_t tid;
+
+ tid = trussinfo->curthread->tid;
+ if (ptrace(PT_GETREGS, tid, (caddr_t)&regs, 0) < 0) {
+ fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
+ return (-1);
+ }
+
+ retval[0] = regs.r_eax;
+ retval[1] = regs.r_edx;
+ *errorp = !!(regs.r_eflags & PSL_C);
+ return (0);
+}
+
+static struct procabi i386_freebsd = {
+ "FreeBSD ELF32",
+ syscallnames,
+ nitems(syscallnames),
+ i386_fetch_args,
+ i386_fetch_retval
+};
+
+PROCABI(i386_freebsd);
+
+static struct procabi i386_freebsd_aout = {
+ "FreeBSD a.out",
+ syscallnames,
+ nitems(syscallnames),
+ i386_fetch_args,
+ i386_fetch_retval
+};
+
+PROCABI(i386_freebsd_aout);
+
Index: head/usr.bin/truss/i386-linux.c
===================================================================
--- head/usr.bin/truss/i386-linux.c
+++ head/usr.bin/truss/i386-linux.c
@@ -43,7 +43,7 @@
#include "truss.h"
-#include "linux_syscalls.h"
+#include "i386-linux_syscalls.h"
static int
i386_linux_fetch_args(struct trussinfo *trussinfo, u_int narg)
@@ -131,8 +131,8 @@
static struct procabi i386_linux = {
"Linux ELF32",
- linux_syscallnames,
- nitems(linux_syscallnames),
+ syscallnames,
+ nitems(syscallnames),
i386_linux_fetch_args,
i386_linux_fetch_retval
};
Index: head/usr.bin/truss/i386.conf
===================================================================
--- head/usr.bin/truss/i386.conf
+++ head/usr.bin/truss/i386.conf
@@ -1,13 +0,0 @@
-# $FreeBSD$
-
-sysnames="syscalls.h"
-sysproto="/dev/null"
-sysproto_h="/dev/null"
-syshdr="/dev/null"
-sysmk="/dev/null"
-syssw="/dev/null"
-syshide="/dev/null"
-syscallprefix="SYS_"
-switchname="sysent"
-namesname="syscallnames"
-systrace="/dev/null"
Index: head/usr.bin/truss/i386linux.conf
===================================================================
--- head/usr.bin/truss/i386linux.conf
+++ head/usr.bin/truss/i386linux.conf
@@ -1,13 +0,0 @@
-# $FreeBSD$
-
-sysnames="linux_syscalls.h"
-sysproto="/dev/null"
-sysproto_h="/dev/null"
-syshdr="/dev/null"
-sysmk="/dev/null"
-syssw="/dev/null"
-syshide="/dev/null"
-syscallprefix="SYS_"
-switchname="sysent"
-namesname="linux_syscallnames"
-systrace="/dev/null"
Index: head/usr.bin/truss/makesyscallsconf.sh
===================================================================
--- head/usr.bin/truss/makesyscallsconf.sh
+++ head/usr.bin/truss/makesyscallsconf.sh
@@ -0,0 +1,21 @@
+#! /bin/sh
+# $FreeBSD$
+
+ABI="$1"
+CONF="$2"
+
+header="${ABI}_syscalls.h"
+
+cat > "${CONF}" << EOF
+sysnames="${header}.tmp"
+sysproto="/dev/null"
+sysproto_h="/dev/null"
+syshdr="/dev/null"
+sysmk="/dev/null"
+syssw="/dev/null"
+syshide="/dev/null"
+syscallprefix="SYS_"
+switchname="sysent"
+namesname="syscallnames"
+systrace="/dev/null"
+EOF
Index: head/usr.bin/truss/mips-fbsd.c
===================================================================
--- head/usr.bin/truss/mips-fbsd.c
+++ head/usr.bin/truss/mips-fbsd.c
@@ -1,141 +0,0 @@
-/*
- * Copyright 1998 Sean Eric Fagan
- *
- * 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. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by Sean Eric Fagan
- * 4. Neither the name of the author may be used to endorse or promote
- * products derived from this software without specific prior written
- * permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
- */
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-/* FreeBSD/mips-specific system call handling. */
-
-#include <sys/ptrace.h>
-#include <sys/syscall.h>
-
-#include <machine/frame.h>
-#include <machine/reg.h>
-
-#include <stdio.h>
-
-#include "truss.h"
-
-#include "syscalls.h"
-
-static int
-mips_fetch_args(struct trussinfo *trussinfo, u_int narg)
-{
- struct ptrace_io_desc iorequest;
- struct reg regs;
- struct current_syscall *cs;
- lwpid_t tid;
- u_int i, reg;
-
- tid = trussinfo->curthread->tid;
- cs = &trussinfo->curthread->cs;
- if (ptrace(PT_GETREGS, tid, (caddr_t)&regs, 0) < 0) {
- fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
- return (-1);
- }
-
- /*
- * FreeBSD has two special kinds of system call redirections --
- * SYS_syscall, and SYS___syscall. The former is the old syscall()
- * routine, basically; the latter is for quad-aligned arguments.
- *
- * The system call argument count and code from ptrace() already
- * account for these, but we need to skip over the first argument.
- */
- reg = A0;
- switch (regs.r_regs[V0]) {
- case SYS_syscall:
- reg = A1;
- break;
- case SYS___syscall:
-#if defined(__mips_n32) || defined(__mips_n64)
- reg = A1;
-#else
- reg = A2;
-#endif
- break;
- }
-
-#if defined(__mips_n32) || defined(__mips_n64)
-#define MAXREG A7
-#else
-#define MAXREG A3
-#endif
-
- for (i = 0; i < narg && reg <= MAXREG; i++, reg++)
- cs->args[i] = regs.r_regs[reg];
- if (narg > i) {
- iorequest.piod_op = PIOD_READ_D;
- iorequest.piod_offs = (void *)((uintptr_t)regs.r_regs[SP] +
- 4 * sizeof(cs->args[0]));
- iorequest.piod_addr = &cs->args[i];
- iorequest.piod_len = (narg - i) * sizeof(cs->args[0]);
- ptrace(PT_IO, tid, (caddr_t)&iorequest, 0);
- if (iorequest.piod_len == 0)
- return (-1);
- }
-
- return (0);
-}
-
-static int
-mips_fetch_retval(struct trussinfo *trussinfo, long *retval, int *errorp)
-{
- struct reg regs;
- lwpid_t tid;
-
- tid = trussinfo->curthread->tid;
- if (ptrace(PT_GETREGS, tid, (caddr_t)&regs, 0) < 0) {
- fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
- return (-1);
- }
-
- /* XXX: Does not have special handling for __syscall(). */
- retval[0] = regs.r_regs[V0];
- retval[1] = regs.r_regs[V1];
- *errorp = !!regs.r_regs[A3];
- return (0);
-}
-
-
-static struct procabi mips_fbsd = {
-#ifdef __mips_n64
- "FreeBSD ELF64",
-#else
- "FreeBSD ELF32",
-#endif
- syscallnames,
- nitems(syscallnames),
- mips_fetch_args,
- mips_fetch_retval
-};
-
-PROCABI(mips_fbsd);
Index: head/usr.bin/truss/mips-freebsd.c
===================================================================
--- head/usr.bin/truss/mips-freebsd.c
+++ head/usr.bin/truss/mips-freebsd.c
@@ -0,0 +1,141 @@
+/*
+ * Copyright 1998 Sean Eric Fagan
+ *
+ * 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. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by Sean Eric Fagan
+ * 4. Neither the name of the author may be used to endorse or promote
+ * products derived from this software without specific prior written
+ * permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+/* FreeBSD/mips-specific system call handling. */
+
+#include <sys/ptrace.h>
+#include <sys/syscall.h>
+
+#include <machine/frame.h>
+#include <machine/reg.h>
+
+#include <stdio.h>
+
+#include "truss.h"
+
+#include "freebsd_syscalls.h"
+
+static int
+mips_fetch_args(struct trussinfo *trussinfo, u_int narg)
+{
+ struct ptrace_io_desc iorequest;
+ struct reg regs;
+ struct current_syscall *cs;
+ lwpid_t tid;
+ u_int i, reg;
+
+ tid = trussinfo->curthread->tid;
+ cs = &trussinfo->curthread->cs;
+ if (ptrace(PT_GETREGS, tid, (caddr_t)&regs, 0) < 0) {
+ fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
+ return (-1);
+ }
+
+ /*
+ * FreeBSD has two special kinds of system call redirections --
+ * SYS_syscall, and SYS___syscall. The former is the old syscall()
+ * routine, basically; the latter is for quad-aligned arguments.
+ *
+ * The system call argument count and code from ptrace() already
+ * account for these, but we need to skip over the first argument.
+ */
+ reg = A0;
+ switch (regs.r_regs[V0]) {
+ case SYS_syscall:
+ reg = A1;
+ break;
+ case SYS___syscall:
+#if defined(__mips_n32) || defined(__mips_n64)
+ reg = A1;
+#else
+ reg = A2;
+#endif
+ break;
+ }
+
+#if defined(__mips_n32) || defined(__mips_n64)
+#define MAXREG A7
+#else
+#define MAXREG A3
+#endif
+
+ for (i = 0; i < narg && reg <= MAXREG; i++, reg++)
+ cs->args[i] = regs.r_regs[reg];
+ if (narg > i) {
+ iorequest.piod_op = PIOD_READ_D;
+ iorequest.piod_offs = (void *)((uintptr_t)regs.r_regs[SP] +
+ 4 * sizeof(cs->args[0]));
+ iorequest.piod_addr = &cs->args[i];
+ iorequest.piod_len = (narg - i) * sizeof(cs->args[0]);
+ ptrace(PT_IO, tid, (caddr_t)&iorequest, 0);
+ if (iorequest.piod_len == 0)
+ return (-1);
+ }
+
+ return (0);
+}
+
+static int
+mips_fetch_retval(struct trussinfo *trussinfo, long *retval, int *errorp)
+{
+ struct reg regs;
+ lwpid_t tid;
+
+ tid = trussinfo->curthread->tid;
+ if (ptrace(PT_GETREGS, tid, (caddr_t)&regs, 0) < 0) {
+ fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
+ return (-1);
+ }
+
+ /* XXX: Does not have special handling for __syscall(). */
+ retval[0] = regs.r_regs[V0];
+ retval[1] = regs.r_regs[V1];
+ *errorp = !!regs.r_regs[A3];
+ return (0);
+}
+
+
+static struct procabi mips_freebsd = {
+#ifdef __mips_n64
+ "FreeBSD ELF64",
+#else
+ "FreeBSD ELF32",
+#endif
+ syscallnames,
+ nitems(syscallnames),
+ mips_fetch_args,
+ mips_fetch_retval
+};
+
+PROCABI(mips_freebsd);
Index: head/usr.bin/truss/powerpc-fbsd.c
===================================================================
--- head/usr.bin/truss/powerpc-fbsd.c
+++ head/usr.bin/truss/powerpc-fbsd.c
@@ -1,150 +0,0 @@
-/*
- * Copyright 2006 Peter Grehan <grehan@freebsd.org>
- * Copyright 2005 Orlando Bassotto <orlando@break.net>
- * Copyright 1998 Sean Eric Fagan
- *
- * 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.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
- */
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-/* FreeBSD/powerpc-specific system call handling. */
-
-#include <sys/ptrace.h>
-#include <sys/syscall.h>
-
-#include <machine/reg.h>
-#include <machine/frame.h>
-
-#include <stdio.h>
-
-#include "truss.h"
-
-#ifdef __powerpc64__ /* 32-bit compatibility */
-#include "freebsd32_syscalls.h"
-#define syscallnames freebsd32_syscallnames
-#else /* native 32-bit */
-#include "syscalls.h"
-#endif
-
-static int
-powerpc_fetch_args(struct trussinfo *trussinfo, u_int narg)
-{
- struct ptrace_io_desc iorequest;
- struct reg regs;
- struct current_syscall *cs;
- lwpid_t tid;
- u_int i, reg;
-
- tid = trussinfo->curthread->tid;
- cs = &trussinfo->curthread->cs;
- if (ptrace(PT_GETREGS, tid, (caddr_t)&regs, 0) < 0) {
- fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
- return (-1);
- }
-
- /*
- * FreeBSD has two special kinds of system call redirections --
- * SYS_syscall, and SYS___syscall. The former is the old syscall()
- * routine, basically; the latter is for quad-aligned arguments.
- *
- * The system call argument count and code from ptrace() already
- * account for these, but we need to skip over the first argument.
- */
- reg = 0;
- switch (regs.fixreg[0]) {
- case SYS_syscall:
- reg += 1;
- break;
- case SYS___syscall:
- reg += 2;
- break;
- }
-
- for (i = 0; i < narg && reg < NARGREG; i++, reg++) {
-#ifdef __powerpc64__
- cs->args[i] = regs.fixreg[FIRSTARG + reg] & 0xffffffff;
-#else
- cs->args[i] = regs.fixreg[FIRSTARG + reg];
-#endif
- }
- if (narg > i) {
-#ifdef __powerpc64__
- uint32_t args32[narg - i];
- u_int j;
-
-#endif
- iorequest.piod_op = PIOD_READ_D;
- iorequest.piod_offs = (void *)(regs.fixreg[1] + 8);
-#ifdef __powerpc64__
- iorequest.piod_addr = args32;
- iorequest.piod_len = sizeof(args32);
-#else
- iorequest.piod_addr = &cs->args[i];
- iorequest.piod_len = (narg - i) * sizeof(cs->args[0]);
-#endif
- ptrace(PT_IO, tid, (caddr_t)&iorequest, 0);
- if (iorequest.piod_len == 0)
- return (-1);
-#ifdef __powerpc64__
- for (j = 0; j < narg - i; j++)
- cs->args[i + j] = args32[j];
-#endif
- }
-
- return (0);
-}
-
-static int
-powerpc_fetch_retval(struct trussinfo *trussinfo, long *retval, int *errorp)
-{
- struct reg regs;
- lwpid_t tid;
-
- tid = trussinfo->curthread->tid;
- if (ptrace(PT_GETREGS, tid, (caddr_t)&regs, 0) < 0) {
- fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
- return (-1);
- }
-
- /* XXX: Does not have fixup for __syscall(). */
-#ifdef __powerpc64__
- retval[0] = regs.fixreg[3] & 0xffffffff;
- retval[1] = regs.fixreg[4] & 0xffffffff;
-#else
- retval[0] = regs.fixreg[3];
- retval[1] = regs.fixreg[4];
-#endif
- *errorp = !!(regs.cr & 0x10000000);
- return (0);
-}
-
-static struct procabi powerpc_fbsd = {
- "FreeBSD ELF32",
- syscallnames,
- nitems(syscallnames),
- powerpc_fetch_args,
- powerpc_fetch_retval
-};
-
-PROCABI(powerpc_fbsd);
Index: head/usr.bin/truss/powerpc-freebsd.c
===================================================================
--- head/usr.bin/truss/powerpc-freebsd.c
+++ head/usr.bin/truss/powerpc-freebsd.c
@@ -0,0 +1,122 @@
+/*
+ * Copyright 2006 Peter Grehan <grehan@freebsd.org>
+ * Copyright 2005 Orlando Bassotto <orlando@break.net>
+ * Copyright 1998 Sean Eric Fagan
+ *
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+/* FreeBSD/powerpc-specific system call handling. */
+
+#include <sys/ptrace.h>
+#include <sys/syscall.h>
+
+#include <machine/reg.h>
+#include <machine/frame.h>
+
+#include <stdio.h>
+
+#include "truss.h"
+
+#include "freebsd_syscalls.h"
+
+static int
+powerpc_fetch_args(struct trussinfo *trussinfo, u_int narg)
+{
+ struct ptrace_io_desc iorequest;
+ struct reg regs;
+ struct current_syscall *cs;
+ lwpid_t tid;
+ u_int i, reg;
+
+ tid = trussinfo->curthread->tid;
+ cs = &trussinfo->curthread->cs;
+ if (ptrace(PT_GETREGS, tid, (caddr_t)&regs, 0) < 0) {
+ fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
+ return (-1);
+ }
+
+ /*
+ * FreeBSD has two special kinds of system call redirections --
+ * SYS_syscall, and SYS___syscall. The former is the old syscall()
+ * routine, basically; the latter is for quad-aligned arguments.
+ *
+ * The system call argument count and code from ptrace() already
+ * account for these, but we need to skip over the first argument.
+ */
+ reg = 0;
+ switch (regs.fixreg[0]) {
+ case SYS_syscall:
+ reg += 1;
+ break;
+ case SYS___syscall:
+ reg += 2;
+ break;
+ }
+
+ for (i = 0; i < narg && reg < NARGREG; i++, reg++) {
+ cs->args[i] = regs.fixreg[FIRSTARG + reg];
+ }
+ if (narg > i) {
+ iorequest.piod_op = PIOD_READ_D;
+ iorequest.piod_offs = (void *)(regs.fixreg[1] + 8);
+ iorequest.piod_addr = &cs->args[i];
+ iorequest.piod_len = (narg - i) * sizeof(cs->args[0]);
+ ptrace(PT_IO, tid, (caddr_t)&iorequest, 0);
+ if (iorequest.piod_len == 0)
+ return (-1);
+ }
+
+ return (0);
+}
+
+static int
+powerpc_fetch_retval(struct trussinfo *trussinfo, long *retval, int *errorp)
+{
+ struct reg regs;
+ lwpid_t tid;
+
+ tid = trussinfo->curthread->tid;
+ if (ptrace(PT_GETREGS, tid, (caddr_t)&regs, 0) < 0) {
+ fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
+ return (-1);
+ }
+
+ /* XXX: Does not have fixup for __syscall(). */
+ retval[0] = regs.fixreg[3];
+ retval[1] = regs.fixreg[4];
+ *errorp = !!(regs.cr & 0x10000000);
+ return (0);
+}
+
+static struct procabi powerpc_freebsd = {
+ "FreeBSD ELF32",
+ syscallnames,
+ nitems(syscallnames),
+ powerpc_fetch_args,
+ powerpc_fetch_retval
+};
+
+PROCABI(powerpc_freebsd);
Index: head/usr.bin/truss/powerpc64-fbsd.c
===================================================================
--- head/usr.bin/truss/powerpc64-fbsd.c
+++ head/usr.bin/truss/powerpc64-fbsd.c
@@ -1,118 +0,0 @@
-/*
- * Copyright 2006 Peter Grehan <grehan@freebsd.org>
- * Copyright 2005 Orlando Bassotto <orlando@break.net>
- * Copyright 1998 Sean Eric Fagan
- *
- * 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.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
- */
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-/* FreeBSD/powerpc64-specific system call handling. */
-
-#include <sys/ptrace.h>
-#include <sys/syscall.h>
-
-#include <machine/reg.h>
-#include <machine/frame.h>
-
-#include <stdio.h>
-
-#include "truss.h"
-
-#include "syscalls.h"
-
-static int
-powerpc64_fetch_args(struct trussinfo *trussinfo, u_int narg)
-{
- struct ptrace_io_desc iorequest;
- struct reg regs;
- struct current_syscall *cs;
- lwpid_t tid;
- u_int i, reg;
-
- tid = trussinfo->curthread->tid;
- cs = &trussinfo->curthread->cs;
- if (ptrace(PT_GETREGS, tid, (caddr_t)&regs, 0) < 0) {
- fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
- return (-1);
- }
-
- /*
- * FreeBSD has two special kinds of system call redirections --
- * SYS_syscall, and SYS___syscall. The former is the old syscall()
- * routine, basically; the latter is for quad-aligned arguments.
- *
- * The system call argument count and code from ptrace() already
- * account for these, but we need to skip over the first argument.
- */
- reg = 0;
- switch (regs.fixreg[0]) {
- case SYS_syscall:
- case SYS___syscall:
- reg += 1;
- break;
- }
-
- for (i = 0; i < narg && reg < NARGREG; i++, reg++)
- cs->args[i] = regs.fixreg[FIRSTARG + reg];
- if (narg > i) {
- iorequest.piod_op = PIOD_READ_D;
- iorequest.piod_offs = (void *)(regs.fixreg[1] + 48);
- iorequest.piod_addr = &cs->args[i];
- iorequest.piod_len = (narg - i) * sizeof(cs->args[0]);
- ptrace(PT_IO, tid, (caddr_t)&iorequest, 0);
- if (iorequest.piod_len == 0)
- return (-1);
- }
-
- return (0);
-}
-
-static int
-powerpc64_fetch_retval(struct trussinfo *trussinfo, long *retval, int *errorp)
-{
- struct reg regs;
- lwpid_t tid;
-
- tid = trussinfo->curthread->tid;
- if (ptrace(PT_GETREGS, tid, (caddr_t)&regs, 0) < 0) {
- fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
- return (-1);
- }
-
- retval[0] = regs.fixreg[3];
- retval[1] = regs.fixreg[4];
- *errorp = !!(regs.cr & 0x10000000);
- return (0);
-}
-
-static struct procabi powerpc64_fbsd = {
- "FreeBSD ELF64",
- syscallnames,
- nitems(syscallnames),
- powerpc64_fetch_args,
- powerpc64_fetch_retval
-};
-
-PROCABI(powerpc64_fbsd);
Index: head/usr.bin/truss/powerpc64-freebsd.c
===================================================================
--- head/usr.bin/truss/powerpc64-freebsd.c
+++ head/usr.bin/truss/powerpc64-freebsd.c
@@ -0,0 +1,118 @@
+/*
+ * Copyright 2006 Peter Grehan <grehan@freebsd.org>
+ * Copyright 2005 Orlando Bassotto <orlando@break.net>
+ * Copyright 1998 Sean Eric Fagan
+ *
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+/* FreeBSD/powerpc64-specific system call handling. */
+
+#include <sys/ptrace.h>
+#include <sys/syscall.h>
+
+#include <machine/reg.h>
+#include <machine/frame.h>
+
+#include <stdio.h>
+
+#include "truss.h"
+
+#include "freebsd_syscalls.h"
+
+static int
+powerpc64_fetch_args(struct trussinfo *trussinfo, u_int narg)
+{
+ struct ptrace_io_desc iorequest;
+ struct reg regs;
+ struct current_syscall *cs;
+ lwpid_t tid;
+ u_int i, reg;
+
+ tid = trussinfo->curthread->tid;
+ cs = &trussinfo->curthread->cs;
+ if (ptrace(PT_GETREGS, tid, (caddr_t)&regs, 0) < 0) {
+ fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
+ return (-1);
+ }
+
+ /*
+ * FreeBSD has two special kinds of system call redirections --
+ * SYS_syscall, and SYS___syscall. The former is the old syscall()
+ * routine, basically; the latter is for quad-aligned arguments.
+ *
+ * The system call argument count and code from ptrace() already
+ * account for these, but we need to skip over the first argument.
+ */
+ reg = 0;
+ switch (regs.fixreg[0]) {
+ case SYS_syscall:
+ case SYS___syscall:
+ reg += 1;
+ break;
+ }
+
+ for (i = 0; i < narg && reg < NARGREG; i++, reg++)
+ cs->args[i] = regs.fixreg[FIRSTARG + reg];
+ if (narg > i) {
+ iorequest.piod_op = PIOD_READ_D;
+ iorequest.piod_offs = (void *)(regs.fixreg[1] + 48);
+ iorequest.piod_addr = &cs->args[i];
+ iorequest.piod_len = (narg - i) * sizeof(cs->args[0]);
+ ptrace(PT_IO, tid, (caddr_t)&iorequest, 0);
+ if (iorequest.piod_len == 0)
+ return (-1);
+ }
+
+ return (0);
+}
+
+static int
+powerpc64_fetch_retval(struct trussinfo *trussinfo, long *retval, int *errorp)
+{
+ struct reg regs;
+ lwpid_t tid;
+
+ tid = trussinfo->curthread->tid;
+ if (ptrace(PT_GETREGS, tid, (caddr_t)&regs, 0) < 0) {
+ fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
+ return (-1);
+ }
+
+ retval[0] = regs.fixreg[3];
+ retval[1] = regs.fixreg[4];
+ *errorp = !!(regs.cr & 0x10000000);
+ return (0);
+}
+
+static struct procabi powerpc64_freebsd = {
+ "FreeBSD ELF64",
+ syscallnames,
+ nitems(syscallnames),
+ powerpc64_fetch_args,
+ powerpc64_fetch_retval
+};
+
+PROCABI(powerpc64_freebsd);
Index: head/usr.bin/truss/powerpc64-freebsd32.c
===================================================================
--- head/usr.bin/truss/powerpc64-freebsd32.c
+++ head/usr.bin/truss/powerpc64-freebsd32.c
@@ -0,0 +1,127 @@
+/*
+ * Copyright 2006 Peter Grehan <grehan@freebsd.org>
+ * Copyright 2005 Orlando Bassotto <orlando@break.net>
+ * Copyright 1998 Sean Eric Fagan
+ *
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+/* FreeBSD/powerpc64-freebsd32-specific system call handling. */
+
+#include <sys/ptrace.h>
+#include <sys/syscall.h>
+
+#include <machine/reg.h>
+#include <machine/frame.h>
+
+#include <stdio.h>
+
+#include "truss.h"
+
+#include "freebsd32_syscalls.h"
+
+static int
+powerpc64_freebsd32_fetch_args(struct trussinfo *trussinfo, u_int narg)
+{
+ struct ptrace_io_desc iorequest;
+ struct reg regs;
+ struct current_syscall *cs;
+ lwpid_t tid;
+ u_int i, reg;
+
+ tid = trussinfo->curthread->tid;
+ cs = &trussinfo->curthread->cs;
+ if (ptrace(PT_GETREGS, tid, (caddr_t)&regs, 0) < 0) {
+ fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
+ return (-1);
+ }
+
+ /*
+ * FreeBSD has two special kinds of system call redirections --
+ * SYS_syscall, and SYS___syscall. The former is the old syscall()
+ * routine, basically; the latter is for quad-aligned arguments.
+ *
+ * The system call argument count and code from ptrace() already
+ * account for these, but we need to skip over the first argument.
+ */
+ reg = 0;
+ switch (regs.fixreg[0]) {
+ case SYS_syscall:
+ reg += 1;
+ break;
+ case SYS___syscall:
+ reg += 2;
+ break;
+ }
+
+ for (i = 0; i < narg && reg < NARGREG; i++, reg++) {
+ cs->args[i] = regs.fixreg[FIRSTARG + reg] & 0xffffffff;
+ }
+ if (narg > i) {
+ uint32_t args32[narg - i];
+ u_int j;
+
+ iorequest.piod_op = PIOD_READ_D;
+ iorequest.piod_offs = (void *)(regs.fixreg[1] + 8);
+ iorequest.piod_addr = args32;
+ iorequest.piod_len = sizeof(args32);
+ ptrace(PT_IO, tid, (caddr_t)&iorequest, 0);
+ if (iorequest.piod_len == 0)
+ return (-1);
+ for (j = 0; j < narg - i; j++)
+ cs->args[i + j] = args32[j];
+ }
+
+ return (0);
+}
+
+static int
+powerpc64_freebsd32_fetch_retval(struct trussinfo *trussinfo, long *retval, int *errorp)
+{
+ struct reg regs;
+ lwpid_t tid;
+
+ tid = trussinfo->curthread->tid;
+ if (ptrace(PT_GETREGS, tid, (caddr_t)&regs, 0) < 0) {
+ fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
+ return (-1);
+ }
+
+ /* XXX: Does not have fixup for __syscall(). */
+ retval[0] = regs.fixreg[3] & 0xffffffff;
+ retval[1] = regs.fixreg[4] & 0xffffffff;
+ *errorp = !!(regs.cr & 0x10000000);
+ return (0);
+}
+
+static struct procabi powerpc64_freebsd32 = {
+ "FreeBSD ELF32",
+ syscallnames,
+ nitems(syscallnames),
+ powerpc64_freebsd32_fetch_args,
+ powerpc64_freebsd32_fetch_retval
+};
+
+PROCABI(powerpc64_freebsd32);
Index: head/usr.bin/truss/sparc64-fbsd.c
===================================================================
--- head/usr.bin/truss/sparc64-fbsd.c
+++ head/usr.bin/truss/sparc64-fbsd.c
@@ -1,125 +0,0 @@
-/*
- * Copyright 1998 Sean Eric Fagan
- *
- * 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. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by Sean Eric Fagan
- * 4. Neither the name of the author may be used to endorse or promote
- * products derived from this software without specific prior written
- * permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
- */
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-/* FreeBSD/sparc64-specific system call handling. */
-
-#include <sys/ptrace.h>
-#include <sys/syscall.h>
-
-#include <machine/frame.h>
-#include <machine/reg.h>
-#include <machine/tstate.h>
-
-#include <stddef.h>
-#include <stdio.h>
-
-#include "truss.h"
-
-#include "syscalls.h"
-
-static int
-sparc64_fetch_args(struct trussinfo *trussinfo, u_int narg)
-{
- struct ptrace_io_desc iorequest;
- struct reg regs;
- struct current_syscall *cs;
- lwpid_t tid;
- u_int i, reg;
-
- tid = trussinfo->curthread->tid;
- cs = &trussinfo->curthread->cs;
- if (ptrace(PT_GETREGS, tid, (caddr_t)&regs, 0) < 0) {
- fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
- return (-1);
- }
-
- /*
- * FreeBSD has two special kinds of system call redirections --
- * SYS_syscall, and SYS___syscall. The former is the old syscall()
- * routine, basically; the latter is for quad-aligned arguments.
- *
- * The system call argument count and code from ptrace() already
- * account for these, but we need to skip over the first argument.
- */
- reg = 0;
- switch (regs.r_global[1]) {
- case SYS_syscall:
- case SYS___syscall:
- reg = 1;
- break;
- }
-
- for (i = 0; i < narg && reg < 6; i++, reg++)
- cs->args[i] = regs.r_out[reg];
- if (narg > i) {
- iorequest.piod_op = PIOD_READ_D;
- iorequest.piod_offs = (void *)(regs.r_out[6] + SPOFF +
- offsetof(struct frame, fr_pad[6]));
- iorequest.piod_addr = &cs->args[i];
- iorequest.piod_len = (narg - i) * sizeof(cs->args[0]);
- ptrace(PT_IO, tid, (caddr_t)&iorequest, 0);
- if (iorequest.piod_len == 0)
- return (-1);
- }
-
- return (0);
-}
-
-static int
-sparc64_fetch_retval(struct trussinfo *trussinfo, long *retval, int *errorp)
-{
- struct reg regs;
- lwpid_t tid;
-
- tid = trussinfo->curthread->tid;
- if (ptrace(PT_GETREGS, tid, (caddr_t)&regs, 0) < 0) {
- fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
- return (-1);
- }
-
- retval[0] = regs.r_out[0];
- retval[1] = regs.r_out[1];
- *errorp = !!(regs.r_tstate & TSTATE_XCC_C);
- return (0);
-}
-
-static struct procabi sparc64_fbsd = {
- "FreeBSD ELF64",
- syscallnames,
- nitems(syscallnames),
- sparc64_fetch_args,
- sparc64_fetch_retval
-};
-
-PROCABI(sparc64_fbsd);
Index: head/usr.bin/truss/sparc64-freebsd.c
===================================================================
--- head/usr.bin/truss/sparc64-freebsd.c
+++ head/usr.bin/truss/sparc64-freebsd.c
@@ -0,0 +1,125 @@
+/*
+ * Copyright 1998 Sean Eric Fagan
+ *
+ * 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. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by Sean Eric Fagan
+ * 4. Neither the name of the author may be used to endorse or promote
+ * products derived from this software without specific prior written
+ * permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+/* FreeBSD/sparc64-specific system call handling. */
+
+#include <sys/ptrace.h>
+#include <sys/syscall.h>
+
+#include <machine/frame.h>
+#include <machine/reg.h>
+#include <machine/tstate.h>
+
+#include <stddef.h>
+#include <stdio.h>
+
+#include "truss.h"
+
+#include "freebsd_syscalls.h"
+
+static int
+sparc64_fetch_args(struct trussinfo *trussinfo, u_int narg)
+{
+ struct ptrace_io_desc iorequest;
+ struct reg regs;
+ struct current_syscall *cs;
+ lwpid_t tid;
+ u_int i, reg;
+
+ tid = trussinfo->curthread->tid;
+ cs = &trussinfo->curthread->cs;
+ if (ptrace(PT_GETREGS, tid, (caddr_t)&regs, 0) < 0) {
+ fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
+ return (-1);
+ }
+
+ /*
+ * FreeBSD has two special kinds of system call redirections --
+ * SYS_syscall, and SYS___syscall. The former is the old syscall()
+ * routine, basically; the latter is for quad-aligned arguments.
+ *
+ * The system call argument count and code from ptrace() already
+ * account for these, but we need to skip over the first argument.
+ */
+ reg = 0;
+ switch (regs.r_global[1]) {
+ case SYS_syscall:
+ case SYS___syscall:
+ reg = 1;
+ break;
+ }
+
+ for (i = 0; i < narg && reg < 6; i++, reg++)
+ cs->args[i] = regs.r_out[reg];
+ if (narg > i) {
+ iorequest.piod_op = PIOD_READ_D;
+ iorequest.piod_offs = (void *)(regs.r_out[6] + SPOFF +
+ offsetof(struct frame, fr_pad[6]));
+ iorequest.piod_addr = &cs->args[i];
+ iorequest.piod_len = (narg - i) * sizeof(cs->args[0]);
+ ptrace(PT_IO, tid, (caddr_t)&iorequest, 0);
+ if (iorequest.piod_len == 0)
+ return (-1);
+ }
+
+ return (0);
+}
+
+static int
+sparc64_fetch_retval(struct trussinfo *trussinfo, long *retval, int *errorp)
+{
+ struct reg regs;
+ lwpid_t tid;
+
+ tid = trussinfo->curthread->tid;
+ if (ptrace(PT_GETREGS, tid, (caddr_t)&regs, 0) < 0) {
+ fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
+ return (-1);
+ }
+
+ retval[0] = regs.r_out[0];
+ retval[1] = regs.r_out[1];
+ *errorp = !!(regs.r_tstate & TSTATE_XCC_C);
+ return (0);
+}
+
+static struct procabi sparc64_freebsd = {
+ "FreeBSD ELF64",
+ syscallnames,
+ nitems(syscallnames),
+ sparc64_fetch_args,
+ sparc64_fetch_retval
+};
+
+PROCABI(sparc64_freebsd);

File Metadata

Mime Type
text/plain
Expires
Sat, Jan 18, 1:26 PM (59 m, 23 s)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
15861582
Default Alt Text
D3851.diff (87 KB)

Event Timeline