Index: sys/amd64/amd64/elf_machdep.c =================================================================== --- sys/amd64/amd64/elf_machdep.c +++ sys/amd64/amd64/elf_machdep.c @@ -59,6 +59,9 @@ .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 @@ .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, Index: sys/amd64/cloudabi32/cloudabi32_sysvec.c =================================================================== --- sys/amd64/cloudabi32/cloudabi32_sysvec.c +++ sys/amd64/cloudabi32/cloudabi32_sysvec.c @@ -209,6 +209,9 @@ .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, Index: sys/amd64/cloudabi64/cloudabi64_sysvec.c =================================================================== --- sys/amd64/cloudabi64/cloudabi64_sysvec.c +++ sys/amd64/cloudabi64/cloudabi64_sysvec.c @@ -197,6 +197,9 @@ .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, Index: sys/amd64/linux/linux_machdep.c =================================================================== --- sys/amd64/linux/linux_machdep.c +++ sys/amd64/linux/linux_machdep.c @@ -79,6 +79,7 @@ #include #include +#include #include #include @@ -347,3 +348,36 @@ return ((cpu_stdext_feature & CPUID_STDEXT_SMAP) != 0 ? futex_xorl_smap : futex_xorl_nosmap); } + +void +bsd_to_linux_regset(struct reg *b_reg, struct linux_pt_regset *l_regset) +{ + + l_regset->r15 = b_reg->r_r15; + l_regset->r14 = b_reg->r_r14; + l_regset->r13 = b_reg->r_r13; + l_regset->r12 = b_reg->r_r12; + l_regset->rbp = b_reg->r_rbp; + l_regset->rbx = b_reg->r_rbx; + l_regset->r11 = b_reg->r_r11; + l_regset->r10 = b_reg->r_r10; + l_regset->r9 = b_reg->r_r9; + l_regset->r8 = b_reg->r_r8; + l_regset->rax = b_reg->r_rax; + l_regset->rcx = b_reg->r_rcx; + l_regset->rdx = b_reg->r_rdx; + l_regset->rsi = b_reg->r_rsi; + l_regset->rdi = b_reg->r_rdi; + l_regset->orig_rax = b_reg->r_rax; + l_regset->rip = b_reg->r_rip; + l_regset->cs = b_reg->r_cs; + l_regset->eflags = b_reg->r_rflags; + l_regset->rsp = b_reg->r_rsp; + l_regset->ss = b_reg->r_ss; + l_regset->fs_base = 0; + l_regset->gs_base = 0; + l_regset->ds = b_reg->r_ds; + l_regset->es = b_reg->r_es; + l_regset->fs = b_reg->r_fs; + l_regset->gs = b_reg->r_gs; +} Index: sys/amd64/linux/linux_ptrace.c =================================================================== --- sys/amd64/linux/linux_ptrace.c +++ sys/amd64/linux/linux_ptrace.c @@ -205,39 +205,6 @@ l_reg->ss = b_reg->r_ss; } -void -bsd_to_linux_regset(struct reg *b_reg, struct linux_pt_regset *l_regset) -{ - - l_regset->r15 = b_reg->r_r15; - l_regset->r14 = b_reg->r_r14; - l_regset->r13 = b_reg->r_r13; - l_regset->r12 = b_reg->r_r12; - l_regset->rbp = b_reg->r_rbp; - l_regset->rbx = b_reg->r_rbx; - l_regset->r11 = b_reg->r_r11; - l_regset->r10 = b_reg->r_r10; - l_regset->r9 = b_reg->r_r9; - l_regset->r8 = b_reg->r_r8; - l_regset->rax = b_reg->r_rax; - l_regset->rcx = b_reg->r_rcx; - l_regset->rdx = b_reg->r_rdx; - l_regset->rsi = b_reg->r_rsi; - l_regset->rdi = b_reg->r_rdi; - l_regset->orig_rax = b_reg->r_rax; - l_regset->rip = b_reg->r_rip; - l_regset->cs = b_reg->r_cs; - l_regset->eflags = b_reg->r_rflags; - l_regset->rsp = b_reg->r_rsp; - l_regset->ss = b_reg->r_ss; - l_regset->fs_base = 0; - l_regset->gs_base = 0; - l_regset->ds = b_reg->r_ds; - l_regset->es = b_reg->r_es; - l_regset->fs = b_reg->r_fs; - l_regset->gs = b_reg->r_gs; -} - static void map_regs_from_linux(struct reg *b_reg, struct linux_pt_reg *l_reg) { Index: sys/amd64/linux/linux_sysvec.c =================================================================== --- sys/amd64/linux/linux_sysvec.c +++ sys/amd64/linux/linux_sysvec.c @@ -741,6 +741,9 @@ .sv_szsigcode = &linux_szsigcode, .sv_name = "Linux ELF64", .sv_coredump = elf64_coredump, + .sv_elf_core_osabi = ELFOSABI_NONE, + .sv_elf_core_abi_vendor = LINUX_ABI_VENDOR, + .sv_elf_core_prepare_notes = linux64_prepare_notes, .sv_imgact_try = linux_exec_imgact_try, .sv_minsigstksz = LINUX_MINSIGSTKSZ, .sv_minuser = VM_MIN_ADDRESS, Index: sys/amd64/linux32/linux32_sysvec.c =================================================================== --- sys/amd64/linux32/linux32_sysvec.c +++ sys/amd64/linux32/linux32_sysvec.c @@ -907,6 +907,9 @@ .sv_szsigcode = &linux_szsigcode, .sv_name = "Linux ELF32", .sv_coredump = elf32_coredump, + .sv_elf_core_osabi = ELFOSABI_NONE, + .sv_elf_core_abi_vendor = LINUX_ABI_VENDOR, + .sv_elf_core_prepare_notes = linux32_prepare_notes, .sv_imgact_try = linux_exec_imgact_try, .sv_minsigstksz = LINUX_MINSIGSTKSZ, .sv_minuser = VM_MIN_ADDRESS, Index: sys/arm/arm/elf_machdep.c =================================================================== --- sys/arm/arm/elf_machdep.c +++ sys/arm/arm/elf_machdep.c @@ -72,6 +72,9 @@ .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, Index: sys/arm/cloudabi32/cloudabi32_sysvec.c =================================================================== --- sys/arm/cloudabi32/cloudabi32_sysvec.c +++ sys/arm/cloudabi32/cloudabi32_sysvec.c @@ -173,6 +173,9 @@ .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, Index: sys/arm64/arm64/elf32_machdep.c =================================================================== --- sys/arm64/arm64/elf32_machdep.c +++ sys/arm64/arm64/elf32_machdep.c @@ -87,6 +87,9 @@ .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, Index: sys/arm64/arm64/elf_machdep.c =================================================================== --- sys/arm64/arm64/elf_machdep.c +++ sys/arm64/arm64/elf_machdep.c @@ -68,6 +68,9 @@ .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, Index: sys/arm64/cloudabi32/cloudabi32_sysvec.c =================================================================== --- sys/arm64/cloudabi32/cloudabi32_sysvec.c +++ sys/arm64/cloudabi32/cloudabi32_sysvec.c @@ -181,6 +181,9 @@ .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, Index: sys/arm64/cloudabi64/cloudabi64_sysvec.c =================================================================== --- sys/arm64/cloudabi64/cloudabi64_sysvec.c +++ sys/arm64/cloudabi64/cloudabi64_sysvec.c @@ -165,6 +165,9 @@ .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, Index: sys/arm64/linux/linux_sysvec.c =================================================================== --- sys/arm64/linux/linux_sysvec.c +++ sys/arm64/linux/linux_sysvec.c @@ -417,6 +417,9 @@ .sv_szsigcode = &linux_szsigcode, .sv_name = "Linux ELF64", .sv_coredump = elf64_coredump, + .sv_elf_core_osabi = ELFOSABI_NONE, + .sv_elf_core_abi_vendor = LINUX_ABI_VENDOR, + .sv_elf_core_prepare_notes = linux64_prepare_notes, .sv_imgact_try = linux_exec_imgact_try, .sv_minsigstksz = LINUX_MINSIGSTKSZ, .sv_minuser = VM_MIN_ADDRESS, Index: sys/compat/ia32/ia32_sysvec.c =================================================================== --- sys/compat/ia32/ia32_sysvec.c +++ sys/compat/ia32/ia32_sysvec.c @@ -105,6 +105,9 @@ .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, Index: sys/compat/linux/linux_elf.h =================================================================== --- /dev/null +++ sys/compat/linux/linux_elf.h @@ -0,0 +1,56 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2018 Chuck Tuffli + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef _COMPAT_LINUX_ELF_H_ +#define _COMPAT_LINUX_ELF_H_ + +struct l_elf_siginfo { + l_int si_signo; + l_int si_code; + l_int si_errno; +}; + +typedef struct linux_pt_regset l_elf_gregset_t; + +struct linux_elf_prstatus { + struct l_elf_siginfo pr_info; + l_short pr_cursig; + l_ulong pr_sigpend; + l_ulong pr_sighold; + l_pid_t pr_pid; + l_pid_t pr_ppid; + l_pid_t pr_pgrp; + l_pid_t pr_sid; + l_timeval pr_utime; + l_timeval pr_stime; + l_timeval pr_cutime; + l_timeval pr_cstime; + l_elf_gregset_t pr_reg; + l_int pr_fpvalid; +}; + +#endif Index: sys/compat/linux/linux_elf.c =================================================================== --- /dev/null +++ sys/compat/linux/linux_elf.c @@ -0,0 +1,295 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 2021 Edward Tomasz Napierala + * Copyright (c) 2018 Chuck Tuffli + * Copyright (c) 2017 Dell EMC + * Copyright (c) 2000 David O'Brien + * Copyright (c) 1995-1996 Søren Schmidt + * Copyright (c) 1996 Peter Wemm + * All rights reserved. + * + * This software was developed by the University of Cambridge Computer + * Laboratory as part of the CHERI for Hypervisors and Operating Systems + * (CHaOS) project, funded by EPSRC grant EP/V000292/1. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer + * in this position and unchanged. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD$"); + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#if __ELF_WORD_SIZE == 32 +#define linux_pt_regset linux_pt_regset32 +#define bsd_to_linux_regset bsd_to_linux_regset32 +#include +#else +#include +#endif +#include +#include +#include + +/* This adds "linux32_" and "linux64_" prefixes. */ +#define __linuxN(x) __CONCAT(__CONCAT(__CONCAT(linux,__ELF_WORD_SIZE),_),x) + +#define LINUX_NT_AUXV 6 + +static void __linuxN(note_fpregset)(void *, struct sbuf *, size_t *); +static void __linuxN(note_prpsinfo)(void *, struct sbuf *, size_t *); +static void __linuxN(note_prstatus)(void *, struct sbuf *, size_t *); +static void __linuxN(note_threadmd)(void *, struct sbuf *, size_t *); +static void __linuxN(note_nt_auxv)(void *, struct sbuf *, size_t *); + +void +__linuxN(prepare_notes)(struct thread *td, struct note_info_list *list, + size_t *sizep) +{ + struct proc *p; + struct thread *thr; + size_t size; + + p = td->td_proc; + size = 0; + + /* + * To have the debugger select the right thread (LWP) as the initial + * thread, we dump the state of the thread passed to us in td first. + * This is the thread that causes the core dump and thus likely to + * be the right thread one wants to have selected in the debugger. + */ + thr = td; + while (thr != NULL) { + size += __elfN(register_note)(td, list, + NT_PRSTATUS, __linuxN(note_prstatus), thr); + size += __elfN(register_note)(td, list, + NT_PRPSINFO, __linuxN(note_prpsinfo), p); + size += __elfN(register_note)(td, list, + LINUX_NT_AUXV, __linuxN(note_nt_auxv), p); + size += __elfN(register_note)(td, list, + NT_FPREGSET, __linuxN(note_fpregset), thr); + size += __elfN(register_note)(td, list, + -1, __linuxN(note_threadmd), thr); + + thr = thr == td ? TAILQ_FIRST(&p->p_threads) : + TAILQ_NEXT(thr, td_plist); + if (thr == td) + thr = TAILQ_NEXT(thr, td_plist); + } + + *sizep = size; +} + +#if __ELF_WORD_SIZE == 32 +typedef struct linux_elf_prstatus elf_prstatus_t; +typedef struct prpsinfo32 elf_prpsinfo_t; +typedef struct fpreg32 elf_prfpregset_t; +#else +typedef struct linux_elf_prstatus elf_prstatus_t; +typedef prpsinfo_t elf_prpsinfo_t; +typedef prfpregset_t elf_prfpregset_t; +#endif + +static void +__linuxN(note_prpsinfo)(void *arg, struct sbuf *sb, size_t *sizep) +{ + struct sbuf sbarg; + size_t len; + char *cp, *end; + struct proc *p; + elf_prpsinfo_t *psinfo; + int error; + + p = arg; + if (sb != NULL) { + KASSERT(*sizep == sizeof(*psinfo), ("invalid size")); + psinfo = malloc(sizeof(*psinfo), M_TEMP, M_ZERO | M_WAITOK); + psinfo->pr_version = PRPSINFO_VERSION; + psinfo->pr_psinfosz = sizeof(elf_prpsinfo_t); + strlcpy(psinfo->pr_fname, p->p_comm, sizeof(psinfo->pr_fname)); + PROC_LOCK(p); + if (p->p_args != NULL) { + len = sizeof(psinfo->pr_psargs) - 1; + if (len > p->p_args->ar_length) + len = p->p_args->ar_length; + memcpy(psinfo->pr_psargs, p->p_args->ar_args, len); + PROC_UNLOCK(p); + error = 0; + } else { + _PHOLD(p); + PROC_UNLOCK(p); + sbuf_new(&sbarg, psinfo->pr_psargs, + sizeof(psinfo->pr_psargs), SBUF_FIXEDLEN); + error = proc_getargv(curthread, p, &sbarg); + PRELE(p); + if (sbuf_finish(&sbarg) == 0) + len = sbuf_len(&sbarg) - 1; + else + len = sizeof(psinfo->pr_psargs) - 1; + sbuf_delete(&sbarg); + } + if (error || len == 0) + strlcpy(psinfo->pr_psargs, p->p_comm, + sizeof(psinfo->pr_psargs)); + else { + KASSERT(len < sizeof(psinfo->pr_psargs), + ("len is too long: %zu vs %zu", len, + sizeof(psinfo->pr_psargs))); + cp = psinfo->pr_psargs; + end = cp + len - 1; + for (;;) { + cp = memchr(cp, '\0', end - cp); + if (cp == NULL) + break; + *cp = ' '; + } + } + psinfo->pr_pid = p->p_pid; + sbuf_bcat(sb, psinfo, sizeof(*psinfo)); + free(psinfo, M_TEMP); + } + *sizep = sizeof(*psinfo); +} + +static void +__linuxN(note_prstatus)(void *arg, struct sbuf *sb, size_t *sizep) +{ + struct thread *td; + elf_prstatus_t *status; +#if __ELF_WORD_SIZE == 32 + struct reg32 pr_reg; +#else + struct reg pr_reg; +#endif + + td = (struct thread *)arg; + if (sb != NULL) { + KASSERT(*sizep == sizeof(*status), ("invalid size")); + status = malloc(sizeof(*status), M_TEMP, M_ZERO | M_WAITOK); + + /* + * XXX: Some fields missing. + */ + status->pr_cursig = td->td_proc->p_sig; + status->pr_pid = td->td_tid; + +#if __ELF_WORD_SIZE == 32 + fill_regs32(td, &pr_reg); +#else + fill_regs(td, &pr_reg); +#endif + bsd_to_linux_regset(&pr_reg, &status->pr_reg); + sbuf_bcat(sb, status, sizeof(*status)); + free(status, M_TEMP); + } + *sizep = sizeof(*status); +} + +static void +__linuxN(note_fpregset)(void *arg, struct sbuf *sb, size_t *sizep) +{ + struct thread *td; + elf_prfpregset_t *fpregset; + + td = (struct thread *)arg; + if (sb != NULL) { + KASSERT(*sizep == sizeof(*fpregset), ("invalid size")); + fpregset = malloc(sizeof(*fpregset), M_TEMP, M_ZERO | M_WAITOK); +#if __ELF_WORD_SIZE == 32 + fill_fpregs32(td, fpregset); +#else + fill_fpregs(td, fpregset); +#endif + sbuf_bcat(sb, fpregset, sizeof(*fpregset)); + free(fpregset, M_TEMP); + } + *sizep = sizeof(*fpregset); +} + +/* + * Allow for MD specific notes, as well as any MD + * specific preparations for writing MI notes. + */ +static void +__linuxN(note_threadmd)(void *arg, struct sbuf *sb, size_t *sizep) +{ + struct thread *td; + void *buf; + size_t size; + + td = (struct thread *)arg; + size = *sizep; + if (size != 0 && sb != NULL) + buf = malloc(size, M_TEMP, M_ZERO | M_WAITOK); + else + buf = NULL; + size = 0; + __elfN(dump_thread)(td, buf, &size); + KASSERT(sb == NULL || *sizep == size, ("invalid size")); + if (size != 0 && sb != NULL) + sbuf_bcat(sb, buf, size); + free(buf, M_TEMP); + *sizep = size; +} + +static void +__linuxN(note_nt_auxv)(void *arg, struct sbuf *sb, size_t *sizep) +{ + struct proc *p; + size_t size; + + p = arg; + if (sb == NULL) { + size = 0; + sb = sbuf_new(NULL, NULL, LINUX_AT_COUNT * sizeof(Elf_Auxinfo), + SBUF_FIXEDLEN); + sbuf_set_drain(sb, sbuf_count_drain, &size); + PHOLD(p); + proc_getauxv(curthread, p, sb); + PRELE(p); + sbuf_finish(sb); + sbuf_delete(sb); + *sizep = size; + } else { + PHOLD(p); + proc_getauxv(curthread, p, sb); + PRELE(p); + } +} Index: sys/compat/linux/linux_elf32.c =================================================================== --- /dev/null +++ sys/compat/linux/linux_elf32.c @@ -0,0 +1,38 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2021 Edward Tomasz Napierala + * Copyright (c) 2002 Doug Rabson + * All rights reserved. + * + * This software was developed by the University of Cambridge Computer + * Laboratory as part of the CHERI for Hypervisors and Operating Systems + * (CHaOS) project, funded by EPSRC grant EP/V000292/1. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD$"); + +#define __ELF_WORD_SIZE 32 +#include Index: sys/compat/linux/linux_elf64.c =================================================================== --- /dev/null +++ sys/compat/linux/linux_elf64.c @@ -0,0 +1,38 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2021 Edward Tomasz Napierala + * Copyright (c) 2002 Doug Rabson + * All rights reserved. + * + * This software was developed by the University of Cambridge Computer + * Laboratory as part of the CHERI for Hypervisors and Operating Systems + * (CHaOS) project, funded by EPSRC grant EP/V000292/1. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD$"); + +#define __ELF_WORD_SIZE 64 +#include Index: sys/compat/linux/linux_emul.h =================================================================== --- sys/compat/linux/linux_emul.h +++ sys/compat/linux/linux_emul.h @@ -33,6 +33,10 @@ #define _LINUX_EMUL_H_ struct image_params; +struct note_info_list; + +/* Linux core notes are labeled "CORE" */ +#define LINUX_ABI_VENDOR "CORE" /* * modeled after similar structure in NetBSD @@ -58,6 +62,8 @@ void linux_thread_dtor(struct thread *); void linux_thread_detach(struct thread *); int linux_common_execve(struct thread *, struct image_args *); +void linux32_prepare_notes(struct thread *, struct note_info_list *, size_t *); +void linux64_prepare_notes(struct thread *, struct note_info_list *, size_t *); /* process emuldata flags */ #define LINUX_XDEPR_REQUEUEOP 0x00000001 /* uses deprecated Index: sys/conf/files.amd64 =================================================================== --- sys/conf/files.amd64 +++ sys/conf/files.amd64 @@ -413,6 +413,7 @@ amd64/linux32/linux32_sysent.c optional compat_linux32 amd64/linux32/linux32_sysvec.c optional compat_linux32 compat/linux/linux_dummy.c optional compat_linux32 +compat/linux/linux_elf32.c optional compat_linux32 compat/linux/linux_emul.c optional compat_linux32 compat/linux/linux_errno.c optional compat_linux32 compat/linux/linux_file.c optional compat_linux32 Index: sys/i386/i386/elf_machdep.c =================================================================== --- sys/i386/i386/elf_machdep.c +++ sys/i386/i386/elf_machdep.c @@ -61,6 +61,9 @@ .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, Index: sys/i386/linux/linux_sysvec.c =================================================================== --- sys/i386/linux/linux_sysvec.c +++ sys/i386/linux/linux_sysvec.c @@ -886,6 +886,9 @@ .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, Index: sys/kern/imgact_elf.c =================================================================== --- sys/kern/imgact_elf.c +++ sys/kern/imgact_elf.c @@ -197,8 +197,6 @@ #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 @@ 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 @@ 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 @@ 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 @@ 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 @@ return (error); } -static void +void __elfN(prepare_notes)(struct thread *td, struct note_info_list *list, size_t *sizep) { @@ -1755,7 +1748,7 @@ 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 @@ */ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ } 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 @@ 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; Index: sys/mips/mips/elf_machdep.c =================================================================== --- sys/mips/mips/elf_machdep.c +++ sys/mips/mips/elf_machdep.c @@ -65,6 +65,8 @@ .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, Index: sys/mips/mips/freebsd32_machdep.c =================================================================== --- sys/mips/mips/freebsd32_machdep.c +++ sys/mips/mips/freebsd32_machdep.c @@ -85,6 +85,9 @@ .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, Index: sys/modules/linux/Makefile =================================================================== --- sys/modules/linux/Makefile +++ sys/modules/linux/Makefile @@ -26,6 +26,7 @@ .endif .if ${MACHINE_CPUARCH} == "amd64" SRCS+= linux${SFX}_support.s +SRCS+= linux_elf32.c .else SRCS+= linux_copyout.c .endif Index: sys/modules/linux64/Makefile =================================================================== --- sys/modules/linux64/Makefile +++ sys/modules/linux64/Makefile @@ -18,6 +18,7 @@ linux_support.s .if ${MACHINE_CPUARCH} == "amd64" SRCS+= linux_dummy_x86.c +SRCS+= linux_elf64.c .endif DPSRCS= assym.inc linux_genassym.c Index: sys/powerpc/powerpc/elf32_machdep.c =================================================================== --- sys/powerpc/powerpc/elf32_machdep.c +++ sys/powerpc/powerpc/elf32_machdep.c @@ -98,6 +98,9 @@ .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, Index: sys/powerpc/powerpc/elf64_machdep.c =================================================================== --- sys/powerpc/powerpc/elf64_machdep.c +++ sys/powerpc/powerpc/elf64_machdep.c @@ -69,6 +69,9 @@ .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 @@ .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, Index: sys/riscv/riscv/elf_machdep.c =================================================================== --- sys/riscv/riscv/elf_machdep.c +++ sys/riscv/riscv/elf_machdep.c @@ -72,6 +72,9 @@ .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, Index: sys/sys/imgact_elf.h =================================================================== --- sys/sys/imgact_elf.h +++ 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 @@ __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 @@ 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 *); Index: sys/sys/sysent.h =================================================================== --- sys/sys/sysent.h +++ sys/sys/sysent.h @@ -98,6 +98,7 @@ struct __sigset; struct trapframe; struct vnode; +struct note_info_list; struct sysentvec { int sv_size; /* number of entries */ @@ -113,6 +114,10 @@ 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 *,