1*1d7f24eaSmatt /* $NetBSD: linux_exec_elf32.c,v 1.86 2012/02/12 16:34:10 matt Exp $ */ 28fb507a3Schristos 38fb507a3Schristos /*- 4ac10cf69Smanu * Copyright (c) 1995, 1998, 2000, 2001 The NetBSD Foundation, Inc. 58fb507a3Schristos * All rights reserved. 68fb507a3Schristos * 78fb507a3Schristos * This code is derived from software contributed to The NetBSD Foundation 8ac10cf69Smanu * by Christos Zoulas, Frank van der Linden, Eric Haszlakiewicz and 9ac10cf69Smanu * Emmanuel Dreyfus. 108fb507a3Schristos * 118fb507a3Schristos * Redistribution and use in source and binary forms, with or without 128fb507a3Schristos * modification, are permitted provided that the following conditions 138fb507a3Schristos * are met: 148fb507a3Schristos * 1. Redistributions of source code must retain the above copyright 158fb507a3Schristos * notice, this list of conditions and the following disclaimer. 168fb507a3Schristos * 2. Redistributions in binary form must reproduce the above copyright 178fb507a3Schristos * notice, this list of conditions and the following disclaimer in the 188fb507a3Schristos * documentation and/or other materials provided with the distribution. 198fb507a3Schristos * 208fb507a3Schristos * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 218fb507a3Schristos * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 228fb507a3Schristos * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 238fb507a3Schristos * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 248fb507a3Schristos * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 258fb507a3Schristos * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 268fb507a3Schristos * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 278fb507a3Schristos * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 288fb507a3Schristos * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 298fb507a3Schristos * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 308fb507a3Schristos * POSSIBILITY OF SUCH DAMAGE. 318fb507a3Schristos */ 323bf459f3Sfvdl 333bf459f3Sfvdl /* 34fb777788Sfvdl * based on exec_aout.c, sunos_exec.c and svr4_exec.c 353bf459f3Sfvdl */ 363bf459f3Sfvdl 37dab6ef8bSlukem #include <sys/cdefs.h> 38*1d7f24eaSmatt __KERNEL_RCSID(0, "$NetBSD: linux_exec_elf32.c,v 1.86 2012/02/12 16:34:10 matt Exp $"); 39dab6ef8bSlukem 40f7ac1bd3Serh #ifndef ELFSIZE 41ea0cda2cSchristos /* XXX should die */ 42ea0cda2cSchristos #define ELFSIZE 32 43f7ac1bd3Serh #endif 449c3e274cScgd 453bf459f3Sfvdl #include <sys/param.h> 463bf459f3Sfvdl #include <sys/systm.h> 473bf459f3Sfvdl #include <sys/kernel.h> 483bf459f3Sfvdl #include <sys/proc.h> 493bf459f3Sfvdl #include <sys/malloc.h> 503bf459f3Sfvdl #include <sys/namei.h> 513bf459f3Sfvdl #include <sys/vnode.h> 52151fa70fSchristos #include <sys/mount.h> 53d551a4edSchristos #include <sys/exec.h> 54c4aaa600Sfvdl #include <sys/exec_elf.h> 55cee43b67Sjdolecek #include <sys/stat.h> 56874fef37Selad #include <sys/kauth.h> 573bf459f3Sfvdl 583bf459f3Sfvdl #include <sys/mman.h> 59151fa70fSchristos #include <sys/syscallargs.h> 60151fa70fSchristos 61a2a38285Sad #include <sys/cpu.h> 623bf459f3Sfvdl #include <machine/reg.h> 633bf459f3Sfvdl 64908291d2Schristos #include <compat/linux/common/linux_types.h> 65908291d2Schristos #include <compat/linux/common/linux_signal.h> 66908291d2Schristos #include <compat/linux/common/linux_util.h> 67908291d2Schristos #include <compat/linux/common/linux_exec.h> 68908291d2Schristos #include <compat/linux/common/linux_machdep.h> 691ab7ca8fSad #include <compat/linux/common/linux_ipc.h> 701ab7ca8fSad #include <compat/linux/common/linux_sem.h> 713bf459f3Sfvdl 72908291d2Schristos #include <compat/linux/linux_syscallargs.h> 73908291d2Schristos #include <compat/linux/linux_syscall.h> 74fc7cfb5fSfvdl 7565fc8539Schristos #ifdef DEBUG_LINUX 7665fc8539Schristos #define DPRINTF(a) uprintf a 7765fc8539Schristos #else 7865fc8539Schristos #define DPRINTF(a) 7965fc8539Schristos #endif 8065fc8539Schristos 81ac10cf69Smanu #ifdef LINUX_ATEXIT_SIGNATURE 82ac10cf69Smanu /* 83ac10cf69Smanu * On the PowerPC, statically linked Linux binaries are not recognized 84ac10cf69Smanu * by linux_signature nor by linux_gcc_signature. Fortunately, thoses 85ac10cf69Smanu * binaries features a __libc_atexit ELF section. We therefore assume we 86ac10cf69Smanu * have a Linux binary if we find this section. 87ac10cf69Smanu */ 88ee0c5b44Smanu int 89*1d7f24eaSmatt ELFNAME2(linux,atexit_signature)( 90*1d7f24eaSmatt struct lwp *l, 91*1d7f24eaSmatt struct exec_package *epp, 92*1d7f24eaSmatt Elf_Ehdr *eh) 93ac10cf69Smanu { 94ac10cf69Smanu size_t shsize; 95ac10cf69Smanu int strndx; 96ac10cf69Smanu size_t i; 97ac10cf69Smanu static const char signature[] = "__libc_atexit"; 983b6d3c71Schs char *strtable = NULL; 99ac10cf69Smanu Elf_Shdr *sh; 100ac10cf69Smanu 101ac10cf69Smanu int error; 102ac10cf69Smanu 103ac10cf69Smanu /* 104ac10cf69Smanu * load the section header table 105ac10cf69Smanu */ 106ac10cf69Smanu shsize = eh->e_shnum * sizeof(Elf_Shdr); 107ac10cf69Smanu sh = (Elf_Shdr *) malloc(shsize, M_TEMP, M_WAITOK); 10895e1ffb1Schristos error = exec_read_from(l, epp->ep_vp, eh->e_shoff, sh, shsize); 109ac10cf69Smanu if (error) 110ac10cf69Smanu goto out; 111ac10cf69Smanu 112ac10cf69Smanu /* 113ac10cf69Smanu * Now let's find the string table. If it does not exists, give up. 114ac10cf69Smanu */ 115ac10cf69Smanu strndx = (int)(eh->e_shstrndx); 116ac10cf69Smanu if (strndx == SHN_UNDEF) { 117ac10cf69Smanu error = ENOEXEC; 118ac10cf69Smanu goto out; 119ac10cf69Smanu } 120ac10cf69Smanu 121ac10cf69Smanu /* 12297c9d7a9Schristos * strndx is the index in section header table of the string table 12397c9d7a9Schristos * section get the whole string table in strtable, and then we get access to the names 124ac10cf69Smanu * s->sh_name is the offset of the section name in strtable. 125ac10cf69Smanu */ 126ac10cf69Smanu strtable = malloc(sh[strndx].sh_size, M_TEMP, M_WAITOK); 12795e1ffb1Schristos error = exec_read_from(l, epp->ep_vp, sh[strndx].sh_offset, strtable, 12897c9d7a9Schristos sh[strndx].sh_size); 129ac10cf69Smanu if (error) 130ac10cf69Smanu goto out; 131ac10cf69Smanu 132ac10cf69Smanu for (i = 0; i < eh->e_shnum; i++) { 133ac10cf69Smanu Elf_Shdr *s = &sh[i]; 134ac10cf69Smanu if (!memcmp((void*)(&(strtable[s->sh_name])), signature, 135ac10cf69Smanu sizeof(signature))) { 13665fc8539Schristos DPRINTF(("linux_atexit_sig=%s\n", 13765fc8539Schristos &(strtable[s->sh_name]))); 138ac10cf69Smanu error = 0; 139ac10cf69Smanu goto out; 140ac10cf69Smanu } 141ac10cf69Smanu } 142ac10cf69Smanu error = ENOEXEC; 143ac10cf69Smanu 144ac10cf69Smanu out: 145ac10cf69Smanu free(sh, M_TEMP); 1463b6d3c71Schs if (strtable) 147ac10cf69Smanu free(strtable, M_TEMP); 148ac10cf69Smanu return (error); 149ac10cf69Smanu } 150ac10cf69Smanu #endif 151f7ac1bd3Serh 152f7ac1bd3Serh #ifdef LINUX_GCC_SIGNATURE 1534d9a6e09Schristos /* 1544d9a6e09Schristos * Take advantage of the fact that all the linux binaries are compiled 1554d9a6e09Schristos * with gcc, and gcc sticks in the comment field a signature. Note that 1564d9a6e09Schristos * on SVR4 binaries, the gcc signature will follow the OS name signature, 1574d9a6e09Schristos * that will not be a problem. We don't bother to read in the string table, 1584d9a6e09Schristos * but we check all the progbits headers. 159f7ac1bd3Serh * 160f7ac1bd3Serh * XXX This only works in the i386. On the alpha (at least) 161f7ac1bd3Serh * XXX we have the same gcc signature which incorrectly identifies 162f7ac1bd3Serh * XXX NetBSD binaries as Linux. 1634d9a6e09Schristos */ 164ee0c5b44Smanu int 165*1d7f24eaSmatt ELFNAME2(linux,gcc_signature)( 166*1d7f24eaSmatt struct lwp *l, 167*1d7f24eaSmatt struct exec_package *epp, 168*1d7f24eaSmatt Elf_Ehdr *eh) 1694d9a6e09Schristos { 170b29180b2Smycroft size_t shsize; 1714d9a6e09Schristos size_t i; 1724d9a6e09Schristos static const char signature[] = "\0GCC: (GNU) "; 173fb4b40b7Schristos char tbuf[sizeof(signature) - 1]; 174f7ac1bd3Serh Elf_Shdr *sh; 1754d9a6e09Schristos int error; 1764d9a6e09Schristos 177b29180b2Smycroft shsize = eh->e_shnum * sizeof(Elf_Shdr); 178f7ac1bd3Serh sh = (Elf_Shdr *) malloc(shsize, M_TEMP, M_WAITOK); 17995e1ffb1Schristos error = exec_read_from(l, epp->ep_vp, eh->e_shoff, sh, shsize); 180b29180b2Smycroft if (error) 1814d9a6e09Schristos goto out; 1824d9a6e09Schristos 1834d9a6e09Schristos for (i = 0; i < eh->e_shnum; i++) { 184f7ac1bd3Serh Elf_Shdr *s = &sh[i]; 1854d9a6e09Schristos 1864d9a6e09Schristos /* 1874d9a6e09Schristos * Identify candidates for the comment header; 188d83602c1Schristos * Header cannot have a load address, or flags and 1894d9a6e09Schristos * it must be large enough. 1904d9a6e09Schristos */ 191522cbf02Skleink if (s->sh_type != SHT_PROGBITS || 1924d9a6e09Schristos s->sh_addr != 0 || 1934d9a6e09Schristos s->sh_flags != 0 || 1944d9a6e09Schristos s->sh_size < sizeof(signature) - 1) 1954d9a6e09Schristos continue; 1964d9a6e09Schristos 19795e1ffb1Schristos error = exec_read_from(l, epp->ep_vp, s->sh_offset, tbuf, 19897c9d7a9Schristos sizeof(signature) - 1); 199b29180b2Smycroft if (error) 200b29180b2Smycroft continue; 2014d9a6e09Schristos 202d83602c1Schristos /* 203d83602c1Schristos * error is 0, if the signatures match we are done. 204d83602c1Schristos */ 205fb4b40b7Schristos DPRINTF(("linux_gcc_sig: sig=%s\n", tbuf)); 206fb4b40b7Schristos if (!memcmp(tbuf, signature, sizeof(signature) - 1)) { 207b29180b2Smycroft error = 0; 2084d9a6e09Schristos goto out; 2094d9a6e09Schristos } 210b29180b2Smycroft } 211b29180b2Smycroft error = ENOEXEC; 2124d9a6e09Schristos 2134d9a6e09Schristos out: 2144d9a6e09Schristos free(sh, M_TEMP); 215b29180b2Smycroft return (error); 2164d9a6e09Schristos } 217f7ac1bd3Serh #endif 2184d9a6e09Schristos 21905c8a1b8Smanu #ifdef LINUX_DEBUGLINK_SIGNATURE 22005c8a1b8Smanu /* 22105c8a1b8Smanu * Look for a .gnu_debuglink, specific to x86_64 interpeter 22205c8a1b8Smanu */ 22305c8a1b8Smanu int 2249fca5da6Scegger ELFNAME2(linux,debuglink_signature)(struct lwp *l, struct exec_package *epp, Elf_Ehdr *eh) 22505c8a1b8Smanu { 22605c8a1b8Smanu size_t shsize; 22705c8a1b8Smanu int strndx; 22805c8a1b8Smanu size_t i; 22905c8a1b8Smanu static const char signature[] = ".gnu_debuglink"; 23005c8a1b8Smanu char *strtable = NULL; 23105c8a1b8Smanu Elf_Shdr *sh; 23205c8a1b8Smanu 23305c8a1b8Smanu int error; 23405c8a1b8Smanu 23505c8a1b8Smanu /* 23605c8a1b8Smanu * load the section header table 23705c8a1b8Smanu */ 23805c8a1b8Smanu shsize = eh->e_shnum * sizeof(Elf_Shdr); 23905c8a1b8Smanu sh = (Elf_Shdr *) malloc(shsize, M_TEMP, M_WAITOK); 24005c8a1b8Smanu error = exec_read_from(l, epp->ep_vp, eh->e_shoff, sh, shsize); 24105c8a1b8Smanu if (error) 24205c8a1b8Smanu goto out; 24305c8a1b8Smanu 24405c8a1b8Smanu /* 24505c8a1b8Smanu * Now let's find the string table. If it does not exists, give up. 24605c8a1b8Smanu */ 24705c8a1b8Smanu strndx = (int)(eh->e_shstrndx); 24805c8a1b8Smanu if (strndx == SHN_UNDEF) { 24905c8a1b8Smanu error = ENOEXEC; 25005c8a1b8Smanu goto out; 25105c8a1b8Smanu } 25205c8a1b8Smanu 25305c8a1b8Smanu /* 25405c8a1b8Smanu * strndx is the index in section header table of the string table 25505c8a1b8Smanu * section get the whole string table in strtable, and then we get access to the names 25605c8a1b8Smanu * s->sh_name is the offset of the section name in strtable. 25705c8a1b8Smanu */ 25805c8a1b8Smanu strtable = malloc(sh[strndx].sh_size, M_TEMP, M_WAITOK); 25905c8a1b8Smanu error = exec_read_from(l, epp->ep_vp, sh[strndx].sh_offset, strtable, 26005c8a1b8Smanu sh[strndx].sh_size); 26105c8a1b8Smanu if (error) 26205c8a1b8Smanu goto out; 26305c8a1b8Smanu 26405c8a1b8Smanu for (i = 0; i < eh->e_shnum; i++) { 26505c8a1b8Smanu Elf_Shdr *s = &sh[i]; 26605c8a1b8Smanu 26705c8a1b8Smanu if (!memcmp((void*)(&(strtable[s->sh_name])), signature, 26805c8a1b8Smanu sizeof(signature))) { 26905c8a1b8Smanu DPRINTF(("linux_debuglink_sig=%s\n", 27005c8a1b8Smanu &(strtable[s->sh_name]))); 27105c8a1b8Smanu error = 0; 27205c8a1b8Smanu goto out; 27305c8a1b8Smanu } 27405c8a1b8Smanu } 27505c8a1b8Smanu error = ENOEXEC; 27605c8a1b8Smanu 27705c8a1b8Smanu out: 27805c8a1b8Smanu free(sh, M_TEMP); 27905c8a1b8Smanu if (strtable) 28005c8a1b8Smanu free(strtable, M_TEMP); 28105c8a1b8Smanu return (error); 28205c8a1b8Smanu } 28305c8a1b8Smanu #endif 28405c8a1b8Smanu 285ee0c5b44Smanu int 2869fca5da6Scegger ELFNAME2(linux,signature)(struct lwp *l, struct exec_package *epp, Elf_Ehdr *eh, char *itp) 287f7ac1bd3Serh { 288f7ac1bd3Serh size_t i; 289f7ac1bd3Serh Elf_Phdr *ph; 290f7ac1bd3Serh size_t phsize; 291b29180b2Smycroft int error; 2926cc14962Schristos static const char linux[] = "Linux"; 2936cc14962Schristos 2946cc14962Schristos if (eh->e_ident[EI_OSABI] == 3 || 2956cc14962Schristos memcmp(&eh->e_ident[EI_ABIVERSION], linux, sizeof(linux)) == 0) 2966cc14962Schristos return 0; 297f7ac1bd3Serh 298f7ac1bd3Serh phsize = eh->e_phnum * sizeof(Elf_Phdr); 299f7ac1bd3Serh ph = (Elf_Phdr *)malloc(phsize, M_TEMP, M_WAITOK); 30095e1ffb1Schristos error = exec_read_from(l, epp->ep_vp, eh->e_phoff, ph, phsize); 301b29180b2Smycroft if (error) 302b29180b2Smycroft goto out; 303f7ac1bd3Serh 304f7ac1bd3Serh for (i = 0; i < eh->e_phnum; i++) { 305f7ac1bd3Serh Elf_Phdr *ephp = &ph[i]; 306b29180b2Smycroft Elf_Nhdr *np; 307b29180b2Smycroft u_int32_t *abi; 308f7ac1bd3Serh 309b29180b2Smycroft if (ephp->p_type != PT_NOTE || 310b29180b2Smycroft ephp->p_filesz > 1024 || 311b29180b2Smycroft ephp->p_filesz < sizeof(Elf_Nhdr) + 20) 312f7ac1bd3Serh continue; 313f7ac1bd3Serh 314b29180b2Smycroft np = (Elf_Nhdr *)malloc(ephp->p_filesz, M_TEMP, M_WAITOK); 31595e1ffb1Schristos error = exec_read_from(l, epp->ep_vp, ephp->p_offset, np, 31697c9d7a9Schristos ephp->p_filesz); 317b29180b2Smycroft if (error) 318b29180b2Smycroft goto next; 319f7ac1bd3Serh 320b29180b2Smycroft if (np->n_type != ELF_NOTE_TYPE_ABI_TAG || 321b29180b2Smycroft np->n_namesz != ELF_NOTE_ABI_NAMESZ || 322b29180b2Smycroft np->n_descsz != ELF_NOTE_ABI_DESCSZ || 32353524e44Schristos memcmp((void *)(np + 1), ELF_NOTE_ABI_NAME, 324b29180b2Smycroft ELF_NOTE_ABI_NAMESZ)) 325b29180b2Smycroft goto next; 326b29180b2Smycroft 327b29180b2Smycroft /* Make sure the OS is Linux. */ 32853524e44Schristos abi = (u_int32_t *)((char *)np + sizeof(Elf_Nhdr) + 329b29180b2Smycroft np->n_namesz); 330b29180b2Smycroft if (abi[0] == ELF_NOTE_ABI_OS_LINUX) 331f7ac1bd3Serh error = 0; 332b29180b2Smycroft else 333b29180b2Smycroft error = ENOEXEC; 334b29180b2Smycroft free(np, M_TEMP); 335b29180b2Smycroft goto out; 336f7ac1bd3Serh 337b29180b2Smycroft next: 338b29180b2Smycroft free(np, M_TEMP); 339f7ac1bd3Serh continue; 340f7ac1bd3Serh } 341f7ac1bd3Serh 342b29180b2Smycroft /* Check for certain intepreter names. */ 343714de045Sdrochner if (itp) { 344b29180b2Smycroft if (!strncmp(itp, "/lib/ld-linux", 13) || 34589647c7cSmanu #if (ELFSIZE == 64) 34689647c7cSmanu !strncmp(itp, "/lib64/ld-linux", 15) || 34789647c7cSmanu #endif 348b29180b2Smycroft !strncmp(itp, "/lib/ld.so.", 11)) 349f7ac1bd3Serh error = 0; 350b29180b2Smycroft else 351b29180b2Smycroft error = ENOEXEC; 352b29180b2Smycroft goto out; 353f7ac1bd3Serh } 354f7ac1bd3Serh 355f7ac1bd3Serh error = ENOEXEC; 356b29180b2Smycroft out: 357f7ac1bd3Serh free(ph, M_TEMP); 358b29180b2Smycroft return (error); 359f7ac1bd3Serh } 360f7ac1bd3Serh 361f7ac1bd3Serh int 3624d595fd7Schristos ELFNAME2(linux,probe)(struct lwp *l, struct exec_package *epp, void *eh, 363168cd830Schristos char *itp, vaddr_t *pos) 364fc7cfb5fSfvdl { 365fc7cfb5fSfvdl int error; 366fc7cfb5fSfvdl 36795e1ffb1Schristos if (((error = ELFNAME2(linux,signature)(l, epp, eh, itp)) != 0) && 368f7ac1bd3Serh #ifdef LINUX_GCC_SIGNATURE 36995e1ffb1Schristos ((error = ELFNAME2(linux,gcc_signature)(l, epp, eh)) != 0) && 3708537f76cSmanu #endif 371ac10cf69Smanu #ifdef LINUX_ATEXIT_SIGNATURE 37295e1ffb1Schristos ((error = ELFNAME2(linux,atexit_signature)(l, epp, eh)) != 0) && 373ac10cf69Smanu #endif 37405c8a1b8Smanu #ifdef LINUX_DEBUGLINK_SIGNATURE 37505c8a1b8Smanu ((error = ELFNAME2(linux,debuglink_signature)(l, epp, eh)) != 0) && 37605c8a1b8Smanu #endif 37705c8a1b8Smanu 1) { 37805c8a1b8Smanu DPRINTF(("linux_probe: returning %d\n", error)); 3798537f76cSmanu return error; 38005c8a1b8Smanu } 3814d9a6e09Schristos 382714de045Sdrochner if (itp) { 383b8fbaf8cSdsl if ((error = emul_find_interp(l, epp, itp))) 38447cd9b85Sjdolecek return (error); 385fc7cfb5fSfvdl } 386590b9069Schs epp->ep_flags |= EXEC_FORCEAUX; 38765fc8539Schristos DPRINTF(("linux_probe: returning 0\n")); 388c4aaa600Sfvdl return 0; 389fc7cfb5fSfvdl } 390c4aaa600Sfvdl 391cee43b67Sjdolecek #ifndef LINUX_MACHDEP_ELF_COPYARGS 392cee43b67Sjdolecek /* 393cee43b67Sjdolecek * Copy arguments onto the stack in the normal way, but add some 394cee43b67Sjdolecek * extra information in case of dynamic binding. 395cee43b67Sjdolecek */ 396cee43b67Sjdolecek int 39795e1ffb1Schristos ELFNAME2(linux,copyargs)(struct lwp *l, struct exec_package *pack, 398cee43b67Sjdolecek struct ps_strings *arginfo, char **stackp, void *argp) 399cee43b67Sjdolecek { 400cee43b67Sjdolecek size_t len; 401cee43b67Sjdolecek AuxInfo ai[LINUX_ELF_AUX_ENTRIES], *a; 402cee43b67Sjdolecek struct elf_args *ap; 403cee43b67Sjdolecek int error; 404cee43b67Sjdolecek struct vattr *vap; 405cee43b67Sjdolecek 40695e1ffb1Schristos if ((error = copyargs(l, pack, arginfo, stackp, argp)) != 0) 407cee43b67Sjdolecek return error; 408cee43b67Sjdolecek 409cee43b67Sjdolecek a = ai; 410cee43b67Sjdolecek 411cee43b67Sjdolecek /* 412cee43b67Sjdolecek * Push extra arguments used by glibc on the stack. 413cee43b67Sjdolecek */ 414cee43b67Sjdolecek 415cee43b67Sjdolecek a->a_type = AT_PAGESZ; 416cee43b67Sjdolecek a->a_v = PAGE_SIZE; 417cee43b67Sjdolecek a++; 418cee43b67Sjdolecek 419cee43b67Sjdolecek if ((ap = (struct elf_args *)pack->ep_emul_arg)) { 420cee43b67Sjdolecek 421cee43b67Sjdolecek a->a_type = AT_PHDR; 422cee43b67Sjdolecek a->a_v = ap->arg_phaddr; 423cee43b67Sjdolecek a++; 424cee43b67Sjdolecek 425cee43b67Sjdolecek a->a_type = AT_PHENT; 426cee43b67Sjdolecek a->a_v = ap->arg_phentsize; 427cee43b67Sjdolecek a++; 428cee43b67Sjdolecek 429cee43b67Sjdolecek a->a_type = AT_PHNUM; 430cee43b67Sjdolecek a->a_v = ap->arg_phnum; 431cee43b67Sjdolecek a++; 432cee43b67Sjdolecek 433cee43b67Sjdolecek a->a_type = AT_BASE; 434cee43b67Sjdolecek a->a_v = ap->arg_interp; 435cee43b67Sjdolecek a++; 436cee43b67Sjdolecek 437cee43b67Sjdolecek a->a_type = AT_FLAGS; 438cee43b67Sjdolecek a->a_v = 0; 439cee43b67Sjdolecek a++; 440cee43b67Sjdolecek 441cee43b67Sjdolecek a->a_type = AT_ENTRY; 442cee43b67Sjdolecek a->a_v = ap->arg_entry; 443cee43b67Sjdolecek a++; 444cee43b67Sjdolecek 4452210079eSmatt exec_free_emul_arg(pack); 446cee43b67Sjdolecek } 447cee43b67Sjdolecek 448cee43b67Sjdolecek /* Linux-specific items */ 449cee43b67Sjdolecek a->a_type = LINUX_AT_CLKTCK; 450cee43b67Sjdolecek a->a_v = hz; 451cee43b67Sjdolecek a++; 452cee43b67Sjdolecek 453cee43b67Sjdolecek vap = pack->ep_vap; 454cee43b67Sjdolecek 455cee43b67Sjdolecek a->a_type = LINUX_AT_UID; 456f474dcebSad a->a_v = kauth_cred_getuid(l->l_cred); 457cee43b67Sjdolecek a++; 458cee43b67Sjdolecek 459cee43b67Sjdolecek a->a_type = LINUX_AT_EUID; 460cee43b67Sjdolecek if (vap->va_mode & S_ISUID) 461cee43b67Sjdolecek a->a_v = vap->va_uid; 462cee43b67Sjdolecek else 463f474dcebSad a->a_v = kauth_cred_geteuid(l->l_cred); 464cee43b67Sjdolecek a++; 465cee43b67Sjdolecek 466cee43b67Sjdolecek a->a_type = LINUX_AT_GID; 467f474dcebSad a->a_v = kauth_cred_getgid(l->l_cred); 468cee43b67Sjdolecek a++; 469cee43b67Sjdolecek 470cee43b67Sjdolecek a->a_type = LINUX_AT_EGID; 471cee43b67Sjdolecek if (vap->va_mode & S_ISGID) 472cee43b67Sjdolecek a->a_v = vap->va_gid; 473cee43b67Sjdolecek else 474f474dcebSad a->a_v = kauth_cred_getegid(l->l_cred); 475cee43b67Sjdolecek a++; 476cee43b67Sjdolecek 477cee43b67Sjdolecek a->a_type = AT_NULL; 478cee43b67Sjdolecek a->a_v = 0; 479cee43b67Sjdolecek a++; 480cee43b67Sjdolecek 481cee43b67Sjdolecek len = (a - ai) * sizeof(AuxInfo); 482cee43b67Sjdolecek if ((error = copyout(ai, *stackp, len)) != 0) 483cee43b67Sjdolecek return error; 484cee43b67Sjdolecek *stackp += len; 485cee43b67Sjdolecek 486cee43b67Sjdolecek return 0; 487cee43b67Sjdolecek } 488cee43b67Sjdolecek #endif /* !LINUX_MACHDEP_ELF_COPYARGS */ 489