From nobody Sat Oct 30 10:14:28 2021 X-Original-To: dev-commits-src-main@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 E4800181C402; Sat, 30 Oct 2021 10:14:28 +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 4HhFX45k6lz4X3q; Sat, 30 Oct 2021 10:14:28 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 9FAEAB44; Sat, 30 Oct 2021 10:14:28 +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 19UAESA5030601; Sat, 30 Oct 2021 10:14:28 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 19UAESZK030600; Sat, 30 Oct 2021 10:14:28 GMT (envelope-from git) Date: Sat, 30 Oct 2021 10:14:28 GMT Message-Id: <202110301014.19UAESZK030600@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Edward Tomasz Napierala Subject: git: f0d9a6a781f3 - main - linux: make PTRACE_SETREGS use a correct struct List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@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/main X-Git-Reftype: branch X-Git-Commit: f0d9a6a781f331440baf9a846e773e44a297d59c Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by trasz: URL: https://cgit.FreeBSD.org/src/commit/?id=f0d9a6a781f331440baf9a846e773e44a297d59c commit f0d9a6a781f331440baf9a846e773e44a297d59c Author: Edward Tomasz Napierala AuthorDate: 2021-10-30 09:13:32 +0000 Commit: Edward Tomasz Napierala CommitDate: 2021-10-30 09:13:37 +0000 linux: make PTRACE_SETREGS use a correct struct Note that this is largely untested at this point, as was the previous version; I'm committing this mostly to get rid of `struct linux_pt_reg`. Sponsored By: EPSRC Differential Revision: https://reviews.freebsd.org/D32735 --- sys/amd64/linux/linux.h | 3 ++ sys/amd64/linux/linux_machdep.c | 31 +++++++++++++++++++ sys/amd64/linux/linux_ptrace.c | 66 ++--------------------------------------- 3 files changed, 37 insertions(+), 63 deletions(-) diff --git a/sys/amd64/linux/linux.h b/sys/amd64/linux/linux.h index 519b6bd200ac..16fe3793eae7 100644 --- a/sys/amd64/linux/linux.h +++ b/sys/amd64/linux/linux.h @@ -461,5 +461,8 @@ struct reg; void bsd_to_linux_regset(const struct reg *b_reg, struct linux_pt_regset *l_regset); +void linux_to_bsd_regset(struct reg *b_reg, + const struct linux_pt_regset *l_regset); + #endif /* !_AMD64_LINUX_H_ */ diff --git a/sys/amd64/linux/linux_machdep.c b/sys/amd64/linux/linux_machdep.c index c34d98e86d0b..e2346f68da3a 100644 --- a/sys/amd64/linux/linux_machdep.c +++ b/sys/amd64/linux/linux_machdep.c @@ -330,3 +330,34 @@ bsd_to_linux_regset(const struct reg *b_reg, struct linux_pt_regset *l_regset) l_regset->fs = b_reg->r_fs; l_regset->gs = b_reg->r_gs; } + +void +linux_to_bsd_regset(struct reg *b_reg, const struct linux_pt_regset *l_regset) +{ + + b_reg->r_r15 = l_regset->r15; + b_reg->r_r14 = l_regset->r14; + b_reg->r_r13 = l_regset->r13; + b_reg->r_r12 = l_regset->r12; + b_reg->r_rbp = l_regset->rbp; + b_reg->r_rbx = l_regset->rbx; + b_reg->r_r11 = l_regset->r11; + b_reg->r_r10 = l_regset->r10; + b_reg->r_r9 = l_regset->r9; + b_reg->r_r8 = l_regset->r8; + b_reg->r_rax = l_regset->rax; + b_reg->r_rcx = l_regset->rcx; + b_reg->r_rdx = l_regset->rdx; + b_reg->r_rsi = l_regset->rsi; + b_reg->r_rdi = l_regset->rdi; + b_reg->r_rax = l_regset->orig_rax; + b_reg->r_rip = l_regset->rip; + b_reg->r_cs = l_regset->cs; + b_reg->r_rflags = l_regset->eflags; + b_reg->r_rsp = l_regset->rsp; + b_reg->r_ss = l_regset->ss; + b_reg->r_ds = l_regset->ds; + b_reg->r_es = l_regset->es; + b_reg->r_fs = l_regset->fs; + b_reg->r_gs = l_regset->gs; +} diff --git a/sys/amd64/linux/linux_ptrace.c b/sys/amd64/linux/linux_ptrace.c index 0f06f2aa9c5c..191e6265b39c 100644 --- a/sys/amd64/linux/linux_ptrace.c +++ b/sys/amd64/linux/linux_ptrace.c @@ -168,30 +168,6 @@ linux_ptrace_status(struct thread *td, pid_t pid, int status) return (status); } -struct linux_pt_reg { - l_ulong r15; - l_ulong r14; - l_ulong r13; - l_ulong r12; - l_ulong rbp; - l_ulong rbx; - l_ulong r11; - l_ulong r10; - l_ulong r9; - l_ulong r8; - l_ulong rax; - l_ulong rcx; - l_ulong rdx; - l_ulong rsi; - l_ulong rdi; - l_ulong orig_rax; - l_ulong rip; - l_ulong cs; - l_ulong eflags; - l_ulong rsp; - l_ulong ss; -}; - struct syscall_info { uint8_t op; uint32_t arch; @@ -214,42 +190,6 @@ struct syscall_info { }; }; -static void -map_regs_from_linux(struct reg *b_reg, struct linux_pt_reg *l_reg) -{ - b_reg->r_r15 = l_reg->r15; - b_reg->r_r14 = l_reg->r14; - b_reg->r_r13 = l_reg->r13; - b_reg->r_r12 = l_reg->r12; - b_reg->r_r11 = l_reg->r11; - b_reg->r_r10 = l_reg->r10; - b_reg->r_r9 = l_reg->r9; - b_reg->r_r8 = l_reg->r8; - b_reg->r_rdi = l_reg->rdi; - b_reg->r_rsi = l_reg->rsi; - b_reg->r_rbp = l_reg->rbp; - b_reg->r_rbx = l_reg->rbx; - b_reg->r_rdx = l_reg->rdx; - b_reg->r_rcx = l_reg->rcx; - b_reg->r_rax = l_reg->rax; - - /* - * XXX: Are zeroes the right thing to put here? - */ - b_reg->r_trapno = 0; - b_reg->r_fs = 0; - b_reg->r_gs = 0; - b_reg->r_err = 0; - b_reg->r_es = 0; - b_reg->r_ds = 0; - - b_reg->r_rip = l_reg->rip; - b_reg->r_cs = l_reg->cs; - b_reg->r_rflags = l_reg->eflags; - b_reg->r_rsp = l_reg->rsp; - b_reg->r_ss = l_reg->ss; -} - static int linux_ptrace_peek(struct thread *td, pid_t pid, void *addr, void *data) { @@ -446,13 +386,13 @@ static int linux_ptrace_setregs(struct thread *td, pid_t pid, void *data) { struct reg b_reg; - struct linux_pt_reg l_reg; + struct linux_pt_regset l_regset; int error; - error = copyin(data, &l_reg, sizeof(l_reg)); + error = copyin(data, &l_regset, sizeof(l_regset)); if (error != 0) return (error); - map_regs_from_linux(&b_reg, &l_reg); + linux_to_bsd_regset(&b_reg, &l_regset); error = kern_ptrace(td, PT_SETREGS, pid, &b_reg, 0); return (error); }