1 /* $NetBSD: exec_elf32.c,v 1.39 1998/10/03 20:39:32 christos Exp $ */ 2 3 /*- 4 * Copyright (c) 1994 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Christos Zoulas. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 3. All advertising materials mentioning features or use of this software 19 * must display the following acknowledgement: 20 * This product includes software developed by the NetBSD 21 * Foundation, Inc. and its contributors. 22 * 4. Neither the name of The NetBSD Foundation nor the names of its 23 * contributors may be used to endorse or promote products derived 24 * from this software without specific prior written permission. 25 * 26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 * POSSIBILITY OF SUCH DAMAGE. 37 */ 38 39 /* 40 * Copyright (c) 1996 Christopher G. Demetriou 41 * All rights reserved. 42 * 43 * Redistribution and use in source and binary forms, with or without 44 * modification, are permitted provided that the following conditions 45 * are met: 46 * 1. Redistributions of source code must retain the above copyright 47 * notice, this list of conditions and the following disclaimer. 48 * 2. Redistributions in binary form must reproduce the above copyright 49 * notice, this list of conditions and the following disclaimer in the 50 * documentation and/or other materials provided with the distribution. 51 * 3. The name of the author may not be used to endorse or promote products 52 * derived from this software without specific prior written permission 53 * 54 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 55 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 56 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 57 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 58 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 59 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 60 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 61 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 62 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 63 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 64 */ 65 66 /* If not included by exec_elf64.c, ELFSIZE won't be defined. */ 67 #ifndef ELFSIZE 68 #define ELFSIZE 32 69 #endif 70 71 #include "opt_compat_linux.h" 72 #include "opt_compat_ibcs2.h" 73 #include "opt_compat_svr4.h" 74 75 #include <sys/param.h> 76 #include <sys/systm.h> 77 #include <sys/kernel.h> 78 #include <sys/proc.h> 79 #include <sys/malloc.h> 80 #include <sys/namei.h> 81 #include <sys/vnode.h> 82 #include <sys/exec.h> 83 #include <sys/exec_elf.h> 84 #include <sys/fcntl.h> 85 #include <sys/syscall.h> 86 #include <sys/signalvar.h> 87 #include <sys/mount.h> 88 #include <sys/stat.h> 89 90 #include <sys/mman.h> 91 #include <vm/vm.h> 92 #include <vm/vm_param.h> 93 #include <vm/vm_map.h> 94 95 #include <machine/cpu.h> 96 #include <machine/reg.h> 97 98 #ifdef COMPAT_LINUX 99 #include <compat/linux/common/linux_exec.h> 100 #endif 101 102 #ifdef COMPAT_SVR4 103 #include <compat/svr4/svr4_exec.h> 104 #endif 105 106 #ifdef COMPAT_IBCS2 107 #include <compat/ibcs2/ibcs2_exec.h> 108 #endif 109 110 int ELFNAME(check_header) __P((Elf_Ehdr *, int)); 111 int ELFNAME(load_file) __P((struct proc *, struct exec_package *, char *, 112 struct exec_vmcmd_set *, u_long *, struct elf_args *, Elf_Addr *)); 113 void ELFNAME(load_psection) __P((struct exec_vmcmd_set *, struct vnode *, 114 Elf_Phdr *, Elf_Addr *, u_long *, int *)); 115 116 extern char sigcode[], esigcode[]; 117 #ifdef SYSCALL_DEBUG 118 extern char *syscallnames[]; 119 #endif 120 121 struct emul ELFNAMEEND(emul_netbsd) = { 122 "netbsd", 123 NULL, 124 sendsig, 125 SYS_syscall, 126 SYS_MAXSYSCALL, 127 sysent, 128 #ifdef SYSCALL_DEBUG 129 syscallnames, 130 #else 131 NULL, 132 #endif 133 ELF_AUX_ENTRIES * sizeof(AuxInfo), 134 ELFNAME(copyargs), 135 setregs, 136 sigcode, 137 esigcode, 138 }; 139 140 int (*ELFNAME(probe_funcs)[]) __P((struct proc *, struct exec_package *, 141 Elf_Ehdr *, char *, Elf_Addr *)) = { 142 #if defined(COMPAT_LINUX) 143 ELFNAME2(linux,probe), 144 #endif 145 #if defined(COMPAT_SVR4) && (ELFSIZE == 32) 146 ELFNAME2(svr4,probe), /* XXX not 64-bit safe */ 147 #endif 148 #if defined(COMPAT_IBCS2) && (ELFSIZE == 32) 149 ELFNAME2(ibcs2,probe), /* XXX not 64-bit safe */ 150 #endif 151 }; 152 153 /* round up and down to page boundaries. */ 154 #define ELF_ROUND(a, b) (((a) + (b) - 1) & ~((b) - 1)) 155 #define ELF_TRUNC(a, b) ((a) & ~((b) - 1)) 156 157 /* 158 * Copy arguments onto the stack in the normal way, but add some 159 * extra information in case of dynamic binding. 160 */ 161 void * 162 ELFNAME(copyargs)(pack, arginfo, stack, argp) 163 struct exec_package *pack; 164 struct ps_strings *arginfo; 165 void *stack; 166 void *argp; 167 { 168 size_t len; 169 AuxInfo ai[ELF_AUX_ENTRIES], *a; 170 struct elf_args *ap; 171 172 stack = copyargs(pack, arginfo, stack, argp); 173 if (!stack) 174 return NULL; 175 176 a = ai; 177 178 /* 179 * Push extra arguments on the stack needed by dynamically 180 * linked binaries 181 */ 182 if ((ap = (struct elf_args *)pack->ep_emul_arg)) { 183 184 a->au_id = AUX_phdr; 185 a->au_v = ap->arg_phaddr; 186 a++; 187 188 a->au_id = AUX_phent; 189 a->au_v = ap->arg_phentsize; 190 a++; 191 192 a->au_id = AUX_phnum; 193 a->au_v = ap->arg_phnum; 194 a++; 195 196 a->au_id = AUX_pagesz; 197 a->au_v = NBPG; 198 a++; 199 200 a->au_id = AUX_base; 201 a->au_v = ap->arg_interp; 202 a++; 203 204 a->au_id = AUX_flags; 205 a->au_v = 0; 206 a++; 207 208 a->au_id = AUX_entry; 209 a->au_v = ap->arg_entry; 210 a++; 211 212 free((char *)ap, M_TEMP); 213 pack->ep_emul_arg = NULL; 214 } 215 216 a->au_id = AUX_null; 217 a->au_v = 0; 218 a++; 219 220 len = (a - ai) * sizeof(AuxInfo); 221 if (copyout(ai, stack, len)) 222 return NULL; 223 (caddr_t)stack += len; 224 225 return stack; 226 } 227 228 /* 229 * elf_check_header(): 230 * 231 * Check header for validity; return 0 of ok ENOEXEC if error 232 */ 233 int 234 ELFNAME(check_header)(eh, type) 235 Elf_Ehdr *eh; 236 int type; 237 { 238 239 if (memcmp(eh->e_ident, Elf_e_ident, Elf_e_siz) != 0) 240 return ENOEXEC; 241 242 switch (eh->e_machine) { 243 244 ELFDEFNNAME(MACHDEP_ID_CASES) 245 246 default: 247 return ENOEXEC; 248 } 249 250 if (eh->e_type != type) 251 return ENOEXEC; 252 253 return 0; 254 } 255 256 /* 257 * elf_load_psection(): 258 * 259 * Load a psection at the appropriate address 260 */ 261 void 262 ELFNAME(load_psection)(vcset, vp, ph, addr, size, prot) 263 struct exec_vmcmd_set *vcset; 264 struct vnode *vp; 265 Elf_Phdr *ph; 266 Elf_Addr *addr; 267 u_long *size; 268 int *prot; 269 { 270 u_long uaddr, msize, psize, rm, rf; 271 long diff, offset; 272 273 /* 274 * If the user specified an address, then we load there. 275 */ 276 if (*addr != ELFDEFNNAME(NO_ADDR)) { 277 if (ph->p_align > 1) { 278 *addr = ELF_ROUND(*addr, ph->p_align); 279 uaddr = ELF_TRUNC(ph->p_vaddr, ph->p_align); 280 } else 281 uaddr = ph->p_vaddr; 282 diff = ph->p_vaddr - uaddr; 283 } else { 284 *addr = uaddr = ph->p_vaddr; 285 if (ph->p_align > 1) 286 *addr = ELF_TRUNC(uaddr, ph->p_align); 287 diff = uaddr - *addr; 288 } 289 290 *prot |= (ph->p_flags & Elf_pf_r) ? VM_PROT_READ : 0; 291 *prot |= (ph->p_flags & Elf_pf_w) ? VM_PROT_WRITE : 0; 292 *prot |= (ph->p_flags & Elf_pf_x) ? VM_PROT_EXECUTE : 0; 293 294 offset = ph->p_offset - diff; 295 *size = ph->p_filesz + diff; 296 msize = ph->p_memsz + diff; 297 psize = round_page(*size); 298 299 if ((ph->p_flags & Elf_pf_w) != 0) { 300 /* 301 * Because the pagedvn pager can't handle zero fill of the last 302 * data page if it's not page aligned we map the last page 303 * readvn. 304 */ 305 psize = trunc_page(*size); 306 NEW_VMCMD(vcset, vmcmd_map_pagedvn, psize, *addr, vp, 307 offset, *prot); 308 if(psize != *size) 309 NEW_VMCMD(vcset, vmcmd_map_readvn, *size - psize, 310 *addr + psize, vp, offset + psize, *prot); 311 } else 312 NEW_VMCMD(vcset, vmcmd_map_pagedvn, psize, *addr, vp, 313 offset, *prot); 314 315 /* 316 * Check if we need to extend the size of the segment 317 */ 318 rm = round_page(*addr + msize); 319 rf = round_page(*addr + *size); 320 321 if (rm != rf) { 322 NEW_VMCMD(vcset, vmcmd_map_zero, rm - rf, rf, NULLVP, 323 0, *prot); 324 *size = msize; 325 } 326 } 327 328 /* 329 * elf_read_from(): 330 * 331 * Read from vnode into buffer at offset. 332 */ 333 int 334 ELFNAME(read_from)(p, vp, off, buf, size) 335 struct vnode *vp; 336 u_long off; 337 struct proc *p; 338 caddr_t buf; 339 int size; 340 { 341 int error; 342 size_t resid; 343 344 if ((error = vn_rdwr(UIO_READ, vp, buf, size, off, UIO_SYSSPACE, 345 0, p->p_ucred, &resid, p)) != 0) 346 return error; 347 /* 348 * See if we got all of it 349 */ 350 if (resid != 0) 351 return ENOEXEC; 352 return 0; 353 } 354 355 /* 356 * elf_load_file(): 357 * 358 * Load a file (interpreter/library) pointed to by path 359 * [stolen from coff_load_shlib()]. Made slightly generic 360 * so it might be used externally. 361 */ 362 int 363 ELFNAME(load_file)(p, epp, path, vcset, entry, ap, last) 364 struct proc *p; 365 struct exec_package *epp; 366 char *path; 367 struct exec_vmcmd_set *vcset; 368 u_long *entry; 369 struct elf_args *ap; 370 Elf_Addr *last; 371 { 372 int error, i; 373 struct nameidata nd; 374 struct vnode *vp; 375 struct vattr attr; 376 Elf_Ehdr eh; 377 Elf_Phdr *ph = NULL; 378 u_long phsize; 379 char *bp = NULL; 380 Elf_Addr addr = *last; 381 382 bp = path; 383 /* 384 * 1. open file 385 * 2. read filehdr 386 * 3. map text, data, and bss out of it using VM_* 387 */ 388 NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF, UIO_SYSSPACE, path, p); 389 if ((error = namei(&nd)) != 0) 390 return error; 391 vp = nd.ni_vp; 392 393 /* 394 * Similarly, if it's not marked as executable, or it's not a regular 395 * file, we don't allow it to be used. 396 */ 397 if (vp->v_type != VREG) { 398 error = EACCES; 399 goto badunlock; 400 } 401 if ((error = VOP_ACCESS(vp, VEXEC, p->p_ucred, p)) != 0) 402 goto badunlock; 403 404 /* get attributes */ 405 if ((error = VOP_GETATTR(vp, &attr, p->p_ucred, p)) != 0) 406 goto badunlock; 407 408 /* 409 * Check mount point. Though we're not trying to exec this binary, 410 * we will be executing code from it, so if the mount point 411 * disallows execution or set-id-ness, we punt or kill the set-id. 412 */ 413 if (vp->v_mount->mnt_flag & MNT_NOEXEC) { 414 error = EACCES; 415 goto badunlock; 416 } 417 if (vp->v_mount->mnt_flag & MNT_NOSUID) 418 epp->ep_vap->va_mode &= ~(S_ISUID | S_ISGID); 419 420 #ifdef notyet /* XXX cgd 960926 */ 421 XXX cgd 960926: (maybe) VOP_OPEN it (and VOP_CLOSE in copyargs?) 422 #endif 423 VOP_UNLOCK(vp, 0); 424 425 if ((error = ELFNAME(read_from)(p, vp, 0, (caddr_t) &eh, 426 sizeof(eh))) != 0) 427 goto bad; 428 429 if ((error = ELFNAME(check_header)(&eh, Elf_et_dyn)) != 0) 430 goto bad; 431 432 phsize = eh.e_phnum * sizeof(Elf_Phdr); 433 ph = (Elf_Phdr *)malloc(phsize, M_TEMP, M_WAITOK); 434 435 if ((error = ELFNAME(read_from)(p, vp, eh.e_phoff, 436 (caddr_t) ph, phsize)) != 0) 437 goto bad; 438 439 /* 440 * Load all the necessary sections 441 */ 442 for (i = 0; i < eh.e_phnum; i++) { 443 u_long size = 0; 444 int prot = 0; 445 446 switch (ph[i].p_type) { 447 case Elf_pt_load: 448 ELFNAME(load_psection)(vcset, vp, &ph[i], &addr, 449 &size, &prot); 450 /* If entry is within this section it must be text */ 451 if (eh.e_entry >= ph[i].p_vaddr && 452 eh.e_entry < (ph[i].p_vaddr + size)) { 453 /* XXX */ 454 *entry = addr + eh.e_entry; 455 #ifdef mips 456 *entry -= ph[i].p_vaddr; 457 #endif 458 ap->arg_interp = addr; 459 } 460 addr += size; 461 break; 462 463 case Elf_pt_dynamic: 464 case Elf_pt_phdr: 465 case Elf_pt_note: 466 break; 467 468 default: 469 break; 470 } 471 } 472 473 free((char *)ph, M_TEMP); 474 *last = addr; 475 vrele(vp); 476 return 0; 477 478 badunlock: 479 VOP_UNLOCK(vp, 0); 480 481 bad: 482 if (ph != NULL) 483 free((char *)ph, M_TEMP); 484 #ifdef notyet /* XXX cgd 960926 */ 485 (maybe) VOP_CLOSE it 486 #endif 487 vrele(vp); 488 return error; 489 } 490 491 /* 492 * exec_elf_makecmds(): Prepare an Elf binary's exec package 493 * 494 * First, set of the various offsets/lengths in the exec package. 495 * 496 * Then, mark the text image busy (so it can be demand paged) or error 497 * out if this is not possible. Finally, set up vmcmds for the 498 * text, data, bss, and stack segments. 499 */ 500 int 501 ELFNAME2(exec,makecmds)(p, epp) 502 struct proc *p; 503 struct exec_package *epp; 504 { 505 Elf_Ehdr *eh = epp->ep_hdr; 506 Elf_Phdr *ph, *pp; 507 Elf_Addr phdr = 0, pos = 0; 508 int error, i, n, nload; 509 char interp[MAXPATHLEN]; 510 u_long phsize; 511 512 if (epp->ep_hdrvalid < sizeof(Elf_Ehdr)) 513 return ENOEXEC; 514 515 if (ELFNAME(check_header)(eh, Elf_et_exec)) 516 return ENOEXEC; 517 518 /* 519 * check if vnode is in open for writing, because we want to 520 * demand-page out of it. if it is, don't do it, for various 521 * reasons 522 */ 523 if (epp->ep_vp->v_writecount != 0) { 524 #ifdef DIAGNOSTIC 525 if (epp->ep_vp->v_flag & VTEXT) 526 panic("exec: a VTEXT vnode has writecount != 0\n"); 527 #endif 528 return ETXTBSY; 529 } 530 /* 531 * Allocate space to hold all the program headers, and read them 532 * from the file 533 */ 534 phsize = eh->e_phnum * sizeof(Elf_Phdr); 535 ph = (Elf_Phdr *)malloc(phsize, M_TEMP, M_WAITOK); 536 537 if ((error = ELFNAME(read_from)(p, epp->ep_vp, eh->e_phoff, 538 (caddr_t) ph, phsize)) != 0) 539 goto bad; 540 541 epp->ep_taddr = epp->ep_tsize = ELFDEFNNAME(NO_ADDR); 542 epp->ep_daddr = epp->ep_dsize = ELFDEFNNAME(NO_ADDR); 543 544 interp[0] = '\0'; 545 546 for (i = 0; i < eh->e_phnum; i++) { 547 pp = &ph[i]; 548 if (pp->p_type == Elf_pt_interp) { 549 if (pp->p_filesz >= sizeof(interp)) 550 goto bad; 551 if ((error = ELFNAME(read_from)(p, epp->ep_vp, 552 pp->p_offset, (caddr_t) interp, 553 pp->p_filesz)) != 0) 554 goto bad; 555 break; 556 } 557 } 558 559 /* 560 * Setup things for native emulation. 561 */ 562 epp->ep_emul = &ELFNAMEEND(emul_netbsd); 563 pos = ELFDEFNNAME(NO_ADDR); 564 565 /* 566 * On the same architecture, we may be emulating different systems. 567 * See which one will accept this executable. This currently only 568 * applies to SVR4, and IBCS2 on the i386 and Linux on the i386 569 * and the Alpha. 570 * 571 * Probe functions would normally see if the interpreter (if any) 572 * exists. Emulation packages may possibly replace the interpreter in 573 * interp[] with a changed path (/emul/xxx/<path>), and also 574 * set the ep_emul field in the exec package structure. 575 */ 576 n = sizeof(ELFNAME(probe_funcs)) / sizeof(ELFNAME(probe_funcs)[0]); 577 if (n != 0) { 578 error = ENOEXEC; 579 for (i = 0; i < n && error; i++) 580 error = ELFNAME(probe_funcs)[i](p, epp, eh, 581 interp, &pos); 582 #ifdef notyet 583 /* 584 * We should really use a signature in our native binaries 585 * and have our own probe function for matching binaries, 586 * before trying the emulations. For now, if the emulation 587 * probes failed we default to native. 588 */ 589 if (error) 590 goto bad; 591 #endif 592 } 593 594 /* 595 * Load all the necessary sections 596 */ 597 for (i = nload = 0; i < eh->e_phnum; i++) { 598 Elf_Addr addr = ELFDEFNNAME(NO_ADDR); 599 u_long size = 0; 600 int prot = 0; 601 602 pp = &ph[i]; 603 604 switch (ph[i].p_type) { 605 case Elf_pt_load: 606 /* 607 * XXX 608 * Can handle only 2 sections: text and data 609 */ 610 if (nload++ == 2) 611 goto bad; 612 ELFNAME(load_psection)(&epp->ep_vmcmds, epp->ep_vp, 613 &ph[i], &addr, &size, &prot); 614 615 /* 616 * Decide whether it's text or data by looking 617 * at the entry point. 618 */ 619 if (eh->e_entry >= addr && 620 eh->e_entry < (addr + size)) { 621 epp->ep_taddr = addr; 622 epp->ep_tsize = size; 623 if (epp->ep_daddr == ELFDEFNNAME(NO_ADDR)) { 624 epp->ep_daddr = addr; 625 epp->ep_dsize = size; 626 } 627 } else { 628 epp->ep_daddr = addr; 629 epp->ep_dsize = size; 630 } 631 break; 632 633 case Elf_pt_shlib: 634 #ifndef COMPAT_IBCS2 /* SCO has these sections */ 635 error = ENOEXEC; 636 goto bad; 637 #endif 638 639 case Elf_pt_interp: 640 /* Already did this one */ 641 case Elf_pt_dynamic: 642 case Elf_pt_note: 643 break; 644 645 case Elf_pt_phdr: 646 /* Note address of program headers (in text segment) */ 647 phdr = pp->p_vaddr; 648 break; 649 650 default: 651 /* 652 * Not fatal; we don't need to understand everything. 653 */ 654 break; 655 } 656 } 657 658 /* this breaks on, e.g., OpenBSD-compatible mips shared binaries. */ 659 #ifndef ELF_INTERP_NON_RELOCATABLE 660 /* 661 * If no position to load the interpreter was set by a probe 662 * function, pick the same address that a non-fixed mmap(0, ..) 663 * would (i.e. something safely out of the way). 664 */ 665 if (pos == ELFDEFNNAME(NO_ADDR)) 666 pos = round_page(epp->ep_daddr + MAXDSIZ); 667 #endif /* !ELF_INTERP_NON_RELOCATABLE */ 668 669 /* 670 * Check if we found a dynamically linked binary and arrange to load 671 * it's interpreter 672 */ 673 if (interp[0]) { 674 struct elf_args *ap; 675 676 ap = (struct elf_args *)malloc(sizeof(struct elf_args), 677 M_TEMP, M_WAITOK); 678 if ((error = ELFNAME(load_file)(p, epp, interp, 679 &epp->ep_vmcmds, &epp->ep_entry, ap, &pos)) != 0) { 680 free((char *)ap, M_TEMP); 681 goto bad; 682 } 683 pos += phsize; 684 ap->arg_phaddr = phdr; 685 686 ap->arg_phentsize = eh->e_phentsize; 687 ap->arg_phnum = eh->e_phnum; 688 ap->arg_entry = eh->e_entry; 689 690 epp->ep_emul_arg = ap; 691 } else 692 epp->ep_entry = eh->e_entry; 693 694 #ifdef ELF_MAP_PAGE_ZERO 695 /* Dell SVR4 maps page zero, yeuch! */ 696 NEW_VMCMD(&epp->ep_vmcmds, vmcmd_map_readvn, NBPG, 0, epp->ep_vp, 0, 697 VM_PROT_READ); 698 #endif 699 free((char *)ph, M_TEMP); 700 epp->ep_vp->v_flag |= VTEXT; 701 return exec_elf_setup_stack(p, epp); 702 703 bad: 704 free((char *)ph, M_TEMP); 705 kill_vmcmds(&epp->ep_vmcmds); 706 return ENOEXEC; 707 } 708