Date: Tue, 29 Jun 2021 07:58:04 GMT From: Edward Tomasz Napierala <trasz@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org Subject: git: 435754a59ee2 - main - Add infrastructure required for Linux coredump support Message-ID: <202106290758.15T7w4GB008232@gitrepo.freebsd.org>
next in thread | raw e-mail | index | archive | help
The branch main has been updated by trasz: URL: https://cgit.FreeBSD.org/src/commit/?id=435754a59ee203c3369f47ff9103f269c81581b7 commit 435754a59ee203c3369f47ff9103f269c81581b7 Author: Edward Tomasz Napierala <trasz@FreeBSD.org> AuthorDate: 2021-06-29 07:49:04 +0000 Commit: Edward Tomasz Napierala <trasz@FreeBSD.org> CommitDate: 2021-06-29 07:49:12 +0000 Add infrastructure required for Linux coredump support This adds `sv_elf_core_osabi`, `sv_elf_core_abi_vendor`, and `sv_elf_core_prepare_notes` fields to `struct sysentvec`, and modifies imgact_elf.c to make use of them instead of hardcoding FreeBSD-specific values. It also updates all of the ABI definitions to preserve current behaviour. This makes it possible to implement non-native ELF coredump support without unnecessary code duplication. It will be used for Linux coredumps. Reviewed By: kib Sponsored By: EPSRC Differential Revision: https://reviews.freebsd.org/D30921 --- sys/amd64/amd64/elf_machdep.c | 6 +++ sys/amd64/cloudabi32/cloudabi32_sysvec.c | 3 ++ sys/amd64/cloudabi64/cloudabi64_sysvec.c | 3 ++ sys/amd64/linux/linux_sysvec.c | 3 ++ sys/amd64/linux32/linux32_sysvec.c | 3 ++ sys/arm/arm/elf_machdep.c | 3 ++ sys/arm/cloudabi32/cloudabi32_sysvec.c | 3 ++ sys/arm64/arm64/elf32_machdep.c | 3 ++ sys/arm64/arm64/elf_machdep.c | 3 ++ sys/arm64/cloudabi32/cloudabi32_sysvec.c | 3 ++ sys/arm64/cloudabi64/cloudabi64_sysvec.c | 3 ++ sys/arm64/linux/linux_sysvec.c | 3 ++ sys/compat/ia32/ia32_sysvec.c | 3 ++ sys/i386/i386/elf_machdep.c | 3 ++ sys/i386/linux/linux_sysvec.c | 3 ++ sys/kern/imgact_elf.c | 66 ++++++++++++++++---------------- sys/mips/mips/elf_machdep.c | 2 + sys/mips/mips/freebsd32_machdep.c | 3 ++ sys/powerpc/powerpc/elf32_machdep.c | 3 ++ sys/powerpc/powerpc/elf64_machdep.c | 6 +++ sys/riscv/riscv/elf_machdep.c | 3 ++ sys/sys/imgact_elf.h | 11 +++++- sys/sys/sysent.h | 5 +++ 23 files changed, 113 insertions(+), 34 deletions(-) diff --git a/sys/amd64/amd64/elf_machdep.c b/sys/amd64/amd64/elf_machdep.c index a3fb1184bb05..a7cef2a8d92a 100644 --- a/sys/amd64/amd64/elf_machdep.c +++ b/sys/amd64/amd64/elf_machdep.c @@ -59,6 +59,9 @@ struct sysentvec elf64_freebsd_sysvec_la48 = { .sv_szsigcode = &szsigcode, .sv_name = "FreeBSD ELF64", .sv_coredump = __elfN(coredump), + .sv_elf_core_osabi = ELFOSABI_FREEBSD, + .sv_elf_core_abi_vendor = FREEBSD_ABI_VENDOR, + .sv_elf_core_prepare_notes = __elfN(prepare_notes), .sv_imgact_try = NULL, .sv_minsigstksz = MINSIGSTKSZ, .sv_minuser = VM_MIN_ADDRESS, @@ -94,6 +97,9 @@ struct sysentvec elf64_freebsd_sysvec_la57 = { .sv_szsigcode = &szsigcode, .sv_name = "FreeBSD ELF64", .sv_coredump = __elfN(coredump), + .sv_elf_core_osabi = ELFOSABI_FREEBSD, + .sv_elf_core_abi_vendor = FREEBSD_ABI_VENDOR, + .sv_elf_core_prepare_notes = __elfN(prepare_notes), .sv_imgact_try = NULL, .sv_minsigstksz = MINSIGSTKSZ, .sv_minuser = VM_MIN_ADDRESS, diff --git a/sys/amd64/cloudabi32/cloudabi32_sysvec.c b/sys/amd64/cloudabi32/cloudabi32_sysvec.c index 5f04c35a5c72..164f87e90e91 100644 --- a/sys/amd64/cloudabi32/cloudabi32_sysvec.c +++ b/sys/amd64/cloudabi32/cloudabi32_sysvec.c @@ -209,6 +209,9 @@ static struct sysentvec cloudabi32_elf_sysvec = { .sv_fixup = cloudabi32_fixup_tcb, .sv_name = "CloudABI ELF32", .sv_coredump = elf32_coredump, + .sv_elf_core_osabi = ELFOSABI_FREEBSD, + .sv_elf_core_abi_vendor = FREEBSD_ABI_VENDOR, + .sv_elf_core_prepare_notes = elf32_prepare_notes, .sv_minuser = FREEBSD32_MINUSER, .sv_maxuser = FREEBSD32_MAXUSER, .sv_stackprot = VM_PROT_READ | VM_PROT_WRITE, diff --git a/sys/amd64/cloudabi64/cloudabi64_sysvec.c b/sys/amd64/cloudabi64/cloudabi64_sysvec.c index 34ad0aedfe8b..d3893902b08e 100644 --- a/sys/amd64/cloudabi64/cloudabi64_sysvec.c +++ b/sys/amd64/cloudabi64/cloudabi64_sysvec.c @@ -197,6 +197,9 @@ static struct sysentvec cloudabi64_elf_sysvec = { .sv_fixup = cloudabi64_fixup_tcb, .sv_name = "CloudABI ELF64", .sv_coredump = elf64_coredump, + .sv_elf_core_osabi = ELFOSABI_FREEBSD, + .sv_elf_core_abi_vendor = FREEBSD_ABI_VENDOR, + .sv_elf_core_prepare_notes = elf64_prepare_notes, .sv_minuser = VM_MIN_ADDRESS, /* Keep top page reserved to work around AMD Ryzen stability issues. */ .sv_maxuser = VM_MAXUSER_ADDRESS - PAGE_SIZE, diff --git a/sys/amd64/linux/linux_sysvec.c b/sys/amd64/linux/linux_sysvec.c index 32db8399ad42..655214b10047 100644 --- a/sys/amd64/linux/linux_sysvec.c +++ b/sys/amd64/linux/linux_sysvec.c @@ -740,6 +740,9 @@ struct sysentvec elf_linux_sysvec = { .sv_szsigcode = &linux_szsigcode, .sv_name = "Linux ELF64", .sv_coredump = elf64_coredump, + .sv_elf_core_osabi = ELFOSABI_NONE, + .sv_elf_core_abi_vendor = FREEBSD_ABI_VENDOR, + .sv_elf_core_prepare_notes = elf64_prepare_notes, .sv_imgact_try = linux_exec_imgact_try, .sv_minsigstksz = LINUX_MINSIGSTKSZ, .sv_minuser = VM_MIN_ADDRESS, diff --git a/sys/amd64/linux32/linux32_sysvec.c b/sys/amd64/linux32/linux32_sysvec.c index 8e3e728161ce..740e8a54a4da 100644 --- a/sys/amd64/linux32/linux32_sysvec.c +++ b/sys/amd64/linux32/linux32_sysvec.c @@ -912,6 +912,9 @@ struct sysentvec elf_linux_sysvec = { .sv_szsigcode = &linux_szsigcode, .sv_name = "Linux ELF32", .sv_coredump = elf32_coredump, + .sv_elf_core_osabi = ELFOSABI_FREEBSD, + .sv_elf_core_abi_vendor = FREEBSD_ABI_VENDOR, + .sv_elf_core_prepare_notes = elf32_prepare_notes, .sv_imgact_try = linux_exec_imgact_try, .sv_minsigstksz = LINUX_MINSIGSTKSZ, .sv_minuser = VM_MIN_ADDRESS, diff --git a/sys/arm/arm/elf_machdep.c b/sys/arm/arm/elf_machdep.c index d32dbb5baf90..c67cd225a1af 100644 --- a/sys/arm/arm/elf_machdep.c +++ b/sys/arm/arm/elf_machdep.c @@ -72,6 +72,9 @@ struct sysentvec elf32_freebsd_sysvec = { .sv_szsigcode = &szsigcode, .sv_name = "FreeBSD ELF32", .sv_coredump = __elfN(coredump), + .sv_elf_core_osabi = ELFOSABI_FREEBSD, + .sv_elf_core_abi_vendor = FREEBSD_ABI_VENDOR, + .sv_elf_core_prepare_notes = __elfN(prepare_notes), .sv_imgact_try = NULL, .sv_minsigstksz = MINSIGSTKSZ, .sv_minuser = VM_MIN_ADDRESS, diff --git a/sys/arm/cloudabi32/cloudabi32_sysvec.c b/sys/arm/cloudabi32/cloudabi32_sysvec.c index c6dfe0661b7c..a8c5da47d265 100644 --- a/sys/arm/cloudabi32/cloudabi32_sysvec.c +++ b/sys/arm/cloudabi32/cloudabi32_sysvec.c @@ -173,6 +173,9 @@ static struct sysentvec cloudabi32_elf_sysvec = { .sv_fixup = cloudabi32_fixup, .sv_name = "CloudABI ELF32", .sv_coredump = elf32_coredump, + .sv_elf_core_osabi = ELFOSABI_FREEBSD, + .sv_elf_core_abi_vendor = FREEBSD_ABI_VENDOR, + .sv_elf_core_prepare_notes = elf32_prepare_notes, .sv_minuser = VM_MIN_ADDRESS, .sv_maxuser = VM_MAXUSER_ADDRESS, .sv_stackprot = VM_PROT_READ | VM_PROT_WRITE, diff --git a/sys/arm64/arm64/elf32_machdep.c b/sys/arm64/arm64/elf32_machdep.c index b9669616e1dd..7792374f865b 100644 --- a/sys/arm64/arm64/elf32_machdep.c +++ b/sys/arm64/arm64/elf32_machdep.c @@ -87,6 +87,9 @@ static struct sysentvec elf32_freebsd_sysvec = { .sv_szsigcode = &sz_aarch32_sigcode, .sv_name = "FreeBSD ELF32", .sv_coredump = elf32_coredump, + .sv_elf_core_osabi = ELFOSABI_FREEBSD, + .sv_elf_core_abi_vendor = FREEBSD_ABI_VENDOR, + .sv_elf_core_prepare_notes = elf32_prepare_notes, .sv_imgact_try = NULL, .sv_minsigstksz = MINSIGSTKSZ, .sv_minuser = FREEBSD32_MINUSER, diff --git a/sys/arm64/arm64/elf_machdep.c b/sys/arm64/arm64/elf_machdep.c index cd12d40c37df..82ecdf894911 100644 --- a/sys/arm64/arm64/elf_machdep.c +++ b/sys/arm64/arm64/elf_machdep.c @@ -68,6 +68,9 @@ static struct sysentvec elf64_freebsd_sysvec = { .sv_szsigcode = &szsigcode, .sv_name = "FreeBSD ELF64", .sv_coredump = __elfN(coredump), + .sv_elf_core_osabi = ELFOSABI_FREEBSD, + .sv_elf_core_abi_vendor = FREEBSD_ABI_VENDOR, + .sv_elf_core_prepare_notes = __elfN(prepare_notes), .sv_imgact_try = NULL, .sv_minsigstksz = MINSIGSTKSZ, .sv_minuser = VM_MIN_ADDRESS, diff --git a/sys/arm64/cloudabi32/cloudabi32_sysvec.c b/sys/arm64/cloudabi32/cloudabi32_sysvec.c index eb8c51742dc7..889393560ede 100644 --- a/sys/arm64/cloudabi32/cloudabi32_sysvec.c +++ b/sys/arm64/cloudabi32/cloudabi32_sysvec.c @@ -181,6 +181,9 @@ static struct sysentvec cloudabi32_elf_sysvec = { .sv_fixup = cloudabi32_fixup, .sv_name = "CloudABI ELF32", .sv_coredump = elf32_coredump, + .sv_elf_core_osabi = ELFOSABI_FREEBSD, + .sv_elf_core_abi_vendor = FREEBSD_ABI_VENDOR, + .sv_elf_core_prepare_notes = elf32_prepare_notes, .sv_minuser = VM_MIN_ADDRESS, .sv_maxuser = (uintmax_t)1 << 32, .sv_stackprot = VM_PROT_READ | VM_PROT_WRITE, diff --git a/sys/arm64/cloudabi64/cloudabi64_sysvec.c b/sys/arm64/cloudabi64/cloudabi64_sysvec.c index 92deb356a112..bdbd828b7b62 100644 --- a/sys/arm64/cloudabi64/cloudabi64_sysvec.c +++ b/sys/arm64/cloudabi64/cloudabi64_sysvec.c @@ -165,6 +165,9 @@ static struct sysentvec cloudabi64_elf_sysvec = { .sv_fixup = cloudabi64_fixup, .sv_name = "CloudABI ELF64", .sv_coredump = elf64_coredump, + .sv_elf_core_osabi = ELFOSABI_FREEBSD, + .sv_elf_core_abi_vendor = FREEBSD_ABI_VENDOR, + .sv_elf_core_prepare_notes = elf64_prepare_notes, .sv_minuser = VM_MIN_ADDRESS, .sv_maxuser = VM_MAXUSER_ADDRESS, .sv_stackprot = VM_PROT_READ | VM_PROT_WRITE, diff --git a/sys/arm64/linux/linux_sysvec.c b/sys/arm64/linux/linux_sysvec.c index afcca9f7e948..33bc303b5ada 100644 --- a/sys/arm64/linux/linux_sysvec.c +++ b/sys/arm64/linux/linux_sysvec.c @@ -416,6 +416,9 @@ struct sysentvec elf_linux_sysvec = { .sv_szsigcode = &linux_szsigcode, .sv_name = "Linux ELF64", .sv_coredump = elf64_coredump, + .sv_elf_core_osabi = ELFOSABI_NONE, + .sv_elf_core_abi_vendor = FREEBSD_ABI_VENDOR, + .sv_elf_core_prepare_notes = elf64_prepare_notes, .sv_imgact_try = linux_exec_imgact_try, .sv_minsigstksz = LINUX_MINSIGSTKSZ, .sv_minuser = VM_MIN_ADDRESS, diff --git a/sys/compat/ia32/ia32_sysvec.c b/sys/compat/ia32/ia32_sysvec.c index f5a2c1200fc6..2b019e3b0323 100644 --- a/sys/compat/ia32/ia32_sysvec.c +++ b/sys/compat/ia32/ia32_sysvec.c @@ -105,6 +105,9 @@ struct sysentvec ia32_freebsd_sysvec = { .sv_szsigcode = &sz_ia32_sigcode, .sv_name = "FreeBSD ELF32", .sv_coredump = elf32_coredump, + .sv_elf_core_osabi = ELFOSABI_FREEBSD, + .sv_elf_core_abi_vendor = FREEBSD_ABI_VENDOR, + .sv_elf_core_prepare_notes = elf32_prepare_notes, .sv_imgact_try = NULL, .sv_minsigstksz = MINSIGSTKSZ, .sv_minuser = FREEBSD32_MINUSER, diff --git a/sys/i386/i386/elf_machdep.c b/sys/i386/i386/elf_machdep.c index 0d870748967e..cb7b5617715c 100644 --- a/sys/i386/i386/elf_machdep.c +++ b/sys/i386/i386/elf_machdep.c @@ -61,6 +61,9 @@ struct sysentvec elf32_freebsd_sysvec = { .sv_szsigcode = &szsigcode, .sv_name = "FreeBSD ELF32", .sv_coredump = __elfN(coredump), + .sv_elf_core_osabi = ELFOSABI_FREEBSD, + .sv_elf_core_abi_vendor = FREEBSD_ABI_VENDOR, + .sv_elf_core_prepare_notes = __elfN(prepare_notes), .sv_imgact_try = NULL, .sv_minsigstksz = MINSIGSTKSZ, .sv_minuser = VM_MIN_ADDRESS, diff --git a/sys/i386/linux/linux_sysvec.c b/sys/i386/linux/linux_sysvec.c index 9cc15bbfd5c3..adb70fded6dc 100644 --- a/sys/i386/linux/linux_sysvec.c +++ b/sys/i386/linux/linux_sysvec.c @@ -854,6 +854,9 @@ struct sysentvec elf_linux_sysvec = { .sv_szsigcode = &linux_szsigcode, .sv_name = "Linux ELF32", .sv_coredump = elf32_coredump, + .sv_elf_core_osabi = ELFOSABI_FREEBSD, + .sv_elf_core_abi_vendor = FREEBSD_ABI_VENDOR, + .sv_elf_core_prepare_notes = elf32_prepare_notes, .sv_imgact_try = linux_exec_imgact_try, .sv_minsigstksz = LINUX_MINSIGSTKSZ, .sv_minuser = VM_MIN_ADDRESS, diff --git a/sys/kern/imgact_elf.c b/sys/kern/imgact_elf.c index 4a649664c917..8c56660b1fe4 100644 --- a/sys/kern/imgact_elf.c +++ b/sys/kern/imgact_elf.c @@ -197,8 +197,6 @@ static Elf_Brandinfo *elf_brand_list[MAX_BRANDS]; #define aligned(a, t) (rounddown2((u_long)(a), sizeof(t)) == (u_long)(a)) -static const char FREEBSD_ABI_VENDOR[] = "FreeBSD"; - Elf_Brandnote __elfN(freebsd_brandnote) = { .hdr.n_namesz = sizeof(FREEBSD_ABI_VENDOR), .hdr.n_descsz = sizeof(int32_t), @@ -1434,8 +1432,6 @@ struct phdr_closure { Elf_Off offset; /* Offset of segment in core file */ }; -typedef void (*outfunc_t)(void *, struct sbuf *, size_t *); - struct note_info { int type; /* Note type. */ outfunc_t outfunc; /* Output function. */ @@ -1455,10 +1451,7 @@ static void each_dumpable_segment(struct thread *, segment_callback, void *, int); static int __elfN(corehdr)(struct coredump_params *, int, void *, size_t, struct note_info_list *, size_t, int); -static void __elfN(prepare_notes)(struct thread *, struct note_info_list *, - size_t *); -static void __elfN(putnote)(struct note_info *, struct sbuf *); -static size_t register_note(struct note_info_list *, int, outfunc_t, void *); +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 *); @@ -1509,7 +1502,7 @@ __elfN(coredump)(struct thread *td, struct vnode *vp, off_t limit, int flags) hdrsize = sizeof(Elf_Ehdr) + sizeof(Elf_Phdr) * (1 + seginfo.count); if (seginfo.count + 1 >= PN_XNUM) hdrsize += sizeof(Elf_Shdr); - __elfN(prepare_notes)(td, ¬elst, ¬esz); + td->td_proc->p_sysent->sv_elf_core_prepare_notes(td, ¬elst, ¬esz); coresize = round_page(hdrsize + notesz) + seginfo.size; /* Set up core dump parameters. */ @@ -1735,7 +1728,7 @@ __elfN(corehdr)(struct coredump_params *p, int numsegs, void *hdr, sbuf_start_section(sb, NULL); sbuf_bcat(sb, hdr, hdrsize); TAILQ_FOREACH(ninfo, notelst, link) - __elfN(putnote)(ninfo, sb); + __elfN(putnote)(p->td, ninfo, sb); /* Align up to a page boundary for the program segments. */ sbuf_end_section(sb, -1, PAGE_SIZE, 0); error = sbuf_finish(sb); @@ -1744,7 +1737,7 @@ __elfN(corehdr)(struct coredump_params *p, int numsegs, void *hdr, return (error); } -static void +void __elfN(prepare_notes)(struct thread *td, struct note_info_list *list, size_t *sizep) { @@ -1755,7 +1748,7 @@ __elfN(prepare_notes)(struct thread *td, struct note_info_list *list, p = td->td_proc; size = 0; - size += register_note(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 @@ -1765,15 +1758,15 @@ __elfN(prepare_notes)(struct thread *td, struct note_info_list *list, */ thr = td; while (thr != NULL) { - size += register_note(list, NT_PRSTATUS, + size += __elfN(register_note)(td, list, NT_PRSTATUS, __elfN(note_prstatus), thr); - size += register_note(list, NT_FPREGSET, + size += __elfN(register_note)(td, list, NT_FPREGSET, __elfN(note_fpregset), thr); - size += register_note(list, NT_THRMISC, + size += __elfN(register_note)(td, list, NT_THRMISC, __elfN(note_thrmisc), thr); - size += register_note(list, NT_PTLWPINFO, + size += __elfN(register_note)(td, list, NT_PTLWPINFO, __elfN(note_ptlwpinfo), thr); - size += register_note(list, -1, + size += __elfN(register_note)(td, list, -1, __elfN(note_threadmd), thr); thr = thr == td ? TAILQ_FIRST(&p->p_threads) : @@ -1782,23 +1775,23 @@ __elfN(prepare_notes)(struct thread *td, struct note_info_list *list, thr = TAILQ_NEXT(thr, td_plist); } - size += register_note(list, NT_PROCSTAT_PROC, + size += __elfN(register_note)(td, list, NT_PROCSTAT_PROC, __elfN(note_procstat_proc), p); - size += register_note(list, NT_PROCSTAT_FILES, + size += __elfN(register_note)(td, list, NT_PROCSTAT_FILES, note_procstat_files, p); - size += register_note(list, NT_PROCSTAT_VMMAP, + size += __elfN(register_note)(td, list, NT_PROCSTAT_VMMAP, note_procstat_vmmap, p); - size += register_note(list, NT_PROCSTAT_GROUPS, + size += __elfN(register_note)(td, list, NT_PROCSTAT_GROUPS, note_procstat_groups, p); - size += register_note(list, NT_PROCSTAT_UMASK, + size += __elfN(register_note)(td, list, NT_PROCSTAT_UMASK, note_procstat_umask, p); - size += register_note(list, NT_PROCSTAT_RLIMIT, + size += __elfN(register_note)(td, list, NT_PROCSTAT_RLIMIT, note_procstat_rlimit, p); - size += register_note(list, NT_PROCSTAT_OSREL, + size += __elfN(register_note)(td, list, NT_PROCSTAT_OSREL, note_procstat_osrel, p); - size += register_note(list, NT_PROCSTAT_PSSTRINGS, + size += __elfN(register_note)(td, list, NT_PROCSTAT_PSSTRINGS, __elfN(note_procstat_psstrings), p); - size += register_note(list, NT_PROCSTAT_AUXV, + size += __elfN(register_note)(td, list, NT_PROCSTAT_AUXV, __elfN(note_procstat_auxv), p); *sizep = size; @@ -1822,7 +1815,7 @@ __elfN(puthdr)(struct thread *td, void *hdr, size_t hdrsize, int numsegs, ehdr->e_ident[EI_CLASS] = ELF_CLASS; ehdr->e_ident[EI_DATA] = ELF_DATA; ehdr->e_ident[EI_VERSION] = EV_CURRENT; - ehdr->e_ident[EI_OSABI] = ELFOSABI_FREEBSD; + ehdr->e_ident[EI_OSABI] = td->td_proc->p_sysent->sv_elf_core_osabi; ehdr->e_ident[EI_ABIVERSION] = 0; ehdr->e_ident[EI_PAD] = 0; ehdr->e_type = ET_CORE; @@ -1888,12 +1881,15 @@ __elfN(puthdr)(struct thread *td, void *hdr, size_t hdrsize, int numsegs, each_dumpable_segment(td, cb_put_phdr, &phc, flags); } -static size_t -register_note(struct note_info_list *list, int type, outfunc_t out, void *arg) +size_t +__elfN(register_note)(struct thread *td, struct note_info_list *list, + int type, outfunc_t out, void *arg) { + const struct sysentvec *sv; struct note_info *ninfo; size_t size, notesize; + sv = td->td_proc->p_sysent; size = 0; out(arg, NULL, &size); ninfo = malloc(sizeof(*ninfo), M_TEMP, M_ZERO | M_WAITOK); @@ -1907,7 +1903,7 @@ register_note(struct note_info_list *list, int type, outfunc_t out, void *arg) return (size); notesize = sizeof(Elf_Note) + /* note header */ - roundup2(sizeof(FREEBSD_ABI_VENDOR), ELF_NOTE_ROUNDSIZE) + + roundup2(strlen(sv->sv_elf_core_abi_vendor) + 1, ELF_NOTE_ROUNDSIZE) + /* note name */ roundup2(size, ELF_NOTE_ROUNDSIZE); /* note description */ @@ -1957,9 +1953,10 @@ __elfN(populate_note)(int type, void *src, void *dst, size_t size, void **descp) } static void -__elfN(putnote)(struct note_info *ninfo, struct sbuf *sb) +__elfN(putnote)(struct thread *td, struct note_info *ninfo, struct sbuf *sb) { Elf_Note note; + const struct sysentvec *sv; ssize_t old_len, sect_len; size_t new_len, descsz, i; @@ -1968,13 +1965,16 @@ __elfN(putnote)(struct note_info *ninfo, struct sbuf *sb) return; } - note.n_namesz = sizeof(FREEBSD_ABI_VENDOR); + sv = td->td_proc->p_sysent; + + note.n_namesz = strlen(sv->sv_elf_core_abi_vendor) + 1; note.n_descsz = ninfo->outsize; note.n_type = ninfo->type; sbuf_bcat(sb, ¬e, sizeof(note)); sbuf_start_section(sb, &old_len); - sbuf_bcat(sb, FREEBSD_ABI_VENDOR, sizeof(FREEBSD_ABI_VENDOR)); + sbuf_bcat(sb, sv->sv_elf_core_abi_vendor, + strlen(sv->sv_elf_core_abi_vendor) + 1); sbuf_end_section(sb, old_len, ELF_NOTE_ROUNDSIZE, 0); if (note.n_descsz == 0) return; diff --git a/sys/mips/mips/elf_machdep.c b/sys/mips/mips/elf_machdep.c index 9e27e5e7f2a4..9df6d1d36436 100644 --- a/sys/mips/mips/elf_machdep.c +++ b/sys/mips/mips/elf_machdep.c @@ -65,6 +65,8 @@ static struct sysentvec elf_freebsd_sysvec = { .sv_name = "FreeBSD ELF32", #endif .sv_coredump = __elfN(coredump), + .sv_elf_core_abi_vendor = FREEBSD_ABI_VENDOR, + .sv_elf_core_prepare_notes = __elfN(prepare_notes), .sv_imgact_try = NULL, .sv_minsigstksz = MINSIGSTKSZ, .sv_minuser = VM_MIN_ADDRESS, diff --git a/sys/mips/mips/freebsd32_machdep.c b/sys/mips/mips/freebsd32_machdep.c index 5d7fd4719efb..e30753e7a59c 100644 --- a/sys/mips/mips/freebsd32_machdep.c +++ b/sys/mips/mips/freebsd32_machdep.c @@ -85,6 +85,9 @@ struct sysentvec elf32_freebsd_sysvec = { .sv_szsigcode = &szsigcode32, .sv_name = "FreeBSD ELF32", .sv_coredump = __elfN(coredump), + .sv_elf_core_osabi = ELFOSABI_FREEBSD, + .sv_elf_core_abi_vendor = FREEBSD_ABI_VENDOR, + .sv_elf_core_prepare_notes = __elfN(prepare_notes), .sv_imgact_try = NULL, .sv_minsigstksz = MINSIGSTKSZ, .sv_minuser = VM_MIN_ADDRESS, diff --git a/sys/powerpc/powerpc/elf32_machdep.c b/sys/powerpc/powerpc/elf32_machdep.c index 04150f02bb9c..2c4928f7d9df 100644 --- a/sys/powerpc/powerpc/elf32_machdep.c +++ b/sys/powerpc/powerpc/elf32_machdep.c @@ -98,6 +98,9 @@ struct sysentvec elf32_freebsd_sysvec = { .sv_szsigcode = &szsigcode32, .sv_name = "FreeBSD ELF32", .sv_coredump = __elfN(coredump), + .sv_elf_core_osabi = ELFOSABI_FREEBSD, + .sv_elf_core_abi_vendor = FREEBSD_ABI_VENDOR, + .sv_elf_core_prepare_notes = __elfN(prepare_notes), .sv_imgact_try = NULL, .sv_minsigstksz = MINSIGSTKSZ, .sv_minuser = VM_MIN_ADDRESS, diff --git a/sys/powerpc/powerpc/elf64_machdep.c b/sys/powerpc/powerpc/elf64_machdep.c index 1bca857d9ca5..38f76c158793 100644 --- a/sys/powerpc/powerpc/elf64_machdep.c +++ b/sys/powerpc/powerpc/elf64_machdep.c @@ -69,6 +69,9 @@ struct sysentvec elf64_freebsd_sysvec_v1 = { .sv_szsigcode = &szsigcode64, .sv_name = "FreeBSD ELF64", .sv_coredump = __elfN(coredump), + .sv_elf_core_osabi = ELFOSABI_FREEBSD, + .sv_elf_core_abi_vendor = FREEBSD_ABI_VENDOR, + .sv_elf_core_prepare_notes = __elfN(prepare_notes), .sv_imgact_try = NULL, .sv_minsigstksz = MINSIGSTKSZ, .sv_minuser = VM_MIN_ADDRESS, @@ -105,6 +108,9 @@ struct sysentvec elf64_freebsd_sysvec_v2 = { .sv_szsigcode = &szsigcode64, .sv_name = "FreeBSD ELF64 V2", .sv_coredump = __elfN(coredump), + .sv_elf_core_osabi = ELFOSABI_FREEBSD, + .sv_elf_core_abi_vendor = FREEBSD_ABI_VENDOR, + .sv_elf_core_prepare_notes = __elfN(prepare_notes), .sv_imgact_try = NULL, .sv_minsigstksz = MINSIGSTKSZ, .sv_minuser = VM_MIN_ADDRESS, diff --git a/sys/riscv/riscv/elf_machdep.c b/sys/riscv/riscv/elf_machdep.c index 06d117128ef7..ee80e04e8c31 100644 --- a/sys/riscv/riscv/elf_machdep.c +++ b/sys/riscv/riscv/elf_machdep.c @@ -72,6 +72,9 @@ struct sysentvec elf64_freebsd_sysvec = { .sv_szsigcode = &szsigcode, .sv_name = "FreeBSD ELF64", .sv_coredump = __elfN(coredump), + .sv_elf_core_osabi = ELFOSABI_FREEBSD, + .sv_elf_core_abi_vendor = FREEBSD_ABI_VENDOR, + .sv_elf_core_prepare_notes = __elfN(prepare_notes), .sv_imgact_try = NULL, .sv_minsigstksz = MINSIGSTKSZ, .sv_minuser = VM_MIN_ADDRESS, diff --git a/sys/sys/imgact_elf.h b/sys/sys/imgact_elf.h index f0c112b2bcdc..44a860359a75 100644 --- a/sys/sys/imgact_elf.h +++ b/sys/sys/imgact_elf.h @@ -50,6 +50,8 @@ struct image_params; struct thread; struct vnode; +struct note_info_list; +struct sbuf; /* * Structure used to pass information from the loader to the @@ -98,7 +100,10 @@ typedef struct { __ElfType(Auxargs); __ElfType(Brandinfo); -#define MAX_BRANDS 8 +#define MAX_BRANDS 8 +#define FREEBSD_ABI_VENDOR "FreeBSD" + +typedef void (*outfunc_t)(void *, struct sbuf *, size_t *); /* Closure for __elfN(size_segments)(). */ struct sseg_closure { @@ -115,7 +120,11 @@ size_t __elfN(populate_note)(int, void *, void *, size_t, void **); void __elfN(stackgap)(struct image_params *, uintptr_t *); int __elfN(freebsd_copyout_auxargs)(struct image_params *, uintptr_t); void __elfN(puthdr)(struct thread *, void *, size_t, int, size_t, int); +void __elfN(prepare_notes)(struct thread *, struct note_info_list *, + size_t *); void __elfN(size_segments)(struct thread *, struct sseg_closure *, int); +size_t __elfN(register_note)(struct thread *, struct note_info_list *, + int, outfunc_t, void *); /* Machine specific function to dump per-thread information. */ void __elfN(dump_thread)(struct thread *, void *, size_t *); diff --git a/sys/sys/sysent.h b/sys/sys/sysent.h index 8b0903f7dcc0..e0e5e351ae20 100644 --- a/sys/sys/sysent.h +++ b/sys/sys/sysent.h @@ -98,6 +98,7 @@ struct proc; struct __sigset; struct trapframe; struct vnode; +struct note_info_list; struct sysentvec { int sv_size; /* number of entries */ @@ -113,6 +114,10 @@ struct sysentvec { char *sv_name; /* name of binary type */ int (*sv_coredump)(struct thread *, struct vnode *, off_t, int); /* function to dump core, or NULL */ + int sv_elf_core_osabi; + const char *sv_elf_core_abi_vendor; + void (*sv_elf_core_prepare_notes)(struct thread *, + struct note_info_list *, size_t *); int (*sv_imgact_try)(struct image_params *); void (*sv_stackgap)(struct image_params *, uintptr_t *); int (*sv_copyout_auxargs)(struct image_params *,
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202106290758.15T7w4GB008232>