From nobody Wed Mar 23 20:33:19 2022 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 8299E1A29D3A; Wed, 23 Mar 2022 20:33: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 4KP0Rg2xHfz4g29; Wed, 23 Mar 2022 20:33:19 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1648067599; 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=JtoNVumnrzhFB0fqKO18YM8gFw/yfiZQsoctrCIxe9o=; b=M25YKI9omW8lAjYLy2lv0/iMm55tlWUmIByl9hDgpMTdzUKH7f3i/bidcBlhBj+HNaEsPS DPKo8Vhw7ZWtFpNbGZq28F8kj/XJZDf6cnUoW8pWSjGWX2DpO0MFCL48tN0PbCJY5T5O8D tNjUn2qdq95SBhU+h+6pGYnDo5vGE2El+Qzb1shBCzzQWY3TaVyDIaXS5DjvDcyMj7f+9/ 3MntpgitH1UFjcO+yM9kYS4c1TYPL2OSONug3EqbCeWNJOD34PIrR5TxQBZG+W5VZXAqQI Jo5FbgYoP8/+1qf46nEo5PaSbrwj2SuIun3KpGRAeeiASWOvih3m3urtufjATg== 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 3B51422EC; Wed, 23 Mar 2022 20:33: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 22NKXJhx075713; Wed, 23 Mar 2022 20:33:19 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 22NKXJrU075712; Wed, 23 Mar 2022 20:33:19 GMT (envelope-from git) Date: Wed, 23 Mar 2022 20:33:19 GMT Message-Id: <202203232033.22NKXJrU075712@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: John Baldwin Subject: git: add00c381e5c - main - Use a regset for NT_ARM_VFP. 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: jhb X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: add00c381e5c9938133061c401dcba764009cafc Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1648067599; 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=JtoNVumnrzhFB0fqKO18YM8gFw/yfiZQsoctrCIxe9o=; b=HlCADbJj8Hd++5/uFwGboAB8VzsH0XLvlptsdKJzCUfcLi9nZdgu6ayr0BfiHt1ZEKrQEQ FS5G0eOkF+DD2Oex2F1SvqmxjgGi2ugUuCb+fcQuUvydv/6eRYtOl1ymQzapXpPfkhuMAy CYMbahtaBqkHTO/6VOAUOgsP/NgBn0N8yGCjZelVZxFMhZaisNlLNLXgBb46pZS4P+sKNB jcT2pJUAQl34TCaCdeN9fqDnbwgfjWh31v6yjHfQfIJRM2I22kXYMM1Xcuv5vy4D2IDoLI 8ybDGaYJYf19mez/fUnS3FtwAHf/LsA2TstlELD91grgmbeWgovN+tLE5H2BUg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1648067599; a=rsa-sha256; cv=none; b=NvP+JZnSAtNETN/xdsf/OdwbFeMqBSHh/2v2PShetEyUUDi29zyzrr3LrnaR5f/N6Pv3ok qgUQ0plL6p6g2haLs5B1IwMmTb3jKpC7izSr5+eZP77d7wxoUKGiuPewu5QDj0CjFMi6H7 pmKmn5EPPcOym7ce0X8z9RSJUAMRZDWm5p5UfHiaik1l2j5aY6pGxDQFzORxFiVkws/JTn ZVvyzwAjcxFUtcavtoXGQAc2eesC4Ysy/PIjS/yKu2Lp4glk5uQYU3uQWalPynh0TaHX9n Po8j72FRXWNFQf0hGR1UqLJuyGdSkhNzIVJbPJ5VvB8v76+/0yeyyB5I+IcWvQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=add00c381e5c9938133061c401dcba764009cafc commit add00c381e5c9938133061c401dcba764009cafc Author: John Baldwin AuthorDate: 2022-03-23 20:33:06 +0000 Commit: John Baldwin CommitDate: 2022-03-23 20:33:06 +0000 Use a regset for NT_ARM_VFP. This includes adding support for NT_ARM_VFP for 32-bit binaries running under aarch64 kernels both for ptrace(), and coredumps via the kernel and gcore. Reviewed by: andrew, markj Sponsored by: University of Cambridge, Google, Inc. Differential Revision: https://reviews.freebsd.org/D34448 --- sys/arm/arm/elf_machdep.c | 14 ++------------ sys/arm/arm/ptrace_machdep.c | 33 +++++++++++++++++++++++++++++++++ sys/arm64/arm64/elf32_machdep.c | 1 - sys/arm64/arm64/freebsd32_machdep.c | 9 +++------ sys/arm64/arm64/ptrace_machdep.c | 33 +++++++++++++++++++++++++++++++++ sys/arm64/include/vfp.h | 5 +++++ usr.bin/gcore/elfcore.c | 7 ++----- 7 files changed, 78 insertions(+), 24 deletions(-) diff --git a/sys/arm/arm/elf_machdep.c b/sys/arm/arm/elf_machdep.c index d993ba57c7d0..735c00766f9b 100644 --- a/sys/arm/arm/elf_machdep.c +++ b/sys/arm/arm/elf_machdep.c @@ -145,19 +145,9 @@ elf32_arm_abi_supported(struct image_params *imgp, int32_t *osrel __unused, } void -elf32_dump_thread(struct thread *td, void *dst, size_t *off) +elf32_dump_thread(struct thread *td __unused, void *dst __unused, + size_t *off __unused) { -#ifdef VFP - mcontext_vfp_t vfp; - - if (dst != NULL) { - get_vfpcontext(td, &vfp); - *off = elf32_populate_note(NT_ARM_VFP, &vfp, dst, sizeof(vfp), - NULL); - } else - *off = elf32_populate_note(NT_ARM_VFP, NULL, NULL, sizeof(vfp), - NULL); -#endif } bool diff --git a/sys/arm/arm/ptrace_machdep.c b/sys/arm/arm/ptrace_machdep.c index 563f962dc473..d8acc58d0fd0 100644 --- a/sys/arm/arm/ptrace_machdep.c +++ b/sys/arm/arm/ptrace_machdep.c @@ -28,12 +28,45 @@ __FBSDID("$FreeBSD$"); #include +#include #include #include +#include #ifdef VFP #include #endif +#ifdef VFP +static bool +get_arm_vfp(struct regset *rs, struct thread *td, void *buf, size_t *sizep) +{ + if (buf != NULL) { + KASSERT(*sizep == sizeof(mcontext_vfp_t), + ("%s: invalid size", __func__)); + get_vfpcontext(td, buf); + } + *sizep = sizeof(mcontext_vfp_t); + return (true); +} + +static bool +set_arm_vfp(struct regset *rs, struct thread *td, void *buf, + size_t size) +{ + KASSERT(size == sizeof(mcontext_vfp_t), ("%s: invalid size", __func__)); + set_vfpcontext(td, buf); + return (true); +} + +static struct regset regset_arm_vfp = { + .note = NT_ARM_VFP, + .size = sizeof(mcontext_vfp_t), + .get = get_arm_vfp, + .set = set_arm_vfp, +}; +ELF_REGSET(regset_arm_vfp); +#endif + int cpu_ptrace(struct thread *td, int req, void *addr, int data) { diff --git a/sys/arm64/arm64/elf32_machdep.c b/sys/arm64/arm64/elf32_machdep.c index 919ef20425a3..685a328a9595 100644 --- a/sys/arm64/arm64/elf32_machdep.c +++ b/sys/arm64/arm64/elf32_machdep.c @@ -288,5 +288,4 @@ freebsd32_setregs(struct thread *td, struct image_params *imgp, void elf32_dump_thread(struct thread *td, void *dst, size_t *off) { - /* XXX: VFP */ } diff --git a/sys/arm64/arm64/freebsd32_machdep.c b/sys/arm64/arm64/freebsd32_machdep.c index c4bb515becf7..3997b1ea6ab5 100644 --- a/sys/arm64/arm64/freebsd32_machdep.c +++ b/sys/arm64/arm64/freebsd32_machdep.c @@ -61,10 +61,6 @@ extern void freebsd32_sendsig(sig_t catcher, ksiginfo_t *ksi, sigset_t *mask); */ #define UC32_COPY_SIZE offsetof(ucontext32_t, uc_link) -#ifdef VFP -static void get_fpcontext32(struct thread *td, mcontext32_vfp_t *); -#endif - /* * Stubs for machine dependent 32-bits system calls. */ @@ -127,7 +123,7 @@ freebsd32_sysarch(struct thread *td, struct freebsd32_sysarch_args *uap) } #ifdef VFP -static void +void get_fpcontext32(struct thread *td, mcontext32_vfp_t *mcp) { struct pcb *pcb; @@ -159,7 +155,7 @@ get_fpcontext32(struct thread *td, mcontext32_vfp_t *mcp) } } -static void +void set_fpcontext32(struct thread *td, mcontext32_vfp_t *mcp) { struct pcb *pcb; @@ -176,6 +172,7 @@ set_fpcontext32(struct thread *td, mcontext32_vfp_t *mcp) critical_exit(); } #endif + static void get_mcontext32(struct thread *td, mcontext32_t *mcp, int flags) { diff --git a/sys/arm64/arm64/ptrace_machdep.c b/sys/arm64/arm64/ptrace_machdep.c index 3f362e5343cd..eac1ebe79ae9 100644 --- a/sys/arm64/arm64/ptrace_machdep.c +++ b/sys/arm64/arm64/ptrace_machdep.c @@ -30,6 +30,7 @@ __FBSDID("$FreeBSD$"); #include #include +#include #include #include #include @@ -48,6 +49,38 @@ __FBSDID("$FreeBSD$"); #include +#if defined(VFP) && defined(COMPAT_FREEBSD32) +static bool +get_arm_vfp(struct regset *rs, struct thread *td, void *buf, size_t *sizep) +{ + if (buf != NULL) { + KASSERT(*sizep == sizeof(mcontext32_vfp_t), + ("%s: invalid size", __func__)); + get_fpcontext32(td, buf); + } + *sizep = sizeof(mcontext32_vfp_t); + return (true); +} + +static bool +set_arm_vfp(struct regset *rs, struct thread *td, void *buf, + size_t size) +{ + KASSERT(size == sizeof(mcontext32_vfp_t), ("%s: invalid size", + __func__)); + set_fpcontext32(td, buf); + return (true); +} + +static struct regset regset_arm_vfp = { + .note = NT_ARM_VFP, + .size = sizeof(mcontext32_vfp_t), + .get = get_arm_vfp, + .set = set_arm_vfp, +}; +ELF32_REGSET(regset_arm_vfp); +#endif + int ptrace_set_pc(struct thread *td, u_long addr) { diff --git a/sys/arm64/include/vfp.h b/sys/arm64/include/vfp.h index bee0121d9d2a..b28c6edf3c53 100644 --- a/sys/arm64/include/vfp.h +++ b/sys/arm64/include/vfp.h @@ -94,6 +94,11 @@ int is_fpu_kern_thread(u_int); #define VFP_FPSR_FROM_FPSCR(vpscr) ((vpscr) &~ 0x7c00000) #define VFP_FPCR_FROM_FPSCR(vpsrc) ((vpsrc) & 0x7c00000) +#ifdef COMPAT_FREEBSD32 +void get_fpcontext32(struct thread *td, mcontext32_vfp_t *mcp); +void set_fpcontext32(struct thread *td, mcontext32_vfp_t *mcp); +#endif + #endif #endif diff --git a/usr.bin/gcore/elfcore.c b/usr.bin/gcore/elfcore.c index b93ef7ed92d6..42d90aaaf155 100644 --- a/usr.bin/gcore/elfcore.c +++ b/usr.bin/gcore/elfcore.c @@ -110,9 +110,6 @@ static void elf_detach(void); /* atexit() handler. */ static void *elf_note_prpsinfo(void *, size_t *); static void *elf_note_thrmisc(void *, size_t *); static void *elf_note_ptlwpinfo(void *, size_t *); -#if defined(__arm__) -static void *elf_note_arm_vfp(void *, size_t *); -#endif #if defined(__i386__) || defined(__amd64__) static void *elf_note_x86_xstate(void *, size_t *); #endif @@ -375,8 +372,8 @@ elf_putnotes(pid_t pid, struct sbuf *sb, size_t *sizep) elf_putregnote(NT_FPREGSET, tids[i], sb); elf_putnote(NT_THRMISC, elf_note_thrmisc, tids + i, sb); elf_putnote(NT_PTLWPINFO, elf_note_ptlwpinfo, tids + i, sb); -#if defined(__arm__) - elf_putnote(NT_ARM_VFP, elf_note_arm_vfp, tids + i, sb); +#if (defined(ELFCORE_COMPAT_32) && defined(__aarch64__)) || defined(__arm__) + elf_putregnote(NT_ARM_VFP, tids[i], sb); #endif #if defined(__i386__) || defined(__amd64__) elf_putnote(NT_X86_XSTATE, elf_note_x86_xstate, tids + i, sb);