From owner-dev-commits-src-main@freebsd.org Tue May 4 14:21:20 2021 Return-Path: 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 5097963365A; Tue, 4 May 2021 14:21:20 +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 4FZMTX1sp8z3Ksh; Tue, 4 May 2021 14:21:20 +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 3332813387; Tue, 4 May 2021 14:21:20 +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 144ELKNC076333; Tue, 4 May 2021 14:21:20 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 144ELKUq076332; Tue, 4 May 2021 14:21:20 GMT (envelope-from git) Date: Tue, 4 May 2021 14:21:20 GMT Message-Id: <202105041421.144ELKUq076332@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Edward Tomasz Napierala Subject: git: 023bff799098 - main - linux(4): fix ptrace(2) to properly handle orig_rax MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: trasz X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 023bff799098cac28732f2800c967f0248d2eb47 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 04 May 2021 14:21:20 -0000 The branch main has been updated by trasz: URL: https://cgit.FreeBSD.org/src/commit/?id=023bff799098cac28732f2800c967f0248d2eb47 commit 023bff799098cac28732f2800c967f0248d2eb47 Author: Edward Tomasz Napierala AuthorDate: 2021-05-04 13:11:01 +0000 Commit: Edward Tomasz Napierala CommitDate: 2021-05-04 14:21:06 +0000 linux(4): fix ptrace(2) to properly handle orig_rax This fixes strace(1) erroneously reporting return values as "Function not implemented", combined with reporting the binary ABI as X32. Very similar code in linux_ptrace_getregs() is left as it is - it's probably wrong too, but I don't have a way to test it. Sponsored By: EPSRC Differential Revision: https://reviews.freebsd.org/D29927 --- sys/amd64/linux/linux_ptrace.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/sys/amd64/linux/linux_ptrace.c b/sys/amd64/linux/linux_ptrace.c index 76ad9b1e25c4..43ecd8892e0f 100644 --- a/sys/amd64/linux/linux_ptrace.c +++ b/sys/amd64/linux/linux_ptrace.c @@ -506,18 +506,18 @@ linux_ptrace_getregset_prstatus(struct thread *td, pid_t pid, l_ulong data) } if (lwpinfo.pl_flags & PL_FLAG_SCE) { /* - * The strace(1) utility depends on RAX being set to -ENOSYS - * on syscall entry; otherwise it loops printing those: - * - * [ Process PID=928 runs in 64 bit mode. ] - * [ Process PID=928 runs in x32 mode. ] + * Undo the mangling done in exception.S:fast_syscall_common(). */ - l_regset.rax = -38; /* -ENOSYS */ + l_regset.r10 = l_regset.rcx; + } + if (lwpinfo.pl_flags & (PL_FLAG_SCE | PL_FLAG_SCX)) { /* - * Undo the mangling done in exception.S:fast_syscall_common(). + * In Linux, the syscall number - passed to the syscall + * as rax - is preserved in orig_rax; rax gets overwritten + * with syscall return value. */ - l_regset.r10 = l_regset.rcx; + l_regset.orig_rax = lwpinfo.pl_syscall_code; } len = MIN(iov.iov_len, sizeof(l_regset));