From owner-svn-src-all@freebsd.org Thu Dec 21 09:21:41 2017 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id AC298E8901D; Thu, 21 Dec 2017 09:21:41 +0000 (UTC) (envelope-from ed@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 83C717EB52; Thu, 21 Dec 2017 09:21:41 +0000 (UTC) (envelope-from ed@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id vBL9LenM046741; Thu, 21 Dec 2017 09:21:40 GMT (envelope-from ed@FreeBSD.org) Received: (from ed@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id vBL9Leuu046739; Thu, 21 Dec 2017 09:21:40 GMT (envelope-from ed@FreeBSD.org) Message-Id: <201712210921.vBL9Leuu046739@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ed set sender to ed@FreeBSD.org using -f From: Ed Schouten Date: Thu, 21 Dec 2017 09:21:40 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r327057 - head/usr.bin/truss X-SVN-Group: head X-SVN-Commit-Author: ed X-SVN-Commit-Paths: head/usr.bin/truss X-SVN-Commit-Revision: 327057 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 21 Dec 2017 09:21:41 -0000 Author: ed Date: Thu Dec 21 09:21:40 2017 New Revision: 327057 URL: https://svnweb.freebsd.org/changeset/base/327057 Log: Make truss work for CloudABI executables on i386. The system call convention is different from i386 binaries running on FreeBSD/amd64, but this is not noticeable by executables. On FreeBSD/amd64, the vDSO already does padding of arguments and return values to 64-bit values. On i386, it does not, meaning that system call return values are simply stored in registers. Added: head/usr.bin/truss/i386-cloudabi32.c - copied, changed from r327055, head/usr.bin/truss/amd64-cloudabi32.c Modified: head/usr.bin/truss/Makefile Modified: head/usr.bin/truss/Makefile ============================================================================== --- head/usr.bin/truss/Makefile Thu Dec 21 09:17:48 2017 (r327056) +++ head/usr.bin/truss/Makefile Thu Dec 21 09:21:40 2017 (r327057) @@ -18,6 +18,7 @@ ABIS+= cloudabi64 .endif .if ${MACHINE_CPUARCH} == "i386" ABIS+= i386-linux +ABIS+= cloudabi32 .endif .if ${MACHINE_CPUARCH} == "amd64" ABIS+= amd64-linux Copied and modified: head/usr.bin/truss/i386-cloudabi32.c (from r327055, head/usr.bin/truss/amd64-cloudabi32.c) ============================================================================== --- head/usr.bin/truss/amd64-cloudabi32.c Thu Dec 21 04:23:00 2017 (r327055, copy source) +++ head/usr.bin/truss/i386-cloudabi32.c Thu Dec 21 09:21:40 2017 (r327057) @@ -38,7 +38,7 @@ __FBSDID("$FreeBSD$"); #include "truss.h" static int -amd64_cloudabi32_fetch_args(struct trussinfo *trussinfo, unsigned int narg) +i386_cloudabi32_fetch_args(struct trussinfo *trussinfo, unsigned int narg) { struct current_syscall *cs; struct ptrace_io_desc iorequest; @@ -46,7 +46,7 @@ amd64_cloudabi32_fetch_args(struct trussinfo *trussinf lwpid_t tid; if (narg > 0) { - /* Fetch registers, containing the address of the arguments. */ + /* Fetch registers, containing the stack pointer. */ tid = trussinfo->curthread->tid; if (ptrace(PT_GETREGS, tid, (caddr_t)®s, 0) == -1) { fprintf(trussinfo->outfile, @@ -54,10 +54,10 @@ amd64_cloudabi32_fetch_args(struct trussinfo *trussinf return (-1); } - /* Fetch arguments. They are already padded to 64 bits. */ + /* Fetch arguments. */ cs = &trussinfo->curthread->cs; iorequest.piod_op = PIOD_READ_D; - iorequest.piod_offs = (void *)regs.r_rcx; + 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 || @@ -68,45 +68,31 @@ amd64_cloudabi32_fetch_args(struct trussinfo *trussinf } static int -amd64_cloudabi32_fetch_retval(struct trussinfo *trussinfo, long *retval, +i386_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)®s, 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; - } + retval[0] = regs.r_eax; + retval[1] = regs.r_edx; + *errorp = (regs.r_eflags & PSL_C) != 0; return (0); } -static struct procabi amd64_cloudabi32 = { +static struct procabi i386_cloudabi32 = { "CloudABI ELF32", SYSDECODE_ABI_CLOUDABI32, - amd64_cloudabi32_fetch_args, - amd64_cloudabi32_fetch_retval, - STAILQ_HEAD_INITIALIZER(amd64_cloudabi32.extra_syscalls), + i386_cloudabi32_fetch_args, + i386_cloudabi32_fetch_retval, + STAILQ_HEAD_INITIALIZER(i386_cloudabi32.extra_syscalls), { NULL } }; -PROCABI(amd64_cloudabi32); +PROCABI(i386_cloudabi32);