From nobody Mon Feb 21 13:48:55 2022 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id BE6C61839F38; Mon, 21 Feb 2022 13:48:57 +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 4K2Ntw4W2Zz3Pww; Mon, 21 Feb 2022 13:48:56 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1645451336; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=49Y6Fp5dSBzf+x3ZzyGGr3DOZQU+UK9sd3Wq+NLIRII=; b=SCamvTv45LfHO84Z2nEHQtRiFFzGZHCykQ9xmpBFgT7hvB1SeBORddbKdW7Wk8f04q9gdI 7wKZeNhmcr53McP+CFf8j9gxPotdC08K9Ecqf3eBM4CtL3vNVbEAchMme/50wmF6UEhqB+ g1cLdvh3gJNpSfYFR2yWzkqS33tQJuPyxpBQJc/49ITNbrf9iye7xhMALN8Yum0fwHPdzz fB9xKkmZ73MRrronY5xXYB8wBpP4TNk9oMfkXw+hKf9hjBfZQQFBRcjxxOPFAZiZx8Mz/I d5tsxCY/SXl4wuPM+I5WJLjSyjC5iZfRdMqpbmnaHdTcIlyo2/bOl6Lc35cqDw== 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 7150F114C7; Mon, 21 Feb 2022 13:48:55 +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 21LDmthN091923; Mon, 21 Feb 2022 13:48:55 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 21LDmt95091922; Mon, 21 Feb 2022 13:48:55 GMT (envelope-from git) Date: Mon, 21 Feb 2022 13:48:55 GMT Message-Id: <202202211348.21LDmt95091922@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Edward Tomasz Napierala Subject: git: d33684f3710e - stable/13 - linux: Implement some bits of PTRACE_PEEKUSER List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org 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/stable/13 X-Git-Reftype: branch X-Git-Commit: d33684f3710e579322835d4737dc8a92ac30144b Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1645451336; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=49Y6Fp5dSBzf+x3ZzyGGr3DOZQU+UK9sd3Wq+NLIRII=; b=BOyjlxM81rmqvChIXIG9O2N3X8Pu4ovlNsKb17m0TiG06Snizt9aQEShVeJ5UJI8REFTen 9zKOtw7lefaib699GirXHO56E2CWLOwPeR59QWsJkMa+obTslTeUHBVViBhxkcIvK1P7i6 uCvste2QcF/S27ESYD3CGREU1DZeF5bqWnHs/fxnq1Wc3/Kr4jrayWnXS4qKWkeK4MlpsN OY9aRdUO2zxmle62p5poWSi/I3pOKWhQB5qcEQAtY0cOxPdRz47vEmtT9E+WgINqbO+DMT 3zCs8f8Tmx2RMZW1bzaLuO0OucKuLANcX9iOxsSDWzf6ZcUlB+V7TmXFbdeHjw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1645451336; a=rsa-sha256; cv=none; b=DTeilU7op33bnfP2+mUtXIjh96m6Xzpshs82BQ618IX6ISmeDDMzKKY/GwGCIM5Pycgxfj l/CV7O31Sd1+pfNo9bvSLtUKohlx7HIMWIYgGAx4m3EYK+8jz7KRS6yWq3TOL5UoV/c0P6 2W8F9t1ddB+171hEfH9w7SP7ISXz36NBBmuUgJEFDUl3bvef9wtcEWvSysioDkIb7hrRGm X7PAJ+6loKYk4PJNDYFIS6V9uziu+1iObu/wP3bcmK/1jb00ju/4vGCR3quqMZ6P2HX3EQ fLEhxc77aHCmDJgBK5C0gQBuSyzA6qurdpWEOCTnSY+0l9iSg3di81Sg0d1tag== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by trasz: URL: https://cgit.FreeBSD.org/src/commit/?id=d33684f3710e579322835d4737dc8a92ac30144b commit d33684f3710e579322835d4737dc8a92ac30144b Author: Edward Tomasz Napierala AuthorDate: 2021-10-17 11:20:16 +0000 Commit: Edward Tomasz Napierala CommitDate: 2022-02-21 13:34:56 +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 (cherry picked from commit f9246e14848820664539763b72b6fdef408d20e4) --- 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 cccef2ad5461..5f1e0eb93f5a 100644 --- a/sys/amd64/linux/linux_ptrace.c +++ b/sys/amd64/linux/linux_ptrace.c @@ -98,6 +98,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 @@ -320,9 +325,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