Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 23 Aug 2020 19:20:38 +0000 (UTC)
From:      Edward Tomasz Napierala <trasz@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org
Subject:   svn commit: r364504 - stable/12/sys/amd64/linux
Message-ID:  <202008231920.07NJKcD8056412@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: trasz
Date: Sun Aug 23 19:20:38 2020
New Revision: 364504
URL: https://svnweb.freebsd.org/changeset/base/364504

Log:
  MFC r347580:
  
  Fix handling of r10 in Linux ptrace(2).  This fixes decoding
  of the 'flags' argument to mmap(2) with Linux strace(1).
  
  Sponsored by:	The FreeBSD Foundation

Modified:
  stable/12/sys/amd64/linux/linux_ptrace.c
Directory Properties:
  stable/12/   (props changed)

Modified: stable/12/sys/amd64/linux/linux_ptrace.c
==============================================================================
--- stable/12/sys/amd64/linux/linux_ptrace.c	Sun Aug 23 19:19:00 2020	(r364503)
+++ stable/12/sys/amd64/linux/linux_ptrace.c	Sun Aug 23 19:20:38 2020	(r364504)
@@ -338,18 +338,27 @@ linux_ptrace_getregs(struct thread *td, pid_t pid, voi
 
 	map_regs_to_linux(&b_reg, &l_reg);
 
-	/*
-	 * The strace(1) utility depends on RAX being set to -ENOSYS
-	 * on syscall entry.
-	 */
 	error = kern_ptrace(td, PT_LWPINFO, pid, &lwpinfo, sizeof(lwpinfo));
 	if (error != 0) {
 		printf("%s: PT_LWPINFO failed with error %d\n", __func__, error);
 		return (error);
 	}
-	if (lwpinfo.pl_flags & PL_FLAG_SCE)
-		l_reg.rax = -38; // XXX: Don't hardcode?
+	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. ]
+		 */
+		l_reg.rax = -38; /* -ENOSYS */
 
+		/*
+		 * Undo the mangling done in exception.S:fast_syscall_common().
+		 */
+		l_reg.r10 = l_reg.rcx;
+	}
+
 	error = copyout(&l_reg, (void *)data, sizeof(l_reg));
 	return (error);
 }
@@ -399,21 +408,27 @@ linux_ptrace_getregset_prstatus(struct thread *td, pid
 
 	map_regs_to_linux_regset(&b_reg, fsbase, gsbase, &l_regset);
 
-	/*
-	 * 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. ]
-	 */
 	error = kern_ptrace(td, PT_LWPINFO, pid, &lwpinfo, sizeof(lwpinfo));
 	if (error != 0) {
 		printf("%s: PT_LWPINFO failed with error %d\n",
 		    __func__, error);
 		return (error);
 	}
-	if (lwpinfo.pl_flags & PL_FLAG_SCE)
-		l_regset.rax = -38; // XXX: Don't hardcode?
+	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. ]
+		 */
+		l_regset.rax = -38; /* -ENOSYS */
+
+		/*
+		 * Undo the mangling done in exception.S:fast_syscall_common().
+		 */
+		l_regset.r10 = l_regset.rcx;
+	}
 
 	len = MIN(iov.iov_len, sizeof(l_regset));
 	error = copyout(&l_regset, (void *)iov.iov_base, len);



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