From nobody Thu May 12 22:56:36 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 91AEF1AE4F44; Thu, 12 May 2022 22:56:38 +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 4KznFx0K0Sz3GP6; Thu, 12 May 2022 22:56:37 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1652396197; 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=C2HTnZMShs8u7a7tbG0e2AxXRxP6//nJzWAPobbutHY=; b=SH07RAQn9SNYXWLRQ/hb1iCqi1mB7XGd7FzvNeHxdEKsMczmqB+gjQm8q3+AECP7NrEE3T XDVkkwk/xKHkR6NE0GMhYq5DNrSDZsbZW/lSsoOTzhgeXNVuc5h7zu3QswatK6EKzaaAoN 5PAxOVaW2dR/3V34kZuhFtK9NC1P6j/wnpPA4vJELgm8b/ZT+u2ikYEmUDQoix5J/FLwRj Cus/DfJp7jemtb5FuR+ujJi5vud1nHRhl1f6y1Ez7JTYNVwSnuEitEEgyx4MBBG6mi/3Gx 3Y2gw9RaM9BbEMqdsK3bNxTSuJqSv5uoFRS00HbbU8EbM7w6M73mtU6O7L4Mwg== 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 D839617671; Thu, 12 May 2022 22:56:36 +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 24CMuaN7020720; Thu, 12 May 2022 22:56:36 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 24CMua0b020719; Thu, 12 May 2022 22:56:36 GMT (envelope-from git) Date: Thu, 12 May 2022 22:56:36 GMT Message-Id: <202205122256.24CMua0b020719@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: John Baldwin Subject: git: f0d88ce88589 - stable/13 - Store core dump notes for all valid register sets for FreeBSD processes. 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: jhb X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: f0d88ce885897efe90db2a7c81207379e4d4d8b1 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1652396197; 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=C2HTnZMShs8u7a7tbG0e2AxXRxP6//nJzWAPobbutHY=; b=b5GlqSzx+bAal9pwb/nfBQ5jDyhUBw4qgFtyYphnjZXFRCV5shM33fOwsV/XXDmkyUJyWi 0N/5sRU33q94YQhbZ71222zmVydvmQsvu4m/TAz252/QHoepco+9f/b0glz0RlD3MBVigF qaOth+7GkWJkGbdSKMlH5l7ETq9XtEQq8eLoH+impX7pWiF9rdWtkoCIyiNd52Khg0xaYj yIDj6/pUd7h8GE6BmA1yMGSqYvYmjNsujVwqra7rDfAObd2ALZOImTSVpHiw+xz+4TPrdH mg2GW22ubm11kLl7bvz6LGg04rm0CoUfBEvRTvup2rSk/6xnKJHr0qIWA5XQnw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1652396197; a=rsa-sha256; cv=none; b=er+sXV3VCklNEA/R3BzQXIRghYTTRFXjTW8V9G4MDEjyULVSwPXgKjbWUqR7acGodAMRut QwZxRpuTB33RYCtk8Y+XlKSe487AVUjpiJn2t1nVOJCydjh5RfV73lAVgx4XENetbFOU7u 93L3suETFktKZkX+9Eakha4NMN8UEU89wh8BpE6Q1R4aH041K5x3CjrZPiy8+6J4rQw+u+ BXLAknS6PYbO1Q2LvmlVYCA4yr70icbzcoVkVy3hawffl5MSuu5/Reily4/I9v9up7hpTe 7bV8QoTSCPUtuZwYNN6Woh7QDLbcJQrCQDrjHXLlZLDt9mIuZLeFRzz4Pm5KkA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=f0d88ce885897efe90db2a7c81207379e4d4d8b1 commit f0d88ce885897efe90db2a7c81207379e4d4d8b1 Author: John Baldwin AuthorDate: 2022-03-10 23:40:19 +0000 Commit: John Baldwin CommitDate: 2022-05-12 22:13:00 +0000 Store core dump notes for all valid register sets for FreeBSD processes. In particular, use a generic wrapper around struct regset rather than requiring per-regset helpers. This helper replaces the MI __elfN(note_prstatus) and __elfN(note_fpregset) helpers. It also removes the need to explicitly dump NT_ARM_ADDR_MASK in the arm64 __elfN(dump_thread). Reviewed by: markj, emaste Sponsored by: University of Cambridge, Google, Inc. Differential Revision: https://reviews.freebsd.org/D34446 (cherry picked from commit 6b71405bfe8dc76834603f8f9e48346c3f49eae0) Note that this does not remove NT_ARM_ADDR_MASK from the arm64 hook on stable/13 as NT_ARM_ADDR_MASK is not present in stable/13. --- sys/kern/imgact_elf.c | 110 +++++++++++++++++++++++++++++++++----------------- 1 file changed, 72 insertions(+), 38 deletions(-) diff --git a/sys/kern/imgact_elf.c b/sys/kern/imgact_elf.c index c39a865dcf05..f81f565cacc9 100644 --- a/sys/kern/imgact_elf.c +++ b/sys/kern/imgact_elf.c @@ -102,6 +102,8 @@ static boolean_t __elfN(check_note)(struct image_params *imgp, uint32_t *fctl0); static vm_prot_t __elfN(trans_prot)(Elf_Word); static Elf_Word __elfN(untrans_prot)(vm_prot_t); +static size_t __elfN(prepare_register_notes)(struct thread *td, + struct note_info_list *list, struct thread *target_td); SYSCTL_NODE(_kern, OID_AUTO, __CONCAT(elf, __ELF_WORD_SIZE), CTLFLAG_RW | CTLFLAG_MPSAFE, 0, @@ -1505,6 +1507,7 @@ struct phdr_closure { struct note_info { int type; /* Note type. */ + struct regset *regset; /* Register set. */ outfunc_t outfunc; /* Output function. */ void *outarg; /* Argument for the output function. */ size_t outsize; /* Output size. */ @@ -1524,9 +1527,7 @@ static int __elfN(corehdr)(struct coredump_params *, int, void *, size_t, struct note_info_list *, size_t, int); static void __elfN(putnote)(struct thread *td, struct note_info *, struct sbuf *); -static void __elfN(note_fpregset)(void *, struct sbuf *, size_t *); static void __elfN(note_prpsinfo)(void *, struct sbuf *, size_t *); -static void __elfN(note_prstatus)(void *, struct sbuf *, size_t *); static void __elfN(note_threadmd)(void *, struct sbuf *, size_t *); static void __elfN(note_thrmisc)(void *, struct sbuf *, size_t *); static void __elfN(note_ptlwpinfo)(void *, struct sbuf *, size_t *); @@ -1819,7 +1820,8 @@ __elfN(prepare_notes)(struct thread *td, struct note_info_list *list, p = td->td_proc; size = 0; - size += __elfN(register_note)(td, list, NT_PRPSINFO, __elfN(note_prpsinfo), p); + size += __elfN(register_note)(td, list, NT_PRPSINFO, + __elfN(note_prpsinfo), p); /* * To have the debugger select the right thread (LWP) as the initial @@ -1829,10 +1831,7 @@ __elfN(prepare_notes)(struct thread *td, struct note_info_list *list, */ thr = td; while (thr != NULL) { - size += __elfN(register_note)(td, list, NT_PRSTATUS, - __elfN(note_prstatus), thr); - size += __elfN(register_note)(td, list, NT_FPREGSET, - __elfN(note_fpregset), thr); + size += __elfN(prepare_register_notes)(td, list, thr); size += __elfN(register_note)(td, list, NT_THRMISC, __elfN(note_thrmisc), thr); size += __elfN(register_note)(td, list, NT_PTLWPINFO, @@ -1952,6 +1951,34 @@ __elfN(puthdr)(struct thread *td, void *hdr, size_t hdrsize, int numsegs, each_dumpable_segment(td, cb_put_phdr, &phc, flags); } +static size_t +__elfN(register_regset_note)(struct thread *td, struct note_info_list *list, + struct regset *regset, struct thread *target_td) +{ + const struct sysentvec *sv; + struct note_info *ninfo; + size_t size, notesize; + + size = 0; + if (!regset->get(regset, target_td, NULL, &size) || size == 0) + return (0); + + ninfo = malloc(sizeof(*ninfo), M_TEMP, M_ZERO | M_WAITOK); + ninfo->type = regset->note; + ninfo->regset = regset; + ninfo->outarg = target_td; + ninfo->outsize = size; + TAILQ_INSERT_TAIL(list, ninfo, link); + + sv = td->td_proc->p_sysent; + notesize = sizeof(Elf_Note) + /* note header */ + roundup2(strlen(sv->sv_elf_core_abi_vendor) + 1, ELF_NOTE_ROUNDSIZE) + + /* note name */ + roundup2(size, ELF_NOTE_ROUNDSIZE); /* note description */ + + return (notesize); +} + size_t __elfN(register_note)(struct thread *td, struct note_info_list *list, int type, outfunc_t out, void *arg) @@ -2050,7 +2077,16 @@ __elfN(putnote)(struct thread *td, struct note_info *ninfo, struct sbuf *sb) if (note.n_descsz == 0) return; sbuf_start_section(sb, &old_len); - ninfo->outfunc(ninfo->outarg, sb, &ninfo->outsize); + if (ninfo->regset != NULL) { + struct regset *regset = ninfo->regset; + void *buf; + + buf = malloc(ninfo->outsize, M_TEMP, M_ZERO | M_WAITOK); + (void)regset->get(regset, ninfo->outarg, buf, &ninfo->outsize); + sbuf_bcat(sb, buf, ninfo->outsize); + free(buf, M_TEMP); + } else + ninfo->outfunc(ninfo->outarg, sb, &ninfo->outsize); sect_len = sbuf_end_section(sb, old_len, ELF_NOTE_ROUNDSIZE, 0); if (sect_len < 0) return; @@ -2222,24 +2258,6 @@ static struct regset __elfN(regset_prstatus) = { }; ELF_REGSET(__elfN(regset_prstatus)); -static void -__elfN(note_prstatus)(void *arg, struct sbuf *sb, size_t *sizep) -{ - struct thread *td; - elf_prstatus_t *status; - - td = arg; - if (sb != NULL) { - KASSERT(*sizep == sizeof(*status), ("%s: invalid size", - __func__)); - status = malloc(sizeof(*status), M_TEMP, M_ZERO | M_WAITOK); - __elfN(get_prstatus)(NULL, td, status, sizep); - sbuf_bcat(sb, status, sizeof(*status)); - free(status, M_TEMP); - } - *sizep = sizeof(*status); -} - static bool __elfN(get_fpregset)(struct regset *rs, struct thread *td, void *buf, size_t *sizep) @@ -2284,21 +2302,37 @@ static struct regset __elfN(regset_fpregset) = { }; ELF_REGSET(__elfN(regset_fpregset)); -static void -__elfN(note_fpregset)(void *arg, struct sbuf *sb, size_t *sizep) +static size_t +__elfN(prepare_register_notes)(struct thread *td, struct note_info_list *list, + struct thread *target_td) { - struct thread *td; - elf_prfpregset_t *fpregset; + struct sysentvec *sv = td->td_proc->p_sysent; + struct regset **regsetp, **regset_end, *regset; + size_t size; - td = arg; - if (sb != NULL) { - KASSERT(*sizep == sizeof(*fpregset), ("invalid size")); - fpregset = malloc(sizeof(*fpregset), M_TEMP, M_ZERO | M_WAITOK); - __elfN(get_fpregset)(NULL, td, fpregset, sizep); - sbuf_bcat(sb, fpregset, sizeof(*fpregset)); - free(fpregset, M_TEMP); + size = 0; + + /* NT_PRSTATUS must be the first register set note. */ + size += __elfN(register_regset_note)(td, list, &__elfN(regset_prstatus), + target_td); + + regsetp = sv->sv_regset_begin; + if (regsetp == NULL) { + /* XXX: This shouldn't be true for any FreeBSD ABIs. */ + size += __elfN(register_regset_note)(td, list, + &__elfN(regset_fpregset), target_td); + return (size); } - *sizep = sizeof(*fpregset); + regset_end = sv->sv_regset_end; + MPASS(regset_end != NULL); + for (; regsetp < regset_end; regsetp++) { + regset = *regsetp; + if (regset->note == NT_PRSTATUS) + continue; + size += __elfN(register_regset_note)(td, list, regset, + target_td); + } + return (size); } static void