1 /*- 2 * SPDX-License-Identifier: BSD-3-Clause 3 * 4 * Copyright (c) 2019 Justin Hibbits 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer 11 * in this position and unchanged. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 3. The name of the author may not be used to endorse or promote products 16 * derived from this software without specific prior written permission 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * 29 * $FreeBSD$ 30 */ 31 32 static int 33 __elfN(powerpc_copyout_auxargs)(struct image_params *imgp, uintptr_t base) 34 { 35 Elf_Auxargs *args; 36 Elf_Auxinfo *argarray, *pos; 37 int error; 38 39 if (imgp->proc->p_osrel >= P_OSREL_POWERPC_NEW_AUX_ARGS) 40 return (__elfN(freebsd_copyout_auxargs)(imgp, base)); 41 42 args = (Elf_Auxargs *)imgp->auxargs; 43 argarray = pos = malloc(AT_OLD_COUNT * sizeof(*pos), M_TEMP, 44 M_WAITOK | M_ZERO); 45 46 if (args->execfd != -1) 47 AUXARGS_ENTRY(pos, AT_OLD_EXECFD, args->execfd); 48 AUXARGS_ENTRY(pos, AT_OLD_PHDR, args->phdr); 49 AUXARGS_ENTRY(pos, AT_OLD_PHENT, args->phent); 50 AUXARGS_ENTRY(pos, AT_OLD_PHNUM, args->phnum); 51 AUXARGS_ENTRY(pos, AT_OLD_PAGESZ, args->pagesz); 52 AUXARGS_ENTRY(pos, AT_OLD_FLAGS, args->flags); 53 AUXARGS_ENTRY(pos, AT_OLD_ENTRY, args->entry); 54 AUXARGS_ENTRY(pos, AT_OLD_BASE, args->base); 55 AUXARGS_ENTRY(pos, AT_OLD_EHDRFLAGS, args->hdr_eflags); 56 if (imgp->execpathp != 0) 57 AUXARGS_ENTRY_PTR(pos, AT_OLD_EXECPATH, imgp->execpathp); 58 AUXARGS_ENTRY(pos, AT_OLD_OSRELDATE, 59 imgp->proc->p_ucred->cr_prison->pr_osreldate); 60 if (imgp->canary != 0) { 61 AUXARGS_ENTRY_PTR(pos, AT_OLD_CANARY, imgp->canary); 62 AUXARGS_ENTRY(pos, AT_OLD_CANARYLEN, imgp->canarylen); 63 } 64 AUXARGS_ENTRY(pos, AT_OLD_NCPUS, mp_ncpus); 65 if (imgp->pagesizes != 0) { 66 AUXARGS_ENTRY_PTR(pos, AT_OLD_PAGESIZES, imgp->pagesizes); 67 AUXARGS_ENTRY(pos, AT_OLD_PAGESIZESLEN, imgp->pagesizeslen); 68 } 69 if (imgp->sysent->sv_timekeep_base != 0) { 70 AUXARGS_ENTRY(pos, AT_OLD_TIMEKEEP, 71 imgp->sysent->sv_timekeep_base); 72 } 73 AUXARGS_ENTRY(pos, AT_OLD_STACKPROT, imgp->sysent->sv_shared_page_obj 74 != NULL && imgp->stack_prot != 0 ? imgp->stack_prot : 75 imgp->sysent->sv_stackprot); 76 if (imgp->sysent->sv_hwcap != NULL) 77 AUXARGS_ENTRY(pos, AT_OLD_HWCAP, *imgp->sysent->sv_hwcap); 78 if (imgp->sysent->sv_hwcap2 != NULL) 79 AUXARGS_ENTRY(pos, AT_OLD_HWCAP2, *imgp->sysent->sv_hwcap2); 80 AUXARGS_ENTRY(pos, AT_OLD_NULL, 0); 81 82 free(imgp->auxargs, M_TEMP); 83 imgp->auxargs = NULL; 84 KASSERT(pos - argarray <= AT_OLD_COUNT, ("Too many auxargs")); 85 86 error = copyout(argarray, (void *)base, sizeof(*argarray) * AT_OLD_COUNT); 87 free(argarray, M_TEMP); 88 return (error); 89 } 90