Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 17 Oct 2021 11:51:26 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: f9246e148488 - main - linux: Implement some bits of PTRACE_PEEKUSER
Message-ID:  <202110171151.19HBpQmx059959@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=f9246e14848820664539763b72b6fdef408d20e4

commit f9246e14848820664539763b72b6fdef408d20e4
Author:     Edward Tomasz Napierala <trasz@FreeBSD.org>
AuthorDate: 2021-10-17 11:20:16 +0000
Commit:     Edward Tomasz Napierala <trasz@FreeBSD.org>
CommitDate: 2021-10-17 11:20:21 +0000

    linux: Implement some bits of PTRACE_PEEKUSER
    
    This makes Linux gdb from Bionic a little less broken.
    
    Sponsored By:   EPSRC
    Differential Revision:  https://reviews.freebsd.org/D32455
---
 sys/amd64/linux/linux_ptrace.c | 37 +++++++++++++++++++++++++++++++++++--
 1 file changed, 35 insertions(+), 2 deletions(-)

diff --git a/sys/amd64/linux/linux_ptrace.c b/sys/amd64/linux/linux_ptrace.c
index a59702757972..39587ec9b2ad 100644
--- a/sys/amd64/linux/linux_ptrace.c
+++ b/sys/amd64/linux/linux_ptrace.c
@@ -97,6 +97,11 @@ __FBSDID("$FreeBSD$");
 #define	LINUX_PTRACE_SYSCALL_INFO_ENTRY	1
 #define	LINUX_PTRACE_SYSCALL_INFO_EXIT	2
 
+#define LINUX_PTRACE_PEEKUSER_ORIG_RAX	120
+#define LINUX_PTRACE_PEEKUSER_RIP	128
+#define LINUX_PTRACE_PEEKUSER_CS	136
+#define LINUX_PTRACE_PEEKUSER_DS	184
+
 #define	LINUX_ARCH_AMD64		0xc000003e
 
 static int
@@ -286,9 +291,37 @@ linux_ptrace_peek(struct thread *td, pid_t pid, void *addr, void *data)
 static int
 linux_ptrace_peekuser(struct thread *td, pid_t pid, void *addr, void *data)
 {
+	struct reg b_reg;
+	uint64_t val;
+	int error;
 
-	linux_msg(td, "PTRACE_PEEKUSER not implemented; returning EINVAL");
-	return (EINVAL);
+	error = kern_ptrace(td, PT_GETREGS, pid, &b_reg, 0);
+	if (error != 0)
+		return (error);
+
+	switch ((uintptr_t)addr) {
+	case LINUX_PTRACE_PEEKUSER_ORIG_RAX:
+		val = b_reg.r_rax;
+		break;
+	case LINUX_PTRACE_PEEKUSER_RIP:
+		val = b_reg.r_rip;
+		break;
+	case LINUX_PTRACE_PEEKUSER_CS:
+		val = b_reg.r_cs;
+		break;
+	case LINUX_PTRACE_PEEKUSER_DS:
+		val = b_reg.r_ds;
+		break;
+	default:
+		linux_msg(td, "PTRACE_PEEKUSER offset %ld not implemented; "
+		    "returning EINVAL", (uintptr_t)addr);
+		return (EINVAL);
+	}
+
+	error = copyout(&val, data, sizeof(val));
+	td->td_retval[0] = error;
+
+	return (error);
 }
 
 static int



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