From owner-dev-commits-src-main@freebsd.org  Wed Jun 16 16:21:06 2021
Return-Path: <owner-dev-commits-src-main@freebsd.org>
Delivered-To: dev-commits-src-main@mailman.nyi.freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1])
 by mailman.nyi.freebsd.org (Postfix) with ESMTP id 22C50665442;
 Wed, 16 Jun 2021 16:21:06 +0000 (UTC) (envelope-from git@FreeBSD.org)
Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org
 [IPv6:2610:1c1:1:606c::19:3])
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
 key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256
 client-signature RSA-PSS (4096 bits) client-digest SHA256)
 (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK))
 by mx1.freebsd.org (Postfix) with ESMTPS id 4G4r5s5xHxz4jTr;
 Wed, 16 Jun 2021 16:21:05 +0000 (UTC) (envelope-from git@FreeBSD.org)
Received: from gitrepo.freebsd.org (gitrepo.freebsd.org
 [IPv6:2610:1c1:1:6068::e6a:5])
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
 key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256)
 (Client did not present a certificate)
 by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id A7B741E8FE;
 Wed, 16 Jun 2021 16:21:05 +0000 (UTC) (envelope-from git@FreeBSD.org)
Received: from gitrepo.freebsd.org ([127.0.1.44])
 by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 15GGL5R5007144;
 Wed, 16 Jun 2021 16:21:05 GMT (envelope-from git@gitrepo.freebsd.org)
Received: (from git@localhost)
 by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 15GGL5n8007143;
 Wed, 16 Jun 2021 16:21:05 GMT (envelope-from git)
Date: Wed, 16 Jun 2021 16:21:05 GMT
Message-Id: <202106161621.15GGL5n8007143@gitrepo.freebsd.org>
To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org,
 dev-commits-src-main@FreeBSD.org
From: Alex Richardson <arichardson@FreeBSD.org>
Subject: git: 8ba2e89e987c - main - truss: fix handling of 64-bit
 arguments/return values for compat32
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
X-Git-Committer: arichardson
X-Git-Repository: src
X-Git-Refname: refs/heads/main
X-Git-Reftype: branch
X-Git-Commit: 8ba2e89e987c7ae171c5f099e59d599294d626b7
Auto-Submitted: auto-generated
X-BeenThere: dev-commits-src-main@freebsd.org
X-Mailman-Version: 2.1.34
Precedence: list
List-Id: Commit messages for the main branch of the src repository
 <dev-commits-src-main.freebsd.org>
List-Unsubscribe: <https://lists.freebsd.org/mailman/options/dev-commits-src-main>, 
 <mailto:dev-commits-src-main-request@freebsd.org?subject=unsubscribe>
List-Archive: <http://lists.freebsd.org/pipermail/dev-commits-src-main/>
List-Post: <mailto:dev-commits-src-main@freebsd.org>
List-Help: <mailto:dev-commits-src-main-request@freebsd.org?subject=help>
List-Subscribe: <https://lists.freebsd.org/mailman/listinfo/dev-commits-src-main>, 
 <mailto:dev-commits-src-main-request@freebsd.org?subject=subscribe>
X-List-Received-Date: Wed, 16 Jun 2021 16:21:06 -0000

The branch main has been updated by arichardson:

URL: https://cgit.FreeBSD.org/src/commit/?id=8ba2e89e987c7ae171c5f099e59d599294d626b7

commit 8ba2e89e987c7ae171c5f099e59d599294d626b7
Author:     Alex Richardson <arichardson@FreeBSD.org>
AuthorDate: 2021-06-16 15:29:57 +0000
Commit:     Alex Richardson <arichardson@FreeBSD.org>
CommitDate: 2021-06-16 15:29:57 +0000

    truss: fix handling of 64-bit arguments/return values for compat32
    
    Deciding whether to combine two values to a 64-bit one should be based on
    the process ABI, and not dependent on whether truss is compiled for an
    LP64 ABI. This is a follow-up cleanup for D27625. I found this while
    looking for uses of the `__LP64__` macro (since using this is wrong for
    CHERI systems).
    
    Test Plan: truss still works. Since I tested on AMD64 and all syscalls
    in the trace have their quad argument last there was no difference
    in the output. Should fix output for compat32 on MIPS64 though.
    
    Reviewed By:    jhb
    MFC after:      3 days
    Differential Revision: https://reviews.freebsd.org/D27637
---
 usr.bin/truss/syscalls.c | 40 +++++++++++++++++-----------------------
 1 file changed, 17 insertions(+), 23 deletions(-)

diff --git a/usr.bin/truss/syscalls.c b/usr.bin/truss/syscalls.c
index b9c6ff4ad361..c19f3c3e598d 100644
--- a/usr.bin/truss/syscalls.c
+++ b/usr.bin/truss/syscalls.c
@@ -1908,32 +1908,29 @@ print_arg(struct syscall_arg *sc, unsigned long *args, register_t *retval,
 		fputs(" ]", fp);
 		break;
 	}
-#ifdef __LP64__
-	case Quad:
-		fprintf(fp, "%ld", args[sc->offset]);
-		break;
-	case QuadHex:
-		fprintf(fp, "0x%lx", args[sc->offset]);
-		break;
-#else
 	case Quad:
 	case QuadHex: {
-		unsigned long long ll;
+		uint64_t value;
+		size_t pointer_size =
+		    trussinfo->curthread->proc->abi->pointer_size;
 
+		if (pointer_size == 4) {
 #if _BYTE_ORDER == _LITTLE_ENDIAN
-		ll = (unsigned long long)args[sc->offset + 1] << 32 |
-		    args[sc->offset];
+			value = (uint64_t)args[sc->offset + 1] << 32 |
+			    args[sc->offset];
 #else
-		ll = (unsigned long long)args[sc->offset] << 32 |
-		    args[sc->offset + 1];
+			value = (uint64_t)args[sc->offset] << 32 |
+			    args[sc->offset + 1];
 #endif
+		} else {
+			value = (uint64_t)args[sc->offset];
+		}
 		if ((sc->type & ARG_MASK) == Quad)
-			fprintf(fp, "%lld", ll);
+			fprintf(fp, "%jd", (intmax_t)value);
 		else
-			fprintf(fp, "0x%llx", ll);
+			fprintf(fp, "0x%jx", (intmax_t)value);
 		break;
 	}
-#endif
 	case PQuadHex: {
 		uint64_t val;
 
@@ -3015,11 +3012,9 @@ print_syscall_ret(struct trussinfo *trussinfo, int error, register_t *retval)
 		fprintf(trussinfo->outfile, " ERR#%d '%s'\n",
 		    sysdecode_freebsd_to_abi_errno(t->proc->abi->abi, error),
 		    strerror(error));
-	}
-#ifndef __LP64__
-	else if (sc->decode.ret_type == 2) {
+	} else if (sc->decode.ret_type == 2 &&
+	    t->proc->abi->pointer_size == 4) {
 		off_t off;
-
 #if _BYTE_ORDER == _LITTLE_ENDIAN
 		off = (off_t)retval[1] << 32 | retval[0];
 #else
@@ -3027,11 +3022,10 @@ print_syscall_ret(struct trussinfo *trussinfo, int error, register_t *retval)
 #endif
 		fprintf(trussinfo->outfile, " = %jd (0x%jx)\n", (intmax_t)off,
 		    (intmax_t)off);
-	}
-#endif
-	else
+	} else {
 		fprintf(trussinfo->outfile, " = %jd (0x%jx)\n",
 		    (intmax_t)retval[0], (intmax_t)retval[0]);
+	}
 }
 
 void