2 * SPDX-License-Identifier: BSD-3-Clause
4 * Copyright (c) 2019 Justin Hibbits
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
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
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.
33 __elfN(powerpc_copyout_auxargs)(struct image_params *imgp, uintptr_t base)
36 Elf_Auxinfo *argarray, *pos;
40 * XXX If we can't find image's OSREL, assume it uses the new auxv
43 * This is specially important for rtld, that is not tagged. Using
44 * direct exec mode with new (ELFv2) binaries that expect the new auxv
45 * format would result in crashes otherwise.
47 * Unfortunately, this may break direct exec'ing old binaries,
48 * but it seems better to correctly support new binaries by default,
49 * considering the transition to ELFv2 happened quite some time
50 * ago. If needed, a sysctl may be added to allow old auxv format to
51 * be used when OSREL is not found.
53 if (imgp->proc->p_osrel >= P_OSREL_POWERPC_NEW_AUX_ARGS ||
54 imgp->proc->p_osrel == 0)
55 return (__elfN(freebsd_copyout_auxargs)(imgp, base));
57 args = (Elf_Auxargs *)imgp->auxargs;
58 argarray = pos = malloc(AT_OLD_COUNT * sizeof(*pos), M_TEMP,
61 if (args->execfd != -1)
62 AUXARGS_ENTRY(pos, AT_OLD_EXECFD, args->execfd);
63 AUXARGS_ENTRY(pos, AT_OLD_PHDR, args->phdr);
64 AUXARGS_ENTRY(pos, AT_OLD_PHENT, args->phent);
65 AUXARGS_ENTRY(pos, AT_OLD_PHNUM, args->phnum);
66 AUXARGS_ENTRY(pos, AT_OLD_PAGESZ, args->pagesz);
67 AUXARGS_ENTRY(pos, AT_OLD_FLAGS, args->flags);
68 AUXARGS_ENTRY(pos, AT_OLD_ENTRY, args->entry);
69 AUXARGS_ENTRY(pos, AT_OLD_BASE, args->base);
70 AUXARGS_ENTRY(pos, AT_OLD_EHDRFLAGS, args->hdr_eflags);
71 if (imgp->execpathp != 0)
72 AUXARGS_ENTRY_PTR(pos, AT_OLD_EXECPATH, imgp->execpathp);
73 AUXARGS_ENTRY(pos, AT_OLD_OSRELDATE,
74 imgp->proc->p_ucred->cr_prison->pr_osreldate);
75 if (imgp->canary != 0) {
76 AUXARGS_ENTRY_PTR(pos, AT_OLD_CANARY, imgp->canary);
77 AUXARGS_ENTRY(pos, AT_OLD_CANARYLEN, imgp->canarylen);
79 AUXARGS_ENTRY(pos, AT_OLD_NCPUS, mp_ncpus);
80 if (imgp->pagesizes != 0) {
81 AUXARGS_ENTRY_PTR(pos, AT_OLD_PAGESIZES, imgp->pagesizes);
82 AUXARGS_ENTRY(pos, AT_OLD_PAGESIZESLEN, imgp->pagesizeslen);
84 if (imgp->sysent->sv_timekeep_base != 0) {
85 AUXARGS_ENTRY(pos, AT_OLD_TIMEKEEP,
86 imgp->sysent->sv_timekeep_base);
88 AUXARGS_ENTRY(pos, AT_OLD_STACKPROT, imgp->sysent->sv_shared_page_obj
89 != NULL && imgp->stack_prot != 0 ? imgp->stack_prot :
90 imgp->sysent->sv_stackprot);
91 if (imgp->sysent->sv_hwcap != NULL)
92 AUXARGS_ENTRY(pos, AT_OLD_HWCAP, *imgp->sysent->sv_hwcap);
93 if (imgp->sysent->sv_hwcap2 != NULL)
94 AUXARGS_ENTRY(pos, AT_OLD_HWCAP2, *imgp->sysent->sv_hwcap2);
95 AUXARGS_ENTRY(pos, AT_OLD_NULL, 0);
97 free(imgp->auxargs, M_TEMP);
99 KASSERT(pos - argarray <= AT_OLD_COUNT, ("Too many auxargs"));
101 error = copyout(argarray, (void *)base, sizeof(*argarray) * AT_OLD_COUNT);
102 free(argarray, M_TEMP);