From owner-svn-src-all@freebsd.org Wed Dec 20 13:13:12 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 1FA45E883D6; Wed, 20 Dec 2017 13:13:12 +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 EB7B86C8B1; Wed, 20 Dec 2017 13:13:11 +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 vBKDDB3v029413; Wed, 20 Dec 2017 13:13:11 GMT (envelope-from ed@FreeBSD.org) Received: (from ed@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id vBKDDAJu029411; Wed, 20 Dec 2017 13:13:10 GMT (envelope-from ed@FreeBSD.org) Message-Id: <201712201313.vBKDDAJu029411@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ed set sender to ed@FreeBSD.org using -f From: Ed Schouten Date: Wed, 20 Dec 2017 13:13:10 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r327022 - 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: 327022 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: Wed, 20 Dec 2017 13:13:12 -0000 Author: ed Date: Wed Dec 20 13:13:10 2017 New Revision: 327022 URL: https://svnweb.freebsd.org/changeset/base/327022 Log: Make truss(8) work for 32-bit CloudABI executables on ARM64. This change effectively merges the existing 64-bit support for ARM64 with the 32-on-64-bit support for AMD64. Added: head/usr.bin/truss/aarch64-cloudabi32.c - copied, changed from r327021, head/usr.bin/truss/aarch64-cloudabi64.c Modified: head/usr.bin/truss/Makefile Modified: head/usr.bin/truss/Makefile ============================================================================== --- head/usr.bin/truss/Makefile Wed Dec 20 07:55:47 2017 (r327021) +++ head/usr.bin/truss/Makefile Wed Dec 20 13:13:10 2017 (r327022) @@ -13,6 +13,7 @@ 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" Copied and modified: head/usr.bin/truss/aarch64-cloudabi32.c (from r327021, head/usr.bin/truss/aarch64-cloudabi64.c) ============================================================================== --- head/usr.bin/truss/aarch64-cloudabi64.c Wed Dec 20 07:55:47 2017 (r327021, copy source) +++ head/usr.bin/truss/aarch64-cloudabi32.c Wed Dec 20 13:13:10 2017 (r327022) @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2015 Nuxi, https://nuxi.nl/ + * 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 @@ -38,51 +38,75 @@ __FBSDID("$FreeBSD$"); #include "truss.h" static int -aarch64_cloudabi64_fetch_args(struct trussinfo *trussinfo, unsigned int narg) +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; - unsigned int i; - tid = trussinfo->curthread->tid; - if (ptrace(PT_GETREGS, tid, (caddr_t)®s, 0) == -1) { - fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n"); - return (-1); - } + if (narg > 0) { + /* Fetch registers, containing the address of the arguments. */ + tid = trussinfo->curthread->tid; + if (ptrace(PT_GETREGS, tid, (caddr_t)®s, 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]; + /* 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_cloudabi64_fetch_retval(struct trussinfo *trussinfo, long *retval, +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)®s, 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; + 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_cloudabi64 = { - "CloudABI ELF64", - SYSDECODE_ABI_CLOUDABI64, - aarch64_cloudabi64_fetch_args, - aarch64_cloudabi64_fetch_retval, - STAILQ_HEAD_INITIALIZER(aarch64_cloudabi64.extra_syscalls), +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_cloudabi64); +PROCABI(aarch64_cloudabi32);