From nobody Fri Jun 17 19:38:19 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 02B7485B15C; Fri, 17 Jun 2022 19:38:19 +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 4LPq8W4lyGz3QJ2; Fri, 17 Jun 2022 19:38:19 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1655494699; 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=UJanf4k0U/zTR/6+YPdC5Md44NyJ3Z95e3tDMDFPHEw=; b=mhRK/mfU+vEzuYvpljMxMt8ZAKTgnG22tW9BDuAUdLd26AmBeBYYo4EXiNGXbRj38DmLp9 Vudxx2Ot8MMXMB8WTcjjhVxk1oUxHUb4j8zxHtIEmh98pscRo0uAG+w36JSIhq7h7e1nuC hhHoHjEKBclJFh2cxRAArQuIA49tm7UzGj+PMnmhAajVyJxlVsmdhaTe0cgPzeHjHB3ULW srOGtsUZ7kCyuD9EMY1/97uO3edZp7yELQnZRPt5PkIcY7XpBUKqctLBJKIk85NUDg6GI3 RUMOIODGc8Og7b0o+gM+D3ILoWzNcUSTk060ALiRKdMavH+iqUs5l1UUBc39WQ== 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 6256B25D80; Fri, 17 Jun 2022 19:38:19 +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 25HJcJHX014527; Fri, 17 Jun 2022 19:38:19 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 25HJcJ8R014526; Fri, 17 Jun 2022 19:38:19 GMT (envelope-from git) Date: Fri, 17 Jun 2022 19:38:19 GMT Message-Id: <202206171938.25HJcJ8R014526@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Dmitry Chagin Subject: git: ab52de447881 - stable/13 - linux: Make linux_ptrace.c portable 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: dchagin X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: ab52de4478816f50f62da19d82eaabac30eaee30 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1655494699; 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=UJanf4k0U/zTR/6+YPdC5Md44NyJ3Z95e3tDMDFPHEw=; b=I9yWn0hsXGegFOVNQ60cvhpNOtOpW3n9IZVFQ4kwXU7k/28Cr8f2oQGnC/Qh+wiAByEVVp A+S7qQDB2mKpAfBdL8d3nDVLR5srntGfQ/468GAtfOSVsnSDVPrygwXhXg9NOW5ZHnuhhP w9mMWJ9xDR/yXvb/TKnEGYDUoLUP8vvrlKE1kKp2IlAvFf5gm8BG0xqhWJuyHAtxN3CStC 0x4z/Sde+ZMfRJjEb5w07riuE8yUDbPuhMY9tZFp/Ajbd4H5nSDypsT7xQSCTr8octefTU 5HTn4JbRJkzRhX8nCc+ZJ477tYiqWOSYBc9vL82CBBd93aAzZ9Fqd7kt4wBKug== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1655494699; a=rsa-sha256; cv=none; b=rCaeyJHE+xZpgXtJ+WwPbWDMnhT8DIB7EUW61f8N6rXmop/0XEgtJYeVrMBVAID3gwoN/b TJnvGmDsRnmFQDHmnjgmtafvYZo9Hegmr26pZGRvpiuZ+IQ9X6fQ2Qdx3NSCXRa1MJ6IRJ d4c7IJRaP/BbhKE2OJF989qQ4pzBNTWc3E+aLrut+dK8UhbCePMjH32GY53QlIwlFQrJe/ Sk3o5izkNT8CenRNBRhswLnyBlPd2Xk3nha7T8RjYluM2PMVRU143mfTCe7DotJ+kOa8LY 2yWilhYE7U2lZ5bp0QObrsuBcbz6j+zYnxcRL9yncZtsQ4oWP98YhxW8SNqDRw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by dchagin: URL: https://cgit.FreeBSD.org/src/commit/?id=ab52de4478816f50f62da19d82eaabac30eaee30 commit ab52de4478816f50f62da19d82eaabac30eaee30 Author: Edward Tomasz Napierala AuthorDate: 2021-11-03 08:54:30 +0000 Commit: Dmitry Chagin CommitDate: 2022-06-17 19:33:35 +0000 linux: Make linux_ptrace.c portable Make sys/amd64/linux/linux_ptrace.c machine-independent, in preparation for moving it into sys/compat/linux/. No functional changes. Reviewed By: kib Sponsored By: EPSRC Differential Revision: https://reviews.freebsd.org/D32756 (cherry picked from commit c91d0e59be10f9412cbce467b8b038f006bb6f18) --- sys/amd64/linux/linux_ptrace.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/sys/amd64/linux/linux_ptrace.c b/sys/amd64/linux/linux_ptrace.c index 35b66522cf06..a227aa1069eb 100644 --- a/sys/amd64/linux/linux_ptrace.c +++ b/sys/amd64/linux/linux_ptrace.c @@ -108,6 +108,7 @@ __FBSDID("$FreeBSD$"); #define LINUX_PTRACE_PEEKUSER_DS 184 #define LINUX_ARCH_AMD64 0xc000003e +#define LINUX_ARCH_AARCH64 0xc00000b7 static int map_signum(int lsig, int *bsigp) @@ -217,6 +218,7 @@ linux_ptrace_peekuser(struct thread *td, pid_t pid, void *addr, void *data) return (error); switch ((uintptr_t)addr) { +#ifdef __amd64__ case LINUX_PTRACE_PEEKUSER_ORIG_RAX: val = b_reg.r_rax; break; @@ -229,6 +231,7 @@ linux_ptrace_peekuser(struct thread *td, pid_t pid, void *addr, void *data) case LINUX_PTRACE_PEEKUSER_DS: val = b_reg.r_ds; break; +#endif /* __amd64__ */ default: linux_msg(td, "PTRACE_PEEKUSER offset %ld not implemented; " "returning EINVAL", (uintptr_t)addr); @@ -343,20 +346,25 @@ linux_ptrace_getregs(struct thread *td, pid_t pid, void *data) struct ptrace_lwpinfo lwpinfo; struct reg b_reg; struct linux_pt_regset l_regset; +#ifdef __amd64__ struct pcb *pcb; +#endif int error; error = kern_ptrace(td, PT_GETREGS, pid, &b_reg, 0); if (error != 0) return (error); + bsd_to_linux_regset(&b_reg, &l_regset); + +#ifdef __amd64__ pcb = td->td_pcb; if (td == curthread) update_pcb_bases(pcb); - bsd_to_linux_regset(&b_reg, &l_regset); l_regset.fs_base = pcb->pcb_fsbase; l_regset.gs_base = pcb->pcb_gsbase; +#endif error = kern_ptrace(td, PT_LWPINFO, pid, &lwpinfo, sizeof(lwpinfo)); if (error != 0) { @@ -404,7 +412,9 @@ linux_ptrace_getregset_prstatus(struct thread *td, pid_t pid, l_ulong data) struct reg b_reg; struct linux_pt_regset l_regset; struct iovec iov; +#ifdef __amd64__ struct pcb *pcb; +#endif size_t len; int error; @@ -418,13 +428,16 @@ linux_ptrace_getregset_prstatus(struct thread *td, pid_t pid, l_ulong data) if (error != 0) return (error); + bsd_to_linux_regset(&b_reg, &l_regset); + +#ifdef __amd64__ pcb = td->td_pcb; if (td == curthread) update_pcb_bases(pcb); - bsd_to_linux_regset(&b_reg, &l_regset); l_regset.fs_base = pcb->pcb_fsbase; l_regset.gs_base = pcb->pcb_gsbase; +#endif error = kern_ptrace(td, PT_LWPINFO, pid, &lwpinfo, sizeof(lwpinfo)); if (error != 0) { @@ -569,9 +582,17 @@ linux_ptrace_get_syscall_info(struct thread *td, pid_t pid, if (error != 0) return (error); +#if defined(__amd64__) si.arch = LINUX_ARCH_AMD64; si.instruction_pointer = b_reg.r_rip; si.stack_pointer = b_reg.r_rsp; +#elif defined(__aarch64__) + si.arch = LINUX_ARCH_AARCH64; + si.instruction_pointer = b_reg.lr; + si.stack_pointer = b_reg.sp; +#else +#error "unknown architecture" +#endif len = MIN(len, sizeof(si)); error = copyout(&si, (void *)data, len);