Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 4 May 2021 14:21:20 GMT
From:      Edward Tomasz Napierala <trasz@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: 023bff799098 - main - linux(4): fix ptrace(2) to properly handle orig_rax
Message-ID:  <202105041421.144ELKUq076332@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by trasz:

URL: https://cgit.FreeBSD.org/src/commit/?id=023bff799098cac28732f2800c967f0248d2eb47

commit 023bff799098cac28732f2800c967f0248d2eb47
Author:     Edward Tomasz Napierala <trasz@FreeBSD.org>
AuthorDate: 2021-05-04 13:11:01 +0000
Commit:     Edward Tomasz Napierala <trasz@FreeBSD.org>
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));



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