char	*interp; int	error; struct	elf_args *ap; AuxInfo ai[ELF_AUX_ENTRIES], *a; Elf_Addr	pos = epp->ep_interp_pos;  if (epp->ep_interp == NULL) { return (0); }  interp = (char *)epp->ep_interp; ap = (struct elf_args *)epp->ep_emul_arg;  if ((error = ELFNAME(load_file)(p, interp, epp, ap, &pos)) != 0) { free((char *)ap, M_TEMP); free((char *)interp, M_TEMP); kill_vmcmds(&epp->ep_vmcmds); return (error); }  error = exec_process_vmcmds(p, epp);   if (error == 0) { a = ai;  a->au_id = AUX_phdr; a->au_v = ap->arg_phaddr; a++;  a->au_id = AUX_phent; a->au_v = ap->arg_phentsize; a++;  a->au_id = AUX_phnum; a->au_v = ap->arg_phnum; a++;  a->au_id = AUX_pagesz; a->au_v = PAGE_SIZE; a++;  a->au_id = AUX_base; a->au_v = ap->arg_interp; a++;  a->au_id = AUX_flags; a->au_v = 0; a++;  a->au_id = AUX_entry; a->au_v = ap->arg_entry; a++;  a->au_id = AUX_null; a->au_v = 0; a++;  error = copyout(ai, epp->ep_emul_argp, sizeof ai); } free((char *)ap, M_TEMP); free((char *)interp, M_TEMP); return (error);
Elf_Ehdr *eh = epp->ep_hdr; Elf_Phdr *ph, *pp; Elf_Addr phdr = 0; int error, i; char interp[MAXPATHLEN]; u_long pos = 0, phsize; u_int8_t os = OOS_NULL;  if (epp->ep_hdrvalid < sizeof(Elf_Ehdr)) return (ENOEXEC);  if (ELFNAME(check_header)(eh, ET_EXEC) && ELFNAME(olf_check_header)(eh, ET_EXEC, &os)) return (ENOEXEC);   if (epp->ep_vp->v_writecount != 0) { #ifdef DIAGNOSTIC if (epp->ep_vp->v_flag & VTEXT) panic("exec: a VTEXT vnode has writecount != 0"); #endif return (ETXTBSY); }  phsize = eh->e_phnum * sizeof(Elf_Phdr); ph = (Elf_Phdr *)malloc(phsize, M_TEMP, M_WAITOK);  if ((error = ELFNAME(read_from)(p, epp->ep_vp, eh->e_phoff, (caddr_t)ph, phsize)) != 0) goto bad;  epp->ep_tsize = ELFDEFNNAME(NO_ADDR); epp->ep_dsize = ELFDEFNNAME(NO_ADDR);  interp[0] = '\0';  for (i = 0; i < eh->e_phnum; i++) { pp = &ph[i]; if (pp->p_type == PT_INTERP) { if (pp->p_filesz >= sizeof(interp)) goto bad; if ((error = ELFNAME(read_from)(p, epp->ep_vp, pp->p_offset, (caddr_t)interp, pp->p_filesz)) != 0) goto bad; break; } }   epp->ep_emul = &ELFNAMEEND(emul); pos = ELFDEFNNAME(NO_ADDR);   error = ENOEXEC; p->p_os = OOS_OPENBSD; #ifdef NATIVE_EXEC_ELF if (ELFNAME(os_pt_note)(p, epp, epp->ep_hdr, "OpenBSD", 8, 4) == 0) { goto native; } #endif for (i = 0; i < sizeof(ELFNAME(probes)) / sizeof(ELFNAME(probes)[0]) && error; i++) { if (os == OOS_NULL || ((1 << os) & ELFNAME(probes)[i].os_mask)) error = ELFNAME(probes)[i].func ? (*ELFNAME(probes)[i].func)(p, epp, interp, &pos, &os) : 0; } if (!error) p->p_os = os; #ifndef NATIVE_EXEC_ELF else goto bad; #else native: #endif   for (i = 0; i < eh->e_phnum; i++) { Elf_Addr addr = ELFDEFNNAME(NO_ADDR), size = 0; int prot = 0;  pp = &ph[i];  switch (ph[i].p_type) { case PT_LOAD:  ELFNAME(load_psection)(&epp->ep_vmcmds, epp->ep_vp, &ph[i], &addr, &size, &prot, 0);  if (prot & VM_PROT_WRITE) {  if (epp->ep_dsize == ELFDEFNNAME(NO_ADDR)) { epp->ep_daddr = addr; epp->ep_dsize = size; } else { if (addr < epp->ep_daddr) { epp->ep_dsize = epp->ep_dsize + epp->ep_daddr - addr; epp->ep_daddr = addr; } else epp->ep_dsize = addr+size - epp->ep_daddr; } } else if (prot & VM_PROT_EXECUTE) {  if (epp->ep_tsize == ELFDEFNNAME(NO_ADDR)) { epp->ep_taddr = addr; epp->ep_tsize = size; } else { if (addr < epp->ep_taddr) { epp->ep_tsize = epp->ep_tsize + epp->ep_taddr - addr; epp->ep_taddr = addr; } else epp->ep_tsize = addr+size - epp->ep_taddr; } } break;  case PT_SHLIB: error = ENOEXEC; goto bad;  case PT_INTERP:  case PT_DYNAMIC: case PT_NOTE: break;  case PT_PHDR:  phdr = pp->p_vaddr; break;  default:  break; } }  #if !defined(__mips__)  if (pos == ELFDEFNNAME(NO_ADDR)) pos = round_page(epp->ep_daddr + MAXDSIZ); #endif   if (interp[0]) { char *ip; struct elf_args *ap;  ip = (char *)malloc(MAXPATHLEN, M_TEMP, M_WAITOK); ap = (struct elf_args *) malloc(sizeof(struct elf_args), M_TEMP, M_WAITOK);  bcopy(interp, ip, MAXPATHLEN); epp->ep_interp = ip; epp->ep_interp_pos = pos;  ap->arg_phaddr = phdr; ap->arg_phentsize = eh->e_phentsize; ap->arg_phnum = eh->e_phnum; ap->arg_entry = eh->e_entry; ap->arg_os = os;  epp->ep_emul_arg = ap; epp->ep_entry = eh->e_entry;  } else { epp->ep_interp = NULL; epp->ep_entry = eh->e_entry; }  #if defined(COMPAT_SVR4) && defined(i386) #ifndef ELF_MAP_PAGE_ZERO  if (p->p_os == OOS_DELL) #endif NEW_VMCMD(&epp->ep_vmcmds, vmcmd_map_readvn, PAGE_SIZE, 0, epp->ep_vp, 0, VM_PROT_READ); #endif  free((char *)ph, M_TEMP); vn_marktext(epp->ep_vp); return (exec_setup_stack(p, epp));  bad: free((char *)ph, M_TEMP); kill_vmcmds(&epp->ep_vmcmds); return (ENOEXEC);
ELFNAME2(exec,fixup)(struct proc *p, struct exec_package *epp){	char	*interp;	int	error;	struct	elf_args *ap;	AuxInfo ai[ELF_AUX_ENTRIES], *a;	Elf_Addr	pos = epp->ep_interp_pos;	if (epp->ep_interp == NULL) {		return (0);	}	interp = (char *)epp->ep_interp;	ap = (struct elf_args *)epp->ep_emul_arg;	if ((error = ELFNAME(load_file)(p, interp, epp, ap, &pos)) != 0) {		free((char *)ap, M_TEMP);		free((char *)interp, M_TEMP);		kill_vmcmds(&epp->ep_vmcmds);		return (error);	}	/*	 * We have to do this ourselves...	 */	error = exec_process_vmcmds(p, epp);	/*	 * Push extra arguments on the stack needed by dynamically	 * linked binaries	 */	if (error == 0) {		a = ai;		a->au_id = AUX_phdr;		a->au_v = ap->arg_phaddr;		a++;		a->au_id = AUX_phent;		a->au_v = ap->arg_phentsize;		a++;		a->au_id = AUX_phnum;		a->au_v = ap->arg_phnum;		a++;		a->au_id = AUX_pagesz;		a->au_v = PAGE_SIZE;		a++;		a->au_id = AUX_base;		a->au_v = ap->arg_interp;		a++;		a->au_id = AUX_flags;		a->au_v = 0;		a++;		a->au_id = AUX_entry;		a->au_v = ap->arg_entry;		a++;		a->au_id = AUX_null;		a->au_v = 0;		a++;		error = copyout(ai, epp->ep_emul_argp, sizeof ai);	}	free((char *)ap, M_TEMP);	free((char *)interp, M_TEMP);	return (error);}