Page MenuHomeFreeBSD

D20963.diff
No OneTemporary

D20963.diff

Index: head/usr.bin/truss/Makefile
===================================================================
--- head/usr.bin/truss/Makefile
+++ head/usr.bin/truss/Makefile
@@ -9,38 +9,4 @@
#CFLAGS+= -I${.CURDIR} -I. -I${SRCTOP}/sys
CFLAGS+= -I${SRCTOP}/sys
-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_ARCH} == "aarch64"
-ABIS+= cloudabi32
-ABIS+= cloudabi64
-.endif
-.if ${MACHINE_CPUARCH} == "i386"
-ABIS+= i386-linux
-ABIS+= cloudabi32
-.endif
-.if ${MACHINE_CPUARCH} == "amd64"
-ABIS+= amd64-linux
-ABIS+= amd64-linux32
-ABIS+= freebsd32
-ABIS+= cloudabi32
-ABIS+= cloudabi64
-.endif
-.if ${MACHINE_ARCH} == "powerpc64"
-ABIS+= freebsd32
-.endif
-
-.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}
-.endfor
-
.include <bsd.prog.mk>
Index: head/usr.bin/truss/aarch64-cloudabi32.c
===================================================================
--- head/usr.bin/truss/aarch64-cloudabi32.c
+++ head/usr.bin/truss/aarch64-cloudabi32.c
@@ -1,112 +0,0 @@
-/*-
- * Copyright (c) 2015-2017 Nuxi, https://nuxi.nl/
- *
- * 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$");
-
-#include <sys/param.h>
-#include <sys/ptrace.h>
-
-#include <machine/armreg.h>
-
-#include <stdbool.h>
-#include <stdio.h>
-#include <sysdecode.h>
-
-#include "truss.h"
-
-static int
-aarch64_cloudabi32_fetch_args(struct trussinfo *trussinfo, unsigned int narg)
-{
- struct current_syscall *cs;
- struct ptrace_io_desc iorequest;
- struct reg regs;
- lwpid_t tid;
-
- if (narg > 0) {
- /* Fetch registers, containing the address of the arguments. */
- tid = trussinfo->curthread->tid;
- if (ptrace(PT_GETREGS, tid, (caddr_t)&regs, 0) == -1) {
- fprintf(trussinfo->outfile,
- "-- CANNOT READ REGISTERS --\n");
- return (-1);
- }
-
- /* Fetch arguments. They are already padded to 64 bits. */
- cs = &trussinfo->curthread->cs;
- iorequest.piod_op = PIOD_READ_D;
- iorequest.piod_offs = (void *)regs.x[2];
- iorequest.piod_addr = cs->args;
- iorequest.piod_len = sizeof(cs->args[0]) * narg;
- if (ptrace(PT_IO, tid, (caddr_t)&iorequest, 0) == -1 ||
- iorequest.piod_len == 0)
- return (-1);
- }
- return (0);
-}
-
-static int
-aarch64_cloudabi32_fetch_retval(struct trussinfo *trussinfo, long *retval,
- int *errorp)
-{
- struct ptrace_io_desc iorequest;
- struct reg regs;
- lwpid_t tid;
-
- /* Fetch registers, containing the address of the return values. */
- tid = trussinfo->curthread->tid;
- if (ptrace(PT_GETREGS, tid, (caddr_t)&regs, 0) == -1) {
- fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
- return (-1);
- }
-
- if ((regs.spsr & PSR_C) == 0) {
- /* System call succeeded. Fetch return values. */
- iorequest.piod_op = PIOD_READ_D;
- iorequest.piod_offs = (void *)regs.x[2];
- iorequest.piod_addr = retval;
- iorequest.piod_len = sizeof(retval[0]) * 2;
- if (ptrace(PT_IO, tid, (caddr_t)&iorequest, 0) == -1 ||
- iorequest.piod_len == 0)
- return (-1);
- *errorp = 0;
- } else {
- /* System call failed. Set error. */
- retval[0] = regs.x[0];
- *errorp = 1;
- }
- return (0);
-}
-
-static struct procabi aarch64_cloudabi32 = {
- "CloudABI ELF32",
- SYSDECODE_ABI_CLOUDABI32,
- aarch64_cloudabi32_fetch_args,
- aarch64_cloudabi32_fetch_retval,
- STAILQ_HEAD_INITIALIZER(aarch64_cloudabi32.extra_syscalls),
- { NULL }
-};
-
-PROCABI(aarch64_cloudabi32);
Index: head/usr.bin/truss/aarch64-cloudabi64.c
===================================================================
--- head/usr.bin/truss/aarch64-cloudabi64.c
+++ head/usr.bin/truss/aarch64-cloudabi64.c
@@ -1,88 +0,0 @@
-/*-
- * Copyright (c) 2015 Nuxi, https://nuxi.nl/
- *
- * 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$");
-
-#include <sys/param.h>
-#include <sys/ptrace.h>
-
-#include <machine/armreg.h>
-
-#include <stdbool.h>
-#include <stdio.h>
-#include <sysdecode.h>
-
-#include "truss.h"
-
-static int
-aarch64_cloudabi64_fetch_args(struct trussinfo *trussinfo, unsigned int narg)
-{
- struct current_syscall *cs;
- struct reg regs;
- lwpid_t tid;
- unsigned int i;
-
- tid = trussinfo->curthread->tid;
- if (ptrace(PT_GETREGS, tid, (caddr_t)&regs, 0) == -1) {
- fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
- return (-1);
- }
-
- cs = &trussinfo->curthread->cs;
- for (i = 0; i < narg && i < 8; i++)
- cs->args[i] = regs.x[i];
- return (0);
-}
-
-static int
-aarch64_cloudabi64_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) == -1) {
- fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
- return (-1);
- }
-
- retval[0] = regs.x[0];
- retval[1] = regs.x[1];
- *errorp = (regs.spsr & PSR_C) != 0;
- return (0);
-}
-
-static struct procabi aarch64_cloudabi64 = {
- "CloudABI ELF64",
- SYSDECODE_ABI_CLOUDABI64,
- aarch64_cloudabi64_fetch_args,
- aarch64_cloudabi64_fetch_retval,
- STAILQ_HEAD_INITIALIZER(aarch64_cloudabi64.extra_syscalls),
- { NULL }
-};
-
-PROCABI(aarch64_cloudabi64);
Index: head/usr.bin/truss/aarch64-freebsd.c
===================================================================
--- head/usr.bin/truss/aarch64-freebsd.c
+++ head/usr.bin/truss/aarch64-freebsd.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 <stdbool.h>
-#include <stdio.h>
-#include <sysdecode.h>
-
-#include "truss.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",
- SYSDECODE_ABI_FREEBSD,
- aarch64_fetch_args,
- aarch64_fetch_retval,
- STAILQ_HEAD_INITIALIZER(aarch64_freebsd.extra_syscalls),
- { NULL }
-};
-
-PROCABI(aarch64_freebsd);
Index: head/usr.bin/truss/amd64-cloudabi32.c
===================================================================
--- head/usr.bin/truss/amd64-cloudabi32.c
+++ head/usr.bin/truss/amd64-cloudabi32.c
@@ -1,112 +0,0 @@
-/*-
- * Copyright (c) 2015-2017 Nuxi, https://nuxi.nl/
- *
- * 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$");
-
-#include <sys/param.h>
-#include <sys/ptrace.h>
-
-#include <machine/psl.h>
-
-#include <stdbool.h>
-#include <stdio.h>
-#include <sysdecode.h>
-
-#include "truss.h"
-
-static int
-amd64_cloudabi32_fetch_args(struct trussinfo *trussinfo, unsigned int narg)
-{
- struct current_syscall *cs;
- struct ptrace_io_desc iorequest;
- struct reg regs;
- lwpid_t tid;
-
- if (narg > 0) {
- /* Fetch registers, containing the address of the arguments. */
- tid = trussinfo->curthread->tid;
- if (ptrace(PT_GETREGS, tid, (caddr_t)&regs, 0) == -1) {
- fprintf(trussinfo->outfile,
- "-- CANNOT READ REGISTERS --\n");
- return (-1);
- }
-
- /* Fetch arguments. They are already padded to 64 bits. */
- cs = &trussinfo->curthread->cs;
- iorequest.piod_op = PIOD_READ_D;
- iorequest.piod_offs = (void *)regs.r_rcx;
- iorequest.piod_addr = cs->args;
- iorequest.piod_len = sizeof(cs->args[0]) * narg;
- if (ptrace(PT_IO, tid, (caddr_t)&iorequest, 0) == -1 ||
- iorequest.piod_len == 0)
- return (-1);
- }
- return (0);
-}
-
-static int
-amd64_cloudabi32_fetch_retval(struct trussinfo *trussinfo, long *retval,
- int *errorp)
-{
- struct ptrace_io_desc iorequest;
- struct reg regs;
- lwpid_t tid;
-
- /* Fetch registers, containing the address of the return values. */
- tid = trussinfo->curthread->tid;
- if (ptrace(PT_GETREGS, tid, (caddr_t)&regs, 0) == -1) {
- fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
- return (-1);
- }
-
- if (regs.r_rax == 0) {
- /* System call succeeded. Fetch return values. */
- iorequest.piod_op = PIOD_READ_D;
- iorequest.piod_offs = (void *)regs.r_rcx;
- iorequest.piod_addr = retval;
- iorequest.piod_len = sizeof(retval[0]) * 2;
- if (ptrace(PT_IO, tid, (caddr_t)&iorequest, 0) == -1 ||
- iorequest.piod_len == 0)
- return (-1);
- *errorp = 0;
- } else {
- /* System call failed. Set error. */
- retval[0] = regs.r_rax;
- *errorp = 1;
- }
- return (0);
-}
-
-static struct procabi amd64_cloudabi32 = {
- "CloudABI ELF32",
- SYSDECODE_ABI_CLOUDABI32,
- amd64_cloudabi32_fetch_args,
- amd64_cloudabi32_fetch_retval,
- STAILQ_HEAD_INITIALIZER(amd64_cloudabi32.extra_syscalls),
- { NULL }
-};
-
-PROCABI(amd64_cloudabi32);
Index: head/usr.bin/truss/amd64-cloudabi64.c
===================================================================
--- head/usr.bin/truss/amd64-cloudabi64.c
+++ head/usr.bin/truss/amd64-cloudabi64.c
@@ -1,97 +0,0 @@
-/*-
- * Copyright (c) 2015 Nuxi, https://nuxi.nl/
- *
- * 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$");
-
-#include <sys/param.h>
-#include <sys/ptrace.h>
-
-#include <machine/psl.h>
-
-#include <stdbool.h>
-#include <stdio.h>
-#include <sysdecode.h>
-
-#include "truss.h"
-
-static int
-amd64_cloudabi64_fetch_args(struct trussinfo *trussinfo, unsigned int narg)
-{
- struct current_syscall *cs;
- struct reg regs;
- lwpid_t tid;
-
- tid = trussinfo->curthread->tid;
- if (ptrace(PT_GETREGS, tid, (caddr_t)&regs, 0) == -1) {
- fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
- return (-1);
- }
-
- cs = &trussinfo->curthread->cs;
- if (narg >= 1)
- cs->args[0] = regs.r_rdi;
- if (narg >= 2)
- cs->args[1] = regs.r_rsi;
- if (narg >= 3)
- cs->args[2] = regs.r_rdx;
- if (narg >= 4)
- cs->args[3] = regs.r_rcx;
- if (narg >= 5)
- cs->args[4] = regs.r_r8;
- if (narg >= 6)
- cs->args[5] = regs.r_r9;
- return (0);
-}
-
-static int
-amd64_cloudabi64_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) == -1) {
- 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) != 0;
- return (0);
-}
-
-static struct procabi amd64_cloudabi64 = {
- "CloudABI ELF64",
- SYSDECODE_ABI_CLOUDABI64,
- amd64_cloudabi64_fetch_args,
- amd64_cloudabi64_fetch_retval,
- STAILQ_HEAD_INITIALIZER(amd64_cloudabi64.extra_syscalls),
- { NULL }
-};
-
-PROCABI(amd64_cloudabi64);
Index: head/usr.bin/truss/amd64-freebsd.c
===================================================================
--- head/usr.bin/truss/amd64-freebsd.c
+++ head/usr.bin/truss/amd64-freebsd.c
@@ -1,134 +0,0 @@
-/*-
- * SPDX-License-Identifier: BSD-4-Clause
- *
- * 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 <stdbool.h>
-#include <stdio.h>
-#include <sysdecode.h>
-
-#include "truss.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",
- SYSDECODE_ABI_FREEBSD,
- amd64_fetch_args,
- amd64_fetch_retval,
- STAILQ_HEAD_INITIALIZER(amd64_freebsd.extra_syscalls),
- { NULL }
-};
-
-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
@@ -1,141 +0,0 @@
-/*-
- * SPDX-License-Identifier: BSD-4-Clause
- *
- * 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 <stdbool.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <sysdecode.h>
-
-#include "truss.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",
- SYSDECODE_ABI_FREEBSD32,
- amd64_freebsd32_fetch_args,
- amd64_freebsd32_fetch_retval,
- STAILQ_HEAD_INITIALIZER(amd64_freebsd32.extra_syscalls),
- { NULL }
-};
-
-PROCABI(amd64_freebsd32);
-
-static struct procabi amd64_freebsd32_aout = {
- "FreeBSD a.out",
- SYSDECODE_ABI_FREEBSD32,
- amd64_freebsd32_fetch_args,
- amd64_freebsd32_fetch_retval,
- STAILQ_HEAD_INITIALIZER(amd64_freebsd32.extra_syscalls),
- { NULL }
-};
-
-PROCABI(amd64_freebsd32_aout);
Index: head/usr.bin/truss/amd64-linux.c
===================================================================
--- head/usr.bin/truss/amd64-linux.c
+++ head/usr.bin/truss/amd64-linux.c
@@ -1,109 +0,0 @@
-/*-
- * SPDX-License-Identifier: BSD-4-Clause
- *
- * 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$");
-
-/* Linux/x86_64-specific system call handling. */
-
-#include <sys/ptrace.h>
-
-#include <machine/reg.h>
-#include <machine/psl.h>
-
-#include <stdbool.h>
-#include <stdio.h>
-#include <sysdecode.h>
-
-#include "truss.h"
-
-static int
-amd64_linux_fetch_args(struct trussinfo *trussinfo, u_int narg)
-{
- struct reg regs;
- struct current_syscall *cs;
- lwpid_t tid;
-
- 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);
- }
-
- switch (narg) {
- default:
- cs->args[5] = regs.r_r9;
- case 5:
- cs->args[4] = regs.r_r8;
- case 4:
- cs->args[3] = regs.r_rcx;
- case 3:
- cs->args[2] = regs.r_rdx;
- case 2:
- cs->args[1] = regs.r_rsi;
- case 1:
- cs->args[0] = regs.r_rdi;
- }
-
- return (0);
-}
-
-static int
-amd64_linux_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_linux = {
- "Linux ELF64",
- SYSDECODE_ABI_LINUX,
- amd64_linux_fetch_args,
- amd64_linux_fetch_retval,
- STAILQ_HEAD_INITIALIZER(amd64_linux.extra_syscalls),
- { NULL }
-};
-
-PROCABI(amd64_linux);
Index: head/usr.bin/truss/amd64-linux32.c
===================================================================
--- head/usr.bin/truss/amd64-linux32.c
+++ head/usr.bin/truss/amd64-linux32.c
@@ -1,119 +0,0 @@
-/*-
- * SPDX-License-Identifier: BSD-4-Clause
- *
- * 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$");
-
-/* Linux/i386-specific system call handling. */
-
-#include <sys/ptrace.h>
-
-#include <machine/reg.h>
-#include <machine/psl.h>
-
-#include <stdbool.h>
-#include <stdio.h>
-#include <sysdecode.h>
-
-#include "truss.h"
-
-static int
-amd64_linux32_fetch_args(struct trussinfo *trussinfo, u_int narg)
-{
- struct reg regs;
- struct current_syscall *cs;
- lwpid_t tid;
-
- 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);
- }
-
- /*
- * Linux passes syscall arguments in registers, not
- * on the stack. Fortunately, we've got access to the
- * register set. Note that we don't bother checking the
- * number of arguments. And what does linux do for syscalls
- * that have more than five arguments?
- */
- switch (narg) {
- default:
- cs->args[5] = regs.r_rbp; /* Unconfirmed */
- case 5:
- cs->args[4] = regs.r_rdi;
- case 4:
- cs->args[3] = regs.r_rsi;
- case 3:
- cs->args[2] = regs.r_rdx;
- case 2:
- cs->args[1] = regs.r_rcx;
- case 1:
- cs->args[0] = regs.r_rbx;
- }
-
- return (0);
-}
-
-static int
-amd64_linux32_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);
- if (*errorp)
- retval[0] = (int)retval[0];
- return (0);
-}
-
-static struct procabi amd64_linux32 = {
- "Linux ELF32",
- SYSDECODE_ABI_LINUX32,
- amd64_linux32_fetch_args,
- amd64_linux32_fetch_retval,
- STAILQ_HEAD_INITIALIZER(amd64_linux32.extra_syscalls),
- { NULL }
-};
-
-PROCABI(amd64_linux32);
Index: head/usr.bin/truss/arm-freebsd.c
===================================================================
--- head/usr.bin/truss/arm-freebsd.c
+++ head/usr.bin/truss/arm-freebsd.c
@@ -1,141 +0,0 @@
-/*-
- * SPDX-License-Identifier: BSD-4-Clause
- *
- * 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 <stdbool.h>
-#include <stdio.h>
-#include <sysdecode.h>
-
-#include "truss.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",
- SYSDECODE_ABI_FREEBSD,
- arm_fetch_args,
- arm_fetch_retval,
- STAILQ_HEAD_INITIALIZER(arm_freebsd.extra_syscalls),
- { NULL }
-};
-
-PROCABI(arm_freebsd);
Index: head/usr.bin/truss/i386-cloudabi32.c
===================================================================
--- head/usr.bin/truss/i386-cloudabi32.c
+++ head/usr.bin/truss/i386-cloudabi32.c
@@ -1,98 +0,0 @@
-/*-
- * Copyright (c) 2015-2017 Nuxi, https://nuxi.nl/
- *
- * 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$");
-
-#include <sys/param.h>
-#include <sys/ptrace.h>
-
-#include <machine/psl.h>
-
-#include <stdbool.h>
-#include <stdio.h>
-#include <sysdecode.h>
-
-#include "truss.h"
-
-static int
-i386_cloudabi32_fetch_args(struct trussinfo *trussinfo, unsigned int narg)
-{
- struct current_syscall *cs;
- struct ptrace_io_desc iorequest;
- struct reg regs;
- lwpid_t tid;
-
- if (narg > 0) {
- /* Fetch registers, containing the stack pointer. */
- tid = trussinfo->curthread->tid;
- if (ptrace(PT_GETREGS, tid, (caddr_t)&regs, 0) == -1) {
- fprintf(trussinfo->outfile,
- "-- CANNOT READ REGISTERS --\n");
- return (-1);
- }
-
- /* Fetch arguments. */
- cs = &trussinfo->curthread->cs;
- iorequest.piod_op = PIOD_READ_D;
- iorequest.piod_offs = (void **)regs.r_esp + 1;
- iorequest.piod_addr = cs->args;
- iorequest.piod_len = sizeof(cs->args[0]) * narg;
- if (ptrace(PT_IO, tid, (caddr_t)&iorequest, 0) == -1 ||
- iorequest.piod_len == 0)
- return (-1);
- }
- return (0);
-}
-
-static int
-i386_cloudabi32_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) == -1) {
- 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) != 0;
- return (0);
-}
-
-static struct procabi i386_cloudabi32 = {
- "CloudABI ELF32",
- SYSDECODE_ABI_CLOUDABI32,
- i386_cloudabi32_fetch_args,
- i386_cloudabi32_fetch_retval,
- STAILQ_HEAD_INITIALIZER(i386_cloudabi32.extra_syscalls),
- { NULL }
-};
-
-PROCABI(i386_cloudabi32);
Index: head/usr.bin/truss/i386-freebsd.c
===================================================================
--- head/usr.bin/truss/i386-freebsd.c
+++ head/usr.bin/truss/i386-freebsd.c
@@ -1,135 +0,0 @@
-/*-
- * SPDX-License-Identifier: BSD-4-Clause
- *
- * 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 <stdbool.h>
-#include <stdio.h>
-#include <sysdecode.h>
-
-#include "truss.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",
- SYSDECODE_ABI_FREEBSD,
- i386_fetch_args,
- i386_fetch_retval,
- STAILQ_HEAD_INITIALIZER(i386_freebsd.extra_syscalls),
- { NULL }
-};
-
-PROCABI(i386_freebsd);
-
-static struct procabi i386_freebsd_aout = {
- "FreeBSD a.out",
- SYSDECODE_ABI_FREEBSD,
- i386_fetch_args,
- i386_fetch_retval,
- STAILQ_HEAD_INITIALIZER(i386_freebsd_aout.extra_syscalls),
- { NULL }
-};
-
-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
@@ -1,116 +0,0 @@
-/*-
- * SPDX-License-Identifier: BSD-4-Clause
- *
- * 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$");
-
-/* Linux/i386-specific system call handling. */
-
-#include <sys/ptrace.h>
-
-#include <machine/reg.h>
-#include <machine/psl.h>
-
-#include <stdbool.h>
-#include <stdio.h>
-#include <sysdecode.h>
-
-#include "truss.h"
-
-static int
-i386_linux_fetch_args(struct trussinfo *trussinfo, u_int narg)
-{
- struct reg regs;
- struct current_syscall *cs;
- lwpid_t tid;
-
- 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);
- }
-
- /*
- * Linux passes syscall arguments in registers, not
- * on the stack. Fortunately, we've got access to the
- * register set. Note that we don't bother checking the
- * number of arguments. And what does linux do for syscalls
- * that have more than five arguments?
- */
- switch (narg) {
- default:
- cs->args[5] = regs.r_ebp; /* Unconfirmed */
- case 5:
- cs->args[4] = regs.r_edi;
- case 4:
- cs->args[3] = regs.r_esi;
- case 3:
- cs->args[2] = regs.r_edx;
- case 2:
- cs->args[1] = regs.r_ecx;
- case 1:
- cs->args[0] = regs.r_ebx;
- }
-
- return (0);
-}
-
-static int
-i386_linux_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_linux = {
- "Linux ELF",
- SYSDECODE_ABI_LINUX,
- i386_linux_fetch_args,
- i386_linux_fetch_retval,
- STAILQ_HEAD_INITIALIZER(i386_linux.extra_syscalls),
- { NULL }
-};
-
-PROCABI(i386_linux);
Index: head/usr.bin/truss/mips-freebsd.c
===================================================================
--- head/usr.bin/truss/mips-freebsd.c
+++ head/usr.bin/truss/mips-freebsd.c
@@ -1,144 +0,0 @@
-/*-
- * SPDX-License-Identifier: BSD-4-Clause
- *
- * 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 <stdbool.h>
-#include <stdio.h>
-#include <sysdecode.h>
-
-#include "truss.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
- SYSDECODE_ABI_FREEBSD,
- mips_fetch_args,
- mips_fetch_retval,
- STAILQ_HEAD_INITIALIZER(mips_freebsd.extra_syscalls),
- { NULL }
-};
-
-PROCABI(mips_freebsd);
Index: head/usr.bin/truss/powerpc-freebsd.c
===================================================================
--- head/usr.bin/truss/powerpc-freebsd.c
+++ head/usr.bin/truss/powerpc-freebsd.c
@@ -1,123 +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 <stdbool.h>
-#include <stdio.h>
-#include <sysdecode.h>
-
-#include "truss.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",
- SYSDECODE_ABI_FREEBSD,
- powerpc_fetch_args,
- powerpc_fetch_retval,
- STAILQ_HEAD_INITIALIZER(powerpc_freebsd.extra_syscalls),
- { NULL }
-};
-
-PROCABI(powerpc_freebsd);
Index: head/usr.bin/truss/powerpc64-freebsd.c
===================================================================
--- head/usr.bin/truss/powerpc64-freebsd.c
+++ head/usr.bin/truss/powerpc64-freebsd.c
@@ -1,130 +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 <stdbool.h>
-#include <stdio.h>
-#include <sysdecode.h>
-
-#include "truss.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",
- SYSDECODE_ABI_FREEBSD,
- powerpc64_fetch_args,
- powerpc64_fetch_retval,
- STAILQ_HEAD_INITIALIZER(powerpc64_freebsd.extra_syscalls),
- { NULL }
-};
-
-PROCABI(powerpc64_freebsd);
-
-static struct procabi powerpc64_freebsd_elfv2 = {
- "FreeBSD ELF64 V2",
- SYSDECODE_ABI_FREEBSD,
- powerpc64_fetch_args,
- powerpc64_fetch_retval,
- STAILQ_HEAD_INITIALIZER(powerpc64_freebsd_elfv2.extra_syscalls),
- { NULL }
-};
-
-PROCABI(powerpc64_freebsd_elfv2);
Index: head/usr.bin/truss/powerpc64-freebsd32.c
===================================================================
--- head/usr.bin/truss/powerpc64-freebsd32.c
+++ head/usr.bin/truss/powerpc64-freebsd32.c
@@ -1,128 +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-freebsd32-specific system call handling. */
-
-#include <sys/ptrace.h>
-#include <sys/syscall.h>
-
-#include <machine/reg.h>
-#include <machine/frame.h>
-
-#include <stdbool.h>
-#include <stdio.h>
-#include <sysdecode.h>
-
-#include "truss.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",
- SYSDECODE_ABI_FREEBSD32,
- powerpc64_freebsd32_fetch_args,
- powerpc64_freebsd32_fetch_retval,
- STAILQ_HEAD_INITIALIZER(powerpc64_freebsd32.extra_syscalls),
- { NULL }
-};
-
-PROCABI(powerpc64_freebsd32);
Index: head/usr.bin/truss/riscv-freebsd.c
===================================================================
--- head/usr.bin/truss/riscv-freebsd.c
+++ head/usr.bin/truss/riscv-freebsd.c
@@ -1,106 +0,0 @@
-/*-
- * Copyright 2017 Li-Wen Hsu <lwhsu@FreeBSD.org>
- *
- * 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/riscv-specific system call handling. */
-
-#include <sys/ptrace.h>
-#include <sys/syscall.h>
-
-#include <machine/frame.h>
-#include <machine/reg.h>
-
-#include <stdbool.h>
-#include <stdio.h>
-#include <sysdecode.h>
-
-#include "truss.h"
-
-static int
-riscv_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.t[0];
- if (syscall_num == SYS_syscall || syscall_num == SYS___syscall) {
- reg = 1;
- syscall_num = regs.a[0];
- } else {
- reg = 0;
- }
-
- for (i = 0; i < narg && reg < NARGREG; i++, reg++)
- cs->args[i] = regs.a[reg];
- return (0);
-}
-
-static int
-riscv_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.a[0];
- retval[1] = regs.a[1];
- *errorp = !!(regs.t[0]);
- return (0);
-}
-
-static struct procabi riscv_freebsd = {
- "FreeBSD ELF64",
- SYSDECODE_ABI_FREEBSD,
- riscv_fetch_args,
- riscv_fetch_retval,
- STAILQ_HEAD_INITIALIZER(riscv_freebsd.extra_syscalls),
- { NULL }
-};
-
-PROCABI(riscv_freebsd);
Index: head/usr.bin/truss/setup.c
===================================================================
--- head/usr.bin/truss/setup.c
+++ head/usr.bin/truss/setup.c
@@ -61,7 +61,10 @@
#include "syscall.h"
#include "extern.h"
-SET_DECLARE(procabi, struct procabi);
+struct procabi_table {
+ const char *name;
+ struct procabi *abi;
+};
static sig_atomic_t detaching;
@@ -69,6 +72,79 @@
struct ptrace_lwpinfo *);
static void new_proc(struct trussinfo *, pid_t, lwpid_t);
+
+static struct procabi cloudabi32 = {
+ "CloudABI32",
+ SYSDECODE_ABI_CLOUDABI32,
+ STAILQ_HEAD_INITIALIZER(cloudabi32.extra_syscalls),
+ { NULL }
+};
+
+static struct procabi cloudabi64 = {
+ "CloudABI64",
+ SYSDECODE_ABI_CLOUDABI64,
+ STAILQ_HEAD_INITIALIZER(cloudabi64.extra_syscalls),
+ { NULL }
+};
+
+static struct procabi freebsd = {
+ "FreeBSD",
+ SYSDECODE_ABI_FREEBSD,
+ STAILQ_HEAD_INITIALIZER(freebsd.extra_syscalls),
+ { NULL }
+};
+
+#ifdef __LP64__
+static struct procabi freebsd32 = {
+ "FreeBSD32",
+ SYSDECODE_ABI_FREEBSD32,
+ STAILQ_HEAD_INITIALIZER(freebsd32.extra_syscalls),
+ { NULL }
+};
+#endif
+
+static struct procabi linux = {
+ "Linux",
+ SYSDECODE_ABI_LINUX,
+ STAILQ_HEAD_INITIALIZER(linux.extra_syscalls),
+ { NULL }
+};
+
+#ifdef __LP64__
+static struct procabi linux32 = {
+ "Linux32",
+ SYSDECODE_ABI_LINUX32,
+ STAILQ_HEAD_INITIALIZER(linux32.extra_syscalls),
+ { NULL }
+};
+#endif
+
+static struct procabi_table abis[] = {
+ { "CloudABI ELF32", &cloudabi32 },
+ { "CloudABI ELF64", &cloudabi64 },
+#ifdef __LP64__
+ { "FreeBSD ELF64", &freebsd },
+ { "FreeBSD ELF32", &freebsd32 },
+#else
+ { "FreeBSD ELF32", &freebsd },
+#endif
+#if defined(__powerpc64__)
+ { "FreeBSD ELF64 V2", &freebsd },
+#endif
+#if defined(__amd64__)
+ { "FreeBSD a.out", &freebsd32 },
+#endif
+#if defined(__i386__)
+ { "FreeBSD a.out", &freebsd },
+#endif
+#ifdef __LP64__
+ { "Linux ELF64", &linux },
+ { "Linux ELF32", &linux32 },
+#else
+ { "Linux ELF", &linux },
+#endif
+};
+
/*
* setup_and_wait() is called to start a process. All it really does
* is fork(), enable tracing in the child, and then exec the given
@@ -153,8 +229,8 @@
static struct procabi *
find_abi(pid_t pid)
{
- struct procabi **pabi;
size_t len;
+ unsigned int i;
int error;
int mib[4];
char progt[32];
@@ -168,9 +244,9 @@
if (error != 0)
err(2, "can not get sysvec name");
- SET_FOREACH(pabi, procabi) {
- if (strcmp((*pabi)->type, progt) == 0)
- return (*pabi);
+ for (i = 0; i < nitems(abis); i++) {
+ if (strcmp(abis[i].name, progt) == 0)
+ return (abis[i].abi);
}
warnx("ABI %s for pid %ld is not supported", progt, (long)pid);
return (NULL);
@@ -376,7 +452,8 @@
alloc_syscall(t, pl);
narg = MIN(pl->pl_syscall_narg, nitems(t->cs.args));
- if (narg != 0 && t->proc->abi->fetch_args(info, narg) != 0) {
+ if (narg != 0 && ptrace(PT_GET_SC_ARGS, t->tid, (caddr_t)t->cs.args,
+ sizeof(t->cs.args)) != 0) {
free_syscall(t);
return;
}
@@ -408,7 +485,7 @@
#endif
if (!(sc->args[i].type & OUT)) {
t->cs.s_args[i] = print_arg(&sc->args[i],
- t->cs.args, 0, info);
+ t->cs.args, NULL, info);
}
}
#if DEBUG
@@ -446,9 +523,8 @@
struct threadinfo *t;
struct procinfo *p;
struct syscall *sc;
- long retval[2];
+ struct ptrace_sc_ret psr;
u_int i;
- int errorp;
t = info->curthread;
if (!t->in_syscall)
@@ -456,7 +532,7 @@
clock_gettime(CLOCK_REALTIME, &t->after);
p = t->proc;
- if (p->abi->fetch_retval(info, retval, &errorp) < 0) {
+ if (ptrace(PT_GET_SC_RET, t->tid, (caddr_t)&psr, sizeof(psr)) != 0) {
free_syscall(t);
return;
}
@@ -474,18 +550,18 @@
* If an error occurred, then don't bother
* getting the data; it may not be valid.
*/
- if (errorp) {
+ if (psr.sr_error != 0) {
asprintf(&temp, "0x%lx",
t->cs.args[sc->args[i].offset]);
} else {
temp = print_arg(&sc->args[i],
- t->cs.args, retval, info);
+ t->cs.args, psr.sr_retval, info);
}
t->cs.s_args[i] = temp;
}
}
- print_syscall_ret(info, errorp, retval);
+ print_syscall_ret(info, psr.sr_error, psr.sr_retval);
free_syscall(t);
/*
Index: head/usr.bin/truss/sparc64-freebsd.c
===================================================================
--- head/usr.bin/truss/sparc64-freebsd.c
+++ head/usr.bin/truss/sparc64-freebsd.c
@@ -1,128 +0,0 @@
-/*-
- * SPDX-License-Identifier: BSD-4-Clause
- *
- * 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 <stdbool.h>
-#include <stddef.h>
-#include <stdio.h>
-#include <sysdecode.h>
-
-#include "truss.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",
- SYSDECODE_ABI_FREEBSD,
- sparc64_fetch_args,
- sparc64_fetch_retval,
- STAILQ_HEAD_INITIALIZER(sparc64_freebsd.extra_syscalls),
- { NULL }
-};
-
-PROCABI(sparc64_freebsd);
Index: head/usr.bin/truss/syscall.h
===================================================================
--- head/usr.bin/truss/syscall.h
+++ head/usr.bin/truss/syscall.h
@@ -227,7 +227,8 @@
};
struct syscall *get_syscall(struct threadinfo *, u_int, u_int);
-char *print_arg(struct syscall_args *, unsigned long*, long *, struct trussinfo *);
+char *print_arg(struct syscall_args *, unsigned long*, register_t *,
+ struct trussinfo *);
/*
* Linux Socket defines
@@ -271,5 +272,5 @@
void init_syscalls(void);
void print_syscall(struct trussinfo *);
-void print_syscall_ret(struct trussinfo *, int, long *);
+void print_syscall_ret(struct trussinfo *, int, register_t *);
void print_summary(struct trussinfo *trussinfo);
Index: head/usr.bin/truss/syscalls.c
===================================================================
--- head/usr.bin/truss/syscalls.c
+++ head/usr.bin/truss/syscalls.c
@@ -61,6 +61,8 @@
#include <assert.h>
#include <ctype.h>
#include <err.h>
+#define _WANT_KERNEL_ERRNO
+#include <errno.h>
#include <fcntl.h>
#include <poll.h>
#include <sched.h>
@@ -1556,7 +1558,7 @@
* an array of all of the system call arguments.
*/
char *
-print_arg(struct syscall_args *sc, unsigned long *args, long *retval,
+print_arg(struct syscall_args *sc, unsigned long *args, register_t *retval,
struct trussinfo *trussinfo)
{
FILE *fp;
@@ -2277,7 +2279,7 @@
* Overwrite the first retval to signal a successful
* return as well.
*/
- fprintf(fp, "{ %ld, %ld }", retval[0], retval[1]);
+ fprintf(fp, "{ %d, %d }", (int)retval[0], (int)retval[1]);
retval[0] = 0;
break;
case Utrace: {
@@ -2646,12 +2648,11 @@
}
void
-print_syscall_ret(struct trussinfo *trussinfo, int errorp, long *retval)
+print_syscall_ret(struct trussinfo *trussinfo, int error, register_t *retval)
{
struct timespec timediff;
struct threadinfo *t;
struct syscall *sc;
- int error;
t = trussinfo->curthread;
sc = t->cs.sc;
@@ -2659,7 +2660,7 @@
timespecsub(&t->after, &t->before, &timediff);
timespecadd(&sc->time, &timediff, &sc->time);
sc->ncalls++;
- if (errorp)
+ if (error != 0)
sc->nerror++;
return;
}
@@ -2676,11 +2677,14 @@
return;
}
- if (errorp) {
- error = sysdecode_abi_to_freebsd_errno(t->proc->abi->abi,
- retval[0]);
- fprintf(trussinfo->outfile, " ERR#%ld '%s'\n", retval[0],
- error == INT_MAX ? "Unknown error" : strerror(error));
+ if (error == ERESTART)
+ fprintf(trussinfo->outfile, " ERESTART\n");
+ else if (error == EJUSTRETURN)
+ fprintf(trussinfo->outfile, " EJUSTRETURN\n");
+ else if (error != 0) {
+ fprintf(trussinfo->outfile, " ERR#%d '%s'\n",
+ sysdecode_freebsd_to_abi_errno(t->proc->abi->abi, error),
+ strerror(error));
}
#ifndef __LP64__
else if (sc->ret_type == 2) {
@@ -2696,8 +2700,8 @@
}
#endif
else
- fprintf(trussinfo->outfile, " = %ld (0x%lx)\n", retval[0],
- retval[0]);
+ fprintf(trussinfo->outfile, " = %jd (0x%jx)\n",
+ (intmax_t)retval[0], (intmax_t)retval[0]);
}
void
Index: head/usr.bin/truss/truss.h
===================================================================
--- head/usr.bin/truss/truss.h
+++ head/usr.bin/truss/truss.h
@@ -27,7 +27,6 @@
* $FreeBSD$
*/
-#include <sys/linker_set.h>
#include <sys/queue.h>
#define FOLLOWFORKS 0x00000001
@@ -59,13 +58,9 @@
struct procabi {
const char *type;
enum sysdecode_abi abi;
- int (*fetch_args)(struct trussinfo *, u_int);
- int (*fetch_retval)(struct trussinfo *, long *, int *);
STAILQ_HEAD(, extra_syscall) extra_syscalls;
struct syscall *syscalls[SYSCALL_NORMAL_COUNT];
};
-
-#define PROCABI(abi) DATA_SET(procabi, abi)
/*
* This is confusingly named. It holds per-thread state about the

File Metadata

Mime Type
text/plain
Expires
Fri, Mar 20, 3:20 PM (6 h, 16 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
29980320
Default Alt Text
D20963.diff (82 KB)

Event Timeline