Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 20 Dec 2017 13:13:10 +0000 (UTC)
From:      Ed Schouten <ed@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r327022 - head/usr.bin/truss
Message-ID:  <201712201313.vBKDDAJu029411@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
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)&regs, 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)&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];
+		/* 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)&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;
+	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);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201712201313.vBKDDAJu029411>